@xopcai/xopc 0.0.158 → 0.0.159

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 (105) hide show
  1. package/dist/browser-ext/manifest.json +1 -1
  2. package/dist/extensions/dashscope/src/image-generation-provider.js +1 -1
  3. package/dist/extensions/fal/src/image-generation-provider.js +1 -1
  4. package/dist/extensions/google/src/image-generation-provider.js +1 -1
  5. package/dist/extensions/telegram/xopc.extension.json +1 -1
  6. package/dist/gateway/static/root/assets/{action-boundary-settings-panel-2p1f4-KA.js → action-boundary-settings-panel-CaRK2vIy.js} +1 -1
  7. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-BIl6X2b_.js → agent-avatar-dicebear-BeVf03hx.js} +1 -1
  8. package/dist/gateway/static/root/assets/{agents-bnkKH9EI.js → agents-P05C4A-3.js} +1 -1
  9. package/dist/gateway/static/root/assets/{app-management-settings-panel-CZxw161D.js → app-management-settings-panel-BG2ulMYw.js} +1 -1
  10. package/dist/gateway/static/root/assets/{appearance-settings-CRXNlDhH.js → appearance-settings-0Kjenr2T.js} +1 -1
  11. package/dist/gateway/static/root/assets/{apps-page-l4ripRNG.js → apps-page-DANGrBpN.js} +1 -1
  12. package/dist/gateway/static/root/assets/{archive-plugin-CpVshjXu.js → archive-plugin-ChiNnH1e.js} +1 -1
  13. package/dist/gateway/static/root/assets/{attachment-load-M9WqqJnQ.js → attachment-load-pbBlQR-g.js} +1 -1
  14. package/dist/gateway/static/root/assets/{automation-suggestion-card-CYMsAsYf.js → automation-suggestion-card-CTZDOyDy.js} +1 -1
  15. package/dist/gateway/static/root/assets/{automations-page-Kny7tLiF.js → automations-page-BXfGL_cm.js} +1 -1
  16. package/dist/gateway/static/root/assets/{binary-plugins-Cjn3zb4u.js → binary-plugins-BeZGzpGF.js} +1 -1
  17. package/dist/gateway/static/root/assets/{block-editor-BPKdquaV.js → block-editor-BnDmhN5Z.js} +1 -1
  18. package/dist/gateway/static/root/assets/{browser-settings-page-vr1tXAab.js → browser-settings-page-534luV0B.js} +1 -1
  19. package/dist/gateway/static/root/assets/{capability-presets-api-Bzkcsyzn.js → capability-presets-api-Ii36j_7v.js} +1 -1
  20. package/dist/gateway/static/root/assets/{capability-presets-settings-panel-D4rH4Dax.js → capability-presets-settings-panel-Cl3dw4yh.js} +1 -1
  21. package/dist/gateway/static/root/assets/{channels-settings-Tlhbi5eh.js → channels-settings-M91zFJVi.js} +1 -1
  22. package/dist/gateway/static/root/assets/{connector-logo-ljPKdYKh.js → connector-logo-CiLxuZ8S.js} +1 -1
  23. package/dist/gateway/static/root/assets/{connectors-page-_XfvjXoY.js → connectors-page-CV5UulW6.js} +1 -1
  24. package/dist/gateway/static/root/assets/{desktop-pet-DKUlAgm7.js → desktop-pet-Cil2eSpW.js} +1 -1
  25. package/dist/gateway/static/root/assets/{desktop-pet-settings-aWWzjdza.js → desktop-pet-settings-DwsC6l5F.js} +1 -1
  26. package/dist/gateway/static/root/assets/{directory-picker-path-field-Dmy1035j.js → directory-picker-path-field-CC2VL5Mc.js} +1 -1
  27. package/dist/gateway/static/root/assets/{dreaming-settings-tT4WkBkd.js → dreaming-settings-KY7ZfVsy.js} +1 -1
  28. package/dist/gateway/static/root/assets/{extension-debug-page-CL79q8AH.js → extension-debug-page-C8KBeucs.js} +1 -1
  29. package/dist/gateway/static/root/assets/{extension-page-hq80wkFI.js → extension-page-CV-5Kcyk.js} +1 -1
  30. package/dist/gateway/static/root/assets/{extension-settings-page-BV-9GDfT.js → extension-settings-page-DvUtDrAu.js} +1 -1
  31. package/dist/gateway/static/root/assets/{gateway-config-api-CFqoN2NW.js → gateway-config-api-DXfVeJLc.js} +1 -1
  32. package/dist/gateway/static/root/assets/{gateway-settings-DzR-kM91.js → gateway-settings-BpJ0v56l.js} +1 -1
  33. package/dist/gateway/static/root/assets/{goal-create-dialog-BLjHRtqe.js → goal-create-dialog-lMHD-2CX.js} +1 -1
  34. package/dist/gateway/static/root/assets/{goal-detail-page-BRxeujXh.js → goal-detail-page-yPmF-G7b.js} +1 -1
  35. package/dist/gateway/static/root/assets/{goals-config-api--qJ4qlRq.js → goals-config-api-P8VhLqYF.js} +1 -1
  36. package/dist/gateway/static/root/assets/{goals-page-BaZ3aw4u.js → goals-page-BHTCKobG.js} +1 -1
  37. package/dist/gateway/static/root/assets/{goals-settings-h7x9h5lb.js → goals-settings-DHXyaH_O.js} +1 -1
  38. package/dist/gateway/static/root/assets/{heartbeat-settings-71IhhM3s.js → heartbeat-settings-CNckP_Dv.js} +1 -1
  39. package/dist/gateway/static/root/assets/index-BgZhEOkN.css +1 -0
  40. package/dist/gateway/static/root/assets/{index-EXa_i6BT.js → index-BuqGh2SW.js} +65 -65
  41. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BZGmHvLu.js → keyboard-shortcuts-settings-jXmv1RVX.js} +1 -1
  42. package/dist/gateway/static/root/assets/{local-app-workbench-page-lUpd6lSo.js → local-app-workbench-page-zpp_wciE.js} +1 -1
  43. package/dist/gateway/static/root/assets/{local-apps-page-CiLqrMIh.js → local-apps-page-Cs5LKjtc.js} +1 -1
  44. package/dist/gateway/static/root/assets/{logs-page-FPDTmcWe.js → logs-page-B4CRYqYR.js} +1 -1
  45. package/dist/gateway/static/root/assets/{markdown-split-r1HPWfCU.js → markdown-split-BFqeSNte.js} +1 -1
  46. package/dist/gateway/static/root/assets/{media-plugins-D74kd3hn.js → media-plugins-Cc8379gq.js} +1 -1
  47. package/dist/gateway/static/root/assets/{models-hub-panel-BXrdePhv.js → models-hub-panel-1hdoAoB_.js} +1 -1
  48. package/dist/gateway/static/root/assets/{notes-page-Dgu02514.js → notes-page-DlGU4ipo.js} +1 -1
  49. package/dist/gateway/static/root/assets/{notes-workbench-D-EAhXv1.js → notes-workbench-DQEAZTA5.js} +2 -2
  50. package/dist/gateway/static/root/assets/{page-tabs-hinRdDy3.js → page-tabs-kFOswGlG.js} +1 -1
  51. package/dist/gateway/static/root/assets/{preview-open-alternatives-C7fw3oGy.js → preview-open-alternatives-CvjuvABg.js} +1 -1
  52. package/dist/gateway/static/root/assets/{project-detail-page-BjpB1wrp.js → project-detail-page-Bp9bC7A6.js} +1 -1
  53. package/dist/gateway/static/root/assets/{projects-page-BxyjqOfC.js → projects-page-RNorFXTw.js} +1 -1
  54. package/dist/gateway/static/root/assets/{remote-access-hub-BFv6Upke.js → remote-access-hub-BqRTcM_6.js} +1 -1
  55. package/dist/gateway/static/root/assets/{save-bar-controls-C3aU8-vO.js → save-bar-controls-DwrD7ODx.js} +1 -1
  56. package/dist/gateway/static/root/assets/{schedule-field-DjegExFD.js → schedule-field-Ba4WzTmE.js} +1 -1
  57. package/dist/gateway/static/root/assets/{schema-form-DLubnsql.js → schema-form-DvydL8eF.js} +1 -1
  58. package/dist/gateway/static/root/assets/{sessions-page-BX4DH8J7.js → sessions-page-B2EfW1cm.js} +1 -1
  59. package/dist/gateway/static/root/assets/settings-advanced-gate-CklL85T4.js +1 -0
  60. package/dist/gateway/static/root/assets/{settings-collapsible-section-3syQHsNR.js → settings-collapsible-section-LaQqGGej.js} +1 -1
  61. package/dist/gateway/static/root/assets/{settings-form-section-D4DCZzKg.js → settings-form-section-DruI__qO.js} +1 -1
  62. package/dist/gateway/static/root/assets/{settings-loading-skeleton-c5K85ylS.js → settings-loading-skeleton-UvA-eDhF.js} +1 -1
  63. package/dist/gateway/static/root/assets/{settings-page-DNiDlaRq.js → settings-page-5oCGSebm.js} +1 -1
  64. package/dist/gateway/static/root/assets/{settings-page-layout-iTRY1Hy-.js → settings-page-layout-DG-XMIPu.js} +1 -1
  65. package/dist/gateway/static/root/assets/{setup-status-panel-BH4xQKM9.js → setup-status-panel-D3my1HgB.js} +1 -1
  66. package/dist/gateway/static/root/assets/{share-preview-page-B88Afrhe.js → share-preview-page-FLVeTrRt.js} +1 -1
  67. package/dist/gateway/static/root/assets/{shares-settings-B6kKkvOb.js → shares-settings-DVxgjrsP.js} +1 -1
  68. package/dist/gateway/static/root/assets/{skill-reload-api-DtjS-nUK.js → skill-reload-api-Bcu58ZaF.js} +1 -1
  69. package/dist/gateway/static/root/assets/{skills-page-CQEoPv0u.js → skills-page-CDd-84FE.js} +1 -1
  70. package/dist/gateway/static/root/assets/{system-settings-panel-DtpTq837.js → system-settings-panel-CeK93xVi.js} +1 -1
  71. package/dist/gateway/static/root/assets/{typed-models-lib-ndEnUP3b.js → typed-models-lib-D1Lr2gG0.js} +1 -1
  72. package/dist/gateway/static/root/assets/{user-context-page-Dn2T3itn.js → user-context-page-1OyJnTyR.js} +1 -1
  73. package/dist/gateway/static/root/assets/{voice-api-key-field-wtWc3SfN.js → voice-api-key-field-B2ncRwHS.js} +1 -1
  74. package/dist/gateway/static/root/assets/{work-discovery-page-Ckxhj66e.js → work-discovery-page-BZlY4PZL.js} +1 -1
  75. package/dist/gateway/static/root/assets/{work-item-detail-page-_1QgGPNw.js → work-item-detail-page-DPXMrneY.js} +1 -1
  76. package/dist/gateway/static/root/assets/{work-page-BPdf2iuv.js → work-page-CTERoqyv.js} +1 -1
  77. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-ukmpkj66.js → workflow-run-setup-panel-Bynqe4kV.js} +1 -1
  78. package/dist/gateway/static/root/assets/{workflows-page-DdKTx0Hs.js → workflows-page-CLgsnqFQ.js} +1 -1
  79. package/dist/gateway/static/root/index.html +2 -2
  80. package/dist/package.js +1 -1
  81. package/dist/src/agent/embedded/session-tool-result-guard.js +14 -0
  82. package/dist/src/agent/image/generation/openai-compatible-image-provider.js +1 -1
  83. package/dist/src/agent/service/process-direct-streaming.js +1 -1
  84. package/dist/src/agent/tools/image-generate-tool.js +10 -3
  85. package/dist/src/agent/tools/send-media.js +20 -70
  86. package/dist/src/agent/tools/tool-media.d.ts +9 -0
  87. package/dist/src/agent/tools/tool-media.js +58 -0
  88. package/dist/src/config/agent-profile.js +1 -1
  89. package/dist/src/gateway/agent-run-relay.d.ts +2 -0
  90. package/dist/src/gateway/agent-run-relay.js +114 -14
  91. package/dist/src/gateway/agents-admin.js +1 -1
  92. package/dist/src/gateway/chat-stream/mapper.d.ts +1 -1
  93. package/dist/src/gateway/chat-stream/mapper.js +27 -42
  94. package/dist/src/gateway/chat-stream/thinking-delta-coalescer.d.ts +7 -0
  95. package/dist/src/gateway/chat-stream/thinking-delta-coalescer.js +103 -0
  96. package/dist/src/gateway/hono/sse.d.ts +1 -1
  97. package/dist/src/gateway/hono/sse.js +1 -1
  98. package/dist/src/gateway/service/run-gateway-agent.js +5 -1
  99. package/dist/src/media/session-references.js +9 -6
  100. package/dist/src/session/client-history.d.ts +1 -0
  101. package/dist/src/session/client-history.js +56 -12
  102. package/dist/src/session/types.d.ts +1 -0
  103. package/package.json +1 -1
  104. package/dist/gateway/static/root/assets/index-gpwk8Nro.css +0 -1
  105. package/dist/gateway/static/root/assets/settings-advanced-gate-CJ9MbRP8.js +0 -1
