@lobu/runtime-server 24.6.0 → 24.8.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 +199 -316
- package/dist/component.json +1 -1
- package/dist/connectors/imessage.ts +953 -0
- package/dist/connectors/linkedin.ts +20 -377
- package/dist/dependencies.bun.lock +124 -92
- package/dist/embeddings-server.mjs +14 -2
- package/dist/owletto/dist/assets/_-B0tmXZ86.js +2 -0
- package/dist/owletto/dist/assets/_-DwXULq4r.js +3 -0
- package/dist/owletto/dist/assets/_agentId-B1dNkhnr.js +2 -0
- package/dist/owletto/dist/assets/_agentId-sYjvnBaB.js +2 -0
- package/dist/owletto/dist/assets/_automationId-Bnw_CnT_.js +2 -0
- package/dist/owletto/dist/assets/_connectorKey._connectionId-D7Z8DQ-B.js +2 -0
- package/dist/owletto/dist/assets/_connectorKey.index-DM5MTO8c.js +2 -0
- package/dist/owletto/dist/assets/_conversationId-OJrZjd0o.js +2 -0
- package/dist/owletto/dist/assets/_eventId-CfB0_2zK.js +2 -0
- package/dist/owletto/dist/assets/_owner-BDvTUY0a.js +3 -0
- package/dist/owletto/dist/assets/_shape-BZidoJMB.js +2 -0
- package/dist/owletto/dist/assets/_slug-R989vOiM.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-BDUSrpe5.js +2 -0
- package/dist/owletto/dist/assets/_viewKey-BnFqh5-t.js +2 -0
- package/dist/owletto/dist/assets/{accept-invitation-CQZQ0wwC.js → accept-invitation-BC-ZIsrf.js} +2 -2
- package/dist/owletto/dist/assets/activity-route-view-CN2dOiCD.js +2 -0
- package/dist/owletto/dist/assets/agent-connect-pages-CdDjrHjn.js +4 -0
- package/dist/owletto/dist/assets/agent-editor-form-CDAHRNWl.js +2 -0
- package/dist/owletto/dist/assets/{agent-loading-shells-_18OREnx.js → agent-loading-shells-BupiSjR-.js} +2 -2
- package/dist/owletto/dist/assets/agent-permissions-matrix-ju7L2M0l.js +2 -0
- package/dist/owletto/dist/assets/{agent-skill-context-1DBn7Xc_.js → agent-skill-context-B0ZYVE3n.js} +2 -2
- package/dist/owletto/dist/assets/agent-subpage-shell-ByU0xhXn.js +2 -0
- package/dist/owletto/dist/assets/{agent-thread-FyEO-y44.js → agent-thread-DiVKn1WX.js} +4 -4
- package/dist/owletto/dist/assets/agent-thread-storage-Bx2-WBHQ.js +2 -0
- package/dist/owletto/dist/assets/app._appId-BQWElSoP.js +2 -0
- package/dist/owletto/dist/assets/assist-composer-igTXq3DL.js +2 -0
- package/dist/owletto/dist/assets/automation-detail-content-BJwRU6qT.js +2 -0
- package/dist/owletto/dist/assets/{callback-9xSHyA12.js → callback-Dmaio9CX.js} +2 -2
- package/dist/owletto/dist/assets/{card-g4yxo4Hr.js → card-rE4Ctuy6.js} +2 -2
- package/dist/owletto/dist/assets/{claim-B98IhDra.js → claim-BN17CPYh.js} +2 -2
- package/dist/owletto/dist/assets/{client-activity-scopes-BD2HBo-_.js → client-activity-scopes-B7xVaUA-.js} +2 -2
- package/dist/owletto/dist/assets/{client-rows-x_CxeWkP.js → client-rows-B3LULJxW.js} +2 -2
- package/dist/owletto/dist/assets/clients-CydgUHrc.js +2 -0
- package/dist/owletto/dist/assets/code-editor-UppEMWpt.js +26 -0
- package/dist/owletto/dist/assets/connect-OdHpIVV9.js +2 -0
- package/dist/owletto/dist/assets/connect-menu-B9u86bb2.js +2 -0
- package/dist/owletto/dist/assets/connect._clientId-EI1tcdSE.js +2 -0
- package/dist/owletto/dist/assets/connected._clientId-CaF-ZWlZ.js +2 -0
- package/dist/owletto/dist/assets/{connection-B6fM2KHN.js → connection-D8ZAMHBT.js} +2 -2
- package/dist/owletto/dist/assets/connection-feed-detail-CJYqryAV.js +2 -0
- package/dist/owletto/dist/assets/connector-boxes-BWPXijAk.js +2 -0
- package/dist/owletto/dist/assets/connector-page-shell-C23dWdKz.js +2 -0
- package/dist/owletto/dist/assets/connector-provenance-CW4CXtCz.js +2 -0
- package/dist/owletto/dist/assets/{connectors-DnOUxX_U.js → connectors-Bp08_KPq.js} +2 -2
- package/dist/owletto/dist/assets/consent-_PpYI1cT.js +2 -0
- package/dist/owletto/dist/assets/copy-button-1ALlvZU1.js +2 -0
- package/dist/owletto/dist/assets/{core.esm-BsXtvNoI.js → core.esm-6koO33th.js} +3 -3
- package/dist/owletto/dist/assets/create-DULVO0HS.js +2 -0
- package/dist/owletto/dist/assets/create-Drx9tcnG.js +2 -0
- package/dist/owletto/dist/assets/create-automation-form-BhujNbRr.js +3 -0
- package/dist/owletto/dist/assets/create-kUevP9Xx.js +2 -0
- package/dist/owletto/dist/assets/create._connectorKey-N6fhcIPy.js +2 -0
- package/dist/owletto/dist/assets/custom-guardrail-edits-B_aCgvoZ.js +2 -0
- package/dist/owletto/dist/assets/definition-comparison-3zKUSTt8.js +2 -0
- package/dist/owletto/dist/assets/detail-page-skeleton-BmxqqIsH.js +2 -0
- package/dist/owletto/dist/assets/{device-DdCoCj-Q.js → device-D2eUt_nr.js} +2 -2
- package/dist/owletto/dist/assets/device-automation-Dp3faMvp.js +2 -0
- package/dist/owletto/dist/assets/device-pin-tombstone-BFPbTM_o.js +2 -0
- package/dist/owletto/dist/assets/device._deviceId-Dqtmb1Xp.js +2 -0
- package/dist/owletto/dist/assets/dynamic-schema-form-D3KnzCsW.js +2 -0
- package/dist/owletto/dist/assets/entity-options-IUdQ-64R.js +2 -0
- package/dist/owletto/dist/assets/entity-page-B3Im65EI.js +2 -0
- package/dist/owletto/dist/assets/entity-pages-DJNSQrfB.js +2 -0
- package/dist/owletto/dist/assets/entity-type-page-CouHZbc9.js +2 -0
- package/dist/owletto/dist/assets/event-detail-CvaRN1qB.js +2 -0
- package/dist/owletto/dist/assets/event-kind-options-fHAIXu24.js +2 -0
- package/dist/owletto/dist/assets/events-feed-DwOkLk6A.js +2 -0
- package/dist/owletto/dist/assets/filter-editors-DQ5V4Cvh.js +2 -0
- package/dist/owletto/dist/assets/{full-page-spinner-B5xXnKtV.js → full-page-spinner-B7A6Ycyi.js} +2 -2
- package/dist/owletto/dist/assets/home-stream-Bg97PUBJ.js +2 -0
- package/dist/owletto/dist/assets/home-toolbar-CpCcHA6z.js +2 -0
- package/dist/owletto/dist/assets/index-9PGnv4-5.js +2 -0
- package/dist/owletto/dist/assets/{index-TkPy_P_u.js → index-B-dZruj6.js} +2 -2
- package/dist/owletto/dist/assets/index-BztXeLBN.js +2 -0
- package/dist/owletto/dist/assets/index-C2TCKJDP.js +7901 -0
- package/dist/owletto/dist/assets/index-C7QM3aqU.js +2 -0
- package/dist/owletto/dist/assets/index-CWn46a4y.js +2 -0
- package/dist/owletto/dist/assets/index-CxJONizf.js +2 -0
- package/dist/owletto/dist/assets/index-DJhb3li3.js +2 -0
- package/dist/owletto/dist/assets/{index-BDl1_w6U.js → index-DXfYVs5m.js} +2 -2
- package/dist/owletto/dist/assets/{index-BdNR51Ua.js → index-DY-YGnCe.js} +2 -2
- package/dist/owletto/dist/assets/index-j3v7ITPb.js +2 -0
- package/dist/owletto/dist/assets/index-oiy6ygaI.js +2 -0
- package/dist/owletto/dist/assets/index-pEgtAY1t.js +2 -0
- package/dist/owletto/dist/assets/index-xAvK3IyQ.css +1 -0
- package/dist/owletto/dist/assets/json-diff-CJK-gzCt.js +4 -0
- package/dist/owletto/dist/assets/list-skeleton-bQAZ0hQp.js +2 -0
- package/dist/owletto/dist/assets/{login-TWR0vF4_.js → login-DLqL54Rk.js} +2 -2
- package/dist/owletto/dist/assets/{logout-BA5kojS0.js → logout-H0F3IfiO.js} +2 -2
- package/dist/owletto/dist/assets/member-scope-gate-Doic_6qX.js +2 -0
- package/dist/owletto/dist/assets/memory-browse-page-CUea2Llz.js +74 -0
- package/dist/owletto/dist/assets/model-selector-BrfaDwIg.js +2 -0
- package/dist/owletto/dist/assets/new-5GkxlOuQ.js +2 -0
- package/dist/owletto/dist/assets/{new-Dc5Bbotb.js → new-BiA4DGoN.js} +2 -2
- package/dist/owletto/dist/assets/new-M-MX_T5C.js +2 -0
- package/dist/owletto/dist/assets/organization-CLrcmgNK.js +2 -0
- package/dist/owletto/dist/assets/peek-pane-content-B29OcHwm.js +2 -0
- package/dist/owletto/dist/assets/{pending-seed-BP3xHM2d.js → pending-seed-DYYOoCvj.js} +2 -2
- package/dist/owletto/dist/assets/proposal-review-shell-BVwOMoq9.js +2 -0
- package/dist/owletto/dist/assets/public-shell-ready-BbjPgh3k.js +2 -0
- package/dist/owletto/dist/assets/record-activity-BCpNKaUo.js +2 -0
- package/dist/owletto/dist/assets/{record-session-DOFgdd43.js → record-session-KuEDuF3S.js} +2 -2
- package/dist/owletto/dist/assets/{renderer-CHPS-1vD.js → renderer-ucwCQmBk.js} +26 -26
- package/dist/owletto/dist/assets/{reset-password-BmNM-apc.js → reset-password-BkiAmXZW.js} +2 -2
- package/dist/owletto/dist/assets/run-initiator-8vdkq-3o.js +2 -0
- package/dist/owletto/dist/assets/{runs-BntGAKQG.js → runs-B_iywKWb.js} +2 -2
- package/dist/owletto/dist/assets/runs-list-CJJFRhTl.js +2 -0
- package/dist/owletto/dist/assets/schema-type-editor-panel-C4e8pq1A.js +2 -0
- package/dist/owletto/dist/assets/{schema-value-BFb7jCBo.js → schema-value-CefbtPIY.js} +3 -3
- package/dist/owletto/dist/assets/scoped-feed-bar-CapleZvS.js +2 -0
- package/dist/owletto/dist/assets/{settings-DubSpJfg.js → settings-DvzkRYQy.js} +2 -2
- package/dist/owletto/dist/assets/skill-route-key-sF006xiz.js +2 -0
- package/dist/owletto/dist/assets/source-record-panels-LJIWGtHb.js +2 -0
- package/dist/owletto/dist/assets/status-variants-BxHtpMOj.js +2 -0
- package/dist/owletto/dist/assets/subDays-DwIOMzYC.js +2 -0
- package/dist/owletto/dist/assets/{table-DALHuXPE.js → table-1O-ik4_O.js} +2 -2
- package/dist/owletto/dist/assets/{use-automations-D9hKpufo.js → use-automations-lV8PuE8L.js} +2 -2
- package/dist/owletto/dist/assets/use-login-redirect-CfCbEeJR.js +2 -0
- package/dist/owletto/dist/assets/use-mention-search-CA-evCDf.js +91 -0
- package/dist/owletto/dist/assets/view-param-filters-Bp84PUMd.js +2 -0
- package/dist/owletto/dist/assets/{views-access-required-CZ1fvAks.js → views-access-required-BerT4Z1d.js} +2 -2
- package/dist/owletto/dist/index.html +2 -2
- package/dist/server-main.bundle.mjs +358 -141
- package/npm-shrinkwrap.json +540 -447
- package/package.json +4 -2
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/core/dist/connector-query-errors.d.ts +6 -0
- package/vendor/core/dist/connector-query-errors.js +4 -0
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +2 -0
- package/vendor/core/dist/contracts/tools/manage-entity.js +7 -0
- package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +2 -0
- package/vendor/core/dist/contracts/tools/manage-feeds.js +3 -0
- package/vendor/core/dist/contracts/tools/view-host.js +2 -0
- package/vendor/core/dist/error-report.js +1 -0
- package/vendor/core/package.json +1 -1
- package/vendor/views/package.json +1 -1
- package/dist/connectors/linkedin-takeout.ts +0 -577
- package/dist/connectors/takeout-utils.ts +0 -240
- package/dist/owletto/dist/assets/_-DT3E3BmS.js +0 -3
- package/dist/owletto/dist/assets/_-DtqBFgK5.js +0 -2
- package/dist/owletto/dist/assets/_-c1xy7bLu.js +0 -2
- package/dist/owletto/dist/assets/_agentId-CTfoi0-7.js +0 -2
- package/dist/owletto/dist/assets/_agentId-DV8utajn.js +0 -2
- package/dist/owletto/dist/assets/_automationId-DvP3qyYL.js +0 -2
- package/dist/owletto/dist/assets/_connectorKey._connectionId-CL5SivCn.js +0 -2
- package/dist/owletto/dist/assets/_connectorKey.index-tnMwC67b.js +0 -2
- package/dist/owletto/dist/assets/_conversationId-DXN_8m88.js +0 -2
- package/dist/owletto/dist/assets/_eventId-SdpFT7jB.js +0 -2
- package/dist/owletto/dist/assets/_name-CM1AMywz.js +0 -2
- package/dist/owletto/dist/assets/_owner-CaGsXXBW.js +0 -3
- package/dist/owletto/dist/assets/_shape-DGAkETDp.js +0 -2
- package/dist/owletto/dist/assets/_skillKey-Dd4ZHPY8.js +0 -2
- package/dist/owletto/dist/assets/_slug-cRvJQtNo.js +0 -2
- package/dist/owletto/dist/assets/_view-B5I7mmkl.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-Bwn0dyLo.js +0 -2
- package/dist/owletto/dist/assets/_viewKey-YjSYD0wc.js +0 -2
- package/dist/owletto/dist/assets/activity-route-view-CZykJXQp.js +0 -2
- package/dist/owletto/dist/assets/agent-card-controls-DuQJhtqp.js +0 -2
- package/dist/owletto/dist/assets/agent-client-setup-list-CpUTAjXf.js +0 -4
- package/dist/owletto/dist/assets/agent-connect-pages-Br_ycC0z.js +0 -2
- package/dist/owletto/dist/assets/agent-editor-form-BXQBFHSv.js +0 -2
- package/dist/owletto/dist/assets/agent-guardrails-route-CN7vpC0X.js +0 -2
- package/dist/owletto/dist/assets/agent-list-row-BnP6r4pm.js +0 -2
- package/dist/owletto/dist/assets/agent-permissions-matrix-DSjidWHL.js +0 -2
- package/dist/owletto/dist/assets/agent-skills-route-d5jh3oBR.js +0 -2
- package/dist/owletto/dist/assets/agent-tab-intro-DKrC3SQt.js +0 -2
- package/dist/owletto/dist/assets/agent-thread-storage-U6htL3ad.js +0 -2
- package/dist/owletto/dist/assets/agents-kXojozTU.js +0 -2
- package/dist/owletto/dist/assets/agents-workbench-CDpJmUVN.js +0 -2
- package/dist/owletto/dist/assets/app._appId-DwNeXRJp.js +0 -2
- package/dist/owletto/dist/assets/assist-composer-Mn9EfX4X.js +0 -2
- package/dist/owletto/dist/assets/automation-detail-content-Bs3vwAPd.js +0 -2
- package/dist/owletto/dist/assets/automation-row-B5Q1B10y.js +0 -2
- package/dist/owletto/dist/assets/automation-source-list-Dhucq1sI.js +0 -2
- package/dist/owletto/dist/assets/automations-kXojozTU.js +0 -2
- package/dist/owletto/dist/assets/change-summary-DeuXQEpb.js +0 -2
- package/dist/owletto/dist/assets/clients-Cmp0LmOp.js +0 -2
- package/dist/owletto/dist/assets/connect-menu-CezOH3s7.js +0 -2
- package/dist/owletto/dist/assets/connect-zUot_0kG.js +0 -2
- package/dist/owletto/dist/assets/connect._clientId-nsGxe6yO.js +0 -2
- package/dist/owletto/dist/assets/connected._clientId-DnclRRXk.js +0 -2
- package/dist/owletto/dist/assets/connected._clientId.activity-CDB8atTX.js +0 -2
- package/dist/owletto/dist/assets/connected._clientId.index-DBNP2mZo.js +0 -2
- package/dist/owletto/dist/assets/connection-feed-detail-Ckq-qEbD.js +0 -2
- package/dist/owletto/dist/assets/connection-label-BobuYiAG.js +0 -2
- package/dist/owletto/dist/assets/connections-browser-BXsJqieG.js +0 -2
- package/dist/owletto/dist/assets/connector-boxes-CbqSFeVm.js +0 -2
- package/dist/owletto/dist/assets/connector-page-shell-Di6XzkVo.js +0 -2
- package/dist/owletto/dist/assets/connector-provenance-BrnasBW4.js +0 -2
- package/dist/owletto/dist/assets/connector-scope-lists-dQnZARCD.js +0 -2
- package/dist/owletto/dist/assets/consent-Byli4yMs.js +0 -2
- package/dist/owletto/dist/assets/copy-button-Ddf7lBjZ.js +0 -2
- package/dist/owletto/dist/assets/create-B34eskZ_.js +0 -2
- package/dist/owletto/dist/assets/create-DLB9sXgU.js +0 -2
- package/dist/owletto/dist/assets/create-YdAnh3ml.js +0 -2
- package/dist/owletto/dist/assets/create-automation-form-C9PMX7N8.js +0 -3
- package/dist/owletto/dist/assets/create._connectorKey-Bz4OYRiC.js +0 -2
- package/dist/owletto/dist/assets/definition-comparison-B5WgZILB.js +0 -2
- package/dist/owletto/dist/assets/device-pin-tombstone-B06J7Af1.js +0 -2
- package/dist/owletto/dist/assets/device._deviceId-Bh9S4bFp.js +0 -2
- package/dist/owletto/dist/assets/dynamic-schema-form-qWSRtOAv.js +0 -2
- package/dist/owletto/dist/assets/entity-options-BkU_En_f.js +0 -2
- package/dist/owletto/dist/assets/entity-page-BPFDHY8q.js +0 -2
- package/dist/owletto/dist/assets/entity-pages-DxgbjLMt.js +0 -2
- package/dist/owletto/dist/assets/entity-type-page-D0ghgRgq.js +0 -2
- package/dist/owletto/dist/assets/event-card-CjA_dLzq.js +0 -2
- package/dist/owletto/dist/assets/event-detail-CmC-DVrK.js +0 -2
- package/dist/owletto/dist/assets/events-feed-CGzA1w3R.js +0 -2
- package/dist/owletto/dist/assets/filter-bar-CQ_oE7a9.js +0 -2
- package/dist/owletto/dist/assets/guardrails-DkXatmea.js +0 -2
- package/dist/owletto/dist/assets/identity-BwJy3ixB.js +0 -2
- package/dist/owletto/dist/assets/index-35ehGReZ.js +0 -2
- package/dist/owletto/dist/assets/index-B9hYiwBw.js +0 -2
- package/dist/owletto/dist/assets/index-BjcZVe7n.js +0 -7899
- package/dist/owletto/dist/assets/index-BqAVebvY.js +0 -2
- package/dist/owletto/dist/assets/index-BvK1fS1J.js +0 -2
- package/dist/owletto/dist/assets/index-CNEpTkgw.css +0 -1
- package/dist/owletto/dist/assets/index-CRc73k1t.js +0 -2
- package/dist/owletto/dist/assets/index-CYGaSD3y.js +0 -2
- package/dist/owletto/dist/assets/index-CfZGe-zn.js +0 -2
- package/dist/owletto/dist/assets/index-CkiyxW4w.js +0 -2
- package/dist/owletto/dist/assets/index-CzLDNB2E.js +0 -2
- package/dist/owletto/dist/assets/index-D-o5iOVd.js +0 -2
- package/dist/owletto/dist/assets/index-DjYVV1Ml.js +0 -2
- package/dist/owletto/dist/assets/index-VyAX-asP.js +0 -2
- package/dist/owletto/dist/assets/json-diff-DtZtra_g.js +0 -28
- package/dist/owletto/dist/assets/list-skeleton-CIHWCi2a.js +0 -2
- package/dist/owletto/dist/assets/manage-gear-C-0BAMbC.js +0 -2
- package/dist/owletto/dist/assets/member-scope-gate-BQiRAqtx.js +0 -2
- package/dist/owletto/dist/assets/memory-browse-page-Ba32-vVL.js +0 -74
- package/dist/owletto/dist/assets/model-C2q7WDcS.js +0 -2
- package/dist/owletto/dist/assets/model-selector-B2cjCn0V.js +0 -2
- package/dist/owletto/dist/assets/models-CZkH5gtj.js +0 -2
- package/dist/owletto/dist/assets/nav-pill-Bam6s3jj.js +0 -2
- package/dist/owletto/dist/assets/new-BJst6K0b.js +0 -2
- package/dist/owletto/dist/assets/new-DgbivfDe.js +0 -2
- package/dist/owletto/dist/assets/organization-B9U1L-56.js +0 -2
- package/dist/owletto/dist/assets/peek-pane-content-Cq8P38s3.js +0 -2
- package/dist/owletto/dist/assets/permissions-BVlbeY4u.js +0 -2
- package/dist/owletto/dist/assets/proposal-review-shell-BED-DO9C.js +0 -2
- package/dist/owletto/dist/assets/public-shell-ready-Diq15_QW.js +0 -2
- package/dist/owletto/dist/assets/record-activity-CTLwq8s1.js +0 -2
- package/dist/owletto/dist/assets/run-activity-link-Dh1YyCfk.js +0 -2
- package/dist/owletto/dist/assets/run-initiator-CCxNv0rK.js +0 -2
- package/dist/owletto/dist/assets/runs-panel-BwTVaRsE.js +0 -2
- package/dist/owletto/dist/assets/runs-table-CYS1jDdL.js +0 -2
- package/dist/owletto/dist/assets/schema-type-editor-panel-v3nR2Oa2.js +0 -2
- package/dist/owletto/dist/assets/settings-DBgT60nY.js +0 -2
- package/dist/owletto/dist/assets/skills-DDoeRGhJ.js +0 -2
- package/dist/owletto/dist/assets/source-record-panels-m8gECt82.js +0 -2
- package/dist/owletto/dist/assets/status-dot-BnQPFrcU.js +0 -2
- package/dist/owletto/dist/assets/use-login-redirect-ciwfc-7A.js +0 -2
- package/dist/owletto/dist/assets/use-mention-search-CJGCatFS.js +0 -96
- package/dist/owletto/dist/assets/use-scroll-sentinel-BWCrmNIB.js +0 -2
- package/dist/owletto/dist/assets/view-param-filters-CDvwie_f.js +0 -2
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{r,j as e,bl as oe,bm as ie,bn as re,bo as ce,bp as D,I as ae,B as Y,X as Cs,aH as Es,aB as Fs,l as ds,hn as As,ho as Os,S as Lt,H as b,i as R,dh as We,eR as Rt,e5 as Ts,e7 as Ds,gh as Ms,cI as us,eb as Ps,fu as Ls,fl as It,hp as Rs,gu as ct,cU as Ue,Y as rt,gw as bt,bc as ms,d6 as Xe,cP as Is,a3 as $s,Q as qs,aI as Ks,hq as Bs,hr as Ws,hs as zs,ht as Us,hu as Vs,V as Qs,L as Js,v as hs,hl as Gs,bb as Hs,aG as Ys,fC as $t,g_ as Xs,hv as Zs,ce as en,eL as tn,bP as _t,ab as sn,hw as nn,fg as an,hx as on,hy as rn,bO as cn}from"./index-BjcZVe7n.js";import{c as ln,a as qt}from"./model-C2q7WDcS.js";import{C as dn,f as un}from"./entity-options-BkU_En_f.js";import{c as mn,d as hn,e as xn,f as gn,g as pn,u as fn}from"./use-automations-D9hKpufo.js";import{M as vn}from"./model-selector-B2cjCn0V.js";import{b as yn}from"./skill-editor-D_W3QlRz.js";import{C as Nt,J as Kt}from"./json-diff-DtZtra_g.js";import{u as jn,b as Bt,c as Wt,s as _n,o as Nn,a as bn,d as kn,e as Sn,f as wn,v as Cn,r as En}from"./use-mention-search-CJGCatFS.js";import{A as Fn}from"./automation-source-list-Dhucq1sI.js";const at=[{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 An(n){const s=n.trim();if(!s)return null;try{return ln.toString(s,{throwExceptionOnParseError:!0})}catch{return null}}function On({value:n,onChange:s,placeholder:t="No schedule",className:c}){const d=n??"",u=at.some(g=>g.value===d),[i,o]=r.useState(!u&&d!==""),f=g=>{g==="custom"?o(!0):(o(!1),s(g))},N=d?An(d):null,m=d?e.jsx("p",{className:N?"text-xs text-muted-foreground":"text-xs text-destructive",children:N??"Not a valid cron expression."}):null;return!d&&!i?e.jsxs(oe,{onValueChange:f,children:[e.jsx(ie,{className:c??"w-full",children:e.jsx(re,{placeholder:t})}),e.jsx(ce,{children:at.map(g=>e.jsxs(D,{value:g.value,children:[g.label,g.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:g.value})]},g.value))})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[i?e.jsx(ae,{placeholder:"0 */6 * * *",value:d,onChange:g=>s(g.target.value),className:"font-mono text-sm flex-1"}):e.jsxs(oe,{value:d,onValueChange:f,children:[e.jsx(ie,{className:c??"w-full flex-1",children:e.jsx(re,{children:at.find(g=>g.value===d)?.label??d})}),e.jsx(ce,{children:at.map(g=>e.jsxs(D,{value:g.value,children:[g.label,g.value!=="custom"&&e.jsx("span",{className:"ml-2 text-xs text-muted-foreground font-mono",children:g.value})]},g.value))})]}),e.jsx(Y,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",onClick:()=>{o(!1),s("")},children:e.jsx(Cs,{className:"h-4 w-4"})})]}),m]})}const gt="__all_workspace_event_types__",Tn=[],Dn={};function zt(n,s,t){const c=new Map;if(!s)for(const[u,i]of Object.entries(t??{}))c.set(u,{key:u,label:It(u),description:i.description});const d=[...n].filter(u=>!s||u.slug===s).sort((u,i)=>u.slug.localeCompare(i.slug));for(const u of d)for(const[i,o]of Object.entries(u.event_kinds??{})){const f=c.get(i);if(f){!f.description&&o.description&&(f.description=o.description),JSON.stringify(f.metadataSchema??null)!==JSON.stringify(o.metadataSchema??null)&&(f.metadataSchema=void 0);continue}c.set(i,{key:i,label:It(i),description:o.description,metadataSchema:o.metadataSchema})}return[...c.values()].sort((u,i)=>u.label.localeCompare(i.label))}function Ut(n){const s=n[0];if(!s)return;const t=d=>JSON.stringify(Object.keys(d?.properties??{}).sort()),c=t(s);return n.every(d=>t(d)===c)?s:void 0}function Vt(n,s,t){const c=new Set(Object.keys(s.properties??{}));return{...Object.fromEntries(Object.entries(n).filter(([d])=>!c.has(d))),...t}}function Be(n,s,t){return t==="steer"&&(n==="window"||s!=="reply_to_source")?"coalesce":t}function He(n,s){return n==="window"?"silent":s}function Qt(n){return Object.fromEntries(Object.entries(n).filter(([s])=>s==="resource_ref"||s==="resource_type"))}function Jt(n,s,t){const c=new Set(Object.keys(s?.properties??{})),d=new Set(t.flatMap(u=>Object.keys(u.filterSchema?.properties??{})));return Object.fromEntries(Object.entries(Rs(n)).filter(([u])=>u==="resource_ref"||u==="resource_type"||!d.has(u)||c.has(u)))}function Mn({value:n,options:s,onChange:t}){return e.jsx("div",{className:"inline-flex rounded-md border bg-muted/30 p-0.5 text-sm",children:s.map(c=>e.jsx("button",{type:"button","aria-pressed":n===c.value,onClick:()=>t(c.value),className:R("rounded px-3 py-1 transition-colors",n===c.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:c.label},c.value))})}function Gt({events:n,selectedKeys:s,onToggle:t,ariaLabel:c="Events"}){const d=r.useId(),u=n.filter(o=>s.includes(o.key)).map(o=>o.label),i=u.length===0?"Choose events":u.length===1?u[0]:`${u.length} events selected`;return e.jsx(ct,{contentClassName:"w-[var(--radix-popover-trigger-width)] min-w-[280px]",searchPlaceholder:"Filter events...",emptyText:"No events found.",trigger:o=>e.jsxs(Y,{type:"button",variant:"outline",role:"combobox","aria-label":c,"aria-expanded":o,className:"w-full justify-between font-normal",children:[e.jsx("span",{className:R(u.length===0&&"text-muted-foreground"),children:i}),e.jsx(bt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>n.map((o,f)=>{const N=s.includes(o.key),m=`${d}-${f}-state`;return e.jsxs(Ue,{value:`${o.label} ${o.key}`,onSelect:()=>t(o.key),"aria-label":o.label,"aria-describedby":m,className:"cursor-pointer",children:[e.jsx(rt,{className:R("mr-2 h-4 w-4",N?"opacity-100":"opacity-0")}),o.label,e.jsx("span",{id:m,className:"sr-only",children:N?"Selected":"Not selected"})]},o.key)})})}function Pn({organizationId:n,initialTrigger:s,onChange:t,allowedKinds:c,showSectionHeader:d=!0,fieldIdPrefix:u="automation-trigger-"}){const i=Es(n,{status:"active",limit:500}),o=Fs(n),f=ds({organizationId:n}),N=As({organizationId:n}),m=i.data??[],g=o.data??[],I=f.data??Tn,h=N.data??Dn,k=r.useMemo(()=>I.filter(l=>l.organization_id===n),[I,n]),S=s?.kind==="event"&&s?.source==="workspace",F=S||s===void 0,W=c?.length?[...c]:["event","time","manual"],p=W.join("|"),M=(()=>{const l=s===null?"manual":s?.kind==="schedule"?"time":"event";return W.includes(l)?l:W[0]??"event"})(),[j,le]=r.useState(M),[$,de]=r.useState(S?"workspace":typeof s?.connection_id=="number"?String(s.connection_id):s?.kind==="event"&&s.connector_key?"":"workspace"),w=$==="workspace",X=w?"":$,[v,_]=r.useState(typeof s?.entity_type=="string"?s.entity_type:""),Se=r.useMemo(()=>Array.isArray(s?.event_types)?s.event_types:[],[s]),[E,ge]=r.useState(()=>Se.filter(l=>typeof l=="string")),[z,pe]=r.useState(s?.match&&typeof s.match=="object"&&!Array.isArray(s.match)?s.match:{}),[fe,ve]=r.useState(typeof s?.cron=="string"?s.cron:"0 9 * * 1-5"),Ne=typeof s?.timezone=="string"?s.timezone:void 0,[q,ye]=r.useState(s?.kind==="schedule"||F&&s?.execution!=="turn"||s?.execution==="window"?"window":"turn"),[K,ue]=r.useState(He(q,s?.output==="reply_to_source"?"reply_to_source":"silent")),[J,Z]=r.useState(s?.kind==="schedule"||F&&s?.active_run!=="queue"?"coalesce":Be(q,K,s?.active_run==="coalesce"||s?.active_run==="steer"?s.active_run:"queue")),[je,Te]=r.useState(s?.skip_if_unchanged!==!1),[De,Me]=r.useState(!1);r.useEffect(()=>{const l=p.split("|");if(!l.includes(j)){const y=l[0]??"event";le(y),ye(y==="time"||y==="event"&&w?"window":"turn"),Z(y==="time"||y==="event"&&w?"coalesce":"queue"),ue("silent")}},[p,j,w]);const se=m.find(l=>String(l.id)===X),x=i.isLoading||o.isLoading,me=f.isLoading,U=typeof s?.connector_key=="string"?s.connector_key:void 0,te=j==="event"&&!w&&s?.kind==="event"&&s?.source!=="workspace"&&typeof s.connection_id=="number"&&String(s.connection_id)===X&&!se,P=j==="event"&&!w&&s?.kind==="event"&&s?.source!=="workspace"&&s.connection_id==null&&U!==void 0&&X==="",Pe=g.find(l=>l.key===(se?.connector_key??(P?U:void 0))),G=Pe?.automation_events??[],Ve=G.filter(l=>E.includes(l.key)),we=Ve[0],Le=k.find(l=>l.slug===v),Fe=[...k.filter(l=>Object.keys(l.event_kinds??{}).length>0||l.slug===v),...v&&!Le?[{slug:v,name:v}]:[]],A=r.useMemo(()=>zt(k,v||void 0,h),[k,v,h]),Ae=A.filter(l=>E.includes(l.key)),Re=Ae[0],he=Ut(Ve.map(l=>l.filterSchema)),Ce=Ut(Ae.map(l=>l.metadataSchema)),Ie=!!(w&&v&&!Le),$e=te||P,xe=(j==="event"?w?E.length>0&&!Ie:!!(E.length>0&&(X&&se||$e)):j==="time"?!!fe.trim():!0)&&(j!=="event"||!Os(z));r.useEffect(()=>{let l;if(xe&&j==="event"&&!w){const y=Jt(z,he,Pe?.automation_events??[]);se||P?l={kind:"event",source:"connector",connector_key:se?.connector_key??U,...se?{connection_id:Number(X)}:{},event_types:E,...Object.keys(y).length>0?{match:y}:{},execution:q,active_run:Be(q,K,J),output:He(q,K),skip_if_unchanged:je}:te&&(l=s?{...s,source:"connector"}:void 0)}else if(xe&&j==="event"&&w){const y=Jt(z,Ce,A.map(O=>({filterSchema:O.metadataSchema})));l={kind:"event",source:"workspace",...v?{entity_type:v}:{},event_types:E,...Object.keys(y).length>0?{match:y}:{},execution:q,active_run:J==="queue"?"queue":"coalesce"}}else xe&&j==="time"&&(l={kind:"schedule",cron:fe.trim(),...Ne?{timezone:Ne}:{},execution:"window",active_run:"coalesce",skip_if_unchanged:je});t({ready:xe,kind:j,trigger:l})},[J,X,se,fe,Pe,E,q,z,j,U,Ne,s,w,t,K,xe,he,Ce,je,v,A,P,te]);const qe=l=>{const y=m.find(T=>String(T.id)===l),O=g.find(T=>T.key===y?.connector_key),ee=E.filter(T=>O?.automation_events?.some(ke=>ke.key===T)),ne=O?.automation_events?.find(T=>T.key===ee[0]),be=y?.connector_key!==(se?.connector_key??U);if(de(l),ge(ee),!ne)pe(Qt);else if(be){const T=ne.defaults?.execution??"turn",ke=ne.defaults?.activeRun??"queue",V=He(T,ne.defaults?.output??"silent");pe(Qt),ye(T),Z(Be(T,V,ke)),ue(V)}},et=l=>{if(l==="workspace"){de("workspace"),ge(y=>y.filter(O=>A.some(ee=>ee.key===O))),pe({}),ye("window"),Z("coalesce"),ue("silent");return}qe(l)},Je=l=>{const y=E.includes(l)?E.filter(T=>T!==l):G.map(T=>T.key).filter(T=>T===l||E.includes(T));if(ge(y),y[0]===E[0])return;const O=G.find(T=>T.key===y[0]),ee=O?.defaults?.execution??"turn",ne=O?.defaults?.activeRun??"queue",be=He(ee,O?.defaults?.output??"silent");ye(ee),Z(Be(ee,be,ne)),ue(be)},tt=l=>{const y=l===gt?"":l,O=k.find(ne=>ne.slug===y),ee=zt(k,O?.slug,h);_(y),ge(ne=>ne.filter(be=>ee.some(T=>T.key===be))),pe({})},st=l=>{ge(y=>y.includes(l)?y.filter(O=>O!==l):A.map(O=>O.key).filter(O=>O===l||y.includes(O)))},Oe=[{value:"event",label:"Event"},{value:"time",label:"Schedule"},{value:"manual",label:"Manual"}].filter(l=>W.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,Oe.length>1?e.jsx(Mn,{value:j,options:Oe,onChange:l=>{le(l),ye(l==="time"||l==="event"&&w?"window":"turn"),Z(l==="time"||l==="event"&&w?"coalesce":"queue"),ue("silent")}}):null,j==="event"?x||w&&me?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Lt,{className:"h-9 w-full"}),e.jsx(Lt,{className:"h-9 w-full"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Source"}),e.jsx(dn,{connections:m,value:$,onValueChange:et,disabled:$e,includeWorkspaceEvents:!0,ariaLabel:"Source",placeholder:"Choose a source"}),te?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."}):P?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This Automation listens across all"," ",String(s?.connector_key)," connections. Other Automation fields can still be edited."]}):null]}),w?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:A.length>1?"Events":"Event"}),A.length>0?e.jsx(Gt,{events:A,selectedKeys:E,onToggle:st}):e.jsx("div",{className:R(We,"px-3 py-2 text-sm text-muted-foreground"),children:v?"This entity type has no declared Automation events.":"This workspace has no declared Automation events."}),Re?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:Re.description}):null,Ie?e.jsxs("p",{className:"text-xs text-destructive",children:["This trigger filters on entity type “",v,"”, 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."})]}),Ce?e.jsx(Rt,{schema:Ce,values:z,onValuesChange:l=>pe(y=>Vt(y,Ce,l)),fieldIdPrefix:`${u}workspace-`},`${v||"workspace"}:${E.join(",")}`):null]}):se||P?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:G.length>1?"Events":"Event"}),G.length?e.jsx(Gt,{events:G,selectedKeys:E,onToggle:Je}):e.jsx("div",{className:R(We,"px-3 py-2 text-sm text-muted-foreground"),children:"This connector has not published subscribable events."}),we?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:we.description}):null]}),typeof z.resource_ref=="string"||he?e.jsxs("div",{className:"space-y-3",children:[typeof z.resource_ref=="string"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Resource"}),e.jsx("div",{className:R(We,"px-3 py-2 text-sm"),children:z.resource_ref})]}):null,he?e.jsx(Rt,{schema:he,values:z,onValuesChange:l=>pe(y=>Vt(y,he,l)),fieldIdPrefix:u},E.join(",")):null]}):null]}):$?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose workspace events or a connected app as the source."})]}):j==="time"?e.jsx(On,{value:fe,onChange:ve}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this Automation explicitly from Lobu, the API, CLI, or MCP."}),j!=="manual"&&!$e?e.jsxs(Ts,{open:De,onOpenChange:Me,children:[e.jsx(Ds,{asChild:!0,children:e.jsxs(Y,{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(Ms,{className:"h-4 w-4"}),"Trigger options",e.jsxs("span",{className:"font-normal text-muted-foreground",children:["· ",q==="turn"?"Each event":"Window"," ·"," ",j==="time"?"Combine":w?J==="queue"?"Queue":"Combine":J==="queue"?"Queue":J==="coalesce"?"Combine":"Update current run",j==="event"&&!w?` · ${q==="turn"&&K==="reply_to_source"?"Reply":"Save in Lobu"}`:""]})]}),e.jsx(us,{className:R("h-4 w-4 transition-transform",De&&"rotate-180")})]})}),e.jsxs(Ps,{className:"space-y-4 pt-3",children:[j==="event"&&w?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Entity type filter"}),e.jsxs(oe,{value:v||gt,onValueChange:tt,children:[e.jsx(ie,{"aria-label":"Entity type filter",children:e.jsx(re,{})}),e.jsxs(ce,{children:[e.jsx(D,{value:gt,children:"All event types"}),Fe.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,j==="event"?e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Run"}),e.jsxs(oe,{value:q,onValueChange:l=>{const y=l,O=He(y,K);ye(y),ue(O),Z(Be(y,O,J))},children:[e.jsx(ie,{children:e.jsx(re,{})}),e.jsxs(ce,{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(b,{children:"When busy"}),e.jsxs(oe,{value:J,onValueChange:l=>Z(l),children:[e.jsx(ie,{children:e.jsx(re,{})}),e.jsxs(ce,{children:[e.jsx(D,{value:"queue",children:"Queue"}),e.jsx(D,{value:"coalesce",children:"Combine waiting events"}),!w&&q==="turn"&&K==="reply_to_source"&&we?.capabilities?.steering?e.jsx(D,{value:"steer",children:"Update the current run"}):null]})]})]})]}):null,q==="window"&&(j==="time"||!w)?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(Ls,{"aria-label":"Skip unchanged windows",checked:je,onCheckedChange:Te})]}):null,j==="event"&&!w&&q==="turn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Result"}),e.jsxs(oe,{value:K,onValueChange:l=>{const y=l;ue(y),Z(Be(q,y,J))},children:[e.jsx(ie,{children:e.jsx(re,{})}),e.jsxs(ce,{children:[we?.capabilities?.replyToSource?e.jsx(D,{value:"reply_to_source",children:"Reply where it happened"}):null,e.jsx(D,{value:"silent",children:"Save in Lobu"})]})]}),we?.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 Ln=16;function ze(){return crypto.randomUUID()}function Rn(n){return n===void 0?[{key:ze(),initial:void 0}]:n.length===0?[{key:ze(),initial:null}]:n.map(s=>({key:ze(),initial:s}))}function xs(n){return n?n.kind==="time"||n.trigger?.kind==="schedule":!1}function In(n,s){return n?n.ready===s.ready&&n.kind===s.kind&&JSON.stringify(n.trigger)===JSON.stringify(s.trigger):!1}function $n(n,s){const t=n.map(o=>s[o.key]??{ready:!1,kind:"event"});if(!(n.length>1)&&t[0]?.kind==="manual")return{ready:t[0].ready,triggers:[]};const d=t.filter(xs).length;return{ready:!t.some(o=>o.kind==="manual")&&d<=1&&t.length>0&&t.every(o=>o.ready&&o.trigger),triggers:t.filter(o=>o.trigger).map(o=>o.trigger)}}function ja({organizationId:n,initialTriggers:s,onChange:t}){const c=r.useId(),[d,u]=r.useState(()=>Rn(s)),[i,o]=r.useState({}),f=r.useRef("");r.useEffect(()=>{const h=$n(d,i),k=JSON.stringify(h);k!==f.current&&(f.current=k,t(h))},[d,i,t]);const N=d.find(h=>xs(i[h.key]))?.key??d.find(h=>h.initial&&typeof h.initial=="object"&&h.initial.kind==="schedule"&&!i[h.key])?.key??null,m=r.useCallback((h,k)=>{o(S=>In(S[h],k)?S:{...S,[h]:k})},[]),g=()=>{const h=d[0],k=h?i[h.key]:void 0;if(d.length===1&&(k?.kind==="manual"||h?.initial===null)){const S=ze();o({}),u([{key:S,initial:void 0}]);return}u(S=>[...S,{key:ze(),initial:void 0}])},I=h=>{if(d.length<=1){const k=ze();o({}),u([{key:k,initial:null}]);return}o(k=>{const S={...k};return delete S[h],S}),u(k=>k.filter(S=>S.key!==h))};return e.jsxs("section",{className:"space-y-4","aria-labelledby":`${c}-heading`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{id:`${c}-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,k)=>{const S=d.length>1,F=S?N&&N!==h.key?["event"]:["event","time"]:["event","time","manual"],W=i[h.key],p=S||(W?W.kind!=="manual":h.initial!==null);return e.jsxs("div",{className:R("space-y-3 rounded-lg border bg-card/40 p-3",S&&"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:S?`Trigger ${k+1}`:"Trigger"}),p?e.jsx(Y,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive","aria-label":S?`Remove trigger ${k+1}`:"Clear trigger",onClick:()=>I(h.key),children:e.jsx(ms,{className:"h-3.5 w-3.5"})}):null]}),e.jsx(qn,{slotKey:h.key,organizationId:n,initial:h.initial,kinds:F,fieldIdPrefix:`${c}-${h.key}-`,onChange:m})]},h.key)})}),e.jsxs(Y,{type:"button",variant:"outline",size:"sm",className:"w-full sm:w-auto",onClick:g,disabled:d.length>=Ln,children:[e.jsx(Xe,{className:"mr-1.5 h-3.5 w-3.5"}),"Add another trigger"]})]})}function qn({slotKey:n,organizationId:s,initial:t,kinds:c,fieldIdPrefix:d,onChange:u}){const i=r.useCallback(o=>u(n,o),[u,n]);return e.jsx(Pn,{organizationId:s,initialTrigger:t,allowedKinds:c,showSectionHeader:!1,fieldIdPrefix:d,onChange:i})}const Kn=["claude-code","codex","opencode","pi","agy"],Bn={"claude-code":"Claude Code",codex:"Codex",opencode:"OpenCode",pi:"Pi",agy:"Antigravity (agy)"},Wn=[{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__search_sdk,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(Wn.map(n=>[n.kind,n]));const Ht={agents:!0,lobuEmbedded:!1};function zn(){const{data:n}=Is({queryKey:["features"],queryFn:async()=>{const s=await $s(`${qs}/api/features`);return s.ok?s.json():Ht},staleTime:3e4,refetchInterval:6e4});return n??Ht}const pt="__none__";function Ye(n){return`${n.connection_id}:${n.feed_key}`}function Un(n){const s=n.indexOf(":");if(s<=0)return null;const t=Number(n.slice(0,s)),c=n.slice(s+1);return!Number.isSafeInteger(t)||t<=0||!c?null:{connection_id:t,channel_id:c}}function ft(n){return n?`${n.connection_id}:${n.channel_id}`:""}function ot(n){return`${n.display_name||n.feed_key} (${n.feed_key})`}function Vn(n){return n.connection_name?`connection ${n.connection_id} (${n.connection_name})`:`connection ${n.connection_id}`}function Yt(n,s){return n.store==="channel_messages"&&n.target_agent_id===s&&n.connection_status==="active"}function Qn({organizationId:n,agentId:s,value:t,onChange:c,disabled:d=!1,automationName:u,onPendingChange:i}){const{data:o=[],isLoading:f}=Ks(n),N=ft(t),[m,g]=r.useState(null),[I,h]=r.useState(!1),k=r.useRef(s),S=r.useMemo(()=>o.filter(v=>Yt(v,s)),[o,s]);r.useEffect(()=>{if(k.current===s)return;const v=k.current;if(k.current=s,g(null),h(!1),!v||t==null)return;const _=ft(t);if(_==="")return;o.some(E=>Yt(E,s)&&Ye(E)===_)||c(null)},[s,o,t,c]);const F=m??N,W=F===""?pt:F,p=S.find(v=>Ye(v)===F),M=m!==null&&m!==""&&m!==N;r.useEffect(()=>{i?.(M)},[M,i]);const j=p??(m?void 0:S.find(v=>Ye(v)===N)),le=v=>{const _=v===pt?"":v;if(_===""){g(null),h(!1),c(null);return}if(_===N){g(null),h(!1);return}g(_),h(!1)},$=v=>{if(h(v),v&&m){const _=Un(m);_&&(g(null),c(_))}else!v&&m&&g(null)},w=(t&&ft(t)!==""?t:void 0)??(p?{connection_id:p.connection_id,channel_id:p.feed_key}:void 0),X=(u??"").trim()||"This automation";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"automation-delivery-target",children:["Digest destination"," ",e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),s?e.jsxs(oe,{value:W,onValueChange:le,disabled:d||f,children:[e.jsx(ie,{id:"automation-delivery-target",className:"font-mono text-sm",children:e.jsx(re,{placeholder:f?"Loading bound channels…":S.length===0?"No bound chat channels":"No digest — runs stay silent"})}),e.jsxs(ce,{children:[e.jsx(D,{value:pt,children:"No digest — runs stay silent"}),S.map(v=>e.jsxs(D,{value:Ye(v),children:[ot(v)," · ",v.connector_key]},Ye(v)))]})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select a managed agent first — only channels bound to that agent can receive digests."}),s&&!f&&S.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No active chat channels are bound to this agent yet. Link a private channel first, then select it here."}):null,M&&p?e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-xs",children:[e.jsx("input",{type:"checkbox",checked:I,onChange:v=>$(v.target.checked),className:"mt-0.5","aria-label":`Confirm digest delivery to ${ot(p)}`}),e.jsxs("span",{className:"text-muted-foreground",children:["I confirm posting material-change digests to"," ",e.jsx("span",{className:"font-medium text-foreground",children:ot(p)}),". Destination changes are audited."]})]}):null,j||w?e.jsxs("div",{className:R(We,"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:j?`${j.connector_key} ${ot(j)} · ${Vn(j)}`:`${w?.channel_id} · connection ${w?.connection_id}`})]}),e.jsxs("p",{className:"font-mono text-xs",children:[X," 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 Xt=4096;function Jn({open:n,onOpenChange:s,initial:t,onSubmit:c}){const[d,u]=r.useState(""),[i,o]=r.useState(""),[f,N]=r.useState(null);r.useEffect(()=>{n&&(u(t?.name??""),o(t?.query??""),N(null))},[n,t]);const m=()=>{const I=d.trim(),h=i.trim();if(!I){N("Give the SQL source a name.");return}if(!h){N("Enter a query.");return}if(h.length>Xt){N(`Query is too long (${h.length} chars, max ${Xt}).`);return}c({name:I,query:h}),s(!1)},g=!!t;return e.jsx(Bs,{open:n,onOpenChange:s,children:e.jsxs(Ws,{className:"max-w-2xl",children:[e.jsxs(zs,{children:[e.jsx(Us,{children:g?"Edit SQL source":"SQL source"}),e.jsx(Vs,{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(b,{htmlFor:"sql-source-name",children:"Name"}),e.jsx(ae,{id:"sql-source-name",value:d,onChange:I=>u(I.target.value),placeholder:"recent_cancellations",autoFocus:!g}),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(b,{htmlFor:"sql-source-query",children:"Query"}),e.jsx(Nt,{value:i,onChange:o,language:"sql",placeholder:"SELECT id, payload_text, occurred_at FROM events ORDER BY occurred_at DESC",minHeight:"160px"})]}),f?e.jsx("p",{className:"text-sm text-destructive",children:f}):null]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(Y,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(Y,{onClick:m,children:g?"Save":"Add source"})]})]})})}const Gn=["skill","feed","connection","connector","metric","entity_type"];function Hn({value:n,onChange:s,library:t,pinned:c,required:d,error:u,owner:i,agentId:o,sources:f,onAddSources:N}){const m=jn(Gn,Bt,{skills:t,skillAgentId:o||null}),g=r.useRef(null),[I,h]=r.useState(null),k=r.useMemo(()=>{if(!f)return[];const p=new Set(f.map(M=>M.query.trim()));return Wt(n).filter(M=>!p.has(M.query.trim()))},[n,f]),S=_n(n),F=Nn(c.filter(p=>S.includes(p.name)),t),W=t.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(b,{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)"})]}),S.length>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[S.length,"/",Bt," skills"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring",children:e.jsx(bn,{value:n,onChange:s,onSubmit:()=>{},submitOnEnter:!1,searchRefs:m,handleRef:g,onSqlRequest:()=>h({}),onSqlEdit:(p,M)=>h({initial:p,pos:M}),placeholder:W?"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(Jn,{open:I!==null,onOpenChange:p=>{p||h(null)},initial:I?.initial,onSubmit:p=>{g.current?.insertSql(p,I?.pos),h(null)}}),k.length>0&&N?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:[k.length===1?`"${k[0]?.name}" is referenced in the instructions but is not a source on this Automation.`:`${k.length} references in the instructions are not sources on this Automation.`," ","Editing an Automation does not add them automatically."]}),e.jsx(Y,{type:"button",variant:"outline",size:"sm",onClick:()=>N(Wt(n,f)),children:k.length===1?"Add as a source":"Add as sources"})]}):null,S.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:S.map(p=>{const M=F.includes(p),j=!t.some(le=>le.name===p);return e.jsxs(Qs,{variant:j?"destructive":"secondary",className:"font-normal",children:[p,j?" · unavailable":M?" · newer text":null]},p)})}):null,F.length>0?e.jsxs("p",{className:"rounded-lg border border-dashed p-3 text-xs text-muted-foreground",children:[F.length===1?`"${F[0]}" has been edited since this Automation pinned it.`:`${F.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,!W&&o?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This agent has no skills yet."," ",e.jsx(Js,{to:"/$owner/agents/$agentId/skills",params:{owner:i,agentId:o},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:W?"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 Yn=["connection","connector","feed","metric","entity_type"];function Xn({sources:n,onChange:s,disabled:t}){const{currentOwner:c,resolvedOrganizationId:d}=hs(),[u,i]=r.useState(""),{refs:o}=kn({owner:c,organizationId:d,kinds:Yn,query:u,limitPerKind:10});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Sources"}),e.jsx(Fn,{sources:n,disabled:t,onRemove:f=>s(n.filter(N=>N.query!==f.query))}),e.jsx("div",{className:"flex gap-2",children:e.jsx(ct,{searchPlaceholder:"Search feeds, connections, metrics…",emptyText:"No matching reference.",onQueryChange:i,trigger:()=>e.jsxs(Y,{type:"button",variant:"outline",size:"sm",disabled:t,children:[e.jsx(Xe,{className:"mr-2 h-3.5 w-3.5"}),"Add source"]}),children:f=>o.map(N=>e.jsxs(Ue,{value:`${N.label} ${N.kind}`,onSelect:()=>{s(Sn(N,n)),f()},children:[e.jsx("span",{className:"truncate text-sm",children:N.label}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-muted-foreground",children:N.kind})]},`${N.kind}:${N.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 Zn({organizationId:n,value:s,onChange:t,className:c}){const{data:d=[]}=Gs(n),u=un(d),i=u.find(o=>o.id===s);return e.jsx(ct,{contentClassName:"w-[300px]",searchPlaceholder:"Search entities...",emptyText:"No entities found.",trigger:o=>e.jsxs(Y,{variant:"outline",role:"combobox","aria-expanded":o,className:R("w-full justify-between",c),children:[i?`${i.name} (${i.entityType})`:"All workspace",e.jsx(bt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:o=>e.jsxs(e.Fragment,{children:[e.jsxs(Ue,{value:"all workspace",onSelect:()=>{t(void 0),o()},className:"cursor-pointer",children:[e.jsx(rt,{className:R("mr-2 h-4 w-4",s===void 0?"opacity-100":"opacity-0")}),e.jsx("span",{children:"All workspace"})]}),u.map(f=>e.jsxs(Ue,{value:`${f.name} ${f.entityType}`,onSelect:()=>{t(f.id),o()},className:"cursor-pointer",children:[e.jsx(rt,{className:R("mr-2 h-4 w-4",s===f.id?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[f.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",f.entityType,")"]})]})]},f.id))]})})}function it(n){if(Array.isArray(n))return n;if(typeof n=="string"&&n.startsWith("{")&&n.endsWith("}")){const s=n.slice(1,-1);return s?s.split(",").map(t=>t.trim()):[]}return[]}function Zt(n){return JSON.stringify(n,(s,t)=>t&&typeof t=="object"&&!Array.isArray(t)?Object.fromEntries(Object.keys(t).sort().map(c=>[c,t[c]])):t)}const ea=Kn.map(n=>({value:n,label:Bn[n]})),es=[{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 ts(n){const s=!!(n?.prompt?.trim()||n?.skills?.some(c=>c.content.trim())),t=!!n?.reaction_script?.trim();return s&&t?"both":t?"code":"agent"}const ta=["text","number","date","boolean","json"],sa=[{value:"key",label:"Key"},{value:"plain",label:"Plain"}],vt=[{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 ss=0;function na(){return ss+=1,`field-${ss}`}function gs(n={}){return{id:na(),name:n.name??"",type:n.type??"text",role:n.role??"plain"}}function Ze(n){return n.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")}function aa(n){return n?Object.keys(n).every(s=>["entity_type","entity_path","key_fields","key_output_field"].includes(s)):!0}function ns(n){return n?aa(n.keying_config)?"fields":"json":"fields"}function as(n){const s=n?.keying_config?.entity_type;return typeof s=="string"?s:""}function os(n){const s=n?.keying_config?.entity_path;return typeof s=="string"&&s.trim()?s:"$"}function is(n){const s=new Map,t=Array.isArray(n?.keying_config?.key_fields)?n?.keying_config?.key_fields:[];for(const c of t){if(typeof c!="string")continue;const d=Ze(c);d&&s.set(d,gs({name:d,role:"key"}))}return Array.from(s.values())}function H(n,s){const t=n?.execution_config?.[s];return typeof t=="number"||typeof t=="string"?String(t):""}function rs(n,s,t){const c=n?.execution_config?.[s];return typeof c=="string"&&t.includes(c)?c:""}function yt(n,s){const t=n.trim();if(!t)return{};const c=Number(t);return Number.isFinite(c)?{value:c}:{error:`${s} must be a number.`}}function cs({entityType:n,entityPath:s,fields:t}){const d=t.map(o=>({...o,name:Ze(o.name)})).filter(o=>o.name).filter(o=>o.role==="key").map(o=>o.name),u=Ze(n),i=s.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:i,key_fields:d,key_output_field:`${u}_key`}:void 0})}function oa(n,s){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:s})]})}function ls(n){return!!(n?.keying_config||n?.reactions_guidance||n?.model_config||n?.execution_config||n?.sources?.length||it(n?.tags).length)}function ia({organizationId:n,entityId:s,prefill:t,onSubmit:c,isSubmitting:d,error:u,isEditing:i,onCancel:o,triggerFields:f,submitLabel:N="Create Automation",submitDisabled:m=!1,triggers:g,savedTriggers:I=g,agentFirst:h=!1}){const{lobuEmbedded:k}=zn(),{currentOwner:S}=hs(),{data:F=[]}=Hs(),{data:W=[]}=Ys(),[p,M]=r.useState(t?.managed_agent_id??""),j=!!t?.managed_agent_id&&!i,[le,$]=r.useState(t?.delivery_target??null),[de,w]=r.useState(!1),[X,v]=r.useState(t?.device_worker_id??""),[_,Se]=r.useState(()=>{const a=qt(t);return a==="manual"&&!i?"agent":a}),E=_==="external"||_==="script",ge=E&&i,[z,pe]=r.useState(t?.agent_kind??""),{data:fe=[]}=ds({organizationId:n}),[ve,Ne]=r.useState(t?.name??""),[q,ye]=r.useState(t?.slug??""),[K,ue]=r.useState(!!t?.slug),[J,Z]=r.useState(t?.description??""),[je,Te]=r.useState(t?.prompt??""),[De,Me]=r.useState(!1),se=t?.skills??[],[x,me]=r.useState(t?.sources??[]),[U,te]=r.useState(t?.entity_id??s),[P,Pe]=r.useState(t?.reaction_script??""),[G,Ve]=r.useState(()=>ts(t)),[we,Le]=r.useState(t?.keying_config?JSON.stringify(t.keying_config,null,2):""),[Fe,A]=r.useState(null),[Ae,Re]=r.useState(()=>ns(t)),[he,Ce]=r.useState(()=>as(t)),[Ie,$e]=r.useState(()=>os(t)),[Qe,xe]=r.useState(()=>is(t)),[qe,et]=r.useState(t?.reactions_guidance??""),[Je,tt]=r.useState(()=>H(t,"timeout_seconds")),[st,kt]=r.useState(()=>H(t,"max_budget_usd")),[Oe,l]=r.useState(()=>H(t,"model")),[y,O]=r.useState(()=>rs(t,"permission_mode",vt.map(a=>a.value))),[ee,ne]=r.useState(()=>H(t,"effort")),[be,T]=r.useState(()=>H(t,"finalize_nudges")),[ke,V]=r.useState(null),[nt,St]=r.useState(it(t?.tags).join(", ")),[lt,wt]=r.useState(""),[dt,Ct]=r.useState(!!(i||ls(t)));r.useEffect(()=>{if(!t)return;Ne(t.name??""),ye(t.slug??""),ue(!!t.slug),Z(t.description??""),Te(t.prompt??""),Me(!1),me(t.sources??[]),te(t.entity_id??s),v(t.device_worker_id??"");const a=qt(t);Se(a==="manual"&&!i?"agent":a),pe(t.agent_kind??""),Pe(t.reaction_script??""),Ve(ts(t)),Le(t.keying_config?JSON.stringify(t.keying_config,null,2):""),A(null),Re(ns(t)),Ce(as(t)),$e(os(t)),xe(is(t)),et(t.reactions_guidance??""),tt(H(t,"timeout_seconds")),kt(H(t,"max_budget_usd")),l(H(t,"model")),O(rs(t,"permission_mode",vt.map(C=>C.value))),ne(H(t,"effort")),T(H(t,"finalize_nudges")),V(null),St(it(t.tags).join(", ")),wt(""),M(t.managed_agent_id??""),$(t.delivery_target??null),Ct(!!(i||ls(t)))},[t,s,i]);const ps=K?q:$t(ve),{data:fs}=Xs(p||null),{data:vs}=Zs(p||null,{enabled:!!p}),ut=yn(fs??null,vs?.catalog??[]),ys=wn(g),mt=P.trim().length>0,Ge=!i&&G==="code"?"":je,js=!i&&G==="agent"?void 0:P.trim()||void 0,Et=_==="script"||(i||G==="code")&&mt,Ft=Cn(Ge,ut,g,Et),_s=De||Ge.trim()!==""?Ft:null,At=En(Ge,ut),ht=[["Name",t?.name??"",ve],["Description",t?.description??"",J],["Instructions",t?.prompt??"",Ge],["Sources",t?.sources??[],x],["Triggers",I??[],g??[]],["Reaction script",t?.reaction_script??"",P],["Reactions guidance",t?.reactions_guidance??"",qe],["Agent",t?.managed_agent_id??null,_==="manual"?null:p||null],["Device",t?.device_worker_id??null,_==="device"&&X||null],["Device runtime",t?.agent_kind??null,_==="device"&&z||null],["Delivery target",t?.delivery_target??null,le],["Timeout seconds",H(t,"timeout_seconds"),Je],["Budget USD",H(t,"max_budget_usd"),st],["Model",H(t,"model"),Oe],["Permission mode",H(t,"permission_mode"),y],["Effort",H(t,"effort"),ee],["Finalize nudges",H(t,"finalize_nudges"),be],["Tags",it(t?.tags),nt.split(",").map(a=>a.trim()).filter(Boolean)],["Change notes","",lt]].filter(([,a,C])=>Zt(a)!==Zt(C)),Ot=!i&&G!=="agent",Ke=h&&!i,Tt=_==="device"||_==="script"||Ke&&_==="agent",Ns=Tt&&!p.trim(),xt=F.length===1?F[0]?.agentId:void 0;r.useEffect(()=>{Ke&&_==="agent"&&!p&&xt&&M(xt)},[Ke,_,p,xt]);const Dt=!!ve.trim()&&!Ns&&!Ft&&(!Ot||mt)&&!de,bs=ys&&!Et&&At.length===0,ks=()=>{if(E&&!i){V("Choose a native agent or code module before creating a copy of a legacy Automation.");return}if(!Dt)return;let a;if(!i&&Ae==="fields"){const _e=cs({entityType:he,entityPath:Ie,fields:Qe});if(_e.error){A(_e.error);return}a=_e.keyingConfig,A(null)}else if(!i){if(we.trim())try{const _e=JSON.parse(we);if(typeof _e!="object"||Array.isArray(_e)){A("Keying config must be a JSON object.");return}a=_e}catch{A("Invalid JSON. Please check the syntax.");return}A(null)}const C=yt(Je,"Timeout");if(C.error){V(C.error);return}if(C.value!==void 0&&(!Number.isInteger(C.value)||C.value<1)){V("Timeout must be a whole number greater than 0.");return}const B=yt(st,"Budget");if(B.error){V(B.error);return}if(B.value!==void 0&&B.value<0){V("Budget cannot be negative.");return}const L=yt(be,"Finalize nudges");if(L.error){V(L.error);return}if(L.value!==void 0&&(!Number.isInteger(L.value)||L.value<0||L.value>5)){V("Finalize nudges must be a whole number from 0 to 5.");return}const Ee={...Object.fromEntries(Object.entries(t?.execution_config??{}).filter(([_e])=>!["timeout_seconds","max_budget_usd","model","permission_mode","effort","finalize_nudges"].includes(_e))),...C.value!==void 0?{timeout_seconds:C.value}:{},...B.value!==void 0?{max_budget_usd:B.value}:{},...Oe.trim()?{model:Oe.trim()}:{},...y?{permission_mode:y}:{},...ee.trim()?{effort:ee.trim()}:{},...L.value!==void 0?{finalize_nudges:L.value}:{}},Q=E?void 0:Object.keys(Ee).length>0||i?Ee:void 0;V(null);const ws=nt.trim()?nt.split(",").map(_e=>_e.trim()).filter(Boolean):i?[]:void 0;c({slug:ps,name:ve.trim(),description:i?J.trim():J.trim()||void 0,prompt:Ge,skills:At,entity_id:U,sources:x,reaction_script:js,keying_config:a,reactions_guidance:i?qe.trim():qe.trim()||void 0,execution_config:Q,tags:ws,outputs:t?.outputs,change_notes:lt.trim()||void 0,managed_agent_id:ge?t?.managed_agent_id??null:_==="manual"?null:p.trim()||null,device_worker_id:_==="device"&&X.trim()||null,agent_kind:_==="device"&&z.trim()||null,delivery_target:le})},Mt=e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"scratch-reaction",children:["Reaction Script"," ",Ot?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(Nt,{value:P,onChange:Pe,language:"typescript",placeholder:"export default async function reaction(ctx) { ... }",minHeight:"120px"}),i?null:e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Export ",e.jsx("code",{children:"prepare"})," to save sources before analysis and a default handler to run after completion. A module without agent instructions, extraction input or outputs runs without an LLM."]})]}),Pt=!j&&!ge&&_!=="manual"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"scratch-agent-id",children:[E?"Owning agent":"Agent",Tt&&e.jsx("span",{className:"text-destructive",children:" *"})]}),k?e.jsxs(oe,{value:p,onValueChange:M,disabled:F.length===0,children:[e.jsx(ie,{id:"scratch-agent-id",className:"font-mono text-sm",children:e.jsx(re,{placeholder:F.length===0?"No agents yet":"Select a Lobu agent"})}),e.jsx(ce,{children:F.map(a=>e.jsxs(D,{value:a.agentId,children:[a.name," (",a.agentId,")"]},a.agentId))})]}):e.jsx(ae,{id:"scratch-agent-id",value:p,onChange:a=>{M(a.target.value)},placeholder:"e.g., agent-123",className:"font-mono text-sm"}),_==="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."}):Ke?e.jsx("p",{className:"text-xs text-muted-foreground",children:"This agent answers the conversation's messages."}):null]}):null,Ss=F.find(a=>a.agentId===p)?.name??p;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(b,{htmlFor:"scratch-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),!i&&e.jsx("button",{type:"button",onClick:()=>ue(!K),className:"text-xs text-muted-foreground hover:text-foreground",children:K?"Use automatic slug":"Customize slug"})]}),e.jsx(ae,{id:"scratch-name",value:ve,onChange:a=>Ne(a.target.value),placeholder:"e.g., Escalation signals"}),!i&&K?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-slug",children:"Slug"}),e.jsx(ae,{id:"scratch-slug",value:q,onChange:a=>ye(a.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:$t(ve)||"custom-slug"})]}):null]})}),Ke?j?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Agent"}),e.jsx("p",{className:"text-sm",children:Ss})]}):Pt:null,i?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:es.map(a=>e.jsx("button",{type:"button","aria-pressed":G===a.value,onClick:()=>Ve(a.value),className:R("rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors",G===a.value?"bg-secondary text-secondary-foreground":"text-muted-foreground hover:bg-accent/50 hover:text-foreground"),children:a.label},a.value))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:es.find(a=>a.value===G)?.hint})]}),i||G!=="code"?e.jsx(Hn,{value:je,onChange:a=>{Me(!0),Te(a)},library:ut,pinned:se,required:bs,error:_s,owner:S??"",agentId:p,sources:i?x:void 0,onAddSources:i?me:void 0}):null,!i&&G!=="agent"?Mt:null,i?e.jsx(Xn,{sources:x,onChange:me,disabled:d}):null,e.jsx("div",{className:"space-y-4",children:f}),e.jsx(Qn,{organizationId:n,agentId:_==="agent"?p.trim():"",value:le,onChange:$,disabled:d,automationName:ve,onPendingChange:w}),de?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(Y,{type:"button",variant:"ghost",className:"w-full justify-between px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-expanded":dt,"aria-controls":"automation-advanced-settings",onClick:()=>Ct(a=>!a),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(en,{className:"h-4 w-4"}),"Advanced settings"]}),e.jsx(us,{className:R("h-4 w-4 transition-transform",dt&&"rotate-180")})]}),e.jsxs("div",{id:"automation-advanced-settings",className:R("space-y-4",!dt&&"hidden"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-description",children:"Description"}),e.jsx(ae,{id:"scratch-description",value:J,onChange:a=>Z(a.target.value),placeholder:"What this automation does"})]}),!i&&!s&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Entity scope"}),e.jsx(Zn,{organizationId:n,value:U,onChange:te}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit this automation to one workspace entity."})]}),i?Mt:null,i?e.jsxs("section",{"aria-label":"Legacy output configuration",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Legacy output keying is read-only here. This editor cannot save changes to it."}),t?.keying_config?e.jsx(Kt,{before:null,after:t.keying_config}):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(b,{children:"Output fields"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Key fields become stable entity keys."})]}),e.jsx(Y,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(Ae==="fields"){const a=cs({entityType:he,entityPath:Ie,fields:Qe});if(a.error){A(a.error);return}Le(a.keyingConfig?JSON.stringify(a.keyingConfig,null,2):""),Re("json")}else Re("fields");A(null)},children:Ae==="fields"?"Edit JSON":"Use fields"})]}),Ae==="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(b,{htmlFor:"scratch-output-entity-type",children:"Output entity type"}),e.jsx(ct,{contentClassName:"w-[320px]",searchPlaceholder:"Search or type a new type…",emptyText:"Type a name to create a new entity type.",trigger:a=>e.jsxs(Y,{type:"button",variant:"outline",role:"combobox","aria-expanded":a,id:"scratch-output-entity-type",className:"w-full justify-between font-mono text-sm font-normal",children:[e.jsx("span",{className:R("truncate",!he&&"text-muted-foreground"),children:he||"Select entity type"}),e.jsx(bt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(a,C)=>{const B=Ze(C),L=fe.filter(Q=>!Q.backing_sql),Ee=L.some(Q=>Q.slug===B);return e.jsxs(e.Fragment,{children:[L.map(Q=>e.jsxs(Ue,{value:`${Q.name??Q.slug} ${Q.slug}`,onSelect:()=>{Ce(Q.slug),A(null),a()},className:"cursor-pointer",children:[e.jsx(rt,{className:R("mr-2 h-4 w-4",he===Q.slug?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-sm",children:Q.slug}),Q.name&&Q.name!==Q.slug&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:Q.name})]})]},Q.slug)),B&&!Ee&&e.jsxs(Ue,{value:C,onSelect:()=>{Ce(B),A(null),a()},className:"cursor-pointer",children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"text-sm",children:["Create"," ",e.jsx("span",{className:"font-mono",children:B})]})]})]})}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-output-path",children:"Output path"}),e.jsx(ae,{id:"scratch-output-path",value:Ie,onChange:a=>{$e(a.target.value),A(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(b,{children:"Fields"}),e.jsxs(Y,{type:"button",variant:"outline",size:"sm",onClick:()=>{xe(a=>[...a,gs()]),A(null)},children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),"Add field"]})]}),Qe.length===0?e.jsx("div",{className:R(We,"px-3 py-2 text-sm text-muted-foreground"),children:"No output fields configured."}):e.jsx("div",{className:"space-y-2",children:Qe.map(a=>e.jsxs("div",{className:R(We,"grid gap-2 p-3 sm:grid-cols-[minmax(0,1fr)_128px_minmax(0,240px)_auto]"),children:[e.jsx(ae,{value:a.name,onChange:C=>{const B=Ze(C.target.value);xe(L=>L.map(Ee=>Ee.id===a.id?{...Ee,name:B}:Ee)),A(null)},placeholder:"severity","aria-label":"Output field name",className:"font-mono text-sm"}),e.jsxs(oe,{value:a.type,onValueChange:C=>{xe(B=>B.map(L=>L.id===a.id?{...L,type:C}:L))},children:[e.jsx(ie,{"aria-label":"Output field type",children:e.jsx(re,{})}),e.jsx(ce,{children:ta.map(C=>e.jsx(D,{value:C,children:C},C))})]}),e.jsx("div",{className:"grid grid-cols-2 rounded-md border border-input bg-background p-1",children:sa.map(C=>e.jsx("button",{type:"button",onClick:()=>{xe(B=>B.map(L=>L.id===a.id?{...L,role:C.value}:L)),A(null)},className:R("rounded-sm px-2 py-1 text-xs transition-colors",a.role===C.value?"bg-muted/70 text-foreground":"text-muted-foreground hover:text-foreground"),children:C.label},C.value))}),e.jsx(Y,{type:"button",variant:"ghost",size:"icon",onClick:()=>{xe(C=>C.filter(B=>B.id!==a.id)),A(null)},"aria-label":"Remove output field",children:e.jsx(ms,{className:"h-4 w-4"})})]},a.id))})]}),Fe&&e.jsx("p",{className:"text-xs text-destructive",children:Fe})]}):e.jsx("div",{className:"space-y-3",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-keying-config",children:"Keying Config (JSON)"}),e.jsx(Nt,{value:we,onChange:a=>{Le(a),A(null)},language:"json",placeholder:'{ "entity_type": "topic", "entity_path": "$.items[*]", "key_fields": ["name"], "key_output_field": "entity_key" }',minHeight:"60px"}),Fe&&e.jsx("p",{className:"text-xs text-destructive",children:Fe})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-reactions-guidance",children:"Reactions Guidance"}),e.jsx(tn,{id:"scratch-reactions-guidance",value:qe,onChange:a=>et(a.target.value),placeholder:"Guidance text for the reaction system (e.g., when to alert, severity thresholds)...",className:"font-mono text-xs min-h-[80px]"})]}),e.jsxs("div",{className:"space-y-4",children:[oa("Run settings","Choose where the automation runs and the budget it can use."),E?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Runs on"}),e.jsx("p",{className:"text-sm",children:_==="external"?"External executor":"Script"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This executor is configured outside this editor."}),ge&&e.jsxs(e.Fragment,{children:[e.jsx(b,{children:"Owning agent"}),e.jsx("p",{className:"text-sm",children:p||"None assigned"})]})]}):!j&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-runs-on",children:"Runs on"}),e.jsxs(oe,{value:_,onValueChange:a=>Se(a),children:[e.jsx(ie,{id:"scratch-runs-on",className:"text-sm",children:e.jsx(re,{})}),e.jsxs(ce,{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:_==="agent"?"Automated runs dispatch to a managed Lobu agent.":_==="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."})]}),!Ke&&Pt,!j&&_==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-device-id",children:"Device"}),e.jsxs(oe,{value:X||"__unselected__",onValueChange:a=>v(a==="__unselected__"?"":a),children:[e.jsx(ie,{id:"scratch-device-id",className:"font-mono text-sm",children:e.jsx(re,{placeholder:"Select a device worker"})}),e.jsx(ce,{children:W.map(a=>e.jsx(D,{value:a.id,children:a.label||a.platform||a.id},a.id))})]})]}),!j&&_==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-device-agent-kind",children:"Runs as"}),e.jsxs(oe,{value:z||"__default__",onValueChange:a=>pe(a==="__default__"?"":a),children:[e.jsx(ie,{id:"scratch-device-agent-kind",className:"text-sm",children:e.jsx(re,{placeholder:"Device default"})}),e.jsxs(ce,{children:[e.jsx(D,{value:"__default__",children:"Device default"}),ea.map(a=>e.jsx(D,{value:a.value,children:a.label},a.value))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Device default uses that device's preferred local agent. Availability is checked again when a run is claimed, so a run stays queued if its selected runtime is no longer available."})]}),!E&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Model"}),e.jsx(vn,{value:Oe,onChange:a=>{l(a),V(null)},placeholder:"Use agent default"})]})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-timeout",children:"Timeout seconds"}),e.jsx(ae,{id:"scratch-timeout",type:"number",min:1,max:86400,value:Je,onChange:a=>{tt(a.target.value),V(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(b,{htmlFor:"scratch-permission-mode",children:"Permission mode"}),e.jsxs(oe,{value:y||"__default__",onValueChange:a=>{O(a==="__default__"?"":a),V(null)},children:[e.jsx(ie,{id:"scratch-permission-mode",children:e.jsx(re,{placeholder:"Default"})}),e.jsxs(ce,{children:[e.jsx(D,{value:"__default__",children:"Default"}),vt.map(a=>e.jsx(D,{value:a.value,children:a.label},a.value))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-effort",children:"Effort"}),e.jsx(ae,{id:"scratch-effort",value:ee,onChange:a=>{ne(a.target.value),V(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(b,{htmlFor:"scratch-finalize-nudges",children:"Finalize nudges"}),e.jsx(ae,{id:"scratch-finalize-nudges",type:"number",min:0,max:5,value:be,onChange:a=>{T(a.target.value),V(null)},placeholder:"Default"})]})]}),ke&&e.jsx("p",{className:"text-xs text-destructive",children:ke})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-tags",children:"Tags"}),e.jsx(ae,{id:"scratch-tags",value:nt,onChange:a=>St(a.target.value),placeholder:"ops, support, risk"})]}),i&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-change-notes",children:"Change notes"}),e.jsx(ae,{id:"scratch-change-notes",value:lt,onChange:a=>wt(a.target.value),placeholder:"What changed in this version?"})]})]})]}),(E&&ke||u&&!Fe&&!ke)&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:E&&ke?ke:u}),i&&ht.length>0?e.jsxs("section",{"aria-label":"Review changes",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Review changes"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Saved values compared with this draft. Only changed fields are shown."}),e.jsx(Kt,{before:Object.fromEntries(ht.map(([a,C])=>[a,C])),after:Object.fromEntries(ht.map(([a,,C])=>[a,C]))})]}):null,e.jsx(_t,{onCancel:o,children:e.jsx(Y,{onClick:ks,disabled:!Dt||d||m,children:d?e.jsxs(e.Fragment,{children:[e.jsx(sn,{size:"lg",className:"mr-2"}),i?"Saving...":"Creating..."]}):i?"Save Automation":N})})]})}function ra(n,s){const t=n??null,c=s??null;return t===null||c===null?t===c:t.connection_id===c.connection_id&&t.channel_id===c.channel_id}function ca(n){const s=n.detail??{};return{name:n.name,slug:s.slug,description:s.description??n.description??void 0,prompt:s.prompt,triggers:s.triggers,sources:s.sources,keying_config:s.keying_config,reactions_guidance:s.reactions_guidance,reaction_script:s.reaction_script,model_config:s.model_config,execution_config:s.execution_config,tags:s.tags,outputs:s.outputs}}function _a({startFromScratch:n=!1,onClose:s,hideCancel:t=!1,hideHeader:c=!1,organizationId:d,entityId:u,entityName:i,prefillAgentId:o,conversationSetup:f,onSuccess:N,editingAutomation:m,catalogPrefill:g,onDraft:I,triggerFields:h,submitLabel:k,submitDisabled:S,createFields:F,onPrefillTriggers:W}){const p=mn(),M=hn(),j=xn(),le=gn(),$=!!m,[de,w]=r.useState(n?"scratch":"template"),[X,v]=r.useState(void 0),[_,Se]=r.useState(void 0),{data:E=[],isLoading:ge}=pn(),[z,pe]=r.useState(""),fe=f?.name,ve=r.useMemo(()=>o||fe?{...fe?{name:fe}:{},...o?{managed_agent_id:o}:{}}:void 0,[o,fe]),Ne=r.useMemo(()=>E.map(x=>({key:x.id,name:x.name,description:x.description??"",badges:x.detail?.tags??[]})),[E]),q=r.useMemo(()=>Ne.filter(x=>x.name.toLowerCase().includes(z.toLowerCase())||x.description.toLowerCase().includes(z.toLowerCase())),[Ne,z]),ye=x=>{const me=E.find(te=>te.id===x.key);if(!me)return;const U=ca(me);Se(o?{...U,managed_agent_id:o}:U),W?.(U.triggers??[]),w("scratch")},K=()=>{p.reset(),M.reset(),w("template"),v(void 0),Se(void 0),s()},ue=$?F?.triggers??m.triggers??[]:F?.triggers??_?.triggers??g?.triggers??[],J=async x=>{try{if(I){await I(x);return}if($){const me=F?.triggers??m.triggers??[],U=m.reaction_script??"",te=x.reaction_script??"";te&&te!==U&&await j.mutateAsync({automation_id:m.automation_id,reaction_script:te}),await M.mutateAsync({automation_id:m.automation_id,name:x.name,description:x.description,prompt:x.prompt,sources:x.sources,set_as_current:!0,triggers:me,keying_config:x.keying_config,reactions_guidance:x.reactions_guidance,change_notes:x.change_notes}),!te&&U&&await j.mutateAsync({automation_id:m.automation_id,reaction_script:""});const P={};x.model_config!==void 0&&(P.model_config=x.model_config),x.execution_config!==void 0&&(P.execution_config=x.execution_config),x.tags!==void 0&&(P.tags=x.tags),x.delivery_target!==void 0&&!ra(x.delivery_target,m.delivery_target)&&(P.delivery_target=x.delivery_target),x.managed_agent_id!==void 0&&(P.managed_agent_id=x.managed_agent_id||null),x.agent_kind!==void 0&&(P.agent_kind=x.agent_kind||null),x.device_worker_id!==void 0&&(P.device_worker_id=x.device_worker_id||null),Object.keys(P).length>0&&await le.mutateAsync({automation_id:m.automation_id,...P}),K(),N?.(m.automation_id)}else{const me=F?.triggers??_?.triggers??g?.triggers??[],U=await p.mutateAsync({...x,managed_agent_id:x.managed_agent_id??void 0,device_worker_id:x.device_worker_id??void 0,agent_kind:x.agent_kind??void 0,delivery_target:x.delivery_target??void 0,triggers:me});K(),U.automation_id&&N?.(U.automation_id)}}catch{}},Z=$?M:p;let je="Add an automation";$?je="Edit automation configuration (saves as a new version)":i&&(je=`Add an automation for ${i}`);const Te=r.useMemo(()=>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,[m]),De=$?"Edit Automation":"Create Automation",Me=e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:De}),e.jsx("p",{className:"text-sm text-muted-foreground",children:je})]}),se=e.jsxs("div",{className:"py-6 space-y-6",children:[!$&&e.jsxs("div",{className:"flex flex-wrap justify-start gap-2",children:[e.jsx(jt,{active:de==="template",onClick:()=>w("template"),icon:e.jsx(nn,{className:"h-4 w-4"}),label:"From templates"}),e.jsx(jt,{active:de==="scratch",onClick:()=>{w("scratch"),v(void 0),Se(void 0)},icon:e.jsx(Xe,{className:"h-4 w-4"}),label:"From scratch"}),e.jsx(jt,{active:de==="clone",onClick:()=>w("clone"),icon:e.jsx(an,{className:"h-4 w-4"}),label:"Clone existing"})]}),!$&&de==="template"?e.jsxs(e.Fragment,{children:[ge?e.jsx(on,{}):e.jsx(rn,{items:q,searchQuery:z,onSearchChange:pe,onSelect:ye,searchPlaceholder:"Search templates...",searchAriaLabel:"Search automation templates",emptyMessage:Ne.length===0?"No automation templates available.":void 0}),c&&!t?e.jsx(_t,{onCancel:K}):null]}):!$&&de==="clone"&&!X?e.jsxs(e.Fragment,{children:[e.jsx(la,{organizationId:d,onSelect:x=>{v(x),W?.(x.triggers??[]),w("scratch")}}),c&&!t?e.jsx(_t,{onCancel:K}):null]}):e.jsx(ia,{organizationId:d,entityId:u,prefill:Te??X??_??g??ve,onSubmit:J,isSubmitting:Z.isPending,error:Z.error?Z.error.message:null,isEditing:$,onCancel:t?void 0:K,triggerFields:h,submitLabel:k,submitDisabled:S,triggers:ue,savedTriggers:m?.triggers,agentFirst:!!f})]});return e.jsxs("div",{className:"flex flex-col",children:[c?null:Me,se]})}function jt({active:n,onClick:s,icon:t,label:c}){return e.jsxs("button",{type:"button",onClick:s,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:[t,c]})}function la({organizationId:n,onSelect:s}){const{data:t,isLoading:c}=fn(n),[d,u]=r.useState(""),i=(t||[]).filter(o=>o.name?.toLowerCase().includes(d.toLowerCase()));return c?e.jsx(cn,{label:"automations",variant:"list-picker",rows:4}):!t||t.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:o=>u(o.target.value),placeholder:"Search automations...",className:"w-full rounded-md border px-3 py-2 text-sm bg-background"}),e.jsxs("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:[i.map(o=>e.jsxs("button",{type:"button",onClick:()=>s({name:`${o.name} (copy)`,slug:`${o.slug||o.automation_id}-copy`,prompt:o.prompt,keying_config:o.keying_config,triggers:o.triggers,sources:o.sources,outputs:o.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:o.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[o.entity_name||"Space-level"," · v",o.version??"?"]})]},o.automation_id)),i.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No automations match your search."})]})]})}export{ja as A,_a as C};
|
|
3
|
-
//# sourceMappingURL=create-automation-form-C9PMX7N8.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as y,j as e,f5 as fe,H as h,eL as v,I as w,$ as je,bl as be,bm as ye,bn as Ne,bo as ve,bp as k,f6 as we,bu as M,f7 as Te,f8 as F,f9 as Ce,fa as Me,fb as Ie,fc as Se,fd as G,bx as Ae,B as _e}from"./index-BjcZVe7n.js";import{A as $e}from"./automation-source-list-Dhucq1sI.js";import{S as Fe}from"./schema-value-BFb7jCBo.js";import{C as De,J as Re}from"./json-diff-DtZtra_g.js";const Ee=72,Oe=2e3;function Pe({value:s,onChange:t,section:a="all",create:r=!1,disabled:l=!1,loading:m=!1,modelsEditor:d,sandboxes:x=[],includedFields:g}){const o=y.useId(),i=n=>!g||g.includes(n),{name:c,description:f,identityMd:te,soulMd:ne,userMd:ae,models:re,showToolCalls:ie,sandboxId:S,starters:A}=s,j=(n,b)=>t?.({...s,[n]:b}),oe=n=>j("name",n),de=n=>j("description",n),le=n=>j("identityMd",n),ce=n=>j("soulMd",n),ue=n=>j("userMd",n),me=n=>j("showToolCalls",n),xe=n=>j("sandboxId",n),E=n=>j("starters",n),O=r,p=l||!t,he=m,pe=r||a==="settings"||a==="all",ge=!r&&(a==="identity"||a==="settings"||a==="all"),P=!r&&(a==="settings"||a==="all"),L=!r&&(a==="models"||a==="all");return e.jsxs("div",{className:"grid content-start gap-4 py-2",children:[ge?he?e.jsx(fe,{rows:4}):e.jsxs(e.Fragment,{children:[i("identityMd")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-identity-md`,children:"Identity"}),e.jsx(v,{id:`${o}-identity-md`,rows:6,value:te,onChange:n=>le(n.target.value),readOnly:p,placeholder:"You are a market intelligence agent. Track competitors, analyze launches and signals, and surface concise, decision-ready insights."})]}):null,i("soulMd")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-soul-md`,children:"Soul"}),e.jsx(v,{id:`${o}-soul-md`,rows:6,value:ne,onChange:n=>ce(n.target.value),readOnly:p,placeholder:"Be rigorous, skeptical of weak signals, and calm under ambiguity. Prefer crisp summaries, explicit evidence, and clear confidence levels."})]}):null,i("userMd")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-user-md`,children:"User prompt"}),e.jsx(v,{id:`${o}-user-md`,rows:6,value:ae,onChange:n=>ue(n.target.value),readOnly:p,placeholder:"Monitor the market for notable competitor moves, pricing changes, launches, partnerships, and customer sentiment shifts. Summarize what changed, why it matters, and what to watch next."})]}):null]}):null,pe?e.jsxs(e.Fragment,{children:[i("name")?e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(h,{htmlFor:`${o}-agent-name`,children:["Name ",e.jsx("span",{className:"ml-1 text-destructive",children:"*"})]}),e.jsx(w,{id:`${o}-agent-name`,placeholder:"Support Bot",value:c,onChange:n=>oe(n.target.value),readOnly:p,required:!0}),O?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"The agent ID will be generated automatically from the name."}):null]}):null,O||!i("description")?null:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-agent-description`,children:"Description"}),e.jsx(v,{id:`${o}-agent-description`,placeholder:"Handles customer support and triage across channels.",value:f,onChange:n=>de(n.target.value),readOnly:p,rows:3})]})]}):null,P&&i("showToolCalls")?e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border bg-muted/20 p-3",children:[e.jsx(je,{id:`${o}-show-tool-calls`,checked:ie,onCheckedChange:n=>me(n===!0),disabled:p,className:"mt-0.5"}),e.jsxs("div",{className:"grid gap-0.5",children:[e.jsx(h,{htmlFor:`${o}-show-tool-calls`,className:"cursor-pointer",children:"Show tool calls in chat"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Render the agent's tool invocations (name, arguments, and result) as cards in the web chat. Off by default."})]})]}):null,P&&i("starters")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{children:"Conversation starters"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Up to three prompts offered on a new chat, on the web and in Slack. The message is sent as the user when tapped."}),A.map((n,b)=>e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[12rem_1fr]",children:[e.jsx(w,{"aria-label":`Starter ${b+1} title`,placeholder:"Plan this week",maxLength:Ee,value:n.title,onChange:_=>E(A.map((N,$)=>$===b?{...N,title:_.target.value}:N)),readOnly:p}),e.jsx(w,{"aria-label":`Starter ${b+1} message`,placeholder:"Plan this week's posts from what's trending",maxLength:Oe,value:n.message,onChange:_=>E(A.map((N,$)=>$===b?{...N,message:_.target.value}:N)),readOnly:p})]},b))]}):null,L&&i("models")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{children:"Models"}),d??e.jsx("ol",{className:"grid gap-2",children:re.map(n=>e.jsx("li",{className:"rounded-lg border px-3 py-2 text-sm",children:n},n))}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Ordered list; the first is the default. Only these models may be used — a request for anything else falls back to the first available one. Leave empty to use the org default."})]}):null,L&&i("sandboxId")?e.jsxs("div",{className:"grid gap-2",children:[e.jsx(h,{htmlFor:`${o}-agent-sandbox`,children:"Run in sandbox"}),t?e.jsxs(be,{value:S,onValueChange:xe,disabled:p,children:[e.jsx(ye,{id:`${o}-agent-sandbox`,className:"w-full",children:e.jsx(Ne,{placeholder:"Built-in"})}),e.jsxs(ve,{children:[e.jsx(k,{value:"builtin",children:"Built-in (default)"}),x.map(n=>e.jsxs(k,{value:n.id,children:[n.name," (",n.providerKind,")",n.connected?"":" — no credential"]},n.id))]})]}):e.jsx(w,{"aria-label":"Run in sandbox",value:S==="builtin"?"Built-in (default)":S,readOnly:!0}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Where this agent's commands execute. Built-in runs in-process; sandboxes run on a connected provider. Manage sandboxes under Connect › Runtime."})]}):null]})}function q(s){return s&&typeof s=="object"&&!Array.isArray(s)?s:{}}function u(s){return typeof s=="string"?s:""}function z(s){return Array.isArray(s)?s.map(q):[]}function Le(s){return Array.isArray(s)?s.filter(t=>typeof t=="string"):[]}function T({label:s,children:t}){return e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-sm font-medium",children:s}),t]})}function D({label:s,value:t,multiline:a=!1}){return e.jsxs(h,{className:"grid gap-2",children:[e.jsx("span",{children:s}),t===void 0?e.jsx("span",{className:"text-sm text-muted-foreground",children:"Not included in snapshot"}):t===null?e.jsx("span",{className:"text-sm text-muted-foreground",children:"Not set"}):a?e.jsx(v,{value:u(t),readOnly:!0,rows:6}):e.jsx(w,{value:u(t),readOnly:!0})]})}function C({value:s}){return s===null?e.jsx("span",{className:"text-muted-foreground",children:"Not set"}):Array.isArray(s)?s.length?e.jsx("ol",{className:"grid gap-3",children:s.map((t,a)=>e.jsx("li",{className:"min-w-0 rounded-lg border p-3",children:e.jsx(C,{value:t})},a))}):e.jsx("span",{className:"text-muted-foreground",children:"Empty list"}):s&&typeof s=="object"?e.jsx("dl",{className:"grid gap-3",children:Object.entries(s).map(([t,a])=>e.jsxs("div",{className:"grid min-w-0 gap-1",children:[e.jsx("dt",{className:"text-xs text-muted-foreground",children:t.replaceAll("_"," ")}),e.jsx("dd",{className:"min-w-0 whitespace-pre-wrap text-sm",children:e.jsx(C,{value:a})})]},t))}):s===""?e.jsx("span",{className:"text-muted-foreground",children:"Empty text"}):e.jsx(Fe,{value:s})}function K({value:s,omit:t}){const a=Object.entries(s).filter(([r])=>!t.includes(r));return a.length?e.jsx(T,{label:"Settings",children:e.jsx("dl",{className:"grid gap-4",children:a.map(([r,l])=>e.jsxs("div",{className:"grid min-w-0 gap-1",children:[e.jsx("dt",{className:"text-sm text-muted-foreground",children:r.replaceAll("_"," ")}),e.jsx("dd",{className:"min-w-0 text-sm",children:e.jsx(C,{value:l})})]},r))})}):null}function Ye({value:s}){const t=z(s.sources).map(a=>({name:u(a.name),query:u(a.query)}));return e.jsxs("div",{className:"grid gap-6 py-2 [&_.cm-content_span]:text-inherit",children:[e.jsx(D,{label:"Name",value:s.name}),e.jsx(D,{label:"Description",value:s.description}),e.jsx(D,{label:"Instructions",value:s.prompt,multiline:!0}),e.jsx(T,{label:"Sources",children:s.sources===void 0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Not included in snapshot"}):t.length?e.jsx($e,{sources:t,wrap:!0}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No sources."})}),e.jsx(T,{label:"When",children:s.triggers===void 0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Not included in snapshot"}):Array.isArray(s.triggers)&&s.triggers.length?e.jsx(C,{value:s.triggers}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manual only."})}),s.outputs!==void 0?e.jsx(T,{label:"Outputs",children:e.jsx(C,{value:s.outputs})}):null,typeof s.reaction_script=="string"?e.jsx(T,{label:"Code",children:e.jsx(De,{value:s.reaction_script,language:"typescript",readonly:!0})}):null,e.jsx(K,{value:s,omit:["name","description","prompt","sources","triggers","outputs","reaction_script"]})]})}function Qe({value:s}){const t=q(s.settings);return e.jsxs("div",{className:"grid gap-6",children:[e.jsx(Pe,{includedFields:[...s.name!==void 0?["name"]:[],...s.description!==void 0?["description"]:[],...s.identity_md!==void 0||s.identityMd!==void 0?["identityMd"]:[],...s.soul_md!==void 0||s.soulMd!==void 0?["soulMd"]:[],...s.user_md!==void 0||s.userMd!==void 0?["userMd"]:[],...s.models!==void 0||t.models!==void 0?["models"]:[],...s.showToolCalls!==void 0||t.showToolCalls!==void 0?["showToolCalls"]:[],...s.sandboxId!==void 0||t.sandboxId!==void 0?["sandboxId"]:[],...s.starters!==void 0?["starters"]:[]],value:{name:u(s.name),description:u(s.description),identityMd:u(s.identity_md??s.identityMd),soulMd:u(s.soul_md??s.soulMd),userMd:u(s.user_md??s.userMd),models:Le(s.models??t.models),showToolCalls:(s.showToolCalls??t.showToolCalls)===!0,sandboxId:u(s.sandboxId??t.sandboxId)||"builtin",starters:z(s.starters).map(a=>({title:u(a.title),message:u(a.message)}))}}),e.jsx(K,{value:s,omit:["name","description","identity_md","identityMd","soul_md","soulMd","user_md","userMd","models","showToolCalls","sandboxId","starters"]})]})}var I="Tabs",[ke]=Ae(I,[G]),H=G(),[Ve,R]=ke(I),U=y.forwardRef((s,t)=>{const{__scopeTabs:a,value:r,onValueChange:l,defaultValue:m,orientation:d="horizontal",dir:x,activationMode:g="automatic",...o}=s,i=Me(x),[c,f]=Ie({prop:r,onChange:l,defaultProp:m??"",caller:I});return e.jsx(Ve,{scope:a,baseId:Se(),value:c,onValueChange:f,orientation:d,dir:i,activationMode:g,children:e.jsx(M.div,{dir:i,"data-orientation":d,...o,ref:t})})});U.displayName=I;var J="TabsList",W=y.forwardRef((s,t)=>{const{__scopeTabs:a,loop:r=!0,...l}=s,m=R(J,a),d=H(a);return e.jsx(Ce,{asChild:!0,...d,orientation:m.orientation,dir:m.dir,loop:r,children:e.jsx(M.div,{role:"tablist","aria-orientation":m.orientation,...l,ref:t})})});W.displayName=J;var X="TabsTrigger",Y=y.forwardRef((s,t)=>{const{__scopeTabs:a,value:r,disabled:l=!1,...m}=s,d=R(X,a),x=H(a),g=ee(d.baseId,r),o=se(d.baseId,r),i=r===d.value;return e.jsx(Te,{asChild:!0,...x,focusable:!l,active:i,children:e.jsx(M.button,{type:"button",role:"tab","aria-selected":i,"aria-controls":o,"data-state":i?"active":"inactive","data-disabled":l?"":void 0,disabled:l,id:g,...m,ref:t,onMouseDown:F(s.onMouseDown,c=>{!l&&c.button===0&&c.ctrlKey===!1?d.onValueChange(r):c.preventDefault()}),onKeyDown:F(s.onKeyDown,c=>{[" ","Enter"].includes(c.key)&&d.onValueChange(r)}),onFocus:F(s.onFocus,()=>{const c=d.activationMode!=="manual";!i&&!l&&c&&d.onValueChange(r)})})})});Y.displayName=X;var Q="TabsContent",Z=y.forwardRef((s,t)=>{const{__scopeTabs:a,value:r,forceMount:l,children:m,...d}=s,x=R(Q,a),g=ee(x.baseId,r),o=se(x.baseId,r),i=r===x.value,c=y.useRef(i);return y.useEffect(()=>{const f=requestAnimationFrame(()=>c.current=!1);return()=>cancelAnimationFrame(f)},[]),e.jsx(we,{present:l||i,children:({present:f})=>e.jsx(M.div,{"data-state":i?"active":"inactive","data-orientation":x.orientation,role:"tabpanel","aria-labelledby":g,hidden:!f,id:o,tabIndex:0,...d,ref:t,style:{...s.style,animationDuration:c.current?"0s":void 0},children:f&&m})})});Z.displayName=Q;function ee(s,t){return`${s}-trigger-${t}`}function se(s,t){return`${s}-content-${t}`}var Be=U,Ge=W,qe=Y,ze=Z;function Ke({defaultValue:s,children:t}){return e.jsx(Be,{defaultValue:s,className:"space-y-4",children:t})}function He({label:s="Views",children:t}){return e.jsx(Ge,{"aria-label":s,className:"flex flex-wrap gap-1 border-b pb-2",children:t})}function V({value:s,children:t}){return e.jsx(qe,{value:s,asChild:!0,children:e.jsx(_e,{type:"button",variant:"ghost",size:"sm",className:"data-[state=active]:bg-secondary data-[state=active]:text-secondary-foreground",children:t})})}function B({value:s,children:t}){return e.jsx(ze,{value:s,children:t})}function Ze({current:s,proposed:t,render:a}){return e.jsxs("div",{className:"space-y-4",children:[e.jsxs(Ke,{defaultValue:"proposed",children:[e.jsxs(He,{label:"Definition version",children:[e.jsx(V,{value:"current",children:"Current"}),e.jsx(V,{value:"proposed",children:"Proposed"})]}),e.jsx(B,{value:"current",children:s?a(s):e.jsx("p",{className:"py-4 text-sm text-muted-foreground",children:"No current definition."})}),e.jsx(B,{value:"proposed",children:t?a(t):e.jsx("p",{className:"py-4 text-sm text-muted-foreground",children:"This definition will be removed."})})]}),e.jsxs("details",{className:"text-sm",children:[e.jsx("summary",{className:"cursor-pointer rounded-sm py-2 text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:"Show technical diff"}),e.jsx(Re,{before:s,after:t})]})]})}export{Qe as A,Ze as D,B as T,Ye as a,V as b,He as c,Ke as d,Pe as e};
|
|
2
|
-
//# sourceMappingURL=definition-comparison-B5WgZILB.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as e,f5 as j,r as f,iK as v,iL as C,gl as k,B as A,L,d6 as I,iM as N,iN as w,iO as E,u as O,iP as P,gn as F}from"./index-BjcZVe7n.js";import{b as S}from"./runs-table-CYS1jDdL.js";import{R as b}from"./run-activity-link-Dh1YyCfk.js";import{c as y,C as R,b as $}from"./connector-scope-lists-dQnZARCD.js";function V({formRows:s=5}){return e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsx(S,{}),e.jsx(j,{rows:s})]})}function H({connection:s,connectorDef:t,ownerSlug:a,openSettings:n=!1,authResult:o,showActivity:r=!0,embedded:i=!1,showShare:c=!0}){const[l,d]=f.useState(n);f.useEffect(()=>{n&&d(!0)},[n]);const m=s.id,u=s.connector_key,p=s.facets?.chat??!1,h=p?"Channels":"Feeds",x=s.has_operations===!0,_=s.feed_count>0||y(t),g=e.jsx(E,{connection:s,connectorDef:t,ownerSlug:a,showShare:c});return e.jsxs("div",{className:"space-y-6",children:[o&&e.jsx(v,{result:o}),s.auth_profile_kind==="oauth_account"&&e.jsx(C,{connection:s,connectorDef:t,onReview:()=>{d(!0),requestAnimationFrame(()=>document.getElementById("connection-auth")?.scrollIntoView({block:"nearest"}))}}),(_||x)&&e.jsxs("div",{className:i?"space-y-6":"grid grid-cols-1 items-start gap-3 sm:grid-cols-2",children:[_&&(i?e.jsx(k,{title:h,count:s.feed_count===1?"1 source":`${s.feed_count} sources`,action:y(t)?e.jsx(A,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(L,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:a,connectorKey:u,connectionId:String(m)},search:{addFeed:!0},children:[e.jsx(I,{className:"h-3.5 w-3.5"}),p?"Add channel":"Add source"]})}):null,children:e.jsx(R,{connection:s,ownerSlug:a,connectorKey:u,connectorDef:t})}):e.jsx($,{connection:s,ownerSlug:a,title:h})),x&&(i?e.jsx(N,{connection:s,ownerSlug:a}):e.jsx(B,{connection:s,ownerSlug:a}))]}),i?e.jsx(w,{title:"Connection settings",summary:"name, visibility, credentials, remove",open:l,onOpenChange:d,children:g}):g,r&&e.jsx(b,{owner:a,filters:{connectionIds:[m]},name:s.display_name||u})]})}function B({connection:s,ownerSlug:t}){const a=O(),{data:n=[],isLoading:o,isError:r}=P(s.id),i=n.filter(l=>l.readiness==="scope_upgrade_required").length,c=o?"Loading actions…":r?"Could not load actions — open to retry":`${n.length} actions${i?` · ${i} need additional provider access`:" · permissions and approval policy"}`;return e.jsx(F,{title:"Actions",summary:c,onOpen:()=>a?.open({href:"",title:"Actions",connectorPanel:{section:"actions",connectionId:s.id,connectorKey:s.connector_key,organizationId:s.organization_id,ownerSlug:t}})})}const K=new Set(["Device was removed","Device was moved to another workspace"]);function D(s){const t=s.error_message??null;return!t||!K.has(t)?t:!!s.device_worker_id&&(s.device_last_seen_at!=null||s.device_worker_handle!=null||s.device_label!=null)?null:t}export{H as C,V as R,D as c};
|
|
2
|
-
//# sourceMappingURL=device-pin-tombstone-B06J7Af1.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{aQ as G,ix as ne,iy as U,r as v,j as e,iz as z,B as b,ab as L,gi as C,aH as J,aB as te,gl as I,S as R,b7 as M,e5 as ae,e7 as ie,C as ce,eb as oe,iA as re,a1 as le,c as de,aG as me,iB as ue,iC as xe,iD as he,aJ as pe,aC as fe,al as P,b6 as q,L as E,iE as ge,iF as je,aW as ve,iG as ye,iH as be,W as Ne,gS as ke,iI as H,I as _e,bc as we,eT as Ce,gT as Se,gU as K,ek as $e,iJ as O,az as De}from"./index-BjcZVe7n.js";import{C as Pe}from"./connector-page-shell-Di6XzkVo.js";import{c as V,C as ze,R as Le}from"./device-pin-tombstone-B06J7Af1.js";import{R as Ie}from"./runs-panel-BwTVaRsE.js";import{S as Re,g as Ae}from"./runs-table-CYS1jDdL.js";import{c as Ee}from"./connection-label-BobuYiAG.js";import{w as B}from"./workspace-label-o_QfBuCM.js";import"./run-activity-link-Dh1YyCfk.js";import"./connector-scope-lists-dQnZARCD.js";import"./status-dot-BnQPFrcU.js";import"./use-scroll-sentinel-BWCrmNIB.js";import"./runs-BntGAKQG.js";import"./filter-bar-CQ_oE7a9.js";import"./manage-gear-C-0BAMbC.js";import"./run-initiator-CCxNv0rK.js";import"./use-automations-D9hKpufo.js";import"./clients-Cmp0LmOp.js";import"./table-DALHuXPE.js";function Be(s,n,o){const h=new Set(s.capabilities??[]),m=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key)),r=new Set(Y(s,o).map(t=>t.connector_key));return n.filter(t=>G(t)&&!!t.required_capability&&h.has(t.required_capability)&&!m.has(t.key)&&!r.has(t.key))}function Y(s,n){return s.organization_slug===n?s.update_required:[]}function Me(s,n,o){const h=s.organization_slug;if(!h||h===o)return[];const m=new Set(n.map(t=>t.key)),r=new Set(s.connectors.filter(t=>t.organization_slug===o).map(t=>t.connector_key));return s.connectors.filter(t=>t.organization_slug!==h||m.has(t.connector_key)||r.has(t.connector_key)?!1:(r.add(t.connector_key),!0))}function Te({device:s,organizationId:n,ownerSlug:o,connectable:h,unavailable:m}){const r=ne(),t=U(),[u,p]=v.useState(null),[g,a]=v.useState(null),[f,N]=v.useState(null),[j,d]=v.useState([]),x=s.organization_id===n,y=async i=>{p(null),N(null),a(i.key);try{x||await t.mutateAsync({deviceWorkerId:s.id,organizationId:n});const w=await r.mutateAsync({connector_key:i.key,device_worker_id:s.id}),S=w.connection_id??w.connection?.id;if(S===void 0)throw new Error(w.instructions??"The connection was not created.");d($=>[...$.filter(D=>D.connectorKey!==i.key),{connectorKey:i.key,name:i.name,connectionId:S,instructions:w.status==="setup_required"?w.instructions:void 0}])}catch(w){N({key:i.key,message:w instanceof Error?w.message:"Could not connect."})}finally{a(null)}},k=new Set(j.map(i=>i.connectorKey)),l=Y(s,o),c=h.filter(i=>!k.has(i.key));return e.jsxs("div",{className:"mt-4 space-y-3",children:[j.map(i=>e.jsx(qe,{outcome:i,device:s,organizationId:n},i.connectorKey)),c.length>0?e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium",children:"Supported by this device"}),e.jsxs("p",{className:"mb-2 text-xs text-muted-foreground",children:["Not connected in this workspace yet.",x?null:" Connecting one moves the device here; you will be asked to confirm first."]}),e.jsx("div",{className:"divide-y border-y",children:c.map(i=>e.jsxs("div",{className:"space-y-2 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-sm font-medium",children:[i.name,i.required_capability&&z[i.required_capability]&&z[i.required_capability]!==i.name?e.jsx("span",{className:"ml-2 text-xs font-normal text-muted-foreground",children:z[i.required_capability]}):null]}),e.jsxs(b,{size:"sm",variant:"outline","aria-label":`Connect ${i.name}`,disabled:g!==null,onClick:()=>x?void y(i):p(i.key),children:[g===i.key?e.jsx(L,{className:"mr-1.5"}):null,"Connect"]})]}),u===i.key?e.jsx(Q,{device:s,ownerSlug:o,title:"Move device to this workspace",intro:`${C(s)} lives in ${s.organization_name??"another workspace"}. A device serves one workspace at a time, so it has to move here before it can be connected.`,confirmLabel:"Move here and connect",onConfirm:()=>void y(i),onCancel:()=>p(null)}):null,f?.key===i.key?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:f.message}):null]},i.key))})]}):null,l.length>0?e.jsxs("div",{role:"status",children:[e.jsx("p",{className:"text-xs font-medium",children:"Update Lobu on this device"}),e.jsx("ul",{className:"mt-1 space-y-1 text-xs text-muted-foreground",children:l.map(i=>e.jsx("li",{children:`${i.display_name} — this device has ${i.device_version}, this workspace uses ${i.workspace_version}`},i.connector_key))})]}):null,m.length>0?e.jsx("ul",{className:"space-y-1 text-xs text-muted-foreground",children:m.map(i=>e.jsx("li",{children:`${i.display_name} — set up on this device in ${s.organization_name??"its home workspace"}, not available in this workspace yet`},i.connector_key))}):null]})}function Q({device:s,ownerSlug:n,title:o,intro:h,aftermath:m,confirmLabel:r,pending:t=!1,onConfirm:u,onCancel:p}){const g=s.connector_count,a=s.connectors.filter(f=>f.organization_slug===n).length;return e.jsxs("div",{role:"alertdialog","aria-label":o,className:"space-y-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs",children:[e.jsx("p",{children:h}),e.jsxs("p",{className:"text-muted-foreground",children:[g>0?`Moving pauses and unpins all ${g} connection${g===1?"":"s"} pinned to it${a>0?`, including ${a} in this workspace`:""}. They stay paused until you reconnect them.`:"It has no pinned connections, so nothing is paused.",m?` ${m}`:null]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(b,{size:"sm",disabled:t,onClick:u,children:[t?e.jsx(L,{className:"mr-1.5"}):null,r]}),e.jsx(b,{size:"sm",variant:"ghost",disabled:t,onClick:p,children:"Cancel"})]})]})}function qe({outcome:s,device:n,organizationId:o}){const{data:h=[],isLoading:m}=J(o,{connectionIds:[s.connectionId]}),r=h.find(p=>p.id===s.connectionId),t=C(n);if(m)return e.jsxs("p",{role:"status",className:"text-sm text-muted-foreground",children:["Checking ",s.name,"…"]});const u=[];if(!r)u.push(`${s.name} was created but could not be loaded yet.`);else if(r.status!=="active"){const p=V(r);u.push(`${s.name} is ${r.status}${p?`: ${p}`:"."}`)}return s.instructions&&u.push(s.instructions),n.online||u.push(`${t} is offline. ${s.name} runs once it reconnects.`),e.jsx("div",{role:"status",className:"rounded-lg border px-3 py-2 text-sm",children:u.length===0?e.jsxs("p",{children:[s.name," is ready on ",t,"."]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"font-medium",children:[s.name," connected, not ready yet"]}),e.jsx("ul",{className:"mt-1 list-disc pl-4 text-xs text-muted-foreground",children:u.map(p=>e.jsx("li",{children:p},p))})]})})}function W({device:s,organizationId:n,ownerSlug:o,selectedConnection:h,openSettings:m}){const{data:r=[],isLoading:t,isError:u,refetch:p}=te(n),g=new Map(r.map(d=>[d.key,d])),a=new Map,f=[];for(const d of s.connectors){if(d.organization_slug!==o)continue;const x=g.get(d.connector_key);if(!x||!G(x)){f.push(d);continue}const y=x.required_capability??`connector:${x.key}`,k=a.get(y)??{key:y,name:x.name,connections:[]};k.name=z[y]??x.name,k.connections.push(d),a.set(y,k)}const N=Be(s,r,o),j=Me(s,r,o);return e.jsxs(e.Fragment,{children:[e.jsxs(I,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),s.online?null:e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"This device is offline. You can edit its settings; actions and sync need it to reconnect."}),!n||t?e.jsx(R,{className:"h-24 w-full"}):u?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>void p(),children:"Retry"})]}):a.size===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No native connections on this device in this workspace."}):e.jsx("div",{className:"divide-y border-y",children:[...a.values()].map(d=>e.jsx(F,{group:d,deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:g,selectedConnection:h,openSettings:m},d.key))}),n&&!t&&!u?e.jsx(Te,{device:s,organizationId:n,ownerSlug:o,connectable:N,unavailable:j}):null,M(s)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),n&&f.length>0&&!t&&!u?e.jsxs(I,{title:"Apps and sources",count:String(f.length),children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Apps and sources that use this device."}),e.jsx("div",{className:"divide-y border-y",children:[...new Set(f.map(d=>d.connector_key))].map(d=>e.jsx(F,{group:{key:d,name:g.get(d)?.name??d,connections:f.filter(x=>x.connector_key===d)},deviceId:s.id,organizationId:n,ownerSlug:o,definitionsByKey:g,selectedConnection:h,openSettings:m},d))})]}):null]})}function F({group:s,deviceId:n,organizationId:o,ownerSlug:h,definitionsByKey:m,selectedConnection:r,openSettings:t}){const u=s.connections.some(a=>a.connection_id===r),[p,g]=v.useState(u);return v.useEffect(()=>{u&&r!==void 0&&g(!0)},[u,r]),e.jsxs(ae,{open:p,onOpenChange:g,children:[e.jsxs(ie,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(ce,{className:"size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90"}),e.jsx("span",{className:"min-w-0 flex-1 text-sm font-medium",children:s.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:s.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":s.connections.length>1?`${s.connections.length} connections`:"Configured"})]}),e.jsx(oe,{className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:s.connections.map(a=>e.jsx(He,{summary:a,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m.get(a.connector_key),openSettings:a.connection_id===r&&t},a.connection_id))})})]})}function He({summary:s,deviceId:n,organizationId:o,ownerSlug:h,connectorDef:m,openSettings:r}){const{data:t=[],isLoading:u,isError:p,refetch:g}=J(o,{connectionIds:[s.connection_id]}),a=t.find(j=>j.id===s.connection_id&&j.device_worker_id===n),f=m?.name??s.connector_key,N=a?V(a):null;return e.jsxs("section",{id:`connection-${s.connection_id}`,"aria-label":f,className:"scroll-mt-24",children:[a?e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:Ee(a)}),e.jsx("span",{children:a.status})]}):null,u||!o?e.jsx(R,{className:"h-24 w-full"}):p?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>void g(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[N?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:N}):null,e.jsx("div",{className:"mb-4",children:e.jsx(re,{connection:a})}),e.jsx(ze,{connection:a,connectorDef:m,ownerSlug:h,openSettings:r,showActivity:!1,showShare:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function Ke({device:s,ownerSlug:n}){const o=v.useId(),{data:h=[]}=le(),m=U(),[r,t]=v.useState(!1),[u,p]=v.useState(null),[g,a]=v.useState(null),f=h.filter(l=>l.is_member).map(l=>({id:l.id,name:l.name,isPersonal:l.is_personal===!0})),N=f.find(l=>l.id===s.organization_id),j=N?B(N):s.organization_name??"No workspace",d=f.filter(l=>l.id!==s.organization_id),x=d.find(l=>l.id===u)??null,y=()=>{t(!1),p(null)},k=async l=>{a(null);try{await m.mutateAsync({deviceWorkerId:s.id,organizationId:l}),y()}catch(c){a(c instanceof Error?c.message:"Could not move the device.")}};return e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Workspace: "}),j]}),!r&&d.length>0?e.jsx(b,{size:"sm",variant:"outline",onClick:()=>{a(null),t(!0)},children:"Change workspace"}):null]}),r?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("label",{htmlFor:o,className:"text-xs text-muted-foreground",children:"Move to"}),e.jsxs("select",{id:o,value:u??"",disabled:m.isPending,onChange:l=>p(l.target.value||null),className:"h-8 rounded-md border border-input bg-background px-2 text-sm",children:[e.jsx("option",{value:"",children:"Choose a workspace"}),d.map(l=>e.jsx("option",{value:l.id,children:B(l)},l.id))]}),x?null:e.jsx(b,{size:"sm",variant:"ghost",onClick:y,children:"Cancel"})]}):null,x?e.jsx(Q,{device:s,ownerSlug:n,title:`Move device to ${x.name}`,intro:`Move ${C(s)} from ${j} to ${B(x)}?`,aftermath:`It is set up fresh in ${x.name}, with its connections there private to you until you share them.`,confirmLabel:"Move device",pending:m.isPending,onConfirm:()=>void k(x.id),onCancel:y}):null,g?e.jsx("p",{role:"alert",className:"text-sm text-destructive",children:g}):null]})}function Oe({ownerSlug:s,deviceId:n,organizationId:o,selectedConnection:h,openSettings:m}){const r=de(),{data:t=[],isLoading:u,isError:p,refetch:g}=me(),a=ue(),f=xe(),[N,j]=v.useState(!1),[d,x]=v.useState(!1),[y,k]=v.useState(""),l=he(t,n),c=l&&pe(l,s)?l:void 0,i=c?.id??n,{data:w=[]}=fe(o,{profileKind:"browser_session"}),S=v.useMemo(()=>w.filter(_=>_.device_worker_id===i&&_.status!=="revoked"),[w,i]),$=c?.label?.trim()??"";if(v.useEffect(()=>{d||k($)},[$,d]),u)return e.jsxs(P,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-6 w-6 rounded"}),e.jsx(R,{className:"h-5 w-40"})]}),e.jsx(Le,{})]});if(p)return e.jsx(P,{children:e.jsxs("div",{role:"alert",className:"space-y-2",children:[e.jsx("p",{children:"Could not load this device."}),e.jsx(b,{variant:"outline",size:"sm",onClick:()=>void g(),children:"Retry"})]})});if(!c&&l&&o)return e.jsxs(P,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{platform:M(l),className:"h-5 w-5"}),e.jsx("h1",{className:"text-base font-semibold",children:C(l)})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This device lives in"," ",l.organization_name??"another workspace",", not this workspace."]}),e.jsx(W,{device:l,organizationId:o,ownerSlug:s})]});if(!c)return e.jsxs(P,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This device isn't in this workspace, so its details aren't available."}),e.jsx(E,{to:"/$owner/connectors",params:{owner:s},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const D=ge(c),A=D?je(s,D,ve()):void 0,X=M(c),Z=ye(c.app_version),ee=be(c,Z),T=()=>{const _=y.trim(),se=c.label?.trim()??"";if(_===se){x(!1);return}f.mutate({deviceWorkerId:c.id,label:_.length===0?null:_},{onSuccess:()=>x(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(Pe,{header:e.jsx(ke,{breadcrumb:e.jsx(Se,{crumbs:[e.jsx(E,{to:"/$owner/connectors",params:{owner:s},search:{},className:K,children:"Connectors"},"connectors"),...A?[e.jsx(E,{to:"/$owner/connectors/app/$appId",params:{owner:s,appId:A.id},className:K,children:A.name},"app")]:[]]}),icon:e.jsx(q,{platform:X,className:"h-5 w-5"}),title:d?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(_e,{"aria-label":"Device name",value:y,onChange:_=>k(_.target.value),placeholder:C({...c,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:_=>{_.key==="Enter"?(_.preventDefault(),N||T()):_.key==="Escape"&&(j(!1),k(c.label?.trim()??""),x(!1))}}),N?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Forgets this device"," ",c.connector_count>0?`and un-pins ${c.connector_count} connector${c.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(b,{variant:"destructive",size:"sm",disabled:a.isPending,onClick:()=>a.mutate(c.id,{onSuccess:()=>{j(!1),r({to:"/$owner/connectors",params:{owner:s},search:{}})}}),children:[a.isPending?e.jsx(L,{className:"mr-1.5"}):null,a.isPending?"Removing...":"Confirm remove"]}),e.jsx(b,{size:"sm",variant:"ghost",disabled:a.isPending,onClick:()=>j(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(b,{size:"sm",onClick:T,disabled:f.isPending,children:[f.isPending?e.jsx(L,{className:"mr-1.5"}):null,f.isPending?"Saving...":"Save"]}),e.jsx(b,{size:"sm",variant:"ghost",disabled:f.isPending,onClick:()=>{k(c.label?.trim()??""),x(!1)},children:"Cancel"}),e.jsxs(b,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:f.isPending||a.isPending,onClick:()=>j(!0),children:[e.jsx(we,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[C(c),e.jsx(b,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{j(!1),k(c.label?.trim()??""),x(!0)},children:e.jsx(Ce,{className:"h-3.5 w-3.5"})})]}),badge:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:`size-1.5 rounded-full ${c.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),c.online?c.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:ee||void 0,caption:`Last seen ${H(new Date(c.last_seen_at),{addSuffix:!0})}${c.last_sync_at?` · Last sync ${H(new Date(c.last_sync_at),{addSuffix:!0})}`:""}`}),children:[e.jsx(Ke,{device:c,ownerSlug:s}),c.connector_error_count>0?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[e.jsx(Ne,{className:"h-3.5 w-3.5 shrink-0"}),c.connector_error_count," connector",c.connector_error_count===1?"":"s"," pinned to this device ",c.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(W,{device:c,organizationId:o,ownerSlug:s,selectedConnection:h,openSettings:m}),S.length>0?e.jsx(I,{title:"Browser auth profiles",children:e.jsx(We,{profiles:S})}):null,e.jsx(I,{title:"Runs",children:e.jsx(Ie,{scope:{deviceId:i},ownerSlug:s})})]})})}function We({profiles:s}){return s.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:s.map(n=>e.jsxs("li",{className:"space-y-2 px-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:n.display_name}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:n.connector_key??"Any connector"}),n.browser_kind?e.jsxs("span",{children:["· ",n.browser_kind]}):null,n.captured_at?e.jsxs("span",{title:n.captured_at,children:["· captured ",$e(n.captured_at)]}):null,typeof n.cookie_count=="number"?e.jsxs("span",{children:["· ",n.cookie_count," cookie",n.cookie_count===1?"":"s"]}):null]})]}),e.jsx(Re,{status:n.is_expired?"error":Ae(n.status),showDot:!0,children:n.is_expired?"expired":n.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},n.id))})})}function ls(){const{owner:s,deviceId:n}=O.useParams(),{connection:o,settings:h}=O.useSearch();return e.jsx(De,{owner:s,children:({ownerSlug:m,organizationId:r})=>e.jsx(Oe,{ownerSlug:m,deviceId:n,organizationId:r,selectedConnection:o,openSettings:h})})}export{ls as component};
|
|
2
|
-
//# sourceMappingURL=device._deviceId-Bh9S4bFp.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as e,eW as M,H as p,$ as ae,bl as ie,bm as re,bn as ne,bo as le,bp as ce,ff as de,go as me,gp as E,gq as U,gr as oe,gs as R,gt as ue,B as O,bc as H,d6 as G,I as J,c$ as xe,eY as be,gu as je,cU as Q,gv as fe,Y as ye,i as q,gw as he,r as Y,dT as Ne,dV as ge,gx as we,dU as $e,di as k}from"./index-BjcZVe7n.js";import{d as A,h as Se,F as ve,i as z,j as Oe}from"./renderer-CHPS-1vD.js";import{C as Te}from"./filter-bar-CQ_oE7a9.js";import{T as Be,a as De,b as C,c as Z,d as Ee,e as V}from"./table-DALHuXPE.js";import{p as K,a as Ie}from"./schema-value-BFb7jCBo.js";function ee(l){return l.replace(/[^a-zA-Z0-9_-]/g,"-")}function Ae(l,r=!1){return l?Ie(l,r):r?"Pick a date and time":"Pick a date"}function P(l){if(!l)return"";const r=K(l);if(Number.isNaN(r.getTime()))return"";const s=r.getTimezoneOffset()*6e4;return new Date(r.getTime()-s).toISOString().slice(0,16)}function W(l){if(!l)return;const r=new Date(l);if(!Number.isNaN(r.getTime()))return r.toISOString()}function I(l,r){const s=r==="slug"?l.slug:l.metadata?.[r];return s==null?"":String(s)}function X({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,includeTime:N=!1,clearable:j}){const d=r?K(r):void 0,[m,u]=Y.useState(()=>P(r).slice(11));return Y.useEffect(()=>{u(P(r).slice(11))},[r]),e.jsx("div",{className:"relative",children:e.jsxs(Ne,{children:[e.jsx(ge,{asChild:!0,children:e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",disabled:a,className:q("w-full justify-start rounded-md bg-muted px-3 text-left font-normal",!r&&"text-muted-foreground"),children:[e.jsx(we,{className:"mr-2 h-4 w-4 shrink-0"}),e.jsx("span",{className:"truncate",children:Ae(r,N)})]})}),e.jsxs($e,{className:"w-auto space-y-3 p-0",align:"start",children:[e.jsx(Te,{mode:"single",selected:d,defaultMonth:d,onSelect:i=>{if(!i)return;if(!N){s(k(i,"yyyy-MM-dd"));return}const t=m||"00:00";s(W(`${k(i,"yyyy-MM-dd")}T${t}`))},initialFocus:!0}),N?e.jsxs("div",{className:"border-t p-3 pt-0",children:[e.jsx(p,{htmlFor:`${l}-time`,className:"text-xs text-muted-foreground",children:"Time"}),e.jsx(J,{id:`${l}-time`,type:"time",value:m,onChange:i=>{u(i.target.value);const t=r?P(r).slice(0,10):d?k(d,"yyyy-MM-dd"):"";t&&s(W(`${t}T${i.target.value}`))},disabled:a})]}):null,j&&r?e.jsx("div",{className:"border-t p-2",children:e.jsx(O,{type:"button",variant:"ghost",size:"sm",className:"w-full",onClick:()=>s(void 0),children:"Clear"})}):null]})]})})}function Fe({id:l,value:r,onChange:s,readonly:a,ariaLabel:c,ariaDescribedBy:w,entityType:N,lookupField:j,numeric:d=!1,orgContext:m}){const u=o=>{if(o===void 0||o==="")return s(void 0);if(!d)return s(o);const x=Number(o);s(Number.isFinite(x)?x:o)},{data:i}=xe(N,m,{limit:be}),t=(i?.entities??[]).filter(o=>I(o,j)!==""),$=r==null?"":String(r),v=t.find(o=>I(o,j)===$);return m?a?e.jsx("div",{className:"flex h-9 items-center rounded-md border border-input bg-muted px-3 text-sm",children:v?.name||$||"-"}):e.jsx(je,{contentClassName:"w-[320px]",searchPlaceholder:`Search ${z(N).toLowerCase()}...`,emptyText:`No ${N} found.`,trigger:o=>e.jsxs(O,{id:l,"aria-label":c,"aria-describedby":w,type:"button",variant:"outline",role:"combobox","aria-expanded":o,className:"w-full justify-between",children:[e.jsx("span",{className:q("truncate",!$&&"text-muted-foreground"),children:v?.name||$||`Select ${z(N).toLowerCase()}`}),e.jsx(he,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(o,x)=>{const n=x.trim(),f=n.length>0&&!t.some(y=>I(y,j)===n);return e.jsxs(e.Fragment,{children:[f?e.jsxs(Q,{value:`use ${n}`,onSelect:()=>{u(n),o()},children:[e.jsx(fe,{className:"mr-2 h-3.5 w-3.5 opacity-60"}),e.jsxs("span",{className:"truncate",children:["Use ",e.jsx("span",{className:"font-medium",children:n})]})]}):null,t.map(y=>{const h=I(y,j),T=h===$;return e.jsxs(Q,{value:`${y.name} ${y.slug} ${y.entity_type} ${h}`,onSelect:()=>{u(h||void 0),o()},children:[e.jsx(ye,{className:q("mr-2 h-4 w-4",T?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate",children:y.name}),e.jsx("div",{className:"text-xs text-muted-foreground",children:y.slug})]})]},`${y.id}-${h}`)})]})}}):e.jsx(J,{id:l,"aria-label":c,"aria-describedby":w,type:d?"number":"text",value:$,onChange:o=>u(o.target.value||void 0),disabled:a})}function se({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:j,ariaLabel:d,helpId:m}){const u=A(r,s),i=ee(l),t=N||s.readOnly===!0,$=s.type==="object"||!!s.properties,v=s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties),o=s.type==="array"&&!!s.items&&(s.items?.type==="string"||s.items?.type==="number"||s.items?.type==="integer"||s.items?.type==="boolean");if(s.type==="boolean")return e.jsx(ae,{id:i,"aria-label":d,"aria-describedby":m,checked:a??!1,onCheckedChange:n=>c(n),disabled:t});let x;if(s.enum&&Array.isArray(s.enum))x=e.jsxs(ie,{value:a==null?"":String(a),onValueChange:n=>c(n===""?void 0:s.type==="number"||s.type==="integer"?Number(n):n),disabled:t,children:[e.jsx(re,{id:i,"aria-label":d,"aria-describedby":m,children:e.jsx(ne,{placeholder:`Select ${u.toLowerCase()}`})}),e.jsx(le,{children:s.enum.map(n=>{const f=String(n);return e.jsx(ce,{value:f,children:de(s,n)??z(f)},f)})})]});else if(s["x-link-entity-type"])x=e.jsx(Fe,{id:i,value:a,onChange:c,readonly:t,ariaLabel:d,ariaDescribedBy:m,entityType:s["x-link-entity-type"],lookupField:s["x-link-lookup-field"]||"slug",numeric:s.type==="number"||s.type==="integer",orgContext:j});else if(s.type==="number"||s.type==="integer")x=e.jsx(me,{id:i,ariaLabel:d,ariaDescribedBy:m,value:a,onChange:c,integer:s.type==="integer",placeholder:`Enter ${u.toLowerCase()}`,readOnly:t});else if($){const n=M(s.properties),f=new Set(s.required??[]),y=E(a)?a:{};x=Object.keys(s.properties??{}).length===0||!E(a)&&a!==void 0&&a!==null?e.jsx(U,{id:i,value:a,ariaLabel:`${u} JSON object`,ariaDescribedBy:m,readOnly:t,onChange:c}):e.jsx("fieldset",{"aria-label":d,"aria-labelledby":d?void 0:`${i}-label`,"aria-describedby":m,className:"space-y-3 rounded-md border p-3",children:n.map(([h,T])=>e.jsx(te,{fieldPath:`${l}.${h}`,fieldKey:h,prop:T,value:y[h],onChange:S=>{const b={...y};S===void 0?delete b[h]:b[h]=S,c(b)},isRequired:f.has(h),readonly:t,orgContext:j},h))})}else if(o)x=a!=null&&!oe(a)?e.jsx(R,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:m,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c}):e.jsx(ue,{id:i,value:a,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,ariaLabel:d,ariaDescribedBy:m,readOnly:t,showHelp:!d,onChange:c});else if(v&&s.items){const n=Array.isArray(a)?a:[],f=M(s.items.properties),y=new Set(s.items.required??[]),h=s.maxItems===void 0||n.length<s.maxItems,T=s.minItems===void 0||n.length>s.minItems;x=!Array.isArray(a)&&a!==void 0&&a!==null||Object.keys(s.items.properties??{}).length>0&&n.some(S=>!E(S))?e.jsx(R,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:m,readOnly:t,itemType:"object",minItems:s.minItems,maxItems:s.maxItems,onChange:c}):Object.keys(s.items.properties??{}).length===0?e.jsxs("fieldset",{"aria-label":d,"aria-labelledby":d?void 0:`${i}-label`,"aria-describedby":m,className:"space-y-3",children:[n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No rows"}):n.map((S,b)=>e.jsxs("fieldset",{className:"space-y-2 rounded-md border p-3",children:[e.jsxs("legend",{className:"px-1 text-xs font-medium text-muted-foreground",children:["Row ",b+1]}),e.jsx(U,{id:`${i}-${b}-json`,value:S,ariaLabel:`${u} row ${b+1} JSON object`,readOnly:t,onChange:B=>{const g=[...n];g[b]=B,c(g)}}),t?null:e.jsxs(O,{type:"button",variant:"ghost",size:"sm","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((B,g)=>g!==b)),children:[e.jsx(H,{className:"mr-1.5 h-4 w-4"}),"Remove row"]})]},`${l}.${b}`)),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]}):e.jsxs("fieldset",{"aria-label":d,"aria-labelledby":d?void 0:`${i}-label`,"aria-describedby":m,className:"space-y-3",children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(Be,{children:[e.jsx(De,{children:e.jsxs(C,{children:[f.map(([S,b])=>e.jsxs(Z,{children:[A(S,b),y.has(S)?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]},S)),t?null:e.jsx(Z,{className:"w-12"})]})}),e.jsx(Ee,{children:n.length===0?e.jsx(C,{children:e.jsx(V,{colSpan:f.length+(t?0:1),className:"text-sm text-muted-foreground",children:"No rows"})}):n.map((S,b)=>{const B=E(S)?S:{};return e.jsxs(C,{children:[f.map(([g,D])=>e.jsx(V,{className:"align-top",children:e.jsx(se,{fieldPath:`${l}.${b}.${g}`,fieldKey:g,prop:D,ariaLabel:A(g,D),value:B[g],onChange:L=>{const _=[...n],F={...B};L===void 0?delete F[g]:F[g]=L,_[b]=F,c(_)},isRequired:y.has(g),readonly:t,orgContext:j})},g)),t?null:e.jsx(V,{className:"align-top",children:e.jsx(O,{type:"button",variant:"ghost",size:"icon","aria-label":`Remove row ${b+1}`,disabled:!T,onClick:()=>c(n.filter((g,D)=>D!==b)),children:e.jsx(H,{className:"h-4 w-4"})})})]},`${l}.${b}`)})})]})}),t?null:e.jsxs(O,{type:"button",variant:"outline",size:"sm",disabled:!h,onClick:()=>c([...n,{}]),children:[e.jsx(G,{className:"mr-1.5 h-4 w-4"}),"Add row"]})]})}else if(s.type==="array")x=e.jsx(R,{id:i,value:a,ariaLabel:`${u} JSON array`,ariaDescribedBy:m,readOnly:t,itemType:s.items?.type,itemEnum:s.items?.enum,minItems:s.minItems,maxItems:s.maxItems,onChange:c});else if(s.format==="date")x=e.jsx(X,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:d,ariaDescribedBy:m,clearable:!w});else if(s.format==="date-time")x=e.jsx(X,{id:i,value:typeof a=="string"?a:void 0,onChange:c,readonly:t,ariaLabel:d,ariaDescribedBy:m,includeTime:!0,clearable:!w});else{const n=s.format==="uri"||s.format==="url";x=e.jsx(J,{id:i,"aria-label":d,"aria-describedby":m,type:n?"url":"text",value:a??"",onChange:f=>c(f.target.value||void 0),placeholder:n?"https://example.com":`Enter ${u.toLowerCase()}`,disabled:t})}return x}function te({fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,control:j,orgContext:d,customControl:m}){const u=A(r,s),i=Se(s),t=ee(l),$=i?`${t}-description`:void 0,v=i?e.jsx("p",{id:$,className:"text-xs text-muted-foreground",children:i}):null,o=j?e.jsx(ve,{control:j}):null,x=m??e.jsx(se,{fieldPath:l,fieldKey:r,prop:s,value:a,onChange:c,isRequired:w,readonly:N,orgContext:d,helpId:$});if(s.type==="boolean"){const f=e.jsxs("div",{className:"flex items-center space-x-2 py-1",children:[x,e.jsxs(p,{htmlFor:t,className:"flex items-center gap-1.5 font-normal",children:[u,o]})]});return v?e.jsxs("div",{className:"space-y-1",children:[f,v]}):f}const n=s.type==="object"||!!s.properties||s.type==="array"&&!!s.items&&(s.items?.type==="object"||!!s.items?.properties);return e.jsxs("div",{className:"space-y-1.5",children:[n?e.jsxs("p",{id:`${t}-label`,className:"flex items-center gap-1.5 text-sm font-medium",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}):e.jsxs(p,{htmlFor:t,className:"flex items-center gap-1.5",children:[e.jsxs("span",{children:[u,w?e.jsx("span",{className:"text-destructive ml-1",children:"*"}):null]}),o]}),x,v]})}function Me(l){const r={};for(const[s,a]of Object.entries(l)){const c=Oe(a);c!==void 0&&(r[s]=c)}return r}function pe({schema:l,values:r,onValuesChange:s,readonly:a=!1,fieldControls:c,orgContext:w,renderControl:N}){const j=l,d=j?.properties,m=new Set(j?.required??[]),u=(i,t)=>{s({...r,[i]:t})};return!d||Object.keys(d).length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"No additional fields required for this entity type."}):e.jsx("div",{className:"space-y-4",children:M(d).map(([i,t])=>"x-measure"in t||"x-dimension"in t?null:e.jsx(te,{fieldPath:i,fieldKey:i,prop:t,value:r[i],onChange:$=>u(i,$),isRequired:m.has(i),readonly:a,control:c?.[i],orgContext:w,customControl:N?.(i,t,r[i])},i))})}export{pe as D,se as S,Me as c};
|
|
2
|
-
//# sourceMappingURL=dynamic-schema-form-qWSRtOAv.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{c as x,at as m,j as e,bl as C,bm as _,bn as S,bo as b,bp as i,ft as u}from"./index-BjcZVe7n.js";import{c as w}from"./connection-label-BobuYiAG.js";const h="__connection_picker_create_new__";function y({connections:s,value:r,onValueChange:n,connectorKey:a,disabled:p,placeholder:d="Choose a connection",includeWorkspaceEvents:c=!1,ariaLabel:f="Connection"}){const g=x(),l=m().org?.slug,o=a?s.filter(t=>t.connector_key===a):s,j=t=>{if(t===h){if(!l)return;g({to:"/$owner/connectors/create",params:{owner:l},search:a?{connector:a}:{}});return}n(t)};return e.jsxs(C,{value:r,onValueChange:j,disabled:p,children:[e.jsx(_,{"aria-label":f,children:e.jsx(S,{placeholder:d})}),e.jsxs(b,{children:[c?e.jsxs(e.Fragment,{children:[e.jsx(i,{value:"workspace",children:"Current workspace"}),o.length>0?e.jsx(u,{}):null]}):null,o.map(t=>e.jsx(i,{value:String(t.id),children:w(t)},t.id)),l?e.jsxs(e.Fragment,{children:[o.length>0||c?e.jsx(u,{}):null,e.jsx(i,{value:h,children:"Connect an app…"})]}):null]})]})}function v(s){const r=[];for(const n of s)typeof n.id=="number"&&r.push({id:n.id,name:n.name,entityType:n.entity_type}),n.children&&n.children.length>0&&r.push(...v(n.children));return r}export{y as C,v as f};
|
|
2
|
-
//# sourceMappingURL=entity-options-BkU_En_f.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{dj as we,r as E,c2 as Se,jI as S,fU as Re,ew as te,j as e,B as N,u as Y,jC as Ee,S as se,g2 as me,jJ as Fe,E as De,c as he,b as Ce,c3 as B,at as Le,k as Be,ey as X,eI as Pe,jD as Te,jK as Ie,eT as Ve,ch as ae,fe as $e,fZ as Me,f5 as Oe,hq as Ae,hr as ze,hs as Ue,ht as He,hu as Ke,jL as We,c7 as qe,H as K,I as ne,eL as Ge,W as Xe,fS as ie,e4 as W,gT as Qe,L as q,gU as G}from"./index-BjcZVe7n.js";import{N as Ye,d as Je,f as Ze,g as et,S as tt,h as st}from"./entity-pages-DxgbjLMt.js";import{R as at}from"./record-activity-CTLwq8s1.js";import{D as nt}from"./dynamic-schema-form-qWSRtOAv.js";import{r as it,V as ot}from"./views-access-required-CZ1fvAks.js";import{a as pe,V as oe,M as rt,b as lt}from"./view-param-filters-CDvwie_f.js";import{m as ct,j as Q,d as dt,o as re,c as fe,R as xe,q as ut,r as mt}from"./renderer-CHPS-1vD.js";import"./filter-bar-CQ_oE7a9.js";import"./table-DALHuXPE.js";import{a as ht}from"./source-record-panels-m8gECt82.js";import{r as pt,R as le,b as ft}from"./event-card-CjA_dLzq.js";import{a as xt}from"./record-session-DOFgdd43.js";import"./schema-value-BFb7jCBo.js";import"./connection-label-BobuYiAG.js";import"./manage-gear-C-0BAMbC.js";import"./runs-BntGAKQG.js";import"./clients-Cmp0LmOp.js";import"./client-activity-scopes-BD2HBo-_.js";import"./client-rows-x_CxeWkP.js";import"./events-feed-CGzA1w3R.js";import"./use-scroll-sentinel-BWCrmNIB.js";import"./agent-loading-shells-_18OREnx.js";import"./member-scope-gate-BQiRAqtx.js";import"./app-bridge-C4nPtae3.js";import"./card-g4yxo4Hr.js";import"./definition-comparison-B5WgZILB.js";import"./automation-source-list-Dhucq1sI.js";import"./json-diff-DtZtra_g.js";import"./index-Vcq4gwWv.js";import"./run-initiator-CCxNv0rK.js";import"./use-automations-D9hKpufo.js";import"./change-summary-DeuXQEpb.js";import"./copy-button-Ddf7lBjZ.js";import"./agent-list-row-BnP6r4pm.js";import"./automation-row-B5Q1B10y.js";import"./model-C2q7WDcS.js";function gt(t,s){if(t===void 0)return{shouldBlockFn:()=>!0,withResolver:!1};if("shouldBlockFn"in t)return t;if(typeof t=="function")return{shouldBlockFn:async()=>await t(),enableBeforeUnload:!0,withResolver:!1};const i=!!(t.condition??!0),n=t.blockerFn;return{shouldBlockFn:async()=>i&&n!==void 0?await n():i,enableBeforeUnload:i,withResolver:n===void 0}}function vt(t,s){const{shouldBlockFn:i,enableBeforeUnload:n=!0,disabled:a=!1,withResolver:c=!1}=gt(t),o=we(),{history:r}=o,[u,x]=E.useState({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0});return E.useEffect(()=>{const p=async f=>{function l(j){const b=o.parseLocation(j),v=o.getMatchedRoutes(b.pathname);return v.foundRoute===void 0?{routeId:"__notFound__",fullPath:b.pathname,pathname:b.pathname,params:v.routeParams,search:o.options.parseSearch(j.search)}:{routeId:v.foundRoute.id,fullPath:v.foundRoute.fullPath,pathname:b.pathname,params:v.routeParams,search:o.options.parseSearch(j.search)}}const m=l(f.currentLocation),d=l(f.nextLocation);if(m.routeId==="__notFound__"&&d.routeId!=="__notFound__")return!1;const h=await i({action:f.action,current:m,next:d});if(!c)return h;if(!h)return!1;const k=await new Promise(j=>{x({status:"blocked",current:m,next:d,action:f.action,proceed:()=>j(!1),reset:()=>j(!0)})});return x({status:"idle",current:void 0,next:void 0,action:void 0,proceed:void 0,reset:void 0}),k};return a?void 0:r.block({blockerFn:p,enableBeforeUnload:n})},[i,n,a,c,r,o]),u}function U(t,s){return te(Q(t))===te(Q(s))}function jt(t,s){const i={};for(const n of new Set([...Object.keys(t),...Object.keys(s)]))U(t[n],s[n])||(i[n]=Q(t[n])??null);return Object.keys(i).length>0?i:void 0}function yt(t,s){return[...new Set([...Object.keys(t),...Object.keys(s)])].filter(i=>{try{return!U(t[i],s[i])}catch{return!0}})}function ce(t,s){return{name:t.name,slug:t.slug,metadata:ct(t.metadata??{},s)}}function bt(t,s,i){const n=new Set(i),a={},c={},o=new Set([...Object.keys(t.values.metadata),...Object.keys(t.baseline.metadata),...Object.keys(s.metadata)]);for(const r of o){const u=n.has(r),x=u?t.values.metadata[r]:t.baseline.metadata[r],p=U(x,s.metadata[r])?x:s.metadata[r];p!==void 0&&(a[r]=p);let f=!1;if(!u)try{f=!U(t.values.metadata[r],t.baseline.metadata[r])}catch{f=!0}const l=f?t.values.metadata[r]:p;l!==void 0&&(c[r]=l)}return{baseline:{name:s.name,slug:s.slug,metadata:a},values:{name:s.name,slug:s.slug,metadata:c}}}function kt({entity:t,schema:s,orgContext:i}){const n=E.useMemo(()=>ce(t,s),[t,s]),a=Se(S(t),n,s),c=Re(i),{values:o,baseline:r,commit:u}=a,x=E.useMemo(()=>yt(o.metadata,r.metadata),[o.metadata,r.metadata]),p=o.name!==r.name||o.slug!==r.slug,f=E.useCallback((m,d)=>a.setValues(h=>({...h,metadata:{...h.metadata,[m]:d}})),[a.setValues]),l=async({note:m}={})=>{if(typeof t.id!="number")throw new Error("Source records are read-only");if(!a.canSubmit)return null;const d=jt(o.metadata,r.metadata),h=o.name.trim()!==r.name.trim();if(!d&&!p)return null;const k=await c.mutateAsync({entityId:t.id,name:h?o.name.trim():void 0,slug:o.slug,metadata:d,field_note:d&&m?.trim()||void 0}),j=ce(k.entity,s);return u(b=>bt(b,j,Object.keys(d??{})),j),{held:k.blocked_fields??[],approvalUrl:k.approval_url}};return{values:o,baseline:r,revision:a.revision,setValues:a.setValues,setMetadataField:f,reset:a.reset,save:l,saving:c.isPending,dirtyKeys:x,identityDirty:p,isDirty:p||x.length>0,canSubmit:a.canSubmit,hasConflict:a.hasConflict,hasInvalidInput:a.hasInvalidInput}}const _t=3,Nt=50;function ge(t){const s=E.useRef(null);return E.useEffect(()=>{t&&(s.current?.scrollIntoView?.({block:"start"}),s.current?.focus())},[t]),s}function T({headingRef:t,children:s}){return e.jsx("h3",{ref:t,tabIndex:-1,className:"text-xs font-medium uppercase tracking-wide text-muted-foreground outline-none",children:s})}function wt({entityId:t,entityName:s,ownerSlug:i,orgContext:n,focus:a,collapsed:c=!1}){const o=Y(),r=ge(a),{data:u,isLoading:x,isError:p,refetch:f}=Ee(t,n,{limit:Nt});if(t===void 0)return null;if(x)return e.jsxs("section",{className:"space-y-2","aria-busy":"true",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx(se,{className:"h-4 w-24"}),e.jsx(se,{className:"h-6 w-full rounded-md"})]});if(p||!u)return e.jsxs("section",{className:"space-y-2",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Could not load this record's links."," ",e.jsx("button",{type:"button",className:"underline",onClick:()=>void f(),children:"Retry"})]})]});if(u.countsByType.length===0&&!u.hasMore&&!u.failures?.length)return a?e.jsxs("section",{className:"space-y-2",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"No links to other records yet."})]}):null;if(c){const l=u.countsByType.flatMap(m=>{const d=m.count===1?u.rows.find(h=>h.relationship_type_slug===m.relationship_type_slug):void 0;return d?[pt(d,m.relationship_type_name)]:[m.relationship_type_name,String(m.count)]});return e.jsxs("section",{className:"space-y-1","aria-label":"Linked records",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx(le,{count:u.failures?.length??0,onRetry:()=>void f()}),e.jsx("p",{"data-testid":"linked-summary",className:"truncate text-sm text-muted-foreground",children:l.join(" · ")})]})}return e.jsxs("section",{className:"space-y-3","aria-label":"Linked records",children:[e.jsx(T,{headingRef:r,children:"Linked"}),e.jsx(le,{count:u.failures?.length??0,onRetry:()=>void f()}),u.hasMore&&o?e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>o.open({href:"",key:`record-links:${t}`,title:"Linked records",recordLinks:{entityId:t,entityName:s,ownerSlug:i,orgContext:n,label:"Linked records"}}),children:"Browse linked records"}):null,u.countsByType.map(l=>{const m=u.rows.filter(h=>h.relationship_type_slug===l.relationship_type_slug).slice(0,_t),d=l.count>m.length;return e.jsxs("div",{className:"space-y-1 text-sm",children:[d||m.length===0?e.jsxs("p",{className:"text-muted-foreground",children:[l.relationship_type_name,d?e.jsxs("span",{className:"tabular-nums text-muted-foreground/70",children:[" ","· ",l.count,u.countsScope==="page"?" shown":""]}):null]}):null,e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[m.map(h=>e.jsx(ft,{row:h,label:l.relationship_type_name,entityId:t,ownerSlug:i,orgContext:n},h.id)),d&&o?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-primary hover:text-primary",onClick:()=>o.open({href:"",key:`record-links:${t}:${l.relationship_type_slug}`,title:`${l.relationship_type_name} · ${l.count}`,recordLinks:{entityId:t,entityName:s,ownerSlug:i,orgContext:n,relationshipType:l.relationship_type_slug,label:l.relationship_type_name}}),children:["Show all ",l.count]}):null]})]},l.relationship_type_slug)})]})}function St({record:t,ownerSlug:s,orgContext:i,focus:n}){const[a,c]=E.useState(n),o=ge(n);return e.jsxs("section",{className:"space-y-2",children:[e.jsx(T,{headingRef:o,children:"Linked"}),a?e.jsx(ht,{record:t,ownerSlug:s,orgContext:i}):e.jsx(N,{type:"button",variant:"outline",size:"sm",className:"h-7",onClick:()=>c(!0),children:"Find linked records"})]})}const Rt="$name";function ve({outcome:t,schema:s}){if(!t||t.held.length===0)return null;const i=s?.properties??{},n=t.held.map(a=>a===Rt?"Name":dt(a,i[a]??{}));return e.jsxs("div",{role:"status",className:"rounded-md bg-amber-500/10 px-3 py-2 text-sm text-amber-700 dark:text-amber-300",children:[n.join(", ")," ",n.length===1?"needs":"need"," approval before ",n.length===1?"it changes":"they change",".",t.approvalUrl?e.jsxs(e.Fragment,{children:[" ",e.jsx("a",{href:t.approvalUrl,className:"underline",children:"Review"})]}):null]})}const Et=320,Ft={},Dt=()=>{};function Ct({view:t,orgSlug:s,recordUrl:i,scope:n}){const a=Y(),c=`${i}${me(t.key)}`,o=a?()=>a.open({href:c,title:t.name}):void 0;return e.jsxs("section",{className:"min-w-0 rounded-lg border","data-testid":"view-card","data-view":t.key,children:[e.jsxs("header",{className:"flex items-start justify-between gap-3 px-4 pt-3 pb-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"truncate text-sm font-medium",children:t.name}),t.description?e.jsx("p",{className:"truncate text-xs text-muted-foreground",children:t.description}):null]}),o?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-7 shrink-0 gap-1.5 px-2 text-muted-foreground hover:text-foreground",onClick:o,"aria-label":`Open ${t.name}`,children:[e.jsx(Fe,{className:"h-3.5 w-3.5"}),"Open"]}):null]}),e.jsx("div",{className:"px-4 pb-3",children:e.jsx(pe,{orgSlug:s,viewKey:t.key,scope:n,params:Ft,onParamsChange:Dt,contentHash:t.content_hash,title:t.name,minHeight:64,displayMode:"inline",maxHeight:Et,onRequestDisplayMode:o?r=>{r==="fullscreen"&&o()}:void 0})})]})}function Lt({recordUrl:t,dirty:s,onDiscard:i}){const n=vt({disabled:!s,enableBeforeUnload:s,withResolver:!0,shouldBlockFn:({next:c})=>c.pathname!==t&&!c.pathname.startsWith(`${t}${me("")}`)}),a=n.status==="blocked";return e.jsx(Ae,{open:a,onOpenChange:c=>{!c&&a&&n.reset()},children:e.jsxs(ze,{className:"max-w-sm",children:[e.jsxs(Ue,{children:[e.jsx(He,{children:"Discard unsaved changes?"}),e.jsx(Ke,{children:"This record has edits that are not saved. Leaving discards them."})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",onClick:()=>a&&n.reset(),children:"Keep editing"}),e.jsx(N,{type:"button",variant:"destructive",onClick:()=>{a&&(i(),n.proceed())},children:"Discard"})]})]})})}const de=6;function Bt({entity:t,ownerSlug:s,orgContext:i,recordUrl:n,schema:a,entityTypeName:c,isTypeLoading:o,record:r,canEdit:u,editing:x,onEditingChange:p,outcome:f,onSaved:l,formId:m,fieldLimit:d,onDeleted:h}){const k=x&&u,j=Y(),b={entity:{id:S(t),name:t.name,entity_type:t.entity_type},ownerSlug:s,orgContext:i,schema:a,record:r,editing:k};xt(b);const v=j?.item?.recordField,D={ownerSlug:s,orgContext:i,controls:t.field_controls,dirtyKeys:r.dirtyKeys,openField:j?L=>j.open(it(b,L.key)):void 0,openFieldKey:v?.entityId===S(t)?v.field:void 0},C=e.jsx(Lt,{recordUrl:n,dirty:k&&r.isDirty,onDiscard:()=>{r.reset(),p(!1)}});if(o)return e.jsx(Oe,{rows:6});if(k)return e.jsxs(e.Fragment,{children:[C,e.jsx(Pt,{formId:m,entity:t,entityTypeName:c,schema:a,record:r,orgContext:i,renderControl:(L,P,F)=>ut(P)?e.jsx(mt,{field:{key:L,prop:P},value:F,context:D}):void 0,onSaved:l,onDeleted:h,onDone:()=>p(!1)})]});const R=fe(r.revision);return e.jsxs("div",{className:"space-y-3",children:[e.jsx(ve,{outcome:f,schema:a}),e.jsx(xe,{fields:R,fieldLimit:d,values:r.values.metadata,context:D})]})}function Pt({formId:t,entity:s,entityTypeName:i,schema:n,record:a,orgContext:c,renderControl:o,onSaved:r,onDeleted:u,onDone:x}){const p=We(),f=s.field_controls,{name:l,slug:m,metadata:d}=a.values,h=g=>a.setValues(y=>({...y,name:g})),k=g=>a.setValues(y=>({...y,slug:g})),j=g=>a.setValues(y=>({...y,metadata:g})),[b,v]=B(S(s),""),[D,C]=B(S(s),null),[R,L]=B(S(s),null),[P,F]=B(S(s),!1),[w,I]=B(S(s),null),V=a.dirtyKeys.length>0,O=async g=>{if(g.preventDefault(),!!a.canSubmit){if(C(null),!l.trim()){C("Name is required");return}try{const y=await a.save({note:b});L(y),r(y),v(""),y?.held.length||x()}catch(y){C(y instanceof Error?y.message:"Failed to update entity")}}},H=async()=>{I(null);try{if(typeof s.id!="number")throw new Error("Source records are read-only");await p.mutateAsync({entityId:s.id}),F(!1),u?.()}catch(g){I(g instanceof Error?g.message:"Failed to delete entity")}},A=[s.total_content>0&&`${s.total_content} content item${s.total_content===1?"":"s"}`,s.automations_count>0&&`${s.automations_count} Automation${s.automations_count===1?"":"s"}`,s.active_connections>0&&`${s.active_connections} connector${s.active_connections===1?"":"s"}`].filter(Boolean).join(", ");return e.jsxs("form",{id:t,onSubmit:O,className:"space-y-4",children:[e.jsx(qe,{visible:a.hasConflict,onReload:a.reset}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(K,{htmlFor:"sidebar-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(ne,{id:"sidebar-name",value:l,onChange:g=>h(g.target.value)})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(K,{htmlFor:"sidebar-slug",children:"URL Slug"}),e.jsx(ne,{id:"sidebar-slug",value:m,onChange:g=>k(g.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]}),a.revision&&Object.keys(a.revision).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(tt,{}),e.jsx(nt,{schema:a.revision,values:d,onValuesChange:j,fieldControls:f,orgContext:c,renderControl:o})]}),V&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(K,{htmlFor:"sidebar-correction-note",children:"Correction note (optional)"}),e.jsx(Ge,{id:"sidebar-correction-note",value:b,onChange:g=>v(g.target.value),placeholder:"Why are you changing these fields? Helps Automations respect the correction.",rows:2})]}),D&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:D}),e.jsx(ve,{outcome:R,schema:n}),P?e.jsxs("div",{className:"space-y-3 rounded-lg border border-destructive/40 bg-destructive/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 text-sm",children:[e.jsx(Xe,{className:"h-4 w-4 shrink-0 text-destructive mt-0.5"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:['Delete "',s.name,'"?']}),A&&e.jsxs("p",{className:"text-muted-foreground",children:["Removes ",A,". This cannot be easily undone."]})]})]}),w&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-2.5 py-1.5 text-sm text-destructive",children:w}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{F(!1),I(null)},children:"Cancel"}),e.jsx(N,{type:"button",variant:"destructive",size:"sm",onClick:H,disabled:p.isPending,children:p.isPending?"Deleting...":`Delete ${i||"entity"}`})]})]}):e.jsx("div",{className:"pt-2",children:e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>F(!0),children:"Delete"})})]})}function je(t,s){const i=new Set(t.measure_columns??[]),n=s?.properties??{};return Object.keys(t.metadata??{}).filter(a=>a!=="id"&&a!=="slug"&&a!=="name"&&!$e(n[a])&&n[a]?.const===void 0).map(a=>({key:a,prop:n[a]??{},label:n[a]?.["x-table-label"]??(i.has(a)?a:Me(a.replace(/_/g," "))),numeric:i.has(a)}))}function Tt({entity:t,schema:s,ownerSlug:i,fieldLimit:n}){const a=je(t,s);return e.jsxs("div",{children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Managed by the source"}),e.jsx(xe,{fields:a,fieldLimit:n,values:t.metadata??{},context:{ownerSlug:i}})]})}const ue="owletto:record-details-expanded";function It(){const[t,s]=E.useState(()=>{try{return window.localStorage.getItem(ue)==="1"}catch{return!1}});return[t,n=>{s(n);try{window.localStorage.setItem(ue,n?"1":"0")}catch{}}]}function Vt({namespace:t,entity:s,recordUrl:i,viewKey:n,title:a,onDeleted:c}){const o=De({strict:!1}),r=he(),u=E.useRef(null),x=Ce(u,Ye),[p,f]=It(),[l,m]=B(S(s),!1),d={slug:t.slug,organizationId:t.id},{isMember:h,isPublic:k,isLoading:j}=Le(t.slug),b=h||k,v=Be({...d,organizationId:h?t.id:null}),{data:D,isLoading:C}=X(s.entity_type,d),R=D?.metadata_schema,{isAdmin:L,isLoading:P}=Pe(h?d.organizationId:void 0),F=h&&L&&!P&&!s.is_derived,w=kt({entity:s,schema:R,orgContext:d}),[I,V]=B(S(s),null),O=`record-form-${s.id}`,H=l&&F,A=b?v.data??[]:[],g=Te(A,{type:s.entity_type,id:S(s)}),y=Ie(g,n),z=!n&&o.tab==="relationships",ye=_=>void r({to:".",search:_,replace:!0}),J={type:s.entity_type,entity:s.is_derived?s.slug:s.id??s.slug},$=x&&!p&&!l&&!z,Z=s.is_derived?re(je(s,R),s.metadata??{}).length:re(fe(w.revision),w.values.metadata).length,ee=$?de:void 0,be=e.jsxs("div",{className:"space-y-6",children:[s.is_derived?e.jsxs(e.Fragment,{children:[e.jsx(Tt,{entity:s,schema:R,ownerSlug:t.slug,fieldLimit:ee}),e.jsx(St,{record:{type:s.entity_type,key:s.slug},ownerSlug:t.slug,orgContext:d,focus:z})]}):e.jsxs(e.Fragment,{children:[e.jsx(Bt,{entity:s,ownerSlug:t.slug,orgContext:d,recordUrl:i,schema:R,entityTypeName:D?.name,isTypeLoading:C,record:w,canEdit:F,editing:l,onEditingChange:m,outcome:I,onSaved:V,formId:O,fieldLimit:ee,onDeleted:c}),e.jsx(wt,{entityId:typeof s.id=="number"?s.id:void 0,entityName:s.name,ownerSlug:t.slug,orgContext:d,focus:z,collapsed:$})]}),x&&!l&&!z?e.jsx(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-primary hover:text-primary","aria-expanded":!$,onClick:()=>f($),children:$?Z>de?`Show all ${Z} fields`:"Show all details":"Show fewer"}):null]}),ke=_=>e.jsx(Ze,{rootRef:u,narrow:x,details:be,summary:e.jsx(et,{entity:s,schema:R}),children:_}),_e=H?e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(N,{type:"button",variant:"ghost",size:"sm",onClick:()=>{w.reset(),V(null),m(!1)},children:"Cancel"}),e.jsx(N,{type:"submit",form:O,size:"sm",disabled:!w.canSubmit||!w.isDirty||w.saving||!w.values.name.trim(),children:w.saving?"Saving...":"Save"})]}):F&&!C?e.jsxs(N,{type:"button",variant:"ghost",size:"sm",className:"h-8 shrink-0 gap-1.5 px-2 text-muted-foreground hover:text-foreground",onClick:()=>{V(null),m(!0)},children:[e.jsx(Ve,{className:"h-3.5 w-3.5"}),"Edit"]}):null,M=_=>e.jsx(Je,{entity:s,owner:t.slug,schema:R,title:a??null,actions:_e,layout:"content",children:_});if(n&&!b)return M(j?null:e.jsx(ot,{}));if(n&&v.data===void 0)return M(v.isError?e.jsx(oe,{onRetry:()=>void v.refetch()}):null);if(y.kind==="missing")return M(e.jsx(rt,{viewKey:y.key,backTo:i,backLabel:`Back to ${s.name}`}));if(y.kind==="view"){const{view:_}=y;return M(e.jsxs("div",{className:"min-w-0 space-y-3",children:[e.jsx(lt,{decls:_.params,params:ae(o),onParamsChange:Ne=>void r({to:".",search:Ne})}),e.jsx(pe,{orgSlug:t.slug,viewKey:_.key,scope:J,params:ae(o),onParamsChange:ye,contentHash:_.content_hash,title:_.name,minHeight:320})]}))}return M(ke(e.jsxs("div",{className:"min-w-0 space-y-4",children:[b&&v.isError&&e.jsx(oe,{onRetry:()=>void v.refetch()}),g.map(_=>e.jsx(Ct,{view:_,orgSlug:t.slug,recordUrl:i,scope:J},_.key)),e.jsxs("section",{"aria-labelledby":"record-activity-heading",className:"min-w-0",children:[e.jsx("h2",{id:"record-activity-heading",className:"mb-2 text-sm font-medium text-muted-foreground",children:"Activity"}),e.jsx(at,{entity:s,organizationId:t.id,ownerSlug:t.slug})]})]})))}function $t(t){return t?.trim()?t:void 0}function bs({namespace:t,path:s,entity:i,viewKey:n}){const a=he(),{data:c}=X(i.entity_type,{slug:t.slug}),o=s[0]?.entity_type??i.entity_type,{data:r}=X(o,{slug:t.slug}),u=$t(c?.icon),x=s.map(l=>({entity_type:l.entity_type,slug:l.slug})),p=`/${t.slug}/${ie(i.entity_type)}`,f=W(t.slug,x);return e.jsxs("div",{className:"mx-auto flex min-h-0 w-full max-w-7xl flex-1 flex-col gap-4 px-4 pt-2.5 pb-8 lg:px-6",children:[e.jsx(Qe,{crumbs:[...o==="$member"?[]:[e.jsx(q,{to:"/$owner/data",params:{owner:t.slug},className:G,children:"Memory"},"memory")],e.jsx(q,{to:`/${t.slug}/${ie(o)}`,className:G,children:o==="$member"?"Team":r?.name??o},"type"),...s.slice(0,-1).map((l,m)=>e.jsx(q,{to:W(t.slug,x.slice(0,m+1)),className:G,children:l.name},l.id))],current:i.name}),e.jsx(Vt,{namespace:t,entity:i,recordUrl:f,viewKey:n,title:e.jsx(st,{entity:i,schema:c?.metadata_schema,icon:u}),onDeleted:()=>{const l=s.slice(0,-1);l.length>0?a({to:W(t.slug,l)}):a({to:p})}})]})}export{bs as EntityPage};
|
|
2
|
-
//# sourceMappingURL=entity-page-BPFDHY8q.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as x,j as e,bu as ue,i as U,dT as me,dV as xe,B as P,f$ as he,dU as pe,d5 as ge,eW as ne,fZ as F,fe,cR as A,V as q,L as T,e4 as je,b as ve,S as E}from"./index-BjcZVe7n.js";import{p as S,n as be,e as re,b as ye,g as Ne,f as J,R as we,c as _e}from"./renderer-CHPS-1vD.js";import{S as V}from"./schema-value-BFb7jCBo.js";import{T as Se,a as ke,b as B,c as Y,d as Ce,e as K}from"./table-DALHuXPE.js";var Ee="Separator",ee="horizontal",Re=["horizontal","vertical"],ae=x.forwardRef((t,s)=>{const{decorative:n,orientation:a=ee,...l}=t,o=Le(a)?a:ee,h=n?{role:"none"}:{"aria-orientation":o==="vertical"?o:void 0,role:"separator"};return e.jsx(ue.div,{"data-orientation":o,...h,...l,ref:s})});ae.displayName=Ee;function Le(t){return Re.includes(t)}var oe=ae;const Me=x.forwardRef(({className:t,orientation:s="horizontal",decorative:n=!0,...a},l)=>e.jsx(oe,{ref:l,decorative:n,orientation:s,className:U("shrink-0 bg-border",s==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",t),...a}));Me.displayName=oe.displayName;function Te({choices:t,visible:s,onChange:n}){return e.jsxs(me,{children:[e.jsx(xe,{asChild:!0,children:e.jsx(P,{variant:"ghost",size:"icon",className:"size-7 text-muted-foreground hover:text-foreground","aria-label":"Choose columns",title:"Choose columns",children:e.jsx(he,{className:"h-4 w-4"})})}),e.jsxs(pe,{align:"end",className:"max-h-80 overflow-y-auto p-3",children:[e.jsx("p",{className:"mb-2 text-sm font-medium",children:"Visible columns"}),t.map(a=>e.jsxs("label",{className:"flex cursor-pointer items-center gap-2 py-1.5 text-sm",children:[e.jsx("input",{type:"checkbox",checked:!s||s.includes(a.field),onChange:l=>{const o=s??t.map(c=>c.field);n(l.target.checked?[...o,a.field]:o.filter(c=>c!==a.field))}}),a.label]},a.field))]})]})}function Ae({direction:t}){return t?e.jsxs("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("title",{children:t==="asc"?"Sort ascending":"Sort descending"}),t==="asc"?e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 15l7-7 7 7"}):e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 9l-7 7-7-7"})]}):e.jsxs("svg",{className:"h-4 w-4 text-muted-foreground/50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("title",{children:"Sort"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"})]})}function te(t,s){const n=t?.properties;if(n)return Object.entries(n).find(([,a])=>a[s])?.[0]}function Pe(t){const s=t.trim(),n=s.split(/[\s._@/-]+/).filter(Boolean),a=n.length>=2?`${n[0][0]}${n[1][0]}`:(n[0]??s).slice(0,2);let l=0;for(let o=0;o<s.length;o++)l=l*31+s.charCodeAt(o)>>>0;return{initials:a.toUpperCase()||"?",hue:l%360}}function Fe(t){const[s,n]=x.useState();return x.useEffect(()=>{if(!t||!globalThis.crypto?.subtle){n(void 0);return}let a=!1;const l=t.trim().toLowerCase();return crypto.subtle.digest("SHA-256",new TextEncoder().encode(l)).then(o=>{a||n(Array.from(new Uint8Array(o)).map(c=>c.toString(16).padStart(2,"0")).join(""))}),()=>{a=!0}},[t]),s?`https://www.gravatar.com/avatar/${s}?d=identicon&s=80`:void 0}function le({metadata:t,metadataSchema:s,name:n,typeIcon:a,className:l="h-6 w-6",iconClassName:o="h-5 w-5",initialsFallback:c=!1}){const h=te(s,"x-image"),j=te(s,"x-email"),y=h&&t?.[h]||void 0,v=j&&t?.[j]||void 0,N=Fe(y?void 0:v),w=y||N,[k,R]=x.useState(!1);if(x.useEffect(()=>{R(!1)},[w]),w&&!k)return e.jsx("img",{src:w,alt:n,referrerPolicy:"no-referrer",onError:()=>R(!0),className:U("rounded-full object-cover border border-border",l)});if(c){const L=n.trim()||v||Oe(t,s)||n,{initials:O,hue:z}=Pe(L);return e.jsx("span",{role:"img","aria-label":n,className:U("inline-grid place-items-center rounded-full border border-border font-semibold text-white select-none",l),style:{background:`oklch(0.55 0.13 ${z})`,fontSize:"0.85em"},children:O})}return e.jsx(ge,{icon:a,className:o})}function Oe(t,s){if(!t)return;const n=s?.properties,a=["email","handle","username","login","github","x_handle","slug"],l=Object.keys(n||t);for(const o of l)if(a.includes(o.toLowerCase())){const c=t[o];if(typeof c=="string"&&c.trim())return c}}function _({column:t,children:s,alignRight:n=!1}){return e.jsxs("button",{type:"button",className:`flex items-center gap-1.5 whitespace-nowrap text-left transition-colors hover:text-foreground [&>svg]:shrink-0${n?" ml-auto":""}`,onClick:()=>t.toggleSorting(t.getIsSorted()==="asc"),children:[s,e.jsx(Ae,{direction:t.getIsSorted()})]})}function se(t,s,n){const a=ne(t?.properties).filter(([o,c])=>(!s||o!=="name")&&!c["x-image"]&&c["x-table-column"]===!0);if(a.length)return a.map(([o,c])=>({field:o,label:c["x-table-label"]??F(o.replaceAll("_"," "))}));if(!s)return[];const l=n.find(o=>Object.keys(S(o.metadata)).length>0);return Object.keys(S(l?.metadata)).filter(o=>o!=="id"&&o!=="slug"&&o!=="name"&&!fe(t?.properties?.[o])).map(o=>({field:o,label:F(o.replaceAll("_"," "))}))}function ze(t){return t.some(s=>Object.hasOwn(S(s.metadata),"name"))}function Ie(t,s){return A(t,re(s))}function $e(t){return`${t.entityType}:${t.lookupField}`}const Be=new Set(["stage","category","round_type","investor_type"]);function Ke(t,s){const n=t.toLowerCase();return n==="mrr"||n==="arr"||n==="revenue"||n==="valuation"||n==="funding_raised"||n==="fund_size"||n.endsWith("_usd")||s.description?.toLowerCase().includes("usd")===!0}function Ue(t,s){if(Ke(t,s))return"currency";if(Be.has(t)||t.endsWith("_slug"))return"enum"}function Ve({entities:t,owner:s,schema:n,entityTypeIcon:a,isDerived:l,measureColumns:o,linkedEntityLookups:c,hasAnyParents:h,sorting:j,onSortingChange:y,visibleColumns:v,columnChoices:N,onVisibleColumnsChange:w,page:k,pageSize:R,totalCount:L,hasMore:O,pageTitle:z,onPrevPage:ie,onNextPage:ce}){const M=N?.length&&w?e.jsx(Te,{choices:N,visible:v,onChange:w}):null,f=n?.properties,H=!l||ze(t),W=x.useMemo(()=>f?Object.fromEntries(Object.entries(f).flatMap(([i,r])=>r["x-link-entity-type"]?[[i,{entityType:r["x-link-entity-type"],lookupField:r["x-link-lookup-field"]||"slug"}]]:[])):{},[f]),C=x.useMemo(()=>f?se({properties:f},l,[]).map(({field:r})=>[r,f[r]]).map(([r,u])=>{const m=W[r],d=m?c[$e(m)]:void 0;return{id:l?r:`meta_${r}`,accessorFn:p=>{const g=S(p.metadata);return be(g[r],u.enum)},header:({column:p})=>{const g=u["x-table-label"]||u.title||u.description||F(r.replace(/_/g," "));return l?e.jsx(_,{column:p,children:g}):g},cell:({getValue:p})=>e.jsx(V,{value:p(),prop:u,format:Ue(r,u),className:"text-muted-foreground",resolveLink:d?g=>{const b=d[g];return b?{label:b.name,to:A(s,[{entity_type:b.entity_type,slug:b.slug}])}:void 0}:void 0})}}):[],[l,W,c,s,f]),D=x.useMemo(()=>new Set(o),[o]),I=x.useMemo(()=>!l||C.length>0?[]:se({properties:f},!0,t).map(({field:r})=>r).map(r=>{const u=D.has(r);return{id:r,accessorFn:m=>S(m.metadata)[r],header:({column:m})=>e.jsxs(_,{column:m,children:[u?r:F(r.replace(/_/g," ")),u&&e.jsx(q,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]}),cell:({getValue:m})=>e.jsx(V,{value:m(),prop:f?.[r],className:u?"tabular-nums":"text-muted-foreground"}),meta:u?{align:"right"}:void 0}}),[l,C,t,D,f]),Z=x.useMemo(()=>{const i=n?.["x-table-relationships"];return!i||i.length===0?[]:i.map(r=>({id:`rel_${r.relationship_type}`,accessorFn:u=>u.relationships?.[r.relationship_type]??[],header:r.label,cell:({getValue:u})=>{const m=u();return!m||m.length===0?e.jsx("span",{className:"text-muted-foreground",children:"-"}):e.jsx("div",{className:"flex flex-wrap gap-1",children:m.map((d,p)=>{const g=A(s,[{entity_type:d.entity_type,slug:d.slug}]);return e.jsxs("span",{children:[e.jsx(T,{to:g,className:"text-primary hover:underline",onClick:b=>b.stopPropagation(),children:d.name}),p<m.length-1&&","]},d.id)})})}}))},[s,n]),G=x.useMemo(()=>h||t.some(r=>r.parent_name&&r.parent_slug&&r.parent_entity_type)?[{id:"parent",accessorFn:r=>r.parent_name,header:"Parent",cell:({row:r})=>{if(!r.original.parent_name||!r.original.parent_slug||!r.original.parent_entity_type)return e.jsx("span",{className:"text-muted-foreground",children:"-"});const u=A(s,[{entity_type:r.original.parent_entity_type,slug:r.original.parent_slug}]);return e.jsx(T,{to:u,className:"text-primary hover:underline",children:r.original.parent_name})}}]:[],[t,h,s]),Q=x.useMemo(()=>{const i=[],r=t.some(d=>(d.total_content??0)>0),u=t.some(d=>(d.active_connections??0)>0),m=t.some(d=>(d.automations_count??0)>0);return r&&i.push({accessorKey:"total_content",header:({column:d})=>e.jsx(_,{column:d,alignRight:!0,children:"Activity"}),cell:({row:d,getValue:p})=>{const g=p()??0;if(g===0)return e.jsx("span",{className:"tabular-nums",children:"0"});const b=re(d.original);return e.jsx(T,{to:je(s,b),className:"tabular-nums hover:underline",children:g})},meta:{align:"right"}}),u&&i.push({accessorKey:"active_connections",header:"Connectors",cell:({getValue:d})=>{const p=d();return p&&p>0?e.jsxs(q,{variant:"outline",className:"text-green-600 dark:text-green-400",children:[p," active"]}):e.jsx("span",{className:"text-muted-foreground",children:"-"})},meta:{align:"right"}}),m&&i.push({accessorKey:"automations_count",header:({column:d})=>e.jsx(_,{column:d,alignRight:!0,children:"Automations"}),cell:({getValue:d})=>e.jsx("span",{className:"tabular-nums",children:d()??0}),meta:{align:"right"}}),i},[t,s]),X=x.useMemo(()=>[{accessorKey:"name",header:({column:i})=>H?e.jsx(_,{column:i,children:"Name"}):"Name",cell:({row:i})=>{const r=S(i.original.metadata);return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(le,{metadata:r,metadataSchema:n,name:i.original.name,typeIcon:a,className:"h-6 w-6 shrink-0"}),e.jsx("div",{className:"min-w-0",children:(()=>{const u=Ie(s,i.original);return e.jsx(T,{to:u,className:"block max-w-56 truncate font-medium hover:underline",title:i.original.name,children:i.original.name})})()})]})}},...G,...C,...I,...Z,...Q,...l?[]:[{accessorKey:"created_at",header:({column:i})=>e.jsx(_,{column:i,children:"Created"}),cell:({getValue:i})=>e.jsx("span",{className:"whitespace-nowrap text-muted-foreground",children:new Date(i()).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"})})}]],[s,G,C,I,Z,Q,n,a,l,H]),$=ye({data:t,columns:X,state:{sorting:j,columnVisibility:Object.fromEntries([...C,...I].flatMap(i=>i.id?[[i.id,!v||v.includes(l?i.id:i.id.replace(/^meta_/,""))]]:[]))},onSortingChange:y,getCoreRowModel:Ne(),manualSorting:!0,enableSortingRemoval:!1}),de=t.length>0||k>0;return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"rounded-lg border",children:e.jsxs(Se,{className:"min-w-[48rem]",children:[e.jsx(ke,{children:$.getHeaderGroups().map(i=>e.jsxs(B,{children:[i.headers.map(r=>e.jsx(Y,{"aria-sort":r.column.getIsSorted()==="asc"?"ascending":r.column.getIsSorted()==="desc"?"descending":void 0,className:r.column.columnDef.meta?.align==="right"?"text-right":"",children:r.isPlaceholder?null:J(r.column.columnDef.header,r.getContext())},r.id)),M?e.jsx(Y,{className:"w-10 pr-2 text-right",children:M}):null]},i.id))}),e.jsx(Ce,{children:$.getRowModel().rows.length?$.getRowModel().rows.map(i=>e.jsxs(B,{children:[i.getVisibleCells().map(r=>e.jsx(K,{className:r.column.columnDef.meta?.align==="right"?"whitespace-nowrap text-right":"",children:J(r.column.columnDef.cell,r.getContext())},r.id)),M?e.jsx(K,{}):null]},i.id)):e.jsx(B,{children:e.jsx(K,{colSpan:X.length+(M?1:0),className:"h-24 text-center",children:"No results found."})})})]})}),de&&e.jsxs("div",{className:"mt-4 flex flex-col gap-2 text-sm text-muted-foreground sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:["Showing ",t.length," of ",L," ",z.toLowerCase()]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{children:["Page ",k+1," of ",Math.max(1,Math.ceil(L/R))]}),e.jsx(P,{variant:"outline",size:"sm",onClick:ie,disabled:k===0,children:"Previous"}),e.jsx(P,{variant:"outline",size:"sm",onClick:ce,disabled:!O,children:"Next"})]})]})]})}const He=720;function We(){return e.jsxs("div",{className:"space-y-4","aria-label":"Loading entities",role:"status",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(E,{className:"h-9 max-w-sm flex-1"}),e.jsx(E,{className:"h-9 w-28"})]}),e.jsxs("div",{className:"overflow-hidden rounded-lg border",children:[e.jsx("div",{className:"border-b px-4 py-3",children:e.jsx(E,{className:"h-3 w-1/3"})}),e.jsx("div",{className:"divide-y",children:Array.from({length:5},(t,s)=>e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3",children:[e.jsx(E,{className:"h-3 flex-1"}),e.jsx(E,{className:"h-3 w-16 shrink-0"})]},s))})]})]})}function et({title:t,actions:s,controls:n,table:a,children:l,loading:o=!1,error:c=null,onRetry:h,empty:j=e.jsx("p",{className:"py-12 text-center text-sm text-muted-foreground",children:"No records."})}){return e.jsxs("div",{className:"@container space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[typeof t=="string"?e.jsx("h2",{className:"text-lg font-semibold",children:t}):t,s]}),e.jsxs("div",{children:[n,o?e.jsx(We,{}):c!==null?e.jsxs("div",{role:"alert",className:"rounded-lg border border-destructive/30 bg-destructive/5 px-4 py-6 text-sm text-destructive",children:[c,h?e.jsx(P,{className:"ml-3",variant:"outline",size:"sm",onClick:h,children:"Retry"}):null]}):l!==void 0?l:a?e.jsx(Ve,{...a}):j]})]})}function De(t,s){return s?.properties?ne(s.properties).map(([n,a])=>({key:n,prop:a})):Object.keys(t.metadata??{}).map(n=>({key:n,prop:{}}))}function Ze({entity:t,schema:s,icon:n}){return e.jsxs(e.Fragment,{children:[e.jsx(le,{metadata:t.metadata,metadataSchema:s?{...s}:void 0,name:t.name,typeIcon:n,className:"h-6 w-6 shrink-0"}),e.jsx("h2",{className:"truncate text-lg font-semibold leading-tight",children:t.name})]})}function Ge({entity:t,schema:s}){const n=_e(s?{...s}:void 0).filter(({key:a,prop:l})=>l["x-table-column"]===!0&&!l["x-image"]&&t.metadata?.[a]!==void 0&&t.metadata[a]!==null&&t.metadata[a]!=="");return n.length?e.jsx("p",{"data-testid":"record-summary",className:"-mt-2 truncate text-sm text-muted-foreground tabular-nums",children:n.map(({key:a,prop:l},o)=>e.jsxs("span",{children:[o>0?" · ":null,e.jsx(V,{value:t.metadata?.[a],prop:l})]},a))}):null}function Qe({details:t,summary:s,children:n,rootRef:a,narrow:l}){return e.jsx("div",{ref:a,className:"min-w-0 space-y-4",children:l?e.jsxs(e.Fragment,{children:[s,e.jsx("section",{"aria-label":"Details","data-testid":"record-details",children:t}),n]}):e.jsxs("div",{className:"grid grid-cols-[18rem_minmax(0,1fr)] gap-6",children:[e.jsx("aside",{className:"sticky top-12 max-h-[calc(100dvh-7rem)] min-w-0 self-start overflow-y-auto overscroll-contain pr-2 pb-16",children:t}),n]})})}function tt({entity:t,owner:s,schema:n,title:a,actions:l,details:o,summary:c,children:h,layout:j="record"}){const y=x.useRef(null),v=ve(y,He),N=e.jsxs(e.Fragment,{children:[e.jsxs("div",{"data-testid":"record-header",className:"sticky top-0 z-30 -mx-4 flex h-12 items-center justify-between gap-3 bg-background px-4 lg:-mx-6 lg:px-6",children:[e.jsx("div",{className:"flex min-w-0 items-center gap-2",children:a===void 0?e.jsx(Ze,{entity:t,schema:n}):a}),l]}),j==="content"?h:e.jsx(Qe,{rootRef:y,narrow:v,details:o===void 0?e.jsx(we,{fields:De(t,n),values:t.metadata??{},context:{ownerSlug:s}}):o,summary:c===void 0?e.jsx(Ge,{entity:t,schema:n}):c,children:h})]});return j==="content"?N:e.jsx("div",{className:"mx-auto flex min-h-0 w-full max-w-7xl flex-1 flex-col gap-4 px-4 pt-2.5 pb-8 lg:px-6",children:N})}export{le as E,He as N,Me as S,Ve as a,et as b,We as c,tt as d,se as e,Qe as f,Ge as g,Ze as h};
|
|
2
|
-
//# sourceMappingURL=entity-pages-DxgbjLMt.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as e,v as $,fp as me,g6 as xe,fs as Y,bO as ae,r as x,fq as he,fr as pe,dT as ge,dV as fe,B as f,d6 as V,dU as je,H as C,bl as q,bm as P,bn as M,bo as L,bp as R,I as O,ab as ve,g7 as Ne,g8 as ye,V as K,ev as be,X as W,cI as ne,C as re,$ as we,bc as le,g9 as ie,ga as Se,W as oe,gb as Ce,fX as ke,c2 as Ee,c3 as X,c7 as _e,eL as Re,bP as Oe,gc as Te,gd as De,i as G,L as Ae}from"./index-BjcZVe7n.js";import{C as Fe}from"./change-summary-DeuXQEpb.js";import{J as U,C as ce}from"./json-diff-DtZtra_g.js";function ze({entry:s}){return e.jsxs("div",{className:"relative pl-6 pb-6 last:pb-0",children:[e.jsx("div",{className:"absolute left-0 top-1.5 h-3 w-3 rounded-full border-2 border-border bg-background"}),e.jsx("div",{className:"absolute left-[5px] top-5 bottom-0 w-px bg-border last:hidden"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(Fe,{operation:s.action,actor:s.actor,createdAt:s.created_at}),s.action==="update"&&e.jsx(U,{before:s.before_payload,after:s.after_payload}),s.action==="create"&&s.after_payload&&e.jsx(U,{before:null,after:s.after_payload}),s.action==="delete"&&s.before_payload&&e.jsx(U,{before:s.before_payload,after:null})]})]})}function qe({entityType:s}){const{orgContext:a}=$(),{data:c,isLoading:n}=me(a),{data:r}=xe(a),t=(c||[]).filter(m=>m.status==="active"),i=t.filter(m=>!m.organization_slug||m.organization_slug===a?.slug),o=i.filter(m=>m.purpose!==Y),d=i.filter(m=>m.purpose===Y),h=t.filter(m=>m.organization_slug&&m.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(ae,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]}),d.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Managed by access control"}),e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:d,allEntityTypes:r||[],readOnly:!0})]}),h.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"From public catalogs"}),e.jsx(B,{entityTypeSlug:s.slug,relationshipTypes:h,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Le,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]})]})})}function B({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Pe,{relationshipType:r,entityTypeSlug:s,allEntityTypes:c,readOnly:n},r.id))})}function Pe({relationshipType:s,entityTypeSlug:a,allEntityTypes:c,readOnly:n=!1}){const{orgContext:r}=$(),{data:t}=Ne(s.slug,r),i=ye(),o=(t||[]).filter(h=>h.source_entity_type_slug===a||h.target_entity_type_slug===a);if(o.length===0)return null;const d=new Map(c.map(h=>[h.slug,h.name]));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:s.slug}),s.is_symmetric&&e.jsx(K,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx(K,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),o.map(h=>e.jsx(Me,{rule:h,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(h.id),isRemoving:i.isPending,readOnly:n},h.id))]})}function Me({rule:s,entityTypeSlug:a,entityTypeNameMap:c,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,o]=x.useState(!1),d=s.source_entity_type_slug===a,h=d?s.target_entity_type_slug:s.source_entity_type_slug,m=c.get(h)||h;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-3 rounded-md border border-border bg-muted/30 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:d?"this":m}),e.jsx(be,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?m:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(f,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>o(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>o(!0),disabled:r,children:e.jsx(W,{className:"h-3 w-3"})})})]})}function Le({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c}){const{orgContext:n}=$(),r=c.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=x.useState(!1),[o,d]=x.useState("existing"),[h,m]=x.useState(""),[S,N]=x.useState(""),[y,b]=x.useState("source"),[g,j]=x.useState(""),[k,E]=x.useState(""),[D,w]=x.useState(!1),[A,_]=x.useState(null),u=he(),p=pe(),v=()=>{d("existing"),m(""),N(""),b("source"),j(""),E(""),w(!1),_(null)},T=l=>{i(l),l||v()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),J=async()=>{_(null);try{let l=h;if(o==="new"){if(!g.trim()){_("Name is required");return}const H=k.trim()||F(g);if(!H){_("Slug is required");return}l=(await u.mutateAsync({slug:H,name:g.trim(),is_symmetric:D})).relationship_type.slug}if(!l){_("Select a relationship type");return}if(!S){_("Select a target entity type");return}const I=y==="source"?s:S,ue=y==="source"?S:s;await p.mutateAsync({slug:l,source_entity_type_slug:I,target_entity_type_slug:ue}),T(!1)}catch(l){_(l instanceof Error?l.message:"An error occurred")}},z=u.isPending||p.isPending;return e.jsxs(ge,{open:t,onOpenChange:T,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(V,{className:"h-3.5 w-3.5 mr-1.5"}),"Add Relationship Rule"]})}),e.jsx(je,{className:"w-80 p-4",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(f,{variant:o==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(f,{variant:o==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),o==="existing"?e.jsxs(q,{value:h,onValueChange:m,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select relationship type..."})}),e.jsxs(L,{children:[a.map(l=>e.jsx(R,{value:l.slug,children:l.name},l.slug)),a.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No relationship types yet. Create one."})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(O,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:g,onChange:l=>{j(l.target.value),k||E("")}}),e.jsx(O,{placeholder:g?F(g)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:k,onChange:l=>E(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>w(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:y,onValueChange:l=>b(l),children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"source",children:"This type → other"}),e.jsx(R,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(C,{className:"text-xs",children:[y==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:S,onValueChange:N,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select entity type..."})}),e.jsx(L,{children:r.map(l=>e.jsxs(R,{value:l.slug,children:[l.icon?`${l.icon} `:"",l.name]},l.slug))})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),e.jsx(f,{size:"sm",className:"w-full",onClick:J,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ie({options:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const i=c.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((o,d)=>d!==i))};return e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((i,o)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-sm px-2 py-0.5 rounded",children:[i,e.jsx("button",{type:"button",onClick:()=>t(o),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(O,{value:c,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(V,{className:"h-3 w-3"})})]})]})}const Ve=[{value:"string",label:"Text"},{value:"number",label:"Number"},{value:"integer",label:"Whole number"},{value:"boolean",label:"Yes/No"},{value:"enum",label:"Choice"}];function Je({examples:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const t=c.trim();t&&!s.includes(t)&&(a([...s,t]),n(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((t,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-xs px-2 py-0.5 rounded",children:[t,e.jsx("button",{type:"button",onClick:()=>a(s.filter((o,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(W,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(O,{value:c,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(V,{className:"h-3 w-3"})})]})]})}function Ue({field:s,onChange:a,onDelete:c}){const[n,r]=x.useState(!!(s.description||s.default||s.role||s.examples&&s.examples.length>0));return e.jsxs("div",{className:"rounded-md border border-border p-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>r(!n),className:"text-muted-foreground hover:text-foreground shrink-0",children:n?e.jsx(ne,{className:"h-3.5 w-3.5"}):e.jsx(re,{className:"h-3.5 w-3.5"})}),e.jsx(O,{value:s.name,onChange:t=>a({...s,name:t.target.value}),placeholder:"Field name",className:"h-8 flex-1"}),e.jsxs(q,{value:s.type,onValueChange:t=>a({...s,type:t,enumOptions:t==="enum"?s.enumOptions||[]:void 0,role:t==="enum"||s.role!=="workflowState"?s.role:void 0}),children:[e.jsx(P,{className:"h-8 w-32",children:e.jsx(M,{})}),e.jsx(L,{children:Ve.map(t=>e.jsx(R,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground whitespace-nowrap",children:[e.jsx(we,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:c,children:e.jsx(le,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Ie,{options:s.enumOptions||[],onChange:t=>a({...s,enumOptions:t})})}),n&&e.jsxs("div",{className:"pl-6 space-y-2 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Description"}),e.jsx(O,{value:s.description||"",onChange:t=>a({...s,description:t.target.value||void 0}),placeholder:"Field description",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default"}),e.jsx(O,{value:s.default||"",onChange:t=>a({...s,default:t.target.value||void 0}),placeholder:s.type==="boolean"?"true / false":"Default value",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"View role"}),e.jsxs(q,{value:s.role||"none",onValueChange:t=>a({...s,role:t==="workflowState"||t==="sortRank"?t:void 0}),children:[e.jsx(P,{className:"h-7 text-xs mt-0.5",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"none",children:"None"}),e.jsx(R,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(R,{value:"sortRank",children:"Sort rank"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Examples"}),e.jsx("div",{className:"mt-0.5",children:e.jsx(Je,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function Q({value:s,onChange:a,readonly:c,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{value:s,onChange:a,readonly:c,placeholder:'{ "type": "object", "properties": {} }',minHeight:"200px"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n})]})}function Z(s){if(s.type!=="object")return!1;const a=s.properties;if(!a||typeof a!="object")return Object.keys(s).length<=1;for(const c of Object.values(a)){if(!c||typeof c!="object")return!1;const n=c,r=n.type;if(!n.enum&&(!r||!["string","number","integer","boolean"].includes(r)||n.properties||n.items||n.allOf||n.oneOf||n.anyOf))return!1}return!0}function de(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`field-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ee(s){const a=s.properties||{},c=s.required||[];return Object.entries(a).map(([n,r])=>{const t=r["x-lobu"]?.role||r["x-lobu-role"],i=t==="workflowState"?"workflowState":t==="sortRank"?"sortRank":void 0,o={id:de(),name:n,required:c.includes(n),description:r.description||void 0,default:r.default!==void 0?String(r.default):void 0,examples:Array.isArray(r.examples)?r.examples.map(String):void 0,role:i};return r.enum?{...o,type:"enum",enumOptions:r.enum||[]}:{...o,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const c=Number(s);return Number.isNaN(c)?s:c}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function Be(s,a="auto"){const c={},n=[];for(const t of s){if(!t.name.trim())continue;const i={};t.type==="enum"?i.enum=t.enumOptions||[]:i.type=t.type,t.description?.trim()&&(i.description=t.description.trim()),t.default!==void 0&&t.default!==""&&(i.default=se(t.default,t.type)),t.examples&&t.examples.length>0&&(i.examples=t.examples.map(o=>se(o,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(o=>({value:o,label:o.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(o.toLowerCase())}))}:{}}),c[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:c};return n.length>0&&(r.required=n),a&&a!=="auto"&&(r["x-lobu"]={defaultView:a}),r}function te(s){const a=s["x-lobu"]?.defaultView;return a==="table"||a==="board"?a:"auto"}function $e({value:s,onChange:a,readonly:c=!1}){const[n,r]=x.useState("visual"),[t,i]=x.useState([]),[o,d]=x.useState("auto"),[h,m]=x.useState(""),[S,N]=x.useState(null),[y,b]=x.useState(!1),g=x.useRef(!1);x.useEffect(()=>{if(g.current){g.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),m(""),b(!1);return}const u=JSON.stringify(s,null,2);m(u),d(te(s)),Z(s)?(i(ee(s)),b(!1)):(b(!0),r("json"))},[s]);const j=x.useCallback((u,p)=>{g.current=!0;const v=Be(u,p),T=u.some(F=>F.name.trim());m(T?JSON.stringify(v,null,2):""),a(T?v:void 0)},[a]),k=x.useCallback(u=>{i(u),j(u,o)},[j,o]),E=x.useCallback(u=>{d(u),j(t,u)},[j,t]),D=x.useCallback(u=>{if(g.current=!0,m(u),!u.trim()){N(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(u);N(null),d(te(p)),Z(p)?(i(ee(p)),b(!1)):b(!0),a(p)}catch(p){N(p instanceof Error?p.message:"Invalid JSON")}},[a]),w=()=>{k([...t,{id:de(),name:"",type:"string",required:!1}])},A=(u,p)=>{const v=[...t];v[u]=p,k(v)},_=u=>{k(t.filter((p,v)=>v!==u))};return c?e.jsx(Q,{value:h,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(f,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!y&&r("visual"),disabled:y,className:"h-7 text-xs",children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(f,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Se,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),y&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-amber-500/10 text-amber-600 text-xs",children:[e.jsx(oe,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:"This schema uses advanced features (nested objects, allOf, etc.) that can only be edited in JSON mode."})]}),n==="visual"?e.jsxs("div",{className:"space-y-3",children:[t.map((u,p)=>e.jsx(Ue,{field:u,onChange:v=>A(p,v),onDelete:()=>_(p)},u.id)),e.jsxs(f,{type:"button",variant:"outline",size:"sm",onClick:w,className:"w-full",children:[e.jsx(V,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(u=>u.name.trim())&&e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border p-2.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default view"}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Which view this type opens in. Auto picks from your fields (a workflow field → board, otherwise table)."})]}),e.jsxs(q,{value:o,onValueChange:u=>E(u),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(R,{value:"auto",children:"Auto"}),e.jsx(R,{value:"table",children:"Table"}),e.jsx(R,{value:"board",children:"Board"})]})]})]})]}):e.jsx(Q,{value:h,onChange:D,error:S})]})}function We(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function He({entityType:s,onCancel:a,onSaved:c}){const n=!!s,r=Ce(),t=ke(),i=s?.slug??"new",o=Ee(i,{name:s?.name??"",slug:s?.slug??"",description:s?.description??"",icon:s?.icon??"",color:s?.color??"",metadataSchema:s?.metadata_schema??void 0,backingSql:s?.backing_sql??""}),[d,h]=o.field("name"),[m,S]=o.field("slug"),[N,y]=o.field("description"),[b,g]=o.field("icon"),[j,k]=o.field("color"),[E,D]=o.field("metadataSchema"),[w,A]=o.field("backingSql"),[_,u]=X(i,n),[p,v]=X(i,null),T=w.trim().length>0,F=l=>{h(l),!n&&!_&&S(We(l))},J=async()=>{if(!o.canSubmit)return;if(v(null),!d.trim()){v("Name is required");return}if(!n&&!m.trim()){v("Slug is required");return}const l=T?{sql:w.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:T?void 0:E,backing:l}):await r.mutateAsync({slug:m.trim(),name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:T?void 0:E,backing:l}),c()}catch(I){v(I instanceof Error?I.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(_e,{visible:o.hasConflict,onReload:o.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-name",children:"Name"}),e.jsx(O,{id:"et-name",value:d,onChange:l=>F(l.target.value),placeholder:"e.g. Product"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-slug",children:"Slug"}),e.jsx(O,{id:"et-slug",value:m,onChange:l=>{u(!0),S(l.target.value)},placeholder:"e.g. topic",disabled:n}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Slug cannot be changed after creation."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-desc",children:"Description"}),e.jsx(Re,{id:"et-desc",value:N,onChange:l=>y(l.target.value),placeholder:"Optional description...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(O,{id:"et-icon",value:b,onChange:l=>g(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{id:"et-color",value:j,onChange:l=>k(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),j&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:j}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Backing query (SQL)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. A read-only SELECT turns this into a derived (view) type — rows are computed from the query, not stored. Leave empty for a normal stored type. Table references are auto-scoped to your organization."}),e.jsx(ce,{value:w,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),T?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground",children:[e.jsx(ie,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Derived view — columns are computed from the query, so there's no stored-row schema to define."})]}),s?.measure_columns&&s.measure_columns.length>0&&e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(C,{children:"Measure columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.measure_columns.map(l=>e.jsx("span",{className:"rounded-md border border-border bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:l},l))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Metadata Schema"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define the structure of metadata fields for entities of this type."}),e.jsx($e,{value:E,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(qe,{entityType:s})]}),p&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:p}),e.jsx(Oe,{onCancel:a,cancelDisabled:z,className:"pt-2",children:e.jsx(f,{onClick:J,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function Qe({entityType:s,onClose:a,orgContext:c,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,o]=x.useState(!1),[d,h]=x.useState(!1),[m,S]=x.useState(null),N=Te(),{data:y,isLoading:b}=De(i&&s?s.slug:null,c),g=s?.entity_count??0,j=g>0,k=async()=>{if(s){S(null);try{await N.mutateAsync(s.slug),a()}catch(w){S(w instanceof Error?w.message:"Failed to delete")}}},E=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",D=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:G("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsx("h1",{className:G("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:E}),e.jsx("p",{className:"text-sm text-muted-foreground",children:D})]}),e.jsx("div",{className:"py-4",children:e.jsx(He,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-t border-border pt-4 space-y-3",children:[c.slug&&s?e.jsx(Ae,{to:"/$owner/events",params:{owner:c.slug},search:{semantic_types:"change",event_category:"config",resource_kind:"entity-type",resource_id:s.slug},className:"text-sm text-primary underline underline-offset-4",children:"View configuration history in Events"}):null,e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors w-full",children:[i?e.jsx(ne,{className:"h-4 w-4"}):e.jsx(re,{className:"h-4 w-4"}),"Schema audit records"]}),i&&e.jsx("div",{className:"mt-3",children:b?e.jsx(ae,{label:"history",variant:"rows",rows:4}):y&&y.length>0?e.jsx("div",{className:"relative ml-1.5",children:y.map(w=>e.jsx(ze,{entry:w},w.id))}):e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No audit history found."})})]}),!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:d?e.jsxs("div",{className:"space-y-3",children:[j?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(oe,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Cannot delete this entity type"}),e.jsxs("p",{className:"mt-1 text-amber-600/80",children:["There ",g===1?"is":"are"," ",g," entit",g===1?"y":"ies",' of type "',s.name,'". Migrate or delete them first.']})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:['Are you sure you want to delete "',s.name,'"? This action will soft-delete the entity type. It can be restored by a database administrator.']}),m&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{h(!1),S(null)},children:"Cancel"}),e.jsx(f,{variant:"destructive",size:"sm",onClick:k,disabled:j||N.isPending,children:N.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(f,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>h(!0),children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}export{Qe as E};
|
|
2
|
-
//# sourceMappingURL=entity-type-page-D0ghgRgq.js.map
|