@lobu/runtime-server 20.1.0 → 20.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component.json +1 -1
- package/dist/connectors/chat-user-identity.ts +41 -0
- package/dist/connectors/google-identity.ts +11 -0
- package/dist/connectors/slack-identity.ts +19 -0
- package/dist/db/migrations/20260915030000_owner_dm_delivery_request_platform.sql +51 -0
- package/dist/dependencies.bun.lock +28 -30
- package/dist/owletto/dist/assets/{_-DdvHIadV.js → _-Ds4DyQjj.js} +2 -2
- package/dist/owletto/dist/assets/_-VmyR6aN_.js +1 -0
- package/dist/owletto/dist/assets/{_agentId-DbTBU4KZ.js → _agentId-BAVnp0c7.js} +1 -1
- package/dist/owletto/dist/assets/_agentId-Df-3rGi5.js +1 -0
- package/dist/owletto/dist/assets/{_automationId-C7dZzg6X.js → _automationId-D696vOjd.js} +1 -1
- package/dist/owletto/dist/assets/{_connectorKey._connectionId-NQf43Ew3.js → _connectorKey._connectionId-BAJGfcy7.js} +1 -1
- package/dist/owletto/dist/assets/{_connectorKey.index-D-0ZNsgM.js → _connectorKey.index-BBF8vGJS.js} +1 -1
- package/dist/owletto/dist/assets/{_conversationId-F5YmyLV9.js → _conversationId-Ci4rgrHm.js} +1 -1
- package/dist/owletto/dist/assets/{_deploymentId-3LTMi0ZT.js → _deploymentId-Iy-D5PDq.js} +1 -1
- package/dist/owletto/dist/assets/_name-CeGwb0oK.js +1 -0
- package/dist/owletto/dist/assets/{_owner-DglbbDEx.js → _owner-CFR1G8OX.js} +1 -1
- package/dist/owletto/dist/assets/_skillKey-DuLcQWBu.js +1 -0
- package/dist/owletto/dist/assets/{_slug-CnQDfsCE.js → _slug-CDSO20ac.js} +1 -1
- package/dist/owletto/dist/assets/{accept-invitation-Dgoyublh.js → accept-invitation-Db5jklHT.js} +1 -1
- package/dist/owletto/dist/assets/{activity-route-view-BNzKO6aD.js → activity-route-view-DVW3DoB7.js} +1 -1
- package/dist/owletto/dist/assets/{agent-card-controls-VJgcB5-0.js → agent-card-controls-CZO6GI0s.js} +1 -1
- package/dist/owletto/dist/assets/{agent-client-setup-list-C5KRNRw3.js → agent-client-setup-list-_chLOorY.js} +1 -1
- package/dist/owletto/dist/assets/{agent-connect-pages-BFSb6vmW.js → agent-connect-pages-DWBgSIYT.js} +1 -1
- package/dist/owletto/dist/assets/{agent-editor-form-CajEehVn.js → agent-editor-form-BTNlg0kQ.js} +1 -1
- package/dist/owletto/dist/assets/{agent-guardrails-route-CZ_rXj-3.js → agent-guardrails-route-B5uoMC6o.js} +1 -1
- package/dist/owletto/dist/assets/{agent-loading-shells-Dczhk067.js → agent-loading-shells-CLoLeFcB.js} +1 -1
- package/dist/owletto/dist/assets/{agent-permissions-matrix-DIVHvpZG.js → agent-permissions-matrix-TP00-MYL.js} +1 -1
- package/dist/owletto/dist/assets/{agent-skill-context-CxglCznW.js → agent-skill-context-D4a2QCoZ.js} +1 -1
- package/dist/owletto/dist/assets/{agent-skills-route-CatU8soC.js → agent-skills-route-KVDDTbJB.js} +1 -1
- package/dist/owletto/dist/assets/{agent-subpage-shell-DVSUdIBn.js → agent-subpage-shell-DuVYZvBE.js} +1 -1
- package/dist/owletto/dist/assets/{agent-thread-DnLUOzXk.js → agent-thread-CzCJU3-R.js} +1 -1
- package/dist/owletto/dist/assets/agents-DFs57C3c.js +1 -0
- package/dist/owletto/dist/assets/{agents-workbench-BOKifKIO.js → agents-workbench-C2bUlJP2.js} +1 -1
- package/dist/owletto/dist/assets/{app._appId-BXmITXO7.js → app._appId-D0_LQTJU.js} +1 -1
- package/dist/owletto/dist/assets/{automation-detail-content-wJC9hhmA.js → automation-detail-content-DWkdhnv2.js} +1 -1
- package/dist/owletto/dist/assets/automations-DFs57C3c.js +1 -0
- package/dist/owletto/dist/assets/{calendar-taCoBmAh.js → calendar-C0XpOHd8.js} +1 -1
- package/dist/owletto/dist/assets/{callback-CJxC8u_x.js → callback-CO_K9eR-.js} +1 -1
- package/dist/owletto/dist/assets/{card-kpw3EaKC.js → card-DeFQuU_J.js} +1 -1
- package/dist/owletto/dist/assets/{claim-DLHRN0bA.js → claim-CUpWOSie.js} +1 -1
- package/dist/owletto/dist/assets/{clients-R4JsT_Fz.js → clients-DhYr4lyL.js} +1 -1
- package/dist/owletto/dist/assets/{code-editor-D3X0yQdI.js → code-editor-BqGUZFt6.js} +1 -1
- package/dist/owletto/dist/assets/connect-Dtb-E5An.js +1 -0
- package/dist/owletto/dist/assets/connect._clientId-DWtceAAw.js +1 -0
- package/dist/owletto/dist/assets/{connected._clientId-ByH4etku.js → connected._clientId-CMe-wTuV.js} +1 -1
- package/dist/owletto/dist/assets/{connection-DdBkXNbX.js → connection-BgAlYjeV.js} +1 -1
- package/dist/owletto/dist/assets/{connection-feed-detail-DF93zx0A.js → connection-feed-detail-B3ePAinf.js} +1 -1
- package/dist/owletto/dist/assets/{connector-provenance-N3sc0nbo.js → connector-provenance-DgsDg0Z9.js} +1 -1
- package/dist/owletto/dist/assets/{connectors-Ckn_aoNE.js → connectors-CqPQPo9U.js} +1 -1
- package/dist/owletto/dist/assets/{consent-Bi6KCVtT.js → consent-bswcIzsf.js} +1 -1
- package/dist/owletto/dist/assets/{core.esm-CFYXLQXH.js → core.esm-DsLgjoel.js} +1 -1
- package/dist/owletto/dist/assets/create-CcXUdke7.js +1 -0
- package/dist/owletto/dist/assets/create-Cp6hMoeU.js +1 -0
- package/dist/owletto/dist/assets/{create-BiHpu2f4.js → create-Dwo04oWV.js} +1 -1
- package/dist/owletto/dist/assets/{create-automation-form-Cv2RHsQ6.js → create-automation-form-CJ4meayB.js} +1 -1
- package/dist/owletto/dist/assets/{create._connectorKey-Qynix_hA.js → create._connectorKey-CCBb2pil.js} +1 -1
- package/dist/owletto/dist/assets/{cronstrue-D7xlYtGk.js → cronstrue-ChFyC9ps.js} +1 -1
- package/dist/owletto/dist/assets/deployments-CjfFxyDA.js +1 -0
- package/dist/owletto/dist/assets/{deployments-body-BPCALbQe.js → deployments-body-Cg0KiWGr.js} +1 -1
- package/dist/owletto/dist/assets/device-DpY67Jaj.js +1 -0
- package/dist/owletto/dist/assets/{device-pin-tombstone-DrTJYNKG.js → device-pin-tombstone-1ikyqSdb.js} +1 -1
- package/dist/owletto/dist/assets/{device-rows-fVm-zAiU.js → device-rows-Cp3yMcuV.js} +1 -1
- package/dist/owletto/dist/assets/{device._deviceId-CIe7taim.js → device._deviceId-DTYKGBY8.js} +1 -1
- package/dist/owletto/dist/assets/{entity-options-DOGD_EyZ.js → entity-options-1EaSGMX4.js} +1 -1
- package/dist/owletto/dist/assets/{entity-page-C8oDszRY.js → entity-page-DJmM70dv.js} +1 -1
- package/dist/owletto/dist/assets/{entity-type-page-BfxIgJLq.js → entity-type-page-C3mT7tXn.js} +1 -1
- package/dist/owletto/dist/assets/{events-feed-B9OqmSBy.js → events-feed-iliGfjit.js} +1 -1
- package/dist/owletto/dist/assets/{full-page-spinner-DTSqneUO.js → full-page-spinner-BN2G_YiM.js} +1 -1
- package/dist/owletto/dist/assets/guardrails-CLlnRRy9.js +1 -0
- package/dist/owletto/dist/assets/identity-MSLryUi8.js +1 -0
- package/dist/owletto/dist/assets/index-3o4Eepb4.js +1 -0
- package/dist/owletto/dist/assets/{index-Bfux0kHb.js → index-BUr8321-.js} +3 -3
- package/dist/owletto/dist/assets/{index-CK2-iHcz.js → index-Bulu5ldM.js} +1 -1
- package/dist/owletto/dist/assets/{index-DcWyuLQS.js → index-BvbfITqH.js} +1 -1
- package/dist/owletto/dist/assets/{index-Bq4m-sK0.js → index-C-u4yR8Z.js} +1 -1
- package/dist/owletto/dist/assets/{index-DkKALC2l.js → index-C2oCgDX7.js} +1 -1
- package/dist/owletto/dist/assets/{index-jGZeANLE.js → index-C6VAJ8Ku.js} +1 -1
- package/dist/owletto/dist/assets/index-Clw9ZBj-.js +1 -0
- package/dist/owletto/dist/assets/index-D2oL4Ydo.js +1 -0
- package/dist/owletto/dist/assets/index-D7wulT4y.js +1 -0
- package/dist/owletto/dist/assets/{index-COgBJ_ab.js → index-DOLFe19K.js} +1 -1
- package/dist/owletto/dist/assets/index-DTSA0Xh1.js +1 -0
- package/dist/owletto/dist/assets/index-DxXXVPU0.js +1 -0
- package/dist/owletto/dist/assets/{index-CMOHHdFH.js → index-hSE2E46p.js} +1 -1
- package/dist/owletto/dist/assets/index-nzvsA3hT.js +1 -0
- package/dist/owletto/dist/assets/{index-DYe_DVHa.js → index-vdqhlocx.js} +1 -1
- package/dist/owletto/dist/assets/{json-diff-CANZD4MQ.js → json-diff-DnsW7Pin.js} +1 -1
- package/dist/owletto/dist/assets/{list-skeleton-DZTUxpBx.js → list-skeleton-CHzLN7GK.js} +1 -1
- package/dist/owletto/dist/assets/{login-D53geSP7.js → login-CCKNM0gV.js} +1 -1
- package/dist/owletto/dist/assets/{logout-DKQS25qd.js → logout-B-N2aodZ.js} +1 -1
- package/dist/owletto/dist/assets/{member-scope-gate-C4QyRm2Q.js → member-scope-gate-B560Wg-t.js} +1 -1
- package/dist/owletto/dist/assets/{memory-browse-page-DOpV3vht.js → memory-browse-page-DMDqKJn7.js} +1 -1
- package/dist/owletto/dist/assets/{model-selector-CvU3VP90.js → model-selector-DfbmHjLu.js} +1 -1
- package/dist/owletto/dist/assets/models-M51OGDRE.js +1 -0
- package/dist/owletto/dist/assets/{new-B8_sRMYD.js → new-BVQS9H-Y.js} +1 -1
- package/dist/owletto/dist/assets/{new-DIjOVXrQ.js → new-Df_dY6Z5.js} +1 -1
- package/dist/owletto/dist/assets/{new-Df1q7GEj.js → new-DxDVE9nL.js} +1 -1
- package/dist/owletto/dist/assets/{oauth-workspace-access-DWfiekRz.js → oauth-workspace-access-D9GmiMfK.js} +1 -1
- package/dist/owletto/dist/assets/{organization-DHEC7kDq.js → organization-uSDYkJpX.js} +1 -1
- package/dist/owletto/dist/assets/{permissions-i7iwnE1a.js → permissions-Fe0DP6b8.js} +1 -1
- package/dist/owletto/dist/assets/{proposal-review-shell-C_LcyUEF.js → proposal-review-shell-D9HwnDda.js} +1 -1
- package/dist/owletto/dist/assets/{recent-By19_Buq.js → recent-C03LhMD7.js} +1 -1
- package/dist/owletto/dist/assets/{renderer-B1UThnk2.js → renderer-CHNejd95.js} +1 -1
- package/dist/owletto/dist/assets/{reset-password-Dsz5-Xeo.js → reset-password-CuISnlG_.js} +1 -1
- package/dist/owletto/dist/assets/{runs-BQ11PAQT.js → runs-BnYdToDc.js} +1 -1
- package/dist/owletto/dist/assets/{runs-panel-wkV1aGD9.js → runs-panel-DsdESupx.js} +1 -1
- package/dist/owletto/dist/assets/{runs-table-DzSWYkaf.js → runs-table-B7jKuILd.js} +1 -1
- package/dist/owletto/dist/assets/{schema-value-normalization--DhnhJNf.js → schema-value-normalization-B--OWDL8.js} +1 -1
- package/dist/owletto/dist/assets/settings-Bg9yCCoN.js +1 -0
- package/dist/owletto/dist/assets/{settings-Bu239SXe.js → settings-wGNHtsDP.js} +1 -1
- package/dist/owletto/dist/assets/skills-CN5Ube7A.js +1 -0
- package/dist/owletto/dist/assets/{switch-CCKllS7w.js → switch-Dzse_XFM.js} +1 -1
- package/dist/owletto/dist/assets/{use-mention-search-CldNZTiT.js → use-mention-search-uyW1Uwf6.js} +1 -1
- package/dist/owletto/dist/index.html +1 -1
- package/dist/server-main.bundle.mjs +9903 -9541
- package/npm-shrinkwrap.json +116 -140
- package/package.json +1 -1
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/core/dist/credentials.d.ts +16 -1
- package/vendor/core/dist/credentials.js +10 -1
- package/vendor/core/package.json +1 -1
- package/dist/owletto/dist/assets/_-CfcfHJO8.js +0 -1
- package/dist/owletto/dist/assets/_agentId-BTmFhpb6.js +0 -1
- package/dist/owletto/dist/assets/_name-BKeZbc-h.js +0 -1
- package/dist/owletto/dist/assets/_skillKey-DhiGYYFq.js +0 -1
- package/dist/owletto/dist/assets/agents-OLmcj-qM.js +0 -1
- package/dist/owletto/dist/assets/automations-OLmcj-qM.js +0 -1
- package/dist/owletto/dist/assets/connect-1ysEq9l0.js +0 -1
- package/dist/owletto/dist/assets/connect._clientId-BbMPs6l3.js +0 -1
- package/dist/owletto/dist/assets/create-C37QtjbJ.js +0 -1
- package/dist/owletto/dist/assets/create-kAQa5_Q7.js +0 -1
- package/dist/owletto/dist/assets/deployments-C5kSeowq.js +0 -1
- package/dist/owletto/dist/assets/device-DToHXxDM.js +0 -1
- package/dist/owletto/dist/assets/guardrails-9Mr6avxk.js +0 -1
- package/dist/owletto/dist/assets/identity-DMfCjdBz.js +0 -1
- package/dist/owletto/dist/assets/index-CkwwaMrx.js +0 -1
- package/dist/owletto/dist/assets/index-D0lZrXrY.js +0 -1
- package/dist/owletto/dist/assets/index-DZadnZpq.js +0 -1
- package/dist/owletto/dist/assets/index-DlqjyZKQ.js +0 -1
- package/dist/owletto/dist/assets/index-Dv0huHrO.js +0 -1
- package/dist/owletto/dist/assets/index-DxIDxgPJ.js +0 -1
- package/dist/owletto/dist/assets/index-bKUccXCc.js +0 -1
- package/dist/owletto/dist/assets/models-ooBIWFuB.js +0 -1
- package/dist/owletto/dist/assets/settings-FxbIvOhH.js +0 -1
- package/dist/owletto/dist/assets/skills-MBZ5ilDK.js +0 -1
package/dist/owletto/dist/assets/{device._deviceId-CIe7taim.js → device._deviceId-DTYKGBY8.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{dI as K,h1 as O,j as e,fi as N,S as _,B as j,bq as E,L as w,dU as A,r as b,dz as F,dB as H,dC as V,a as q,a2 as U,bb as W,h2 as Y,h3 as G,h4 as J,b7 as Q,bc as P,h5 as X,h6 as Z,gH as ee,bF as se,g2 as ne,h7 as L,ab as te,d8 as R,s as $,bw as ae,H as ie,bp as ce,g3 as oe,g4 as re,x as le,h8 as B,aV as de}from"./index-Bfux0kHb.js";import{c as me,C as xe,R as ue}from"./device-pin-tombstone-DrTJYNKG.js";import{R as he}from"./runs-panel-wkV1aGD9.js";import{S as pe,g as fe}from"./runs-table-DzSWYkaf.js";import{c as ge}from"./connection-label-BobuYiAG.js";import{c as je}from"./device-rows-fVm-zAiU.js";import"./runs-BQ11PAQT.js";function ve({device:t,organizationId:s,ownerSlug:r,selectedConnection:p,openSettings:u}){const{data:d=[],isLoading:g,isError:h,refetch:l}=K(s),c=new Map(d.map(i=>[i.key,i])),a=new Map,m=[];for(const i of t.connectors){if(i.organization_slug!==r)continue;const o=c.get(i.connector_key);if(!o||!je(o)){m.push(i);continue}const v=o.required_capability??`connector:${o.key}`,f=a.get(v)??{key:v,name:o.name,connections:[]};f.name=O[v]??o.name,f.connections.push(i),a.set(v,f)}return e.jsxs(e.Fragment,{children:[e.jsxs(N,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),t.online?null:e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"This device is offline. You can edit its settings; actions and sync need it to reconnect."}),!s||g?e.jsx(_,{className:"h-24 w-full"}):h?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void l(),children:"Retry"})]}):a.size===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No native connections on this device in this workspace."}):e.jsx("div",{className:"divide-y border-y",children:[...a.values()].map(i=>e.jsx(be,{group:i,deviceId:t.id,organizationId:s,ownerSlug:r,definitionsByKey:c,selectedConnection:p,openSettings:u},i.key))}),E(t)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),s&&m.length>0&&!g&&!h?e.jsxs(N,{title:"Connections",count:String(m.length),children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Apps and sources that use this device."}),e.jsx("div",{className:"divide-y border-y",children:m.map(i=>e.jsxs(w,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:r,connectorKey:i.connector_key,connectionId:String(i.connection_id)},search:{},className:"flex items-center gap-3 py-3 text-sm hover:text-primary",children:[e.jsx("span",{className:"min-w-0 flex-1",children:i.display_name||c.get(i.connector_key)?.name||i.connector_key}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i.status}),e.jsx(A,{className:"size-3.5 text-muted-foreground"})]},i.connection_id))})]}):null]})}function be({group:t,deviceId:s,organizationId:r,ownerSlug:p,definitionsByKey:u,selectedConnection:d,openSettings:g}){const h=t.connections.some(a=>a.connection_id===d),[l,c]=b.useState(h);return b.useEffect(()=>{h&&d!==void 0&&c(!0)},[h,d]),e.jsxs(F,{open:l,onOpenChange:c,children:[e.jsxs(H,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(A,{className:"size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90"}),e.jsx("span",{className:"min-w-0 flex-1 text-sm font-medium",children:t.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:t.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":t.connections.length>1?`${t.connections.length} connections`:"Configured"})]}),e.jsx(V,{forceMount:!0,hidden:!l,className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:t.connections.map(a=>e.jsx(Ne,{summary:a,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u.get(a.connector_key),openSettings:a.connection_id===d&&g},a.connection_id))})})]})}function Ne({summary:t,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u,openSettings:d}){const{data:g=[],isLoading:h,isError:l,refetch:c}=q(r,{connectionIds:[t.connection_id]}),a=g.find(o=>o.id===t.connection_id&&o.device_worker_id===s),m=u?.name??t.connector_key,i=a?me(a):null;return e.jsxs("section",{id:`connection-${t.connection_id}`,"aria-label":m,className:"scroll-mt-24",children:[a?e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:ge(a)}),e.jsx("span",{children:a.status})]}):null,h||!r?e.jsx(_,{className:"h-24 w-full"}):l?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void c(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[i?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:i}):null,e.jsx(xe,{connection:a,connectorDef:u,ownerSlug:p,openSettings:d,showActivity:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function _e({ownerSlug:t,deviceId:s,organizationId:r,selectedConnection:p,openSettings:u}){const d=U(),{data:g=[],isLoading:h}=W(),l=Y(),c=G(),[a,m]=b.useState(!1),[i,o]=b.useState(!1),[v,f]=b.useState(""),n=J(g,s),y=n?.id??s,{data:k=[]}=Q(r,{profileKind:"browser_session"}),C=b.useMemo(()=>k.filter(x=>x.device_worker_id===y&&x.status!=="revoked"),[k,y]),D=n?.label?.trim()??"";if(b.useEffect(()=>{i||f(D)},[D,i]),h)return e.jsxs(P,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"h-6 w-6 rounded"}),e.jsx(_,{className:"h-5 w-40"})]}),e.jsx(ue,{})]});if(!n)return e.jsxs(P,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This device isn't in this workspace, so its details aren't available."}),e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const I=E(n),z=X(n.app_version),T=Z(n,z),S=()=>{const x=v.trim(),M=n.label?.trim()??"";if(x===M){o(!1);return}c.mutate({deviceWorkerId:n.id,label:x.length===0?null:x},{onSuccess:()=>o(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(ee,{header:e.jsx(ne,{breadcrumb:e.jsx(oe,{crumbs:[e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:re,children:"Connectors"},"connectors")]}),icon:e.jsx(ce,{platform:I,className:"h-5 w-5"}),title:i?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{"aria-label":"Device name",value:v,onChange:x=>f(x.target.value),placeholder:R({...n,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:x=>{x.key==="Enter"?(x.preventDefault(),a||S()):x.key==="Escape"&&(m(!1),f(n.label?.trim()??""),o(!1))}}),a?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Forgets this device"," ",n.connector_count>0?`and un-pins ${n.connector_count} connector${n.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(j,{variant:"destructive",size:"sm",disabled:l.isPending,onClick:()=>l.mutate(n.id,{onSuccess:()=>{m(!1),d({to:"/$owner/connectors",params:{owner:t},search:{}})}}),children:[l.isPending?e.jsx($,{className:"mr-1.5"}):null,l.isPending?"Removing...":"Confirm remove"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:l.isPending,onClick:()=>m(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{size:"sm",onClick:S,disabled:c.isPending,children:[c.isPending?e.jsx($,{className:"mr-1.5"}):null,c.isPending?"Saving...":"Save"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:c.isPending,onClick:()=>{f(n.label?.trim()??""),o(!1)},children:"Cancel"}),e.jsxs(j,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:c.isPending||l.isPending,onClick:()=>m(!0),children:[e.jsx(ae,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[R(n),e.jsx(j,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{m(!1),f(n.label?.trim()??""),o(!0)},children:e.jsx(ie,{className:"h-3.5 w-3.5"})})]}),badge:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:`size-1.5 rounded-full ${n.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),n.online?n.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:T||void 0,caption:`Last seen ${L(new Date(n.last_seen_at),{addSuffix:!0})}${n.last_sync_at?` · Last sync ${L(new Date(n.last_sync_at),{addSuffix:!0})}`:""}`}),children:[n.connector_error_count>0?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[e.jsx(se,{className:"h-3.5 w-3.5 shrink-0"}),n.connector_error_count," connector",n.connector_error_count===1?"":"s"," pinned to this device ",n.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(ve,{device:n,organizationId:r,ownerSlug:t,selectedConnection:p,openSettings:u}),C.length>0?e.jsx(N,{title:"Browser auth profiles",children:e.jsx(ye,{profiles:C})}):null,e.jsx(N,{title:"Runs",children:e.jsx(he,{scope:{deviceId:y},ownerSlug:t})})]})})}function ye({profiles:t}){return t.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:t.map(s=>e.jsxs("li",{className:"space-y-2 px-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:s.display_name}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:s.connector_key??"Any connector"}),s.browser_kind?e.jsxs("span",{children:["· ",s.browser_kind]}):null,s.captured_at?e.jsxs("span",{title:s.captured_at,children:["· captured ",le(s.captured_at)]}):null,typeof s.cookie_count=="number"?e.jsxs("span",{children:["· ",s.cookie_count," cookie",s.cookie_count===1?"":"s"]}):null]})]}),e.jsx(pe,{status:s.is_expired?"error":fe(s.status),showDot:!0,children:s.is_expired?"expired":s.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},s.id))})})}function Re(){const{owner:t,deviceId:s}=B.useParams(),{connection:r,settings:p}=B.useSearch();return e.jsx(de,{owner:t,children:({ownerSlug:u,organizationId:d})=>e.jsx(_e,{ownerSlug:u,deviceId:s,organizationId:d,selectedConnection:r,openSettings:p})})}export{Re as component};
|
|
1
|
+
import{dI as K,h1 as O,j as e,fi as N,S as _,B as j,bq as E,L as w,dU as A,r as b,dz as F,dB as H,dC as V,a as q,a2 as U,bb as W,h2 as Y,h3 as G,h4 as J,b7 as Q,bc as P,h5 as X,h6 as Z,gH as ee,bF as se,g2 as ne,h7 as L,ab as te,d8 as R,s as $,bw as ae,H as ie,bp as ce,g3 as oe,g4 as re,x as le,h8 as B,aV as de}from"./index-BUr8321-.js";import{c as me,C as xe,R as ue}from"./device-pin-tombstone-1ikyqSdb.js";import{R as he}from"./runs-panel-DsdESupx.js";import{S as pe,g as fe}from"./runs-table-B7jKuILd.js";import{c as ge}from"./connection-label-BobuYiAG.js";import{c as je}from"./device-rows-Cp3yMcuV.js";import"./runs-BnYdToDc.js";function ve({device:t,organizationId:s,ownerSlug:r,selectedConnection:p,openSettings:u}){const{data:d=[],isLoading:g,isError:h,refetch:l}=K(s),c=new Map(d.map(i=>[i.key,i])),a=new Map,m=[];for(const i of t.connectors){if(i.organization_slug!==r)continue;const o=c.get(i.connector_key);if(!o||!je(o)){m.push(i);continue}const v=o.required_capability??`connector:${o.key}`,f=a.get(v)??{key:v,name:o.name,connections:[]};f.name=O[v]??o.name,f.connections.push(i),a.set(v,f)}return e.jsxs(e.Fragment,{children:[e.jsxs(N,{title:"Capabilities",children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Manage the native connections available to this workspace."}),t.online?null:e.jsx("p",{className:"mb-3 text-sm text-muted-foreground",children:"This device is offline. You can edit its settings; actions and sync need it to reconnect."}),!s||g?e.jsx(_,{className:"h-24 w-full"}):h?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load capability settings."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void l(),children:"Retry"})]}):a.size===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No native connections on this device in this workspace."}):e.jsx("div",{className:"divide-y border-y",children:[...a.values()].map(i=>e.jsx(be,{group:i,deviceId:t.id,organizationId:s,ownerSlug:r,definitionsByKey:c,selectedConnection:p,openSettings:u},i.key))}),E(t)==="macos"?e.jsx("p",{className:"mt-3 text-xs text-muted-foreground",children:"Manage macOS permissions in the Lobu app on this device."}):null]}),s&&m.length>0&&!g&&!h?e.jsxs(N,{title:"Connections",count:String(m.length),children:[e.jsx("p",{className:"mb-3 text-xs text-muted-foreground",children:"Apps and sources that use this device."}),e.jsx("div",{className:"divide-y border-y",children:m.map(i=>e.jsxs(w,{to:"/$owner/connectors/$connectorKey/$connectionId",params:{owner:r,connectorKey:i.connector_key,connectionId:String(i.connection_id)},search:{},className:"flex items-center gap-3 py-3 text-sm hover:text-primary",children:[e.jsx("span",{className:"min-w-0 flex-1",children:i.display_name||c.get(i.connector_key)?.name||i.connector_key}),e.jsx("span",{className:"text-xs text-muted-foreground",children:i.status}),e.jsx(A,{className:"size-3.5 text-muted-foreground"})]},i.connection_id))})]}):null]})}function be({group:t,deviceId:s,organizationId:r,ownerSlug:p,definitionsByKey:u,selectedConnection:d,openSettings:g}){const h=t.connections.some(a=>a.connection_id===d),[l,c]=b.useState(h);return b.useEffect(()=>{h&&d!==void 0&&c(!0)},[h,d]),e.jsxs(F,{open:l,onOpenChange:c,children:[e.jsxs(H,{className:"group flex w-full items-center gap-3 py-3 text-left",children:[e.jsx(A,{className:"size-3.5 shrink-0 text-muted-foreground transition-transform group-data-[state=open]:rotate-90"}),e.jsx("span",{className:"min-w-0 flex-1 text-sm font-medium",children:t.name}),e.jsx("span",{className:"text-right text-xs text-muted-foreground",children:t.connections.some(a=>a.status==="error"||a.status==="revoked")?"Needs attention":t.connections.length>1?`${t.connections.length} connections`:"Configured"})]}),e.jsx(V,{forceMount:!0,hidden:!l,className:"pb-4 pl-6",children:e.jsx("div",{className:"space-y-5",children:t.connections.map(a=>e.jsx(Ne,{summary:a,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u.get(a.connector_key),openSettings:a.connection_id===d&&g},a.connection_id))})})]})}function Ne({summary:t,deviceId:s,organizationId:r,ownerSlug:p,connectorDef:u,openSettings:d}){const{data:g=[],isLoading:h,isError:l,refetch:c}=q(r,{connectionIds:[t.connection_id]}),a=g.find(o=>o.id===t.connection_id&&o.device_worker_id===s),m=u?.name??t.connector_key,i=a?me(a):null;return e.jsxs("section",{id:`connection-${t.connection_id}`,"aria-label":m,className:"scroll-mt-24",children:[a?e.jsxs("div",{className:"mb-3 flex items-baseline justify-between gap-3 text-xs text-muted-foreground",children:[e.jsx("span",{children:ge(a)}),e.jsx("span",{children:a.status})]}):null,h||!r?e.jsx(_,{className:"h-24 w-full"}):l?e.jsxs("div",{role:"alert",className:"space-y-2 text-sm",children:[e.jsx("p",{children:"Could not load this connection."}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>void c(),children:"Retry"})]}):a?e.jsxs(e.Fragment,{children:[i?e.jsx("p",{role:"alert",className:"mb-4 text-sm text-destructive",children:i}):null,e.jsx(xe,{connection:a,connectorDef:u,ownerSlug:p,openSettings:d,showActivity:!1,embedded:!0})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"This connection is no longer available on this device."})]})}function _e({ownerSlug:t,deviceId:s,organizationId:r,selectedConnection:p,openSettings:u}){const d=U(),{data:g=[],isLoading:h}=W(),l=Y(),c=G(),[a,m]=b.useState(!1),[i,o]=b.useState(!1),[v,f]=b.useState(""),n=J(g,s),y=n?.id??s,{data:k=[]}=Q(r,{profileKind:"browser_session"}),C=b.useMemo(()=>k.filter(x=>x.device_worker_id===y&&x.status!=="revoked"),[k,y]),D=n?.label?.trim()??"";if(b.useEffect(()=>{i||f(D)},[D,i]),h)return e.jsxs(P,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"h-6 w-6 rounded"}),e.jsx(_,{className:"h-5 w-40"})]}),e.jsx(ue,{})]});if(!n)return e.jsxs(P,{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"This device isn't in this workspace, so its details aren't available."}),e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:"text-sm text-primary hover:underline",children:"Back to connectors"})]});const I=E(n),z=X(n.app_version),T=Z(n,z),S=()=>{const x=v.trim(),M=n.label?.trim()??"";if(x===M){o(!1);return}c.mutate({deviceWorkerId:n.id,label:x.length===0?null:x},{onSuccess:()=>o(!1)})};return e.jsx("div",{className:"flex flex-1 flex-col",children:e.jsxs(ee,{header:e.jsx(ne,{breadcrumb:e.jsx(oe,{crumbs:[e.jsx(w,{to:"/$owner/connectors",params:{owner:t},search:{},className:re,children:"Connectors"},"connectors")]}),icon:e.jsx(ce,{platform:I,className:"h-5 w-5"}),title:i?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(te,{"aria-label":"Device name",value:v,onChange:x=>f(x.target.value),placeholder:R({...n,label:null}),maxLength:80,className:"h-9 max-w-sm text-base font-semibold",autoFocus:!0,onKeyDown:x=>{x.key==="Enter"?(x.preventDefault(),a||S()):x.key==="Escape"&&(m(!1),f(n.label?.trim()??""),o(!1))}}),a?e.jsxs("div",{className:"flex flex-wrap items-center gap-2 rounded-lg bg-destructive/10 px-3 py-2",children:[e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Forgets this device"," ",n.connector_count>0?`and un-pins ${n.connector_count} connector${n.connector_count===1?"":"s"} across every workspace, not just this one.`:"with no pinned connections."]}),e.jsxs(j,{variant:"destructive",size:"sm",disabled:l.isPending,onClick:()=>l.mutate(n.id,{onSuccess:()=>{m(!1),d({to:"/$owner/connectors",params:{owner:t},search:{}})}}),children:[l.isPending?e.jsx($,{className:"mr-1.5"}):null,l.isPending?"Removing...":"Confirm remove"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:l.isPending,onClick:()=>m(!1),children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(j,{size:"sm",onClick:S,disabled:c.isPending,children:[c.isPending?e.jsx($,{className:"mr-1.5"}):null,c.isPending?"Saving...":"Save"]}),e.jsx(j,{size:"sm",variant:"ghost",disabled:c.isPending,onClick:()=>{f(n.label?.trim()??""),o(!1)},children:"Cancel"}),e.jsxs(j,{size:"sm",variant:"ghost",className:"text-destructive hover:text-destructive",disabled:c.isPending||l.isPending,onClick:()=>m(!0),children:[e.jsx(ae,{className:"mr-1.5 h-3.5 w-3.5"}),"Remove device"]})]})]}):e.jsxs("span",{className:"flex items-center gap-1.5",children:[R(n),e.jsx(j,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground","aria-label":"Edit device",onClick:()=>{m(!1),f(n.label?.trim()??""),o(!0)},children:e.jsx(ie,{className:"h-3.5 w-3.5"})})]}),badge:e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:`size-1.5 rounded-full ${n.online?"bg-emerald-500":"bg-muted-foreground/50"}`}),n.online?n.connector_error_count>0?"Needs attention":"Online":"Offline"]}),meta:T||void 0,caption:`Last seen ${L(new Date(n.last_seen_at),{addSuffix:!0})}${n.last_sync_at?` · Last sync ${L(new Date(n.last_sync_at),{addSuffix:!0})}`:""}`}),children:[n.connector_error_count>0?e.jsxs("div",{className:"flex items-center gap-2 rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[e.jsx(se,{className:"h-3.5 w-3.5 shrink-0"}),n.connector_error_count," connector",n.connector_error_count===1?"":"s"," pinned to this device ",n.connector_error_count===1?"is":"are"," erroring."]}):null,e.jsx(ve,{device:n,organizationId:r,ownerSlug:t,selectedConnection:p,openSettings:u}),C.length>0?e.jsx(N,{title:"Browser auth profiles",children:e.jsx(ye,{profiles:C})}):null,e.jsx(N,{title:"Runs",children:e.jsx(he,{scope:{deviceId:y},ownerSlug:t})})]})})}function ye({profiles:t}){return t.length===0?null:e.jsx("div",{className:"rounded-lg border",children:e.jsx("ul",{className:"divide-y",children:t.map(s=>e.jsxs("li",{className:"space-y-2 px-3 py-2.5 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:s.display_name}),e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx("span",{children:s.connector_key??"Any connector"}),s.browser_kind?e.jsxs("span",{children:["· ",s.browser_kind]}):null,s.captured_at?e.jsxs("span",{title:s.captured_at,children:["· captured ",le(s.captured_at)]}):null,typeof s.cookie_count=="number"?e.jsxs("span",{children:["· ",s.cookie_count," cookie",s.cookie_count===1?"":"s"]}):null]})]}),e.jsx(pe,{status:s.is_expired?"error":fe(s.status),showDot:!0,children:s.is_expired?"expired":s.status})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Refresh the session using the connector’s authorization instructions."})]},s.id))})})}function Re(){const{owner:t,deviceId:s}=B.useParams(),{connection:r,settings:p}=B.useSearch();return e.jsx(de,{owner:t,children:({ownerSlug:u,organizationId:d})=>e.jsx(_e,{ownerSlug:u,deviceId:s,organizationId:d,selectedConnection:r,openSettings:p})})}export{Re as component};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a2 as x,bM as _,j as e,bY as C,bZ as m,b_ as S,b$ as b,c0 as o,c1 as u}from"./index-
|
|
1
|
+
import{a2 as x,bM as _,j as e,bY as C,bZ as m,b_ as S,b$ as b,c0 as o,c1 as u}from"./index-BUr8321-.js";import{c as w}from"./connection-label-BobuYiAG.js";const h="__connection_picker_create_new__";function y({connections:s,value:r,onValueChange:n,connectorKey:a,disabled:d,placeholder:g="Choose a connection",includeWorkspaceEvents:i=!1,ariaLabel:p="Connection"}){const f=x(),l=_().org?.slug,c=a?s.filter(t=>t.connector_key===a):s,j=t=>{if(t===h){if(!l)return;f({to:"/$owner/connectors/create",params:{owner:l},search:a?{connector:a}:{}});return}n(t)};return e.jsxs(C,{value:r,onValueChange:j,disabled:d,children:[e.jsx(m,{"aria-label":p,children:e.jsx(S,{placeholder:g})}),e.jsxs(b,{children:[i?e.jsxs(e.Fragment,{children:[e.jsx(o,{value:"workspace",children:"Current workspace"}),c.length>0?e.jsx(u,{}):null]}):null,c.map(t=>e.jsx(o,{value:String(t.id),children:w(t)},t.id)),l?e.jsxs(e.Fragment,{children:[c.length>0||i?e.jsx(u,{}):null,e.jsx(o,{value:h,children:"Connect an app…"})]}):null]})]})}function v(s){const r=[];for(const n of s)r.push({id:n.id,name:n.name,entityType:n.entity_type}),n.children&&n.children.length>0&&r.push(...v(n.children));return r}export{y as C,v as f};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a1 as Y,hF as ye,r as g,j as e,S as P,a2 as Q,hG as _e,af as Z,aj as _,cF as Ne,hH as we,cx as M,dv as Ce,dr as Se,aE as C,hI as Te,hJ as Ee,hK as ke,ds as R,hL as Ie,aH as De,hM as ee,cy as Fe,cC as Pe,cA as Re,cD as K,cv as Ae,cw as Le,g as Me,cn as te,cG as $e,hN as Oe,k as ze,co as w,cr as Ve,F as Be,aa as A,ab as q,ea as Ge,bF as Je,B as v,eT as Ue,L as He,fa as Ke,hO as qe,J as We,hP as Xe,eh as Ye,cX as Qe,aS as Ze}from"./index-Bfux0kHb.js";import{a as W,c as X,S as et,D as tt,E as st}from"./schema-value-normalization--DhnhJNf.js";import{J as L}from"./renderer-B1UThnk2.js";import"./calendar-taCoBmAh.js";import"./card-kpw3EaKC.js";function at({entityId:t,ownerSlug:s}){const{orgContext:n}=Y(),{data:i,isLoading:a}=ye(t,n),o=g.useMemo(()=>{if(!i)return[];const r=new Map;for(const l of i.rows){const u=r.get(l.relationship_type_slug);u?u.rows.push(l):r.set(l.relationship_type_slug,{slug:l.relationship_type_slug,label:l.relationship_type_name,rows:[l]})}return[...r.values()]},[i]);return a?e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{className:"h-4 w-32"}),e.jsx(P,{className:"h-12 w-full rounded-lg"}),e.jsx(P,{className:"h-12 w-full rounded-lg"})]}):!i||i.rows.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No relationships for this entity yet."}):e.jsx("div",{className:"space-y-3",children:o.map(({slug:r,label:l,rows:u})=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("p",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[l,e.jsx("span",{className:"text-[10px] tabular-nums text-muted-foreground/70",children:u.length})]}),e.jsx("ul",{className:"space-y-1",children:u.map(c=>e.jsx(nt,{entityId:t,row:c,ownerSlug:s},c.id))})]},r))})}function nt({entityId:t,row:s,ownerSlug:n}){const i=Q(),{orgContext:a}=Y(),[o,r]=g.useState(!1),[l,u]=g.useState(!1),c=s.from_entity_id===s.to_entity_id,d=s.from_entity_id===t,x=c?"this entity":d?s.to_entity_name??`Entity #${s.to_entity_id}`:s.from_entity_name??`Entity #${s.from_entity_id}`,p=d?s.to_entity_type:s.from_entity_type,T=d?s.to_entity_id:s.from_entity_id,m=p?`${p} · ${x}`:x;async function f(){r(!0),u(!1);try{const N=[],j=new Set;let b=T;for(;b!==null;){if(j.has(b))throw new Error("Cyclic entity ancestry");j.add(b);const{entity:y}=await Ne("manage_entity",{action:"get",entity_id:b},we(a));N.unshift({entity_type:y.entity_type,slug:y.slug}),b=y.parent_id}await i({to:M(n,N)})}catch{u(!0)}finally{r(!1)}}return e.jsxs("li",{className:_("flex items-center gap-2 rounded-md border border-border/70 px-2.5 py-1.5"),children:[e.jsx(_e,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c||!p?e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:m}):e.jsxs("button",{type:"button",onClick:f,disabled:o,"aria-busy":o,className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-sm hover:underline",children:m}),p?e.jsx(Z,{variant:"outline",className:"shrink-0 text-[9px] px-1.5 py-0 h-4 text-muted-foreground",children:p}):null]}),l?e.jsx("span",{role:"alert",className:"text-xs text-destructive",children:"Could not open this record. Try again."}):null]})}var S="Tabs",[it]=De(S,[ee]),se=ee(),[rt,z]=it(S),ae=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,onValueChange:a,defaultValue:o,orientation:r="horizontal",dir:l,activationMode:u="automatic",...c}=t,d=Ce(l),[x,p]=Se({prop:i,onChange:a,defaultProp:o??"",caller:S});return e.jsx(rt,{scope:n,baseId:Te(),value:x,onValueChange:p,orientation:r,dir:d,activationMode:u,children:e.jsx(C.div,{dir:d,"data-orientation":r,...c,ref:s})})});ae.displayName=S;var ne="TabsList",ie=g.forwardRef((t,s)=>{const{__scopeTabs:n,loop:i=!0,...a}=t,o=z(ne,n),r=se(n);return e.jsx(Ee,{asChild:!0,...r,orientation:o.orientation,dir:o.dir,loop:i,children:e.jsx(C.div,{role:"tablist","aria-orientation":o.orientation,...a,ref:s})})});ie.displayName=ne;var re="TabsTrigger",oe=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,disabled:a=!1,...o}=t,r=z(re,n),l=se(n),u=de(r.baseId,i),c=me(r.baseId,i),d=i===r.value;return e.jsx(ke,{asChild:!0,...l,focusable:!a,active:d,children:e.jsx(C.button,{type:"button",role:"tab","aria-selected":d,"aria-controls":c,"data-state":d?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...o,ref:s,onMouseDown:R(t.onMouseDown,x=>{!a&&x.button===0&&x.ctrlKey===!1?r.onValueChange(i):x.preventDefault()}),onKeyDown:R(t.onKeyDown,x=>{[" ","Enter"].includes(x.key)&&r.onValueChange(i)}),onFocus:R(t.onFocus,()=>{const x=r.activationMode!=="manual";!d&&!a&&x&&r.onValueChange(i)})})})});oe.displayName=re;var le="TabsContent",ce=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,forceMount:a,children:o,...r}=t,l=z(le,n),u=de(l.baseId,i),c=me(l.baseId,i),d=i===l.value,x=g.useRef(d);return g.useEffect(()=>{const p=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(p)},[]),e.jsx(Ie,{present:a||d,children:({present:p})=>e.jsx(C.div,{"data-state":d?"active":"inactive","data-orientation":l.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:c,tabIndex:0,...r,ref:s,style:{...t.style,animationDuration:x.current?"0s":void 0},children:p&&o})})});ce.displayName=le;function de(t,s){return`${t}-trigger-${s}`}function me(t,s){return`${t}-content-${s}`}var ot=ae,ue=ie,xe=oe,ge=ce;const lt=ot,pe=g.forwardRef(({className:t,...s},n)=>e.jsx(ue,{ref:n,className:_("inline-flex h-9 items-center justify-start gap-1 border-b border-border bg-transparent p-0",t),...s}));pe.displayName=ue.displayName;const $=g.forwardRef(({className:t,...s},n)=>e.jsx(xe,{ref:n,className:_("inline-flex items-center justify-center whitespace-nowrap px-3 pb-2 pt-1 text-sm font-medium text-muted-foreground transition-all","border-b-2 border-transparent","hover:text-foreground","data-[state=active]:border-foreground data-[state=active]:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","disabled:pointer-events-none disabled:opacity-50",t),...s}));$.displayName=xe.displayName;const O=g.forwardRef(({className:t,...s},n)=>e.jsx(ge,{ref:n,className:_("mt-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t),...s}));O.displayName=ge.displayName;function ct(t,s){const n=new Set([...Object.keys(t),...Object.keys(s)]);let i=!1;const a={};for(const o of n){const r=o in t,l=o in s;if(!r&&l){a[o]=s[o];continue}r&&(a[o]=t[o],(!l||JSON.stringify(t[o])!==JSON.stringify(s[o]))&&(i=!0))}return i?a:void 0}function dt({entity:t,entityTypeSlug:s,orgContext:n,onDeleted:i}){const{isAdmin:a,isLoading:o}=Me(n.organizationId),r=a&&!o,{data:l,isLoading:u}=te(s,n),c=$e(),d=Oe(),x=l?.metadata_schema,p=t.field_controls,T=g.useMemo(()=>W(t.metadata??{},x),[t.metadata,x]),m=ze(t.id,{name:t.name,slug:t.slug,metadata:T},x),[f,N]=m.field("name"),[j,b]=m.field("slug"),[y,he]=m.field("metadata"),[V,B]=w(t.id,""),[G,E]=w(t.id,null),[fe,k]=w(t.id,!1),[J,I]=w(t.id,null),D=g.useMemo(()=>m.hasInvalidInput?void 0:ct(X(y),X(m.baseline.metadata)),[m.baseline.metadata,y,m.hasInvalidInput]),F=D!==void 0,ve=f!==m.baseline.name||j!==m.baseline.slug||F,je=async h=>{if(h.preventDefault(),!(!r||!m.canSubmit)){if(E(null),!f.trim()){E("Name is required");return}try{await c.mutateAsync({entityId:t.id,name:f.trim()!==m.baseline.name.trim()?f.trim():void 0,slug:j,metadata:D,field_note:F&&V.trim()||void 0}),m.accept(m.values,{name:f.trim(),slug:j,metadata:W({...Ue(m.baseline.metadata),...D},x)}),B("")}catch(H){E(H instanceof Error?H.message:"Failed to update entity")}}},be=async()=>{if(r){I(null);try{await d.mutateAsync({entityId:t.id}),k(!1),i?.()}catch(h){I(h instanceof Error?h.message:"Failed to delete entity")}}},U=[t.total_content>0&&`${t.total_content} content item${t.total_content===1?"":"s"}`,t.automations_count>0&&`${t.automations_count} Automation${t.automations_count===1?"":"s"}`,t.active_connections>0&&`${t.active_connections} connector${t.active_connections===1?"":"s"}`].filter(Boolean).join(", ");return u?e.jsx(Ve,{rows:6}):e.jsxs("form",{onSubmit:je,className:"space-y-4",children:[e.jsx(Be,{visible:m.hasConflict,onReload:m.reset}),!r&&e.jsx("p",{className:"text-sm text-muted-foreground",role:"status",children:o?"Checking edit permissions…":"You can view this record. Ask a workspace owner or admin to make changes."}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(A,{htmlFor:"sidebar-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(q,{id:"sidebar-name",readOnly:!r,value:f,onChange:h=>N(h.target.value)})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(A,{htmlFor:"sidebar-slug",children:"URL Slug"}),e.jsx(q,{id:"sidebar-slug",readOnly:!r,value:j,onChange:h=>b(h.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]}),m.revision&&Object.keys(m.revision).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(et,{}),e.jsx(tt,{schema:m.revision,values:y,onValuesChange:he,readonly:!r,fieldControls:p,orgContext:n})]}),r&&F&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(A,{htmlFor:"sidebar-correction-note",children:"Correction note (optional)"}),e.jsx(Ge,{id:"sidebar-correction-note",value:V,onChange:h=>B(h.target.value),placeholder:"Why are you changing these fields? Helps Automations respect the correction.",rows:2})]}),G&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:G}),r&&(fe?e.jsxs("div",{className:"space-y-3 rounded-lg border border-destructive/40 bg-destructive/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 text-sm",children:[e.jsx(Je,{className:"h-4 w-4 shrink-0 text-destructive mt-0.5"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:['Delete "',t.name,'"?']}),U&&e.jsxs("p",{className:"text-muted-foreground",children:["Removes ",U,". This cannot be easily undone."]})]})]}),J&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-2.5 py-1.5 text-sm text-destructive",children:J}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>{k(!1),I(null)},children:"Cancel"}),e.jsx(v,{type:"button",variant:"destructive",size:"sm",onClick:be,disabled:d.isPending,children:d.isPending?"Deleting...":`Delete ${l?.name||"entity"}`})]})]}):e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx(v,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>k(!0),children:"Delete"}),e.jsx(v,{type:"submit",size:"sm",disabled:!m.canSubmit||!ve||c.isPending||!f.trim(),children:c.isPending?"Saving...":"Save"})]}))]})}function mt({entity:t}){const s=new Set(t.measure_columns??[]),n=t.metadata??{},i=Object.keys(n).filter(a=>a!=="id"&&a!=="slug"&&a!=="name");return e.jsx("div",{className:"mt-4 max-w-2xl",children:e.jsx("div",{className:"rounded-lg border",children:e.jsx(Fe,{children:e.jsx(Pe,{children:i.map(a=>{const o=s.has(a);return e.jsxs(Re,{children:[e.jsx(K,{className:"w-44 align-top font-medium text-muted-foreground",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[o?a:Ae(a.replace(/_/g," ")),o&&e.jsx(Z,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]})}),e.jsx(K,{className:_("break-words align-top",o?"text-right tabular-nums":""),children:Le(n[a])})]},a)})})})})})}function ut({namespace:t,entity:s,onDeleted:n}){if(s.is_derived)return e.jsx(mt,{entity:s});const i={...s.metadata,...s.template_data??{},name:s.name,entity_type:s.entity_type,total_content:s.total_content,active_connections:s.active_connections,automations_count:s.automations_count},a=s.tabs??[],o=a.length>0,r=!o&&s.json_template_version==null,l=e.jsx(dt,{entity:s,entityTypeSlug:s.entity_type,orgContext:{slug:t.slug,organizationId:t.id},onDeleted:n}),u=s.is_derived?null:e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Relationships"}),e.jsx(at,{entityId:s.id,ownerSlug:t.slug})]});return r?e.jsxs("div",{className:"mt-4 max-w-xl",children:[u,e.jsx("div",{className:"mt-4",children:l})]}):e.jsxs("div",{className:"mt-4 grid gap-6 xl:grid-cols-[minmax(0,1.5fr)_460px]",children:[e.jsx("div",{className:"space-y-6",children:o?e.jsxs(lt,{defaultValue:s.json_template?"__default__":a[0]?.tab_name,children:[e.jsxs(pe,{children:[s.json_template&&e.jsx($,{value:"__default__",children:"Overview"}),a.map(c=>e.jsx($,{value:c.tab_name,children:c.tab_name},c.tab_name))]}),s.json_template&&e.jsx(O,{value:"__default__",children:e.jsx(L,{template:{root:s.json_template},data:i})}),a.map(c=>e.jsx(O,{value:c.tab_name,children:e.jsx(L,{template:{root:c.json_template},data:{...i,...c.template_data??{}}})},c.tab_name))]}):e.jsx(L,{template:{root:s.json_template},data:i})}),e.jsxs("div",{className:"space-y-4",children:[u,l]})]})}function xt(t){return typeof t=="string"?t:t===null?"None":JSON.stringify(t)??String(t)}function gt({records:t}){const s=Ye(),[n,i]=g.useState(null);return t.length===0?null:e.jsxs("details",{className:_(Ze,"px-4 py-3"),children:[e.jsxs("summary",{className:"cursor-pointer text-sm font-medium",children:["Merged records (",t.length,")"]}),e.jsx("div",{className:"mt-3 space-y-3",children:t.map(a=>e.jsxs("div",{className:"rounded-lg bg-background p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:a.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Merged ",new Date(a.merged_at).toLocaleString()]})]}),a.can_unmerge?n===a.id?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{type:"button",variant:"destructive",size:"sm",disabled:s.isPending,onClick:()=>s.mutate({entityId:a.id},{onSettled:()=>i(null)}),children:"Confirm undo"}),e.jsx(v,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>i(null),children:"Cancel"})]}):e.jsxs(v,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>i(a.id),children:[e.jsx(Qe,{className:"mr-1.5 size-3.5"}),"Undo merge"]}):null]}),Object.keys(a.metadata).length>0?e.jsx("dl",{className:"mt-3 grid gap-x-4 gap-y-1 text-xs sm:grid-cols-2",children:Object.entries(a.metadata).map(([o,r])=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground",children:o}),e.jsx("dd",{className:"break-words",children:xt(r)})]},o))}):null]},a.id))})]})}function pt(t){return t?.trim()?t:void 0}function ht({ownerSlug:t,entityName:s,activityHref:n}){const i=We();return e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>i?.open({href:n,title:`${s} · Activity`,owner:t}),disabled:!i,children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),"See activity"]})}function _t({namespace:t,path:s,entity:n,mergedFrom:i}){const a=Q(),{data:o}=te(n.entity_type,{slug:t.slug}),r=pt(o?.icon),l=s.map(d=>({entity_type:d.entity_type,slug:d.slug})),u=`/${t.slug}/${n.entity_type}`,c=s.length>1?M(t.slug,l.slice(0,-1)):u;return e.jsxs("div",{className:"mx-auto flex min-h-0 w-full max-w-3xl flex-1 flex-col gap-6 px-4 py-6 lg:px-6",children:[i?e.jsxs("div",{className:"rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-sm",children:[e.jsx("strong",{children:i})," was merged into this canonical record."]}):null,e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[e.jsx(v,{asChild:!0,variant:"ghost",size:"sm",className:"-ml-2 h-7 w-fit px-2 text-muted-foreground hover:text-foreground",children:e.jsxs(He,{to:c,children:[e.jsx(Ke,{className:"mr-1 h-4 w-4"}),"Back"]})}),!n.is_derived&&e.jsx("div",{className:"ml-auto",children:e.jsx(ht,{ownerSlug:t.slug,entityName:n.name,activityHref:`/${t.slug}/events/${qe(l)}`})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(st,{metadata:n.metadata,metadataSchema:o?.metadata_schema,name:n.name,typeIcon:r,className:"h-6 w-6"}),e.jsx("h2",{className:"text-lg font-semibold leading-tight",children:n.name})]})]}),e.jsx(gt,{records:n.merged_records??[]}),e.jsx(ut,{namespace:t,entity:n,onDeleted:()=>{const d=s.slice(0,-1);d.length>0?a({to:M(t.slug,d)}):a({to:u})}})]})}export{_t as EntityPage};
|
|
1
|
+
import{a1 as Y,hF as ye,r as g,j as e,S as P,a2 as Q,hG as _e,af as Z,aj as _,cF as Ne,hH as we,cx as M,dv as Ce,dr as Se,aE as C,hI as Te,hJ as Ee,hK as ke,ds as R,hL as Ie,aH as De,hM as ee,cy as Fe,cC as Pe,cA as Re,cD as K,cv as Ae,cw as Le,g as Me,cn as te,cG as $e,hN as Oe,k as ze,co as w,cr as Ve,F as Be,aa as A,ab as q,ea as Ge,bF as Je,B as v,eT as Ue,L as He,fa as Ke,hO as qe,J as We,hP as Xe,eh as Ye,cX as Qe,aS as Ze}from"./index-BUr8321-.js";import{a as W,c as X,S as et,D as tt,E as st}from"./schema-value-normalization-B--OWDL8.js";import{J as L}from"./renderer-CHNejd95.js";import"./calendar-C0XpOHd8.js";import"./card-DeFQuU_J.js";function at({entityId:t,ownerSlug:s}){const{orgContext:n}=Y(),{data:i,isLoading:a}=ye(t,n),o=g.useMemo(()=>{if(!i)return[];const r=new Map;for(const l of i.rows){const u=r.get(l.relationship_type_slug);u?u.rows.push(l):r.set(l.relationship_type_slug,{slug:l.relationship_type_slug,label:l.relationship_type_name,rows:[l]})}return[...r.values()]},[i]);return a?e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{className:"h-4 w-32"}),e.jsx(P,{className:"h-12 w-full rounded-lg"}),e.jsx(P,{className:"h-12 w-full rounded-lg"})]}):!i||i.rows.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No relationships for this entity yet."}):e.jsx("div",{className:"space-y-3",children:o.map(({slug:r,label:l,rows:u})=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("p",{className:"flex items-center gap-2 text-xs font-medium text-muted-foreground",children:[l,e.jsx("span",{className:"text-[10px] tabular-nums text-muted-foreground/70",children:u.length})]}),e.jsx("ul",{className:"space-y-1",children:u.map(c=>e.jsx(nt,{entityId:t,row:c,ownerSlug:s},c.id))})]},r))})}function nt({entityId:t,row:s,ownerSlug:n}){const i=Q(),{orgContext:a}=Y(),[o,r]=g.useState(!1),[l,u]=g.useState(!1),c=s.from_entity_id===s.to_entity_id,d=s.from_entity_id===t,x=c?"this entity":d?s.to_entity_name??`Entity #${s.to_entity_id}`:s.from_entity_name??`Entity #${s.from_entity_id}`,p=d?s.to_entity_type:s.from_entity_type,T=d?s.to_entity_id:s.from_entity_id,m=p?`${p} · ${x}`:x;async function f(){r(!0),u(!1);try{const N=[],j=new Set;let b=T;for(;b!==null;){if(j.has(b))throw new Error("Cyclic entity ancestry");j.add(b);const{entity:y}=await Ne("manage_entity",{action:"get",entity_id:b},we(a));N.unshift({entity_type:y.entity_type,slug:y.slug}),b=y.parent_id}await i({to:M(n,N)})}catch{u(!0)}finally{r(!1)}}return e.jsxs("li",{className:_("flex items-center gap-2 rounded-md border border-border/70 px-2.5 py-1.5"),children:[e.jsx(_e,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),c||!p?e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm",children:m}):e.jsxs("button",{type:"button",onClick:f,disabled:o,"aria-busy":o,className:"flex min-w-0 flex-1 items-center gap-2",children:[e.jsx("span",{className:"min-w-0 truncate text-sm hover:underline",children:m}),p?e.jsx(Z,{variant:"outline",className:"shrink-0 text-[9px] px-1.5 py-0 h-4 text-muted-foreground",children:p}):null]}),l?e.jsx("span",{role:"alert",className:"text-xs text-destructive",children:"Could not open this record. Try again."}):null]})}var S="Tabs",[it]=De(S,[ee]),se=ee(),[rt,z]=it(S),ae=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,onValueChange:a,defaultValue:o,orientation:r="horizontal",dir:l,activationMode:u="automatic",...c}=t,d=Ce(l),[x,p]=Se({prop:i,onChange:a,defaultProp:o??"",caller:S});return e.jsx(rt,{scope:n,baseId:Te(),value:x,onValueChange:p,orientation:r,dir:d,activationMode:u,children:e.jsx(C.div,{dir:d,"data-orientation":r,...c,ref:s})})});ae.displayName=S;var ne="TabsList",ie=g.forwardRef((t,s)=>{const{__scopeTabs:n,loop:i=!0,...a}=t,o=z(ne,n),r=se(n);return e.jsx(Ee,{asChild:!0,...r,orientation:o.orientation,dir:o.dir,loop:i,children:e.jsx(C.div,{role:"tablist","aria-orientation":o.orientation,...a,ref:s})})});ie.displayName=ne;var re="TabsTrigger",oe=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,disabled:a=!1,...o}=t,r=z(re,n),l=se(n),u=de(r.baseId,i),c=me(r.baseId,i),d=i===r.value;return e.jsx(ke,{asChild:!0,...l,focusable:!a,active:d,children:e.jsx(C.button,{type:"button",role:"tab","aria-selected":d,"aria-controls":c,"data-state":d?"active":"inactive","data-disabled":a?"":void 0,disabled:a,id:u,...o,ref:s,onMouseDown:R(t.onMouseDown,x=>{!a&&x.button===0&&x.ctrlKey===!1?r.onValueChange(i):x.preventDefault()}),onKeyDown:R(t.onKeyDown,x=>{[" ","Enter"].includes(x.key)&&r.onValueChange(i)}),onFocus:R(t.onFocus,()=>{const x=r.activationMode!=="manual";!d&&!a&&x&&r.onValueChange(i)})})})});oe.displayName=re;var le="TabsContent",ce=g.forwardRef((t,s)=>{const{__scopeTabs:n,value:i,forceMount:a,children:o,...r}=t,l=z(le,n),u=de(l.baseId,i),c=me(l.baseId,i),d=i===l.value,x=g.useRef(d);return g.useEffect(()=>{const p=requestAnimationFrame(()=>x.current=!1);return()=>cancelAnimationFrame(p)},[]),e.jsx(Ie,{present:a||d,children:({present:p})=>e.jsx(C.div,{"data-state":d?"active":"inactive","data-orientation":l.orientation,role:"tabpanel","aria-labelledby":u,hidden:!p,id:c,tabIndex:0,...r,ref:s,style:{...t.style,animationDuration:x.current?"0s":void 0},children:p&&o})})});ce.displayName=le;function de(t,s){return`${t}-trigger-${s}`}function me(t,s){return`${t}-content-${s}`}var ot=ae,ue=ie,xe=oe,ge=ce;const lt=ot,pe=g.forwardRef(({className:t,...s},n)=>e.jsx(ue,{ref:n,className:_("inline-flex h-9 items-center justify-start gap-1 border-b border-border bg-transparent p-0",t),...s}));pe.displayName=ue.displayName;const $=g.forwardRef(({className:t,...s},n)=>e.jsx(xe,{ref:n,className:_("inline-flex items-center justify-center whitespace-nowrap px-3 pb-2 pt-1 text-sm font-medium text-muted-foreground transition-all","border-b-2 border-transparent","hover:text-foreground","data-[state=active]:border-foreground data-[state=active]:text-foreground","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","disabled:pointer-events-none disabled:opacity-50",t),...s}));$.displayName=xe.displayName;const O=g.forwardRef(({className:t,...s},n)=>e.jsx(ge,{ref:n,className:_("mt-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",t),...s}));O.displayName=ge.displayName;function ct(t,s){const n=new Set([...Object.keys(t),...Object.keys(s)]);let i=!1;const a={};for(const o of n){const r=o in t,l=o in s;if(!r&&l){a[o]=s[o];continue}r&&(a[o]=t[o],(!l||JSON.stringify(t[o])!==JSON.stringify(s[o]))&&(i=!0))}return i?a:void 0}function dt({entity:t,entityTypeSlug:s,orgContext:n,onDeleted:i}){const{isAdmin:a,isLoading:o}=Me(n.organizationId),r=a&&!o,{data:l,isLoading:u}=te(s,n),c=$e(),d=Oe(),x=l?.metadata_schema,p=t.field_controls,T=g.useMemo(()=>W(t.metadata??{},x),[t.metadata,x]),m=ze(t.id,{name:t.name,slug:t.slug,metadata:T},x),[f,N]=m.field("name"),[j,b]=m.field("slug"),[y,he]=m.field("metadata"),[V,B]=w(t.id,""),[G,E]=w(t.id,null),[fe,k]=w(t.id,!1),[J,I]=w(t.id,null),D=g.useMemo(()=>m.hasInvalidInput?void 0:ct(X(y),X(m.baseline.metadata)),[m.baseline.metadata,y,m.hasInvalidInput]),F=D!==void 0,ve=f!==m.baseline.name||j!==m.baseline.slug||F,je=async h=>{if(h.preventDefault(),!(!r||!m.canSubmit)){if(E(null),!f.trim()){E("Name is required");return}try{await c.mutateAsync({entityId:t.id,name:f.trim()!==m.baseline.name.trim()?f.trim():void 0,slug:j,metadata:D,field_note:F&&V.trim()||void 0}),m.accept(m.values,{name:f.trim(),slug:j,metadata:W({...Ue(m.baseline.metadata),...D},x)}),B("")}catch(H){E(H instanceof Error?H.message:"Failed to update entity")}}},be=async()=>{if(r){I(null);try{await d.mutateAsync({entityId:t.id}),k(!1),i?.()}catch(h){I(h instanceof Error?h.message:"Failed to delete entity")}}},U=[t.total_content>0&&`${t.total_content} content item${t.total_content===1?"":"s"}`,t.automations_count>0&&`${t.automations_count} Automation${t.automations_count===1?"":"s"}`,t.active_connections>0&&`${t.active_connections} connector${t.active_connections===1?"":"s"}`].filter(Boolean).join(", ");return u?e.jsx(Ve,{rows:6}):e.jsxs("form",{onSubmit:je,className:"space-y-4",children:[e.jsx(Be,{visible:m.hasConflict,onReload:m.reset}),!r&&e.jsx("p",{className:"text-sm text-muted-foreground",role:"status",children:o?"Checking edit permissions…":"You can view this record. Ask a workspace owner or admin to make changes."}),e.jsxs("div",{className:"grid gap-2",children:[e.jsxs(A,{htmlFor:"sidebar-name",children:["Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(q,{id:"sidebar-name",readOnly:!r,value:f,onChange:h=>N(h.target.value)})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(A,{htmlFor:"sidebar-slug",children:"URL Slug"}),e.jsx(q,{id:"sidebar-slug",readOnly:!r,value:j,onChange:h=>b(h.target.value.toLowerCase().replace(/[^a-z0-9-]/g,""))})]}),m.revision&&Object.keys(m.revision).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(et,{}),e.jsx(tt,{schema:m.revision,values:y,onValuesChange:he,readonly:!r,fieldControls:p,orgContext:n})]}),r&&F&&e.jsxs("div",{className:"grid gap-2",children:[e.jsx(A,{htmlFor:"sidebar-correction-note",children:"Correction note (optional)"}),e.jsx(Ge,{id:"sidebar-correction-note",value:V,onChange:h=>B(h.target.value),placeholder:"Why are you changing these fields? Helps Automations respect the correction.",rows:2})]}),G&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-3 py-2 text-sm text-destructive",children:G}),r&&(fe?e.jsxs("div",{className:"space-y-3 rounded-lg border border-destructive/40 bg-destructive/5 p-3",children:[e.jsxs("div",{className:"flex items-start gap-2.5 text-sm",children:[e.jsx(Je,{className:"h-4 w-4 shrink-0 text-destructive mt-0.5"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"font-medium text-foreground",children:['Delete "',t.name,'"?']}),U&&e.jsxs("p",{className:"text-muted-foreground",children:["Removes ",U,". This cannot be easily undone."]})]})]}),J&&e.jsx("div",{className:"rounded-md bg-destructive/10 px-2.5 py-1.5 text-sm text-destructive",children:J}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(v,{type:"button",variant:"ghost",size:"sm",onClick:()=>{k(!1),I(null)},children:"Cancel"}),e.jsx(v,{type:"button",variant:"destructive",size:"sm",onClick:be,disabled:d.isPending,children:d.isPending?"Deleting...":`Delete ${l?.name||"entity"}`})]})]}):e.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx(v,{type:"button",variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>k(!0),children:"Delete"}),e.jsx(v,{type:"submit",size:"sm",disabled:!m.canSubmit||!ve||c.isPending||!f.trim(),children:c.isPending?"Saving...":"Save"})]}))]})}function mt({entity:t}){const s=new Set(t.measure_columns??[]),n=t.metadata??{},i=Object.keys(n).filter(a=>a!=="id"&&a!=="slug"&&a!=="name");return e.jsx("div",{className:"mt-4 max-w-2xl",children:e.jsx("div",{className:"rounded-lg border",children:e.jsx(Fe,{children:e.jsx(Pe,{children:i.map(a=>{const o=s.has(a);return e.jsxs(Re,{children:[e.jsx(K,{className:"w-44 align-top font-medium text-muted-foreground",children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[o?a:Ae(a.replace(/_/g," ")),o&&e.jsx(Z,{variant:"secondary",className:"font-normal lowercase",children:"measure"})]})}),e.jsx(K,{className:_("break-words align-top",o?"text-right tabular-nums":""),children:Le(n[a])})]},a)})})})})})}function ut({namespace:t,entity:s,onDeleted:n}){if(s.is_derived)return e.jsx(mt,{entity:s});const i={...s.metadata,...s.template_data??{},name:s.name,entity_type:s.entity_type,total_content:s.total_content,active_connections:s.active_connections,automations_count:s.automations_count},a=s.tabs??[],o=a.length>0,r=!o&&s.json_template_version==null,l=e.jsx(dt,{entity:s,entityTypeSlug:s.entity_type,orgContext:{slug:t.slug,organizationId:t.id},onDeleted:n}),u=s.is_derived?null:e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:"Relationships"}),e.jsx(at,{entityId:s.id,ownerSlug:t.slug})]});return r?e.jsxs("div",{className:"mt-4 max-w-xl",children:[u,e.jsx("div",{className:"mt-4",children:l})]}):e.jsxs("div",{className:"mt-4 grid gap-6 xl:grid-cols-[minmax(0,1.5fr)_460px]",children:[e.jsx("div",{className:"space-y-6",children:o?e.jsxs(lt,{defaultValue:s.json_template?"__default__":a[0]?.tab_name,children:[e.jsxs(pe,{children:[s.json_template&&e.jsx($,{value:"__default__",children:"Overview"}),a.map(c=>e.jsx($,{value:c.tab_name,children:c.tab_name},c.tab_name))]}),s.json_template&&e.jsx(O,{value:"__default__",children:e.jsx(L,{template:{root:s.json_template},data:i})}),a.map(c=>e.jsx(O,{value:c.tab_name,children:e.jsx(L,{template:{root:c.json_template},data:{...i,...c.template_data??{}}})},c.tab_name))]}):e.jsx(L,{template:{root:s.json_template},data:i})}),e.jsxs("div",{className:"space-y-4",children:[u,l]})]})}function xt(t){return typeof t=="string"?t:t===null?"None":JSON.stringify(t)??String(t)}function gt({records:t}){const s=Ye(),[n,i]=g.useState(null);return t.length===0?null:e.jsxs("details",{className:_(Ze,"px-4 py-3"),children:[e.jsxs("summary",{className:"cursor-pointer text-sm font-medium",children:["Merged records (",t.length,")"]}),e.jsx("div",{className:"mt-3 space-y-3",children:t.map(a=>e.jsxs("div",{className:"rounded-lg bg-background p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:a.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Merged ",new Date(a.merged_at).toLocaleString()]})]}),a.can_unmerge?n===a.id?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(v,{type:"button",variant:"destructive",size:"sm",disabled:s.isPending,onClick:()=>s.mutate({entityId:a.id},{onSettled:()=>i(null)}),children:"Confirm undo"}),e.jsx(v,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>i(null),children:"Cancel"})]}):e.jsxs(v,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>i(a.id),children:[e.jsx(Qe,{className:"mr-1.5 size-3.5"}),"Undo merge"]}):null]}),Object.keys(a.metadata).length>0?e.jsx("dl",{className:"mt-3 grid gap-x-4 gap-y-1 text-xs sm:grid-cols-2",children:Object.entries(a.metadata).map(([o,r])=>e.jsxs("div",{className:"min-w-0",children:[e.jsx("dt",{className:"text-muted-foreground",children:o}),e.jsx("dd",{className:"break-words",children:xt(r)})]},o))}):null]},a.id))})]})}function pt(t){return t?.trim()?t:void 0}function ht({ownerSlug:t,entityName:s,activityHref:n}){const i=We();return e.jsxs(v,{variant:"outline",size:"sm",onClick:()=>i?.open({href:n,title:`${s} · Activity`,owner:t}),disabled:!i,children:[e.jsx(Xe,{className:"mr-2 h-4 w-4"}),"See activity"]})}function _t({namespace:t,path:s,entity:n,mergedFrom:i}){const a=Q(),{data:o}=te(n.entity_type,{slug:t.slug}),r=pt(o?.icon),l=s.map(d=>({entity_type:d.entity_type,slug:d.slug})),u=`/${t.slug}/${n.entity_type}`,c=s.length>1?M(t.slug,l.slice(0,-1)):u;return e.jsxs("div",{className:"mx-auto flex min-h-0 w-full max-w-3xl flex-1 flex-col gap-6 px-4 py-6 lg:px-6",children:[i?e.jsxs("div",{className:"rounded-lg border border-primary/30 bg-primary/5 px-4 py-3 text-sm",children:[e.jsx("strong",{children:i})," was merged into this canonical record."]}):null,e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[e.jsx(v,{asChild:!0,variant:"ghost",size:"sm",className:"-ml-2 h-7 w-fit px-2 text-muted-foreground hover:text-foreground",children:e.jsxs(He,{to:c,children:[e.jsx(Ke,{className:"mr-1 h-4 w-4"}),"Back"]})}),!n.is_derived&&e.jsx("div",{className:"ml-auto",children:e.jsx(ht,{ownerSlug:t.slug,entityName:n.name,activityHref:`/${t.slug}/events/${qe(l)}`})})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(st,{metadata:n.metadata,metadataSchema:o?.metadata_schema,name:n.name,typeIcon:r,className:"h-6 w-6"}),e.jsx("h2",{className:"text-lg font-semibold leading-tight",children:n.name})]})]}),e.jsx(gt,{records:n.merged_records??[]}),e.jsx(ut,{namespace:t,entity:n,onDeleted:()=>{const d=s.slice(0,-1);d.length>0?a({to:M(t.slug,d)}):a({to:u})}})]})}export{_t as EntityPage};
|
package/dist/owletto/dist/assets/{entity-type-page-BfxIgJLq.js → entity-type-page-C3mT7tXn.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,af as $,a1 as W,bU as me,c6 as xe,bX as G,c7 as ae,r as x,bV as he,bW as pe,ci as ge,cj as fe,B as f,P as U,ck as je,aa as C,bY as q,bZ as P,b_ as M,b$ as L,c0 as k,ab as T,s as ve,cd as Ne,e4 as ye,e5 as be,X as H,cP as ne,dU as re,ak as we,bw as le,e6 as ie,e7 as Se,bF as oe,e8 as Ce,e9 as ke,k as Ee,co as K,F as _e,ea as Re,c2 as Te,eb as Oe,ec as De,aj as X}from"./index-Bfux0kHb.js";import{J as B}from"./json-diff-CANZD4MQ.js";import{C as ce}from"./code-editor-D3X0yQdI.js";function Ae(s){switch(s){case"create":return"default";case"update":return"secondary";case"delete":return"destructive";default:return"outline"}}function Fe(s){switch(s){case"create":return"Created";case"update":return"Updated";case"delete":return"Deleted";default:return s}}function ze(s){try{return new Date(s).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}catch{return s}}function qe({entry:s}){return e.jsxs("div",{className:"relative pl-6 pb-6 last:pb-0",children:[e.jsx("div",{className:"absolute left-0 top-1.5 h-3 w-3 rounded-full border-2 border-border bg-background"}),e.jsx("div",{className:"absolute left-[5px] top-5 bottom-0 w-px bg-border last:hidden"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{variant:Ae(s.action),children:Fe(s.action)}),s.actor&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.actor})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ze(s.created_at)}),s.action==="update"&&e.jsx(B,{before:s.before_payload,after:s.after_payload}),s.action==="create"&&s.after_payload&&e.jsx(B,{before:null,after:s.after_payload}),s.action==="delete"&&s.before_payload&&e.jsx(B,{before:s.before_payload,after:null})]})]})}function Pe({entityType:s}){const{orgContext:a}=W(),{data:c,isLoading:n}=me(a),{data:r}=xe(a),t=(c||[]).filter(m=>m.status==="active"),i=t.filter(m=>!m.organization_slug||m.organization_slug===a?.slug),o=i.filter(m=>m.purpose!==G),d=i.filter(m=>m.purpose===G),h=t.filter(m=>m.organization_slug&&m.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(ae,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]}),d.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Managed by access control"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:d,allEntityTypes:r||[],readOnly:!0})]}),h.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"From public catalogs"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:h,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Ie,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]})]})})}function J({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Me,{relationshipType:r,entityTypeSlug:s,allEntityTypes:c,readOnly:n},r.id))})}function Me({relationshipType:s,entityTypeSlug:a,allEntityTypes:c,readOnly:n=!1}){const{orgContext:r}=W(),{data:t}=Ne(s.slug,r),i=ye(),o=(t||[]).filter(h=>h.source_entity_type_slug===a||h.target_entity_type_slug===a);if(o.length===0)return null;const d=new Map(c.map(h=>[h.slug,h.name]));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:s.slug}),s.is_symmetric&&e.jsx($,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx($,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),o.map(h=>e.jsx(Le,{rule:h,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(h.id),isRemoving:i.isPending,readOnly:n},h.id))]})}function Le({rule:s,entityTypeSlug:a,entityTypeNameMap:c,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,o]=x.useState(!1),d=s.source_entity_type_slug===a,h=d?s.target_entity_type_slug:s.source_entity_type_slug,m=c.get(h)||h;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-3 rounded-md border border-border bg-muted/30 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:d?"this":m}),e.jsx(be,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?m:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(f,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>o(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>o(!0),disabled:r,children:e.jsx(H,{className:"h-3 w-3"})})})]})}function Ie({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c}){const{orgContext:n}=W(),r=c.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=x.useState(!1),[o,d]=x.useState("existing"),[h,m]=x.useState(""),[S,N]=x.useState(""),[y,b]=x.useState("source"),[g,j]=x.useState(""),[E,_]=x.useState(""),[D,w]=x.useState(!1),[A,R]=x.useState(null),u=he(),p=pe(),v=()=>{d("existing"),m(""),N(""),b("source"),j(""),_(""),w(!1),R(null)},O=l=>{i(l),l||v()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),V=async()=>{R(null);try{let l=h;if(o==="new"){if(!g.trim()){R("Name is required");return}const Y=E.trim()||F(g);if(!Y){R("Slug is required");return}l=(await u.mutateAsync({slug:Y,name:g.trim(),is_symmetric:D})).relationship_type.slug}if(!l){R("Select a relationship type");return}if(!S){R("Select a target entity type");return}const I=y==="source"?s:S,ue=y==="source"?S:s;await p.mutateAsync({slug:l,source_entity_type_slug:I,target_entity_type_slug:ue}),O(!1)}catch(l){R(l instanceof Error?l.message:"An error occurred")}},z=u.isPending||p.isPending;return e.jsxs(ge,{open:t,onOpenChange:O,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1.5"}),"Add Relationship Rule"]})}),e.jsx(je,{className:"w-80 p-4",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(f,{variant:o==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(f,{variant:o==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),o==="existing"?e.jsxs(q,{value:h,onValueChange:m,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select relationship type..."})}),e.jsxs(L,{children:[a.map(l=>e.jsx(k,{value:l.slug,children:l.name},l.slug)),a.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No relationship types yet. Create one."})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:g,onChange:l=>{j(l.target.value),E||_("")}}),e.jsx(T,{placeholder:g?F(g)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:E,onChange:l=>_(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>w(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:y,onValueChange:l=>b(l),children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"source",children:"This type → other"}),e.jsx(k,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(C,{className:"text-xs",children:[y==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:S,onValueChange:N,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select entity type..."})}),e.jsx(L,{children:r.map(l=>e.jsxs(k,{value:l.slug,children:[l.icon?`${l.icon} `:"",l.name]},l.slug))})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),e.jsx(f,{size:"sm",className:"w-full",onClick:V,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ue({options:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const i=c.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((o,d)=>d!==i))};return e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((i,o)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-sm px-2 py-0.5 rounded",children:[i,e.jsx("button",{type:"button",onClick:()=>t(o),className:"text-muted-foreground hover:text-foreground",children:e.jsx(H,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(T,{value:c,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}const Ve=[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"integer",label:"Integer"},{value:"boolean",label:"Boolean"},{value:"enum",label:"Enum"}];function Be({examples:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const t=c.trim();t&&!s.includes(t)&&(a([...s,t]),n(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((t,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-xs px-2 py-0.5 rounded",children:[t,e.jsx("button",{type:"button",onClick:()=>a(s.filter((o,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(H,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(T,{value:c,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}function Je({field:s,onChange:a,onDelete:c}){const[n,r]=x.useState(!!(s.description||s.default||s.role||s.examples&&s.examples.length>0));return e.jsxs("div",{className:"rounded-md border border-border p-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>r(!n),className:"text-muted-foreground hover:text-foreground shrink-0",children:n?e.jsx(ne,{className:"h-3.5 w-3.5"}):e.jsx(re,{className:"h-3.5 w-3.5"})}),e.jsx(T,{value:s.name,onChange:t=>a({...s,name:t.target.value}),placeholder:"Field name",className:"h-8 flex-1"}),e.jsxs(q,{value:s.type,onValueChange:t=>a({...s,type:t,enumOptions:t==="enum"?s.enumOptions||[]:void 0,role:t==="enum"||s.role!=="workflowState"?s.role:void 0}),children:[e.jsx(P,{className:"h-8 w-32",children:e.jsx(M,{})}),e.jsx(L,{children:Ve.map(t=>e.jsx(k,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground whitespace-nowrap",children:[e.jsx(we,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:c,children:e.jsx(le,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Ue,{options:s.enumOptions||[],onChange:t=>a({...s,enumOptions:t})})}),n&&e.jsxs("div",{className:"pl-6 space-y-2 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Description"}),e.jsx(T,{value:s.description||"",onChange:t=>a({...s,description:t.target.value||void 0}),placeholder:"Field description",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default"}),e.jsx(T,{value:s.default||"",onChange:t=>a({...s,default:t.target.value||void 0}),placeholder:s.type==="boolean"?"true / false":"Default value",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"View role"}),e.jsxs(q,{value:s.role||"none",onValueChange:t=>a({...s,role:t==="workflowState"||t==="sortRank"?t:void 0}),children:[e.jsx(P,{className:"h-7 text-xs mt-0.5",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"none",children:"None"}),e.jsx(k,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(k,{value:"sortRank",children:"Sort rank"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Examples"}),e.jsx("div",{className:"mt-0.5",children:e.jsx(Be,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function Z({value:s,onChange:a,readonly:c,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{value:s,onChange:a,readonly:c,placeholder:'{ "type": "object", "properties": {} }',minHeight:"200px"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n})]})}function Q(s){if(s.type!=="object")return!1;const a=s.properties;if(!a||typeof a!="object")return Object.keys(s).length<=1;for(const c of Object.values(a)){if(!c||typeof c!="object")return!1;const n=c,r=n.type;if(!n.enum&&(!r||!["string","number","integer","boolean"].includes(r)||n.properties||n.items||n.allOf||n.oneOf||n.anyOf))return!1}return!0}function de(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`field-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ee(s){const a=s.properties||{},c=s.required||[];return Object.entries(a).map(([n,r])=>{const t=r["x-lobu"]?.role||r["x-lobu-role"],i=t==="workflowState"?"workflowState":t==="sortRank"?"sortRank":void 0,o={id:de(),name:n,required:c.includes(n),description:r.description||void 0,default:r.default!==void 0?String(r.default):void 0,examples:Array.isArray(r.examples)?r.examples.map(String):void 0,role:i};return r.enum?{...o,type:"enum",enumOptions:r.enum||[]}:{...o,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const c=Number(s);return Number.isNaN(c)?s:c}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function $e(s,a="auto"){const c={},n=[];for(const t of s){if(!t.name.trim())continue;const i={};t.type==="enum"?i.enum=t.enumOptions||[]:i.type=t.type,t.description?.trim()&&(i.description=t.description.trim()),t.default!==void 0&&t.default!==""&&(i.default=se(t.default,t.type)),t.examples&&t.examples.length>0&&(i.examples=t.examples.map(o=>se(o,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(o=>({value:o,label:o.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(o.toLowerCase())}))}:{}}),c[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:c};return n.length>0&&(r.required=n),a&&a!=="auto"&&(r["x-lobu"]={defaultView:a}),r}function te(s){const a=s["x-lobu"]?.defaultView;return a==="table"||a==="board"||a==="gallery"?a:"auto"}function We({value:s,onChange:a,readonly:c=!1}){const[n,r]=x.useState("visual"),[t,i]=x.useState([]),[o,d]=x.useState("auto"),[h,m]=x.useState(""),[S,N]=x.useState(null),[y,b]=x.useState(!1),g=x.useRef(!1);x.useEffect(()=>{if(g.current){g.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),m(""),b(!1);return}const u=JSON.stringify(s,null,2);m(u),d(te(s)),Q(s)?(i(ee(s)),b(!1)):(b(!0),r("json"))},[s]);const j=x.useCallback((u,p)=>{g.current=!0;const v=$e(u,p),O=u.some(F=>F.name.trim());m(O?JSON.stringify(v,null,2):""),a(O?v:void 0)},[a]),E=x.useCallback(u=>{i(u),j(u,o)},[j,o]),_=x.useCallback(u=>{d(u),j(t,u)},[j,t]),D=x.useCallback(u=>{if(g.current=!0,m(u),!u.trim()){N(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(u);N(null),d(te(p)),Q(p)?(i(ee(p)),b(!1)):b(!0),a(p)}catch(p){N(p instanceof Error?p.message:"Invalid JSON")}},[a]),w=()=>{E([...t,{id:de(),name:"",type:"string",required:!1}])},A=(u,p)=>{const v=[...t];v[u]=p,E(v)},R=u=>{E(t.filter((p,v)=>v!==u))};return c?e.jsx(Z,{value:h,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(f,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!y&&r("visual"),disabled:y,className:"h-7 text-xs",children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(f,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Se,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),y&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-amber-500/10 text-amber-600 text-xs",children:[e.jsx(oe,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:"This schema uses advanced features (nested objects, allOf, etc.) that can only be edited in JSON mode."})]}),n==="visual"?e.jsxs("div",{className:"space-y-3",children:[t.map((u,p)=>e.jsx(Je,{field:u,onChange:v=>A(p,v),onDelete:()=>R(p)},u.id)),e.jsxs(f,{type:"button",variant:"outline",size:"sm",onClick:w,className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(u=>u.name.trim())&&e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border p-2.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default view"}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Which view this type opens in. Auto picks from your fields (a workflow field → board, an image field → gallery)."})]}),e.jsxs(q,{value:o,onValueChange:u=>_(u),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"auto",children:"Auto"}),e.jsx(k,{value:"table",children:"Table"}),e.jsx(k,{value:"board",children:"Board"}),e.jsx(k,{value:"gallery",children:"Gallery"})]})]})]})]}):e.jsx(Z,{value:h,onChange:D,error:S})]})}function He(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ye({entityType:s,onCancel:a,onSaved:c}){const n=!!s,r=Ce(),t=ke(),i=s?.slug??"new",o=Ee(i,{name:s?.name??"",slug:s?.slug??"",description:s?.description??"",icon:s?.icon??"",color:s?.color??"",metadataSchema:s?.metadata_schema??void 0,backingSql:s?.backing_sql??""}),[d,h]=o.field("name"),[m,S]=o.field("slug"),[N,y]=o.field("description"),[b,g]=o.field("icon"),[j,E]=o.field("color"),[_,D]=o.field("metadataSchema"),[w,A]=o.field("backingSql"),[R,u]=K(i,n),[p,v]=K(i,null),O=w.trim().length>0,F=l=>{h(l),!n&&!R&&S(He(l))},V=async()=>{if(!o.canSubmit)return;if(v(null),!d.trim()){v("Name is required");return}if(!n&&!m.trim()){v("Slug is required");return}const l=O?{sql:w.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:O?void 0:_,backing:l}):await r.mutateAsync({slug:m.trim(),name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:O?void 0:_,backing:l}),c()}catch(I){v(I instanceof Error?I.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(_e,{visible:o.hasConflict,onReload:o.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-name",children:"Name"}),e.jsx(T,{id:"et-name",value:d,onChange:l=>F(l.target.value),placeholder:"e.g. Product"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-slug",children:"Slug"}),e.jsx(T,{id:"et-slug",value:m,onChange:l=>{u(!0),S(l.target.value)},placeholder:"e.g. topic",disabled:n}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Slug cannot be changed after creation."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-desc",children:"Description"}),e.jsx(Re,{id:"et-desc",value:N,onChange:l=>y(l.target.value),placeholder:"Optional description...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(T,{id:"et-icon",value:b,onChange:l=>g(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{id:"et-color",value:j,onChange:l=>E(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),j&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:j}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Backing query (SQL)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. A read-only SELECT turns this into a derived (view) type — rows are computed from the query, not stored. Leave empty for a normal stored type. Table references are auto-scoped to your organization."}),e.jsx(ce,{value:w,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),O?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground",children:[e.jsx(ie,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Derived view — columns are computed from the query, so there's no stored-row schema to define."})]}),s?.measure_columns&&s.measure_columns.length>0&&e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(C,{children:"Measure columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.measure_columns.map(l=>e.jsx("span",{className:"rounded-md border border-border bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:l},l))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Metadata Schema"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define the structure of metadata fields for entities of this type."}),e.jsx(We,{value:_,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(Pe,{entityType:s})]}),p&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:p}),e.jsx(Te,{onCancel:a,cancelDisabled:z,className:"pt-2",children:e.jsx(f,{onClick:V,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function Qe({entityType:s,onClose:a,orgContext:c,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,o]=x.useState(!1),[d,h]=x.useState(!1),[m,S]=x.useState(null),N=Oe(),{data:y,isLoading:b}=De(i&&s?s.slug:null,c),g=s?.entity_count??0,j=g>0,E=async()=>{if(s){S(null);try{await N.mutateAsync(s.slug),a()}catch(w){S(w instanceof Error?w.message:"Failed to delete")}}},_=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",D=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:X("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsx("h1",{className:X("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:_}),e.jsx("p",{className:"text-sm text-muted-foreground",children:D})]}),e.jsx("div",{className:"py-4",children:e.jsx(Ye,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors w-full",children:[i?e.jsx(ne,{className:"h-4 w-4"}):e.jsx(re,{className:"h-4 w-4"}),"History"]}),i&&e.jsx("div",{className:"mt-3",children:b?e.jsx(ae,{label:"history",variant:"rows",rows:4}):y&&y.length>0?e.jsx("div",{className:"relative ml-1.5",children:y.map(w=>e.jsx(qe,{entry:w},w.id))}):e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No audit history found."})})]}),!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:d?e.jsxs("div",{className:"space-y-3",children:[j?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(oe,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Cannot delete this entity type"}),e.jsxs("p",{className:"mt-1 text-amber-600/80",children:["There ",g===1?"is":"are"," ",g," entit",g===1?"y":"ies",' of type "',s.name,'". Migrate or delete them first.']})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:['Are you sure you want to delete "',s.name,'"? This action will soft-delete the entity type. It can be restored by a database administrator.']}),m&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{h(!1),S(null)},children:"Cancel"}),e.jsx(f,{variant:"destructive",size:"sm",onClick:E,disabled:j||N.isPending,children:N.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(f,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>h(!0),children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}export{Qe as E};
|
|
1
|
+
import{j as e,af as $,a1 as W,bU as me,c6 as xe,bX as G,c7 as ae,r as x,bV as he,bW as pe,ci as ge,cj as fe,B as f,P as U,ck as je,aa as C,bY as q,bZ as P,b_ as M,b$ as L,c0 as k,ab as T,s as ve,cd as Ne,e4 as ye,e5 as be,X as H,cP as ne,dU as re,ak as we,bw as le,e6 as ie,e7 as Se,bF as oe,e8 as Ce,e9 as ke,k as Ee,co as K,F as _e,ea as Re,c2 as Te,eb as Oe,ec as De,aj as X}from"./index-BUr8321-.js";import{J as B}from"./json-diff-DnsW7Pin.js";import{C as ce}from"./code-editor-BqGUZFt6.js";function Ae(s){switch(s){case"create":return"default";case"update":return"secondary";case"delete":return"destructive";default:return"outline"}}function Fe(s){switch(s){case"create":return"Created";case"update":return"Updated";case"delete":return"Deleted";default:return s}}function ze(s){try{return new Date(s).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"numeric",minute:"2-digit"})}catch{return s}}function qe({entry:s}){return e.jsxs("div",{className:"relative pl-6 pb-6 last:pb-0",children:[e.jsx("div",{className:"absolute left-0 top-1.5 h-3 w-3 rounded-full border-2 border-border bg-background"}),e.jsx("div",{className:"absolute left-[5px] top-5 bottom-0 w-px bg-border last:hidden"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{variant:Ae(s.action),children:Fe(s.action)}),s.actor&&e.jsx("span",{className:"text-xs text-muted-foreground",children:s.actor})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:ze(s.created_at)}),s.action==="update"&&e.jsx(B,{before:s.before_payload,after:s.after_payload}),s.action==="create"&&s.after_payload&&e.jsx(B,{before:null,after:s.after_payload}),s.action==="delete"&&s.before_payload&&e.jsx(B,{before:s.before_payload,after:null})]})]})}function Pe({entityType:s}){const{orgContext:a}=W(),{data:c,isLoading:n}=me(a),{data:r}=xe(a),t=(c||[]).filter(m=>m.status==="active"),i=t.filter(m=>!m.organization_slug||m.organization_slug===a?.slug),o=i.filter(m=>m.purpose!==G),d=i.filter(m=>m.purpose===G),h=t.filter(m=>m.organization_slug&&m.organization_slug!==a?.slug);return e.jsx("div",{className:"space-y-4 py-4",children:n?e.jsx(ae,{label:"relationships",variant:"rows",rows:4}):e.jsxs(e.Fragment,{children:[e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]}),d.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Managed by access control"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:d,allEntityTypes:r||[],readOnly:!0})]}),h.length>0&&e.jsxs("div",{className:"space-y-2 pt-2",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"From public catalogs"}),e.jsx(J,{entityTypeSlug:s.slug,relationshipTypes:h,allEntityTypes:r||[],readOnly:!0})]}),e.jsx(Ie,{entityTypeSlug:s.slug,relationshipTypes:o,allEntityTypes:r||[]})]})})}function J({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c,readOnly:n=!1}){return e.jsx("div",{className:"space-y-2",children:a.map(r=>e.jsx(Me,{relationshipType:r,entityTypeSlug:s,allEntityTypes:c,readOnly:n},r.id))})}function Me({relationshipType:s,entityTypeSlug:a,allEntityTypes:c,readOnly:n=!1}){const{orgContext:r}=W(),{data:t}=Ne(s.slug,r),i=ye(),o=(t||[]).filter(h=>h.source_entity_type_slug===a||h.target_entity_type_slug===a);if(o.length===0)return null;const d=new Map(c.map(h=>[h.slug,h.name]));return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium",children:s.name}),e.jsx("code",{className:"text-[11px] bg-muted px-1.5 py-0.5 rounded text-muted-foreground",children:s.slug}),s.is_symmetric&&e.jsx($,{variant:"secondary",className:"text-[10px] px-1.5 py-0",children:"symmetric"}),n&&e.jsx($,{variant:"outline",className:"text-[10px] px-1.5 py-0",children:"read-only"})]}),o.map(h=>e.jsx(Le,{rule:h,entityTypeSlug:a,entityTypeNameMap:d,onRemove:()=>i.mutate(h.id),isRemoving:i.isPending,readOnly:n},h.id))]})}function Le({rule:s,entityTypeSlug:a,entityTypeNameMap:c,onRemove:n,isRemoving:r,readOnly:t=!1}){const[i,o]=x.useState(!1),d=s.source_entity_type_slug===a,h=d?s.target_entity_type_slug:s.source_entity_type_slug,m=c.get(h)||h;return e.jsxs("div",{className:"flex items-center gap-2 py-1.5 px-3 rounded-md border border-border bg-muted/30 text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:d?"this":m}),e.jsx(be,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:d?m:"this"}),t?null:i?e.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[e.jsx(f,{variant:"destructive",size:"sm",className:"h-6 px-2 text-xs",onClick:n,disabled:r,children:r?"Removing...":"Remove"}),e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 px-2 text-xs",onClick:()=>o(!1),disabled:r,children:"Cancel"})]}):e.jsx("div",{className:"ml-auto",children:e.jsx(f,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground hover:text-destructive",onClick:()=>o(!0),disabled:r,children:e.jsx(H,{className:"h-3 w-3"})})})]})}function Ie({entityTypeSlug:s,relationshipTypes:a,allEntityTypes:c}){const{orgContext:n}=W(),r=c.filter(l=>!l.organization_slug||l.organization_slug===n?.slug),[t,i]=x.useState(!1),[o,d]=x.useState("existing"),[h,m]=x.useState(""),[S,N]=x.useState(""),[y,b]=x.useState("source"),[g,j]=x.useState(""),[E,_]=x.useState(""),[D,w]=x.useState(!1),[A,R]=x.useState(null),u=he(),p=pe(),v=()=>{d("existing"),m(""),N(""),b("source"),j(""),_(""),w(!1),R(null)},O=l=>{i(l),l||v()},F=l=>l.toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,""),V=async()=>{R(null);try{let l=h;if(o==="new"){if(!g.trim()){R("Name is required");return}const Y=E.trim()||F(g);if(!Y){R("Slug is required");return}l=(await u.mutateAsync({slug:Y,name:g.trim(),is_symmetric:D})).relationship_type.slug}if(!l){R("Select a relationship type");return}if(!S){R("Select a target entity type");return}const I=y==="source"?s:S,ue=y==="source"?S:s;await p.mutateAsync({slug:l,source_entity_type_slug:I,target_entity_type_slug:ue}),O(!1)}catch(l){R(l instanceof Error?l.message:"An error occurred")}},z=u.isPending||p.isPending;return e.jsxs(ge,{open:t,onOpenChange:O,children:[e.jsx(fe,{asChild:!0,children:e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1.5"}),"Add Relationship Rule"]})}),e.jsx(je,{className:"w-80 p-4",align:"start",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Relationship Type"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(f,{variant:o==="existing"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("existing"),children:"Existing"}),e.jsx(f,{variant:o==="new"?"default":"outline",size:"sm",className:"h-7 text-xs flex-1",onClick:()=>d("new"),children:"Create New"})]})]}),o==="existing"?e.jsxs(q,{value:h,onValueChange:m,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select relationship type..."})}),e.jsxs(L,{children:[a.map(l=>e.jsx(k,{value:l.slug,children:l.name},l.slug)),a.length===0&&e.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No relationship types yet. Create one."})]})]}):e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{placeholder:"Name (e.g. Integrates With)",className:"h-8 text-sm",value:g,onChange:l=>{j(l.target.value),E||_("")}}),e.jsx(T,{placeholder:g?F(g)||"slug":"Slug (auto-generated)",className:"h-8 text-sm",value:E,onChange:l=>_(l.target.value)}),e.jsxs("label",{className:"flex items-center gap-2 text-xs cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:l=>w(l.target.checked),className:"rounded"}),"Symmetric (A↔B = B↔A)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{className:"text-xs",children:"Direction"}),e.jsxs(q,{value:y,onValueChange:l=>b(l),children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"source",children:"This type → other"}),e.jsx(k,{value:"target",children:"Other → this type"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(C,{className:"text-xs",children:[y==="source"?"Target":"Source"," Entity Type"]}),e.jsxs(q,{value:S,onValueChange:N,children:[e.jsx(P,{className:"h-8 text-sm",children:e.jsx(M,{placeholder:"Select entity type..."})}),e.jsx(L,{children:r.map(l=>e.jsxs(k,{value:l.slug,children:[l.icon?`${l.icon} `:"",l.name]},l.slug))})]})]}),A&&e.jsx("p",{className:"text-xs text-destructive",children:A}),e.jsx(f,{size:"sm",className:"w-full",onClick:V,disabled:z,children:z?e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"mr-1.5"}),"Saving..."]}):"Add Rule"})]})})]})}function Ue({options:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const i=c.trim();i&&!s.includes(i)&&(a([...s,i]),n(""))},t=i=>{a(s.filter((o,d)=>d!==i))};return e.jsxs("div",{className:"space-y-2 pl-4 border-l-2 border-muted",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((i,o)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-sm px-2 py-0.5 rounded",children:[i,e.jsx("button",{type:"button",onClick:()=>t(o),className:"text-muted-foreground hover:text-foreground",children:e.jsx(H,{className:"h-3 w-3"})})]},i))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(T,{value:c,onChange:i=>n(i.target.value),onKeyDown:i=>{i.key==="Enter"&&(i.preventDefault(),r())},placeholder:"Add option...",className:"h-7 text-sm"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}const Ve=[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"integer",label:"Integer"},{value:"boolean",label:"Boolean"},{value:"enum",label:"Enum"}];function Be({examples:s,onChange:a}){const[c,n]=x.useState(""),r=()=>{const t=c.trim();t&&!s.includes(t)&&(a([...s,t]),n(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((t,i)=>e.jsxs("span",{className:"inline-flex items-center gap-1 bg-muted text-xs px-2 py-0.5 rounded",children:[t,e.jsx("button",{type:"button",onClick:()=>a(s.filter((o,d)=>d!==i)),className:"text-muted-foreground hover:text-foreground",children:e.jsx(H,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx(T,{value:c,onChange:t=>n(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),r())},placeholder:"Add example...",className:"h-7 text-xs"}),e.jsx(f,{type:"button",variant:"outline",size:"sm",className:"h-7 px-2",onClick:r,children:e.jsx(U,{className:"h-3 w-3"})})]})]})}function Je({field:s,onChange:a,onDelete:c}){const[n,r]=x.useState(!!(s.description||s.default||s.role||s.examples&&s.examples.length>0));return e.jsxs("div",{className:"rounded-md border border-border p-2.5 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>r(!n),className:"text-muted-foreground hover:text-foreground shrink-0",children:n?e.jsx(ne,{className:"h-3.5 w-3.5"}):e.jsx(re,{className:"h-3.5 w-3.5"})}),e.jsx(T,{value:s.name,onChange:t=>a({...s,name:t.target.value}),placeholder:"Field name",className:"h-8 flex-1"}),e.jsxs(q,{value:s.type,onValueChange:t=>a({...s,type:t,enumOptions:t==="enum"?s.enumOptions||[]:void 0,role:t==="enum"||s.role!=="workflowState"?s.role:void 0}),children:[e.jsx(P,{className:"h-8 w-32",children:e.jsx(M,{})}),e.jsx(L,{children:Ve.map(t=>e.jsx(k,{value:t.value,children:t.label},t.value))})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-sm text-muted-foreground whitespace-nowrap",children:[e.jsx(we,{checked:s.required,onCheckedChange:t=>a({...s,required:t===!0})}),e.jsx("span",{children:"Required"})]}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 p-0 text-muted-foreground hover:text-destructive",onClick:c,children:e.jsx(le,{className:"h-3.5 w-3.5"})})]}),s.type==="enum"&&e.jsx("div",{className:"pl-6",children:e.jsx(Ue,{options:s.enumOptions||[],onChange:t=>a({...s,enumOptions:t})})}),n&&e.jsxs("div",{className:"pl-6 space-y-2 pt-1",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Description"}),e.jsx(T,{value:s.description||"",onChange:t=>a({...s,description:t.target.value||void 0}),placeholder:"Field description",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default"}),e.jsx(T,{value:s.default||"",onChange:t=>a({...s,default:t.target.value||void 0}),placeholder:s.type==="boolean"?"true / false":"Default value",className:"h-7 text-xs mt-0.5"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"View role"}),e.jsxs(q,{value:s.role||"none",onValueChange:t=>a({...s,role:t==="workflowState"||t==="sortRank"?t:void 0}),children:[e.jsx(P,{className:"h-7 text-xs mt-0.5",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"none",children:"None"}),e.jsx(k,{value:"workflowState",disabled:s.type!=="enum",children:"Workflow state (board)"}),e.jsx(k,{value:"sortRank",children:"Sort rank"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Examples"}),e.jsx("div",{className:"mt-0.5",children:e.jsx(Be,{examples:s.examples||[],onChange:t=>a({...s,examples:t.length>0?t:void 0})})})]})]})]})}function Z({value:s,onChange:a,readonly:c,error:n}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx(ce,{value:s,onChange:a,readonly:c,placeholder:'{ "type": "object", "properties": {} }',minHeight:"200px"}),n&&e.jsx("p",{className:"text-sm text-destructive",children:n})]})}function Q(s){if(s.type!=="object")return!1;const a=s.properties;if(!a||typeof a!="object")return Object.keys(s).length<=1;for(const c of Object.values(a)){if(!c||typeof c!="object")return!1;const n=c,r=n.type;if(!n.enum&&(!r||!["string","number","integer","boolean"].includes(r)||n.properties||n.items||n.allOf||n.oneOf||n.anyOf))return!1}return!0}function de(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`field-${Date.now()}-${Math.random().toString(36).slice(2,10)}`}function ee(s){const a=s.properties||{},c=s.required||[];return Object.entries(a).map(([n,r])=>{const t=r["x-lobu"]?.role||r["x-lobu-role"],i=t==="workflowState"?"workflowState":t==="sortRank"?"sortRank":void 0,o={id:de(),name:n,required:c.includes(n),description:r.description||void 0,default:r.default!==void 0?String(r.default):void 0,examples:Array.isArray(r.examples)?r.examples.map(String):void 0,role:i};return r.enum?{...o,type:"enum",enumOptions:r.enum||[]}:{...o,type:r.type||"string"}})}function se(s,a){if(a==="number"||a==="integer"){const c=Number(s);return Number.isNaN(c)?s:c}return a==="boolean"?s==="true"?!0:s==="false"?!1:s:s}function $e(s,a="auto"){const c={},n=[];for(const t of s){if(!t.name.trim())continue;const i={};t.type==="enum"?i.enum=t.enumOptions||[]:i.type=t.type,t.description?.trim()&&(i.description=t.description.trim()),t.default!==void 0&&t.default!==""&&(i.default=se(t.default,t.type)),t.examples&&t.examples.length>0&&(i.examples=t.examples.map(o=>se(o,t.type))),t.role&&(i["x-lobu"]={role:t.role,...t.role==="workflowState"&&t.type==="enum"?{states:(t.enumOptions||[]).map(o=>({value:o,label:o.replace(/[_-]+/g," ").replace(/\b\w/g,d=>d.toUpperCase()),terminal:["done","complete","completed","closed","archived"].includes(o.toLowerCase())}))}:{}}),c[t.name]=i,t.required&&n.push(t.name)}const r={type:"object",properties:c};return n.length>0&&(r.required=n),a&&a!=="auto"&&(r["x-lobu"]={defaultView:a}),r}function te(s){const a=s["x-lobu"]?.defaultView;return a==="table"||a==="board"||a==="gallery"?a:"auto"}function We({value:s,onChange:a,readonly:c=!1}){const[n,r]=x.useState("visual"),[t,i]=x.useState([]),[o,d]=x.useState("auto"),[h,m]=x.useState(""),[S,N]=x.useState(null),[y,b]=x.useState(!1),g=x.useRef(!1);x.useEffect(()=>{if(g.current){g.current=!1;return}if(!s||Object.keys(s).length===0){i([]),d("auto"),m(""),b(!1);return}const u=JSON.stringify(s,null,2);m(u),d(te(s)),Q(s)?(i(ee(s)),b(!1)):(b(!0),r("json"))},[s]);const j=x.useCallback((u,p)=>{g.current=!0;const v=$e(u,p),O=u.some(F=>F.name.trim());m(O?JSON.stringify(v,null,2):""),a(O?v:void 0)},[a]),E=x.useCallback(u=>{i(u),j(u,o)},[j,o]),_=x.useCallback(u=>{d(u),j(t,u)},[j,t]),D=x.useCallback(u=>{if(g.current=!0,m(u),!u.trim()){N(null),i([]),d("auto"),a(void 0);return}try{const p=JSON.parse(u);N(null),d(te(p)),Q(p)?(i(ee(p)),b(!1)):b(!0),a(p)}catch(p){N(p instanceof Error?p.message:"Invalid JSON")}},[a]),w=()=>{E([...t,{id:de(),name:"",type:"string",required:!1}])},A=(u,p)=>{const v=[...t];v[u]=p,E(v)},R=u=>{E(t.filter((p,v)=>v!==u))};return c?e.jsx(Z,{value:h,onChange:()=>{},readonly:!0}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(f,{type:"button",variant:n==="visual"?"default":"outline",size:"sm",onClick:()=>!y&&r("visual"),disabled:y,className:"h-7 text-xs",children:[e.jsx(ie,{className:"h-3 w-3 mr-1"}),"Visual"]}),e.jsxs(f,{type:"button",variant:n==="json"?"default":"outline",size:"sm",onClick:()=>r("json"),className:"h-7 text-xs",children:[e.jsx(Se,{className:"h-3 w-3 mr-1"}),"JSON"]})]}),y&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-amber-500/10 text-amber-600 text-xs",children:[e.jsx(oe,{className:"h-3.5 w-3.5 mt-0.5 shrink-0"}),e.jsx("span",{children:"This schema uses advanced features (nested objects, allOf, etc.) that can only be edited in JSON mode."})]}),n==="visual"?e.jsxs("div",{className:"space-y-3",children:[t.map((u,p)=>e.jsx(Je,{field:u,onChange:v=>A(p,v),onDelete:()=>R(p)},u.id)),e.jsxs(f,{type:"button",variant:"outline",size:"sm",onClick:w,className:"w-full",children:[e.jsx(U,{className:"h-3.5 w-3.5 mr-1"}),"Add Field"]}),t.some(u=>u.name.trim())&&e.jsxs("div",{className:"flex items-center gap-3 rounded-md border border-border p-2.5",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium",children:"Default view"}),e.jsx("p",{className:"text-[11px] text-muted-foreground/70",children:"Which view this type opens in. Auto picks from your fields (a workflow field → board, an image field → gallery)."})]}),e.jsxs(q,{value:o,onValueChange:u=>_(u),children:[e.jsx(P,{className:"h-8 w-32 text-xs",children:e.jsx(M,{})}),e.jsxs(L,{children:[e.jsx(k,{value:"auto",children:"Auto"}),e.jsx(k,{value:"table",children:"Table"}),e.jsx(k,{value:"board",children:"Board"}),e.jsx(k,{value:"gallery",children:"Gallery"})]})]})]})]}):e.jsx(Z,{value:h,onChange:D,error:S})]})}function He(s){return s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ye({entityType:s,onCancel:a,onSaved:c}){const n=!!s,r=Ce(),t=ke(),i=s?.slug??"new",o=Ee(i,{name:s?.name??"",slug:s?.slug??"",description:s?.description??"",icon:s?.icon??"",color:s?.color??"",metadataSchema:s?.metadata_schema??void 0,backingSql:s?.backing_sql??""}),[d,h]=o.field("name"),[m,S]=o.field("slug"),[N,y]=o.field("description"),[b,g]=o.field("icon"),[j,E]=o.field("color"),[_,D]=o.field("metadataSchema"),[w,A]=o.field("backingSql"),[R,u]=K(i,n),[p,v]=K(i,null),O=w.trim().length>0,F=l=>{h(l),!n&&!R&&S(He(l))},V=async()=>{if(!o.canSubmit)return;if(v(null),!d.trim()){v("Name is required");return}if(!n&&!m.trim()){v("Slug is required");return}const l=O?{sql:w.trim()}:null;try{n?await t.mutateAsync({slug:s.slug,name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:O?void 0:_,backing:l}):await r.mutateAsync({slug:m.trim(),name:d.trim(),description:N.trim()||void 0,icon:b.trim()||void 0,color:j.trim()||void 0,metadata_schema:O?void 0:_,backing:l}),c()}catch(I){v(I instanceof Error?I.message:"An error occurred")}},z=r.isPending||t.isPending;return e.jsxs("div",{className:"space-y-5",children:[e.jsx(_e,{visible:o.hasConflict,onReload:o.reset}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-name",children:"Name"}),e.jsx(T,{id:"et-name",value:d,onChange:l=>F(l.target.value),placeholder:"e.g. Product"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-slug",children:"Slug"}),e.jsx(T,{id:"et-slug",value:m,onChange:l=>{u(!0),S(l.target.value)},placeholder:"e.g. topic",disabled:n}),n&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"Slug cannot be changed after creation."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-desc",children:"Description"}),e.jsx(Re,{id:"et-desc",value:N,onChange:l=>y(l.target.value),placeholder:"Optional description...",rows:2})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-icon",children:"Icon (emoji)"}),e.jsx(T,{id:"et-icon",value:b,onChange:l=>g(l.target.value),placeholder:"e.g. 📦"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{htmlFor:"et-color",children:"Color"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(T,{id:"et-color",value:j,onChange:l=>E(l.target.value),placeholder:"e.g. #6366f1",className:"flex-1"}),j&&e.jsx("div",{className:"h-9 w-9 rounded-md border border-border shrink-0",style:{backgroundColor:j}})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Backing query (SQL)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Optional. A read-only SELECT turns this into a derived (view) type — rows are computed from the query, not stored. Leave empty for a normal stored type. Table references are auto-scoped to your organization."}),e.jsx(ce,{value:w,onChange:A,minHeight:"120px",placeholder:"SELECT (metadata->>'vendor') AS vendor, SUM((metadata->>'amount')::numeric) AS total FROM events GROUP BY 1"})]}),O?e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground",children:[e.jsx(ie,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:"Derived view — columns are computed from the query, so there's no stored-row schema to define."})]}),s?.measure_columns&&s.measure_columns.length>0&&e.jsxs("div",{className:"space-y-1 pt-1",children:[e.jsx(C,{children:"Measure columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.measure_columns.map(l=>e.jsx("span",{className:"rounded-md border border-border bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground",children:l},l))})]})]}):e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Metadata Schema"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define the structure of metadata fields for entities of this type."}),e.jsx(We,{value:_,onChange:D})]}),n&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(C,{children:"Relationships"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Define how this entity type relates to others."}),e.jsx(Pe,{entityType:s})]}),p&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:p}),e.jsx(Te,{onCancel:a,cancelDisabled:z,className:"pt-2",children:e.jsx(f,{onClick:V,disabled:z,children:z?"Saving...":n?"Update":"Create"})})]})}function Qe({entityType:s,onClose:a,orgContext:c,hideDelete:n=!1,compact:r=!1}){const t=!!s,[i,o]=x.useState(!1),[d,h]=x.useState(!1),[m,S]=x.useState(null),N=Oe(),{data:y,isLoading:b}=De(i&&s?s.slug:null,c),g=s?.entity_count??0,j=g>0,E=async()=>{if(s){S(null);try{await N.mutateAsync(s.slug),a()}catch(w){S(w instanceof Error?w.message:"Failed to delete")}}},_=t?`${s?.icon||"📄"} ${s?.name}`:"Create Entity Type",D=t?"Edit entity type configuration.":"Define a new entity type for your workspace.";return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:X("space-y-1.5",!t&&!r&&"text-center"),children:[e.jsx("h1",{className:X("font-semibold leading-tight",r?"text-lg":"text-2xl"),children:_}),e.jsx("p",{className:"text-sm text-muted-foreground",children:D})]}),e.jsx("div",{className:"py-4",children:e.jsx(Ye,{entityType:s,onCancel:a,onSaved:a})}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-t border-border pt-4",children:[e.jsxs("button",{type:"button",onClick:()=>o(!i),className:"flex items-center gap-2 text-sm font-medium text-muted-foreground hover:text-foreground transition-colors w-full",children:[i?e.jsx(ne,{className:"h-4 w-4"}):e.jsx(re,{className:"h-4 w-4"}),"History"]}),i&&e.jsx("div",{className:"mt-3",children:b?e.jsx(ae,{label:"history",variant:"rows",rows:4}):y&&y.length>0?e.jsx("div",{className:"relative ml-1.5",children:y.map(w=>e.jsx(qe,{entry:w},w.id))}):e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No audit history found."})})]}),!n&&e.jsx("div",{className:"border-t border-border pt-4 mt-4",children:d?e.jsxs("div",{className:"space-y-3",children:[j?e.jsxs("div",{className:"flex items-start gap-3 p-3 rounded-md bg-amber-500/10 text-amber-600",children:[e.jsx(oe,{className:"h-5 w-5 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Cannot delete this entity type"}),e.jsxs("p",{className:"mt-1 text-amber-600/80",children:["There ",g===1?"is":"are"," ",g," entit",g===1?"y":"ies",' of type "',s.name,'". Migrate or delete them first.']})]})]}):e.jsxs("p",{className:"text-sm text-muted-foreground",children:['Are you sure you want to delete "',s.name,'"? This action will soft-delete the entity type. It can be restored by a database administrator.']}),m&&e.jsx("div",{className:"p-3 rounded-md bg-destructive/10 text-destructive text-sm",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{variant:"outline",size:"sm",onClick:()=>{h(!1),S(null)},children:"Cancel"}),e.jsx(f,{variant:"destructive",size:"sm",onClick:E,disabled:j||N.isPending,children:N.isPending?"Deleting...":"Delete"})]})]}):e.jsxs(f,{variant:"outline",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>h(!0),children:[e.jsx(le,{className:"h-3.5 w-3.5 mr-1.5"}),"Delete entity type"]})})]})]})}export{Qe as E};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as N,j as e,L as B,dU as $e,cx as ve,an as Pe,ag as Oe,eJ as Ie,J as De,a1 as Fe,aD as le,t as Me,af as J,z as Le,ci as ze,cj as Be,B as k,ck as Ue,dl as qe,dm as He,E as Ne,dn as Je,eK as be,eL as ae,cP as oe,eM as Ve,aj as We,bM as Y,G as _e,eN as Ke,eO as Qe,s as K,eP as Ge,eQ as Ye,k as Xe,eR as Ze,bE as et,F as tt,en as nt,cs as st,eS as rt,aO as it,eT as at,X as ot,bP as lt,Y as dt,dI as ct,dJ as ut,dQ as mt,dR as pt,eU as xt,eV as ht,S as gt,c8 as ft,bm as yt,I as jt,dz as xe,dB as he,aW as vt,dC as ge,x as we,eW as ke,eX as Nt}from"./index-Bfux0kHb.js";import{u as bt}from"./clients-R4JsT_Fz.js";import{J as _t}from"./renderer-B1UThnk2.js";function wt({onIntersect:n,enabled:t,rootMargin:s="400px"}){const r=N.useRef(null),a=N.useRef(n);return a.current=n,N.useEffect(()=>{const m=r.current;if(!m||!t)return;const y=new IntersectionObserver(o=>{o[0]?.isIntersecting&&a.current()},{rootMargin:s});return y.observe(m),()=>y.disconnect()},[t,s]),r}function kt(n,t){const s=t.parentEntityType&&t.parentEntitySlug?[{entity_type:t.parentEntityType,slug:t.parentEntitySlug},{entity_type:t.entityType,slug:t.entitySlug}]:[{entity_type:t.entityType,slug:t.entitySlug}];return ve(n,s)}function Ct({ownerSlug:n,entity:t,className:s}){const r=kt(n,t);return e.jsxs(B,{to:r,className:`flex items-center gap-1 text-primary hover:underline group ${s??""}`,children:[e.jsx("span",{className:"font-medium",children:t.entityName}),e.jsx($e,{className:"h-3 w-3 opacity-0 group-hover:opacity-100 transition-opacity"})]})}async function St(n,t,s,r){const a=await Pe(`${Oe}/api/${encodeURIComponent(n)}/events/${t}/actions/${encodeURIComponent(s.action)}`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:s.value,interaction_id:r})});return await Ie(a,"Could not record interaction"),a.json()}function w(n){if(typeof n!="string")return;const t=n.trim();return t.length>0?t:void 0}function de(n){return typeof n=="boolean"?n:void 0}function Rt(n,t,s){const r=(s??"").toLowerCase();return!!(r==="prepare_comment"||r==="verify_staged_comment"||r.includes("prepare_")||r.includes("verify_staged")||t?.prepared===!0||typeof t?.verified=="boolean"||w(t?.reason_preview)&&w(t?.message)||w(n?.body)&&(w(n?.post_url)||w(n?.activity_id)))}function At(n,t,s){if(!Rt(n,t,s))return null;const r=(s??"").toLowerCase(),a=w(t?.body)??w(n?.body),m=w(t?.reason_preview)??w(n?.reason),y=w(t?.post_url)??w(n?.post_url)??(w(n?.activity_id)?`https://www.linkedin.com/feed/update/urn:li:activity:${w(n?.activity_id)}`:void 0),o=de(t?.prepared),x=de(t?.verified),p=de(t?.banner_shown),f=w(t?.message),d=t?.match&&typeof t.match=="object"?t.match:null,b=w(d?.text_preview),c=w(d?.author);let h="generic";r==="verify_staged_comment"||r.includes("verify")||typeof x=="boolean"?h="verify":(r==="prepare_comment"||r.includes("prepare")||o===!0||a&&y)&&(h="prepare");const g=[];return o===!0&&g.push("Staged — not posted"),o===!1&&g.push("Not staged"),x===!0&&g.push("Verified posted"),x===!1&&g.push("Not verified as posted"),p===!0&&g.push("In-page banner"),p===!1&&g.push("No banner"),{kind:h,message:f,reason:m,body:a,postUrl:y,prepared:o,bannerShown:p,verified:x,matchPreview:b,matchAuthor:c,chips:g}}const Tt={};function te(n){return n.replace(/_/g," ").replace(/\s+/g," ").trim().replace(/^./,t=>t.toUpperCase())}const Et={notification:"Notification",tool_invocation:"Action",deployment:"Deployment",config_change:"Config change",message:"Message",msg:"Note",summary:"Summary"};function $t(n){return n.author_name?n.author_name:n.platform?te(n.platform):n.origin_type?Et[n.origin_type]??te(n.origin_type):null}function fe(n){return n==null?"":typeof n=="string"?n:typeof n=="number"||typeof n=="boolean"||typeof n=="bigint"?String(n):Array.isArray(n)?n.length===0?"":n.every(t=>typeof t!="object")?n.map(t=>String(t)).join(", "):e.jsx("pre",{className:"overflow-x-auto rounded bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap",children:JSON.stringify(n,null,2)}):e.jsx("pre",{className:"overflow-x-auto rounded bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap",children:JSON.stringify(n,null,2)})}const ce=1e5;function Pt({value:n}){const t=JSON.stringify(n,null,2)??"null",s=t.length>ce;return e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-80 overflow-auto whitespace-pre-wrap break-words rounded-md border bg-muted/40 p-3 font-mono text-xs",children:s?t.slice(0,ce):t}),s&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing the first ",ce.toLocaleString()," of"," ",t.length.toLocaleString()," characters."]})]})}function Ot(n){return Object.entries(n).filter(([,t])=>t==null?!1:typeof t=="string"?t.trim().length>0:Array.isArray(t)?t.length>0:typeof t=="object"?Object.keys(t).length>0:!0).sort(([t],[s])=>t.localeCompare(s))}function It({breakdown:n}){if(!n)return null;const t=[{label:"Engagement",value:n.engagement,max:100},{label:"Criticality",value:n.criticality,max:100},{label:"Depth",value:n.depth,max:100},{label:"Authority",value:n.authority,max:100},{label:"Recency",value:n.recency,max:100},{label:"Quality",value:n.quality,max:100}];return e.jsx("div",{className:"space-y-2 text-sm",children:t.map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-20 text-muted-foreground",children:s.label}),e.jsx("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary",style:{width:`${s.value/s.max*100}%`}})}),e.jsx("span",{className:"w-8 text-right",children:s.value})]},s.label))})}function Dt({slug:n,value:t,isManual:s}){return e.jsxs(J,{variant:"secondary",className:"text-xs",children:[n,": ",t,s&&e.jsx(be,{className:"ml-1 h-2.5 w-2.5 fill-current"})]})}function Ft(n){if(n&&typeof n=="object"){const t=n;if(Array.isArray(t.values))return{values:t.values.map(s=>String(s)).filter(s=>s.length>0),isManual:t.is_manual===!0};if(t.value!==void 0&&t.value!==null)return{values:[String(t.value)],isManual:t.is_manual===!0};if(typeof t.values=="string"&&t.values.length>0)return{values:[t.values],isManual:t.is_manual===!0}}return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||typeof n=="bigint"?{values:[String(n)],isManual:!1}:{values:[],isManual:!1}}function Mt(n,t){if(n)switch(n){case"pending":return"pending_approval";case"approved":return"confirmed";case"rejected":return"rejected";case"completed":return"completed";case"failed":return"failed";default:return n}return t||"pending_approval"}function O(n){return!n||typeof n!="object"||Array.isArray(n)?null:n}function ye(n){return n==null||n===""?"Not set":typeof n=="string"?n:JSON.stringify(n,null,2)}function Lt(n){return n.replace(/\s+[—-]\s+pending approval$/i,"")}function W(n){return n.replace(/^\$/,"").replace(/[_-]/g," ").replace(/\s+/g," ").trim().replace(/^./,t=>t.toUpperCase())}function Ce(n,t,s){return n?.kind==="agent_session"&&n.agent_id?n.client_id?`${n.agent_id} via ${n.client_id}`:n.agent_id:n?.kind==="user"?"a person":t==="agent"?"an agent":s?`Automation ${s}`:"an Automation"}function zt({initiator:n,clientName:t,fallback:s}){const{org:r}=Y(),a=r?.slug,m=n?.client_id??t,o=bt(void 0,{enabled:!!(a&&m)}).data?.find(d=>d.id===m)?.title,x=n&&n.kind!=="user"?Ce(n,void 0,n.automation_id===void 0?void 0:String(n.automation_id)):s,p="font-medium text-foreground",f=`${p} underline-offset-4 hover:underline`;return a&&n?.kind==="automation"&&n.automation_id?e.jsx(B,{to:"/$owner/automations/$automationId",params:{owner:a,automationId:String(n.automation_id)},search:{view:"definition",run_id:void 0},className:f,children:x}):a&&n?.kind==="agent_session"&&n.agent_id?e.jsx(B,{to:"/$owner/agents/$agentId",params:{owner:a,agentId:String(n.agent_id)},className:f,children:x}):a&&m?e.jsxs(B,{to:"/$owner/agents/connected/$clientId",params:{owner:a,clientId:m},className:`${f} inline-flex items-center gap-1 align-middle`,children:[e.jsx(lt,{name:o??t??m}),o??x]}):e.jsx("span",{className:p,children:x})}function Bt(n){const t=Object.keys(n.fields),s=t.map(W).join(", ")||"field",r=t.length===1?"field":"fields";return`Update ${n.entityType?W(n.entityType).toLowerCase():"entity"} ${r}: ${s}`}function Ut(n,t){const s=O(t.fields);if(!s||Object.keys(s).length===0||t.action_key!=="entity_field_change"&&t.tool!=="entity_field_change")return null;const r=O(t.current)??{},a=n;return{fields:s,current:r,reason:typeof t.reason=="string"?t.reason:void 0,automationId:t.automation_id!=null?String(t.automation_id):void 0,automationName:typeof t.automation_name=="string"?t.automation_name:void 0,automationAgentId:typeof t.automation_agent_id=="string"?t.automation_agent_id:void 0,entityType:typeof t.entity_type=="string"?t.entity_type:void 0,entityName:(typeof t.entity_name=="string"?t.entity_name:void 0)??a.entity_name??void 0,entitySlug:typeof t.entity_slug=="string"?t.entity_slug:void 0,parentSlug:typeof t.parent_slug=="string"?t.parent_slug:void 0,parentEntityType:typeof t.parent_entity_type=="string"?t.parent_entity_type:void 0,attribution:typeof t.attribution=="string"?t.attribution:void 0,initiator:t.initiator&&typeof t.initiator=="object"?t.initiator:void 0}}function qt(n){return!n||!Array.isArray(n.evidence)?[]:n.evidence.flatMap(t=>{const s=O(t),r=s?.kind,a=s?.identifier;return typeof r=="string"&&typeof a=="string"?[{kind:r,identifier:a}]:[]})}function je(n){return Array.isArray(n)?n.flatMap(t=>{const s=O(t),r=s?.kind,a=s?.identifier;return typeof r=="string"&&typeof a=="string"?[{kind:r,identifier:a}]:[]}):[]}function Ht(n){const t=O(n?.evidence_change);if(t&&!(!Array.isArray(t.dropped)||!Array.isArray(t.gained)))return{dropped:je(t.dropped),gained:je(t.gained)}}function P(n){return typeof n=="string"?n:void 0}function Jt(n){const t=O(n.current),s=O(n.proposal),r=O(t?.winner),a=O(t?.loser),m=Array.isArray(t?.duplicates)?t.duplicates.map(O):[],o=(m.length>0?m:a?[a]:[]).flatMap(c=>{const h=P(c?.name),g=c?.id;return h&&(typeof g=="string"||typeof g=="number")?[{key:String(g),name:h,slug:P(c?.slug),entityType:P(c?.entity_type),parentSlug:P(c?.parent_slug),parentEntityType:P(c?.parent_entity_type)}]:[]}),x=Array.isArray(s?.entity_ids)?s.entity_ids:[],p=Array.isArray(s?.names)?s.names.flatMap((c,h)=>{const g=x[h];return typeof c=="string"&&(typeof g=="string"||typeof g=="number")?[{key:String(g),name:c}]:[]}):[],f=P(s?.name),d=s?.entity_id,b=o.length>0?o:p.length>0?p:f&&(typeof d=="string"||typeof d=="number")?[{key:String(d),name:f}]:[];return{winnerName:P(r?.name)??P(s?.winner_name),winnerSlug:P(r?.slug),winnerEntityType:P(r?.entity_type),winnerParentSlug:P(r?.parent_slug),winnerParentEntityType:P(r?.parent_entity_type),losers:b,matchEvidence:qt(s),evidenceChange:Ht(s)}}function Vt(n){const t=n.entityType?W(n.entityType).toLowerCase():"entity";if(n.operation==="merge"){const s=n.merge?.losers??[];return s.length>1?`Merge ${s.length} duplicate ${t}s`:`Merge duplicate ${t}`}return`${W(n.operation)} ${t}`}function Wt(n,t){if(t.action_key!=="entity_change"&&t.tool!=="entity_change")return null;const s=t.action;if(s!=="create"&&s!=="delete"&&s!=="merge")return null;const r=n;return{operation:s,merge:s==="merge"?Jt(t):void 0,proposal:O(t.proposal),current:O(t.current),reason:typeof t.reason=="string"?t.reason:void 0,automationId:t.automation_id!=null?String(t.automation_id):void 0,automationName:typeof t.automation_name=="string"?t.automation_name:void 0,automationAgentId:typeof t.automation_agent_id=="string"?t.automation_agent_id:void 0,entityType:typeof t.entity_type=="string"?t.entity_type:void 0,entityName:(typeof t.entity_name=="string"?t.entity_name:void 0)??r.entity_name??void 0,entitySlug:typeof t.entity_slug=="string"?t.entity_slug:void 0,parentSlug:typeof t.parent_slug=="string"?t.parent_slug:void 0,parentEntityType:typeof t.parent_entity_type=="string"?t.parent_entity_type:void 0,attribution:typeof t.attribution=="string"?t.attribution:void 0,proposerRationale:typeof t.proposer_rationale=="string"?t.proposer_rationale:void 0,initiator:t.initiator&&typeof t.initiator=="object"?t.initiator:void 0}}function ue(n,t){return!n||!t.entityType||!t.entitySlug?null:ve(n,t.parentEntityType&&t.parentSlug?[{entity_type:t.parentEntityType,slug:t.parentSlug},{entity_type:t.entityType,slug:t.entitySlug}]:[{entity_type:t.entityType,slug:t.entitySlug}])}function Se({runId:n,details:t}){const{org:s}=Y(),a=_e(t.automationId,void 0,s?.id,{includeVersions:!1}).data?.automation,m=Ce(t.initiator,t.attribution,t.automationId),y=a?.automation_name??t.automationName??m,o=s?.slug;return e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Requested by"," ",o&&t.automationId?e.jsx(B,{to:"/$owner/automations/$automationId",params:{owner:o,automationId:t.automationId},search:{view:"definition",run_id:void 0},className:"font-medium text-foreground underline-offset-4 hover:underline",children:y}):e.jsx("span",{className:"font-medium text-foreground",children:y}),o&&n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:" · "}),e.jsxs(B,{to:"/$owner/events",params:{owner:o},search:{run_ids:String(n)},className:"font-medium text-foreground underline-offset-4 hover:underline",children:["Run #",n]})]})]})}function Re({details:n}){const{org:t}=Y(),s=ue(t?.slug,n);return n.entityName?e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Entity"}),e.jsx("div",{className:"mt-1 text-sm font-medium",children:s?e.jsx(B,{to:s,className:"underline-offset-4 hover:underline",children:n.entityName}):n.entityName})]}):null}function Ae({label:n,before:t,after:s}){return e.jsxs("div",{className:"rounded-md border border-border/70 overflow-hidden",children:[e.jsx("div",{className:"border-b border-border/70 px-3 py-2 text-xs font-medium",children:n}),e.jsxs("div",{className:"grid gap-px bg-border/70 sm:grid-cols-2",children:[e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Current"}),e.jsx("div",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:ye(t)})]}),e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Proposed"}),e.jsx("div",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:ye(s)})]})]})]})}function Kt({runId:n,details:t}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx(Se,{runId:n,details:t}),e.jsx(Re,{details:t}),Object.entries(t.fields).map(([s,r])=>e.jsx(Ae,{label:W(s),before:t.current[s],after:r},s)),t.reason&&e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Reasoning"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.reason})]})]})}function Qt({merge:n,status:t}){const{org:s}=Y(),r=ue(s?.slug,{entityType:n.winnerEntityType,entitySlug:n.winnerSlug,parentEntityType:n.winnerParentEntityType,parentSlug:n.winnerParentSlug}),a=n.losers.length,m=t==="rejected"||t==="failed",y=t==="completed";return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"rounded-lg border border-border/70 overflow-hidden",children:e.jsxs("div",{className:"grid gap-px bg-border/70 sm:grid-cols-2",children:[e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:m?"Would have kept":"Kept"}),e.jsx("div",{className:"text-sm font-medium leading-relaxed",children:n.winnerName?r?e.jsx(B,{to:r,className:"underline-offset-4 hover:underline",children:n.winnerName}):n.winnerName:e.jsx("span",{className:"text-muted-foreground",children:"Unknown"})})]}),e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:m?a>1?`Kept separate (${a})`:"Kept separate":y?a>1?`Merged away (${a})`:"Merged away":a>1?`To merge away (${a})`:"To merge away"}),e.jsx("div",{className:"space-y-0.5 text-sm leading-relaxed",children:a>0?n.losers.map(o=>{const x=ue(s?.slug,{entityType:o.entityType,entitySlug:o.slug,parentEntityType:o.parentEntityType,parentSlug:o.parentSlug}),p=y?"line-through decoration-muted-foreground/60":"";return e.jsx("div",{className:"break-words",children:x?e.jsx(B,{to:x,className:`${p} underline-offset-4 hover:underline`,children:o.name}):e.jsx("span",{className:p,children:o.name})},o.key)}):e.jsx("span",{className:"text-muted-foreground",children:"Unknown"})})]})]})}),n.evidenceChange&&e.jsxs("div",{className:n.evidenceChange.dropped.length>0?"rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2":"rounded-lg bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:n.evidenceChange.dropped.length>0?"What changed since you reviewed this":"Evidence re-checked"}),e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1",children:[n.evidenceChange.dropped.map(o=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"mr-1.5 font-medium text-amber-700 dark:text-amber-400",children:"No longer proven"}),W(o.kind),": ",o.identifier]},`dropped-${o.kind}:${o.identifier}`)),n.evidenceChange.gained.map(o=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"mr-1.5 font-medium text-emerald-700 dark:text-emerald-400",children:"Newly proven"}),W(o.kind),": ",o.identifier]},`gained-${o.kind}:${o.identifier}`)),n.evidenceChange.dropped.length===0&&n.evidenceChange.gained.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"The recorded match evidence did not change."})]})]}),n.matchEvidence.length>0&&e.jsxs("div",{className:"rounded-lg bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Match evidence"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:n.matchEvidence.map(o=>e.jsxs(J,{variant:"outline",className:"text-[10px] font-normal",children:[W(o.kind),": ",o.identifier]},`${o.kind}:${o.identifier}`))})]})]})}function Gt({runId:n,details:t,status:s}){const r=t.operation==="merge";return e.jsxs("div",{className:"space-y-3",children:[e.jsx(Se,{runId:n,details:t}),r&&t.merge?e.jsx(Qt,{merge:t.merge,status:s}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{details:t}),e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Change"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.operation==="create"?"Create a new entity after approval.":"Delete this entity after approval."})]})]}),!r&&t.proposal&&e.jsxs("div",{className:"rounded-md border border-border/70 p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Proposal"}),e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-xs leading-relaxed",children:JSON.stringify(t.proposal,null,2)})]}),t.proposerRationale&&e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:t.attribution==="agent"?"The agent's reasoning":"The Automation's reasoning"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.proposerRationale})]}),t.reason&&e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:r?"Why this needs approval":"Reasoning"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.reason})]})]})}function Yt({summary:n}){return e.jsxs("div",{className:"space-y-2 rounded-md border border-border/70 bg-muted/30 p-3 text-sm",children:[n.chips.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.chips.map(t=>e.jsx(J,{variant:"outline",className:"text-[10px] font-normal",children:t},t))}),n.message&&e.jsx("p",{className:"leading-relaxed text-foreground",children:n.message}),n.reason&&e.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Why"}),e.jsx("div",{className:"mt-0.5 leading-relaxed",children:n.reason})]}),n.body&&e.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:n.kind==="verify"?"Expected comment":"Draft"}),e.jsx("div",{className:"mt-0.5 whitespace-pre-wrap leading-relaxed",children:n.body})]}),n.matchPreview&&e.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[e.jsxs("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:["Matched comment",n.matchAuthor?` · ${n.matchAuthor}`:""]}),e.jsx("div",{className:"mt-0.5 whitespace-pre-wrap leading-relaxed text-muted-foreground",children:n.matchPreview})]}),n.postUrl&&e.jsxs("a",{href:n.postUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Open post",e.jsx(Ne,{className:"h-3 w-3"})]})]})}function Xt({content:n}){const t=n.metadata||{},s=n.run_id??void 0,r=Ut(n,t),a=Wt(n,t),m=(r?Bt(r):a?Vt(a):void 0)||t.operation_name||t.action_name||(n.title?Lt(n.title):void 0)||"Action",y=t.connection_name,o=t.operation_key||t.action_key||null,x=n.interaction_input_schema||t.input_schema||null,p=N.useMemo(()=>n.interaction_input||t.action_input||t.operation_input||Tt,[n.interaction_input,t.action_input,t.operation_input]),f=n.interaction_output||t.action_output||void 0,d=At(p,f??null,o),b=n.interaction_error||t.error_message||void 0,c=Mt(n.interaction_status,t.status),h=t.reviewed_by_name||t.reviewed_by_id||void 0,g=t.reject_reason||void 0,R=t.initiator,D=Ge(),v=Ye(),A=Xe(n.id,Ze(x,p),x),{values:F,setValues:U}=A,[I,q]=N.useState(null),[_,M]=N.useState(!1),[E,l]=N.useState(""),S=c==="pending_approval",L=typeof t.source_run_id=="number";return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(et,{className:"h-4 w-4 text-yellow-500"}),e.jsx("span",{className:"font-medium",children:m}),y&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["on ",y]}),c==="confirmed"&&e.jsxs(J,{variant:"outline",className:"text-blue-700 border-blue-300 bg-blue-50 dark:bg-blue-950/30 text-[10px]",children:[e.jsx(K,{size:"xs",className:"mr-1"}),"Executing"]}),c==="completed"&&e.jsx(J,{variant:"outline",className:"text-green-700 border-green-300 bg-green-50 dark:bg-green-950/30 text-[10px]",children:"Completed"}),c==="failed"&&e.jsx(J,{variant:"outline",className:"text-red-700 border-red-300 bg-red-50 dark:bg-red-950/30 text-[10px]",children:"Failed"}),c==="rejected"&&e.jsx(J,{variant:"outline",className:"text-muted-foreground text-[10px]",children:"Rejected"})]}),!r&&!a&&(n.author_name||h)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-xs text-muted-foreground",children:[n.author_name&&e.jsxs("span",{children:["Requested by"," ",e.jsx(zt,{initiator:R,clientName:n.author_name,fallback:n.author_name})]}),n.author_name&&h&&e.jsx("span",{children:"·"}),h&&e.jsxs("span",{children:[c==="rejected"?"Rejected":"Approved"," by"," ",e.jsx("span",{className:"font-medium text-foreground",children:h})]})]}),r&&e.jsx(Kt,{runId:s,details:r}),!r&&a&&e.jsx(Gt,{runId:s,details:a,status:c}),c==="rejected"&&g&&e.jsxs("div",{className:"rounded-md bg-muted/50 p-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Reason:"})," ",g]}),d&&e.jsx(Yt,{summary:d}),(S?A.revision:x)&&(S||Object.keys(p).length>0)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:d?"Full input":"Input"}),S?e.jsxs(e.Fragment,{children:[e.jsx(tt,{visible:A.hasConflict,onReload:A.reset}),e.jsx(nt,{schema:A.revision,values:F,onValuesChange:U,fieldIdPrefix:`action-${n.id}-`},`action-${n.id}`)]}):d?e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"Raw input"}),e.jsx("pre",{className:"mt-1 bg-muted/50 rounded p-2 font-mono overflow-auto max-h-32",children:JSON.stringify(p,null,2)})]}):e.jsx("pre",{className:"text-xs bg-muted/50 rounded p-2 font-mono overflow-auto max-h-32",children:JSON.stringify(p,null,2)})]}),c==="completed"&&f&&Object.keys(f).length>0&&!d&&e.jsxs("div",{className:"rounded-md bg-green-50 dark:bg-green-950/30 p-3 text-sm space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-green-700 dark:text-green-400 font-medium",children:[e.jsx(st,{className:"h-3.5 w-3.5"}),"Output"]}),e.jsx("pre",{className:"text-xs text-green-800 dark:text-green-300 font-mono whitespace-pre-wrap",children:JSON.stringify(f,null,2)})]}),c==="completed"&&f&&Object.keys(f).length>0&&d&&e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"Raw output"}),e.jsx("pre",{className:"mt-1 rounded bg-green-50 p-2 font-mono dark:bg-green-950/30 overflow-auto max-h-32",children:JSON.stringify(f,null,2)})]}),c==="failed"&&b&&e.jsxs("div",{className:"rounded-md bg-red-50 dark:bg-red-950/30 p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-red-700 dark:text-red-400 font-medium",children:[e.jsx(rt,{className:"h-3.5 w-3.5"}),"Error"]}),e.jsx("p",{className:"text-xs text-red-800 dark:text-red-300 font-mono mt-1",children:b})]}),I==="confirmed"&&e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-blue-700 dark:text-blue-400 font-medium",children:[e.jsx(K,{size:"md"}),"Confirmed — executing..."]}),e.jsx("p",{className:"text-xs text-blue-800 dark:text-blue-300 mt-1",children:"The worker will execute this action shortly. Redirecting..."})]}),I==="rejected"&&e.jsx(J,{variant:"outline",className:"text-muted-foreground text-xs",children:"Rejected — redirecting..."}),S&&!I&&L&&e.jsx("div",{className:"pt-1 text-xs text-muted-foreground",children:"Part of an Automation run — approve or reject it from the run's change-set above."}),S&&s&&!I&&!L&&e.jsx("div",{className:"flex items-center gap-2 pt-1",children:_?e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("input",{type:"text",placeholder:"Reason (optional)",value:E,onChange:$=>l($.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),e.jsxs(k,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>v.mutate({run_id:s,reason:E||void 0},{onSuccess:()=>{q("rejected")}}),disabled:v.isPending,children:[v.isPending&&e.jsx(K,{size:"sm",className:"mr-1"}),"Confirm Reject"]}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{M(!1),l("")},children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(k,{size:"sm",className:"h-7 text-xs",onClick:()=>D.mutate({run_id:s,input:at(F)},{onSuccess:()=>{q("confirmed")}}),disabled:!A.canSubmit||D.isPending||v.isPending,children:[D.isPending?e.jsx(K,{size:"sm",className:"mr-1"}):e.jsx(it,{className:"h-3 w-3 mr-1"}),"Confirm"]}),e.jsxs(k,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>M(!0),disabled:D.isPending||v.isPending,children:[e.jsx(ot,{className:"h-3 w-3 mr-1"}),"Reject"]})]})})]})}function Zt({content:n}){const t=n.metadata||{},s=t.kind,r=n.run_id??null,a=typeof t.automation_id=="number"?t.automation_id:null,{org:m}=Y(),y=m?.slug,p=_e(a!=null?String(a):void 0,void 0,m?.id,{includeVersions:!1}).data?.automation?.automation_name??(a!=null?`Automation ${a}`:"An Automation"),f=Ke(),d=Qe(),[b,c]=N.useState(!1),[h,g]=N.useState(""),[R,D]=N.useState(null);if(s==="automation_batch_reject"){const l=t.reason||void 0;return e.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Proposals rejected"}),l&&e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:l}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Ask the agent to revise its proposals with this feedback."})]})}const v=Array.isArray(t.changes)?t.changes:[],A=typeof t.created_count=="number"?t.created_count:v.filter(l=>l.kind==="created").length,F=typeof t.updated_count=="number"?t.updated_count:v.filter(l=>l.kind==="updated").length,U=typeof t.denied_count=="number"?t.denied_count:v.filter(l=>l.kind==="denied").length,I=v.filter(l=>l.kind==="denied"),q=v.filter(l=>l.kind==="updated"&&Object.keys(l.applied||{}).length>0),_=typeof t.pending_proposal_count=="number"?t.pending_proposal_count:null,M=_==null||_>0,E=M?"proposed":"applied";return e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1",children:[e.jsxs("div",{className:"text-sm font-medium",children:[E==="proposed"?"Proposed":"Applied"," ",A," ","new + ",F," updated",U>0&&e.jsxs(e.Fragment,{children:[" + ",U," denied"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[y&&a!=null?e.jsx(B,{to:"/$owner/automations/$automationId",params:{owner:y,automationId:String(a)},search:{view:"definition",run_id:void 0},className:"font-medium text-foreground underline-offset-4 hover:underline",children:p}):e.jsx("span",{className:"font-medium text-foreground",children:p}),r!=null&&e.jsxs("span",{children:[" · run #",r]}),_!=null&&_>0&&e.jsxs("span",{children:[" · ",_," pending"]})]})]}),q.length>0&&e.jsx("div",{className:"mt-3 space-y-2",children:q.map(l=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:l.name}),Object.entries(l.applied).map(([S,L])=>e.jsx(Ae,{label:S,before:L.old,after:L.new},S))]},l.entityId))}),I.length>0&&e.jsx("div",{className:"mt-3 space-y-1.5",children:I.map(l=>e.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-2.5 py-2",children:[e.jsxs("div",{className:"text-xs font-medium",children:[l.name," — not written"]}),l.denied&&e.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground",children:[l.denied.reason,e.jsxs("span",{className:"ml-1 opacity-70",children:["(refused by"," ",l.denied.source==="rule"?"a write rule":"org policy",")"]})]})]},`denied-${l.entityId}-${l.name}`))}),r!=null&&R==null&&M&&e.jsx("div",{className:"mt-3 border-t border-border/70 pt-3",children:b?e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("input",{type:"text",placeholder:"What should the agent change?",value:h,onChange:l=>g(l.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),e.jsxs(k,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>d.mutate({run_id:r,reason:h||void 0},{onSuccess:()=>D("rejected")}),disabled:d.isPending,children:[d.isPending&&e.jsx(K,{size:"sm",className:"mr-1"}),"Reject all"]}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{c(!1),g("")},children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(k,{size:"sm",className:"h-7 text-xs",onClick:()=>f.mutate({run_id:r},{onSuccess:()=>D("approved")}),disabled:f.isPending||d.isPending,children:[f.isPending&&e.jsx(K,{size:"sm",className:"mr-1"}),"Approve all proposals"]}),e.jsx(k,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>c(!0),disabled:f.isPending||d.isPending,children:"Reject with feedback"})]})}),R==="approved"&&e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals approved."}),R==="rejected"&&e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"Proposals rejected — ask the agent to revise them."}),r!=null&&R==null&&!M&&e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals reviewed."})]})}function ie({ownerSlug:n,content:t,isReply:s,showParentContext:r,connectorDefinitions:a}){const[m,y]=N.useState(!1),[o,x]=N.useState(!1),p=De(),{currentOwner:f}=Fe(),d=n??f,b=d==="me"?null:d,c=N.useCallback(async i=>{if(!b){le.error("Open this event inside a workspace to interact with it.");return}try{await St(b,Number(t.id),i,crypto.randomUUID()),le.success("Recorded")}catch(u){le.error(u instanceof Error?u.message:"Could not record that interaction.")}},[t.id,b]),h=t.payload_data??{},g=t.semantic_type==="audit"&&t.origin_type==="tool_invocation",R=g&&(h.request!==void 0||h.request_status==="too_large"),v=g&&h.request_status==="complete"&&d?`/${d}/events?content_ids=${t.id}`:!d||d==="me"?null:t.run_id!=null?`/${d}/events?run_ids=${t.run_id}`:null,A=!!(p&&v&&Me(v)),F=()=>{!p||!v||p.open({href:v,title:t.title??(t.run_id!=null?`Run #${t.run_id}`:"Event"),runId:t.run_id??void 0})},U=i=>{const u=i.target;if(!(u instanceof Element))return!1;const j=u.closest('a,button,input,select,textarea,[role="button"],[role="radio"]');return j!==null&&j!==i.currentTarget},I=i=>{U(i)||F()},q=i=>{i.key!=="Enter"&&i.key!==" "||U(i)||(i.preventDefault(),F())},_=t.metadata||{};if(t.semantic_type==="change_set")return e.jsx(Zt,{content:t});if(t.interaction_type==="approval"||t.semantic_type==="operation"||_.status!=null||_.action_key!=null)return e.jsx(Xt,{content:t});const E=Number.isFinite(t.score)?Math.round(t.score):"-",l=t.payload_type||"text",S=t.text_content||"",L=(l==="text"||l==="markdown")&&S.length>500,$=L&&!m?`${S.slice(0,500)}...`:S,Q=_.thumbnail_url||_.thumbnail,H=_.media_url,G=Ot(_),ne=Object.entries(t.classifications||{}).flatMap(([i,u])=>{const j=Ft(u);return j.values.map(T=>({slug:i,value:T,isManual:j.isManual}))}),X=(()=>{const i=t.metadata??{},u=t.platform||(typeof i.platform=="string"?i.platform:null),j=t.connection_id!=null?t.connection_id:i.source_connection_id!=null?Number(i.source_connection_id):null;return{...t,platform:u,connection_id:j!=null&&Number.isFinite(j)?j:null}})();return e.jsxs("div",{className:We(s?"border-l-2 border-l-muted pl-4":"",A&&"-mx-2 cursor-pointer rounded-lg px-2 py-1 transition-colors hover:bg-accent/40"),...A?{role:"button",tabIndex:0,onClick:I,onKeyDown:q}:{},children:[r&&t.parent_context&&e.jsxs("div",{className:"mb-3 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Replying to:"}),e.jsx("div",{className:"font-medium",children:t.parent_context.author_name}),e.jsx("div",{className:"text-muted-foreground line-clamp-2",children:t.parent_context.text_content})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[t.title&&e.jsx("h4",{className:"font-medium line-clamp-2 mb-1",children:t.title}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:(()=>{const i=$t(t),u=!!t.platform&&i!==te(t.platform);return e.jsxs(e.Fragment,{children:[i&&e.jsx("span",{className:"font-medium",children:i}),u&&e.jsxs(e.Fragment,{children:[i&&e.jsx("span",{children:"·"}),e.jsx(J,{variant:"outline",className:"text-xs",children:t.platform})]})]})})()}),d?e.jsx(Le,{owner:d,source:X,connectorDefinitions:a,className:"mt-0.5 text-xs"}):null]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.score_breakdown?e.jsxs(ze,{children:[e.jsx(Be,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 px-2",children:e.jsx("span",{className:"font-medium",children:E})})}),e.jsx(Ue,{className:"w-64",align:"end",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium",children:"Score Breakdown"}),e.jsx(It,{breakdown:t.score_breakdown})]})})]}):e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 px-2",disabled:!0,children:e.jsx("span",{className:"font-medium",children:E})}),t.source_url&&e.jsxs(qe,{children:[e.jsx(He,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7",asChild:!0,children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})})}),e.jsx(Je,{children:"View original"})]})]})]}),t.rating&&e.jsx("div",{className:"flex items-center gap-1 mb-2",children:[1,2,3,4,5].map(i=>e.jsx(be,{className:`h-4 w-4 ${i<=Number(t.rating)?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},i))}),Q&&e.jsx("a",{href:H||t.source_url||"#",target:"_blank",rel:"noopener noreferrer",className:"block mb-2",children:e.jsx("img",{src:Q,alt:"",className:`rounded-md object-cover ${l==="media"?"max-h-96 w-full":"max-h-48"}`,loading:"lazy"})}),t.excerpt&&e.jsx("div",{className:"text-sm italic text-muted-foreground border-l-2 border-primary/40 pl-2 mb-1",children:t.excerpt}),(()=>{switch(l){case"markdown":if($)return e.jsx("div",{className:"max-w-none text-sm space-y-2",children:e.jsx(Ve,{text:$})});break;case"json_template":{const i=t.payload_template;if(i?.root)return e.jsx(_t,{template:{root:i.root},data:t.payload_data||{},onAction:c,interactions:i.interactions});if($)return e.jsx("div",{className:"text-sm whitespace-pre-wrap",children:$});break}case"media":return e.jsxs("div",{className:"space-y-3",children:[!Q&&H&&e.jsx("a",{href:H,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline truncate block",children:H}),$&&e.jsx("div",{className:"text-sm whitespace-pre-wrap text-muted-foreground",children:$})]});case"empty":return e.jsxs("div",{className:"space-y-3",children:[R&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(k,{variant:"outline",size:"sm","aria-expanded":o,onClick:()=>x(i=>!i),children:[o?e.jsx(ae,{className:"h-3.5 w-3.5"}):e.jsx(oe,{className:"h-3.5 w-3.5"}),"Request"]}),o&&(h.request_status==="too_large"?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["The request was too large to retain",typeof h.request_bytes=="number"?` (${h.request_bytes.toLocaleString()} bytes).`:"."]}):e.jsx(Pt,{value:h.request}))]}),G.length>0?e.jsx("dl",{className:"grid gap-x-3 gap-y-2 text-sm sm:grid-cols-[minmax(140px,180px)_1fr]",children:G.map(([i,u])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:te(i)}),e.jsx("dd",{className:"min-w-0 break-words font-mono text-xs sm:text-sm",children:fe(u)})]},i))}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No content"})]});default:if($)return e.jsx("div",{className:"text-sm whitespace-pre-wrap",children:$});break}return e.jsxs("div",{className:"space-y-3",children:[H&&!Q&&e.jsx("a",{href:H,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground truncate block",children:H}),G.length>0&&e.jsx("dl",{className:"grid gap-x-3 gap-y-2 text-sm sm:grid-cols-[minmax(140px,180px)_1fr]",children:G.map(([i,u])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:te(i)}),e.jsx("dd",{className:"min-w-0 break-words font-mono text-xs sm:text-sm",children:fe(u)})]},i))})]})})(),L&&e.jsx(k,{variant:"link",size:"sm",className:"px-0 h-6 mt-1",onClick:()=>y(!m),children:m?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3 w-3 mr-1"})," Show less"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3 w-3 mr-1"})," Show more"]})}),ne.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:ne.map(i=>e.jsx(Dt,{slug:i.slug,value:i.value||"",isManual:i.isManual},i.slug))})]})}function en({occurredAt:n,isLast:t,children:s}){return e.jsxs("div",{className:"relative flex gap-4 pb-6",children:[e.jsxs("div",{className:"relative flex w-2.5 shrink-0 justify-center",children:[!t&&e.jsx("div",{className:"absolute top-1 bottom-[-1.5rem] left-1/2 w-px -translate-x-1/2 bg-border","aria-hidden":!0}),e.jsx("div",{className:"relative z-10 mt-1 h-2.5 w-2.5 rounded-full border-2 border-background bg-muted-foreground/60"})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[n&&e.jsx("time",{dateTime:new Date(n).toISOString(),title:ke(n),className:"mb-1 block text-xs leading-none text-muted-foreground",children:we(n)}),s]})]})}function rn({organizationId:n,ownerSlug:t,entityId:s,filters:r,showEntityLinks:a=!1,emptyState:m,dense:y=!1}){const{isAuthenticated:o,isReady:x}=dt(),{isMember:p,isLoading:f}=Y(),d=t==="me",b=!d&&x&&o&&p,c=!d&&x&&(!o||!f&&!p),{data:h=[]}=ct(x&&b?n:null),{data:g=[]}=ut(c?t:null),R=b?h:g,D=mt(x&&b?n:null,s,r,t),v=pt(c?t:null,s,r),A=c?v:D,{data:F,isLoading:U,error:I,fetchNextPage:q,hasNextPage:_,isFetchingNextPage:M}=A,E=N.useMemo(()=>F?.pages.flatMap(i=>i.content)??[],[F]),l=wt({onIntersect:()=>q(),enabled:!!_&&!M}),S=N.useMemo(()=>{const i=xt(E),u=i.map(V=>V.head),j=new Map(i.map(V=>[V.head.id,V])),T=ht(u);return Array.from(T.entries()).map(([V,Z])=>{const se=Z.root||Z.replies[0],ee=se?j.get(se.id):void 0;return{rootId:V,group:Z,history:ee?.history??[],runId:ee?.runId??null}})},[E]),[L,$]=N.useState(new Set),[Q,H]=N.useState(new Set),[G,ne]=N.useState(new Set),X=(i,u)=>i(j=>{const T=new Set(j);return T.has(u)?T.delete(u):T.add(u),T});return U&&E.length===0?e.jsx("div",{className:"space-y-4",children:["s1","s2","s3"].map(i=>e.jsx(gt,{className:"h-32 rounded-lg"},i))}):I?e.jsx(ft,{label:"events"}):E.length===0?m??e.jsx(yt,{icon:jt,title:"Nothing here yet",description:"No events match this view."}):e.jsxs("div",{className:y?"":"pt-1",children:[S.map(({rootId:i,group:u,history:j,runId:T},V,Z)=>{const se=u.replies.length>0,ee=L.has(i),me=G.has(i),pe=Q.has(i),Te=u.replies.filter(C=>C.depth<=3),re=u.replies.filter(C=>C.depth>3),Ee=!u.root&&u.replies.length>0,z=u.root||u.replies[0];return z?e.jsxs(en,{occurredAt:z.occurred_at,isLast:V===Z.length-1,children:[a&&t&&z.entity_name&&z.entity_type&&z.entity_slug&&e.jsx("div",{className:"mb-2",children:e.jsx(Ct,{ownerSlug:t,entity:{entityName:z.entity_name,entityType:z.entity_type,entitySlug:z.entity_slug}})}),e.jsx(ie,{ownerSlug:t,content:z,showParentContext:Ee&&!!z.parent_context,connectorDefinitions:R}),j.length>0&&e.jsxs(xe,{open:pe,children:[e.jsx(he,{asChild:!0,children:e.jsxs(k,{variant:"ghost",size:"sm",className:"mt-1 h-7 gap-1 text-xs text-muted-foreground",onClick:()=>X(H,i),children:[e.jsx(vt,{className:"h-3.5 w-3.5"}),pe?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Hide ",T!=null?`run #${T} `:"","history"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),T!=null?`Run #${T} · ${j.length===1?"1 earlier step":`${j.length} earlier steps`}`:j.length===1?"1 earlier state":`${j.length} earlier states`]})]})}),e.jsx(ge,{className:"mt-2 space-y-3 border-l-2 border-l-muted pl-4",children:j.map(C=>e.jsxs("div",{children:[e.jsx("time",{dateTime:new Date(C.occurred_at).toISOString(),title:ke(C.occurred_at),className:"mb-1 block text-xs text-muted-foreground",children:we(C.occurred_at)}),e.jsx(ie,{ownerSlug:t,content:C,connectorDefinitions:R})]},C.id))})]}),se&&e.jsxs(xe,{open:ee,children:[e.jsx(he,{asChild:!0,children:e.jsxs(k,{variant:"ghost",size:"sm",className:"mt-2 ml-6 gap-1",onClick:()=>X($,i),children:[e.jsx(Nt,{className:"h-3.5 w-3.5"}),ee?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Hide ",u.replies.length," replies"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),"Show ",u.replies.length," replies"]})]})}),e.jsxs(ge,{className:"space-y-2 mt-2",children:[Te.map(C=>e.jsx(ie,{ownerSlug:t,content:C,isReply:!0,connectorDefinitions:R},C.id)),re.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"ghost",size:"sm",className:"ml-12",onClick:()=>X(ne,i),children:me?e.jsxs(e.Fragment,{children:["Hide ",re.length," nested replies"]}):e.jsxs(e.Fragment,{children:["Show ",re.length," nested replies"]})}),me&&re.map(C=>e.jsx(ie,{ownerSlug:t,content:C,isReply:!0,connectorDefinitions:R},C.id))]})]})]})]},i):null}),e.jsx("div",{ref:l,className:"h-1"}),M&&e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(K,{size:"xl",className:"text-muted-foreground"})})]})}export{rn as E};
|
|
1
|
+
import{r as N,j as e,L as B,dU as $e,cx as ve,an as Pe,ag as Oe,eJ as Ie,J as De,a1 as Fe,aD as le,t as Me,af as J,z as Le,ci as ze,cj as Be,B as k,ck as Ue,dl as qe,dm as He,E as Ne,dn as Je,eK as be,eL as ae,cP as oe,eM as Ve,aj as We,bM as Y,G as _e,eN as Ke,eO as Qe,s as K,eP as Ge,eQ as Ye,k as Xe,eR as Ze,bE as et,F as tt,en as nt,cs as st,eS as rt,aO as it,eT as at,X as ot,bP as lt,Y as dt,dI as ct,dJ as ut,dQ as mt,dR as pt,eU as xt,eV as ht,S as gt,c8 as ft,bm as yt,I as jt,dz as xe,dB as he,aW as vt,dC as ge,x as we,eW as ke,eX as Nt}from"./index-BUr8321-.js";import{u as bt}from"./clients-DhYr4lyL.js";import{J as _t}from"./renderer-CHNejd95.js";function wt({onIntersect:n,enabled:t,rootMargin:s="400px"}){const r=N.useRef(null),a=N.useRef(n);return a.current=n,N.useEffect(()=>{const m=r.current;if(!m||!t)return;const y=new IntersectionObserver(o=>{o[0]?.isIntersecting&&a.current()},{rootMargin:s});return y.observe(m),()=>y.disconnect()},[t,s]),r}function kt(n,t){const s=t.parentEntityType&&t.parentEntitySlug?[{entity_type:t.parentEntityType,slug:t.parentEntitySlug},{entity_type:t.entityType,slug:t.entitySlug}]:[{entity_type:t.entityType,slug:t.entitySlug}];return ve(n,s)}function Ct({ownerSlug:n,entity:t,className:s}){const r=kt(n,t);return e.jsxs(B,{to:r,className:`flex items-center gap-1 text-primary hover:underline group ${s??""}`,children:[e.jsx("span",{className:"font-medium",children:t.entityName}),e.jsx($e,{className:"h-3 w-3 opacity-0 group-hover:opacity-100 transition-opacity"})]})}async function St(n,t,s,r){const a=await Pe(`${Oe}/api/${encodeURIComponent(n)}/events/${t}/actions/${encodeURIComponent(s.action)}`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify({value:s.value,interaction_id:r})});return await Ie(a,"Could not record interaction"),a.json()}function w(n){if(typeof n!="string")return;const t=n.trim();return t.length>0?t:void 0}function de(n){return typeof n=="boolean"?n:void 0}function Rt(n,t,s){const r=(s??"").toLowerCase();return!!(r==="prepare_comment"||r==="verify_staged_comment"||r.includes("prepare_")||r.includes("verify_staged")||t?.prepared===!0||typeof t?.verified=="boolean"||w(t?.reason_preview)&&w(t?.message)||w(n?.body)&&(w(n?.post_url)||w(n?.activity_id)))}function At(n,t,s){if(!Rt(n,t,s))return null;const r=(s??"").toLowerCase(),a=w(t?.body)??w(n?.body),m=w(t?.reason_preview)??w(n?.reason),y=w(t?.post_url)??w(n?.post_url)??(w(n?.activity_id)?`https://www.linkedin.com/feed/update/urn:li:activity:${w(n?.activity_id)}`:void 0),o=de(t?.prepared),x=de(t?.verified),p=de(t?.banner_shown),f=w(t?.message),d=t?.match&&typeof t.match=="object"?t.match:null,b=w(d?.text_preview),c=w(d?.author);let h="generic";r==="verify_staged_comment"||r.includes("verify")||typeof x=="boolean"?h="verify":(r==="prepare_comment"||r.includes("prepare")||o===!0||a&&y)&&(h="prepare");const g=[];return o===!0&&g.push("Staged — not posted"),o===!1&&g.push("Not staged"),x===!0&&g.push("Verified posted"),x===!1&&g.push("Not verified as posted"),p===!0&&g.push("In-page banner"),p===!1&&g.push("No banner"),{kind:h,message:f,reason:m,body:a,postUrl:y,prepared:o,bannerShown:p,verified:x,matchPreview:b,matchAuthor:c,chips:g}}const Tt={};function te(n){return n.replace(/_/g," ").replace(/\s+/g," ").trim().replace(/^./,t=>t.toUpperCase())}const Et={notification:"Notification",tool_invocation:"Action",deployment:"Deployment",config_change:"Config change",message:"Message",msg:"Note",summary:"Summary"};function $t(n){return n.author_name?n.author_name:n.platform?te(n.platform):n.origin_type?Et[n.origin_type]??te(n.origin_type):null}function fe(n){return n==null?"":typeof n=="string"?n:typeof n=="number"||typeof n=="boolean"||typeof n=="bigint"?String(n):Array.isArray(n)?n.length===0?"":n.every(t=>typeof t!="object")?n.map(t=>String(t)).join(", "):e.jsx("pre",{className:"overflow-x-auto rounded bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap",children:JSON.stringify(n,null,2)}):e.jsx("pre",{className:"overflow-x-auto rounded bg-muted/40 p-2 text-[11px] leading-relaxed whitespace-pre-wrap",children:JSON.stringify(n,null,2)})}const ce=1e5;function Pt({value:n}){const t=JSON.stringify(n,null,2)??"null",s=t.length>ce;return e.jsxs(e.Fragment,{children:[e.jsx("pre",{className:"max-h-80 overflow-auto whitespace-pre-wrap break-words rounded-md border bg-muted/40 p-3 font-mono text-xs",children:s?t.slice(0,ce):t}),s&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Showing the first ",ce.toLocaleString()," of"," ",t.length.toLocaleString()," characters."]})]})}function Ot(n){return Object.entries(n).filter(([,t])=>t==null?!1:typeof t=="string"?t.trim().length>0:Array.isArray(t)?t.length>0:typeof t=="object"?Object.keys(t).length>0:!0).sort(([t],[s])=>t.localeCompare(s))}function It({breakdown:n}){if(!n)return null;const t=[{label:"Engagement",value:n.engagement,max:100},{label:"Criticality",value:n.criticality,max:100},{label:"Depth",value:n.depth,max:100},{label:"Authority",value:n.authority,max:100},{label:"Recency",value:n.recency,max:100},{label:"Quality",value:n.quality,max:100}];return e.jsx("div",{className:"space-y-2 text-sm",children:t.map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-20 text-muted-foreground",children:s.label}),e.jsx("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-primary",style:{width:`${s.value/s.max*100}%`}})}),e.jsx("span",{className:"w-8 text-right",children:s.value})]},s.label))})}function Dt({slug:n,value:t,isManual:s}){return e.jsxs(J,{variant:"secondary",className:"text-xs",children:[n,": ",t,s&&e.jsx(be,{className:"ml-1 h-2.5 w-2.5 fill-current"})]})}function Ft(n){if(n&&typeof n=="object"){const t=n;if(Array.isArray(t.values))return{values:t.values.map(s=>String(s)).filter(s=>s.length>0),isManual:t.is_manual===!0};if(t.value!==void 0&&t.value!==null)return{values:[String(t.value)],isManual:t.is_manual===!0};if(typeof t.values=="string"&&t.values.length>0)return{values:[t.values],isManual:t.is_manual===!0}}return typeof n=="string"||typeof n=="number"||typeof n=="boolean"||typeof n=="bigint"?{values:[String(n)],isManual:!1}:{values:[],isManual:!1}}function Mt(n,t){if(n)switch(n){case"pending":return"pending_approval";case"approved":return"confirmed";case"rejected":return"rejected";case"completed":return"completed";case"failed":return"failed";default:return n}return t||"pending_approval"}function O(n){return!n||typeof n!="object"||Array.isArray(n)?null:n}function ye(n){return n==null||n===""?"Not set":typeof n=="string"?n:JSON.stringify(n,null,2)}function Lt(n){return n.replace(/\s+[—-]\s+pending approval$/i,"")}function W(n){return n.replace(/^\$/,"").replace(/[_-]/g," ").replace(/\s+/g," ").trim().replace(/^./,t=>t.toUpperCase())}function Ce(n,t,s){return n?.kind==="agent_session"&&n.agent_id?n.client_id?`${n.agent_id} via ${n.client_id}`:n.agent_id:n?.kind==="user"?"a person":t==="agent"?"an agent":s?`Automation ${s}`:"an Automation"}function zt({initiator:n,clientName:t,fallback:s}){const{org:r}=Y(),a=r?.slug,m=n?.client_id??t,o=bt(void 0,{enabled:!!(a&&m)}).data?.find(d=>d.id===m)?.title,x=n&&n.kind!=="user"?Ce(n,void 0,n.automation_id===void 0?void 0:String(n.automation_id)):s,p="font-medium text-foreground",f=`${p} underline-offset-4 hover:underline`;return a&&n?.kind==="automation"&&n.automation_id?e.jsx(B,{to:"/$owner/automations/$automationId",params:{owner:a,automationId:String(n.automation_id)},search:{view:"definition",run_id:void 0},className:f,children:x}):a&&n?.kind==="agent_session"&&n.agent_id?e.jsx(B,{to:"/$owner/agents/$agentId",params:{owner:a,agentId:String(n.agent_id)},className:f,children:x}):a&&m?e.jsxs(B,{to:"/$owner/agents/connected/$clientId",params:{owner:a,clientId:m},className:`${f} inline-flex items-center gap-1 align-middle`,children:[e.jsx(lt,{name:o??t??m}),o??x]}):e.jsx("span",{className:p,children:x})}function Bt(n){const t=Object.keys(n.fields),s=t.map(W).join(", ")||"field",r=t.length===1?"field":"fields";return`Update ${n.entityType?W(n.entityType).toLowerCase():"entity"} ${r}: ${s}`}function Ut(n,t){const s=O(t.fields);if(!s||Object.keys(s).length===0||t.action_key!=="entity_field_change"&&t.tool!=="entity_field_change")return null;const r=O(t.current)??{},a=n;return{fields:s,current:r,reason:typeof t.reason=="string"?t.reason:void 0,automationId:t.automation_id!=null?String(t.automation_id):void 0,automationName:typeof t.automation_name=="string"?t.automation_name:void 0,automationAgentId:typeof t.automation_agent_id=="string"?t.automation_agent_id:void 0,entityType:typeof t.entity_type=="string"?t.entity_type:void 0,entityName:(typeof t.entity_name=="string"?t.entity_name:void 0)??a.entity_name??void 0,entitySlug:typeof t.entity_slug=="string"?t.entity_slug:void 0,parentSlug:typeof t.parent_slug=="string"?t.parent_slug:void 0,parentEntityType:typeof t.parent_entity_type=="string"?t.parent_entity_type:void 0,attribution:typeof t.attribution=="string"?t.attribution:void 0,initiator:t.initiator&&typeof t.initiator=="object"?t.initiator:void 0}}function qt(n){return!n||!Array.isArray(n.evidence)?[]:n.evidence.flatMap(t=>{const s=O(t),r=s?.kind,a=s?.identifier;return typeof r=="string"&&typeof a=="string"?[{kind:r,identifier:a}]:[]})}function je(n){return Array.isArray(n)?n.flatMap(t=>{const s=O(t),r=s?.kind,a=s?.identifier;return typeof r=="string"&&typeof a=="string"?[{kind:r,identifier:a}]:[]}):[]}function Ht(n){const t=O(n?.evidence_change);if(t&&!(!Array.isArray(t.dropped)||!Array.isArray(t.gained)))return{dropped:je(t.dropped),gained:je(t.gained)}}function P(n){return typeof n=="string"?n:void 0}function Jt(n){const t=O(n.current),s=O(n.proposal),r=O(t?.winner),a=O(t?.loser),m=Array.isArray(t?.duplicates)?t.duplicates.map(O):[],o=(m.length>0?m:a?[a]:[]).flatMap(c=>{const h=P(c?.name),g=c?.id;return h&&(typeof g=="string"||typeof g=="number")?[{key:String(g),name:h,slug:P(c?.slug),entityType:P(c?.entity_type),parentSlug:P(c?.parent_slug),parentEntityType:P(c?.parent_entity_type)}]:[]}),x=Array.isArray(s?.entity_ids)?s.entity_ids:[],p=Array.isArray(s?.names)?s.names.flatMap((c,h)=>{const g=x[h];return typeof c=="string"&&(typeof g=="string"||typeof g=="number")?[{key:String(g),name:c}]:[]}):[],f=P(s?.name),d=s?.entity_id,b=o.length>0?o:p.length>0?p:f&&(typeof d=="string"||typeof d=="number")?[{key:String(d),name:f}]:[];return{winnerName:P(r?.name)??P(s?.winner_name),winnerSlug:P(r?.slug),winnerEntityType:P(r?.entity_type),winnerParentSlug:P(r?.parent_slug),winnerParentEntityType:P(r?.parent_entity_type),losers:b,matchEvidence:qt(s),evidenceChange:Ht(s)}}function Vt(n){const t=n.entityType?W(n.entityType).toLowerCase():"entity";if(n.operation==="merge"){const s=n.merge?.losers??[];return s.length>1?`Merge ${s.length} duplicate ${t}s`:`Merge duplicate ${t}`}return`${W(n.operation)} ${t}`}function Wt(n,t){if(t.action_key!=="entity_change"&&t.tool!=="entity_change")return null;const s=t.action;if(s!=="create"&&s!=="delete"&&s!=="merge")return null;const r=n;return{operation:s,merge:s==="merge"?Jt(t):void 0,proposal:O(t.proposal),current:O(t.current),reason:typeof t.reason=="string"?t.reason:void 0,automationId:t.automation_id!=null?String(t.automation_id):void 0,automationName:typeof t.automation_name=="string"?t.automation_name:void 0,automationAgentId:typeof t.automation_agent_id=="string"?t.automation_agent_id:void 0,entityType:typeof t.entity_type=="string"?t.entity_type:void 0,entityName:(typeof t.entity_name=="string"?t.entity_name:void 0)??r.entity_name??void 0,entitySlug:typeof t.entity_slug=="string"?t.entity_slug:void 0,parentSlug:typeof t.parent_slug=="string"?t.parent_slug:void 0,parentEntityType:typeof t.parent_entity_type=="string"?t.parent_entity_type:void 0,attribution:typeof t.attribution=="string"?t.attribution:void 0,proposerRationale:typeof t.proposer_rationale=="string"?t.proposer_rationale:void 0,initiator:t.initiator&&typeof t.initiator=="object"?t.initiator:void 0}}function ue(n,t){return!n||!t.entityType||!t.entitySlug?null:ve(n,t.parentEntityType&&t.parentSlug?[{entity_type:t.parentEntityType,slug:t.parentSlug},{entity_type:t.entityType,slug:t.entitySlug}]:[{entity_type:t.entityType,slug:t.entitySlug}])}function Se({runId:n,details:t}){const{org:s}=Y(),a=_e(t.automationId,void 0,s?.id,{includeVersions:!1}).data?.automation,m=Ce(t.initiator,t.attribution,t.automationId),y=a?.automation_name??t.automationName??m,o=s?.slug;return e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Requested by"," ",o&&t.automationId?e.jsx(B,{to:"/$owner/automations/$automationId",params:{owner:o,automationId:t.automationId},search:{view:"definition",run_id:void 0},className:"font-medium text-foreground underline-offset-4 hover:underline",children:y}):e.jsx("span",{className:"font-medium text-foreground",children:y}),o&&n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:" · "}),e.jsxs(B,{to:"/$owner/events",params:{owner:o},search:{run_ids:String(n)},className:"font-medium text-foreground underline-offset-4 hover:underline",children:["Run #",n]})]})]})}function Re({details:n}){const{org:t}=Y(),s=ue(t?.slug,n);return n.entityName?e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Entity"}),e.jsx("div",{className:"mt-1 text-sm font-medium",children:s?e.jsx(B,{to:s,className:"underline-offset-4 hover:underline",children:n.entityName}):n.entityName})]}):null}function Ae({label:n,before:t,after:s}){return e.jsxs("div",{className:"rounded-md border border-border/70 overflow-hidden",children:[e.jsx("div",{className:"border-b border-border/70 px-3 py-2 text-xs font-medium",children:n}),e.jsxs("div",{className:"grid gap-px bg-border/70 sm:grid-cols-2",children:[e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Current"}),e.jsx("div",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:ye(t)})]}),e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Proposed"}),e.jsx("div",{className:"whitespace-pre-wrap text-sm leading-relaxed",children:ye(s)})]})]})]})}function Kt({runId:n,details:t}){return e.jsxs("div",{className:"space-y-3",children:[e.jsx(Se,{runId:n,details:t}),e.jsx(Re,{details:t}),Object.entries(t.fields).map(([s,r])=>e.jsx(Ae,{label:W(s),before:t.current[s],after:r},s)),t.reason&&e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Reasoning"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.reason})]})]})}function Qt({merge:n,status:t}){const{org:s}=Y(),r=ue(s?.slug,{entityType:n.winnerEntityType,entitySlug:n.winnerSlug,parentEntityType:n.winnerParentEntityType,parentSlug:n.winnerParentSlug}),a=n.losers.length,m=t==="rejected"||t==="failed",y=t==="completed";return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"rounded-lg border border-border/70 overflow-hidden",children:e.jsxs("div",{className:"grid gap-px bg-border/70 sm:grid-cols-2",children:[e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:m?"Would have kept":"Kept"}),e.jsx("div",{className:"text-sm font-medium leading-relaxed",children:n.winnerName?r?e.jsx(B,{to:r,className:"underline-offset-4 hover:underline",children:n.winnerName}):n.winnerName:e.jsx("span",{className:"text-muted-foreground",children:"Unknown"})})]}),e.jsxs("div",{className:"bg-background p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:m?a>1?`Kept separate (${a})`:"Kept separate":y?a>1?`Merged away (${a})`:"Merged away":a>1?`To merge away (${a})`:"To merge away"}),e.jsx("div",{className:"space-y-0.5 text-sm leading-relaxed",children:a>0?n.losers.map(o=>{const x=ue(s?.slug,{entityType:o.entityType,entitySlug:o.slug,parentEntityType:o.parentEntityType,parentSlug:o.parentSlug}),p=y?"line-through decoration-muted-foreground/60":"";return e.jsx("div",{className:"break-words",children:x?e.jsx(B,{to:x,className:`${p} underline-offset-4 hover:underline`,children:o.name}):e.jsx("span",{className:p,children:o.name})},o.key)}):e.jsx("span",{className:"text-muted-foreground",children:"Unknown"})})]})]})}),n.evidenceChange&&e.jsxs("div",{className:n.evidenceChange.dropped.length>0?"rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2":"rounded-lg bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:n.evidenceChange.dropped.length>0?"What changed since you reviewed this":"Evidence re-checked"}),e.jsxs("div",{className:"mt-1.5 flex flex-col gap-1",children:[n.evidenceChange.dropped.map(o=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"mr-1.5 font-medium text-amber-700 dark:text-amber-400",children:"No longer proven"}),W(o.kind),": ",o.identifier]},`dropped-${o.kind}:${o.identifier}`)),n.evidenceChange.gained.map(o=>e.jsxs("div",{className:"text-sm",children:[e.jsx("span",{className:"mr-1.5 font-medium text-emerald-700 dark:text-emerald-400",children:"Newly proven"}),W(o.kind),": ",o.identifier]},`gained-${o.kind}:${o.identifier}`)),n.evidenceChange.dropped.length===0&&n.evidenceChange.gained.length===0&&e.jsx("div",{className:"text-sm text-muted-foreground",children:"The recorded match evidence did not change."})]})]}),n.matchEvidence.length>0&&e.jsxs("div",{className:"rounded-lg bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Match evidence"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:n.matchEvidence.map(o=>e.jsxs(J,{variant:"outline",className:"text-[10px] font-normal",children:[W(o.kind),": ",o.identifier]},`${o.kind}:${o.identifier}`))})]})]})}function Gt({runId:n,details:t,status:s}){const r=t.operation==="merge";return e.jsxs("div",{className:"space-y-3",children:[e.jsx(Se,{runId:n,details:t}),r&&t.merge?e.jsx(Qt,{merge:t.merge,status:s}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{details:t}),e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Change"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.operation==="create"?"Create a new entity after approval.":"Delete this entity after approval."})]})]}),!r&&t.proposal&&e.jsxs("div",{className:"rounded-md border border-border/70 p-3",children:[e.jsx("div",{className:"mb-1 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Proposal"}),e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-xs leading-relaxed",children:JSON.stringify(t.proposal,null,2)})]}),t.proposerRationale&&e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:t.attribution==="agent"?"The agent's reasoning":"The Automation's reasoning"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.proposerRationale})]}),t.reason&&e.jsxs("div",{className:"rounded-md bg-muted/40 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:r?"Why this needs approval":"Reasoning"}),e.jsx("div",{className:"mt-1 text-sm leading-relaxed",children:t.reason})]})]})}function Yt({summary:n}){return e.jsxs("div",{className:"space-y-2 rounded-md border border-border/70 bg-muted/30 p-3 text-sm",children:[n.chips.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:n.chips.map(t=>e.jsx(J,{variant:"outline",className:"text-[10px] font-normal",children:t},t))}),n.message&&e.jsx("p",{className:"leading-relaxed text-foreground",children:n.message}),n.reason&&e.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Why"}),e.jsx("div",{className:"mt-0.5 leading-relaxed",children:n.reason})]}),n.body&&e.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:n.kind==="verify"?"Expected comment":"Draft"}),e.jsx("div",{className:"mt-0.5 whitespace-pre-wrap leading-relaxed",children:n.body})]}),n.matchPreview&&e.jsxs("div",{className:"rounded-md bg-background/80 px-2.5 py-2",children:[e.jsxs("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:["Matched comment",n.matchAuthor?` · ${n.matchAuthor}`:""]}),e.jsx("div",{className:"mt-0.5 whitespace-pre-wrap leading-relaxed text-muted-foreground",children:n.matchPreview})]}),n.postUrl&&e.jsxs("a",{href:n.postUrl,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Open post",e.jsx(Ne,{className:"h-3 w-3"})]})]})}function Xt({content:n}){const t=n.metadata||{},s=n.run_id??void 0,r=Ut(n,t),a=Wt(n,t),m=(r?Bt(r):a?Vt(a):void 0)||t.operation_name||t.action_name||(n.title?Lt(n.title):void 0)||"Action",y=t.connection_name,o=t.operation_key||t.action_key||null,x=n.interaction_input_schema||t.input_schema||null,p=N.useMemo(()=>n.interaction_input||t.action_input||t.operation_input||Tt,[n.interaction_input,t.action_input,t.operation_input]),f=n.interaction_output||t.action_output||void 0,d=At(p,f??null,o),b=n.interaction_error||t.error_message||void 0,c=Mt(n.interaction_status,t.status),h=t.reviewed_by_name||t.reviewed_by_id||void 0,g=t.reject_reason||void 0,R=t.initiator,D=Ge(),v=Ye(),A=Xe(n.id,Ze(x,p),x),{values:F,setValues:U}=A,[I,q]=N.useState(null),[_,M]=N.useState(!1),[E,l]=N.useState(""),S=c==="pending_approval",L=typeof t.source_run_id=="number";return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(et,{className:"h-4 w-4 text-yellow-500"}),e.jsx("span",{className:"font-medium",children:m}),y&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["on ",y]}),c==="confirmed"&&e.jsxs(J,{variant:"outline",className:"text-blue-700 border-blue-300 bg-blue-50 dark:bg-blue-950/30 text-[10px]",children:[e.jsx(K,{size:"xs",className:"mr-1"}),"Executing"]}),c==="completed"&&e.jsx(J,{variant:"outline",className:"text-green-700 border-green-300 bg-green-50 dark:bg-green-950/30 text-[10px]",children:"Completed"}),c==="failed"&&e.jsx(J,{variant:"outline",className:"text-red-700 border-red-300 bg-red-50 dark:bg-red-950/30 text-[10px]",children:"Failed"}),c==="rejected"&&e.jsx(J,{variant:"outline",className:"text-muted-foreground text-[10px]",children:"Rejected"})]}),!r&&!a&&(n.author_name||h)&&e.jsxs("div",{className:"flex flex-wrap items-center gap-x-1.5 gap-y-0.5 text-xs text-muted-foreground",children:[n.author_name&&e.jsxs("span",{children:["Requested by"," ",e.jsx(zt,{initiator:R,clientName:n.author_name,fallback:n.author_name})]}),n.author_name&&h&&e.jsx("span",{children:"·"}),h&&e.jsxs("span",{children:[c==="rejected"?"Rejected":"Approved"," by"," ",e.jsx("span",{className:"font-medium text-foreground",children:h})]})]}),r&&e.jsx(Kt,{runId:s,details:r}),!r&&a&&e.jsx(Gt,{runId:s,details:a,status:c}),c==="rejected"&&g&&e.jsxs("div",{className:"rounded-md bg-muted/50 p-2 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:"Reason:"})," ",g]}),d&&e.jsx(Yt,{summary:d}),(S?A.revision:x)&&(S||Object.keys(p).length>0)&&e.jsxs("div",{children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1",children:d?"Full input":"Input"}),S?e.jsxs(e.Fragment,{children:[e.jsx(tt,{visible:A.hasConflict,onReload:A.reset}),e.jsx(nt,{schema:A.revision,values:F,onValuesChange:U,fieldIdPrefix:`action-${n.id}-`},`action-${n.id}`)]}):d?e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"Raw input"}),e.jsx("pre",{className:"mt-1 bg-muted/50 rounded p-2 font-mono overflow-auto max-h-32",children:JSON.stringify(p,null,2)})]}):e.jsx("pre",{className:"text-xs bg-muted/50 rounded p-2 font-mono overflow-auto max-h-32",children:JSON.stringify(p,null,2)})]}),c==="completed"&&f&&Object.keys(f).length>0&&!d&&e.jsxs("div",{className:"rounded-md bg-green-50 dark:bg-green-950/30 p-3 text-sm space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-green-700 dark:text-green-400 font-medium",children:[e.jsx(st,{className:"h-3.5 w-3.5"}),"Output"]}),e.jsx("pre",{className:"text-xs text-green-800 dark:text-green-300 font-mono whitespace-pre-wrap",children:JSON.stringify(f,null,2)})]}),c==="completed"&&f&&Object.keys(f).length>0&&d&&e.jsxs("details",{className:"text-xs",children:[e.jsx("summary",{className:"cursor-pointer text-muted-foreground hover:text-foreground",children:"Raw output"}),e.jsx("pre",{className:"mt-1 rounded bg-green-50 p-2 font-mono dark:bg-green-950/30 overflow-auto max-h-32",children:JSON.stringify(f,null,2)})]}),c==="failed"&&b&&e.jsxs("div",{className:"rounded-md bg-red-50 dark:bg-red-950/30 p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-red-700 dark:text-red-400 font-medium",children:[e.jsx(rt,{className:"h-3.5 w-3.5"}),"Error"]}),e.jsx("p",{className:"text-xs text-red-800 dark:text-red-300 font-mono mt-1",children:b})]}),I==="confirmed"&&e.jsxs("div",{className:"rounded-md bg-blue-50 dark:bg-blue-950/30 p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-blue-700 dark:text-blue-400 font-medium",children:[e.jsx(K,{size:"md"}),"Confirmed — executing..."]}),e.jsx("p",{className:"text-xs text-blue-800 dark:text-blue-300 mt-1",children:"The worker will execute this action shortly. Redirecting..."})]}),I==="rejected"&&e.jsx(J,{variant:"outline",className:"text-muted-foreground text-xs",children:"Rejected — redirecting..."}),S&&!I&&L&&e.jsx("div",{className:"pt-1 text-xs text-muted-foreground",children:"Part of an Automation run — approve or reject it from the run's change-set above."}),S&&s&&!I&&!L&&e.jsx("div",{className:"flex items-center gap-2 pt-1",children:_?e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("input",{type:"text",placeholder:"Reason (optional)",value:E,onChange:$=>l($.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),e.jsxs(k,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>v.mutate({run_id:s,reason:E||void 0},{onSuccess:()=>{q("rejected")}}),disabled:v.isPending,children:[v.isPending&&e.jsx(K,{size:"sm",className:"mr-1"}),"Confirm Reject"]}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{M(!1),l("")},children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[e.jsxs(k,{size:"sm",className:"h-7 text-xs",onClick:()=>D.mutate({run_id:s,input:at(F)},{onSuccess:()=>{q("confirmed")}}),disabled:!A.canSubmit||D.isPending||v.isPending,children:[D.isPending?e.jsx(K,{size:"sm",className:"mr-1"}):e.jsx(it,{className:"h-3 w-3 mr-1"}),"Confirm"]}),e.jsxs(k,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>M(!0),disabled:D.isPending||v.isPending,children:[e.jsx(ot,{className:"h-3 w-3 mr-1"}),"Reject"]})]})})]})}function Zt({content:n}){const t=n.metadata||{},s=t.kind,r=n.run_id??null,a=typeof t.automation_id=="number"?t.automation_id:null,{org:m}=Y(),y=m?.slug,p=_e(a!=null?String(a):void 0,void 0,m?.id,{includeVersions:!1}).data?.automation?.automation_name??(a!=null?`Automation ${a}`:"An Automation"),f=Ke(),d=Qe(),[b,c]=N.useState(!1),[h,g]=N.useState(""),[R,D]=N.useState(null);if(s==="automation_batch_reject"){const l=t.reason||void 0;return e.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3",children:[e.jsx("div",{className:"text-sm font-medium",children:"Proposals rejected"}),l&&e.jsx("div",{className:"mt-1 text-sm text-muted-foreground",children:l}),e.jsx("div",{className:"mt-1 text-xs text-muted-foreground",children:"Ask the agent to revise its proposals with this feedback."})]})}const v=Array.isArray(t.changes)?t.changes:[],A=typeof t.created_count=="number"?t.created_count:v.filter(l=>l.kind==="created").length,F=typeof t.updated_count=="number"?t.updated_count:v.filter(l=>l.kind==="updated").length,U=typeof t.denied_count=="number"?t.denied_count:v.filter(l=>l.kind==="denied").length,I=v.filter(l=>l.kind==="denied"),q=v.filter(l=>l.kind==="updated"&&Object.keys(l.applied||{}).length>0),_=typeof t.pending_proposal_count=="number"?t.pending_proposal_count:null,M=_==null||_>0,E=M?"proposed":"applied";return e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1",children:[e.jsxs("div",{className:"text-sm font-medium",children:[E==="proposed"?"Proposed":"Applied"," ",A," ","new + ",F," updated",U>0&&e.jsxs(e.Fragment,{children:[" + ",U," denied"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[y&&a!=null?e.jsx(B,{to:"/$owner/automations/$automationId",params:{owner:y,automationId:String(a)},search:{view:"definition",run_id:void 0},className:"font-medium text-foreground underline-offset-4 hover:underline",children:p}):e.jsx("span",{className:"font-medium text-foreground",children:p}),r!=null&&e.jsxs("span",{children:[" · run #",r]}),_!=null&&_>0&&e.jsxs("span",{children:[" · ",_," pending"]})]})]}),q.length>0&&e.jsx("div",{className:"mt-3 space-y-2",children:q.map(l=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:l.name}),Object.entries(l.applied).map(([S,L])=>e.jsx(Ae,{label:S,before:L.old,after:L.new},S))]},l.entityId))}),I.length>0&&e.jsx("div",{className:"mt-3 space-y-1.5",children:I.map(l=>e.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 px-2.5 py-2",children:[e.jsxs("div",{className:"text-xs font-medium",children:[l.name," — not written"]}),l.denied&&e.jsxs("div",{className:"mt-0.5 text-xs text-muted-foreground",children:[l.denied.reason,e.jsxs("span",{className:"ml-1 opacity-70",children:["(refused by"," ",l.denied.source==="rule"?"a write rule":"org policy",")"]})]})]},`denied-${l.entityId}-${l.name}`))}),r!=null&&R==null&&M&&e.jsx("div",{className:"mt-3 border-t border-border/70 pt-3",children:b?e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[e.jsx("input",{type:"text",placeholder:"What should the agent change?",value:h,onChange:l=>g(l.target.value),className:"h-7 text-xs border rounded px-2 flex-1 bg-background"}),e.jsxs(k,{size:"sm",variant:"destructive",className:"h-7 text-xs",onClick:()=>d.mutate({run_id:r,reason:h||void 0},{onSuccess:()=>D("rejected")}),disabled:d.isPending,children:[d.isPending&&e.jsx(K,{size:"sm",className:"mr-1"}),"Reject all"]}),e.jsx(k,{size:"sm",variant:"ghost",className:"h-7 text-xs px-2",onClick:()=>{c(!1),g("")},children:"Cancel"})]}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(k,{size:"sm",className:"h-7 text-xs",onClick:()=>f.mutate({run_id:r},{onSuccess:()=>D("approved")}),disabled:f.isPending||d.isPending,children:[f.isPending&&e.jsx(K,{size:"sm",className:"mr-1"}),"Approve all proposals"]}),e.jsx(k,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>c(!0),disabled:f.isPending||d.isPending,children:"Reject with feedback"})]})}),R==="approved"&&e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals approved."}),R==="rejected"&&e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"Proposals rejected — ask the agent to revise them."}),r!=null&&R==null&&!M&&e.jsx("div",{className:"mt-3 text-xs text-muted-foreground",children:"All proposals reviewed."})]})}function ie({ownerSlug:n,content:t,isReply:s,showParentContext:r,connectorDefinitions:a}){const[m,y]=N.useState(!1),[o,x]=N.useState(!1),p=De(),{currentOwner:f}=Fe(),d=n??f,b=d==="me"?null:d,c=N.useCallback(async i=>{if(!b){le.error("Open this event inside a workspace to interact with it.");return}try{await St(b,Number(t.id),i,crypto.randomUUID()),le.success("Recorded")}catch(u){le.error(u instanceof Error?u.message:"Could not record that interaction.")}},[t.id,b]),h=t.payload_data??{},g=t.semantic_type==="audit"&&t.origin_type==="tool_invocation",R=g&&(h.request!==void 0||h.request_status==="too_large"),v=g&&h.request_status==="complete"&&d?`/${d}/events?content_ids=${t.id}`:!d||d==="me"?null:t.run_id!=null?`/${d}/events?run_ids=${t.run_id}`:null,A=!!(p&&v&&Me(v)),F=()=>{!p||!v||p.open({href:v,title:t.title??(t.run_id!=null?`Run #${t.run_id}`:"Event"),runId:t.run_id??void 0})},U=i=>{const u=i.target;if(!(u instanceof Element))return!1;const j=u.closest('a,button,input,select,textarea,[role="button"],[role="radio"]');return j!==null&&j!==i.currentTarget},I=i=>{U(i)||F()},q=i=>{i.key!=="Enter"&&i.key!==" "||U(i)||(i.preventDefault(),F())},_=t.metadata||{};if(t.semantic_type==="change_set")return e.jsx(Zt,{content:t});if(t.interaction_type==="approval"||t.semantic_type==="operation"||_.status!=null||_.action_key!=null)return e.jsx(Xt,{content:t});const E=Number.isFinite(t.score)?Math.round(t.score):"-",l=t.payload_type||"text",S=t.text_content||"",L=(l==="text"||l==="markdown")&&S.length>500,$=L&&!m?`${S.slice(0,500)}...`:S,Q=_.thumbnail_url||_.thumbnail,H=_.media_url,G=Ot(_),ne=Object.entries(t.classifications||{}).flatMap(([i,u])=>{const j=Ft(u);return j.values.map(T=>({slug:i,value:T,isManual:j.isManual}))}),X=(()=>{const i=t.metadata??{},u=t.platform||(typeof i.platform=="string"?i.platform:null),j=t.connection_id!=null?t.connection_id:i.source_connection_id!=null?Number(i.source_connection_id):null;return{...t,platform:u,connection_id:j!=null&&Number.isFinite(j)?j:null}})();return e.jsxs("div",{className:We(s?"border-l-2 border-l-muted pl-4":"",A&&"-mx-2 cursor-pointer rounded-lg px-2 py-1 transition-colors hover:bg-accent/40"),...A?{role:"button",tabIndex:0,onClick:I,onKeyDown:q}:{},children:[r&&t.parent_context&&e.jsxs("div",{className:"mb-3 p-2 bg-muted/50 rounded-md text-sm",children:[e.jsx("div",{className:"text-xs text-muted-foreground mb-1",children:"Replying to:"}),e.jsx("div",{className:"font-medium",children:t.parent_context.author_name}),e.jsx("div",{className:"text-muted-foreground line-clamp-2",children:t.parent_context.text_content})]}),e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[t.title&&e.jsx("h4",{className:"font-medium line-clamp-2 mb-1",children:t.title}),e.jsx("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:(()=>{const i=$t(t),u=!!t.platform&&i!==te(t.platform);return e.jsxs(e.Fragment,{children:[i&&e.jsx("span",{className:"font-medium",children:i}),u&&e.jsxs(e.Fragment,{children:[i&&e.jsx("span",{children:"·"}),e.jsx(J,{variant:"outline",className:"text-xs",children:t.platform})]})]})})()}),d?e.jsx(Le,{owner:d,source:X,connectorDefinitions:a,className:"mt-0.5 text-xs"}):null]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t.score_breakdown?e.jsxs(ze,{children:[e.jsx(Be,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 px-2",children:e.jsx("span",{className:"font-medium",children:E})})}),e.jsx(Ue,{className:"w-64",align:"end",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"font-medium",children:"Score Breakdown"}),e.jsx(It,{breakdown:t.score_breakdown})]})})]}):e.jsx(k,{variant:"ghost",size:"sm",className:"h-7 px-2",disabled:!0,children:e.jsx("span",{className:"font-medium",children:E})}),t.source_url&&e.jsxs(qe,{children:[e.jsx(He,{asChild:!0,children:e.jsx(k,{variant:"ghost",size:"icon",className:"h-7 w-7",asChild:!0,children:e.jsx("a",{href:t.source_url,target:"_blank",rel:"noopener noreferrer",children:e.jsx(Ne,{className:"h-3.5 w-3.5"})})})}),e.jsx(Je,{children:"View original"})]})]})]}),t.rating&&e.jsx("div",{className:"flex items-center gap-1 mb-2",children:[1,2,3,4,5].map(i=>e.jsx(be,{className:`h-4 w-4 ${i<=Number(t.rating)?"fill-yellow-400 text-yellow-400":"text-muted-foreground"}`},i))}),Q&&e.jsx("a",{href:H||t.source_url||"#",target:"_blank",rel:"noopener noreferrer",className:"block mb-2",children:e.jsx("img",{src:Q,alt:"",className:`rounded-md object-cover ${l==="media"?"max-h-96 w-full":"max-h-48"}`,loading:"lazy"})}),t.excerpt&&e.jsx("div",{className:"text-sm italic text-muted-foreground border-l-2 border-primary/40 pl-2 mb-1",children:t.excerpt}),(()=>{switch(l){case"markdown":if($)return e.jsx("div",{className:"max-w-none text-sm space-y-2",children:e.jsx(Ve,{text:$})});break;case"json_template":{const i=t.payload_template;if(i?.root)return e.jsx(_t,{template:{root:i.root},data:t.payload_data||{},onAction:c,interactions:i.interactions});if($)return e.jsx("div",{className:"text-sm whitespace-pre-wrap",children:$});break}case"media":return e.jsxs("div",{className:"space-y-3",children:[!Q&&H&&e.jsx("a",{href:H,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline truncate block",children:H}),$&&e.jsx("div",{className:"text-sm whitespace-pre-wrap text-muted-foreground",children:$})]});case"empty":return e.jsxs("div",{className:"space-y-3",children:[R&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs(k,{variant:"outline",size:"sm","aria-expanded":o,onClick:()=>x(i=>!i),children:[o?e.jsx(ae,{className:"h-3.5 w-3.5"}):e.jsx(oe,{className:"h-3.5 w-3.5"}),"Request"]}),o&&(h.request_status==="too_large"?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["The request was too large to retain",typeof h.request_bytes=="number"?` (${h.request_bytes.toLocaleString()} bytes).`:"."]}):e.jsx(Pt,{value:h.request}))]}),G.length>0?e.jsx("dl",{className:"grid gap-x-3 gap-y-2 text-sm sm:grid-cols-[minmax(140px,180px)_1fr]",children:G.map(([i,u])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:te(i)}),e.jsx("dd",{className:"min-w-0 break-words font-mono text-xs sm:text-sm",children:fe(u)})]},i))}):e.jsx("p",{className:"text-sm text-muted-foreground italic",children:"No content"})]});default:if($)return e.jsx("div",{className:"text-sm whitespace-pre-wrap",children:$});break}return e.jsxs("div",{className:"space-y-3",children:[H&&!Q&&e.jsx("a",{href:H,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-muted-foreground hover:text-foreground truncate block",children:H}),G.length>0&&e.jsx("dl",{className:"grid gap-x-3 gap-y-2 text-sm sm:grid-cols-[minmax(140px,180px)_1fr]",children:G.map(([i,u])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted-foreground",children:te(i)}),e.jsx("dd",{className:"min-w-0 break-words font-mono text-xs sm:text-sm",children:fe(u)})]},i))})]})})(),L&&e.jsx(k,{variant:"link",size:"sm",className:"px-0 h-6 mt-1",onClick:()=>y(!m),children:m?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3 w-3 mr-1"})," Show less"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3 w-3 mr-1"})," Show more"]})}),ne.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5 mt-3",children:ne.map(i=>e.jsx(Dt,{slug:i.slug,value:i.value||"",isManual:i.isManual},i.slug))})]})}function en({occurredAt:n,isLast:t,children:s}){return e.jsxs("div",{className:"relative flex gap-4 pb-6",children:[e.jsxs("div",{className:"relative flex w-2.5 shrink-0 justify-center",children:[!t&&e.jsx("div",{className:"absolute top-1 bottom-[-1.5rem] left-1/2 w-px -translate-x-1/2 bg-border","aria-hidden":!0}),e.jsx("div",{className:"relative z-10 mt-1 h-2.5 w-2.5 rounded-full border-2 border-background bg-muted-foreground/60"})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[n&&e.jsx("time",{dateTime:new Date(n).toISOString(),title:ke(n),className:"mb-1 block text-xs leading-none text-muted-foreground",children:we(n)}),s]})]})}function rn({organizationId:n,ownerSlug:t,entityId:s,filters:r,showEntityLinks:a=!1,emptyState:m,dense:y=!1}){const{isAuthenticated:o,isReady:x}=dt(),{isMember:p,isLoading:f}=Y(),d=t==="me",b=!d&&x&&o&&p,c=!d&&x&&(!o||!f&&!p),{data:h=[]}=ct(x&&b?n:null),{data:g=[]}=ut(c?t:null),R=b?h:g,D=mt(x&&b?n:null,s,r,t),v=pt(c?t:null,s,r),A=c?v:D,{data:F,isLoading:U,error:I,fetchNextPage:q,hasNextPage:_,isFetchingNextPage:M}=A,E=N.useMemo(()=>F?.pages.flatMap(i=>i.content)??[],[F]),l=wt({onIntersect:()=>q(),enabled:!!_&&!M}),S=N.useMemo(()=>{const i=xt(E),u=i.map(V=>V.head),j=new Map(i.map(V=>[V.head.id,V])),T=ht(u);return Array.from(T.entries()).map(([V,Z])=>{const se=Z.root||Z.replies[0],ee=se?j.get(se.id):void 0;return{rootId:V,group:Z,history:ee?.history??[],runId:ee?.runId??null}})},[E]),[L,$]=N.useState(new Set),[Q,H]=N.useState(new Set),[G,ne]=N.useState(new Set),X=(i,u)=>i(j=>{const T=new Set(j);return T.has(u)?T.delete(u):T.add(u),T});return U&&E.length===0?e.jsx("div",{className:"space-y-4",children:["s1","s2","s3"].map(i=>e.jsx(gt,{className:"h-32 rounded-lg"},i))}):I?e.jsx(ft,{label:"events"}):E.length===0?m??e.jsx(yt,{icon:jt,title:"Nothing here yet",description:"No events match this view."}):e.jsxs("div",{className:y?"":"pt-1",children:[S.map(({rootId:i,group:u,history:j,runId:T},V,Z)=>{const se=u.replies.length>0,ee=L.has(i),me=G.has(i),pe=Q.has(i),Te=u.replies.filter(C=>C.depth<=3),re=u.replies.filter(C=>C.depth>3),Ee=!u.root&&u.replies.length>0,z=u.root||u.replies[0];return z?e.jsxs(en,{occurredAt:z.occurred_at,isLast:V===Z.length-1,children:[a&&t&&z.entity_name&&z.entity_type&&z.entity_slug&&e.jsx("div",{className:"mb-2",children:e.jsx(Ct,{ownerSlug:t,entity:{entityName:z.entity_name,entityType:z.entity_type,entitySlug:z.entity_slug}})}),e.jsx(ie,{ownerSlug:t,content:z,showParentContext:Ee&&!!z.parent_context,connectorDefinitions:R}),j.length>0&&e.jsxs(xe,{open:pe,children:[e.jsx(he,{asChild:!0,children:e.jsxs(k,{variant:"ghost",size:"sm",className:"mt-1 h-7 gap-1 text-xs text-muted-foreground",onClick:()=>X(H,i),children:[e.jsx(vt,{className:"h-3.5 w-3.5"}),pe?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Hide ",T!=null?`run #${T} `:"","history"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),T!=null?`Run #${T} · ${j.length===1?"1 earlier step":`${j.length} earlier steps`}`:j.length===1?"1 earlier state":`${j.length} earlier states`]})]})}),e.jsx(ge,{className:"mt-2 space-y-3 border-l-2 border-l-muted pl-4",children:j.map(C=>e.jsxs("div",{children:[e.jsx("time",{dateTime:new Date(C.occurred_at).toISOString(),title:ke(C.occurred_at),className:"mb-1 block text-xs text-muted-foreground",children:we(C.occurred_at)}),e.jsx(ie,{ownerSlug:t,content:C,connectorDefinitions:R})]},C.id))})]}),se&&e.jsxs(xe,{open:ee,children:[e.jsx(he,{asChild:!0,children:e.jsxs(k,{variant:"ghost",size:"sm",className:"mt-2 ml-6 gap-1",onClick:()=>X($,i),children:[e.jsx(Nt,{className:"h-3.5 w-3.5"}),ee?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Hide ",u.replies.length," replies"]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),"Show ",u.replies.length," replies"]})]})}),e.jsxs(ge,{className:"space-y-2 mt-2",children:[Te.map(C=>e.jsx(ie,{ownerSlug:t,content:C,isReply:!0,connectorDefinitions:R},C.id)),re.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(k,{variant:"ghost",size:"sm",className:"ml-12",onClick:()=>X(ne,i),children:me?e.jsxs(e.Fragment,{children:["Hide ",re.length," nested replies"]}):e.jsxs(e.Fragment,{children:["Show ",re.length," nested replies"]})}),me&&re.map(C=>e.jsx(ie,{ownerSlug:t,content:C,isReply:!0,connectorDefinitions:R},C.id))]})]})]})]},i):null}),e.jsx("div",{ref:l,className:"h-1"}),M&&e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(K,{size:"xl",className:"text-muted-foreground"})})]})}export{rn as E};
|
package/dist/owletto/dist/assets/{full-page-spinner-DTSqneUO.js → full-page-spinner-BN2G_YiM.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r,j as t,aj as u}from"./index-
|
|
1
|
+
import{r,j as t,aj as u}from"./index-BUr8321-.js";function l({className:i,delayMs:e=500}){const[s,n]=r.useState(e<=0);return r.useEffect(()=>{if(e<=0)return;const a=setTimeout(()=>n(!0),e);return()=>clearTimeout(a)},[e]),s?t.jsx("div",{className:u("flex min-h-[50vh] items-center justify-center",i),role:"status","aria-label":"Loading",children:t.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):null}export{l as F};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as t,a0 as o}from"./index-BUr8321-.js";function a(){return t.jsx(o,{})}export{a as component};
|