@lobu/runtime-server 23.0.0 → 24.0.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.
- package/dist/catalogs/connectors.json +70 -6
- package/dist/catalogs/skills.json +1 -1
- package/dist/component.json +1 -1
- package/dist/connectors/README.md +1 -1
- package/dist/connectors/linkedin-inbox-adapter.js +4 -7
- package/dist/connectors/linkedin.ts +53 -34
- package/dist/connectors/reddit.ts +92 -20
- package/dist/connectors/slack.ts +1 -0
- package/dist/connectors/whatsapp-web-adapter.js +41 -11
- package/dist/connectors/whatsapp-web-helpers.ts +1 -1
- package/dist/connectors/whatsapp_web.ts +2 -2
- package/dist/connectors/x-identity.ts +5 -3
- package/dist/db/migrations/20261019120000_retire_identities_of_deleted_entities.sql +21 -0
- package/dist/db/migrations/20261020120000_entities_live_metadata_domain.sql +66 -0
- package/dist/db/migrations/20261020130000_agents_starters.sql +14 -0
- package/dist/db/migrations/20261020140000_view_attachments_by_page.sql +71 -0
- package/dist/dependencies.bun.lock +63 -60
- package/dist/guest.bundle.js +362 -300
- package/dist/owletto/dist/assets/_-CC8cTmRg.js +3 -0
- package/dist/owletto/dist/assets/_-ksFp4zVf.js +2 -0
- package/dist/owletto/dist/assets/_agentId-DWUFSrVp.js +2 -0
- package/dist/owletto/dist/assets/_agentId-MENLoohA.js +2 -0
- package/dist/owletto/dist/assets/_automationId-BnHqdXOC.js +2 -0
- package/dist/owletto/dist/assets/_connectorKey._connectionId-CefXIqy2.js +2 -0
- package/dist/owletto/dist/assets/_connectorKey.index-C1QPGf9E.js +2 -0
- package/dist/owletto/dist/assets/_conversationId-DinuPCUp.js +2 -0
- package/dist/owletto/dist/assets/{_deploymentId-BuUzGtVL.js → _deploymentId-BeyzVjRm.js} +2 -2
- package/dist/owletto/dist/assets/_eventId-3L_qeL_l.js +2 -0
- package/dist/owletto/dist/assets/_name-Dgedji78.js +2 -0
- package/dist/owletto/dist/assets/_owner-DbrKma4e.js +3 -0
- package/dist/owletto/dist/assets/_shape-DtVfRFz_.js +2 -0
- package/dist/owletto/dist/assets/_skillKey-CqLHzm7L.js +2 -0
- package/dist/owletto/dist/assets/_slug-ndDr_CUg.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-3CH5w8mr.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-DHQY9A8u.js +2 -0
- package/dist/owletto/dist/assets/{accept-invitation-w17IFTtf.js → accept-invitation-CRKbM2Xy.js} +2 -2
- package/dist/owletto/dist/assets/activity-route-view-CFLNukhD.js +2 -0
- package/dist/owletto/dist/assets/{agent-card-controls-mnTN2AZt.js → agent-card-controls-Be1Okb2C.js} +2 -2
- package/dist/owletto/dist/assets/{agent-client-setup-list-Bg3hBfUV.js → agent-client-setup-list-BA8dU_C6.js} +2 -2
- package/dist/owletto/dist/assets/agent-connect-pages-CAV-yXus.js +2 -0
- package/dist/owletto/dist/assets/agent-editor-form-Bi6WvYX-.js +2 -0
- package/dist/owletto/dist/assets/{agent-guardrails-route-BOrCXcAl.js → agent-guardrails-route-DMOjG1D4.js} +2 -2
- package/dist/owletto/dist/assets/{agent-loading-shells-Dqcvky-k.js → agent-loading-shells-De_2d8Lr.js} +2 -2
- package/dist/owletto/dist/assets/{agent-permissions-matrix-BOo_4r_4.js → agent-permissions-matrix-gZWl6mAe.js} +2 -2
- package/dist/owletto/dist/assets/{agent-skill-context-CCdvtlmH.js → agent-skill-context-JLaTamGR.js} +2 -2
- package/dist/owletto/dist/assets/{agent-skills-route-BUxIswuq.js → agent-skills-route-DcK41PWj.js} +2 -2
- package/dist/owletto/dist/assets/agent-subpage-shell-BBJoyTuC.js +2 -0
- package/dist/owletto/dist/assets/agent-thread-Buz3naVF.js +6 -0
- package/dist/owletto/dist/assets/agents-C-ReckCa.js +2 -0
- package/dist/owletto/dist/assets/agents-workbench-CqaKGggb.js +2 -0
- package/dist/owletto/dist/assets/app._appId-Cl1fTuIt.js +2 -0
- package/dist/owletto/dist/assets/automation-detail-content-BMLL4lxO.js +2 -0
- package/dist/owletto/dist/assets/automations-C-ReckCa.js +2 -0
- package/dist/owletto/dist/assets/callback-DTKKsfkz.js +2 -0
- package/dist/owletto/dist/assets/{card-Djgp00r_.js → card-yU0TmNRH.js} +2 -2
- package/dist/owletto/dist/assets/{claim-BYUZnyMp.js → claim-DJfTvlT2.js} +2 -2
- package/dist/owletto/dist/assets/client-rows--FrZfJol.js +2 -0
- package/dist/owletto/dist/assets/{clients-D3Zbjxin.js → clients-L4K1UT8c.js} +2 -2
- package/dist/owletto/dist/assets/{code-editor-DHeyRGZI.js → code-editor-U54Gwjit.js} +2 -2
- package/dist/owletto/dist/assets/connect-4zqtnDHb.js +2 -0
- package/dist/owletto/dist/assets/connect._clientId-Dj0SqgbE.js +2 -0
- package/dist/owletto/dist/assets/connected._clientId-sgtocSvf.js +2 -0
- package/dist/owletto/dist/assets/connected._clientId.activity-DTpSW1Xy.js +2 -0
- package/dist/owletto/dist/assets/connected._clientId.index-h9X5H1x8.js +2 -0
- package/dist/owletto/dist/assets/{connection-C3XXFEqh.js → connection-ByvKkyFm.js} +2 -2
- package/dist/owletto/dist/assets/{connection-feed-detail-CIJJLDP8.js → connection-feed-detail-DWM9lTao.js} +2 -2
- package/dist/owletto/dist/assets/connections-browser-CEwYrYqt.js +2 -0
- package/dist/owletto/dist/assets/{connector-provenance-8-d8hl10.js → connector-provenance-BocTm__v.js} +2 -2
- package/dist/owletto/dist/assets/connector-scope-lists-OYDOydtz.js +2 -0
- package/dist/owletto/dist/assets/connectors-CyZpcE5f.js +2 -0
- package/dist/owletto/dist/assets/{consent-CdSvVCgx.js → consent-DdfINrVp.js} +2 -2
- package/dist/owletto/dist/assets/{conversations-table-BdXoZAfc.js → conversations-table-BSznfdYt.js} +2 -2
- package/dist/owletto/dist/assets/{core.esm-CYvgWCuv.js → core.esm-Dr7tcIB-.js} +2 -2
- package/dist/owletto/dist/assets/create-CBGwASon.js +2 -0
- package/dist/owletto/dist/assets/create-Cf5hp6Z8.js +2 -0
- package/dist/owletto/dist/assets/create-CwThQtd3.js +2 -0
- package/dist/owletto/dist/assets/{create-automation-form-CtSSeYj3.js → create-automation-form-9T5WnoUs.js} +3 -3
- package/dist/owletto/dist/assets/create._connectorKey-sNHQHNpg.js +2 -0
- package/dist/owletto/dist/assets/{cronstrue-n4qGUraE.js → cronstrue-BWFEyy_P.js} +2 -2
- package/dist/owletto/dist/assets/deployments-DHh9dyzv.js +2 -0
- package/dist/owletto/dist/assets/{deployments-body-BMp7UsMo.js → deployments-body-2xKS8gRo.js} +2 -2
- package/dist/owletto/dist/assets/{deployments-RvUdVkj3.js → deployments-wG_8QzOF.js} +2 -2
- package/dist/owletto/dist/assets/{device-CPU6CjkJ.js → device-6z-xgsoW.js} +2 -2
- package/dist/owletto/dist/assets/device-pin-tombstone-Cwq88RMU.js +2 -0
- package/dist/owletto/dist/assets/device._deviceId-BDerBfD9.js +2 -0
- package/dist/owletto/dist/assets/entity-avatar-Cc1CuI-0.js +2 -0
- package/dist/owletto/dist/assets/entity-options-DHdMC1Lx.js +2 -0
- package/dist/owletto/dist/assets/entity-page--OkXmlNP.js +2 -0
- package/dist/owletto/dist/assets/entity-type-page-89RoK_-P.js +2 -0
- package/dist/owletto/dist/assets/event-detail-D4YZRtrA.js +2 -0
- package/dist/owletto/dist/assets/events-feed-DsrkV2ix.js +2 -0
- package/dist/owletto/dist/assets/filter-editors-B1_QUpg_.js +2 -0
- package/dist/owletto/dist/assets/{full-page-spinner-DqpH99np.js → full-page-spinner-Cqih-8IW.js} +2 -2
- package/dist/owletto/dist/assets/guardrails-B8Rs1be3.js +2 -0
- package/dist/owletto/dist/assets/identity-B0nH4yiC.js +2 -0
- package/dist/owletto/dist/assets/index-4TSkcsth.js +2 -0
- package/dist/owletto/dist/assets/index-BSH07yVD.css +1 -0
- package/dist/owletto/dist/assets/index-BgkhXElB.js +2 -0
- package/dist/owletto/dist/assets/index-CoW4Bz3w.js +2 -0
- package/dist/owletto/dist/assets/index-Codw-Qqi.js +2 -0
- package/dist/owletto/dist/assets/{index-BQVliQW1.js → index-DAOyXG1X.js} +2 -2
- package/dist/owletto/dist/assets/{index-B9uPN6FC.js → index-DKPwCasf.js} +2 -2
- package/dist/owletto/dist/assets/index-DMyXd3bJ.js +2 -0
- package/dist/owletto/dist/assets/index-DYCqXaMf.js +7950 -0
- package/dist/owletto/dist/assets/index-DYYZLcJ0.js +2 -0
- package/dist/owletto/dist/assets/index-DYzWV5_z.js +2 -0
- package/dist/owletto/dist/assets/index-Da6CrGEu.js +2 -0
- package/dist/owletto/dist/assets/{index-Hio-HRfo.js → index-DfyDUpuI.js} +2 -2
- package/dist/owletto/dist/assets/index-DneshLbf.js +2 -0
- package/dist/owletto/dist/assets/index-TgRS2v_F.js +2 -0
- package/dist/owletto/dist/assets/{index-ICgKp3YK.js → index-ZNlrDc_f.js} +2 -2
- package/dist/owletto/dist/assets/{json-diff-DBoag_OS.js → json-diff-DFvYINBT.js} +3 -3
- package/dist/owletto/dist/assets/{list-skeleton-C_GuoxAH.js → list-skeleton-DFsEqLU1.js} +2 -2
- package/dist/owletto/dist/assets/login-DO0j-AYr.js +2 -0
- package/dist/owletto/dist/assets/{logout-CLGgeZB7.js → logout-BmNwoAf7.js} +2 -2
- package/dist/owletto/dist/assets/member-scope-gate-B2LrMWBU.js +2 -0
- package/dist/owletto/dist/assets/memory-browse-page-Cjpl8EbB.js +103 -0
- package/dist/owletto/dist/assets/{model-selector-dAbDgJvx.js → model-selector-TQcA93xm.js} +2 -2
- package/dist/owletto/dist/assets/models-D7aED5Sa.js +2 -0
- package/dist/owletto/dist/assets/new-BMrFy5Qa.js +2 -0
- package/dist/owletto/dist/assets/{new-BkdULx2r.js → new-ByBhteWA.js} +2 -2
- package/dist/owletto/dist/assets/new-DWp3deoW.js +2 -0
- package/dist/owletto/dist/assets/{oauth-workspace-access-BxsjwgdH.js → oauth-workspace-access-D_5uESuz.js} +2 -2
- package/dist/owletto/dist/assets/{organization-gxGeDjIV.js → organization-DTFoYP4V.js} +2 -2
- package/dist/owletto/dist/assets/peek-pane-content-DF5iGC3c.js +2 -0
- package/dist/owletto/dist/assets/{permissions-aPHaKLec.js → permissions-C_auqxfP.js} +2 -2
- package/dist/owletto/dist/assets/proposal-review-shell-DsNiavG_.js +2 -0
- package/dist/owletto/dist/assets/public-shell-ready-B2NUI89V.js +2 -0
- package/dist/owletto/dist/assets/{recent-D-65Pgu-.js → recent-3d99S2IE.js} +2 -2
- package/dist/owletto/dist/assets/record-activity-C9KfBkXb.js +2 -0
- package/dist/owletto/dist/assets/record-field-peek-BBZcRuGT.js +2 -0
- package/dist/owletto/dist/assets/record-session-BizRugWs.js +2 -0
- package/dist/owletto/dist/assets/{reset-password-uX_V6bip.js → reset-password-DqfcSn8M.js} +2 -2
- package/dist/owletto/dist/assets/runs-panel-T1ZxTVz6.js +2 -0
- package/dist/owletto/dist/assets/runs-table-D_8QlCCN.js +2 -0
- package/dist/owletto/dist/assets/schema-value-normalization-CylKX3PK.js +97 -0
- package/dist/owletto/dist/assets/settings-B_ClYztB.js +2 -0
- package/dist/owletto/dist/assets/settings-DgX1-xo7.js +2 -0
- package/dist/owletto/dist/assets/skills-Drw5tcZw.js +2 -0
- package/dist/owletto/dist/assets/{source-record-panels-CPyzlfD1.js → source-record-panels-Cg249m1S.js} +2 -2
- package/dist/owletto/dist/assets/{use-mention-search-By8RZyKW.js → use-mention-search-BYbFvHbJ.js} +2 -2
- package/dist/owletto/dist/assets/view-param-filters-DMSqkN2J.js +2 -0
- package/dist/owletto/dist/index.html +2 -2
- package/dist/server-main.bundle.mjs +3881 -3215
- package/npm-shrinkwrap.json +277 -261
- package/package.json +6 -5
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/core/dist/agent-policy.js +0 -3
- package/vendor/core/dist/agent-tooling.d.ts +1 -1
- package/vendor/core/dist/agent-tooling.js +3 -1
- package/vendor/core/dist/contracts/agent-settings.d.ts +6 -2
- package/vendor/core/dist/contracts/agent-settings.js +12 -1
- package/vendor/core/dist/contracts/tools/manage-views.d.ts +53 -234
- package/vendor/core/dist/contracts/tools/manage-views.js +50 -76
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +5 -8
- package/vendor/core/dist/contracts/tools/view-attach.js +14 -31
- package/vendor/core/dist/contracts/tools/view-definition.d.ts +21 -0
- package/vendor/core/dist/contracts/tools/view-definition.js +165 -0
- package/vendor/core/dist/contracts/worker/protocol.d.ts +39 -2
- package/vendor/core/dist/contracts/worker/protocol.js +24 -1
- package/vendor/core/dist/index.d.ts +1 -1
- package/vendor/core/dist/index.js +2 -1
- package/vendor/core/dist/suggestions.d.ts +15 -2
- package/vendor/core/dist/suggestions.js +48 -3
- package/vendor/core/dist/types.d.ts +26 -0
- package/vendor/core/dist/types.js +5 -0
- package/vendor/core/package.json +11 -5
- package/vendor/postgres/cf/src/connection.js +18 -0
- package/vendor/postgres/cjs/src/connection.js +18 -0
- package/vendor/postgres/src/connection.js +18 -0
- package/vendor/views/dist/api.d.ts +71 -17
- package/vendor/views/dist/api.js +200 -35
- package/vendor/views/dist/bridge.d.ts +3 -0
- package/vendor/views/dist/bridge.js +9 -1
- package/vendor/views/dist/components.d.ts +170 -0
- package/vendor/views/dist/components.js +361 -0
- package/vendor/views/dist/index.d.ts +1 -1
- package/vendor/views/package.json +11 -1
- package/dist/owletto/dist/assets/_-3J-IrxWk.js +0 -2
- package/dist/owletto/dist/assets/_-DYUE3ix4.js +0 -3
- package/dist/owletto/dist/assets/_agentId-Bn2IAjIy.js +0 -2
- package/dist/owletto/dist/assets/_agentId-Cam7Z0N7.js +0 -2
- package/dist/owletto/dist/assets/_automationId-CXEiKVZJ.js +0 -2
- package/dist/owletto/dist/assets/_connectorKey._connectionId-CS85l61t.js +0 -2
- package/dist/owletto/dist/assets/_connectorKey.index-clVDIyW0.js +0 -2
- package/dist/owletto/dist/assets/_conversationId-Ci2k-BuN.js +0 -2
- package/dist/owletto/dist/assets/_eventId-B0662F8h.js +0 -2
- package/dist/owletto/dist/assets/_name-CwWePlOl.js +0 -2
- package/dist/owletto/dist/assets/_owner-dTWkrKsK.js +0 -3
- package/dist/owletto/dist/assets/_shape-BtS3y4M9.js +0 -2
- package/dist/owletto/dist/assets/_skillKey-Dc9m-nlR.js +0 -2
- package/dist/owletto/dist/assets/_slug-DQHutM41.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-B30ik8ma.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-CUHypQnF.js +0 -2
- package/dist/owletto/dist/assets/activity-route-view-CMqYiiKM.js +0 -2
- package/dist/owletto/dist/assets/agent-connect-pages-B_vrqLVc.js +0 -2
- package/dist/owletto/dist/assets/agent-editor-form-hTs7eO_U.js +0 -2
- package/dist/owletto/dist/assets/agent-subpage-shell-D92imvSt.js +0 -2
- package/dist/owletto/dist/assets/agent-thread-BJOijbT0.js +0 -6
- package/dist/owletto/dist/assets/agents-9XjpDj_S.js +0 -2
- package/dist/owletto/dist/assets/agents-workbench-Bt5QCYQ7.js +0 -2
- package/dist/owletto/dist/assets/app._appId-CKv7_squ.js +0 -2
- package/dist/owletto/dist/assets/automation-detail-content-vUwVumXf.js +0 -2
- package/dist/owletto/dist/assets/automations-9XjpDj_S.js +0 -2
- package/dist/owletto/dist/assets/callback-BRgcL8gz.js +0 -2
- package/dist/owletto/dist/assets/client-rows-EJSKR6z1.js +0 -2
- package/dist/owletto/dist/assets/connect-CfsFsy9P.js +0 -2
- package/dist/owletto/dist/assets/connect._clientId-DkiC8xos.js +0 -2
- package/dist/owletto/dist/assets/connected._clientId-CIXrGOsT.js +0 -2
- package/dist/owletto/dist/assets/connected._clientId.activity-Ckdz6I0y.js +0 -2
- package/dist/owletto/dist/assets/connected._clientId.index-CNxafNeo.js +0 -2
- package/dist/owletto/dist/assets/connections-browser-CKZjzRz6.js +0 -2
- package/dist/owletto/dist/assets/connector-scope-lists-CadPVsI3.js +0 -2
- package/dist/owletto/dist/assets/connectors-lvLJ30lo.js +0 -2
- package/dist/owletto/dist/assets/create-0xW9eXxG.js +0 -2
- package/dist/owletto/dist/assets/create-B0qhrrX4.js +0 -2
- package/dist/owletto/dist/assets/create-CAfF-yI1.js +0 -2
- package/dist/owletto/dist/assets/create._connectorKey-i6xxkWKV.js +0 -2
- package/dist/owletto/dist/assets/deployments-4Itm35Xc.js +0 -2
- package/dist/owletto/dist/assets/device-pin-tombstone-CrjG7gPo.js +0 -2
- package/dist/owletto/dist/assets/device._deviceId-Cs3ZmXWo.js +0 -2
- package/dist/owletto/dist/assets/entity-options-uXjgT7y9.js +0 -2
- package/dist/owletto/dist/assets/entity-page-Dc0LGr5U.js +0 -2
- package/dist/owletto/dist/assets/entity-type-page-CwZxa0BR.js +0 -2
- package/dist/owletto/dist/assets/event-detail-ve2d6Gbb.js +0 -2
- package/dist/owletto/dist/assets/events-feed-BtvhZF1f.js +0 -2
- package/dist/owletto/dist/assets/filter-editors-Cj-v6NtH.js +0 -2
- package/dist/owletto/dist/assets/guardrails-HFo2Ut8B.js +0 -2
- package/dist/owletto/dist/assets/identity-BigVSBCl.js +0 -2
- package/dist/owletto/dist/assets/index-BLEcy9-T.css +0 -1
- package/dist/owletto/dist/assets/index-BfedB4Rc.js +0 -2
- package/dist/owletto/dist/assets/index-CUw3aKBI.js +0 -2
- package/dist/owletto/dist/assets/index-CXhxUkv3.js +0 -2
- package/dist/owletto/dist/assets/index-Cr5hwh-C.js +0 -7950
- package/dist/owletto/dist/assets/index-CzkTV4ZQ.js +0 -2
- package/dist/owletto/dist/assets/index-DKSx8JN_.js +0 -2
- package/dist/owletto/dist/assets/index-DVk7Ug0d.js +0 -2
- package/dist/owletto/dist/assets/index-DmZuKGf8.js +0 -2
- package/dist/owletto/dist/assets/index-cPcroOH0.js +0 -2
- package/dist/owletto/dist/assets/index-n7sTbNv4.js +0 -2
- package/dist/owletto/dist/assets/index-xiFpcWKv.js +0 -2
- package/dist/owletto/dist/assets/login-Ci6ixHuL.js +0 -2
- package/dist/owletto/dist/assets/member-scope-gate-B44INDPY.js +0 -2
- package/dist/owletto/dist/assets/memory-browse-page-DyQiRvzl.js +0 -103
- package/dist/owletto/dist/assets/models-DpVP7ZwX.js +0 -2
- package/dist/owletto/dist/assets/new-BUb7AnEW.js +0 -2
- package/dist/owletto/dist/assets/new-CHOr-EcI.js +0 -2
- package/dist/owletto/dist/assets/peek-pane-content-CHoQHe2H.js +0 -2
- package/dist/owletto/dist/assets/proposal-review-shell-UcZr87_Q.js +0 -2
- package/dist/owletto/dist/assets/public-shell-ready-DcnlADmj.js +0 -2
- package/dist/owletto/dist/assets/record-activity-CBXH6v1d.js +0 -2
- package/dist/owletto/dist/assets/renderer-mEDnVW0O.js +0 -97
- package/dist/owletto/dist/assets/runs-C0rCgGwX.js +0 -2
- package/dist/owletto/dist/assets/runs-panel-Du1JMjg5.js +0 -2
- package/dist/owletto/dist/assets/runs-table-syPJ6r6T.js +0 -2
- package/dist/owletto/dist/assets/settings-9NkNA1G1.js +0 -2
- package/dist/owletto/dist/assets/settings-E-10sLQX.js +0 -2
- package/dist/owletto/dist/assets/skills-D2Ri9b4f.js +0 -2
- package/dist/owletto/dist/assets/status-dot-B-EWMgq6.js +0 -2
- package/dist/owletto/dist/assets/tabs-DqIIkCX-.js +0 -2
- package/dist/owletto/dist/assets/view-param-filters-CqLZQrnO.js +0 -2
- /package/vendor/postgres/{.bun-tag-f39dafdb2305d504 → .bun-tag-2f292c6554a8475e} +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{r as i,j as e,bn as ie,bo as re,bp as ce,bq as le,br as P,I as oe,B as Q,X as Xt,cN as gs,cL as ps,cg as Zt,gl as fs,gm as vs,S as Ct,y as k,P as R,ae as Ie,dM as Et,dO as ys,dP as js,ft as _s,dv as es,dQ as Ns,ei as ks,a$ as Ft,gn as bs,fe as st,ck as Ke,dd as tt,fg as yt,a_ as ts,cy as Je,cc as Ss,V as ws,H as Cs,cu as Es,go as Fs,gp as As,gq as Os,gr as Ms,gs as Ds,M as Ps,L as Ts,k as ss,gi as Ls,aZ as Rs,az as $s,ew as At,fV as Is,gt as qs,bY as Ks,f3 as Bs,by as pt,a1 as Ws,gu as Vs,gv as zs,gw as Us,gx as Qs,gy as Gs,gz as Js,gA as Hs,gB as Ys,gC as Xs,b0 as Zs,bx as en}from"./index-Cr5hwh-C.js";import{c as tn}from"./cronstrue-n4qGUraE.js";import{C as sn,f as nn}from"./entity-options-uXjgT7y9.js";import{M as an}from"./model-selector-dAbDgJvx.js";import{b as on}from"./skill-editor-D_W3QlRz.js";import{C as ft}from"./code-editor-DHeyRGZI.js";import{u as rn,b as Ot,c as Mt,s as cn,o as ln,M as dn,d as un,e as mn,f as hn,v as xn,r as gn}from"./use-mention-search-By8RZyKW.js";const Ze=[{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 pn(n){const t=n.trim();if(!t)return null;try{return tn.toString(t,{throwExceptionOnParseError:!0})}catch{return null}}function fn({value:n,onChange:t,placeholder:s="No schedule",className:r}){const d=n??"",u=Ze.some(f=>f.value===d),[c,a]=i.useState(!u&&d!==""),x=f=>{f==="custom"?a(!0):(a(!1),t(f))},m=d?pn(d):null,S=d?e.jsx("p",{className:m?"text-xs text-muted-foreground":"text-xs text-destructive",children:m??"Not a valid cron expression."}):null;return!d&&!c?e.jsxs(ie,{onValueChange:x,children:[e.jsx(re,{className:r??"w-full",children:e.jsx(ce,{placeholder:s})}),e.jsx(le,{children:Ze.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(oe,{placeholder:"0 */6 * * *",value:d,onChange:f=>t(f.target.value),className:"font-mono text-sm flex-1"}):e.jsxs(ie,{value:d,onValueChange:x,children:[e.jsx(re,{className:r??"w-full flex-1",children:e.jsx(ce,{children:Ze.find(f=>f.value===d)?.label??d})}),e.jsx(le,{children:Ze.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(Q,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",onClick:()=>{a(!1),t("")},children:e.jsx(Xt,{className:"h-4 w-4"})})]}),S]})}const dt="__all_workspace_event_types__",vn=[],yn={};function Dt(n,t,s){const r=new Map;if(!t)for(const[u,c]of Object.entries(s??{}))r.set(u,{key:u,label:Ft(u),description:c.description});const d=[...n].filter(u=>!t||u.slug===t).sort((u,c)=>u.slug.localeCompare(c.slug));for(const u of d)for(const[c,a]of Object.entries(u.event_kinds??{})){const x=r.get(c);if(x){!x.description&&a.description&&(x.description=a.description),JSON.stringify(x.metadataSchema??null)!==JSON.stringify(a.metadataSchema??null)&&(x.metadataSchema=void 0);continue}r.set(c,{key:c,label:Ft(c),description:a.description,metadataSchema:a.metadataSchema})}return[...r.values()].sort((u,c)=>u.label.localeCompare(c.label))}function Pt(n){const t=n[0];if(!t)return;const s=d=>JSON.stringify(Object.keys(d?.properties??{}).sort()),r=s(t);return n.every(d=>s(d)===r)?t:void 0}function Tt(n,t,s){const r=new Set(Object.keys(t.properties??{}));return{...Object.fromEntries(Object.entries(n).filter(([d])=>!r.has(d))),...s}}function $e(n,t,s){return s==="steer"&&(n==="window"||t!=="reply_to_source")?"coalesce":s}function Qe(n,t){return n==="window"?"silent":t}function Lt(n){return Object.fromEntries(Object.entries(n).filter(([t])=>t==="resource_ref"||t==="resource_type"))}function Rt(n,t,s){const r=new Set(Object.keys(t?.properties??{})),d=new Set(s.flatMap(u=>Object.keys(u.filterSchema?.properties??{})));return Object.fromEntries(Object.entries(bs(n)).filter(([u])=>u==="resource_ref"||u==="resource_type"||!d.has(u)||r.has(u)))}function jn({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(r=>e.jsx("button",{type:"button","aria-pressed":n===r.value,onClick:()=>s(r.value),className:R("rounded px-3 py-1 transition-colors",n===r.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:r.label},r.value))})}function $t({events:n,selectedKeys:t,onToggle:s,ariaLabel:r="Events"}){const d=i.useId(),u=n.filter(a=>t.includes(a.key)).map(a=>a.label),c=u.length===0?"Choose events":u.length===1?u[0]:`${u.length} events selected`;return e.jsx(st,{contentClassName:"w-[var(--radix-popover-trigger-width)] min-w-[280px]",searchPlaceholder:"Filter events...",emptyText:"No events found.",trigger:a=>e.jsxs(Q,{type:"button",variant:"outline",role:"combobox","aria-label":r,"aria-expanded":a,className:"w-full justify-between font-normal",children:[e.jsx("span",{className:R(u.length===0&&"text-muted-foreground"),children:c}),e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>n.map((a,x)=>{const m=t.includes(a.key),S=`${d}-${x}-state`;return e.jsxs(Ke,{value:`${a.label} ${a.key}`,onSelect:()=>s(a.key),"aria-label":a.label,"aria-describedby":S,className:"cursor-pointer",children:[e.jsx(tt,{className:R("mr-2 h-4 w-4",m?"opacity-100":"opacity-0")}),a.label,e.jsx("span",{id:S,className:"sr-only",children:m?"Selected":"Not selected"})]},a.key)})})}function _n({organizationId:n,initialTrigger:t,onChange:s,allowedKinds:r,showSectionHeader:d=!0,fieldIdPrefix:u="automation-trigger-"}){const c=gs(n,{status:"active",limit:500}),a=ps(n),x=Zt({organizationId:n}),m=fs({organizationId:n}),S=c.data??[],f=a.data??[],I=x.data??vn,h=m.data??yn,j=i.useMemo(()=>I.filter(l=>l.organization_id===n),[I,n]),y=t?.kind==="event"&&t?.source==="workspace",w=y||t===void 0,T=r?.length?[...r]:["event","time","manual"],_=T.join("|"),q=(()=>{const l=t===null?"manual":t?.kind==="schedule"?"time":"event";return T.includes(l)?l:T[0]??"event"})(),[N,K]=i.useState(q),[Y,te]=i.useState(y?"workspace":typeof t?.connection_id=="number"?String(t.connection_id):t?.kind==="event"&&t.connector_key?"":"workspace"),b=Y==="workspace",C=b?"":Y,[g,G]=i.useState(typeof t?.entity_type=="string"?t.entity_type:""),se=i.useMemo(()=>Array.isArray(t?.event_types)?t.event_types:[],[t]),[$,z]=i.useState(()=>se.filter(l=>typeof l=="string")),[X,he]=i.useState(t?.match&&typeof t.match=="object"&&!Array.isArray(t.match)?t.match:{}),[xe,ke]=i.useState(typeof t?.cron=="string"?t.cron:"0 9 * * 1-5"),be=typeof t?.timezone=="string"?t.timezone:void 0,[D,ge]=i.useState(t?.kind==="schedule"||w&&t?.execution!=="turn"||t?.execution==="window"?"window":"turn"),[ne,Z]=i.useState(Qe(D,t?.output==="reply_to_source"?"reply_to_source":"silent")),[J,ae]=i.useState(t?.kind==="schedule"||w&&t?.active_run!=="queue"?"coalesce":$e(D,ne,t?.active_run==="coalesce"||t?.active_run==="steer"?t.active_run:"queue")),[Se,Fe]=i.useState(t?.skip_if_unchanged!==!1),[we,p]=i.useState(!1);i.useEffect(()=>{const l=_.split("|");if(!l.includes(N)){const v=l[0]??"event";K(v),ge(v==="time"||v==="event"&&b?"window":"turn"),ae(v==="time"||v==="event"&&b?"coalesce":"queue"),Z("silent")}},[_,N,b]);const B=S.find(l=>String(l.id)===C),H=c.isLoading||a.isLoading,pe=x.isLoading,E=typeof t?.connector_key=="string"?t.connector_key:void 0,Ae=N==="event"&&!b&&t?.kind==="event"&&t?.source!=="workspace"&&typeof t.connection_id=="number"&&String(t.connection_id)===C&&!B,ve=N==="event"&&!b&&t?.kind==="event"&&t?.source!=="workspace"&&t.connection_id==null&&E!==void 0&&C==="",Oe=f.find(l=>l.key===(B?.connector_key??(ve?E:void 0))),de=Oe?.automation_events??[],W=de.filter(l=>$.includes(l.key)),ye=W[0],De=j.find(l=>l.slug===g),Me=[...j.filter(l=>Object.keys(l.event_kinds??{}).length>0||l.slug===g),...g&&!De?[{slug:g,name:g}]:[]],ue=i.useMemo(()=>Dt(j,g||void 0,h),[j,g,h]),Pe=ue.filter(l=>$.includes(l.key)),Be=Pe[0],fe=Pt(W.map(l=>l.filterSchema)),me=Pt(Pe.map(l=>l.metadataSchema)),We=!!(b&&g&&!De),Te=Ae||ve,Ce=(N==="event"?b?$.length>0&&!We:!!($.length>0&&(C&&B||Te)):N==="time"?!!xe.trim():!0)&&(N!=="event"||!vs(X));i.useEffect(()=>{let l;if(Ce&&N==="event"&&!b){const v=Rt(X,fe,Oe?.automation_events??[]);B||ve?l={kind:"event",source:"connector",connector_key:B?.connector_key??E,...B?{connection_id:Number(C)}:{},event_types:$,...Object.keys(v).length>0?{match:v}:{},execution:D,active_run:$e(D,ne,J),output:Qe(D,ne),skip_if_unchanged:Se}:Ae&&(l=t?{...t,source:"connector"}:void 0)}else if(Ce&&N==="event"&&b){const v=Rt(X,me,ue.map(F=>({filterSchema:F.metadataSchema})));l={kind:"event",source:"workspace",...g?{entity_type:g}:{},event_types:$,...Object.keys(v).length>0?{match:v}:{},execution:D,active_run:J==="queue"?"queue":"coalesce"}}else Ce&&N==="time"&&(l={kind:"schedule",cron:xe.trim(),...be?{timezone:be}:{},execution:"window",active_run:"coalesce",skip_if_unchanged:Se});s({ready:Ce,kind:N,trigger:l})},[J,C,B,xe,Oe,$,D,X,N,E,be,t,b,s,ne,Ce,fe,me,Se,g,ue,ve,Ae]);const at=l=>{const v=S.find(A=>String(A.id)===l),F=f.find(A=>A.key===v?.connector_key),ee=$.filter(A=>F?.automation_events?.some(Re=>Re.key===A)),M=F?.automation_events?.find(A=>A.key===ee[0]),je=v?.connector_key!==(B?.connector_key??E);if(te(l),z(ee),!M)he(Lt);else if(je){const A=M.defaults?.execution??"turn",Re=M.defaults?.activeRun??"queue",Ue=Qe(A,M.defaults?.output??"silent");he(Lt),ge(A),ae($e(A,Ue,Re)),Z(Ue)}},ot=l=>{if(l==="workspace"){te("workspace"),z(v=>v.filter(F=>ue.some(ee=>ee.key===F))),he({}),ge("window"),ae("coalesce"),Z("silent");return}at(l)},Ve=l=>{const v=$.includes(l)?$.filter(A=>A!==l):de.map(A=>A.key).filter(A=>A===l||$.includes(A));if(z(v),v[0]===$[0])return;const F=de.find(A=>A.key===v[0]),ee=F?.defaults?.execution??"turn",M=F?.defaults?.activeRun??"queue",je=Qe(ee,F?.defaults?.output??"silent");ge(ee),ae($e(ee,je,M)),Z(je)},Ye=l=>{const v=l===dt?"":l,F=j.find(M=>M.slug===v),ee=Dt(j,F?.slug,h);G(v),z(M=>M.filter(je=>ee.some(A=>A.key===je))),he({})},ze=l=>{z(v=>v.includes(l)?v.filter(F=>F!==l):ue.map(F=>F.key).filter(F=>F===l||v.includes(F)))},Le=[{value:"event",label:"Event"},{value:"time",label:"Schedule"},{value:"manual",label:"Manual"}].filter(l=>T.includes(l.value));return e.jsxs("div",{className:"space-y-4",children:[d?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,Le.length>1?e.jsx(jn,{value:N,options:Le,onChange:l=>{K(l),ge(l==="time"||l==="event"&&b?"window":"turn"),ae(l==="time"||l==="event"&&b?"coalesce":"queue"),Z("silent")}}):null,N==="event"?H||b&&pe?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ct,{className:"h-9 w-full"}),e.jsx(Ct,{className:"h-9 w-full"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Source"}),e.jsx(sn,{connections:S,value:Y,onValueChange:ot,disabled:Te,includeWorkspaceEvents:!0,ariaLabel:"Source",placeholder:"Choose a source"}),Ae?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."}):ve?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]}),b?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:ue.length>1?"Events":"Event"}),ue.length>0?e.jsx($t,{events:ue,selectedKeys:$,onToggle:ze}):e.jsx("div",{className:R(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:g?"This entity type has no declared Automation events.":"This workspace has no declared Automation events."}),Be?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:Be.description}):null,We?e.jsxs("p",{className:"text-xs text-destructive",children:["This trigger filters on entity type “",g,"”, 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."})]}),me?e.jsx(Et,{schema:me,values:X,onValuesChange:l=>he(v=>Tt(v,me,l)),fieldIdPrefix:`${u}workspace-`},`${g||"workspace"}:${$.join(",")}`):null]}):B||ve?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:de.length>1?"Events":"Event"}),de.length?e.jsx($t,{events:de,selectedKeys:$,onToggle:Ve}):e.jsx("div",{className:R(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:"This connector has not published subscribable events."}),ye?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:ye.description}):null]}),typeof X.resource_ref=="string"||fe?e.jsxs("div",{className:"space-y-3",children:[typeof X.resource_ref=="string"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Resource"}),e.jsx("div",{className:R(Ie,"px-3 py-2 text-sm"),children:X.resource_ref})]}):null,fe?e.jsx(Et,{schema:fe,values:X,onValuesChange:l=>he(v=>Tt(v,fe,l)),fieldIdPrefix:u},$.join(",")):null]}):null]}):Y?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose workspace events or a connected app as the source."})]}):N==="time"?e.jsx(fn,{value:xe,onChange:ke}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this Automation explicitly from Lobu, the API, CLI, or MCP."}),N!=="manual"&&!Te?e.jsxs(ys,{open:we,onOpenChange:p,children:[e.jsx(js,{asChild:!0,children:e.jsxs(Q,{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(_s,{className:"h-4 w-4"}),"Trigger options",e.jsxs("span",{className:"font-normal text-muted-foreground",children:["· ",D==="turn"?"Each event":"Window"," ·"," ",N==="time"?"Combine":b?J==="queue"?"Queue":"Combine":J==="queue"?"Queue":J==="coalesce"?"Combine":"Update current run",N==="event"&&!b?` · ${D==="turn"&&ne==="reply_to_source"?"Reply":"Save in Lobu"}`:""]})]}),e.jsx(es,{className:R("h-4 w-4 transition-transform",we&&"rotate-180")})]})}),e.jsxs(Ns,{className:"space-y-4 pt-3",children:[N==="event"&&b?e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Entity type filter"}),e.jsxs(ie,{value:g||dt,onValueChange:Ye,children:[e.jsx(re,{"aria-label":"Entity type filter",children:e.jsx(ce,{})}),e.jsxs(le,{children:[e.jsx(P,{value:dt,children:"All event types"}),Me.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,N==="event"?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Run"}),e.jsxs(ie,{value:D,onValueChange:l=>{const v=l,F=Qe(v,ne);ge(v),Z(F),ae($e(v,F,J))},children:[e.jsx(re,{children:e.jsx(ce,{})}),e.jsxs(le,{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(k,{children:"When busy"}),e.jsxs(ie,{value:J,onValueChange:l=>ae(l),children:[e.jsx(re,{children:e.jsx(ce,{})}),e.jsxs(le,{children:[e.jsx(P,{value:"queue",children:"Queue"}),e.jsx(P,{value:"coalesce",children:"Combine waiting events"}),!b&&D==="turn"&&ne==="reply_to_source"&&ye?.capabilities?.steering?e.jsx(P,{value:"steer",children:"Update the current run"}):null]})]})]})]}):null,D==="window"&&(N==="time"||!b)?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(ks,{"aria-label":"Skip unchanged windows",checked:Se,onCheckedChange:Fe})]}):null,N==="event"&&!b&&D==="turn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Result"}),e.jsxs(ie,{value:ne,onValueChange:l=>{const v=l;Z(v),ae($e(D,v,J))},children:[e.jsx(re,{children:e.jsx(ce,{})}),e.jsxs(le,{children:[ye?.capabilities?.replyToSource?e.jsx(P,{value:"reply_to_source",children:"Reply where it happened"}):null,e.jsx(P,{value:"silent",children:"Save in Lobu"})]})]}),ye?.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 Nn=16;function qe(){return crypto.randomUUID()}function kn(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 ns(n){return n?n.kind==="time"||n.trigger?.kind==="schedule":!1}function bn(n,t){return n?n.ready===t.ready&&n.kind===t.kind&&JSON.stringify(n.trigger)===JSON.stringify(t.trigger):!1}function Sn(n,t){const s=n.map(a=>t[a.key]??{ready:!1,kind:"event"});if(!(n.length>1)&&s[0]?.kind==="manual")return{ready:s[0].ready,triggers:[]};const d=s.filter(ns).length;return{ready:!s.some(a=>a.kind==="manual")&&d<=1&&s.length>0&&s.every(a=>a.ready&&a.trigger),triggers:s.filter(a=>a.trigger).map(a=>a.trigger)}}function na({organizationId:n,initialTriggers:t,onChange:s}){const r=i.useId(),[d,u]=i.useState(()=>kn(t)),[c,a]=i.useState({}),x=i.useRef("");i.useEffect(()=>{const h=Sn(d,c),j=JSON.stringify(h);j!==x.current&&(x.current=j,s(h))},[d,c,s]);const m=d.find(h=>ns(c[h.key]))?.key??d.find(h=>h.initial&&typeof h.initial=="object"&&h.initial.kind==="schedule"&&!c[h.key])?.key??null,S=i.useCallback((h,j)=>{a(y=>bn(y[h],j)?y:{...y,[h]:j})},[]),f=()=>{const h=d[0],j=h?c[h.key]:void 0;if(d.length===1&&(j?.kind==="manual"||h?.initial===null)){const y=qe();a({}),u([{key:y,initial:void 0}]);return}u(y=>[...y,{key:qe(),initial:void 0}])},I=h=>{if(d.length<=1){const j=qe();a({}),u([{key:j,initial:null}]);return}a(j=>{const y={...j};return delete y[h],y}),u(j=>j.filter(y=>y.key!==h))};return e.jsxs("section",{className:"space-y-4","aria-labelledby":`${r}-heading`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{id:`${r}-heading`,className:"text-sm font-medium",children:"When"}),d.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:d.map((h,j)=>{const y=d.length>1,w=y?m&&m!==h.key?["event"]:["event","time"]:["event","time","manual"],T=c[h.key],_=y||(T?T.kind!=="manual":h.initial!==null);return e.jsxs("div",{className:R("space-y-3 rounded-lg border bg-card/40 p-3",y&&"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:y?`Trigger ${j+1}`:"Trigger"}),_?e.jsx(Q,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive","aria-label":y?`Remove trigger ${j+1}`:"Clear trigger",onClick:()=>I(h.key),children:e.jsx(ts,{className:"h-3.5 w-3.5"})}):null]}),e.jsx(wn,{slotKey:h.key,organizationId:n,initial:h.initial,kinds:w,fieldIdPrefix:`${r}-${h.key}-`,onChange:S})]},h.key)})}),e.jsxs(Q,{type:"button",variant:"outline",size:"sm",className:"w-full sm:w-auto",onClick:f,disabled:d.length>=Nn,children:[e.jsx(Je,{className:"mr-1.5 h-3.5 w-3.5"}),"Add another trigger"]})]})}function wn({slotKey:n,organizationId:t,initial:s,kinds:r,fieldIdPrefix:d,onChange:u}){const c=i.useCallback(a=>u(n,a),[u,n]);return e.jsx(_n,{organizationId:t,initialTrigger:s,allowedKinds:r,showSectionHeader:!1,fieldIdPrefix:d,onChange:c})}const Cn=["claude-code","codex","opencode","pi","agy"],En={"claude-code":"Claude Code",codex:"Codex",opencode:"OpenCode",pi:"Pi",agy:"Antigravity (agy)"},Fn=[{kind:"claude-code",binaryName:"claude",promptDelivery:{kind:"flag",flag:"-p"},mcpDelivery:{kind:"claude-config-file",flag:"--mcp-config",extraArgs:["--strict-mcp-config","--allowedTools","mcp__lobu__query_sdk,mcp__lobu__run_sdk"]},headlessArgs:[],modelFlag:"--model",effortFlag:"--effort",permissionModeFlag:"--permission-mode",budgetFlag:"--max-budget-usd",timeoutFlag:null,trailingArgs:[]},{kind:"agy",binaryName:"agy",promptDelivery:{kind:"flag",flag:"-p"},mcpDelivery:{kind:"none"},headlessArgs:["--dangerously-skip-permissions"],modelFlag:"--model",effortFlag:"--effort",permissionModeFlag:null,budgetFlag:null,timeoutFlag:{flag:"--print-timeout",suffix:"s"},trailingArgs:[]},{kind:"opencode",binaryName:"opencode",promptDelivery:{kind:"positional",subcommand:["run"]},mcpDelivery:{kind:"opencode-config-env",variable:"OPENCODE_CONFIG_CONTENT"},headlessArgs:["--auto","--print-logs","--log-level","ERROR"],modelFlag:"-m",effortFlag:"--variant",permissionModeFlag:null,budgetFlag:null,timeoutFlag:null,trailingArgs:[]},{kind:"codex",binaryName:"codex",promptDelivery:{kind:"positional",subcommand:["exec"]},mcpDelivery:{kind:"none"},headlessArgs:["--skip-git-repo-check","--sandbox","workspace-write","-c","sandbox_workspace_write.network_access=true"],modelFlag:"-m",effortFlag:"-c",effortConfigKey:"model_reasoning_effort",permissionModeFlag:null,budgetFlag:null,timeoutFlag:null,trailingArgs:[]},{kind:"pi",binaryName:"pi",promptDelivery:{kind:"positional",subcommand:[]},mcpDelivery:{kind:"none"},headlessArgs:["-p","--no-session","--tools","read,bash,edit,write"],modelFlag:"--model",effortFlag:"--thinking",permissionModeFlag:null,budgetFlag:null,timeoutFlag:null,trailingArgs:[]}];new Map(Fn.map(n=>[n.kind,n]));const It={agents:!0,lobuEmbedded:!1};function An(){const{data:n}=Ss({queryKey:["features"],queryFn:async()=>{const t=await ws(`${Cs}/api/features`);return t.ok?t.json():It},staleTime:3e4,refetchInterval:6e4});return n??It}const qt=["slack","imessage"],ut="__none__";function Ge(n){return`${n.connection_id}:${n.feed_key}`}function On(n){const t=n.indexOf(":");if(t<=0)return null;const s=Number(n.slice(0,t)),r=n.slice(t+1);return!Number.isSafeInteger(s)||s<=0||!r?null:{connection_id:s,channel_id:r}}function mt(n){return n?`${n.connection_id}:${n.channel_id}`:""}function et(n){return`${n.display_name||n.feed_key} (${n.feed_key})`}function Mn({organizationId:n,agentId:t,value:s,onChange:r,disabled:d=!1,automationName:u,onPendingChange:c}){const{data:a=[],isLoading:x}=Es(n),m=mt(s),[S,f]=i.useState(null),[I,h]=i.useState(!1),j=i.useRef(t),y=i.useMemo(()=>a.filter(g=>g.store==="channel_messages"&&g.target_agent_id===t&&qt.includes(g.connector_key)),[a,t]);i.useEffect(()=>{if(j.current===t||(j.current=t,f(null),h(!1),s==null))return;const g=mt(s);if(g==="")return;a.some(se=>se.store==="channel_messages"&&se.target_agent_id===t&&qt.includes(se.connector_key)&&Ge(se)===g)||r(null)},[t,a,s,r]);const w=S??m,T=w===""?ut:w,_=y.find(g=>Ge(g)===w),q=S!==null&&S!==""&&S!==m;i.useEffect(()=>{c?.(q)},[q,c]);const N=_??(S?void 0:y.find(g=>Ge(g)===m)),K=g=>{const G=g===ut?"":g;if(G===""){f(null),h(!1),r(null);return}if(G===m){f(null),h(!1);return}f(G),h(!1)},Y=g=>{if(h(g),g&&S){const G=On(S);G&&(f(null),r(G))}else!g&&S&&f(null)},b=(s&&mt(s)!==""?s:void 0)??(_?{connection_id:_.connection_id,channel_id:_.feed_key}:void 0),C=(u??"").trim()||"This automation";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"automation-delivery-target",children:["Digest destination"," ",e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),t?e.jsxs(ie,{value:T,onValueChange:K,disabled:d||x,children:[e.jsx(re,{id:"automation-delivery-target",className:"font-mono text-sm",children:e.jsx(ce,{placeholder:x?"Loading bound channels…":y.length===0?"No bound Slack or iMessage channels":"No digest — runs stay silent"})}),e.jsxs(le,{children:[e.jsx(P,{value:ut,children:"No digest — runs stay silent"}),y.map(g=>e.jsxs(P,{value:Ge(g),children:[et(g)," · ",g.connector_key]},Ge(g)))]})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select a managed agent first — only channels bound to that agent can receive digests."}),t&&!x&&y.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No Slack or iMessage channels are bound to this agent yet. Link a private channel first, then select it here."}):null,q&&_?e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-xs",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:g=>Y(g.target.checked),className:"mt-0.5","aria-label":`Confirm digest delivery to ${et(_)}`}),e.jsxs("span",{className:"text-muted-foreground",children:["I confirm posting material-change digests to"," ",e.jsx("span",{className:"font-medium text-foreground",children:et(_)}),". Destination changes are audited."]})]}):null,N||b?e.jsxs("div",{className:R(Ie,"space-y-1.5 px-3 py-2"),children:[e.jsxs("p",{className:"text-xs font-medium",children:["Digest preview →"," ",e.jsx("span",{className:"font-mono font-normal",children:N?`${N.connector_key} ${et(N)} · connection ${N.connection_id}`:`${b?.channel_id} · connection ${b?.connection_id}`})]}),e.jsxs("p",{className:"font-mono text-xs",children:[C," applied 2 new + 1 updated"]}),e.jsx("p",{className:"whitespace-pre-line font-mono text-xs text-muted-foreground",children:`+ Example task (#12)
|
|
2
|
-
~ Follow-up item (#34)`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sends only after a successful run with material changes. Runs with zero changes send nothing. Retries reuse the same notification and delivery receipts dedupe channel posts, but provider acceptance with a lost receipt can still duplicate."})]}):null]})}const Kt=4096;function Dn({open:n,onOpenChange:t,initial:s,onSubmit:r}){const[d,u]=i.useState(""),[c,a]=i.useState(""),[x,m]=i.useState(null);i.useEffect(()=>{n&&(u(s?.name??""),a(s?.query??""),m(null))},[n,s]);const S=()=>{const I=d.trim(),h=c.trim();if(!I){m("Give the SQL source a name.");return}if(!h){m("Enter a query.");return}if(h.length>Kt){m(`Query is too long (${h.length} chars, max ${Kt}).`);return}r({name:I,query:h}),t(!1)},f=!!s;return e.jsx(Fs,{open:n,onOpenChange:t,children:e.jsxs(As,{className:"max-w-2xl",children:[e.jsxs(Os,{children:[e.jsx(Ms,{children:f?"Edit SQL source":"SQL source"}),e.jsx(Ds,{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(k,{htmlFor:"sql-source-name",children:"Name"}),e.jsx(oe,{id:"sql-source-name",value:d,onChange:I=>u(I.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(k,{htmlFor:"sql-source-query",children:"Query"}),e.jsx(ft,{value:c,onChange:a,language:"sql",placeholder:"SELECT id, payload_text, occurred_at FROM events ORDER BY occurred_at DESC",minHeight:"160px"})]}),x?e.jsx("p",{className:"text-sm text-destructive",children:x}):null]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(Q,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(Q,{onClick:S,children:f?"Save":"Add source"})]})]})})}const Pn=["skill","feed","connection","connector","metric","entity_type"];function Tn({value:n,onChange:t,library:s,pinned:r,required:d,error:u,owner:c,agentId:a,sources:x,onAddSources:m}){const S=rn(Pn,Ot,{skills:s,skillAgentId:a||null}),f=i.useRef(null),[I,h]=i.useState(null),j=i.useMemo(()=>{if(!x)return[];const _=new Set(x.map(q=>q.query.trim()));return Mt(n).filter(q=>!_.has(q.query.trim()))},[n,x]),y=cn(n),w=ln(r.filter(_=>y.includes(_.name)),s),T=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(k,{htmlFor:"automation-prompt",children:["Instructions"," ",d?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),y.length>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[y.length,"/",Ot," skills"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring",children:e.jsx(dn,{value:n,onChange:t,onSubmit:()=>{},submitOnEnter:!1,searchRefs:S,handleRef:f,onSqlRequest:()=>h({}),onSqlEdit:(_,q)=>h({initial:_,pos:q}),placeholder:T?"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(Dn,{open:I!==null,onOpenChange:_=>{_||h(null)},initial:I?.initial,onSubmit:_=>{f.current?.insertSql(_,I?.pos),h(null)}}),j.length>0&&m?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:[j.length===1?`"${j[0]?.name}" is referenced in the instructions but is not a source on this Automation.`:`${j.length} references in the instructions are not sources on this Automation.`," ","Editing an Automation does not add them automatically."]}),e.jsx(Q,{type:"button",variant:"outline",size:"sm",onClick:()=>m(Mt(n,x)),children:j.length===1?"Add as a source":"Add as sources"})]}):null,y.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:y.map(_=>{const q=w.includes(_),N=!s.some(K=>K.name===_);return e.jsxs(Ps,{variant:N?"destructive":"secondary",className:"font-normal",children:[_,N?" · unavailable":q?" · newer text":null]},_)})}):null,w.length>0?e.jsxs("p",{className:"rounded-lg border border-dashed p-3 text-xs text-muted-foreground",children:[w.length===1?`"${w[0]}" has been edited since this Automation pinned it.`:`${w.length} skills have been edited since this Automation pinned them.`," ","This Automation keeps running the pinned text until you save it again."]}):null,u?e.jsx("p",{className:"text-xs text-destructive",children:u}):null,!T&&a?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This agent has no skills yet."," ",e.jsx(Ts,{to:"/$owner/agents/$agentId/skills",params:{owner:c,agentId:a},className:"font-medium text-foreground underline underline-offset-2",children:"Add one"})," ","to reuse instructions across Automations."]}):u?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:T?"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 Ln=["connection","connector","feed","metric","entity_type"];function Rn({sources:n,onChange:t,disabled:s}){const{currentOwner:r,resolvedOrganizationId:d}=ss(),[u,c]=i.useState(""),{refs:a}=un({owner:r,organizationId:d,kinds:Ln,query:u,limitPerKind:10});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Sources"}),n.length>0?e.jsx("ul",{className:"space-y-2",children:n.map(x=>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:x.name}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:x.query})]}),e.jsx(Q,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0","aria-label":`Remove source ${x.name}`,disabled:s,onClick:()=>t(n.filter(m=>m.query!==x.query)),children:e.jsx(Xt,{className:"h-3.5 w-3.5"})})]},x.query))}):null,e.jsx("div",{className:"flex gap-2",children:e.jsx(st,{searchPlaceholder:"Search feeds, connections, metrics…",emptyText:"No matching reference.",onQueryChange:c,trigger:()=>e.jsxs(Q,{type:"button",variant:"outline",size:"sm",disabled:s,children:[e.jsx(Je,{className:"mr-2 h-3.5 w-3.5"}),"Add source"]}),children:x=>a.map(m=>e.jsxs(Ke,{value:`${m.label} ${m.kind}`,onSelect:()=>{t(mn(m,n)),x()},children:[e.jsx("span",{className:"truncate text-sm",children:m.label}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-muted-foreground",children:m.kind})]},`${m.kind}:${m.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 $n({organizationId:n,value:t,onChange:s,className:r}){const{data:d=[]}=Ls(n),u=nn(d),c=u.find(a=>a.id===t);return e.jsx(st,{contentClassName:"w-[300px]",searchPlaceholder:"Search entities...",emptyText:"No entities found.",trigger:a=>e.jsxs(Q,{variant:"outline",role:"combobox","aria-expanded":a,className:R("w-full justify-between",r),children:[c?`${c.name} (${c.entityType})`:"All workspace",e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:a=>e.jsxs(e.Fragment,{children:[e.jsxs(Ke,{value:"all workspace",onSelect:()=>{s(void 0),a()},className:"cursor-pointer",children:[e.jsx(tt,{className:R("mr-2 h-4 w-4",t===void 0?"opacity-100":"opacity-0")}),e.jsx("span",{children:"All workspace"})]}),u.map(x=>e.jsxs(Ke,{value:`${x.name} ${x.entityType}`,onSelect:()=>{s(x.id),a()},className:"cursor-pointer",children:[e.jsx(tt,{className:R("mr-2 h-4 w-4",t===x.id?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[x.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",x.entityType,")"]})]})]},x.id))]})})}function vt(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 In=Cn.map(n=>({value:n,label:En[n]})),Bt=[{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 Wt(n){const t=!!(n?.prompt?.trim()||n?.skills?.some(r=>r.content.trim())),s=!!n?.reaction_script?.trim();return t&&s?"both":s?"code":"agent"}const qn=["text","number","date","boolean","json"],Kn=[{value:"key",label:"Key"},{value:"plain",label:"Plain"}],ht=[{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 Vt=0;function Bn(){return Vt+=1,`field-${Vt}`}function as(n={}){return{id:Bn(),name:n.name??"",type:n.type??"text",role:n.role??"plain"}}function He(n){return n.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")}function Wn(n){return n?Object.keys(n).every(t=>["entity_type","entity_path","key_fields","key_output_field"].includes(t)):!0}function zt(n){return n?Wn(n.keying_config)?"fields":"json":"fields"}function Ut(n){const t=n?.keying_config?.entity_type;return typeof t=="string"?t:""}function Qt(n){const t=n?.keying_config?.entity_path;return typeof t=="string"&&t.trim()?t:"$"}function Gt(n){const t=new Map,s=Array.isArray(n?.keying_config?.key_fields)?n?.keying_config?.key_fields:[];for(const r of s){if(typeof r!="string")continue;const d=He(r);d&&t.set(d,as({name:d,role:"key"}))}return Array.from(t.values())}function _e(n,t){const s=n?.execution_config?.[t];return typeof s=="number"||typeof s=="string"?String(s):""}function Jt(n,t,s){const r=n?.execution_config?.[t];return typeof r=="string"&&s.includes(r)?r:""}function xt(n,t){const s=n.trim();if(!s)return{};const r=Number(s);return Number.isFinite(r)?{value:r}:{error:`${t} must be a number.`}}function Ht({entityType:n,entityPath:t,fields:s}){const d=s.map(a=>({...a,name:He(a.name)})).filter(a=>a.name).filter(a=>a.role==="key").map(a=>a.name),u=He(n),c=t.trim()||"$";return d.length>0&&!u?{error:"Key fields need an output entity type."}:(d.length>0,{keyingConfig:d.length>0?{entity_type:u,entity_path:c,key_fields:d,key_output_field:`${u}_key`}:void 0})}function Vn(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 Yt(n){return!!(n?.keying_config||n?.reactions_guidance||n?.model_config||n?.execution_config||n?.sources?.length||vt(n?.tags).length)}function zn({organizationId:n,entityId:t,prefill:s,onSubmit:r,isSubmitting:d,error:u,isEditing:c,onCancel:a,triggerFields:x,submitLabel:m="Create Automation",submitDisabled:S=!1,triggers:f}){const{lobuEmbedded:I}=An(),{currentOwner:h}=ss(),{data:j=[]}=Rs(),{data:y=[]}=$s(),[w,T]=i.useState(s?.managed_agent_id??""),_=!!s?.managed_agent_id&&!c,[q,N]=i.useState(s?.delivery_target??null),[K,Y]=i.useState(!1),[te,b]=i.useState(s?.device_worker_id??""),[C,g]=i.useState(s?.device_worker_id?"device":"agent"),[G,se]=i.useState(s?.agent_kind??""),{data:$=[]}=Zt({organizationId:n}),[z,X]=i.useState(s?.name??""),[he,xe]=i.useState(s?.slug??""),[ke,be]=i.useState(!!s?.slug),[D,ge]=i.useState(s?.description??""),[ne,Z]=i.useState(s?.prompt??""),[J,ae]=i.useState(!1),Se=s?.skills??[],[Fe,we]=i.useState(s?.sources??[]),[p,B]=i.useState(s?.entity_id??t),[H,pe]=i.useState(s?.reaction_script??""),[E,Ae]=i.useState(()=>Wt(s)),[ve,Oe]=i.useState(s?.keying_config?JSON.stringify(s.keying_config,null,2):""),[de,W]=i.useState(null),[ye,De]=i.useState(()=>zt(s)),[Me,ue]=i.useState(()=>Ut(s)),[Pe,Be]=i.useState(()=>Qt(s)),[fe,me]=i.useState(()=>Gt(s)),[We,Te]=i.useState(s?.reactions_guidance??""),[nt,Ce]=i.useState(()=>_e(s,"timeout_seconds")),[at,ot]=i.useState(()=>_e(s,"max_budget_usd")),[Ve,Ye]=i.useState(()=>_e(s,"model")),[ze,it]=i.useState(()=>Jt(s,"permission_mode",ht.map(o=>o.value))),[Le,l]=i.useState(()=>_e(s,"effort")),[v,F]=i.useState(()=>_e(s,"finalize_nudges")),[ee,M]=i.useState(null),[je,A]=i.useState(vt(s?.tags).join(", ")),[Re,Ue]=i.useState(""),[rt,jt]=i.useState(!!(c||Yt(s)));i.useEffect(()=>{s&&(X(s.name??""),xe(s.slug??""),be(!!s.slug),ge(s.description??""),Z(s.prompt??""),ae(!1),we(s.sources??[]),B(s.entity_id??t),b(s.device_worker_id??""),g(s.device_worker_id?"device":"agent"),se(s.agent_kind??""),pe(s.reaction_script??""),Ae(Wt(s)),Oe(s.keying_config?JSON.stringify(s.keying_config,null,2):""),W(null),De(zt(s)),ue(Ut(s)),Be(Qt(s)),me(Gt(s)),Te(s.reactions_guidance??""),Ce(_e(s,"timeout_seconds")),ot(_e(s,"max_budget_usd")),Ye(_e(s,"model")),it(Jt(s,"permission_mode",ht.map(o=>o.value))),l(_e(s,"effort")),F(_e(s,"finalize_nudges")),M(null),A(vt(s.tags).join(", ")),Ue(""),T(s.managed_agent_id??""),N(s.delivery_target??null),jt(!!(c||Yt(s))))},[s,t,c]);const os=ke?he:At(z),{data:is}=Is(w||null),{data:rs}=qs(w||null,{enabled:!!w}),ct=on(is??null,rs?.catalog??[]),cs=hn(f),lt=H.trim().length>0,Xe=!c&&E==="code"?"":ne,ls=!c&&E==="agent"?void 0:H.trim()||void 0,_t=(c||E==="code")&<,Nt=xn(Xe,ct,f,_t),ds=J||Xe.trim()!==""?Nt:null,kt=gn(Xe,ct),bt=!c&&E!=="agent",us=C==="device"&&!w.trim(),St=!!z.trim()&&!us&&!Nt&&(!bt||lt)&&!K,ms=cs&&!_t&&kt.length===0,hs=()=>{if(!St)return;let o;if(ye==="fields"){const Ne=Ht({entityType:Me,entityPath:Pe,fields:fe});if(Ne.error){W(Ne.error);return}o=Ne.keyingConfig,W(null)}else{if(ve.trim())try{const Ne=JSON.parse(ve);if(typeof Ne!="object"||Array.isArray(Ne)){W("Keying config must be a JSON object.");return}o=Ne}catch{W("Invalid JSON. Please check the syntax.");return}W(null)}const O=xt(nt,"Timeout");if(O.error){M(O.error);return}if(O.value!==void 0&&(!Number.isInteger(O.value)||O.value<1)){M("Timeout must be a whole number greater than 0.");return}const V=xt(at,"Budget");if(V.error){M(V.error);return}if(V.value!==void 0&&V.value<0){M("Budget cannot be negative.");return}const L=xt(v,"Finalize nudges");if(L.error){M(L.error);return}if(L.value!==void 0&&(!Number.isInteger(L.value)||L.value<0||L.value>5)){M("Finalize nudges must be a whole number from 0 to 5.");return}const Ee={...O.value!==void 0?{timeout_seconds:O.value}:{},...V.value!==void 0?{max_budget_usd:V.value}:{},...Ve.trim()?{model:Ve.trim()}:{},...ze?{permission_mode:ze}:{},...Le.trim()?{effort:Le.trim()}:{},...L.value!==void 0?{finalize_nudges:L.value}:{}},U=Object.keys(Ee).length>0||c?Ee:void 0;M(null);const xs=je.trim()?je.split(",").map(Ne=>Ne.trim()).filter(Boolean):void 0;r({slug:os,name:z.trim(),description:D.trim()||void 0,prompt:Xe,skills:kt,entity_id:p,sources:Fe,reaction_script:ls,keying_config:o,reactions_guidance:We.trim()||void 0,execution_config:U,tags:xs,outputs:s?.outputs,change_notes:Re.trim()||void 0,managed_agent_id:C==="manual"?null:w.trim()||null,device_worker_id:C==="device"&&te.trim()||null,agent_kind:C==="device"&&G.trim()||null,delivery_target:q})},wt=e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"scratch-reaction",children:["Reaction Script"," ",bt?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(ft,{value:H,onChange:pe,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(k,{htmlFor:"scratch-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),!c&&e.jsx("button",{type:"button",onClick:()=>be(!ke),className:"text-xs text-muted-foreground hover:text-foreground",children:ke?"Use automatic slug":"Customize slug"})]}),e.jsx(oe,{id:"scratch-name",value:z,onChange:o=>X(o.target.value),placeholder:"e.g., Escalation signals"}),!c&&ke?e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-slug",children:"Slug"}),e.jsx(oe,{id:"scratch-slug",value:he,onChange:o=>xe(o.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:At(z)||"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:Bt.map(o=>e.jsx("button",{type:"button","aria-pressed":E===o.value,onClick:()=>Ae(o.value),className:R("rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors",E===o.value?"bg-secondary text-secondary-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:o.label},o.value))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Bt.find(o=>o.value===E)?.hint})]}),c||E!=="code"?e.jsx(Tn,{value:ne,onChange:o=>{ae(!0),Z(o)},library:ct,pinned:Se,required:ms,error:ds,owner:h??"",agentId:w,sources:c?Fe:void 0,onAddSources:c?we:void 0}):null,!c&&E!=="agent"?wt:null,c?e.jsx(Rn,{sources:Fe,onChange:we,disabled:d}):null,e.jsx("div",{className:"space-y-4",children:x}),e.jsx(Mn,{organizationId:n,agentId:C==="agent"?w.trim():"",value:q,onChange:N,disabled:d,automationName:z,onPendingChange:Y}),K?e.jsx("p",{className:"text-xs text-destructive",children:"Confirm the digest destination above before saving — an unconfirmed destination is not sent."}):null,e.jsxs(Q,{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:()=>jt(o=>!o),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"h-4 w-4"}),"Advanced settings"]}),e.jsx(es,{className:R("h-4 w-4 transition-transform",rt&&"rotate-180")})]}),e.jsxs("div",{id:"automation-advanced-settings",className:R("space-y-4",!rt&&"hidden"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-description",children:"Description"}),e.jsx(oe,{id:"scratch-description",value:D,onChange:o=>ge(o.target.value),placeholder:"What this automation does"})]}),!t&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Entity scope"}),e.jsx($n,{organizationId:n,value:p,onChange:B}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit this automation to one workspace entity."})]}),c?wt: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(k,{children:"Output fields"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Key fields become stable entity keys."})]}),e.jsx(Q,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(ye==="fields"){const o=Ht({entityType:Me,entityPath:Pe,fields:fe});if(o.error){W(o.error);return}Oe(o.keyingConfig?JSON.stringify(o.keyingConfig,null,2):""),De("json")}else De("fields");W(null)},children:ye==="fields"?"Edit JSON":"Use fields"})]}),ye==="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(k,{htmlFor:"scratch-output-entity-type",children:"Output entity type"}),e.jsx(st,{contentClassName:"w-[320px]",searchPlaceholder:"Search or type a new type…",emptyText:"Type a name to create a new entity type.",trigger:o=>e.jsxs(Q,{type:"button",variant:"outline",role:"combobox","aria-expanded":o,id:"scratch-output-entity-type",className:"w-full justify-between font-mono text-sm font-normal",children:[e.jsx("span",{className:R("truncate",!Me&&"text-muted-foreground"),children:Me||"Select entity type"}),e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(o,O)=>{const V=He(O),L=$.filter(U=>!U.backing_sql),Ee=L.some(U=>U.slug===V);return e.jsxs(e.Fragment,{children:[L.map(U=>e.jsxs(Ke,{value:`${U.name??U.slug} ${U.slug}`,onSelect:()=>{ue(U.slug),W(null),o()},className:"cursor-pointer",children:[e.jsx(tt,{className:R("mr-2 h-4 w-4",Me===U.slug?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-sm",children:U.slug}),U.name&&U.name!==U.slug&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:U.name})]})]},U.slug)),V&&!Ee&&e.jsxs(Ke,{value:O,onSelect:()=>{ue(V),W(null),o()},className:"cursor-pointer",children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"text-sm",children:["Create"," ",e.jsx("span",{className:"font-mono",children:V})]})]})]})}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-output-path",children:"Output path"}),e.jsx(oe,{id:"scratch-output-path",value:Pe,onChange:o=>{Be(o.target.value),W(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(k,{children:"Fields"}),e.jsxs(Q,{type:"button",variant:"outline",size:"sm",onClick:()=>{me(o=>[...o,as()]),W(null)},children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Add field"]})]}),fe.length===0?e.jsx("div",{className:R(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:"No output fields configured."}):e.jsx("div",{className:"space-y-2",children:fe.map(o=>e.jsxs("div",{className:R(Ie,"grid gap-2 p-3 sm:grid-cols-[minmax(0,1fr)_128px_minmax(0,240px)_auto]"),children:[e.jsx(oe,{value:o.name,onChange:O=>{const V=He(O.target.value);me(L=>L.map(Ee=>Ee.id===o.id?{...Ee,name:V}:Ee)),W(null)},placeholder:"severity","aria-label":"Output field name",className:"font-mono text-sm"}),e.jsxs(ie,{value:o.type,onValueChange:O=>{me(V=>V.map(L=>L.id===o.id?{...L,type:O}:L))},children:[e.jsx(re,{"aria-label":"Output field type",children:e.jsx(ce,{})}),e.jsx(le,{children:qn.map(O=>e.jsx(P,{value:O,children:O},O))})]}),e.jsx("div",{className:"grid grid-cols-2 rounded-md border border-input bg-background p-1",children:Kn.map(O=>e.jsx("button",{type:"button",onClick:()=>{me(V=>V.map(L=>L.id===o.id?{...L,role:O.value}:L)),W(null)},className:R("rounded-sm px-2 py-1 text-xs transition-colors",o.role===O.value?"bg-muted/70 text-foreground":"text-muted-foreground hover:text-foreground"),children:O.label},O.value))}),e.jsx(Q,{type:"button",variant:"ghost",size:"icon",onClick:()=>{me(O=>O.filter(V=>V.id!==o.id)),W(null)},"aria-label":"Remove output field",children:e.jsx(ts,{className:"h-4 w-4"})})]},o.id))})]}),de&&e.jsx("p",{className:"text-xs text-destructive",children:de})]}):e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-keying-config",children:"Keying Config (JSON)"}),e.jsx(ft,{value:ve,onChange:o=>{Oe(o),W(null)},language:"json",placeholder:'{ "entity_type": "topic", "entity_path": "$.items[*]", "key_fields": ["name"], "key_output_field": "entity_key" }',minHeight:"60px"}),de&&e.jsx("p",{className:"text-xs text-destructive",children:de})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-reactions-guidance",children:"Reactions Guidance"}),e.jsx(Bs,{id:"scratch-reactions-guidance",value:We,onChange:o=>Te(o.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:[Vn("Run settings","Choose where the automation runs and the budget it can use."),!_&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-runs-on",children:"Runs on"}),e.jsxs(ie,{value:C,onValueChange:o=>g(o),children:[e.jsx(re,{id:"scratch-runs-on",className:"text-sm",children:e.jsx(ce,{})}),e.jsxs(le,{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:C==="agent"?"Automated runs dispatch to a managed Lobu agent.":C==="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."})]}),!_&&C!=="manual"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"scratch-agent-id",children:["Agent",C==="device"&&e.jsx("span",{className:"text-destructive",children:" *"})]}),I?e.jsxs(ie,{value:w||"__unselected__",onValueChange:o=>{T(o==="__unselected__"?"":o)},children:[e.jsx(re,{id:"scratch-agent-id",className:"font-mono text-sm",children:e.jsx(ce,{placeholder:"Select a Lobu agent"})}),e.jsx(le,{children:j.map(o=>e.jsxs(P,{value:o.agentId,children:[o.name," (",o.agentId,")"]},o.agentId))})]}):e.jsx(oe,{id:"scratch-agent-id",value:w,onChange:o=>{T(o.target.value)},placeholder:"e.g., agent-123",className:"font-mono text-sm"}),C==="device"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"The device run uses this agent's memory and tools, acting as the agent's owner."})]}),!_&&C==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-device-id",children:"Device"}),e.jsxs(ie,{value:te||"__unselected__",onValueChange:o=>b(o==="__unselected__"?"":o),children:[e.jsx(re,{id:"scratch-device-id",className:"font-mono text-sm",children:e.jsx(ce,{placeholder:"Select a device worker"})}),e.jsx(le,{children:y.map(o=>e.jsx(P,{value:o.id,children:o.label||o.platform||o.id},o.id))})]})]}),!_&&C==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-device-agent-kind",children:"Runs as"}),e.jsxs(ie,{value:G||"__default__",onValueChange:o=>se(o==="__default__"?"":o),children:[e.jsx(re,{id:"scratch-device-agent-kind",className:"text-sm",children:e.jsx(ce,{placeholder:"Device default"})}),e.jsxs(le,{children:[e.jsx(P,{value:"__default__",children:"Device default"}),In.map(o=>e.jsx(P,{value:o.value,children:o.label},o.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(k,{children:"Model"}),e.jsx(an,{value:Ve,onChange:o=>{Ye(o),M(null)},placeholder:"Use agent default"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-timeout",children:"Timeout seconds"}),e.jsx(oe,{id:"scratch-timeout",type:"number",min:1,max:86400,value:nt,onChange:o=>{Ce(o.target.value),M(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(k,{htmlFor:"scratch-permission-mode",children:"Permission mode"}),e.jsxs(ie,{value:ze||"__default__",onValueChange:o=>{it(o==="__default__"?"":o),M(null)},children:[e.jsx(re,{id:"scratch-permission-mode",children:e.jsx(ce,{placeholder:"Default"})}),e.jsxs(le,{children:[e.jsx(P,{value:"__default__",children:"Default"}),ht.map(o=>e.jsx(P,{value:o.value,children:o.label},o.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-effort",children:"Effort"}),e.jsx(oe,{id:"scratch-effort",value:Le,onChange:o=>{l(o.target.value),M(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(k,{htmlFor:"scratch-finalize-nudges",children:"Finalize nudges"}),e.jsx(oe,{id:"scratch-finalize-nudges",type:"number",min:0,max:5,value:v,onChange:o=>{F(o.target.value),M(null)},placeholder:"Default"})]})]}),ee&&e.jsx("p",{className:"text-xs text-destructive",children:ee})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-tags",children:"Tags"}),e.jsx(oe,{id:"scratch-tags",value:je,onChange:o=>A(o.target.value),placeholder:"ops, support, risk"})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-change-notes",children:"Change notes"}),e.jsx(oe,{id:"scratch-change-notes",value:Re,onChange:o=>Ue(o.target.value),placeholder:"What changed in this version?"})]})]})]}),u&&!de&&!ee&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:u}),e.jsx(pt,{onCancel:a,children:e.jsx(Q,{onClick:hs,disabled:!St||d||S,children:d?e.jsxs(e.Fragment,{children:[e.jsx(Ws,{size:"lg",className:"mr-2"}),c?"Saving...":"Creating..."]}):c?"Save Automation":m})})]})}function Un(n,t){const s=n??null,r=t??null;return s===null||r===null?s===r:s.connection_id===r.connection_id&&s.channel_id===r.channel_id}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,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,outputs:t.outputs}}function aa({startFromScratch:n=!1,onClose:t,hideCancel:s=!1,hideHeader:r=!1,organizationId:d,entityId:u,entityName:c,prefillAgentId:a,onSuccess:x,editingAutomation:m,catalogPrefill:S,onDraft:f,triggerFields:I,submitLabel:h,submitDisabled:j,createFields:y,onPrefillTriggers:w}){const T=Vs(),_=zs(),q=Us(),N=Qs(),K=!!m,[Y,te]=i.useState(n?"scratch":"template"),[b,C]=i.useState(void 0),[g,G]=i.useState(void 0),{data:se=[],isLoading:$}=Gs(),[z,X]=i.useState(""),he=i.useMemo(()=>a?{managed_agent_id:a}:void 0,[a]),xe=i.useMemo(()=>se.map(p=>({key:p.id,name:p.name,description:p.description??"",badges:p.detail?.tags??[]})),[se]),ke=i.useMemo(()=>xe.filter(p=>p.name.toLowerCase().includes(z.toLowerCase())||p.description.toLowerCase().includes(z.toLowerCase())),[xe,z]),be=p=>{const B=se.find(pe=>pe.id===p.key);if(!B)return;const H=Qn(B);G(a?{...H,managed_agent_id:a}:H),w?.(H.triggers??[]),te("scratch")},D=()=>{T.reset(),_.reset(),te("template"),C(void 0),G(void 0),t()},ge=K?y?.triggers??m.triggers??[]:y?.triggers??g?.triggers??S?.triggers??[],ne=async p=>{try{if(f){await f(p);return}if(K){const B=y?.triggers??m.triggers??[],H=m.reaction_script??"",pe=p.reaction_script??"";pe&&pe!==H&&await q.mutateAsync({automation_id:m.automation_id,reaction_script:pe}),await _.mutateAsync({automation_id:m.automation_id,name:p.name,description:p.description,prompt:p.prompt,sources:p.sources,set_as_current:!0,triggers:B,keying_config:p.keying_config,reactions_guidance:p.reactions_guidance,change_notes:p.change_notes}),!pe&&H&&await q.mutateAsync({automation_id:m.automation_id,reaction_script:""});const E={};p.model_config!==void 0&&(E.model_config=p.model_config),p.execution_config!==void 0&&(E.execution_config=p.execution_config),p.tags!==void 0&&(E.tags=p.tags),p.delivery_target!==void 0&&!Un(p.delivery_target,m.delivery_target)&&(E.delivery_target=p.delivery_target),p.managed_agent_id!==void 0&&(E.managed_agent_id=p.managed_agent_id||null),p.agent_kind!==void 0&&(E.agent_kind=p.agent_kind||null),p.device_worker_id!==void 0&&(E.device_worker_id=p.device_worker_id||null),Object.keys(E).length>0&&await N.mutateAsync({automation_id:m.automation_id,...E}),D(),x?.(m.automation_id)}else{const B=y?.triggers??g?.triggers??S?.triggers??[],H=await T.mutateAsync({...p,managed_agent_id:p.managed_agent_id??void 0,device_worker_id:p.device_worker_id??void 0,agent_kind:p.agent_kind??void 0,delivery_target:p.delivery_target??void 0,triggers:B});D(),H.automation_id&&x?.(H.automation_id)}}catch{}},Z=K?_:T;let J="Add an automation";K?J="Edit automation configuration (saves as a new version)":c&&(J=`Add an automation for ${c}`);const ae=m?{entity_id:m.entity_id,name:m.name,slug:m.slug,description:m.description,prompt:m.prompt,sources:m.sources,reaction_script:m.reaction_script,device_worker_id:m.device_worker_id??void 0,agent_kind:m.agent_kind??void 0,keying_config:m.keying_config,reactions_guidance:m.reactions_guidance,model_config:m.model_config,execution_config:m.execution_config,tags:m.tags,managed_agent_id:m.managed_agent_id??void 0,delivery_target:m.delivery_target??void 0}:void 0,Se=K?"Edit Automation":"Create Automation",Fe=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:J})]}),we=e.jsxs("div",{className:"py-6 space-y-6",children:[!K&&e.jsxs("div",{className:"flex flex-wrap justify-start gap-2",children:[e.jsx(gt,{active:Y==="template",onClick:()=>te("template"),icon:e.jsx(Js,{className:"h-4 w-4"}),label:"From templates"}),e.jsx(gt,{active:Y==="scratch",onClick:()=>{te("scratch"),C(void 0),G(void 0)},icon:e.jsx(Je,{className:"h-4 w-4"}),label:"From scratch"}),e.jsx(gt,{active:Y==="clone",onClick:()=>te("clone"),icon:e.jsx(Hs,{className:"h-4 w-4"}),label:"Clone existing"})]}),!K&&Y==="template"?e.jsxs(e.Fragment,{children:[$?e.jsx(Ys,{}):e.jsx(Xs,{items:ke,searchQuery:z,onSearchChange:X,onSelect:be,searchPlaceholder:"Search templates...",searchAriaLabel:"Search automation templates",emptyMessage:xe.length===0?"No automation templates available.":void 0}),r&&!s?e.jsx(pt,{onCancel:D}):null]}):!K&&Y==="clone"&&!b?e.jsxs(e.Fragment,{children:[e.jsx(Gn,{organizationId:d,onSelect:p=>{C(p),w?.(p.triggers??[]),te("scratch")}}),r&&!s?e.jsx(pt,{onCancel:D}):null]}):e.jsx(zn,{organizationId:d,entityId:u,prefill:ae??b??g??S??he,onSubmit:ne,isSubmitting:Z.isPending,error:Z.error?Z.error.message:null,isEditing:K,onCancel:s?void 0:D,triggerFields:I,submitLabel:h,submitDisabled:j,triggers:ge})]});return e.jsxs("div",{className:"flex flex-col",children:[r?null:Fe,we]})}function gt({active:n,onClick:t,icon:s,label:r}){return e.jsxs("button",{type:"button",onClick:t,className:R("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,r]})}function Gn({organizationId:n,onSelect:t}){const{data:s,isLoading:r}=Zs(n),[d,u]=i.useState(""),c=(s||[]).filter(a=>a.name?.toLowerCase().includes(d.toLowerCase()));return r?e.jsx(en,{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:d,onChange:a=>u(a.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(a=>e.jsxs("button",{type:"button",onClick:()=>t({name:`${a.name} (copy)`,slug:`${a.slug||a.automation_id}-copy`,prompt:a.prompt,keying_config:a.keying_config,triggers:a.triggers,sources:a.sources,outputs:a.outputs}),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:a.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[a.entity_name||"Space-level"," · v",a.version??"?"]})]},a.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{na as A,aa as C};
|
|
3
|
-
//# sourceMappingURL=create-automation-form-
|
|
1
|
+
import{r as i,j as e,bp as ie,bq as re,br as ce,bs as le,bt as D,I as oe,B as Q,X as Yt,d7 as gs,cg as ps,cB as Zt,gM as fs,gN as vs,S as Ct,z as k,Q as R,af as Ie,ed as Et,ef as ys,eg as js,fT as _s,d$ as es,eh as Ns,eS as ks,b0 as Ft,gO as bs,eE as st,cF as Ke,dy as tt,eG as yt,a$ as ts,cT as Je,ch as Ss,W as ws,J as Cs,ci as Es,gP as Fs,gQ as As,gR as Os,gS as Ts,gT as Ms,P as Ds,L as Ps,n as ss,gJ as Ls,a_ as Rs,aA as $s,f3 as At,gj as Is,gU as qs,b_ as Ks,fN as Ws,bA as pt,a2 as Bs,gV as zs,gW as Vs,gX as Us,gY as Qs,gZ as Gs,g_ as Js,g$ as Hs,h0 as Xs,h1 as Ys,b1 as Zs,bz as en}from"./index-DYCqXaMf.js";import{c as tn}from"./cronstrue-BWFEyy_P.js";import{C as sn,f as nn}from"./entity-options-DHdMC1Lx.js";import{M as an}from"./model-selector-TQcA93xm.js";import{b as on}from"./skill-editor-D_W3QlRz.js";import{C as ft}from"./code-editor-U54Gwjit.js";import{u as rn,b as Ot,c as Tt,s as cn,o as ln,M as dn,d as un,e as mn,f as hn,v as xn,r as gn}from"./use-mention-search-BYbFvHbJ.js";const Ze=[{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 pn(n){const t=n.trim();if(!t)return null;try{return tn.toString(t,{throwExceptionOnParseError:!0})}catch{return null}}function fn({value:n,onChange:t,placeholder:s="No schedule",className:r}){const d=n??"",u=Ze.some(f=>f.value===d),[c,a]=i.useState(!u&&d!==""),x=f=>{f==="custom"?a(!0):(a(!1),t(f))},m=d?pn(d):null,S=d?e.jsx("p",{className:m?"text-xs text-muted-foreground":"text-xs text-destructive",children:m??"Not a valid cron expression."}):null;return!d&&!c?e.jsxs(ie,{onValueChange:x,children:[e.jsx(re,{className:r??"w-full",children:e.jsx(ce,{placeholder:s})}),e.jsx(le,{children:Ze.map(f=>e.jsxs(D,{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(oe,{placeholder:"0 */6 * * *",value:d,onChange:f=>t(f.target.value),className:"font-mono text-sm flex-1"}):e.jsxs(ie,{value:d,onValueChange:x,children:[e.jsx(re,{className:r??"w-full flex-1",children:e.jsx(ce,{children:Ze.find(f=>f.value===d)?.label??d})}),e.jsx(le,{children:Ze.map(f=>e.jsxs(D,{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(Q,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",onClick:()=>{a(!1),t("")},children:e.jsx(Yt,{className:"h-4 w-4"})})]}),S]})}const dt="__all_workspace_event_types__",vn=[],yn={};function Mt(n,t,s){const r=new Map;if(!t)for(const[u,c]of Object.entries(s??{}))r.set(u,{key:u,label:Ft(u),description:c.description});const d=[...n].filter(u=>!t||u.slug===t).sort((u,c)=>u.slug.localeCompare(c.slug));for(const u of d)for(const[c,a]of Object.entries(u.event_kinds??{})){const x=r.get(c);if(x){!x.description&&a.description&&(x.description=a.description),JSON.stringify(x.metadataSchema??null)!==JSON.stringify(a.metadataSchema??null)&&(x.metadataSchema=void 0);continue}r.set(c,{key:c,label:Ft(c),description:a.description,metadataSchema:a.metadataSchema})}return[...r.values()].sort((u,c)=>u.label.localeCompare(c.label))}function Dt(n){const t=n[0];if(!t)return;const s=d=>JSON.stringify(Object.keys(d?.properties??{}).sort()),r=s(t);return n.every(d=>s(d)===r)?t:void 0}function Pt(n,t,s){const r=new Set(Object.keys(t.properties??{}));return{...Object.fromEntries(Object.entries(n).filter(([d])=>!r.has(d))),...s}}function $e(n,t,s){return s==="steer"&&(n==="window"||t!=="reply_to_source")?"coalesce":s}function Qe(n,t){return n==="window"?"silent":t}function Lt(n){return Object.fromEntries(Object.entries(n).filter(([t])=>t==="resource_ref"||t==="resource_type"))}function Rt(n,t,s){const r=new Set(Object.keys(t?.properties??{})),d=new Set(s.flatMap(u=>Object.keys(u.filterSchema?.properties??{})));return Object.fromEntries(Object.entries(bs(n)).filter(([u])=>u==="resource_ref"||u==="resource_type"||!d.has(u)||r.has(u)))}function jn({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(r=>e.jsx("button",{type:"button","aria-pressed":n===r.value,onClick:()=>s(r.value),className:R("rounded px-3 py-1 transition-colors",n===r.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:r.label},r.value))})}function $t({events:n,selectedKeys:t,onToggle:s,ariaLabel:r="Events"}){const d=i.useId(),u=n.filter(a=>t.includes(a.key)).map(a=>a.label),c=u.length===0?"Choose events":u.length===1?u[0]:`${u.length} events selected`;return e.jsx(st,{contentClassName:"w-[var(--radix-popover-trigger-width)] min-w-[280px]",searchPlaceholder:"Filter events...",emptyText:"No events found.",trigger:a=>e.jsxs(Q,{type:"button",variant:"outline",role:"combobox","aria-label":r,"aria-expanded":a,className:"w-full justify-between font-normal",children:[e.jsx("span",{className:R(u.length===0&&"text-muted-foreground"),children:c}),e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>n.map((a,x)=>{const m=t.includes(a.key),S=`${d}-${x}-state`;return e.jsxs(Ke,{value:`${a.label} ${a.key}`,onSelect:()=>s(a.key),"aria-label":a.label,"aria-describedby":S,className:"cursor-pointer",children:[e.jsx(tt,{className:R("mr-2 h-4 w-4",m?"opacity-100":"opacity-0")}),a.label,e.jsx("span",{id:S,className:"sr-only",children:m?"Selected":"Not selected"})]},a.key)})})}function _n({organizationId:n,initialTrigger:t,onChange:s,allowedKinds:r,showSectionHeader:d=!0,fieldIdPrefix:u="automation-trigger-"}){const c=gs(n,{status:"active",limit:500}),a=ps(n),x=Zt({organizationId:n}),m=fs({organizationId:n}),S=c.data??[],f=a.data??[],I=x.data??vn,h=m.data??yn,j=i.useMemo(()=>I.filter(l=>l.organization_id===n),[I,n]),y=t?.kind==="event"&&t?.source==="workspace",w=y||t===void 0,P=r?.length?[...r]:["event","time","manual"],_=P.join("|"),q=(()=>{const l=t===null?"manual":t?.kind==="schedule"?"time":"event";return P.includes(l)?l:P[0]??"event"})(),[N,K]=i.useState(q),[X,te]=i.useState(y?"workspace":typeof t?.connection_id=="number"?String(t.connection_id):t?.kind==="event"&&t.connector_key?"":"workspace"),b=X==="workspace",C=b?"":X,[g,G]=i.useState(typeof t?.entity_type=="string"?t.entity_type:""),se=i.useMemo(()=>Array.isArray(t?.event_types)?t.event_types:[],[t]),[$,V]=i.useState(()=>se.filter(l=>typeof l=="string")),[Y,he]=i.useState(t?.match&&typeof t.match=="object"&&!Array.isArray(t.match)?t.match:{}),[xe,ke]=i.useState(typeof t?.cron=="string"?t.cron:"0 9 * * 1-5"),be=typeof t?.timezone=="string"?t.timezone:void 0,[M,ge]=i.useState(t?.kind==="schedule"||w&&t?.execution!=="turn"||t?.execution==="window"?"window":"turn"),[ne,Z]=i.useState(Qe(M,t?.output==="reply_to_source"?"reply_to_source":"silent")),[J,ae]=i.useState(t?.kind==="schedule"||w&&t?.active_run!=="queue"?"coalesce":$e(M,ne,t?.active_run==="coalesce"||t?.active_run==="steer"?t.active_run:"queue")),[Se,Fe]=i.useState(t?.skip_if_unchanged!==!1),[we,p]=i.useState(!1);i.useEffect(()=>{const l=_.split("|");if(!l.includes(N)){const v=l[0]??"event";K(v),ge(v==="time"||v==="event"&&b?"window":"turn"),ae(v==="time"||v==="event"&&b?"coalesce":"queue"),Z("silent")}},[_,N,b]);const W=S.find(l=>String(l.id)===C),H=c.isLoading||a.isLoading,pe=x.isLoading,E=typeof t?.connector_key=="string"?t.connector_key:void 0,Ae=N==="event"&&!b&&t?.kind==="event"&&t?.source!=="workspace"&&typeof t.connection_id=="number"&&String(t.connection_id)===C&&!W,ve=N==="event"&&!b&&t?.kind==="event"&&t?.source!=="workspace"&&t.connection_id==null&&E!==void 0&&C==="",Oe=f.find(l=>l.key===(W?.connector_key??(ve?E:void 0))),de=Oe?.automation_events??[],B=de.filter(l=>$.includes(l.key)),ye=B[0],Me=j.find(l=>l.slug===g),Te=[...j.filter(l=>Object.keys(l.event_kinds??{}).length>0||l.slug===g),...g&&!Me?[{slug:g,name:g}]:[]],ue=i.useMemo(()=>Mt(j,g||void 0,h),[j,g,h]),De=ue.filter(l=>$.includes(l.key)),We=De[0],fe=Dt(B.map(l=>l.filterSchema)),me=Dt(De.map(l=>l.metadataSchema)),Be=!!(b&&g&&!Me),Pe=Ae||ve,Ce=(N==="event"?b?$.length>0&&!Be:!!($.length>0&&(C&&W||Pe)):N==="time"?!!xe.trim():!0)&&(N!=="event"||!vs(Y));i.useEffect(()=>{let l;if(Ce&&N==="event"&&!b){const v=Rt(Y,fe,Oe?.automation_events??[]);W||ve?l={kind:"event",source:"connector",connector_key:W?.connector_key??E,...W?{connection_id:Number(C)}:{},event_types:$,...Object.keys(v).length>0?{match:v}:{},execution:M,active_run:$e(M,ne,J),output:Qe(M,ne),skip_if_unchanged:Se}:Ae&&(l=t?{...t,source:"connector"}:void 0)}else if(Ce&&N==="event"&&b){const v=Rt(Y,me,ue.map(F=>({filterSchema:F.metadataSchema})));l={kind:"event",source:"workspace",...g?{entity_type:g}:{},event_types:$,...Object.keys(v).length>0?{match:v}:{},execution:M,active_run:J==="queue"?"queue":"coalesce"}}else Ce&&N==="time"&&(l={kind:"schedule",cron:xe.trim(),...be?{timezone:be}:{},execution:"window",active_run:"coalesce",skip_if_unchanged:Se});s({ready:Ce,kind:N,trigger:l})},[J,C,W,xe,Oe,$,M,Y,N,E,be,t,b,s,ne,Ce,fe,me,Se,g,ue,ve,Ae]);const at=l=>{const v=S.find(A=>String(A.id)===l),F=f.find(A=>A.key===v?.connector_key),ee=$.filter(A=>F?.automation_events?.some(Re=>Re.key===A)),T=F?.automation_events?.find(A=>A.key===ee[0]),je=v?.connector_key!==(W?.connector_key??E);if(te(l),V(ee),!T)he(Lt);else if(je){const A=T.defaults?.execution??"turn",Re=T.defaults?.activeRun??"queue",Ue=Qe(A,T.defaults?.output??"silent");he(Lt),ge(A),ae($e(A,Ue,Re)),Z(Ue)}},ot=l=>{if(l==="workspace"){te("workspace"),V(v=>v.filter(F=>ue.some(ee=>ee.key===F))),he({}),ge("window"),ae("coalesce"),Z("silent");return}at(l)},ze=l=>{const v=$.includes(l)?$.filter(A=>A!==l):de.map(A=>A.key).filter(A=>A===l||$.includes(A));if(V(v),v[0]===$[0])return;const F=de.find(A=>A.key===v[0]),ee=F?.defaults?.execution??"turn",T=F?.defaults?.activeRun??"queue",je=Qe(ee,F?.defaults?.output??"silent");ge(ee),ae($e(ee,je,T)),Z(je)},Xe=l=>{const v=l===dt?"":l,F=j.find(T=>T.slug===v),ee=Mt(j,F?.slug,h);G(v),V(T=>T.filter(je=>ee.some(A=>A.key===je))),he({})},Ve=l=>{V(v=>v.includes(l)?v.filter(F=>F!==l):ue.map(F=>F.key).filter(F=>F===l||v.includes(F)))},Le=[{value:"event",label:"Event"},{value:"time",label:"Schedule"},{value:"manual",label:"Manual"}].filter(l=>P.includes(l.value));return e.jsxs("div",{className:"space-y-4",children:[d?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,Le.length>1?e.jsx(jn,{value:N,options:Le,onChange:l=>{K(l),ge(l==="time"||l==="event"&&b?"window":"turn"),ae(l==="time"||l==="event"&&b?"coalesce":"queue"),Z("silent")}}):null,N==="event"?H||b&&pe?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ct,{className:"h-9 w-full"}),e.jsx(Ct,{className:"h-9 w-full"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Source"}),e.jsx(sn,{connections:S,value:X,onValueChange:ot,disabled:Pe,includeWorkspaceEvents:!0,ariaLabel:"Source",placeholder:"Choose a source"}),Ae?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."}):ve?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]}),b?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:ue.length>1?"Events":"Event"}),ue.length>0?e.jsx($t,{events:ue,selectedKeys:$,onToggle:Ve}):e.jsx("div",{className:R(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:g?"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 “",g,"”, 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."})]}),me?e.jsx(Et,{schema:me,values:Y,onValuesChange:l=>he(v=>Pt(v,me,l)),fieldIdPrefix:`${u}workspace-`},`${g||"workspace"}:${$.join(",")}`):null]}):W||ve?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:de.length>1?"Events":"Event"}),de.length?e.jsx($t,{events:de,selectedKeys:$,onToggle:ze}):e.jsx("div",{className:R(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:"This connector has not published subscribable events."}),ye?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:ye.description}):null]}),typeof Y.resource_ref=="string"||fe?e.jsxs("div",{className:"space-y-3",children:[typeof Y.resource_ref=="string"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Resource"}),e.jsx("div",{className:R(Ie,"px-3 py-2 text-sm"),children:Y.resource_ref})]}):null,fe?e.jsx(Et,{schema:fe,values:Y,onValuesChange:l=>he(v=>Pt(v,fe,l)),fieldIdPrefix:u},$.join(",")):null]}):null]}):X?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose workspace events or a connected app as the source."})]}):N==="time"?e.jsx(fn,{value:xe,onChange:ke}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this Automation explicitly from Lobu, the API, CLI, or MCP."}),N!=="manual"&&!Pe?e.jsxs(ys,{open:we,onOpenChange:p,children:[e.jsx(js,{asChild:!0,children:e.jsxs(Q,{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(_s,{className:"h-4 w-4"}),"Trigger options",e.jsxs("span",{className:"font-normal text-muted-foreground",children:["· ",M==="turn"?"Each event":"Window"," ·"," ",N==="time"?"Combine":b?J==="queue"?"Queue":"Combine":J==="queue"?"Queue":J==="coalesce"?"Combine":"Update current run",N==="event"&&!b?` · ${M==="turn"&&ne==="reply_to_source"?"Reply":"Save in Lobu"}`:""]})]}),e.jsx(es,{className:R("h-4 w-4 transition-transform",we&&"rotate-180")})]})}),e.jsxs(Ns,{className:"space-y-4 pt-3",children:[N==="event"&&b?e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Entity type filter"}),e.jsxs(ie,{value:g||dt,onValueChange:Xe,children:[e.jsx(re,{"aria-label":"Entity type filter",children:e.jsx(ce,{})}),e.jsxs(le,{children:[e.jsx(D,{value:dt,children:"All event types"}),Te.map(l=>e.jsx(D,{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,N==="event"?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Run"}),e.jsxs(ie,{value:M,onValueChange:l=>{const v=l,F=Qe(v,ne);ge(v),Z(F),ae($e(v,F,J))},children:[e.jsx(re,{children:e.jsx(ce,{})}),e.jsxs(le,{children:[e.jsx(D,{value:"turn",children:"Start a run for each event"}),e.jsx(D,{value:"window",children:"Batch events into a window"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"When busy"}),e.jsxs(ie,{value:J,onValueChange:l=>ae(l),children:[e.jsx(re,{children:e.jsx(ce,{})}),e.jsxs(le,{children:[e.jsx(D,{value:"queue",children:"Queue"}),e.jsx(D,{value:"coalesce",children:"Combine waiting events"}),!b&&M==="turn"&&ne==="reply_to_source"&&ye?.capabilities?.steering?e.jsx(D,{value:"steer",children:"Update the current run"}):null]})]})]})]}):null,M==="window"&&(N==="time"||!b)?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(ks,{"aria-label":"Skip unchanged windows",checked:Se,onCheckedChange:Fe})]}):null,N==="event"&&!b&&M==="turn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Result"}),e.jsxs(ie,{value:ne,onValueChange:l=>{const v=l;Z(v),ae($e(M,v,J))},children:[e.jsx(re,{children:e.jsx(ce,{})}),e.jsxs(le,{children:[ye?.capabilities?.replyToSource?e.jsx(D,{value:"reply_to_source",children:"Reply where it happened"}):null,e.jsx(D,{value:"silent",children:"Save in Lobu"})]})]}),ye?.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 Nn=16;function qe(){return crypto.randomUUID()}function kn(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 ns(n){return n?n.kind==="time"||n.trigger?.kind==="schedule":!1}function bn(n,t){return n?n.ready===t.ready&&n.kind===t.kind&&JSON.stringify(n.trigger)===JSON.stringify(t.trigger):!1}function Sn(n,t){const s=n.map(a=>t[a.key]??{ready:!1,kind:"event"});if(!(n.length>1)&&s[0]?.kind==="manual")return{ready:s[0].ready,triggers:[]};const d=s.filter(ns).length;return{ready:!s.some(a=>a.kind==="manual")&&d<=1&&s.length>0&&s.every(a=>a.ready&&a.trigger),triggers:s.filter(a=>a.trigger).map(a=>a.trigger)}}function na({organizationId:n,initialTriggers:t,onChange:s}){const r=i.useId(),[d,u]=i.useState(()=>kn(t)),[c,a]=i.useState({}),x=i.useRef("");i.useEffect(()=>{const h=Sn(d,c),j=JSON.stringify(h);j!==x.current&&(x.current=j,s(h))},[d,c,s]);const m=d.find(h=>ns(c[h.key]))?.key??d.find(h=>h.initial&&typeof h.initial=="object"&&h.initial.kind==="schedule"&&!c[h.key])?.key??null,S=i.useCallback((h,j)=>{a(y=>bn(y[h],j)?y:{...y,[h]:j})},[]),f=()=>{const h=d[0],j=h?c[h.key]:void 0;if(d.length===1&&(j?.kind==="manual"||h?.initial===null)){const y=qe();a({}),u([{key:y,initial:void 0}]);return}u(y=>[...y,{key:qe(),initial:void 0}])},I=h=>{if(d.length<=1){const j=qe();a({}),u([{key:j,initial:null}]);return}a(j=>{const y={...j};return delete y[h],y}),u(j=>j.filter(y=>y.key!==h))};return e.jsxs("section",{className:"space-y-4","aria-labelledby":`${r}-heading`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{id:`${r}-heading`,className:"text-sm font-medium",children:"When"}),d.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:d.map((h,j)=>{const y=d.length>1,w=y?m&&m!==h.key?["event"]:["event","time"]:["event","time","manual"],P=c[h.key],_=y||(P?P.kind!=="manual":h.initial!==null);return e.jsxs("div",{className:R("space-y-3 rounded-lg border bg-card/40 p-3",y&&"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:y?`Trigger ${j+1}`:"Trigger"}),_?e.jsx(Q,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive","aria-label":y?`Remove trigger ${j+1}`:"Clear trigger",onClick:()=>I(h.key),children:e.jsx(ts,{className:"h-3.5 w-3.5"})}):null]}),e.jsx(wn,{slotKey:h.key,organizationId:n,initial:h.initial,kinds:w,fieldIdPrefix:`${r}-${h.key}-`,onChange:S})]},h.key)})}),e.jsxs(Q,{type:"button",variant:"outline",size:"sm",className:"w-full sm:w-auto",onClick:f,disabled:d.length>=Nn,children:[e.jsx(Je,{className:"mr-1.5 h-3.5 w-3.5"}),"Add another trigger"]})]})}function wn({slotKey:n,organizationId:t,initial:s,kinds:r,fieldIdPrefix:d,onChange:u}){const c=i.useCallback(a=>u(n,a),[u,n]);return e.jsx(_n,{organizationId:t,initialTrigger:s,allowedKinds:r,showSectionHeader:!1,fieldIdPrefix:d,onChange:c})}const Cn=["claude-code","codex","opencode","pi","agy"],En={"claude-code":"Claude Code",codex:"Codex",opencode:"OpenCode",pi:"Pi",agy:"Antigravity (agy)"},Fn=[{kind:"claude-code",binaryName:"claude",promptDelivery:{kind:"flag",flag:"-p"},mcpDelivery:{kind:"claude-config-file",flag:"--mcp-config",extraArgs:["--strict-mcp-config","--allowedTools","mcp__lobu__query_sdk,mcp__lobu__run_sdk"]},headlessArgs:[],modelFlag:"--model",effortFlag:"--effort",permissionModeFlag:"--permission-mode",budgetFlag:"--max-budget-usd",timeoutFlag:null,trailingArgs:[]},{kind:"agy",binaryName:"agy",promptDelivery:{kind:"flag",flag:"-p"},mcpDelivery:{kind:"none"},headlessArgs:["--dangerously-skip-permissions"],modelFlag:"--model",effortFlag:"--effort",permissionModeFlag:null,budgetFlag:null,timeoutFlag:{flag:"--print-timeout",suffix:"s"},trailingArgs:[]},{kind:"opencode",binaryName:"opencode",promptDelivery:{kind:"positional",subcommand:["run"]},mcpDelivery:{kind:"opencode-config-env",variable:"OPENCODE_CONFIG_CONTENT"},headlessArgs:["--auto","--print-logs","--log-level","ERROR"],modelFlag:"-m",effortFlag:"--variant",permissionModeFlag:null,budgetFlag:null,timeoutFlag:null,trailingArgs:[]},{kind:"codex",binaryName:"codex",promptDelivery:{kind:"positional",subcommand:["exec"]},mcpDelivery:{kind:"none"},headlessArgs:["--skip-git-repo-check","--sandbox","workspace-write","-c","sandbox_workspace_write.network_access=true"],modelFlag:"-m",effortFlag:"-c",effortConfigKey:"model_reasoning_effort",permissionModeFlag:null,budgetFlag:null,timeoutFlag:null,trailingArgs:[]},{kind:"pi",binaryName:"pi",promptDelivery:{kind:"positional",subcommand:[]},mcpDelivery:{kind:"none"},headlessArgs:["-p","--no-session","--tools","read,bash,edit,write"],modelFlag:"--model",effortFlag:"--thinking",permissionModeFlag:null,budgetFlag:null,timeoutFlag:null,trailingArgs:[]}];new Map(Fn.map(n=>[n.kind,n]));const It={agents:!0,lobuEmbedded:!1};function An(){const{data:n}=Ss({queryKey:["features"],queryFn:async()=>{const t=await ws(`${Cs}/api/features`);return t.ok?t.json():It},staleTime:3e4,refetchInterval:6e4});return n??It}const qt=["slack","imessage"],ut="__none__";function Ge(n){return`${n.connection_id}:${n.feed_key}`}function On(n){const t=n.indexOf(":");if(t<=0)return null;const s=Number(n.slice(0,t)),r=n.slice(t+1);return!Number.isSafeInteger(s)||s<=0||!r?null:{connection_id:s,channel_id:r}}function mt(n){return n?`${n.connection_id}:${n.channel_id}`:""}function et(n){return`${n.display_name||n.feed_key} (${n.feed_key})`}function Tn({organizationId:n,agentId:t,value:s,onChange:r,disabled:d=!1,automationName:u,onPendingChange:c}){const{data:a=[],isLoading:x}=Es(n),m=mt(s),[S,f]=i.useState(null),[I,h]=i.useState(!1),j=i.useRef(t),y=i.useMemo(()=>a.filter(g=>g.store==="channel_messages"&&g.target_agent_id===t&&qt.includes(g.connector_key)),[a,t]);i.useEffect(()=>{if(j.current===t||(j.current=t,f(null),h(!1),s==null))return;const g=mt(s);if(g==="")return;a.some(se=>se.store==="channel_messages"&&se.target_agent_id===t&&qt.includes(se.connector_key)&&Ge(se)===g)||r(null)},[t,a,s,r]);const w=S??m,P=w===""?ut:w,_=y.find(g=>Ge(g)===w),q=S!==null&&S!==""&&S!==m;i.useEffect(()=>{c?.(q)},[q,c]);const N=_??(S?void 0:y.find(g=>Ge(g)===m)),K=g=>{const G=g===ut?"":g;if(G===""){f(null),h(!1),r(null);return}if(G===m){f(null),h(!1);return}f(G),h(!1)},X=g=>{if(h(g),g&&S){const G=On(S);G&&(f(null),r(G))}else!g&&S&&f(null)},b=(s&&mt(s)!==""?s:void 0)??(_?{connection_id:_.connection_id,channel_id:_.feed_key}:void 0),C=(u??"").trim()||"This automation";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"automation-delivery-target",children:["Digest destination"," ",e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),t?e.jsxs(ie,{value:P,onValueChange:K,disabled:d||x,children:[e.jsx(re,{id:"automation-delivery-target",className:"font-mono text-sm",children:e.jsx(ce,{placeholder:x?"Loading bound channels…":y.length===0?"No bound Slack or iMessage channels":"No digest — runs stay silent"})}),e.jsxs(le,{children:[e.jsx(D,{value:ut,children:"No digest — runs stay silent"}),y.map(g=>e.jsxs(D,{value:Ge(g),children:[et(g)," · ",g.connector_key]},Ge(g)))]})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select a managed agent first — only channels bound to that agent can receive digests."}),t&&!x&&y.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No Slack or iMessage channels are bound to this agent yet. Link a private channel first, then select it here."}):null,q&&_?e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-xs",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:g=>X(g.target.checked),className:"mt-0.5","aria-label":`Confirm digest delivery to ${et(_)}`}),e.jsxs("span",{className:"text-muted-foreground",children:["I confirm posting material-change digests to"," ",e.jsx("span",{className:"font-medium text-foreground",children:et(_)}),". Destination changes are audited."]})]}):null,N||b?e.jsxs("div",{className:R(Ie,"space-y-1.5 px-3 py-2"),children:[e.jsxs("p",{className:"text-xs font-medium",children:["Digest preview →"," ",e.jsx("span",{className:"font-mono font-normal",children:N?`${N.connector_key} ${et(N)} · connection ${N.connection_id}`:`${b?.channel_id} · connection ${b?.connection_id}`})]}),e.jsxs("p",{className:"font-mono text-xs",children:[C," applied 2 new + 1 updated"]}),e.jsx("p",{className:"whitespace-pre-line font-mono text-xs text-muted-foreground",children:`+ Example task (#12)
|
|
2
|
+
~ Follow-up item (#34)`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sends only after a successful run with material changes. Runs with zero changes send nothing. Retries reuse the same notification and delivery receipts dedupe channel posts, but provider acceptance with a lost receipt can still duplicate."})]}):null]})}const Kt=4096;function Mn({open:n,onOpenChange:t,initial:s,onSubmit:r}){const[d,u]=i.useState(""),[c,a]=i.useState(""),[x,m]=i.useState(null);i.useEffect(()=>{n&&(u(s?.name??""),a(s?.query??""),m(null))},[n,s]);const S=()=>{const I=d.trim(),h=c.trim();if(!I){m("Give the SQL source a name.");return}if(!h){m("Enter a query.");return}if(h.length>Kt){m(`Query is too long (${h.length} chars, max ${Kt}).`);return}r({name:I,query:h}),t(!1)},f=!!s;return e.jsx(Fs,{open:n,onOpenChange:t,children:e.jsxs(As,{className:"max-w-2xl",children:[e.jsxs(Os,{children:[e.jsx(Ts,{children:f?"Edit SQL source":"SQL source"}),e.jsx(Ms,{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(k,{htmlFor:"sql-source-name",children:"Name"}),e.jsx(oe,{id:"sql-source-name",value:d,onChange:I=>u(I.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(k,{htmlFor:"sql-source-query",children:"Query"}),e.jsx(ft,{value:c,onChange:a,language:"sql",placeholder:"SELECT id, payload_text, occurred_at FROM events ORDER BY occurred_at DESC",minHeight:"160px"})]}),x?e.jsx("p",{className:"text-sm text-destructive",children:x}):null]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(Q,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(Q,{onClick:S,children:f?"Save":"Add source"})]})]})})}const Dn=["skill","feed","connection","connector","metric","entity_type"];function Pn({value:n,onChange:t,library:s,pinned:r,required:d,error:u,owner:c,agentId:a,sources:x,onAddSources:m}){const S=rn(Dn,Ot,{skills:s,skillAgentId:a||null}),f=i.useRef(null),[I,h]=i.useState(null),j=i.useMemo(()=>{if(!x)return[];const _=new Set(x.map(q=>q.query.trim()));return Tt(n).filter(q=>!_.has(q.query.trim()))},[n,x]),y=cn(n),w=ln(r.filter(_=>y.includes(_.name)),s),P=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(k,{htmlFor:"automation-prompt",children:["Instructions"," ",d?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),y.length>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[y.length,"/",Ot," skills"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring",children:e.jsx(dn,{value:n,onChange:t,onSubmit:()=>{},submitOnEnter:!1,searchRefs:S,handleRef:f,onSqlRequest:()=>h({}),onSqlEdit:(_,q)=>h({initial:_,pos:q}),placeholder:P?"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(Mn,{open:I!==null,onOpenChange:_=>{_||h(null)},initial:I?.initial,onSubmit:_=>{f.current?.insertSql(_,I?.pos),h(null)}}),j.length>0&&m?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:[j.length===1?`"${j[0]?.name}" is referenced in the instructions but is not a source on this Automation.`:`${j.length} references in the instructions are not sources on this Automation.`," ","Editing an Automation does not add them automatically."]}),e.jsx(Q,{type:"button",variant:"outline",size:"sm",onClick:()=>m(Tt(n,x)),children:j.length===1?"Add as a source":"Add as sources"})]}):null,y.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:y.map(_=>{const q=w.includes(_),N=!s.some(K=>K.name===_);return e.jsxs(Ds,{variant:N?"destructive":"secondary",className:"font-normal",children:[_,N?" · unavailable":q?" · newer text":null]},_)})}):null,w.length>0?e.jsxs("p",{className:"rounded-lg border border-dashed p-3 text-xs text-muted-foreground",children:[w.length===1?`"${w[0]}" has been edited since this Automation pinned it.`:`${w.length} skills have been edited since this Automation pinned them.`," ","This Automation keeps running the pinned text until you save it again."]}):null,u?e.jsx("p",{className:"text-xs text-destructive",children:u}):null,!P&&a?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This agent has no skills yet."," ",e.jsx(Ps,{to:"/$owner/agents/$agentId/skills",params:{owner:c,agentId:a},className:"font-medium text-foreground underline underline-offset-2",children:"Add one"})," ","to reuse instructions across Automations."]}):u?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:P?"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 Ln=["connection","connector","feed","metric","entity_type"];function Rn({sources:n,onChange:t,disabled:s}){const{currentOwner:r,resolvedOrganizationId:d}=ss(),[u,c]=i.useState(""),{refs:a}=un({owner:r,organizationId:d,kinds:Ln,query:u,limitPerKind:10});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Sources"}),n.length>0?e.jsx("ul",{className:"space-y-2",children:n.map(x=>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:x.name}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:x.query})]}),e.jsx(Q,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0","aria-label":`Remove source ${x.name}`,disabled:s,onClick:()=>t(n.filter(m=>m.query!==x.query)),children:e.jsx(Yt,{className:"h-3.5 w-3.5"})})]},x.query))}):null,e.jsx("div",{className:"flex gap-2",children:e.jsx(st,{searchPlaceholder:"Search feeds, connections, metrics…",emptyText:"No matching reference.",onQueryChange:c,trigger:()=>e.jsxs(Q,{type:"button",variant:"outline",size:"sm",disabled:s,children:[e.jsx(Je,{className:"mr-2 h-3.5 w-3.5"}),"Add source"]}),children:x=>a.map(m=>e.jsxs(Ke,{value:`${m.label} ${m.kind}`,onSelect:()=>{t(mn(m,n)),x()},children:[e.jsx("span",{className:"truncate text-sm",children:m.label}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-muted-foreground",children:m.kind})]},`${m.kind}:${m.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 $n({organizationId:n,value:t,onChange:s,className:r}){const{data:d=[]}=Ls(n),u=nn(d),c=u.find(a=>a.id===t);return e.jsx(st,{contentClassName:"w-[300px]",searchPlaceholder:"Search entities...",emptyText:"No entities found.",trigger:a=>e.jsxs(Q,{variant:"outline",role:"combobox","aria-expanded":a,className:R("w-full justify-between",r),children:[c?`${c.name} (${c.entityType})`:"All workspace",e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:a=>e.jsxs(e.Fragment,{children:[e.jsxs(Ke,{value:"all workspace",onSelect:()=>{s(void 0),a()},className:"cursor-pointer",children:[e.jsx(tt,{className:R("mr-2 h-4 w-4",t===void 0?"opacity-100":"opacity-0")}),e.jsx("span",{children:"All workspace"})]}),u.map(x=>e.jsxs(Ke,{value:`${x.name} ${x.entityType}`,onSelect:()=>{s(x.id),a()},className:"cursor-pointer",children:[e.jsx(tt,{className:R("mr-2 h-4 w-4",t===x.id?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[x.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",x.entityType,")"]})]})]},x.id))]})})}function vt(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 In=Cn.map(n=>({value:n,label:En[n]})),Wt=[{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 Bt(n){const t=!!(n?.prompt?.trim()||n?.skills?.some(r=>r.content.trim())),s=!!n?.reaction_script?.trim();return t&&s?"both":s?"code":"agent"}const qn=["text","number","date","boolean","json"],Kn=[{value:"key",label:"Key"},{value:"plain",label:"Plain"}],ht=[{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 zt=0;function Wn(){return zt+=1,`field-${zt}`}function as(n={}){return{id:Wn(),name:n.name??"",type:n.type??"text",role:n.role??"plain"}}function He(n){return n.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")}function Bn(n){return n?Object.keys(n).every(t=>["entity_type","entity_path","key_fields","key_output_field"].includes(t)):!0}function Vt(n){return n?Bn(n.keying_config)?"fields":"json":"fields"}function Ut(n){const t=n?.keying_config?.entity_type;return typeof t=="string"?t:""}function Qt(n){const t=n?.keying_config?.entity_path;return typeof t=="string"&&t.trim()?t:"$"}function Gt(n){const t=new Map,s=Array.isArray(n?.keying_config?.key_fields)?n?.keying_config?.key_fields:[];for(const r of s){if(typeof r!="string")continue;const d=He(r);d&&t.set(d,as({name:d,role:"key"}))}return Array.from(t.values())}function _e(n,t){const s=n?.execution_config?.[t];return typeof s=="number"||typeof s=="string"?String(s):""}function Jt(n,t,s){const r=n?.execution_config?.[t];return typeof r=="string"&&s.includes(r)?r:""}function xt(n,t){const s=n.trim();if(!s)return{};const r=Number(s);return Number.isFinite(r)?{value:r}:{error:`${t} must be a number.`}}function Ht({entityType:n,entityPath:t,fields:s}){const d=s.map(a=>({...a,name:He(a.name)})).filter(a=>a.name).filter(a=>a.role==="key").map(a=>a.name),u=He(n),c=t.trim()||"$";return d.length>0&&!u?{error:"Key fields need an output entity type."}:(d.length>0,{keyingConfig:d.length>0?{entity_type:u,entity_path:c,key_fields:d,key_output_field:`${u}_key`}:void 0})}function zn(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 Xt(n){return!!(n?.keying_config||n?.reactions_guidance||n?.model_config||n?.execution_config||n?.sources?.length||vt(n?.tags).length)}function Vn({organizationId:n,entityId:t,prefill:s,onSubmit:r,isSubmitting:d,error:u,isEditing:c,onCancel:a,triggerFields:x,submitLabel:m="Create Automation",submitDisabled:S=!1,triggers:f}){const{lobuEmbedded:I}=An(),{currentOwner:h}=ss(),{data:j=[]}=Rs(),{data:y=[]}=$s(),[w,P]=i.useState(s?.managed_agent_id??""),_=!!s?.managed_agent_id&&!c,[q,N]=i.useState(s?.delivery_target??null),[K,X]=i.useState(!1),[te,b]=i.useState(s?.device_worker_id??""),[C,g]=i.useState(s?.device_worker_id?"device":"agent"),[G,se]=i.useState(s?.agent_kind??""),{data:$=[]}=Zt({organizationId:n}),[V,Y]=i.useState(s?.name??""),[he,xe]=i.useState(s?.slug??""),[ke,be]=i.useState(!!s?.slug),[M,ge]=i.useState(s?.description??""),[ne,Z]=i.useState(s?.prompt??""),[J,ae]=i.useState(!1),Se=s?.skills??[],[Fe,we]=i.useState(s?.sources??[]),[p,W]=i.useState(s?.entity_id??t),[H,pe]=i.useState(s?.reaction_script??""),[E,Ae]=i.useState(()=>Bt(s)),[ve,Oe]=i.useState(s?.keying_config?JSON.stringify(s.keying_config,null,2):""),[de,B]=i.useState(null),[ye,Me]=i.useState(()=>Vt(s)),[Te,ue]=i.useState(()=>Ut(s)),[De,We]=i.useState(()=>Qt(s)),[fe,me]=i.useState(()=>Gt(s)),[Be,Pe]=i.useState(s?.reactions_guidance??""),[nt,Ce]=i.useState(()=>_e(s,"timeout_seconds")),[at,ot]=i.useState(()=>_e(s,"max_budget_usd")),[ze,Xe]=i.useState(()=>_e(s,"model")),[Ve,it]=i.useState(()=>Jt(s,"permission_mode",ht.map(o=>o.value))),[Le,l]=i.useState(()=>_e(s,"effort")),[v,F]=i.useState(()=>_e(s,"finalize_nudges")),[ee,T]=i.useState(null),[je,A]=i.useState(vt(s?.tags).join(", ")),[Re,Ue]=i.useState(""),[rt,jt]=i.useState(!!(c||Xt(s)));i.useEffect(()=>{s&&(Y(s.name??""),xe(s.slug??""),be(!!s.slug),ge(s.description??""),Z(s.prompt??""),ae(!1),we(s.sources??[]),W(s.entity_id??t),b(s.device_worker_id??""),g(s.device_worker_id?"device":"agent"),se(s.agent_kind??""),pe(s.reaction_script??""),Ae(Bt(s)),Oe(s.keying_config?JSON.stringify(s.keying_config,null,2):""),B(null),Me(Vt(s)),ue(Ut(s)),We(Qt(s)),me(Gt(s)),Pe(s.reactions_guidance??""),Ce(_e(s,"timeout_seconds")),ot(_e(s,"max_budget_usd")),Xe(_e(s,"model")),it(Jt(s,"permission_mode",ht.map(o=>o.value))),l(_e(s,"effort")),F(_e(s,"finalize_nudges")),T(null),A(vt(s.tags).join(", ")),Ue(""),P(s.managed_agent_id??""),N(s.delivery_target??null),jt(!!(c||Xt(s))))},[s,t,c]);const os=ke?he:At(V),{data:is}=Is(w||null),{data:rs}=qs(w||null,{enabled:!!w}),ct=on(is??null,rs?.catalog??[]),cs=hn(f),lt=H.trim().length>0,Ye=!c&&E==="code"?"":ne,ls=!c&&E==="agent"?void 0:H.trim()||void 0,_t=(c||E==="code")&<,Nt=xn(Ye,ct,f,_t),ds=J||Ye.trim()!==""?Nt:null,kt=gn(Ye,ct),bt=!c&&E!=="agent",us=C==="device"&&!w.trim(),St=!!V.trim()&&!us&&!Nt&&(!bt||lt)&&!K,ms=cs&&!_t&&kt.length===0,hs=()=>{if(!St)return;let o;if(ye==="fields"){const Ne=Ht({entityType:Te,entityPath:De,fields:fe});if(Ne.error){B(Ne.error);return}o=Ne.keyingConfig,B(null)}else{if(ve.trim())try{const Ne=JSON.parse(ve);if(typeof Ne!="object"||Array.isArray(Ne)){B("Keying config must be a JSON object.");return}o=Ne}catch{B("Invalid JSON. Please check the syntax.");return}B(null)}const O=xt(nt,"Timeout");if(O.error){T(O.error);return}if(O.value!==void 0&&(!Number.isInteger(O.value)||O.value<1)){T("Timeout must be a whole number greater than 0.");return}const z=xt(at,"Budget");if(z.error){T(z.error);return}if(z.value!==void 0&&z.value<0){T("Budget cannot be negative.");return}const L=xt(v,"Finalize nudges");if(L.error){T(L.error);return}if(L.value!==void 0&&(!Number.isInteger(L.value)||L.value<0||L.value>5)){T("Finalize nudges must be a whole number from 0 to 5.");return}const Ee={...O.value!==void 0?{timeout_seconds:O.value}:{},...z.value!==void 0?{max_budget_usd:z.value}:{},...ze.trim()?{model:ze.trim()}:{},...Ve?{permission_mode:Ve}:{},...Le.trim()?{effort:Le.trim()}:{},...L.value!==void 0?{finalize_nudges:L.value}:{}},U=Object.keys(Ee).length>0||c?Ee:void 0;T(null);const xs=je.trim()?je.split(",").map(Ne=>Ne.trim()).filter(Boolean):void 0;r({slug:os,name:V.trim(),description:M.trim()||void 0,prompt:Ye,skills:kt,entity_id:p,sources:Fe,reaction_script:ls,keying_config:o,reactions_guidance:Be.trim()||void 0,execution_config:U,tags:xs,outputs:s?.outputs,change_notes:Re.trim()||void 0,managed_agent_id:C==="manual"?null:w.trim()||null,device_worker_id:C==="device"&&te.trim()||null,agent_kind:C==="device"&&G.trim()||null,delivery_target:q})},wt=e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"scratch-reaction",children:["Reaction Script"," ",bt?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(ft,{value:H,onChange:pe,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(k,{htmlFor:"scratch-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),!c&&e.jsx("button",{type:"button",onClick:()=>be(!ke),className:"text-xs text-muted-foreground hover:text-foreground",children:ke?"Use automatic slug":"Customize slug"})]}),e.jsx(oe,{id:"scratch-name",value:V,onChange:o=>Y(o.target.value),placeholder:"e.g., Escalation signals"}),!c&&ke?e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-slug",children:"Slug"}),e.jsx(oe,{id:"scratch-slug",value:he,onChange:o=>xe(o.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:At(V)||"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:Wt.map(o=>e.jsx("button",{type:"button","aria-pressed":E===o.value,onClick:()=>Ae(o.value),className:R("rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors",E===o.value?"bg-secondary text-secondary-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:o.label},o.value))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:Wt.find(o=>o.value===E)?.hint})]}),c||E!=="code"?e.jsx(Pn,{value:ne,onChange:o=>{ae(!0),Z(o)},library:ct,pinned:Se,required:ms,error:ds,owner:h??"",agentId:w,sources:c?Fe:void 0,onAddSources:c?we:void 0}):null,!c&&E!=="agent"?wt:null,c?e.jsx(Rn,{sources:Fe,onChange:we,disabled:d}):null,e.jsx("div",{className:"space-y-4",children:x}),e.jsx(Tn,{organizationId:n,agentId:C==="agent"?w.trim():"",value:q,onChange:N,disabled:d,automationName:V,onPendingChange:X}),K?e.jsx("p",{className:"text-xs text-destructive",children:"Confirm the digest destination above before saving — an unconfirmed destination is not sent."}):null,e.jsxs(Q,{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:()=>jt(o=>!o),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ks,{className:"h-4 w-4"}),"Advanced settings"]}),e.jsx(es,{className:R("h-4 w-4 transition-transform",rt&&"rotate-180")})]}),e.jsxs("div",{id:"automation-advanced-settings",className:R("space-y-4",!rt&&"hidden"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-description",children:"Description"}),e.jsx(oe,{id:"scratch-description",value:M,onChange:o=>ge(o.target.value),placeholder:"What this automation does"})]}),!t&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{children:"Entity scope"}),e.jsx($n,{organizationId:n,value:p,onChange:W}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit this automation to one workspace entity."})]}),c?wt: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(k,{children:"Output fields"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Key fields become stable entity keys."})]}),e.jsx(Q,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(ye==="fields"){const o=Ht({entityType:Te,entityPath:De,fields:fe});if(o.error){B(o.error);return}Oe(o.keyingConfig?JSON.stringify(o.keyingConfig,null,2):""),Me("json")}else Me("fields");B(null)},children:ye==="fields"?"Edit JSON":"Use fields"})]}),ye==="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(k,{htmlFor:"scratch-output-entity-type",children:"Output entity type"}),e.jsx(st,{contentClassName:"w-[320px]",searchPlaceholder:"Search or type a new type…",emptyText:"Type a name to create a new entity type.",trigger:o=>e.jsxs(Q,{type:"button",variant:"outline",role:"combobox","aria-expanded":o,id:"scratch-output-entity-type",className:"w-full justify-between font-mono text-sm font-normal",children:[e.jsx("span",{className:R("truncate",!Te&&"text-muted-foreground"),children:Te||"Select entity type"}),e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(o,O)=>{const z=He(O),L=$.filter(U=>!U.backing_sql),Ee=L.some(U=>U.slug===z);return e.jsxs(e.Fragment,{children:[L.map(U=>e.jsxs(Ke,{value:`${U.name??U.slug} ${U.slug}`,onSelect:()=>{ue(U.slug),B(null),o()},className:"cursor-pointer",children:[e.jsx(tt,{className:R("mr-2 h-4 w-4",Te===U.slug?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-sm",children:U.slug}),U.name&&U.name!==U.slug&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:U.name})]})]},U.slug)),z&&!Ee&&e.jsxs(Ke,{value:O,onSelect:()=>{ue(z),B(null),o()},className:"cursor-pointer",children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"text-sm",children:["Create"," ",e.jsx("span",{className:"font-mono",children:z})]})]})]})}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-output-path",children:"Output path"}),e.jsx(oe,{id:"scratch-output-path",value:De,onChange:o=>{We(o.target.value),B(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(k,{children:"Fields"}),e.jsxs(Q,{type:"button",variant:"outline",size:"sm",onClick:()=>{me(o=>[...o,as()]),B(null)},children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Add field"]})]}),fe.length===0?e.jsx("div",{className:R(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:"No output fields configured."}):e.jsx("div",{className:"space-y-2",children:fe.map(o=>e.jsxs("div",{className:R(Ie,"grid gap-2 p-3 sm:grid-cols-[minmax(0,1fr)_128px_minmax(0,240px)_auto]"),children:[e.jsx(oe,{value:o.name,onChange:O=>{const z=He(O.target.value);me(L=>L.map(Ee=>Ee.id===o.id?{...Ee,name:z}:Ee)),B(null)},placeholder:"severity","aria-label":"Output field name",className:"font-mono text-sm"}),e.jsxs(ie,{value:o.type,onValueChange:O=>{me(z=>z.map(L=>L.id===o.id?{...L,type:O}:L))},children:[e.jsx(re,{"aria-label":"Output field type",children:e.jsx(ce,{})}),e.jsx(le,{children:qn.map(O=>e.jsx(D,{value:O,children:O},O))})]}),e.jsx("div",{className:"grid grid-cols-2 rounded-md border border-input bg-background p-1",children:Kn.map(O=>e.jsx("button",{type:"button",onClick:()=>{me(z=>z.map(L=>L.id===o.id?{...L,role:O.value}:L)),B(null)},className:R("rounded-sm px-2 py-1 text-xs transition-colors",o.role===O.value?"bg-muted/70 text-foreground":"text-muted-foreground hover:text-foreground"),children:O.label},O.value))}),e.jsx(Q,{type:"button",variant:"ghost",size:"icon",onClick:()=>{me(O=>O.filter(z=>z.id!==o.id)),B(null)},"aria-label":"Remove output field",children:e.jsx(ts,{className:"h-4 w-4"})})]},o.id))})]}),de&&e.jsx("p",{className:"text-xs text-destructive",children:de})]}):e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-keying-config",children:"Keying Config (JSON)"}),e.jsx(ft,{value:ve,onChange:o=>{Oe(o),B(null)},language:"json",placeholder:'{ "entity_type": "topic", "entity_path": "$.items[*]", "key_fields": ["name"], "key_output_field": "entity_key" }',minHeight:"60px"}),de&&e.jsx("p",{className:"text-xs text-destructive",children:de})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-reactions-guidance",children:"Reactions Guidance"}),e.jsx(Ws,{id:"scratch-reactions-guidance",value:Be,onChange:o=>Pe(o.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:[zn("Run settings","Choose where the automation runs and the budget it can use."),!_&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-runs-on",children:"Runs on"}),e.jsxs(ie,{value:C,onValueChange:o=>g(o),children:[e.jsx(re,{id:"scratch-runs-on",className:"text-sm",children:e.jsx(ce,{})}),e.jsxs(le,{children:[e.jsx(D,{value:"agent",children:"Managed agent"}),e.jsx(D,{value:"device",children:"On a device"}),e.jsx(D,{value:"manual",children:"Manual-only"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:C==="agent"?"Automated runs dispatch to a managed Lobu agent.":C==="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."})]}),!_&&C!=="manual"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(k,{htmlFor:"scratch-agent-id",children:["Agent",C==="device"&&e.jsx("span",{className:"text-destructive",children:" *"})]}),I?e.jsxs(ie,{value:w||"__unselected__",onValueChange:o=>{P(o==="__unselected__"?"":o)},children:[e.jsx(re,{id:"scratch-agent-id",className:"font-mono text-sm",children:e.jsx(ce,{placeholder:"Select a Lobu agent"})}),e.jsx(le,{children:j.map(o=>e.jsxs(D,{value:o.agentId,children:[o.name," (",o.agentId,")"]},o.agentId))})]}):e.jsx(oe,{id:"scratch-agent-id",value:w,onChange:o=>{P(o.target.value)},placeholder:"e.g., agent-123",className:"font-mono text-sm"}),C==="device"&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"The device run uses this agent's memory and tools, acting as the agent's owner."})]}),!_&&C==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-device-id",children:"Device"}),e.jsxs(ie,{value:te||"__unselected__",onValueChange:o=>b(o==="__unselected__"?"":o),children:[e.jsx(re,{id:"scratch-device-id",className:"font-mono text-sm",children:e.jsx(ce,{placeholder:"Select a device worker"})}),e.jsx(le,{children:y.map(o=>e.jsx(D,{value:o.id,children:o.label||o.platform||o.id},o.id))})]})]}),!_&&C==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-device-agent-kind",children:"Runs as"}),e.jsxs(ie,{value:G||"__default__",onValueChange:o=>se(o==="__default__"?"":o),children:[e.jsx(re,{id:"scratch-device-agent-kind",className:"text-sm",children:e.jsx(ce,{placeholder:"Device default"})}),e.jsxs(le,{children:[e.jsx(D,{value:"__default__",children:"Device default"}),In.map(o=>e.jsx(D,{value:o.value,children:o.label},o.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(k,{children:"Model"}),e.jsx(an,{value:ze,onChange:o=>{Xe(o),T(null)},placeholder:"Use agent default"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-timeout",children:"Timeout seconds"}),e.jsx(oe,{id:"scratch-timeout",type:"number",min:1,max:86400,value:nt,onChange:o=>{Ce(o.target.value),T(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(k,{htmlFor:"scratch-permission-mode",children:"Permission mode"}),e.jsxs(ie,{value:Ve||"__default__",onValueChange:o=>{it(o==="__default__"?"":o),T(null)},children:[e.jsx(re,{id:"scratch-permission-mode",children:e.jsx(ce,{placeholder:"Default"})}),e.jsxs(le,{children:[e.jsx(D,{value:"__default__",children:"Default"}),ht.map(o=>e.jsx(D,{value:o.value,children:o.label},o.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-effort",children:"Effort"}),e.jsx(oe,{id:"scratch-effort",value:Le,onChange:o=>{l(o.target.value),T(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(k,{htmlFor:"scratch-finalize-nudges",children:"Finalize nudges"}),e.jsx(oe,{id:"scratch-finalize-nudges",type:"number",min:0,max:5,value:v,onChange:o=>{F(o.target.value),T(null)},placeholder:"Default"})]})]}),ee&&e.jsx("p",{className:"text-xs text-destructive",children:ee})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-tags",children:"Tags"}),e.jsx(oe,{id:"scratch-tags",value:je,onChange:o=>A(o.target.value),placeholder:"ops, support, risk"})]}),c&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(k,{htmlFor:"scratch-change-notes",children:"Change notes"}),e.jsx(oe,{id:"scratch-change-notes",value:Re,onChange:o=>Ue(o.target.value),placeholder:"What changed in this version?"})]})]})]}),u&&!de&&!ee&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:u}),e.jsx(pt,{onCancel:a,children:e.jsx(Q,{onClick:hs,disabled:!St||d||S,children:d?e.jsxs(e.Fragment,{children:[e.jsx(Bs,{size:"lg",className:"mr-2"}),c?"Saving...":"Creating..."]}):c?"Save Automation":m})})]})}function Un(n,t){const s=n??null,r=t??null;return s===null||r===null?s===r:s.connection_id===r.connection_id&&s.channel_id===r.channel_id}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,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,outputs:t.outputs}}function aa({startFromScratch:n=!1,onClose:t,hideCancel:s=!1,hideHeader:r=!1,organizationId:d,entityId:u,entityName:c,prefillAgentId:a,onSuccess:x,editingAutomation:m,catalogPrefill:S,onDraft:f,triggerFields:I,submitLabel:h,submitDisabled:j,createFields:y,onPrefillTriggers:w}){const P=zs(),_=Vs(),q=Us(),N=Qs(),K=!!m,[X,te]=i.useState(n?"scratch":"template"),[b,C]=i.useState(void 0),[g,G]=i.useState(void 0),{data:se=[],isLoading:$}=Gs(),[V,Y]=i.useState(""),he=i.useMemo(()=>a?{managed_agent_id:a}:void 0,[a]),xe=i.useMemo(()=>se.map(p=>({key:p.id,name:p.name,description:p.description??"",badges:p.detail?.tags??[]})),[se]),ke=i.useMemo(()=>xe.filter(p=>p.name.toLowerCase().includes(V.toLowerCase())||p.description.toLowerCase().includes(V.toLowerCase())),[xe,V]),be=p=>{const W=se.find(pe=>pe.id===p.key);if(!W)return;const H=Qn(W);G(a?{...H,managed_agent_id:a}:H),w?.(H.triggers??[]),te("scratch")},M=()=>{P.reset(),_.reset(),te("template"),C(void 0),G(void 0),t()},ge=K?y?.triggers??m.triggers??[]:y?.triggers??g?.triggers??S?.triggers??[],ne=async p=>{try{if(f){await f(p);return}if(K){const W=y?.triggers??m.triggers??[],H=m.reaction_script??"",pe=p.reaction_script??"";pe&&pe!==H&&await q.mutateAsync({automation_id:m.automation_id,reaction_script:pe}),await _.mutateAsync({automation_id:m.automation_id,name:p.name,description:p.description,prompt:p.prompt,sources:p.sources,set_as_current:!0,triggers:W,keying_config:p.keying_config,reactions_guidance:p.reactions_guidance,change_notes:p.change_notes}),!pe&&H&&await q.mutateAsync({automation_id:m.automation_id,reaction_script:""});const E={};p.model_config!==void 0&&(E.model_config=p.model_config),p.execution_config!==void 0&&(E.execution_config=p.execution_config),p.tags!==void 0&&(E.tags=p.tags),p.delivery_target!==void 0&&!Un(p.delivery_target,m.delivery_target)&&(E.delivery_target=p.delivery_target),p.managed_agent_id!==void 0&&(E.managed_agent_id=p.managed_agent_id||null),p.agent_kind!==void 0&&(E.agent_kind=p.agent_kind||null),p.device_worker_id!==void 0&&(E.device_worker_id=p.device_worker_id||null),Object.keys(E).length>0&&await N.mutateAsync({automation_id:m.automation_id,...E}),M(),x?.(m.automation_id)}else{const W=y?.triggers??g?.triggers??S?.triggers??[],H=await P.mutateAsync({...p,managed_agent_id:p.managed_agent_id??void 0,device_worker_id:p.device_worker_id??void 0,agent_kind:p.agent_kind??void 0,delivery_target:p.delivery_target??void 0,triggers:W});M(),H.automation_id&&x?.(H.automation_id)}}catch{}},Z=K?_:P;let J="Add an automation";K?J="Edit automation configuration (saves as a new version)":c&&(J=`Add an automation for ${c}`);const ae=m?{entity_id:m.entity_id,name:m.name,slug:m.slug,description:m.description,prompt:m.prompt,sources:m.sources,reaction_script:m.reaction_script,device_worker_id:m.device_worker_id??void 0,agent_kind:m.agent_kind??void 0,keying_config:m.keying_config,reactions_guidance:m.reactions_guidance,model_config:m.model_config,execution_config:m.execution_config,tags:m.tags,managed_agent_id:m.managed_agent_id??void 0,delivery_target:m.delivery_target??void 0}:void 0,Se=K?"Edit Automation":"Create Automation",Fe=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:J})]}),we=e.jsxs("div",{className:"py-6 space-y-6",children:[!K&&e.jsxs("div",{className:"flex flex-wrap justify-start gap-2",children:[e.jsx(gt,{active:X==="template",onClick:()=>te("template"),icon:e.jsx(Js,{className:"h-4 w-4"}),label:"From templates"}),e.jsx(gt,{active:X==="scratch",onClick:()=>{te("scratch"),C(void 0),G(void 0)},icon:e.jsx(Je,{className:"h-4 w-4"}),label:"From scratch"}),e.jsx(gt,{active:X==="clone",onClick:()=>te("clone"),icon:e.jsx(Hs,{className:"h-4 w-4"}),label:"Clone existing"})]}),!K&&X==="template"?e.jsxs(e.Fragment,{children:[$?e.jsx(Xs,{}):e.jsx(Ys,{items:ke,searchQuery:V,onSearchChange:Y,onSelect:be,searchPlaceholder:"Search templates...",searchAriaLabel:"Search automation templates",emptyMessage:xe.length===0?"No automation templates available.":void 0}),r&&!s?e.jsx(pt,{onCancel:M}):null]}):!K&&X==="clone"&&!b?e.jsxs(e.Fragment,{children:[e.jsx(Gn,{organizationId:d,onSelect:p=>{C(p),w?.(p.triggers??[]),te("scratch")}}),r&&!s?e.jsx(pt,{onCancel:M}):null]}):e.jsx(Vn,{organizationId:d,entityId:u,prefill:ae??b??g??S??he,onSubmit:ne,isSubmitting:Z.isPending,error:Z.error?Z.error.message:null,isEditing:K,onCancel:s?void 0:M,triggerFields:I,submitLabel:h,submitDisabled:j,triggers:ge})]});return e.jsxs("div",{className:"flex flex-col",children:[r?null:Fe,we]})}function gt({active:n,onClick:t,icon:s,label:r}){return e.jsxs("button",{type:"button",onClick:t,className:R("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,r]})}function Gn({organizationId:n,onSelect:t}){const{data:s,isLoading:r}=Zs(n),[d,u]=i.useState(""),c=(s||[]).filter(a=>a.name?.toLowerCase().includes(d.toLowerCase()));return r?e.jsx(en,{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:d,onChange:a=>u(a.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(a=>e.jsxs("button",{type:"button",onClick:()=>t({name:`${a.name} (copy)`,slug:`${a.slug||a.automation_id}-copy`,prompt:a.prompt,keying_config:a.keying_config,triggers:a.triggers,sources:a.sources,outputs:a.outputs}),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:a.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[a.entity_name||"Space-level"," · v",a.version??"?"]})]},a.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{na as A,aa as C};
|
|
3
|
+
//# sourceMappingURL=create-automation-form-9T5WnoUs.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{eo as U}from"./index-Cr5hwh-C.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};
|
|
2
|
-
//# sourceMappingURL=cronstrue-
|
|
1
|
+
import{eY as U}from"./index-DYCqXaMf.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};
|
|
2
|
+
//# sourceMappingURL=cronstrue-BWFEyy_P.js.map
|
package/dist/owletto/dist/assets/{deployments-body-BMp7UsMo.js → deployments-body-2xKS8gRo.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{j as a,
|
|
2
|
-
//# sourceMappingURL=deployments-body-
|
|
1
|
+
import{j as a,bz as x,bM as p,aR as m,hn as o,B as f,bd as c,L as i,ho as h,P as r}from"./index-DYCqXaMf.js";import{u as g}from"./deployments-wG_8QzOF.js";function y(e){return e==="partial_failure"?a.jsx(r,{variant:"destructive",children:"Partial failure"}):e==="succeeded"?a.jsx(r,{variant:"secondary",children:"Succeeded"}):null}function j(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 N(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 u="flex items-start gap-3 px-3 py-2.5 transition-colors hover:bg-accent/50";function B({owner:e}){const t=g(),n=t.data?.pages.flatMap(s=>s.items)??[];return t.isLoading?a.jsx("div",{className:"max-w-3xl",children:a.jsx(x,{label:"deployments"})}):t.isError?a.jsx(p,{label:"deployments"}):n.length===0?a.jsx(m,{icon:o,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 d=l===n.length-1;return s.type==="deployment"?a.jsx(b,{item:s,owner:e,isLast:d},s.id):a.jsx(v,{item:s,owner:e,isLast:d},s.id)})}),t.hasNextPage?a.jsx(f,{variant:"outline",size:"sm",className:"h-8 text-xs",disabled:t.isFetchingNextPage,onClick:()=>t.fetchNextPage(),children:t.isFetchingNextPage?"Loading...":"Load more"}):null]})}function b({item:e,owner:t,isLast:n}){const l=[N(e.counts),e.createdBy?`by ${e.createdBy}`:null,c(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(i,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:e.applyId??String(e.id)},className:`${u} ${n?"":"border-b"}`,children:[a.jsx(o,{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"}),y(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 v({item:e,owner:t,isLast:n}){const s=[e.actorSource?`via ${e.actorSource}`:null,e.createdBy?`by ${e.createdBy}`:null,c(e.createdAt)].filter(Boolean).join(" · ");return a.jsxs(i,{to:"/$owner/connectors/deployments/$deploymentId",params:{owner:t,deploymentId:`change-${e.id}`},className:`${u} ${n?"":"border-b"}`,children:[a.jsx(h,{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]}),j(e.op)]}),a.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:s})]})]})}export{B as D,j as c,y as d};
|
|
2
|
+
//# sourceMappingURL=deployments-body-2xKS8gRo.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
//# sourceMappingURL=deployments-
|
|
1
|
+
import{cx as r,h6 as l,W as i,dD as u,ch as c,J as d}from"./index-DYCqXaMf.js";function o(e,n=""){return`${d}/api/${e}/deployments${n}`}const y=50;function f(e){const{slug:n}=r();return l({queryKey:["deployments-feed",n,e?.resourceKind,e?.resourceId],queryFn:async({pageParam:t})=>{const a=new URLSearchParams({limit:String(y)});t!==null&&a.set("before_id",String(t)),e&&(a.set("resource_kind",e.resourceKind),a.set("resource_id",e.resourceId));const s=await i(o(n,`?${a.toString()}`),{credentials:"include"});return s.status===404?{items:[],has_more:!1}:(await u(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:!!n,staleTime:15e3,retry:!1})}function h(e){const{slug:n}=r();return c({queryKey:["deployment-detail",n,e],queryFn:async()=>{const t=await i(o(n,`/${e}`),{credentials:"include"});return t.status===404?null:(await u(t,"Failed to fetch deployment"),await t.json())},enabled:!!n&&!!e,staleTime:15e3,retry:!1})}function g(e){const{slug:n}=r();return c({queryKey:["deployment-change-detail",n,e],queryFn:async()=>{const t=await i(o(n,`/changes/${e}`),{credentials:"include"});return t.status===404?null:(await u(t,"Failed to fetch change"),(await t.json()).change)},enabled:!!n&&!!e,staleTime:15e3,retry:!1})}export{g as a,h as b,f as u};
|
|
2
|
+
//# sourceMappingURL=deployments-wG_8QzOF.js.map
|