@lobu/runtime-server 21.1.0 → 21.2.1
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 +2 -35
- package/dist/component.json +1 -1
- package/dist/connectors/README.md +6 -3
- package/dist/connectors/github.ts +0 -6
- package/dist/connectors/google_calendar.ts +0 -4
- package/dist/connectors/google_drive.ts +0 -2
- package/dist/connectors/google_gmail.ts +0 -6
- package/dist/connectors/market_quotes.ts +0 -1
- package/dist/connectors/microsoft_outlook.ts +0 -2
- package/dist/connectors/postgres.ts +68 -3
- package/dist/connectors/whatsapp_web.ts +2 -8
- package/dist/connectors/x.ts +3 -9
- package/dist/connectors/youtube.ts +0 -5
- package/dist/db/migrations/20260930010000_connector_policy_scopes.sql +113 -0
- package/dist/db/migrations/20261002230000_connector_exact_policy_target.sql +36 -0
- package/dist/db/migrations/20261003120000_source_backed_entity_identity.sql +109 -0
- package/dist/db/migrations/20261003200000_drop_source_backed_entity_identity.sql +111 -0
- package/dist/db/migrations/preconditions/20261002230000_connector_exact_policy_target.sql +38 -0
- package/dist/db/migrations/preconditions/20261003200000_drop_source_backed_entity_identity.sql +21 -0
- package/dist/dependencies.bun.lock +52 -54
- package/dist/owletto/dist/assets/_-CLhipgJI.js +1 -0
- package/dist/owletto/dist/assets/_-D0ZVGAIA.js +2 -0
- package/dist/owletto/dist/assets/_agentId-BLXUf3ot.js +1 -0
- package/dist/owletto/dist/assets/_agentId-DnI66MF3.js +1 -0
- package/dist/owletto/dist/assets/_automationId-ziwseLb7.js +1 -0
- package/dist/owletto/dist/assets/_connectorKey._connectionId-B6V3ySFK.js +1 -0
- package/dist/owletto/dist/assets/_connectorKey.index-CR5u_dtt.js +1 -0
- package/dist/owletto/dist/assets/{_conversationId-CpuEvflw.js → _conversationId-FBMYmOl8.js} +1 -1
- package/dist/owletto/dist/assets/{_deploymentId-BL9tnDFl.js → _deploymentId-DNTXbT_m.js} +1 -1
- package/dist/owletto/dist/assets/_name-B37LKIxH.js +1 -0
- package/dist/owletto/dist/assets/_owner-BxYumqC2.js +1 -0
- package/dist/owletto/dist/assets/_shape-Bxz-04jR.js +1 -0
- package/dist/owletto/dist/assets/_skillKey-D5MFbiw2.js +1 -0
- package/dist/owletto/dist/assets/_slug-Dlhit09k.js +1 -0
- package/dist/owletto/dist/assets/_viewKey-C6535i-t.js +1 -0
- package/dist/owletto/dist/assets/_viewKey-CQCtY3Y8.js +1 -0
- package/dist/owletto/dist/assets/_viewKey-CxKfKbRa.js +1 -0
- package/dist/owletto/dist/assets/accept-invitation-BQQwec3R.js +1 -0
- package/dist/owletto/dist/assets/activity-route-view-BwThvdGs.js +1 -0
- package/dist/owletto/dist/assets/{agent-card-controls-bhTMPoVi.js → agent-card-controls-B3RhzsPz.js} +1 -1
- package/dist/owletto/dist/assets/{agent-client-setup-list-BBbq_2B1.js → agent-client-setup-list-BFtgRwe8.js} +1 -1
- package/dist/owletto/dist/assets/agent-connect-pages-BO4wQn4L.js +1 -0
- package/dist/owletto/dist/assets/agent-editor-form-BYC4uSNz.js +1 -0
- package/dist/owletto/dist/assets/agent-guardrails-route-Dp02G1AQ.js +1 -0
- package/dist/owletto/dist/assets/{agent-loading-shells-BQLjzMPy.js → agent-loading-shells-OagauQzV.js} +1 -1
- package/dist/owletto/dist/assets/agent-permissions-matrix-B9Ho3P1t.js +1 -0
- package/dist/owletto/dist/assets/{agent-skill-context-s42Q4Wjo.js → agent-skill-context-BAr2Dw3F.js} +1 -1
- package/dist/owletto/dist/assets/agent-skills-route-B4VUnVi0.js +1 -0
- package/dist/owletto/dist/assets/agent-subpage-shell-Dz8I-GUt.js +1 -0
- package/dist/owletto/dist/assets/agent-thread-B9-cdkaV.js +8 -0
- package/dist/owletto/dist/assets/agents-D0CIg4b9.js +1 -0
- package/dist/owletto/dist/assets/agents-workbench-C2sr5h82.js +1 -0
- package/dist/owletto/dist/assets/{app._appId-CqYz3AOO.js → app._appId-DLsJ_QWS.js} +1 -1
- package/dist/owletto/dist/assets/automation-detail-content-9Rjb_I9j.js +1 -0
- package/dist/owletto/dist/assets/automations-D0CIg4b9.js +1 -0
- package/dist/owletto/dist/assets/{calendar-CHXehtu0.js → calendar-DAiyi1ZL.js} +1 -1
- package/dist/owletto/dist/assets/callback-CaRe2TOT.js +1 -0
- package/dist/owletto/dist/assets/{card-4Ull9W6d.js → card-CMmh2mzo.js} +1 -1
- package/dist/owletto/dist/assets/{claim-BGLCPLXq.js → claim-CYHnUF7G.js} +1 -1
- package/dist/owletto/dist/assets/{clients-C7ubnFsS.js → clients-Cp1BJ28u.js} +1 -1
- package/dist/owletto/dist/assets/{code-editor-BHiWR94J.js → code-editor-CYsR2VBP.js} +1 -1
- package/dist/owletto/dist/assets/connect-CZip2g_B.js +1 -0
- package/dist/owletto/dist/assets/connect._clientId-CEKY8Dnv.js +1 -0
- package/dist/owletto/dist/assets/connected._clientId-C5xRjxNO.js +1 -0
- package/dist/owletto/dist/assets/connection-C06HZ241.js +1 -0
- package/dist/owletto/dist/assets/connection-feed-detail-D1whY5hL.js +1 -0
- package/dist/owletto/dist/assets/{connector-provenance-DRdUEmQ1.js → connector-provenance-BjKiUhYE.js} +1 -1
- package/dist/owletto/dist/assets/connectors-Baejya0T.js +1 -0
- package/dist/owletto/dist/assets/{consent-fmhPPlpi.js → consent-CfYDldcF.js} +1 -1
- package/dist/owletto/dist/assets/{core.esm-C-eNiUAl.js → core.esm-QA7BQgiK.js} +1 -1
- package/dist/owletto/dist/assets/create-C3P-3_8O.js +1 -0
- package/dist/owletto/dist/assets/create-CwnrPUEw.js +1 -0
- package/dist/owletto/dist/assets/create-DOScS9Gl.js +1 -0
- package/dist/owletto/dist/assets/create-automation-form-CuxiIRCF.js +2 -0
- package/dist/owletto/dist/assets/{create._connectorKey-CHAotlsF.js → create._connectorKey-Bjv3lCf8.js} +1 -1
- package/dist/owletto/dist/assets/{cronstrue-C5yTgk5z.js → cronstrue-2GHCtD7h.js} +1 -1
- package/dist/owletto/dist/assets/{deployments-D1gbQwsy.js → deployments-ByBv1DW-.js} +1 -1
- package/dist/owletto/dist/assets/deployments-C-_ECORv.js +1 -0
- package/dist/owletto/dist/assets/{deployments-body-DycIGlnL.js → deployments-body-Bm2upStd.js} +1 -1
- package/dist/owletto/dist/assets/{device-DyPnQkhO.js → device-B0i7Xp8y.js} +1 -1
- package/dist/owletto/dist/assets/device-pin-tombstone-Bd6vS2zu.js +1 -0
- package/dist/owletto/dist/assets/device-rows-Bwf8qDte.js +1 -0
- package/dist/owletto/dist/assets/device._deviceId-DJLAesm3.js +1 -0
- package/dist/owletto/dist/assets/entity-options-CrbS6K-i.js +1 -0
- package/dist/owletto/dist/assets/entity-page-ijZe_1-6.js +1 -0
- package/dist/owletto/dist/assets/entity-type-page-onp2Tk_E.js +1 -0
- package/dist/owletto/dist/assets/event-page-C0B2UDY-.js +1 -0
- package/dist/owletto/dist/assets/events-feed-DK35T4g7.js +1 -0
- package/dist/owletto/dist/assets/{full-page-spinner-DsU-Cb3L.js → full-page-spinner-Dd8eEaxq.js} +1 -1
- package/dist/owletto/dist/assets/guardrails-DKO8_J-G.js +1 -0
- package/dist/owletto/dist/assets/identity-CKM54vrM.js +1 -0
- package/dist/owletto/dist/assets/index--VmN5WxW.js +1 -0
- package/dist/owletto/dist/assets/{index-DtRfQcRH.js → index-B2AmRqYh.js} +1595 -1595
- package/dist/owletto/dist/assets/{index-DwtfHCHB.js → index-B_rcEgFX.js} +1 -1
- package/dist/owletto/dist/assets/index-BmAuAhub.css +1 -0
- package/dist/owletto/dist/assets/index-BmhGe6-Z.js +1 -0
- package/dist/owletto/dist/assets/index-C1dJSGrL.js +1 -0
- package/dist/owletto/dist/assets/index-CAFw4qCb.js +1 -0
- package/dist/owletto/dist/assets/{index-1YrrvVJ4.js → index-CCcc_xBw.js} +8 -8
- package/dist/owletto/dist/assets/index-CLU3gXVm.js +1 -0
- package/dist/owletto/dist/assets/{index-D2dcENg2.js → index-Cf0GJoiG.js} +1 -1
- package/dist/owletto/dist/assets/index-CqQVnAY-.js +1 -0
- package/dist/owletto/dist/assets/{index-nOYvNROJ.js → index-CxT0uyIe.js} +1 -1
- package/dist/owletto/dist/assets/index-DR08e6Ec.js +1 -0
- package/dist/owletto/dist/assets/index-DYb9L5FC.js +1 -0
- package/dist/owletto/dist/assets/{index-CpWKAAGX.js → index-DlepU3cY.js} +1 -1
- package/dist/owletto/dist/assets/index-SUUcQGT-.js +1 -0
- package/dist/owletto/dist/assets/index-SdiFOfR1.js +1 -0
- package/dist/owletto/dist/assets/index-zcfi5r1l.js +1 -0
- package/dist/owletto/dist/assets/{json-diff-DYeX-xLk.js → json-diff-ClBBYBQD.js} +3 -3
- package/dist/owletto/dist/assets/{list-skeleton-s4GPSJ8J.js → list-skeleton-BtWn2eo2.js} +1 -1
- package/dist/owletto/dist/assets/login-d3PdO-qV.js +1 -0
- package/dist/owletto/dist/assets/logout-DgckxwLn.js +1 -0
- package/dist/owletto/dist/assets/member-scope-gate-DXOCfx-v.js +1 -0
- package/dist/owletto/dist/assets/{memory-browse-page-Bibfs2sK.js → memory-browse-page-CeAnKoTR.js} +1 -1
- package/dist/owletto/dist/assets/{missing-view-CD4DOaG8.js → missing-view-DrZ8m8yo.js} +1 -1
- package/dist/owletto/dist/assets/{model-selector-XC5CI2Et.js → model-selector-CapL1ARf.js} +1 -1
- package/dist/owletto/dist/assets/models-CB8mhq7j.js +1 -0
- package/dist/owletto/dist/assets/new-BBUb-VR4.js +1 -0
- package/dist/owletto/dist/assets/new-CBLJ25_w.js +1 -0
- package/dist/owletto/dist/assets/new-tTXB4qBW.js +1 -0
- package/dist/owletto/dist/assets/{oauth-workspace-access-D6epOq0R.js → oauth-workspace-access-DearynqZ.js} +1 -1
- package/dist/owletto/dist/assets/organization-BgdBg-PJ.js +1 -0
- package/dist/owletto/dist/assets/{permissions-D8uJHINS.js → permissions-h_qSft1A.js} +1 -1
- package/dist/owletto/dist/assets/{proposal-review-shell-C3K-JXjb.js → proposal-review-shell-D4YNrrye.js} +1 -1
- package/dist/owletto/dist/assets/{recent-CFcWceBl.js → recent-JiBNvZzD.js} +1 -1
- package/dist/owletto/dist/assets/{renderer-1nRJFMGx.js → renderer-DgPLyEbx.js} +1 -1
- package/dist/owletto/dist/assets/{reset-password-9RTWhBEb.js → reset-password-B8tWPtIj.js} +1 -1
- package/dist/owletto/dist/assets/runs-oHveuEUB.js +1 -0
- package/dist/owletto/dist/assets/{runs-panel-B2852xus.js → runs-panel-C56GDaJm.js} +1 -1
- package/dist/owletto/dist/assets/runs-table-BUKDjiBc.js +1 -0
- package/dist/owletto/dist/assets/{schema-value-normalization-BspxVEGy.js → schema-value-normalization-3JuM_r1H.js} +1 -1
- package/dist/owletto/dist/assets/settings-DaKg6U5O.js +1 -0
- package/dist/owletto/dist/assets/{settings-9lDASETT.js → settings-DhnRi2nq.js} +1 -1
- package/dist/owletto/dist/assets/skills-BpQncuMC.js +1 -0
- package/dist/owletto/dist/assets/{switch-CxDXvPGE.js → switch-BQ40_DMb.js} +1 -1
- package/dist/owletto/dist/assets/{use-applied-views-DvMT3wap.js → use-applied-views-B-Z-Weji.js} +1 -1
- package/dist/owletto/dist/assets/{use-mention-search-CeTEE3oE.js → use-mention-search-B4DfZFm5.js} +1 -1
- package/dist/owletto/dist/assets/{view-frame-HoBawpT2.js → view-frame-C7ciEoLo.js} +1 -1
- package/dist/owletto/dist/index.html +2 -2
- package/dist/server-main.bundle.mjs +7827 -7972
- package/npm-shrinkwrap.json +198 -207
- package/package.json +1 -1
- package/vendor/connector-sdk/dist/connector-runtime.d.ts +1 -1
- package/vendor/connector-sdk/dist/connector-runtime.js +1 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +14 -2
- package/vendor/connector-sdk/dist/define-connector.d.ts +3 -5
- package/vendor/connector-sdk/dist/define-connector.js +1 -1
- package/vendor/connector-sdk/dist/device-manifest.d.ts +0 -1
- package/vendor/connector-sdk/dist/extension-network.js +1 -2
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/core/dist/contracts/agent-settings.d.ts +0 -1
- package/vendor/core/dist/contracts/agent-settings.js +0 -1
- package/vendor/core/dist/contracts/tools/manage-classifiers.d.ts +6 -6
- package/vendor/core/dist/contracts/tools/manage-classifiers.js +4 -6
- package/vendor/core/dist/contracts/tools/manage-connections.d.ts +0 -1
- package/vendor/core/dist/contracts/tools/manage-connections.js +3 -4
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +2 -2
- package/vendor/core/dist/contracts/tools/manage-entity.js +4 -2
- package/vendor/core/dist/logger.js +13 -2
- package/vendor/core/dist/worker/wire.d.ts +1 -6
- package/vendor/core/dist/worker/wire.js +1 -1
- package/vendor/core/package.json +1 -1
- package/vendor/views/dist/api.d.ts +42 -5
- package/vendor/views/dist/api.js +63 -6
- package/vendor/views/package.json +6 -1
- package/dist/owletto/dist/assets/_-00GgOtdu.js +0 -1
- package/dist/owletto/dist/assets/_-XlUwOWCI.js +0 -2
- package/dist/owletto/dist/assets/_agentId-B2DrawIk.js +0 -1
- package/dist/owletto/dist/assets/_agentId-CS0AcWH2.js +0 -1
- package/dist/owletto/dist/assets/_automationId-BLnqLtUv.js +0 -1
- package/dist/owletto/dist/assets/_connectorKey._connectionId-DcUWoZ-C.js +0 -1
- package/dist/owletto/dist/assets/_connectorKey.index-C_yKycN_.js +0 -1
- package/dist/owletto/dist/assets/_name-DlxjWkKk.js +0 -1
- package/dist/owletto/dist/assets/_owner-Cg50UU6m.js +0 -1
- package/dist/owletto/dist/assets/_shape-BWZW4mj8.js +0 -1
- package/dist/owletto/dist/assets/_skillKey-B25fO0_O.js +0 -1
- package/dist/owletto/dist/assets/_slug-DbD-wv2m.js +0 -1
- package/dist/owletto/dist/assets/_viewKey-BcTEvQ3N.js +0 -1
- package/dist/owletto/dist/assets/_viewKey-W4RjiUWL.js +0 -1
- package/dist/owletto/dist/assets/_viewKey-iGPCKSda.js +0 -1
- package/dist/owletto/dist/assets/accept-invitation-BmQKbQem.js +0 -1
- package/dist/owletto/dist/assets/activity-route-view-BvtAoGVt.js +0 -1
- package/dist/owletto/dist/assets/agent-connect-pages-DkDlFVY5.js +0 -1
- package/dist/owletto/dist/assets/agent-editor-form-DwHD9j1Y.js +0 -1
- package/dist/owletto/dist/assets/agent-guardrails-route-0PsTrqMC.js +0 -1
- package/dist/owletto/dist/assets/agent-permissions-matrix-B-Q5rmuB.js +0 -1
- package/dist/owletto/dist/assets/agent-skills-route-Cwq1QrhW.js +0 -1
- package/dist/owletto/dist/assets/agent-subpage-shell-DtzoRy6N.js +0 -1
- package/dist/owletto/dist/assets/agent-thread-D7AGGjRV.js +0 -8
- package/dist/owletto/dist/assets/agents-BqCKU4CT.js +0 -1
- package/dist/owletto/dist/assets/agents-workbench-Cl7FO7b3.js +0 -1
- package/dist/owletto/dist/assets/automation-detail-content-CKSywvzE.js +0 -1
- package/dist/owletto/dist/assets/automations-BqCKU4CT.js +0 -1
- package/dist/owletto/dist/assets/callback-DZ3YyXeV.js +0 -1
- package/dist/owletto/dist/assets/connect-BNatqg6j.js +0 -1
- package/dist/owletto/dist/assets/connect._clientId-BGG2IqiQ.js +0 -1
- package/dist/owletto/dist/assets/connected._clientId-7RU89sVW.js +0 -1
- package/dist/owletto/dist/assets/connection-CTaUGXl6.js +0 -1
- package/dist/owletto/dist/assets/connection-feed-detail-B1xieiEh.js +0 -1
- package/dist/owletto/dist/assets/connectors-NBwCLuZg.js +0 -1
- package/dist/owletto/dist/assets/create-8bBbQJGY.js +0 -1
- package/dist/owletto/dist/assets/create-Cl6cfNAp.js +0 -1
- package/dist/owletto/dist/assets/create-DrVso8O7.js +0 -1
- package/dist/owletto/dist/assets/create-automation-form-De8J-JD5.js +0 -2
- package/dist/owletto/dist/assets/deployments-C7M3fV5K.js +0 -1
- package/dist/owletto/dist/assets/device-pin-tombstone-CwJitllC.js +0 -1
- package/dist/owletto/dist/assets/device-rows-BBhW1C7Y.js +0 -1
- package/dist/owletto/dist/assets/device._deviceId-XswfXHOc.js +0 -1
- package/dist/owletto/dist/assets/entity-options-utGBmFX0.js +0 -1
- package/dist/owletto/dist/assets/entity-page-BxwuqqWk.js +0 -1
- package/dist/owletto/dist/assets/entity-type-page-BrWqk6so.js +0 -1
- package/dist/owletto/dist/assets/event-page-LIm4EDmJ.js +0 -1
- package/dist/owletto/dist/assets/events-feed-C4L8mQV7.js +0 -1
- package/dist/owletto/dist/assets/guardrails-CGFWCfbQ.js +0 -1
- package/dist/owletto/dist/assets/identity-uPYpPogR.js +0 -1
- package/dist/owletto/dist/assets/index-BKMafTe4.js +0 -1
- package/dist/owletto/dist/assets/index-BsL1-C2-.js +0 -1
- package/dist/owletto/dist/assets/index-C58oW727.js +0 -1
- package/dist/owletto/dist/assets/index-C8CR2-Ck.css +0 -1
- package/dist/owletto/dist/assets/index-CQ4s6nzy.js +0 -1
- package/dist/owletto/dist/assets/index-DCK0KhMM.js +0 -1
- package/dist/owletto/dist/assets/index-DXqiRON3.js +0 -1
- package/dist/owletto/dist/assets/index-DgEc5IvT.js +0 -1
- package/dist/owletto/dist/assets/index-DvhM9tuI.js +0 -1
- package/dist/owletto/dist/assets/index-DyYFZjh-.js +0 -1
- package/dist/owletto/dist/assets/index-oDoJENMF.js +0 -1
- package/dist/owletto/dist/assets/index-rPdUEOa3.js +0 -1
- package/dist/owletto/dist/assets/login-Di5VF2F_.js +0 -1
- package/dist/owletto/dist/assets/logout-BuaQGSnw.js +0 -1
- package/dist/owletto/dist/assets/member-scope-gate-CJqJZk7T.js +0 -1
- package/dist/owletto/dist/assets/models--8mTFOLz.js +0 -1
- package/dist/owletto/dist/assets/new-BzkA1sq2.js +0 -1
- package/dist/owletto/dist/assets/new-C3f0BShb.js +0 -1
- package/dist/owletto/dist/assets/new-DA5LF6iB.js +0 -1
- package/dist/owletto/dist/assets/organization-DOtBRqDQ.js +0 -1
- package/dist/owletto/dist/assets/runs-_yVh6PPB.js +0 -1
- package/dist/owletto/dist/assets/runs-table--dnFQatY.js +0 -1
- package/dist/owletto/dist/assets/settings-DQo_ZS2P.js +0 -1
- package/dist/owletto/dist/assets/skills-a5xQ4RE9.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a4 as m,j as e,al as h,B as n,ez as i}from"./index-DtRfQcRH.js";function p({owner:t,agentId:a,children:s,showBack:r,backLabel:o,backTo:x,title:c,className:u}){const d=m(),l=()=>{d({to:x,params:{owner:t,agentId:a}})};return e.jsx("div",{className:h("mx-auto w-full max-w-3xl pb-8",u),children:c?e.jsxs(e.Fragment,{children:[e.jsx(j,{title:c,onBack:l,backLabel:o}),s]}):r?e.jsx(g,{onBack:l,backLabel:o,children:s}):s})}function g({onBack:t,backLabel:a,children:s}){return e.jsxs("div",{className:"relative",children:[e.jsx(n,{type:"button",variant:"ghost",size:"icon",className:"absolute right-full top-0 mr-1 size-8 text-muted-foreground hover:text-foreground","aria-label":`Back to ${a}`,onClick:t,children:e.jsx(i,{className:"h-4 w-4"})}),s]})}function j({title:t,onBack:a,backLabel:s,action:r}){return e.jsx("div",{className:"sticky top-0 z-10 mb-2 bg-background py-2",children:e.jsxs("div",{className:"relative flex items-center justify-center gap-1",children:[e.jsx(n,{type:"button",variant:"ghost",size:"icon",className:"size-8 shrink-0 text-muted-foreground hover:text-foreground","aria-label":`Back to ${s}`,onClick:a,children:e.jsx(i,{className:"h-4 w-4"})}),e.jsx("span",{className:"truncate text-base font-semibold",children:t}),r?e.jsx("div",{className:"absolute right-0",children:r}):null]})})}function v({title:t,description:a,onBack:s,backLabel:r}){return e.jsxs("div",{className:"mb-2 space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(n,{type:"button",variant:"ghost",size:"icon",className:"size-8 shrink-0 text-muted-foreground hover:text-foreground","aria-label":`Back to ${r}`,onClick:s,children:e.jsx(i,{className:"h-4 w-4"})}),e.jsx("h1",{className:"text-xl font-semibold",children:t})]}),e.jsx("p",{className:"text-center text-sm text-muted-foreground",children:a})]})}export{p as A,v as a};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import{j as s,r as l,el as qt,as as Kt,em as Gt,dQ as Jt,ap as ze,ai as Be,aq as st,cc as Qt,en as lt,eo as Xt,L as xt,al as U,cL as Yt,cU as wt,cW as Zt,ep as en,cm as tn,cX as nn,eq as rn,B as ce,er as on,es as sn,et as We,Z as ln,s as an,cV as cn,aV as Ne,eu as un,cj as dn,ck as pn,ev as fn,cn as mn,bM as hn,ew as gn,ex as vn,e8 as yn,bJ as bn,du as xn,dv as wn}from"./index-DtRfQcRH.js";import{D as Rn,E as Sn}from"./app-bridge-BH3g2mKG.js";import{A as Tn,a as jn,b as Cn,c as Xe,d as Rt,e as Nn}from"./agent-loading-shells-BQLjzMPy.js";import{t as An}from"./pending-seed-CPbfgnLX.js";import{h as En,t as kn,R as _n,i as In,u as On,b as Pn,f as Ln}from"./use-mention-search-CeTEE3oE.js";const St=l.createContext(null);function Mn({extension:e,children:t}){return s.jsx(St.Provider,{value:e??null,children:t})}function Ye(){return l.useContext(St)}var Ze=(e=>(e.PROVIDER_QUOTA_EXHAUSTED="PROVIDER_QUOTA_EXHAUSTED",e.PROVIDER_AUTH="PROVIDER_AUTH",e.PROVIDER_UNKNOWN_MODEL="PROVIDER_UNKNOWN_MODEL",e.PROVIDER_BASE_URL_UNRESOLVED="PROVIDER_BASE_URL_UNRESOLVED",e.NO_MODEL_CONFIGURED="NO_MODEL_CONFIGURED",e.WORKER_UNRESPONSIVE="WORKER_UNRESPONSIVE",e.WORKER_DIED="WORKER_DIED",e.WORKER_STARTUP_FAILED="WORKER_STARTUP_FAILED",e.PROVIDER_TOOL_CALL_FAILED="PROVIDER_TOOL_CALL_FAILED",e.SESSION_TIMEOUT="SESSION_TIMEOUT",e))(Ze||{});const $n={PROVIDER_QUOTA_EXHAUSTED:{cta:"provider-management",ctaLabel:"Manage provider"},PROVIDER_AUTH:{cta:"provider-management",ctaLabel:"Reconnect provider"},PROVIDER_UNKNOWN_MODEL:{cta:"agent-settings",ctaLabel:"Choose model"},PROVIDER_BASE_URL_UNRESOLVED:{cta:"provider-management",ctaLabel:"Manage provider"},PROVIDER_TOOL_CALL_FAILED:{message:"The model provider rejected its own tool call and ended the turn. This is usually temporary — please try again.",cta:"none"},NO_MODEL_CONFIGURED:{message:"No model is configured for this agent. Choose a model in agent settings.",cta:"agent-settings",ctaLabel:"Choose a model"},WORKER_UNRESPONSIVE:{message:"The agent didn't finish responding in time. This is usually temporary — please try again.",cta:"none"},WORKER_DIED:{message:"The agent stopped unexpectedly before it could reply. This is usually temporary — please try again.",cta:"none"},WORKER_STARTUP_FAILED:{message:"The agent couldn't start, so your request wasn't processed. Please try again in a moment.",cta:"none"},SESSION_TIMEOUT:{cta:"none",silent:!0}};function Un(e){if(typeof e=="string")return Object.values(Ze).includes(e)?e:void 0}const Dn=Object.freeze(Object.defineProperty({__proto__:null,AGENT_ERRORS:$n,AgentErrorCode:Ze,toAgentErrorCode:Un},Symbol.toStringTag,{value:"Module"})),{AGENT_ERRORS:Fn,toAgentErrorCode:Vn}=Dn;function it(e,t){if(!t)return null;try{const n=new URL(t);return n.protocol!=="http:"&&n.protocol!=="https:"?null:new URL(e,`${n.origin}/`).toString()}catch{return null}}function Tt(e,t){const n=Vn(e);if(!n)return null;const r=Fn[n];if(r.cta==="none"||!t.workspaceSlug)return null;const o=encodeURIComponent(t.workspaceSlug);if(r.cta==="provider-connect"||r.cta==="provider-management"){const a=t.provider?`/${o}/connectors/${encodeURIComponent(`${qt}${t.provider}`)}`:`/${o}/connectors`,c=it(a,t.webOrigin);if(!c)return null;const u=new URL(c);return t.provider&&t.model&&u.searchParams.set("model",t.model),{label:r.ctaLabel??"Connect a provider",href:u.toString()}}if(!t.agentId)return null;const i=it(`/${o}/agents/${encodeURIComponent(t.agentId)}/settings`,t.webOrigin);return i?{label:r.ctaLabel??"Open settings",href:i}:null}function jt(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e.subscribable;if(!t||typeof t!="object"||Array.isArray(t))return null;const n=t;if(typeof n.connector_key!="string"||!n.connector_key||typeof n.resource_type!="string"||!n.resource_type||typeof n.resource_ref!="string"||!n.resource_ref||typeof n.label!="string"||!n.label)return null;const r=Array.isArray(n.suggested_event_keys)?n.suggested_event_keys.filter(o=>typeof o=="string"&&!!o):void 0;return{connector_key:n.connector_key,resource_type:n.resource_type,resource_ref:n.resource_ref,label:n.label,...r?.length?{suggested_event_keys:r}:{}}}const at=new Set(["localhost","127.0.0.1","::1","[::1]"]);function Bn(e){return e?.trim().toLowerCase().replace(/^\.+|\.+$/g,"")||null}function ct(e,t){const n=Bn(t);if(!n)return!1;const r=e.toLowerCase().replace(/\.$/,"");return r===n||r.endsWith(`.${n}`)}function ut(e,t,n){try{const r=new URL(t),o=new URL(e,t),i=at.has(o.hostname)&&at.has(r.hostname),a=o.protocol===r.protocol&&(o.protocol==="https:"||o.protocol==="http:")&&ct(o.hostname,n)&&ct(r.hostname,n);return o.origin!==r.origin&&(i||a)&&(o.protocol=r.protocol,o.host=r.host),o.origin===r.origin&&o.pathname.startsWith("/api/v1/agents")&&(o.pathname=`/lobu${o.pathname}`),o.toString()}catch{return e}}const Hn=/\.(png|jpe?g|gif|webp|avif|bmp|svg)$/i,Ct=new Set(["suggest_actions"]),Me="Thinking…";function zn(e){const{textOut:t,statusLine:n,errorText:r,toolCalls:o}=e,i=[];n===Me&&i.push({type:"reasoning"}),r&&i.push({type:"error",text:r});let a=t;return n&&n!==Me&&(a=t?`${t}
|
|
2
|
-
|
|
3
|
-
${n}`:n),a&&i.push({type:"text",text:a}),i.push(...o),i}const et=l.createContext(null);function Ae(){const e=l.useContext(et);if(!e)throw new Error("useLobuChat must be used within <LobuChatProvider>");return e}function $o({messages:e,children:t}){const n=l.useMemo(()=>({messages:e,running:!1,append:()=>{},cancel:()=>{},pendingAttachments:[],addAttachments:()=>{},removeAttachment:()=>{},agentId:null,conversationId:"",workspaceSlug:null,currentSuggestions:null}),[e]);return s.jsx(et.Provider,{value:n,children:t})}const Nt=/\[([^\]]*)\]\((\S*?\/api\/v1\/files\/[^)\s]+)\)/g;function dt(e){return e.replace(/<lobu_internal_context>[\s\S]*?<\/lobu_internal_context>\n*/g,"").replace(Nt,"").replace(/\n{3,}/g,`
|
|
4
|
-
|
|
5
|
-
`).trim()}function Wn(e){const t=[];for(const n of e.matchAll(Nt)){const r=n[1]?.trim()||"file",o=n[2];o&&t.push({name:r,url:o})}return t}function qn(e,t={}){if(typeof e=="string"){const r=dt(e);return r?[{type:"text",text:r}]:[]}if(!Array.isArray(e))return[];const n=[];for(const r of e){if(!r||typeof r!="object")continue;const o=r;if(o.type==="text"&&typeof o.text=="string"){const i=dt(o.text);i&&n.push({type:"text",text:i})}else t.showToolCalls&&o.type==="toolCall"&&typeof o.name=="string"&&!Ct.has(o.name)&&n.push({type:"tool-call",toolCallId:o.id??`tc-${n.length}`,toolName:o.name,args:o.arguments??{}})}return n}function Kn(e){const t=[],n=r=>{for(const{name:o,url:i}of Wn(r))t.push({id:`file-${t.length}`,name:o,url:i,isImage:Hn.test(o)})};if(typeof e=="string")return n(e),t.length>0?t:void 0;if(Array.isArray(e)){for(const r of e){if(!r||typeof r!="object")continue;const o=r;if(o.type==="image"&&typeof o.data=="string"){const i=o.mimeType||"image/png";t.push({id:`img-${t.length}`,name:`image-${t.length+1}`,imageDataUrl:`data:${i};base64,${o.data}`,isImage:!0})}else o.type==="text"&&typeof o.text=="string"&&n(o.text)}return t.length>0?t:void 0}}function Gn(e,t){if(e.type==="bashExecution"){const r=e.content??{},o=e.timestamp?new Date(e.timestamp).getTime():void 0;return{id:e.id,role:"user",parts:[{type:"bash",command:r.command??"",output:r.output??"",exitCode:r.exitCode,cancelled:r.cancelled??!1}],createdAt:o&&!Number.isNaN(o)?o:void 0}}if(e.type!=="message"||e.isVerbose||e.role!=="assistant"&&e.role!=="user"&&e.role!=="system")return null;const n=e.timestamp?new Date(e.timestamp).getTime():void 0;return{id:e.id,role:e.role,parts:qn(e.content,t),attachments:Kn(e.content),createdAt:n&&!Number.isNaN(n)?n:void 0}}const Jn=[],Qn=[];function Xn(e){let t=null;for(const n of e)n.type==="suggestion"&&(t=n.prompts.length>0?n.prompts:null);return t}function Yn(e,t){if(e.length===0)return null;const n=[];for(const r of e)if(r.type!=="suggestion"){if(r.type==="agent-error"){n.push({type:"error",text:String(r.error??"Agent reported an error.")});const o=Tt(r.errorCode,{...t,provider:r.errorContext?.provider,model:r.errorContext?.model});o&&n.push({type:"tool-call",toolCallId:`error-run-${r.runId}`,toolName:"link-button",args:{label:o.label,url:o.href}});continue}n.push({type:"tool-call",toolCallId:`approval-event-${r.eventId}`,toolName:"tool-approval",args:{runId:r.runId,action:r.action,proposal:r.proposal,current:r.current,fields:r.fields??null,attribution:r.attribution??null,resourceKind:r.resourceKind??null,reason:r.reason??null,status:r.status??"pending",reviewedByName:r.reviewedByName??null,requestId:null}})}return n.length===0?null:{id:"history-interactions",role:"assistant",parts:n}}const Zn=3e4,er=3*Zn,tr=15e3;function pt(e){try{return JSON.parse(e.data)}catch{return{content:e.data}}}const me=e=>`${e}-${Date.now()}-${Math.random().toString(36).slice(2,6)}`;function ft(e){const t=[],n=new Set;for(const r of e){if(!r||typeof r!="object")continue;const{title:o,message:i}=r;if(typeof o!="string"||typeof i!="string")continue;const a=o.trim(),c=i.trim();if(a.length===0||c.length===0)continue;const u=`${a}\0${c}`;n.has(u)||(n.add(u),t.push({title:a,message:c}))}return t.length>0?t:null}function Uo({agentId:e,workspaceSlug:t,thread:n="agent-panel",loadHistory:r=!0,ephemeralContext:o,onFirstUserMessage:i,children:a,initialDraft:c}){const u=Kt(),d=l.useRef(null),f=l.useRef(null),y=l.useRef(!1),v=l.useRef(o),m=l.useRef(void 0),[R,O]=l.useState(void 0),x=l.useRef(!1),L=l.useRef(null);v.current=o;const{data:k,isLoading:j}=Gt(e,n,{orgSlug:t,enabled:r&&!!e&&!!n}),A=k?.messages??Jn,K=k?.interactions??Qn,{data:E}=Jt(e,{enabled:!!e}),$=!!(E?.showToolCalls??E?.settings?.showToolCalls),[Z,ne]=l.useState([]),[z,Q]=l.useState(!1),[q,w]=l.useState([]);l.useEffect(()=>{R&&w([])},[R]);const[S,C]=l.useState(null),P=l.useRef(!1);P.current=z;const I=l.useMemo(()=>A.map(N=>Gn(N,{showToolCalls:$})).filter(N=>N!==null),[A,$]),ee=l.useRef(!1);l.useEffect(()=>{if(ee.current||j||P.current)return;ee.current=!0;const N=Yn(K,{workspaceSlug:t,agentId:e,webOrigin:typeof window>"u"?null:window.location.origin});ne(N?[...I,N]:I),C(Xn(K))},[e,j,I,K,t]);const X=l.useCallback(()=>{u.invalidateQueries({queryKey:["agent-thread-messages",t,e,n]}),u.invalidateQueries({queryKey:["agent-threads",t,e]})},[u,t,e,n]),re=l.useCallback(async()=>{if(d.current)return d.current;if(f.current)return f.current;if(!e)throw new Error("No agent selected");const N=(async()=>{const T=await ze(`${Be}/lobu/api/v1/agents`,{method:"POST",headers:{"Content-Type":"application/json",...t?{"x-lobu-org":t}:{}},credentials:"include",body:JSON.stringify({agentId:e,thread:n,...m.current?{executionTarget:m.current}:{}}),timeoutMs:2e4});if(!T.ok)throw await st(T);const V=await T.json(),W=Qt(),B={sessionId:V.agentId,sseUrl:ut(V.sseUrl,Be,W),messagesUrl:ut(V.messagesUrl,Be,W),executionTarget:V.executionTarget};return m.current=V.executionTarget,O(V.executionTarget),d.current=B,B})();f.current=N;try{return await N}catch(T){throw d.current=null,T}finally{f.current=null}},[e,t,n]),se=l.useCallback(async(N,T,V)=>{const W=new AbortController;L.current=W;const B=p=>{ne(h=>h.map(b=>b.id===V?{...b,parts:p}:b))};let G;try{G=await re()}catch(p){B([{type:"text",text:`Error: ${p instanceof Error?p.message:"Could not start a session."}`}]);return}let H=await lt(G.sseUrl,{throwOnFailure:!0});const ie=[];let he=null;const Re=()=>{const p=he;he=null,p?.()},ge=p=>{ie.push(p),Re()};let ve=!1,Se=null;const _e=new Promise(p=>{Se=p});let pe=0,ye=Date.now();const fe=p=>{ye=Date.now();const h=Number(p.lastEventId);Number.isFinite(h)&&h>pe&&(pe=h)},Ie=["output","status","complete","closed","agent-error","question","suggestion","link-button","tool-approval","tool_use"],Te=p=>{p.addEventListener("open",()=>{ve=!0,Se?.()}),p.addEventListener("connected",b=>{fe(b),ve||(ve=!0,Se?.())}),p.addEventListener("ping",fe);const h=b=>M=>{fe(M);const te=M;typeof te.data=="string"&&ge({kind:b,payload:pt(te)})};for(const b of Ie)p.addEventListener(b,h(b));p.addEventListener("error",b=>{const M=b;if(typeof M.data=="string"&&M.data){fe(b),ge({kind:"error",payload:pt(M)});return}p.readyState===EventSource.CLOSED&&ge({kind:"error",payload:{error:"Connection closed"}})})};Te(H);const Oe=async()=>{H.close();let p=G.sseUrl;if(pe){const h=new URL(G.sseUrl,window.location.origin);h.searchParams.set("since",String(pe)),p=h.toString()}H=await lt(p,{throwOnFailure:!1}),Te(H),ye=Date.now()};await Promise.race([_e,new Promise(p=>setTimeout(p,1500))]);const Pe=()=>{H.close(),Re()};W.signal.addEventListener("abort",Pe,{once:!0});try{const p=v.current?.trim(),h=!!p&&!x.current;h&&(x.current=!0);let b;if(T.length>0){const g=new FormData;g.set("content",N),h&&p&&g.set("ephemeralContext",p);for(const _ of T)g.append("files",_,_.name);b={method:"POST",credentials:"include",body:g,timeoutMs:12e4}}else{const g={content:N};h&&p&&(g.ephemeralContext=p),b={method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(g),timeoutMs:2e4}}const M=await ze(G.messagesUrl,b);if(!M.ok)throw d.current=null,await st(M);let te="",F=Me,ot=null;const be=[],ae=()=>zn({textOut:te,statusLine:F,errorText:ot,toolCalls:be});for(B(ae());!W.signal.aborted;){if(ie.length===0){let _;const J=await Promise.race([new Promise(Ve=>{he=()=>Ve(!0)}),new Promise(Ve=>{_=setTimeout(()=>Ve(!1),tr)})]);_&&clearTimeout(_),!J&&Date.now()-ye>=er&&(await Oe(),X());continue}const g=ie.shift();if(g){if(g.kind==="output")F=null,te+=String(g.payload.content??"");else if(g.kind==="status")F=Me;else if(g.kind==="complete"){F=null;const _=g.payload.finalText;typeof _=="string"&&_.length>0&&(te=_);const J=g.payload.suggestions;J!==void 0&&C(Array.isArray(J)?ft(J):null),X(),B(ae());return}else if(g.kind==="closed"){d.current=null;const _=g.payload.reason;F=`Session ended${_?`: ${_}`:""}.`,X(),B(ae());return}else if(g.kind==="error"||g.kind==="agent-error"){F=null,ot=typeof g.payload.error=="string"&&g.payload.error?g.payload.error:"Agent reported an error.";const _=g.payload.errorContext&&typeof g.payload.errorContext=="object"?g.payload.errorContext:void 0,J=Tt(g.payload.errorCode,{workspaceSlug:t,agentId:e,webOrigin:typeof window>"u"?null:window.location.origin,provider:typeof _?.provider=="string"?_.provider:void 0,model:typeof _?.model=="string"?_.model:void 0});J&&be.push({type:"tool-call",toolCallId:me("l"),toolName:"link-button",args:{label:J.label,url:J.href}}),X(),B(ae());return}else if(g.kind==="question")be.push({type:"tool-call",toolCallId:me("q"),toolName:"question",args:{question:g.payload.question??"",options:g.payload.options??[]}});else if(g.kind==="tool_use"){if(F=null,Ct.has(g.payload.name??"")){B(ae());continue}const _=g.payload.result_summary,J=jt(_);if(!$&&!J){B(ae());continue}be.push({type:"tool-call",toolCallId:g.payload.toolCallId??me("t"),toolName:$?g.payload.name??"tool":"subscription-candidate",args:$?g.payload.input??{}:null,result:_,isError:g.payload.isError})}else if(g.kind==="suggestion"){const _=g.payload.prompts;_!==void 0&&(C(Array.isArray(_)?ft(_):null),B(ae()))}else if(g.kind==="link-button")be.push({type:"tool-call",toolCallId:me("l"),toolName:"link-button",args:{label:g.payload.label??"Open link",url:g.payload.url??""}});else if(g.kind==="tool-approval"){const _=G.messagesUrl.replace(/\/agents\/[^/]+\/messages$/,"/agents/approve"),J=g.payload.runId;be.push({type:"tool-call",toolCallId:g.payload.requestId??(J!=null?`run-${J}`:me("a")),toolName:"tool-approval",args:{requestId:g.payload.requestId??null,tool:g.payload.toolName??"a tool",args:g.payload.args??null,durationOptions:g.payload.durationOptions??["1h","24h","always"],approveUrl:_,orgSlug:t??null,runId:J??null,action:g.payload.action??null,proposal:g.payload.proposal??null,current:g.payload.current??null,fields:g.payload.fields??null,attribution:g.payload.attribution??null,resourceKind:g.payload.resourceKind??null}})}B(ae())}}}catch(p){B([{type:"text",text:`Error: ${p instanceof Error?p.message:"Send failed."}`}])}finally{W.signal.removeEventListener("abort",Pe),H.close()}},[e,re,X,$,t]),ue=l.useCallback(N=>{const T=N.trim(),V=q.map(H=>H.file);if(!T&&V.length===0||P.current||!e)return;y.current||(y.current=!0,i?.(T||V[0]?.name||""));const W={id:me("u"),role:"user",parts:T?[{type:"text",text:T}]:[],attachments:q.map(H=>({id:H.id,name:H.name,isImage:H.isImage,imageDataUrl:H.isImage?URL.createObjectURL(H.file):void 0})),createdAt:Date.now()},B=me("asst"),G={id:B,role:"assistant",parts:[{type:"reasoning"}],createdAt:Date.now()};ne(H=>[...H,W,G]),w([]),Q(!0),P.current=!0,se(T,V,B).finally(()=>{Q(!1),P.current=!1,L.current=null})},[e,i,q,se]),Y=l.useCallback(()=>{L.current?.abort()},[]),le=l.useCallback(N=>{const T=Array.from(N);w(V=>[...V,...T.map(W=>({id:crypto.randomUUID(),name:W.name,file:W,isImage:W.type.startsWith("image/")}))])},[]),D=l.useCallback(N=>{w(T=>T.filter(V=>V.id!==N))},[]),de=l.useRef(!1);l.useEffect(()=>{if(de.current)return;const N=An(n);N&&(de.current=!0,m.current=N.executionTarget,O(N.executionTarget),ue(N.text))},[n,ue]),l.useEffect(()=>{j||I.length===0||re().catch(()=>{})},[re,I.length,j]);const ke=l.useMemo(()=>({messages:Z,running:z,append:ue,cancel:Y,pendingAttachments:q,addAttachments:le,removeAttachment:D,initialDraft:c,agentId:e,conversationId:n,workspaceSlug:t,currentSuggestions:S,executionTarget:R}),[Z,z,ue,Y,q,le,D,c,e,n,t,S,R]);return r&&j?s.jsx(Tn,{}):s.jsx(et.Provider,{value:ke,children:a})}const mt="mx-0.5 inline-flex items-center gap-1 rounded-md bg-accent px-1.5 py-0.5 align-baseline font-medium text-[0.9em] text-accent-foreground no-underline";function nr({refItem:e}){const t=_n[e.kind]??Xt;return In(e.path)?s.jsxs("span",{className:mt,children:[s.jsx(t,{className:"h-3 w-3 shrink-0 opacity-70"}),e.label]}):s.jsxs(xt,{to:e.path,className:U(mt,"hover:bg-accent/80"),children:[s.jsx(t,{className:"h-3 w-3 shrink-0 opacity-70"}),e.label]})}const tt=({text:e,renderText:t})=>En(e)?s.jsx(s.Fragment,{children:kn(e).map((n,r)=>n.type==="ref"?s.jsx(nr,{refItem:n.ref},`r${r}`):s.jsx("span",{children:t(n.text)},`t${r}`))}):s.jsx(s.Fragment,{children:t(e)}),rr=({label:e="Thinking"})=>s.jsx("span",{className:"aui-thinking-shimmer inline-block text-sm","aria-live":"polite","aria-busy":"true",children:e}),At=l.createContext(null),Et=()=>{const e=l.useContext(At);if(!e)throw new Error("ChainOfThought components must be used within ChainOfThought");return e},kt=l.memo(({className:e,open:t,defaultOpen:n=!1,onOpenChange:r,children:o,...i})=>{const[a,c]=Yt({prop:t,defaultProp:n,onChange:r}),u=l.useMemo(()=>({isOpen:a,setIsOpen:c}),[a,c]);return s.jsx(At.Provider,{value:u,children:s.jsx("div",{className:U("not-prose max-w-prose space-y-4",e),...i,children:o})})}),_t=l.memo(({className:e,children:t,...n})=>{const{isOpen:r,setIsOpen:o}=Et();return s.jsx(wt,{onOpenChange:o,open:r,children:s.jsxs(Zt,{className:U("flex w-full items-center gap-2 text-muted-foreground text-sm transition-colors hover:text-foreground",e),...n,children:[s.jsx(en,{className:"size-4"}),s.jsx("span",{className:"flex-1 text-left",children:t??"Chain of Thought"}),s.jsx(tn,{className:U("size-4 transition-transform",r?"rotate-180":"rotate-0")})]})})}),It=l.memo(({className:e,icon:t=rn,label:n,description:r,status:o="complete",children:i,...a})=>{const c={complete:"text-muted-foreground",active:"text-foreground",pending:"text-muted-foreground/50"};return s.jsxs("div",{className:U("flex gap-2 text-sm",c[o],"fade-in-0 slide-in-from-top-2 animate-in",e),...a,children:[s.jsxs("div",{className:"relative mt-0.5",children:[s.jsx(t,{className:"size-4"}),s.jsx("div",{className:"-mx-px absolute top-7 bottom-0 left-1/2 w-px bg-border"})]}),s.jsxs("div",{className:"flex-1 space-y-2 overflow-hidden",children:[s.jsx("div",{children:n}),r&&s.jsx("div",{className:"text-muted-foreground text-xs",children:r}),i]})]})}),Ot=l.memo(({className:e,children:t,...n})=>{const{isOpen:r}=Et();return s.jsx(wt,{open:r,children:s.jsx(nn,{className:U("mt-2 space-y-3","data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2 text-popover-foreground outline-none data-[state=closed]:animate-out data-[state=open]:animate-in",e),...n,children:t})})});kt.displayName="ChainOfThought";_t.displayName="ChainOfThoughtHeader";It.displayName="ChainOfThoughtStep";Ot.displayName="ChainOfThoughtContent";function or(e){const t=e.current?.loser??{};return{duplicates:Array.isArray(e.current?.duplicates)?e.current.duplicates:[t],winner:e.current?.winner??{}}}function Pt(e,t){if(e.length===0)return"No deterministic identity match details are available for these records.";if(e.length===1&&t===2){const[n]=e;return`Both records have the same ${String(n?.kind??"identity")}: ${String(n?.identifier??"")}.`}return`Recorded match evidence:
|
|
6
|
-
${e.map(n=>`• ${String(n.kind??"Identity")}: ${String(n.identifier??"")}`).join(`
|
|
7
|
-
`)}`}function $e(e,t,n){const r=String(t.id??e.toLowerCase());let o;const i=[],a=new Set;typeof t.href=="string"&&(n.add(t.href),o={id:`entity-${r}`,label:"Open record",variant:"ghost",icon:"external",terminal:!1,tool:"open_review_link",args:{url:t.href}});const c=new Set;for(const u of Array.isArray(t.identities)?t.identities:[]){const d=String(u.connection_name??u.source_connector??"Unknown source");c.add(`${d} · ${String(u.namespace??"identity")}: ${String(u.identifier??"")}`),!(typeof u.connection_href!="string"||a.has(u.connection_href))&&(a.add(u.connection_href),n.add(u.connection_href),i.push({id:`connection-${String(u.id??u.connection_href)}`,label:`Open source: ${d}`,variant:"ghost",icon:"external",terminal:!1,tool:"open_review_link",args:{url:u.connection_href}}))}return{type:"entity",id:r,label:e,name:String(t.name??`Entity ${r}`),details:[...c],recordLink:o,sourceLinks:i}}function nt(e){return Array.isArray(e)?e.filter(t=>!!t&&typeof t=="object"&&!Array.isArray(t)):[]}function ht(e){return`${String(e.kind??"Identity")}: ${String(e.identifier??"")}`}function gt(e){if(!Array.isArray(e))return null;const t=nt(e);return t.length===e.length&&t.every(n=>typeof n.kind=="string"&&n.kind.trim().length>0&&typeof n.identifier=="string"&&n.identifier.trim().length>0)?t:null}function sr(e){if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e,n=gt(t.dropped),r=gt(t.gained);if(!n||!r)return null;const o=[];for(const i of n)o.push(`− No longer proven — ${ht(i)}`);for(const i of r)o.push(`+ Newly proven — ${ht(i)}`);return{weakened:n.length>0,block:{type:"text",label:n.length>0?"What changed since you reviewed this":r.length>0?"What the re-check newly found":"What changed since you reviewed this",value:o.length>0?o.join(`
|
|
8
|
-
`):"The recorded match evidence did not change."}}}function lr(e){const{duplicates:t,winner:n}=or(e),r=nt(e.proposal?.evidence),o=new Set,i=typeof e.status=="string"?e.status:"pending",a=i==="pending",c=i==="rejected"?"Kept separate":i==="failed"?"Failed":"Approved",u=typeof e.reason=="string"?e.reason:typeof e.proposal?.reason=="string"?e.proposal.reason:null,d=[{type:"text",label:"Why Lobu thinks they match",value:Pt(r,t.length+1)}];u&&d.push({type:"text",label:"Why this needs review",value:u,muted:!0});const f=sr(e.proposal?.evidence_change);f&&d.push(f.block),d.push(...t.map(v=>$e("Duplicate",v,o)),$e("Canonical",n,o),{type:"text",value:a?`If approved, ${t.length===1?"the":"each"} duplicate's relationships and aliases will move to the canonical record.`:typeof e.reviewedByName=="string"?`${c} by ${e.reviewedByName}.`:`${c}.`,muted:!0});const y=a?[{id:"approve",label:f?"Approve again to apply":"Approve merge",variant:"primary",icon:"check",...f?.weakened?{confirm:!0,confirmPrompt:"The evidence for this merge no longer holds. Merge these records anyway?"}:{},tool:"manage_operations",args:{action:"approve"},resolvedLabel:"Merge approved and is being applied."},{id:"reject",label:"Keep separate",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Keep these entities separate?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:"The entities were kept separate."}]:[];return{view:{title:`Merge ${t.length} duplicate ${t.length===1?"record":"records"}${a?"":` · ${c}`}`,icon:"entity",impact:a?{level:"high",reason:"This combines duplicate records into the selected winner."}:{level:"normal"},tone:a||i==="failed"?"warning":"default",blocks:d,actions:y},reviewUrls:o}}function Do(e){const t=e.loser&&typeof e.loser=="object"&&!Array.isArray(e.loser)?{...e.loser}:{},n=e.winner&&typeof e.winner=="object"&&!Array.isArray(e.winner)?{...e.winner}:{};typeof e.loserHref=="string"&&(t.href=e.loserHref),typeof e.winnerHref=="string"&&(n.href=e.winnerHref);const r=nt(e.evidence),o=new Set,i=e.status==="active",c=i&&e.canUndo===!0?[{id:"undo",label:"Undo merge",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Undo this automatic merge?",tool:"manage_entity",args:{action:"unmerge"},resolvedLabel:"Merge undone."}]:[];return{view:{title:i?"Merged automatically":"Automatic merge undone",icon:"entity",impact:{level:"normal"},tone:i?"default":"warning",blocks:[{type:"text",label:"Why Lobu merged them",value:Pt(r,2)},$e("Duplicate",t,o),$e("Canonical",n,o),{type:"text",value:i?"The entity type's deterministic identity rule applied this merge without human review.":"This automatic merge was undone.",muted:!0}],actions:c},reviewUrls:o}}function ir({defaultTagName:e,props:t,render:n,state:r={},stateAttributesMapping:o}){let i=qe(ar(r,o),t);if(!n)return l.createElement(e,i);if(typeof n=="function")return n(i,r);if(!l.isValidElement(n))return null;let a=n.props,c={...qe(i,a),ref:Ee(i.ref,a.ref)};return l.cloneElement(n,c)}function qe(...e){let t={};for(let n of e){if(!n)continue;let r=n;for(let o of Object.keys(r)){let i=r[o];if(i===void 0)continue;let a=t[o];o==="className"?t[o]=[a,i].filter(Boolean).join(" "):o==="style"?t[o]={...a,...i}:o==="ref"?t[o]=Ee(a,i):ur(o)&&typeof a=="function"&&typeof i=="function"?t[o]=cr(i,a):t[o]=i}}return t}function ar(e,t){let n={};for(let r of Object.keys(e)){let o=e[r],i=t?.[r]?.(o);if(i){Object.assign(n,i);continue}if(r==="slot"){n["data-slot"]=o;continue}let a=`data-${String(r).replace(/[A-Z]/g,c=>`-${c.toLowerCase()}`)}`;typeof o=="boolean"?n[a]=o?"":void 0:o!=null&&(n[a]=String(o))}return n}function cr(e,t){return function(n){e(n),n.defaultPrevented||t(n)}}function ur(e){return/^on[A-Z]/.test(e)}function Ee(...e){let t=e.filter(Boolean);if(t.length!==0)return n=>{for(let r of t)typeof r=="function"?r(n):r&&(r.current=n)}}var dr=8,pr=64,fr=0,Ue=.5,mr=180,hr=new Set(["ArrowDown","ArrowUp","End","Home","PageDown","PageUp"," "]),Lt={start:!1,end:!1},gr=[],De={currentAnchorId:null,visibleMessageIds:gr};function vr({content:e,scrollEdgeThreshold:t,spacer:n,viewport:r}){if(!r||!e)return Lt;let o=rt({content:e,spacer:n,viewport:r});return{start:r.scrollTop>t,end:o-r.scrollTop-r.clientHeight>t}}function yr({content:e,scrollMargin:t,scrollPreviousItemPeek:n,spacer:r,viewport:o,visibleMessageIds:i}){if(!e||!o)return De;let a=o.getBoundingClientRect(),c=a.top+t+n,u=typeof IntersectionObserver>"u",d=[],f=null;for(let y of je(e,r)){let v=y.dataset.messageId;if(!v)continue;let m=y.dataset.scrollAnchor==="true",R=m||u?y.getBoundingClientRect():null;(u&&R?R.bottom>c&&R.top<a.bottom:i.has(v))&&d.push(v),m&&R&&R.top<=c+Ue&&(f=v)}return d.length===0&&f===null?De:{currentAnchorId:f,visibleMessageIds:d}}function je(e,t){return Array.from(e.children).filter(n=>n instanceof HTMLElement&&n!==t)}function br(e,t){for(let n=t;n<e.length;n++){let r=e[n];if(r?.dataset.scrollAnchor==="true")return r}return null}function xr(e,t){for(let n of e)if(n.dataset.scrollAnchor==="true"&&!t.has(n))return n;return null}function wr(e,t){let n=0;for(let r=t;r<e.length;r++)if(e[r]?.dataset.scrollAnchor==="true"&&(n+=1,n>1))return!0;return!1}function Rr(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.dataset.scrollAnchor==="true")return n}return null}function Sr({content:e,spacer:t,viewport:n}){let r=n.getBoundingClientRect();for(let o of je(e,t)){if(!o.dataset.messageId)continue;let i=o.getBoundingClientRect();if(i.bottom>r.top&&i.top<r.bottom)return o}return null}function Tr({align:e,element:t,scrollMargin:n,spacer:r,viewport:o}){let i=Mt(t,o),a=t.getBoundingClientRect().height,c=Nr(r);if(e==="center"){let u=Math.max(0,o.clientHeight-c.start-c.end);return i-c.start-(u-a)/2-n}if(e==="end")return i-o.clientHeight+a+c.end+n;if(e==="nearest"){let u=i+a,d=o.scrollTop+c.start,f=o.scrollTop+o.clientHeight-c.end;return i>=d&&u<=f?o.scrollTop:i<d?i-c.start-n:u-o.clientHeight+c.end+n}return i-c.start-n}function Mt(e,t){let n=e.getBoundingClientRect(),r=t.getBoundingClientRect();return n.top-r.top+t.scrollTop}function Le(e,t){return e.getBoundingClientRect().top-t.getBoundingClientRect().top}function jr({content:e,scrollTop:t,spacer:n,viewport:r}){let o=rt({content:e,spacer:n,viewport:r});return t+r.clientHeight-o}function rt({content:e,spacer:t,viewport:n}){let r=je(e,t),o=$t(e),i=n.getBoundingClientRect(),a=n.scrollTop,c=o.start+o.end;for(let u of r){let d=u.getBoundingClientRect();c=Math.max(c,d.bottom-i.top+a+o.end)}return c}function Cr(e){return Math.max(0,e.scrollHeight-e.clientHeight)}function $t(e){let t=window.getComputedStyle(e);return{end:Ke(t.paddingBlockEnd||t.paddingBottom),start:Ke(t.paddingBlockStart||t.paddingTop)}}function Nr(e){let t=e?.parentElement;return t?$t(t):{end:0,start:0}}function Ar(e){if(!e)return 0;let t=window.getComputedStyle(e),n=t.rowGap==="normal"?t.gap:t.rowGap;return Ke(n)}function Ke(e){if(!e)return 0;let t=Number.parseFloat(e);return Number.isFinite(t)?t:0}function Er({refs:e,commitScrollState:t,scheduleStateCommit:n,scheduleVisibilitySync:r}){let{streamingTurnRef:o,autoScrollRef:i,autoscrollingRef:a,autoscrollingTimeoutRef:c,contentRef:u,defaultScrollPositionAppliedRef:d,itemCountRef:f,messageElementsRef:y,modeRef:v,pendingScrollToMessageRef:m,prependRestoreRef:R,scrollMarginRef:O,scrollPreviousItemPeekRef:x,spacerGapRef:L,spacerHeightRef:k,spacerRef:j,viewportRef:A}=e,K=l.useCallback(w=>{c.current!==null&&(window.clearTimeout(c.current),c.current=null),a.current!==w&&(a.current=w,t()),w&&(c.current=window.setTimeout(()=>{c.current=null,a.current=!1,t()},mr))},[t]),E=l.useCallback(w=>{let S=j.current;if(!S)return;let C=Math.max(0,Math.ceil(w));k.current!==C&&(k.current=C,S.hidden=C===0,S.style.height=`${C}px`,S.style.marginTop=C>0?`${-L.current}px`:"")},[]),$=l.useCallback((w,{behavior:S="auto",autoscrolling:C=!1}={})=>{let P=A.current;if(!P)return;let I=Math.max(0,w);if(Math.abs(P.scrollTop-I)<=Ue){P.scrollTop=I,t();return}C&&K(!0),P.scrollTo({top:I,behavior:S}),n()},[t,n,K]),Z=l.useCallback(({behavior:w="auto"}={})=>A.current?(E(0),o.current=null,v.current="free-scrolling",$(0,{behavior:w}),r(),!0):!1,[r,$,E]),ne=l.useCallback(({behavior:w="auto"}={})=>{let S=A.current;return S?(E(0),o.current=null,v.current=i.current?"following-bottom":"free-scrolling",$(Cr(S),{autoscrolling:!0,behavior:w}),r(),!0):!1},[r,$,E]),z=l.useCallback((w,{align:S="start",behavior:C="auto",scrollMargin:P=O.current}={},{keepPreviousPeek:I=!1}={})=>{let ee=u.current,X=A.current;if(!ee||!X||!ee.contains(w))return!1;let re=Tr({align:S,element:w,scrollMargin:I?P+x.current:P,spacer:j.current,viewport:X}),se=jr({content:ee,scrollTop:re,spacer:j.current,viewport:X});return E(se),R.current={element:w,viewportTop:Le(w,X)},v.current=I?"anchored-to-message":"settling-jump",o.current=I?w:null,$(re,{behavior:C}),r(),!0},[r,$,E]),Q=l.useCallback(()=>{let w=o.current;return!w||!w.isConnected||v.current!=="anchored-to-message"?!1:z(w,{align:"start"},{keepPreviousPeek:!0})},[z]),q=l.useCallback((w,S)=>{let C=y.current.get(w);return C?(d.current=!0,z(C,S)?(m.current=null,!0):(m.current={messageId:w,options:S},!0)):f.current===0?(m.current={messageId:w,options:S},d.current=!0,!0):!1},[z]);return{flushPendingScrollToMessage:l.useCallback(()=>{let w=m.current;if(!w)return!1;let S=y.current.get(w.messageId);return!S||!z(S,w.options)?!1:(m.current=null,d.current=!0,!0)},[z]),reanchorToAnchoredMessage:Q,scrollToElement:z,scrollToEnd:ne,scrollToMessage:q,scrollToStart:Z}}function Ut(e,t){let n=e,r=new Set;return{getSnapshot:()=>n,hasListeners:()=>r.size>0,setSnapshot:o=>{t(n,o)||(n=o,r.forEach(i=>i()))},subscribe:(o,i,a)=>{let c=r.size===0;return r.add(o),c&&i?.(),()=>{r.delete(o),r.size===0&&a?.()}}}}function kr(e,t){return Ut(e,t)}function _r(){return Ut(De,Or)}function Ir(e,t){return e.start===t.start&&e.end===t.end}function Or(e,t){return e.currentAnchorId!==t.currentAnchorId||e.visibleMessageIds.length!==t.visibleMessageIds.length?!1:e.visibleMessageIds.every((n,r)=>n===t.visibleMessageIds[r])}function Pr({autoScroll:e,scrollEdgeThreshold:t,scrollMargin:n,scrollPreviousItemPeek:r}){let o=l.useRef(e),i=l.useRef(!1),a=l.useRef(null),c=l.useRef(!1),u=l.useRef(t),d=l.useRef(0),f=l.useRef(null),y=l.useRef(0),v=l.useRef(e?"following-bottom":"free-scrolling"),m=l.useRef(new Map),R=l.useRef(null),O=l.useRef(null),x=l.useRef(null),L=l.useRef(r),k=l.useRef(!0),j=l.useRef(null),A=l.useRef(n),K=l.useRef(null),E=l.useRef(0),$=l.useRef(0),Z=l.useRef(null),ne=l.useRef(null),z=l.useRef(null),Q=l.useRef(null),q=l.useRef(null),w=l.useRef(null),S=l.useRef(null),C=l.useRef(null),P=l.useRef(new Set),I=l.useRef(new WeakSet);return z.current===null&&(z.current=kr(Lt,Ir)),C.current===null&&(C.current=_r()),o.current=e,u.current=t,A.current=n,L.current=r,{autoScrollRef:o,autoscrollingRef:i,autoscrollingTimeoutRef:Q,streamingTurnRef:x,contentRef:a,defaultScrollPositionAppliedRef:c,firstItemRef:f,itemCountRef:d,lastScrollTopRef:y,messageElementsRef:m,modeRef:v,pendingScrollFrameRef:K,pendingScrollToMessageRef:R,prependRestoreRef:O,preserveScrollOnPrependRef:k,rootRef:j,scrollEdgeThresholdRef:u,scrollMarginRef:A,scrollPreviousItemPeekRef:L,spacerGapRef:E,spacerHeightRef:$,spacerRef:Z,stateFrameRef:ne,stateStore:z.current,viewportRef:q,visibilityFrameRef:w,visibilityObserverRef:S,visibilityStore:C.current,visibleMessageIdsRef:P,handledScrollAnchorsRef:I}}function vt(e,t){return l.useCallback(n=>{e.current=n,n&&t()},[e,t])}function Lr({autoScroll:e=!1,defaultScrollPosition:t="end",scrollEdgeThreshold:n=dr,scrollPreviousItemPeek:r=pr,scrollMargin:o=fr}){let i=Pr({autoScroll:e,scrollEdgeThreshold:n,scrollMargin:o,scrollPreviousItemPeek:r}),{streamingTurnRef:a,autoScrollRef:c,autoscrollingRef:u,autoscrollingTimeoutRef:d,contentRef:f,defaultScrollPositionAppliedRef:y,firstItemRef:v,itemCountRef:m,lastScrollTopRef:R,messageElementsRef:O,modeRef:x,pendingScrollFrameRef:L,pendingScrollToMessageRef:k,prependRestoreRef:j,preserveScrollOnPrependRef:A,rootRef:K,scrollEdgeThresholdRef:E,scrollMarginRef:$,scrollPreviousItemPeekRef:Z,spacerGapRef:ne,spacerHeightRef:z,spacerRef:Q,stateFrameRef:q,stateStore:w,viewportRef:S,visibilityFrameRef:C,visibilityObserverRef:P,visibilityStore:I,visibleMessageIdsRef:ee,handledScrollAnchorsRef:X}=i,re=l.useRef(t);re.current!==t&&(re.current=t,y.current=!1);let se=l.useCallback(p=>{let h=K.current,b=S.current,M=[p.start&&"start",p.end&&"end"].filter(Boolean).join(" "),te=u.current;for(let F of[h,b])F&&(M?F.setAttribute("data-scrollable",M):F.removeAttribute("data-scrollable"),F.toggleAttribute("data-autoscrolling",te))},[]),ue=l.useCallback(p=>{let h=S.current?.scrollTop??0,b=h<R.current-Ue;R.current=h,c.current&&!p.end&&x.current!=="settling-jump"&&x.current!=="anchored-to-message"?x.current="following-bottom":x.current==="following-bottom"&&p.end&&b&&!u.current&&(x.current="free-scrolling")},[]),Y=l.useCallback(()=>{let p=vr({content:f.current,scrollEdgeThreshold:E.current,spacer:Q.current,viewport:S.current});ue(p);let h=x.current==="following-bottom"?{...p,end:!1}:p;se(h),w.setSnapshot(h)},[ue,w,se]),le=l.useCallback(()=>{q.current===null&&(q.current=window.requestAnimationFrame(()=>{q.current=null,Y()}))},[Y]),D=l.useCallback(()=>{I.hasListeners()&&C.current===null&&(C.current=window.requestAnimationFrame(()=>{C.current=null,I.hasListeners()&&I.setSnapshot(yr({content:f.current,scrollMargin:$.current,scrollPreviousItemPeek:Z.current,spacer:Q.current,viewport:S.current,visibleMessageIds:ee.current}))}))},[I]),{flushPendingScrollToMessage:de,reanchorToAnchoredMessage:ke,scrollToElement:N,scrollToEnd:T,scrollToMessage:V,scrollToStart:W}=Er({refs:i,commitScrollState:Y,scheduleStateCommit:le,scheduleVisibilitySync:D}),B=l.useCallback(()=>{let p=j.current,h=S.current;if(!p||!h||!p.element.isConnected)return!1;let b=Le(p.element,h)-p.viewportTop;return Math.abs(b)<=Ue?!1:(h.scrollTop+=b,p.viewportTop=Le(p.element,h),le(),D(),!0)},[le,D]),G=l.useCallback(()=>{let p=f.current,h=S.current;if(!p||!h){j.current=null;return}let b=Sr({content:p,spacer:Q.current,viewport:h});j.current=b?{element:b,viewportTop:Le(b,h)}:null},[]),H=l.useCallback(()=>{L.current===null&&(L.current=window.requestAnimationFrame(()=>{L.current=null,de()&&G()}))},[G,de]),ie=l.useCallback(()=>{if(!t||y.current||m.current===0)return!1;let p=!1;if(t==="last-anchor"){let h=f.current,b=S.current,M=h&&b?Rr(je(h,Q.current)):null;if(!h||!b||!M)p=T({behavior:"auto"});else{let te=Mt(M,b);p=rt({content:h,spacer:Q.current,viewport:b})-te<=b.clientHeight?T({behavior:"auto"}):N(M,{align:"start"},{keepPreviousPeek:!0})}}else p=t==="end"?T({behavior:"auto"}):W({behavior:"auto"});return p?(y.current=!0,!0):!1},[t,N,T,W]),he=l.useCallback(()=>{let p=f.current;if(!p)return;let h=je(p,Q.current),b=m.current,M=v.current;m.current=h.length,v.current=h[0]??null,(()=>{if(de())return;if(b===0){if(ie()||h.length>0&&c.current&&T({behavior:"auto"}))return;Y(),D();return}let te=M?h.indexOf(M):-1;if(A.current&&te>0){B();return}if(h.length>b){let F=br(h,b);if(F){if(c.current&&x.current==="following-bottom"&&wr(h,b)){T({behavior:"auto"});return}N(F,{align:"start"},{keepPreviousPeek:!0}),X.current.add(F);return}}if(h.length===b){let F=xr(h,X.current);if(F){N(F,{align:"start"},{keepPreviousPeek:!0}),X.current.add(F);return}}x.current==="following-bottom"&&c.current?T({behavior:"auto"}):(Y(),D())})(),G()},[ie,G,Y,de,B,D,N,T]),Re=l.useCallback(()=>{if(x.current==="following-bottom"&&c.current){T({behavior:"auto"});return}let p=z.current;if(ke()){c.current&&p>0&&z.current===0&&T({behavior:"auto"});return}le(),D()},[ke,le,D,T]),ge=l.useCallback(()=>{let p=S.current;if(!(!p||!I.hasListeners())){if(typeof IntersectionObserver>"u"){D();return}P.current||(P.current=new IntersectionObserver(h=>{for(let b of h){let M=b.target.dataset.messageId;M&&(b.isIntersecting?ee.current.add(M):ee.current.delete(M))}D()},{root:p,rootMargin:`${-($.current+Z.current)}px 0px 0px 0px`,threshold:[0,.01,.5,1]})),O.current.forEach(h=>{P.current?.observe(h)}),D()}},[D,I]),ve=l.useCallback(()=>{C.current!==null&&(window.cancelAnimationFrame(C.current),C.current=null),P.current?.disconnect(),P.current=null,ee.current.clear(),I.setSnapshot(De)},[I]),Se=l.useCallback((p,h,b)=>{if(h){O.current.set(p,h),P.current?.observe(h),D(),k.current?.messageId===p&&H();return}b&&O.current.get(p)===b&&(O.current.delete(p),ee.current.delete(p),P.current?.unobserve(b),D())},[H,D]),_e=l.useCallback(()=>{(x.current==="following-bottom"||x.current==="anchored-to-message"||x.current==="settling-jump")&&(a.current=null,x.current="free-scrolling")},[]),pe=l.useCallback(()=>se(w.getSnapshot()),[w,se]),ye=vt(K,pe),fe=vt(S,pe),Ie=l.useCallback(p=>{f.current=p},[]),Te=l.useCallback(p=>{Q.current=p,ne.current=Ar(p?.parentElement??null)},[]),Oe=l.useCallback(()=>{Y(),D(),G()},[G,Y,D]),Pe=l.useMemo(()=>({handleContentChange:he,handleResize:Re,observeVisibility:ge,preserveScrollOnPrependRef:A,scrollToEnd:T,scrollToMessage:V,scrollToStart:W,setContentElement:Ie,setRootElement:ye,setSpacerElement:Te,setViewportElement:fe,stateStore:w,syncAfterScroll:Oe,unobserveVisibility:ve,userScrollIntent:_e,viewportRef:S,visibilityStore:I}),[he,Re,ge,T,V,W,Ie,ye,Te,fe,w,Oe,ve,_e,I]);return l.useLayoutEffect(()=>{ie()},[ie]),l.useEffect(()=>()=>{q.current!==null&&(window.cancelAnimationFrame(q.current),q.current=null),C.current!==null&&(window.cancelAnimationFrame(C.current),C.current=null),d.current!==null&&(window.clearTimeout(d.current),d.current=null),L.current!==null&&(window.cancelAnimationFrame(L.current),L.current=null),P.current?.disconnect(),P.current=null},[]),l.useLayoutEffect(()=>{if(e&&x.current==="following-bottom"&&m.current>0){T({behavior:"auto"});return}Y()},[e,Y,T]),{context:Pe,registerMessage:Se}}function Mr(e){let t=l.useRef(e);return t.current=e,t}var Dt=l.createContext(null),Ft=l.createContext(null);function xe(){let e=l.useContext(Dt);if(!e)throw new Error("useMessageScroller must be used within a MessageScroller.");return e}function $r(){let e=l.useContext(Ft);if(!e)throw new Error("MessageScrollerItem must be used within a MessageScroller.");return e}function Vt(){let{scrollToEnd:e,scrollToMessage:t,scrollToStart:n}=xe();return l.useMemo(()=>({scrollToEnd:e,scrollToMessage:t,scrollToStart:n}),[e,t,n])}function Bt(){let{observeVisibility:e,unobserveVisibility:t,visibilityStore:n}=xe(),r=l.useCallback(o=>n.subscribe(o,e,t),[e,t,n]);return l.useSyncExternalStore(r,n.getSnapshot,n.getSnapshot)}function Ur({autoScroll:e=!1,children:t,defaultScrollPosition:n="end",scrollEdgeThreshold:r,scrollPreviousItemPeek:o,scrollMargin:i}){let{context:a,registerMessage:c}=Lr({autoScroll:e,defaultScrollPosition:n,scrollEdgeThreshold:r,scrollPreviousItemPeek:o,scrollMargin:i});return s.jsx(Dt.Provider,{value:a,children:s.jsx(Ft.Provider,{value:c,children:t})})}function Dr({children:e,...t}){let{setRootElement:n}=xe();return s.jsx("div",{ref:n,...t,children:e})}function Fr({"aria-label":e,children:t,onKeyDown:n,onScroll:r,onTouchMove:o,onWheel:i,preserveScrollOnPrepend:a=!0,ref:c,role:u,tabIndex:d,...f}){let{handleResize:y,preserveScrollOnPrependRef:v,setViewportElement:m,syncAfterScroll:R,userScrollIntent:O,viewportRef:x}=xe();v.current=a;let L=l.useCallback(E=>{m(E),Ee(c)?.(E)},[c,m]);function k(E){R(),r?.(E)}function j(E){O(),i?.(E)}function A(E){O(),o?.(E)}function K(E){hr.has(E.key)&&O(),n?.(E)}return l.useEffect(()=>{let E=x.current;if(!E||typeof ResizeObserver>"u")return;let $=0,Z=new ResizeObserver(()=>{window.cancelAnimationFrame($),$=window.requestAnimationFrame(y)});return Z.observe(E),()=>{window.cancelAnimationFrame($),Z.disconnect()}},[y,x]),s.jsx("div",{ref:L,role:u??"region","aria-label":e??"Messages",tabIndex:d??0,onKeyDown:K,onScroll:k,onTouchMove:A,onWheel:j,...f,children:t})}function Vr({"aria-relevant":e,children:t,ref:n,role:r,spacerClassName:o,...i}){let{handleContentChange:a,handleResize:c,setContentElement:u,setSpacerElement:d}=xe(),f=l.useRef(null),y=l.useCallback(v=>{f.current=v,u(v),Ee(n)?.(v)},[n,u]);return l.useLayoutEffect(()=>{let v=f.current;if(!v||(a(),typeof MutationObserver>"u"))return;let m=new MutationObserver(()=>{a()});return m.observe(v,{childList:!0}),()=>m.disconnect()},[a]),l.useEffect(()=>{let v=f.current;if(!v||typeof ResizeObserver>"u")return;let m=0,R=new ResizeObserver(()=>{window.cancelAnimationFrame(m),m=window.requestAnimationFrame(c)});return R.observe(v),()=>{window.cancelAnimationFrame(m),R.disconnect()}},[c]),s.jsxs("div",{ref:y,role:r??"log","aria-relevant":e??"additions",...i,children:[t,s.jsx("div",{ref:d,"aria-hidden":"true","data-message-scroller-spacer":"",hidden:!0,className:o})]})}function Br({messageId:e,ref:t,scrollAnchor:n=!1,...r}){let o=$r(),i=l.useRef(null),a=l.useCallback(c=>{let u=i.current;i.current=c,e&&o(e,c,u),Ee(t)?.(c)},[e,t,o]);return s.jsx("div",{ref:a,"data-message-id":e,"data-scroll-anchor":n?"true":"false",...r})}function Hr({behavior:e="smooth",children:t,direction:n="end",onClick:r,render:o,tabIndex:i,type:a="button",...c}){let{scrollToEnd:u,scrollToStart:d,stateStore:f}=xe(),y=Mr(r),v=l.useCallback(x=>f.subscribe(x),[f]),m=l.useCallback(()=>{let x=f.getSnapshot();return n==="start"?x.start:x.end},[n,f]),R=l.useSyncExternalStore(v,m,m),O=l.useCallback(x=>{R&&(y.current?.(x),x.defaultPrevented||(x.currentTarget.blur(),n==="start"?d({behavior:e}):u({behavior:e})))},[e,n,R,y,u,d]);return ir({defaultTagName:"button",props:qe({type:a,inert:!R,tabIndex:R?i:-1,children:t??s.jsxs("span",{children:["Scroll to ",n]}),onClick:O},c),render:o,state:{active:R,direction:n},stateAttributesMapping:{active:x=>({"data-active":x?"true":"false"})}})}var we={Provider:Ur,Root:Dr,Viewport:Fr,Content:Vr,Item:Br,Button:Hr};const zr=we.Provider;function Wr({className:e,...t}){return s.jsx(we.Root,{className:U("relative flex size-full min-h-0 flex-col overflow-hidden",e),...t})}function qr({className:e,...t}){return s.jsx(we.Viewport,{className:U("size-full min-h-0 overflow-y-auto overscroll-contain [scrollbar-gutter:stable]",e),...t})}function Kr({className:e,...t}){return s.jsx(we.Content,{className:U("flex h-max min-h-full flex-col",e),...t})}function Gr({className:e,...t}){return s.jsx(we.Item,{className:U("min-w-0 shrink-0",e),...t})}function Jr({className:e,...t}){return s.jsx(we.Button,{direction:"end",behavior:"smooth",render:({active:n,...r})=>n?s.jsx(ce,{...r,type:"button",variant:"outline",size:"icon",className:U("absolute right-4 bottom-4 z-20 rounded-full bg-background ",e),"aria-label":"Scroll to latest message",children:s.jsx(on,{})}):null,...t})}function Qr(e){if(!e)return"";const t=e.startsWith("?")?e.slice(1):e,n=new URLSearchParams(t);return n.get("message_id")?.trim()||n.get("message")?.trim()||""}function Xr(e){const t=e.scrollTarget.trim();return t?e.alreadyScrolledTo===t?{scroll:!1}:e.messageIds.includes(t)?{scroll:!0,id:t}:{scroll:!1}:{scroll:!1}}const Yr="lobu-spa";function He(e){return typeof e=="string"&&/^https?:\/\//i.test(e.trim())}function Fe(e,t){return t.type==="tool-call"?`tc-${t.toolCallId}`:t.type==="reasoning"?`${e.id}-reasoning`:t.type==="bash"?`${e.id}-bash-${t.command.slice(0,24)}`:t.type==="error"?`${e.id}-error`:`${e.id}-text-${t.text.slice(0,24)}`}const Fo=({afterMessagesContent:e,readOnly:t=!1,readerPositionMode:n="messages",interactionExtension:r,onRunSelect:o})=>{const{messages:i,agentId:a,conversationId:c}=Ae(),{data:u=[]}=sn(a,{conversationId:c});return s.jsx(Mn,{extension:r,children:s.jsxs("div",{"data-agent-thread":!0,className:"flex min-h-0 flex-1 flex-col",children:[s.jsx(Zr,{messages:i,trips:u,mode:n,afterMessagesContent:e,onRunSelect:o}),t?null:s.jsx("div",{className:jn,children:s.jsx(ko,{})})]})})},Zr=({messages:e,trips:t,mode:n,afterMessagesContent:r,onRunSelect:o})=>s.jsx(zr,{autoScroll:!0,defaultScrollPosition:n==="runs"?"last-anchor":"end",scrollPreviousItemPeek:48,children:s.jsx(to,{messages:e,trips:t,mode:n,afterMessagesContent:r,onRunSelect:o})});function eo(e){if(!e.startsWith("sep:"))return null;const t=Number(e.slice(4));return Number.isFinite(t)&&t>0?t:null}const to=({messages:e,trips:t,mode:n,afterMessagesContent:r,onRunSelect:o})=>{const{currentAnchorId:i}=Bt(),{scrollToMessage:a}=Vt(),c=l.useRef(null);l.useEffect(()=>{if(e.length===0||typeof window>"u")return;const d=Xr({messageIds:e.map(f=>f.id),scrollTarget:Qr(window.location.search),alreadyScrolledTo:c.current});d.scroll&&(c.current=d.id,a(d.id,{align:"start",behavior:"smooth"}))},[e,a]);const u=d=>n==="runs"?d.id.startsWith("sep:"):d.role==="user";return s.jsxs(Wr,{children:[s.jsx(qr,{"aria-label":n==="runs"?"Automation run history":"Conversation",children:s.jsxs(Kr,{className:U(Xe,Cn),children:[e.map(d=>{const f=n==="runs"&&o?eo(d.id):null;return s.jsx(Gr,{messageId:d.id,scrollAnchor:u(d),"aria-current":d.id===i?"location":void 0,className:U("flex flex-col",n==="runs"&&u(d)&&"border-l-2 border-transparent pl-2 transition-colors",n==="runs"&&d.id===i&&"border-primary"),children:f!=null?s.jsx(go,{message:d,onClick:()=>o?.(f)}):s.jsx(lo,{message:d})},d.id)}),t.map(d=>s.jsx(ro,{trip:d},d.id)),s.jsx(so,{}),r?s.jsx("div",{className:"mt-auto shrink-0 py-2",children:r}):null]})}),e.length>0?s.jsx(no,{messages:e,mode:n}):null,s.jsx(Jr,{})]})},no=({messages:e,mode:t})=>{const{scrollToMessage:n}=Vt(),{currentAnchorId:r,visibleMessageIds:o}=Bt(),i=t==="runs"?e.flatMap(c=>c.parts).filter(c=>c.type==="tool-call"&&c.toolName==="tool-approval"&&c.args!==null&&typeof c.args=="object"&&c.args.status==="pending").length:0,a=e.flatMap(c=>{if(!(t==="runs"?c.id.startsWith("sep:"):c.role==="user"))return[];const d=c.parts.find(f=>f.type==="text");return[{id:c.id,label:d?.type==="text"?d.text:"Automation run"}]});return a.length===0?null:s.jsxs(dn,{children:[s.jsx(pn,{asChild:!0,children:s.jsxs(ce,{type:"button",variant:"outline",size:"icon",className:U("absolute top-1/2 right-4 z-20 -translate-y-1/2 rounded-full bg-background/95 ",i>0&&"w-auto px-3"),"aria-label":i>0?`Open transcript outline, ${i} ${i===1?"approval":"approvals"} waiting`:"Open transcript outline",children:[s.jsx(fn,{}),i>0?s.jsxs("span",{className:"text-xs tabular-nums",children:[i," waiting"]}):null]})}),s.jsxs(mn,{side:"left",align:"center",className:"w-80 space-y-3 p-3",children:[s.jsxs("div",{className:"px-1",children:[s.jsx("p",{className:"text-sm font-medium",children:"Transcript outline"}),s.jsx("p",{className:"text-xs text-muted-foreground",children:t==="runs"?"Track and jump between Automation runs.":"Track and jump between your messages."})]}),s.jsx("div",{className:"max-h-80 space-y-1 overflow-y-auto",children:a.map(c=>{const u=c.id===r,d=o.includes(c.id);return s.jsxs(ce,{type:"button",variant:u?"secondary":"ghost",className:"h-auto w-full justify-start gap-2 px-2 py-2 text-left text-xs font-normal","aria-current":u?"location":void 0,onClick:()=>n(c.id,{align:"start",behavior:"smooth"}),children:[s.jsx("span",{className:U("size-1.5 shrink-0 rounded-full bg-muted-foreground/30",d&&"bg-primary/60",u&&"bg-primary")}),s.jsx("span",{className:"line-clamp-2",children:c.label})]},c.id)})})]})]})},ro=({trip:e})=>s.jsxs("div",{className:U(Xe,"flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive"),children:[s.jsx(un,{className:"mt-0.5 size-4 shrink-0"}),s.jsxs("div",{className:"min-w-0",children:[s.jsxs("div",{className:"font-medium",children:["Guardrail blocked: ",e.guardrailName," ",s.jsxs("span",{className:"font-normal opacity-70",children:["(",e.stage,")"]})]}),e.reason?s.jsx("div",{className:"mt-0.5 break-words opacity-80",children:e.reason}):null]})]}),oo=({prompts:e,onPick:t,className:n})=>e.length===0?null:s.jsx("div",{className:U("flex flex-wrap gap-2",n),children:e.map(r=>s.jsx(ce,{type:"button",variant:"outline",size:"sm",className:"h-auto rounded-full whitespace-normal text-left",title:r.message,"aria-label":`${r.title}: ${r.message}`,onClick:()=>t(r.message),children:r.title},`${r.title}\0${r.message}`))}),so=()=>{const{currentSuggestions:e,running:t,append:n}=Ae();return t||!e||e.length===0?null:s.jsx(oo,{prompts:e,className:Xe,onPick:r=>n(r)})},lo=({message:e})=>e.role==="user"?s.jsx(io,{message:e}):e.role==="system"?s.jsx(vo,{message:e}):s.jsx(uo,{message:e}),Ht=({attachment:e})=>{const t=e.isImage?e.imageDataUrl??e.url:void 0;if(t)return s.jsx("a",{href:e.url??t,target:"_blank",rel:"noreferrer",children:s.jsx("img",{src:t,alt:e.name,className:"max-h-64 rounded-lg border object-contain"})});const n=s.jsxs(s.Fragment,{children:[s.jsx(We,{className:"h-3 w-3 shrink-0"}),s.jsx("span",{className:"max-w-[14rem] truncate",children:e.name})]});return s.jsx("div",{className:"flex items-center gap-1.5 rounded-md border bg-background px-2 py-1 text-xs",children:e.url?s.jsx("a",{href:e.url,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 hover:underline",children:n}):n})},io=({message:e})=>{const t=e.parts.filter(n=>n.type==="bash");return t.length>0?s.jsx("div",{className:Rt,children:s.jsx("div",{className:"space-y-2",children:t.map(n=>s.jsx(ao,{part:n},Fe(e,n)))})}):s.jsx("div",{className:Nn,children:s.jsxs("div",{className:U(Ne,"px-3 py-2 text-sm"),children:[e.attachments&&e.attachments.length>0?s.jsx("div",{className:"mb-1.5 flex flex-wrap gap-1.5",children:e.attachments.map(n=>s.jsx(Ht,{attachment:n},n.id))}):null,e.parts.map(n=>n.type==="text"?s.jsx("div",{className:"whitespace-pre-wrap break-words",children:s.jsx(tt,{text:n.text,renderText:r=>r})},Fe(e,n)):null)]})})},ao=({part:e})=>{const t=e.cancelled||e.exitCode!==void 0&&e.exitCode!==0;return s.jsxs("div",{className:U(Ne,"overflow-hidden text-xs"),children:[s.jsxs("div",{className:"flex items-center gap-1.5 border-border/60 border-b px-3 py-1.5",children:[s.jsx(hn,{className:"size-3.5 shrink-0 text-muted-foreground"}),s.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-foreground/90",children:e.command}),e.cancelled?s.jsx("span",{className:"rounded bg-muted px-1.5 py-0.5 font-medium text-[10px] text-muted-foreground",children:"cancelled"}):t?s.jsxs("span",{className:"rounded bg-destructive/15 px-1.5 py-0.5 font-medium text-[10px] text-destructive",children:["exit ",e.exitCode]}):null]}),e.output.trim()?s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words px-3 py-2 font-mono text-foreground/80",children:e.output}):null]})},zt=new Set(["question","link-button","tool-approval"]),co="subscription-candidate",uo=({message:e})=>{const t=Ye(),{agentId:n,workspaceSlug:r}=Ae(),o=u=>u.type==="tool-call"&&(zt.has(u.toolName)||t?.toolNames.has(u.toolName)),i=e.parts.filter(u=>u.type==="tool-call"&&!o(u)&&u.toolName!==co),a=e.parts.filter(u=>u.type!=="tool-call"||o(u)),c=e.parts.flatMap(u=>{if(u.type!=="tool-call")return[];const d=jt(u.result);return d?[d]:[]});return s.jsx("div",{className:Rt,children:s.jsxs("div",{className:"space-y-2 text-sm",children:[i.length>0?s.jsx(fo,{tools:i}):null,n&&r?c.map(u=>s.jsx(po,{candidate:u,agentId:n,workspaceSlug:r},`${u.connector_key}:${u.resource_ref}`)):null,a.map(u=>s.jsx(ho,{part:u},Fe(e,u))),e.attachments&&e.attachments.length>0?s.jsx("div",{className:"flex flex-wrap gap-2",children:e.attachments.map(u=>s.jsx(Ht,{attachment:u},u.id))}):null]})})},po=({candidate:e,agentId:t,workspaceSlug:n})=>s.jsxs("div",{className:U(Ne,"flex items-center justify-between gap-3 p-3"),children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:"truncate text-sm font-medium",children:e.label}),s.jsx("p",{className:"text-xs text-muted-foreground",children:"Run this agent when the resource changes."})]}),s.jsx(ce,{asChild:!0,size:"sm",variant:"outline",className:"shrink-0",children:s.jsxs(xt,{to:"/$owner/automations/new",params:{owner:n},search:{agent:t,platform:e.connector_key,resource_type:e.resource_type,resource:e.resource_ref,events:e.suggested_event_keys?.join(","),label:e.label},children:[s.jsx(vn,{className:"mr-1.5 h-4 w-4"}),"Add automation"]})})]}),fo=({tools:e})=>s.jsxs(kt,{defaultOpen:!1,children:[s.jsx(_t,{children:e.length===1?e[0].toolName:`${e.length} tool calls`}),s.jsx(Ot,{children:e.map(t=>{const n=t.args!==void 0&&t.args!==null,r=t.result!==void 0&&t.result!==null;return s.jsxs(It,{icon:gn,label:s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"font-medium",children:t.toolName}),t.isError?s.jsx("span",{className:"rounded bg-destructive/15 px-1.5 py-0.5 font-medium text-[10px] text-destructive",children:"error"}):null]}),status:t.isError?"active":"complete",children:[n?s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-foreground/80 text-xs",children:Ce(t.args)}):null,r?s.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-foreground/80 text-xs",children:Ce(t.result)}):null]},t.toolCallId)})})]}),mo=({text:e})=>{let t=e,n=null;const r=e.match(/\{[\s\S]*\}/);if(r)try{const i=JSON.parse(r[0])?.error?.message;typeof i=="string"&&i.trim()&&(t=i,n=e)}catch{}return s.jsxs("div",{className:"flex gap-2 rounded-lg border border-destructive/30 bg-destructive/5 px-3 py-2.5 text-sm",children:[s.jsx(bn,{className:"mt-0.5 size-4 shrink-0 text-destructive"}),s.jsxs("div",{className:"min-w-0 flex-1 space-y-1",children:[s.jsx("p",{className:"text-foreground/80",children:t}),n&&s.jsxs("details",{className:"text-xs text-muted-foreground",children:[s.jsx("summary",{className:"cursor-pointer select-none hover:text-foreground",children:"Technical details"}),s.jsx("pre",{className:"mt-1 overflow-x-auto whitespace-pre-wrap break-all font-mono",children:n})]})]})]})},ho=({part:e})=>{const t=Ye();return e.type==="reasoning"?s.jsx(rr,{}):e.type==="error"?s.jsx(mo,{text:e.text}):e.type==="text"?e.text.trim()?s.jsx(tt,{text:e.text,renderText:n=>s.jsx(yn,{text:n})}):null:e.type!=="tool-call"?null:zt.has(e.toolName)||t?.toolNames.has(e.toolName)?s.jsx(Eo,{toolName:e.toolName,args:e.args}):null},go=({message:e,onClick:t})=>{const n=e.parts.find(r=>r.type==="text");return s.jsx("button",{type:"button",onClick:t,className:U(Ne,"block w-full cursor-pointer whitespace-pre-wrap break-words px-3 py-2 text-left text-xs text-muted-foreground transition-colors hover:bg-muted/50"),children:n?.type==="text"?n.text:"Automation run"})},vo=({message:e})=>s.jsx("div",{className:"self-stretch",children:s.jsx("div",{className:U(Ne,"px-3 py-2 text-xs text-muted-foreground"),children:e.parts.map(t=>t.type==="text"?s.jsx("div",{className:"whitespace-pre-wrap break-words",children:s.jsx(tt,{text:t.text,renderText:n=>n})},Fe(e,t)):null)})}),yo="/mcp-apps/interaction/index.html";function yt(e){return new Promise(t=>{e({onSettled:(n,r)=>t(!!r)})})}const bo=({src:e,title:t,renderPayload:n,onToolCall:r,onOpenLink:o})=>{const i=l.useRef(null),[a,c]=l.useState(48),u=l.useRef({renderPayload:n,onToolCall:r,onOpenLink:o});return u.current={renderPayload:n,onToolCall:r,onOpenLink:o},l.useEffect(()=>{const d=i.current;if(!d?.contentWindow)return;const f=new Rn(null,{name:"Lobu",version:"1.0.0"},{openLinks:{},serverTools:{}},{hostContext:{theme:document.documentElement.classList.contains("dark")?"dark":"light",displayMode:"inline",platform:"web"}});f.addEventListener("sizechange",({height:m})=>{typeof m=="number"&&c(Math.max(32,Math.ceil(m)))}),f.oncalltool=async({name:m,arguments:R})=>({content:[],isError:await u.current.onToolCall(m,R??{})}),f.onopenlink=async({url:m})=>({isError:await u.current.onOpenLink(m)}),f.addEventListener("initialized",()=>{(async()=>(await f.sendToolInput({arguments:{}}),await f.sendToolResult({content:[],structuredContent:{...u.current.renderPayload,version:1,source:Yr}})))()});const y=new Sn(d.contentWindow,d.contentWindow);f.connect(y).catch(m=>{console.error("[mcp-app-host] failed to initialize",m)});const v=new MutationObserver(()=>{f.setHostContext({theme:document.documentElement.classList.contains("dark")?"dark":"light",displayMode:"inline",platform:"web"})});return v.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>{v.disconnect(),y.close()}},[]),s.jsx("iframe",{ref:i,title:t,src:e,sandbox:"allow-scripts",style:{width:"100%",height:a,border:"none",display:"block"}})},xo=new Set(["action"]),wo=["name","description","identity_md"];function oe(e){return e==null||e===""?"":typeof e=="string"?e:Ce(e)}function bt(e){return e===null?"(cleared)":e===void 0?"":typeof e=="string"?e===""?"":e:Ce(e)}function Ge(e){return e.length>0?e[0].toUpperCase()+e.slice(1):e}const Wt=new Set(["delete","disconnect","merge","remove","remove_rule","reset","revoke"]);function Je(e){return e&&Wt.has(e)?"warning":"default"}function Qe(e,t){return e&&Wt.has(e)?{level:"high",reason:t}:{level:"normal"}}function Ro(e,t){const n=e.attribution==="automation"?"An Automation":"An agent",r=Object.keys(t),o=r.map(i=>({label:i,before:oe(e.current?.[i]),after:oe(t[i])}));return{title:`${n} proposes a change`,icon:"entity",impact:{level:"normal"},tone:"default",blocks:o.length>0?[{type:"diff",fields:o}]:[{type:"text",value:"No field changes.",muted:!0}],actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${r.join(", ")} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${r.join(", ")} was not applied.`}]}}function So(e){const t=e.action??"change",n=e.proposal?.slug??e.proposal?.name??(e.proposal?.automation_id!=null?String(e.proposal.automation_id):void 0)??e.current?.slug??e.current?.name??"automation",r=[];e.action==="delete"&&r.push({type:"text",value:"This will archive the Automation.",muted:!0});const o=e.proposal??{},i=Object.keys(o).filter(a=>!xo.has(a)&&o[a]!==void 0).map(a=>({label:a,...e.action==="update"&&e.current?.[a]!==void 0?{before:bt(e.current?.[a])}:{},after:bt(o[a])}));return r.push(i.length>0?{type:"diff",fields:i}:{type:"text",value:"No field changes.",muted:!0}),{title:`${Ge(t)} Automation ${n}`,icon:"automation",impact:Qe(e.action,"This archives the Automation and stops future runs."),tone:Je(e.action),blocks:r,actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${t} ${n} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${t} ${n} was not applied.`}]}}function To(e){return e.action==="merge"&&(e.resourceKind==="entity"||e.proposal?.entity_id!==void 0||e.proposal?.winner_entity_id!==void 0||e.current?.winner!==void 0)}function jo(e){if(e.resourceKind==="automation")return So(e);if(e.fields&&Object.keys(e.fields).length>0)return Ro(e,e.fields);if(e.resourceKind==="entity"||e.proposal?.entity_id!==void 0||e.current?.entity_type!==void 0||e.proposal?.entity_type!==void 0){const i=e.proposal?.name??e.current?.name??e.proposal?.entity_id??e.current?.id??"entity",a=e.action??"change",c=[];if(e.action==="delete")c.push({type:"text",value:"This will delete the entity.",muted:!0});else{const u=Object.keys(e.proposal??{}).filter(d=>!["entity_id","id"].includes(d)&&e.proposal?.[d]!==void 0&&oe(e.proposal?.[d])!==oe(e.current?.[d])).map(d=>({label:d,...e.action==="update"?{before:oe(e.current?.[d])}:{},after:oe(e.proposal?.[d])}));c.push(u.length>0?{type:"diff",fields:u}:{type:"text",value:"No field changes.",muted:!0})}return{title:`${Ge(a)} entity ${i}`,icon:"entity",impact:Qe(e.action,e.action==="merge"?"This combines duplicate records into the selected winner.":"This deletes the entity."),tone:Je(e.action),blocks:c,actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${a} ${i} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${a} ${i} was not applied.`}]}}const n=e.proposal?.agent_id??e.current?.id??"agent",r=e.action??"change",o=[];if(e.action==="delete")o.push({type:"text",value:"This will permanently delete the agent.",muted:!0});else{const i=wo.filter(a=>e.proposal?.[a]!==void 0&&oe(e.proposal?.[a])!==oe(e.current?.[a])).map(a=>({label:a,...e.action==="update"?{before:oe(e.current?.[a])}:{},after:oe(e.proposal?.[a])}));o.push(i.length>0?{type:"diff",fields:i}:{type:"text",value:"No field changes.",muted:!0})}return{title:`${Ge(r)} agent ${n}`,icon:"agent",impact:Qe(e.action,"This permanently deletes the agent and its configuration."),tone:Je(e.action),blocks:o,actions:[{id:"approve",label:"Approve",variant:"primary",icon:"check",tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved — ${r} ${n} is being applied.`},{id:"reject",label:"Reject",variant:"outline",icon:"x",confirm:!0,confirmPrompt:"Reject this change?",tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected — ${r} ${n} was not applied.`}]}}function Co(e,t){const n=[];e.args!==void 0&&e.args!==null&&n.push({type:"code",value:Ce(e.args)});const r=t.map(o=>({id:o,label:o==="always"?"Always allow":`Approve ${o}`,variant:"outline",tool:"approve_tool_request",args:{decision:o},resolvedLabel:o==="always"?"Approved — always allowed.":`Approved for ${o}.`}));return r.push({id:"deny",label:"Deny",variant:"ghost",tool:"approve_tool_request",args:{decision:"deny"},resolvedLabel:"Denied."}),{title:`Wants to run ${e.tool??"a tool"}`,icon:"tool",impact:{level:"high",reason:"This grants the agent permission to use a tool."},tone:"warning",blocks:n,actions:r}}function No(e){const t=Array.isArray(e.options)?e.options.filter(o=>typeof o=="string"):[],n=[{type:"text",value:e.question||"The agent has a question."}];t.length===0&&n.push({type:"text",value:"Reply below to answer.",muted:!0});const r=t.map(o=>({id:o,label:o,variant:"outline",tool:"answer_question",args:{answer:o},resolvedLabel:`Answered: ${o}`}));return{title:"Input needed",icon:"question",tone:"default",blocks:n,actions:r}}function Ao(e,t){return{tone:"bare",actions:[{id:"open",label:e.label??"Open link",variant:"outline",icon:"external",terminal:!1,href:t}]}}const Eo=({toolName:e,args:t})=>{const n=xn(),r=wn(),{append:o}=Ae(),i=Ye(),a=t??{},c=i?.resolve(e,t)??null;let u=c?.view??null;const d={...c?.handlers??{}},f=new Set;if(!c){if(e==="tool-approval"&&typeof a.runId=="number"){const y=a.runId,v=typeof a.status=="string"?a.status:"pending",m=v==="pending",R=To(a),O=R?lr(a):null,x=O?.view??jo(a),L=v==="rejected"?a.action==="merge"?"Kept separate":"Rejected":v==="failed"?"Failed":"Approved";u=m||R?x:{...x,title:`${x.title??"Approval"} · ${L}`,tone:v==="failed"?"warning":"default",blocks:[...x.blocks??[],{type:"text",value:typeof a.reviewedByName=="string"?`${L} by ${a.reviewedByName}.`:`${L}.`,muted:!0}],actions:(x.actions??[]).filter(j=>j.terminal===!1)},m&&(d.manage_operations=j=>{if(j.action==="approve")return yt(A=>n.mutate({run_id:y},A));if(j.action==="reject"){const A=typeof j.reason=="string"?j.reason:void 0;return yt(K=>r.mutate({run_id:y,...A?{reason:A}:{}},K))}return Promise.resolve(!0)});const k=O?.reviewUrls??new Set;for(const j of k)f.add(j);d.open_review_link=j=>{const A=typeof j.url=="string"?j.url:"";return!k.has(A)||!He(A)?Promise.resolve(!0):(window.open(A,"_blank","noopener,noreferrer"),Promise.resolve(!1))}}else if(e==="tool-approval"){const y=Array.isArray(a.durationOptions)&&a.durationOptions.every(m=>typeof m=="string")&&a.durationOptions.length>0?a.durationOptions:["1h","24h","always"],v=new Set([...y,"deny"]);u=Co(a,y),d.approve_tool_request=async m=>{const R=typeof m.decision=="string"?m.decision:"";if(!a.requestId||!a.approveUrl||!v.has(R))return!0;try{return!(await ze(a.approveUrl,{method:"POST",headers:{"Content-Type":"application/json",...a.orgSlug?{"x-lobu-org":a.orgSlug}:{}},credentials:"include",body:JSON.stringify({requestId:a.requestId,decision:R}),timeoutMs:2e4})).ok}catch{return!0}}}else if(e==="question"){const y=Array.isArray(a.options)?a.options.filter(v=>typeof v=="string"):[];u=No(a),d.answer_question=v=>{const m=typeof v.answer=="string"?v.answer:"";return y.includes(m)?(o(m),Promise.resolve(!1)):Promise.resolve(!0)}}else if(e==="link-button"){if(!He(a.url))return null;const y=a.url;f.add(y),u=Ao(a,y)}}return u?s.jsx(bo,{src:yo,title:u.title??"Interaction",renderPayload:u,onToolCall:(y,v)=>d[y]?d[y](v):Promise.resolve(!0),onOpenLink:y=>!f.has(y)||!He(y)?Promise.resolve(!0):(window.open(y,"_blank","noopener,noreferrer"),Promise.resolve(!1))}):null};function Ce(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}const ko=()=>{const{running:e,append:t,cancel:n,pendingAttachments:r,addAttachments:o,removeAttachment:i,initialDraft:a,currentSuggestions:c,executionTarget:u}=Ae(),d=_o({suggestions:e?null:c}),[f,y]=l.useState(a??""),v=l.useRef(null),m=l.useRef(null),R=On(Ln),O=l.useRef(a??"");l.useEffect(()=>{const k=a??"";if(k===O.current)return;const j=O.current;O.current=k,k!==""&&y(A=>A===""||A===j?k:A)},[a]);const x=l.useRef(f);x.current=f;const L=()=>{e||(t(x.current),y(""),m.current?.clear())};return s.jsxs("div",{className:"rounded-2xl border bg-background transition-colors focus-within:ring-1 focus-within:ring-ring",children:[!u&&r.length>0?s.jsx("div",{className:"flex flex-wrap gap-1.5 px-3 pt-3",children:r.map(k=>s.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg border bg-muted/50 px-2 py-1 text-xs",children:[s.jsx(We,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),s.jsx("span",{className:"max-w-[12rem] truncate",children:k.name}),s.jsx("button",{type:"button",className:"text-muted-foreground transition-colors hover:text-foreground","aria-label":"Remove attachment",onClick:()=>i(k.id),children:s.jsx(ln,{className:"h-3 w-3"})})]},k.id))}):null,s.jsx(Pn,{value:f,onChange:y,onSubmit:L,searchRefs:R,handleRef:m,placeholder:d,className:"max-h-48 overflow-y-auto"}),s.jsxs("div",{className:"flex items-center justify-between px-3 pb-2",children:[u?s.jsx("span",{className:"px-2 text-xs text-muted-foreground",children:"Running on your device"}):s.jsxs(s.Fragment,{children:[s.jsx("input",{ref:v,type:"file",multiple:!0,className:"hidden",onChange:k=>{k.target.files&&o(k.target.files),k.target.value=""}}),s.jsxs(ce,{type:"button",size:"icon",variant:"ghost",className:"h-8 w-8 rounded-full text-muted-foreground hover:text-foreground",onClick:()=>v.current?.click(),children:[s.jsx(We,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Attach files"})]})]}),e?s.jsxs(ce,{type:"button",size:"icon",variant:"secondary",className:"h-8 w-8 rounded-full",onClick:n,children:[s.jsx(an,{size:"lg"}),s.jsx("span",{className:"sr-only",children:"Cancel"})]}):s.jsxs(ce,{type:"button",size:"icon",className:"h-8 w-8 rounded-full",onClick:L,children:[s.jsx(cn,{className:"h-4 w-4"}),s.jsx("span",{className:"sr-only",children:"Send message"})]})]})]})};function _o({suggestions:e}){const t=e?.find(n=>n.message.trim().length>0)?.message;return t?`Recommended: ${t.trim()}`:"Chat… (@ to mention, / for commands)"}export{Fo as A,Uo as L,$o as R,Do as a,lr as b,Yn as h,Gn as s};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as t,a2 as o}from"./index-DtRfQcRH.js";const n=()=>t.jsx(o,{});export{n as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as s,gw as $,gx as N,cm as L,al as x,gy as M,gz as I,a4 as b,a5 as S,v as j,w,bz as k,r as D,a2 as O,gA as W,gB as P,c7 as E,gC as R,gD as z,a3 as y,g as F,L as G,p as H}from"./index-DtRfQcRH.js";import{A as U}from"./agent-editor-form-DwHD9j1Y.js";import{P as _}from"./proposal-review-shell-C3K-JXjb.js";function B({identity:e,sections:n,activeSection:t,activeItem:o,onSectionSelect:r,sectionLabel:c,highlightSection:l=!0,className:g}){const a=o??n.find(i=>i.key===t)??n[0];if(!a)return null;const d=a.icon;return s.jsx("div",{className:x("flex shrink-0 flex-col items-center px-4 lg:px-6",g),children:s.jsxs("div",{className:"flex min-w-0 max-w-full flex-wrap items-center justify-center gap-x-3 gap-y-2",children:[e,s.jsxs($,{children:[s.jsx(N,{asChild:!0,children:s.jsxs("button",{type:"button",className:x("inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-sm transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring",l?"bg-muted font-medium text-foreground":"text-muted-foreground hover:bg-muted/60 hover:text-foreground"),"aria-label":c,children:[s.jsx(d,{className:"h-3.5 w-3.5 shrink-0"}),a.label,s.jsx(L,{className:"h-3.5 w-3.5 shrink-0 opacity-60"})]})}),s.jsx(M,{align:"center",className:"min-w-[11rem]",children:n.map(({key:i,label:u,icon:m})=>s.jsxs(I,{className:x(i===t&&"bg-accent font-medium"),onSelect:()=>r(i),children:[s.jsx(m,{className:"h-4 w-4"}),s.jsx("span",{children:u})]},i))})]})]})})}const p=[{key:"skills",label:"Skills",icon:W},{key:"guardrails",label:"Guardrails",icon:P},{key:"permissions",label:"Permissions",icon:E,adminOnly:!0},{key:"models",label:"Models",icon:R},{key:"settings",label:"Settings",icon:z}];function T(e){return p.filter(n=>!n.adminOnly||e)}function q(e,n){if(n===`${e}/conversations`||n.startsWith(`${e}/conversations/`))return null;for(const{key:t}of p)if(n===`${e}/${t}`||n.startsWith(`${e}/${t}/`))return t;return n===`${e}/identity`||n===`${e}/identity/`?"settings":null}function J(e){return e.trim().charAt(0).toUpperCase()||"?"}function K({owner:e,agentId:n,agentName:t,activeDest:o}){const r=b(),{orgContext:c}=y(),{isAdmin:l}=F(c.organizationId),g=T(!!l),a=o??"settings",d=p.find(i=>i.key===a);return s.jsx(B,{identity:s.jsxs(G,{to:"/$owner/agents/$agentId/settings",params:{owner:e,agentId:n},search:{run_id:void 0},className:"flex min-w-0 items-center gap-2 rounded-md outline-none transition-colors hover:opacity-90 focus-visible:ring-2 focus-visible:ring-ring",title:"Agent settings",children:[s.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-muted text-xs font-semibold text-foreground",children:J(t)}),s.jsx("h1",{className:"min-w-0 truncate text-base font-semibold tracking-tight",children:t})]}),sections:g,activeSection:a,activeItem:d,sectionLabel:"Agent section",highlightSection:o!==null,onSectionSelect:i=>{r({to:`/$owner/agents/$agentId/${i}`,params:{owner:e,agentId:n}})}})}function Z({owner:e,agentId:n}){const t=b(),{pathname:o}=S(),{isAuthenticated:r}=j(),{isMember:c}=w(),l=r&&c,{data:g=[],isLoading:a}=k({enabled:l}),d=g.find(C=>C.agentId===n)??null,i=!d&&!a&&l,u=`/${e}/agents/${n}`,m=`${u}/conversations`,f=o===m||o.startsWith(`${m}/`),h=q(u,o);D.useEffect(()=>{i&&t({to:"/$owner",params:{owner:e},replace:!0})},[i,t,e]);const A=d?.name??"Agent";return s.jsxs("div",{className:"flex min-h-0 flex-1 flex-col gap-3 overflow-hidden py-4 md:py-6",children:[s.jsx(K,{owner:e,agentId:n,agentName:A,activeDest:h}),s.jsx("div",{className:x("flex min-h-0 min-w-0 flex-1 flex-col px-4 lg:px-6",f?"overflow-hidden":"overflow-y-auto"),children:s.jsx(O,{})})]})}function Q({agent:e,tab:n,runId:t}){return s.jsx("div",{className:"mx-auto w-full max-w-3xl pb-6",children:s.jsx(_,{resource:{kind:"agent",agentId:e.agentId},runId:t,children:({reviewMode:o,proposal:r,controlsDisabled:c})=>s.jsx(U,{mode:{kind:"edit",agent:e},section:n,reviewMode:o,reviewProposal:r,reviewControlsDisabled:c},e.agentId)})})}function ee({owner:e,agentId:n,tab:t,runId:o}){const{orgContext:r,hasOrgContext:c}=y(),{isLoading:l}=H(`/${e}`,r),{isAuthenticated:g}=j(),{isMember:a,isLoading:d}=w(),i=g&&a,{data:u=[],isLoading:m}=k({enabled:i}),v=i?!c||l||m||d:l||d,f=u.find(h=>h.agentId===n)??null;return v||!f?null:s.jsx(Q,{agent:f,tab:t,runId:o})}export{Z as A,ee as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as j,j as e,S as A,ds as O,dt as L,du as D,dv as M,dw as B,dx as F,t as U,dy as H,M as S,a3 as J,p as K,v as V,w as W,dz as z,dA as w,B as P,L as T,dB as $,al as X,aV as Y,dC as G}from"./index-DtRfQcRH.js";import{C as q,A as Q}from"./create-automation-form-De8J-JD5.js";import{P as Z}from"./proposal-review-shell-C3K-JXjb.js";import{J as R}from"./json-diff-DYeX-xLk.js";import{u as ee,a as te}from"./deployments-D1gbQwsy.js";import{A as ne}from"./agent-loading-shells-BQLjzMPy.js";import{b as oe,a as se,s as ae,h as re,R as ie,A as le}from"./agent-thread-D7AGGjRV.js";import{E as ue}from"./events-feed-C4L8mQV7.js";const ce=20;function C({automationId:t}){const n=ee({resourceKind:"automation",resourceId:t}),[s,r]=j.useState(null),u=te(s!=null?String(s):null),d=(n.data?.pages.length??0)>=ce&&!!n.hasNextPage,o=!!n.isFetchNextPageError;j.useEffect(()=>{!d&&n.hasNextPage&&!n.isFetchingNextPage&&!n.isError&&!o&&n.fetchNextPage()},[d,n.fetchNextPage,n.hasNextPage,n.isFetchingNextPage,n.isError,o]);const f=j.useMemo(()=>(n.data?.pages??[]).flatMap(c=>c.items).filter(c=>c.type==="change"&&c.resourceKind==="automation"&&c.resourceId===String(t)),[n.data,t]),i=!!n.hasNextPage&&!d,p=typeof n.refetch=="function",m=typeof n.fetchNextPage=="function";return n.isLoading?e.jsx(A,{className:"h-20 w-full rounded-lg"}):n.isError&&!o?e.jsxs("section",{className:"space-y-2","aria-label":"Automation definition history","data-testid":"automation-definition-history",children:[e.jsx("h3",{className:"font-medium text-sm",children:"Definition history"}),e.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"automation-definition-history-error",children:"Definition history unavailable."}),p?e.jsx("button",{type:"button",className:"text-sm underline","data-testid":"automation-definition-history-retry",onClick:()=>void n.refetch(),children:"Retry"}):null]}):e.jsxs("section",{className:"space-y-2","aria-label":"Automation definition history","data-testid":"automation-definition-history",children:[e.jsx("h3",{className:"font-medium text-sm",children:"Definition history"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Runtime and delivery configuration changes with actor and before/after. Content versions (prompt, sources) are listed separately."}),f.length===0&&!i?e.jsx("p",{className:"py-4 text-sm text-muted-foreground","data-testid":"automation-definition-history-empty",children:"No definition changes recorded yet."}):e.jsx("ul",{className:"space-y-1","data-testid":"automation-definition-history-list",children:f.map(a=>{if(a.type!=="change")return null;const l=a.createdBy??a.agentId??a.actorSource??"unknown";return e.jsx("li",{children:e.jsxs("button",{type:"button",className:"flex w-full flex-wrap items-center justify-between gap-2 rounded-lg border border-border/60 px-3 py-2 text-left text-sm hover:bg-muted/50",onClick:()=>r(c=>c===a.id?null:a.id),"data-testid":`automation-definition-history-item-${a.id}`,children:[e.jsx("span",{className:"font-medium",children:a.action??a.op??"change"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:(a.changedFields??[]).join(", ")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:l}),e.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(a.createdAt).toLocaleString()})]})},a.id)})}),i?e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"automation-definition-history-loading-more",children:"Loading more history…"}):null,d?e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"automation-definition-history-capped",children:"Showing recent definition changes"}):null,o?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground","data-testid":"automation-definition-history-page-error",children:"Couldn't load more history."}),m?e.jsx("button",{type:"button",className:"text-xs underline","data-testid":"automation-definition-history-retry-next",onClick:()=>void n.fetchNextPage(),children:"Retry"}):null]}):null,s!=null?e.jsx("div",{"data-testid":"automation-definition-history-detail",children:u.isLoading?e.jsx(A,{className:"h-24 w-full rounded-lg"}):u.isError?e.jsx("p",{className:"text-sm text-muted-foreground","data-testid":"automation-definition-history-detail-error",children:"Change detail unavailable."}):u.data?e.jsx(R,{before:u.data.before,after:u.data.after}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Change detail unavailable."})}):null]})}const E=Symbol("trusted-automation-interaction");function _(t){return Object.defineProperty(t,E,{value:!0}),t}function de(t){return{title:`${t} items waiting for you`,icon:"entity",impact:{level:"normal"},tone:"default",blocks:[{type:"text",value:"Review the individual proposals below, or decide the whole run at once.",muted:!0}],actions:[{id:"approve-all",label:"Approve all",variant:"primary",icon:"check",confirm:!0,confirmPrompt:`Approve all ${t} proposals?`,tool:"manage_operations",args:{action:"approve"},resolvedLabel:`Approved all ${t} proposals.`},{id:"reject-all",label:"Keep all separate",variant:"outline",icon:"x",confirm:!0,confirmPrompt:`Reject all ${t} proposals?`,tool:"manage_operations",args:{action:"reject"},resolvedLabel:`Rejected all ${t} proposals.`}]}}const me=new Set(["entity-merge-approval","automation-approval-batch","entity-merge-result"]);function N(t){return new Promise(n=>{t({onSettled:(s,r)=>n(!!r)})})}function I(t){try{return new URL(t,window.location.origin).origin===window.location.origin}catch{return!1}}function pe(){const t=O(),n=L(),s=D(),r=M(),u=B();return j.useMemo(()=>({toolNames:me,resolve:(h,d)=>{if(!d||typeof d!="object"||d[E]!==!0)return null;const o=d;if(h==="automation-approval-batch"){const m=typeof o.runId=="number"&&Number.isSafeInteger(o.runId)&&o.runId>0?o.runId:null,a=typeof o.count=="number"&&Number.isSafeInteger(o.count)&&o.count>1?o.count:null,l=Array.isArray(o.runIds)?o.runIds.filter(c=>typeof c=="number"&&Number.isSafeInteger(c)&&c>0):[];return m===null||a===null||l.length!==a||new Set(l).size!==a?null:{view:de(a),handlers:{manage_operations:c=>c.action!=="approve"&&c.action!=="reject"?Promise.resolve(!0):N(y=>c.action==="approve"?t.mutate({run_id:m,run_ids:l},y):n.mutate({run_id:m,run_ids:l},y))}}}if(h==="entity-merge-approval"){const m=typeof o.runId=="number"&&Number.isSafeInteger(o.runId)&&o.runId>0?o.runId:null;if(m===null||o.action!=="merge"||o.resourceKind!=="entity")return null;const a=oe(o),l=(o.status??"pending")==="pending";return{view:a.view,handlers:{open_review_link:c=>{const y=typeof c.url=="string"?c.url:"";return!a.reviewUrls.has(y)||!I(y)?Promise.resolve(!0):(window.open(y,"_blank","noopener,noreferrer"),Promise.resolve(!1))},...l?{manage_operations:c=>c.action==="approve"?N(y=>s.mutate({run_id:m},y)):c.action==="reject"?N(y=>r.mutate({run_id:m},y)):Promise.resolve(!0)}:{}}}}if(h!=="entity-merge-result")return null;const f=o.loser&&typeof o.loser=="object"?o.loser:null,i=typeof f?.id=="number"?f.id:null;if(i===null)return null;const p=se(o);return{view:p.view,handlers:{open_review_link:m=>{const a=typeof m.url=="string"?m.url:"";return!p.reviewUrls.has(a)||!I(a)?Promise.resolve(!0):(window.open(a,"_blank","noopener,noreferrer"),Promise.resolve(!1))},manage_entity:()=>N(m=>u.mutate({entityId:i},m))}}}}),[s,t,r,n,u])}function ge(t){const n=[];return t.forEach((s,r)=>{n.push({id:`sep:${s.runId}`,role:"system",parts:[{type:"text",text:fe(s,r)}],createdAt:s.completedAt?new Date(s.completedAt).getTime():void 0});for(const u of s.messages)n.push({...u,id:`r${s.runId}:${u.id}`})}),n}function fe(t,n){const s=(t.pendingActionCount??0)>0?`Waiting for you (${t.pendingActionCount})`:t.status==="completed"?"Completed":t.status??"Completed",r=(t.autoAppliedCount??0)>0?` · ${t.autoAppliedCount} applied automatically`:"",u=t.completedAt?new Date(t.completedAt).toLocaleString():null;return u?`Run ${n+1} · ${s}${r} · ${u}`:`Run ${n+1} · ${s}${r}`}const he=/(?:^|\n)Run this Automation now/;function xe(t){return t.role==="user"&&t.parts.some(n=>n.type==="text"&&he.test(n.text))}function ye(t){return`history-interaction:${t.runId}:${t.eventId??"error"}`}function ve({agentId:t,automationId:n,ownerSlug:s,runId:r}){const{data:u,isLoading:h}=F(t,n,{orgSlug:s}),d=pe(),o=U(),f=j.useCallback(p=>{o?.open({href:`/${s}/automations/${n}?run_id=${p}`,title:`Automation run #${p}`,runId:p})},[o,s,t,n]),i=j.useMemo(()=>{const p=u?.runs??[],a=(r!=null?p.filter(l=>l.runId===r):p).slice().reverse();return ge(a.map(l=>{const c=l.messages.map(g=>ae(g,{showToolCalls:!0})).filter(g=>g!==null&&!xe(g));l.task?.trim()&&c.unshift({id:"task",role:"user",parts:[{type:"text",text:l.task.trim()}]});for(const g of l.automaticActions??[]){const v=x=>H(s,[...x.parentEntityType&&x.parentSlug?[{entity_type:x.parentEntityType,slug:x.parentSlug}]:[],{entity_type:x.entityType,slug:x.slug}]);c.push({id:`automatic-action:${g.operationId}`,role:"assistant",parts:[{type:"tool-call",toolCallId:`automatic-action-${g.operationId}`,toolName:"entity-merge-result",args:_({...g,loserHref:v(g.loser),winnerHref:v(g.winner)})}]})}const y=l.actions??[],b=y.filter(g=>g.status==="pending");if(b.length>1){const g=b.map(v=>v.runId).sort((v,x)=>v-x);c.push({id:"approval-batch",role:"assistant",parts:[{type:"tool-call",toolCallId:`approval-batch-${l.runId}`,toolName:"automation-approval-batch",args:_({runId:l.runId,count:b.length,runIds:g})}]})}for(const g of y){const v=re([g],{workspaceSlug:s,agentId:t,webOrigin:typeof window>"u"?null:window.location.origin});v&&c.push({...v,id:ye(g),parts:v.parts.map(x=>x.type==="tool-call"&&x.toolName==="tool-approval"&&g.action==="merge"&&g.resourceKind==="entity"?{...x,toolName:"entity-merge-approval",args:_({...x.args})}:x)})}return{runId:l.runId,completedAt:l.completedAt,status:l.status,pendingActionCount:l.pendingActionCount,autoAppliedCount:l.autoAppliedCount,messages:c}}))},[t,u,s,r]);return h?e.jsx(ne,{readOnly:!0}):i.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No run transcripts yet. Recent runs will show here when the Automation fires (failed runs appear with their prompt even without a full transcript)."}):e.jsx("div",{className:"flex h-[calc(100dvh-12rem)] min-h-[24rem] min-w-0 flex-1 flex-col",children:e.jsx(ie,{messages:i,children:e.jsx(le,{readOnly:!0,readerPositionMode:"runs",interactionExtension:d,onRunSelect:r==null&&o?f:void 0})})})}function k(t){const{orgContext:n,hasOrgContext:s}=J(),{data:r,isLoading:u}=K(`/${t}`,n),{isAuthenticated:h}=V(),{isMember:d,isLoading:o}=W(),f=h&&d,i=r?.workspace,p=f?!s||u||o:u||o;return{organizationId:i?.id??"",isLoading:p}}function Re(t){return k(t)}function je({owner:t,automationId:n,organizationId:s}){const{data:r,isLoading:u}=z(n,s),h=r?.length??0,d=h>w,o=Math.min(h,w),f=new Set(r?.map(l=>l.entity_type).filter(Boolean)??[]),i=!d&&f.size===1?[...f][0]:null;if(u)return e.jsx(A,{className:"h-10 w-full rounded-lg"});if(o===0)return null;const p=d?`${w}+`:String(o),m=i!=null?`${p} ${i} ${o===1?"entity":"entities"} built by this automation`:`${p} ${o===1?"entity":"entities"} built by this automation`,a=i!=null?G(t,i):{to:"/$owner/data",params:{owner:t},search:{}};return e.jsxs("div",{className:X(Y,"flex flex-wrap items-center justify-between gap-2 px-3 py-2.5 text-sm"),children:[e.jsx("span",{className:"text-muted-foreground",children:m}),e.jsx(P,{asChild:!0,variant:"ghost",size:"sm",className:"h-7 gap-1",children:e.jsxs(T,{to:a.to,params:a.params,search:a.search,children:["View in Memory",e.jsx($,{className:"h-3.5 w-3.5"})]})})]})}function Ne({owner:t,automationId:n,organizationId:s}){const r=Number(n),u=j.useMemo(()=>({producedByAutomationId:r}),[r]);return Number.isFinite(r)?e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-medium text-sm",children:"Produced by this Automation"}),e.jsx(P,{asChild:!0,variant:"ghost",size:"sm",className:"h-7 gap-1",children:e.jsxs(T,{to:"/$owner/events",params:{owner:t},search:{produced_by:String(r)},children:["Open in Activity",e.jsx($,{className:"h-3.5 w-3.5"})]})})]}),e.jsx(ue,{organizationId:s,ownerSlug:t,filters:u,emptyState:e.jsx("p",{className:"py-6 text-sm text-muted-foreground",children:"This Automation hasn't written anything yet. Events it creates, entities it changes and notifications it sends will appear here."})})]}):null}function Ae({agentId:t,owner:n,automationId:s,organizationId:r}){return e.jsxs("div",{className:"space-y-4",children:[r?e.jsx(je,{owner:n,automationId:s,organizationId:r}):null,t?e.jsx(ve,{agentId:t,automationId:s,ownerSlug:n}):e.jsx("p",{className:"rounded-lg border border-border/60 px-3 py-2.5 text-sm text-muted-foreground",children:"Runs execute on the automation's executor, so there is no agent transcript to show. What it produced is below."}),r?e.jsx(Ne,{owner:n,automationId:s,organizationId:r}):null]})}function be({agentId:t,automationId:n,runId:s,organizationId:r,onDone:u}){const[h,d]=j.useState({ready:!1,triggers:[]}),o=j.useCallback(a=>{d(l=>JSON.stringify(l)===JSON.stringify(a)?l:a)},[]),f=S(n,void 0,r,{includeVersions:!0}),i=f.data?.automation,p=e.jsx("div",{className:"flex flex-col gap-4",children:[0,1,2].map(a=>e.jsx(A,{className:"h-16 w-full rounded-lg"},a))}),m=f.isLoading?p:i?e.jsx(q,{organizationId:r,prefillAgentId:t??void 0,editingAutomation:{automation_id:i.automation_id,name:i.automation_name,slug:i.slug,description:i.description,prompt:i.prompt,sources:i.sources,reaction_script:i.reaction_script,managed_agent_id:i.managed_agent_id,device_worker_id:i.device_worker_id,agent_kind:i.agent_kind,delivery_target:i.delivery_target??void 0,execution_config:i.execution_config??void 0,keying_config:i.keying_config,reactions_guidance:i.reactions_guidance,triggers:i.triggers},createFields:{triggers:h.triggers},triggerFields:e.jsx(Q,{organizationId:r,initialTriggers:i.triggers??[],onChange:o},JSON.stringify(i.triggers??[])),hideHeader:!0,hideCancel:!0,submitDisabled:!h.ready,onClose:u,onSuccess:u}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Automation not found. It may have been removed."});return t?e.jsxs("div",{className:"space-y-6",children:[e.jsx(Z,{resource:{kind:"automation",agentId:t,automationId:n},runId:s,onDone:u,children:({reviewMode:a,proposal:l})=>a==="active"?e.jsx(R,{before:l?.current??null,after:{...l?.current??{},...l?.proposedAfter??{}}}):a==="loading"?p:a==="error"?null:m}),e.jsx(C,{automationId:n})]}):e.jsxs("div",{className:"space-y-6",children:[m,e.jsx(C,{automationId:n})]})}function Ee({owner:t,agentId:n,automationId:s,view:r,runId:u,onDone:h}){const{organizationId:d}=k(t),o=S(s,void 0,d),f=n??o.data?.automation?.managed_agent_id??null;return u||r==="definition"?e.jsx(be,{agentId:f,automationId:s,runId:u,organizationId:d,onDone:h}):e.jsx(Ae,{agentId:f,owner:t,automationId:s,organizationId:d})}export{ve as A,Ee as a,Re as u};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as t,a2 as o}from"./index-DtRfQcRH.js";const n=()=>t.jsx(o,{});export{n as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a4 as a,v as i,r as n,j as t}from"./index-DtRfQcRH.js";function r(){const s=a(),{isReady:e}=i();return n.useEffect(()=>{e&&setTimeout(()=>{s({to:"/"})},500)},[e,s]),t.jsx("div",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center",children:t.jsx("div",{className:"text-center",children:t.jsx("p",{className:"text-muted-foreground",children:e?"Redirecting...":"Completing sign in..."})})})}export{r as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as t,a2 as o}from"./index-DtRfQcRH.js";const n=()=>t.jsx(o,{});export{n as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{hK as r,j as t,aY as a}from"./index-DtRfQcRH.js";import{a as s}from"./agent-connect-pages-DkDlFVY5.js";import"./agent-client-setup-list-BBbq_2B1.js";import"./clients-C7ubnFsS.js";import"./client-rows-EJSKR6z1.js";function x(){const{owner:e,clientId:o}=r.useParams();return t.jsx(a,{owner:e,children:({ownerSlug:n})=>t.jsx(s,{owner:n,clientId:o})})}export{x as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a4 as D,j as e,eO as _,eP as $,eQ as k,eR as c,eS as M,eT as o,L as b,hI as z,ah as K,E as H,Y as G,a3 as O,g as Q,r as m,d4 as I,S as w,ct as Y,eH as f,B as y,s as J,h0 as V,gg as W,bS as q,gh as F,gi as X,hJ as Z,aY as ee}from"./index-DtRfQcRH.js";import{u as P,a as se}from"./clients-C7ubnFsS.js";import{g as T,r as te}from"./client-rows-EJSKR6z1.js";function L(a,n){return{client_ids:a.join(","),mcp_activity_id:n}}function A(a){const n=a.title?.trim();return n||(a.activityKind==="session"?"MCP session":a.clientId)}function R({scopes:a,clientIds:n}){const l=D(),d=t=>{l({to:"/$owner/events",params:{owner:"me"},search:L(n,t.activityId)})};return e.jsx("div",{className:"rounded-lg border",children:e.jsxs(_,{children:[e.jsx($,{children:e.jsxs(k,{children:[e.jsx(c,{className:"px-3 py-1.5 text-xs",children:"Conversation"}),e.jsx(c,{className:"px-3 py-1.5 text-xs",children:"Calls"}),e.jsx(c,{className:"px-3 py-1.5 text-xs",children:"Last action"}),e.jsx(c,{className:"px-3 py-1.5 text-xs",children:"Last active"}),e.jsx(c,{className:"w-8 px-3 py-1.5"})]})}),e.jsx(M,{children:a.map(t=>e.jsxs(k,{className:"cursor-pointer transition-colors hover:bg-accent/50",onClick:()=>d(t),children:[e.jsx(o,{className:"max-w-0 px-3 py-2 text-xs font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{to:"/$owner/events",params:{owner:"me"},search:L(n,t.activityId),onClick:r=>r.stopPropagation(),className:"truncate hover:underline",children:A(t)}),t.activityKind==="session"?e.jsx(z,{isLive:t.isLive}):null,t.unreadNotificationCount>0?e.jsxs(K,{variant:"secondary",className:"shrink-0 text-[10px]",children:[t.unreadNotificationCount," unread"]}):null]})}),e.jsx(o,{className:"px-3 py-2 font-mono text-xs text-muted-foreground",children:t.callCount}),e.jsx(o,{className:"max-w-0 truncate px-3 py-2 text-xs text-muted-foreground",children:t.lastAction||"—"}),e.jsx(o,{className:"px-3 py-2 text-xs text-muted-foreground",children:H(t.lastCallAt)}),e.jsx(o,{className:"px-3 py-2 text-right",children:e.jsx("button",{type:"button","aria-label":`View ${A(t)} activity`,className:"text-muted-foreground hover:text-foreground",tabIndex:-1,children:e.jsx(G,{className:"h-3.5 w-3.5"})})})]},`${t.clientId}:${t.activityId}`))})]})})}function ne({ownerSlug:a,clientId:n}){const{orgContext:l}=O(),{isAdmin:d}=Q(l.organizationId),{data:t=[],isLoading:r}=P(null),x=se(),[B,h]=m.useState(!1),s=m.useMemo(()=>T(t),[t]).find(i=>i.clientIds.includes(n)),N=s?.clientIds??[],g=I({enabled:!!s,limit:100,clientIds:N,activityKind:"conversation"}),p=I({enabled:!!s,limit:100,clientIds:N,activityKind:"session",refetchInterval:i=>i?5e3:!1}),u=g.data??[],v=p.data??[],E=m.useMemo(()=>t.filter(i=>s?.clientIds.includes(i.id)),[t,s]);if(r)return e.jsxs("div",{className:"space-y-4",children:[e.jsx(w,{className:"h-16 w-full rounded-lg"}),e.jsx(w,{className:"h-24 w-full rounded-lg"})]});if(!s)return e.jsx("p",{className:"text-sm text-muted-foreground",children:"This app isn't connected to this workspace, so its details aren't available."});const j=E[0],C=j?.details?.redirectUris??[],S=s.linkedUserEntitySlug?Y(a,[{entity_type:"$member",slug:s.linkedUserEntitySlug}]):null,U=[{label:"Registered",value:s.title},{label:s.clientIds.length===1?"Client ID":"Client IDs",value:e.jsx("div",{className:"space-y-1",children:s.clientIds.map(i=>e.jsx("code",{className:"block break-all",children:i},i))})},...s.drivenBy&&s.drivenBy!==s.title?[{label:"Driven by",value:s.drivenBy}]:[],...j?.platform?[{label:"Software",value:j.platform}]:[],...C.length>0?[{label:"Redirects",value:C.join(", ")}]:[],{label:"Granted by",value:S&&s.linkedUser?e.jsx(b,{to:S,className:"font-medium text-primary hover:underline",children:s.linkedUser}):s.linkedUser??"—"},{label:"Last active",value:s.connected?te(s.lastSeenAt):"disconnected"},{label:"Registrations",value:String(s.clientIds.length)}];return e.jsxs("div",{className:"space-y-7",children:[e.jsx(f,{title:"Settings",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"overflow-hidden rounded-lg border text-xs",children:e.jsx("dl",{className:"divide-y",children:U.map(i=>e.jsxs("div",{className:"flex gap-3 px-3 py-2",children:[e.jsx("dt",{className:"w-28 shrink-0 text-muted-foreground",children:i.label}),e.jsx("dd",{className:"min-w-0 flex-1 break-words",children:i.value})]},i.label))})}),d&&s.connected?e.jsxs("div",{className:"space-y-2 rounded-lg border p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Revoking disconnects every registration this app holds",s.clientIds.length>1?` (${s.clientIds.length} of them)`:""," ","and kills its live sessions. It can reconnect by authorizing again."]}),B?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{variant:"destructive",size:"sm",className:"h-7 px-2 text-xs",disabled:x.isPending,onClick:()=>x.mutate({clientId:s.clientIds[0],scope:"all"},{onSettled:()=>h(!1)}),children:x.isPending?"Revoking…":"Confirm revoke"}),e.jsx(y,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs",disabled:x.isPending,onClick:()=>h(!1),children:"Cancel"})]}):e.jsx(y,{variant:"outline",size:"sm",className:"h-7 px-2 text-xs text-destructive hover:text-destructive",onClick:()=>h(!0),children:"Revoke"})]}):null]})}),e.jsx(f,{title:"Conversations",count:u.length>0?String(u.length):void 0,children:g.isLoading||p.isLoading?e.jsxs("div",{className:"flex items-center py-4 text-xs text-muted-foreground",children:[e.jsx(J,{className:"mr-2"})," Loading client activity…"]}):g.isError||p.isError?e.jsx("p",{className:"py-3 text-xs text-destructive",children:"Could not load this app's activity."}):u.length===0?e.jsx("p",{className:"py-3 text-xs text-muted-foreground",children:"No recent conversations."}):e.jsx(R,{scopes:u,clientIds:s.clientIds})}),v.length>0?e.jsx(f,{title:"Sessions",count:String(v.length),children:e.jsx(R,{scopes:v,clientIds:s.clientIds})}):null]})}const ae="flex min-h-0 flex-1 flex-col gap-3 px-4 pt-4 pb-8 lg:px-6";function ie({owner:a,clientId:n}){const{data:l=[]}=P(null),t=m.useMemo(()=>T(l).find(r=>r.clientIds.includes(n)),[n,l])?.title??"Connected agent";return e.jsx("div",{className:ae,children:e.jsx(V,{header:e.jsx(W,{breadcrumb:e.jsx(F,{crumbs:[e.jsx(b,{to:"/$owner/agents",params:{owner:a},className:X,children:"Agents"},"agents")]}),icon:e.jsx("span",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md border",children:e.jsx(q,{name:t})}),title:t,caption:"An external agent connected to this workspace through Lobu. Review its Lobu conversations, activity, and access."}),children:e.jsx(ne,{ownerSlug:a,clientId:n},n)})})}function de(){const{owner:a,clientId:n}=Z.useParams();return e.jsx(ee,{owner:a,children:({ownerSlug:l})=>e.jsx(ie,{owner:l,clientId:n})})}export{de as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{bW as T,a9 as U,r as l,ap as _,ai as z,j as e,s as y,B as x,bX as A,bY as V,bZ as W,b_ as Y,b$ as P,ad as F,aw as K,ae as M}from"./index-DtRfQcRH.js";import{C as q,a as B,b as D,c as G}from"./card-4Ull9W6d.js";const j="__new_org__";function H(r){return r.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function C(r){return r.length>0?r[0].toUpperCase()+r.slice(1):r}function J(r,i){return r==="not_admin"?`You must be an admin or owner to connect ${i} to Lobu.`:`You don't have permission to connect ${i} to Lobu.`}function L(r,i,t){switch(r){case"not_authorized":return J(i,t);case"no_pending":return`No Lobu install was found for ${t}. Add Lobu from the marketplace to get started.`;case"no_org":return`Your account has no Lobu organization to connect ${t} to.`;default:return`Something went wrong while connecting ${t}. Please try again.`}}function ee(){const{name:r}=T({from:"/connector/$name/connection"}),{ref:i}=U({from:"/connector/$name/connection"}),[t,o]=l.useState({kind:"loading"}),[d,b]=l.useState(""),[v,E]=l.useState(""),[g,w]=l.useState(!1),[k,m]=l.useState(null),[h,f]=l.useState(null),u=C(r),a=t.kind==="confirm"&&t.subjectKind||"connection",I=t.kind==="confirm"&&t.subjectName?t.subjectName:`this ${u} ${a}`,S=l.useCallback(async()=>{if(!i){o({kind:"error",message:"This connection link is missing its reference."});return}o({kind:"loading"});try{const n=await(await _(`${z}/api/connector/${encodeURIComponent(r)}/connection/claim-context?ref=${encodeURIComponent(i)}`,{credentials:"include"})).json();if("error"in n){if(n.error==="unauthenticated"){o({kind:"signin",signinProvider:r});return}if(n.error==="signin_required"){o({kind:"signin",signinProvider:n.signinProvider??r});return}o({kind:"error",message:L(n.error,n.code,`this ${u} ${a}`)});return}if("alreadyConnected"in n){o({kind:"already_connected",orgSlug:n.orgSlug});return}b(n.orgs[0]?.slug??""),o({kind:"confirm",subjectKind:n.subjectKind,subjectName:n.subjectName,orgs:n.orgs})}catch{o({kind:"error",message:"We couldn’t load this connection link. Please try again."})}},[r,i,u]);l.useEffect(()=>{S()},[S]);const O=async c=>{await K.social({provider:c,callbackURL:window.location.href})},$=async(c=!1)=>{if(!(!i||!d)){w(!0),m(null),f(null);try{let n=d;if(d===j){const N=v.trim();if(!N){m("Enter a name for the new organization.");return}const p=await M.create({name:N,slug:H(N)});if(p.error||!p.data){m(p.error?.message??"Couldn’t create the organization.");return}n=p.data.slug}const s=await(await _(`${z}/api/connector/${encodeURIComponent(r)}/connection/claim`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({ref:i,org:n,confirmMove:c})})).json();if("error"in s){if(s.error==="signin_required"){o({kind:"signin",signinProvider:s.signinProvider??r});return}if((s.error==="already_connected_elsewhere"||s.error==="enterprise_scope_overlap")&&s.existing){f({kind:s.error,existing:s.existing});return}m(L(s.error,s.code,`this ${u} ${a}`));return}window.location.href=s.orgSlug?`/${s.orgSlug}/connectors/${encodeURIComponent(r)}?connected=1`:"/"}catch{m(`Something went wrong while connecting this ${a}. Please try again.`)}finally{w(!1)}}},R=t.kind==="signin"?"Sign in to continue":t.kind==="error"?`Can’t connect this ${a}`:t.kind==="already_connected"?"Already connected":`Connect ${u} to Lobu`;return e.jsx("div",{className:"min-h-[calc(100vh-3.5rem)] flex items-center justify-center",children:e.jsx("div",{className:"w-full max-w-md p-8",children:e.jsxs(q,{children:[e.jsx(B,{children:e.jsx(D,{asChild:!0,children:e.jsx("h1",{children:R})})}),e.jsxs(G,{children:[t.kind==="loading"&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-6 text-sm text-muted-foreground",children:[e.jsx(y,{size:"lg"}),e.jsx("span",{children:"Checking this connection link…"})]}),t.kind==="error"&&e.jsx("div",{className:"rounded-lg bg-destructive/10 px-3 py-2 text-sm text-destructive",children:t.message}),t.kind==="already_connected"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This ",u," ",a," is already connected to Lobu."]}),e.jsx(x,{className:"w-full",asChild:!0,children:e.jsx("a",{href:t.orgSlug?`/${t.orgSlug}/connectors/${encodeURIComponent(r)}`:"/",children:"Open Lobu"})})]}),t.kind==="signin"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Sign in with ",C(t.signinProvider)," to verify you can connect this ",a,"."]}),e.jsxs(x,{className:"w-full",onClick:()=>O(t.signinProvider),children:["Sign in with ",C(t.signinProvider)]})]}),t.kind==="confirm"&&(()=>{const c=t.subjectName||I;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Connecting"," ",e.jsx("strong",{className:"font-medium text-foreground",children:c}),". Choose the organization to connect it to:"]}),e.jsxs(A,{value:d,onValueChange:n=>{f(null),b(n)},children:[e.jsx(V,{children:e.jsx(W,{placeholder:"Select an organization"})}),e.jsxs(Y,{children:[t.orgs.map(n=>e.jsxs(P,{value:n.slug,children:[n.name,n.isPersonal&&e.jsx("span",{className:"ml-1 text-muted-foreground",children:"(personal)"})]},n.id)),e.jsx(P,{value:j,children:"+ New organization"})]})]}),d===j&&e.jsx(F,{autoFocus:!0,value:v,onChange:n=>E(n.target.value),placeholder:"New organization name","aria-label":"New organization name"}),k&&e.jsx("div",{className:"rounded-lg bg-destructive/10 px-3 py-2 text-sm text-destructive",children:k}),h&&(()=>{const n=h.existing.orgName??h.existing.orgSlug??"another organization";return h.kind==="already_connected_elsewhere"?e.jsxs("div",{className:"space-y-3 rounded-lg border border-border bg-muted/40 px-3 py-3",children:[e.jsxs("p",{className:"text-sm text-foreground",children:[c," is already connected in"," ",e.jsx("strong",{className:"font-medium",children:n}),". Move it here?"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(x,{className:"flex-1",onClick:()=>$(!0),disabled:g,children:g?e.jsxs(e.Fragment,{children:[e.jsx(y,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Moving…"})]}):"Move it here"}),e.jsx(x,{className:"flex-1",variant:"outline",onClick:()=>f(null),disabled:g,children:"Cancel"})]})]}):e.jsxs("div",{className:"rounded-lg bg-destructive/10 px-3 py-2 text-sm text-destructive",children:["This ",u," Enterprise Grid is already connected in"," ",e.jsx("strong",{className:"font-medium",children:n}),"; connecting this ",a," here may change how its messages route. Contact support to move it."]})})(),e.jsx(x,{className:"w-full",onClick:()=>$(),disabled:g||h!==null||!d||d===j&&!v.trim(),children:g?e.jsxs(e.Fragment,{children:[e.jsx(y,{size:"lg"}),e.jsx("span",{className:"ml-2",children:"Connecting…"})]}):`Connect ${c}`})]})})()]})]})})})}export{ee as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{dO as K,r as o,j as e,cv as U,cw as q,aR as W,al as C,B as b,dI as X,ey as G,k as M,ed as w,dH as F,bX as J,bY as Y,bZ as Z,b_ as Q,b$ as ee,dF as O,F as R,dT as se,s as E,ez as te,ek as ne,J as ae,eA as ce,aV as ie,eB as le,eC as re,eD as oe,eE as de,eF as ue,eG as me,ef as xe,L as I,eH as T,ah as he,E as V}from"./index-DtRfQcRH.js";import{f as ge,C as pe}from"./entity-options-utGBmFX0.js";import{V as fe,R as je,S as $,g as L}from"./runs-table--dnFQatY.js";function ve({organizationId:s,value:t,onChange:a,entities:n,className:m}){const{data:i=[]}=K(n?void 0:s),u=o.useMemo(()=>n??ge(i),[n,i]),f=new Set(t),l=u.filter(c=>f.has(c.id)),d=c=>{const p=new Set(f);p.has(c)?p.delete(c):p.add(c),a(Array.from(p).sort((v,y)=>v-y))},x=l.length===0?"All entities":l.length===1?l[0].name:`${l.length} entities selected`;return e.jsx(U,{contentClassName:"w-[320px]",searchPlaceholder:"Filter entities...",emptyText:"No entities found.",trigger:c=>e.jsxs(b,{variant:"outline",role:"combobox","aria-expanded":c,className:C("justify-between",m),children:[x,e.jsx(X,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>u.map(c=>{const p=f.has(c.id);return e.jsxs(q,{value:`${c.name} ${c.entityType}`,onSelect:()=>d(c.id),className:"cursor-pointer",children:[e.jsx(W,{className:C("mr-2 h-4 w-4",p?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[c.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",c.entityType,")"]})]})]},c.id)})})}function ye(s){return s?.feeds_schema?Object.entries(s.feeds_schema).map(([t,a])=>({key:t,name:a.name??t,description:a.description,configSchema:a.configSchema})):[]}const ke="Feeds are optional scheduled sync targets for an existing connection.";function Ce({organizationId:s,connections:t,connectorDefinitions:a,entityId:n,onClose:m}){const i=t.length===1,[u,f]=o.useState(i?String(t[0].id):""),[l,d]=o.useState(""),[x,c]=o.useState(n?[n]:[]),[p,v]=o.useState(null),y=G(),_=o.useMemo(()=>new Map(a.map(r=>[r.key,r])),[a]),h=o.useMemo(()=>t.find(r=>String(r.id)===u),[t,u]),N=o.useMemo(()=>h?ye(_.get(h.connector_key)):[],[h,_]),S=o.useMemo(()=>N.find(r=>r.key===l)??null,[N,l]),g=M(`${u}:${l}`,w(S?.configSchema),S?.configSchema),{values:j,setValues:P}=g,D=o.useCallback(()=>{f(i?String(t[0].id):""),d(""),c(n?[n]:[]),v(null)},[n,i,t]),k=o.useCallback(()=>{D(),m()},[m,D]),B=o.useCallback(async()=>{if(!g.canSubmit||!h||!l)return;v(null);const r=F(j);try{await y.mutateAsync({connection_id:h.id,feed_key:l,config:Object.keys(r).length>0?r:void 0,entity_ids:n?[n]:x.length>0?x:void 0}),k()}catch(A){v(A instanceof Error?A.message:"Failed to create feed")}},[j,g.canSubmit,y,n,k,h,x,l]),z=e.jsxs("div",{className:"flex-1 space-y-4 overflow-y-auto py-6 pr-1",children:[!i&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Connection"}),e.jsx(pe,{connections:t,value:u,onValueChange:r=>{f(r),d(""),v(null)},placeholder:"Select a connection"})]}),h&&N.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Feed Type"}),e.jsxs(J,{value:l,onValueChange:d,children:[e.jsx(Y,{children:e.jsx(Z,{placeholder:"Select feed type"})}),e.jsx(Q,{children:N.map(r=>e.jsx(ee,{value:r.key,children:e.jsxs("div",{children:[e.jsx("span",{children:r.name}),r.description&&e.jsxs("span",{className:"text-muted-foreground ml-1 text-xs",children:["— ",r.description]})]})},r.key))})]})]}),n?e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Target Entity"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This feed will be attached to the current entity."})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Target Entities"}),e.jsx(ve,{organizationId:s,value:x,onChange:c,className:"w-full"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Leave empty to create an unscoped feed."})]}),g.revision&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"Feed Configuration"}),e.jsx(O,{schema:g.revision,values:j,onValuesChange:P})]}),h&&N.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connector has no configurable feed types."}),e.jsx(R,{visible:g.hasConflict,onReload:g.reset}),p&&e.jsx("p",{className:"text-sm text-destructive",children:p})]}),H=e.jsx(se,{onCancel:k,className:"mt-2",children:e.jsxs(b,{disabled:!g.canSubmit||!l||y.isPending,onClick:()=>void B(),children:[y.isPending&&e.jsx(E,{size:"lg",className:"mr-2"}),"Create Feed"]})});return e.jsxs("div",{className:"flex flex-col",children:[z,H]})}function we({feed:s,onClose:t,hideHeader:a=!1}){const n=s.display_name?.trim()||s.feed_key,m=s.feed_key.includes(":")?s.feed_key.slice(s.feed_key.indexOf(":")+1):s.feed_key,i=s.external_tenant_id,u=s.connector_key==="slack"&&i?`https://app.slack.com/client/${i}/${m}`:void 0;return e.jsxs("div",{className:"flex max-w-xl flex-col gap-4",children:[a?null:e.jsxs(e.Fragment,{children:[t?e.jsxs("button",{type:"button",onClick:t,className:"inline-flex w-fit items-center gap-1 text-xs text-muted-foreground transition-colors hover:text-foreground",children:[e.jsx(te,{className:"h-3 w-3"}),"Back to connection"]}):null,e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("h2",{className:"text-lg font-semibold leading-tight",children:n}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"chat channel"})]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Messages captured for this channel are available to Lobu Automations. Open Slack to read the channel history."}),u?e.jsx(b,{asChild:!0,variant:"outline",className:"w-full justify-center",children:e.jsxs("a",{href:u,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(ae,{className:"mr-2 h-4 w-4"}),"Open in Slack"]})}):null,e.jsxs("div",{className:C(ie,"flex flex-col gap-3 p-4"),children:[e.jsx("div",{className:"text-xs font-medium uppercase text-muted-foreground",children:"Channel"}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm",children:[e.jsx(ce,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"break-all",children:n})]}),i?e.jsxs("div",{className:"flex items-baseline justify-between gap-2 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Workspace"}),e.jsx("span",{className:"break-all font-mono text-xs",children:i})]}):null,e.jsx("p",{className:"text-xs text-muted-foreground",children:"Messages the bot sees here are captured as they arrive. Open the channel in Slack to read the full history."})]})]})}function Fe(s,t){return s.display_name?s.display_name:t?.feeds_schema?.[s.feed_key]?.name??s.feed_key}function Ne(s,t){const a=s?.feeds_schema;if(!a)return;if(a[t]?.configSchema)return a[t].configSchema;for(const m of Object.values(a))if(m?.key===t&&m.configSchema)return m.configSchema;const n=Object.values(a);if(n.length===1&&n[0]?.configSchema)return n[0].configSchema}function Ee({feed:s,ownerSlug:t}){return e.jsxs(e.Fragment,{children:[e.jsx($,{status:L(s.status),showDot:!0,children:s.status}),s.connection_status&&s.connection_status!==s.status&&e.jsxs($,{status:L(s.connection_status),showDot:!0,children:["Connection: ",s.connection_status]}),s.device_worker_id?e.jsx(I,{to:"/$owner/connectors/device/$deviceId",params:{owner:t,deviceId:s.device_worker_id},children:e.jsx(he,{variant:s.device_status==="offline"?"secondary":"outline",className:"text-xs hover:bg-accent",children:s.device_status==="offline"?`Waiting for ${s.device_label||s.device_platform||"device"}`:`On ${s.device_label||s.device_platform||"device"}`})}):null]})}function De({feed:s}){return s.operations.includes("sync")?e.jsxs(e.Fragment,{children:[e.jsxs("span",{children:["Last sync: ",s.last_sync_at?V(s.last_sync_at):"—"]}),e.jsxs("span",{children:["Next: ",s.next_run_at?V(s.next_run_at):"—"]}),e.jsxs("span",{className:"font-mono",children:[(s.event_count??0).toLocaleString()," events"]})]}):e.jsx("span",{children:"Read live when queried"})}function Ae({feed:s,connectorDef:t,ownerSlug:a}){const{data:n,refetch:m}=le(s.id),i=re(),u=oe(),f=n?.recent_runs?.some(j=>["running","pending","claimed"].includes(j.status));o.useEffect(()=>{if(!f)return;const j=setInterval(()=>m(),5e3);return()=>clearInterval(j)},[f,m]);const l=o.useMemo(()=>Ne(t,s.feed_key),[t,s.feed_key]),d=M(s.id,w(l,s.config??{}),l),{values:x,setValues:c,dirty:p}=d,v=o.useCallback(async()=>{d.canSubmit&&(await i.mutateAsync({feed_id:s.id,config:F(x)}),d.accept(x,w(l,F(x))))},[i,s.id,x,l,d.canSubmit,d.accept]),y=o.useCallback(async()=>{const j=s.status==="active"?"paused":"active";await i.mutateAsync({feed_id:s.id,status:j})},[i,s.id,s.status]),_=o.useCallback(async()=>{await u.mutateAsync(s.id)},[u,s.id]),h=s.status==="active",N=s.operations.includes("sync"),S=s.auth_profile_status&&s.auth_profile_status!=="active",g=i.isPending||u.isPending;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(b,{variant:"outline",size:"sm",disabled:g,onClick:()=>void y(),children:[h?e.jsx(de,{className:"h-3.5 w-3.5 mr-1.5"}):e.jsx(ue,{className:"h-3.5 w-3.5 mr-1.5"}),h?"Pause":"Resume"]}),N?e.jsxs(b,{variant:"outline",size:"sm",disabled:g||!h,onClick:()=>void _(),children:[u.isPending?e.jsx(E,{size:"md",className:"mr-1.5"}):e.jsx(me,{className:"h-3.5 w-3.5 mr-1.5"}),"Sync now"]}):null,e.jsx(fe,{ownerSlug:a,scope:{kind:"feed",id:s.id},variant:"ghost",label:"View in memory"})]}),S&&e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-50 dark:bg-amber-950/20 px-3 py-2 text-sm",children:[e.jsx(xe,{className:"h-4 w-4 text-amber-500 shrink-0"}),e.jsxs("span",{className:"text-amber-700 dark:text-amber-400",children:["Authentication issue: ",s.auth_profile_status]}),e.jsx(b,{asChild:!0,variant:"outline",size:"sm",className:"ml-auto h-7 text-xs",children:e.jsx(I,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:a,connectorKey:s.connector_key,connectionId:String(s.connection_id)},search:{settings:!0},children:"Fix auth"})})]}),d.revision?e.jsx(T,{title:"Settings",children:e.jsxs("div",{className:"max-w-xl space-y-4",children:[e.jsx(O,{schema:d.revision,values:x,onValuesChange:c}),e.jsx(R,{visible:d.hasConflict,onReload:d.reset}),p&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(b,{size:"sm",disabled:g||!d.canSubmit,onClick:()=>void v(),children:[i.isPending?e.jsx(E,{size:"md",className:"mr-1.5"}):null,"Save"]})})]})}):null,N?e.jsx(T,{title:"Recent syncs",children:n?.recent_runs&&n.recent_runs.length>0?e.jsx(je,{runs:n.recent_runs,ownerSlug:a}):e.jsx("p",{className:"rounded-lg border bg-muted/20 px-3 py-6 text-center text-xs text-muted-foreground",children:"No syncs yet."})}):null]})}export{Ce as A,we as C,Ee as F,Ae as a,De as b,ke as c,Fe as f};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,a2 as l}from"./index-DtRfQcRH.js";function n(){return e.jsx("div",{className:"flex min-h-0 flex-1 flex-col gap-3 px-4 pt-4 pb-8 lg:px-6",children:e.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col",children:e.jsx(l,{})})})}export{n as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as n,aY as t,a2 as c,a as r,bg as i,gg as l,aW as m,gh as x,L as d,gi as C,gj as u,fK as j}from"./index-DtRfQcRH.js";function p({owner:o,initialConnectorKey:e}){return n.jsx(t,{owner:o,children:a=>n.jsx(g,{ownerSlug:a.ownerSlug,organizationId:a.organizationId,initialConnectorKey:e})})}function g({ownerSlug:o,organizationId:e,initialConnectorKey:a}){const{data:s=[]}=r(e??"");return n.jsxs(i,{className:"flex flex-1 flex-col gap-6",children:[n.jsx(l,{breadcrumb:n.jsx(x,{crumbs:[n.jsx(d,{to:"/$owner/connectors",params:{owner:o},search:{},className:C,children:"Connectors"},"connectors")]}),icon:n.jsx(m.connectors.icon,{className:"h-6 w-6"}),title:"Add a connection",caption:"Pick a connector from the catalog or drop in an MCP URL — Lobu handles auth and brings the data into memory."}),e?n.jsx(u,{ownerSlug:o,organizationId:e,connections:s,initialConnectorKey:a}):n.jsx("div",{className:"max-w-3xl",children:n.jsx(j,{rows:4})})]})}const f=()=>n.jsx(c,{});export{p as ConnectionsCreateRouteContent,f as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{hZ as o,j as e}from"./index-DtRfQcRH.js";import{a}from"./agent-guardrails-route-0PsTrqMC.js";import"./model-selector-XC5CI2Et.js";import"./agent-subpage-shell-DtzoRy6N.js";import"./agent-loading-shells-BQLjzMPy.js";import"./agent-card-controls-bhTMPoVi.js";import"./switch-CxDXvPGE.js";function x(){const{owner:r,agentId:t}=o.useParams();return e.jsx(a,{owner:r,agentId:t})}export{x as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{hX as r,j as e}from"./index-DtRfQcRH.js";import{a as m}from"./agent-skills-route-Cwq1QrhW.js";import"./agent-subpage-shell-DtzoRy6N.js";import"./agent-skill-context-s42Q4Wjo.js";import"./core.esm-C-eNiUAl.js";import"./skill-editor-D_W3QlRz.js";import"./agent-loading-shells-BQLjzMPy.js";import"./agent-card-controls-bhTMPoVi.js";import"./switch-CxDXvPGE.js";function c(){const{owner:t,agentId:o}=r.useParams();return e.jsx(m,{owner:t,agentId:o})}export{c as component};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{r as i,j as e,bX as oe,bY as ie,bZ as ce,b_ as re,b$ as T,ad as ae,B as U,Z as Yt,a as xs,d1 as ps,cy as Zt,dD as gs,dE as fs,S as Ct,ac as b,al as D,aV as Ie,dF as Et,cU as vs,cW as ys,dG as js,cm as es,cX as _s,bB as Ot,dH as Ns,cv as st,cw as Ke,aR as tt,dI as yt,bA as ts,P as Je,cr as bs,ap as ks,ai as Ss,d3 as ws,dJ as Cs,dK as Es,dL as Os,dM as As,dN as Fs,ah as Ps,L as Ts,a3 as ss,dO as Ms,bz as Ls,bf as Rs,dP as At,dQ as Ds,dR as $s,cf as Is,dS as qs,dT as gt,s as Ks,dU as Ws,dV as Bs,dW as Us,dX as Vs,dY as zs,dZ as Qs,d_ as Gs,d$ as Js,e0 as Hs,bC as Xs,c1 as Ys}from"./index-DtRfQcRH.js";import{c as Zs}from"./cronstrue-C5yTgk5z.js";import{C as en,f as tn}from"./entity-options-utGBmFX0.js";import{S as sn}from"./switch-CxDXvPGE.js";import{a as nn,A as an}from"./device-automation-BIjs7DZJ.js";import{M as on}from"./model-selector-XC5CI2Et.js";import{b as cn}from"./skill-editor-D_W3QlRz.js";import{C as ft}from"./code-editor-BHiWR94J.js";import{u as rn,M as Ft,a as Pt,s as ln,o as dn,b as un,c as mn,d as hn,e as xn,v as pn,r as gn}from"./use-mention-search-CeTEE3oE.js";const Ze=[{value:"*/15 * * * *",label:"Every 15 minutes"},{value:"0 * * * *",label:"Every hour"},{value:"0 */6 * * *",label:"Every 6 hours"},{value:"0 9 * * *",label:"Daily at 9:00 AM"},{value:"0 18 * * *",label:"Daily at 6:00 PM"},{value:"0 9 * * 1-5",label:"Weekdays at 9:00 AM"},{value:"0 9 * * 1",label:"Weekly · Monday 9:00 AM"},{value:"0 9 1 * *",label:"Monthly · 1st at 9:00 AM"},{value:"custom",label:"Custom cron…"}];function fn(n){const t=n.trim();if(!t)return null;try{return Zs.toString(t,{throwExceptionOnParseError:!0})}catch{return null}}function vn({value:n,onChange:t,placeholder:s="No schedule",className:r}){const u=n??"",m=Ze.some(g=>g.value===u),[c,o]=i.useState(!m&&u!==""),l=g=>{g==="custom"?o(!0):(o(!1),t(g))},y=u?fn(u):null,S=u?e.jsx("p",{className:y?"text-xs text-muted-foreground":"text-xs text-destructive",children:y??"Not a valid cron expression."}):null;return!u&&!c?e.jsxs(oe,{onValueChange:l,children:[e.jsx(ie,{className:r??"w-full",children:e.jsx(ce,{placeholder:s})}),e.jsx(re,{children:Ze.map(g=>e.jsxs(T,{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:[c?e.jsx(ae,{placeholder:"0 */6 * * *",value:u,onChange:g=>t(g.target.value),className:"font-mono text-sm flex-1"}):e.jsxs(oe,{value:u,onValueChange:l,children:[e.jsx(ie,{className:r??"w-full flex-1",children:e.jsx(ce,{children:Ze.find(g=>g.value===u)?.label??u})}),e.jsx(re,{children:Ze.map(g=>e.jsxs(T,{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(U,{type:"button",variant:"ghost",size:"icon",className:"h-9 w-9 shrink-0",onClick:()=>{o(!1),t("")},children:e.jsx(Yt,{className:"h-4 w-4"})})]}),S]})}const dt="__all_workspace_event_types__",yn=[],jn={};function Tt(n,t,s){const r=new Map;if(!t)for(const[m,c]of Object.entries(s??{}))r.set(m,{key:m,label:Ot(m),description:c.description});const u=[...n].filter(m=>!t||m.slug===t).sort((m,c)=>m.slug.localeCompare(c.slug));for(const m of u)for(const[c,o]of Object.entries(m.event_kinds??{})){const l=r.get(c);if(l){!l.description&&o.description&&(l.description=o.description),JSON.stringify(l.metadataSchema??null)!==JSON.stringify(o.metadataSchema??null)&&(l.metadataSchema=void 0);continue}r.set(c,{key:c,label:Ot(c),description:o.description,metadataSchema:o.metadataSchema})}return[...r.values()].sort((m,c)=>m.label.localeCompare(c.label))}function Mt(n){const t=n[0];if(!t)return;const s=u=>JSON.stringify(Object.keys(u?.properties??{}).sort()),r=s(t);return n.every(u=>s(u)===r)?t:void 0}function Lt(n,t,s){const r=new Set(Object.keys(t.properties??{}));return{...Object.fromEntries(Object.entries(n).filter(([u])=>!r.has(u))),...s}}function $e(n,t,s){return s==="steer"&&(n==="window"||t!=="reply_to_source")?"coalesce":s}function Qe(n,t){return n==="window"?"silent":t}function Rt(n){return Object.fromEntries(Object.entries(n).filter(([t])=>t==="resource_ref"||t==="resource_type"))}function Dt(n,t,s){const r=new Set(Object.keys(t?.properties??{})),u=new Set(s.flatMap(m=>Object.keys(m.filterSchema?.properties??{})));return Object.fromEntries(Object.entries(Ns(n)).filter(([m])=>m==="resource_ref"||m==="resource_type"||!u.has(m)||r.has(m)))}function _n({value:n,options:t,onChange:s}){return e.jsx("div",{className:"inline-flex rounded-md border bg-muted/30 p-0.5 text-sm",children:t.map(r=>e.jsx("button",{type:"button","aria-pressed":n===r.value,onClick:()=>s(r.value),className:D("rounded px-3 py-1 transition-colors",n===r.value?"bg-background text-foreground ":"text-muted-foreground hover:text-foreground"),children:r.label},r.value))})}function $t({events:n,selectedKeys:t,onToggle:s,ariaLabel:r="Events"}){const u=i.useId(),m=n.filter(o=>t.includes(o.key)).map(o=>o.label),c=m.length===0?"Choose events":m.length===1?m[0]:`${m.length} events selected`;return e.jsx(st,{contentClassName:"w-[var(--radix-popover-trigger-width)] min-w-[280px]",searchPlaceholder:"Filter events...",emptyText:"No events found.",trigger:o=>e.jsxs(U,{type:"button",variant:"outline",role:"combobox","aria-label":r,"aria-expanded":o,className:"w-full justify-between font-normal",children:[e.jsx("span",{className:D(m.length===0&&"text-muted-foreground"),children:c}),e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:()=>n.map((o,l)=>{const y=t.includes(o.key),S=`${u}-${l}-state`;return e.jsxs(Ke,{value:`${o.label} ${o.key}`,onSelect:()=>s(o.key),"aria-label":o.label,"aria-describedby":S,className:"cursor-pointer",children:[e.jsx(tt,{className:D("mr-2 h-4 w-4",y?"opacity-100":"opacity-0")}),o.label,e.jsx("span",{id:S,className:"sr-only",children:y?"Selected":"Not selected"})]},o.key)})})}function Nn({organizationId:n,initialTrigger:t,onChange:s,allowedKinds:r,showSectionHeader:u=!0,fieldIdPrefix:m="automation-trigger-"}){const c=xs(n,{status:"active",limit:500}),o=ps(n),l=Zt({organizationId:n}),y=gs({organizationId:n}),S=c.data??[],g=o.data??[],$=l.data??yn,h=y.data??jn,j=i.useMemo(()=>$.filter(d=>d.organization_id===n),[$,n]),_=t?.kind==="event"&&t?.source==="workspace",w=_||t===void 0,L=r?.length?[...r]:["event","time","manual"],N=L.join("|"),W=(()=>{const d=t===null?"manual":t?.kind==="schedule"?"time":"event";return L.includes(d)?d:L[0]??"event"})(),[f,z]=i.useState(W),[Q,Ne]=i.useState(_?"workspace":typeof t?.connection_id=="number"?String(t.connection_id):t?.kind==="event"&&t.connector_key?"":"workspace"),k=Q==="workspace",F=k?"":Q,[p,V]=i.useState(typeof t?.entity_type=="string"?t.entity_type:""),xe=i.useMemo(()=>Array.isArray(t?.event_types)?t.event_types:[],[t]),[P,H]=i.useState(()=>xe.filter(d=>typeof d=="string")),[X,te]=i.useState(t?.match&&typeof t.match=="object"&&!Array.isArray(t.match)?t.match:{}),[be,Se]=i.useState(typeof t?.cron=="string"?t.cron:"0 9 * * 1-5"),le=typeof t?.timezone=="string"?t.timezone:void 0,[I,pe]=i.useState(t?.kind==="schedule"||w&&t?.execution!=="turn"||t?.execution==="window"?"window":"turn"),[G,Y]=i.useState(Qe(I,t?.output==="reply_to_source"?"reply_to_source":"silent")),[se,ne]=i.useState(t?.kind==="schedule"||w&&t?.active_run!=="queue"?"coalesce":$e(I,G,t?.active_run==="coalesce"||t?.active_run==="steer"?t.active_run:"queue")),[we,Oe]=i.useState(t?.skip_if_unchanged!==!1),[x,ge]=i.useState(!1);i.useEffect(()=>{const d=N.split("|");if(!d.includes(f)){const v=d[0]??"event";z(v),pe(v==="time"||v==="event"&&k?"window":"turn"),ne(v==="time"||v==="event"&&k?"coalesce":"queue"),Y("silent")}},[N,f,k]);const M=S.find(d=>String(d.id)===F),de=c.isLoading||o.isLoading,Z=l.isLoading,J=typeof t?.connector_key=="string"?t.connector_key:void 0,Ae=f==="event"&&!k&&t?.kind==="event"&&t?.source!=="workspace"&&typeof t.connection_id=="number"&&String(t.connection_id)===F&&!M,ve=f==="event"&&!k&&t?.kind==="event"&&t?.source!=="workspace"&&t.connection_id==null&&J!==void 0&&F==="",Fe=g.find(d=>d.key===(M?.connector_key??(ve?J:void 0))),ue=Fe?.automation_events??[],q=ue.filter(d=>P.includes(d.key)),ye=q[0],Te=j.find(d=>d.slug===p),Pe=[...j.filter(d=>Object.keys(d.event_kinds??{}).length>0||d.slug===p),...p&&!Te?[{slug:p,name:p}]:[]],me=i.useMemo(()=>Tt(j,p||void 0,h),[j,p,h]),Me=me.filter(d=>P.includes(d.key)),We=Me[0],fe=Mt(q.map(d=>d.filterSchema)),he=Mt(Me.map(d=>d.metadataSchema)),Be=!!(k&&p&&!Te),Le=Ae||ve,Ce=(f==="event"?k?P.length>0&&!Be:!!(P.length>0&&(F&&M||Le)):f==="time"?!!be.trim():!0)&&(f!=="event"||!fs(X));i.useEffect(()=>{let d;if(Ce&&f==="event"&&!k){const v=Dt(X,fe,Fe?.automation_events??[]);M||ve?d={kind:"event",source:"connector",connector_key:M?.connector_key??J,...M?{connection_id:Number(F)}:{},event_types:P,...Object.keys(v).length>0?{match:v}:{},execution:I,active_run:$e(I,G,se),output:Qe(I,G),skip_if_unchanged:we}:Ae&&(d=t?{...t,source:"connector"}:void 0)}else if(Ce&&f==="event"&&k){const v=Dt(X,he,me.map(C=>({filterSchema:C.metadataSchema})));d={kind:"event",source:"workspace",...p?{entity_type:p}:{},event_types:P,...Object.keys(v).length>0?{match:v}:{},execution:I,active_run:se==="queue"?"queue":"coalesce"}}else Ce&&f==="time"&&(d={kind:"schedule",cron:be.trim(),...le?{timezone:le}:{},execution:"window",active_run:"coalesce",skip_if_unchanged:we});s({ready:Ce,kind:f,trigger:d})},[se,F,M,be,Fe,P,I,X,f,J,le,t,k,s,G,Ce,fe,he,we,p,me,ve,Ae]);const at=d=>{const v=S.find(E=>String(E.id)===d),C=g.find(E=>E.key===v?.connector_key),ee=P.filter(E=>C?.automation_events?.some(De=>De.key===E)),A=C?.automation_events?.find(E=>E.key===ee[0]),je=v?.connector_key!==(M?.connector_key??J);if(Ne(d),H(ee),!A)te(Rt);else if(je){const E=A.defaults?.execution??"turn",De=A.defaults?.activeRun??"queue",ze=Qe(E,A.defaults?.output??"silent");te(Rt),pe(E),ne($e(E,ze,De)),Y(ze)}},ot=d=>{if(d==="workspace"){Ne("workspace"),H(v=>v.filter(C=>me.some(ee=>ee.key===C))),te({}),pe("window"),ne("coalesce"),Y("silent");return}at(d)},Ue=d=>{const v=P.includes(d)?P.filter(E=>E!==d):ue.map(E=>E.key).filter(E=>E===d||P.includes(E));if(H(v),v[0]===P[0])return;const C=ue.find(E=>E.key===v[0]),ee=C?.defaults?.execution??"turn",A=C?.defaults?.activeRun??"queue",je=Qe(ee,C?.defaults?.output??"silent");pe(ee),ne($e(ee,je,A)),Y(je)},Xe=d=>{const v=d===dt?"":d,C=j.find(A=>A.slug===v),ee=Tt(j,C?.slug,h);V(v),H(A=>A.filter(je=>ee.some(E=>E.key===je))),te({})},Ve=d=>{H(v=>v.includes(d)?v.filter(C=>C!==d):me.map(C=>C.key).filter(C=>C===d||v.includes(C)))},Re=[{value:"event",label:"Event"},{value:"time",label:"Schedule"},{value:"manual",label:"Manual"}].filter(d=>L.includes(d.value));return e.jsxs("div",{className:"space-y-4",children:[u?e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:"When"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose what starts this Automation. Its goal and context stay reusable."})]}):null,Re.length>1?e.jsx(_n,{value:f,options:Re,onChange:d=>{z(d),pe(d==="time"||d==="event"&&k?"window":"turn"),ne(d==="time"||d==="event"&&k?"coalesce":"queue"),Y("silent")}}):null,f==="event"?de||k&&Z?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ct,{className:"h-9 w-full"}),e.jsx(Ct,{className:"h-9 w-full"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Source"}),e.jsx(en,{connections:S,value:Q,onValueChange:ot,disabled:Le,includeWorkspaceEvents:!0,ariaLabel:"Source",placeholder:"Choose a source"}),Ae?e.jsx("p",{className:"text-xs text-muted-foreground",children:"This shared connection is managed outside this organization. Other Automation fields can still be edited."}):ve?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This Automation listens across all"," ",String(t?.connector_key)," connections. Other Automation fields can still be edited."]}):null]}),k?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:me.length>1?"Events":"Event"}),me.length>0?e.jsx($t,{events:me,selectedKeys:P,onToggle:Ve}):e.jsx("div",{className:D(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:p?"This entity type has no declared Automation events.":"This workspace has no declared Automation events."}),We?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:We.description}):null,Be?e.jsxs("p",{className:"text-xs text-destructive",children:["This trigger filters on entity type “",p,"”, 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."})]}),he?e.jsx(Et,{schema:he,values:X,onValuesChange:d=>te(v=>Lt(v,he,d)),fieldIdPrefix:`${m}workspace-`},`${p||"workspace"}:${P.join(",")}`):null]}):M||ve?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:ue.length>1?"Events":"Event"}),ue.length?e.jsx($t,{events:ue,selectedKeys:P,onToggle:Ue}):e.jsx("div",{className:D(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:"This connector has not published subscribable events."}),ye?.description?e.jsx("p",{className:"text-xs text-muted-foreground",children:ye.description}):null]}),typeof X.resource_ref=="string"||fe?e.jsxs("div",{className:"space-y-3",children:[typeof X.resource_ref=="string"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Resource"}),e.jsx("div",{className:D(Ie,"px-3 py-2 text-sm"),children:X.resource_ref})]}):null,fe?e.jsx(Et,{schema:fe,values:X,onValuesChange:d=>te(v=>Lt(v,fe,d)),fieldIdPrefix:m},P.join(",")):null]}):null]}):Q?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose workspace events or a connected app as the source."})]}):f==="time"?e.jsx(vn,{value:be,onChange:Se}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Run this Automation explicitly from Lobu, the API, CLI, or MCP."}),f!=="manual"&&!Le?e.jsxs(vs,{open:x,onOpenChange:ge,children:[e.jsx(ys,{asChild:!0,children:e.jsxs(U,{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(js,{className:"h-4 w-4"}),"Trigger options",e.jsxs("span",{className:"font-normal text-muted-foreground",children:["· ",I==="turn"?"Each event":"Window"," ·"," ",f==="time"?"Combine":k?se==="queue"?"Queue":"Combine":se==="queue"?"Queue":se==="coalesce"?"Combine":"Update current run",f==="event"&&!k?` · ${I==="turn"&&G==="reply_to_source"?"Reply":"Save in Lobu"}`:""]})]}),e.jsx(es,{className:D("h-4 w-4 transition-transform",x&&"rotate-180")})]})}),e.jsxs(_s,{className:"space-y-4 pt-3",children:[f==="event"&&k?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Entity type filter"}),e.jsxs(oe,{value:p||dt,onValueChange:Xe,children:[e.jsx(ie,{"aria-label":"Entity type filter",children:e.jsx(ce,{})}),e.jsxs(re,{children:[e.jsx(T,{value:dt,children:"All event types"}),Pe.map(d=>e.jsx(T,{value:d.slug,children:d.name},d.slug))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. Limit selected events to outputs linked to this entity type."})]}):null,f==="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:I,onValueChange:d=>{const v=d,C=Qe(v,G);pe(v),Y(C),ne($e(v,C,se))},children:[e.jsx(ie,{children:e.jsx(ce,{})}),e.jsxs(re,{children:[e.jsx(T,{value:"turn",children:"Start a run for each event"}),e.jsx(T,{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:se,onValueChange:d=>ne(d),children:[e.jsx(ie,{children:e.jsx(ce,{})}),e.jsxs(re,{children:[e.jsx(T,{value:"queue",children:"Queue"}),e.jsx(T,{value:"coalesce",children:"Combine waiting events"}),!k&&I==="turn"&&G==="reply_to_source"&&ye?.capabilities?.steering?e.jsx(T,{value:"steer",children:"Update the current run"}):null]})]})]})]}):null,I==="window"&&(f==="time"||!k)?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(sn,{"aria-label":"Skip unchanged windows",checked:we,onCheckedChange:Oe})]}):null,f==="event"&&!k&&I==="turn"?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Result"}),e.jsxs(oe,{value:G,onValueChange:d=>{const v=d;Y(v),ne($e(I,v,se))},children:[e.jsx(ie,{children:e.jsx(ce,{})}),e.jsxs(re,{children:[ye?.capabilities?.replyToSource?e.jsx(T,{value:"reply_to_source",children:"Reply where it happened"}):null,e.jsx(T,{value:"silent",children:"Save in Lobu"})]})]}),ye?.capabilities?.replyToSource?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Messages matching this trigger run the Automation; anything else in the conversation stays with the connected agent."}):null]}):null]})]}):null]})}const bn=16;function qe(){return crypto.randomUUID()}function kn(n){return n===void 0?[{key:qe(),initial:void 0}]:n.length===0?[{key:qe(),initial:null}]:n.map(t=>({key:qe(),initial:t}))}function ns(n){return n?n.kind==="time"||n.trigger?.kind==="schedule":!1}function Sn(n,t){return n?n.ready===t.ready&&n.kind===t.kind&&JSON.stringify(n.trigger)===JSON.stringify(t.trigger):!1}function wn(n,t){const s=n.map(o=>t[o.key]??{ready:!1,kind:"event"});if(!(n.length>1)&&s[0]?.kind==="manual")return{ready:s[0].ready,triggers:[]};const u=s.filter(ns).length;return{ready:!s.some(o=>o.kind==="manual")&&u<=1&&s.length>0&&s.every(o=>o.ready&&o.trigger),triggers:s.filter(o=>o.trigger).map(o=>o.trigger)}}function na({organizationId:n,initialTriggers:t,onChange:s}){const r=i.useId(),[u,m]=i.useState(()=>kn(t)),[c,o]=i.useState({}),l=i.useRef("");i.useEffect(()=>{const h=wn(u,c),j=JSON.stringify(h);j!==l.current&&(l.current=j,s(h))},[u,c,s]);const y=u.find(h=>ns(c[h.key]))?.key??u.find(h=>h.initial&&typeof h.initial=="object"&&h.initial.kind==="schedule"&&!c[h.key])?.key??null,S=i.useCallback((h,j)=>{o(_=>Sn(_[h],j)?_:{..._,[h]:j})},[]),g=()=>{const h=u[0],j=h?c[h.key]:void 0;if(u.length===1&&(j?.kind==="manual"||h?.initial===null)){const _=qe();o({}),m([{key:_,initial:void 0}]);return}m(_=>[..._,{key:qe(),initial:void 0}])},$=h=>{if(u.length<=1){const j=qe();o({}),m([{key:j,initial:null}]);return}o(j=>{const _={...j};return delete _[h],_}),m(j=>j.filter(_=>_.key!==h))};return e.jsxs("section",{className:"space-y-4","aria-labelledby":`${r}-heading`,children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{id:`${r}-heading`,className:"text-sm font-medium",children:"When"}),u.length>1?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Each trigger can start this Automation independently (OR). At most one schedule. If several match the same event, the first listed wins for run options."}):null]}),e.jsx("div",{className:"space-y-3",children:u.map((h,j)=>{const _=u.length>1,w=_?y&&y!==h.key?["event"]:["event","time"]:["event","time","manual"],L=c[h.key],N=_||(L?L.kind!=="manual":h.initial!==null);return e.jsxs("div",{className:D("space-y-3 rounded-lg border bg-card/40 p-3",_&&"relative"),children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:_?`Trigger ${j+1}`:"Trigger"}),N?e.jsx(U,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 text-muted-foreground hover:text-destructive","aria-label":_?`Remove trigger ${j+1}`:"Clear trigger",onClick:()=>$(h.key),children:e.jsx(ts,{className:"h-3.5 w-3.5"})}):null]}),e.jsx(Cn,{slotKey:h.key,organizationId:n,initial:h.initial,kinds:w,fieldIdPrefix:`${r}-${h.key}-`,onChange:S})]},h.key)})}),e.jsxs(U,{type:"button",variant:"outline",size:"sm",className:"w-full sm:w-auto",onClick:g,disabled:u.length>=bn,children:[e.jsx(Je,{className:"mr-1.5 h-3.5 w-3.5"}),"Add another trigger"]})]})}function Cn({slotKey:n,organizationId:t,initial:s,kinds:r,fieldIdPrefix:u,onChange:m}){const c=i.useCallback(o=>m(n,o),[m,n]);return e.jsx(Nn,{organizationId:t,initialTrigger:s,allowedKinds:r,showSectionHeader:!1,fieldIdPrefix:u,onChange:c})}const It={agents:!0,lobuEmbedded:!1};function En(){const{data:n}=bs({queryKey:["features"],queryFn:async()=>{const t=await ks(`${Ss}/api/features`);return t.ok?t.json():It},staleTime:3e4,refetchInterval:6e4});return n??It}const qt=["slack","imessage"],ut="__none__";function Ge(n){return`${n.connection_id}:${n.feed_key}`}function On(n){const t=n.indexOf(":");if(t<=0)return null;const s=Number(n.slice(0,t)),r=n.slice(t+1);return!Number.isSafeInteger(s)||s<=0||!r?null:{connection_id:s,channel_id:r}}function mt(n){return n?`${n.connection_id}:${n.channel_id}`:""}function et(n){return`${n.display_name||n.feed_key} (${n.feed_key})`}function An({organizationId:n,agentId:t,value:s,onChange:r,disabled:u=!1,automationName:m,onPendingChange:c}){const{data:o=[],isLoading:l}=ws(n),y=mt(s),[S,g]=i.useState(null),[$,h]=i.useState(!1),j=i.useRef(t),_=i.useMemo(()=>o.filter(p=>p.store==="channel_messages"&&p.target_agent_id===t&&qt.includes(p.connector_key)),[o,t]);i.useEffect(()=>{if(j.current===t||(j.current=t,g(null),h(!1),s==null))return;const p=mt(s);if(p==="")return;o.some(xe=>xe.store==="channel_messages"&&xe.target_agent_id===t&&qt.includes(xe.connector_key)&&Ge(xe)===p)||r(null)},[t,o,s,r]);const w=S??y,L=w===""?ut:w,N=_.find(p=>Ge(p)===w),W=S!==null&&S!==""&&S!==y;i.useEffect(()=>{c?.(W)},[W,c]);const f=N??(S?void 0:_.find(p=>Ge(p)===y)),z=p=>{const V=p===ut?"":p;if(V===""){g(null),h(!1),r(null);return}if(V===y){g(null),h(!1);return}g(V),h(!1)},Q=p=>{if(h(p),p&&S){const V=On(S);V&&(g(null),r(V))}else!p&&S&&g(null)},k=(s&&mt(s)!==""?s:void 0)??(N?{connection_id:N.connection_id,channel_id:N.feed_key}:void 0),F=(m??"").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)"})]}),t?e.jsxs(oe,{value:L,onValueChange:z,disabled:u||l,children:[e.jsx(ie,{id:"automation-delivery-target",className:"font-mono text-sm",children:e.jsx(ce,{placeholder:l?"Loading bound channels…":_.length===0?"No bound Slack or iMessage channels":"No digest — runs stay silent"})}),e.jsxs(re,{children:[e.jsx(T,{value:ut,children:"No digest — runs stay silent"}),_.map(p=>e.jsxs(T,{value:Ge(p),children:[et(p)," · ",p.connector_key]},Ge(p)))]})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:"Select a managed agent first — only channels bound to that agent can receive digests."}),t&&!l&&_.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No Slack or iMessage channels are bound to this agent yet. Link a private channel first, then select it here."}):null,W&&N?e.jsxs("label",{className:"flex cursor-pointer items-start gap-2 text-xs",children:[e.jsx("input",{type:"checkbox",checked:$,onChange:p=>Q(p.target.checked),className:"mt-0.5","aria-label":`Confirm digest delivery to ${et(N)}`}),e.jsxs("span",{className:"text-muted-foreground",children:["I confirm posting material-change digests to"," ",e.jsx("span",{className:"font-medium text-foreground",children:et(N)}),". Destination changes are audited."]})]}):null,f||k?e.jsxs("div",{className:D(Ie,"space-y-1.5 px-3 py-2"),children:[e.jsxs("p",{className:"text-xs font-medium",children:["Digest preview →"," ",e.jsx("span",{className:"font-mono font-normal",children:f?`${f.connector_key} ${et(f)} · connection ${f.connection_id}`:`${k?.channel_id} · connection ${k?.connection_id}`})]}),e.jsxs("p",{className:"font-mono text-xs",children:[F," applied 2 new + 1 updated"]}),e.jsx("p",{className:"whitespace-pre-line font-mono text-xs text-muted-foreground",children:`+ Example task (#12)
|
|
2
|
-
~ Follow-up item (#34)`}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Sends only after a successful run with material changes. Runs with zero changes send nothing. Retries reuse the same notification and delivery receipts dedupe channel posts, but provider acceptance with a lost receipt can still duplicate."})]}):null]})}const Kt=4096;function Fn({open:n,onOpenChange:t,initial:s,onSubmit:r}){const[u,m]=i.useState(""),[c,o]=i.useState(""),[l,y]=i.useState(null);i.useEffect(()=>{n&&(m(s?.name??""),o(s?.query??""),y(null))},[n,s]);const S=()=>{const $=u.trim(),h=c.trim();if(!$){y("Give the SQL source a name.");return}if(!h){y("Enter a query.");return}if(h.length>Kt){y(`Query is too long (${h.length} chars, max ${Kt}).`);return}r({name:$,query:h}),t(!1)},g=!!s;return e.jsx(Cs,{open:n,onOpenChange:t,children:e.jsxs(Es,{className:"max-w-2xl",children:[e.jsxs(Os,{children:[e.jsx(As,{children:g?"Edit SQL source":"SQL source"}),e.jsx(Fs,{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:u,onChange:$=>m($.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(ft,{value:c,onChange:o,language:"sql",placeholder:"SELECT id, payload_text, occurred_at FROM events ORDER BY occurred_at DESC",minHeight:"160px"})]}),l?e.jsx("p",{className:"text-sm text-destructive",children:l}):null]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(U,{variant:"outline",onClick:()=>t(!1),children:"Cancel"}),e.jsx(U,{onClick:S,children:g?"Save":"Add source"})]})]})})}const Pn=["skill","feed","connection","connector","metric","entity_type"];function Tn({value:n,onChange:t,library:s,pinned:r,required:u,error:m,owner:c,agentId:o,sources:l,onAddSources:y}){const S=rn(Pn,Ft,{skills:s,skillAgentId:o||null}),g=i.useRef(null),[$,h]=i.useState(null),j=i.useMemo(()=>{if(!l)return[];const N=new Set(l.map(W=>W.query.trim()));return Pt(n).filter(W=>!N.has(W.query.trim()))},[n,l]),_=ln(n),w=dn(r.filter(N=>_.includes(N.name)),s),L=s.length>0;return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(b,{htmlFor:"automation-prompt",children:["Instructions"," ",u?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),_.length>0?e.jsxs("span",{className:"text-xs text-muted-foreground",children:[_.length,"/",Ft," skills"]}):null]}),e.jsx("div",{className:"rounded-lg border bg-background focus-within:ring-1 focus-within:ring-ring",children:e.jsx(un,{value:n,onChange:t,onSubmit:()=>{},submitOnEnter:!1,searchRefs:S,handleRef:g,onSqlRequest:()=>h({}),onSqlEdit:(N,W)=>h({initial:N,pos:W}),placeholder:L?"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(Fn,{open:$!==null,onOpenChange:N=>{N||h(null)},initial:$?.initial,onSubmit:N=>{g.current?.insertSql(N,$?.pos),h(null)}}),j.length>0&&y?e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-lg border border-dashed p-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:[j.length===1?`"${j[0]?.name}" is referenced in the instructions but is not a source on this Automation.`:`${j.length} references in the instructions are not sources on this Automation.`," ","Editing an Automation does not add them automatically."]}),e.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>y(Pt(n,l)),children:j.length===1?"Add as a source":"Add as sources"})]}):null,_.length>0?e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:_.map(N=>{const W=w.includes(N),f=!s.some(z=>z.name===N);return e.jsxs(Ps,{variant:f?"destructive":"secondary",className:"font-normal",children:[N,f?" · unavailable":W?" · newer text":null]},N)})}):null,w.length>0?e.jsxs("p",{className:"rounded-lg border border-dashed p-3 text-xs text-muted-foreground",children:[w.length===1?`"${w[0]}" has been edited since this Automation pinned it.`:`${w.length} skills have been edited since this Automation pinned them.`," ","This Automation keeps running the pinned text until you save it again."]}):null,m?e.jsx("p",{className:"text-xs text-destructive",children:m}):null,!L&&o?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["This agent has no skills yet."," ",e.jsx(Ts,{to:"/$owner/agents/$agentId/skills",params:{owner:c,agentId:o},className:"font-medium text-foreground underline underline-offset-2",children:"Add one"})," ","to reuse instructions across Automations."]}):m?null:e.jsx("p",{className:"text-xs text-muted-foreground",children:L?"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 Mn=["connection","connector","feed","metric","entity_type"];function Ln({sources:n,onChange:t,disabled:s}){const{currentOwner:r,resolvedOrganizationId:u}=ss(),[m,c]=i.useState(""),{refs:o}=mn({owner:r,organizationId:u,kinds:Mn,query:m,limitPerKind:10});return e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Sources"}),n.length>0?e.jsx("ul",{className:"space-y-2",children:n.map(l=>e.jsxs("li",{className:"flex items-start gap-2 rounded-lg border bg-background p-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-mono text-xs font-medium",children:l.name}),e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:l.query})]}),e.jsx(U,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0","aria-label":`Remove source ${l.name}`,disabled:s,onClick:()=>t(n.filter(y=>y.query!==l.query)),children:e.jsx(Yt,{className:"h-3.5 w-3.5"})})]},l.query))}):null,e.jsx("div",{className:"flex gap-2",children:e.jsx(st,{searchPlaceholder:"Search feeds, connections, metrics…",emptyText:"No matching reference.",onQueryChange:c,trigger:()=>e.jsxs(U,{type:"button",variant:"outline",size:"sm",disabled:s,children:[e.jsx(Je,{className:"mr-2 h-3.5 w-3.5"}),"Add source"]}),children:l=>o.map(y=>e.jsxs(Ke,{value:`${y.label} ${y.kind}`,onSelect:()=>{t(hn(y,n)),l()},children:[e.jsx("span",{className:"truncate text-sm",children:y.label}),e.jsx("span",{className:"ml-2 shrink-0 text-xs text-muted-foreground",children:y.kind})]},`${y.kind}:${y.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 Rn({organizationId:n,value:t,onChange:s,className:r}){const{data:u=[]}=Ms(n),m=tn(u),c=m.find(o=>o.id===t);return e.jsx(st,{contentClassName:"w-[300px]",searchPlaceholder:"Search entities...",emptyText:"No entities found.",trigger:o=>e.jsxs(U,{variant:"outline",role:"combobox","aria-expanded":o,className:D("w-full justify-between",r),children:[c?`${c.name} (${c.entityType})`:"All workspace",e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:o=>e.jsxs(e.Fragment,{children:[e.jsxs(Ke,{value:"all workspace",onSelect:()=>{s(void 0),o()},className:"cursor-pointer",children:[e.jsx(tt,{className:D("mr-2 h-4 w-4",t===void 0?"opacity-100":"opacity-0")}),e.jsx("span",{children:"All workspace"})]}),m.map(l=>e.jsxs(Ke,{value:`${l.name} ${l.entityType}`,onSelect:()=>{s(l.id),o()},className:"cursor-pointer",children:[e.jsx(tt,{className:D("mr-2 h-4 w-4",t===l.id?"opacity-100":"opacity-0")}),e.jsxs("span",{children:[l.name," ",e.jsxs("span",{className:"text-muted-foreground text-xs",children:["(",l.entityType,")"]})]})]},l.id))]})})}function vt(n){if(Array.isArray(n))return n;if(typeof n=="string"&&n.startsWith("{")&&n.endsWith("}")){const t=n.slice(1,-1);return t?t.split(",").map(s=>s.trim()):[]}return[]}const Dn=nn.map(n=>({value:n,label:an[n]})),Wt=[{value:"agent",label:"Agent",hint:"An agent reads the window and follows your instructions."},{value:"code",label:"Code",hint:"A deterministic script processes each completed window."},{value:"both",label:"Agent + code",hint:"An agent extracts per your instructions, then the script runs."}];function Bt(n){const t=!!(n?.prompt?.trim()||n?.skills?.some(r=>r.content.trim())),s=!!n?.reaction_script?.trim();return t&&s?"both":s?"code":"agent"}const $n=["text","number","date","boolean","json"],In=[{value:"key",label:"Key"},{value:"plain",label:"Plain"}],ht=[{value:"plan",label:"Plan first"},{value:"auto",label:"Auto"},{value:"acceptEdits",label:"Accept edits"},{value:"dontAsk",label:"Don't ask"},{value:"bypassPermissions",label:"Bypass permissions"}];let Ut=0;function qn(){return Ut+=1,`field-${Ut}`}function as(n={}){return{id:qn(),name:n.name??"",type:n.type??"text",role:n.role??"plain"}}function He(n){return n.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_").replace(/^_+|_+$/g,"")}function Kn(n){return n?Object.keys(n).every(t=>["entity_type","entity_path","key_fields","key_output_field"].includes(t)):!0}function Vt(n){return n?Kn(n.keying_config)?"fields":"json":"fields"}function zt(n){const t=n?.keying_config?.entity_type;return typeof t=="string"?t:""}function Qt(n){const t=n?.keying_config?.entity_path;return typeof t=="string"&&t.trim()?t:"$"}function Gt(n){const t=new Map,s=Array.isArray(n?.keying_config?.key_fields)?n?.keying_config?.key_fields:[];for(const r of s){if(typeof r!="string")continue;const u=He(r);u&&t.set(u,as({name:u,role:"key"}))}return Array.from(t.values())}function _e(n,t){const s=n?.execution_config?.[t];return typeof s=="number"||typeof s=="string"?String(s):""}function Jt(n,t,s){const r=n?.execution_config?.[t];return typeof r=="string"&&s.includes(r)?r:""}function xt(n,t){const s=n.trim();if(!s)return{};const r=Number(s);return Number.isFinite(r)?{value:r}:{error:`${t} must be a number.`}}function Ht({entityType:n,entityPath:t,fields:s}){const u=s.map(o=>({...o,name:He(o.name)})).filter(o=>o.name).filter(o=>o.role==="key").map(o=>o.name),m=He(n),c=t.trim()||"$";return u.length>0&&!m?{error:"Key fields need an output entity type."}:(u.length>0,{keyingConfig:u.length>0?{entity_type:m,entity_path:c,key_fields:u,key_output_field:`${m}_key`}:void 0})}function Wn(n,t){return e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-sm font-medium",children:n}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t})]})}function Xt(n){return!!(n?.keying_config||n?.reactions_guidance||n?.model_config||n?.execution_config||n?.sources?.length||vt(n?.tags).length)}function Bn({organizationId:n,entityId:t,prefill:s,onSubmit:r,isSubmitting:u,error:m,isEditing:c,onCancel:o,triggerFields:l,submitLabel:y="Create Automation",submitDisabled:S=!1,triggers:g}){const{lobuEmbedded:$}=En(),{currentOwner:h}=ss(),{data:j=[]}=Ls(),{data:_=[]}=Rs(),[w,L]=i.useState(s?.managed_agent_id??""),N=!!s?.managed_agent_id&&!c,[W,f]=i.useState(s?.delivery_target??null),[z,Q]=i.useState(!1),[Ne,k]=i.useState(s?.device_worker_id??""),[F,p]=i.useState(s?.device_worker_id?"device":"agent"),[V,xe]=i.useState(s?.agent_kind??""),{data:P=[]}=Zt({organizationId:n}),[H,X]=i.useState(s?.name??""),[te,be]=i.useState(s?.slug??""),[Se,le]=i.useState(!!s?.slug),[I,pe]=i.useState(s?.description??""),[G,Y]=i.useState(s?.prompt??""),[se,ne]=i.useState(!1),we=s?.skills??[],[Oe,x]=i.useState(s?.sources??[]),[ge,M]=i.useState(s?.entity_id??t),[de,Z]=i.useState(s?.reaction_script??""),[J,Ae]=i.useState(()=>Bt(s)),[ve,Fe]=i.useState(s?.keying_config?JSON.stringify(s.keying_config,null,2):""),[ue,q]=i.useState(null),[ye,Te]=i.useState(()=>Vt(s)),[Pe,me]=i.useState(()=>zt(s)),[Me,We]=i.useState(()=>Qt(s)),[fe,he]=i.useState(()=>Gt(s)),[Be,Le]=i.useState(s?.reactions_guidance??""),[nt,Ce]=i.useState(()=>_e(s,"timeout_seconds")),[at,ot]=i.useState(()=>_e(s,"max_budget_usd")),[Ue,Xe]=i.useState(()=>_e(s,"model")),[Ve,it]=i.useState(()=>Jt(s,"permission_mode",ht.map(a=>a.value))),[Re,d]=i.useState(()=>_e(s,"effort")),[v,C]=i.useState(()=>_e(s,"finalize_nudges")),[ee,A]=i.useState(null),[je,E]=i.useState(vt(s?.tags).join(", ")),[De,ze]=i.useState(""),[ct,jt]=i.useState(!!(c||Xt(s)));i.useEffect(()=>{s&&(X(s.name??""),be(s.slug??""),le(!!s.slug),pe(s.description??""),Y(s.prompt??""),ne(!1),x(s.sources??[]),M(s.entity_id??t),k(s.device_worker_id??""),p(s.device_worker_id?"device":"agent"),xe(s.agent_kind??""),Z(s.reaction_script??""),Ae(Bt(s)),Fe(s.keying_config?JSON.stringify(s.keying_config,null,2):""),q(null),Te(Vt(s)),me(zt(s)),We(Qt(s)),he(Gt(s)),Le(s.reactions_guidance??""),Ce(_e(s,"timeout_seconds")),ot(_e(s,"max_budget_usd")),Xe(_e(s,"model")),it(Jt(s,"permission_mode",ht.map(a=>a.value))),d(_e(s,"effort")),C(_e(s,"finalize_nudges")),A(null),E(vt(s.tags).join(", ")),ze(""),L(s.managed_agent_id??""),f(s.delivery_target??null),jt(!!(c||Xt(s))))},[s,t,c]);const os=Se?te:At(H),{data:is}=Ds(w||null),{data:cs}=$s(w||null,{enabled:!!w}),rt=cn(is??null,cs?.catalog??[]),rs=xn(g),lt=de.trim().length>0,Ye=!c&&J==="code"?"":G,ls=!c&&J==="agent"?void 0:de.trim()||void 0,_t=(c||J==="code")&<,Nt=pn(Ye,rt,g,_t),ds=se||Ye.trim()!==""?Nt:null,bt=gn(Ye,rt),kt=!c&&J!=="agent",St=!!H.trim()&&!Nt&&(!kt||lt)&&!z,us=rs&&!_t&&bt.length===0,ms=()=>{if(!St)return;let a;if(ye==="fields"){const ke=Ht({entityType:Pe,entityPath:Me,fields:fe});if(ke.error){q(ke.error);return}a=ke.keyingConfig,q(null)}else{if(ve.trim())try{const ke=JSON.parse(ve);if(typeof ke!="object"||Array.isArray(ke)){q("Keying config must be a JSON object.");return}a=ke}catch{q("Invalid JSON. Please check the syntax.");return}q(null)}const O=xt(nt,"Timeout");if(O.error){A(O.error);return}if(O.value!==void 0&&(!Number.isInteger(O.value)||O.value<1)){A("Timeout must be a whole number greater than 0.");return}const K=xt(at,"Budget");if(K.error){A(K.error);return}if(K.value!==void 0&&K.value<0){A("Budget cannot be negative.");return}const R=xt(v,"Finalize nudges");if(R.error){A(R.error);return}if(R.value!==void 0&&(!Number.isInteger(R.value)||R.value<0||R.value>5)){A("Finalize nudges must be a whole number from 0 to 5.");return}const Ee={...O.value!==void 0?{timeout_seconds:O.value}:{},...K.value!==void 0?{max_budget_usd:K.value}:{},...Ue.trim()?{model:Ue.trim()}:{},...Ve?{permission_mode:Ve}:{},...Re.trim()?{effort:Re.trim()}:{},...R.value!==void 0?{finalize_nudges:R.value}:{}},B=Object.keys(Ee).length>0||c?Ee:void 0;A(null);const hs=je.trim()?je.split(",").map(ke=>ke.trim()).filter(Boolean):void 0;r({slug:os,name:H.trim(),description:I.trim()||void 0,prompt:Ye,skills:bt,entity_id:ge,sources:Oe,reaction_script:ls,keying_config:a,reactions_guidance:Be.trim()||void 0,execution_config:B,tags:hs,change_notes:De.trim()||void 0,managed_agent_id:F==="agent"&&w.trim()||null,device_worker_id:F==="device"&&Ne.trim()||null,agent_kind:F==="device"&&V.trim()||null,delivery_target:W})},wt=e.jsxs("div",{className:"space-y-2",children:[e.jsxs(b,{htmlFor:"scratch-reaction",children:["Reaction Script"," ",kt?e.jsx("span",{className:"text-destructive",children:"*"}):e.jsx("span",{className:"text-xs font-normal text-muted-foreground",children:"(optional)"})]}),e.jsx(ft,{value:de,onChange:Z,language:"typescript",placeholder:"export default async function reaction(ctx) { ... }",minHeight:"120px"}),c?null:e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Runs deterministically on every completed window, after agent extraction. Declare an ",e.jsx("code",{children:"input"})," export to set the window's extraction contract."]})]});return e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs(b,{htmlFor:"scratch-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),!c&&e.jsx("button",{type:"button",onClick:()=>le(!Se),className:"text-xs text-muted-foreground hover:text-foreground",children:Se?"Use automatic slug":"Customize slug"})]}),e.jsx(ae,{id:"scratch-name",value:H,onChange:a=>X(a.target.value),placeholder:"e.g., Escalation signals"}),!c&&Se?e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-slug",children:"Slug"}),e.jsx(ae,{id:"scratch-slug",value:te,onChange:a=>be(a.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")),placeholder:At(H)||"custom-slug"})]}):null]})}),c?null:e.jsxs("fieldset",{className:"space-y-2",children:[e.jsx("legend",{className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",children:"How does this run?"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Wt.map(a=>e.jsx("button",{type:"button","aria-pressed":J===a.value,onClick:()=>Ae(a.value),className:D("rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors",J===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:Wt.find(a=>a.value===J)?.hint})]}),c||J!=="code"?e.jsx(Tn,{value:G,onChange:a=>{ne(!0),Y(a)},library:rt,pinned:we,required:us,error:ds,owner:h??"",agentId:w,sources:c?Oe:void 0,onAddSources:c?x:void 0}):null,!c&&J!=="agent"?wt:null,c?e.jsx(Ln,{sources:Oe,onChange:x,disabled:u}):null,e.jsx("div",{className:"space-y-4",children:l}),e.jsx(An,{organizationId:n,agentId:F==="agent"?w.trim():"",value:W,onChange:f,disabled:u,automationName:H,onPendingChange:Q}),z?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(U,{type:"button",variant:"ghost",className:"w-full justify-between px-0 text-muted-foreground hover:bg-transparent hover:text-foreground","aria-expanded":ct,"aria-controls":"automation-advanced-settings",onClick:()=>jt(a=>!a),children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Is,{className:"h-4 w-4"}),"Advanced settings"]}),e.jsx(es,{className:D("h-4 w-4 transition-transform",ct&&"rotate-180")})]}),e.jsxs("div",{id:"automation-advanced-settings",className:D("space-y-4",!ct&&"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:I,onChange:a=>pe(a.target.value),placeholder:"What this automation does"})]}),!t&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Entity scope"}),e.jsx(Rn,{organizationId:n,value:ge,onChange:M}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Limit this automation to one workspace entity."})]}),c?wt:null,e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(b,{children:"Output fields"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Key fields become stable entity keys."})]}),e.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>{if(ye==="fields"){const a=Ht({entityType:Pe,entityPath:Me,fields:fe});if(a.error){q(a.error);return}Fe(a.keyingConfig?JSON.stringify(a.keyingConfig,null,2):""),Te("json")}else Te("fields");q(null)},children:ye==="fields"?"Edit JSON":"Use fields"})]}),ye==="fields"?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-output-entity-type",children:"Output entity type"}),e.jsx(st,{contentClassName:"w-[320px]",searchPlaceholder:"Search or type a new type…",emptyText:"Type a name to create a new entity type.",trigger:a=>e.jsxs(U,{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:D("truncate",!Pe&&"text-muted-foreground"),children:Pe||"Select entity type"}),e.jsx(yt,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]}),children:(a,O)=>{const K=He(O),R=P.filter(B=>!B.backing_sql),Ee=R.some(B=>B.slug===K);return e.jsxs(e.Fragment,{children:[R.map(B=>e.jsxs(Ke,{value:`${B.name??B.slug} ${B.slug}`,onSelect:()=>{me(B.slug),q(null),a()},className:"cursor-pointer",children:[e.jsx(tt,{className:D("mr-2 h-4 w-4",Pe===B.slug?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-mono text-sm",children:B.slug}),B.name&&B.name!==B.slug&&e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:B.name})]})]},B.slug)),K&&!Ee&&e.jsxs(Ke,{value:O,onSelect:()=>{me(K),q(null),a()},className:"cursor-pointer",children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),e.jsxs("span",{className:"text-sm",children:["Create"," ",e.jsx("span",{className:"font-mono",children:K})]})]})]})}})]}),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:Me,onChange:a=>{We(a.target.value),q(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(U,{type:"button",variant:"outline",size:"sm",onClick:()=>{he(a=>[...a,as()]),q(null)},children:[e.jsx(Je,{className:"mr-2 h-4 w-4"}),"Add field"]})]}),fe.length===0?e.jsx("div",{className:D(Ie,"px-3 py-2 text-sm text-muted-foreground"),children:"No output fields configured."}):e.jsx("div",{className:"space-y-2",children:fe.map(a=>e.jsxs("div",{className:D(Ie,"grid gap-2 p-3 sm:grid-cols-[minmax(0,1fr)_128px_minmax(0,240px)_auto]"),children:[e.jsx(ae,{value:a.name,onChange:O=>{const K=He(O.target.value);he(R=>R.map(Ee=>Ee.id===a.id?{...Ee,name:K}:Ee)),q(null)},placeholder:"severity","aria-label":"Output field name",className:"font-mono text-sm"}),e.jsxs(oe,{value:a.type,onValueChange:O=>{he(K=>K.map(R=>R.id===a.id?{...R,type:O}:R))},children:[e.jsx(ie,{"aria-label":"Output field type",children:e.jsx(ce,{})}),e.jsx(re,{children:$n.map(O=>e.jsx(T,{value:O,children:O},O))})]}),e.jsx("div",{className:"grid grid-cols-2 rounded-md border border-input bg-background p-1",children:In.map(O=>e.jsx("button",{type:"button",onClick:()=>{he(K=>K.map(R=>R.id===a.id?{...R,role:O.value}:R)),q(null)},className:D("rounded-sm px-2 py-1 text-xs transition-colors",a.role===O.value?"bg-muted/70 text-foreground":"text-muted-foreground hover:text-foreground"),children:O.label},O.value))}),e.jsx(U,{type:"button",variant:"ghost",size:"icon",onClick:()=>{he(O=>O.filter(K=>K.id!==a.id)),q(null)},"aria-label":"Remove output field",children:e.jsx(ts,{className:"h-4 w-4"})})]},a.id))})]}),ue&&e.jsx("p",{className:"text-xs text-destructive",children:ue})]}):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(ft,{value:ve,onChange:a=>{Fe(a),q(null)},language:"json",placeholder:'{ "entity_type": "topic", "entity_path": "$.items[*]", "key_fields": ["name"], "key_output_field": "entity_key" }',minHeight:"60px"}),ue&&e.jsx("p",{className:"text-xs text-destructive",children:ue})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-reactions-guidance",children:"Reactions Guidance"}),e.jsx(qs,{id:"scratch-reactions-guidance",value:Be,onChange:a=>Le(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:[Wn("Run settings","Choose where the automation runs and the budget it can use."),!N&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-runs-on",children:"Runs on"}),e.jsxs(oe,{value:F,onValueChange:a=>p(a),children:[e.jsx(ie,{id:"scratch-runs-on",className:"text-sm",children:e.jsx(ce,{})}),e.jsxs(re,{children:[e.jsx(T,{value:"agent",children:"Managed agent"}),e.jsx(T,{value:"device",children:"On a device"}),e.jsx(T,{value:"manual",children:"Manual-only"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:F==="agent"?"Automated runs dispatch to a managed Lobu agent.":F==="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."})]}),!N&&F==="agent"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-agent-id",children:"Agent"}),$?e.jsxs(oe,{value:w||"__unselected__",onValueChange:a=>{L(a==="__unselected__"?"":a)},children:[e.jsx(ie,{id:"scratch-agent-id",className:"font-mono text-sm",children:e.jsx(ce,{placeholder:"Select a Lobu agent"})}),e.jsx(re,{children:j.map(a=>e.jsxs(T,{value:a.agentId,children:[a.name," (",a.agentId,")"]},a.agentId))})]}):e.jsx(ae,{id:"scratch-agent-id",value:w,onChange:a=>{L(a.target.value)},placeholder:"e.g., agent-123",className:"font-mono text-sm"})]}),!N&&F==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-device-id",children:"Device"}),e.jsxs(oe,{value:Ne||"__unselected__",onValueChange:a=>k(a==="__unselected__"?"":a),children:[e.jsx(ie,{id:"scratch-device-id",className:"font-mono text-sm",children:e.jsx(ce,{placeholder:"Select a device worker"})}),e.jsx(re,{children:_.map(a=>e.jsx(T,{value:a.id,children:a.label||a.platform||a.id},a.id))})]})]}),!N&&F==="device"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-device-agent-kind",children:"Runs as"}),e.jsxs(oe,{value:V||"__default__",onValueChange:a=>xe(a==="__default__"?"":a),children:[e.jsx(ie,{id:"scratch-device-agent-kind",className:"text-sm",children:e.jsx(ce,{placeholder:"Device default"})}),e.jsxs(re,{children:[e.jsx(T,{value:"__default__",children:"Device default"}),Dn.map(a=>e.jsx(T,{value:a.value,children:a.label},a.value))]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Device default uses that device's preferred local agent. Availability is checked again when a run is claimed, so a run stays queued if its selected runtime is no longer available."})]}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{children:"Model"}),e.jsx(on,{value:Ue,onChange:a=>{Xe(a),A(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:nt,onChange:a=>{Ce(a.target.value),A(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:Ve||"__default__",onValueChange:a=>{it(a==="__default__"?"":a),A(null)},children:[e.jsx(ie,{id:"scratch-permission-mode",children:e.jsx(ce,{placeholder:"Default"})}),e.jsxs(re,{children:[e.jsx(T,{value:"__default__",children:"Default"}),ht.map(a=>e.jsx(T,{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:Re,onChange:a=>{d(a.target.value),A(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:v,onChange:a=>{C(a.target.value),A(null)},placeholder:"Default"})]})]}),ee&&e.jsx("p",{className:"text-xs text-destructive",children:ee})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(b,{htmlFor:"scratch-tags",children:"Tags"}),e.jsx(ae,{id:"scratch-tags",value:je,onChange:a=>E(a.target.value),placeholder:"ops, support, risk"})]}),c&&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:De,onChange:a=>ze(a.target.value),placeholder:"What changed in this version?"})]})]})]}),m&&!ue&&!ee&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:m}),e.jsx(gt,{onCancel:o,children:e.jsx(U,{onClick:ms,disabled:!St||u||S,children:u?e.jsxs(e.Fragment,{children:[e.jsx(Ks,{size:"lg",className:"mr-2"}),c?"Saving...":"Creating..."]}):c?"Save Automation":y})})]})}function Un(n,t){const s=n??null,r=t??null;return s===null||r===null?s===r:s.connection_id===r.connection_id&&s.channel_id===r.channel_id}function Vn(n){const t=n.detail??{};return{name:n.name,slug:t.slug,description:t.description??n.description??void 0,prompt:t.prompt,triggers:t.triggers,sources:t.sources,keying_config:t.keying_config,reactions_guidance:t.reactions_guidance,reaction_script:t.reaction_script,model_config:t.model_config,execution_config:t.execution_config,tags:t.tags}}function aa({onClose:n,hideCancel:t=!1,hideHeader:s=!1,organizationId:r,entityId:u,entityName:m,prefillAgentId:c,onSuccess:o,editingAutomation:l,catalogPrefill:y,onDraft:S,triggerFields:g,submitLabel:$,submitDisabled:h,createFields:j,onPrefillTriggers:_}){const w=Ws(),L=Bs(),N=Us(),W=Vs(),f=!!l,[z,Q]=i.useState("template"),[Ne,k]=i.useState(void 0),[F,p]=i.useState(void 0),{data:V=[],isLoading:xe}=zs(),[P,H]=i.useState(""),X=i.useMemo(()=>c?{managed_agent_id:c}:void 0,[c]),te=i.useMemo(()=>V.map(x=>({key:x.id,name:x.name,description:x.description??"",badges:x.detail?.tags??[]})),[V]),be=i.useMemo(()=>te.filter(x=>x.name.toLowerCase().includes(P.toLowerCase())||x.description.toLowerCase().includes(P.toLowerCase())),[te,P]),Se=x=>{const ge=V.find(de=>de.id===x.key);if(!ge)return;const M=Vn(ge);p(c?{...M,managed_agent_id:c}:M),_?.(M.triggers??[]),Q("scratch")},le=()=>{w.reset(),L.reset(),Q("template"),k(void 0),p(void 0),n()},I=f?j?.triggers??l.triggers??[]:j?.triggers??F?.triggers??y?.triggers??[],pe=async x=>{try{if(S){await S(x);return}if(f){const ge=j?.triggers??l.triggers??[],M=l.reaction_script??"",de=x.reaction_script??"";de&&de!==M&&await N.mutateAsync({automation_id:l.automation_id,reaction_script:de}),await L.mutateAsync({automation_id:l.automation_id,name:x.name,description:x.description,prompt:x.prompt,sources:x.sources,set_as_current:!0,triggers:ge,keying_config:x.keying_config,reactions_guidance:x.reactions_guidance,change_notes:x.change_notes}),!de&&M&&await N.mutateAsync({automation_id:l.automation_id,reaction_script:""});const Z={};x.model_config!==void 0&&(Z.model_config=x.model_config),x.execution_config!==void 0&&(Z.execution_config=x.execution_config),x.tags!==void 0&&(Z.tags=x.tags),x.delivery_target!==void 0&&!Un(x.delivery_target,l.delivery_target)&&(Z.delivery_target=x.delivery_target),x.managed_agent_id!==void 0&&(Z.managed_agent_id=x.managed_agent_id||null),x.agent_kind!==void 0&&(Z.agent_kind=x.agent_kind||null),x.device_worker_id!==void 0&&(Z.device_worker_id=x.device_worker_id||null),Object.keys(Z).length>0&&await W.mutateAsync({automation_id:l.automation_id,...Z}),le(),o?.(l.automation_id)}else{const ge=j?.triggers??F?.triggers??y?.triggers??[],M=await w.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:ge});le(),M.automation_id&&o?.(M.automation_id)}}catch{}},G=f?L:w;let Y="Add an automation";f?Y="Edit automation configuration (saves as a new version)":m&&(Y=`Add an automation for ${m}`);const se=l?{entity_id:l.entity_id,name:l.name,slug:l.slug,description:l.description,prompt:l.prompt,sources:l.sources,reaction_script:l.reaction_script,device_worker_id:l.device_worker_id??void 0,agent_kind:l.agent_kind??void 0,keying_config:l.keying_config,reactions_guidance:l.reactions_guidance,model_config:l.model_config,execution_config:l.execution_config,tags:l.tags,managed_agent_id:l.managed_agent_id??void 0,delivery_target:l.delivery_target??void 0}:void 0,ne=f?"Edit Automation":"Create Automation",we=e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("h1",{className:"text-2xl font-semibold leading-tight",children:ne}),e.jsx("p",{className:"text-sm text-muted-foreground",children:Y})]}),Oe=e.jsxs("div",{className:"py-6 space-y-6",children:[!f&&e.jsxs("div",{className:"flex flex-wrap justify-start gap-2",children:[e.jsx(pt,{active:z==="template",onClick:()=>Q("template"),icon:e.jsx(Qs,{className:"h-4 w-4"}),label:"From templates"}),e.jsx(pt,{active:z==="scratch",onClick:()=>{Q("scratch"),k(void 0),p(void 0)},icon:e.jsx(Je,{className:"h-4 w-4"}),label:"From scratch"}),e.jsx(pt,{active:z==="clone",onClick:()=>Q("clone"),icon:e.jsx(Gs,{className:"h-4 w-4"}),label:"Clone existing"})]}),!f&&z==="template"?e.jsxs(e.Fragment,{children:[xe?e.jsx(Js,{}):e.jsx(Hs,{items:be,searchQuery:P,onSearchChange:H,onSelect:Se,searchPlaceholder:"Search templates...",searchAriaLabel:"Search automation templates",emptyMessage:te.length===0?"No automation templates available.":void 0}),s&&!t?e.jsx(gt,{onCancel:le}):null]}):!f&&z==="clone"&&!Ne?e.jsxs(e.Fragment,{children:[e.jsx(zn,{organizationId:r,onSelect:x=>{k(x),_?.(x.triggers??[]),Q("scratch")}}),s&&!t?e.jsx(gt,{onCancel:le}):null]}):e.jsx(Bn,{organizationId:r,entityId:u,prefill:se??Ne??F??y??X,onSubmit:pe,isSubmitting:G.isPending,error:G.error?G.error.message:null,isEditing:f,onCancel:t?void 0:le,triggerFields:g,submitLabel:$,submitDisabled:h,triggers:I})]});return e.jsxs("div",{className:"flex flex-col",children:[s?null:we,Oe]})}function pt({active:n,onClick:t,icon:s,label:r}){return e.jsxs("button",{type:"button",onClick:t,className:D("flex items-center gap-2 rounded-md border px-3 py-2 text-sm transition-colors",n?"border-primary bg-primary/5 text-primary":"border-border text-muted-foreground hover:border-muted-foreground/30 hover:text-foreground"),children:[s,r]})}function zn({organizationId:n,onSelect:t}){const{data:s,isLoading:r}=Xs(n),[u,m]=i.useState(""),c=(s||[]).filter(o=>o.name?.toLowerCase().includes(u.toLowerCase()));return r?e.jsx(Ys,{label:"automations",variant:"list-picker",rows:4}):!s||s.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"No existing automations to clone."}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("input",{type:"text",value:u,onChange:o=>m(o.target.value),placeholder:"Search automations...",className:"w-full rounded-md border px-3 py-2 text-sm bg-background"}),e.jsxs("div",{className:"space-y-2 max-h-[400px] overflow-y-auto",children:[c.map(o=>e.jsxs("button",{type:"button",onClick:()=>t({name:`${o.name} (copy)`,slug:`${o.slug||o.automation_id}-copy`,prompt:o.prompt,keying_config:o.keying_config,triggers:o.triggers,sources:o.sources}),className:"w-full text-left rounded-md border p-3 hover:border-primary/50 hover:bg-primary/5 transition-colors",children:[e.jsx("p",{className:"text-sm font-medium",children:o.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[o.entity_name||"Space-level"," · v",o.version??"?"]})]},o.automation_id)),c.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No automations match your search."})]})]})}export{na as A,aa as C};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as t,a2 as o}from"./index-DtRfQcRH.js";const n=()=>t.jsx(o,{});export{n as component};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,fK as C,n as w,hu as b,r as x,s as k,bq as A,hv as v,B as m,hw as F,E as L,bA as I,al as S,aV as E,hx as y,aG as P,hy as R,hz as $,eH as _,L as O,P as z,b as B,hA as T,hB as D,t as K,hC as V,eJ as q}from"./index-DtRfQcRH.js";import{a as H,R as M}from"./runs-panel-B2852xus.js";import{S as G,g as J,c as N,b as U,d as X}from"./runs-table--dnFQatY.js";function ae({formRows:s=5}){return e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsx(H,{}),e.jsx(C,{rows:s})]})}function Q(s,a){const n=s?.display_name;return typeof n=="string"&&n.trim()?n:a?.trim()||"Folder"}function W({connectionId:s}){const{data:a=[],isLoading:n}=w(s),o=b(),[c,r]=x.useState(null),i=a.filter(t=>t.config?.folder_id!=null),d=()=>{window.location.href=y("feeds/add"),P("Opening Lobu…",{description:"Choose a folder in the Lobu app. It appears here after the next sync."})},l=t=>{const u=t.config?.folder_id;typeof u=="string"&&(window.location.href=y(`feeds/remove?folder_id=${encodeURIComponent(u)}`)),o.mutate(t.id),r(null)};return n?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(k,{size:"lg"})}):i.length===0?e.jsx(A,{icon:v,title:"No folders yet",description:"Add a local folder for Lobu to read text files from.",actionLabel:"Add folder",onAction:d}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Folders"}),e.jsxs(m,{variant:"outline",size:"sm",onClick:d,children:[e.jsx(F,{className:"mr-2 h-4 w-4"}),"Add folder"]})]}),e.jsx("div",{className:"space-y-2",children:i.map(t=>e.jsxs("div",{className:S(E,"flex items-center justify-between gap-3 px-3 py-2"),children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx(v,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:Q(t.config,t.display_name)}),e.jsxs("p",{className:"truncate text-xs text-muted-foreground",children:[t.event_count>0?`${t.event_count} document${t.event_count===1?"":"s"}`:"No documents yet",t.last_sync_at?` · synced ${L(t.last_sync_at)}`:""]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[e.jsx(G,{status:J(t.status),children:t.status}),c===t.id?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(m,{variant:"destructive",size:"sm",onClick:()=>l(t),children:"Remove"}),e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>r(null),children:"Cancel"})]}):e.jsx(m,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive","aria-label":"Remove folder",onClick:()=>r(t.id),children:e.jsx(I,{className:"h-4 w-4"})})]})]},t.id))})]})}function ne({connection:s,connectorDef:a,ownerSlug:n,openSettings:o=!1,authResult:c,showActivity:r=!0,embedded:i=!1}){const[d,l]=x.useState(o);x.useEffect(()=>{o&&l(!0)},[o]);const t=s.id,u=s.connector_key,h=s.facets?.chat??!1,p=h?"Channels":"Feeds",f=s.has_operations===!0,j=s.feed_count>0||N(a),g=e.jsx(D,{connection:s,connectorDef:a,ownerSlug:n});return e.jsxs("div",{className:"space-y-6",children:[c&&e.jsx(R,{result:c}),s.auth_profile_kind==="oauth_account"&&e.jsx($,{connection:s,connectorDef:a,onReview:()=>{l(!0),requestAnimationFrame(()=>document.getElementById("connection-auth")?.scrollIntoView({block:"nearest"}))}}),u==="local.directory"&&e.jsx(W,{connectionId:t}),(j||f)&&e.jsxs("div",{className:i?"space-y-6":"grid grid-cols-1 items-start gap-3 sm:grid-cols-2",children:[j&&(i?e.jsx(_,{title:p,count:s.feed_count===1?"1 source":`${s.feed_count} sources`,action:N(a)?e.jsx(m,{asChild:!0,size:"sm",variant:"outline",children:e.jsxs(O,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:n,connectorKey:u,connectionId:String(t)},search:{addFeed:!0},children:[e.jsx(z,{className:"h-3.5 w-3.5"}),h?"Add channel":"Add source"]})}):null,children:e.jsx(U,{connection:s,ownerSlug:n,connectorKey:u,connectorDef:a})}):e.jsx(X,{connection:s,ownerSlug:n,title:p})),f&&(i?e.jsx(B,{connection:s}):e.jsx(Y,{connection:s,ownerSlug:n}))]}),i?e.jsx(T,{title:"Connection settings",summary:"name, visibility, credentials, remove",open:d,onOpenChange:l,children:g}):g,r&&!h&&e.jsx(_,{title:"Recent activity",children:e.jsx(M,{scope:{connectionId:t},ownerSlug:n})})]})}function Y({connection:s,ownerSlug:a}){const n=K(),{data:o=[],isLoading:c,isError:r}=V(s.id),i=o.filter(l=>l.readiness==="scope_upgrade_required").length,d=c?"Loading actions…":r?"Could not load actions — open to retry":`${o.length} actions${i?` · ${i} need additional provider access`:" · permissions and approval policy"}`;return e.jsx(q,{title:"Actions",summary:d,onOpen:()=>n?.open({href:"",title:"Actions",connectorPanel:{section:"actions",connectionId:s.id,connectorKey:s.connector_key,organizationId:s.organization_id,ownerSlug:a}})})}const Z=new Set(["Device was removed","Device was moved to another workspace"]);function ie(s){const a=s.error_message??null;return!a||!Z.has(a)?a:!!s.device_worker_id&&(s.device_last_seen_at!=null||s.device_worker_handle!=null||s.device_label!=null)?null:a}export{ne as C,ae as R,ie as c};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{ci as u,eI as l,bu as f}from"./index-DtRfQcRH.js";function p(n){return l(n)&&n.required_capability!=="os.files"}const m={data:!1,chat:!1,actions:!1,audience:!1,inference:!1,runtime:!0};function _(n){return n==="macos"?"macOS":n==="ios"?"iOS":n==="chrome-extension"?"Chrome":n??"Unknown platform"}function y(n,c,o){const i=new Map(c.map(e=>[e.connector_key,e]));return n.map(e=>{const s={...m};for(const r of e.connectors){if(r.organization_slug!==o)continue;const a=i.get(r.connector_key);if(a?.connections.some(t=>t.id===r.connection_id))for(const t of Object.keys(s))s[t]||=a.facets[t]}return{device:e,facets:s,connector:{key:`device-row:${e.id}`,name:u(e),description:null,version:"",auth_schema:null,feeds_schema:null,actions_schema:null,options_schema:null,status:e.online?"active":"inactive",login_enabled:!1,installed:!0}}})}function b(n){const c=_(f(n)),o=n.connector_count,i=`${o} ${o===1?"connector":"connectors"}`;return[c,i,n.online?"online":"offline"].join(" · ")}export{y as b,p as c,b as d};
|