@lobu/runtime-server 20.1.0 → 20.2.0

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 (146) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/connectors/chat-user-identity.ts +41 -0
  3. package/dist/connectors/google-identity.ts +11 -0
  4. package/dist/connectors/slack-identity.ts +19 -0
  5. package/dist/db/migrations/20260915030000_owner_dm_delivery_request_platform.sql +51 -0
  6. package/dist/dependencies.bun.lock +28 -30
  7. package/dist/owletto/dist/assets/{_-DdvHIadV.js → _-Ds4DyQjj.js} +2 -2
  8. package/dist/owletto/dist/assets/_-VmyR6aN_.js +1 -0
  9. package/dist/owletto/dist/assets/{_agentId-DbTBU4KZ.js → _agentId-BAVnp0c7.js} +1 -1
  10. package/dist/owletto/dist/assets/_agentId-Df-3rGi5.js +1 -0
  11. package/dist/owletto/dist/assets/{_automationId-C7dZzg6X.js → _automationId-D696vOjd.js} +1 -1
  12. package/dist/owletto/dist/assets/{_connectorKey._connectionId-NQf43Ew3.js → _connectorKey._connectionId-BAJGfcy7.js} +1 -1
  13. package/dist/owletto/dist/assets/{_connectorKey.index-D-0ZNsgM.js → _connectorKey.index-BBF8vGJS.js} +1 -1
  14. package/dist/owletto/dist/assets/{_conversationId-F5YmyLV9.js → _conversationId-Ci4rgrHm.js} +1 -1
  15. package/dist/owletto/dist/assets/{_deploymentId-3LTMi0ZT.js → _deploymentId-Iy-D5PDq.js} +1 -1
  16. package/dist/owletto/dist/assets/_name-CeGwb0oK.js +1 -0
  17. package/dist/owletto/dist/assets/{_owner-DglbbDEx.js → _owner-CFR1G8OX.js} +1 -1
  18. package/dist/owletto/dist/assets/_skillKey-DuLcQWBu.js +1 -0
  19. package/dist/owletto/dist/assets/{_slug-CnQDfsCE.js → _slug-CDSO20ac.js} +1 -1
  20. package/dist/owletto/dist/assets/{accept-invitation-Dgoyublh.js → accept-invitation-Db5jklHT.js} +1 -1
  21. package/dist/owletto/dist/assets/{activity-route-view-BNzKO6aD.js → activity-route-view-DVW3DoB7.js} +1 -1
  22. package/dist/owletto/dist/assets/{agent-card-controls-VJgcB5-0.js → agent-card-controls-CZO6GI0s.js} +1 -1
  23. package/dist/owletto/dist/assets/{agent-client-setup-list-C5KRNRw3.js → agent-client-setup-list-_chLOorY.js} +1 -1
  24. package/dist/owletto/dist/assets/{agent-connect-pages-BFSb6vmW.js → agent-connect-pages-DWBgSIYT.js} +1 -1
  25. package/dist/owletto/dist/assets/{agent-editor-form-CajEehVn.js → agent-editor-form-BTNlg0kQ.js} +1 -1
  26. package/dist/owletto/dist/assets/{agent-guardrails-route-CZ_rXj-3.js → agent-guardrails-route-B5uoMC6o.js} +1 -1
  27. package/dist/owletto/dist/assets/{agent-loading-shells-Dczhk067.js → agent-loading-shells-CLoLeFcB.js} +1 -1
  28. package/dist/owletto/dist/assets/{agent-permissions-matrix-DIVHvpZG.js → agent-permissions-matrix-TP00-MYL.js} +1 -1
  29. package/dist/owletto/dist/assets/{agent-skill-context-CxglCznW.js → agent-skill-context-D4a2QCoZ.js} +1 -1
  30. package/dist/owletto/dist/assets/{agent-skills-route-CatU8soC.js → agent-skills-route-KVDDTbJB.js} +1 -1
  31. package/dist/owletto/dist/assets/{agent-subpage-shell-DVSUdIBn.js → agent-subpage-shell-DuVYZvBE.js} +1 -1
  32. package/dist/owletto/dist/assets/{agent-thread-DnLUOzXk.js → agent-thread-CzCJU3-R.js} +1 -1
  33. package/dist/owletto/dist/assets/agents-DFs57C3c.js +1 -0
  34. package/dist/owletto/dist/assets/{agents-workbench-BOKifKIO.js → agents-workbench-C2bUlJP2.js} +1 -1
  35. package/dist/owletto/dist/assets/{app._appId-BXmITXO7.js → app._appId-D0_LQTJU.js} +1 -1
  36. package/dist/owletto/dist/assets/{automation-detail-content-wJC9hhmA.js → automation-detail-content-DWkdhnv2.js} +1 -1
  37. package/dist/owletto/dist/assets/automations-DFs57C3c.js +1 -0
  38. package/dist/owletto/dist/assets/{calendar-taCoBmAh.js → calendar-C0XpOHd8.js} +1 -1
  39. package/dist/owletto/dist/assets/{callback-CJxC8u_x.js → callback-CO_K9eR-.js} +1 -1
  40. package/dist/owletto/dist/assets/{card-kpw3EaKC.js → card-DeFQuU_J.js} +1 -1
  41. package/dist/owletto/dist/assets/{claim-DLHRN0bA.js → claim-CUpWOSie.js} +1 -1
  42. package/dist/owletto/dist/assets/{clients-R4JsT_Fz.js → clients-DhYr4lyL.js} +1 -1
  43. package/dist/owletto/dist/assets/{code-editor-D3X0yQdI.js → code-editor-BqGUZFt6.js} +1 -1
  44. package/dist/owletto/dist/assets/connect-Dtb-E5An.js +1 -0
  45. package/dist/owletto/dist/assets/connect._clientId-DWtceAAw.js +1 -0
  46. package/dist/owletto/dist/assets/{connected._clientId-ByH4etku.js → connected._clientId-CMe-wTuV.js} +1 -1
  47. package/dist/owletto/dist/assets/{connection-DdBkXNbX.js → connection-BgAlYjeV.js} +1 -1
  48. package/dist/owletto/dist/assets/{connection-feed-detail-DF93zx0A.js → connection-feed-detail-B3ePAinf.js} +1 -1
  49. package/dist/owletto/dist/assets/{connector-provenance-N3sc0nbo.js → connector-provenance-DgsDg0Z9.js} +1 -1
  50. package/dist/owletto/dist/assets/{connectors-Ckn_aoNE.js → connectors-CqPQPo9U.js} +1 -1
  51. package/dist/owletto/dist/assets/{consent-Bi6KCVtT.js → consent-bswcIzsf.js} +1 -1
  52. package/dist/owletto/dist/assets/{core.esm-CFYXLQXH.js → core.esm-DsLgjoel.js} +1 -1
  53. package/dist/owletto/dist/assets/create-CcXUdke7.js +1 -0
  54. package/dist/owletto/dist/assets/create-Cp6hMoeU.js +1 -0
  55. package/dist/owletto/dist/assets/{create-BiHpu2f4.js → create-Dwo04oWV.js} +1 -1
  56. package/dist/owletto/dist/assets/{create-automation-form-Cv2RHsQ6.js → create-automation-form-CJ4meayB.js} +1 -1
  57. package/dist/owletto/dist/assets/{create._connectorKey-Qynix_hA.js → create._connectorKey-CCBb2pil.js} +1 -1
  58. package/dist/owletto/dist/assets/{cronstrue-D7xlYtGk.js → cronstrue-ChFyC9ps.js} +1 -1
  59. package/dist/owletto/dist/assets/deployments-CjfFxyDA.js +1 -0
  60. package/dist/owletto/dist/assets/{deployments-body-BPCALbQe.js → deployments-body-Cg0KiWGr.js} +1 -1
  61. package/dist/owletto/dist/assets/device-DpY67Jaj.js +1 -0
  62. package/dist/owletto/dist/assets/{device-pin-tombstone-DrTJYNKG.js → device-pin-tombstone-1ikyqSdb.js} +1 -1
  63. package/dist/owletto/dist/assets/{device-rows-fVm-zAiU.js → device-rows-Cp3yMcuV.js} +1 -1
  64. package/dist/owletto/dist/assets/{device._deviceId-CIe7taim.js → device._deviceId-DTYKGBY8.js} +1 -1
  65. package/dist/owletto/dist/assets/{entity-options-DOGD_EyZ.js → entity-options-1EaSGMX4.js} +1 -1
  66. package/dist/owletto/dist/assets/{entity-page-C8oDszRY.js → entity-page-DJmM70dv.js} +1 -1
  67. package/dist/owletto/dist/assets/{entity-type-page-BfxIgJLq.js → entity-type-page-C3mT7tXn.js} +1 -1
  68. package/dist/owletto/dist/assets/{events-feed-B9OqmSBy.js → events-feed-iliGfjit.js} +1 -1
  69. package/dist/owletto/dist/assets/{full-page-spinner-DTSqneUO.js → full-page-spinner-BN2G_YiM.js} +1 -1
  70. package/dist/owletto/dist/assets/guardrails-CLlnRRy9.js +1 -0
  71. package/dist/owletto/dist/assets/identity-MSLryUi8.js +1 -0
  72. package/dist/owletto/dist/assets/index-3o4Eepb4.js +1 -0
  73. package/dist/owletto/dist/assets/{index-Bfux0kHb.js → index-BUr8321-.js} +3 -3
  74. package/dist/owletto/dist/assets/{index-CK2-iHcz.js → index-Bulu5ldM.js} +1 -1
  75. package/dist/owletto/dist/assets/{index-DcWyuLQS.js → index-BvbfITqH.js} +1 -1
  76. package/dist/owletto/dist/assets/{index-Bq4m-sK0.js → index-C-u4yR8Z.js} +1 -1
  77. package/dist/owletto/dist/assets/{index-DkKALC2l.js → index-C2oCgDX7.js} +1 -1
  78. package/dist/owletto/dist/assets/{index-jGZeANLE.js → index-C6VAJ8Ku.js} +1 -1
  79. package/dist/owletto/dist/assets/index-Clw9ZBj-.js +1 -0
  80. package/dist/owletto/dist/assets/index-D2oL4Ydo.js +1 -0
  81. package/dist/owletto/dist/assets/index-D7wulT4y.js +1 -0
  82. package/dist/owletto/dist/assets/{index-COgBJ_ab.js → index-DOLFe19K.js} +1 -1
  83. package/dist/owletto/dist/assets/index-DTSA0Xh1.js +1 -0
  84. package/dist/owletto/dist/assets/index-DxXXVPU0.js +1 -0
  85. package/dist/owletto/dist/assets/{index-CMOHHdFH.js → index-hSE2E46p.js} +1 -1
  86. package/dist/owletto/dist/assets/index-nzvsA3hT.js +1 -0
  87. package/dist/owletto/dist/assets/{index-DYe_DVHa.js → index-vdqhlocx.js} +1 -1
  88. package/dist/owletto/dist/assets/{json-diff-CANZD4MQ.js → json-diff-DnsW7Pin.js} +1 -1
  89. package/dist/owletto/dist/assets/{list-skeleton-DZTUxpBx.js → list-skeleton-CHzLN7GK.js} +1 -1
  90. package/dist/owletto/dist/assets/{login-D53geSP7.js → login-CCKNM0gV.js} +1 -1
  91. package/dist/owletto/dist/assets/{logout-DKQS25qd.js → logout-B-N2aodZ.js} +1 -1
  92. package/dist/owletto/dist/assets/{member-scope-gate-C4QyRm2Q.js → member-scope-gate-B560Wg-t.js} +1 -1
  93. package/dist/owletto/dist/assets/{memory-browse-page-DOpV3vht.js → memory-browse-page-DMDqKJn7.js} +1 -1
  94. package/dist/owletto/dist/assets/{model-selector-CvU3VP90.js → model-selector-DfbmHjLu.js} +1 -1
  95. package/dist/owletto/dist/assets/models-M51OGDRE.js +1 -0
  96. package/dist/owletto/dist/assets/{new-B8_sRMYD.js → new-BVQS9H-Y.js} +1 -1
  97. package/dist/owletto/dist/assets/{new-DIjOVXrQ.js → new-Df_dY6Z5.js} +1 -1
  98. package/dist/owletto/dist/assets/{new-Df1q7GEj.js → new-DxDVE9nL.js} +1 -1
  99. package/dist/owletto/dist/assets/{oauth-workspace-access-DWfiekRz.js → oauth-workspace-access-D9GmiMfK.js} +1 -1
  100. package/dist/owletto/dist/assets/{organization-DHEC7kDq.js → organization-uSDYkJpX.js} +1 -1
  101. package/dist/owletto/dist/assets/{permissions-i7iwnE1a.js → permissions-Fe0DP6b8.js} +1 -1
  102. package/dist/owletto/dist/assets/{proposal-review-shell-C_LcyUEF.js → proposal-review-shell-D9HwnDda.js} +1 -1
  103. package/dist/owletto/dist/assets/{recent-By19_Buq.js → recent-C03LhMD7.js} +1 -1
  104. package/dist/owletto/dist/assets/{renderer-B1UThnk2.js → renderer-CHNejd95.js} +1 -1
  105. package/dist/owletto/dist/assets/{reset-password-Dsz5-Xeo.js → reset-password-CuISnlG_.js} +1 -1
  106. package/dist/owletto/dist/assets/{runs-BQ11PAQT.js → runs-BnYdToDc.js} +1 -1
  107. package/dist/owletto/dist/assets/{runs-panel-wkV1aGD9.js → runs-panel-DsdESupx.js} +1 -1
  108. package/dist/owletto/dist/assets/{runs-table-DzSWYkaf.js → runs-table-B7jKuILd.js} +1 -1
  109. package/dist/owletto/dist/assets/{schema-value-normalization--DhnhJNf.js → schema-value-normalization-B--OWDL8.js} +1 -1
  110. package/dist/owletto/dist/assets/settings-Bg9yCCoN.js +1 -0
  111. package/dist/owletto/dist/assets/{settings-Bu239SXe.js → settings-wGNHtsDP.js} +1 -1
  112. package/dist/owletto/dist/assets/skills-CN5Ube7A.js +1 -0
  113. package/dist/owletto/dist/assets/{switch-CCKllS7w.js → switch-Dzse_XFM.js} +1 -1
  114. package/dist/owletto/dist/assets/{use-mention-search-CldNZTiT.js → use-mention-search-uyW1Uwf6.js} +1 -1
  115. package/dist/owletto/dist/index.html +1 -1
  116. package/dist/server-main.bundle.mjs +9903 -9541
  117. package/npm-shrinkwrap.json +116 -140
  118. package/package.json +1 -1
  119. package/vendor/connector-sdk/package.json +1 -1
  120. package/vendor/core/dist/credentials.d.ts +16 -1
  121. package/vendor/core/dist/credentials.js +10 -1
  122. package/vendor/core/package.json +1 -1
  123. package/dist/owletto/dist/assets/_-CfcfHJO8.js +0 -1
  124. package/dist/owletto/dist/assets/_agentId-BTmFhpb6.js +0 -1
  125. package/dist/owletto/dist/assets/_name-BKeZbc-h.js +0 -1
  126. package/dist/owletto/dist/assets/_skillKey-DhiGYYFq.js +0 -1
  127. package/dist/owletto/dist/assets/agents-OLmcj-qM.js +0 -1
  128. package/dist/owletto/dist/assets/automations-OLmcj-qM.js +0 -1
  129. package/dist/owletto/dist/assets/connect-1ysEq9l0.js +0 -1
  130. package/dist/owletto/dist/assets/connect._clientId-BbMPs6l3.js +0 -1
  131. package/dist/owletto/dist/assets/create-C37QtjbJ.js +0 -1
  132. package/dist/owletto/dist/assets/create-kAQa5_Q7.js +0 -1
  133. package/dist/owletto/dist/assets/deployments-C5kSeowq.js +0 -1
  134. package/dist/owletto/dist/assets/device-DToHXxDM.js +0 -1
  135. package/dist/owletto/dist/assets/guardrails-9Mr6avxk.js +0 -1
  136. package/dist/owletto/dist/assets/identity-DMfCjdBz.js +0 -1
  137. package/dist/owletto/dist/assets/index-CkwwaMrx.js +0 -1
  138. package/dist/owletto/dist/assets/index-D0lZrXrY.js +0 -1
  139. package/dist/owletto/dist/assets/index-DZadnZpq.js +0 -1
  140. package/dist/owletto/dist/assets/index-DlqjyZKQ.js +0 -1
  141. package/dist/owletto/dist/assets/index-Dv0huHrO.js +0 -1
  142. package/dist/owletto/dist/assets/index-DxIDxgPJ.js +0 -1
  143. package/dist/owletto/dist/assets/index-bKUccXCc.js +0 -1
  144. package/dist/owletto/dist/assets/models-ooBIWFuB.js +0 -1
  145. package/dist/owletto/dist/assets/settings-FxbIvOhH.js +0 -1
  146. package/dist/owletto/dist/assets/skills-MBZ5ilDK.js +0 -1