@@ -1,4 +1,4 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,t as a}from"./chunk-KS7C4IRE-uQ0fehio.js";import{t as o}from"./cn-BQ_8x0bT.js";import{t as s}from"./circle-alert-RzVebuX2.js";import{t as c}from"./messages-BuT0SR1R.js";import{n as l}from"./locale-store-C_M71MK9.js";import{i as u}from"./vendor-swr-BIWyz7Rc.js";import{Ao as d,Cc as f,Ci as p,Di as m,Fo as h,Go as g,Gs as _,Ic as v,Io as y,No as b,Ol as x,Po as S,Ql as C,Ro as w,Si as T,Ti as E,Vc as D,Xl as ee,Yi as O,Ys as te,_c as k,_s as A,ao as j,bu as ne,cc as M,eu as re,hc as ie,jo as ae,js as N,ko as oe,ml as se,ms as P,qo as F,sa as ce,to as le,tu as ue,vs as de,wi as fe,x as I,xc as L,yt as pe,zr as R}from"./index-EXa_i6BT.js";import{t as z}from"./format-cron-label-arqgGlVV.js";import{a as me,i as he,n as B,r as V,t as ge}from"./workflow-run-setup-panel-ukmpkj66.js";var H=e(t(),1),U=n(),W=1e3,G=60*W,K=60*G,_e=24*K,ve=7*_e,ye=new Intl.ListFormat(`en-US`,{type:`conjunction`}),q=Object.fromEntries([`second`,`minute`,`hour`,`day`,`week`].map(e=>[e,new Intl.NumberFormat(`en-US`,{style:`unit`,unit:e,unitDisplay:`long`})])),be={en:new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),zh:new Intl.DateTimeFormat(`zh-CN`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})},xe={en:new Intl.DateTimeFormat(`en-US`,{hour:`2-digit`,minute:`2-digit`}),zh:new Intl.DateTimeFormat(`zh-CN`,{hour:`2-digit`,minute:`2-digit`})},Se={minute:G,hour:K,day:_e,week:ve};function J(e){return e===`zh`?`zh-CN`:`en-US`}function Ce(e,t,n){return n===`zh`?`${e} ${t===`week`?`周`:t===`day`?`天`:t===`hour`?`小时`:t===`minute`?`分钟`:`秒`}`:q[String(t)].format(e)}function we(e,t){return t===`zh`?e.join(` `):ye.format(e)}function Te(e,t){let n=typeof e==`number`?e:Number.parseFloat(e);return Math.max(G,Math.round((Number.isFinite(n)&&n>0?n:1)*Se[t]))}function Ee(e,t,n){let r=typeof e==`number`?e:Number.parseFloat(e),i=Number.isFinite(r)&&r>0?r:1;return String(Number.parseFloat((i*Se[t]/Se[n]).toFixed(6)))}function De(e,t){let n=Math.max(W,Math.round(e)),r=n===_e?[{unit:`hour`,ms:K}]:n>=ve&&n%ve===0?[{unit:`week`,ms:ve}]:n>=_e?[{unit:`day`,ms:_e},{unit:`hour`,ms:K},{unit:`minute`,ms:G},{unit:`second`,ms:W}]:n>=K?[{unit:`hour`,ms:K},{unit:`minute`,ms:G},{unit:`second`,ms:W}]:n>=G?[{unit:`minute`,ms:G},{unit:`second`,ms:W}]:[{unit:`second`,ms:W}],i=n,a=[];for(let{unit:e,ms:n}of r){let r=Math.floor(i/n);r<=0||(a.push(Ce(r,e,t)),i%=n)}return we(a,t)}function Oe(e,t){let n=De(e,t);return t===`zh`?`每 ${n}运行一次`:`Runs every ${n}`}function ke(e,t){return be[t].format(new Date(e))}function Ae(e){return Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())}function Y(e,t,n=Date.now()){let r=new Date(e),i=Math.round((Ae(r)-Ae(new Date(n)))/_e),a=xe[t].format(r);return i===0?t===`zh`?`今天 ${a}`:`today at ${a}`:i===1?t===`zh`?`明天 ${a}`:`tomorrow at ${a}`:i===-1?t===`zh`?`昨天 ${a}`:`yesterday at ${a}`:ke(e,t)}function je(e,t){return e.eventType===`goal.status_changed`&&e.payloadMatch?.status===`blocked`?t.trigger.goalBlockedWhen:e.eventType===`note.created`?t.trigger.noteCreatedWhen:e.eventType===`workflow.run.completed`&&e.payloadMatch?.status===`failed`?t.trigger.workflowFailedWhen:e.eventType===`session.transcript.updated`?t.trigger.sessionUpdatedWhen:t.trigger.eventWithType.replace(`{type}`,e.eventType)}function Me(e,t,n,r){if(e.kind===`manual`)return t.trigger.manualWhen;if(e.kind===`webhook`)return t.trigger.webhookWhen;if(e.kind===`event`)return je(e,t);let i=e.schedule;return i.kind===`once`?t.trigger.onceAt.replace(`{time}`,Y(Date.parse(i.at),r)):i.kind===`interval`?Oe(i.everyMs,r):z(i.expr,J(r),n.scheduleBadge,{timezone:i.tz})}function X(e,t,n,r=Date.now()){return e.enabled?e.state.nextRunAtMs?Y(e.state.nextRunAtMs,n,r):e.trigger.kind===`manual`?t.info.noAutomaticTrigger:e.trigger.kind===`event`||e.trigger.kind===`webhook`?t.info.waitingForTrigger:t.info.noUpcomingRun:t.info.pausedNoAutomaticRuns}function Ne(e,t,n,r=Date.now()){if(!e.state.lastRunAtMs)return t.info.notRunYet;let i=Y(e.state.lastRunAtMs,n,r),a=e.state.lastRunStatus;return a?`${i} · ${t.status[a]}`:i}var Pe={name:``,description:``,triggerMode:`daily`,time:`09:00`,weekday:`1`,intervalValue:`1`,intervalUnit:`hour`,cronExpr:`0 9 * * *`,webhookSecretId:``,onceAt:``,eventType:``,eventSource:``,eventPayloadMatch:``,actionMode:`agent`,agentId:``,instruction:``,workflowId:``,workflowGoal:``,workflowInput:{goal:``,argValues:{},schemaInput:{},concurrency:``,maxSubagents:``},workflowInputValid:!0,safetyMode:`suggest_only`,timeoutSeconds:`300`,afterRunMode:`none`,webhookUrl:``,disableAfterFailures:`3`},Fe=[{value:`15`,unit:`minute`},{value:`30`,unit:`minute`},{value:`1`,unit:`hour`},{value:`6`,unit:`hour`},{value:`24`,unit:`hour`}];function Ie(e,t){let[n,r]=e.time.split(`:`),i=Number.parseInt(n||`9`,10),a=Number.parseInt(r||`0`,10),o;if(e.triggerMode===`manual`)o={kind:`manual`};else if(e.triggerMode===`once`)o={kind:`schedule`,schedule:{kind:`once`,at:new Date(e.onceAt).toISOString()}};else if(e.triggerMode===`webhook`)o={kind:`webhook`,...e.webhookSecretId.trim()?{secretId:e.webhookSecretId.trim()}:{}};else if(e.triggerMode===`goalBlocked`)o={kind:`event`,eventType:`goal.status_changed`,source:`goals`,payloadMatch:{status:`blocked`}};else if(e.triggerMode===`noteCreated`)o={kind:`event`,eventType:`note.created`,source:`notes`};else if(e.triggerMode===`workflowFailed`)o={kind:`event`,eventType:`workflow.run.completed`,source:`workflows`,payloadMatch:{status:`failed`}};else if(e.triggerMode===`sessionUpdated`)o={kind:`event`,eventType:`session.transcript.updated`,source:`sessions`};else if(e.triggerMode===`event`){let t=e.eventPayloadMatch.trim()?JSON.parse(e.eventPayloadMatch):void 0;o={kind:`event`,eventType:e.eventType.trim(),...e.eventSource.trim()?{source:e.eventSource.trim()}:{},...t?{payloadMatch:t}:{}}}else o=e.triggerMode===`interval`?{kind:`schedule`,schedule:{kind:`interval`,everyMs:Te(e.intervalValue,e.intervalUnit)}}:e.triggerMode===`weekly`?{kind:`schedule`,schedule:{kind:`cron`,expr:`${a} ${i} * * ${e.weekday}`}}:e.triggerMode===`cron`?{kind:`schedule`,schedule:{kind:`cron`,expr:e.cronExpr.trim()}}:{kind:`schedule`,schedule:{kind:`cron`,expr:`${a} ${i} * * *`}};let s=V(t,e.workflowInput),c=e.workflowInput.goal.trim()||e.workflowGoal.trim(),l=e.safetyMode===`auto_apply`?e.afterRunMode:`none`,u=e.actionMode===`workflow`?{kind:`workflow`,workflowId:e.workflowId.trim(),...e.agentId.trim()?{agentId:e.agentId.trim()}:{},...s===void 0?{}:{input:s},...c?{goal:c}:{},...e.workflowInput.concurrency.trim()?{concurrency:Math.max(1,Number.parseInt(e.workflowInput.concurrency,10)||1)}:{},...e.workflowInput.maxSubagents.trim()?{maxSubagents:Math.max(1,Number.parseInt(e.workflowInput.maxSubagents,10)||1)}:{},timeoutSeconds:Math.max(1,Number.parseInt(e.timeoutSeconds,10)||300)}:{kind:`agent`,instruction:e.instruction.trim(),...e.agentId.trim()?{agentId:e.agentId.trim()}:{},timeoutSeconds:Math.max(1,Number.parseInt(e.timeoutSeconds,10)||300)};return{name:e.name.trim(),...e.description.trim()?{description:e.description.trim()}:{},trigger:o,action:u,safety:{mode:e.safetyMode},afterRun:l===`webhook`?{kind:`webhook`,url:e.webhookUrl.trim()}:{kind:l},reliability:{timeoutSeconds:Math.max(1,Number.parseInt(e.timeoutSeconds,10)||300),disableAfterConsecutiveFailures:Math.max(1,Number.parseInt(e.disableAfterFailures,10)||3)}}}function Le(e){let t=e.match(/^(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s+\*$/);if(t)return{triggerMode:`daily`,time:`${t[2].padStart(2,`0`)}:${t[1].padStart(2,`0`)}`,weekday:`1`,cronExpr:e};let n=e.match(/^(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s+([0-6])$/);return n?{triggerMode:`weekly`,time:`${n[2].padStart(2,`0`)}:${n[1].padStart(2,`0`)}`,weekday:n[3],cronExpr:e}:{triggerMode:`cron`,time:Pe.time,weekday:Pe.weekday,cronExpr:e}}function Re(e){let t=[[`week`,10080*6e4],[`day`,1440*6e4],[`hour`,60*6e4],[`minute`,6e4]],[n,r]=t.find(([,t])=>e>=t&&e%t===0)??t.at(-1);return{intervalValue:String(e/r),intervalUnit:n}}function ze(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return e;let n=t.getTimezoneOffset()*6e4;return new Date(t.getTime()-n).toISOString().slice(0,16)}function Be(e){let t=e.payloadMatch;return e.eventType===`goal.status_changed`&&e.source===`goals`&&t?.status===`blocked`?{triggerMode:`goalBlocked`}:e.eventType===`note.created`&&e.source===`notes`&&!t?{triggerMode:`noteCreated`}:e.eventType===`workflow.run.completed`&&e.source===`workflows`&&t?.status===`failed`?{triggerMode:`workflowFailed`}:e.eventType===`session.transcript.updated`&&e.source===`sessions`&&!t?{triggerMode:`sessionUpdated`}:{triggerMode:`event`,eventType:e.eventType,eventSource:e.source??``,eventPayloadMatch:t?JSON.stringify(t,null,2):``}}function Ve(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function He(e){if(!e.trim())return!0;try{let t=JSON.parse(e);return!!t&&typeof t==`object`&&!Array.isArray(t)&&Object.values(t).every(e=>e===null||[`string`,`number`,`boolean`].includes(typeof e))}catch{return!1}}function Ue(e,t=[]){let n={triggerMode:`manual`};if(e.trigger.kind===`webhook`)n={triggerMode:`webhook`,webhookSecretId:e.trigger.secretId??``};else if(e.trigger.kind===`event`)n=Be(e.trigger);else if(e.trigger.kind===`schedule`){let t=e.trigger.schedule;t.kind===`cron`&&(n=Le(t.expr)),t.kind===`interval`&&(n={triggerMode:`interval`,...Re(t.everyMs)}),t.kind===`once`&&(n={triggerMode:`once`,onceAt:ze(t.at)})}let r=e.action,i=r.kind===`workflow`?t.find(e=>e.id===r.workflowId)??null:null,a=r.kind===`workflow`?Ve(r.input):{},o=e.afterRun??{kind:`none`},s=r.timeoutSeconds??e.reliability?.timeoutSeconds??300;return{...Pe,...n,name:e.name,description:e.description??``,actionMode:r.kind,agentId:r.agentId??``,instruction:r.kind===`agent`?r.instruction:``,workflowId:r.kind===`workflow`?r.workflowId:``,workflowGoal:r.kind===`workflow`?r.goal??``:``,workflowInput:{goal:r.kind===`workflow`?r.goal??``:``,argValues:i?B(i.name,a):{},schemaInput:a,concurrency:r.kind===`workflow`&&r.concurrency?String(r.concurrency):``,maxSubagents:r.kind===`workflow`&&r.maxSubagents?String(r.maxSubagents):``},workflowInputValid:!0,safetyMode:e.safety?.mode??`auto_apply`,timeoutSeconds:String(s),afterRunMode:o.kind,webhookUrl:o.kind===`webhook`?o.url:``,disableAfterFailures:String(e.reliability?.disableAfterConsecutiveFailures??3)}}function We(e,t,n){let r=Ie(t,n),i=e.trigger.kind===`schedule`&&r.trigger.kind===`schedule`&&e.trigger.schedule.kind===r.trigger.schedule.kind?{...r.trigger,schedule:{...e.trigger.schedule,...r.trigger.schedule}}:r.trigger,a=r.action;return e.action.kind===`agent`&&r.action.kind===`agent`?a={...e.action,...r.action,agentId:r.action.agentId}:e.action.kind===`workflow`&&r.action.kind===`workflow`&&(a={...e.action,...r.action,agentId:r.action.agentId,input:r.action.input,goal:r.action.goal,concurrency:r.action.concurrency,maxSubagents:r.action.maxSubagents}),{...r,description:t.description.trim(),trigger:i,action:a,reliability:{...e.reliability,...r.reliability}}}var Z=r();function Ge(e,t,n){return e?ke(e,n):t.never}function Ke(e,t){return e.kind===`workflow`?t.action.workflowWithId.replace(`{id}`,e.workflowId):e.agentId?t.action.agentWithId.replace(`{id}`,e.agentId):t.action.agent}function qe(e){return e.safety?.mode??`auto_apply`}function Je(e){return e===`succeeded`?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:e===`failed`||e===`timeout`?`bg-red-500/10 text-red-700 dark:text-red-300`:e===`running`||e===`queued`?`bg-blue-500/10 text-blue-700 dark:text-blue-300`:`bg-surface-hover text-fg-muted`}function Ye(e,t){if(e==null)return t.never;if(e<1e3)return`${e}ms`;let n=Math.round(e/1e3);return n<60?`${n}s`:`${Math.floor(n/60)}m ${n%60}s`}function Xe(e){return e.status===`running`||e.status===`queued`}function Ze(e){return e.status===`failed`||e.status===`timeout`||e.status===`cancelled`}function Qe(e){return(e.description?.match(/\[managed-by=([^\]]+)\]/))?.[1]?.trim()||null}function $e(e){return!!Qe(e)}function et(e){return e.description?.replace(/\s*\[managed-by=[^\]]+\]\s*/g,` `).trim()??``}function tt(e){return Xe(e)?0:Ze(e)?1:e.status===`succeeded`?2:3}function nt(e){return[...e].sort((e,t)=>{let n=tt(e)-tt(t);return n===0?t.createdAtMs-e.createdAtMs:n})}function rt(e){let t=(0,U.c)(5),n;t[0]===e?n=t[1]:(n=()=>typeof window>`u`?!1:window.matchMedia(e).matches,t[0]=e,t[1]=n);let[r,i]=(0,H.useState)(n),a,o;return t[2]===e?(a=t[3],o=t[4]):(a=()=>{if(typeof window>`u`)return;let t=window.matchMedia(e),n=()=>i(t.matches);return n(),t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)},o=[e],t[2]=e,t[3]=a,t[4]=o),(0,H.useEffect)(a,o),r}function it(){let e=(0,U.c)(5),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-2`,children:[(0,Z.jsx)(j,{className:`h-4 w-36`}),(0,Z.jsx)(j,{className:`h-3 w-56 max-w-full`})]}),(0,Z.jsx)(j,{className:`h-7 w-20 rounded-full`})]}),e[0]=t):t=e[0];let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Z.jsxs)(`section`,{className:`rounded-xl bg-surface-panel p-4 shadow-surface`,children:[t,(0,Z.jsx)(`div`,{className:`mt-4 grid gap-2`,children:Array.from({length:6}).map(at)})]}),e[1]=n):n=e[1];let r,i;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Z.jsx)(j,{className:`h-4 w-32`}),i=(0,Z.jsx)(j,{className:`mt-4 h-24 rounded-lg`}),e[2]=r,e[3]=i):(r=e[2],i=e[3]);let a;return e[4]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(`div`,{className:`grid gap-4`,"aria-hidden":`true`,children:(0,Z.jsxs)(`div`,{className:`grid gap-3 xl:grid-cols-[minmax(0,1fr)_26rem]`,children:[n,(0,Z.jsxs)(`section`,{className:`hidden rounded-xl bg-surface-panel p-4 shadow-surface xl:block`,children:[r,i,(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,Z.jsx)(j,{className:`h-12 rounded-lg`}),(0,Z.jsx)(j,{className:`h-12 rounded-lg`}),(0,Z.jsx)(j,{className:`h-12 rounded-lg`})]})]})]})}),e[4]=a):a=e[4],a}function at(e,t){return(0,Z.jsx)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(j,{className:`size-4 rounded-full`}),(0,Z.jsx)(j,{className:`h-4 w-32`}),(0,Z.jsx)(j,{className:`h-5 w-20 rounded-full`})]}),(0,Z.jsx)(j,{className:`mt-3 h-4 w-full`}),(0,Z.jsx)(j,{className:`mt-2 h-4 w-3/5`})]}),(0,Z.jsx)(j,{className:`h-8 w-24 rounded-md`})]})},t)}function ot(){let e=l(e=>e.language),t=c(e),n=t.automations,r=t.cron,a=y(e=>e.setPageHeader),s=y(e=>e.clearPageHeader),[f,g]=i(),_=f.get(`run`)?.trim()??``,v=f.get(`automation`)?.trim()??``,x=f.get(`draft`)?.trim()??``,C=f.get(`action`)?.trim()??``,D=f.get(`projectId`)?.trim()??``,ee=f.get(`autogenerate`)===`1`,O=f.get(`insight`)?.trim()??``,te=(0,H.useRef)(``),k=rt(`(min-width: 1280px)`),[A,j]=(0,H.useState)(`activity`),[ne,M]=(0,H.useState)(!1),[re,N]=(0,H.useState)(`blank`),[se,F]=(0,H.useState)(null),[ue,L]=(0,H.useState)(!1),[R,z]=(0,H.useState)(Pe),[me,B]=(0,H.useState)(null),[V,ge]=(0,H.useState)(null),[U,W]=(0,H.useState)(!1),[G,K]=(0,H.useState)(null),[_e,ve]=(0,H.useState)(``),[ye,q]=(0,H.useState)(null),[be,xe]=(0,H.useState)(!1),[Se,J]=(0,H.useState)(!1),[Ce,we]=(0,H.useState)(null),[Te,Ee]=(0,H.useState)(!1),[De,Oe]=(0,H.useState)(!1),[ke,Ae]=(0,H.useState)(!1),[Y,je]=(0,H.useState)(null),Me=u([`automations`,D],()=>I.list(D?{projectId:D}:void 0),{refreshInterval:15e3}),X=u([`automation-runs`,D],()=>I.runs(50,void 0,D?{projectId:D}:void 0),{refreshInterval:1e4}),Ne=u(`automation-metrics`,()=>I.metrics(),{refreshInterval:15e3}),Fe=u(V?`automation-run-events:${V}`:null,()=>I.runEvents(V),{refreshInterval:5e3}),Le=u(`automation-workflow-definitions`,pe),Re=u(`automation-chat-agents`,le),ze=Me.isLoading&&!Me.data||X.isLoading&&!X.data||Ne.isLoading&&!Ne.data,Be=Me.data?.automations??[],Ve=(0,H.useMemo)(()=>nt(X.data?.runs??[]),[X.data?.runs]),Ke=(0,H.useMemo)(()=>Be.filter(e=>!$e(e)),[Be]),qe=(0,H.useMemo)(()=>Be.filter($e),[Be]),Je=(0,H.useMemo)(()=>new Set(qe.map(e=>e.id)),[qe]),Ye=(0,H.useMemo)(()=>Ve.filter(e=>!Je.has(e.automationId)),[Ve,Je]),Xe=(0,H.useMemo)(()=>{let e;for(let t of Ke){let n=t.state.nextRunAtMs;n&&(e==null||n<e)&&(e=n)}return e},[Ke]),Qe=(0,H.useMemo)(()=>Ve.find(e=>e.id===V)??null,[Ve,V]),et=(0,H.useMemo)(()=>Be.find(e=>e.id===G)??null,[Be,G]),tt=(0,H.useMemo)(()=>Be.find(e=>e.id===se)??null,[Be,se]),at=(0,H.useMemo)(()=>Ve.filter(e=>e.automationId===G),[Ve,G]),ot=Fe.data?.events??[],lt=(0,H.useMemo)(()=>Ye.filter(Ze),[Ye]),ut=Ye[0]??null,pt=(0,H.useMemo)(()=>Le.data??[],[Le.data]),mt=Re.data?.items??[],ht=(0,H.useMemo)(()=>pt.find(e=>e.id===R.workflowId.trim())??null,[R.workflowId,pt]),vt=R.actionMode===`workflow`&&(!R.workflowId.trim()||pt.length>0&&!pt.some(e=>e.id===R.workflowId)),yt=R.actionMode===`workflow`&&ht?!he(ht,R.workflowInput,R.workflowInputValid).valid:!1,bt=!!R.name.trim()&&(R.triggerMode!==`once`||Number.isFinite(new Date(R.onceAt).getTime()))&&(R.triggerMode!==`event`||!!R.eventType.trim()&&He(R.eventPayloadMatch))&&(R.actionMode===`workflow`?!vt&&!yt:!!R.instruction.trim())&&(R.afterRunMode!==`webhook`||!!R.webhookUrl.trim()),xt=(0,H.useMemo)(()=>[{name:n.templates.dailyAgent.name,description:n.templates.dailyAgent.description,form:{...Pe,name:n.templates.dailyAgent.name,instruction:n.templates.dailyAgent.instruction,triggerMode:`daily`}},{name:n.templates.morningWorkflow.name,description:n.templates.morningWorkflow.description,form:{...Pe,name:n.templates.morningWorkflow.formName,actionMode:`workflow`,workflowId:pt[0]?.id??``}},{name:n.templates.webhookAgent.name,description:n.templates.webhookAgent.description,form:{...Pe,name:n.templates.webhookAgent.formName,triggerMode:`webhook`}},{name:n.templates.blockedGoal.name,description:n.templates.blockedGoal.description,form:{...Pe,name:n.templates.blockedGoal.formName,triggerMode:`goalBlocked`,instruction:n.templates.blockedGoal.instruction}},{name:n.templates.noteCreated.name,description:n.templates.noteCreated.description,form:{...Pe,name:n.templates.noteCreated.formName,triggerMode:`noteCreated`,instruction:n.templates.noteCreated.instruction}}],[n,pt]);(0,H.useEffect)(()=>{A!==`activity`||Ye.length===0||V&&Ye.some(e=>e.id===V)||ge(Ye[0].id)},[V,Ye,A]);let St=(0,H.useCallback)(async()=>{await Promise.all([Me.mutate(),X.mutate(),Ne.mutate(),Fe.mutate()])},[Me.mutate,Ne.mutate,Fe.mutate,X.mutate]),Ct=(0,H.useCallback)(e=>{F(null),L(!1),N(e),M(!0),e===`blank`&&z(Pe)},[]),wt=(0,H.useCallback)(e=>{z(Ue(e,pt)),F(e.id),L(!1),K(null),N(`blank`),M(!0)},[pt]),Tt=(0,H.useCallback)(()=>{ye&&(z(Ue(ye.automation,pt)),F(null),L(!0),N(`blank`))},[ye,pt]),Dt=(0,H.useCallback)(async()=>{Ae(!0),B(null);try{await St()}catch(e){let t=e instanceof Error?e.message:String(e);B(t),w({type:`error`,title:n.feedback.actionFailed,message:t})}finally{Ae(!1)}},[n.feedback.actionFailed,St]);(0,H.useEffect)(()=>{_&&(j(`activity`),ge(_),k||W(!0))},[_,k]),(0,H.useEffect)(()=>{if(!v)return;let e=Be.find(e=>e.id===v);e&&(j($e(e)?`system`:`automations`),K(e.id),g(e=>{let t=new URLSearchParams(e);return t.delete(`automation`),t},{replace:!0}))},[v,Be,g]),(0,H.useEffect)(()=>{k&&W(!1)},[k]),(0,H.useEffect)(()=>{C===`create`&&(Ct(`blank`),g(e=>{let t=new URLSearchParams(e);return t.delete(`action`),t},{replace:!0}))},[C,Ct,g]),(0,H.useEffect)(()=>{if(!x)return;let t=`${e}:${ee?`auto`:`seed`}:${x}`;te.current!==t&&(te.current=t,ve(x),q(null),J(!1),N(`draft`),M(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`draft`),t.delete(`autogenerate`),t.delete(`insight`),t},{replace:!0}),ee&&(B(null),xe(!0),I.draft({prompt:x,language:e}).then(e=>{q(e.draft),J(!1),O&&I.completeInsightDraft(O)}).catch(e=>{B(e instanceof Error?e.message:String(e))}).finally(()=>{xe(!1)})))},[ee,x,O,e,g]);let Q=(0,H.useCallback)(e=>{ge(e),k||W(!0),g(t=>{let n=new URLSearchParams(t);return n.set(`run`,e),n},{replace:!0})},[g,k]);(0,H.useEffect)(()=>{we(null),Oe(!1)},[V]);async function $(){if(B(null),bt){if(ue&&ye){je(`draft:edit`);try{let e=Ie(R,ht),{simulation:t}=await I.simulate(e);q({...ye,automation:e,simulation:t}),J(!1),L(!1),N(`draft`)}catch(e){let t=e instanceof Error?e.message:String(e);B(t),w({type:`error`,title:n.feedback.actionFailed,message:t})}finally{je(null)}return}if(tt){let e=tt.id;await Ot(`automation:${e}:edit`,()=>I.update(e,We(tt,R,ht)))&&(M(!1),F(null),K(e));return}try{await I.create({...Ie(R,ht),...D?{projectId:D}:{}}),z(Pe),M(!1),await St()}catch(e){let t=e instanceof Error?e.message:String(e);B(t),w({type:`error`,title:n.feedback.actionFailed,message:t})}}}async function Ot(e,t){B(null),je(e);try{return await t(),await St(),!0}catch(e){let t=e instanceof Error?e.message:String(e);return B(t),w({type:`error`,title:n.feedback.actionFailed,message:t}),!1}finally{je(null)}}async function kt(){let t=_e.trim();if(t){B(null),xe(!0);try{q((await I.draft({prompt:t,language:e})).draft),J(!1)}catch(e){B(e instanceof Error?e.message:String(e))}finally{xe(!1)}}}async function At(){ye&&await Ot(`draft:publish`,async()=>{await I.create({...ye.automation,...D?{projectId:D}:{}}),q(null),ve(``),J(!1),M(!1)})}async function jt(t){B(null),Ee(!0),we(null),Oe(!1);try{we((await I.repairDraft(t.id,{language:e})).repair)}catch(e){B(e instanceof Error?e.message:String(e))}finally{Ee(!1)}}async function Mt(e){Ce&&await Ot(`run:${e.id}:repair`,async()=>{await I.update(e.automationId,Ce.patch),we(null),Oe(!1)})}let Nt=(0,H.useMemo)(()=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ce,{className:`size-9 shrink-0 p-0`,loading:ke,label:n.refresh,onClick:Dt}),(0,Z.jsxs)(E,{children:[(0,Z.jsx)(m,{asChild:!0,children:(0,Z.jsxs)(P,{variant:`primary`,children:[(0,Z.jsx)(ie,{className:`size-4`}),n.new]})}),(0,Z.jsx)(fe,{children:(0,Z.jsxs)(T,{align:`end`,className:`z-70 min-w-52 rounded-lg border border-edge bg-surface-panel p-1 shadow-popover`,children:[(0,Z.jsx)(p,{className:`cursor-pointer rounded-md px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover`,onSelect:()=>Ct(`draft`),children:n.createMenu.draft}),(0,Z.jsx)(p,{className:`cursor-pointer rounded-md px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover`,onSelect:()=>Ct(`template`),children:n.createMenu.template}),(0,Z.jsx)(p,{className:`cursor-pointer rounded-md px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover`,onSelect:()=>Ct(`blank`),children:n.createMenu.blank})]})})]})]}),[n.createMenu.blank,n.createMenu.draft,n.createMenu.template,n.new,n.refresh,Ct,ke,Dt]);return(0,H.useLayoutEffect)(()=>(a({startExtra:null,main:(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:n.title}),(0,Z.jsx)(`p`,{className:`truncate text-xs text-fg-muted`,children:n.subtitle})]}),end:Nt}),()=>s()),[s,Nt,n.subtitle,n.title,a]),(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface-panel`,children:[(0,Z.jsxs)(`div`,{className:`flex w-full flex-col gap-5 px-3 py-6 sm:px-5 xl:px-6`,children:[(0,Z.jsxs)(`section`,{className:`grid gap-3 sm:grid-cols-4`,children:[(0,Z.jsx)(st,{label:n.dashboard.needsAttention,value:lt.length,tone:lt.length>0?`danger`:`neutral`}),(0,Z.jsx)(st,{label:n.metrics.running,value:Ye.filter(e=>e.status===`running`).length}),(0,Z.jsx)(st,{label:n.dashboard.latestResult,value:ut?n.status[ut.status]:n.none,tone:ut&&Ze(ut)?`danger`:`neutral`}),(0,Z.jsx)(st,{label:n.metrics.next,value:Xe?Ge(Xe,n,e):n.none})]}),(0,Z.jsx)(`nav`,{className:`inline-flex w-fit rounded-lg border border-edge bg-surface-panel p-1`,children:[{id:`activity`,label:n.dashboard.activity,count:Ye.length},{id:`automations`,label:n.dashboard.manage,count:Ke.length},{id:`system`,label:n.system.title,count:qe.length}].map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:o(`inline-flex items-center gap-2 rounded-md px-3 py-1.5 text-sm font-medium text-fg-muted`,A===e.id&&`bg-surface-hover text-fg`),onClick:()=>{j(e.id),e.id!==`activity`&&W(!1)},children:[(0,Z.jsx)(`span`,{children:e.label}),(0,Z.jsx)(`span`,{className:`rounded-full border border-edge/70 px-1.5 py-0.5 text-[0.6875rem] leading-none text-fg-muted`,children:e.count})]},e.id))}),me?(0,Z.jsx)(`div`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:me}):null,ze?(0,Z.jsx)(it,{}):A===`activity`?(0,Z.jsxs)(`section`,{className:`grid items-start gap-4 xl:grid-cols-[minmax(18rem,22rem)_minmax(0,1fr)]`,children:[(0,Z.jsx)(`div`,{className:`min-w-0`,children:(0,Z.jsx)(ft,{runs:Ye.slice(0,12),labels:n,cronLabels:r,language:e,selectedRunId:V,busyAction:Y,className:`h-auto`,onSelectRun:Q,onAction:Ot})}),(0,Z.jsx)(gt,{className:`hidden xl:sticky xl:top-4 xl:block`,run:Qe,events:ot,labels:n,cronLabels:r,language:e,loading:Fe.isLoading,repairDraft:Ce,repairLoading:Te,repairApproved:De,busyAction:Y,onRepairApprovedChange:Oe,onSuggestRepair:jt,onApplyRepair:Mt})]}):A===`automations`?(0,Z.jsx)(`section`,{children:(0,Z.jsx)(dt,{automations:Ke,runs:Ye,labels:n,cronLabels:r,language:e,busyAction:Y,onOpenDetails:K,onAction:Ot})}):(0,Z.jsx)(`section`,{children:(0,Z.jsx)(dt,{automations:qe,runs:Ve,labels:n,cronLabels:r,language:e,busyAction:Y,readOnly:!0,onOpenDetails:K,onAction:Ot})})]}),(0,Z.jsx)(oe,{open:ne,onOpenChange:e=>{M(e),e||(F(null),L(!1))},children:(0,Z.jsxs)(S,{children:[(0,Z.jsx)(b,{className:`xopc-dialog-overlay fixed inset-0 z-65 bg-scrim backdrop-blur-[1px]`}),(0,Z.jsxs)(ae,{className:`fixed left-1/2 top-1/2 z-66 flex h-[min(760px,calc(100vh-2rem))] w-[min(100%-2rem,48rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge px-5 py-4`,children:[(0,Z.jsx)(h,{className:`text-base font-semibold text-fg`,children:re===`draft`?n.draft.title:re===`template`?n.createMenu.templatesTitle:tt?n.editTitle:ue?n.draft.editTitle:n.createTitle}),(0,Z.jsx)(d,{asChild:!0,children:(0,Z.jsx)(P,{variant:`ghost`,"aria-label":n.close,children:(0,Z.jsx)(de,{className:`size-4`})})})]}),re===`draft`?(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-5`,children:(0,Z.jsx)(ct,{labels:n,prompt:_e,draft:ye,loading:be,approved:Se,publishBusy:Y===`draft:publish`,onPromptChange:ve,onGenerate:kt,onEdit:Tt,onPublish:At,onApprovedChange:J,onDiscard:()=>{q(null),J(!1)}})}):re===`template`?(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-5`,children:(0,Z.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:xt.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`rounded-lg bg-surface-base p-4 text-left hover:bg-surface-hover`,onClick:()=>{z(e.form),N(`blank`)},children:[(0,Z.jsx)(`div`,{className:`font-medium text-fg`,children:e.name}),(0,Z.jsx)(`div`,{className:`mt-2 text-sm text-fg-muted`,children:e.description})]},e.name))})}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Et,{form:R,labels:n,setForm:z,workflowDefinitions:pt,selectedWorkflow:ht,workflowsLoading:Le.isLoading,agentOptions:mt,agentsLoading:Re.isLoading,language:e}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-edge px-5 py-4`,children:[ue?(0,Z.jsx)(P,{variant:`ghost`,onClick:()=>{L(!1),N(`draft`)},children:n.cancel}):(0,Z.jsx)(d,{asChild:!0,children:(0,Z.jsx)(P,{variant:`ghost`,children:n.cancel})}),(0,Z.jsx)(P,{variant:`primary`,onClick:$,disabled:!bt||Y===`draft:edit`||!!(tt&&Y),children:Y===`draft:edit`||tt&&Y===`automation:${tt.id}:edit`?n.feedback.working:tt||ue?n.save:n.create})]})]})]})]})}),(0,Z.jsx)(_t,{automation:et,runs:at,labels:n,cronLabels:r,language:e,busyAction:Y,onClose:()=>K(null),onSelectRun:e=>{Q(e),K(null)},onEdit:wt,onAction:Ot}),(0,Z.jsx)(oe,{open:!k&&U&&!!Qe,onOpenChange:W,children:(0,Z.jsxs)(S,{children:[(0,Z.jsx)(b,{className:`xopc-dialog-overlay fixed inset-0 z-65 bg-scrim backdrop-blur-[1px]`}),(0,Z.jsxs)(ae,{className:`fixed left-1/2 top-1/2 z-66 flex h-[min(85vh,40rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,Z.jsx)(h,{className:`truncate text-base font-semibold text-fg`,children:Qe?.automationName??n.dashboard.result}),(0,Z.jsx)(d,{asChild:!0,children:(0,Z.jsx)(P,{variant:`ghost`,"aria-label":n.close,children:(0,Z.jsx)(de,{className:`size-4`})})})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Z.jsx)(gt,{className:`rounded-none border-0`,run:Qe,events:ot,labels:n,cronLabels:r,language:e,loading:Fe.isLoading,repairDraft:Ce,repairLoading:Te,repairApproved:De,busyAction:Y,onRepairApprovedChange:Oe,onSuggestRepair:jt,onApplyRepair:Mt})})]})]})})]})}function st(e){let t=(0,U.c)(13),{label:n,value:r,tone:i}=e,a=i===void 0?`neutral`:i,s=a===`danger`&&`bg-red-500/10`,c;t[0]===s?c=t[1]:(c=o(`rounded-lg border border-edge-subtle bg-surface-base px-4 py-3 shadow-surface`,s),t[0]=s,t[1]=c);let l;t[2]===n?l=t[3]:(l=(0,Z.jsx)(`div`,{className:`text-xs font-medium uppercase text-fg-muted`,children:n}),t[2]=n,t[3]=l);let u=a===`danger`?`text-red-700 dark:text-red-300`:`text-fg`,d;t[4]===u?d=t[5]:(d=o(`mt-1 truncate text-lg font-semibold`,u),t[4]=u,t[5]=d);let f;t[6]!==d||t[7]!==r?(f=(0,Z.jsx)(`div`,{className:d,children:r}),t[6]=d,t[7]=r,t[8]=f):f=t[8];let p;return t[9]!==c||t[10]!==l||t[11]!==f?(p=(0,Z.jsxs)(`div`,{className:c,children:[l,f]}),t[9]=c,t[10]=l,t[11]=f,t[12]=p):p=t[12],p}function ct(e){let t=(0,U.c)(49),{labels:n,prompt:r,draft:i,loading:a,approved:o,publishBusy:s,onPromptChange:c,onGenerate:l,onEdit:u,onPublish:d,onApprovedChange:f,onDiscard:p}=e,m=s===void 0?!1:s,h=!!(i&&i.simulation.requiredConfirmations.length>0),g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Z.jsx)(_,{className:`size-4 text-accent`}),t[0]=g):g=t[0];let v;t[1]===n.draft.title?v=t[2]:(v=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[g,n.draft.title]}),t[1]=n.draft.title,t[2]=v);let y;t[3]===n.draft.subtitle?y=t[4]:(y=(0,Z.jsx)(`div`,{className:`mt-1 text-sm text-fg-muted`,children:n.draft.subtitle}),t[3]=n.draft.subtitle,t[4]=y);let b;t[5]!==v||t[6]!==y?(b=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[v,y]}),t[5]=v,t[6]=y,t[7]=b):b=t[7];let x;t[8]!==a||t[9]!==r?(x=a||!r.trim(),t[8]=a,t[9]=r,t[10]=x):x=t[10];let S;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,Z.jsx)(_,{className:`size-4`}),t[11]=S):S=t[11];let C=a?n.draft.generating:n.draft.generate,w;t[12]!==l||t[13]!==x||t[14]!==C?(w=(0,Z.jsxs)(P,{variant:`primary`,onClick:l,disabled:x,children:[S,C]}),t[12]=l,t[13]=x,t[14]=C,t[15]=w):w=t[15];let T;t[16]!==b||t[17]!==w?(T=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[b,w]}),t[16]=b,t[17]=w,t[18]=T):T=t[18];let E;t[19]===c?E=t[20]:(E=e=>c(e.target.value),t[19]=c,t[20]=E);let D;t[21]!==n.draft.placeholder||t[22]!==r||t[23]!==E?(D=(0,Z.jsx)(`textarea`,{className:`mt-4 min-h-20 w-full resize-y rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg outline-none focus:border-accent`,value:r,onChange:E,placeholder:n.draft.placeholder}),t[21]=n.draft.placeholder,t[22]=r,t[23]=E,t[24]=D):D=t[24];let ee;t[25]!==o||t[26]!==i||t[27]!==n.draft.approval||t[28]!==n.draft.assumptions||t[29]!==n.draft.discard||t[30]!==n.draft.edit||t[31]!==n.draft.publish||t[32]!==n.draft.review||t[33]!==n.draft.risks||t[34]!==n.draft.safety||t[35]!==n.feedback||t[36]!==n.info||t[37]!==n.none||t[38]!==f||t[39]!==p||t[40]!==u||t[41]!==d||t[42]!==m||t[43]!==h?(ee=i?(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-3 rounded-lg bg-surface-base p-4 lg:grid-cols-[1fr_1fr]`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:i.automation.name}),i.automation.description?(0,Z.jsx)(`div`,{className:`mt-1 text-sm text-fg-muted`,children:i.automation.description}):null,(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2 text-sm`,children:[(0,Z.jsx)(wt,{label:n.info.when,value:i.simulation.triggerSummary}),(0,Z.jsx)(wt,{label:n.info.run,value:i.simulation.actionSummary})]})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold uppercase text-fg-muted`,children:n.draft.review}),(0,Z.jsx)(lt,{title:n.draft.safety,items:[...i.simulation.safetyNotes,...i.simulation.requiredConfirmations],empty:n.none}),(0,Z.jsx)(lt,{title:n.draft.assumptions,items:i.assumptions,empty:n.none}),(0,Z.jsx)(lt,{title:n.draft.risks,items:i.risks,empty:n.none}),h?(0,Z.jsxs)(`label`,{className:`mt-4 flex items-start gap-2 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{className:`mt-1`,type:`checkbox`,checked:o,onChange:e=>f(e.target.checked)}),(0,Z.jsx)(`span`,{children:n.draft.approval})]}):null,(0,Z.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,Z.jsx)(P,{variant:`ghost`,onClick:p,children:n.draft.discard}),(0,Z.jsxs)(P,{variant:`secondary`,onClick:u,children:[(0,Z.jsx)(L,{className:`size-4`}),n.draft.edit]}),(0,Z.jsx)(P,{variant:`primary`,onClick:d,disabled:m||h&&!o,children:m?n.feedback.working:n.draft.publish})]})]})]}):null,t[25]=o,t[26]=i,t[27]=n.draft.approval,t[28]=n.draft.assumptions,t[29]=n.draft.discard,t[30]=n.draft.edit,t[31]=n.draft.publish,t[32]=n.draft.review,t[33]=n.draft.risks,t[34]=n.draft.safety,t[35]=n.feedback,t[36]=n.info,t[37]=n.none,t[38]=f,t[39]=p,t[40]=u,t[41]=d,t[42]=m,t[43]=h,t[44]=ee):ee=t[44];let O;return t[45]!==T||t[46]!==D||t[47]!==ee?(O=(0,Z.jsxs)(`section`,{className:`rounded-lg border border-edge-subtle bg-surface-base p-4 shadow-surface`,children:[T,D,ee]}),t[45]=T,t[46]=D,t[47]=ee,t[48]=O):O=t[48],O}function lt(e){let t=(0,U.c)(10),{title:n,items:r,empty:i}=e,a;t[0]===n?a=t[1]:(a=(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:n}),t[0]=n,t[1]=a);let o;t[2]!==i||t[3]!==r?(o=r.length>0?r.map(ut):(0,Z.jsx)(`li`,{className:`text-fg-muted`,children:i}),t[2]=i,t[3]=r,t[4]=o):o=t[4];let s;t[5]===o?s=t[6]:(s=(0,Z.jsx)(`ul`,{className:`mt-1 space-y-1 text-sm text-fg`,children:o}),t[5]=o,t[6]=s);let c;return t[7]!==a||t[8]!==s?(c=(0,Z.jsxs)(`div`,{className:`mt-3`,children:[a,s]}),t[7]=a,t[8]=s,t[9]=c):c=t[9],c}function ut(e){return(0,Z.jsxs)(`li`,{children:[`- `,e]},e)}function dt(e){let t=(0,U.c)(24),{automations:n,runs:r,labels:i,cronLabels:a,language:s,busyAction:c,readOnly:l,onOpenDetails:u,onAction:d}=e,p=l===void 0?!1:l;if(n.length===0){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(A,{className:`size-5`}),t[0]=e):e=t[0];let n;return t[1]===i.empty.automations?n=t[2]:(n=(0,Z.jsx)(Tt,{icon:e,title:i.empty.automations}),t[1]=i.empty.automations,t[2]=n),n}let m;if(t[3]!==n||t[4]!==c||t[5]!==a||t[6]!==i||t[7]!==s||t[8]!==d||t[9]!==u||t[10]!==p||t[11]!==r){let e;t[13]!==c||t[14]!==a||t[15]!==i||t[16]!==s||t[17]!==d||t[18]!==u||t[19]!==p||t[20]!==r?(e=e=>{let t=et(e),n=r.filter(t=>t.automationId===e.id),l=n.find(Xe),m=n[0],h=c===`automation:${e.id}:run`,g=c===`automation:${e.id}:toggle`,_=c===`automation:${e.id}:delete`;return(0,Z.jsxs)(`article`,{className:`flex min-h-44 cursor-pointer flex-col rounded-lg border border-edge-subtle bg-surface-base p-3.5 shadow-surface outline-none transition-colors hover:bg-surface-hover`,role:`button`,tabIndex:0,onClick:()=>u(e.id),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&u(e.id)},children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium text-fg`,children:e.name}),l?(0,Z.jsx)(`span`,{className:`size-2 shrink-0 rounded-full bg-blue-500`}):null]}),t?(0,Z.jsx)(`div`,{className:`mt-1 line-clamp-2 text-sm text-fg-muted`,children:t}):null]}),(0,Z.jsx)(`span`,{className:o(`shrink-0 rounded-full px-2 py-0.5 text-xs`,e.enabled?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-surface-hover text-fg-muted`),children:e.enabled?i.enabled:i.paused})]}),(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-fg`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-xs font-medium uppercase text-fg-muted`,children:i.info.when}),(0,Z.jsx)(`span`,{className:`truncate`,children:Me(e.trigger,i,a,s)})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-fg-muted`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-xs font-medium uppercase`,children:i.info.run}),(0,Z.jsx)(`span`,{className:`truncate`,children:Ke(e.action,i)})]})]}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Z.jsxs)(`span`,{children:[i.last,`: `,Ge(e.state.lastRunAtMs,i,s)]}),(0,Z.jsxs)(`span`,{children:[i.next,`: `,Ge(e.state.nextRunAtMs,i,s)]}),(0,Z.jsx)(`span`,{className:o(`rounded-full px-2 py-0.5`,Je(e.state.lastRunStatus)),children:e.state.lastRunStatus?i.status[e.state.lastRunStatus]:i.status.notRun}),m?.error?(0,Z.jsx)(`p`,{className:`basis-full line-clamp-1 text-red-700 dark:text-red-300`,children:m.error}):null]}),p?null:(0,Z.jsx)(`div`,{className:`mt-auto flex justify-end pt-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(P,{variant:`ghost`,className:`size-8 rounded-md p-0`,"aria-label":i.dashboard.runNow,disabled:c!==null,onClick:t=>{t.stopPropagation(),d(`automation:${e.id}:run`,()=>I.runNow(e.id),i.feedback.rerunQueued)},children:(0,Z.jsx)(k,{className:o(`size-4`,h&&`animate-pulse`)})}),(0,Z.jsx)(P,{variant:`ghost`,className:`size-8 rounded-md p-0`,"aria-label":e.enabled?i.dashboard.pause:i.dashboard.resume,disabled:c!==null,onClick:t=>{t.stopPropagation(),d(`automation:${e.id}:toggle`,()=>e.enabled?I.pause(e.id):I.resume(e.id),e.enabled?i.feedback.paused:i.dashboard.resumed)},children:g?(0,Z.jsx)(M,{className:`size-4 animate-spin`}):e.enabled?(0,Z.jsx)(f,{className:`size-4`}):(0,Z.jsx)(k,{className:`size-4`})}),(0,Z.jsx)(P,{variant:`ghost`,className:`size-8 rounded-md p-0`,"aria-label":i.dashboard.delete,disabled:c!==null,onClick:t=>{t.stopPropagation(),d(`automation:${e.id}:delete`,()=>I.remove(e.id),i.dashboard.deleted)},children:_?(0,Z.jsx)(M,{className:`size-4 animate-spin`}):(0,Z.jsx)(N,{className:`size-4`})})]})})]},e.id)},t[13]=c,t[14]=a,t[15]=i,t[16]=s,t[17]=d,t[18]=u,t[19]=p,t[20]=r,t[21]=e):e=t[21],m=n.map(e),t[3]=n,t[4]=c,t[5]=a,t[6]=i,t[7]=s,t[8]=d,t[9]=u,t[10]=p,t[11]=r,t[12]=m}else m=t[12];let h;return t[22]===m?h=t[23]:(h=(0,Z.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-3`,children:m}),t[22]=m,t[23]=h),h}function ft(e){let t=(0,U.c)(25),{runs:n,labels:r,cronLabels:i,language:a,selectedRunId:s,busyAction:c,className:l,onSelectRun:u,onAction:d}=e;if(n.length===0){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(ne,{className:`size-5`}),t[0]=e):e=t[0];let n;return t[1]===r.empty.runs?n=t[2]:(n=(0,Z.jsx)(Tt,{icon:e,title:r.empty.runs}),t[1]=r.empty.runs,t[2]=n),n}let f;t[3]===l?f=t[4]:(f=o(`overflow-hidden rounded-lg border border-edge-subtle bg-surface-base shadow-surface`,l),t[3]=l,t[4]=f);let p;if(t[5]!==c||t[6]!==i||t[7]!==r||t[8]!==a||t[9]!==d||t[10]!==u||t[11]!==n||t[12]!==s){let e;t[14]!==c||t[15]!==i||t[16]!==r||t[17]!==a||t[18]!==d||t[19]!==u||t[20]!==s?(e=e=>(0,Z.jsxs)(`div`,{className:o(`grid cursor-pointer gap-3 border-b border-edge p-4 outline-none last:border-b-0 hover:bg-surface-hover md:grid-cols-[1fr_auto]`,s===e.id&&`bg-surface-hover`),role:`button`,tabIndex:0,onClick:()=>u(e.id),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&u(e.id)},children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:e.automationName}),(0,Z.jsx)(`span`,{className:o(`rounded-full px-2 py-0.5 text-xs`,Je(e.status)),children:r.status[e.status]}),e.workflowRunId?(0,Z.jsxs)(`span`,{className:`text-xs text-fg-muted`,children:[r.workflowPrefix,` `,e.workflowRunId.slice(0,8)]}):null]}),(0,Z.jsx)(`div`,{className:o(`mt-1 line-clamp-2 whitespace-pre-line text-sm text-fg-muted`,e.error&&`text-red-700 dark:text-red-300`),children:e.error||e.summary||(Xe(e)?r.runDetail.resultPending:r.runDetail.noResult)}),(0,Z.jsxs)(`div`,{className:`mt-2 text-xs text-fg-muted`,children:[Ge(e.createdAtMs,r,a),` · `,e.manual?r.trigger.manual:Me(e.triggerSnapshot,r,i,a)]})]}),e.status===`running`||e.status===`queued`?(0,Z.jsx)(P,{variant:`ghost`,disabled:c!==null,onClick:t=>{t.stopPropagation(),d(`run:${e.id}:cancel`,()=>I.cancelRun(e.id),r.dashboard.cancelled)},children:c===`run:${e.id}:cancel`?r.feedback.working:r.cancel}):null]},e.id),t[14]=c,t[15]=i,t[16]=r,t[17]=a,t[18]=d,t[19]=u,t[20]=s,t[21]=e):e=t[21],p=n.map(e),t[5]=c,t[6]=i,t[7]=r,t[8]=a,t[9]=d,t[10]=u,t[11]=n,t[12]=s,t[13]=p}else p=t[13];let m;return t[22]!==f||t[23]!==p?(m=(0,Z.jsx)(`div`,{className:f,children:p}),t[22]=f,t[23]=p,t[24]=m):m=t[24],m}function pt(e,t){let n=t.events,r=e.data&&typeof e.data==`object`?e.data:{},i=typeof r.actionKind==`string`?r.actionKind:null,a=typeof r.status==`string`&&r.status in t.status?t.status[r.status]:null;switch(e.type){case`run.queued`:return e.message.toLowerCase().includes(`manual`)?n.manualQueued:e.message.toLowerCase().includes(`scheduled`)?n.scheduledQueued:n.eventQueued;case`run.started`:return n.runStarted;case`action.started`:return i?n.actionStarted.replace(`{kind}`,i):n.actionStartedFallback;case`action.completed`:return i?n.actionCompleted.replace(`{kind}`,i):n.actionCompletedFallback;case`action.failed`:return i?n.actionFailed.replace(`{kind}`,i):n.actionFailedFallback;case`after_run.started`:return n.afterRunStarted;case`after_run.completed`:return n.afterRunCompleted;case`after_run.failed`:return n.afterRunFailed;case`run.completed`:return a?n.runCompleted.replace(`{status}`,a):n.runCompletedFallback;default:return e.message}}function mt(e){let t=(0,U.c)(17),{value:n,labels:r,title:i,defaultExpanded:a}=e,[s,c]=(0,H.useState)(a===void 0?!1:a),l;t[0]===n?l=t[1]:(l=JSON.stringify(n,null,2),t[0]=n,t[1]=l);let u=l,d;t[2]===u?d=t[3]:(d=u.split(`
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,t as a}from"./chunk-KS7C4IRE-uQ0fehio.js";import{t as o}from"./cn-BQ_8x0bT.js";import{t as s}from"./circle-alert-RzVebuX2.js";import{t as c}from"./messages-BuT0SR1R.js";import{n as l}from"./locale-store-C_M71MK9.js";import{i as u}from"./vendor-swr-BIWyz7Rc.js";import{Ao as d,Cc as f,Ci as p,Di as m,Fo as h,Go as g,Gs as _,Ic as v,Io as y,No as b,Ol as x,Po as S,Ql as C,Ro as w,Si as T,Ti as E,Vc as D,Xl as ee,Yi as O,Ys as te,_c as k,_s as A,ao as j,bu as ne,cc as M,eu as re,hc as ie,jo as ae,js as N,ko as oe,ml as se,ms as P,qo as F,sa as ce,to as le,tu as ue,vs as de,wi as fe,x as I,xc as L,yt as pe,zr as R}from"./index-BuqGh2SW.js";import{t as z}from"./format-cron-label-arqgGlVV.js";import{a as me,i as he,n as B,r as V,t as ge}from"./workflow-run-setup-panel-Bynqe4kV.js";var H=e(t(),1),U=n(),W=1e3,G=60*W,K=60*G,_e=24*K,ve=7*_e,ye=new Intl.ListFormat(`en-US`,{type:`conjunction`}),q=Object.fromEntries([`second`,`minute`,`hour`,`day`,`week`].map(e=>[e,new Intl.NumberFormat(`en-US`,{style:`unit`,unit:e,unitDisplay:`long`})])),be={en:new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}),zh:new Intl.DateTimeFormat(`zh-CN`,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})},xe={en:new Intl.DateTimeFormat(`en-US`,{hour:`2-digit`,minute:`2-digit`}),zh:new Intl.DateTimeFormat(`zh-CN`,{hour:`2-digit`,minute:`2-digit`})},Se={minute:G,hour:K,day:_e,week:ve};function J(e){return e===`zh`?`zh-CN`:`en-US`}function Ce(e,t,n){return n===`zh`?`${e} ${t===`week`?`周`:t===`day`?`天`:t===`hour`?`小时`:t===`minute`?`分钟`:`秒`}`:q[String(t)].format(e)}function we(e,t){return t===`zh`?e.join(` `):ye.format(e)}function Te(e,t){let n=typeof e==`number`?e:Number.parseFloat(e);return Math.max(G,Math.round((Number.isFinite(n)&&n>0?n:1)*Se[t]))}function Ee(e,t,n){let r=typeof e==`number`?e:Number.parseFloat(e),i=Number.isFinite(r)&&r>0?r:1;return String(Number.parseFloat((i*Se[t]/Se[n]).toFixed(6)))}function De(e,t){let n=Math.max(W,Math.round(e)),r=n===_e?[{unit:`hour`,ms:K}]:n>=ve&&n%ve===0?[{unit:`week`,ms:ve}]:n>=_e?[{unit:`day`,ms:_e},{unit:`hour`,ms:K},{unit:`minute`,ms:G},{unit:`second`,ms:W}]:n>=K?[{unit:`hour`,ms:K},{unit:`minute`,ms:G},{unit:`second`,ms:W}]:n>=G?[{unit:`minute`,ms:G},{unit:`second`,ms:W}]:[{unit:`second`,ms:W}],i=n,a=[];for(let{unit:e,ms:n}of r){let r=Math.floor(i/n);r<=0||(a.push(Ce(r,e,t)),i%=n)}return we(a,t)}function Oe(e,t){let n=De(e,t);return t===`zh`?`每 ${n}运行一次`:`Runs every ${n}`}function ke(e,t){return be[t].format(new Date(e))}function Ae(e){return Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())}function Y(e,t,n=Date.now()){let r=new Date(e),i=Math.round((Ae(r)-Ae(new Date(n)))/_e),a=xe[t].format(r);return i===0?t===`zh`?`今天 ${a}`:`today at ${a}`:i===1?t===`zh`?`明天 ${a}`:`tomorrow at ${a}`:i===-1?t===`zh`?`昨天 ${a}`:`yesterday at ${a}`:ke(e,t)}function je(e,t){return e.eventType===`goal.status_changed`&&e.payloadMatch?.status===`blocked`?t.trigger.goalBlockedWhen:e.eventType===`note.created`?t.trigger.noteCreatedWhen:e.eventType===`workflow.run.completed`&&e.payloadMatch?.status===`failed`?t.trigger.workflowFailedWhen:e.eventType===`session.transcript.updated`?t.trigger.sessionUpdatedWhen:t.trigger.eventWithType.replace(`{type}`,e.eventType)}function Me(e,t,n,r){if(e.kind===`manual`)return t.trigger.manualWhen;if(e.kind===`webhook`)return t.trigger.webhookWhen;if(e.kind===`event`)return je(e,t);let i=e.schedule;return i.kind===`once`?t.trigger.onceAt.replace(`{time}`,Y(Date.parse(i.at),r)):i.kind===`interval`?Oe(i.everyMs,r):z(i.expr,J(r),n.scheduleBadge,{timezone:i.tz})}function X(e,t,n,r=Date.now()){return e.enabled?e.state.nextRunAtMs?Y(e.state.nextRunAtMs,n,r):e.trigger.kind===`manual`?t.info.noAutomaticTrigger:e.trigger.kind===`event`||e.trigger.kind===`webhook`?t.info.waitingForTrigger:t.info.noUpcomingRun:t.info.pausedNoAutomaticRuns}function Ne(e,t,n,r=Date.now()){if(!e.state.lastRunAtMs)return t.info.notRunYet;let i=Y(e.state.lastRunAtMs,n,r),a=e.state.lastRunStatus;return a?`${i} · ${t.status[a]}`:i}var Pe={name:``,description:``,triggerMode:`daily`,time:`09:00`,weekday:`1`,intervalValue:`1`,intervalUnit:`hour`,cronExpr:`0 9 * * *`,webhookSecretId:``,onceAt:``,eventType:``,eventSource:``,eventPayloadMatch:``,actionMode:`agent`,agentId:``,instruction:``,workflowId:``,workflowGoal:``,workflowInput:{goal:``,argValues:{},schemaInput:{},concurrency:``,maxSubagents:``},workflowInputValid:!0,safetyMode:`suggest_only`,timeoutSeconds:`300`,afterRunMode:`none`,webhookUrl:``,disableAfterFailures:`3`},Fe=[{value:`15`,unit:`minute`},{value:`30`,unit:`minute`},{value:`1`,unit:`hour`},{value:`6`,unit:`hour`},{value:`24`,unit:`hour`}];function Ie(e,t){let[n,r]=e.time.split(`:`),i=Number.parseInt(n||`9`,10),a=Number.parseInt(r||`0`,10),o;if(e.triggerMode===`manual`)o={kind:`manual`};else if(e.triggerMode===`once`)o={kind:`schedule`,schedule:{kind:`once`,at:new Date(e.onceAt).toISOString()}};else if(e.triggerMode===`webhook`)o={kind:`webhook`,...e.webhookSecretId.trim()?{secretId:e.webhookSecretId.trim()}:{}};else if(e.triggerMode===`goalBlocked`)o={kind:`event`,eventType:`goal.status_changed`,source:`goals`,payloadMatch:{status:`blocked`}};else if(e.triggerMode===`noteCreated`)o={kind:`event`,eventType:`note.created`,source:`notes`};else if(e.triggerMode===`workflowFailed`)o={kind:`event`,eventType:`workflow.run.completed`,source:`workflows`,payloadMatch:{status:`failed`}};else if(e.triggerMode===`sessionUpdated`)o={kind:`event`,eventType:`session.transcript.updated`,source:`sessions`};else if(e.triggerMode===`event`){let t=e.eventPayloadMatch.trim()?JSON.parse(e.eventPayloadMatch):void 0;o={kind:`event`,eventType:e.eventType.trim(),...e.eventSource.trim()?{source:e.eventSource.trim()}:{},...t?{payloadMatch:t}:{}}}else o=e.triggerMode===`interval`?{kind:`schedule`,schedule:{kind:`interval`,everyMs:Te(e.intervalValue,e.intervalUnit)}}:e.triggerMode===`weekly`?{kind:`schedule`,schedule:{kind:`cron`,expr:`${a} ${i} * * ${e.weekday}`}}:e.triggerMode===`cron`?{kind:`schedule`,schedule:{kind:`cron`,expr:e.cronExpr.trim()}}:{kind:`schedule`,schedule:{kind:`cron`,expr:`${a} ${i} * * *`}};let s=V(t,e.workflowInput),c=e.workflowInput.goal.trim()||e.workflowGoal.trim(),l=e.safetyMode===`auto_apply`?e.afterRunMode:`none`,u=e.actionMode===`workflow`?{kind:`workflow`,workflowId:e.workflowId.trim(),...e.agentId.trim()?{agentId:e.agentId.trim()}:{},...s===void 0?{}:{input:s},...c?{goal:c}:{},...e.workflowInput.concurrency.trim()?{concurrency:Math.max(1,Number.parseInt(e.workflowInput.concurrency,10)||1)}:{},...e.workflowInput.maxSubagents.trim()?{maxSubagents:Math.max(1,Number.parseInt(e.workflowInput.maxSubagents,10)||1)}:{},timeoutSeconds:Math.max(1,Number.parseInt(e.timeoutSeconds,10)||300)}:{kind:`agent`,instruction:e.instruction.trim(),...e.agentId.trim()?{agentId:e.agentId.trim()}:{},timeoutSeconds:Math.max(1,Number.parseInt(e.timeoutSeconds,10)||300)};return{name:e.name.trim(),...e.description.trim()?{description:e.description.trim()}:{},trigger:o,action:u,safety:{mode:e.safetyMode},afterRun:l===`webhook`?{kind:`webhook`,url:e.webhookUrl.trim()}:{kind:l},reliability:{timeoutSeconds:Math.max(1,Number.parseInt(e.timeoutSeconds,10)||300),disableAfterConsecutiveFailures:Math.max(1,Number.parseInt(e.disableAfterFailures,10)||3)}}}function Le(e){let t=e.match(/^(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s+\*$/);if(t)return{triggerMode:`daily`,time:`${t[2].padStart(2,`0`)}:${t[1].padStart(2,`0`)}`,weekday:`1`,cronExpr:e};let n=e.match(/^(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s+([0-6])$/);return n?{triggerMode:`weekly`,time:`${n[2].padStart(2,`0`)}:${n[1].padStart(2,`0`)}`,weekday:n[3],cronExpr:e}:{triggerMode:`cron`,time:Pe.time,weekday:Pe.weekday,cronExpr:e}}function Re(e){let t=[[`week`,10080*6e4],[`day`,1440*6e4],[`hour`,60*6e4],[`minute`,6e4]],[n,r]=t.find(([,t])=>e>=t&&e%t===0)??t.at(-1);return{intervalValue:String(e/r),intervalUnit:n}}function ze(e){let t=new Date(e);if(Number.isNaN(t.getTime()))return e;let n=t.getTimezoneOffset()*6e4;return new Date(t.getTime()-n).toISOString().slice(0,16)}function Be(e){let t=e.payloadMatch;return e.eventType===`goal.status_changed`&&e.source===`goals`&&t?.status===`blocked`?{triggerMode:`goalBlocked`}:e.eventType===`note.created`&&e.source===`notes`&&!t?{triggerMode:`noteCreated`}:e.eventType===`workflow.run.completed`&&e.source===`workflows`&&t?.status===`failed`?{triggerMode:`workflowFailed`}:e.eventType===`session.transcript.updated`&&e.source===`sessions`&&!t?{triggerMode:`sessionUpdated`}:{triggerMode:`event`,eventType:e.eventType,eventSource:e.source??``,eventPayloadMatch:t?JSON.stringify(t,null,2):``}}function Ve(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function He(e){if(!e.trim())return!0;try{let t=JSON.parse(e);return!!t&&typeof t==`object`&&!Array.isArray(t)&&Object.values(t).every(e=>e===null||[`string`,`number`,`boolean`].includes(typeof e))}catch{return!1}}function Ue(e,t=[]){let n={triggerMode:`manual`};if(e.trigger.kind===`webhook`)n={triggerMode:`webhook`,webhookSecretId:e.trigger.secretId??``};else if(e.trigger.kind===`event`)n=Be(e.trigger);else if(e.trigger.kind===`schedule`){let t=e.trigger.schedule;t.kind===`cron`&&(n=Le(t.expr)),t.kind===`interval`&&(n={triggerMode:`interval`,...Re(t.everyMs)}),t.kind===`once`&&(n={triggerMode:`once`,onceAt:ze(t.at)})}let r=e.action,i=r.kind===`workflow`?t.find(e=>e.id===r.workflowId)??null:null,a=r.kind===`workflow`?Ve(r.input):{},o=e.afterRun??{kind:`none`},s=r.timeoutSeconds??e.reliability?.timeoutSeconds??300;return{...Pe,...n,name:e.name,description:e.description??``,actionMode:r.kind,agentId:r.agentId??``,instruction:r.kind===`agent`?r.instruction:``,workflowId:r.kind===`workflow`?r.workflowId:``,workflowGoal:r.kind===`workflow`?r.goal??``:``,workflowInput:{goal:r.kind===`workflow`?r.goal??``:``,argValues:i?B(i.name,a):{},schemaInput:a,concurrency:r.kind===`workflow`&&r.concurrency?String(r.concurrency):``,maxSubagents:r.kind===`workflow`&&r.maxSubagents?String(r.maxSubagents):``},workflowInputValid:!0,safetyMode:e.safety?.mode??`auto_apply`,timeoutSeconds:String(s),afterRunMode:o.kind,webhookUrl:o.kind===`webhook`?o.url:``,disableAfterFailures:String(e.reliability?.disableAfterConsecutiveFailures??3)}}function We(e,t,n){let r=Ie(t,n),i=e.trigger.kind===`schedule`&&r.trigger.kind===`schedule`&&e.trigger.schedule.kind===r.trigger.schedule.kind?{...r.trigger,schedule:{...e.trigger.schedule,...r.trigger.schedule}}:r.trigger,a=r.action;return e.action.kind===`agent`&&r.action.kind===`agent`?a={...e.action,...r.action,agentId:r.action.agentId}:e.action.kind===`workflow`&&r.action.kind===`workflow`&&(a={...e.action,...r.action,agentId:r.action.agentId,input:r.action.input,goal:r.action.goal,concurrency:r.action.concurrency,maxSubagents:r.action.maxSubagents}),{...r,description:t.description.trim(),trigger:i,action:a,reliability:{...e.reliability,...r.reliability}}}var Z=r();function Ge(e,t,n){return e?ke(e,n):t.never}function Ke(e,t){return e.kind===`workflow`?t.action.workflowWithId.replace(`{id}`,e.workflowId):e.agentId?t.action.agentWithId.replace(`{id}`,e.agentId):t.action.agent}function qe(e){return e.safety?.mode??`auto_apply`}function Je(e){return e===`succeeded`?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:e===`failed`||e===`timeout`?`bg-red-500/10 text-red-700 dark:text-red-300`:e===`running`||e===`queued`?`bg-blue-500/10 text-blue-700 dark:text-blue-300`:`bg-surface-hover text-fg-muted`}function Ye(e,t){if(e==null)return t.never;if(e<1e3)return`${e}ms`;let n=Math.round(e/1e3);return n<60?`${n}s`:`${Math.floor(n/60)}m ${n%60}s`}function Xe(e){return e.status===`running`||e.status===`queued`}function Ze(e){return e.status===`failed`||e.status===`timeout`||e.status===`cancelled`}function Qe(e){return(e.description?.match(/\[managed-by=([^\]]+)\]/))?.[1]?.trim()||null}function $e(e){return!!Qe(e)}function et(e){return e.description?.replace(/\s*\[managed-by=[^\]]+\]\s*/g,` `).trim()??``}function tt(e){return Xe(e)?0:Ze(e)?1:e.status===`succeeded`?2:3}function nt(e){return[...e].sort((e,t)=>{let n=tt(e)-tt(t);return n===0?t.createdAtMs-e.createdAtMs:n})}function rt(e){let t=(0,U.c)(5),n;t[0]===e?n=t[1]:(n=()=>typeof window>`u`?!1:window.matchMedia(e).matches,t[0]=e,t[1]=n);let[r,i]=(0,H.useState)(n),a,o;return t[2]===e?(a=t[3],o=t[4]):(a=()=>{if(typeof window>`u`)return;let t=window.matchMedia(e),n=()=>i(t.matches);return n(),t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)},o=[e],t[2]=e,t[3]=a,t[4]=o),(0,H.useEffect)(a,o),r}function it(){let e=(0,U.c)(5),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 space-y-2`,children:[(0,Z.jsx)(j,{className:`h-4 w-36`}),(0,Z.jsx)(j,{className:`h-3 w-56 max-w-full`})]}),(0,Z.jsx)(j,{className:`h-7 w-20 rounded-full`})]}),e[0]=t):t=e[0];let n;e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,Z.jsxs)(`section`,{className:`rounded-xl bg-surface-panel p-4 shadow-surface`,children:[t,(0,Z.jsx)(`div`,{className:`mt-4 grid gap-2`,children:Array.from({length:6}).map(at)})]}),e[1]=n):n=e[1];let r,i;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Z.jsx)(j,{className:`h-4 w-32`}),i=(0,Z.jsx)(j,{className:`mt-4 h-24 rounded-lg`}),e[2]=r,e[3]=i):(r=e[2],i=e[3]);let a;return e[4]===Symbol.for(`react.memo_cache_sentinel`)?(a=(0,Z.jsx)(`div`,{className:`grid gap-4`,"aria-hidden":`true`,children:(0,Z.jsxs)(`div`,{className:`grid gap-3 xl:grid-cols-[minmax(0,1fr)_26rem]`,children:[n,(0,Z.jsxs)(`section`,{className:`hidden rounded-xl bg-surface-panel p-4 shadow-surface xl:block`,children:[r,i,(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-2`,children:[(0,Z.jsx)(j,{className:`h-12 rounded-lg`}),(0,Z.jsx)(j,{className:`h-12 rounded-lg`}),(0,Z.jsx)(j,{className:`h-12 rounded-lg`})]})]})]})}),e[4]=a):a=e[4],a}function at(e,t){return(0,Z.jsx)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(j,{className:`size-4 rounded-full`}),(0,Z.jsx)(j,{className:`h-4 w-32`}),(0,Z.jsx)(j,{className:`h-5 w-20 rounded-full`})]}),(0,Z.jsx)(j,{className:`mt-3 h-4 w-full`}),(0,Z.jsx)(j,{className:`mt-2 h-4 w-3/5`})]}),(0,Z.jsx)(j,{className:`h-8 w-24 rounded-md`})]})},t)}function ot(){let e=l(e=>e.language),t=c(e),n=t.automations,r=t.cron,a=y(e=>e.setPageHeader),s=y(e=>e.clearPageHeader),[f,g]=i(),_=f.get(`run`)?.trim()??``,v=f.get(`automation`)?.trim()??``,x=f.get(`draft`)?.trim()??``,C=f.get(`action`)?.trim()??``,D=f.get(`projectId`)?.trim()??``,ee=f.get(`autogenerate`)===`1`,O=f.get(`insight`)?.trim()??``,te=(0,H.useRef)(``),k=rt(`(min-width: 1280px)`),[A,j]=(0,H.useState)(`activity`),[ne,M]=(0,H.useState)(!1),[re,N]=(0,H.useState)(`blank`),[se,F]=(0,H.useState)(null),[ue,L]=(0,H.useState)(!1),[R,z]=(0,H.useState)(Pe),[me,B]=(0,H.useState)(null),[V,ge]=(0,H.useState)(null),[U,W]=(0,H.useState)(!1),[G,K]=(0,H.useState)(null),[_e,ve]=(0,H.useState)(``),[ye,q]=(0,H.useState)(null),[be,xe]=(0,H.useState)(!1),[Se,J]=(0,H.useState)(!1),[Ce,we]=(0,H.useState)(null),[Te,Ee]=(0,H.useState)(!1),[De,Oe]=(0,H.useState)(!1),[ke,Ae]=(0,H.useState)(!1),[Y,je]=(0,H.useState)(null),Me=u([`automations`,D],()=>I.list(D?{projectId:D}:void 0),{refreshInterval:15e3}),X=u([`automation-runs`,D],()=>I.runs(50,void 0,D?{projectId:D}:void 0),{refreshInterval:1e4}),Ne=u(`automation-metrics`,()=>I.metrics(),{refreshInterval:15e3}),Fe=u(V?`automation-run-events:${V}`:null,()=>I.runEvents(V),{refreshInterval:5e3}),Le=u(`automation-workflow-definitions`,pe),Re=u(`automation-chat-agents`,le),ze=Me.isLoading&&!Me.data||X.isLoading&&!X.data||Ne.isLoading&&!Ne.data,Be=Me.data?.automations??[],Ve=(0,H.useMemo)(()=>nt(X.data?.runs??[]),[X.data?.runs]),Ke=(0,H.useMemo)(()=>Be.filter(e=>!$e(e)),[Be]),qe=(0,H.useMemo)(()=>Be.filter($e),[Be]),Je=(0,H.useMemo)(()=>new Set(qe.map(e=>e.id)),[qe]),Ye=(0,H.useMemo)(()=>Ve.filter(e=>!Je.has(e.automationId)),[Ve,Je]),Xe=(0,H.useMemo)(()=>{let e;for(let t of Ke){let n=t.state.nextRunAtMs;n&&(e==null||n<e)&&(e=n)}return e},[Ke]),Qe=(0,H.useMemo)(()=>Ve.find(e=>e.id===V)??null,[Ve,V]),et=(0,H.useMemo)(()=>Be.find(e=>e.id===G)??null,[Be,G]),tt=(0,H.useMemo)(()=>Be.find(e=>e.id===se)??null,[Be,se]),at=(0,H.useMemo)(()=>Ve.filter(e=>e.automationId===G),[Ve,G]),ot=Fe.data?.events??[],lt=(0,H.useMemo)(()=>Ye.filter(Ze),[Ye]),ut=Ye[0]??null,pt=(0,H.useMemo)(()=>Le.data??[],[Le.data]),mt=Re.data?.items??[],ht=(0,H.useMemo)(()=>pt.find(e=>e.id===R.workflowId.trim())??null,[R.workflowId,pt]),vt=R.actionMode===`workflow`&&(!R.workflowId.trim()||pt.length>0&&!pt.some(e=>e.id===R.workflowId)),yt=R.actionMode===`workflow`&&ht?!he(ht,R.workflowInput,R.workflowInputValid).valid:!1,bt=!!R.name.trim()&&(R.triggerMode!==`once`||Number.isFinite(new Date(R.onceAt).getTime()))&&(R.triggerMode!==`event`||!!R.eventType.trim()&&He(R.eventPayloadMatch))&&(R.actionMode===`workflow`?!vt&&!yt:!!R.instruction.trim())&&(R.afterRunMode!==`webhook`||!!R.webhookUrl.trim()),xt=(0,H.useMemo)(()=>[{name:n.templates.dailyAgent.name,description:n.templates.dailyAgent.description,form:{...Pe,name:n.templates.dailyAgent.name,instruction:n.templates.dailyAgent.instruction,triggerMode:`daily`}},{name:n.templates.morningWorkflow.name,description:n.templates.morningWorkflow.description,form:{...Pe,name:n.templates.morningWorkflow.formName,actionMode:`workflow`,workflowId:pt[0]?.id??``}},{name:n.templates.webhookAgent.name,description:n.templates.webhookAgent.description,form:{...Pe,name:n.templates.webhookAgent.formName,triggerMode:`webhook`}},{name:n.templates.blockedGoal.name,description:n.templates.blockedGoal.description,form:{...Pe,name:n.templates.blockedGoal.formName,triggerMode:`goalBlocked`,instruction:n.templates.blockedGoal.instruction}},{name:n.templates.noteCreated.name,description:n.templates.noteCreated.description,form:{...Pe,name:n.templates.noteCreated.formName,triggerMode:`noteCreated`,instruction:n.templates.noteCreated.instruction}}],[n,pt]);(0,H.useEffect)(()=>{A!==`activity`||Ye.length===0||V&&Ye.some(e=>e.id===V)||ge(Ye[0].id)},[V,Ye,A]);let St=(0,H.useCallback)(async()=>{await Promise.all([Me.mutate(),X.mutate(),Ne.mutate(),Fe.mutate()])},[Me.mutate,Ne.mutate,Fe.mutate,X.mutate]),Ct=(0,H.useCallback)(e=>{F(null),L(!1),N(e),M(!0),e===`blank`&&z(Pe)},[]),wt=(0,H.useCallback)(e=>{z(Ue(e,pt)),F(e.id),L(!1),K(null),N(`blank`),M(!0)},[pt]),Tt=(0,H.useCallback)(()=>{ye&&(z(Ue(ye.automation,pt)),F(null),L(!0),N(`blank`))},[ye,pt]),Dt=(0,H.useCallback)(async()=>{Ae(!0),B(null);try{await St()}catch(e){let t=e instanceof Error?e.message:String(e);B(t),w({type:`error`,title:n.feedback.actionFailed,message:t})}finally{Ae(!1)}},[n.feedback.actionFailed,St]);(0,H.useEffect)(()=>{_&&(j(`activity`),ge(_),k||W(!0))},[_,k]),(0,H.useEffect)(()=>{if(!v)return;let e=Be.find(e=>e.id===v);e&&(j($e(e)?`system`:`automations`),K(e.id),g(e=>{let t=new URLSearchParams(e);return t.delete(`automation`),t},{replace:!0}))},[v,Be,g]),(0,H.useEffect)(()=>{k&&W(!1)},[k]),(0,H.useEffect)(()=>{C===`create`&&(Ct(`blank`),g(e=>{let t=new URLSearchParams(e);return t.delete(`action`),t},{replace:!0}))},[C,Ct,g]),(0,H.useEffect)(()=>{if(!x)return;let t=`${e}:${ee?`auto`:`seed`}:${x}`;te.current!==t&&(te.current=t,ve(x),q(null),J(!1),N(`draft`),M(!0),g(e=>{let t=new URLSearchParams(e);return t.delete(`draft`),t.delete(`autogenerate`),t.delete(`insight`),t},{replace:!0}),ee&&(B(null),xe(!0),I.draft({prompt:x,language:e}).then(e=>{q(e.draft),J(!1),O&&I.completeInsightDraft(O)}).catch(e=>{B(e instanceof Error?e.message:String(e))}).finally(()=>{xe(!1)})))},[ee,x,O,e,g]);let Q=(0,H.useCallback)(e=>{ge(e),k||W(!0),g(t=>{let n=new URLSearchParams(t);return n.set(`run`,e),n},{replace:!0})},[g,k]);(0,H.useEffect)(()=>{we(null),Oe(!1)},[V]);async function $(){if(B(null),bt){if(ue&&ye){je(`draft:edit`);try{let e=Ie(R,ht),{simulation:t}=await I.simulate(e);q({...ye,automation:e,simulation:t}),J(!1),L(!1),N(`draft`)}catch(e){let t=e instanceof Error?e.message:String(e);B(t),w({type:`error`,title:n.feedback.actionFailed,message:t})}finally{je(null)}return}if(tt){let e=tt.id;await Ot(`automation:${e}:edit`,()=>I.update(e,We(tt,R,ht)))&&(M(!1),F(null),K(e));return}try{await I.create({...Ie(R,ht),...D?{projectId:D}:{}}),z(Pe),M(!1),await St()}catch(e){let t=e instanceof Error?e.message:String(e);B(t),w({type:`error`,title:n.feedback.actionFailed,message:t})}}}async function Ot(e,t){B(null),je(e);try{return await t(),await St(),!0}catch(e){let t=e instanceof Error?e.message:String(e);return B(t),w({type:`error`,title:n.feedback.actionFailed,message:t}),!1}finally{je(null)}}async function kt(){let t=_e.trim();if(t){B(null),xe(!0);try{q((await I.draft({prompt:t,language:e})).draft),J(!1)}catch(e){B(e instanceof Error?e.message:String(e))}finally{xe(!1)}}}async function At(){ye&&await Ot(`draft:publish`,async()=>{await I.create({...ye.automation,...D?{projectId:D}:{}}),q(null),ve(``),J(!1),M(!1)})}async function jt(t){B(null),Ee(!0),we(null),Oe(!1);try{we((await I.repairDraft(t.id,{language:e})).repair)}catch(e){B(e instanceof Error?e.message:String(e))}finally{Ee(!1)}}async function Mt(e){Ce&&await Ot(`run:${e.id}:repair`,async()=>{await I.update(e.automationId,Ce.patch),we(null),Oe(!1)})}let Nt=(0,H.useMemo)(()=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(ce,{className:`size-9 shrink-0 p-0`,loading:ke,label:n.refresh,onClick:Dt}),(0,Z.jsxs)(E,{children:[(0,Z.jsx)(m,{asChild:!0,children:(0,Z.jsxs)(P,{variant:`primary`,children:[(0,Z.jsx)(ie,{className:`size-4`}),n.new]})}),(0,Z.jsx)(fe,{children:(0,Z.jsxs)(T,{align:`end`,className:`z-70 min-w-52 rounded-lg border border-edge bg-surface-panel p-1 shadow-popover`,children:[(0,Z.jsx)(p,{className:`cursor-pointer rounded-md px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover`,onSelect:()=>Ct(`draft`),children:n.createMenu.draft}),(0,Z.jsx)(p,{className:`cursor-pointer rounded-md px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover`,onSelect:()=>Ct(`template`),children:n.createMenu.template}),(0,Z.jsx)(p,{className:`cursor-pointer rounded-md px-3 py-2 text-sm text-fg outline-none hover:bg-surface-hover`,onSelect:()=>Ct(`blank`),children:n.createMenu.blank})]})})]})]}),[n.createMenu.blank,n.createMenu.draft,n.createMenu.template,n.new,n.refresh,Ct,ke,Dt]);return(0,H.useLayoutEffect)(()=>(a({startExtra:null,main:(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:n.title}),(0,Z.jsx)(`p`,{className:`truncate text-xs text-fg-muted`,children:n.subtitle})]}),end:Nt}),()=>s()),[s,Nt,n.subtitle,n.title,a]),(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col bg-surface-panel`,children:[(0,Z.jsxs)(`div`,{className:`flex w-full flex-col gap-5 px-3 py-6 sm:px-5 xl:px-6`,children:[(0,Z.jsxs)(`section`,{className:`grid gap-3 sm:grid-cols-4`,children:[(0,Z.jsx)(st,{label:n.dashboard.needsAttention,value:lt.length,tone:lt.length>0?`danger`:`neutral`}),(0,Z.jsx)(st,{label:n.metrics.running,value:Ye.filter(e=>e.status===`running`).length}),(0,Z.jsx)(st,{label:n.dashboard.latestResult,value:ut?n.status[ut.status]:n.none,tone:ut&&Ze(ut)?`danger`:`neutral`}),(0,Z.jsx)(st,{label:n.metrics.next,value:Xe?Ge(Xe,n,e):n.none})]}),(0,Z.jsx)(`nav`,{className:`inline-flex w-fit rounded-lg border border-edge bg-surface-panel p-1`,children:[{id:`activity`,label:n.dashboard.activity,count:Ye.length},{id:`automations`,label:n.dashboard.manage,count:Ke.length},{id:`system`,label:n.system.title,count:qe.length}].map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:o(`inline-flex items-center gap-2 rounded-md px-3 py-1.5 text-sm font-medium text-fg-muted`,A===e.id&&`bg-surface-hover text-fg`),onClick:()=>{j(e.id),e.id!==`activity`&&W(!1)},children:[(0,Z.jsx)(`span`,{children:e.label}),(0,Z.jsx)(`span`,{className:`rounded-full border border-edge/70 px-1.5 py-0.5 text-[0.6875rem] leading-none text-fg-muted`,children:e.count})]},e.id))}),me?(0,Z.jsx)(`div`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:me}):null,ze?(0,Z.jsx)(it,{}):A===`activity`?(0,Z.jsxs)(`section`,{className:`grid items-start gap-4 xl:grid-cols-[minmax(18rem,22rem)_minmax(0,1fr)]`,children:[(0,Z.jsx)(`div`,{className:`min-w-0`,children:(0,Z.jsx)(ft,{runs:Ye.slice(0,12),labels:n,cronLabels:r,language:e,selectedRunId:V,busyAction:Y,className:`h-auto`,onSelectRun:Q,onAction:Ot})}),(0,Z.jsx)(gt,{className:`hidden xl:sticky xl:top-4 xl:block`,run:Qe,events:ot,labels:n,cronLabels:r,language:e,loading:Fe.isLoading,repairDraft:Ce,repairLoading:Te,repairApproved:De,busyAction:Y,onRepairApprovedChange:Oe,onSuggestRepair:jt,onApplyRepair:Mt})]}):A===`automations`?(0,Z.jsx)(`section`,{children:(0,Z.jsx)(dt,{automations:Ke,runs:Ye,labels:n,cronLabels:r,language:e,busyAction:Y,onOpenDetails:K,onAction:Ot})}):(0,Z.jsx)(`section`,{children:(0,Z.jsx)(dt,{automations:qe,runs:Ve,labels:n,cronLabels:r,language:e,busyAction:Y,readOnly:!0,onOpenDetails:K,onAction:Ot})})]}),(0,Z.jsx)(oe,{open:ne,onOpenChange:e=>{M(e),e||(F(null),L(!1))},children:(0,Z.jsxs)(S,{children:[(0,Z.jsx)(b,{className:`xopc-dialog-overlay fixed inset-0 z-65 bg-scrim backdrop-blur-[1px]`}),(0,Z.jsxs)(ae,{className:`fixed left-1/2 top-1/2 z-66 flex h-[min(760px,calc(100vh-2rem))] w-[min(100%-2rem,48rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge px-5 py-4`,children:[(0,Z.jsx)(h,{className:`text-base font-semibold text-fg`,children:re===`draft`?n.draft.title:re===`template`?n.createMenu.templatesTitle:tt?n.editTitle:ue?n.draft.editTitle:n.createTitle}),(0,Z.jsx)(d,{asChild:!0,children:(0,Z.jsx)(P,{variant:`ghost`,"aria-label":n.close,children:(0,Z.jsx)(de,{className:`size-4`})})})]}),re===`draft`?(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-5`,children:(0,Z.jsx)(ct,{labels:n,prompt:_e,draft:ye,loading:be,approved:Se,publishBusy:Y===`draft:publish`,onPromptChange:ve,onGenerate:kt,onEdit:Tt,onPublish:At,onApprovedChange:J,onDiscard:()=>{q(null),J(!1)}})}):re===`template`?(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-5`,children:(0,Z.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:xt.map(e=>(0,Z.jsxs)(`button`,{type:`button`,className:`rounded-lg bg-surface-base p-4 text-left hover:bg-surface-hover`,onClick:()=>{z(e.form),N(`blank`)},children:[(0,Z.jsx)(`div`,{className:`font-medium text-fg`,children:e.name}),(0,Z.jsx)(`div`,{className:`mt-2 text-sm text-fg-muted`,children:e.description})]},e.name))})}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(Et,{form:R,labels:n,setForm:z,workflowDefinitions:pt,selectedWorkflow:ht,workflowsLoading:Le.isLoading,agentOptions:mt,agentsLoading:Re.isLoading,language:e}),(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2 border-t border-edge px-5 py-4`,children:[ue?(0,Z.jsx)(P,{variant:`ghost`,onClick:()=>{L(!1),N(`draft`)},children:n.cancel}):(0,Z.jsx)(d,{asChild:!0,children:(0,Z.jsx)(P,{variant:`ghost`,children:n.cancel})}),(0,Z.jsx)(P,{variant:`primary`,onClick:$,disabled:!bt||Y===`draft:edit`||!!(tt&&Y),children:Y===`draft:edit`||tt&&Y===`automation:${tt.id}:edit`?n.feedback.working:tt||ue?n.save:n.create})]})]})]})]})}),(0,Z.jsx)(_t,{automation:et,runs:at,labels:n,cronLabels:r,language:e,busyAction:Y,onClose:()=>K(null),onSelectRun:e=>{Q(e),K(null)},onEdit:wt,onAction:Ot}),(0,Z.jsx)(oe,{open:!k&&U&&!!Qe,onOpenChange:W,children:(0,Z.jsxs)(S,{children:[(0,Z.jsx)(b,{className:`xopc-dialog-overlay fixed inset-0 z-65 bg-scrim backdrop-blur-[1px]`}),(0,Z.jsxs)(ae,{className:`fixed left-1/2 top-1/2 z-66 flex h-[min(85vh,40rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,Z.jsx)(h,{className:`truncate text-base font-semibold text-fg`,children:Qe?.automationName??n.dashboard.result}),(0,Z.jsx)(d,{asChild:!0,children:(0,Z.jsx)(P,{variant:`ghost`,"aria-label":n.close,children:(0,Z.jsx)(de,{className:`size-4`})})})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,Z.jsx)(gt,{className:`rounded-none border-0`,run:Qe,events:ot,labels:n,cronLabels:r,language:e,loading:Fe.isLoading,repairDraft:Ce,repairLoading:Te,repairApproved:De,busyAction:Y,onRepairApprovedChange:Oe,onSuggestRepair:jt,onApplyRepair:Mt})})]})]})})]})}function st(e){let t=(0,U.c)(13),{label:n,value:r,tone:i}=e,a=i===void 0?`neutral`:i,s=a===`danger`&&`bg-red-500/10`,c;t[0]===s?c=t[1]:(c=o(`rounded-lg border border-edge-subtle bg-surface-base px-4 py-3 shadow-surface`,s),t[0]=s,t[1]=c);let l;t[2]===n?l=t[3]:(l=(0,Z.jsx)(`div`,{className:`text-xs font-medium uppercase text-fg-muted`,children:n}),t[2]=n,t[3]=l);let u=a===`danger`?`text-red-700 dark:text-red-300`:`text-fg`,d;t[4]===u?d=t[5]:(d=o(`mt-1 truncate text-lg font-semibold`,u),t[4]=u,t[5]=d);let f;t[6]!==d||t[7]!==r?(f=(0,Z.jsx)(`div`,{className:d,children:r}),t[6]=d,t[7]=r,t[8]=f):f=t[8];let p;return t[9]!==c||t[10]!==l||t[11]!==f?(p=(0,Z.jsxs)(`div`,{className:c,children:[l,f]}),t[9]=c,t[10]=l,t[11]=f,t[12]=p):p=t[12],p}function ct(e){let t=(0,U.c)(49),{labels:n,prompt:r,draft:i,loading:a,approved:o,publishBusy:s,onPromptChange:c,onGenerate:l,onEdit:u,onPublish:d,onApprovedChange:f,onDiscard:p}=e,m=s===void 0?!1:s,h=!!(i&&i.simulation.requiredConfirmations.length>0),g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Z.jsx)(_,{className:`size-4 text-accent`}),t[0]=g):g=t[0];let v;t[1]===n.draft.title?v=t[2]:(v=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[g,n.draft.title]}),t[1]=n.draft.title,t[2]=v);let y;t[3]===n.draft.subtitle?y=t[4]:(y=(0,Z.jsx)(`div`,{className:`mt-1 text-sm text-fg-muted`,children:n.draft.subtitle}),t[3]=n.draft.subtitle,t[4]=y);let b;t[5]!==v||t[6]!==y?(b=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[v,y]}),t[5]=v,t[6]=y,t[7]=b):b=t[7];let x;t[8]!==a||t[9]!==r?(x=a||!r.trim(),t[8]=a,t[9]=r,t[10]=x):x=t[10];let S;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,Z.jsx)(_,{className:`size-4`}),t[11]=S):S=t[11];let C=a?n.draft.generating:n.draft.generate,w;t[12]!==l||t[13]!==x||t[14]!==C?(w=(0,Z.jsxs)(P,{variant:`primary`,onClick:l,disabled:x,children:[S,C]}),t[12]=l,t[13]=x,t[14]=C,t[15]=w):w=t[15];let T;t[16]!==b||t[17]!==w?(T=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[b,w]}),t[16]=b,t[17]=w,t[18]=T):T=t[18];let E;t[19]===c?E=t[20]:(E=e=>c(e.target.value),t[19]=c,t[20]=E);let D;t[21]!==n.draft.placeholder||t[22]!==r||t[23]!==E?(D=(0,Z.jsx)(`textarea`,{className:`mt-4 min-h-20 w-full resize-y rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg outline-none focus:border-accent`,value:r,onChange:E,placeholder:n.draft.placeholder}),t[21]=n.draft.placeholder,t[22]=r,t[23]=E,t[24]=D):D=t[24];let ee;t[25]!==o||t[26]!==i||t[27]!==n.draft.approval||t[28]!==n.draft.assumptions||t[29]!==n.draft.discard||t[30]!==n.draft.edit||t[31]!==n.draft.publish||t[32]!==n.draft.review||t[33]!==n.draft.risks||t[34]!==n.draft.safety||t[35]!==n.feedback||t[36]!==n.info||t[37]!==n.none||t[38]!==f||t[39]!==p||t[40]!==u||t[41]!==d||t[42]!==m||t[43]!==h?(ee=i?(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-3 rounded-lg bg-surface-base p-4 lg:grid-cols-[1fr_1fr]`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:i.automation.name}),i.automation.description?(0,Z.jsx)(`div`,{className:`mt-1 text-sm text-fg-muted`,children:i.automation.description}):null,(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2 text-sm`,children:[(0,Z.jsx)(wt,{label:n.info.when,value:i.simulation.triggerSummary}),(0,Z.jsx)(wt,{label:n.info.run,value:i.simulation.actionSummary})]})]}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold uppercase text-fg-muted`,children:n.draft.review}),(0,Z.jsx)(lt,{title:n.draft.safety,items:[...i.simulation.safetyNotes,...i.simulation.requiredConfirmations],empty:n.none}),(0,Z.jsx)(lt,{title:n.draft.assumptions,items:i.assumptions,empty:n.none}),(0,Z.jsx)(lt,{title:n.draft.risks,items:i.risks,empty:n.none}),h?(0,Z.jsxs)(`label`,{className:`mt-4 flex items-start gap-2 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{className:`mt-1`,type:`checkbox`,checked:o,onChange:e=>f(e.target.checked)}),(0,Z.jsx)(`span`,{children:n.draft.approval})]}):null,(0,Z.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,Z.jsx)(P,{variant:`ghost`,onClick:p,children:n.draft.discard}),(0,Z.jsxs)(P,{variant:`secondary`,onClick:u,children:[(0,Z.jsx)(L,{className:`size-4`}),n.draft.edit]}),(0,Z.jsx)(P,{variant:`primary`,onClick:d,disabled:m||h&&!o,children:m?n.feedback.working:n.draft.publish})]})]})]}):null,t[25]=o,t[26]=i,t[27]=n.draft.approval,t[28]=n.draft.assumptions,t[29]=n.draft.discard,t[30]=n.draft.edit,t[31]=n.draft.publish,t[32]=n.draft.review,t[33]=n.draft.risks,t[34]=n.draft.safety,t[35]=n.feedback,t[36]=n.info,t[37]=n.none,t[38]=f,t[39]=p,t[40]=u,t[41]=d,t[42]=m,t[43]=h,t[44]=ee):ee=t[44];let O;return t[45]!==T||t[46]!==D||t[47]!==ee?(O=(0,Z.jsxs)(`section`,{className:`rounded-lg border border-edge-subtle bg-surface-base p-4 shadow-surface`,children:[T,D,ee]}),t[45]=T,t[46]=D,t[47]=ee,t[48]=O):O=t[48],O}function lt(e){let t=(0,U.c)(10),{title:n,items:r,empty:i}=e,a;t[0]===n?a=t[1]:(a=(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:n}),t[0]=n,t[1]=a);let o;t[2]!==i||t[3]!==r?(o=r.length>0?r.map(ut):(0,Z.jsx)(`li`,{className:`text-fg-muted`,children:i}),t[2]=i,t[3]=r,t[4]=o):o=t[4];let s;t[5]===o?s=t[6]:(s=(0,Z.jsx)(`ul`,{className:`mt-1 space-y-1 text-sm text-fg`,children:o}),t[5]=o,t[6]=s);let c;return t[7]!==a||t[8]!==s?(c=(0,Z.jsxs)(`div`,{className:`mt-3`,children:[a,s]}),t[7]=a,t[8]=s,t[9]=c):c=t[9],c}function ut(e){return(0,Z.jsxs)(`li`,{children:[`- `,e]},e)}function dt(e){let t=(0,U.c)(24),{automations:n,runs:r,labels:i,cronLabels:a,language:s,busyAction:c,readOnly:l,onOpenDetails:u,onAction:d}=e,p=l===void 0?!1:l;if(n.length===0){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(A,{className:`size-5`}),t[0]=e):e=t[0];let n;return t[1]===i.empty.automations?n=t[2]:(n=(0,Z.jsx)(Tt,{icon:e,title:i.empty.automations}),t[1]=i.empty.automations,t[2]=n),n}let m;if(t[3]!==n||t[4]!==c||t[5]!==a||t[6]!==i||t[7]!==s||t[8]!==d||t[9]!==u||t[10]!==p||t[11]!==r){let e;t[13]!==c||t[14]!==a||t[15]!==i||t[16]!==s||t[17]!==d||t[18]!==u||t[19]!==p||t[20]!==r?(e=e=>{let t=et(e),n=r.filter(t=>t.automationId===e.id),l=n.find(Xe),m=n[0],h=c===`automation:${e.id}:run`,g=c===`automation:${e.id}:toggle`,_=c===`automation:${e.id}:delete`;return(0,Z.jsxs)(`article`,{className:`flex min-h-44 cursor-pointer flex-col rounded-lg border border-edge-subtle bg-surface-base p-3.5 shadow-surface outline-none transition-colors hover:bg-surface-hover`,role:`button`,tabIndex:0,onClick:()=>u(e.id),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&u(e.id)},children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`truncate font-medium text-fg`,children:e.name}),l?(0,Z.jsx)(`span`,{className:`size-2 shrink-0 rounded-full bg-blue-500`}):null]}),t?(0,Z.jsx)(`div`,{className:`mt-1 line-clamp-2 text-sm text-fg-muted`,children:t}):null]}),(0,Z.jsx)(`span`,{className:o(`shrink-0 rounded-full px-2 py-0.5 text-xs`,e.enabled?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-surface-hover text-fg-muted`),children:e.enabled?i.enabled:i.paused})]}),(0,Z.jsxs)(`div`,{className:`mt-3 space-y-2 text-sm`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-fg`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-xs font-medium uppercase text-fg-muted`,children:i.info.when}),(0,Z.jsx)(`span`,{className:`truncate`,children:Me(e.trigger,i,a,s)})]}),(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-fg-muted`,children:[(0,Z.jsx)(`span`,{className:`shrink-0 text-xs font-medium uppercase`,children:i.info.run}),(0,Z.jsx)(`span`,{className:`truncate`,children:Ke(e.action,i)})]})]}),(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Z.jsxs)(`span`,{children:[i.last,`: `,Ge(e.state.lastRunAtMs,i,s)]}),(0,Z.jsxs)(`span`,{children:[i.next,`: `,Ge(e.state.nextRunAtMs,i,s)]}),(0,Z.jsx)(`span`,{className:o(`rounded-full px-2 py-0.5`,Je(e.state.lastRunStatus)),children:e.state.lastRunStatus?i.status[e.state.lastRunStatus]:i.status.notRun}),m?.error?(0,Z.jsx)(`p`,{className:`basis-full line-clamp-1 text-red-700 dark:text-red-300`,children:m.error}):null]}),p?null:(0,Z.jsx)(`div`,{className:`mt-auto flex justify-end pt-3`,children:(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(P,{variant:`ghost`,className:`size-8 rounded-md p-0`,"aria-label":i.dashboard.runNow,disabled:c!==null,onClick:t=>{t.stopPropagation(),d(`automation:${e.id}:run`,()=>I.runNow(e.id),i.feedback.rerunQueued)},children:(0,Z.jsx)(k,{className:o(`size-4`,h&&`animate-pulse`)})}),(0,Z.jsx)(P,{variant:`ghost`,className:`size-8 rounded-md p-0`,"aria-label":e.enabled?i.dashboard.pause:i.dashboard.resume,disabled:c!==null,onClick:t=>{t.stopPropagation(),d(`automation:${e.id}:toggle`,()=>e.enabled?I.pause(e.id):I.resume(e.id),e.enabled?i.feedback.paused:i.dashboard.resumed)},children:g?(0,Z.jsx)(M,{className:`size-4 animate-spin`}):e.enabled?(0,Z.jsx)(f,{className:`size-4`}):(0,Z.jsx)(k,{className:`size-4`})}),(0,Z.jsx)(P,{variant:`ghost`,className:`size-8 rounded-md p-0`,"aria-label":i.dashboard.delete,disabled:c!==null,onClick:t=>{t.stopPropagation(),d(`automation:${e.id}:delete`,()=>I.remove(e.id),i.dashboard.deleted)},children:_?(0,Z.jsx)(M,{className:`size-4 animate-spin`}):(0,Z.jsx)(N,{className:`size-4`})})]})})]},e.id)},t[13]=c,t[14]=a,t[15]=i,t[16]=s,t[17]=d,t[18]=u,t[19]=p,t[20]=r,t[21]=e):e=t[21],m=n.map(e),t[3]=n,t[4]=c,t[5]=a,t[6]=i,t[7]=s,t[8]=d,t[9]=u,t[10]=p,t[11]=r,t[12]=m}else m=t[12];let h;return t[22]===m?h=t[23]:(h=(0,Z.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-3`,children:m}),t[22]=m,t[23]=h),h}function ft(e){let t=(0,U.c)(25),{runs:n,labels:r,cronLabels:i,language:a,selectedRunId:s,busyAction:c,className:l,onSelectRun:u,onAction:d}=e;if(n.length===0){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,Z.jsx)(ne,{className:`size-5`}),t[0]=e):e=t[0];let n;return t[1]===r.empty.runs?n=t[2]:(n=(0,Z.jsx)(Tt,{icon:e,title:r.empty.runs}),t[1]=r.empty.runs,t[2]=n),n}let f;t[3]===l?f=t[4]:(f=o(`overflow-hidden rounded-lg border border-edge-subtle bg-surface-base shadow-surface`,l),t[3]=l,t[4]=f);let p;if(t[5]!==c||t[6]!==i||t[7]!==r||t[8]!==a||t[9]!==d||t[10]!==u||t[11]!==n||t[12]!==s){let e;t[14]!==c||t[15]!==i||t[16]!==r||t[17]!==a||t[18]!==d||t[19]!==u||t[20]!==s?(e=e=>(0,Z.jsxs)(`div`,{className:o(`grid cursor-pointer gap-3 border-b border-edge p-4 outline-none last:border-b-0 hover:bg-surface-hover md:grid-cols-[1fr_auto]`,s===e.id&&`bg-surface-hover`),role:`button`,tabIndex:0,onClick:()=>u(e.id),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&u(e.id)},children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:e.automationName}),(0,Z.jsx)(`span`,{className:o(`rounded-full px-2 py-0.5 text-xs`,Je(e.status)),children:r.status[e.status]}),e.workflowRunId?(0,Z.jsxs)(`span`,{className:`text-xs text-fg-muted`,children:[r.workflowPrefix,` `,e.workflowRunId.slice(0,8)]}):null]}),(0,Z.jsx)(`div`,{className:o(`mt-1 line-clamp-2 whitespace-pre-line text-sm text-fg-muted`,e.error&&`text-red-700 dark:text-red-300`),children:e.error||e.summary||(Xe(e)?r.runDetail.resultPending:r.runDetail.noResult)}),(0,Z.jsxs)(`div`,{className:`mt-2 text-xs text-fg-muted`,children:[Ge(e.createdAtMs,r,a),` · `,e.manual?r.trigger.manual:Me(e.triggerSnapshot,r,i,a)]})]}),e.status===`running`||e.status===`queued`?(0,Z.jsx)(P,{variant:`ghost`,disabled:c!==null,onClick:t=>{t.stopPropagation(),d(`run:${e.id}:cancel`,()=>I.cancelRun(e.id),r.dashboard.cancelled)},children:c===`run:${e.id}:cancel`?r.feedback.working:r.cancel}):null]},e.id),t[14]=c,t[15]=i,t[16]=r,t[17]=a,t[18]=d,t[19]=u,t[20]=s,t[21]=e):e=t[21],p=n.map(e),t[5]=c,t[6]=i,t[7]=r,t[8]=a,t[9]=d,t[10]=u,t[11]=n,t[12]=s,t[13]=p}else p=t[13];let m;return t[22]!==f||t[23]!==p?(m=(0,Z.jsx)(`div`,{className:f,children:p}),t[22]=f,t[23]=p,t[24]=m):m=t[24],m}function pt(e,t){let n=t.events,r=e.data&&typeof e.data==`object`?e.data:{},i=typeof r.actionKind==`string`?r.actionKind:null,a=typeof r.status==`string`&&r.status in t.status?t.status[r.status]:null;switch(e.type){case`run.queued`:return e.message.toLowerCase().includes(`manual`)?n.manualQueued:e.message.toLowerCase().includes(`scheduled`)?n.scheduledQueued:n.eventQueued;case`run.started`:return n.runStarted;case`action.started`:return i?n.actionStarted.replace(`{kind}`,i):n.actionStartedFallback;case`action.completed`:return i?n.actionCompleted.replace(`{kind}`,i):n.actionCompletedFallback;case`action.failed`:return i?n.actionFailed.replace(`{kind}`,i):n.actionFailedFallback;case`after_run.started`:return n.afterRunStarted;case`after_run.completed`:return n.afterRunCompleted;case`after_run.failed`:return n.afterRunFailed;case`run.completed`:return a?n.runCompleted.replace(`{status}`,a):n.runCompletedFallback;default:return e.message}}function mt(e){let t=(0,U.c)(17),{value:n,labels:r,title:i,defaultExpanded:a}=e,[s,c]=(0,H.useState)(a===void 0?!1:a),l;t[0]===n?l=t[1]:(l=JSON.stringify(n,null,2),t[0]=n,t[1]=l);let u=l,d;t[2]===u?d=t[3]:(d=u.split(`
2
2
  `),t[2]=u,t[3]=d);let f=d.length,p=u.length>720||f>18,m;t[4]!==p||t[5]!==u?(m=p?`${u.split(`
3
3
  `).slice(0,10).join(`
4
4
  `).trimEnd()}...`:u,t[4]=p,t[5]=u,t[6]=m):m=t[6];let h=m,g;t[7]!==s||t[8]!==p||t[9]!==r||t[10]!==i?(g=p?(0,Z.jsxs)(`button`,{type:`button`,className:`flex w-full items-center justify-between gap-3 px-2.5 py-2 text-left text-xs font-medium text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:()=>c(ht),"aria-expanded":s,children:[(0,Z.jsx)(`span`,{children:i}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-accent-fg`,children:[s?r.details.hideDetails:r.details.showDetails,(0,Z.jsx)(re,{className:o(`size-3.5 transition-transform`,s&&`rotate-180`),"aria-hidden":!0})]})]}):(0,Z.jsx)(`div`,{className:`px-2.5 py-2 text-xs font-medium text-fg-muted`,children:i}),t[7]=s,t[8]=p,t[9]=r,t[10]=i,t[11]=g):g=t[11];let _=s||!p?u:h,v;t[12]===_?v=t[13]:(v=(0,Z.jsx)(`pre`,{className:`whitespace-pre-wrap break-all px-2.5 pb-2 text-xs leading-relaxed text-fg-muted`,children:_}),t[12]=_,t[13]=v);let y;return t[14]!==g||t[15]!==v?(y=(0,Z.jsxs)(`div`,{className:`mt-2 rounded-md border border-edge/70 bg-surface-muted/35`,children:[g,v]}),t[14]=g,t[15]=v,t[16]=y):y=t[16],y}function ht(e){return!e}function gt(e){let t=(0,U.c)(148),{className:n,run:r,events:i,labels:c,cronLabels:l,language:u,loading:d,repairDraft:f,repairLoading:p,repairApproved:m,busyAction:h,onRepairApprovedChange:g,onSuggestRepair:y,onApplyRepair:b}=e;if(!r){let e;t[0]===n?e=t[1]:(e=o(`flex min-h-64 flex-col justify-center rounded-lg border border-edge-subtle bg-surface-base px-4 text-center text-sm text-fg-muted shadow-surface`,n),t[0]=n,t[1]=e);let r;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,Z.jsx)(ne,{className:`mx-auto size-5`}),t[2]=r):r=t[2];let i;t[3]===c.selectRun?i=t[4]:(i=(0,Z.jsx)(`div`,{className:`mt-2`,children:c.selectRun}),t[3]=c.selectRun,t[4]=i);let a;return t[5]!==e||t[6]!==i?(a=(0,Z.jsxs)(`aside`,{className:e,children:[r,i]}),t[5]=e,t[6]=i,t[7]=a):a=t[7],a}let x=r.error||r.summary,S=r.sessionKey?`/chat/${encodeURIComponent(r.sessionKey)}`:r.workflowRunId?`/workflows?run=${encodeURIComponent(r.workflowRunId)}`:null,w=r.sessionKey?c.runDetail.openConversation:c.runDetail.openWorkflow,T=r.sessionKey?v:se,E=Xe(r)?ne:Ze(r)?s:ee,te;t[8]===n?te=t[9]:(te=o(`rounded-lg border border-edge-subtle bg-surface-base shadow-surface`,n),t[8]=n,t[9]=te);let k;t[10]===r.automationName?k=t[11]:(k=(0,Z.jsx)(`div`,{className:`truncate text-sm font-semibold text-fg`,children:r.automationName}),t[10]=r.automationName,t[11]=k);let A;t[12]===r.id?A=t[13]:(A=r.id.slice(0,8),t[12]=r.id,t[13]=A);let M;t[14]===A?M=t[15]:(M=(0,Z.jsx)(`div`,{className:`mt-1 text-xs text-fg-muted`,children:A}),t[14]=A,t[15]=M);let ie;t[16]!==k||t[17]!==M?(ie=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[k,M]}),t[16]=k,t[17]=M,t[18]=ie):ie=t[18];let ae;t[19]===r.status?ae=t[20]:(ae=o(`shrink-0 rounded-full px-2 py-0.5 text-xs`,Je(r.status)),t[19]=r.status,t[20]=ae);let N=c.status[r.status],oe;t[21]!==ae||t[22]!==N?(oe=(0,Z.jsx)(`span`,{className:ae,children:N}),t[21]=ae,t[22]=N,t[23]=oe):oe=t[23];let F;t[24]!==ie||t[25]!==oe?(F=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[ie,oe]}),t[24]=ie,t[25]=oe,t[26]=F):F=t[26];let ce;t[27]!==c||t[28]!==u||t[29]!==r.createdAtMs?(ce=Ge(r.createdAtMs,c,u),t[27]=c,t[28]=u,t[29]=r.createdAtMs,t[30]=ce):ce=t[30];let le;t[31]===ce?le=t[32]:(le=(0,Z.jsx)(`span`,{children:ce}),t[31]=ce,t[32]=le);let ue;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(ue=(0,Z.jsx)(`span`,{"aria-hidden":!0,children:`·`}),t[33]=ue):ue=t[33];let de=c.details.duration,fe;t[34]!==c||t[35]!==r.durationMs?(fe=Ye(r.durationMs,c),t[34]=c,t[35]=r.durationMs,t[36]=fe):fe=t[36];let I;t[37]!==c.details.duration||t[38]!==fe?(I=(0,Z.jsxs)(`span`,{children:[de,` `,fe]}),t[37]=c.details.duration,t[38]=fe,t[39]=I):I=t[39];let L;t[40]!==le||t[41]!==I?(L=(0,Z.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-fg-muted`,children:[le,ue,I]}),t[40]=le,t[41]=I,t[42]=L):L=t[42];let pe;t[43]!==c.repair||t[44]!==y||t[45]!==p||t[46]!==r?(pe=r.status===`failed`||r.status===`timeout`||r.status===`cancelled`?(0,Z.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,Z.jsxs)(P,{variant:`secondary`,onClick:()=>y(r),disabled:p,children:[(0,Z.jsx)(_,{className:`size-4`}),p?c.repair.generating:c.repair.suggest]})}):null,t[43]=c.repair,t[44]=y,t[45]=p,t[46]=r,t[47]=pe):pe=t[47];let R;t[48]!==L||t[49]!==pe||t[50]!==F?(R=(0,Z.jsxs)(`div`,{className:`border-b border-edge px-4 py-3`,children:[F,L,pe]}),t[48]=L,t[49]=pe,t[50]=F,t[51]=R):R=t[51];let z;t[52]===r?z=t[53]:(z=Xe(r)?`text-blue-500`:Ze(r)?`text-red-500`:`text-emerald-500`,t[52]=r,t[53]=z);let me;t[54]===z?me=t[55]:(me=o(`size-4`,z),t[54]=z,t[55]=me);let he;t[56]!==E||t[57]!==me?(he=(0,Z.jsx)(E,{className:me}),t[56]=E,t[57]=me,t[58]=he):he=t[58];let B;t[59]!==c.runDetail.resultTitle||t[60]!==he?(B=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[he,c.runDetail.resultTitle]}),t[59]=c.runDetail.resultTitle,t[60]=he,t[61]=B):B=t[61];let V;t[62]!==T||t[63]!==w||t[64]!==S?(V=S?(0,Z.jsx)(P,{asChild:!0,variant:`secondary`,className:`h-8 rounded-md px-2.5 text-xs`,children:(0,Z.jsxs)(a,{to:S,children:[(0,Z.jsx)(T,{className:`size-3.5`}),w,(0,Z.jsx)(C,{className:`size-3.5`})]})}):null,t[62]=T,t[63]=w,t[64]=S,t[65]=V):V=t[65];let ge;t[66]!==B||t[67]!==V?(ge=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[B,V]}),t[66]=B,t[67]=V,t[68]=ge):ge=t[68];let H=r.error&&`border-red-500/25 bg-red-500/5`,W;t[69]===H?W=t[70]:(W=o(`mt-3 max-h-80 overflow-y-auto rounded-lg border border-edge/70 bg-surface-muted/25 p-3`,H),t[69]=H,t[70]=W);let G;t[71]!==c.runDetail.noResult||t[72]!==c.runDetail.resultPending||t[73]!==x||t[74]!==r?(G=x?r.error?(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap break-words text-sm leading-relaxed text-red-700 dark:text-red-300`,children:x}):(0,Z.jsx)(O,{content:x,compact:!0,className:`text-sm`,openHttpLinksInNewTab:!0}):(0,Z.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:Xe(r)?c.runDetail.resultPending:c.runDetail.noResult}),t[71]=c.runDetail.noResult,t[72]=c.runDetail.resultPending,t[73]=x,t[74]=r,t[75]=G):G=t[75];let K;t[76]!==W||t[77]!==G?(K=(0,Z.jsx)(`div`,{className:W,children:G}),t[76]=W,t[77]=G,t[78]=K):K=t[78];let _e;t[79]!==ge||t[80]!==K?(_e=(0,Z.jsxs)(`section`,{className:`border-b border-edge p-4`,children:[ge,K]}),t[79]=ge,t[80]=K,t[81]=_e):_e=t[81];let ve;t[82]===c.runDetail.runInfo?ve=t[83]:(ve=(0,Z.jsx)(`div`,{className:`text-xs font-semibold uppercase text-fg-muted`,children:c.runDetail.runInfo}),t[82]=c.runDetail.runInfo,t[83]=ve);let ye;t[84]!==l||t[85]!==c||t[86]!==u||t[87]!==r.manual||t[88]!==r.triggerSnapshot?(ye=r.manual?c.trigger.manual:Me(r.triggerSnapshot,c,l,u),t[84]=l,t[85]=c,t[86]=u,t[87]=r.manual,t[88]=r.triggerSnapshot,t[89]=ye):ye=t[89];let q;t[90]!==c.explain.whyRan||t[91]!==ye?(q=(0,Z.jsx)(St,{label:c.explain.whyRan,value:ye}),t[90]=c.explain.whyRan,t[91]=ye,t[92]=q):q=t[92];let be=c.details.started,xe;t[93]!==c||t[94]!==u||t[95]!==r.startedAtMs?(xe=Ge(r.startedAtMs,c,u),t[93]=c,t[94]=u,t[95]=r.startedAtMs,t[96]=xe):xe=t[96];let Se;t[97]!==c.details.started||t[98]!==xe?(Se=(0,Z.jsx)(St,{label:be,value:xe}),t[97]=c.details.started,t[98]=xe,t[99]=Se):Se=t[99];let J;t[100]!==c.details.model||t[101]!==r.model?(J=r.model?(0,Z.jsx)(St,{label:c.details.model,value:r.model}):null,t[100]=c.details.model,t[101]=r.model,t[102]=J):J=t[102];let Ce;t[103]!==q||t[104]!==Se||t[105]!==J?(Ce=(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2 text-xs text-fg-muted`,children:[q,Se,J]}),t[103]=q,t[104]=Se,t[105]=J,t[106]=Ce):Ce=t[106];let we;t[107]!==ve||t[108]!==Ce?(we=(0,Z.jsxs)(`section`,{className:`border-b border-edge p-4`,children:[ve,Ce]}),t[107]=ve,t[108]=Ce,t[109]=we):we=t[109];let Te;t[110]!==h||t[111]!==c||t[112]!==b||t[113]!==g||t[114]!==m||t[115]!==f||t[116]!==r?(Te=f?(0,Z.jsxs)(`div`,{className:`border-b border-edge px-4 py-3`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-semibold uppercase text-fg-muted`,children:c.repair.title}),(0,Z.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:f.explanation}),f.expectedEffect?(0,Z.jsx)(`div`,{className:`mt-2 text-sm text-fg-muted`,children:f.expectedEffect}):null,(0,Z.jsx)(lt,{title:c.repair.risks,items:f.risks,empty:c.none}),(0,Z.jsx)(mt,{value:f.patch,labels:c,title:c.details.repairPatch}),f.requiresApproval?(0,Z.jsxs)(`label`,{className:`mt-3 flex items-start gap-2 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{className:`mt-1`,type:`checkbox`,checked:m,onChange:e=>g(e.target.checked)}),(0,Z.jsx)(`span`,{children:c.repair.approval})]}):null,(0,Z.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,Z.jsx)(P,{variant:`primary`,onClick:()=>b(r),disabled:h===`run:${r.id}:repair`||f.requiresApproval&&!m,children:h===`run:${r.id}:repair`?c.feedback.working:c.repair.apply})})]}):null,t[110]=h,t[111]=c,t[112]=b,t[113]=g,t[114]=m,t[115]=f,t[116]=r,t[117]=Te):Te=t[117];let Ee;t[118]===Symbol.for(`react.memo_cache_sentinel`)?(Ee=(0,Z.jsx)(D,{className:`size-4 shrink-0`}),t[118]=Ee):Ee=t[118];let De;t[119]===c.runDetail.technicalEvents?De=t[120]:(De=(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-medium text-fg-muted`,children:[Ee,c.runDetail.technicalEvents]}),t[119]=c.runDetail.technicalEvents,t[120]=De);let Oe;t[121]!==i.length||t[122]!==c.runDetail.eventCount?(Oe=c.runDetail.eventCount.replace(`{count}`,String(i.length)),t[121]=i.length,t[122]=c.runDetail.eventCount,t[123]=Oe):Oe=t[123];let ke;t[124]===Symbol.for(`react.memo_cache_sentinel`)?(ke=(0,Z.jsx)(re,{className:`size-4 transition-transform group-open:rotate-180`}),t[124]=ke):ke=t[124];let Ae;t[125]===Oe?Ae=t[126]:(Ae=(0,Z.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-xs text-fg-muted`,children:[Oe,ke]}),t[125]=Oe,t[126]=Ae);let Y;t[127]!==De||t[128]!==Ae?(Y=(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 rounded-md outline-none hover:text-fg focus-visible:ring-2 focus-visible:ring-accent`,children:[De,Ae]}),t[127]=De,t[128]=Ae,t[129]=Y):Y=t[129];let je;t[130]===c.runDetail.technicalEventsDescription?je=t[131]:(je=(0,Z.jsx)(`p`,{className:`mt-2 text-xs leading-relaxed text-fg-muted`,children:c.runDetail.technicalEventsDescription}),t[130]=c.runDetail.technicalEventsDescription,t[131]=je);let X;t[132]!==i||t[133]!==c||t[134]!==u||t[135]!==d?(X=(0,Z.jsx)(`div`,{className:`mt-4`,children:d?(0,Z.jsxs)(`div`,{className:`space-y-3`,"aria-label":c.loading,children:[(0,Z.jsx)(j,{className:`h-10 w-full`}),(0,Z.jsx)(j,{className:`h-10 w-4/5`}),(0,Z.jsx)(j,{className:`h-10 w-11/12`})]}):i.length===0?(0,Z.jsx)(`div`,{className:`text-sm text-fg-muted`,children:c.empty.events}):(0,Z.jsx)(`ol`,{className:`space-y-3`,children:i.map(e=>(0,Z.jsxs)(`li`,{className:`grid grid-cols-[0.75rem_1fr] gap-3`,children:[(0,Z.jsx)(`span`,{className:o(`mt-1 size-2 rounded-full`,Ct(e.type))}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm text-fg`,children:pt(e,c)}),(0,Z.jsxs)(`div`,{className:`mt-1 text-xs text-fg-muted`,children:[Ge(e.createdAtMs,c,u),` · `,e.type]}),e.data&&typeof e.data==`object`?(0,Z.jsxs)(`details`,{className:`group/event mt-2 rounded-md border border-edge/70 bg-surface-muted/35`,children:[(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-2 px-2.5 py-2 text-xs font-medium text-fg-muted outline-none hover:text-fg`,children:[c.details.eventData,(0,Z.jsx)(re,{className:`size-3.5 transition-transform group-open/event:rotate-180`})]}),(0,Z.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap break-all border-t border-edge/70 px-2.5 py-2 text-xs leading-relaxed text-fg-muted`,children:JSON.stringify(e.data,null,2)})]}):null]})]},e.id))})}),t[132]=i,t[133]=c,t[134]=u,t[135]=d,t[136]=X):X=t[136];let Ne;t[137]!==Y||t[138]!==je||t[139]!==X?(Ne=(0,Z.jsxs)(`details`,{className:`group px-4 py-3`,children:[Y,je,X]}),t[137]=Y,t[138]=je,t[139]=X,t[140]=Ne):Ne=t[140];let Pe;return t[141]!==te||t[142]!==R||t[143]!==_e||t[144]!==we||t[145]!==Te||t[146]!==Ne?(Pe=(0,Z.jsxs)(`aside`,{className:te,children:[R,_e,we,Te,Ne]}),t[141]=te,t[142]=R,t[143]=_e,t[144]=we,t[145]=Te,t[146]=Ne,t[147]=Pe):Pe=t[147],Pe}function _t(e){let t=(0,U.c)(23),{automation:n,runs:r,labels:i,cronLabels:s,language:c,busyAction:l,onClose:u,onEdit:p,onSelectRun:m,onAction:g}=e,_=n?l===`automation:${n.id}:run`:!1,v=n?l===`automation:${n.id}:toggle`:!1,y=n?l===`automation:${n.id}:delete`:!1,C=!!n,w;t[0]===u?w=t[1]:(w=e=>!e&&u(),t[0]=u,t[1]=w);let T;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,Z.jsx)(b,{className:`xopc-dialog-overlay fixed inset-0 z-65 bg-scrim backdrop-blur-[1px]`}),t[2]=T):T=t[2];let E;t[3]!==n||t[4]!==l||t[5]!==s||t[6]!==y||t[7]!==i||t[8]!==c||t[9]!==g||t[10]!==u||t[11]!==p||t[12]!==m||t[13]!==_||t[14]!==r||t[15]!==v?(E=n?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-edge px-5 py-4`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(h,{className:`truncate text-base font-semibold text-fg`,children:n.name}),n.description?(0,Z.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm text-fg-muted`,children:n.description}):null]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:o(`rounded-full px-2 py-0.5 text-xs`,n.enabled?`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`:`bg-surface-hover text-fg-muted`),children:n.enabled?i.enabled:i.paused}),(0,Z.jsx)(d,{asChild:!0,children:(0,Z.jsx)(P,{variant:`ghost`,"aria-label":i.close,children:(0,Z.jsx)(de,{className:`size-4`})})})]})]}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,Z.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-[20rem_1fr]`,children:[(0,Z.jsx)(yt,{automation:n,labels:i,cronLabels:s,language:c}),(0,Z.jsxs)(`section`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:i.dashboard.runHistory}),(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:i.dashboard.runHistoryDescription})]}),(0,Z.jsx)(`span`,{className:`rounded-full bg-surface-base px-2.5 py-1 text-xs text-fg-muted`,children:r.length})]}),r.length===0?(0,Z.jsx)(Tt,{icon:(0,Z.jsx)(ne,{className:`size-5`}),title:i.empty.runs}):(0,Z.jsx)(`div`,{className:`grid gap-2`,children:r.map(e=>(0,Z.jsx)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,Z.jsxs)(`button`,{type:`button`,className:`min-w-0 text-left outline-none`,onClick:()=>m(e.id),children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[e.status===`succeeded`?(0,Z.jsx)(ee,{className:`size-4 shrink-0 text-emerald-600 dark:text-emerald-300`}):(0,Z.jsx)(ne,{className:`size-4 shrink-0 text-fg-muted`}),(0,Z.jsx)(`span`,{className:`truncate text-sm font-medium text-fg`,children:Ge(e.createdAtMs,i,c)}),(0,Z.jsx)(`span`,{className:o(`rounded-full px-2 py-0.5 text-xs`,Je(e.status)),children:i.status[e.status]})]}),(0,Z.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm text-fg-muted`,children:e.error||e.summary||Ke(e.actionSnapshot,i)})]}),(0,Z.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-1`,children:[e.sessionKey?(0,Z.jsx)(P,{asChild:!0,variant:`ghost`,className:`h-8 rounded-md px-2 text-xs`,children:(0,Z.jsxs)(a,{to:`/chat/${encodeURIComponent(e.sessionKey)}`,children:[(0,Z.jsx)(x,{className:`size-3.5`}),i.dashboard.openSession]})}):null,e.workflowRunId?(0,Z.jsx)(P,{asChild:!0,variant:`ghost`,className:`h-8 rounded-md px-2 text-xs`,children:(0,Z.jsxs)(a,{to:`/workflows?run=${encodeURIComponent(e.workflowRunId)}`,children:[(0,Z.jsx)(se,{className:`size-3.5`}),i.feedback.workflow]})}):null]})]})},e.id))})]})]})}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap justify-between gap-2 border-t border-edge px-5 py-4`,children:[(0,Z.jsxs)(P,{variant:`ghost`,disabled:l!==null,onClick:()=>void g(`automation:${n.id}:delete`,()=>I.remove(n.id),i.dashboard.deleted).then(e=>{e&&u()}),children:[y?(0,Z.jsx)(M,{className:`size-4 animate-spin`}):(0,Z.jsx)(N,{className:`size-4`}),i.dashboard.delete]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[$e(n)?null:(0,Z.jsxs)(P,{variant:`secondary`,disabled:l!==null,onClick:()=>p(n),children:[(0,Z.jsx)(L,{className:`size-4`}),i.edit]}),(0,Z.jsxs)(P,{variant:`secondary`,disabled:l!==null,onClick:()=>void g(`automation:${n.id}:toggle`,()=>n.enabled?I.pause(n.id):I.resume(n.id),n.enabled?i.feedback.paused:i.dashboard.resumed),children:[v?(0,Z.jsx)(M,{className:`size-4 animate-spin`}):n.enabled?(0,Z.jsx)(f,{className:`size-4`}):(0,Z.jsx)(k,{className:`size-4`}),n.enabled?i.dashboard.pause:i.dashboard.resume]}),(0,Z.jsxs)(P,{variant:`primary`,disabled:l!==null,onClick:()=>void g(`automation:${n.id}:run`,()=>I.runNow(n.id),i.feedback.rerunQueued),children:[_?(0,Z.jsx)(M,{className:`size-4 animate-spin`}):(0,Z.jsx)(k,{className:`size-4`}),i.dashboard.runNow]})]})]})]}):null,t[3]=n,t[4]=l,t[5]=s,t[6]=y,t[7]=i,t[8]=c,t[9]=g,t[10]=u,t[11]=p,t[12]=m,t[13]=_,t[14]=r,t[15]=v,t[16]=E):E=t[16];let D;t[17]===E?D=t[18]:(D=(0,Z.jsxs)(S,{children:[T,(0,Z.jsx)(ae,{className:`fixed left-1/2 top-1/2 z-66 flex h-[min(760px,calc(100vh-2rem))] w-[min(100%-2rem,56rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none`,children:E})]}),t[17]=E,t[18]=D);let O;return t[19]!==C||t[20]!==w||t[21]!==D?(O=(0,Z.jsx)(oe,{open:C,onOpenChange:w,children:D}),t[19]=C,t[20]=w,t[21]=D,t[22]=O):O=t[22],O}function vt(e,t){return e===`suggest_only`?t.safety.suggestOnlyDescription:e===`ask_before_apply`?t.safety.askBeforeApplyDescription:t.safety.autoApplyDescription}function yt(e){let t=(0,U.c)(127),{automation:n,labels:r,cronLabels:i,language:a}=e,o,s,c,l,u,d,f,p,m,h,g;if(t[0]!==n||t[1]!==i||t[2]!==r||t[3]!==a){let e=qe(n),_;t[15]!==n||t[16]!==r||t[17]!==a?(_=X(n,r,a),t[15]=n,t[16]=r,t[17]=a,t[18]=_):_=t[18];let v=_,y;t[19]!==n.state.nextRunAtMs||t[20]!==a?(y=n.state.nextRunAtMs?ke(n.state.nextRunAtMs,a):void 0,t[19]=n.state.nextRunAtMs,t[20]=a,t[21]=y):y=t[21];let b=y;if(t[22]!==n.trigger.eventType||t[23]!==n.trigger.kind||t[24]!==n.trigger.schedule||t[25]!==n.trigger.secretId||t[26]!==n.trigger.source||t[27]!==r.info.anchor||t[28]!==r.info.calendarSchedule||t[29]!==r.info.eventSource||t[30]!==r.info.eventType||t[31]!==r.info.expression||t[32]!==r.info.fixedInterval||t[33]!==r.info.oneTimeSchedule||t[34]!==r.info.rawInterval||t[35]!==r.info.scheduleType||t[36]!==r.info.timezone||t[37]!==r.info.webhookSecret||t[38]!==a){if(g=[],n.trigger.kind===`schedule`){let e=n.trigger.schedule,i=e.kind===`interval`?r.info.fixedInterval:e.kind===`cron`?r.info.calendarSchedule:r.info.oneTimeSchedule,o;if(t[40]!==r.info.scheduleType||t[41]!==i?(o={label:r.info.scheduleType,value:i},t[40]=r.info.scheduleType,t[41]=i,t[42]=o):o=t[42],g.push(o),e.kind===`interval`){let n=`${e.everyMs} ms`,i;if(t[43]!==r.info.rawInterval||t[44]!==n?(i={label:r.info.rawInterval,value:n},t[43]=r.info.rawInterval,t[44]=n,t[45]=i):i=t[45],g.push(i),e.anchorMs){let n=r.info.anchor,i;t[46]!==a||t[47]!==e.anchorMs?(i=ke(e.anchorMs,a),t[46]=a,t[47]=e.anchorMs,t[48]=i):i=t[48];let o;t[49]!==r.info.anchor||t[50]!==i?(o={label:n,value:i},t[49]=r.info.anchor,t[50]=i,t[51]=o):o=t[51],g.push(o)}}else if(e.kind===`cron`){let n;if(t[52]!==r.info.expression||t[53]!==e.expr?(n={label:r.info.expression,value:e.expr},t[52]=r.info.expression,t[53]=e.expr,t[54]=n):n=t[54],g.push(n),e.tz){let n;t[55]!==r.info.timezone||t[56]!==e.tz?(n={label:r.info.timezone,value:e.tz},t[55]=r.info.timezone,t[56]=e.tz,t[57]=n):n=t[57],g.push(n)}}else{let n;t[58]!==r.info.oneTimeSchedule||t[59]!==e.at?(n={label:r.info.oneTimeSchedule,value:e.at},t[58]=r.info.oneTimeSchedule,t[59]=e.at,t[60]=n):n=t[60],g.push(n)}}else if(n.trigger.kind===`event`){let e;if(t[61]!==n.trigger.eventType||t[62]!==r.info.eventType?(e={label:r.info.eventType,value:n.trigger.eventType},t[61]=n.trigger.eventType,t[62]=r.info.eventType,t[63]=e):e=t[63],g.push(e),n.trigger.source){let e;t[64]!==n.trigger.source||t[65]!==r.info.eventSource?(e={label:r.info.eventSource,value:n.trigger.source},t[64]=n.trigger.source,t[65]=r.info.eventSource,t[66]=e):e=t[66],g.push(e)}}else if(n.trigger.kind===`webhook`&&n.trigger.secretId){let e;t[67]!==n.trigger.secretId||t[68]!==r.info.webhookSecret?(e={label:r.info.webhookSecret,value:n.trigger.secretId},t[67]=n.trigger.secretId,t[68]=r.info.webhookSecret,t[69]=e):e=t[69],g.push(e)}t[22]=n.trigger.eventType,t[23]=n.trigger.kind,t[24]=n.trigger.schedule,t[25]=n.trigger.secretId,t[26]=n.trigger.source,t[27]=r.info.anchor,t[28]=r.info.calendarSchedule,t[29]=r.info.eventSource,t[30]=r.info.eventType,t[31]=r.info.expression,t[32]=r.info.fixedInterval,t[33]=r.info.oneTimeSchedule,t[34]=r.info.rawInterval,t[35]=r.info.scheduleType,t[36]=r.info.timezone,t[37]=r.info.webhookSecret,t[38]=a,t[39]=g}else g=t[39];m=`h-fit overflow-hidden rounded-xl border border-edge-subtle bg-surface-base shadow-surface`,t[70]===r.info.overview?h=t[71]:(h=(0,Z.jsx)(`div`,{className:`border-b border-edge-subtle px-4 py-3`,children:(0,Z.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:r.info.overview})}),t[70]=r.info.overview,t[71]=h),d=`grid gap-4 p-4`;let x;t[72]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,Z.jsx)(ue,{className:`size-4`,"aria-hidden":!0}),t[72]=x):x=t[72];let S=r.info.schedule,C;t[73]!==n.trigger||t[74]!==i||t[75]!==r||t[76]!==a?(C=Me(n.trigger,r,i,a),t[73]=n.trigger,t[74]=i,t[75]=r,t[76]=a,t[77]=C):C=t[77];let w=n.enabled?`${r.info.nextRun}:${v}`:v;t[78]!==r.info.schedule||t[79]!==b||t[80]!==C||t[81]!==w?(f=(0,Z.jsx)(xt,{icon:x,label:S,value:C,description:w,descriptionTitle:b}),t[78]=r.info.schedule,t[79]=b,t[80]=C,t[81]=w,t[82]=f):f=t[82];let T;t[83]===n.action.kind?T=t[84]:(T=n.action.kind===`workflow`?(0,Z.jsx)(se,{className:`size-4`,"aria-hidden":!0}):(0,Z.jsx)(A,{className:`size-4`,"aria-hidden":!0}),t[83]=n.action.kind,t[84]=T);let E=r.info.action,D;t[85]!==n.action||t[86]!==r?(D=Ke(n.action,r),t[85]=n.action,t[86]=r,t[87]=D):D=t[87],t[88]!==r.info.action||t[89]!==T||t[90]!==D?(p=(0,Z.jsx)(xt,{icon:T,label:E,value:D}),t[88]=r.info.action,t[89]=T,t[90]=D,t[91]=p):p=t[91],o=xt,t[92]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,Z.jsx)(te,{className:`size-4`,"aria-hidden":!0}),t[92]=s):s=t[92],c=r.info.permission,l=r.safety[e],u=vt(e,r),t[0]=n,t[1]=i,t[2]=r,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=f,t[11]=p,t[12]=m,t[13]=h,t[14]=g}else o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10],p=t[11],m=t[12],h=t[13],g=t[14];let _;t[93]!==o||t[94]!==s||t[95]!==c||t[96]!==l||t[97]!==u?(_=(0,Z.jsx)(o,{icon:s,label:c,value:l,description:u}),t[93]=o,t[94]=s,t[95]=c,t[96]=l,t[97]=u,t[98]=_):_=t[98];let v;t[99]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,Z.jsx)(ne,{className:`size-4`,"aria-hidden":!0}),t[99]=v):v=t[99];let y=r.info.lastRun,b;t[100]!==n||t[101]!==r||t[102]!==a?(b=Ne(n,r,a),t[100]=n,t[101]=r,t[102]=a,t[103]=b):b=t[103];let x=n.state.lastRunStatus===`failed`||n.state.lastRunStatus===`timeout`?`danger`:`default`,S;t[104]!==r.info.lastRun||t[105]!==b||t[106]!==x?(S=(0,Z.jsx)(xt,{icon:v,label:y,value:b,valueTone:x}),t[104]=r.info.lastRun,t[105]=b,t[106]=x,t[107]=S):S=t[107];let C;t[108]!==n.state.consecutiveFailures||t[109]!==n.state.lastError||t[110]!==r.dashboard?(C=n.state.consecutiveFailures?(0,Z.jsxs)(`div`,{className:`rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:[r.dashboard.failures,`:`,n.state.consecutiveFailures,n.state.lastError?(0,Z.jsx)(`p`,{className:`mt-1 break-words text-xs`,children:n.state.lastError}):null]}):n.state.lastError?(0,Z.jsx)(`p`,{className:`break-words text-sm text-red-700 dark:text-red-300`,children:n.state.lastError}):null,t[108]=n.state.consecutiveFailures,t[109]=n.state.lastError,t[110]=r.dashboard,t[111]=C):C=t[111];let w;t[112]!==r.info.technicalDetails||t[113]!==g?(w=g.length>0?(0,Z.jsxs)(`details`,{className:`group border-t border-edge-subtle pt-3`,children:[(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-2 text-sm text-fg-muted outline-none hover:text-fg focus-visible:ring-2 focus-visible:ring-accent`,children:[(0,Z.jsx)(`span`,{children:r.info.technicalDetails}),(0,Z.jsx)(re,{className:`size-4 transition-transform group-open:rotate-180`,"aria-hidden":!0})]}),(0,Z.jsx)(`div`,{className:`mt-3 grid gap-2`,children:g.map(bt)})]}):null,t[112]=r.info.technicalDetails,t[113]=g,t[114]=w):w=t[114];let T;t[115]!==_||t[116]!==S||t[117]!==C||t[118]!==w||t[119]!==d||t[120]!==f||t[121]!==p?(T=(0,Z.jsxs)(`div`,{className:d,children:[f,p,_,S,C,w]}),t[115]=_,t[116]=S,t[117]=C,t[118]=w,t[119]=d,t[120]=f,t[121]=p,t[122]=T):T=t[122];let E;return t[123]!==T||t[124]!==m||t[125]!==h?(E=(0,Z.jsxs)(`aside`,{className:m,children:[h,T]}),t[123]=T,t[124]=m,t[125]=h,t[126]=E):E=t[126],E}function bt(e){return(0,Z.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:e.label}),(0,Z.jsx)(`span`,{className:`break-all font-mono text-xs text-fg-muted`,children:e.value})]},`${e.label}:${e.value}`)}function xt(e){let t=(0,U.c)(19),{icon:n,label:r,value:i,description:a,descriptionTitle:s,valueTone:c}=e,l=c===void 0?`default`:c,u;t[0]===n?u=t[1]:(u=(0,Z.jsx)(`span`,{className:`mt-0.5 text-fg-subtle`,children:n}),t[0]=n,t[1]=u);let d;t[2]===r?d=t[3]:(d=(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:r}),t[2]=r,t[3]=d);let f=l===`danger`?`text-red-700 dark:text-red-300`:`text-fg`,p;t[4]===f?p=t[5]:(p=o(`mt-1 text-sm font-medium leading-5`,f),t[4]=f,t[5]=p);let m;t[6]!==p||t[7]!==i?(m=(0,Z.jsx)(`div`,{className:p,children:i}),t[6]=p,t[7]=i,t[8]=m):m=t[8];let h;t[9]!==a||t[10]!==s?(h=a?(0,Z.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-fg-subtle`,title:s,children:a}):null,t[9]=a,t[10]=s,t[11]=h):h=t[11];let g;t[12]!==d||t[13]!==m||t[14]!==h?(g=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[d,m,h]}),t[12]=d,t[13]=m,t[14]=h,t[15]=g):g=t[15];let _;return t[16]!==u||t[17]!==g?(_=(0,Z.jsxs)(`div`,{className:`grid grid-cols-[1.25rem_1fr] gap-2.5`,children:[u,g]}),t[16]=u,t[17]=g,t[18]=_):_=t[18],_}function St(e){let t=(0,U.c)(7),{label:n,value:r}=e,i;t[0]===n?i=t[1]:(i=(0,Z.jsx)(`span`,{children:n}),t[0]=n,t[1]=i);let a;t[2]===r?a=t[3]:(a=(0,Z.jsx)(`span`,{className:`min-w-0 truncate text-fg`,children:r}),t[2]=r,t[3]=a);let o;return t[4]!==i||t[5]!==a?(o=(0,Z.jsxs)(`div`,{className:`grid grid-cols-[5rem_1fr] gap-2`,children:[i,a]}),t[4]=i,t[5]=a,t[6]=o):o=t[6],o}function Ct(e){return e.endsWith(`.failed`)?`bg-red-500`:e.endsWith(`.completed`)?`bg-emerald-500`:e.endsWith(`.started`)?`bg-blue-500`:`bg-fg-muted`}function wt(e){let t=(0,U.c)(7),{label:n,value:r}=e,i;t[0]===n?i=t[1]:(i=(0,Z.jsx)(`div`,{className:`text-xs font-medium uppercase text-fg-muted`,children:n}),t[0]=n,t[1]=i);let a;t[2]===r?a=t[3]:(a=(0,Z.jsx)(`div`,{className:`mt-1 truncate text-sm text-fg`,children:r}),t[2]=r,t[3]=a);let o;return t[4]!==i||t[5]!==a?(o=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[i,a]}),t[4]=i,t[5]=a,t[6]=o):o=t[6],o}function Tt(e){let t=(0,U.c)(5),{icon:n,title:r}=e,i;t[0]===r?i=t[1]:(i=(0,Z.jsx)(`div`,{className:`mt-2 text-sm`,children:r}),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,Z.jsxs)(`div`,{className:`flex min-h-48 flex-col items-center justify-center rounded-lg border border-edge-subtle bg-surface-base text-fg-muted shadow-surface`,children:[n,i]}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}function Et(e){let t=(0,U.c)(242),{form:n,labels:r,setForm:i,workflowDefinitions:a,selectedWorkflow:s,workflowsLoading:l,agentOptions:u,agentsLoading:d,language:f}=e,p=c(f).agentsSettings,m;t[0]===i?m=t[1]:(m=e=>i(t=>({...t,...e})),t[0]=i,t[1]=m);let h=m,_=Te(n.intervalValue,n.intervalUnit),v=Date.now(),y;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(y=[1,2,3],t[2]=y):y=t[2];let b;t[3]!==_||t[4]!==v||t[5]!==f?(b=y.map(e=>Y(v+_*e,f,v)),t[3]=_,t[4]=v,t[5]=f,t[6]=b):b=t[6];let x=b,S,C;t[7]!==n.actionMode||t[8]!==n.workflowId||t[9]!==i||t[10]!==a?(S=()=>{if(n.actionMode!==`workflow`||n.workflowId.trim())return;let e=a[0]?.id;e&&i(t=>({...t,workflowId:e,workflowGoal:``,workflowInput:{goal:``,argValues:{},schemaInput:{},concurrency:``,maxSubagents:``},workflowInputValid:!0}))},C=[n.actionMode,n.workflowId,i,a],t[7]=n.actionMode,t[8]=n.workflowId,t[9]=i,t[10]=a,t[11]=S,t[12]=C):(S=t[11],C=t[12]),(0,H.useEffect)(S,C);let w;t[13]===h?w=t[14]:(w=e=>h({name:e.target.value}),t[13]=h,t[14]=w);let T;t[15]!==n.name||t[16]!==w?(T=(0,Z.jsx)(`input`,{className:Q,value:n.name,onChange:w}),t[15]=n.name,t[16]=w,t[17]=T):T=t[17];let E;t[18]!==r.form.name||t[19]!==T?(E=(0,Z.jsx)($,{label:r.form.name,children:T}),t[18]=r.form.name,t[19]=T,t[20]=E):E=t[20];let D;t[21]===h?D=t[22]:(D=e=>h({description:e.target.value}),t[21]=h,t[22]=D);let ee;t[23]!==n.description||t[24]!==D?(ee=(0,Z.jsx)(`input`,{className:Q,value:n.description,onChange:D}),t[23]=n.description,t[24]=D,t[25]=ee):ee=t[25];let O;t[26]!==r.form.description||t[27]!==ee?(O=(0,Z.jsx)($,{label:r.form.description,children:ee}),t[26]=r.form.description,t[27]=ee,t[28]=O):O=t[28];let te;t[29]===r.form.trigger?te=t[30]:(te=(0,Z.jsx)(Ot,{title:r.form.trigger}),t[29]=r.form.trigger,t[30]=te);let k;t[31]===h?k=t[32]:(k=e=>h({triggerMode:e.target.value}),t[31]=h,t[32]=k);let A;t[33]===r.trigger.manual?A=t[34]:(A=(0,Z.jsx)(F,{value:`manual`,children:r.trigger.manual}),t[33]=r.trigger.manual,t[34]=A);let j;t[35]===r.trigger.once?j=t[36]:(j=(0,Z.jsx)(F,{value:`once`,children:r.trigger.once}),t[35]=r.trigger.once,t[36]=j);let ne;t[37]===r.trigger.daily?ne=t[38]:(ne=(0,Z.jsx)(F,{value:`daily`,children:r.trigger.daily}),t[37]=r.trigger.daily,t[38]=ne);let M;t[39]===r.trigger.weekly?M=t[40]:(M=(0,Z.jsx)(F,{value:`weekly`,children:r.trigger.weekly}),t[39]=r.trigger.weekly,t[40]=M);let re;t[41]===r.trigger.interval?re=t[42]:(re=(0,Z.jsx)(F,{value:`interval`,children:r.trigger.interval}),t[41]=r.trigger.interval,t[42]=re);let ie;t[43]===r.trigger.customCron?ie=t[44]:(ie=(0,Z.jsx)(F,{value:`cron`,children:r.trigger.customCron}),t[43]=r.trigger.customCron,t[44]=ie);let ae;t[45]===r.trigger.webhook?ae=t[46]:(ae=(0,Z.jsx)(F,{value:`webhook`,children:r.trigger.webhook}),t[45]=r.trigger.webhook,t[46]=ae);let N;t[47]===r.trigger.goalBlocked?N=t[48]:(N=(0,Z.jsx)(F,{value:`goalBlocked`,children:r.trigger.goalBlocked}),t[47]=r.trigger.goalBlocked,t[48]=N);let oe;t[49]===r.trigger.noteCreated?oe=t[50]:(oe=(0,Z.jsx)(F,{value:`noteCreated`,children:r.trigger.noteCreated}),t[49]=r.trigger.noteCreated,t[50]=oe);let se;t[51]===r.trigger.workflowFailed?se=t[52]:(se=(0,Z.jsx)(F,{value:`workflowFailed`,children:r.trigger.workflowFailed}),t[51]=r.trigger.workflowFailed,t[52]=se);let P;t[53]===r.trigger.sessionUpdated?P=t[54]:(P=(0,Z.jsx)(F,{value:`sessionUpdated`,children:r.trigger.sessionUpdated}),t[53]=r.trigger.sessionUpdated,t[54]=P);let ce;t[55]===r.trigger.customEvent?ce=t[56]:(ce=(0,Z.jsx)(F,{value:`event`,children:r.trigger.customEvent}),t[55]=r.trigger.customEvent,t[56]=ce);let le;t[57]!==n.triggerMode||t[58]!==k||t[59]!==A||t[60]!==j||t[61]!==ne||t[62]!==M||t[63]!==re||t[64]!==ie||t[65]!==ae||t[66]!==N||t[67]!==oe||t[68]!==se||t[69]!==P||t[70]!==ce?(le=(0,Z.jsxs)(g,{className:Q,value:n.triggerMode,onChange:k,children:[A,j,ne,M,re,ie,ae,N,oe,se,P,ce]}),t[57]=n.triggerMode,t[58]=k,t[59]=A,t[60]=j,t[61]=ne,t[62]=M,t[63]=re,t[64]=ie,t[65]=ae,t[66]=N,t[67]=oe,t[68]=se,t[69]=P,t[70]=ce,t[71]=le):le=t[71];let ue;t[72]!==n.onceAt||t[73]!==n.triggerMode||t[74]!==r.form.onceAt||t[75]!==h?(ue=n.triggerMode===`once`?(0,Z.jsx)($,{label:r.form.onceAt,children:(0,Z.jsx)(`input`,{className:Q,type:`datetime-local`,value:n.onceAt,onChange:e=>h({onceAt:e.target.value})})}):null,t[72]=n.onceAt,t[73]=n.triggerMode,t[74]=r.form.onceAt,t[75]=h,t[76]=ue):ue=t[76];let de;t[77]!==n.time||t[78]!==n.triggerMode||t[79]!==n.weekday||t[80]!==r.form.day||t[81]!==r.form.time||t[82]!==r.weekdays||t[83]!==h?(de=n.triggerMode===`daily`||n.triggerMode===`weekly`?(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsx)($,{label:r.form.time,children:(0,Z.jsx)(`input`,{className:Q,type:`time`,value:n.time,onChange:e=>h({time:e.target.value})})}),n.triggerMode===`weekly`?(0,Z.jsx)($,{label:r.form.day,children:(0,Z.jsxs)(g,{className:Q,value:n.weekday,onChange:e=>h({weekday:e.target.value}),children:[(0,Z.jsx)(F,{value:`1`,children:r.weekdays.monday}),(0,Z.jsx)(F,{value:`2`,children:r.weekdays.tuesday}),(0,Z.jsx)(F,{value:`3`,children:r.weekdays.wednesday}),(0,Z.jsx)(F,{value:`4`,children:r.weekdays.thursday}),(0,Z.jsx)(F,{value:`5`,children:r.weekdays.friday}),(0,Z.jsx)(F,{value:`6`,children:r.weekdays.saturday}),(0,Z.jsx)(F,{value:`0`,children:r.weekdays.sunday})]})}):null]}):null,t[77]=n.time,t[78]=n.triggerMode,t[79]=n.weekday,t[80]=r.form.day,t[81]=r.form.time,t[82]=r.weekdays,t[83]=h,t[84]=de):de=t[84];let fe=n.triggerMode===`interval`?(0,Z.jsxs)(`div`,{className:`grid gap-3 rounded-lg border border-edge-subtle bg-surface-base p-3`,children:[(0,Z.jsx)($,{label:r.form.intervalEvery,children:(0,Z.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-[minmax(0,1fr)_10rem]`,children:[(0,Z.jsx)(`input`,{className:Q,type:`number`,min:6e4/Te(1,n.intervalUnit),step:`any`,inputMode:`decimal`,value:n.intervalValue,onChange:e=>h({intervalValue:e.target.value})}),(0,Z.jsxs)(g,{className:Q,value:n.intervalUnit,onChange:e=>{let t=e.target.value;h({intervalValue:Ee(n.intervalValue,n.intervalUnit,t),intervalUnit:t})},children:[(0,Z.jsx)(F,{value:`minute`,children:r.form.intervalUnits.minute}),(0,Z.jsx)(F,{value:`hour`,children:r.form.intervalUnits.hour}),(0,Z.jsx)(F,{value:`day`,children:r.form.intervalUnits.day}),(0,Z.jsx)(F,{value:`week`,children:r.form.intervalUnits.week})]})]})}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:r.form.commonIntervals}),(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:Fe.map(e=>{let t=Te(e.value,e.unit),n=t===_;return(0,Z.jsx)(`button`,{type:`button`,"aria-pressed":n,className:o(`rounded-full border px-2.5 py-1 text-xs transition-colors`,n?`border-accent bg-accent/10 text-accent`:`border-edge-subtle text-fg-muted hover:border-edge hover:bg-surface-hover hover:text-fg`),onClick:()=>h({intervalValue:e.value,intervalUnit:e.unit}),children:De(t,f)},`${e.value}:${e.unit}`)})})]}),(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel px-3 py-2.5`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:Oe(_,f)}),(0,Z.jsxs)(`div`,{className:`mt-1 text-xs leading-5 text-fg-muted`,children:[r.form.nextThreeRuns,`:`,x.join(f===`zh`?`、`:`, `)]}),(0,Z.jsx)(`div`,{className:`mt-1 text-xs leading-5 text-fg-subtle`,children:r.form.fixedIntervalHint})]})]}):null,I;t[85]!==n.cronExpr||t[86]!==n.triggerMode||t[87]!==r.form.expression||t[88]!==h?(I=n.triggerMode===`cron`?(0,Z.jsx)($,{label:r.form.expression,children:(0,Z.jsx)(`input`,{className:Q,value:n.cronExpr,onChange:e=>h({cronExpr:e.target.value})})}):null,t[85]=n.cronExpr,t[86]=n.triggerMode,t[87]=r.form.expression,t[88]=h,t[89]=I):I=t[89];let L;t[90]!==n.triggerMode||t[91]!==n.webhookSecretId||t[92]!==r.form.secretId||t[93]!==h?(L=n.triggerMode===`webhook`?(0,Z.jsx)($,{label:r.form.secretId,children:(0,Z.jsx)(`input`,{className:Q,value:n.webhookSecretId,onChange:e=>h({webhookSecretId:e.target.value})})}):null,t[90]=n.triggerMode,t[91]=n.webhookSecretId,t[92]=r.form.secretId,t[93]=h,t[94]=L):L=t[94];let pe;t[95]!==n.eventPayloadMatch||t[96]!==n.eventSource||t[97]!==n.eventType||t[98]!==n.triggerMode||t[99]!==r.form.eventPayloadMatch||t[100]!==r.form.eventSource||t[101]!==r.form.eventType||t[102]!==r.form.invalidJsonObject||t[103]!==h?(pe=n.triggerMode===`event`?(0,Z.jsxs)(`div`,{className:`grid gap-3 rounded-lg border border-edge-subtle bg-surface-base p-3`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Z.jsx)($,{label:r.form.eventType,children:(0,Z.jsx)(`input`,{className:Q,value:n.eventType,onChange:e=>h({eventType:e.target.value})})}),(0,Z.jsx)($,{label:r.form.eventSource,children:(0,Z.jsx)(`input`,{className:Q,value:n.eventSource,onChange:e=>h({eventSource:e.target.value})})})]}),(0,Z.jsxs)($,{label:r.form.eventPayloadMatch,children:[(0,Z.jsx)(`textarea`,{className:o(Q,`min-h-24 resize-y font-mono text-xs`),value:n.eventPayloadMatch,onChange:e=>h({eventPayloadMatch:e.target.value}),placeholder:`{
@@ -1,2 +1,2 @@
1
1
  const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/attachment-preview-renderer-DonnL2dL.js","assets/preload-helper-zJ_50EbN.js","assets/excel-worksheet-utils-EyvwNT4X.js"])))=>i.map(i=>d[i]);
2
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{t as i}from"./preload-helper-zJ_50EbN.js";import{t as a}from"./messages-BuT0SR1R.js";import{$a as o,Za as s}from"./index-EXa_i6BT.js";import{t as c}from"./preview-open-alternatives-C7fw3oGy.js";import{t as l}from"./use-blob-object-url-D4BFuzZB.js";var u=e(t(),1),d=n();function f(e){let t=e.trim(),n=t.match(/^<pptx\s+filename="([^"]*)">\s*/),r=t;n&&(r=t.slice(n[0].length),r=r.replace(/\s*<\/pptx>\s*$/u,``).trim());let i=[],a=/<slide number="(\d+)">([\s\S]*?)<\/slide>/gu,o;for(;(o=a.exec(r))!==null;){let e=Number.parseInt(o[1],10),t=o[2].trim();i.push({slideNumber:e,text:t})}let s=[],c=/<!--([\s\S]*?)-->/gu,l;for(;(l=c.exec(r))!==null;)s.push(l[1].trim());return i.length===0?{ok:!1,raw:e}:{ok:!0,slides:i,notes:s}}var p=r();function m(e){let t=(0,d.c)(13),{text:n,slideLabel:r,emptySlideLabel:i}=e,a;t[0]===n?a=t[1]:(a=f(n),t[0]=n,t[1]=a);let o=a;if(!o.ok){let e;return t[2]===o.raw?e=t[3]:(e=(0,p.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-fg`,children:o.raw}),t[2]=o.raw,t[3]=e),e}let s;if(t[4]!==i||t[5]!==o.notes||t[6]!==o.slides||t[7]!==r){let e=[];if(o.notes.length>0){let n;t[9]===o.notes?n=t[10]:(n=o.notes.map(h),t[9]=o.notes,t[10]=n);let r;t[11]===n?r=t[12]:(r=(0,p.jsx)(`div`,{className:`mb-2 border-b border-edge-subtle pb-2 dark:border-edge`,role:`status`,children:n},`notes`),t[11]=n,t[12]=r),e.push(r)}for(let t of o.slides)e.push((0,p.jsxs)(`section`,{className:`rounded-lg border border-edge-subtle bg-surface-panel p-3 dark:border-edge`,children:[(0,p.jsx)(`h3`,{className:`mb-2 text-sm font-semibold text-fg`,children:r(t.slideNumber)}),(0,p.jsx)(`div`,{className:`whitespace-pre-wrap text-sm leading-relaxed text-fg`,children:t.text.length>0?t.text:i})]},t.slideNumber));s=(0,p.jsx)(`div`,{className:`flex flex-col gap-3`,children:e}),t[4]=i,t[5]=o.notes,t[6]=o.slides,t[7]=r,t[8]=s}else s=t[8];return s}function h(e){return(0,p.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e},e)}function g(e,t){return t===`pdf`?a(e).chat.attachmentPreviewPdfRendering:e===`zh`?t===`excel`?`正在加载电子表格…`:`正在加载文档…`:t===`excel`?`Loading spreadsheet...`:`Loading document...`}function _(e,t){e.innerHTML=``;let n=document.createElement(`p`);n.className=`p-4 text-sm text-fg-muted`,n.textContent=t,e.appendChild(n)}function v({language:e,buffer:t,kind:n,fileKey:r,containerEl:o,onPdfPageCount:s}){let c=(0,u.useRef)(null),[l,d]=(0,u.useState)(null),[f,p]=(0,u.useState)(!1);return(0,u.useLayoutEffect)(()=>{if(c.current?.(),c.current=null,d(null),p(!1),!t||!n||!o||!r)return;let l=!1;return _(o,g(e,n)),(async()=>{try{let r=await i(()=>import(`./attachment-preview-renderer-DonnL2dL.js`),__vite__mapDeps([0,1,2]));if(l)return;let u=a(e).chat;if(n===`pdf`){let{cleanup:e}=await r.renderPdfInContainer(o,t,{loadingText:u.attachmentPreviewPdfRendering,loadMoreHint:u.attachmentPreviewPdfLoadMore,onPageCount:s});c.current=e}else if(n===`excel`){let{cleanup:e,truncated:n}=await r.renderExcelInContainer(o,t,{truncationNotice:u.attachmentPreviewExcelTruncated.replaceAll(`{rows}`,`500`).replaceAll(`{cols}`,`64`)});c.current=e,l||p(n)}else if(n===`docx`){let{cleanup:e}=await r.renderDocxInContainer(o,t);c.current=e}}catch(e){l||d(e instanceof Error?e.message:String(e))}})(),()=>{l=!0,c.current?.(),c.current=null}},[t,n,o,r,e,s]),{error:l,excelTruncated:f}}function y(e){let t=(0,d.c)(12),{props:n,message:r}=e,i;t[0]===n.language?i=t[1]:(i=a(n.language),t[0]=n.language,t[1]=i);let o=i,s=n.descriptor.context===`workspace`,l=!!n.actions.onOpenWithSystemApp&&(n.actions.canOpenWithSystemApp??!0)&&s,u=s?o.workspace.openSystemApp:void 0,f=s?o.workspace.chooseApp:void 0,m;return t[2]!==o.chat.attachmentPreviewDownloadFull||t[3]!==r||t[4]!==n.actions.canChooseOpenWithApp||t[5]!==n.actions.onChooseOpenWithApp||t[6]!==n.actions.onDownload||t[7]!==n.actions.onOpenWithSystemApp||t[8]!==l||t[9]!==u||t[10]!==f?(m=(0,p.jsx)(c,{message:r,downloadLabel:o.chat.attachmentPreviewDownloadFull,onDownload:n.actions.onDownload,openSystemLabel:u,onOpenWithSystemApp:n.actions.onOpenWithSystemApp,canOpenWithSystemApp:l,chooseAppLabel:f,onChooseOpenWithApp:n.actions.onChooseOpenWithApp,canChooseOpenWithApp:n.actions.canChooseOpenWithApp}),t[2]=o.chat.attachmentPreviewDownloadFull,t[3]=r,t[4]=n.actions.canChooseOpenWithApp,t[5]=n.actions.onChooseOpenWithApp,t[6]=n.actions.onDownload,t[7]=n.actions.onOpenWithSystemApp,t[8]=l,t[9]=u,t[10]=f,t[11]=m):m=t[11],m}function b(e){let t=a(e.language);return e.descriptor.context===`workspace`?t.workspace.openElsewhereHint:t.chat.attachmentPreviewOpenElsewhereHint}function x(e){let t=(0,d.c)(24),n;bb0:{if(!e.binaryBuffer){n=null;break bb0}let r;if(t[0]!==e.binaryBuffer||t[1]!==e.descriptor.fileName||t[2]!==e.descriptor.mimeType){let n=o(e.descriptor.fileName)??e.descriptor.mimeType??`image/png`;r=new Blob([e.binaryBuffer],{type:n}),t[0]=e.binaryBuffer,t[1]=e.descriptor.fileName,t[2]=e.descriptor.mimeType,t[3]=r}else r=t[3];n=r}let r=l(n),i;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(i={x:0,y:0},t[4]=i):i=t[4];let[a,s]=(0,u.useState)(i),c=(0,u.useRef)(null),f=(0,u.useRef)(null),m=e.controls?.zoom??1,h=e.controls?.rotation??0,g;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s({x:0,y:0})},t[5]=g):g=t[5];let _;if(t[6]!==e.descriptor.id||t[7]!==h?(_=[e.descriptor.id,h],t[6]=e.descriptor.id,t[7]=h,t[8]=_):_=t[8],(0,u.useEffect)(g,_),!r)return null;let v;t[9]!==a.x||t[10]!==a.y?(v=e=>{e.button===0&&(c.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY,ox:a.x,oy:a.y},e.currentTarget.setPointerCapture(e.pointerId))},t[9]=a.x,t[10]=a.y,t[11]=v):v=t[11];let y,b,x;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(y=e=>{let t=c.current;!t||t.pointerId!==e.pointerId||s({x:t.ox+e.clientX-t.x,y:t.oy+e.clientY-t.y})},b=e=>{c.current?.pointerId===e.pointerId&&(c.current=null)},x=e=>{c.current?.pointerId===e.pointerId&&(c.current=null)},t[12]=y,t[13]=b,t[14]=x):(y=t[12],b=t[13],x=t[14]);let S=`translate(${a.x}px, ${a.y}px) scale(${m}) rotate(${h}deg)`,C=m>1?`grab`:`default`,w;t[15]!==S||t[16]!==C?(w={transform:S,cursor:C},t[15]=S,t[16]=C,t[17]=w):w=t[17];let T;t[18]!==r||t[19]!==w?(T=(0,p.jsx)(`img`,{src:r,alt:``,draggable:!1,className:`max-h-full max-w-full select-none object-contain transition-transform duration-100`,style:w}),t[18]=r,t[19]=w,t[20]=T):T=t[20];let E;return t[21]!==T||t[22]!==v?(E=(0,p.jsx)(`div`,{ref:f,className:`flex min-h-0 flex-1 touch-none items-center justify-center overflow-hidden bg-surface-base px-3 py-4 dark:bg-surface-hover/20`,onPointerDown:v,onPointerMove:y,onPointerUp:b,onPointerCancel:x,children:T}),t[21]=T,t[22]=v,t[23]=E):E=t[23],E}function S(e){let t=(0,d.c)(2),n;return t[0]===e?n=t[1]:(n=(0,p.jsx)(T,{...e,kind:`pdf`}),t[0]=e,t[1]=n),n}function C(e){let t=(0,d.c)(2),n;return t[0]===e?n=t[1]:(n=(0,p.jsx)(T,{...e,kind:`docx`}),t[0]=e,t[1]=n),n}function w(e){let t=(0,d.c)(2),n;return t[0]===e?n=t[1]:(n=(0,p.jsx)(T,{...e,kind:`excel`}),t[0]=e,t[1]=n),n}function T(e){let t=(0,d.c)(31),n=(0,u.useRef)(null),[r,i]=(0,u.useState)(null),o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=e=>{n.current=e,i(e)},t[0]=o):o=t[0];let s=o,c=e.kind===`pdf`?e.controls?.setPageCount:void 0,l;t[1]!==r||t[2]!==e.binaryBuffer||t[3]!==e.descriptor.id||t[4]!==e.kind||t[5]!==e.language||t[6]!==c?(l={language:e.language,buffer:e.binaryBuffer,kind:e.kind,fileKey:e.descriptor.id,containerEl:r,onPdfPageCount:c},t[1]=r,t[2]=e.binaryBuffer,t[3]=e.descriptor.id,t[4]=e.kind,t[5]=e.language,t[6]=c,t[7]=l):l=t[7];let{error:f,excelTruncated:m}=v(l),h=a(e.language),g=e.kind===`pdf`?e.controls?.zoom??1:1,_=e.kind===`pdf`?e.controls?.rotation??0:0,x=e.kind===`pdf`?e.controls?.page??1:1,S,C;t[8]!==e.kind||t[9]!==_||t[10]!==g?(S=()=>{e.kind!==`pdf`||!n.current||(n.current.style.setProperty(`--xopc-preview-pdf-zoom`,String(g)),n.current.style.setProperty(`--xopc-preview-pdf-rotation`,`${_}deg`),n.current.querySelectorAll(`[data-pdf-page]`).forEach(e=>{let t=e.dataset.pdfBaseHeight??(e.offsetHeight>0?String(e.offsetHeight):void 0);t&&(e.dataset.pdfBaseHeight=t,e.style.height=`${Number(t)*g}px`),e.style.transformOrigin=`top center`,e.style.transform=`scale(${g}) rotate(${_}deg)`,e.style.marginBottom=g===1?``:`${Math.max(16,24*g)}px`}))},C=[e.kind,_,g],t[8]=e.kind,t[9]=_,t[10]=g,t[11]=S,t[12]=C):(S=t[11],C=t[12]),(0,u.useEffect)(S,C);let w,T;if(t[13]!==x||t[14]!==e.kind?(w=()=>{e.kind!==`pdf`||!n.current||n.current.querySelector(`[data-pdf-page="${x}"]`)?.scrollIntoView({block:`start`})},T=[x,e.kind],t[13]=x,t[14]=e.kind,t[15]=w,t[16]=T):(w=t[15],T=t[16]),(0,u.useEffect)(w,T),f){let n;t[17]===e?n=t[18]:(n=b(e),t[17]=e,t[18]=n);let r;t[19]!==e||t[20]!==n?(r=(0,p.jsx)(y,{props:e,message:n}),t[19]=e,t[20]=n,t[21]=r):r=t[21];let i;t[22]===f?i=t[23]:(i=(0,p.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}),t[22]=f,t[23]=i);let a;return t[24]!==r||t[25]!==i?(a=(0,p.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto p-4`,children:[r,i]}),t[24]=r,t[25]=i,t[26]=a):a=t[26],a}if(e.kind===`excel`){let n=m?(0,p.jsx)(y,{props:e,message:h.chat.attachmentPreviewExcelTruncated.replaceAll(`{rows}`,`500`).replaceAll(`{cols}`,`64`)}):null,r;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,p.jsx)(`div`,{ref:s,className:`docx-preview-host min-h-0 flex-1 overflow-auto rounded-lg border border-edge-subtle bg-surface-panel p-2 dark:border-edge`}),t[27]=r):r=t[27];let i;return t[28]===n?i=t[29]:(i=(0,p.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-2 overflow-hidden px-2 pb-2 pt-1 sm:px-4`,children:[n,r]}),t[28]=n,t[29]=i),i}let E;return t[30]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,p.jsx)(`div`,{ref:s,className:`docx-preview-host min-h-0 flex-1 overflow-auto rounded-lg border border-edge-subtle bg-surface-panel p-2 dark:border-edge`}),t[30]=E):E=t[30],E}function E(e){let t=(0,d.c)(23),n;t[0]===e.language?n=t[1]:(n=a(e.language),t[0]=e.language,t[1]=n);let r=n,i=e.extractedText||r.chat.attachmentPreviewNoText,o=!!e.extractedTextTruncated||i.length>3e5,c;t[2]===i?c=t[3]:(c=i.length>3e5?i.slice(0,s):i,t[2]=i,t[3]=c);let l=c,u;t[4]!==r.chat.attachmentPreviewOpenElsewhereTruncated||t[5]!==e||t[6]!==o?(u=o?(0,p.jsx)(y,{props:e,message:r.chat.attachmentPreviewOpenElsewhereTruncated}):null,t[4]=r.chat.attachmentPreviewOpenElsewhereTruncated,t[5]=e,t[6]=o,t[7]=u):u=t[7];let f;t[8]!==r.chat.attachmentPreviewPptxTruncated||t[9]!==o?(f=o?(0,p.jsx)(`p`,{className:`mb-2 border-b border-edge-subtle pb-2 text-xs text-fg-muted dark:border-edge`,children:r.chat.attachmentPreviewPptxTruncated}):null,t[8]=r.chat.attachmentPreviewPptxTruncated,t[9]=o,t[10]=f):f=t[10];let h;t[11]===r.chat.attachmentPreviewPptxSlide?h=t[12]:(h=e=>r.chat.attachmentPreviewPptxSlide.replaceAll(`{n}`,String(e)),t[11]=r.chat.attachmentPreviewPptxSlide,t[12]=h);let g;t[13]!==r.chat.attachmentPreviewPptxEmptySlide||t[14]!==h||t[15]!==l?(g=(0,p.jsx)(m,{text:l,slideLabel:h,emptySlideLabel:r.chat.attachmentPreviewPptxEmptySlide}),t[13]=r.chat.attachmentPreviewPptxEmptySlide,t[14]=h,t[15]=l,t[16]=g):g=t[16];let _;t[17]!==f||t[18]!==g?(_=(0,p.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:[f,g]}),t[17]=f,t[18]=g,t[19]=_):_=t[19];let v;return t[20]!==u||t[21]!==_?(v=(0,p.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-2 overflow-hidden px-2 pb-2 pt-1 sm:px-4`,children:[u,_]}),t[20]=u,t[21]=_,t[22]=v):v=t[22],v}export{C as DocxPreviewPluginView,x as InteractiveImagePreview,S as PdfPreviewPluginView,E as PptxPreviewPluginView,w as SpreadsheetPreviewPluginView};
2
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{t as i}from"./preload-helper-zJ_50EbN.js";import{t as a}from"./messages-BuT0SR1R.js";import{$a as o,Za as s}from"./index-BuqGh2SW.js";import{t as c}from"./preview-open-alternatives-CvjuvABg.js";import{t as l}from"./use-blob-object-url-D4BFuzZB.js";var u=e(t(),1),d=n();function f(e){let t=e.trim(),n=t.match(/^<pptx\s+filename="([^"]*)">\s*/),r=t;n&&(r=t.slice(n[0].length),r=r.replace(/\s*<\/pptx>\s*$/u,``).trim());let i=[],a=/<slide number="(\d+)">([\s\S]*?)<\/slide>/gu,o;for(;(o=a.exec(r))!==null;){let e=Number.parseInt(o[1],10),t=o[2].trim();i.push({slideNumber:e,text:t})}let s=[],c=/<!--([\s\S]*?)-->/gu,l;for(;(l=c.exec(r))!==null;)s.push(l[1].trim());return i.length===0?{ok:!1,raw:e}:{ok:!0,slides:i,notes:s}}var p=r();function m(e){let t=(0,d.c)(13),{text:n,slideLabel:r,emptySlideLabel:i}=e,a;t[0]===n?a=t[1]:(a=f(n),t[0]=n,t[1]=a);let o=a;if(!o.ok){let e;return t[2]===o.raw?e=t[3]:(e=(0,p.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-fg`,children:o.raw}),t[2]=o.raw,t[3]=e),e}let s;if(t[4]!==i||t[5]!==o.notes||t[6]!==o.slides||t[7]!==r){let e=[];if(o.notes.length>0){let n;t[9]===o.notes?n=t[10]:(n=o.notes.map(h),t[9]=o.notes,t[10]=n);let r;t[11]===n?r=t[12]:(r=(0,p.jsx)(`div`,{className:`mb-2 border-b border-edge-subtle pb-2 dark:border-edge`,role:`status`,children:n},`notes`),t[11]=n,t[12]=r),e.push(r)}for(let t of o.slides)e.push((0,p.jsxs)(`section`,{className:`rounded-lg border border-edge-subtle bg-surface-panel p-3 dark:border-edge`,children:[(0,p.jsx)(`h3`,{className:`mb-2 text-sm font-semibold text-fg`,children:r(t.slideNumber)}),(0,p.jsx)(`div`,{className:`whitespace-pre-wrap text-sm leading-relaxed text-fg`,children:t.text.length>0?t.text:i})]},t.slideNumber));s=(0,p.jsx)(`div`,{className:`flex flex-col gap-3`,children:e}),t[4]=i,t[5]=o.notes,t[6]=o.slides,t[7]=r,t[8]=s}else s=t[8];return s}function h(e){return(0,p.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e},e)}function g(e,t){return t===`pdf`?a(e).chat.attachmentPreviewPdfRendering:e===`zh`?t===`excel`?`正在加载电子表格…`:`正在加载文档…`:t===`excel`?`Loading spreadsheet...`:`Loading document...`}function _(e,t){e.innerHTML=``;let n=document.createElement(`p`);n.className=`p-4 text-sm text-fg-muted`,n.textContent=t,e.appendChild(n)}function v({language:e,buffer:t,kind:n,fileKey:r,containerEl:o,onPdfPageCount:s}){let c=(0,u.useRef)(null),[l,d]=(0,u.useState)(null),[f,p]=(0,u.useState)(!1);return(0,u.useLayoutEffect)(()=>{if(c.current?.(),c.current=null,d(null),p(!1),!t||!n||!o||!r)return;let l=!1;return _(o,g(e,n)),(async()=>{try{let r=await i(()=>import(`./attachment-preview-renderer-DonnL2dL.js`),__vite__mapDeps([0,1,2]));if(l)return;let u=a(e).chat;if(n===`pdf`){let{cleanup:e}=await r.renderPdfInContainer(o,t,{loadingText:u.attachmentPreviewPdfRendering,loadMoreHint:u.attachmentPreviewPdfLoadMore,onPageCount:s});c.current=e}else if(n===`excel`){let{cleanup:e,truncated:n}=await r.renderExcelInContainer(o,t,{truncationNotice:u.attachmentPreviewExcelTruncated.replaceAll(`{rows}`,`500`).replaceAll(`{cols}`,`64`)});c.current=e,l||p(n)}else if(n===`docx`){let{cleanup:e}=await r.renderDocxInContainer(o,t);c.current=e}}catch(e){l||d(e instanceof Error?e.message:String(e))}})(),()=>{l=!0,c.current?.(),c.current=null}},[t,n,o,r,e,s]),{error:l,excelTruncated:f}}function y(e){let t=(0,d.c)(12),{props:n,message:r}=e,i;t[0]===n.language?i=t[1]:(i=a(n.language),t[0]=n.language,t[1]=i);let o=i,s=n.descriptor.context===`workspace`,l=!!n.actions.onOpenWithSystemApp&&(n.actions.canOpenWithSystemApp??!0)&&s,u=s?o.workspace.openSystemApp:void 0,f=s?o.workspace.chooseApp:void 0,m;return t[2]!==o.chat.attachmentPreviewDownloadFull||t[3]!==r||t[4]!==n.actions.canChooseOpenWithApp||t[5]!==n.actions.onChooseOpenWithApp||t[6]!==n.actions.onDownload||t[7]!==n.actions.onOpenWithSystemApp||t[8]!==l||t[9]!==u||t[10]!==f?(m=(0,p.jsx)(c,{message:r,downloadLabel:o.chat.attachmentPreviewDownloadFull,onDownload:n.actions.onDownload,openSystemLabel:u,onOpenWithSystemApp:n.actions.onOpenWithSystemApp,canOpenWithSystemApp:l,chooseAppLabel:f,onChooseOpenWithApp:n.actions.onChooseOpenWithApp,canChooseOpenWithApp:n.actions.canChooseOpenWithApp}),t[2]=o.chat.attachmentPreviewDownloadFull,t[3]=r,t[4]=n.actions.canChooseOpenWithApp,t[5]=n.actions.onChooseOpenWithApp,t[6]=n.actions.onDownload,t[7]=n.actions.onOpenWithSystemApp,t[8]=l,t[9]=u,t[10]=f,t[11]=m):m=t[11],m}function b(e){let t=a(e.language);return e.descriptor.context===`workspace`?t.workspace.openElsewhereHint:t.chat.attachmentPreviewOpenElsewhereHint}function x(e){let t=(0,d.c)(24),n;bb0:{if(!e.binaryBuffer){n=null;break bb0}let r;if(t[0]!==e.binaryBuffer||t[1]!==e.descriptor.fileName||t[2]!==e.descriptor.mimeType){let n=o(e.descriptor.fileName)??e.descriptor.mimeType??`image/png`;r=new Blob([e.binaryBuffer],{type:n}),t[0]=e.binaryBuffer,t[1]=e.descriptor.fileName,t[2]=e.descriptor.mimeType,t[3]=r}else r=t[3];n=r}let r=l(n),i;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(i={x:0,y:0},t[4]=i):i=t[4];let[a,s]=(0,u.useState)(i),c=(0,u.useRef)(null),f=(0,u.useRef)(null),m=e.controls?.zoom??1,h=e.controls?.rotation??0,g;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{s({x:0,y:0})},t[5]=g):g=t[5];let _;if(t[6]!==e.descriptor.id||t[7]!==h?(_=[e.descriptor.id,h],t[6]=e.descriptor.id,t[7]=h,t[8]=_):_=t[8],(0,u.useEffect)(g,_),!r)return null;let v;t[9]!==a.x||t[10]!==a.y?(v=e=>{e.button===0&&(c.current={pointerId:e.pointerId,x:e.clientX,y:e.clientY,ox:a.x,oy:a.y},e.currentTarget.setPointerCapture(e.pointerId))},t[9]=a.x,t[10]=a.y,t[11]=v):v=t[11];let y,b,x;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(y=e=>{let t=c.current;!t||t.pointerId!==e.pointerId||s({x:t.ox+e.clientX-t.x,y:t.oy+e.clientY-t.y})},b=e=>{c.current?.pointerId===e.pointerId&&(c.current=null)},x=e=>{c.current?.pointerId===e.pointerId&&(c.current=null)},t[12]=y,t[13]=b,t[14]=x):(y=t[12],b=t[13],x=t[14]);let S=`translate(${a.x}px, ${a.y}px) scale(${m}) rotate(${h}deg)`,C=m>1?`grab`:`default`,w;t[15]!==S||t[16]!==C?(w={transform:S,cursor:C},t[15]=S,t[16]=C,t[17]=w):w=t[17];let T;t[18]!==r||t[19]!==w?(T=(0,p.jsx)(`img`,{src:r,alt:``,draggable:!1,className:`max-h-full max-w-full select-none object-contain transition-transform duration-100`,style:w}),t[18]=r,t[19]=w,t[20]=T):T=t[20];let E;return t[21]!==T||t[22]!==v?(E=(0,p.jsx)(`div`,{ref:f,className:`flex min-h-0 flex-1 touch-none items-center justify-center overflow-hidden bg-surface-base px-3 py-4 dark:bg-surface-hover/20`,onPointerDown:v,onPointerMove:y,onPointerUp:b,onPointerCancel:x,children:T}),t[21]=T,t[22]=v,t[23]=E):E=t[23],E}function S(e){let t=(0,d.c)(2),n;return t[0]===e?n=t[1]:(n=(0,p.jsx)(T,{...e,kind:`pdf`}),t[0]=e,t[1]=n),n}function C(e){let t=(0,d.c)(2),n;return t[0]===e?n=t[1]:(n=(0,p.jsx)(T,{...e,kind:`docx`}),t[0]=e,t[1]=n),n}function w(e){let t=(0,d.c)(2),n;return t[0]===e?n=t[1]:(n=(0,p.jsx)(T,{...e,kind:`excel`}),t[0]=e,t[1]=n),n}function T(e){let t=(0,d.c)(31),n=(0,u.useRef)(null),[r,i]=(0,u.useState)(null),o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=e=>{n.current=e,i(e)},t[0]=o):o=t[0];let s=o,c=e.kind===`pdf`?e.controls?.setPageCount:void 0,l;t[1]!==r||t[2]!==e.binaryBuffer||t[3]!==e.descriptor.id||t[4]!==e.kind||t[5]!==e.language||t[6]!==c?(l={language:e.language,buffer:e.binaryBuffer,kind:e.kind,fileKey:e.descriptor.id,containerEl:r,onPdfPageCount:c},t[1]=r,t[2]=e.binaryBuffer,t[3]=e.descriptor.id,t[4]=e.kind,t[5]=e.language,t[6]=c,t[7]=l):l=t[7];let{error:f,excelTruncated:m}=v(l),h=a(e.language),g=e.kind===`pdf`?e.controls?.zoom??1:1,_=e.kind===`pdf`?e.controls?.rotation??0:0,x=e.kind===`pdf`?e.controls?.page??1:1,S,C;t[8]!==e.kind||t[9]!==_||t[10]!==g?(S=()=>{e.kind!==`pdf`||!n.current||(n.current.style.setProperty(`--xopc-preview-pdf-zoom`,String(g)),n.current.style.setProperty(`--xopc-preview-pdf-rotation`,`${_}deg`),n.current.querySelectorAll(`[data-pdf-page]`).forEach(e=>{let t=e.dataset.pdfBaseHeight??(e.offsetHeight>0?String(e.offsetHeight):void 0);t&&(e.dataset.pdfBaseHeight=t,e.style.height=`${Number(t)*g}px`),e.style.transformOrigin=`top center`,e.style.transform=`scale(${g}) rotate(${_}deg)`,e.style.marginBottom=g===1?``:`${Math.max(16,24*g)}px`}))},C=[e.kind,_,g],t[8]=e.kind,t[9]=_,t[10]=g,t[11]=S,t[12]=C):(S=t[11],C=t[12]),(0,u.useEffect)(S,C);let w,T;if(t[13]!==x||t[14]!==e.kind?(w=()=>{e.kind!==`pdf`||!n.current||n.current.querySelector(`[data-pdf-page="${x}"]`)?.scrollIntoView({block:`start`})},T=[x,e.kind],t[13]=x,t[14]=e.kind,t[15]=w,t[16]=T):(w=t[15],T=t[16]),(0,u.useEffect)(w,T),f){let n;t[17]===e?n=t[18]:(n=b(e),t[17]=e,t[18]=n);let r;t[19]!==e||t[20]!==n?(r=(0,p.jsx)(y,{props:e,message:n}),t[19]=e,t[20]=n,t[21]=r):r=t[21];let i;t[22]===f?i=t[23]:(i=(0,p.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}),t[22]=f,t[23]=i);let a;return t[24]!==r||t[25]!==i?(a=(0,p.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto p-4`,children:[r,i]}),t[24]=r,t[25]=i,t[26]=a):a=t[26],a}if(e.kind===`excel`){let n=m?(0,p.jsx)(y,{props:e,message:h.chat.attachmentPreviewExcelTruncated.replaceAll(`{rows}`,`500`).replaceAll(`{cols}`,`64`)}):null,r;t[27]===Symbol.for(`react.memo_cache_sentinel`)?(r=(0,p.jsx)(`div`,{ref:s,className:`docx-preview-host min-h-0 flex-1 overflow-auto rounded-lg border border-edge-subtle bg-surface-panel p-2 dark:border-edge`}),t[27]=r):r=t[27];let i;return t[28]===n?i=t[29]:(i=(0,p.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-2 overflow-hidden px-2 pb-2 pt-1 sm:px-4`,children:[n,r]}),t[28]=n,t[29]=i),i}let E;return t[30]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,p.jsx)(`div`,{ref:s,className:`docx-preview-host min-h-0 flex-1 overflow-auto rounded-lg border border-edge-subtle bg-surface-panel p-2 dark:border-edge`}),t[30]=E):E=t[30],E}function E(e){let t=(0,d.c)(23),n;t[0]===e.language?n=t[1]:(n=a(e.language),t[0]=e.language,t[1]=n);let r=n,i=e.extractedText||r.chat.attachmentPreviewNoText,o=!!e.extractedTextTruncated||i.length>3e5,c;t[2]===i?c=t[3]:(c=i.length>3e5?i.slice(0,s):i,t[2]=i,t[3]=c);let l=c,u;t[4]!==r.chat.attachmentPreviewOpenElsewhereTruncated||t[5]!==e||t[6]!==o?(u=o?(0,p.jsx)(y,{props:e,message:r.chat.attachmentPreviewOpenElsewhereTruncated}):null,t[4]=r.chat.attachmentPreviewOpenElsewhereTruncated,t[5]=e,t[6]=o,t[7]=u):u=t[7];let f;t[8]!==r.chat.attachmentPreviewPptxTruncated||t[9]!==o?(f=o?(0,p.jsx)(`p`,{className:`mb-2 border-b border-edge-subtle pb-2 text-xs text-fg-muted dark:border-edge`,children:r.chat.attachmentPreviewPptxTruncated}):null,t[8]=r.chat.attachmentPreviewPptxTruncated,t[9]=o,t[10]=f):f=t[10];let h;t[11]===r.chat.attachmentPreviewPptxSlide?h=t[12]:(h=e=>r.chat.attachmentPreviewPptxSlide.replaceAll(`{n}`,String(e)),t[11]=r.chat.attachmentPreviewPptxSlide,t[12]=h);let g;t[13]!==r.chat.attachmentPreviewPptxEmptySlide||t[14]!==h||t[15]!==l?(g=(0,p.jsx)(m,{text:l,slideLabel:h,emptySlideLabel:r.chat.attachmentPreviewPptxEmptySlide}),t[13]=r.chat.attachmentPreviewPptxEmptySlide,t[14]=h,t[15]=l,t[16]=g):g=t[16];let _;t[17]!==f||t[18]!==g?(_=(0,p.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:[f,g]}),t[17]=f,t[18]=g,t[19]=_):_=t[19];let v;return t[20]!==u||t[21]!==_?(v=(0,p.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-2 overflow-hidden px-2 pb-2 pt-1 sm:px-4`,children:[u,_]}),t[20]=u,t[21]=_,t[22]=v):v=t[22],v}export{C as DocxPreviewPluginView,x as InteractiveImagePreview,S as PdfPreviewPluginView,E as PptxPreviewPluginView,w as SpreadsheetPreviewPluginView};
@@ -1,4 +1,4 @@
1
- import{i as e,n as t,t as n}from"./rolldown-runtime-aKtaBQYM.js";import{a as r,i,n as a,t as o}from"./vendor-react-BOUWij0V.js";import{t as s}from"./cn-BQ_8x0bT.js";import{t as c}from"./messages-BuT0SR1R.js";import{n as l}from"./locale-store-C_M71MK9.js";import{s as u}from"./vendor-swr-BIWyz7Rc.js";import{Bc as d,Cc as f,Cr as p,Er as m,Gc as h,Hc as g,Il as _,Ls as v,Mc as y,Or as b,Ro as x,Tr as S,Uc as C,_c as ee,al as te,dl as ne,fl as re,jc as ie,ks as ae,lc as oe,nr as se,tl as ce,uc as le,ul as ue,uu as de,zc as fe}from"./index-EXa_i6BT.js";import{C as pe,S as me}from"./vendor-codemirror--gTq3YAI.js";import{t as he}from"./with-selector-aYPsXwdl.js";import{n as ge}from"./notes-workbench-D-EAhXv1.js";var w=e(r(),1),_e=e(i(),1),T=o(),ve=u();function E(e){this.content=e}E.prototype={constructor:E,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return-1},get:function(e){var t=this.find(e);return t==-1?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,i=r.find(e),a=r.content.slice();return i==-1?a.push(n||e,t):(a[i+1]=t,n&&(a[i]=n)),new E(a)},remove:function(e){var t=this.find(e);if(t==-1)return this;var n=this.content.slice();return n.splice(t,2),new E(n)},addToStart:function(e,t){return new E([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new E(n)},addBefore:function(e,t,n){var r=this.remove(t),i=r.content.slice(),a=r.find(e);return i.splice(a==-1?i.length:a,0,t,n),new E(i)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return e=E.from(e),e.size?new E(e.content.concat(this.subtract(e).content)):this},append:function(e){return e=E.from(e),e.size?new E(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=E.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},E.from=function(e){if(e instanceof E)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new E(t)};function ye(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){let e=i.text,t=a.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r<e.length&&r<t.length&&Se(e.charCodeAt(r-1))&&xe(e.charCodeAt(r))&&n--,n}if(i.content.size||a.content.size){let e=ye(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function be(e,t,n,r){for(let i=e.childCount,a=t.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let o=e.child(--i),s=t.child(--a),c=o.nodeSize;if(o==s){n-=c,r-=c;continue}if(!o.sameMarkup(s))return{a:n,b:r};if(o.isText&&o.text!=s.text){let e=o.text,t=s.text,i=e.length,a=t.length;for(;i>0&&a>0&&e[i-1]==t[a-1];)i--,a--,n--,r--;return i&&a&&i<e.length&&Se(e.charCodeAt(i-1))&&xe(e.charCodeAt(i))&&(n++,r++),{a:n,b:r}}if(o.content.size||s.content.size){let e=be(o.content,s.content,n-1,r-1);if(e)return e}n-=c,r-=c}}function xe(e){return e>=56320&&e<57344}function Se(e){return e>=55296&&e<56320}var D=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let a=0,o=0;o<t;a++){let s=this.content[a],c=o+s.nodeSize;if(c>e&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);a<t.content.length;a++)i.push(t.content[a]);return new e(i,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],i=0;if(n>t)for(let e=0,a=0;a<n;e++){let o=this.content[e],s=a+o.nodeSize;s>t&&((a<t||s>n)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw RangeError(`Index `+e+` out of range for `+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return ye(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return be(this,e,t,n)}findIndex(e){if(e==0)return we(0,e);if(e==this.size)return we(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?we(t+1,i):we(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;e<t.length;e++){let i=t[e];r+=i.nodeSize,e&&i.isText&&t[e-1].sameMarkup(i)?(n||=t.slice(0,e),n[n.length-1]=i.withText(n[n.length-1].text+i.text)):n&&n.push(i)}return new e(n||t,r)}static from(t){if(!t)return e.empty;if(t instanceof e)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new e([t],t.nodeSize);throw RangeError(`Can not convert `+t+` to a Fragment`+(t.nodesBetween?` (looks like multiple versions of prosemirror-model were loaded)`:``))}};D.empty=new D([],0);var Ce={index:0,offset:0};function we(e,t){return Ce.index=e,Ce.offset=t,Ce}function Te(e,t){if(e===t)return!0;if(!(e&&typeof e==`object`)||!(t&&typeof t==`object`))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!Te(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!Te(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var O=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||=e.slice(0,r);else if(i.type.excludes(this.type))return e;else !n&&i.type.rank>this.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Te(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Mark.fromJSON`);let n=e.marks[t.type];if(!n)throw RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};O.none=[];var k=class extends Error{},A=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=De(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(Ee(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(D.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};A.empty=new A(D.empty,0,0);function Ee(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(Ee(a.content,t-i-1,n-i-1)))}function De(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=De(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function Oe(e,t,n){if(n.openStart>e.depth)throw new k(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new k(`Inconsistent open depths`);return ke(e,t,n,0)}function ke(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r<e.depth-n.openStart){let o=ke(e,t,n,r+1);return a.copy(a.content.replaceChild(i,o))}else if(!n.content.size)return Pe(a,Ie(e,t,r));else if(!n.openStart&&!n.openEnd&&e.depth==r&&t.depth==r){let r=e.parent,i=r.content;return Pe(r,i.cut(0,e.parentOffset).append(n.content).append(i.cut(t.parentOffset)))}else{let{start:i,end:o}=Le(n,e);return Pe(a,Fe(e,i,o,t,r))}}function Ae(e,t){if(!t.type.compatibleContent(e.type))throw new k(`Cannot join `+t.type.name+` onto `+e.type.name)}function je(e,t,n){let r=e.node(n);return Ae(r,t.node(n)),r}function Me(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function Ne(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(Me(e.nodeAfter,r),a++));for(let e=a;e<o;e++)Me(i.child(e),r);t&&t.depth==n&&t.textOffset&&Me(t.nodeBefore,r)}function Pe(e,t){if(!e.type.validContent(t))throw new k(`Invalid content for node `+e.type.name);return e.copy(t)}function Fe(e,t,n,r,i){let a=e.depth>i&&je(e,t,i+1),o=r.depth>i&&je(n,r,i+1),s=[];return Ne(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(Ae(a,o),Me(Pe(a,Fe(e,t,n,r,i+1)),s)):(a&&Me(Pe(a,Ie(e,t,i+1)),s),Ne(t,n,i,s),o&&Me(Pe(o,Ie(n,r,i+1)),s)),Ne(r,null,i,s),new D(s)}function Ie(e,t,n){let r=[];return Ne(null,e,n,r),e.depth>n&&Me(Pe(je(e,t,n+1),Ie(e,t,n+1)),r),Ne(t,null,n,r),new D(r)}function Le(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(D.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var Re=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return O.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var a=0;a<i.length;a++)i[a].type.spec.inclusive===!1&&(!r||!i[a].isInSet(r.marks))&&(i=i[a--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)n[i].type.spec.inclusive===!1&&(!r||!n[i].isInSet(r.marks))&&(n=n[i--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new He(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e=``;for(let t=1;t<=this.depth;t++)e+=(e?`/`:``)+this.node(t).type.name+`_`+this.index(t-1);return e+`:`+this.parentOffset}static resolve(t,n){if(!(n>=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=Ve.get(t);if(r)for(let e=0;e<r.elts.length;e++){let t=r.elts[e];if(t.pos==n)return t}else Ve.set(t,r=new ze);let i=r.elts[r.i]=e.resolve(t,n);return r.i=(r.i+1)%Be,i}},ze=class{constructor(){this.elts=[],this.i=0}},Be=12,Ve=new WeakMap,He=class{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},Ue=Object.create(null),We=class e{constructor(e,t,n,r=O.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||D.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,``)}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&Te(this.attrs,t||e.defaultAttrs||Ue)&&O.sameSet(this.marks,n||O.none)}copy(t=null){return t==this.content?this:new e(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.content,t)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return A.empty;let r=this.resolve(e),i=this.resolve(t),a=n?0:r.sharedDepth(t),o=r.start(a);return new A(r.node(a).content.cut(r.pos-o,i.pos-o),r.depth-a,i.depth-a)}replace(e,t,n){return Oe(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return Re.resolveCached(this,e)}resolveNoCache(e){return Re.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),Ke(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=D.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),a=i&&i.matchFragment(this.content,t);return a?a.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=O.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!O.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=D.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};We.prototype.text=void 0;var Ge=class e extends We{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Ke(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Ke(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var qe=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Je(t,n);if(r.next==null)return e.empty;let i=Ye(r);r.next&&r.err(`Unexpected trailing text`);let a=at(nt(i));return ot(a,r),a}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];function i(a,o){let s=a.matchFragment(e,n);if(s&&(!t||s.validEnd))return D.from(o.map(e=>e.createAndFill()));for(let e=0;e<a.next.length;e++){let{type:t,next:n}=a.next[e];if(!(t.isText||t.hasRequiredAttrs())&&r.indexOf(n)==-1){r.push(n);let e=i(n,o.concat(t));if(e)return e}}return null}return i(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),i=r.match;if(i.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<i.next.length;e++){let{type:a,next:o}=i.next[e];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in t)&&(!r.type||o.validEnd)&&(n.push({match:a.contentMatch,type:a,via:r}),t[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r<n.next.length;r++)e.indexOf(n.next[r].next)==-1&&t(n.next[r].next)}return t(this),e.map((t,n)=>{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n<t.next.length;n++)r+=(n?`, `:``)+t.next[n].type.name+`->`+e.indexOf(t.next[n].next);return r}).join(`
1
+ import{i as e,n as t,t as n}from"./rolldown-runtime-aKtaBQYM.js";import{a as r,i,n as a,t as o}from"./vendor-react-BOUWij0V.js";import{t as s}from"./cn-BQ_8x0bT.js";import{t as c}from"./messages-BuT0SR1R.js";import{n as l}from"./locale-store-C_M71MK9.js";import{s as u}from"./vendor-swr-BIWyz7Rc.js";import{Bc as d,Cc as f,Cr as p,Er as m,Gc as h,Hc as g,Il as _,Ls as v,Mc as y,Or as b,Ro as x,Tr as S,Uc as C,_c as ee,al as te,dl as ne,fl as re,jc as ie,ks as ae,lc as oe,nr as se,tl as ce,uc as le,ul as ue,uu as de,zc as fe}from"./index-BuqGh2SW.js";import{C as pe,S as me}from"./vendor-codemirror--gTq3YAI.js";import{t as he}from"./with-selector-aYPsXwdl.js";import{n as ge}from"./notes-workbench-DQEAZTA5.js";var w=e(r(),1),_e=e(i(),1),T=o(),ve=u();function E(e){this.content=e}E.prototype={constructor:E,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return-1},get:function(e){var t=this.find(e);return t==-1?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,i=r.find(e),a=r.content.slice();return i==-1?a.push(n||e,t):(a[i+1]=t,n&&(a[i]=n)),new E(a)},remove:function(e){var t=this.find(e);if(t==-1)return this;var n=this.content.slice();return n.splice(t,2),new E(n)},addToStart:function(e,t){return new E([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new E(n)},addBefore:function(e,t,n){var r=this.remove(t),i=r.content.slice(),a=r.find(e);return i.splice(a==-1?i.length:a,0,t,n),new E(i)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return e=E.from(e),e.size?new E(e.content.concat(this.subtract(e).content)):this},append:function(e){return e=E.from(e),e.size?new E(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=E.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},E.from=function(e){if(e instanceof E)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new E(t)};function ye(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let i=e.child(r),a=t.child(r);if(i==a){n+=i.nodeSize;continue}if(!i.sameMarkup(a))return n;if(i.isText&&i.text!=a.text){let e=i.text,t=a.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r<e.length&&r<t.length&&Se(e.charCodeAt(r-1))&&xe(e.charCodeAt(r))&&n--,n}if(i.content.size||a.content.size){let e=ye(i.content,a.content,n+1);if(e!=null)return e}n+=i.nodeSize}}function be(e,t,n,r){for(let i=e.childCount,a=t.childCount;;){if(i==0||a==0)return i==a?null:{a:n,b:r};let o=e.child(--i),s=t.child(--a),c=o.nodeSize;if(o==s){n-=c,r-=c;continue}if(!o.sameMarkup(s))return{a:n,b:r};if(o.isText&&o.text!=s.text){let e=o.text,t=s.text,i=e.length,a=t.length;for(;i>0&&a>0&&e[i-1]==t[a-1];)i--,a--,n--,r--;return i&&a&&i<e.length&&Se(e.charCodeAt(i-1))&&xe(e.charCodeAt(i))&&(n++,r++),{a:n,b:r}}if(o.content.size||s.content.size){let e=be(o.content,s.content,n-1,r-1);if(e)return e}n-=c,r-=c}}function xe(e){return e>=56320&&e<57344}function Se(e){return e>=55296&&e<56320}var D=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,i){for(let a=0,o=0;o<t;a++){let s=this.content[a],c=o+s.nodeSize;if(c>e&&n(s,r+o,i||null,a)!==!1&&s.content.size){let i=o+1;s.nodesBetween(Math.max(0,e-i),Math.min(s.content.size,t-i),n,r+i)}o=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let i=``,a=!0;return this.nodesBetween(e,t,(o,s)=>{let c=o.isText?o.text.slice(Math.max(e,s)-s,t-s):o.isLeaf?r?typeof r==`function`?r(o):r:o.type.spec.leafText?o.type.spec.leafText(o):``:``;o.isBlock&&(o.isLeaf&&c||o.isTextblock)&&n&&(a?a=!1:i+=n),i+=c},0),i}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,i=this.content.slice(),a=0;for(n.isText&&n.sameMarkup(r)&&(i[i.length-1]=n.withText(n.text+r.text),a=1);a<t.content.length;a++)i.push(t.content[a]);return new e(i,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],i=0;if(n>t)for(let e=0,a=0;a<n;e++){let o=this.content[e],s=a+o.nodeSize;s>t&&((a<t||s>n)&&(o=o.isText?o.cut(Math.max(0,t-a),Math.min(o.text.length,n-a)):o.cut(Math.max(0,t-a-1),Math.min(o.content.size,n-a-1))),r.push(o),i+=o.nodeSize),a=s}return new e(r,i)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let i=this.content.slice(),a=this.size+n.nodeSize-r.nodeSize;return i[t]=n,new e(i,a)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw RangeError(`Index `+e+` out of range for `+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return ye(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return be(this,e,t,n)}findIndex(e){if(e==0)return we(0,e);if(e==this.size)return we(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),i=n+r.nodeSize;if(i>=e)return i==e?we(t+1,i):we(t,n);n=i}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;e<t.length;e++){let i=t[e];r+=i.nodeSize,e&&i.isText&&t[e-1].sameMarkup(i)?(n||=t.slice(0,e),n[n.length-1]=i.withText(n[n.length-1].text+i.text)):n&&n.push(i)}return new e(n||t,r)}static from(t){if(!t)return e.empty;if(t instanceof e)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new e([t],t.nodeSize);throw RangeError(`Can not convert `+t+` to a Fragment`+(t.nodesBetween?` (looks like multiple versions of prosemirror-model were loaded)`:``))}};D.empty=new D([],0);var Ce={index:0,offset:0};function we(e,t){return Ce.index=e,Ce.offset=t,Ce}function Te(e,t){if(e===t)return!0;if(!(e&&typeof e==`object`)||!(t&&typeof t==`object`))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!Te(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!Te(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var O=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))t||=e.slice(0,r);else if(i.type.excludes(this.type))return e;else !n&&i.type.rank>this.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(i)}return t||=e.slice(),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Te(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Mark.fromJSON`);let n=e.marks[t.type];if(!n)throw RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};O.none=[];var k=class extends Error{},A=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=De(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(Ee(this.content,t+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+`(`+this.openStart+`,`+this.openEnd+`)`}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(t,n){if(!n)return e.empty;let r=n.openStart||0,i=n.openEnd||0;if(typeof r!=`number`||typeof i!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(D.fromJSON(t,n.content),r,i)}static maxOpen(t,n=!0){let r=0,i=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)i++;return new e(t,r,i)}};A.empty=new A(D.empty,0,0);function Ee(e,t,n){let{index:r,offset:i}=e.findIndex(t),a=e.maybeChild(r),{index:o,offset:s}=e.findIndex(n);if(i==t||a.isText){if(s!=n&&!e.child(o).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=o)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,a.copy(Ee(a.content,t-i-1,n-i-1)))}function De(e,t,n,r,i,a){let{index:o,offset:s}=e.findIndex(t),c=e.maybeChild(o);if(s==t||c.isText)return a&&r<=0&&i<=0&&!a.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let l=De(c.content,t-s-1,n,o==0?r-1:0,o==e.childCount-1?i-1:0,c);return l&&e.replaceChild(o,c.copy(l))}function Oe(e,t,n){if(n.openStart>e.depth)throw new k(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new k(`Inconsistent open depths`);return ke(e,t,n,0)}function ke(e,t,n,r){let i=e.index(r),a=e.node(r);if(i==t.index(r)&&r<e.depth-n.openStart){let o=ke(e,t,n,r+1);return a.copy(a.content.replaceChild(i,o))}else if(!n.content.size)return Pe(a,Ie(e,t,r));else if(!n.openStart&&!n.openEnd&&e.depth==r&&t.depth==r){let r=e.parent,i=r.content;return Pe(r,i.cut(0,e.parentOffset).append(n.content).append(i.cut(t.parentOffset)))}else{let{start:i,end:o}=Le(n,e);return Pe(a,Fe(e,i,o,t,r))}}function Ae(e,t){if(!t.type.compatibleContent(e.type))throw new k(`Cannot join `+t.type.name+` onto `+e.type.name)}function je(e,t,n){let r=e.node(n);return Ae(r,t.node(n)),r}function Me(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function Ne(e,t,n,r){let i=(t||e).node(n),a=0,o=t?t.index(n):i.childCount;e&&(a=e.index(n),e.depth>n?a++:e.textOffset&&(Me(e.nodeAfter,r),a++));for(let e=a;e<o;e++)Me(i.child(e),r);t&&t.depth==n&&t.textOffset&&Me(t.nodeBefore,r)}function Pe(e,t){if(!e.type.validContent(t))throw new k(`Invalid content for node `+e.type.name);return e.copy(t)}function Fe(e,t,n,r,i){let a=e.depth>i&&je(e,t,i+1),o=r.depth>i&&je(n,r,i+1),s=[];return Ne(null,e,i,s),a&&o&&t.index(i)==n.index(i)?(Ae(a,o),Me(Pe(a,Fe(e,t,n,r,i+1)),s)):(a&&Me(Pe(a,Ie(e,t,i+1)),s),Ne(t,n,i,s),o&&Me(Pe(o,Ie(n,r,i+1)),s)),Ne(r,null,i,s),new D(s)}function Ie(e,t,n){let r=[];return Ne(null,e,n,r),e.depth>n&&Me(Pe(je(e,t,n+1),Ie(e,t,n+1)),r),Ne(t,null,n,r),new D(r)}function Le(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(D.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var Re=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position before the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw RangeError(`There is no position after the top-level node`);return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return O.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let i=n.marks;for(var a=0;a<i.length;a++)i[a].type.spec.inclusive===!1&&(!r||!i[a].isInSet(r.marks))&&(i=i[a--].removeFromSet(i));return i}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<n.length;i++)n[i].type.spec.inclusive===!1&&(!r||!n[i].isInSet(r.marks))&&(n=n[i--].removeFromSet(n));return n}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new He(this,e,n);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e=``;for(let t=1;t<=this.depth;t++)e+=(e?`/`:``)+this.node(t).type.name+`_`+this.index(t-1);return e+`:`+this.parentOffset}static resolve(t,n){if(!(n>=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],i=0,a=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(a),o=a-n;if(r.push(e,t,i+n),!o||(e=e.child(t),e.isText))break;a=o-1,i+=n+1}return new e(n,r,a)}static resolveCached(t,n){let r=Ve.get(t);if(r)for(let e=0;e<r.elts.length;e++){let t=r.elts[e];if(t.pos==n)return t}else Ve.set(t,r=new ze);let i=r.elts[r.i]=e.resolve(t,n);return r.i=(r.i+1)%Be,i}},ze=class{constructor(){this.elts=[],this.i=0}},Be=12,Ve=new WeakMap,He=class{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},Ue=Object.create(null),We=class e{constructor(e,t,n,r=O.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||D.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,``)}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&Te(this.attrs,t||e.defaultAttrs||Ue)&&O.sameSet(this.marks,n||O.none)}copy(t=null){return t==this.content?this:new e(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.content,t)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return A.empty;let r=this.resolve(e),i=this.resolve(t),a=n?0:r.sharedDepth(t),o=r.start(a);return new A(r.node(a).content.cut(r.pos-o,i.pos-o),r.depth-a,i.depth-a)}replace(e,t,n){return Oe(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return Re.resolveCached(this,e)}resolveNoCache(e){return Re.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),Ke(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=D.empty,r=0,i=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,r,i),o=a&&a.matchFragment(this.content,t);if(!o||!o.validEnd)return!1;for(let e=r;e<i;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(n),a=i&&i.matchFragment(this.content,t);return a?a.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=O.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!O.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=D.fromJSON(e,t.content),i=e.nodeType(t.type).create(t.attrs,r,n);return i.type.checkAttrs(i.attrs),i}};We.prototype.text=void 0;var Ge=class e extends We{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Ke(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Ke(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var qe=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new Je(t,n);if(r.next==null)return e.empty;let i=Ye(r);r.next&&r.err(`Unexpected trailing text`);let a=at(nt(i));return ot(a,r),a}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,n=e.childCount){let r=this;for(let i=t;r&&i<n;i++)r=r.matchType(e.child(i).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];function i(a,o){let s=a.matchFragment(e,n);if(s&&(!t||s.validEnd))return D.from(o.map(e=>e.createAndFill()));for(let e=0;e<a.next.length;e++){let{type:t,next:n}=a.next[e];if(!(t.isText||t.hasRequiredAttrs())&&r.indexOf(n)==-1){r.push(n);let e=i(n,o.concat(t));if(e)return e}}return null}return i(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),i=r.match;if(i.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<i.next.length;e++){let{type:a,next:o}=i.next[e];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in t)&&(!r.type||o.validEnd)&&(n.push({match:a.contentMatch,type:a,via:r}),t[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r<n.next.length;r++)e.indexOf(n.next[r].next)==-1&&t(n.next[r].next)}return t(this),e.map((t,n)=>{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n<t.next.length;n++)r+=(n?`, `:``)+t.next[n].type.name+`->`+e.indexOf(t.next[n].next);return r}).join(`
2
2
  `)}};qe.empty=new qe(!0);var Je=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==``&&this.tokens.pop(),this.tokens[0]==``&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw SyntaxError(e+` (in content expression '`+this.string+`')`)}};function Ye(e){let t=[];do t.push(Xe(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function Xe(e){let t=[];do t.push(Ze(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function Ze(e){let t=tt(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=$e(e,t);else break;return t}function Qe(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function $e(e,t){let n=Qe(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:Qe(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function et(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let i=[];for(let e in n){let r=n[e];r.isInGroup(t)&&i.push(r)}return i.length==0&&e.err(`No node type or group '`+t+`' found`),i}function tt(e){if(e.eat(`(`)){let t=Ye(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=et(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function nt(e){let t=[[]];return i(a(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let i={term:r,to:n};return t[e].push(i),i}function i(e,t){e.forEach(e=>e.to=t)}function a(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(a(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let o=a(e.exprs[r],t);if(r==e.exprs.length-1)return o;i(o,t=n())}else if(e.type==`star`){let o=n();return r(t,o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`plus`){let o=n();return i(a(e.expr,t),o),i(a(e.expr,o),o),[r(o)]}else if(e.type==`opt`)return[r(t)].concat(a(e.expr,t));else if(e.type==`range`){let o=t;for(let t=0;t<e.min;t++){let t=n();i(a(e.expr,o),t),o=t}if(e.max==-1)i(a(e.expr,o),o);else for(let t=e.min;t<e.max;t++){let t=n();r(o,t),i(a(e.expr,o),t),o=t}return[r(o)]}else if(e.type==`name`)return[r(t,void 0,e.value)];else throw Error(`Unknown expr type`)}}function rt(e,t){return t-e}function it(e,t){let n=[];return r(t),n.sort(rt);function r(t){let i=e[t];if(i.length==1&&!i[0].term)return r(i[0].to);n.push(t);for(let e=0;e<i.length;e++){let{term:t,to:a}=i[e];!t&&n.indexOf(a)==-1&&r(a)}}}function at(e){let t=Object.create(null);return n(it(e,0));function n(r){let i=[];r.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<i.length;e++)i[e][0]==t&&(r=i[e][1]);it(e,n).forEach(e=>{r||i.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let a=t[r.join(`,`)]=new qe(r.indexOf(e.length-1)>-1);for(let e=0;e<i.length;e++){let r=i[e][1].sort(rt);a.next.push({type:i[e][0],next:t[r.join(`,`)]||n(r)})}return a}}function ot(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],i=!e.validEnd,a=[];for(let t=0;t<e.next.length;t++){let{type:n,next:o}=e.next[t];a.push(n.name),i&&!(n.isText||n.hasRequiredAttrs())&&(i=!1),r.indexOf(o)==-1&&r.push(o)}i&&t.err(`Only non-generatable nodes (`+a.join(`, `)+`) in a required position (see https://prosemirror.net/docs/guide/#generatable)`)}}function st(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function ct(e,t){let n=Object.create(null);for(let r in e){let i=t&&t[r];if(i===void 0){let t=e[r];if(t.hasDefault)i=t.default;else throw RangeError(`No value supplied for attribute `+r)}n[r]=i}return n}function lt(e,t,n,r){for(let i in t)if(!(i in e))throw RangeError(`Unsupported attribute ${i} for ${n} of type ${r}`);for(let n in e)e[n].validate&&e[n].validate(t[n])}function ut(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new pt(e,r,t[r]);return n}var dt=class e{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(` `):[],this.attrs=ut(e,n.attrs),this.defaultAttrs=st(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e==`text`),this.isText=e==`text`}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==qe.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?`pre`:`normal`)}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:ct(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new We(this,this.computeAttrs(e),D.from(t),O.setFrom(n))}createChecked(e=null,t,n){return t=D.from(t),this.checkContent(t),new We(this,this.computeAttrs(e),t,O.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=D.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),i=r&&r.fillBefore(D.empty,!0);return i?new We(this,e,t.append(i),O.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){lt(this.attrs,e,`node`,this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||=e.slice(0,n);return t?t.length?t:O.none:e}static compile(t,n){let r=Object.create(null);t.forEach((t,i)=>r[t]=new e(t,n,i));let i=n.spec.topNode||`doc`;if(!r[i])throw RangeError(`Schema is missing its top node type ('`+i+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function ft(e,t,n){let r=n.split(`|`);return n=>{let i=n===null?`null`:typeof n;if(r.indexOf(i)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${i}`)}}var pt=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?ft(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},mt=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=ut(e,r.attrs),this.excluded=null;let i=st(this.attrs);this.instance=i?new O(this,i):null}create(e=null){return!e&&this.instance?this.instance:new O(this,ct(this.attrs,e))}static compile(t,n){let r=Object.create(null),i=0;return t.forEach((t,a)=>r[t]=new e(t,i++,n,a)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){lt(this.attrs,e,`mark`,this.name)}excludes(e){return this.excluded.indexOf(e)>-1}},ht=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=E.from(e.nodes),t.marks=E.from(e.marks||{}),this.nodes=dt.compile(this.spec.nodes,this),this.marks=mt.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,i=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=qe.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=i==`_`?null:i?gt(this,i.split(` `)):i==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:gt(this,n.split(` `))}this.nodeFromJSON=e=>We.fromJSON(this,e),this.markFromJSON=e=>O.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof dt))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new Ge(n,n.defaultAttrs,e,O.setFrom(t))}mark(e,t){return typeof e==`string`&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw RangeError(`Unknown node type: `+e);return t}};function gt(e,t){let n=[];for(let r=0;r<t.length;r++){let i=t[r],a=e.marks[i],o=a;if(a)n.push(a);else for(let t in e.marks){let r=e.marks[t];(i==`_`||r.spec.group&&r.spec.group.split(` `).indexOf(i)>-1)&&n.push(o=r)}if(!o)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function _t(e){return e.tag!=null}function vt(e){return e.style!=null}var yt=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(_t(e))this.tags.push(e);else if(vt(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new Ot(this,t,!1);return n.addAll(e,O.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Ot(this,t,!0);return n.addAll(e,O.none,t.from,t.to),A.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(At(e,n.tag)&&(n.namespace===void 0||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(t===!1)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let r=this.styles[i],a=r.style;if(!(a.indexOf(e)!=0||r.context&&!n.matchesContext(r.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((e.priority==null?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=jt(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=jt(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},bt={address:!0,article:!0,aside:!0,blockquote:!0,body:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},xt={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},St={ol:!0,ul:!0},Ct=1,wt=2,Tt=4;function Et(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?Ct:0)|(t===`full`?wt:0)}var Dt=class{constructor(e,t,n,r,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=a,this.content=[],this.activeMarks=O.none,this.match=i||(a&Tt?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(D.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Ct)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=D.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(D.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!bt.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},Ot=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,i,a=Et(null,t.preserveWhitespace,0)|(n?Tt:0);i=r?new Dt(r.type,r.attrs,O.none,!0,t.topMatch||r.type.contentMatch,a):n?new Dt(null,null,O.none,!0,null,a):new Dt(e.schema.topNodeType,null,O.none,!0,null,a),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,i=r.options&wt?`full`:this.localPreserveWS||(r.options&Ct)>0,{schema:a}=this.parser;if(i===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!i){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],i=e.previousSibling;(!t||i&&i.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(i===`full`)n=n.replace(/\r\n?/g,`
3
3
  `);else if(a.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(a.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(a.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(a.text(e[n]),t,!/\S/.test(e[n]));n=``}else n=n.replace(/\r?\n|\r/g,` `);n&&this.insertNode(a.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,i=this.top;(e.tagName==`PRE`||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let a=e.nodeName.toLowerCase(),o;St.hasOwnProperty(a)&&this.parser.normalizeLists&&kt(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(o=this.parser.matchTag(e,this,n));out:if(s?s.ignore:xt.hasOwnProperty(a))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let n,r=this.needsBlock;if(bt.hasOwnProperty(a))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break out}let o=s&&s.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(i),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,s,n,s.consuming===!1?o:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName==`BR`&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
4
4
  `),t)}ignoreFallback(e,t){e.nodeName==`BR`&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text(`-`),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],i=n.getPropertyValue(r);if(i)for(let e;;){let n=this.parser.matchStyle(r,i,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let i,a;if(t.node)if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(a,t.attrs||null,n,t.preserveWhitespace);e&&(i=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let o=this.top;if(a&&a.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}i&&this.sync(o)&&this.open--}addAll(e,t,n,r){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,o=r==null?null:e.childNodes[r];a!=o;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t,n){let r,i;for(let t=this.open,a=0;t>=0;t--){let o=this.nodes[t],s=o.findWrapping(e);if(s&&(!r||r.length>s.length+a)&&(r=s,i=o,!s.length))break;if(o.solid){if(n)break;a+=2}}if(!r)return null;this.sync(i);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&=t.match.matchType(e.type);let n=O.none;for(let i of r.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):Mt(i.type,e.type))&&(n=i.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let i=this.findPlace(e.create(t),n,!1);return i&&=this.enterInner(e,t,n,!0,r),i}enterInner(e,t,n,r=!1,i){this.closeExtra();let a=this.top;a.match=a.match&&a.match.matchType(e);let o=Et(e,i,a.options);a.options&Tt&&a.content.length==0&&(o|=Tt);let s=O.none;return n=n.filter(t=>(a.type?a.type.allowsMarkType(t.type):Mt(t.type,e))?(s=t.addToSet(s),!1):!0),this.nodes.push(new Dt(e,t,s,r,null,o)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=Ct);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf(`|`)>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),i=-(n?n.depth+1:0)+ +!r,a=(e,o)=>{for(;e>=0;e--){let s=t[e];if(s==``){if(e==t.length-1||e==0)continue;for(;o>=i;o--)if(a(e-1,o))return!0;return!1}else{let e=o>0||o==0&&r?this.nodes[o].type:n&&o>=i?n.node(o-i).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;o--}}return!0};return a(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function kt(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&St.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function At(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function jt(e){let t={};for(let n in e)t[n]=e[n];return t}function Mt(e,t){let n=t.schema.nodes;for(let r in n){let i=n[r];if(!i.allowsMarkType(e))continue;let a=[],o=e=>{a.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:i}=e.edge(n);if(r==t||a.indexOf(i)<0&&o(i))return!0}};if(o(i.contentMatch))return!0}}var Nt=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||=Ft(t).createDocumentFragment();let r=n,i=[];return e.forEach(e=>{if(i.length||e.marks.length){let n=0,a=0;for(;n<i.length&&a<e.marks.length;){let t=e.marks[a];if(!this.marks[t.type.name]){a++;continue}if(!t.eq(i[n][0])||t.type.spec.spanning===!1)break;n++,a++}for(;n<i.length;)r=i.pop()[1];for(;a<e.marks.length;){let n=e.marks[a++],o=this.serializeMark(n,e.isInline,t);o&&(i.push([n,r]),r.appendChild(o.dom),r=o.contentDOM||o.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){if(e.isText)return Ft(t).createTextNode(e.text);let{dom:n,contentDOM:r}=zt(Ft(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw RangeError(`Content hole not allowed in a leaf node spec`);this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&zt(Ft(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return typeof t==`string`?{dom:e.createTextNode(t)}:zt(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=Pt(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return Pt(e.marks)}};function Pt(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function Ft(e){return e.document||window.document}var It=new WeakMap;function Lt(e){let t=It.get(e);return t===void 0&&It.set(e,t=Rt(e)),t}function Rt(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t<e.length;t++)n(e[t]);else for(let t in e)n(e[t])}return n(e),t}function zt(e,t,n,r){if(t.nodeType==1)return{dom:t};if(t.dom&&t.dom.nodeType==1)return t;let i=t[0],a;if(typeof i!=`string`)throw RangeError(`Invalid array passed to renderSpec`);if(r&&(a=Lt(r))&&a.indexOf(t)>-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let o=i.indexOf(` `);o>0&&(n=i.slice(0,o),i=i.slice(o+1));let s,c=n?e.createElementNS(n,i):e.createElement(i),l=t[1],u=1;if(l&&typeof l==`object`&&l.nodeType==null&&!Array.isArray(l)){u=2;for(let e in l)if(l[e]!=null){let t=e.indexOf(` `);t>0?c.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):e==`style`&&c.style?c.style.cssText=l[e]:c.setAttribute(e,l[e])}}for(let i=u;i<t.length;i++){let a=t[i];if(a===0){if(i<t.length-1||i>u)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:c,contentDOM:c}}else if(typeof a==`string`)c.appendChild(e.createTextNode(a));else{let{dom:t,contentDOM:i}=zt(e,a,n,r);if(c.appendChild(t),i){if(s)throw RangeError(`Multiple content holes`);s=i}}}return{dom:c,contentDOM:s}}var Bt=65535,Vt=2**16;function Ht(e,t){return e+t*Vt}function Ut(e){return e&Bt}function Wt(e){return(e-(e&Bt))/Vt}var Gt=1,Kt=2,qt=4,Jt=8,Yt=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&Jt)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&qt)>0}},Xt=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=Ut(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[e*3+2]-this.ranges[e*3+1];return this.ranges[n*3]+t+Wt(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,i=this.inverted?2:1,a=this.inverted?1:2;for(let o=0;o<this.ranges.length;o+=3){let s=this.ranges[o]-(this.inverted?r:0);if(s>e)break;let c=this.ranges[o+i],l=this.ranges[o+a],u=s+c;if(e<=u){let i=c?e==s?-1:e==u?1:t:t,a=s+r+(i<0?0:l);if(n)return a;let d=e==(t<0?s:u)?null:Ht(o/3,e-s),f=e==s?Kt:e==u?Gt:qt;return(t<0?e!=s:e!=u)&&(f|=Jt),new Yt(a,f,d)}r+=l-c}return n?e+r:new Yt(e+r,0,null)}touches(e,t){let n=0,r=Ut(t),i=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let o=this.ranges[t]-(this.inverted?n:0);if(o>e)break;let s=this.ranges[t+i];if(e<=o+s&&t==r*3)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let a=this.ranges[r],o=a-(this.inverted?i:0),s=a+(this.inverted?0:i),c=this.ranges[r+t],l=this.ranges[r+n];e(o,o+c,s,s+l),i+=l-c}}invert(){return new e(this.ranges,!this.inverted)}toString(){return(this.inverted?`-`:``)+JSON.stringify(this.ranges)}static offset(t){return t==0?e.empty:new e(t<0?[0,-t,0]:[0,0,t])}};Xt.empty=new Xt([]);var Zt=class e{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(t=0,n=this.maps.length){return new e(this._maps,this.mirror,t,n)}appendMap(e,t){this.ownData||=(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||=[],this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let i=this._maps[n].mapResult(e,t);if(i.recover!=null){let t=this.getMirror(n);if(t!=null&&t>n&&t<this.to){n=t,e=this._maps[t].recover(i.recover);continue}}r|=i.delInfo,e=i.pos}return n?e:new Yt(e,r,null)}},Qt=Object.create(null),$t=class{getMap(){return Xt.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError(`Invalid input for Step.fromJSON`);let n=Qt[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in Qt)throw RangeError(`Duplicate use of step JSON ID `+e);return Qt[e]=t,t.prototype.jsonID=e,t}},en=class e{constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,i){try{return e.ok(t.replace(n,r,i))}catch(t){if(t instanceof k)return e.fail(t.message);throw t}}};function tn(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let a=e.child(i);a.content.size&&(a=a.copy(tn(a.content,t,a))),a.isInline&&(a=t(a,n,i)),r.push(a)}return D.fromArray(r)}var nn=class e extends $t{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),i=new A(tn(t.content,(e,t)=>!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return en.fromReplace(e,this.from,this.to,i)}invert(){return new rn(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};$t.jsonID(`addMark`,nn);var rn=class e extends $t{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new A(tn(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return en.fromReplace(e,this.from,this.to,n)}invert(){return new nn(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};$t.jsonID(`removeMark`,rn);var an=class e extends $t{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return en.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return en.fromReplace(e,this.pos,this.pos+1,new A(D.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(t))return new e(this.pos,n.marks[r]);return new e(this.pos,this.mark)}}return new on(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`addNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for AddNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};$t.jsonID(`addNodeMark`,an);var on=class e extends $t{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return en.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return en.fromReplace(e,this.pos,this.pos+1,new A(D.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new an(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`removeNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for RemoveNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};$t.jsonID(`removeNodeMark`,on);var sn=class e extends $t{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&ln(e,this.from,this.to)?en.fail(`Structure replace would overwrite content`):en.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Xt([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.to,-1),r=this.from==this.to&&e.MAP_BIAS<0?n:t.mapResult(this.from,1);return r.deletedAcross&&n.deletedAcross?null:new e(r.pos,Math.max(r.pos,n.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?A.empty:new A(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new e(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?A.empty:new A(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new e(t.from,this.to,n,this.structure)}else return null}toJSON(){let e={stepType:`replace`,from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for ReplaceStep.fromJSON`);return new e(n.from,n.to,A.fromJSON(t,n.slice),!!n.structure)}};sn.MAP_BIAS=1,$t.jsonID(`replace`,sn);var cn=class e extends $t{constructor(e,t,n,r,i,a,o=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=i,this.insert=a,this.structure=o}apply(e){if(this.structure&&(ln(e,this.from,this.gapFrom)||ln(e,this.gapTo,this.to)))return en.fail(`Structure gap-replace would overwrite content`);let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return en.fail(`Gap is not a flat range`);let n=this.slice.insertAt(this.insert,t.content);return n?en.fromReplace(e,this.from,this.to,n):en.fail(`Content does not fit in gap`)}getMap(){return new Xt([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),i=this.from==this.gapFrom?n.pos:t.map(this.gapFrom,-1),a=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||i<n.pos||a>r.pos?null:new e(n.pos,r.pos,i,a,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:`replaceAround`,from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,A.fromJSON(t,n.slice),n.insert,!!n.structure)}};$t.jsonID(`replaceAround`,cn);function ln(e,t,n){let r=e.resolve(t),i=n-t,a=r.depth;for(;i>0&&a>0&&r.indexAfter(a)==r.node(a).childCount;)a--,i--;if(i>0){let e=r.node(a).maybeChild(r.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}function un(e,t,n,r){let i=[],a=[],o,s;e.doc.nodesBetween(t,n,(e,c,l)=>{if(!e.isInline)return;let u=e.marks;if(!r.isInSet(u)&&l.type.allowsMarkType(r.type)){let l=Math.max(c,t),d=Math.min(c+e.nodeSize,n),f=r.addToSet(u);for(let e=0;e<u.length;e++)u[e].isInSet(f)||(o&&o.to==l&&o.mark.eq(u[e])?o.to=d:i.push(o=new rn(l,d,u[e])));s&&s.to==l?s.to=d:a.push(s=new nn(l,d,r))}}),i.forEach(t=>e.step(t)),a.forEach(t=>e.step(t))}function dn(e,t,n,r){let i=[],a=0;e.doc.nodesBetween(t,n,(e,o)=>{if(!e.isInline)return;a++;let s=null;if(r instanceof mt){let t=e.marks,n;for(;n=r.isInSet(t);)(s||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(s=[r]):s=e.marks;if(s&&s.length){let r=Math.min(o+e.nodeSize,n);for(let e=0;e<s.length;e++){let n=s[e],c;for(let e=0;e<i.length;e++){let t=i[e];t.step==a-1&&n.eq(i[e].style)&&(c=t)}c?(c.to=r,c.step=a):i.push({style:n,from:Math.max(o,t),to:r,step:a})}}}),i.forEach(t=>e.step(new rn(t.from,t.to,t.style)))}function fn(e,t,n,r=n.contentMatch,i=!0){let a=e.doc.nodeAt(t),o=[],s=t+1;for(let t=0;t<a.childCount;t++){let c=a.child(t),l=s+c.nodeSize,u=r.matchType(c.type);if(!u)o.push(new sn(s,l,A.empty));else{r=u;for(let t=0;t<c.marks.length;t++)n.allowsMarkType(c.marks[t].type)||e.step(new rn(s,l,c.marks[t]));if(i&&c.isText&&n.whitespace!=`pre`){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(c.text);)r||=new A(D.from(n.schema.text(` `,n.allowedMarks(c.marks))),0,0),o.push(new sn(s+e.index,s+e.index+e[0].length,r))}}s=l}if(!r.validEnd){let t=r.fillBefore(D.empty,!0);e.replace(s,s,new A(t,0,0))}for(let t=o.length-1;t>=0;t--)e.step(o[t])}function pn(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function mn(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth,r=0,i=0;;--n){let a=e.$from.node(n),o=e.$from.index(n)+r,s=e.$to.indexAfter(n)-i;if(n<e.depth&&a.canReplace(o,s,t))return n;if(n==0||a.type.spec.isolating||!pn(a,o,s))break;o&&(r=1),s<a.childCount&&(i=1)}return null}function hn(e,t,n){let{$from:r,$to:i,depth:a}=t,o=r.before(a+1),s=i.after(a+1),c=o,l=s,u=D.empty,d=0;for(let e=a,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,u=D.from(r.node(e).copy(u)),d++):c--;let f=D.empty,p=0;for(let e=a,t=!1;e>n;e--)t||i.after(e+1)<i.end(e)?(t=!0,f=D.from(i.node(e).copy(f)),p++):l++;e.step(new cn(c,l,o,s,new A(u.append(f),d,p),u.size-d,!0))}function gn(e,t,n=null,r=e){let i=vn(e,t),a=i&&yn(r,t);return a?i.map(_n).concat({type:t,attrs:n}).concat(a.map(_n)):null}function _n(e){return{type:e,attrs:null}}function vn(e,t){let{parent:n,startIndex:r,endIndex:i}=e,a=n.contentMatchAt(r).findWrapping(t);if(!a)return null;let o=a.length?a[0]:t;return n.canReplaceWith(r,i,o)?a:null}function yn(e,t){let{parent:n,startIndex:r,endIndex:i}=e,a=n.child(r),o=t.contentMatch.findWrapping(a.type);if(!o)return null;let s=(o.length?o[o.length-1]:t).contentMatch;for(let e=r;s&&e<i;e++)s=s.matchType(n.child(e).type);return!s||!s.validEnd?null:o}function bn(e,t,n){let r=D.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=D.from(n[e].type.create(n[e].attrs,r))}let i=t.start,a=t.end;e.step(new cn(i,a,i,a,new A(r,0,0),n.length,!0))}function xn(e,t,n,r,i){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let a=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let o=typeof i==`function`?i(t):i;if(t.isTextblock&&!t.hasMarkup(r,o)&&wn(e.doc,e.mapping.slice(a).map(n),r)){let i=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?i=!1:!e&&t&&(i=!0)}i===!1&&Cn(e,t,n,a),fn(e,e.mapping.slice(a).map(n,1),r,void 0,i===null);let s=e.mapping.slice(a),c=s.map(n,1),l=s.map(n+t.nodeSize,1);return e.step(new cn(c,l,c+1,l-1,new A(D.from(r.create(o,null,t.marks)),0,0),1,!0)),i===!0&&Sn(e,t,n,a),!1}})}function Sn(e,t,n,r){t.forEach((i,a)=>{if(i.isText){let o,s=/\r?\n|\r/g;for(;o=s.exec(i.text);){let i=e.mapping.slice(r).map(n+1+a+o.index);e.replaceWith(i,i+1,t.type.schema.linebreakReplacement.create())}}})}function Cn(e,t,n,r){t.forEach((i,a)=>{if(i.type==i.type.schema.linebreakReplacement){let i=e.mapping.slice(r).map(n+1+a);e.replaceWith(i,i+1,t.type.schema.text(`