@@ -1 +1 @@
1
- import{r as i,j as e,bY as me,bZ as he,b_ as xe,b$ as pe,c0 as P,ab as ae,B as z,X as Jt,a as us,dI as ds,cb as Gt,el as ms,em as hs,S as kt,aa as y,aj as T,aS as Je,en as St,dz as xs,dB as ps,eo as gs,cP as Ht,dC as fs,bx as wt,ep as vs,de as tt,df as $e,aO as et,eq as gt,bw as Yt,P as Ge,cE as ys,an as js,ag as _s,er as Ns,es as bs,et as ks,eu as Ss,ev as ws,af as Cs,L as Es,a1 as Xt,ew as Os,bv as As,bb as Fs,cq as Ct,ex as Ps,ey as Ms,d5 as Ls,ea as Ts,c2 as ht,s as Rs,ez as Ds,eA as Is,eB as qs,eC as $s,eD as Ks,eE as Ws,eF as Bs,eG as zs,eH as Us,by as Vs,c7 as Qs}from"./index-Bfux0kHb.js";import{c as Js}from"./cronstrue-D7xlYtGk.js";import{C as Gs,f as Hs}from"./entity-options-DOGD_EyZ.js";import{S as Ys}from"./switch-CCKllS7w.js";import{a as Xs,A as Zs}from"./device-automation-BIjs7DZJ.js";import{M as en}from"./model-selector-CvU3VP90.js";import{b as tn}from"./skill-editor-D_W3QlRz.js";import{C as Ze}from"./code-editor-D3X0yQdI.js";import{u as sn,M as Et,a as Ot,s as nn,o as an,b as on,c as rn,d as cn,e as ln,v as un,r as dn}from"./use-mention-search-CldNZTiT.js";const Xe=[{value:"*/15 * * * *",label:"Every 15 minutes"},{value:"0 * * * *",label:"Every hour"},{value:"0 */6 * * *",label:"Every 6 hours"},{value:"0 9 * * *",label:"Daily at 9:00 AM"},{value:"0 18 * * *",label:"Daily at 6:00 PM"},{value:"0 9 * * 1-5",label:"Weekdays at 9:00 AM"},{value:"0 9 * * 1",label:"Weekly · Monday 9:00 AM"},{value:"0 9 1 * *",label:"Monthly · 1st at 9:00 AM"},{value:"custom",label:"Custom cron…"}];function mn(n){const t=n.trim();if(!t)return null;try{return Js.toString(t,{throwExceptionOnParseError:!0})}catch{return null}}function hn({value:n,onChange:t,placeholder:s="No schedule",className:d}){const u=n??"",m=Xe.some(f=>f.value===u),[c,o]=i.useState(!m&&u!==""),r=f=>{f==="custom"?o(!0):(o(!1),t(f))},j=u?mn(u):null,R=u?e.jsx("p",{className:j?"text-xs text-muted-foreground":"text-xs text-destructive",children:j??"Not a valid cron expression."}):null;return!u&&!c?e.jsxs(me,{onValueChange:r,children:[e.jsx(he,{className:d??"w-full",children:e.jsx(xe,{placeholder:s})}),e.jsx(pe,{children:Xe.map(f=>e.jsxs(P,{value:f.value,children:[f.label,f.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:f.value})]},f.value))})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c?e.jsx(ae,{placeholder:"0 */6 * * *",value:u,onChange:f=>t(f.target.value),className:"font-mono text-sm flex-1"}):e.jsxs(me,{value:u,onValueChange:r,children:[e.jsx(he,{className:d??"w-full flex-1",children:e.jsx(xe,{children:Xe.find(f=>f.value===u)?.label??u})}),e.jsx(pe,{children:Xe.map(f=>e.jsxs(P,{value:f.value,children:[f.label,f.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:f.value})]},f.value))})]}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",onClick:()=>{o(!1),t("")},children:e.jsx(Jt,{className:"h-4 w-4"})})]}),R]})}const lt="__all_workspace_event_types__",xn=[],pn={};function At(n,t,s){const d=new Map;if(!t)for(const[m,c]of Object.entries(s??{}))d.set(m,{key:m,label:wt(m),description:c.description});const u=[...n].filter(m=>!t||m.slug===t).sort((m,c)=>m.slug.localeCompare(c.slug));for(const m of u)for(const[c,o]of Object.entries(m.event_kinds??{})){const r=d.get(c);if(r){!r.description&&o.description&&(r.description=o.description),JSON.stringify(r.metadataSchema??null)!==JSON.stringify(o.metadataSchema??null)&&(r.metadataSchema=void 0);continue}d.set(c,{key:c,label:wt(c),description:o.description,metadataSchema:o.metadataSchema})}return[...d.values()].sort((m,c)=>m.label.localeCompare(c.label))}function Ft(n){const t=n[0];if(!t)return;const s=u=>JSON.stringify(Object.keys(u?.properties??{}).sort()),d=s(t);return n.every(u=>s(u)===d)?t:void 0}function Pt(n,t,s){const d=new Set(Object.keys(t.properties??{}));return{...Object.fromEntries(Object.entries(n).filter(([u])=>!d.has(u))),...s}}function Ie(n,t,s){return s==="steer"&&(n==="window"||t!=="reply_to_source")?"coalesce":s}function Qe(n,t){return n==="window"?"silent":t}function Mt(n){return Object.fromEntries(Object.entries(n).filter(([t])=>t==="resource_ref"||t==="resource_type"))}function Lt(n,t,s){const d=new Set(Object.keys(t?.properties??{})),u=new Set(s.flatMap(m=>Object.keys(m.filterSchema?.properties??{})));return Object.fromEntries(Object.entries(vs(n)).filter(([m])=>m==="resource_ref"||m==="resource_type"||!u.has(m)||d.has(m)))}function gn({value:n,options:t,onChange:s}){return e.jsx("div",{className:"inline-flex rounded-md border bg-muted/30 p-0.5 text-sm",children:t.map(d=>e.jsx("button",{type:"button","aria-pressed":n===d.value,onClick:()=>s(d.value),className:T("rounded px-3 py-1 transition-colors",n===d.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:d.label},d.value))})}function Tt({events:n,selectedKeys:t,onToggle:s,ariaLabel:d="Events"}){const u=i.useId(),m=n.filter(o=>t.includes(o.key)).map(o=>o.label),c=m.length===0?"Choose events":m.length===1?m[0]:`${m.length} events selected`;return e.jsx(tt,{contentClassName:"w-[var(--radix-popover-trigger-width)] min-w-[280px]",searchPlaceholder:"Filter events...",emptyText:"No events found.",trigger:o=>e.jsxs(z,{type:"button",variant:"outline",role:"combobox","aria-label":d,"aria-expanded":o,className:"w-full justify-between font-normal",children:[e.jsx("span",{className:T(m.length===0&&"text-muted-foreground"),children:c}),e.jsx(gt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>n.map((o,r)=>{const j=t.includes(o.key),R=`${u}-${r}-state`;return e.jsxs($e,{value:`${o.label} ${o.key}`,onSelect:()=>s(o.key),"aria-label":o.label,"aria-describedby":R,className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",j?"opacity-100":"opacity-0")}),o.label,e.jsx("span",{id:R,className:"sr-only",children:j?"Selected":"Not selected"})]},o.key)})})}function fn({organizationId:n,initialTrigger:t,onChange:s,allowedKinds:d,showSectionHeader:u=!0,fieldIdPrefix:m="automation-trigger-"}){const c=us(n,{status:"active",limit:500}),o=ds(n),r=Gt({organizationId:n}),j=ms({organizationId:n}),R=c.data??[],f=o.data??[],B=r.data??xn,h=j.data??pn,v=i.useMemo(()=>B.filter(l=>l.organization_id===n),[B,n]),_=t?.kind==="event"&&t?.source==="workspace",O=_||t===void 0,D=d?.length?[...d]:["event","time","manual"],b=D.join("|"),J=(()=>{const l=t===null?"manual":t?.kind==="schedule"?"time":"event";return D.includes(l)?l:D[0]??"event"})(),[g,M]=i.useState(J),[G,Se]=i.useState(_?"workspace":typeof t?.connection_id=="number"?String(t.connection_id):t?.kind==="event"&&t.connector_key?"":"workspace"),N=G==="workspace",oe=N?"":G,[k,we]=i.useState(typeof t?.entity_type=="string"?t.entity_type:""),Fe=i.useMemo(()=>Array.isArray(t?.event_types)?t.event_types:[],[t]),[C,re]=i.useState(()=>Fe.filter(l=>typeof l=="string")),[H,te]=i.useState(t?.match&&typeof t.match=="object"&&!Array.isArray(t.match)?t.match:{}),[be,Pe]=i.useState(typeof t?.cron=="string"?t.cron:"0 9 * * 1-5"),ce=typeof t?.timezone=="string"?t.timezone:void 0,[$,ge]=i.useState(t?.kind==="schedule"||O&&t?.execution!=="turn"||t?.execution==="window"?"window":"turn"),[Y,V]=i.useState(Qe($,t?.output==="reply_to_source"?"reply_to_source":"silent")),[Q,se]=i.useState(t?.kind==="schedule"||O&&t?.active_run!=="queue"?"coalesce":Ie($,Y,t?.active_run==="coalesce"||t?.active_run==="steer"?t.active_run:"queue")),[ke,Ee]=i.useState(t?.skip_if_unchanged!==!1),[x,K]=i.useState(!1);i.useEffect(()=>{const l=b.split("|");if(!l.includes(g)){const p=l[0]??"event";M(p),ge(p==="time"||p==="event"&&N?"window":"turn"),se(p==="time"||p==="event"&&N?"coalesce":"queue"),V("silent")}},[b,g,N]);const A=R.find(l=>String(l.id)===oe),ie=c.isLoading||o.isLoading,X=r.isLoading,fe=typeof t?.connector_key=="string"?t.connector_key:void 0,U=g==="event"&&!N&&t?.kind==="event"&&t?.source!=="workspace"&&typeof t.connection_id=="number"&&String(t.connection_id)===oe&&!A,ye=g==="event"&&!N&&t?.kind==="event"&&t?.source!=="workspace"&&t.connection_id==null&&fe!==void 0&&oe==="",Oe=f.find(l=>l.key===(A?.connector_key??(ye?fe:void 0))),le=Oe?.automation_events??[],I=le.filter(l=>C.includes(l.key)),je=I[0],Me=v.find(l=>l.slug===k),Ae=[...v.filter(l=>Object.keys(l.event_kinds??{}).length>0||l.slug===k),...k&&!Me?[{slug:k,name:k}]:[]],ue=i.useMemo(()=>At(v,k||void 0,h),[v,k,h]),Le=ue.filter(l=>C.includes(l.key)),We=Le[0],ve=Ft(I.map(l=>l.filterSchema)),de=Ft(Le.map(l=>l.metadataSchema)),Be=!!(N&&k&&!Me),Te=U||ye,Ce=(g==="event"?N?C.length>0&&!Be:!!(C.length>0&&(oe&&A||Te)):g==="time"?!!be.trim():!0)&&(g!=="event"||!hs(H));i.useEffect(()=>{let l;if(Ce&&g==="event"&&!N){const p=Lt(H,ve,Oe?.automation_events??[]);A||ye?l={kind:"event",source:"connector",connector_key:A?.connector_key??fe,...A?{connection_id:Number(oe)}:{},event_types:C,...Object.keys(p).length>0?{match:p}:{},execution:$,active_run:Ie($,Y,Q),output:Qe($,Y),skip_if_unchanged:ke}:U&&(l=t?{...t,source:"connector"}:void 0)}else if(Ce&&g==="event"&&N){const p=Lt(H,de,ue.map(S=>({filterSchema:S.metadataSchema})));l={kind:"event",source:"workspace",...k?{entity_type:k}:{},event_types:C,...Object.keys(p).length>0?{match:p}:{},execution:$,active_run:Q==="queue"?"queue":"coalesce"}}else Ce&&g==="time"&&(l={kind:"schedule",cron:be.trim(),...ce?{timezone:ce}:{},execution:"window",active_run:"coalesce",skip_if_unchanged:ke});s({ready:Ce,kind:g,trigger:l})},[Q,oe,A,be,Oe,C,$,H,g,fe,ce,t,N,s,Y,Ce,ve,de,ke,k,ue,ye,U]);const nt=l=>{const p=R.find(w=>String(w.id)===l),S=f.find(w=>w.key===p?.connector_key),Z=C.filter(w=>S?.automation_events?.some(De=>De.key===w)),E=S?.automation_events?.find(w=>w.key===Z[0]),_e=p?.connector_key!==(A?.connector_key??fe);if(Se(l),re(Z),!E)te(Mt);else if(_e){const w=E.defaults?.execution??"turn",De=E.defaults?.activeRun??"queue",Ve=Qe(w,E.defaults?.output??"silent");te(Mt),ge(w),se(Ie(w,Ve,De)),V(Ve)}},at=l=>{if(l==="workspace"){Se("workspace"),re(p=>p.filter(S=>ue.some(Z=>Z.key===S))),te({}),ge("window"),se("coalesce"),V("silent");return}nt(l)},ze=l=>{const p=C.includes(l)?C.filter(w=>w!==l):le.map(w=>w.key).filter(w=>w===l||C.includes(w));if(re(p),p[0]===C[0])return;const S=le.find(w=>w.key===p[0]),Z=S?.defaults?.execution??"turn",E=S?.defaults?.activeRun??"queue",_e=Qe(Z,S?.defaults?.output??"silent");ge(Z),se(Ie(Z,_e,E)),V(_e)},He=l=>{const p=l===lt?"":l,S=v.find(E=>E.slug===p),Z=At(v,S?.slug,h);we(p),re(E=>E.filter(_e=>Z.some(w=>w.key===_e))),te({})},Ue=l=>{re(p=>p.includes(l)?p.filter(S=>S!==l):ue.map(S=>S.key).filter(S=>S===l||p.includes(S)))},Re=[{value:"event",label:"Event"},{value:"time",label:"Schedule"},{value:"manual",label:"Manual"}].filter(l=>D.includes(l.value));return e.jsxs("div",{className:"space-y-4",children:[u?e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:"When"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose what starts this Automation. Its goal and context stay reusable."})]}):null,Re.length>1?e.jsx(gn,{value:g,options:Re,onChange:l=>{M(l),ge(l==="time"||l==="event"&&N?"window":"turn"),se(l==="time"||l==="event"&&N?"coalesce":"queue"),V("silent")}}):null,g==="event"?ie||N&&X?e.jsxs("div",{className:"space-y-2",children:[e.jsx(kt,{className:"h-9 w-full"}),e.jsx(kt,{className:"h-9 w-full"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Source"}),e.jsx(Gs,{connections:R,value:G,onValueChange:at,disabled:Te,includeWorkspaceEvents:!0,ariaLabel:"Source",placeholder:"Choose a source"}),U?e.jsx("p",{className:"text-xs text-muted-foreground",children:"This shared connection is managed outside this organization. Other Automation fields can still be edited."}):ye?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This Automation listens across all"," ",String(t?.connector_key)," connections. Other Automation fields can still be edited."]}):null]}),N?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:ue.length>1?"Events":"Event"}),ue.length>0?e.jsx(Tt,{events:ue,selectedKeys:C,onToggle:Ue}):e.jsx("div",{className:T(Je,"px-3 py-2 text-sm text-muted-foreground"),children:k?"This entity type has no declared Automation events.":"This workspace has no declared Automation events."}),We?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:We.description}):null,Be?e.jsxs("p",{className:"text-xs text-destructive",children:["This trigger filters on entity type “",k,"”, which no longer exists in this workspace. Clear the Entity type filter under Trigger options to save."]}):null,e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only declared Automation outputs in the current workspace can trigger this Automation. Ordinary saved events remain data."})]}),de?e.jsx(St,{schema:de,values:H,onValuesChange:l=>te(p=>Pt(p,de,l)),fieldIdPrefix:`${m}workspace-`},`${k||"workspace"}:${C.join(",")}`):null]}):A||ye?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:le.length>1?"Events":"Event"}),le.length?e.jsx(Tt,{events:le,selectedKeys:C,onToggle:ze}):e.jsx("div",{className:T(Je,"px-3 py-2 text-sm text-muted-foreground"),children:"This connector has not published subscribable events."}),je?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:je.description}):null]}),typeof H.resource_ref=="string"||ve?e.jsxs("div",{className:"space-y-3",children:[typeof H.resource_ref=="string"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Resource"}),e.jsx("div",{className:T(Je,"px-3 py-2 text-sm"),children:H.resource_ref})]}):null,ve?e.jsx(St,{schema:ve,values:H,onValuesChange:l=>te(p=>Pt(p,ve,l)),fieldIdPrefix:m},C.join(",")):null]}):null]}):G?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose workspace events or a connected app as the source."})]}):g==="time"?e.jsx(hn,{value:be,onChange:Pe}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this Automation explicitly from Lobu, the API, CLI, or MCP."}),g!=="manual"&&!Te?e.jsxs(xs,{open:x,onOpenChange:K,children:[e.jsx(ps,{asChild:!0,children:e.jsxs(z,{type:"button",variant:"ghost",className:"h-auto w-full justify-between px-0 py-1 text-muted-foreground hover:bg-transparent hover:text-foreground",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm",children:[e.jsx(gs,{className:"h-4 w-4"}),"Trigger options",e.jsxs("span",{className:"font-normal text-muted-foreground",children:["· ",$==="turn"?"Each event":"Window"," ·"," ",g==="time"?"Combine":N?Q==="queue"?"Queue":"Combine":Q==="queue"?"Queue":Q==="coalesce"?"Combine":"Update current run",g==="event"&&!N?` · ${$==="turn"&&Y==="reply_to_source"?"Reply":"Save in Lobu"}`:""]})]}),e.jsx(Ht,{className:T("h-4 w-4 transition-transform",x&&"rotate-180")})]})}),e.jsxs(fs,{className:"space-y-4 pt-3",children:[g==="event"&&N?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Entity type filter"}),e.jsxs(me,{value:k||lt,onValueChange:He,children:[e.jsx(he,{"aria-label":"Entity type filter",children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:lt,children:"All event types"}),Ae.map(l=>e.jsx(P,{value:l.slug,children:l.name},l.slug))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Limit selected events to outputs linked to this entity type."})]}):null,g==="event"?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Run"}),e.jsxs(me,{value:$,onValueChange:l=>{const p=l,S=Qe(p,Y);ge(p),V(S),se(Ie(p,S,Q))},children:[e.jsx(he,{children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:"turn",children:"Start a run for each event"}),e.jsx(P,{value:"window",children:"Batch events into a window"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"When busy"}),e.jsxs(me,{value:Q,onValueChange:l=>se(l),children:[e.jsx(he,{children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:"queue",children:"Queue"}),e.jsx(P,{value:"coalesce",children:"Combine waiting events"}),!N&&$==="turn"&&Y==="reply_to_source"&&je?.capabilities?.steering?e.jsx(P,{value:"steer",children:"Update the current run"}):null]})]})]})]}):null,$==="window"&&(g==="time"||!N)?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Skip unchanged windows"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No source changes means no agent run or LLM call."})]}),e.jsx(Ys,{"aria-label":"Skip unchanged windows",checked:ke,onCheckedChange:Ee})]}):null,g==="event"&&!N&&$==="turn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Result"}),e.jsxs(me,{value:Y,onValueChange:l=>{const p=l;V(p),se(Ie($,p,Q))},children:[e.jsx(he,{children:e.jsx(xe,{})}),e.jsxs(pe,{children:[je?.capabilities?.replyToSource?e.jsx(P,{value:"reply_to_source",children:"Reply where it happened"}):null,e.jsx(P,{value:"silent",children:"Save in Lobu"})]})]}),je?.capabilities?.replyToSource?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Messages matching this trigger run the Automation; anything else in the conversation stays with the connected agent."}):null]}):null]})]}):null]})}const vn=16;function qe(){return crypto.randomUUID()}function yn(n){return n===void 0?[{key:qe(),initial:void 0}]:n.length===0?[{key:qe(),initial:null}]:n.map(t=>({key:qe(),initial:t}))}function Zt(n){return n?n.kind==="time"||n.trigger?.kind==="schedule":!1}function jn(n,t){return n?n.ready===t.ready&&n.kind===t.kind&&JSON.stringify(n.trigger)===JSON.stringify(t.trigger):!1}function _n(n,t){const s=n.map(o=>t[o.key]??{ready:!1,kind:"event"});if(!(n.length>1)&&s[0]?.kind==="manual")return{ready:s[0].ready,triggers:[]};const u=s.filter(Zt).length;return{ready:!s.some(o=>o.kind==="manual")&&u<=1&&s.length>0&&s.every(o=>o.ready&&o.trigger),triggers:s.filter(o=>o.trigger).map(o=>o.trigger)}}function Yn({organizationId:n,initialTriggers:t,onChange:s}){const d=i.useId(),[u,m]=i.useState(()=>yn(t)),[c,o]=i.useState({}),r=i.useRef("");i.useEffect(()=>{const h=_n(u,c),v=JSON.stringify(h);v!==r.current&&(r.current=v,s(h))},[u,c,s]);const j=u.find(h=>Zt(c[h.key]))?.key??u.find(h=>h.initial&&typeof h.initial=="object"&&h.initial.kind==="schedule"&&!c[h.key])?.key??null,R=i.useCallback((h,v)=>{o(_=>jn(_[h],v)?_:{..._,[h]:v})},[]),f=()=>{const h=u[0],v=h?c[h.key]:void 0;if(u.length===1&&(v?.kind==="manual"||h?.initial===null)){const _=qe();o({}),m([{key:_,initial:void 0}]);return}m(_=>[..._,{key:qe(),initial:void 0}])},B=h=>{if(u.length<=1){const v=qe();o({}),m([{key:v,initial:null}]);return}o(v=>{const _={...v};return delete _[h],_}),m(v=>v.filter(_=>_.key!==h))};return e.jsxs("section",{className:"space-y-4","aria-labelledby":`${d}-heading`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{id:`${d}-heading`,className:"text-sm font-medium",children:"When"}),u.length>1?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Each trigger can start this Automation independently (OR). At most one schedule. If several match the same event, the first listed wins for run options."}):null]}),e.jsx("div",{className:"space-y-3",children:u.map((h,v)=>{const _=u.length>1,O=_?j&&j!==h.key?["event"]:["event","time"]:["event","time","manual"],D=c[h.key],b=_||(D?D.kind!=="manual":h.initial!==null);return e.jsxs("div",{className:T("space-y-3 rounded-lg border bg-card/40 p-3",_&&"relative"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:_?`Trigger ${v+1}`:"Trigger"}),b?e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive","aria-label":_?`Remove trigger ${v+1}`:"Clear trigger",onClick:()=>B(h.key),children:e.jsx(Yt,{className:"h-3.5 w-3.5"})}):null]}),e.jsx(Nn,{slotKey:h.key,organizationId:n,initial:h.initial,kinds:O,fieldIdPrefix:`${d}-${h.key}-`,onChange:R})]},h.key)})}),e.jsxs(z,{type:"button",variant:"outline",size:"sm",className:"w-full sm:w-auto",onClick:f,disabled:u.length>=vn,children:[e.jsx(Ge,{className:"mr-1.5 h-3.5 w-3.5"}),"Add another trigger"]})]})}function Nn({slotKey:n,organizationId:t,initial:s,kinds:d,fieldIdPrefix:u,onChange:m}){const c=i.useCallback(o=>m(n,o),[m,n]);return e.jsx(fn,{organizationId:t,initialTrigger:s,allowedKinds:d,showSectionHeader:!1,fieldIdPrefix:u,onChange:c})}const Rt={agents:!0,lobuEmbedded:!1};function bn(){const{data:n}=ys({queryKey:["features"],queryFn:async()=>{const t=await js(`${_s}/api/features`);return t.ok?t.json():Rt},staleTime:3e4,refetchInterval:6e4});return n??Rt}const Dt=4096;function kn({open:n,onOpenChange:t,initial:s,onSubmit:d}){const[u,m]=i.useState(""),[c,o]=i.useState(""),[r,j]=i.useState(null);i.useEffect(()=>{n&&(m(s?.name??""),o(s?.query??""),j(null))},[n,s]);const R=()=>{const B=u.trim(),h=c.trim();if(!B){j("Give the SQL source a name.");return}if(!h){j("Enter a query.");return}if(h.length>Dt){j(`Query is too long (${h.length} chars, max ${Dt}).`);return}d({name:B,query:h}),t(!1)},f=!!s;return e.jsx(Ns,{open:n,onOpenChange:t,children:e.jsxs(bs,{className:"max-w-2xl",children:[e.jsxs(ks,{children:[e.jsx(Ss,{children:f?"Edit SQL source":"SQL source"}),e.jsx(ws,{children:"Write a query the automation runs each period. It becomes a reference in the prompt — the query travels with the chip."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"sql-source-name",children:"Name"}),e.jsx(ae,{id:"sql-source-name",value:u,onChange:B=>m(B.target.value),placeholder:"recent_cancellations",autoFocus:!f}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The output-field name this source fills."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"sql-source-query",children:"Query"}),e.jsx(Ze,{value:c,onChange:o,language:"sql",placeholder:"SELECT id, payload_text, occurred_at FROM events ORDER BY occurred_at DESC",minHeight:"160px"})]}),r?e.jsx("p",{className:"text-sm text-destructive",children:r}):null]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(z,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(z,{onClick:R,children:f?"Save":"Add source"})]})]})})}const Sn=["skill","feed","connection","connector","metric","entity_type"];function wn({value:n,onChange:t,library:s,pinned:d,required:u,error:m,owner:c,agentId:o,sources:r,onAddSources:j}){const R=sn(Sn,Et,{skills:s,skillAgentId:o||null}),f=i.useRef(null),[B,h]=i.useState(null),v=i.useMemo(()=>{if(!r)return[];const b=new Set(r.map(J=>J.query.trim()));return Ot(n).filter(J=>!b.has(J.query.trim()))},[n,r]),_=nn(n),O=an(d.filter(b=>_.includes(b.name)),s),D=s.length>0;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(y,{htmlFor:"automation-prompt",children:["Instructions"," ",u?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),_.length>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[_.length,"/",Et," skills"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring",children:e.jsx(on,{value:n,onChange:t,onSubmit:()=>{},submitOnEnter:!1,searchRefs:R,handleRef:f,onSqlRequest:()=>h({}),onSqlEdit:(b,J)=>h({initial:b,pos:J}),placeholder:D?"What should this Automation do? Type @ to pull in a skill or a data source.":"What should this Automation do? Type @ to pull in a data source.",className:"[&_.ProseMirror]:min-h-[7rem] [&_.ProseMirror]:max-h-72 [&_.ProseMirror]:overflow-y-auto"})}),e.jsx(kn,{open:B!==null,onOpenChange:b=>{b||h(null)},initial:B?.initial,onSubmit:b=>{f.current?.insertSql(b,B?.pos),h(null)}}),v.length>0&&j?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border border-dashed p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[v.length===1?`"${v[0]?.name}" is referenced in the instructions but is not a source on this Automation.`:`${v.length} references in the instructions are not sources on this Automation.`," ","Editing an Automation does not add them automatically."]}),e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:()=>j(Ot(n,r)),children:v.length===1?"Add as a source":"Add as sources"})]}):null,_.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:_.map(b=>{const J=O.includes(b),g=!s.some(M=>M.name===b);return e.jsxs(Cs,{variant:g?"destructive":"secondary",className:"font-normal",children:[b,g?" · unavailable":J?" · newer text":null]},b)})}):null,O.length>0?e.jsxs("p",{className:"rounded-lg border border-dashed p-3 text-xs text-muted-foreground",children:[O.length===1?`"${O[0]}" has been edited since this Automation pinned it.`:`${O.length} skills have been edited since this Automation pinned them.`," ","This Automation keeps running the pinned text until you save it again."]}):null,m?e.jsx("p",{className:"text-xs text-destructive",children:m}):null,!D&&o?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This agent has no skills yet."," ",e.jsx(Es,{to:"/$owner/agents/$agentId/skills",params:{owner:c,agentId:o},className:"font-medium text-foreground underline underline-offset-2",children:"Add one"})," ","to reuse instructions across Automations."]}):m?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:D?"Type @ to pull in a skill, a feed, connection, connector, metric, entity type, or a SQL query. Skill text is saved with this version, so later edits to the skill do not change this Automation until you update it.":"Type @ to pull in a feed, connection, connector, metric, entity type, or a SQL query this Automation should read."})]})}const Cn=["connection","connector","feed","metric","entity_type"];function En({sources:n,onChange:t,disabled:s}){const{currentOwner:d,resolvedOrganizationId:u}=Xt(),[m,c]=i.useState(""),{refs:o}=rn({owner:d,organizationId:u,kinds:Cn,query:m,limitPerKind:10});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Sources"}),n.length>0?e.jsx("ul",{className:"space-y-2",children:n.map(r=>e.jsxs("li",{className:"flex items-start gap-2 rounded-lg border bg-background p-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-mono text-xs font-medium",children:r.name}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:r.query})]}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0","aria-label":`Remove source ${r.name}`,disabled:s,onClick:()=>t(n.filter(j=>j.query!==r.query)),children:e.jsx(Jt,{className:"h-3.5 w-3.5"})})]},r.query))}):null,e.jsx("div",{className:"flex gap-2",children:e.jsx(tt,{searchPlaceholder:"Search feeds, connections, metrics…",emptyText:"No matching reference.",onQueryChange:c,trigger:()=>e.jsxs(z,{type:"button",variant:"outline",size:"sm",disabled:s,children:[e.jsx(Ge,{className:"mr-2 h-3.5 w-3.5"}),"Add source"]}),children:r=>o.map(j=>e.jsxs($e,{value:`${j.label} ${j.kind}`,onSelect:()=>{t(cn(j,n)),r()},children:[e.jsx("span",{className:"truncate text-sm",children:j.label}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-muted-foreground",children:j.kind})]},`${j.kind}:${j.id}`))})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Data handed to the agent alongside its instructions, and what change detection is measured against. Editing an Automation does not re-read the instructions for these — this list is what runs. To add a SQL source, write it with @ in the instructions above. Automation-owned; skills never add or remove sources."})]})}function On({organizationId:n,value:t,onChange:s,className:d}){const{data:u=[]}=Os(n),m=Hs(u),c=m.find(o=>o.id===t);return e.jsx(tt,{contentClassName:"w-[300px]",searchPlaceholder:"Search entities...",emptyText:"No entities found.",trigger:o=>e.jsxs(z,{variant:"outline",role:"combobox","aria-expanded":o,className:T("w-full justify-between",d),children:[c?`${c.name} (${c.entityType})`:"All workspace",e.jsx(gt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:o=>e.jsxs(e.Fragment,{children:[e.jsxs($e,{value:"all workspace",onSelect:()=>{s(void 0),o()},className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",t===void 0?"opacity-100":"opacity-0")}),e.jsx("span",{children:"All workspace"})]}),m.map(r=>e.jsxs($e,{value:`${r.name} ${r.entityType}`,onSelect:()=>{s(r.id),o()},className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",t===r.id?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[r.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",r.entityType,")"]})]})]},r.id))]})})}function xt(n){if(Array.isArray(n))return n;if(typeof n=="string"&&n.startsWith("{")&&n.endsWith("}")){const t=n.slice(1,-1);return t?t.split(",").map(s=>s.trim()):[]}return[]}const An=Xs.map(n=>({value:n,label:Zs[n]})),It=[{value:"agent",label:"Agent",hint:"An agent reads the window and follows your instructions."},{value:"code",label:"Code",hint:"A deterministic script processes each completed window."},{value:"both",label:"Agent + code",hint:"An agent extracts per your instructions, then the script runs."}];function qt(n){const t=!!(n?.prompt?.trim()||n?.skills?.some(d=>d.content.trim())),s=!!n?.reaction_script?.trim();return t&&s?"both":s?"code":"agent"}const Fn=["text","number","date","boolean","json"],Pn=[{value:"key",label:"Key"},{value:"searchable",label:"Searchable"},{value:"plain",label:"Plain"}],ut=[{value:"plan",label:"Plan first"},{value:"auto",label:"Auto"},{value:"acceptEdits",label:"Accept edits"},{value:"dontAsk",label:"Don't ask"},{value:"bypassPermissions",label:"Bypass permissions"}];let $t=0;function Mn(){return $t+=1,`field-${$t}`}function pt(n={}){return{id:Mn(),name:n.name??"",type:n.type??"text",role:n.role??"plain"}}function Ln(n){return n.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,t=>t.toUpperCase())}function Ke(n){return n.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")}function Tn(n){return n?Object.keys(n).every(t=>["entity_type","entity_path","key_fields","key_output_field"].includes(t)):!0}function Rn(n){return n?n.every(t=>!t||typeof t!="object"||Array.isArray(t)?!1:Object.keys(t).every(s=>["slug","name","source_path","value_field"].includes(s))):!0}function Kt(n){return n?Tn(n.keying_config)&&Rn(n.classifiers)?"fields":"json":"fields"}function Wt(n){const t=n?.keying_config?.entity_type;return typeof t=="string"?t:""}function Bt(n){const t=n?.keying_config?.entity_path;return typeof t=="string"&&t.trim()?t:"$"}function zt(n){const t=new Map,s=Array.isArray(n?.keying_config?.key_fields)?n?.keying_config?.key_fields:[];for(const d of s){if(typeof d!="string")continue;const u=Ke(d);u&&t.set(u,pt({name:u,role:"key"}))}for(const d of n?.classifiers??[]){if(!d||typeof d!="object"||Array.isArray(d))continue;const u=d.value_field;if(typeof u!="string")continue;const m=Ke(u);!m||t.has(m)||t.set(m,pt({name:m,role:"searchable"}))}return Array.from(t.values())}function Ne(n,t){const s=n?.execution_config?.[t];return typeof s=="number"||typeof s=="string"?String(s):""}function Ut(n,t,s){const d=n?.execution_config?.[t];return typeof d=="string"&&s.includes(d)?d:""}function dt(n,t){const s=n.trim();if(!s)return{};const d=Number(s);return Number.isFinite(d)?{value:d}:{error:`${t} must be a number.`}}function Vt({entityType:n,entityPath:t,fields:s}){const d=s.map(r=>({...r,name:Ke(r.name)})).filter(r=>r.name),u=d.filter(r=>r.role==="key").map(r=>r.name),m=d.filter(r=>r.role==="searchable"),c=Ke(n),o=t.trim()||"$";return u.length>0&&!c?{error:"Key fields need an output entity type."}:(u.length>0||m.length>0,{keyingConfig:u.length>0?{entity_type:c,entity_path:o,key_fields:u,key_output_field:`${c}_key`}:void 0,classifiers:m.length>0?m.map(r=>({slug:r.name,name:Ln(r.name),source_path:o,value_field:r.name})):void 0})}function Dn(n,t){return e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:n}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]})}function Qt(n){return!!(n?.classifiers?.length||n?.keying_config||n?.reactions_guidance||n?.model_config||n?.execution_config||n?.sources?.length||xt(n?.tags).length)}function In({organizationId:n,entityId:t,prefill:s,onSubmit:d,isSubmitting:u,error:m,isEditing:c,onCancel:o,triggerFields:r,submitLabel:j="Create Automation",submitDisabled:R=!1,triggers:f}){const{lobuEmbedded:B}=bn(),{currentOwner:h}=Xt(),{data:v=[]}=As(),{data:_=[]}=Fs(),[O,D]=i.useState(s?.managed_agent_id??""),b=!!s?.managed_agent_id&&!c,[J,g]=i.useState(s?.device_worker_id??""),[M,G]=i.useState(s?.device_worker_id?"device":"agent"),[Se,N]=i.useState(s?.agent_kind??""),{data:oe=[]}=Gt({organizationId:n}),[k,we]=i.useState(s?.name??""),[Fe,C]=i.useState(s?.slug??""),[re,H]=i.useState(!!s?.slug),[te,be]=i.useState(s?.description??""),[Pe,ce]=i.useState(s?.prompt??""),[$,ge]=i.useState(!1),Y=s?.skills??[],[V,Q]=i.useState(s?.sources??[]),[se,ke]=i.useState(s?.entity_id??t),[Ee,x]=i.useState(s?.reaction_script??""),[K,A]=i.useState(()=>qt(s)),[ie,X]=i.useState(s?.classifiers?JSON.stringify(s.classifiers,null,2):""),[fe,U]=i.useState(null),[ye,Oe]=i.useState(s?.keying_config?JSON.stringify(s.keying_config,null,2):""),[le,I]=i.useState(null),[je,Me]=i.useState(()=>Kt(s)),[Ae,ue]=i.useState(()=>Wt(s)),[Le,We]=i.useState(()=>Bt(s)),[ve,de]=i.useState(()=>zt(s)),[Be,Te]=i.useState(s?.reactions_guidance??""),[st,Ce]=i.useState(()=>Ne(s,"timeout_seconds")),[nt,at]=i.useState(()=>Ne(s,"max_budget_usd")),[ze,He]=i.useState(()=>Ne(s,"model")),[Ue,ot]=i.useState(()=>Ut(s,"permission_mode",ut.map(a=>a.value))),[Re,l]=i.useState(()=>Ne(s,"effort")),[p,S]=i.useState(()=>Ne(s,"finalize_nudges")),[Z,E]=i.useState(null),[_e,w]=i.useState(xt(s?.tags).join(", ")),[De,Ve]=i.useState(""),[rt,ft]=i.useState(!!(c||Qt(s)));i.useEffect(()=>{s&&(we(s.name??""),C(s.slug??""),H(!!s.slug),be(s.description??""),ce(s.prompt??""),ge(!1),Q(s.sources??[]),ke(s.entity_id??t),g(s.device_worker_id??""),G(s.device_worker_id?"device":"agent"),N(s.agent_kind??""),x(s.reaction_script??""),A(qt(s)),X(s.classifiers?JSON.stringify(s.classifiers,null,2):""),U(null),Oe(s.keying_config?JSON.stringify(s.keying_config,null,2):""),I(null),Me(Kt(s)),ue(Wt(s)),We(Bt(s)),de(zt(s)),Te(s.reactions_guidance??""),Ce(Ne(s,"timeout_seconds")),at(Ne(s,"max_budget_usd")),He(Ne(s,"model")),ot(Ut(s,"permission_mode",ut.map(a=>a.value))),l(Ne(s,"effort")),S(Ne(s,"finalize_nudges")),E(null),w(xt(s.tags).join(", ")),Ve(""),D(s.managed_agent_id??""),ft(!!(c||Qt(s))))},[s,t,c]);const es=re?Fe:Ct(k),{data:ts}=Ps(O||null),{data:ss}=Ms(O||null,{enabled:!!O}),ct=tn(ts??null,ss?.catalog??[]),ns=ln(f),it=Ee.trim().length>0,Ye=!c&&K==="code"?"":Pe,as=!c&&K==="agent"?void 0:Ee.trim()||void 0,vt=(c||K==="code")&&it,yt=un(Ye,ct,f,vt),os=$||Ye.trim()!==""?yt:null,jt=dn(Ye,ct),_t=!c&&K!=="agent",Nt=!!k.trim()&&!yt&&(!_t||it),rs=ns&&!vt&&jt.length===0,cs=()=>{if(!Nt)return;let a,F;if(je==="fields"){const ne=Vt({entityType:Ae,entityPath:Le,fields:ve});if(ne.error){I(ne.error);return}a=ne.classifiers,F=ne.keyingConfig,U(null),I(null)}else{if(ie.trim())try{const ne=JSON.parse(ie);if(!Array.isArray(ne)){U("Classifiers must be a JSON array.");return}a=ne}catch{U("Invalid JSON. Please check the syntax.");return}if(U(null),ye.trim())try{const ne=JSON.parse(ye);if(typeof ne!="object"||Array.isArray(ne)){I("Keying config must be a JSON object.");return}F=ne}catch{I("Invalid JSON. Please check the syntax.");return}I(null)}const L=dt(st,"Timeout");if(L.error){E(L.error);return}if(L.value!==void 0&&(!Number.isInteger(L.value)||L.value<1)){E("Timeout must be a whole number greater than 0.");return}const q=dt(nt,"Budget");if(q.error){E(q.error);return}if(q.value!==void 0&&q.value<0){E("Budget cannot be negative.");return}const ee=dt(p,"Finalize nudges");if(ee.error){E(ee.error);return}if(ee.value!==void 0&&(!Number.isInteger(ee.value)||ee.value<0||ee.value>5)){E("Finalize nudges must be a whole number from 0 to 5.");return}const W={...L.value!==void 0?{timeout_seconds:L.value}:{},...q.value!==void 0?{max_budget_usd:q.value}:{},...ze.trim()?{model:ze.trim()}:{},...Ue?{permission_mode:Ue}:{},...Re.trim()?{effort:Re.trim()}:{},...ee.value!==void 0?{finalize_nudges:ee.value}:{}},is=Object.keys(W).length>0||c?W:void 0;E(null);const ls=_e.trim()?_e.split(",").map(ne=>ne.trim()).filter(Boolean):void 0;d({slug:es,name:k.trim(),description:te.trim()||void 0,prompt:Ye,skills:jt,entity_id:se,sources:V,reaction_script:as,classifiers:a,keying_config:F,reactions_guidance:Be.trim()||void 0,execution_config:is,tags:ls,change_notes:De.trim()||void 0,managed_agent_id:M==="agent"&&O.trim()||null,device_worker_id:M==="device"&&J.trim()||null,agent_kind:M==="device"&&Se.trim()||null})},bt=e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y,{htmlFor:"scratch-reaction",children:["Reaction Script"," ",_t?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(Ze,{value:Ee,onChange:x,language:"typescript",placeholder:"export default async function reaction(ctx) { ... }",minHeight:"120px"}),c?null:e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Runs deterministically on every completed window, after agent extraction. Declare an ",e.jsx("code",{children:"input"})," export to set the window's extraction contract."]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(y,{htmlFor:"scratch-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),!c&&e.jsx("button",{type:"button",onClick:()=>H(!re),className:"text-xs text-muted-foreground hover:text-foreground",children:re?"Use automatic slug":"Customize slug"})]}),e.jsx(ae,{id:"scratch-name",value:k,onChange:a=>we(a.target.value),placeholder:"e.g., Escalation signals"}),!c&&re?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-slug",children:"Slug"}),e.jsx(ae,{id:"scratch-slug",value:Fe,onChange:a=>C(a.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:Ct(k)||"custom-slug"})]}):null]})}),c?null:e.jsxs("fieldset",{className:"space-y-2",children:[e.jsx("legend",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"How does this run?"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:It.map(a=>e.jsx("button",{type:"button","aria-pressed":K===a.value,onClick:()=>A(a.value),className:T("rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors",K===a.value?"bg-secondary text-secondary-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:a.label},a.value))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:It.find(a=>a.value===K)?.hint})]}),c||K!=="code"?e.jsx(wn,{value:Pe,onChange:a=>{ge(!0),ce(a)},library:ct,pinned:Y,required:rs,error:os,owner:h??"",agentId:O,sources:c?V:void 0,onAddSources:c?Q:void 0}):null,!c&&K!=="agent"?bt:null,c?e.jsx(En,{sources:V,onChange:Q,disabled:u}):null,e.jsx("div",{className:"space-y-4",children:r}),e.jsxs(z,{type:"button",variant:"ghost",className:"w-full justify-between px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-expanded":rt,"aria-controls":"automation-advanced-settings",onClick:()=>ft(a=>!a),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ls,{className:"h-4 w-4"}),"Advanced settings"]}),e.jsx(Ht,{className:T("h-4 w-4 transition-transform",rt&&"rotate-180")})]}),e.jsxs("div",{id:"automation-advanced-settings",className:T("space-y-4",!rt&&"hidden"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-description",children:"Description"}),e.jsx(ae,{id:"scratch-description",value:te,onChange:a=>be(a.target.value),placeholder:"What this automation does"})]}),!t&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Entity scope"}),e.jsx(On,{organizationId:n,value:se,onChange:ke}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit this automation to one workspace entity."})]}),c?bt:null,e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(y,{children:"Output fields"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Key fields become stable entity keys. Searchable fields become classifiers."})]}),e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(je==="fields"){const a=Vt({entityType:Ae,entityPath:Le,fields:ve});if(a.error){I(a.error);return}X(a.classifiers?JSON.stringify(a.classifiers,null,2):""),Oe(a.keyingConfig?JSON.stringify(a.keyingConfig,null,2):""),Me("json")}else Me("fields");U(null),I(null)},children:je==="fields"?"Edit JSON":"Use fields"})]}),je==="fields"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-output-entity-type",children:"Output entity type"}),e.jsx(tt,{contentClassName:"w-[320px]",searchPlaceholder:"Search or type a new type…",emptyText:"Type a name to create a new entity type.",trigger:a=>e.jsxs(z,{type:"button",variant:"outline",role:"combobox","aria-expanded":a,id:"scratch-output-entity-type",className:"w-full justify-between font-mono text-sm font-normal",children:[e.jsx("span",{className:T("truncate",!Ae&&"text-muted-foreground"),children:Ae||"Select entity type"}),e.jsx(gt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(a,F)=>{const L=Ke(F),q=oe.filter(W=>!W.backing_sql),ee=q.some(W=>W.slug===L);return e.jsxs(e.Fragment,{children:[q.map(W=>e.jsxs($e,{value:`${W.name??W.slug} ${W.slug}`,onSelect:()=>{ue(W.slug),I(null),a()},className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",Ae===W.slug?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-sm",children:W.slug}),W.name&&W.name!==W.slug&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:W.name})]})]},W.slug)),L&&!ee&&e.jsxs($e,{value:F,onSelect:()=>{ue(L),I(null),a()},className:"cursor-pointer",children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"text-sm",children:["Create"," ",e.jsx("span",{className:"font-mono",children:L})]})]})]})}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-output-path",children:"Output path"}),e.jsx(ae,{id:"scratch-output-path",value:Le,onChange:a=>{We(a.target.value),I(null)},placeholder:"$.items[*]",className:"font-mono text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(y,{children:"Fields"}),e.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{de(a=>[...a,pt()]),U(null),I(null)},children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),"Add field"]})]}),ve.length===0?e.jsx("div",{className:T(Je,"px-3 py-2 text-sm text-muted-foreground"),children:"No output fields configured."}):e.jsx("div",{className:"space-y-2",children:ve.map(a=>e.jsxs("div",{className:T(Je,"grid gap-2 p-3 sm:grid-cols-[minmax(0,1fr)_128px_minmax(0,240px)_auto]"),children:[e.jsx(ae,{value:a.name,onChange:F=>{const L=Ke(F.target.value);de(q=>q.map(ee=>ee.id===a.id?{...ee,name:L}:ee)),U(null),I(null)},placeholder:"severity","aria-label":"Output field name",className:"font-mono text-sm"}),e.jsxs(me,{value:a.type,onValueChange:F=>{de(L=>L.map(q=>q.id===a.id?{...q,type:F}:q))},children:[e.jsx(he,{"aria-label":"Output field type",children:e.jsx(xe,{})}),e.jsx(pe,{children:Fn.map(F=>e.jsx(P,{value:F,children:F},F))})]}),e.jsx("div",{className:"grid grid-cols-3 rounded-md border border-input bg-background p-1",children:Pn.map(F=>e.jsx("button",{type:"button",onClick:()=>{de(L=>L.map(q=>q.id===a.id?{...q,role:F.value}:q)),U(null),I(null)},className:T("rounded-sm px-2 py-1 text-xs transition-colors",a.role===F.value?"bg-muted/70 text-foreground":"text-muted-foreground hover:text-foreground"),children:F.label},F.value))}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:()=>{de(F=>F.filter(L=>L.id!==a.id)),U(null),I(null)},"aria-label":"Remove output field",children:e.jsx(Yt,{className:"h-4 w-4"})})]},a.id))})]}),le&&e.jsx("p",{className:"text-xs text-destructive",children:le}),fe&&e.jsx("p",{className:"text-xs text-destructive",children:fe})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-classifiers",children:"Classifiers (JSON)"}),e.jsx(Ze,{value:ie,onChange:a=>{X(a),U(null)},language:"json",placeholder:'[{ "slug": "sentiment", "name": "Sentiment", "source_path": "$.analysis[*]", "value_field": "sentiment" }]',minHeight:"80px"}),fe&&e.jsx("p",{className:"text-xs text-destructive",children:fe})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-keying-config",children:"Keying Config (JSON)"}),e.jsx(Ze,{value:ye,onChange:a=>{Oe(a),I(null)},language:"json",placeholder:'{ "entity_type": "topic", "entity_path": "$.items[*]", "key_fields": ["name"], "key_output_field": "entity_key" }',minHeight:"60px"}),le&&e.jsx("p",{className:"text-xs text-destructive",children:le})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-reactions-guidance",children:"Reactions Guidance"}),e.jsx(Ts,{id:"scratch-reactions-guidance",value:Be,onChange:a=>Te(a.target.value),placeholder:"Guidance text for the reaction system (e.g., when to alert, severity thresholds)...",className:"font-mono text-xs min-h-[80px]"})]}),e.jsxs("div",{className:"space-y-4",children:[Dn("Run settings","Choose where the automation runs and the budget it can use."),!b&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-runs-on",children:"Runs on"}),e.jsxs(me,{value:M,onValueChange:a=>G(a),children:[e.jsx(he,{id:"scratch-runs-on",className:"text-sm",children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:"agent",children:"Managed agent"}),e.jsx(P,{value:"device",children:"On a device"}),e.jsx(P,{value:"manual",children:"Manual-only"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:M==="agent"?"Automated runs dispatch to a managed Lobu agent.":M==="device"?"Automated runs are claimed and executed locally by a device worker (Mac app, remote worker).":"No executor — this automation runs only when started manually by a connected client."})]}),!b&&M==="agent"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-agent-id",children:"Agent"}),B?e.jsxs(me,{value:O||"__unselected__",onValueChange:a=>{D(a==="__unselected__"?"":a)},children:[e.jsx(he,{id:"scratch-agent-id",className:"font-mono text-sm",children:e.jsx(xe,{placeholder:"Select a Lobu agent"})}),e.jsx(pe,{children:v.map(a=>e.jsxs(P,{value:a.agentId,children:[a.name," (",a.agentId,")"]},a.agentId))})]}):e.jsx(ae,{id:"scratch-agent-id",value:O,onChange:a=>{D(a.target.value)},placeholder:"e.g., agent-123",className:"font-mono text-sm"})]}),!b&&M==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-device-id",children:"Device"}),e.jsxs(me,{value:J||"__unselected__",onValueChange:a=>g(a==="__unselected__"?"":a),children:[e.jsx(he,{id:"scratch-device-id",className:"font-mono text-sm",children:e.jsx(xe,{placeholder:"Select a device worker"})}),e.jsx(pe,{children:_.map(a=>e.jsx(P,{value:a.id,children:a.label||a.platform||a.id},a.id))})]})]}),!b&&M==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-device-agent-kind",children:"Runs as"}),e.jsxs(me,{value:Se||"__default__",onValueChange:a=>N(a==="__default__"?"":a),children:[e.jsx(he,{id:"scratch-device-agent-kind",className:"text-sm",children:e.jsx(xe,{placeholder:"Device default"})}),e.jsxs(pe,{children:[e.jsx(P,{value:"__default__",children:"Device default"}),An.map(a=>e.jsx(P,{value:a.value,children:a.label},a.value))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Device default uses that device's preferred local agent. Availability is checked again when a run is claimed, so a run stays queued if its selected runtime is no longer available."})]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Model"}),e.jsx(en,{value:ze,onChange:a=>{He(a),E(null)},placeholder:"Use agent default"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-timeout",children:"Timeout seconds"}),e.jsx(ae,{id:"scratch-timeout",type:"number",min:1,max:86400,value:st,onChange:a=>{Ce(a.target.value),E(null)},placeholder:"600"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-permission-mode",children:"Permission mode"}),e.jsxs(me,{value:Ue||"__default__",onValueChange:a=>{ot(a==="__default__"?"":a),E(null)},children:[e.jsx(he,{id:"scratch-permission-mode",children:e.jsx(xe,{placeholder:"Default"})}),e.jsxs(pe,{children:[e.jsx(P,{value:"__default__",children:"Default"}),ut.map(a=>e.jsx(P,{value:a.value,children:a.label},a.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-effort",children:"Effort"}),e.jsx(ae,{id:"scratch-effort",value:Re,onChange:a=>{l(a.target.value),E(null)},placeholder:"Default","aria-describedby":"scratch-effort-help"}),e.jsx("p",{id:"scratch-effort-help",className:"text-xs text-muted-foreground",children:"For device runs, use a value supported by the selected CLI and model. Leave empty for its default."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-finalize-nudges",children:"Finalize nudges"}),e.jsx(ae,{id:"scratch-finalize-nudges",type:"number",min:0,max:5,value:p,onChange:a=>{S(a.target.value),E(null)},placeholder:"Default"})]})]}),Z&&e.jsx("p",{className:"text-xs text-destructive",children:Z})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-tags",children:"Tags"}),e.jsx(ae,{id:"scratch-tags",value:_e,onChange:a=>w(a.target.value),placeholder:"ops, support, risk"})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-change-notes",children:"Change notes"}),e.jsx(ae,{id:"scratch-change-notes",value:De,onChange:a=>Ve(a.target.value),placeholder:"What changed in this version?"})]})]})]}),m&&!fe&&!le&&!Z&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:m}),e.jsx(ht,{onCancel:o,children:e.jsx(z,{onClick:cs,disabled:!Nt||u||R,children:u?e.jsxs(e.Fragment,{children:[e.jsx(Rs,{size:"lg",className:"mr-2"}),c?"Saving...":"Creating..."]}):c?"Save Automation":j})})]})}function qn(n){const t=n.detail??{};return{name:n.name,slug:t.slug,description:t.description??n.description??void 0,prompt:t.prompt,triggers:t.triggers,sources:t.sources,classifiers:t.classifiers,keying_config:t.keying_config,reactions_guidance:t.reactions_guidance,reaction_script:t.reaction_script,model_config:t.model_config,execution_config:t.execution_config,tags:t.tags}}function Xn({onClose:n,hideCancel:t=!1,hideHeader:s=!1,organizationId:d,entityId:u,entityName:m,prefillAgentId:c,onSuccess:o,editingAutomation:r,catalogPrefill:j,onDraft:R,triggerFields:f,submitLabel:B,submitDisabled:h,createFields:v,onPrefillTriggers:_}){const O=Ds(),D=Is(),b=qs(),J=$s(),g=!!r,[M,G]=i.useState("template"),[Se,N]=i.useState(void 0),[oe,k]=i.useState(void 0),{data:we=[],isLoading:Fe}=Ks(),[C,re]=i.useState(""),H=i.useMemo(()=>c?{managed_agent_id:c}:void 0,[c]),te=i.useMemo(()=>we.map(x=>({key:x.id,name:x.name,description:x.description??"",badges:x.detail?.tags??[]})),[we]),be=i.useMemo(()=>te.filter(x=>x.name.toLowerCase().includes(C.toLowerCase())||x.description.toLowerCase().includes(C.toLowerCase())),[te,C]),Pe=x=>{const K=we.find(ie=>ie.id===x.key);if(!K)return;const A=qn(K);k(c?{...A,managed_agent_id:c}:A),_?.(A.triggers??[]),G("scratch")},ce=()=>{O.reset(),D.reset(),G("template"),N(void 0),k(void 0),n()},$=g?v?.triggers??r.triggers??[]:v?.triggers??oe?.triggers??j?.triggers??[],ge=async x=>{try{if(R){await R(x);return}if(g){const K=v?.triggers??r.triggers??[],A=r.reaction_script??"",ie=x.reaction_script??"";ie&&ie!==A&&await b.mutateAsync({automation_id:r.automation_id,reaction_script:ie}),await D.mutateAsync({automation_id:r.automation_id,name:x.name,description:x.description,prompt:x.prompt,sources:x.sources,set_as_current:!0,triggers:K,classifiers:x.classifiers,keying_config:x.keying_config,reactions_guidance:x.reactions_guidance,change_notes:x.change_notes}),!ie&&A&&await b.mutateAsync({automation_id:r.automation_id,reaction_script:""});const X={};x.model_config!==void 0&&(X.model_config=x.model_config),x.execution_config!==void 0&&(X.execution_config=x.execution_config),x.tags!==void 0&&(X.tags=x.tags),x.managed_agent_id!==void 0&&(X.managed_agent_id=x.managed_agent_id||null),x.agent_kind!==void 0&&(X.agent_kind=x.agent_kind||null),x.device_worker_id!==void 0&&(X.device_worker_id=x.device_worker_id||null),Object.keys(X).length>0&&await J.mutateAsync({automation_id:r.automation_id,...X}),ce(),o?.(r.automation_id)}else{const K=v?.triggers??oe?.triggers??j?.triggers??[],A=await O.mutateAsync({...x,managed_agent_id:x.managed_agent_id??void 0,device_worker_id:x.device_worker_id??void 0,agent_kind:x.agent_kind??void 0,triggers:K});ce(),A.automation_id&&o?.(A.automation_id)}}catch{}},Y=g?D:O;let V="Add an automation";g?V="Edit automation configuration (saves as a new version)":m&&(V=`Add an automation for ${m}`);const Q=r?{entity_id:r.entity_id,name:r.name,slug:r.slug,description:r.description,prompt:r.prompt,sources:r.sources,reaction_script:r.reaction_script,device_worker_id:r.device_worker_id??void 0,agent_kind:r.agent_kind??void 0,classifiers:r.classifiers,keying_config:r.keying_config,reactions_guidance:r.reactions_guidance,model_config:r.model_config,execution_config:r.execution_config,tags:r.tags,managed_agent_id:r.managed_agent_id??void 0}:void 0,se=g?"Edit Automation":"Create Automation",ke=e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:se}),e.jsx("p",{className:"text-sm text-muted-foreground",children:V})]}),Ee=e.jsxs("div",{className:"py-6 space-y-6",children:[!g&&e.jsxs("div",{className:"flex flex-wrap justify-start gap-2",children:[e.jsx(mt,{active:M==="template",onClick:()=>G("template"),icon:e.jsx(Ws,{className:"h-4 w-4"}),label:"From templates"}),e.jsx(mt,{active:M==="scratch",onClick:()=>{G("scratch"),N(void 0),k(void 0)},icon:e.jsx(Ge,{className:"h-4 w-4"}),label:"From scratch"}),e.jsx(mt,{active:M==="clone",onClick:()=>G("clone"),icon:e.jsx(Bs,{className:"h-4 w-4"}),label:"Clone existing"})]}),!g&&M==="template"?e.jsxs(e.Fragment,{children:[Fe?e.jsx(zs,{}):e.jsx(Us,{items:be,searchQuery:C,onSearchChange:re,onSelect:Pe,searchPlaceholder:"Search templates...",searchAriaLabel:"Search automation templates",emptyMessage:te.length===0?"No automation templates available.":void 0}),s&&!t?e.jsx(ht,{onCancel:ce}):null]}):!g&&M==="clone"&&!Se?e.jsxs(e.Fragment,{children:[e.jsx($n,{organizationId:d,onSelect:x=>{N(x),_?.(x.triggers??[]),G("scratch")}}),s&&!t?e.jsx(ht,{onCancel:ce}):null]}):e.jsx(In,{organizationId:d,entityId:u,prefill:Q??Se??oe??j??H,onSubmit:ge,isSubmitting:Y.isPending,error:Y.error?Y.error.message:null,isEditing:g,onCancel:t?void 0:ce,triggerFields:f,submitLabel:B,submitDisabled:h,triggers:$})]});return e.jsxs("div",{className:"flex flex-col",children:[s?null:ke,Ee]})}function mt({active:n,onClick:t,icon:s,label:d}){return e.jsxs("button",{type:"button",onClick:t,className:T("flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors",n?"border-primary bg-primary/5 text-primary":"border-border text-muted-foreground hover:border-muted-foreground/30 hover:text-foreground"),children:[s,d]})}function $n({organizationId:n,onSelect:t}){const{data:s,isLoading:d}=Vs(n),[u,m]=i.useState(""),c=(s||[]).filter(o=>o.name?.toLowerCase().includes(u.toLowerCase()));return d?e.jsx(Qs,{label:"automations",variant:"list-picker",rows:4}):!s||s.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"No existing automations to clone."}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",value:u,onChange:o=>m(o.target.value),placeholder:"Search automations...",className:"w-full rounded-md border px-3 py-2 text-sm bg-background"}),e.jsxs("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:[c.map(o=>e.jsxs("button",{type:"button",onClick:()=>t({name:`${o.name} (copy)`,slug:`${o.slug||o.automation_id}-copy`,prompt:o.prompt,classifiers:o.classifiers,keying_config:o.keying_config,triggers:o.triggers,sources:o.sources}),className:"w-full text-left rounded-md border p-3 hover:border-primary/50 hover:bg-primary/5 transition-colors",children:[e.jsx("p",{className:"text-sm font-medium",children:o.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[o.entity_name||"Space-level"," · v",o.version??"?"]})]},o.automation_id)),c.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No automations match your search."})]})]})}export{Yn as A,Xn as C};
1
+ import{r as i,j as e,bY as me,bZ as he,b_ as xe,b$ as pe,c0 as P,ab as ae,B as z,X as Jt,a as us,dI as ds,cb as Gt,el as ms,em as hs,S as kt,aa as y,aj as T,aS as Je,en as St,dz as xs,dB as ps,eo as gs,cP as Ht,dC as fs,bx as wt,ep as vs,de as tt,df as $e,aO as et,eq as gt,bw as Yt,P as Ge,cE as ys,an as js,ag as _s,er as Ns,es as bs,et as ks,eu as Ss,ev as ws,af as Cs,L as Es,a1 as Xt,ew as Os,bv as As,bb as Fs,cq as Ct,ex as Ps,ey as Ms,d5 as Ls,ea as Ts,c2 as ht,s as Rs,ez as Ds,eA as Is,eB as qs,eC as $s,eD as Ks,eE as Ws,eF as Bs,eG as zs,eH as Us,by as Vs,c7 as Qs}from"./index-BUr8321-.js";import{c as Js}from"./cronstrue-ChFyC9ps.js";import{C as Gs,f as Hs}from"./entity-options-1EaSGMX4.js";import{S as Ys}from"./switch-Dzse_XFM.js";import{a as Xs,A as Zs}from"./device-automation-BIjs7DZJ.js";import{M as en}from"./model-selector-DfbmHjLu.js";import{b as tn}from"./skill-editor-D_W3QlRz.js";import{C as Ze}from"./code-editor-BqGUZFt6.js";import{u as sn,M as Et,a as Ot,s as nn,o as an,b as on,c as rn,d as cn,e as ln,v as un,r as dn}from"./use-mention-search-uyW1Uwf6.js";const Xe=[{value:"*/15 * * * *",label:"Every 15 minutes"},{value:"0 * * * *",label:"Every hour"},{value:"0 */6 * * *",label:"Every 6 hours"},{value:"0 9 * * *",label:"Daily at 9:00 AM"},{value:"0 18 * * *",label:"Daily at 6:00 PM"},{value:"0 9 * * 1-5",label:"Weekdays at 9:00 AM"},{value:"0 9 * * 1",label:"Weekly · Monday 9:00 AM"},{value:"0 9 1 * *",label:"Monthly · 1st at 9:00 AM"},{value:"custom",label:"Custom cron…"}];function mn(n){const t=n.trim();if(!t)return null;try{return Js.toString(t,{throwExceptionOnParseError:!0})}catch{return null}}function hn({value:n,onChange:t,placeholder:s="No schedule",className:d}){const u=n??"",m=Xe.some(f=>f.value===u),[c,o]=i.useState(!m&&u!==""),r=f=>{f==="custom"?o(!0):(o(!1),t(f))},j=u?mn(u):null,R=u?e.jsx("p",{className:j?"text-xs text-muted-foreground":"text-xs text-destructive",children:j??"Not a valid cron expression."}):null;return!u&&!c?e.jsxs(me,{onValueChange:r,children:[e.jsx(he,{className:d??"w-full",children:e.jsx(xe,{placeholder:s})}),e.jsx(pe,{children:Xe.map(f=>e.jsxs(P,{value:f.value,children:[f.label,f.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:f.value})]},f.value))})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[c?e.jsx(ae,{placeholder:"0 */6 * * *",value:u,onChange:f=>t(f.target.value),className:"font-mono text-sm flex-1"}):e.jsxs(me,{value:u,onValueChange:r,children:[e.jsx(he,{className:d??"w-full flex-1",children:e.jsx(xe,{children:Xe.find(f=>f.value===u)?.label??u})}),e.jsx(pe,{children:Xe.map(f=>e.jsxs(P,{value:f.value,children:[f.label,f.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:f.value})]},f.value))})]}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",onClick:()=>{o(!1),t("")},children:e.jsx(Jt,{className:"h-4 w-4"})})]}),R]})}const lt="__all_workspace_event_types__",xn=[],pn={};function At(n,t,s){const d=new Map;if(!t)for(const[m,c]of Object.entries(s??{}))d.set(m,{key:m,label:wt(m),description:c.description});const u=[...n].filter(m=>!t||m.slug===t).sort((m,c)=>m.slug.localeCompare(c.slug));for(const m of u)for(const[c,o]of Object.entries(m.event_kinds??{})){const r=d.get(c);if(r){!r.description&&o.description&&(r.description=o.description),JSON.stringify(r.metadataSchema??null)!==JSON.stringify(o.metadataSchema??null)&&(r.metadataSchema=void 0);continue}d.set(c,{key:c,label:wt(c),description:o.description,metadataSchema:o.metadataSchema})}return[...d.values()].sort((m,c)=>m.label.localeCompare(c.label))}function Ft(n){const t=n[0];if(!t)return;const s=u=>JSON.stringify(Object.keys(u?.properties??{}).sort()),d=s(t);return n.every(u=>s(u)===d)?t:void 0}function Pt(n,t,s){const d=new Set(Object.keys(t.properties??{}));return{...Object.fromEntries(Object.entries(n).filter(([u])=>!d.has(u))),...s}}function Ie(n,t,s){return s==="steer"&&(n==="window"||t!=="reply_to_source")?"coalesce":s}function Qe(n,t){return n==="window"?"silent":t}function Mt(n){return Object.fromEntries(Object.entries(n).filter(([t])=>t==="resource_ref"||t==="resource_type"))}function Lt(n,t,s){const d=new Set(Object.keys(t?.properties??{})),u=new Set(s.flatMap(m=>Object.keys(m.filterSchema?.properties??{})));return Object.fromEntries(Object.entries(vs(n)).filter(([m])=>m==="resource_ref"||m==="resource_type"||!u.has(m)||d.has(m)))}function gn({value:n,options:t,onChange:s}){return e.jsx("div",{className:"inline-flex rounded-md border bg-muted/30 p-0.5 text-sm",children:t.map(d=>e.jsx("button",{type:"button","aria-pressed":n===d.value,onClick:()=>s(d.value),className:T("rounded px-3 py-1 transition-colors",n===d.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:d.label},d.value))})}function Tt({events:n,selectedKeys:t,onToggle:s,ariaLabel:d="Events"}){const u=i.useId(),m=n.filter(o=>t.includes(o.key)).map(o=>o.label),c=m.length===0?"Choose events":m.length===1?m[0]:`${m.length} events selected`;return e.jsx(tt,{contentClassName:"w-[var(--radix-popover-trigger-width)] min-w-[280px]",searchPlaceholder:"Filter events...",emptyText:"No events found.",trigger:o=>e.jsxs(z,{type:"button",variant:"outline",role:"combobox","aria-label":d,"aria-expanded":o,className:"w-full justify-between font-normal",children:[e.jsx("span",{className:T(m.length===0&&"text-muted-foreground"),children:c}),e.jsx(gt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>n.map((o,r)=>{const j=t.includes(o.key),R=`${u}-${r}-state`;return e.jsxs($e,{value:`${o.label} ${o.key}`,onSelect:()=>s(o.key),"aria-label":o.label,"aria-describedby":R,className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",j?"opacity-100":"opacity-0")}),o.label,e.jsx("span",{id:R,className:"sr-only",children:j?"Selected":"Not selected"})]},o.key)})})}function fn({organizationId:n,initialTrigger:t,onChange:s,allowedKinds:d,showSectionHeader:u=!0,fieldIdPrefix:m="automation-trigger-"}){const c=us(n,{status:"active",limit:500}),o=ds(n),r=Gt({organizationId:n}),j=ms({organizationId:n}),R=c.data??[],f=o.data??[],B=r.data??xn,h=j.data??pn,v=i.useMemo(()=>B.filter(l=>l.organization_id===n),[B,n]),_=t?.kind==="event"&&t?.source==="workspace",O=_||t===void 0,D=d?.length?[...d]:["event","time","manual"],b=D.join("|"),J=(()=>{const l=t===null?"manual":t?.kind==="schedule"?"time":"event";return D.includes(l)?l:D[0]??"event"})(),[g,M]=i.useState(J),[G,Se]=i.useState(_?"workspace":typeof t?.connection_id=="number"?String(t.connection_id):t?.kind==="event"&&t.connector_key?"":"workspace"),N=G==="workspace",oe=N?"":G,[k,we]=i.useState(typeof t?.entity_type=="string"?t.entity_type:""),Fe=i.useMemo(()=>Array.isArray(t?.event_types)?t.event_types:[],[t]),[C,re]=i.useState(()=>Fe.filter(l=>typeof l=="string")),[H,te]=i.useState(t?.match&&typeof t.match=="object"&&!Array.isArray(t.match)?t.match:{}),[be,Pe]=i.useState(typeof t?.cron=="string"?t.cron:"0 9 * * 1-5"),ce=typeof t?.timezone=="string"?t.timezone:void 0,[$,ge]=i.useState(t?.kind==="schedule"||O&&t?.execution!=="turn"||t?.execution==="window"?"window":"turn"),[Y,V]=i.useState(Qe($,t?.output==="reply_to_source"?"reply_to_source":"silent")),[Q,se]=i.useState(t?.kind==="schedule"||O&&t?.active_run!=="queue"?"coalesce":Ie($,Y,t?.active_run==="coalesce"||t?.active_run==="steer"?t.active_run:"queue")),[ke,Ee]=i.useState(t?.skip_if_unchanged!==!1),[x,K]=i.useState(!1);i.useEffect(()=>{const l=b.split("|");if(!l.includes(g)){const p=l[0]??"event";M(p),ge(p==="time"||p==="event"&&N?"window":"turn"),se(p==="time"||p==="event"&&N?"coalesce":"queue"),V("silent")}},[b,g,N]);const A=R.find(l=>String(l.id)===oe),ie=c.isLoading||o.isLoading,X=r.isLoading,fe=typeof t?.connector_key=="string"?t.connector_key:void 0,U=g==="event"&&!N&&t?.kind==="event"&&t?.source!=="workspace"&&typeof t.connection_id=="number"&&String(t.connection_id)===oe&&!A,ye=g==="event"&&!N&&t?.kind==="event"&&t?.source!=="workspace"&&t.connection_id==null&&fe!==void 0&&oe==="",Oe=f.find(l=>l.key===(A?.connector_key??(ye?fe:void 0))),le=Oe?.automation_events??[],I=le.filter(l=>C.includes(l.key)),je=I[0],Me=v.find(l=>l.slug===k),Ae=[...v.filter(l=>Object.keys(l.event_kinds??{}).length>0||l.slug===k),...k&&!Me?[{slug:k,name:k}]:[]],ue=i.useMemo(()=>At(v,k||void 0,h),[v,k,h]),Le=ue.filter(l=>C.includes(l.key)),We=Le[0],ve=Ft(I.map(l=>l.filterSchema)),de=Ft(Le.map(l=>l.metadataSchema)),Be=!!(N&&k&&!Me),Te=U||ye,Ce=(g==="event"?N?C.length>0&&!Be:!!(C.length>0&&(oe&&A||Te)):g==="time"?!!be.trim():!0)&&(g!=="event"||!hs(H));i.useEffect(()=>{let l;if(Ce&&g==="event"&&!N){const p=Lt(H,ve,Oe?.automation_events??[]);A||ye?l={kind:"event",source:"connector",connector_key:A?.connector_key??fe,...A?{connection_id:Number(oe)}:{},event_types:C,...Object.keys(p).length>0?{match:p}:{},execution:$,active_run:Ie($,Y,Q),output:Qe($,Y),skip_if_unchanged:ke}:U&&(l=t?{...t,source:"connector"}:void 0)}else if(Ce&&g==="event"&&N){const p=Lt(H,de,ue.map(S=>({filterSchema:S.metadataSchema})));l={kind:"event",source:"workspace",...k?{entity_type:k}:{},event_types:C,...Object.keys(p).length>0?{match:p}:{},execution:$,active_run:Q==="queue"?"queue":"coalesce"}}else Ce&&g==="time"&&(l={kind:"schedule",cron:be.trim(),...ce?{timezone:ce}:{},execution:"window",active_run:"coalesce",skip_if_unchanged:ke});s({ready:Ce,kind:g,trigger:l})},[Q,oe,A,be,Oe,C,$,H,g,fe,ce,t,N,s,Y,Ce,ve,de,ke,k,ue,ye,U]);const nt=l=>{const p=R.find(w=>String(w.id)===l),S=f.find(w=>w.key===p?.connector_key),Z=C.filter(w=>S?.automation_events?.some(De=>De.key===w)),E=S?.automation_events?.find(w=>w.key===Z[0]),_e=p?.connector_key!==(A?.connector_key??fe);if(Se(l),re(Z),!E)te(Mt);else if(_e){const w=E.defaults?.execution??"turn",De=E.defaults?.activeRun??"queue",Ve=Qe(w,E.defaults?.output??"silent");te(Mt),ge(w),se(Ie(w,Ve,De)),V(Ve)}},at=l=>{if(l==="workspace"){Se("workspace"),re(p=>p.filter(S=>ue.some(Z=>Z.key===S))),te({}),ge("window"),se("coalesce"),V("silent");return}nt(l)},ze=l=>{const p=C.includes(l)?C.filter(w=>w!==l):le.map(w=>w.key).filter(w=>w===l||C.includes(w));if(re(p),p[0]===C[0])return;const S=le.find(w=>w.key===p[0]),Z=S?.defaults?.execution??"turn",E=S?.defaults?.activeRun??"queue",_e=Qe(Z,S?.defaults?.output??"silent");ge(Z),se(Ie(Z,_e,E)),V(_e)},He=l=>{const p=l===lt?"":l,S=v.find(E=>E.slug===p),Z=At(v,S?.slug,h);we(p),re(E=>E.filter(_e=>Z.some(w=>w.key===_e))),te({})},Ue=l=>{re(p=>p.includes(l)?p.filter(S=>S!==l):ue.map(S=>S.key).filter(S=>S===l||p.includes(S)))},Re=[{value:"event",label:"Event"},{value:"time",label:"Schedule"},{value:"manual",label:"Manual"}].filter(l=>D.includes(l.value));return e.jsxs("div",{className:"space-y-4",children:[u?e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:"When"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose what starts this Automation. Its goal and context stay reusable."})]}):null,Re.length>1?e.jsx(gn,{value:g,options:Re,onChange:l=>{M(l),ge(l==="time"||l==="event"&&N?"window":"turn"),se(l==="time"||l==="event"&&N?"coalesce":"queue"),V("silent")}}):null,g==="event"?ie||N&&X?e.jsxs("div",{className:"space-y-2",children:[e.jsx(kt,{className:"h-9 w-full"}),e.jsx(kt,{className:"h-9 w-full"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Source"}),e.jsx(Gs,{connections:R,value:G,onValueChange:at,disabled:Te,includeWorkspaceEvents:!0,ariaLabel:"Source",placeholder:"Choose a source"}),U?e.jsx("p",{className:"text-xs text-muted-foreground",children:"This shared connection is managed outside this organization. Other Automation fields can still be edited."}):ye?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This Automation listens across all"," ",String(t?.connector_key)," connections. Other Automation fields can still be edited."]}):null]}),N?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:ue.length>1?"Events":"Event"}),ue.length>0?e.jsx(Tt,{events:ue,selectedKeys:C,onToggle:Ue}):e.jsx("div",{className:T(Je,"px-3 py-2 text-sm text-muted-foreground"),children:k?"This entity type has no declared Automation events.":"This workspace has no declared Automation events."}),We?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:We.description}):null,Be?e.jsxs("p",{className:"text-xs text-destructive",children:["This trigger filters on entity type “",k,"”, which no longer exists in this workspace. Clear the Entity type filter under Trigger options to save."]}):null,e.jsx("p",{className:"text-xs text-muted-foreground",children:"Only declared Automation outputs in the current workspace can trigger this Automation. Ordinary saved events remain data."})]}),de?e.jsx(St,{schema:de,values:H,onValuesChange:l=>te(p=>Pt(p,de,l)),fieldIdPrefix:`${m}workspace-`},`${k||"workspace"}:${C.join(",")}`):null]}):A||ye?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:le.length>1?"Events":"Event"}),le.length?e.jsx(Tt,{events:le,selectedKeys:C,onToggle:ze}):e.jsx("div",{className:T(Je,"px-3 py-2 text-sm text-muted-foreground"),children:"This connector has not published subscribable events."}),je?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:je.description}):null]}),typeof H.resource_ref=="string"||ve?e.jsxs("div",{className:"space-y-3",children:[typeof H.resource_ref=="string"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Resource"}),e.jsx("div",{className:T(Je,"px-3 py-2 text-sm"),children:H.resource_ref})]}):null,ve?e.jsx(St,{schema:ve,values:H,onValuesChange:l=>te(p=>Pt(p,ve,l)),fieldIdPrefix:m},C.join(",")):null]}):null]}):G?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose workspace events or a connected app as the source."})]}):g==="time"?e.jsx(hn,{value:be,onChange:Pe}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this Automation explicitly from Lobu, the API, CLI, or MCP."}),g!=="manual"&&!Te?e.jsxs(xs,{open:x,onOpenChange:K,children:[e.jsx(ps,{asChild:!0,children:e.jsxs(z,{type:"button",variant:"ghost",className:"h-auto w-full justify-between px-0 py-1 text-muted-foreground hover:bg-transparent hover:text-foreground",children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm",children:[e.jsx(gs,{className:"h-4 w-4"}),"Trigger options",e.jsxs("span",{className:"font-normal text-muted-foreground",children:["· ",$==="turn"?"Each event":"Window"," ·"," ",g==="time"?"Combine":N?Q==="queue"?"Queue":"Combine":Q==="queue"?"Queue":Q==="coalesce"?"Combine":"Update current run",g==="event"&&!N?` · ${$==="turn"&&Y==="reply_to_source"?"Reply":"Save in Lobu"}`:""]})]}),e.jsx(Ht,{className:T("h-4 w-4 transition-transform",x&&"rotate-180")})]})}),e.jsxs(fs,{className:"space-y-4 pt-3",children:[g==="event"&&N?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Entity type filter"}),e.jsxs(me,{value:k||lt,onValueChange:He,children:[e.jsx(he,{"aria-label":"Entity type filter",children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:lt,children:"All event types"}),Ae.map(l=>e.jsx(P,{value:l.slug,children:l.name},l.slug))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Limit selected events to outputs linked to this entity type."})]}):null,g==="event"?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Run"}),e.jsxs(me,{value:$,onValueChange:l=>{const p=l,S=Qe(p,Y);ge(p),V(S),se(Ie(p,S,Q))},children:[e.jsx(he,{children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:"turn",children:"Start a run for each event"}),e.jsx(P,{value:"window",children:"Batch events into a window"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"When busy"}),e.jsxs(me,{value:Q,onValueChange:l=>se(l),children:[e.jsx(he,{children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:"queue",children:"Queue"}),e.jsx(P,{value:"coalesce",children:"Combine waiting events"}),!N&&$==="turn"&&Y==="reply_to_source"&&je?.capabilities?.steering?e.jsx(P,{value:"steer",children:"Update the current run"}):null]})]})]})]}):null,$==="window"&&(g==="time"||!N)?e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"Skip unchanged windows"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No source changes means no agent run or LLM call."})]}),e.jsx(Ys,{"aria-label":"Skip unchanged windows",checked:ke,onCheckedChange:Ee})]}):null,g==="event"&&!N&&$==="turn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Result"}),e.jsxs(me,{value:Y,onValueChange:l=>{const p=l;V(p),se(Ie($,p,Q))},children:[e.jsx(he,{children:e.jsx(xe,{})}),e.jsxs(pe,{children:[je?.capabilities?.replyToSource?e.jsx(P,{value:"reply_to_source",children:"Reply where it happened"}):null,e.jsx(P,{value:"silent",children:"Save in Lobu"})]})]}),je?.capabilities?.replyToSource?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Messages matching this trigger run the Automation; anything else in the conversation stays with the connected agent."}):null]}):null]})]}):null]})}const vn=16;function qe(){return crypto.randomUUID()}function yn(n){return n===void 0?[{key:qe(),initial:void 0}]:n.length===0?[{key:qe(),initial:null}]:n.map(t=>({key:qe(),initial:t}))}function Zt(n){return n?n.kind==="time"||n.trigger?.kind==="schedule":!1}function jn(n,t){return n?n.ready===t.ready&&n.kind===t.kind&&JSON.stringify(n.trigger)===JSON.stringify(t.trigger):!1}function _n(n,t){const s=n.map(o=>t[o.key]??{ready:!1,kind:"event"});if(!(n.length>1)&&s[0]?.kind==="manual")return{ready:s[0].ready,triggers:[]};const u=s.filter(Zt).length;return{ready:!s.some(o=>o.kind==="manual")&&u<=1&&s.length>0&&s.every(o=>o.ready&&o.trigger),triggers:s.filter(o=>o.trigger).map(o=>o.trigger)}}function Yn({organizationId:n,initialTriggers:t,onChange:s}){const d=i.useId(),[u,m]=i.useState(()=>yn(t)),[c,o]=i.useState({}),r=i.useRef("");i.useEffect(()=>{const h=_n(u,c),v=JSON.stringify(h);v!==r.current&&(r.current=v,s(h))},[u,c,s]);const j=u.find(h=>Zt(c[h.key]))?.key??u.find(h=>h.initial&&typeof h.initial=="object"&&h.initial.kind==="schedule"&&!c[h.key])?.key??null,R=i.useCallback((h,v)=>{o(_=>jn(_[h],v)?_:{..._,[h]:v})},[]),f=()=>{const h=u[0],v=h?c[h.key]:void 0;if(u.length===1&&(v?.kind==="manual"||h?.initial===null)){const _=qe();o({}),m([{key:_,initial:void 0}]);return}m(_=>[..._,{key:qe(),initial:void 0}])},B=h=>{if(u.length<=1){const v=qe();o({}),m([{key:v,initial:null}]);return}o(v=>{const _={...v};return delete _[h],_}),m(v=>v.filter(_=>_.key!==h))};return e.jsxs("section",{className:"space-y-4","aria-labelledby":`${d}-heading`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{id:`${d}-heading`,className:"text-sm font-medium",children:"When"}),u.length>1?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Each trigger can start this Automation independently (OR). At most one schedule. If several match the same event, the first listed wins for run options."}):null]}),e.jsx("div",{className:"space-y-3",children:u.map((h,v)=>{const _=u.length>1,O=_?j&&j!==h.key?["event"]:["event","time"]:["event","time","manual"],D=c[h.key],b=_||(D?D.kind!=="manual":h.initial!==null);return e.jsxs("div",{className:T("space-y-3 rounded-lg border bg-card/40 p-3",_&&"relative"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:_?`Trigger ${v+1}`:"Trigger"}),b?e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive","aria-label":_?`Remove trigger ${v+1}`:"Clear trigger",onClick:()=>B(h.key),children:e.jsx(Yt,{className:"h-3.5 w-3.5"})}):null]}),e.jsx(Nn,{slotKey:h.key,organizationId:n,initial:h.initial,kinds:O,fieldIdPrefix:`${d}-${h.key}-`,onChange:R})]},h.key)})}),e.jsxs(z,{type:"button",variant:"outline",size:"sm",className:"w-full sm:w-auto",onClick:f,disabled:u.length>=vn,children:[e.jsx(Ge,{className:"mr-1.5 h-3.5 w-3.5"}),"Add another trigger"]})]})}function Nn({slotKey:n,organizationId:t,initial:s,kinds:d,fieldIdPrefix:u,onChange:m}){const c=i.useCallback(o=>m(n,o),[m,n]);return e.jsx(fn,{organizationId:t,initialTrigger:s,allowedKinds:d,showSectionHeader:!1,fieldIdPrefix:u,onChange:c})}const Rt={agents:!0,lobuEmbedded:!1};function bn(){const{data:n}=ys({queryKey:["features"],queryFn:async()=>{const t=await js(`${_s}/api/features`);return t.ok?t.json():Rt},staleTime:3e4,refetchInterval:6e4});return n??Rt}const Dt=4096;function kn({open:n,onOpenChange:t,initial:s,onSubmit:d}){const[u,m]=i.useState(""),[c,o]=i.useState(""),[r,j]=i.useState(null);i.useEffect(()=>{n&&(m(s?.name??""),o(s?.query??""),j(null))},[n,s]);const R=()=>{const B=u.trim(),h=c.trim();if(!B){j("Give the SQL source a name.");return}if(!h){j("Enter a query.");return}if(h.length>Dt){j(`Query is too long (${h.length} chars, max ${Dt}).`);return}d({name:B,query:h}),t(!1)},f=!!s;return e.jsx(Ns,{open:n,onOpenChange:t,children:e.jsxs(bs,{className:"max-w-2xl",children:[e.jsxs(ks,{children:[e.jsx(Ss,{children:f?"Edit SQL source":"SQL source"}),e.jsx(ws,{children:"Write a query the automation runs each period. It becomes a reference in the prompt — the query travels with the chip."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"sql-source-name",children:"Name"}),e.jsx(ae,{id:"sql-source-name",value:u,onChange:B=>m(B.target.value),placeholder:"recent_cancellations",autoFocus:!f}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The output-field name this source fills."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"sql-source-query",children:"Query"}),e.jsx(Ze,{value:c,onChange:o,language:"sql",placeholder:"SELECT id, payload_text, occurred_at FROM events ORDER BY occurred_at DESC",minHeight:"160px"})]}),r?e.jsx("p",{className:"text-sm text-destructive",children:r}):null]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(z,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(z,{onClick:R,children:f?"Save":"Add source"})]})]})})}const Sn=["skill","feed","connection","connector","metric","entity_type"];function wn({value:n,onChange:t,library:s,pinned:d,required:u,error:m,owner:c,agentId:o,sources:r,onAddSources:j}){const R=sn(Sn,Et,{skills:s,skillAgentId:o||null}),f=i.useRef(null),[B,h]=i.useState(null),v=i.useMemo(()=>{if(!r)return[];const b=new Set(r.map(J=>J.query.trim()));return Ot(n).filter(J=>!b.has(J.query.trim()))},[n,r]),_=nn(n),O=an(d.filter(b=>_.includes(b.name)),s),D=s.length>0;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(y,{htmlFor:"automation-prompt",children:["Instructions"," ",u?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),_.length>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[_.length,"/",Et," skills"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring",children:e.jsx(on,{value:n,onChange:t,onSubmit:()=>{},submitOnEnter:!1,searchRefs:R,handleRef:f,onSqlRequest:()=>h({}),onSqlEdit:(b,J)=>h({initial:b,pos:J}),placeholder:D?"What should this Automation do? Type @ to pull in a skill or a data source.":"What should this Automation do? Type @ to pull in a data source.",className:"[&_.ProseMirror]:min-h-[7rem] [&_.ProseMirror]:max-h-72 [&_.ProseMirror]:overflow-y-auto"})}),e.jsx(kn,{open:B!==null,onOpenChange:b=>{b||h(null)},initial:B?.initial,onSubmit:b=>{f.current?.insertSql(b,B?.pos),h(null)}}),v.length>0&&j?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border border-dashed p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[v.length===1?`"${v[0]?.name}" is referenced in the instructions but is not a source on this Automation.`:`${v.length} references in the instructions are not sources on this Automation.`," ","Editing an Automation does not add them automatically."]}),e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:()=>j(Ot(n,r)),children:v.length===1?"Add as a source":"Add as sources"})]}):null,_.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:_.map(b=>{const J=O.includes(b),g=!s.some(M=>M.name===b);return e.jsxs(Cs,{variant:g?"destructive":"secondary",className:"font-normal",children:[b,g?" · unavailable":J?" · newer text":null]},b)})}):null,O.length>0?e.jsxs("p",{className:"rounded-lg border border-dashed p-3 text-xs text-muted-foreground",children:[O.length===1?`"${O[0]}" has been edited since this Automation pinned it.`:`${O.length} skills have been edited since this Automation pinned them.`," ","This Automation keeps running the pinned text until you save it again."]}):null,m?e.jsx("p",{className:"text-xs text-destructive",children:m}):null,!D&&o?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This agent has no skills yet."," ",e.jsx(Es,{to:"/$owner/agents/$agentId/skills",params:{owner:c,agentId:o},className:"font-medium text-foreground underline underline-offset-2",children:"Add one"})," ","to reuse instructions across Automations."]}):m?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:D?"Type @ to pull in a skill, a feed, connection, connector, metric, entity type, or a SQL query. Skill text is saved with this version, so later edits to the skill do not change this Automation until you update it.":"Type @ to pull in a feed, connection, connector, metric, entity type, or a SQL query this Automation should read."})]})}const Cn=["connection","connector","feed","metric","entity_type"];function En({sources:n,onChange:t,disabled:s}){const{currentOwner:d,resolvedOrganizationId:u}=Xt(),[m,c]=i.useState(""),{refs:o}=rn({owner:d,organizationId:u,kinds:Cn,query:m,limitPerKind:10});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Sources"}),n.length>0?e.jsx("ul",{className:"space-y-2",children:n.map(r=>e.jsxs("li",{className:"flex items-start gap-2 rounded-lg border bg-background p-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-mono text-xs font-medium",children:r.name}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:r.query})]}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0","aria-label":`Remove source ${r.name}`,disabled:s,onClick:()=>t(n.filter(j=>j.query!==r.query)),children:e.jsx(Jt,{className:"h-3.5 w-3.5"})})]},r.query))}):null,e.jsx("div",{className:"flex gap-2",children:e.jsx(tt,{searchPlaceholder:"Search feeds, connections, metrics…",emptyText:"No matching reference.",onQueryChange:c,trigger:()=>e.jsxs(z,{type:"button",variant:"outline",size:"sm",disabled:s,children:[e.jsx(Ge,{className:"mr-2 h-3.5 w-3.5"}),"Add source"]}),children:r=>o.map(j=>e.jsxs($e,{value:`${j.label} ${j.kind}`,onSelect:()=>{t(cn(j,n)),r()},children:[e.jsx("span",{className:"truncate text-sm",children:j.label}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-muted-foreground",children:j.kind})]},`${j.kind}:${j.id}`))})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Data handed to the agent alongside its instructions, and what change detection is measured against. Editing an Automation does not re-read the instructions for these — this list is what runs. To add a SQL source, write it with @ in the instructions above. Automation-owned; skills never add or remove sources."})]})}function On({organizationId:n,value:t,onChange:s,className:d}){const{data:u=[]}=Os(n),m=Hs(u),c=m.find(o=>o.id===t);return e.jsx(tt,{contentClassName:"w-[300px]",searchPlaceholder:"Search entities...",emptyText:"No entities found.",trigger:o=>e.jsxs(z,{variant:"outline",role:"combobox","aria-expanded":o,className:T("w-full justify-between",d),children:[c?`${c.name} (${c.entityType})`:"All workspace",e.jsx(gt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:o=>e.jsxs(e.Fragment,{children:[e.jsxs($e,{value:"all workspace",onSelect:()=>{s(void 0),o()},className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",t===void 0?"opacity-100":"opacity-0")}),e.jsx("span",{children:"All workspace"})]}),m.map(r=>e.jsxs($e,{value:`${r.name} ${r.entityType}`,onSelect:()=>{s(r.id),o()},className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",t===r.id?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[r.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",r.entityType,")"]})]})]},r.id))]})})}function xt(n){if(Array.isArray(n))return n;if(typeof n=="string"&&n.startsWith("{")&&n.endsWith("}")){const t=n.slice(1,-1);return t?t.split(",").map(s=>s.trim()):[]}return[]}const An=Xs.map(n=>({value:n,label:Zs[n]})),It=[{value:"agent",label:"Agent",hint:"An agent reads the window and follows your instructions."},{value:"code",label:"Code",hint:"A deterministic script processes each completed window."},{value:"both",label:"Agent + code",hint:"An agent extracts per your instructions, then the script runs."}];function qt(n){const t=!!(n?.prompt?.trim()||n?.skills?.some(d=>d.content.trim())),s=!!n?.reaction_script?.trim();return t&&s?"both":s?"code":"agent"}const Fn=["text","number","date","boolean","json"],Pn=[{value:"key",label:"Key"},{value:"searchable",label:"Searchable"},{value:"plain",label:"Plain"}],ut=[{value:"plan",label:"Plan first"},{value:"auto",label:"Auto"},{value:"acceptEdits",label:"Accept edits"},{value:"dontAsk",label:"Don't ask"},{value:"bypassPermissions",label:"Bypass permissions"}];let $t=0;function Mn(){return $t+=1,`field-${$t}`}function pt(n={}){return{id:Mn(),name:n.name??"",type:n.type??"text",role:n.role??"plain"}}function Ln(n){return n.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,t=>t.toUpperCase())}function Ke(n){return n.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")}function Tn(n){return n?Object.keys(n).every(t=>["entity_type","entity_path","key_fields","key_output_field"].includes(t)):!0}function Rn(n){return n?n.every(t=>!t||typeof t!="object"||Array.isArray(t)?!1:Object.keys(t).every(s=>["slug","name","source_path","value_field"].includes(s))):!0}function Kt(n){return n?Tn(n.keying_config)&&Rn(n.classifiers)?"fields":"json":"fields"}function Wt(n){const t=n?.keying_config?.entity_type;return typeof t=="string"?t:""}function Bt(n){const t=n?.keying_config?.entity_path;return typeof t=="string"&&t.trim()?t:"$"}function zt(n){const t=new Map,s=Array.isArray(n?.keying_config?.key_fields)?n?.keying_config?.key_fields:[];for(const d of s){if(typeof d!="string")continue;const u=Ke(d);u&&t.set(u,pt({name:u,role:"key"}))}for(const d of n?.classifiers??[]){if(!d||typeof d!="object"||Array.isArray(d))continue;const u=d.value_field;if(typeof u!="string")continue;const m=Ke(u);!m||t.has(m)||t.set(m,pt({name:m,role:"searchable"}))}return Array.from(t.values())}function Ne(n,t){const s=n?.execution_config?.[t];return typeof s=="number"||typeof s=="string"?String(s):""}function Ut(n,t,s){const d=n?.execution_config?.[t];return typeof d=="string"&&s.includes(d)?d:""}function dt(n,t){const s=n.trim();if(!s)return{};const d=Number(s);return Number.isFinite(d)?{value:d}:{error:`${t} must be a number.`}}function Vt({entityType:n,entityPath:t,fields:s}){const d=s.map(r=>({...r,name:Ke(r.name)})).filter(r=>r.name),u=d.filter(r=>r.role==="key").map(r=>r.name),m=d.filter(r=>r.role==="searchable"),c=Ke(n),o=t.trim()||"$";return u.length>0&&!c?{error:"Key fields need an output entity type."}:(u.length>0||m.length>0,{keyingConfig:u.length>0?{entity_type:c,entity_path:o,key_fields:u,key_output_field:`${c}_key`}:void 0,classifiers:m.length>0?m.map(r=>({slug:r.name,name:Ln(r.name),source_path:o,value_field:r.name})):void 0})}function Dn(n,t){return e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:n}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]})}function Qt(n){return!!(n?.classifiers?.length||n?.keying_config||n?.reactions_guidance||n?.model_config||n?.execution_config||n?.sources?.length||xt(n?.tags).length)}function In({organizationId:n,entityId:t,prefill:s,onSubmit:d,isSubmitting:u,error:m,isEditing:c,onCancel:o,triggerFields:r,submitLabel:j="Create Automation",submitDisabled:R=!1,triggers:f}){const{lobuEmbedded:B}=bn(),{currentOwner:h}=Xt(),{data:v=[]}=As(),{data:_=[]}=Fs(),[O,D]=i.useState(s?.managed_agent_id??""),b=!!s?.managed_agent_id&&!c,[J,g]=i.useState(s?.device_worker_id??""),[M,G]=i.useState(s?.device_worker_id?"device":"agent"),[Se,N]=i.useState(s?.agent_kind??""),{data:oe=[]}=Gt({organizationId:n}),[k,we]=i.useState(s?.name??""),[Fe,C]=i.useState(s?.slug??""),[re,H]=i.useState(!!s?.slug),[te,be]=i.useState(s?.description??""),[Pe,ce]=i.useState(s?.prompt??""),[$,ge]=i.useState(!1),Y=s?.skills??[],[V,Q]=i.useState(s?.sources??[]),[se,ke]=i.useState(s?.entity_id??t),[Ee,x]=i.useState(s?.reaction_script??""),[K,A]=i.useState(()=>qt(s)),[ie,X]=i.useState(s?.classifiers?JSON.stringify(s.classifiers,null,2):""),[fe,U]=i.useState(null),[ye,Oe]=i.useState(s?.keying_config?JSON.stringify(s.keying_config,null,2):""),[le,I]=i.useState(null),[je,Me]=i.useState(()=>Kt(s)),[Ae,ue]=i.useState(()=>Wt(s)),[Le,We]=i.useState(()=>Bt(s)),[ve,de]=i.useState(()=>zt(s)),[Be,Te]=i.useState(s?.reactions_guidance??""),[st,Ce]=i.useState(()=>Ne(s,"timeout_seconds")),[nt,at]=i.useState(()=>Ne(s,"max_budget_usd")),[ze,He]=i.useState(()=>Ne(s,"model")),[Ue,ot]=i.useState(()=>Ut(s,"permission_mode",ut.map(a=>a.value))),[Re,l]=i.useState(()=>Ne(s,"effort")),[p,S]=i.useState(()=>Ne(s,"finalize_nudges")),[Z,E]=i.useState(null),[_e,w]=i.useState(xt(s?.tags).join(", ")),[De,Ve]=i.useState(""),[rt,ft]=i.useState(!!(c||Qt(s)));i.useEffect(()=>{s&&(we(s.name??""),C(s.slug??""),H(!!s.slug),be(s.description??""),ce(s.prompt??""),ge(!1),Q(s.sources??[]),ke(s.entity_id??t),g(s.device_worker_id??""),G(s.device_worker_id?"device":"agent"),N(s.agent_kind??""),x(s.reaction_script??""),A(qt(s)),X(s.classifiers?JSON.stringify(s.classifiers,null,2):""),U(null),Oe(s.keying_config?JSON.stringify(s.keying_config,null,2):""),I(null),Me(Kt(s)),ue(Wt(s)),We(Bt(s)),de(zt(s)),Te(s.reactions_guidance??""),Ce(Ne(s,"timeout_seconds")),at(Ne(s,"max_budget_usd")),He(Ne(s,"model")),ot(Ut(s,"permission_mode",ut.map(a=>a.value))),l(Ne(s,"effort")),S(Ne(s,"finalize_nudges")),E(null),w(xt(s.tags).join(", ")),Ve(""),D(s.managed_agent_id??""),ft(!!(c||Qt(s))))},[s,t,c]);const es=re?Fe:Ct(k),{data:ts}=Ps(O||null),{data:ss}=Ms(O||null,{enabled:!!O}),ct=tn(ts??null,ss?.catalog??[]),ns=ln(f),it=Ee.trim().length>0,Ye=!c&&K==="code"?"":Pe,as=!c&&K==="agent"?void 0:Ee.trim()||void 0,vt=(c||K==="code")&&it,yt=un(Ye,ct,f,vt),os=$||Ye.trim()!==""?yt:null,jt=dn(Ye,ct),_t=!c&&K!=="agent",Nt=!!k.trim()&&!yt&&(!_t||it),rs=ns&&!vt&&jt.length===0,cs=()=>{if(!Nt)return;let a,F;if(je==="fields"){const ne=Vt({entityType:Ae,entityPath:Le,fields:ve});if(ne.error){I(ne.error);return}a=ne.classifiers,F=ne.keyingConfig,U(null),I(null)}else{if(ie.trim())try{const ne=JSON.parse(ie);if(!Array.isArray(ne)){U("Classifiers must be a JSON array.");return}a=ne}catch{U("Invalid JSON. Please check the syntax.");return}if(U(null),ye.trim())try{const ne=JSON.parse(ye);if(typeof ne!="object"||Array.isArray(ne)){I("Keying config must be a JSON object.");return}F=ne}catch{I("Invalid JSON. Please check the syntax.");return}I(null)}const L=dt(st,"Timeout");if(L.error){E(L.error);return}if(L.value!==void 0&&(!Number.isInteger(L.value)||L.value<1)){E("Timeout must be a whole number greater than 0.");return}const q=dt(nt,"Budget");if(q.error){E(q.error);return}if(q.value!==void 0&&q.value<0){E("Budget cannot be negative.");return}const ee=dt(p,"Finalize nudges");if(ee.error){E(ee.error);return}if(ee.value!==void 0&&(!Number.isInteger(ee.value)||ee.value<0||ee.value>5)){E("Finalize nudges must be a whole number from 0 to 5.");return}const W={...L.value!==void 0?{timeout_seconds:L.value}:{},...q.value!==void 0?{max_budget_usd:q.value}:{},...ze.trim()?{model:ze.trim()}:{},...Ue?{permission_mode:Ue}:{},...Re.trim()?{effort:Re.trim()}:{},...ee.value!==void 0?{finalize_nudges:ee.value}:{}},is=Object.keys(W).length>0||c?W:void 0;E(null);const ls=_e.trim()?_e.split(",").map(ne=>ne.trim()).filter(Boolean):void 0;d({slug:es,name:k.trim(),description:te.trim()||void 0,prompt:Ye,skills:jt,entity_id:se,sources:V,reaction_script:as,classifiers:a,keying_config:F,reactions_guidance:Be.trim()||void 0,execution_config:is,tags:ls,change_notes:De.trim()||void 0,managed_agent_id:M==="agent"&&O.trim()||null,device_worker_id:M==="device"&&J.trim()||null,agent_kind:M==="device"&&Se.trim()||null})},bt=e.jsxs("div",{className:"space-y-2",children:[e.jsxs(y,{htmlFor:"scratch-reaction",children:["Reaction Script"," ",_t?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(Ze,{value:Ee,onChange:x,language:"typescript",placeholder:"export default async function reaction(ctx) { ... }",minHeight:"120px"}),c?null:e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Runs deterministically on every completed window, after agent extraction. Declare an ",e.jsx("code",{children:"input"})," export to set the window's extraction contract."]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(y,{htmlFor:"scratch-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),!c&&e.jsx("button",{type:"button",onClick:()=>H(!re),className:"text-xs text-muted-foreground hover:text-foreground",children:re?"Use automatic slug":"Customize slug"})]}),e.jsx(ae,{id:"scratch-name",value:k,onChange:a=>we(a.target.value),placeholder:"e.g., Escalation signals"}),!c&&re?e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-slug",children:"Slug"}),e.jsx(ae,{id:"scratch-slug",value:Fe,onChange:a=>C(a.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:Ct(k)||"custom-slug"})]}):null]})}),c?null:e.jsxs("fieldset",{className:"space-y-2",children:[e.jsx("legend",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"How does this run?"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:It.map(a=>e.jsx("button",{type:"button","aria-pressed":K===a.value,onClick:()=>A(a.value),className:T("rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors",K===a.value?"bg-secondary text-secondary-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:a.label},a.value))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:It.find(a=>a.value===K)?.hint})]}),c||K!=="code"?e.jsx(wn,{value:Pe,onChange:a=>{ge(!0),ce(a)},library:ct,pinned:Y,required:rs,error:os,owner:h??"",agentId:O,sources:c?V:void 0,onAddSources:c?Q:void 0}):null,!c&&K!=="agent"?bt:null,c?e.jsx(En,{sources:V,onChange:Q,disabled:u}):null,e.jsx("div",{className:"space-y-4",children:r}),e.jsxs(z,{type:"button",variant:"ghost",className:"w-full justify-between px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-expanded":rt,"aria-controls":"automation-advanced-settings",onClick:()=>ft(a=>!a),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ls,{className:"h-4 w-4"}),"Advanced settings"]}),e.jsx(Ht,{className:T("h-4 w-4 transition-transform",rt&&"rotate-180")})]}),e.jsxs("div",{id:"automation-advanced-settings",className:T("space-y-4",!rt&&"hidden"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-description",children:"Description"}),e.jsx(ae,{id:"scratch-description",value:te,onChange:a=>be(a.target.value),placeholder:"What this automation does"})]}),!t&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Entity scope"}),e.jsx(On,{organizationId:n,value:se,onChange:ke}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit this automation to one workspace entity."})]}),c?bt:null,e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(y,{children:"Output fields"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Key fields become stable entity keys. Searchable fields become classifiers."})]}),e.jsx(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(je==="fields"){const a=Vt({entityType:Ae,entityPath:Le,fields:ve});if(a.error){I(a.error);return}X(a.classifiers?JSON.stringify(a.classifiers,null,2):""),Oe(a.keyingConfig?JSON.stringify(a.keyingConfig,null,2):""),Me("json")}else Me("fields");U(null),I(null)},children:je==="fields"?"Edit JSON":"Use fields"})]}),je==="fields"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-output-entity-type",children:"Output entity type"}),e.jsx(tt,{contentClassName:"w-[320px]",searchPlaceholder:"Search or type a new type…",emptyText:"Type a name to create a new entity type.",trigger:a=>e.jsxs(z,{type:"button",variant:"outline",role:"combobox","aria-expanded":a,id:"scratch-output-entity-type",className:"w-full justify-between font-mono text-sm font-normal",children:[e.jsx("span",{className:T("truncate",!Ae&&"text-muted-foreground"),children:Ae||"Select entity type"}),e.jsx(gt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(a,F)=>{const L=Ke(F),q=oe.filter(W=>!W.backing_sql),ee=q.some(W=>W.slug===L);return e.jsxs(e.Fragment,{children:[q.map(W=>e.jsxs($e,{value:`${W.name??W.slug} ${W.slug}`,onSelect:()=>{ue(W.slug),I(null),a()},className:"cursor-pointer",children:[e.jsx(et,{className:T("mr-2 h-4 w-4",Ae===W.slug?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-sm",children:W.slug}),W.name&&W.name!==W.slug&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:W.name})]})]},W.slug)),L&&!ee&&e.jsxs($e,{value:F,onSelect:()=>{ue(L),I(null),a()},className:"cursor-pointer",children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"text-sm",children:["Create"," ",e.jsx("span",{className:"font-mono",children:L})]})]})]})}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-output-path",children:"Output path"}),e.jsx(ae,{id:"scratch-output-path",value:Le,onChange:a=>{We(a.target.value),I(null)},placeholder:"$.items[*]",className:"font-mono text-sm"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(y,{children:"Fields"}),e.jsxs(z,{type:"button",variant:"outline",size:"sm",onClick:()=>{de(a=>[...a,pt()]),U(null),I(null)},children:[e.jsx(Ge,{className:"mr-2 h-4 w-4"}),"Add field"]})]}),ve.length===0?e.jsx("div",{className:T(Je,"px-3 py-2 text-sm text-muted-foreground"),children:"No output fields configured."}):e.jsx("div",{className:"space-y-2",children:ve.map(a=>e.jsxs("div",{className:T(Je,"grid gap-2 p-3 sm:grid-cols-[minmax(0,1fr)_128px_minmax(0,240px)_auto]"),children:[e.jsx(ae,{value:a.name,onChange:F=>{const L=Ke(F.target.value);de(q=>q.map(ee=>ee.id===a.id?{...ee,name:L}:ee)),U(null),I(null)},placeholder:"severity","aria-label":"Output field name",className:"font-mono text-sm"}),e.jsxs(me,{value:a.type,onValueChange:F=>{de(L=>L.map(q=>q.id===a.id?{...q,type:F}:q))},children:[e.jsx(he,{"aria-label":"Output field type",children:e.jsx(xe,{})}),e.jsx(pe,{children:Fn.map(F=>e.jsx(P,{value:F,children:F},F))})]}),e.jsx("div",{className:"grid grid-cols-3 rounded-md border border-input bg-background p-1",children:Pn.map(F=>e.jsx("button",{type:"button",onClick:()=>{de(L=>L.map(q=>q.id===a.id?{...q,role:F.value}:q)),U(null),I(null)},className:T("rounded-sm px-2 py-1 text-xs transition-colors",a.role===F.value?"bg-muted/70 text-foreground":"text-muted-foreground hover:text-foreground"),children:F.label},F.value))}),e.jsx(z,{type:"button",variant:"ghost",size:"icon",onClick:()=>{de(F=>F.filter(L=>L.id!==a.id)),U(null),I(null)},"aria-label":"Remove output field",children:e.jsx(Yt,{className:"h-4 w-4"})})]},a.id))})]}),le&&e.jsx("p",{className:"text-xs text-destructive",children:le}),fe&&e.jsx("p",{className:"text-xs text-destructive",children:fe})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-classifiers",children:"Classifiers (JSON)"}),e.jsx(Ze,{value:ie,onChange:a=>{X(a),U(null)},language:"json",placeholder:'[{ "slug": "sentiment", "name": "Sentiment", "source_path": "$.analysis[*]", "value_field": "sentiment" }]',minHeight:"80px"}),fe&&e.jsx("p",{className:"text-xs text-destructive",children:fe})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-keying-config",children:"Keying Config (JSON)"}),e.jsx(Ze,{value:ye,onChange:a=>{Oe(a),I(null)},language:"json",placeholder:'{ "entity_type": "topic", "entity_path": "$.items[*]", "key_fields": ["name"], "key_output_field": "entity_key" }',minHeight:"60px"}),le&&e.jsx("p",{className:"text-xs text-destructive",children:le})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-reactions-guidance",children:"Reactions Guidance"}),e.jsx(Ts,{id:"scratch-reactions-guidance",value:Be,onChange:a=>Te(a.target.value),placeholder:"Guidance text for the reaction system (e.g., when to alert, severity thresholds)...",className:"font-mono text-xs min-h-[80px]"})]}),e.jsxs("div",{className:"space-y-4",children:[Dn("Run settings","Choose where the automation runs and the budget it can use."),!b&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-runs-on",children:"Runs on"}),e.jsxs(me,{value:M,onValueChange:a=>G(a),children:[e.jsx(he,{id:"scratch-runs-on",className:"text-sm",children:e.jsx(xe,{})}),e.jsxs(pe,{children:[e.jsx(P,{value:"agent",children:"Managed agent"}),e.jsx(P,{value:"device",children:"On a device"}),e.jsx(P,{value:"manual",children:"Manual-only"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:M==="agent"?"Automated runs dispatch to a managed Lobu agent.":M==="device"?"Automated runs are claimed and executed locally by a device worker (Mac app, remote worker).":"No executor — this automation runs only when started manually by a connected client."})]}),!b&&M==="agent"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-agent-id",children:"Agent"}),B?e.jsxs(me,{value:O||"__unselected__",onValueChange:a=>{D(a==="__unselected__"?"":a)},children:[e.jsx(he,{id:"scratch-agent-id",className:"font-mono text-sm",children:e.jsx(xe,{placeholder:"Select a Lobu agent"})}),e.jsx(pe,{children:v.map(a=>e.jsxs(P,{value:a.agentId,children:[a.name," (",a.agentId,")"]},a.agentId))})]}):e.jsx(ae,{id:"scratch-agent-id",value:O,onChange:a=>{D(a.target.value)},placeholder:"e.g., agent-123",className:"font-mono text-sm"})]}),!b&&M==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-device-id",children:"Device"}),e.jsxs(me,{value:J||"__unselected__",onValueChange:a=>g(a==="__unselected__"?"":a),children:[e.jsx(he,{id:"scratch-device-id",className:"font-mono text-sm",children:e.jsx(xe,{placeholder:"Select a device worker"})}),e.jsx(pe,{children:_.map(a=>e.jsx(P,{value:a.id,children:a.label||a.platform||a.id},a.id))})]})]}),!b&&M==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-device-agent-kind",children:"Runs as"}),e.jsxs(me,{value:Se||"__default__",onValueChange:a=>N(a==="__default__"?"":a),children:[e.jsx(he,{id:"scratch-device-agent-kind",className:"text-sm",children:e.jsx(xe,{placeholder:"Device default"})}),e.jsxs(pe,{children:[e.jsx(P,{value:"__default__",children:"Device default"}),An.map(a=>e.jsx(P,{value:a.value,children:a.label},a.value))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Device default uses that device's preferred local agent. Availability is checked again when a run is claimed, so a run stays queued if its selected runtime is no longer available."})]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{children:"Model"}),e.jsx(en,{value:ze,onChange:a=>{He(a),E(null)},placeholder:"Use agent default"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-timeout",children:"Timeout seconds"}),e.jsx(ae,{id:"scratch-timeout",type:"number",min:1,max:86400,value:st,onChange:a=>{Ce(a.target.value),E(null)},placeholder:"600"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-permission-mode",children:"Permission mode"}),e.jsxs(me,{value:Ue||"__default__",onValueChange:a=>{ot(a==="__default__"?"":a),E(null)},children:[e.jsx(he,{id:"scratch-permission-mode",children:e.jsx(xe,{placeholder:"Default"})}),e.jsxs(pe,{children:[e.jsx(P,{value:"__default__",children:"Default"}),ut.map(a=>e.jsx(P,{value:a.value,children:a.label},a.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-effort",children:"Effort"}),e.jsx(ae,{id:"scratch-effort",value:Re,onChange:a=>{l(a.target.value),E(null)},placeholder:"Default","aria-describedby":"scratch-effort-help"}),e.jsx("p",{id:"scratch-effort-help",className:"text-xs text-muted-foreground",children:"For device runs, use a value supported by the selected CLI and model. Leave empty for its default."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-finalize-nudges",children:"Finalize nudges"}),e.jsx(ae,{id:"scratch-finalize-nudges",type:"number",min:0,max:5,value:p,onChange:a=>{S(a.target.value),E(null)},placeholder:"Default"})]})]}),Z&&e.jsx("p",{className:"text-xs text-destructive",children:Z})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-tags",children:"Tags"}),e.jsx(ae,{id:"scratch-tags",value:_e,onChange:a=>w(a.target.value),placeholder:"ops, support, risk"})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(y,{htmlFor:"scratch-change-notes",children:"Change notes"}),e.jsx(ae,{id:"scratch-change-notes",value:De,onChange:a=>Ve(a.target.value),placeholder:"What changed in this version?"})]})]})]}),m&&!fe&&!le&&!Z&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:m}),e.jsx(ht,{onCancel:o,children:e.jsx(z,{onClick:cs,disabled:!Nt||u||R,children:u?e.jsxs(e.Fragment,{children:[e.jsx(Rs,{size:"lg",className:"mr-2"}),c?"Saving...":"Creating..."]}):c?"Save Automation":j})})]})}function qn(n){const t=n.detail??{};return{name:n.name,slug:t.slug,description:t.description??n.description??void 0,prompt:t.prompt,triggers:t.triggers,sources:t.sources,classifiers:t.classifiers,keying_config:t.keying_config,reactions_guidance:t.reactions_guidance,reaction_script:t.reaction_script,model_config:t.model_config,execution_config:t.execution_config,tags:t.tags}}function Xn({onClose:n,hideCancel:t=!1,hideHeader:s=!1,organizationId:d,entityId:u,entityName:m,prefillAgentId:c,onSuccess:o,editingAutomation:r,catalogPrefill:j,onDraft:R,triggerFields:f,submitLabel:B,submitDisabled:h,createFields:v,onPrefillTriggers:_}){const O=Ds(),D=Is(),b=qs(),J=$s(),g=!!r,[M,G]=i.useState("template"),[Se,N]=i.useState(void 0),[oe,k]=i.useState(void 0),{data:we=[],isLoading:Fe}=Ks(),[C,re]=i.useState(""),H=i.useMemo(()=>c?{managed_agent_id:c}:void 0,[c]),te=i.useMemo(()=>we.map(x=>({key:x.id,name:x.name,description:x.description??"",badges:x.detail?.tags??[]})),[we]),be=i.useMemo(()=>te.filter(x=>x.name.toLowerCase().includes(C.toLowerCase())||x.description.toLowerCase().includes(C.toLowerCase())),[te,C]),Pe=x=>{const K=we.find(ie=>ie.id===x.key);if(!K)return;const A=qn(K);k(c?{...A,managed_agent_id:c}:A),_?.(A.triggers??[]),G("scratch")},ce=()=>{O.reset(),D.reset(),G("template"),N(void 0),k(void 0),n()},$=g?v?.triggers??r.triggers??[]:v?.triggers??oe?.triggers??j?.triggers??[],ge=async x=>{try{if(R){await R(x);return}if(g){const K=v?.triggers??r.triggers??[],A=r.reaction_script??"",ie=x.reaction_script??"";ie&&ie!==A&&await b.mutateAsync({automation_id:r.automation_id,reaction_script:ie}),await D.mutateAsync({automation_id:r.automation_id,name:x.name,description:x.description,prompt:x.prompt,sources:x.sources,set_as_current:!0,triggers:K,classifiers:x.classifiers,keying_config:x.keying_config,reactions_guidance:x.reactions_guidance,change_notes:x.change_notes}),!ie&&A&&await b.mutateAsync({automation_id:r.automation_id,reaction_script:""});const X={};x.model_config!==void 0&&(X.model_config=x.model_config),x.execution_config!==void 0&&(X.execution_config=x.execution_config),x.tags!==void 0&&(X.tags=x.tags),x.managed_agent_id!==void 0&&(X.managed_agent_id=x.managed_agent_id||null),x.agent_kind!==void 0&&(X.agent_kind=x.agent_kind||null),x.device_worker_id!==void 0&&(X.device_worker_id=x.device_worker_id||null),Object.keys(X).length>0&&await J.mutateAsync({automation_id:r.automation_id,...X}),ce(),o?.(r.automation_id)}else{const K=v?.triggers??oe?.triggers??j?.triggers??[],A=await O.mutateAsync({...x,managed_agent_id:x.managed_agent_id??void 0,device_worker_id:x.device_worker_id??void 0,agent_kind:x.agent_kind??void 0,triggers:K});ce(),A.automation_id&&o?.(A.automation_id)}}catch{}},Y=g?D:O;let V="Add an automation";g?V="Edit automation configuration (saves as a new version)":m&&(V=`Add an automation for ${m}`);const Q=r?{entity_id:r.entity_id,name:r.name,slug:r.slug,description:r.description,prompt:r.prompt,sources:r.sources,reaction_script:r.reaction_script,device_worker_id:r.device_worker_id??void 0,agent_kind:r.agent_kind??void 0,classifiers:r.classifiers,keying_config:r.keying_config,reactions_guidance:r.reactions_guidance,model_config:r.model_config,execution_config:r.execution_config,tags:r.tags,managed_agent_id:r.managed_agent_id??void 0}:void 0,se=g?"Edit Automation":"Create Automation",ke=e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:se}),e.jsx("p",{className:"text-sm text-muted-foreground",children:V})]}),Ee=e.jsxs("div",{className:"py-6 space-y-6",children:[!g&&e.jsxs("div",{className:"flex flex-wrap justify-start gap-2",children:[e.jsx(mt,{active:M==="template",onClick:()=>G("template"),icon:e.jsx(Ws,{className:"h-4 w-4"}),label:"From templates"}),e.jsx(mt,{active:M==="scratch",onClick:()=>{G("scratch"),N(void 0),k(void 0)},icon:e.jsx(Ge,{className:"h-4 w-4"}),label:"From scratch"}),e.jsx(mt,{active:M==="clone",onClick:()=>G("clone"),icon:e.jsx(Bs,{className:"h-4 w-4"}),label:"Clone existing"})]}),!g&&M==="template"?e.jsxs(e.Fragment,{children:[Fe?e.jsx(zs,{}):e.jsx(Us,{items:be,searchQuery:C,onSearchChange:re,onSelect:Pe,searchPlaceholder:"Search templates...",searchAriaLabel:"Search automation templates",emptyMessage:te.length===0?"No automation templates available.":void 0}),s&&!t?e.jsx(ht,{onCancel:ce}):null]}):!g&&M==="clone"&&!Se?e.jsxs(e.Fragment,{children:[e.jsx($n,{organizationId:d,onSelect:x=>{N(x),_?.(x.triggers??[]),G("scratch")}}),s&&!t?e.jsx(ht,{onCancel:ce}):null]}):e.jsx(In,{organizationId:d,entityId:u,prefill:Q??Se??oe??j??H,onSubmit:ge,isSubmitting:Y.isPending,error:Y.error?Y.error.message:null,isEditing:g,onCancel:t?void 0:ce,triggerFields:f,submitLabel:B,submitDisabled:h,triggers:$})]});return e.jsxs("div",{className:"flex flex-col",children:[s?null:ke,Ee]})}function mt({active:n,onClick:t,icon:s,label:d}){return e.jsxs("button",{type:"button",onClick:t,className:T("flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors",n?"border-primary bg-primary/5 text-primary":"border-border text-muted-foreground hover:border-muted-foreground/30 hover:text-foreground"),children:[s,d]})}function $n({organizationId:n,onSelect:t}){const{data:s,isLoading:d}=Vs(n),[u,m]=i.useState(""),c=(s||[]).filter(o=>o.name?.toLowerCase().includes(u.toLowerCase()));return d?e.jsx(Qs,{label:"automations",variant:"list-picker",rows:4}):!s||s.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"No existing automations to clone."}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",value:u,onChange:o=>m(o.target.value),placeholder:"Search automations...",className:"w-full rounded-md border px-3 py-2 text-sm bg-background"}),e.jsxs("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:[c.map(o=>e.jsxs("button",{type:"button",onClick:()=>t({name:`${o.name} (copy)`,slug:`${o.slug||o.automation_id}-copy`,prompt:o.prompt,classifiers:o.classifiers,keying_config:o.keying_config,triggers:o.triggers,sources:o.sources}),className:"w-full text-left rounded-md border p-3 hover:border-primary/50 hover:bg-primary/5 transition-colors",children:[e.jsx("p",{className:"text-sm font-medium",children:o.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[o.entity_name||"Space-level"," · v",o.version??"?"]})]},o.automation_id)),c.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No automations match your search."})]})]})}export{Yn as A,Xn as C};
@@ -1 +1 @@
1
- import{hj as e,j as t,gq as r}from"./index-Bfux0kHb.js";function a(){const{owner:n,connectorKey:o}=e.useParams();return t.jsx(r,{owner:n,initialConnectorKey:o})}export{a as component};
1
+ import{hj as e,j as t,gq as r}from"./index-BUr8321-.js";function a(){const{owner:n,connectorKey:o}=e.useParams();return t.jsx(r,{owner:n,initialConnectorKey:o})}export{a as component};
@@ -1 +1 @@
1
- import{aC as U}from"./index-Bfux0kHb.js";var M={exports:{}},A;function H(){return A||(A=1,(function(L,C){(function(w,_){L.exports=_()})(globalThis,()=>(()=>{var D={949(g,p,v){Object.defineProperty(p,"__esModule",{value:!0}),p.CronParser=void 0;var i=v(515),y=(function(){function l(e,t,r){t===void 0&&(t=!0),r===void 0&&(r=!1),this.expression=e,this.dayOfWeekStartIndexZero=t,this.monthStartIndexZero=r}return l.prototype.parse=function(){var e,t,r=(e=this.expression)!==null&&e!==void 0?e:"";if(r==="@reboot")return t=["@reboot","","","","","",""],t;if(r.startsWith("@")){var n=this.parseSpecial(this.expression);t=this.extractParts(n)}else t=this.extractParts(this.expression);return this.normalize(t),this.validate(t),t},l.prototype.parseSpecial=function(e){var t={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *","@reboot":"@reboot"},r=t[e];if(!r)throw new Error("Unknown special expression.");return r},l.prototype.extractParts=function(e){if(!this.expression)throw new Error("cron expression is empty");for(var t=e.trim().split(/[ ]+/),r=0;r<t.length;r++)if(t[r].includes(",")){var n=t[r].split(",").map(function(a){return a.trim()}).filter(function(a){return a!==""}).map(function(a){return isNaN(Number(a))?a:Number(a)}).filter(function(a){return a!==null&&a!==""});n.length===0&&n.push("*"),n.sort(function(a,u){return a!==null&&u!==null?a-u:0}),t[r]=n.map(function(a){return a!==null?a.toString():""}).join(",")}if(t.length<5)throw new Error("Expression has only ".concat(t.length," part").concat(t.length==1?"":"s",". At least 5 parts are required."));if(t.length==5)t.unshift(""),t.push("");else if(t.length==6){var o=/\d{4}$/.test(t[5])||t[4]=="?"||t[2]=="?";o?t.unshift(""):t.push("")}else if(t.length>7)throw new Error("Expression has ".concat(t.length," parts; too many!"));return t},l.prototype.normalize=function(e){var t=this;if(e[3]=e[3].replace("?","*"),e[5]=e[5].replace("?","*"),e[2]=e[2].replace("?","*"),e[0].indexOf("0/")==0&&(e[0]=e[0].replace("0/","*/")),e[1].indexOf("0/")==0&&(e[1]=e[1].replace("0/","*/")),e[2].indexOf("0/")==0&&(e[2]=e[2].replace("0/","*/")),e[3].indexOf("1/")==0&&(e[3]=e[3].replace("1/","*/")),e[4].indexOf("1/")==0&&(e[4]=e[4].replace("1/","*/")),e[6].indexOf("1/")==0&&(e[6]=e[6].replace("1/","*/")),e[5]=e[5].replace(/(^\d)|([^#/\s]\d)/g,function(c){var d=c.replace(/\D/,""),f=d;return t.dayOfWeekStartIndexZero?d=="7"&&(f="0"):f=(parseInt(d)-1).toString(),c.replace(d,f)}),e[5]=="L"&&(e[5]="6"),e[3]=="?"&&(e[3]="*"),e[3].indexOf("W")>-1&&(e[3].indexOf(",")>-1||e[3].indexOf("-")>-1))throw new Error("The 'W' character can be specified only when the day-of-month is a single day, not a range or list of days.");var r={SUN:0,MON:1,TUE:2,WED:3,THU:4,FRI:5,SAT:6};for(var n in r)e[5]=e[5].replace(new RegExp(n,"gi"),r[n].toString());e[4]=e[4].replace(/(^\d{1,2})|([^#/\s]\d{1,2})/g,function(c){var d=c.replace(/\D/,""),f=d;return t.monthStartIndexZero&&(f=(parseInt(d)+1).toString()),c.replace(d,f)});var o={JAN:1,FEB:2,MAR:3,APR:4,MAY:5,JUN:6,JUL:7,AUG:8,SEP:9,OCT:10,NOV:11,DEC:12};for(var a in o)e[4]=e[4].replace(new RegExp(a,"gi"),o[a].toString());e[0]=="0"&&(e[0]=""),!/\*|\-|\,|\//.test(e[2])&&(/\*|\//.test(e[1])||/\*|\//.test(e[0]))&&(e[2]+="-".concat(e[2]));for(var u=0;u<e.length;u++)if(e[u].indexOf(",")!=-1&&(e[u]=e[u].split(",").filter(function(c){return c!==""}).join(",")||"*"),e[u]=="*/1"&&(e[u]="*"),e[u].indexOf("/")>-1&&!/^\*|\-|\,/.test(e[u])){var s=null;switch(u){case 4:s="12";break;case 5:s="6";break;case 6:s="9999";break;default:s=null;break}if(s!==null){var h=e[u].split("/");e[u]="".concat(h[0],"-").concat(s,"/").concat(h[1])}}},l.prototype.validate=function(e){var t="0-9,\\-*/";this.validateOnlyExpectedCharactersFound(e[0],t),this.validateOnlyExpectedCharactersFound(e[1],t),this.validateOnlyExpectedCharactersFound(e[2],t),this.validateOnlyExpectedCharactersFound(e[3],"0-9,\\-*/LW"),this.validateOnlyExpectedCharactersFound(e[4],t),this.validateOnlyExpectedCharactersFound(e[5],"0-9,\\-*/L#"),this.validateOnlyExpectedCharactersFound(e[6],t),this.validateAnyRanges(e)},l.prototype.validateAnyRanges=function(e){i.default.secondRange(e[0]),i.default.minuteRange(e[1]),i.default.hourRange(e[2]),i.default.dayOfMonthRange(e[3]),i.default.monthRange(e[4],this.monthStartIndexZero),i.default.dayOfWeekRange(e[5],this.dayOfWeekStartIndexZero)},l.prototype.validateOnlyExpectedCharactersFound=function(e,t){var r=e.match(new RegExp("[^".concat(t,"]+"),"gi"));if(r&&r.length)throw new Error("Expression contains invalid values: '".concat(r.toString(),"'"))},l})();p.CronParser=y},333(g,p,v){Object.defineProperty(p,"__esModule",{value:!0}),p.ExpressionDescriptor=void 0;var i=v(823),y=v(949),l=(function(){function e(t,r){if(this.expression=t,this.options=r,this.expressionParts=new Array(5),!this.options.locale&&e.defaultLocale&&(this.options.locale=e.defaultLocale),!e.locales[this.options.locale]){var n=Object.keys(e.locales)[0];console.warn("Locale '".concat(this.options.locale,"' could not be found; falling back to '").concat(n,"'.")),this.options.locale=n}this.i18n=e.locales[this.options.locale],r.use24HourTimeFormat===void 0&&(r.use24HourTimeFormat=this.i18n.use24HourTimeFormatByDefault())}return e.toString=function(t,r){var n=r===void 0?{}:r,o=n.throwExceptionOnParseError,a=o===void 0?!0:o,u=n.verbose,s=u===void 0?!1:u,h=n.dayOfWeekStartIndexZero,c=h===void 0?!0:h,d=n.monthStartIndexZero,f=d===void 0?!1:d,O=n.use24HourTimeFormat,T=n.trimHoursLeadingZero,m=T===void 0?!1:T,b=n.locale,E=b===void 0?null:b,X=n.logicalAndDayFields,x=X===void 0?!1:X,S={throwExceptionOnParseError:a,verbose:s,dayOfWeekStartIndexZero:c,monthStartIndexZero:f,use24HourTimeFormat:O,trimHoursLeadingZero:m,locale:E,logicalAndDayFields:x};S.tzOffset&&console.warn("'tzOffset' option has been deprecated and is no longer supported.");var I=new e(t,S);return I.getFullDescription()},e.initialize=function(t,r){r===void 0&&(r="en"),e.specialCharacters=["/","-",",","*"],e.defaultLocale=r,t.load(e.locales)},e.prototype.getFullDescription=function(){var t,r,n="";try{var o=new y.CronParser(this.expression,this.options.dayOfWeekStartIndexZero,this.options.monthStartIndexZero);if(this.expressionParts=o.parse(),this.expressionParts[0]==="@reboot")return((r=(t=this.i18n).atReboot)===null||r===void 0?void 0:r.call(t))||"Run once, at startup";var a=this.getTimeOfDayDescription(),u=this.getDayOfMonthDescription(),s=this.getMonthDescription(),h=this.getDayOfWeekDescription(),c=this.getYearDescription();n+=a+u+h+s+c,n=this.transformVerbosity(n,!!this.options.verbose),n=n.charAt(0).toLocaleUpperCase()+n.substr(1)}catch(d){if(!this.options.throwExceptionOnParseError)n=this.i18n.anErrorOccuredWhenGeneratingTheExpressionD();else throw"".concat(d)}return n},e.prototype.getTimeOfDayDescription=function(){var t=this.expressionParts[0],r=this.expressionParts[1],n=this.expressionParts[2],o="";if(!i.StringUtilities.containsAny(r,e.specialCharacters)&&!i.StringUtilities.containsAny(n,e.specialCharacters)&&!i.StringUtilities.containsAny(t,e.specialCharacters))o+=this.i18n.atSpace()+this.formatTime(n,r,t);else if(!t&&r.indexOf("-")>-1&&!(r.indexOf(",")>-1)&&!(r.indexOf("/")>-1)&&!i.StringUtilities.containsAny(n,e.specialCharacters)){var a=r.split("-");o+=i.StringUtilities.format(this.i18n.everyMinuteBetweenX0AndX1(),this.formatTime(n,a[0],""),this.formatTime(n,a[1],""))}else if(!t&&n.indexOf(",")>-1&&n.indexOf("-")==-1&&n.indexOf("/")==-1&&!i.StringUtilities.containsAny(r,e.specialCharacters)){var u=n.split(",");o+=this.i18n.at();for(var s=0;s<u.length;s++)o&&(o+=" "),o+=this.formatTime(u[s],r,""),s<u.length-2&&(o+=","),s==u.length-2&&(o+=this.i18n.spaceAnd())}else{var h=this.getSecondsDescription(),c=this.getMinutesDescription(),d=this.getHoursDescription();if(o+=h,o&&c&&(o+=", "),o+=c,c===d)return o;o&&d&&(o+=", "),o+=d}return o},e.prototype.getSecondsDescription=function(){var t=this,r=this.getSegmentDescription(this.expressionParts[0],this.i18n.everySecond(),function(n){return n},function(n){return i.StringUtilities.format(t.i18n.everyX0Seconds(n),n)},function(n){return t.i18n.secondsX0ThroughX1PastTheMinute()},function(n){return n=="0"?"":parseInt(n)<20?t.i18n.atX0SecondsPastTheMinute(n):t.i18n.atX0SecondsPastTheMinuteGt20()||t.i18n.atX0SecondsPastTheMinute(n)});return r},e.prototype.getMinutesDescription=function(){var t=this,r=this.expressionParts[0],n=this.expressionParts[2],o=this.getSegmentDescription(this.expressionParts[1],this.i18n.everyMinute(),function(a){return a},function(a){return i.StringUtilities.format(t.i18n.everyX0Minutes(a),a)},function(a){return t.i18n.minutesX0ThroughX1PastTheHour()},function(a){var u,s;try{return a=="0"&&n.indexOf("/")==-1&&r==""?t.i18n.everyHour():a=="0"?((s=(u=t.i18n).onTheHour)===null||s===void 0?void 0:s.call(u))||t.i18n.atX0MinutesPastTheHour(a):parseInt(a)<20?t.i18n.atX0MinutesPastTheHour(a):t.i18n.atX0MinutesPastTheHourGt20()||t.i18n.atX0MinutesPastTheHour(a)}catch{return t.i18n.atX0MinutesPastTheHour(a)}});return o},e.prototype.getHoursDescription=function(){var t=this,r=this.expressionParts[2],n=0,o=[];r.split("/")[0].split(",").forEach(function(s){var h=s.split("-");h.length===2&&o.push({value:h[1],index:n+1}),n+=h.length});var a=0,u=this.getSegmentDescription(r,this.i18n.everyHour(),function(s){var h=o.find(function(d){return d.value===s&&d.index===a}),c=h&&t.expressionParts[1]!=="0";return a++,c?t.formatTime(s,"59",""):t.formatTime(s,"0","")},function(s){return i.StringUtilities.format(t.i18n.everyX0Hours(s),s)},function(s){return t.i18n.betweenX0AndX1()},function(s){return t.i18n.atX0()});return u},e.prototype.getDayOfWeekDescription=function(){var t=this,r=this.i18n.daysOfTheWeek(),n=null;return this.expressionParts[5]=="*"?n="":n=this.getSegmentDescription(this.expressionParts[5],this.i18n.commaEveryDay(),function(o,a){var u=o;o.indexOf("#")>-1?u=o.substring(0,o.indexOf("#")):o.indexOf("L")>-1&&(u=u.replace("L",""));var s=parseInt(u),h=t.i18n.daysOfTheWeekInCase?t.i18n.daysOfTheWeekInCase(a)[s]:r[s];if(o.indexOf("#")>-1){var c=null,d=o.substring(o.indexOf("#")+1),f=o.substring(0,o.indexOf("#"));switch(d){case"1":c=t.i18n.first(f);break;case"2":c=t.i18n.second(f);break;case"3":c=t.i18n.third(f);break;case"4":c=t.i18n.fourth(f);break;case"5":c=t.i18n.fifth(f);break}h=c+" "+h}return h},function(o){return parseInt(o)==1?"":i.StringUtilities.format(t.i18n.commaEveryX0DaysOfTheWeek(o),o)},function(o){var a=o.substring(0,o.indexOf("-")),u=t.expressionParts[3]!="*";return u?t.i18n.commaAndX0ThroughX1(a):t.i18n.commaX0ThroughX1(a)},function(o){var a=null;if(o.indexOf("#")>-1){var u=o.substring(o.indexOf("#")+1),s=o.substring(0,o.indexOf("#"));a=t.i18n.commaOnThe(u,s).trim()+t.i18n.spaceX0OfTheMonth()}else if(o.indexOf("L")>-1)a=t.i18n.commaOnTheLastX0OfTheMonth(o.replace("L",""));else{var h=t.expressionParts[3]!="*";h?t.options.logicalAndDayFields?a=t.i18n.commaOnlyOnX0(o):a=t.i18n.commaAndOnX0():a=t.i18n.commaOnlyOnX0(o)}return a}),n},e.prototype.getMonthDescription=function(){var t=this,r=this.i18n.monthsOfTheYear(),n=this.getSegmentDescription(this.expressionParts[4],"",function(o,a){return a&&t.i18n.monthsOfTheYearInCase?t.i18n.monthsOfTheYearInCase(a)[parseInt(o)-1]:r[parseInt(o)-1]},function(o){return parseInt(o)==1?"":i.StringUtilities.format(t.i18n.commaEveryX0Months(o),o)},function(o){return t.i18n.commaMonthX0ThroughMonthX1()||t.i18n.commaX0ThroughX1()},function(o){return t.i18n.commaOnlyInMonthX0?t.i18n.commaOnlyInMonthX0():t.i18n.commaOnlyInX0()});return n},e.prototype.getDayOfMonthDescription=function(){var t=this,r=null,n=this.expressionParts[3];switch(n){case"L":r=this.i18n.commaOnTheLastDayOfTheMonth();break;case"WL":case"LW":r=this.i18n.commaOnTheLastWeekdayOfTheMonth();break;default:var o=n.match(/(\d{1,2}W)|(W\d{1,2})/);if(o){var a=parseInt(o[0].replace("W","")),u=a==1?this.i18n.firstWeekday():i.StringUtilities.format(this.i18n.weekdayNearestDayX0(),a.toString());r=i.StringUtilities.format(this.i18n.commaOnTheX0OfTheMonth(),u);break}else{var s=n.match(/L-(\d{1,2})/);if(s){var h=s[1];r=i.StringUtilities.format(this.i18n.commaDaysBeforeTheLastDayOfTheMonth(h),h);break}else{if(n=="*"&&this.expressionParts[5]!="*")return"";r=this.getSegmentDescription(n,this.i18n.commaEveryDay(),function(c){return c=="L"?t.i18n.lastDay():t.i18n.dayX0?i.StringUtilities.format(t.i18n.dayX0(),c):c},function(c){return c=="1"?t.i18n.commaEveryDay():t.i18n.commaEveryX0Days(c)},function(c){return t.i18n.commaBetweenDayX0AndX1OfTheMonth(c)},function(c){return t.i18n.commaOnDayX0OfTheMonth(c)})}break}}return r},e.prototype.getYearDescription=function(){var t=this,r=this.getSegmentDescription(this.expressionParts[6],"",function(n){return/^\d+$/.test(n)?new Date(parseInt(n),1).getFullYear().toString():n},function(n){return i.StringUtilities.format(t.i18n.commaEveryX0Years(n),n)},function(n){return t.i18n.commaYearX0ThroughYearX1()||t.i18n.commaX0ThroughX1()},function(n){return t.i18n.commaOnlyInYearX0?t.i18n.commaOnlyInYearX0():t.i18n.commaOnlyInX0()});return r},e.prototype.getSegmentDescription=function(t,r,n,o,a,u){var s=null,h=t.indexOf("/")>-1,c=t.indexOf("-")>-1,d=t.indexOf(",")>-1;if(!t)s="";else if(t==="*")s=r;else if(!h&&!c&&!d)s=i.StringUtilities.format(u(t),n(t));else if(d){for(var f=t.split(","),O="",T=this.i18n.spaceAnd(),m=0;m<f.length;m++)if(m>0&&f.length>2&&(O+=",",m<f.length-1&&(O+=" ")),m>0&&f.length>1&&(m==f.length-1||f.length==2)&&(O+=T==","&&f.length>2?" ":"".concat(T," ")),f[m].indexOf("/")>-1||f[m].indexOf("-")>-1){var b=f[m].indexOf("-")>-1&&f[m].indexOf("/")==-1,E=this.getSegmentDescription(f[m],r,n,o,b?this.i18n.commaX0ThroughX1:a,u);b&&(E=E.replace(", ","")),O+=E}else if(!h)O+=n(f[m]);else{var X=this.getSegmentDescription(f[m],r,n,o,a,u);X&&X.startsWith(", ")&&(X=X.substring(2)),O+=X}h?s=O:s=i.StringUtilities.format(u(t),O)}else if(h){var f=t.split("/");if(s=i.StringUtilities.format(o(f[1]),f[1]),f[0].indexOf("-")>-1){var x=this.generateRangeSegmentDescription(f[0],a,n);x.indexOf(", ")!=0&&(s+=", "),s+=x}else if(f[0].indexOf("*")==-1){var S=i.StringUtilities.format(u(f[0]),n(f[0]));S=S.replace(", ",""),s+=i.StringUtilities.format(this.i18n.commaStartingX0(),S)}}else c&&(s=this.generateRangeSegmentDescription(t,a,n));return s},e.prototype.generateRangeSegmentDescription=function(t,r,n){var o="",a=t.split("-"),u=n(a[0],1),s=n(a[1],2),h=r(t);return o+=i.StringUtilities.format(h,u,s),o},e.prototype.formatTime=function(t,r,n){var o=0,a=0,u=parseInt(t)+o,s=parseInt(r)+a;s>=60?(s-=60,u+=1):s<0&&(s+=60,u-=1),u>=24?u=u-24:u<0&&(u=24+u);var h="",c=!1;this.options.use24HourTimeFormat||(c=!!(this.i18n.setPeriodBeforeTime&&this.i18n.setPeriodBeforeTime()),h=c?"".concat(this.getPeriod(u)," "):" ".concat(this.getPeriod(u)),u>12&&(u-=12),u===0&&(u=12));var d="";n&&(d=":".concat(("00"+n).substring(n.length)));var f=u.toString(),O=("00"+f).substring(f.length),T=s.toString(),m=("00"+T).substring(T.length),b=this.options.trimHoursLeadingZero?f:O;return"".concat(c?h:"").concat(b,":").concat(m).concat(d).concat(c?"":h)},e.prototype.transformVerbosity=function(t,r){if(!r&&(t=t.replace(new RegExp(", ".concat(this.i18n.everyMinute()),"g"),""),t=t.replace(new RegExp(", ".concat(this.i18n.everyHour()),"g"),""),t=t.replace(new RegExp(this.i18n.commaEveryDay(),"g"),""),t=t.replace(/\, ?$/,""),this.i18n.conciseVerbosityReplacements))for(var n=0,o=Object.entries(this.i18n.conciseVerbosityReplacements());n<o.length;n++){var a=o[n],u=a[0],s=a[1];t=t.replace(new RegExp(u,"g"),s)}return t},e.prototype.getPeriod=function(t){return t>=12?this.i18n.pm&&this.i18n.pm()||"PM":this.i18n.am&&this.i18n.am()||"AM"},e.locales={},e})();p.ExpressionDescriptor=l},747(g,p,v){Object.defineProperty(p,"__esModule",{value:!0}),p.enLocaleLoader=void 0;var i=v(486),y=(function(){function l(){}return l.prototype.load=function(e){e.en=new i.en},l})();p.enLocaleLoader=y},486(g,p){Object.defineProperty(p,"__esModule",{value:!0}),p.en=void 0;var v=(function(){function i(){}return i.prototype.atX0SecondsPastTheMinuteGt20=function(){return null},i.prototype.atX0MinutesPastTheHourGt20=function(){return null},i.prototype.commaMonthX0ThroughMonthX1=function(){return null},i.prototype.commaYearX0ThroughYearX1=function(){return null},i.prototype.use24HourTimeFormatByDefault=function(){return!1},i.prototype.anErrorOccuredWhenGeneratingTheExpressionD=function(){return"An error occurred when generating the expression description. Check the cron expression syntax."},i.prototype.everyMinute=function(){return"every minute"},i.prototype.everyHour=function(){return"every hour"},i.prototype.atSpace=function(){return"At "},i.prototype.everyMinuteBetweenX0AndX1=function(){return"Every minute between %s and %s"},i.prototype.at=function(){return"At"},i.prototype.spaceAnd=function(){return" and"},i.prototype.everySecond=function(){return"every second"},i.prototype.everyX0Seconds=function(){return"every %s seconds"},i.prototype.secondsX0ThroughX1PastTheMinute=function(){return"seconds %s through %s past the minute"},i.prototype.atX0SecondsPastTheMinute=function(){return"at %s seconds past the minute"},i.prototype.everyX0Minutes=function(){return"every %s minutes"},i.prototype.minutesX0ThroughX1PastTheHour=function(){return"minutes %s through %s past the hour"},i.prototype.atX0MinutesPastTheHour=function(){return"at %s minutes past the hour"},i.prototype.everyX0Hours=function(){return"every %s hours"},i.prototype.betweenX0AndX1=function(){return"between %s and %s"},i.prototype.atX0=function(){return"at %s"},i.prototype.commaEveryDay=function(){return", every day"},i.prototype.commaEveryX0DaysOfTheWeek=function(){return", every %s days of the week"},i.prototype.commaX0ThroughX1=function(){return", %s through %s"},i.prototype.commaAndX0ThroughX1=function(){return", %s through %s"},i.prototype.first=function(){return"first"},i.prototype.second=function(){return"second"},i.prototype.third=function(){return"third"},i.prototype.fourth=function(){return"fourth"},i.prototype.fifth=function(){return"fifth"},i.prototype.commaOnThe=function(){return", on the "},i.prototype.spaceX0OfTheMonth=function(){return" %s of the month"},i.prototype.lastDay=function(){return"the last day"},i.prototype.commaOnTheLastX0OfTheMonth=function(){return", on the last %s of the month"},i.prototype.commaOnlyOnX0=function(){return", only on %s"},i.prototype.commaAndOnX0=function(){return", and on %s"},i.prototype.commaEveryX0Months=function(){return", every %s months"},i.prototype.commaOnlyInX0=function(){return", only in %s"},i.prototype.commaOnTheLastDayOfTheMonth=function(){return", on the last day of the month"},i.prototype.commaOnTheLastWeekdayOfTheMonth=function(){return", on the last weekday of the month"},i.prototype.commaDaysBeforeTheLastDayOfTheMonth=function(){return", %s days before the last day of the month"},i.prototype.firstWeekday=function(){return"first weekday"},i.prototype.weekdayNearestDayX0=function(){return"weekday nearest day %s"},i.prototype.commaOnTheX0OfTheMonth=function(){return", on the %s of the month"},i.prototype.commaEveryX0Days=function(){return", every %s days in a month"},i.prototype.commaBetweenDayX0AndX1OfTheMonth=function(){return", between day %s and %s of the month"},i.prototype.commaOnDayX0OfTheMonth=function(){return", on day %s of the month"},i.prototype.commaEveryHour=function(){return", every hour"},i.prototype.commaEveryX0Years=function(){return", every %s years"},i.prototype.commaStartingX0=function(){return", starting %s"},i.prototype.daysOfTheWeek=function(){return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},i.prototype.monthsOfTheYear=function(){return["January","February","March","April","May","June","July","August","September","October","November","December"]},i.prototype.atReboot=function(){return"Run once, at startup"},i.prototype.onTheHour=function(){return"on the hour"},i})();p.en=v},515(g,p){Object.defineProperty(p,"__esModule",{value:!0});function v(y,l){if(!y)throw new Error(l)}var i=(function(){function y(){}return y.secondRange=function(l){for(var e=l.split(","),t=0;t<e.length;t++)if(!isNaN(parseInt(e[t],10))){var r=parseInt(e[t],10);v(r>=0&&r<=59,"seconds part must be >= 0 and <= 59")}},y.minuteRange=function(l){for(var e=l.split(","),t=0;t<e.length;t++)if(!isNaN(parseInt(e[t],10))){var r=parseInt(e[t],10);v(r>=0&&r<=59,"minutes part must be >= 0 and <= 59")}},y.hourRange=function(l){for(var e=l.split(","),t=0;t<e.length;t++)if(!isNaN(parseInt(e[t],10))){var r=parseInt(e[t],10);v(r>=0&&r<=23,"hours part must be >= 0 and <= 23")}},y.dayOfMonthRange=function(l){for(var e=l.split(","),t=0;t<e.length;t++)if(!isNaN(parseInt(e[t],10))){var r=parseInt(e[t],10);v(r>=1&&r<=31,"DOM part must be >= 1 and <= 31")}},y.monthRange=function(l,e){for(var t=l.split(","),r=0;r<t.length;r++)if(!isNaN(parseInt(t[r],10))){var n=parseInt(t[r],10);v(n>=1&&n<=12,e?"month part must be >= 0 and <= 11":"month part must be >= 1 and <= 12")}},y.dayOfWeekRange=function(l,e){for(var t=l.split(","),r=0;r<t.length;r++)if(!isNaN(parseInt(t[r],10))){var n=parseInt(t[r],10);v(n>=0&&n<=6,e?"DOW part must be >= 0 and <= 6":"DOW part must be >= 1 and <= 7")}},y})();p.default=i},823(g,p){Object.defineProperty(p,"__esModule",{value:!0}),p.StringUtilities=void 0;var v=(function(){function i(){}return i.format=function(y){for(var l=[],e=1;e<arguments.length;e++)l[e-1]=arguments[e];return y.replace(/%s/g,function(t){return l.shift()})},i.containsAny=function(y,l){return l.some(function(e){return y.indexOf(e)>-1})},i})();p.StringUtilities=v}},w={};function _(g){var p=w[g];if(p!==void 0)return p.exports;var v=w[g]={exports:{}};return D[g](v,v.exports,_),v.exports}var k={};return(()=>{var g=k;Object.defineProperty(g,"__esModule",{value:!0}),g.toString=void 0;var p=_(333),v=_(747);p.ExpressionDescriptor.initialize(new v.enLocaleLoader),g.default=p.ExpressionDescriptor;var i=p.ExpressionDescriptor.toString;g.toString=i})(),k})())})(M)),M.exports}var R=H();const F=U(R);export{F as c};
1
+ import{aC as U}from"./index-BUr8321-.js";var M={exports:{}},A;function H(){return A||(A=1,(function(L,C){(function(w,_){L.exports=_()})(globalThis,()=>(()=>{var D={949(g,p,v){Object.defineProperty(p,"__esModule",{value:!0}),p.CronParser=void 0;var i=v(515),y=(function(){function l(e,t,r){t===void 0&&(t=!0),r===void 0&&(r=!1),this.expression=e,this.dayOfWeekStartIndexZero=t,this.monthStartIndexZero=r}return l.prototype.parse=function(){var e,t,r=(e=this.expression)!==null&&e!==void 0?e:"";if(r==="@reboot")return t=["@reboot","","","","","",""],t;if(r.startsWith("@")){var n=this.parseSpecial(this.expression);t=this.extractParts(n)}else t=this.extractParts(this.expression);return this.normalize(t),this.validate(t),t},l.prototype.parseSpecial=function(e){var t={"@yearly":"0 0 1 1 *","@annually":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *","@reboot":"@reboot"},r=t[e];if(!r)throw new Error("Unknown special expression.");return r},l.prototype.extractParts=function(e){if(!this.expression)throw new Error("cron expression is empty");for(var t=e.trim().split(/[ ]+/),r=0;r<t.length;r++)if(t[r].includes(",")){var n=t[r].split(",").map(function(a){return a.trim()}).filter(function(a){return a!==""}).map(function(a){return isNaN(Number(a))?a:Number(a)}).filter(function(a){return a!==null&&a!==""});n.length===0&&n.push("*"),n.sort(function(a,u){return a!==null&&u!==null?a-u:0}),t[r]=n.map(function(a){return a!==null?a.toString():""}).join(",")}if(t.length<5)throw new Error("Expression has only ".concat(t.length," part").concat(t.length==1?"":"s",". At least 5 parts are required."));if(t.length==5)t.unshift(""),t.push("");else if(t.length==6){var o=/\d{4}$/.test(t[5])||t[4]=="?"||t[2]=="?";o?t.unshift(""):t.push("")}else if(t.length>7)throw new Error("Expression has ".concat(t.length," parts; too many!"));return t},l.prototype.normalize=function(e){var t=this;if(e[3]=e[3].replace("?","*"),e[5]=e[5].replace("?","*"),e[2]=e[2].replace("?","*"),e[0].indexOf("0/")==0&&(e[0]=e[0].replace("0/","*/")),e[1].indexOf("0/")==0&&(e[1]=e[1].replace("0/","*/")),e[2].indexOf("0/")==0&&(e[2]=e[2].replace("0/","*/")),e[3].indexOf("1/")==0&&(e[3]=e[3].replace("1/","*/")),e[4].indexOf("1/")==0&&(e[4]=e[4].replace("1/","*/")),e[6].indexOf("1/")==0&&(e[6]=e[6].replace("1/","*/")),e[5]=e[5].replace(/(^\d)|([^#/\s]\d)/g,function(c){var d=c.replace(/\D/,""),f=d;return t.dayOfWeekStartIndexZero?d=="7"&&(f="0"):f=(parseInt(d)-1).toString(),c.replace(d,f)}),e[5]=="L"&&(e[5]="6"),e[3]=="?"&&(e[3]="*"),e[3].indexOf("W")>-1&&(e[3].indexOf(",")>-1||e[3].indexOf("-")>-1))throw new Error("The 'W' character can be specified only when the day-of-month is a single day, not a range or list of days.");var r={SUN:0,MON:1,TUE:2,WED:3,THU:4,FRI:5,SAT:6};for(var n in r)e[5]=e[5].replace(new RegExp(n,"gi"),r[n].toString());e[4]=e[4].replace(/(^\d{1,2})|([^#/\s]\d{1,2})/g,function(c){var d=c.replace(/\D/,""),f=d;return t.monthStartIndexZero&&(f=(parseInt(d)+1).toString()),c.replace(d,f)});var o={JAN:1,FEB:2,MAR:3,APR:4,MAY:5,JUN:6,JUL:7,AUG:8,SEP:9,OCT:10,NOV:11,DEC:12};for(var a in o)e[4]=e[4].replace(new RegExp(a,"gi"),o[a].toString());e[0]=="0"&&(e[0]=""),!/\*|\-|\,|\//.test(e[2])&&(/\*|\//.test(e[1])||/\*|\//.test(e[0]))&&(e[2]+="-".concat(e[2]));for(var u=0;u<e.length;u++)if(e[u].indexOf(",")!=-1&&(e[u]=e[u].split(",").filter(function(c){return c!==""}).join(",")||"*"),e[u]=="*/1"&&(e[u]="*"),e[u].indexOf("/")>-1&&!/^\*|\-|\,/.test(e[u])){var s=null;switch(u){case 4:s="12";break;case 5:s="6";break;case 6:s="9999";break;default:s=null;break}if(s!==null){var h=e[u].split("/");e[u]="".concat(h[0],"-").concat(s,"/").concat(h[1])}}},l.prototype.validate=function(e){var t="0-9,\\-*/";this.validateOnlyExpectedCharactersFound(e[0],t),this.validateOnlyExpectedCharactersFound(e[1],t),this.validateOnlyExpectedCharactersFound(e[2],t),this.validateOnlyExpectedCharactersFound(e[3],"0-9,\\-*/LW"),this.validateOnlyExpectedCharactersFound(e[4],t),this.validateOnlyExpectedCharactersFound(e[5],"0-9,\\-*/L#"),this.validateOnlyExpectedCharactersFound(e[6],t),this.validateAnyRanges(e)},l.prototype.validateAnyRanges=function(e){i.default.secondRange(e[0]),i.default.minuteRange(e[1]),i.default.hourRange(e[2]),i.default.dayOfMonthRange(e[3]),i.default.monthRange(e[4],this.monthStartIndexZero),i.default.dayOfWeekRange(e[5],this.dayOfWeekStartIndexZero)},l.prototype.validateOnlyExpectedCharactersFound=function(e,t){var r=e.match(new RegExp("[^".concat(t,"]+"),"gi"));if(r&&r.length)throw new Error("Expression contains invalid values: '".concat(r.toString(),"'"))},l})();p.CronParser=y},333(g,p,v){Object.defineProperty(p,"__esModule",{value:!0}),p.ExpressionDescriptor=void 0;var i=v(823),y=v(949),l=(function(){function e(t,r){if(this.expression=t,this.options=r,this.expressionParts=new Array(5),!this.options.locale&&e.defaultLocale&&(this.options.locale=e.defaultLocale),!e.locales[this.options.locale]){var n=Object.keys(e.locales)[0];console.warn("Locale '".concat(this.options.locale,"' could not be found; falling back to '").concat(n,"'.")),this.options.locale=n}this.i18n=e.locales[this.options.locale],r.use24HourTimeFormat===void 0&&(r.use24HourTimeFormat=this.i18n.use24HourTimeFormatByDefault())}return e.toString=function(t,r){var n=r===void 0?{}:r,o=n.throwExceptionOnParseError,a=o===void 0?!0:o,u=n.verbose,s=u===void 0?!1:u,h=n.dayOfWeekStartIndexZero,c=h===void 0?!0:h,d=n.monthStartIndexZero,f=d===void 0?!1:d,O=n.use24HourTimeFormat,T=n.trimHoursLeadingZero,m=T===void 0?!1:T,b=n.locale,E=b===void 0?null:b,X=n.logicalAndDayFields,x=X===void 0?!1:X,S={throwExceptionOnParseError:a,verbose:s,dayOfWeekStartIndexZero:c,monthStartIndexZero:f,use24HourTimeFormat:O,trimHoursLeadingZero:m,locale:E,logicalAndDayFields:x};S.tzOffset&&console.warn("'tzOffset' option has been deprecated and is no longer supported.");var I=new e(t,S);return I.getFullDescription()},e.initialize=function(t,r){r===void 0&&(r="en"),e.specialCharacters=["/","-",",","*"],e.defaultLocale=r,t.load(e.locales)},e.prototype.getFullDescription=function(){var t,r,n="";try{var o=new y.CronParser(this.expression,this.options.dayOfWeekStartIndexZero,this.options.monthStartIndexZero);if(this.expressionParts=o.parse(),this.expressionParts[0]==="@reboot")return((r=(t=this.i18n).atReboot)===null||r===void 0?void 0:r.call(t))||"Run once, at startup";var a=this.getTimeOfDayDescription(),u=this.getDayOfMonthDescription(),s=this.getMonthDescription(),h=this.getDayOfWeekDescription(),c=this.getYearDescription();n+=a+u+h+s+c,n=this.transformVerbosity(n,!!this.options.verbose),n=n.charAt(0).toLocaleUpperCase()+n.substr(1)}catch(d){if(!this.options.throwExceptionOnParseError)n=this.i18n.anErrorOccuredWhenGeneratingTheExpressionD();else throw"".concat(d)}return n},e.prototype.getTimeOfDayDescription=function(){var t=this.expressionParts[0],r=this.expressionParts[1],n=this.expressionParts[2],o="";if(!i.StringUtilities.containsAny(r,e.specialCharacters)&&!i.StringUtilities.containsAny(n,e.specialCharacters)&&!i.StringUtilities.containsAny(t,e.specialCharacters))o+=this.i18n.atSpace()+this.formatTime(n,r,t);else if(!t&&r.indexOf("-")>-1&&!(r.indexOf(",")>-1)&&!(r.indexOf("/")>-1)&&!i.StringUtilities.containsAny(n,e.specialCharacters)){var a=r.split("-");o+=i.StringUtilities.format(this.i18n.everyMinuteBetweenX0AndX1(),this.formatTime(n,a[0],""),this.formatTime(n,a[1],""))}else if(!t&&n.indexOf(",")>-1&&n.indexOf("-")==-1&&n.indexOf("/")==-1&&!i.StringUtilities.containsAny(r,e.specialCharacters)){var u=n.split(",");o+=this.i18n.at();for(var s=0;s<u.length;s++)o&&(o+=" "),o+=this.formatTime(u[s],r,""),s<u.length-2&&(o+=","),s==u.length-2&&(o+=this.i18n.spaceAnd())}else{var h=this.getSecondsDescription(),c=this.getMinutesDescription(),d=this.getHoursDescription();if(o+=h,o&&c&&(o+=", "),o+=c,c===d)return o;o&&d&&(o+=", "),o+=d}return o},e.prototype.getSecondsDescription=function(){var t=this,r=this.getSegmentDescription(this.expressionParts[0],this.i18n.everySecond(),function(n){return n},function(n){return i.StringUtilities.format(t.i18n.everyX0Seconds(n),n)},function(n){return t.i18n.secondsX0ThroughX1PastTheMinute()},function(n){return n=="0"?"":parseInt(n)<20?t.i18n.atX0SecondsPastTheMinute(n):t.i18n.atX0SecondsPastTheMinuteGt20()||t.i18n.atX0SecondsPastTheMinute(n)});return r},e.prototype.getMinutesDescription=function(){var t=this,r=this.expressionParts[0],n=this.expressionParts[2],o=this.getSegmentDescription(this.expressionParts[1],this.i18n.everyMinute(),function(a){return a},function(a){return i.StringUtilities.format(t.i18n.everyX0Minutes(a),a)},function(a){return t.i18n.minutesX0ThroughX1PastTheHour()},function(a){var u,s;try{return a=="0"&&n.indexOf("/")==-1&&r==""?t.i18n.everyHour():a=="0"?((s=(u=t.i18n).onTheHour)===null||s===void 0?void 0:s.call(u))||t.i18n.atX0MinutesPastTheHour(a):parseInt(a)<20?t.i18n.atX0MinutesPastTheHour(a):t.i18n.atX0MinutesPastTheHourGt20()||t.i18n.atX0MinutesPastTheHour(a)}catch{return t.i18n.atX0MinutesPastTheHour(a)}});return o},e.prototype.getHoursDescription=function(){var t=this,r=this.expressionParts[2],n=0,o=[];r.split("/")[0].split(",").forEach(function(s){var h=s.split("-");h.length===2&&o.push({value:h[1],index:n+1}),n+=h.length});var a=0,u=this.getSegmentDescription(r,this.i18n.everyHour(),function(s){var h=o.find(function(d){return d.value===s&&d.index===a}),c=h&&t.expressionParts[1]!=="0";return a++,c?t.formatTime(s,"59",""):t.formatTime(s,"0","")},function(s){return i.StringUtilities.format(t.i18n.everyX0Hours(s),s)},function(s){return t.i18n.betweenX0AndX1()},function(s){return t.i18n.atX0()});return u},e.prototype.getDayOfWeekDescription=function(){var t=this,r=this.i18n.daysOfTheWeek(),n=null;return this.expressionParts[5]=="*"?n="":n=this.getSegmentDescription(this.expressionParts[5],this.i18n.commaEveryDay(),function(o,a){var u=o;o.indexOf("#")>-1?u=o.substring(0,o.indexOf("#")):o.indexOf("L")>-1&&(u=u.replace("L",""));var s=parseInt(u),h=t.i18n.daysOfTheWeekInCase?t.i18n.daysOfTheWeekInCase(a)[s]:r[s];if(o.indexOf("#")>-1){var c=null,d=o.substring(o.indexOf("#")+1),f=o.substring(0,o.indexOf("#"));switch(d){case"1":c=t.i18n.first(f);break;case"2":c=t.i18n.second(f);break;case"3":c=t.i18n.third(f);break;case"4":c=t.i18n.fourth(f);break;case"5":c=t.i18n.fifth(f);break}h=c+" "+h}return h},function(o){return parseInt(o)==1?"":i.StringUtilities.format(t.i18n.commaEveryX0DaysOfTheWeek(o),o)},function(o){var a=o.substring(0,o.indexOf("-")),u=t.expressionParts[3]!="*";return u?t.i18n.commaAndX0ThroughX1(a):t.i18n.commaX0ThroughX1(a)},function(o){var a=null;if(o.indexOf("#")>-1){var u=o.substring(o.indexOf("#")+1),s=o.substring(0,o.indexOf("#"));a=t.i18n.commaOnThe(u,s).trim()+t.i18n.spaceX0OfTheMonth()}else if(o.indexOf("L")>-1)a=t.i18n.commaOnTheLastX0OfTheMonth(o.replace("L",""));else{var h=t.expressionParts[3]!="*";h?t.options.logicalAndDayFields?a=t.i18n.commaOnlyOnX0(o):a=t.i18n.commaAndOnX0():a=t.i18n.commaOnlyOnX0(o)}return a}),n},e.prototype.getMonthDescription=function(){var t=this,r=this.i18n.monthsOfTheYear(),n=this.getSegmentDescription(this.expressionParts[4],"",function(o,a){return a&&t.i18n.monthsOfTheYearInCase?t.i18n.monthsOfTheYearInCase(a)[parseInt(o)-1]:r[parseInt(o)-1]},function(o){return parseInt(o)==1?"":i.StringUtilities.format(t.i18n.commaEveryX0Months(o),o)},function(o){return t.i18n.commaMonthX0ThroughMonthX1()||t.i18n.commaX0ThroughX1()},function(o){return t.i18n.commaOnlyInMonthX0?t.i18n.commaOnlyInMonthX0():t.i18n.commaOnlyInX0()});return n},e.prototype.getDayOfMonthDescription=function(){var t=this,r=null,n=this.expressionParts[3];switch(n){case"L":r=this.i18n.commaOnTheLastDayOfTheMonth();break;case"WL":case"LW":r=this.i18n.commaOnTheLastWeekdayOfTheMonth();break;default:var o=n.match(/(\d{1,2}W)|(W\d{1,2})/);if(o){var a=parseInt(o[0].replace("W","")),u=a==1?this.i18n.firstWeekday():i.StringUtilities.format(this.i18n.weekdayNearestDayX0(),a.toString());r=i.StringUtilities.format(this.i18n.commaOnTheX0OfTheMonth(),u);break}else{var s=n.match(/L-(\d{1,2})/);if(s){var h=s[1];r=i.StringUtilities.format(this.i18n.commaDaysBeforeTheLastDayOfTheMonth(h),h);break}else{if(n=="*"&&this.expressionParts[5]!="*")return"";r=this.getSegmentDescription(n,this.i18n.commaEveryDay(),function(c){return c=="L"?t.i18n.lastDay():t.i18n.dayX0?i.StringUtilities.format(t.i18n.dayX0(),c):c},function(c){return c=="1"?t.i18n.commaEveryDay():t.i18n.commaEveryX0Days(c)},function(c){return t.i18n.commaBetweenDayX0AndX1OfTheMonth(c)},function(c){return t.i18n.commaOnDayX0OfTheMonth(c)})}break}}return r},e.prototype.getYearDescription=function(){var t=this,r=this.getSegmentDescription(this.expressionParts[6],"",function(n){return/^\d+$/.test(n)?new Date(parseInt(n),1).getFullYear().toString():n},function(n){return i.StringUtilities.format(t.i18n.commaEveryX0Years(n),n)},function(n){return t.i18n.commaYearX0ThroughYearX1()||t.i18n.commaX0ThroughX1()},function(n){return t.i18n.commaOnlyInYearX0?t.i18n.commaOnlyInYearX0():t.i18n.commaOnlyInX0()});return r},e.prototype.getSegmentDescription=function(t,r,n,o,a,u){var s=null,h=t.indexOf("/")>-1,c=t.indexOf("-")>-1,d=t.indexOf(",")>-1;if(!t)s="";else if(t==="*")s=r;else if(!h&&!c&&!d)s=i.StringUtilities.format(u(t),n(t));else if(d){for(var f=t.split(","),O="",T=this.i18n.spaceAnd(),m=0;m<f.length;m++)if(m>0&&f.length>2&&(O+=",",m<f.length-1&&(O+=" ")),m>0&&f.length>1&&(m==f.length-1||f.length==2)&&(O+=T==","&&f.length>2?" ":"".concat(T," ")),f[m].indexOf("/")>-1||f[m].indexOf("-")>-1){var b=f[m].indexOf("-")>-1&&f[m].indexOf("/")==-1,E=this.getSegmentDescription(f[m],r,n,o,b?this.i18n.commaX0ThroughX1:a,u);b&&(E=E.replace(", ","")),O+=E}else if(!h)O+=n(f[m]);else{var X=this.getSegmentDescription(f[m],r,n,o,a,u);X&&X.startsWith(", ")&&(X=X.substring(2)),O+=X}h?s=O:s=i.StringUtilities.format(u(t),O)}else if(h){var f=t.split("/");if(s=i.StringUtilities.format(o(f[1]),f[1]),f[0].indexOf("-")>-1){var x=this.generateRangeSegmentDescription(f[0],a,n);x.indexOf(", ")!=0&&(s+=", "),s+=x}else if(f[0].indexOf("*")==-1){var S=i.StringUtilities.format(u(f[0]),n(f[0]));S=S.replace(", ",""),s+=i.StringUtilities.format(this.i18n.commaStartingX0(),S)}}else c&&(s=this.generateRangeSegmentDescription(t,a,n));return s},e.prototype.generateRangeSegmentDescription=function(t,r,n){var o="",a=t.split("-"),u=n(a[0],1),s=n(a[1],2),h=r(t);return o+=i.StringUtilities.format(h,u,s),o},e.prototype.formatTime=function(t,r,n){var o=0,a=0,u=parseInt(t)+o,s=parseInt(r)+a;s>=60?(s-=60,u+=1):s<0&&(s+=60,u-=1),u>=24?u=u-24:u<0&&(u=24+u);var h="",c=!1;this.options.use24HourTimeFormat||(c=!!(this.i18n.setPeriodBeforeTime&&this.i18n.setPeriodBeforeTime()),h=c?"".concat(this.getPeriod(u)," "):" ".concat(this.getPeriod(u)),u>12&&(u-=12),u===0&&(u=12));var d="";n&&(d=":".concat(("00"+n).substring(n.length)));var f=u.toString(),O=("00"+f).substring(f.length),T=s.toString(),m=("00"+T).substring(T.length),b=this.options.trimHoursLeadingZero?f:O;return"".concat(c?h:"").concat(b,":").concat(m).concat(d).concat(c?"":h)},e.prototype.transformVerbosity=function(t,r){if(!r&&(t=t.replace(new RegExp(", ".concat(this.i18n.everyMinute()),"g"),""),t=t.replace(new RegExp(", ".concat(this.i18n.everyHour()),"g"),""),t=t.replace(new RegExp(this.i18n.commaEveryDay(),"g"),""),t=t.replace(/\, ?$/,""),this.i18n.conciseVerbosityReplacements))for(var n=0,o=Object.entries(this.i18n.conciseVerbosityReplacements());n<o.length;n++){var a=o[n],u=a[0],s=a[1];t=t.replace(new RegExp(u,"g"),s)}return t},e.prototype.getPeriod=function(t){return t>=12?this.i18n.pm&&this.i18n.pm()||"PM":this.i18n.am&&this.i18n.am()||"AM"},e.locales={},e})();p.ExpressionDescriptor=l},747(g,p,v){Object.defineProperty(p,"__esModule",{value:!0}),p.enLocaleLoader=void 0;var i=v(486),y=(function(){function l(){}return l.prototype.load=function(e){e.en=new i.en},l})();p.enLocaleLoader=y},486(g,p){Object.defineProperty(p,"__esModule",{value:!0}),p.en=void 0;var v=(function(){function i(){}return i.prototype.atX0SecondsPastTheMinuteGt20=function(){return null},i.prototype.atX0MinutesPastTheHourGt20=function(){return null},i.prototype.commaMonthX0ThroughMonthX1=function(){return null},i.prototype.commaYearX0ThroughYearX1=function(){return null},i.prototype.use24HourTimeFormatByDefault=function(){return!1},i.prototype.anErrorOccuredWhenGeneratingTheExpressionD=function(){return"An error occurred when generating the expression description. Check the cron expression syntax."},i.prototype.everyMinute=function(){return"every minute"},i.prototype.everyHour=function(){return"every hour"},i.prototype.atSpace=function(){return"At "},i.prototype.everyMinuteBetweenX0AndX1=function(){return"Every minute between %s and %s"},i.prototype.at=function(){return"At"},i.prototype.spaceAnd=function(){return" and"},i.prototype.everySecond=function(){return"every second"},i.prototype.everyX0Seconds=function(){return"every %s seconds"},i.prototype.secondsX0ThroughX1PastTheMinute=function(){return"seconds %s through %s past the minute"},i.prototype.atX0SecondsPastTheMinute=function(){return"at %s seconds past the minute"},i.prototype.everyX0Minutes=function(){return"every %s minutes"},i.prototype.minutesX0ThroughX1PastTheHour=function(){return"minutes %s through %s past the hour"},i.prototype.atX0MinutesPastTheHour=function(){return"at %s minutes past the hour"},i.prototype.everyX0Hours=function(){return"every %s hours"},i.prototype.betweenX0AndX1=function(){return"between %s and %s"},i.prototype.atX0=function(){return"at %s"},i.prototype.commaEveryDay=function(){return", every day"},i.prototype.commaEveryX0DaysOfTheWeek=function(){return", every %s days of the week"},i.prototype.commaX0ThroughX1=function(){return", %s through %s"},i.prototype.commaAndX0ThroughX1=function(){return", %s through %s"},i.prototype.first=function(){return"first"},i.prototype.second=function(){return"second"},i.prototype.third=function(){return"third"},i.prototype.fourth=function(){return"fourth"},i.prototype.fifth=function(){return"fifth"},i.prototype.commaOnThe=function(){return", on the "},i.prototype.spaceX0OfTheMonth=function(){return" %s of the month"},i.prototype.lastDay=function(){return"the last day"},i.prototype.commaOnTheLastX0OfTheMonth=function(){return", on the last %s of the month"},i.prototype.commaOnlyOnX0=function(){return", only on %s"},i.prototype.commaAndOnX0=function(){return", and on %s"},i.prototype.commaEveryX0Months=function(){return", every %s months"},i.prototype.commaOnlyInX0=function(){return", only in %s"},i.prototype.commaOnTheLastDayOfTheMonth=function(){return", on the last day of the month"},i.prototype.commaOnTheLastWeekdayOfTheMonth=function(){return", on the last weekday of the month"},i.prototype.commaDaysBeforeTheLastDayOfTheMonth=function(){return", %s days before the last day of the month"},i.prototype.firstWeekday=function(){return"first weekday"},i.prototype.weekdayNearestDayX0=function(){return"weekday nearest day %s"},i.prototype.commaOnTheX0OfTheMonth=function(){return", on the %s of the month"},i.prototype.commaEveryX0Days=function(){return", every %s days in a month"},i.prototype.commaBetweenDayX0AndX1OfTheMonth=function(){return", between day %s and %s of the month"},i.prototype.commaOnDayX0OfTheMonth=function(){return", on day %s of the month"},i.prototype.commaEveryHour=function(){return", every hour"},i.prototype.commaEveryX0Years=function(){return", every %s years"},i.prototype.commaStartingX0=function(){return", starting %s"},i.prototype.daysOfTheWeek=function(){return["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},i.prototype.monthsOfTheYear=function(){return["January","February","March","April","May","June","July","August","September","October","November","December"]},i.prototype.atReboot=function(){return"Run once, at startup"},i.prototype.onTheHour=function(){return"on the hour"},i})();p.en=v},515(g,p){Object.defineProperty(p,"__esModule",{value:!0});function v(y,l){if(!y)throw new Error(l)}var i=(function(){function y(){}return y.secondRange=function(l){for(var e=l.split(","),t=0;t<e.length;t++)if(!isNaN(parseInt(e[t],10))){var r=parseInt(e[t],10);v(r>=0&&r<=59,"seconds part must be >= 0 and <= 59")}},y.minuteRange=function(l){for(var e=l.split(","),t=0;t<e.length;t++)if(!isNaN(parseInt(e[t],10))){var r=parseInt(e[t],10);v(r>=0&&r<=59,"minutes part must be >= 0 and <= 59")}},y.hourRange=function(l){for(var e=l.split(","),t=0;t<e.length;t++)if(!isNaN(parseInt(e[t],10))){var r=parseInt(e[t],10);v(r>=0&&r<=23,"hours part must be >= 0 and <= 23")}},y.dayOfMonthRange=function(l){for(var e=l.split(","),t=0;t<e.length;t++)if(!isNaN(parseInt(e[t],10))){var r=parseInt(e[t],10);v(r>=1&&r<=31,"DOM part must be >= 1 and <= 31")}},y.monthRange=function(l,e){for(var t=l.split(","),r=0;r<t.length;r++)if(!isNaN(parseInt(t[r],10))){var n=parseInt(t[r],10);v(n>=1&&n<=12,e?"month part must be >= 0 and <= 11":"month part must be >= 1 and <= 12")}},y.dayOfWeekRange=function(l,e){for(var t=l.split(","),r=0;r<t.length;r++)if(!isNaN(parseInt(t[r],10))){var n=parseInt(t[r],10);v(n>=0&&n<=6,e?"DOW part must be >= 0 and <= 6":"DOW part must be >= 1 and <= 7")}},y})();p.default=i},823(g,p){Object.defineProperty(p,"__esModule",{value:!0}),p.StringUtilities=void 0;var v=(function(){function i(){}return i.format=function(y){for(var l=[],e=1;e<arguments.length;e++)l[e-1]=arguments[e];return y.replace(/%s/g,function(t){return l.shift()})},i.containsAny=function(y,l){return l.some(function(e){return y.indexOf(e)>-1})},i})();p.StringUtilities=v}},w={};function _(g){var p=w[g];if(p!==void 0)return p.exports;var v=w[g]={exports:{}};return D[g](v,v.exports,_),v.exports}var k={};return(()=>{var g=k;Object.defineProperty(g,"__esModule",{value:!0}),g.toString=void 0;var p=_(333),v=_(747);p.ExpressionDescriptor.initialize(new v.enLocaleLoader),g.default=p.ExpressionDescriptor;var i=p.ExpressionDescriptor.toString;g.toString=i})(),k})())})(M)),M.exports}var R=H();const F=U(R);export{F as c};
@@ -0,0 +1 @@
1
+ import{j as t,a0 as o}from"./index-BUr8321-.js";const n=()=>t.jsx(o,{});export{n as component};
@@ -1 +1 @@
1
- import{dc as i,fq as y,an as d,eJ as c,ag as g,cE as m,j as a,c7 as j,c8 as w,bm as N,gn as f,B as $,x as p,L as x,go as b,af as r}from"./index-Bfux0kHb.js";function o(e,t=""){return`${g}/api/${e}/deployments${t}`}const v=50;function S(){const{slug:e}=i();return y({queryKey:["deployments-feed",e],queryFn:async({pageParam:t})=>{const n=new URLSearchParams({limit:String(v)});t!==null&&n.set("before_id",String(t));const s=await d(o(e,`?${n.toString()}`),{credentials:"include"});return s.status===404?{items:[],has_more:!1}:(await c(s,"Failed to fetch deployments"),await s.json())},initialPageParam:null,getNextPageParam:t=>t.has_more?t.items[t.items.length-1]?.id:void 0,enabled:!!e,staleTime:15e3,retry:!1})}function T(e){const{slug:t}=i();return m({queryKey:["deployment-detail",t,e],queryFn:async()=>{const n=await d(o(t,`/${e}`),{credentials:"include"});return n.status===404?null:(await c(n,"Failed to fetch deployment"),await n.json())},enabled:!!t&&!!e,staleTime:15e3,retry:!1})}function q(e){const{slug:t}=i();return m({queryKey:["deployment-change-detail",t,e],queryFn:async()=>{const n=await d(o(t,`/changes/${e}`),{credentials:"include"});return n.status===404?null:(await c(n,"Failed to fetch change"),(await n.json()).change)},enabled:!!t&&!!e,staleTime:15e3,retry:!1})}function B(e){return e==="partial_failure"?a.jsx(r,{variant:"destructive",children:"Partial failure"}):e==="succeeded"?a.jsx(r,{variant:"secondary",children:"Succeeded"}):null}function D(e){switch(e){case"created":return a.jsx(r,{variant:"default",children:"Created"});case"updated":return a.jsx(r,{variant:"secondary",children:"Updated"});case"deleted":return a.jsx(r,{variant:"destructive",children:"Deleted"});default:return null}}function P(e){if(!e)return null;const t=[e.create?`${e.create} created`:null,e.update?`${e.update} updated`:null,e.delete?`${e.delete} deleted`:null].filter(n=>n!==null);return t.length>0?t.join(" · "):"no changes"}const h="flex items-start gap-3 px-3 py-2.5 transition-colors hover:bg-accent/50";function E({owner:e}){const t=S(),n=t.data?.pages.flatMap(s=>s.items)??[];return t.isLoading?a.jsx("div",{className:"max-w-3xl",children:a.jsx(j,{label:"deployments"})}):t.isError?a.jsx(w,{label:"deployments"}):n.length===0?a.jsx(N,{icon:f,title:"No deployments yet",description:"lobu apply runs and settings edits will appear here as an audit trail."}):a.jsxs("div",{className:"max-w-3xl space-y-3",children:[a.jsx("div",{className:"overflow-hidden rounded-lg border",children:n.map((s,l)=>{const u=l===n.length-1;return s.type==="deployment"?a.jsx(F,{item:s,owner:e,isLast:u},s.id):a.jsx(L,{item:s,owner:e,isLast:u},s.id)})}),t.hasNextPage?a.jsx($,{variant:"outline",size:"sm",className:"h-8 text-xs",disabled:t.isFetchingNextPage,onClick:()=>t.fetchNextPage(),children:t.isFetchingNextPage?"Loading...":"Load more"}):null]})}function F({item:e,owner:t,isLast:n}){const l=[P(e.counts),e.createdBy?`by ${e.createdBy}`:null,p(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(x,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:e.applyId??String(e.id)},className:`${h} ${n?"":"border-b"}`,children:[a.jsx(f,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("span",{className:"truncate text-sm font-medium",children:"Deployment"}),B(e.status),e.gitSha?a.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:e.gitSha.slice(0,7)}):null]}),a.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:l})]})]})}function L({item:e,owner:t,isLast:n}){const s=[e.actorSource?`via ${e.actorSource}`:null,e.createdBy?`by ${e.createdBy}`:null,p(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(x,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:`change-${e.id}`},className:`${h} ${n?"":"border-b"}`,children:[a.jsx(b,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsxs("span",{className:"truncate text-sm font-medium",children:[e.resourceKind??"config",e.resourceId?a.jsxs("span",{className:"text-muted-foreground",children:[" ",e.resourceId]}):null]}),D(e.op)]}),a.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:s})]})]})}export{E as D,q as a,D as c,B as d,T as u};
1
+ import{dc as i,fq as y,an as d,eJ as c,ag as g,cE as m,j as a,c7 as j,c8 as w,bm as N,gn as f,B as $,x as p,L as x,go as b,af as r}from"./index-BUr8321-.js";function o(e,t=""){return`${g}/api/${e}/deployments${t}`}const v=50;function S(){const{slug:e}=i();return y({queryKey:["deployments-feed",e],queryFn:async({pageParam:t})=>{const n=new URLSearchParams({limit:String(v)});t!==null&&n.set("before_id",String(t));const s=await d(o(e,`?${n.toString()}`),{credentials:"include"});return s.status===404?{items:[],has_more:!1}:(await c(s,"Failed to fetch deployments"),await s.json())},initialPageParam:null,getNextPageParam:t=>t.has_more?t.items[t.items.length-1]?.id:void 0,enabled:!!e,staleTime:15e3,retry:!1})}function T(e){const{slug:t}=i();return m({queryKey:["deployment-detail",t,e],queryFn:async()=>{const n=await d(o(t,`/${e}`),{credentials:"include"});return n.status===404?null:(await c(n,"Failed to fetch deployment"),await n.json())},enabled:!!t&&!!e,staleTime:15e3,retry:!1})}function q(e){const{slug:t}=i();return m({queryKey:["deployment-change-detail",t,e],queryFn:async()=>{const n=await d(o(t,`/changes/${e}`),{credentials:"include"});return n.status===404?null:(await c(n,"Failed to fetch change"),(await n.json()).change)},enabled:!!t&&!!e,staleTime:15e3,retry:!1})}function B(e){return e==="partial_failure"?a.jsx(r,{variant:"destructive",children:"Partial failure"}):e==="succeeded"?a.jsx(r,{variant:"secondary",children:"Succeeded"}):null}function D(e){switch(e){case"created":return a.jsx(r,{variant:"default",children:"Created"});case"updated":return a.jsx(r,{variant:"secondary",children:"Updated"});case"deleted":return a.jsx(r,{variant:"destructive",children:"Deleted"});default:return null}}function P(e){if(!e)return null;const t=[e.create?`${e.create} created`:null,e.update?`${e.update} updated`:null,e.delete?`${e.delete} deleted`:null].filter(n=>n!==null);return t.length>0?t.join(" · "):"no changes"}const h="flex items-start gap-3 px-3 py-2.5 transition-colors hover:bg-accent/50";function E({owner:e}){const t=S(),n=t.data?.pages.flatMap(s=>s.items)??[];return t.isLoading?a.jsx("div",{className:"max-w-3xl",children:a.jsx(j,{label:"deployments"})}):t.isError?a.jsx(w,{label:"deployments"}):n.length===0?a.jsx(N,{icon:f,title:"No deployments yet",description:"lobu apply runs and settings edits will appear here as an audit trail."}):a.jsxs("div",{className:"max-w-3xl space-y-3",children:[a.jsx("div",{className:"overflow-hidden rounded-lg border",children:n.map((s,l)=>{const u=l===n.length-1;return s.type==="deployment"?a.jsx(F,{item:s,owner:e,isLast:u},s.id):a.jsx(L,{item:s,owner:e,isLast:u},s.id)})}),t.hasNextPage?a.jsx($,{variant:"outline",size:"sm",className:"h-8 text-xs",disabled:t.isFetchingNextPage,onClick:()=>t.fetchNextPage(),children:t.isFetchingNextPage?"Loading...":"Load more"}):null]})}function F({item:e,owner:t,isLast:n}){const l=[P(e.counts),e.createdBy?`by ${e.createdBy}`:null,p(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(x,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:e.applyId??String(e.id)},className:`${h} ${n?"":"border-b"}`,children:[a.jsx(f,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx("span",{className:"truncate text-sm font-medium",children:"Deployment"}),B(e.status),e.gitSha?a.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:e.gitSha.slice(0,7)}):null]}),a.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:l})]})]})}function L({item:e,owner:t,isLast:n}){const s=[e.actorSource?`via ${e.actorSource}`:null,e.createdBy?`by ${e.createdBy}`:null,p(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(x,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:`change-${e.id}`},className:`${h} ${n?"":"border-b"}`,children:[a.jsx(b,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),a.jsxs("div",{className:"min-w-0 flex-1",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsxs("span",{className:"truncate text-sm font-medium",children:[e.resourceKind??"config",e.resourceId?a.jsxs("span",{className:"text-muted-foreground",children:[" ",e.resourceId]}):null]}),D(e.op)]}),a.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:s})]})]})}export{E as D,q as a,D as c,B as d,T as u};
@@ -0,0 +1 @@
1
+ import{ae as ge,Y as xe,r as n,j as e,ab as ve,B as A,af as X,ag as ne}from"./index-BUr8321-.js";import{s as ye,g as we,u as je,a as be,b as ke,A as Ce,W as Ne}from"./oauth-workspace-access-D9GmiMfK.js";import{C as Z,a as ee,b as se,d as re,c as te}from"./card-DeFQuU_J.js";function W(r){return r.trim().toUpperCase()}async function Se(r){const c=await fetch(`${ne}/oauth/device/info?user_code=${encodeURIComponent(r)}`,{credentials:"include"}),R=await c.json().catch(()=>null);return{response:c,data:R}}function P(r,c){return typeof r?.error_description=="string"&&r.error_description||typeof r?.error=="string"&&r.error||c}function Ee(){const r=ge.useSearch(),{session:c,isReady:R}=xe(),j=!R,[T,oe]=n.useState(r.user_code||""),[o,m]=n.useState(null),[O,i]=n.useState(null),[a,ce]=n.useState(null),[M,_]=n.useState(null),[E,L]=n.useState(null),[q,z]=n.useState(!1),f=n.useRef(0),x=r.return_to,I=x?"app":"terminal",ie=!!r.user_code,b=W(T),l=M?.code===b?M:null,p=l!==null,v=l?.scopes??[],ae=n.useMemo(()=>ye(v,E),[E,v]),F=v.some(s=>s.startsWith("mcp:")),k=v.includes("device_worker:run"),le=v.includes("connections:token"),B=k||le,C=we(l?.resource),y=p&&F&&!C,V=l?.multiWorkspaceGrantsEnabled===!0,{orgList:$,workspaceAccess:de,setWorkspaceAccess:ue,selectedOrgIds:Y,toggleSelectedOrgId:pe,resetWorkspaceSelection:he,personalOrgId:me,orgsLoading:D,orgsError:N,retryOrgs:G,workspaceSelectionReady:fe}=je({requirePersonal:y&&k,allowMultiple:V}),g=$.find(s=>s.id===me)??null,S=p&&k&&!C,H=y?fe:!S||!D&&!N&&g!==null,U=n.useCallback(async s=>{const d=++f.current;m("verify"),i(null),z(!1);try{const{response:h,data:t}=await Se(s);if(d!==f.current)return;if(h.status===401){const w=new URL("/auth/login",window.location.origin);w.searchParams.set("callbackUrl",window.location.href),window.location.href=w.toString();return}if(!h.ok||!t)throw new Error(P(t,"Failed to verify device authorization code"));const u=Array.isArray(t.scopes)?t.scopes:[];_({code:s,clientName:t.client_name??null,scopes:u,resource:typeof t.resource=="string"?t.resource:null,multiWorkspaceGrantsEnabled:t.multi_workspace_grants_enabled===!0}),L(be(u))}catch(h){if(d!==f.current)return;_(null),i(h instanceof Error?h.message:"Unexpected error")}finally{d===f.current&&m(null)}},[]);ke(!!c,j),n.useEffect(()=>{if(!(j||!c||!r.user_code))return U(W(r.user_code)),()=>{f.current+=1}},[c,j,r.user_code,U]);const J=async s=>{const d=b;if(!d){i(`Please enter the code shown in your ${I}.`);return}if(!p){i("Verify the device code before approving or denying access.");return}if(s&&B&&!q){i("Confirm that you initiated this request and that the device code matches.");return}if(s&&!H){i(N?"Workspaces could not be loaded. Retry before approving.":S&&!g?"Your personal workspace is required before this device can be approved.":"Choose at least one workspace before approving.");return}const h=l?.clientName??null;m(s?"approve":"deny"),i(null);try{const t=await fetch(`${ne}/oauth/device/approve`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({user_code:d,approved:s,...s?{scope:ae.join(" ")}:{},...s&&y?{workspace_access:de,organization_ids:Y}:{},...s&&S&&g?{organization_id:g.id}:{}})}),u=await t.json().catch(()=>null);if(t.status===401){const Q=new URL("/auth/login",window.location.origin);Q.searchParams.set("callbackUrl",window.location.href),window.location.href=Q.toString();return}if(!t.ok)throw new Error(P(u,"Failed to process device authorization"));const w=s?"approved":"denied";if(u?.status!==w)throw new Error(P(u,s?"The server did not confirm this approval. The device is still waiting — try again.":"The server did not confirm this denial. Try again."));const K=typeof u.user_code=="string"?W(u.user_code):null;if(K!==null&&K!==d)throw new Error("The server confirmed a different device code. Re-check the code shown on your device.");m(null),ce({outcome:w,code:d,clientName:h})}catch(t){m(null),i(t instanceof Error?t.message:"Unexpected error")}};return n.useEffect(()=>{if(a?.outcome!=="approved"||!x)return;const s=window.setTimeout(()=>{window.location.href=x},600);return()=>window.clearTimeout(s)},[a,x]),j||!c?e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking authentication..."})}):a?e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsxs(Z,{className:"w-full max-w-lg",role:"status","aria-live":"polite",children:[e.jsxs(ee,{children:[e.jsx(se,{children:a.outcome==="approved"?ie?"Access Authorized":"Device Authorized":"Authorization Denied"}),e.jsx(re,{children:a.outcome==="approved"?x?"Returning you to the app...":"You can close this tab and return to your terminal.":"The device was not authorized. You can close this tab."})]}),e.jsx(te,{className:"text-sm",children:e.jsxs("dl",{className:"space-y-1",children:[e.jsx("dt",{className:"text-muted-foreground",children:a.outcome==="approved"?"Approved code":"Denied code"}),e.jsx("dd",{className:"font-mono text-base tracking-widest text-foreground",children:a.code}),a.clientName?e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted-foreground",children:"Requested by"}),e.jsx("dd",{className:"text-foreground",children:a.clientName})]}):null]})})]})}):e.jsx("main",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center p-4",children:e.jsxs(Z,{className:"w-full max-w-lg",children:[e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx("h1",{children:p?"Authorize application":"Connect a device"})}),e.jsx(re,{children:p?"Review the application, access level, and workspaces.":`Enter the code shown in your ${I}.`})]}),e.jsxs(te,{className:"space-y-5","aria-busy":o!==null,children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"user-code",className:"text-sm font-medium",children:"Device code"}),e.jsx(ve,{id:"user-code",value:T,disabled:o==="approve"||o==="deny",onChange:s=>{f.current+=1,oe(s.target.value.toUpperCase()),_(null),L(null),he(),z(!1),m(null),i(null)},placeholder:"ABCD-1234",className:"font-mono text-center text-lg tracking-widest",maxLength:9,autoFocus:!r.user_code})]}),l&&e.jsx(Ce,{idPrefix:"oauth-device",clientName:l.clientName,requestedScopes:l.scopes,accessLevel:E,onAccessLevelChange:L,sensitiveScopesAcknowledged:q,onSensitiveScopesAcknowledgedChange:z,disabled:o!==null}),y&&e.jsx(Ne,{idPrefix:"oauth-device",allowMultiple:V,orgList:$,selectedOrgIds:Y,onWorkspaceAccessChange:ue,onSelectedOrgChange:pe,orgsLoading:D,orgsError:N,onRetry:G,disabled:o!==null,personalRequired:k}),p&&F&&C&&e.jsxs("section",{className:"rounded-md border border-primary/20 bg-primary/5 p-3 text-sm space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:["Workspace access: only ",C]}),e.jsx("p",{className:"text-muted-foreground",children:"This request is fixed to the workspace in the MCP resource URL."})]}),S&&!y&&e.jsxs("section",{className:"rounded-md border border-primary/20 bg-primary/5 p-3 text-sm space-y-2",children:[e.jsx("p",{className:"font-medium text-foreground",children:"Device home"}),D?e.jsx("p",{role:"status","aria-live":"polite",className:"text-muted-foreground",children:"Loading your personal workspace..."}):N?e.jsxs("div",{role:"alert",className:"space-y-2 text-destructive",children:[e.jsx("p",{children:"Workspaces could not be loaded. Approval is unavailable until they load."}),e.jsx(A,{type:"button",variant:"outline",size:"sm",onClick:G,children:"Retry"})]}):g?e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{children:g.name}),e.jsx(X,{variant:"outline",children:"Personal"}),e.jsx(X,{variant:"secondary",children:"Required"})]}),e.jsx("p",{className:"text-muted-foreground",children:"Device data stays in your personal workspace."})]}):e.jsx("p",{role:"alert",className:"text-destructive",children:"A personal workspace is required to authorize this device."})]}),O&&e.jsx("p",{role:"alert",className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:O}),e.jsx("div",{className:"flex items-center justify-end gap-3",children:p?e.jsxs(e.Fragment,{children:[e.jsx(A,{type:"button",variant:"outline",onClick:()=>J(!1),disabled:o!==null,children:o==="deny"?"Denying...":"Deny"}),e.jsx(A,{type:"button",onClick:()=>J(!0),disabled:o!==null||!H||B&&!q,children:o==="approve"?"Approving...":"Approve"})]}):e.jsx(A,{type:"button",onClick:()=>U(b),disabled:o!==null||!b,children:o==="verify"?"Verifying...":"Continue"})})]})]})})}export{Ee as component};
@@ -1 +1 @@
1
- import{j as e,cr as C,n as w,h9 as b,r as x,s as k,bm as F,ha as v,B as u,hb as L,x as A,bw as S,aj as I,aS as P,hc as y,aD as R,hd as E,he as $,fi as _,L as O,P as z,b as B,hf as T,hg as D,J as K,hh as V,fk as q}from"./index-Bfux0kHb.js";import{a as M,R as H}from"./runs-panel-wkV1aGD9.js";import{S as J,g as U,c as N,b as X,d as G}from"./runs-table-DzSWYkaf.js";function ae({formRows:s=5}){return e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsx(M,{}),e.jsx(C,{rows:s})]})}function Q(s,a){const n=s?.display_name;return typeof n=="string"&&n.trim()?n:a?.trim()||"Folder"}function W({connectionId:s}){const{data:a=[],isLoading:n}=w(s),o=b(),[c,r]=x.useState(null),i=a.filter(t=>t.config?.folder_id!=null),d=()=>{window.location.href=y("feeds/add"),R("Opening Lobu…",{description:"Choose a folder in the Lobu app. It appears here after the next sync."})},l=t=>{const m=t.config?.folder_id;typeof m=="string"&&(window.location.href=y(`feeds/remove?folder_id=${encodeURIComponent(m)}`)),o.mutate(t.id),r(null)};return n?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{size:"lg"})}):i.length===0?e.jsx(F,{icon:v,title:"No folders yet",description:"Add a local folder for Lobu to read text files from.",actionLabel:"Add folder",onAction:d}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Folders"}),e.jsxs(u,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(L,{className:"mr-2 h-4 w-4"}),"Add folder"]})]}),e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:I(P,"flex items-center justify-between gap-3 px-3 py-2"),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:Q(t.config,t.display_name)}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[t.event_count>0?`${t.event_count} document${t.event_count===1?"":"s"}`:"No documents yet",t.last_sync_at?` · synced ${A(t.last_sync_at)}`:""]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(J,{status:U(t.status),children:t.status}),c===t.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(u,{variant:"destructive",size:"sm",onClick:()=>l(t),children:"Remove"}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>r(null),children:"Cancel"})]}):e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive","aria-label":"Remove folder",onClick:()=>r(t.id),children:e.jsx(S,{className:"h-4 w-4"})})]})]},t.id))})]})}function ne({connection:s,connectorDef:a,ownerSlug:n,openSettings:o=!1,authResult:c,showActivity:r=!0,embedded:i=!1}){const[d,l]=x.useState(o);x.useEffect(()=>{o&&l(!0)},[o]);const t=s.id,m=s.connector_key,h=s.facets?.chat??!1,p=h?"Channels":"Feeds",f=s.has_operations===!0,j=s.feed_count>0||N(a),g=e.jsx(D,{connection:s,connectorDef:a,ownerSlug:n});return e.jsxs("div",{className:"space-y-6",children:[c&&e.jsx(E,{result:c}),s.auth_profile_kind==="oauth_account"&&e.jsx($,{connection:s,connectorDef:a,onReview:()=>{l(!0),requestAnimationFrame(()=>document.getElementById("connection-auth")?.scrollIntoView({block:"nearest"}))}}),m==="local.directory"&&e.jsx(W,{connectionId:t}),(j||f)&&e.jsxs("div",{className:i?"space-y-6":"grid grid-cols-1 items-start gap-3 sm:grid-cols-2",children:[j&&(i?e.jsx(_,{title:p,count:s.feed_count===1?"1 source":`${s.feed_count} sources`,action:N(a)?e.jsx(u,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(O,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:n,connectorKey:m,connectionId:String(t)},search:{addFeed:!0},children:[e.jsx(z,{className:"h-3.5 w-3.5"}),h?"Add channel":"Add source"]})}):null,children:e.jsx(X,{connection:s,ownerSlug:n,connectorKey:m,connectorDef:a})}):e.jsx(G,{connection:s,ownerSlug:n,title:p})),f&&(i?e.jsx(B,{connection:s}):e.jsx(Y,{connection:s,ownerSlug:n}))]}),i?e.jsx(T,{title:"Connection settings",summary:"name, visibility, credentials, remove",open:d,onOpenChange:l,children:g}):g,r&&!h&&e.jsx(_,{title:"Recent activity",children:e.jsx(H,{scope:{connectionId:t},ownerSlug:n})})]})}function Y({connection:s,ownerSlug:a}){const n=K(),{data:o=[],isLoading:c,isError:r}=V(s.id),i=o.filter(l=>l.readiness==="scope_upgrade_required").length,d=c?"Loading actions…":r?"Could not load actions — open to retry":`${o.length} actions${i?` · ${i} need additional provider access`:" · permissions and approval policy"}`;return e.jsx(q,{title:"Actions",summary:d,onOpen:()=>n?.open({href:"",title:"Actions",connectorPanel:{section:"actions",connectionId:s.id,connectorKey:s.connector_key,organizationId:s.organization_id,ownerSlug:a}})})}const Z=new Set(["Device was removed","Device was moved to another workspace"]);function ie(s){const a=s.error_message??null;return!a||!Z.has(a)?a:!!s.device_worker_id&&(s.device_last_seen_at!=null||s.device_worker_handle!=null||s.device_label!=null)?null:a}export{ne as C,ae as R,ie as c};
1
+ import{j as e,cr as C,n as w,h9 as b,r as x,s as k,bm as F,ha as v,B as u,hb as L,x as A,bw as S,aj as I,aS as P,hc as y,aD as R,hd as E,he as $,fi as _,L as O,P as z,b as B,hf as T,hg as D,J as K,hh as V,fk as q}from"./index-BUr8321-.js";import{a as M,R as H}from"./runs-panel-DsdESupx.js";import{S as J,g as U,c as N,b as X,d as G}from"./runs-table-B7jKuILd.js";function ae({formRows:s=5}){return e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsx(M,{}),e.jsx(C,{rows:s})]})}function Q(s,a){const n=s?.display_name;return typeof n=="string"&&n.trim()?n:a?.trim()||"Folder"}function W({connectionId:s}){const{data:a=[],isLoading:n}=w(s),o=b(),[c,r]=x.useState(null),i=a.filter(t=>t.config?.folder_id!=null),d=()=>{window.location.href=y("feeds/add"),R("Opening Lobu…",{description:"Choose a folder in the Lobu app. It appears here after the next sync."})},l=t=>{const m=t.config?.folder_id;typeof m=="string"&&(window.location.href=y(`feeds/remove?folder_id=${encodeURIComponent(m)}`)),o.mutate(t.id),r(null)};return n?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{size:"lg"})}):i.length===0?e.jsx(F,{icon:v,title:"No folders yet",description:"Add a local folder for Lobu to read text files from.",actionLabel:"Add folder",onAction:d}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Folders"}),e.jsxs(u,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(L,{className:"mr-2 h-4 w-4"}),"Add folder"]})]}),e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:I(P,"flex items-center justify-between gap-3 px-3 py-2"),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:Q(t.config,t.display_name)}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[t.event_count>0?`${t.event_count} document${t.event_count===1?"":"s"}`:"No documents yet",t.last_sync_at?` · synced ${A(t.last_sync_at)}`:""]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(J,{status:U(t.status),children:t.status}),c===t.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(u,{variant:"destructive",size:"sm",onClick:()=>l(t),children:"Remove"}),e.jsx(u,{variant:"ghost",size:"sm",onClick:()=>r(null),children:"Cancel"})]}):e.jsx(u,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive","aria-label":"Remove folder",onClick:()=>r(t.id),children:e.jsx(S,{className:"h-4 w-4"})})]})]},t.id))})]})}function ne({connection:s,connectorDef:a,ownerSlug:n,openSettings:o=!1,authResult:c,showActivity:r=!0,embedded:i=!1}){const[d,l]=x.useState(o);x.useEffect(()=>{o&&l(!0)},[o]);const t=s.id,m=s.connector_key,h=s.facets?.chat??!1,p=h?"Channels":"Feeds",f=s.has_operations===!0,j=s.feed_count>0||N(a),g=e.jsx(D,{connection:s,connectorDef:a,ownerSlug:n});return e.jsxs("div",{className:"space-y-6",children:[c&&e.jsx(E,{result:c}),s.auth_profile_kind==="oauth_account"&&e.jsx($,{connection:s,connectorDef:a,onReview:()=>{l(!0),requestAnimationFrame(()=>document.getElementById("connection-auth")?.scrollIntoView({block:"nearest"}))}}),m==="local.directory"&&e.jsx(W,{connectionId:t}),(j||f)&&e.jsxs("div",{className:i?"space-y-6":"grid grid-cols-1 items-start gap-3 sm:grid-cols-2",children:[j&&(i?e.jsx(_,{title:p,count:s.feed_count===1?"1 source":`${s.feed_count} sources`,action:N(a)?e.jsx(u,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(O,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:n,connectorKey:m,connectionId:String(t)},search:{addFeed:!0},children:[e.jsx(z,{className:"h-3.5 w-3.5"}),h?"Add channel":"Add source"]})}):null,children:e.jsx(X,{connection:s,ownerSlug:n,connectorKey:m,connectorDef:a})}):e.jsx(G,{connection:s,ownerSlug:n,title:p})),f&&(i?e.jsx(B,{connection:s}):e.jsx(Y,{connection:s,ownerSlug:n}))]}),i?e.jsx(T,{title:"Connection settings",summary:"name, visibility, credentials, remove",open:d,onOpenChange:l,children:g}):g,r&&!h&&e.jsx(_,{title:"Recent activity",children:e.jsx(H,{scope:{connectionId:t},ownerSlug:n})})]})}function Y({connection:s,ownerSlug:a}){const n=K(),{data:o=[],isLoading:c,isError:r}=V(s.id),i=o.filter(l=>l.readiness==="scope_upgrade_required").length,d=c?"Loading actions…":r?"Could not load actions — open to retry":`${o.length} actions${i?` · ${i} need additional provider access`:" · permissions and approval policy"}`;return e.jsx(q,{title:"Actions",summary:d,onOpen:()=>n?.open({href:"",title:"Actions",connectorPanel:{section:"actions",connectionId:s.id,connectorKey:s.connector_key,organizationId:s.organization_id,ownerSlug:a}})})}const Z=new Set(["Device was removed","Device was moved to another workspace"]);function ie(s){const a=s.error_message??null;return!a||!Z.has(a)?a:!!s.device_worker_id&&(s.device_last_seen_at!=null||s.device_worker_handle!=null||s.device_label!=null)?null:a}export{ne as C,ae as R,ie as c};
@@ -1 +1 @@
1
- import{d8 as u,fj as l,bq as f}from"./index-Bfux0kHb.js";function p(n){return l(n)&&n.required_capability!=="os.files"}const m={data:!1,chat:!1,actions:!1,audience:!1,inference:!1,runtime:!0};function d(n){return n==="macos"?"macOS":n==="ios"?"iOS":n==="chrome-extension"?"Chrome":n??"Unknown platform"}function y(n,c,o){const s=new Map(c.map(e=>[e.connector_key,e]));return n.map(e=>{const i={...m};for(const r of e.connectors){if(r.organization_slug!==o)continue;const a=s.get(r.connector_key);if(a?.connections.some(t=>t.id===r.connection_id))for(const t of Object.keys(i))i[t]||=a.facets[t]}return{device:e,facets:i,connector:{key:`device-row:${e.id}`,name:u(e),description:null,version:"",auth_schema:null,feeds_schema:null,actions_schema:null,options_schema:null,status:e.online?"active":"inactive",login_enabled:!1,installed:!0}}})}function b(n){const c=d(f(n)),o=n.connector_count,s=`${o} ${o===1?"connector":"connectors"}`;return[c,s,n.online?"online":"offline"].join(" · ")}export{y as b,p as c,b as d};
1
+ import{d8 as u,fj as l,bq as f}from"./index-BUr8321-.js";function p(n){return l(n)&&n.required_capability!=="os.files"}const m={data:!1,chat:!1,actions:!1,audience:!1,inference:!1,runtime:!0};function d(n){return n==="macos"?"macOS":n==="ios"?"iOS":n==="chrome-extension"?"Chrome":n??"Unknown platform"}function y(n,c,o){const s=new Map(c.map(e=>[e.connector_key,e]));return n.map(e=>{const i={...m};for(const r of e.connectors){if(r.organization_slug!==o)continue;const a=s.get(r.connector_key);if(a?.connections.some(t=>t.id===r.connection_id))for(const t of Object.keys(i))i[t]||=a.facets[t]}return{device:e,facets:i,connector:{key:`device-row:${e.id}`,name:u(e),description:null,version:"",auth_schema:null,feeds_schema:null,actions_schema:null,options_schema:null,status:e.online?"active":"inactive",login_enabled:!1,installed:!0}}})}function b(n){const c=d(f(n)),o=n.connector_count,s=`${o} ${o===1?"connector":"connectors"}`;return[c,s,n.online?"online":"offline"].join(" · ")}export{y as b,p as c,b as d};