@objectstack/console 11.10.0 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/dist/.objectui-sha +1 -1
  2. package/dist/assets/{AdapterProvider-DVMiVYFP.js → AdapterProvider-BIB-F0Qa.js} +1 -1
  3. package/dist/assets/{AiPendingActionsPage-Bou3pWLX.js → AiPendingActionsPage-CMVG4Uuj.js} +1 -1
  4. package/dist/assets/ApiConsolePage-BpBKlVk6.js +1 -0
  5. package/dist/assets/{AppDocsIndex-C_YBwvgj.js → AppDocsIndex-35urFMpk.js} +1 -1
  6. package/dist/assets/{AppManagementPage-YsvEXLrM.js → AppManagementPage-Q8hLq3cQ.js} +1 -1
  7. package/dist/assets/ApprovalsInboxPage-Cjd1esAG.js +1 -0
  8. package/dist/assets/AuditLogPage-C2lQmF3X.js +1 -0
  9. package/dist/assets/{ComponentNavView-B2h1_hKD.js → ComponentNavView-BuEXrmXR.js} +1 -1
  10. package/dist/assets/{ConsoleFloatingChatbot-B-0CCFP0.js → ConsoleFloatingChatbot-XMVIlmjf.js} +1 -1
  11. package/dist/assets/{DashboardView-h39c92Wy.js → DashboardView-cKnnhVZW.js} +1 -1
  12. package/dist/assets/DashboardWidgetInspector-DQzulo-e.js +1 -0
  13. package/dist/assets/{DeveloperHubPage-tKxNPDnb.js → DeveloperHubPage-DO4z3Sj9.js} +1 -1
  14. package/dist/assets/{ExpressionProvider-Ccb8aGyF.js → ExpressionProvider-BI-jCA0B.js} +1 -1
  15. package/dist/assets/FlowRunsPage-DVvg_WMt.js +1 -0
  16. package/dist/assets/{IntegrationsPage-DHRFBzYf.js → IntegrationsPage-kF55v0ix.js} +2 -2
  17. package/dist/assets/{InterfaceListPage-DNilCW1a.js → InterfaceListPage-CH9wtpOt.js} +1 -1
  18. package/dist/assets/{ManagedByBadge-CBYGpiPD.js → ManagedByBadge-DtZfR2w_.js} +1 -1
  19. package/dist/assets/{MarketplaceAccessDenied-yP86owRY.js → MarketplaceAccessDenied-JR0ElPYV.js} +1 -1
  20. package/dist/assets/{MarketplaceInstalledPage-BT9VRrrF.js → MarketplaceInstalledPage-c1qqM0m9.js} +1 -1
  21. package/dist/assets/MarketplacePackagePage-CT5bU1QW.js +4 -0
  22. package/dist/assets/MarketplacePage-BkOByUub.js +1 -0
  23. package/dist/assets/{MetadataInspector-Cd9-_Ogw.js → MetadataInspector-FQJn-0mY.js} +1 -1
  24. package/dist/assets/{MetadataProvider-A34LFAxj.js → MetadataProvider-DlGQbrYS.js} +1 -1
  25. package/dist/assets/PageView-BR-dytGp.js +1 -0
  26. package/dist/assets/ProfilePage-BfNhQTic.js +1 -0
  27. package/dist/assets/PublicFormsPage-D5HXZ9gs.js +1 -0
  28. package/dist/assets/RecordDetailView-BUBX12o3.js +9 -0
  29. package/dist/assets/RecordFormPage-dOx4tkq3.js +1 -0
  30. package/dist/assets/ReportDefaultInspector-DQlvnczB.js +11 -0
  31. package/dist/assets/{ReportView-Bp_UWpRC.js → ReportView-BoYtuwGU.js} +1 -1
  32. package/dist/assets/{SearchResultsPage-DpUit7MF.js → SearchResultsPage-Dn6Lg7cm.js} +1 -1
  33. package/dist/assets/{SettingsHub-Bx2yYwy8.js → SettingsHub-BIUh_NaE.js} +1 -1
  34. package/dist/assets/{SettingsView-CwMpw6lM.js → SettingsView-iFSFGurq.js} +1 -1
  35. package/dist/assets/{SystemHubPage-B46BQlXn.js → SystemHubPage-BbYZjpSv.js} +1 -1
  36. package/dist/assets/data-adapter-BJMUjXWO.js +7 -0
  37. package/dist/assets/{framework-CAn_0ZHj.js → framework-Bn8ShCi0.js} +5 -5
  38. package/dist/assets/{highlighted-body-OFNGDK62-Cek-BVxH.js → highlighted-body-OFNGDK62-CLYrkLJN.js} +1 -1
  39. package/dist/assets/index-BecTd5hZ.js +2 -0
  40. package/dist/assets/mermaid-GHXKKRXX-B7A4_dsH.js +1 -0
  41. package/dist/assets/metadata-admin-CwGCDJE1.js +22 -0
  42. package/dist/assets/plugin-calendar-DJ1vxgSA.js +1 -0
  43. package/dist/assets/plugin-charts-vp7sTLa2.js +7 -0
  44. package/dist/assets/plugin-chatbot-DCC-44Dt.js +120 -0
  45. package/dist/assets/plugin-dashboard-z2hSPvkm.js +6 -0
  46. package/dist/assets/plugin-form-BUDPowXG.js +1 -0
  47. package/dist/assets/plugin-gantt-BJIjCj1A.js +93 -0
  48. package/dist/assets/plugin-grid-ieKf1CBn.js +8 -0
  49. package/dist/assets/plugin-kanban-DhARoJCa.js +1 -0
  50. package/dist/assets/plugin-map-C2xGbkMv.js +1 -0
  51. package/dist/assets/{plugin-markdown-DnUEVbKI.js → plugin-markdown-DXEq1goV.js} +1 -1
  52. package/dist/assets/plugin-report-Cho-TzT3.js +59 -0
  53. package/dist/assets/plugin-timeline-6gVRcvzs.js +1 -0
  54. package/dist/assets/{plugin-tree-DS93-F9J.js → plugin-tree-_9p0xC9K.js} +1 -1
  55. package/dist/assets/plugin-view-vYQlhE3F.js +1 -0
  56. package/dist/assets/plugins-views-ycDq-ZXC.js +4 -0
  57. package/dist/assets/{skeletons-DE_bYYsB.js → skeletons-C2aQsjPE.js} +1 -1
  58. package/dist/assets/{src-wFj3msfP.js → src-B4OzWw0f.js} +1 -1
  59. package/dist/assets/src-CbqgiuxM.js +15 -0
  60. package/dist/assets/{types-CdToCFDG.js → types-B0Soeu38.js} +1 -1
  61. package/dist/assets/ui-components-DlauVk27.js +42 -0
  62. package/dist/assets/ui-layout-DnHby9xU.js +1 -0
  63. package/dist/assets/{useOpenRecordList-Cjt1zpXo.js → useOpenRecordList-DWDU_kYn.js} +1 -1
  64. package/dist/assets/{useReconcileOnError-DIcM3hYv.js → useReconcileOnError-B9komLeJ.js} +1 -1
  65. package/dist/assets/{useRecordApprovals-cQzq7nP6.js → useRecordApprovals-B_jxSZvZ.js} +1 -1
  66. package/dist/assets/utils-Bixzg6Bz.js +1 -0
  67. package/dist/index.html +3 -3
  68. package/package.json +1 -1
  69. package/dist/assets/ApiConsolePage-BcYl4bAX.js +0 -1
  70. package/dist/assets/ApprovalsInboxPage-ZUhRdtFJ.js +0 -1
  71. package/dist/assets/AuditLogPage-CF4t6YyY.js +0 -1
  72. package/dist/assets/DashboardWidgetInspector-C09xfdI4.js +0 -1
  73. package/dist/assets/FlowRunsPage-DgR4Cvr0.js +0 -1
  74. package/dist/assets/MarketplacePackagePage-DfBf7Y3G.js +0 -4
  75. package/dist/assets/MarketplacePage-DUrowkIP.js +0 -1
  76. package/dist/assets/PageView-DFYIJhh4.js +0 -1
  77. package/dist/assets/ProfilePage-BWc59SYM.js +0 -1
  78. package/dist/assets/PublicFormsPage-Bon7Mqob.js +0 -1
  79. package/dist/assets/RecordDetailView-CQfdHDqF.js +0 -9
  80. package/dist/assets/RecordFormPage-BfX89gAL.js +0 -1
  81. package/dist/assets/ReportDefaultInspector-DdZJIfG8.js +0 -11
  82. package/dist/assets/data-adapter-CkwHF3aY.js +0 -7
  83. package/dist/assets/index-Dw-VsD8-.js +0 -2
  84. package/dist/assets/mermaid-GHXKKRXX-CntU1OOA.js +0 -1
  85. package/dist/assets/metadata-admin-CUGZYzm9.js +0 -22
  86. package/dist/assets/plugin-calendar-BYYpyQXW.js +0 -1
  87. package/dist/assets/plugin-charts-CeCFBrf0.js +0 -7
  88. package/dist/assets/plugin-chatbot-Ds6mwpav.js +0 -120
  89. package/dist/assets/plugin-dashboard-DjVYQ8s5.js +0 -6
  90. package/dist/assets/plugin-form-BefVAcDj.js +0 -1
  91. package/dist/assets/plugin-gantt-sL0M2g77.js +0 -93
  92. package/dist/assets/plugin-grid-xiUREPgU.js +0 -8
  93. package/dist/assets/plugin-kanban-De5n2Rkv.js +0 -1
  94. package/dist/assets/plugin-map-BpSLuy6T.js +0 -1
  95. package/dist/assets/plugin-report-CIAIFu54.js +0 -59
  96. package/dist/assets/plugin-timeline-CmsJV3D0.js +0 -1
  97. package/dist/assets/plugin-view-DDQkdQz8.js +0 -1
  98. package/dist/assets/plugins-views-CtiW6Mj2.js +0 -4
  99. package/dist/assets/src-CnWu84r5.js +0 -12
  100. package/dist/assets/ui-components-BNnJ5f3_.js +0 -42
  101. package/dist/assets/ui-layout-CFpFE-2o.js +0 -1
  102. package/dist/assets/utils-CFXe_XCU.js +0 -1
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,l as n,r,t as i}from"./vendor-react-slxo-5GC.js";import{$i as a,Ac as o,At as s,Ct as c,Dt as l,Gt as u,Io as d,Mt as f,Ot as p,Qn as m,Tt as h,Vs as g,Xn as _,Zn as v,_o as y,ea as b,jt as x,kt as S,li as C,or as w,rt as T,wt as E,zt as ee}from"./ui-components-DlauVk27.js";import{_ as D,c as O,d as k,n as A,o as j,p as M,s as N,t as P,u as F,v as I,y as L}from"./vendor-dndkit-0M_nRjzm.js";var R=e(t(),1),z=i();function B(e){let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!t)return null;let n=parseInt(t[1],16)/255,r=parseInt(t[2],16)/255,i=parseInt(t[3],16)/255,a=Math.max(n,r,i),o=Math.min(n,r,i),s=0,c=0,l=(a+o)/2;if(a!==o){let e=a-o;switch(c=l>.5?e/(2-a-o):e/(a+o),a){case n:s=((r-i)/e+(r<i?6:0))/6;break;case r:s=((i-n)/e+2)/6;break;case i:s=((n-r)/e+4)/6;break}}return{h:s*360,s:c*100,l:l*100}}function V(e){let t=B(e);return t?`${Math.round(t.h)} ${Math.round(t.s)}% ${Math.round(t.l)}%`:null}function H(e){let t=B(e);if(!t)return null;let n=Math.max(t.l,65),r=t.s>80?Math.max(t.s-10,70):t.s;return`${Math.round(t.h)} ${Math.round(r)}% ${Math.round(n)}%`}function U(e){let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(!t)return`0 0% 100%`;let n=e=>{let t=e/255;return t<=.03928?t/12.92:((t+.055)/1.055)**2.4},r=n(parseInt(t[1],16)),i=n(parseInt(t[2],16)),a=n(parseInt(t[3],16));return .2126*r+.7152*i+.0722*a>.6?`222 47% 11%`:`0 0% 100%`}function W(e,t){(0,R.useEffect)(()=>{let n=document.documentElement,r=()=>n.classList.contains(`dark`),i=()=>{if(e?.primaryColor){let t=V(e.primaryColor),i=H(e.primaryColor),a=r()&&i||t;a&&(n.style.setProperty(`--brand-primary`,e.primaryColor),n.style.setProperty(`--brand-primary-hsl`,t||a),n.style.setProperty(`--primary`,a),n.style.setProperty(`--primary-foreground`,r()?`222 47% 11%`:U(e.primaryColor)),n.style.setProperty(`--ring`,a),n.style.setProperty(`--sidebar-primary`,a),n.style.setProperty(`--sidebar-ring`,a))}else n.style.removeProperty(`--brand-primary`),n.style.removeProperty(`--brand-primary-hsl`),n.style.removeProperty(`--primary`),n.style.removeProperty(`--primary-foreground`),n.style.removeProperty(`--ring`),n.style.removeProperty(`--sidebar-primary`),n.style.removeProperty(`--sidebar-ring`);if(e?.accentColor){let t=V(e.accentColor),i=H(e.accentColor),a=r()&&i||t;a&&(n.style.setProperty(`--brand-accent`,e.accentColor),n.style.setProperty(`--brand-accent-hsl`,t||a),n.style.setProperty(`--accent`,a),n.style.setProperty(`--accent-foreground`,r()?`222 47% 11%`:U(e.accentColor)))}else n.style.removeProperty(`--brand-accent`),n.style.removeProperty(`--brand-accent-hsl`),n.style.removeProperty(`--accent`),n.style.removeProperty(`--accent-foreground`)};i();let a=new MutationObserver(e=>{for(let t of e)if(t.type===`attributes`&&t.attributeName===`class`){i();break}});if(a.observe(n,{attributes:!0,attributeFilter:[`class`]}),e?.favicon){let t=document.querySelector(`#favicon`)||document.querySelector(`link[rel="icon"]`);t&&(t.href=e.favicon)}return t&&(document.title=t),()=>{a.disconnect(),n.style.removeProperty(`--brand-primary`),n.style.removeProperty(`--brand-primary-hsl`),n.style.removeProperty(`--brand-accent`),n.style.removeProperty(`--brand-accent-hsl`),n.style.removeProperty(`--primary`),n.style.removeProperty(`--primary-foreground`),n.style.removeProperty(`--ring`),n.style.removeProperty(`--sidebar-primary`),n.style.removeProperty(`--sidebar-ring`),n.style.removeProperty(`--accent`),n.style.removeProperty(`--accent-foreground`)}},[e?.primaryColor,e?.accentColor,e?.favicon,t])}function G({sidebar:e,navbar:t,children:n,className:r,defaultOpen:i=!0,branding:a}){return W(a,a?.title),(0,z.jsxs)(f,{defaultOpen:i,className:`!flex-col h-svh overflow-hidden`,children:[(0,z.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:t}),(0,z.jsxs)(`div`,{className:`flex flex-1 min-h-0 w-full`,children:[e,(0,z.jsx)(l,{className:`min-w-0`,children:(0,z.jsx)(`main`,{className:o(`flex-1 min-w-0 overflow-auto p-3 sm:p-4 md:p-6 pb-20 sm:pb-4 md:pb-6`,r),children:n})})]})]})}function te(e){return e?T(e):d}function K(e,t){if(typeof e==`string`)return e;if(t){let n=t(e.key,{defaultValue:e.defaultValue,...e.params});if(n&&n!==e.key)return n}return e.defaultValue||e.key}function ne(e,t,n,r,i,a,o){let s=K(e.label,n);if(typeof e.label!=`string`)return s;if(e.type===`object`&&e.objectName){if(e.viewName)return a?a(e.objectName,e.viewName,s):s;if(t)return t(e.objectName,s)}return r&&e.type===`dashboard`&&e.dashboardName?r(e.dashboardName,s):i&&e.type===`group`&&e.id?i(e.id,s):o&&e.id?o(e.id,s):s}var q=e=>!(e===!1||e===`false`),re=()=>!0,J=()=>!0,ie=/\{(current_user_id|current_org_id|[a-z][a-z0-9_]*)\}/g;function Y(e,t){if(!e.includes(`{`))return e;let n=!1,r=e.replace(ie,(e,r)=>{let i;return i=r===`current_user_id`?t?.currentUserId:r===`current_org_id`?t?.currentOrgId:t?.contextValues?.[r],i||(n=!0,``)});return n?null:r}function X(e,t,n){switch(e.type){case`object`:{let r=`${t}/${e.objectName??``}`,i=e.recordId;if(i){let t=Y(i,n);if(t){let n=`${r}/record/${encodeURIComponent(t)}`;return{href:e.recordMode===`edit`?`${n}/edit`:n,external:!1}}}return{href:e.viewName?`${r}/view/${e.viewName}`:r,external:!1}}case`dashboard`:return{href:e.dashboardName?`${t}/dashboard/${e.dashboardName}`:`#`,external:!1};case`page`:{if(!e.pageName)return{href:`#`,external:!1};let r=e.params,i=`${t}/page/${e.pageName}`;if(r&&typeof r==`object`){let e=new URLSearchParams;for(let[t,i]of Object.entries(r))if(i!=null)if(typeof i==`string`){let r=Y(i,n);r!==null&&e.set(t,r)}else e.set(t,JSON.stringify(i));let t=e.toString();t&&(i+=`?${t}`)}return{href:i,external:!1}}case`report`:return{href:e.reportName?`${t}/report/${e.reportName}`:`#`,external:!1};case`url`:return{href:e.url??`#`,external:e.target===`_blank`};case`component`:{let r=e.componentRef;if(!r)return{href:`#`,external:!1};let i=r.split(`:`).filter(Boolean);if(i.length===0)return{href:`#`,external:!1};let a=e.params;if(i[0]===`metadata`){let e=i[1],r=a&&typeof a.type==`string`?a.type:void 0,o=a&&typeof a.name==`string`?a.name:void 0,s=``;if(a&&typeof a==`object`){let e=new URLSearchParams;for(let[t,r]of Object.entries(a))if(!(t===`type`||t===`name`)&&r!=null)if(typeof r==`string`){let i=Y(r,n);i&&e.set(t,i)}else e.set(t,JSON.stringify(r));let t=e.toString();t&&(s=`?${t}`)}return e===`directory`||!e?{href:`${t}/metadata${s}`,external:!1}:e===`resource`&&r?{href:`${t}/metadata${o?`/${encodeURIComponent(r)}/${encodeURIComponent(o)}`:`/${encodeURIComponent(r)}`}${s}`,external:!1}:{href:`${t}/metadata${s}`,external:!1}}let o=`${t}/component/${i.join(`/`)}`;if(a&&typeof a==`object`){let e=new URLSearchParams;for(let[t,n]of Object.entries(a))n!=null&&e.set(t,typeof n==`string`?n:JSON.stringify(n));let t=e.toString();t&&(o+=`?${t}`)}return{href:o,external:!1}}default:return{href:`#`,external:!1}}}function ae(e,t,n){if(t===`#`)return!1;if(n===t)return!0;let r=e.componentRef;return r&&r.split(`:`)[1]===`directory`?!1:e.type===`object`&&e.objectName?!(e.viewName||!n.startsWith(`${t}/`)||n.slice(t.length+1).startsWith(`view/`)):n.startsWith(`${t}/`)}function Z(e,t){if(!t.trim())return e;let n=t.toLowerCase().trim();return e.reduce((e,r)=>{if(r.type===`separator`)return e;if(r.type===`group`&&r.children?.length){let n=Z(r.children,t);return n.length>0&&e.push({...r,children:n}),e}return K(r.label).toLowerCase().includes(n)&&e.push(r),e},[])}var Q=5;function oe({item:e,basePath:t,evalVis:n,checkPerm:r,checkCap:i,onAction:a,enablePinning:o,onPinToggle:s,enableReorder:c,resolveObjectLabel:l,resolveDashboardLabel:u,resolveGroupLabel:d,resolveViewLabel:f,resolveItemLabel:p,t:m,templateContext:h}){let{attributes:g,listeners:_,setNodeRef:v,transform:y,transition:b,isDragging:x}=j({id:e.id,disabled:!c});return(0,z.jsx)(`div`,{ref:v,style:{transform:L.Transform.toString(y),transition:b,opacity:x?.5:void 0,zIndex:x?10:void 0},...g,children:(0,z.jsx)($,{item:e,basePath:t,evalVis:n,checkPerm:r,checkCap:i,onAction:a,enablePinning:o,onPinToggle:s,dragListeners:c?_:void 0,resolveObjectLabel:l,resolveDashboardLabel:u,resolveGroupLabel:d,resolveViewLabel:f,resolveItemLabel:p,t:m,templateContext:h})})}function $({item:e,basePath:t,evalVis:i,checkPerm:l,checkCap:d,onAction:f,enablePinning:C,onPinToggle:T,dragListeners:D,resolveObjectLabel:O,resolveDashboardLabel:k,resolveGroupLabel:A,resolveViewLabel:j,resolveItemLabel:M,t:N,templateContext:P}){let F=n(),I=ee(),L=I?`min-h-[44px] text-[15px] gap-3 rounded-xl`:void 0,B=o(`shrink-0`,I?`h-5 w-5`:`h-4 w-4`),V=(()=>{let t=e.expanded;if(typeof t==`boolean`)return t;if(typeof e.defaultOpen==`boolean`)return e.defaultOpen})(),H=e.type===`group`?e.children?.length??0:0,[U,W]=(0,R.useState)(R.useMemo(()=>{if(e.type!==`group`)return!1;let n=e=>{if(!e)return!1;for(let r of e){if(r.type===`group`){if(n(r.children))return!0;continue}let{href:e}=X(r,t,P);if(ae(r,e,F.pathname))return!0}return!1};return n(e.children)},[e,t,F.pathname])?!0:V??!(H>=8));if(!i(e.visible)||e.requiredPermissions?.length&&!l(e.requiredPermissions))return null;let G=e.requiresObject,q=e.requiresService;if(G&&!d(`object`,G)||q&&!d(`service`,q))return null;if(e.type===`separator`)return(0,z.jsx)(u,{className:`my-2`});if(e.type===`group`){let n=(e.children??[]).slice().sort((e,t)=>(e.order??0)-(t.order??0)),r=ne(e,O,N,k,A,j,M);return(0,z.jsx)(_,{open:U,onOpenChange:W,children:(0,z.jsxs)(c,{children:[(0,z.jsx)(h,{asChild:!0,children:(0,z.jsxs)(m,{className:o(`flex w-full items-center justify-between`,I&&`min-h-[44px] text-[15px] rounded-xl`),children:[r,(0,z.jsx)(g,{className:o(`ml-auto transition-transform`,I?`h-5 w-5`:`h-4 w-4`,U&&`rotate-90`)})]})}),(0,z.jsx)(v,{children:(0,z.jsx)(E,{children:(0,z.jsx)(p,{children:n.map(e=>(0,z.jsx)($,{item:e,basePath:t,evalVis:i,checkPerm:l,checkCap:d,onAction:f,enablePinning:C,onPinToggle:T,resolveObjectLabel:O,resolveDashboardLabel:k,resolveGroupLabel:A,resolveViewLabel:j,resolveItemLabel:M,t:N,templateContext:P},e.id))})})})]})})}if(e.type===`action`){let n=te(e.icon),r=K(e.label,N);return(0,z.jsxs)(x,{children:[D&&(0,z.jsx)(`span`,{className:`absolute left-0.5 top-1/2 -translate-y-1/2 cursor-grab text-muted-foreground`,"aria-label":N?N(`console.nav.dragToReorder`,{defaultValue:`Drag to reorder`}):`Drag to reorder`,...D,children:(0,z.jsx)(y,{className:`h-3.5 w-3.5`})}),(0,z.jsxs)(s,{tooltip:r,onClick:()=>f?.(e),className:L,children:[(0,z.jsx)(n,{className:B}),(0,z.jsx)(`span`,{children:r}),e.badge!=null&&(0,z.jsx)(w,{variant:e.badgeVariant??`default`,className:`ml-auto text-[10px] px-1.5 py-0`,children:e.badge})]}),C&&T&&(0,z.jsx)(S,{showOnHover:!0,onClick:()=>T(e.id,!e.pinned,e,t),"aria-label":N?N(e.pinned?`console.nav.unpinItem`:`console.nav.pinItem`,{defaultValue:e.pinned?`Unpin ${r}`:`Pin ${r}`,name:r}):e.pinned?`Unpin ${r}`:`Pin ${r}`,children:e.pinned?(0,z.jsx)(b,{className:`h-3.5 w-3.5`}):(0,z.jsx)(a,{className:`h-3.5 w-3.5`})})]})}let re=te(e.icon),{href:J,external:ie}=X(e,t,P),Y=ae(e,J,F.pathname),Z=ne(e,O,N,k,A,j,M),Q=(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(re,{className:B}),(0,z.jsx)(`span`,{children:Z}),e.badge!=null&&(0,z.jsx)(w,{variant:e.badgeVariant??`default`,className:`ml-auto text-[10px] px-1.5 py-0`,children:e.badge})]});return(0,z.jsxs)(x,{children:[D&&(0,z.jsx)(`span`,{className:`absolute left-0.5 top-1/2 -translate-y-1/2 cursor-grab text-muted-foreground`,"aria-label":N?N(`console.nav.dragToReorder`,{defaultValue:`Drag to reorder`}):`Drag to reorder`,...D,children:(0,z.jsx)(y,{className:`h-3.5 w-3.5`})}),(0,z.jsx)(s,{asChild:!0,isActive:Y,tooltip:Z,className:L,children:ie?(0,z.jsx)(`a`,{href:J,target:`_blank`,rel:`noopener noreferrer`,children:Q}):(0,z.jsx)(r,{to:J,children:Q})}),C&&T&&(0,z.jsx)(S,{showOnHover:!0,onClick:()=>T(e.id,!e.pinned,e,t),"aria-label":N?N(e.pinned?`console.nav.unpinItem`:`console.nav.pinItem`,{defaultValue:e.pinned?`Unpin ${Z}`:`Pin ${Z}`,name:Z}):e.pinned?`Unpin ${Z}`:`Pin ${Z}`,children:e.pinned?(0,z.jsx)(b,{className:`h-3.5 w-3.5`}):(0,z.jsx)(a,{className:`h-3.5 w-3.5`})})]})}function se({items:e,basePath:t=``,evaluateVisibility:n=q,checkPermission:r=re,checkCapability:i=J,onAction:a,searchQuery:o,enablePinning:s,onPinToggle:l,enableReorder:u,onReorder:d,resolveObjectLabel:f,resolveDashboardLabel:m,resolveGroupLabel:g,resolveViewLabel:_,resolveItemLabel:v,t:y,templateContext:b}){let x=(0,R.useMemo)(()=>o?Z(e,o):e,[e,o]),S=(0,R.useMemo)(()=>ce(x),[x]),w=x.slice().sort((e,t)=>(e.order??0)-(t.order??0)),T=I(D(k,{activationConstraint:{distance:Q}}),D(F)),ee=e=>{let{active:t,over:n}=e;if(!n||t.id===n.id||!d)return;let r=w.findIndex(e=>e.id===t.id),i=w.findIndex(e=>e.id===n.id);r===-1||i===-1||d(A(w,r,i).map((e,t)=>({...e,order:t})))},j={basePath:t,evalVis:n,checkPerm:r,checkCap:i,onAction:a,enablePinning:s,onPinToggle:l,resolveObjectLabel:f,resolveDashboardLabel:m,resolveGroupLabel:g,resolveViewLabel:_,resolveItemLabel:v,t:y,templateContext:b},L=w.some(e=>e.type===`group`),B=S.length>0&&s?(0,z.jsxs)(c,{children:[(0,z.jsxs)(h,{className:`flex items-center gap-1.5`,children:[(0,z.jsx)(C,{className:`h-3.5 w-3.5`}),y?y(`console.nav.favorites`,{defaultValue:`Favorites`}):`Favorites`]}),(0,z.jsx)(E,{children:(0,z.jsx)(p,{children:S.map(e=>(0,z.jsx)($,{item:e,...j},`fav-${e.id}`))})})]}):null;if(!L){let e=w.filter(e=>e.type!==`group`).map(e=>e.id);return(0,z.jsxs)(z.Fragment,{children:[B,(0,z.jsx)(c,{children:(0,z.jsx)(E,{children:u?(0,z.jsx)(O,{sensors:T,collisionDetection:M,onDragEnd:ee,children:(0,z.jsx)(P,{items:e,strategy:N,children:(0,z.jsx)(p,{children:w.map(e=>(0,z.jsx)(oe,{item:e,enableReorder:u,...j},e.id))})})}):(0,z.jsx)(p,{children:w.map(e=>(0,z.jsx)($,{item:e,...j},e.id))})})})]})}let V=[],H=[],U=e=>{if(H.length===0)return;let t=H;H=[],V.push((0,z.jsx)(c,{children:(0,z.jsx)(E,{children:(0,z.jsx)(p,{children:t.map(e=>(0,z.jsx)($,{item:e,...j},e.id))})})},e))};return w.forEach((e,t)=>{e.type===`group`?(U(`leaf-${t}`),V.push((0,z.jsx)($,{item:e,...j},e.id))):H.push(e)}),U(`leaf-end`),(0,z.jsxs)(z.Fragment,{children:[B,V]})}function ce(e){let t=[];for(let n of e)n.pinned&&n.type!==`group`&&n.type!==`separator`&&t.push(n),n.children?.length&&t.push(...ce(n.children));return t}export{X as n,G as r,se as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-slxo-5GC.js";import{Cr as a,Va as o,Wr as s,ki as c}from"./ui-components-BNnJ5f3_.js";import{b as l,v as u,y as d}from"./ReportDefaultInspector-DdZJIfG8.js";var f=e(t(),1);function p(e){if(!e||typeof e!=`object`)return null;let t=e;if(`item`in t){let e=t.item;return!e||typeof e!=`object`?null:Object.keys(e).length>0?e:null}return Object.keys(t).length>0?t:null}async function m(e,t,n,r){await r.metadataClient.save(e,t,n,{mode:`draft`})}async function h(e,t,n,r){return await r.metadataClient.save(e,t,n,{mode:`draft`}),t}async function g(e,t,n){return p(await n.metadataClient.get(e,t,{state:`draft`}))}async function _(e,t,n){await n.metadataClient.reset(e,t,{state:`draft`})}async function v(e,t,n){await n.metadataClient.publish(e,t)}var y=r();function b({type:e,name:t,metadataClient:n,dirty:r,onResume:i,onAfterChange:p,savedSignal:m}){let h=u(),[b,x]=(0,f.useState)(!1),[S,C]=(0,f.useState)(!1),w=(0,f.useRef)(null),T=(0,f.useCallback)(async()=>{if(!t||!n){x(!1);return}let r;try{r=await g(e,t,{metadataClient:n})}catch{x(!1);return}if(x(!!r),r&&i&&w.current!==t){w.current=t;try{i(r)}catch(e){console.error(`[RuntimeDraftBar] Resume draft failed:`,e)}}},[e,t,n,i]);(0,f.useEffect)(()=>{T()},[T]);let E=(0,f.useRef)(m);(0,f.useEffect)(()=>{m!==E.current&&(E.current=m,m&&x(!0))},[m]);let D=(0,f.useCallback)(async()=>{if(t){C(!0);try{await v(e,t,{metadataClient:n}),x(!1),p?.()}catch(e){console.error(`[RuntimeDraftBar] Publish failed:`,e)}finally{C(!1)}}},[e,t,n,p]),O=(0,f.useCallback)(async()=>{if(t&&!(typeof confirm==`function`&&!confirm(l(`engine.edit.discardDraftConfirm`,h,{type:e,name:t})))){C(!0);try{await _(e,t,{metadataClient:n}),x(!1),p?.()}catch(e){console.error(`[RuntimeDraftBar] Discard draft failed:`,e)}finally{C(!1)}}},[e,t,n,p,h]);return b?(0,y.jsxs)(`div`,{className:`mr-auto flex items-center gap-2`,"data-testid":`runtime-draft-bar`,children:[(0,y.jsxs)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,title:d(`engine.edit.draftPending`,h),"data-testid":`runtime-draft-indicator`,children:[`● `,d(`engine.edit.draftPending`,h)]}),(0,y.jsx)(a,{variant:`ghost`,size:`sm`,onClick:O,disabled:S,className:`h-7 w-7 p-0 text-muted-foreground`,title:d(`engine.edit.discardDraft`,h),"aria-label":d(`engine.edit.discardDraft`,h),"data-testid":`runtime-draft-discard`,children:(0,y.jsx)(s,{className:`h-3.5 w-3.5`})}),(0,y.jsx)(a,{size:`sm`,onClick:D,disabled:S||r,className:`h-7 px-2 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:d(r?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,h),"data-testid":`runtime-draft-publish`,children:S?(0,y.jsx)(o,{className:`h-3.5 w-3.5 animate-spin`}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(c,{className:`h-3.5 w-3.5 mr-1`}),d(`engine.edit.publish`,h)]})})]}):null}function x(){let e=i(),{appName:t}=n();return(0,f.useCallback)((n,r)=>{let i=new URLSearchParams;if(r)for(let[e,t]of Object.entries(r))t!=null&&i.set(`filter[${e}]`,String(t));let a=i.toString();e(`${t?`/apps/${t}`:``}/${n}${a?`?${a}`:``}`)},[e,t])}export{m as i,b as n,h as r,x as t};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-slxo-5GC.js";import{Ba as a,Oi as o,Sr as s,Ur as c}from"./ui-components-DlauVk27.js";import{b as l,v as u,y as d}from"./ReportDefaultInspector-DQlvnczB.js";var f=e(t(),1);function p(e){if(!e||typeof e!=`object`)return null;let t=e;if(`item`in t){let e=t.item;return!e||typeof e!=`object`?null:Object.keys(e).length>0?e:null}return Object.keys(t).length>0?t:null}async function m(e,t,n,r){await r.metadataClient.save(e,t,n,{mode:`draft`})}async function h(e,t,n,r){return await r.metadataClient.save(e,t,n,{mode:`draft`}),t}async function g(e,t,n){return p(await n.metadataClient.get(e,t,{state:`draft`}))}async function _(e,t,n){await n.metadataClient.reset(e,t,{state:`draft`})}async function v(e,t,n){await n.metadataClient.publish(e,t)}var y=r();function b({type:e,name:t,metadataClient:n,dirty:r,onResume:i,onAfterChange:p,savedSignal:m}){let h=u(),[b,x]=(0,f.useState)(!1),[S,C]=(0,f.useState)(!1),w=(0,f.useRef)(null),T=(0,f.useCallback)(async()=>{if(!t||!n){x(!1);return}let r;try{r=await g(e,t,{metadataClient:n})}catch{x(!1);return}if(x(!!r),r&&i&&w.current!==t){w.current=t;try{i(r)}catch(e){console.error(`[RuntimeDraftBar] Resume draft failed:`,e)}}},[e,t,n,i]);(0,f.useEffect)(()=>{T()},[T]);let E=(0,f.useRef)(m);(0,f.useEffect)(()=>{m!==E.current&&(E.current=m,m&&x(!0))},[m]);let D=(0,f.useCallback)(async()=>{if(t){C(!0);try{await v(e,t,{metadataClient:n}),x(!1),p?.()}catch(e){console.error(`[RuntimeDraftBar] Publish failed:`,e)}finally{C(!1)}}},[e,t,n,p]),O=(0,f.useCallback)(async()=>{if(t&&!(typeof confirm==`function`&&!confirm(l(`engine.edit.discardDraftConfirm`,h,{type:e,name:t})))){C(!0);try{await _(e,t,{metadataClient:n}),x(!1),p?.()}catch(e){console.error(`[RuntimeDraftBar] Discard draft failed:`,e)}finally{C(!1)}}},[e,t,n,p,h]);return b?(0,y.jsxs)(`div`,{className:`mr-auto flex items-center gap-2`,"data-testid":`runtime-draft-bar`,children:[(0,y.jsxs)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,title:d(`engine.edit.draftPending`,h),"data-testid":`runtime-draft-indicator`,children:[`● `,d(`engine.edit.draftPending`,h)]}),(0,y.jsx)(s,{variant:`ghost`,size:`sm`,onClick:O,disabled:S,className:`h-7 w-7 p-0 text-muted-foreground`,title:d(`engine.edit.discardDraft`,h),"aria-label":d(`engine.edit.discardDraft`,h),"data-testid":`runtime-draft-discard`,children:(0,y.jsx)(c,{className:`h-3.5 w-3.5`})}),(0,y.jsx)(s,{size:`sm`,onClick:D,disabled:S||r,className:`h-7 px-2 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:d(r?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,h),"data-testid":`runtime-draft-publish`,children:S?(0,y.jsx)(a,{className:`h-3.5 w-3.5 animate-spin`}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(o,{className:`h-3.5 w-3.5 mr-1`}),d(`engine.edit.publish`,h)]})})]}):null}function x(){let e=i(),{appName:t}=n();return(0,f.useCallback)((n,r)=>{let i=new URLSearchParams;if(r)for(let[e,t]of Object.entries(r))t!=null&&i.set(`filter[${e}]`,String(t));let a=i.toString();e(`${t?`/apps/${t}`:``}/${n}${a?`?${a}`:``}`)},[e,t])}export{m as i,b as n,h as r,x as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,f as n,p as r,u as i}from"./vendor-react-slxo-5GC.js";import{H as a,M as o,a as s,j as c}from"./framework-CAn_0ZHj.js";import{Pt as l}from"./ui-components-BNnJ5f3_.js";import{r as u}from"./vendor-ui-utils-C1OpMExs.js";import"./AdapterProvider-DVMiVYFP.js";import{a as d}from"./MetadataProvider-A34LFAxj.js";import{o as f,r as p}from"./useRecordApprovals-cQzq7nP6.js";import{n as m}from"./ui-layout-CFpFE-2o.js";import{n as h}from"./appRoute-D5vwtoc_.js";var g=e(t(),1);function _({objectName:e,objectLabel:t,dataSource:r,onEdit:o,onRefresh:c,onConfirm:l,onToast:d}){let f=i(),{appName:p}=n(),{t:m}=s(),h=`/apps/${p}`,{execute:_,loading:v,error:y,runner:b}=a({context:{objectName:e,objectLabel:t||e,baseUrl:h},onConfirm:l,onToast:d});return(0,g.useEffect)(()=>{b.registerHandler(`create`,async()=>(o?.(null),{success:!0})),b.registerHandler(`delete`,async n=>{let i=Array.isArray(n.params?.records)?n.params.records.filter(e=>e?.id!=null):null;if(i&&i.length>1){let n=await Promise.allSettled(i.map(t=>r.delete(e,t.id))),a=n.filter(e=>e.status===`rejected`).length,o=n.length-a;return c?.(),a===0?(u.success(m(`objectActions.bulkDeleteSuccess`,{count:o,label:t||e,defaultValue:`Deleted ${o} ${t||e} records`})),{success:!0,reload:!0}):(u.error(m(`objectActions.bulkDeletePartial`,{succeeded:o,failed:a,defaultValue:`${o} deleted, ${a} failed`})),{success:!1,error:`${a} failed`})}let a=n.params?.recordId??n.params?.record?.id??i?.[0]?.id??n.recordId;if(!a)return{success:!1,error:m(`objectActions.noRecordId`)};try{return await r.delete(e,a),c?.(),u.success(m(`objectActions.deleteSuccess`,{label:t||e})),{success:!0,reload:!0}}catch(n){return u.error(m(`objectActions.deleteFailed`,{label:t||e}),{description:n.message}),{success:!1,error:n.message}}}),b.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&f(t.startsWith(`/`)?t:`${h}/${t}`),{success:!0}}),b.registerHandler(`refresh`,async()=>(c?.(),{success:!0,reload:!0}))},[b,e,r,o,c,f,h,m,t]),{execute:_,create:(0,g.useCallback)(()=>{o?.(null)},[o]),deleteRecord:(0,g.useCallback)(async e=>_({type:`delete`,confirmText:m(`objectActions.deleteConfirm`),params:{recordId:e}}),[_,m]),navigateToView:(0,g.useCallback)(t=>{f(`${h}/${e}/view/${t}`)},[f,h,e]),navigateToRecord:(0,g.useCallback)(t=>{f(`${h}/${e}/record/${encodeURIComponent(t)}`)},[f,h,e]),loading:v,error:y}}function v(e){return e==null?[]:Array.isArray(e)?e:[e]}function y(e,t){let{alias:n,value:i=`1`,replace:a=!0}=t??{},[o,s]=r(),c=(0,g.useMemo)(()=>v(n),[n]),l=(0,g.useCallback)(t=>t.get(e)===i||c.some(e=>t.get(e)===i),[e,i,c]),u=l(o),d=(0,g.useCallback)(t=>{if(t===l(o))return;let n=new URLSearchParams(o);if(t){n.set(e,i);for(let e of c)n.delete(e)}else{n.delete(e);for(let e of c)n.delete(e)}s(n,{replace:a})},[l,o,s,e,i,c,a]);return{open:u,setOpen:d,openOverlay:(0,g.useCallback)(()=>d(!0),[d]),closeOverlay:(0,g.useCallback)(()=>d(!1),[d]),toggleOverlay:(0,g.useCallback)(()=>{s(t=>{let n=new URLSearchParams(t);if(l(n)){n.delete(e);for(let e of c)n.delete(e)}else{n.set(e,i);for(let e of c)n.delete(e)}return n},{replace:a})},[s,l,e,i,c,a])}}var b=20;function x(e,t=``){let{href:n,external:r}=m(e,t);return r?n:!n||n===`#`?``:n}function S(e){return`nav:${e}`}function C(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=p(),a=(0,g.useCallback)((e,i,a,o)=>{let s=S(e);i?(a&&t({id:s,label:a.label,href:x(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,g.useCallback)(e=>i.has(e),[i]),s=(0,g.useCallback)(e=>{if(i.size===0){let t=!1;for(let n of e)if(n.pinned){t=!0;break}if(!t)return e}let t=0,n=e=>e.map(e=>{let r=i.has(e.id)&&t<b;r&&t++;let a=e.children?.length?n(e.children):e.children;return r!==(e.pinned??!1)||a!==e.children?{...e,pinned:r,children:a}:e});return n(e)},[i]),c=(0,g.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,g.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}var w=768,T=1024;function ee(){let{setOpen:e,isMobile:t}=l(),n=(0,g.useRef)(e);(0,g.useEffect)(()=>{n.current=e},[e]),(0,g.useEffect)(()=>{if(t)return;let e=!1;function r(){let t=window.innerWidth,r=t>=w&&t<T;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}function te(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,enabled:e.enabled,fields:t,relationships:e.relationships}}function ne(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var re=class{adapter;constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=te(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(ne)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function ie(){let e=c();return(0,g.useMemo)(()=>e?new re(e):null,[e])}var E=0;function D(e=`nav`){return`${e}_${Date.now()}_${++E}`}function O(e,t){return[...e,t]}function k(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:k(e.children,t,n)}:e)}function A(e,t,n,r){return e.map(e=>{let i=e;return t===`page`&&e.type===`page`&&e.pageName===n?i={...e,pageName:r}:t===`dashboard`&&e.type===`dashboard`&&e.dashboardName===n&&(i={...e,dashboardName:r}),i.children&&i.children.length>0?{...i,children:A(i.children,t,n,r)}:i})}function j(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function ae(e){return typeof e==`string`&&e.startsWith(`sys_`)}function oe(e){if(!e||typeof e!=`object`)return!1;let t=e;return t._packageId!=null||t._provenance===`package`?!0:ae(t.name)}function M(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t._lock??t.protection?.lock;return n!==`full`&&n!==`no-overlay`}function N(){let e=c(),{apps:t,refresh:n}=o(),{t:r}=s(),i=(0,g.useRef)(e);i.current=e;let a=(0,g.useRef)(n);a.current=n;let l=(0,g.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),d=(0,g.useCallback)(e=>h(t,e),[t]),f=(0,g.useCallback)(async(e,t,n)=>{let i=d(e);if(!i)return;let a=i.navigation??[],o=O(a,{id:D(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),s={...i,navigation:o};try{await l(e,s),u.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...i,navigation:a}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),p=(0,g.useCallback)(async(e,t,n)=>{let i=d(e);if(!i)return;let a=i.navigation??[],o=O(a,{id:D(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),s={...i,navigation:o};try{await l(e,s),u.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...i,navigation:a}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),m=(0,g.useCallback)(async(e,t)=>{let n=d(e);if(!n)return;let i=n.navigation??[],a=k(i,`page`,t);if(j(a,i))return;let o={...n,navigation:a};try{await l(e,o),u.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...n,navigation:i}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),_=(0,g.useCallback)(async(e,t)=>{let n=d(e);if(!n)return;let i=n.navigation??[],a=k(i,`dashboard`,t);if(j(a,i))return;let o={...n,navigation:a};try{await l(e,o),u.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...n,navigation:i}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),v=(0,g.useCallback)(async(e,t,n)=>{let i=d(e);if(!i)return;let a=i.navigation??[],o=A(a,`page`,t,n);if(j(o,a))return;let s={...i,navigation:o};try{await l(e,s),u.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...i,navigation:a}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),y=(0,g.useCallback)(async(e,t,n)=>{let i=d(e);if(!i)return;let a=i.navigation??[],o=A(a,`dashboard`,t,n);if(j(o,a))return;let s={...i,navigation:o};try{await l(e,s),u.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...i,navigation:a}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),b=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:f,syncDashboardCreated:p,syncPageDeleted:m,syncDashboardDeleted:_,syncPageRenamed:v,syncDashboardRenamed:y,syncPageCreatedAllApps:(0,g.useCallback)(async(e,n)=>{for(let r of t){let t=b(r);!t||!M(r)||await f(t,e,n)}},[t,f]),syncDashboardCreatedAllApps:(0,g.useCallback)(async(e,n)=>{for(let r of t){let t=b(r);!t||!M(r)||await p(t,e,n)}},[t,p]),syncPageDeletedAllApps:(0,g.useCallback)(async e=>{for(let n of t){let t=b(n);!t||!M(n)||await m(t,e)}},[t,m]),syncDashboardDeletedAllApps:(0,g.useCallback)(async e=>{for(let n of t){let t=b(n);!t||!M(n)||await _(t,e)}},[t,_]),syncPageRenamedAllApps:(0,g.useCallback)(async(e,n)=>{for(let r of t){let t=b(r);!t||!M(r)||await v(t,e,n)}},[t,v]),syncDashboardRenamedAllApps:(0,g.useCallback)(async(e,n)=>{for(let r of t){let t=b(r);!t||!M(r)||await y(t,e,n)}},[t,y])}}function P(){let{pages:e,dashboards:t,apps:n,getTypeStatus:r}=o(),i=c(),a=(0,g.useRef)(i);a.current=i;let s=d(),{syncPageCreated:l,syncDashboardCreated:u,syncPageDeleted:f,syncDashboardDeleted:p}=N(),m=(0,g.useRef)(null),h=(0,g.useRef)(null),_=(0,g.useRef)(0),v=(0,g.useRef)(!1),y=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,g.useEffect)(()=>{if(v.current)return;if(s){m.current=null,h.current=null;return}if(r&&(r(`page`)!==`ready`||r(`dashboard`)!==`ready`))return;let i=e=>new Set(e.filter(e=>!oe(e)).map(e=>e?.name).filter(e=>typeof e==`string`&&e.length>0)),a=i(e??[]),o=i(t??[]),c=m.current,d=h.current;if(c===null||d===null){m.current=a,h.current=o;return}let g=[...a].filter(e=>!c.has(e)),b=[...c].filter(e=>!a.has(e)),x=[...o].filter(e=>!d.has(e)),S=[...d].filter(e=>!o.has(e));if(g.length===0&&b.length===0&&x.length===0&&S.length===0){m.current=a,h.current=o;return}let C=++_.current;v.current=!0;let w=!1;return(async()=>{try{for(let e of n){if(w||_.current!==C)break;let t=y(e);if(!(!t||!M(e))){for(let e of g){if(w)break;await l(t,e)}for(let e of b){if(w)break;await f(t,e)}for(let e of x){if(w)break;await u(t,e)}for(let e of S){if(w)break;await p(t,e)}}}}finally{_.current===C&&(m.current=a,h.current=o,v.current=!1)}})(),()=>{w=!0}},[e,t,n,s,r,l,u,f,p]),null}var F=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function I(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function L(e){try{return decodeURIComponent(e)}catch{return e}}function se({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=f(),o=(0,g.useRef)(n);o.current=n,(0,g.useEffect)(()=>{if(i||!t)return;let n=e.split(`/`).filter(Boolean);if(n[0]!==r||n[1]!==t)return;let s=n[2],c=n[3],l=`/${r}/${t}`;if(s===`metadata`){let e=n[3],t=n[4];e&&t&&t!==`new`&&a({id:`metadata:${e}:${L(t)}`,label:L(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!F.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:I(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:I(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:I(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}function ce(e){return{status:`drafted`,drafted:e.items,...e.summary?{summary:e.summary}:{},...e.packageId?{packageId:e.packageId}:{},...e.autoPublishable?{autoPublishable:!0}:{},...e.failedCount?{failed:Array.from({length:e.failedCount},()=>null)}:{},...e.materialized?{materialized:!0}:{},...e.verification?{verification:e.verification}:{},...e.issues&&e.issues.length?{issues:e.issues}:{},...e.nextSteps&&e.nextSteps.length?{nextSteps:e.nextSteps}:{}}}function le(e){return{status:`blueprint_proposed`,...e.summary?{summary:e.summary}:{},counts:e.counts,questions:e.questions,...e.targetApp?{targetApp:e.targetApp}:{},blueprint:{objects:e.objects.map(e=>({name:e.name,...e.label?{label:e.label}:{},fields:Array.from({length:e.fieldCount},()=>null)})),assumptions:e.assumptions}}}var R=`objectstack:ai-chat-conversation-id`,z=`objectstack:ai-chat-messages`;function B(e,t){return t?`${R}:${e}:${t}`:`${R}:${e}`}function V(e){try{return localStorage.getItem(e)??void 0}catch{return}}function H(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function U(e){return`${z}:${e}`}function W(e){try{let t=localStorage.getItem(U(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&(e.role===`user`||e.role===`assistant`||e.role===`system`)&&Array.isArray(e.parts)):[]}catch{return[]}}function G(e,t){if(e)try{if(t.length===0){localStorage.removeItem(U(e));return}localStorage.setItem(U(e),JSON.stringify(t))}catch{}}function ue(e){return e.map(e=>{let t=[];if(e.content&&t.push({type:`text`,text:e.content}),e.role===`assistant`)for(let n of e.toolInvocations??[]){let e=n.draftReview?ce(n.draftReview):n.proposedPlan?le(n.proposedPlan):void 0;t.push({type:`tool-${n.toolName}`,toolCallId:n.toolCallId,toolName:n.toolName,state:n.state??(n.errorText?`output-error`:`output-available`),...n.errorText?{errorText:n.errorText}:{},...e===void 0?{}:{output:e}})}if(t.length!==0)return{id:e.id,role:e.role,parts:t}}).filter(e=>!!e)}function K(e){return typeof e==`string`?e?[{type:`text`,text:e}]:[]:Array.isArray(e)?e.map(e=>{if(typeof e==`string`)return e?{type:`text`,text:e}:void 0;if(e&&typeof e==`object`&&`type`in e&&typeof e.type==`string`)return e;if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return{type:`text`,text:e.text}}).filter(e=>!!e):e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts)?K(e.parts):[]}function de(e,t){for(let n of K(e)){let e=typeof n.toolCallId==`string`?n.toolCallId:void 0;if(!e)continue;let r=t.get(e);if(!r)continue;let i=n.output??n.result;if(i===void 0)continue;r.output=i;let a=n.errorText;r.state=n.isError||typeof a==`string`?`output-error`:`output-available`,typeof a==`string`&&(r.errorText=a)}}function q(e){if(!e)return[];let t=[],n=new Map;return e.forEach((e,r)=>{let i=e.role;if(i===`tool`){de(e.content,n);return}if(i!==`user`&&i!==`assistant`&&i!==`system`)return;let a=K(e.content);if(a.length!==0){if(i===`assistant`)for(let e of a){e.type===`tool-call`&&typeof e.toolName==`string`&&e.toolName&&(e.type=`tool-${e.toolName}`);let t=typeof e.toolCallId==`string`?e.toolCallId:void 0;t&&(e.type===`tool-call`||e.type.startsWith(`tool-`))&&n.set(t,e)}t.push({id:e.id??`msg-${r}`,role:i,parts:a})}}),t}function J(e){if(!(typeof e!=`string`||!e))try{let t=JSON.parse(e);return Array.isArray(t)?t:void 0}catch{return}}function fe(e){return e?e.map(e=>{let t=e.id,n=typeof e.content==`string`?e.content:``;if(e.role===`assistant`){let r=J(e.tool_calls);if(r&&r.length>0){let e=[];return n&&e.push({type:`text`,text:n}),e.push(...r),{id:t,role:`assistant`,content:e}}return{id:t,role:`assistant`,content:n}}if(e.role===`tool`){let r=J(e.content);return r&&r.length>0&&r[0]?.type===`tool-result`?{id:t,role:`tool`,content:r}:{id:t,role:`tool`,content:[{type:`tool-result`,toolCallId:e.tool_call_id??``,toolName:`unknown`,output:{type:`text`,value:n}}]}}return{id:t,role:e.role,content:n}}):[]}async function Y(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(n.status===404||n.status===403)return null;if(!n.ok)throw Error(`GET conversation failed: ${n.status}`);return await n.json()}async function X(e){let t=await fetch(`${e}/conversations`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error(`POST conversation failed: ${t.status}`);return await t.json()}async function pe(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function Z(e){let{userId:t,scope:n,apiBase:r,activeId:i,forceNew:a,resumeMode:o=`resume`}=e,[s,c]=(0,g.useState)(void 0),[l,u]=(0,g.useState)([]),[d,f]=(0,g.useState)(!!t),p=(0,g.useRef)(!0),m=(0,g.useRef)(void 0),h=(0,g.useRef)(void 0);(0,g.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]),(0,g.useEffect)(()=>{if(!t){c(void 0),u([]),f(!1),m.current=void 0,h.current=void 0;return}let e=h.current!==n;if(!i&&!a&&!e&&m.current===t&&s)return;let l=!1,d=B(t,n);return!i&&(a||e&&m.current===t)&&(c(void 0),u([])),f(!0),(async()=>{try{if(i){let e=await Y(r,i);if(l)return;if(e){H(d,e.id),c(e.id);let r=q(e.messages);u(r.length>0?r:W(e.id)),m.current=t,h.current=n;return}H(d,void 0),G(i,[])}else if(!a){let e=V(d);if(e){let i=await Y(r,e);if(l)return;if(i){let e=q(i.messages);if(o!==`fresh`||e.length===0){c(i.id),u(o===`fresh`?[]:e.length>0?e:W(i.id)),m.current=t,h.current=n;return}}else H(d,void 0),G(e,[])}}let e=await X(r);if(l)return;H(d,e.id),c(e.id),u(q(e.messages)),m.current=t,h.current=n}catch{l||(c(void 0),u([]))}finally{l||f(!1)}})(),()=>{l=!0}},[t,n,r,i,a,o]);let _=(0,g.useCallback)(async()=>{if(!t)return;let e=B(t,n);f(!0);try{s&&await pe(r,s),G(s,[]),H(e,void 0);let t=await X(r);if(H(e,t.id),G(t.id,[]),!p.current)return;c(t.id),u([])}catch{p.current&&(c(void 0),u([]))}finally{p.current&&f(!1)}},[s,t,n,r]),v=(0,g.useCallback)(async()=>{if(!t)return;let e=B(t,n);f(!0);try{let i=await X(r);if(H(e,i.id),G(i.id,[]),!p.current)return;c(i.id),u([]),m.current=t,h.current=n}catch{}finally{p.current&&f(!1)}},[t,n,r]);return{conversationId:s,conversationScope:h.current,initialMessages:l,isLoading:d,reset:_,startNew:v}}var me=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function he(e){let t=e?.trim().toLowerCase();return!t||me.has(t)}function ge(e){let t=e.messages;if(!t||t.length===0)return;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`user`){let e=Q(n.content);if(e)return e}}let n=t[t.length-1];return Q(n?.content)}function Q(e){if(typeof e==`string`)return e.slice(0,140);if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return e.text.slice(0,140);if(e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts))return Q(e.parts);if(Array.isArray(e)){let t=e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``);return t?t.slice(0,140):void 0}}function $(e){let t=e.title?.trim(),n=ge(e)??Q(e.preview);return{id:e.id,title:he(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function _e(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return $(`conversation`in r&&r.conversation?r.conversation:r)}function ve(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,g.useState)([]),[s,c]=(0,g.useState)(!!t),[l,u]=(0,g.useState)(void 0),[d,f]=(0,g.useState)(0),p=(0,g.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,g.useCallback)(async e=>{try{await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`})}finally{o(t=>t.filter(t=>t.id!==e))}},[n]),h=(0,g.useCallback)(async(e,t)=>{let r=t.trim();o(t=>t.map(t=>t.id===e?{...t,title:r||void 0}:t));let i=await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r})});if(!i.ok)throw f(e=>e+1),Error(`PATCH conversation failed: ${i.status}`)},[n]);return(0,g.useEffect)(()=>{if(!t){o([]),c(!1),u(void 0);return}let e=!1;return c(!0),u(void 0),(async()=>{try{let t=await fetch(`${n}/conversations?limit=${encodeURIComponent(String(r))}`,{credentials:`include`});if(!t.ok)throw Error(`GET conversations failed: ${t.status}`);let i=await t.json(),a=Array.isArray(i)?i:i.conversations??i.items??[];if(e)return;let s=a.map($).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));o(s);let c=s.filter(e=>!e.title&&!e.preview).slice(0,20);if(c.length>0){let t=await Promise.all(c.map(e=>_e(n,e.id).catch(()=>void 0)));if(e)return;let r=new Map(t.filter(e=>!!(e?.preview||e?.title)).map(e=>[e.id,e]));r.size>0&&o(e=>e.map(e=>{let t=r.get(e.id);return t?{...e,title:e.title??t.title,preview:e.preview??t.preview}:e}))}}catch(t){if(e)return;u(t instanceof Error?t:Error(String(t))),o([])}finally{e||c(!1)}})(),()=>{e=!0}},[t,n,r,d,i]),{conversations:a,isLoading:s,error:l,refetch:p,remove:m,rename:h}}async function ye(e){let t=await fetch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`_drafts HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.drafts??n?.data?.drafts??[];return Array.isArray(r)?r.length:0}function be(e){if(!e||e.length===0)return!1;let t=e[e.length-1];return!t||t.role!==`assistant`?!1:t.parts.some(e=>e.type===`text`&&String(e.text??``).trim().length>0)}function xe(e){let{chatApi:t,conversationId:n}=e,[r,i]=(0,g.useState)(!1),a=(0,g.useRef)(void 0);return{errorSuppressed:r,handleChatError:(0,g.useCallback)(async e=>{if(e?.notSent){i(!1);return}let r=t?.replace(/\/agents\/[^/]+\/chat$/,``);if(!n||!r){i(!1);return}try{let e=q((await Y(r,n))?.messages);if(be(e)&&a.current){a.current(e),i(!0);return}}catch{}i(!1)},[n,t]),setMessagesRef:a,resetSuppression:(0,g.useCallback)(()=>i(!1),[])}}export{Y as a,Z as c,P as d,ie as f,_ as g,y as h,fe as i,G as l,C as m,ye as n,ue as o,ee as p,ve as r,q as s,xe as t,se as u};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,f as n,p as r,u as i}from"./vendor-react-slxo-5GC.js";import{N as a,P as o,W as s,a as c}from"./framework-Bn8ShCi0.js";import{Nt as l}from"./ui-components-DlauVk27.js";import{r as u}from"./vendor-ui-utils-C1OpMExs.js";import"./AdapterProvider-BIB-F0Qa.js";import{a as d}from"./MetadataProvider-DlGQbrYS.js";import{o as f,r as p}from"./useRecordApprovals-B_jxSZvZ.js";import{n as m}from"./ui-layout-DnHby9xU.js";import{n as h}from"./appRoute-D5vwtoc_.js";var g=e(t(),1);function _({objectName:e,objectLabel:t,dataSource:r,onEdit:a,onRefresh:o,onConfirm:l,onToast:d}){let f=i(),{appName:p}=n(),{t:m}=c(),h=`/apps/${p}`,{execute:_,loading:v,error:y,runner:b}=s({context:{objectName:e,objectLabel:t||e,baseUrl:h},onConfirm:l,onToast:d});return(0,g.useEffect)(()=>{b.registerHandler(`create`,async()=>(a?.(null),{success:!0})),b.registerHandler(`delete`,async n=>{let i=Array.isArray(n.params?.records)?n.params.records.filter(e=>e?.id!=null):null;if(i&&i.length>1){let n=await Promise.allSettled(i.map(t=>r.delete(e,t.id))),a=n.filter(e=>e.status===`rejected`).length,s=n.length-a;return o?.(),a===0?(u.success(m(`objectActions.bulkDeleteSuccess`,{count:s,label:t||e,defaultValue:`Deleted ${s} ${t||e} records`})),{success:!0,reload:!0}):(u.error(m(`objectActions.bulkDeletePartial`,{succeeded:s,failed:a,defaultValue:`${s} deleted, ${a} failed`})),{success:!1,error:`${a} failed`})}let a=n.params?.recordId??n.params?.record?.id??i?.[0]?.id??n.recordId;if(!a)return{success:!1,error:m(`objectActions.noRecordId`)};try{return await r.delete(e,a),o?.(),u.success(m(`objectActions.deleteSuccess`,{label:t||e})),{success:!0,reload:!0}}catch(n){return u.error(m(`objectActions.deleteFailed`,{label:t||e}),{description:n.message}),{success:!1,error:n.message}}}),b.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&f(t.startsWith(`/`)?t:`${h}/${t}`),{success:!0}}),b.registerHandler(`refresh`,async()=>(o?.(),{success:!0,reload:!0}))},[b,e,r,a,o,f,h,m,t]),{execute:_,create:(0,g.useCallback)(()=>{a?.(null)},[a]),deleteRecord:(0,g.useCallback)(async e=>_({type:`delete`,confirmText:m(`objectActions.deleteConfirm`),params:{recordId:e}}),[_,m]),navigateToView:(0,g.useCallback)(t=>{f(`${h}/${e}/view/${t}`)},[f,h,e]),navigateToRecord:(0,g.useCallback)(t=>{f(`${h}/${e}/record/${encodeURIComponent(t)}`)},[f,h,e]),loading:v,error:y}}function v(e){return e==null?[]:Array.isArray(e)?e:[e]}function y(e,t){let{alias:n,value:i=`1`,replace:a=!0}=t??{},[o,s]=r(),c=(0,g.useMemo)(()=>v(n),[n]),l=(0,g.useCallback)(t=>t.get(e)===i||c.some(e=>t.get(e)===i),[e,i,c]),u=l(o),d=(0,g.useCallback)(t=>{if(t===l(o))return;let n=new URLSearchParams(o);if(t){n.set(e,i);for(let e of c)n.delete(e)}else{n.delete(e);for(let e of c)n.delete(e)}s(n,{replace:a})},[l,o,s,e,i,c,a]);return{open:u,setOpen:d,openOverlay:(0,g.useCallback)(()=>d(!0),[d]),closeOverlay:(0,g.useCallback)(()=>d(!1),[d]),toggleOverlay:(0,g.useCallback)(()=>{s(t=>{let n=new URLSearchParams(t);if(l(n)){n.delete(e);for(let e of c)n.delete(e)}else{n.set(e,i);for(let e of c)n.delete(e)}return n},{replace:a})},[s,l,e,i,c,a])}}var b=20;function x(e,t=``){let{href:n,external:r}=m(e,t);return r?n:!n||n===`#`?``:n}function S(e){return`nav:${e}`}function C(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=p(),a=(0,g.useCallback)((e,i,a,o)=>{let s=S(e);i?(a&&t({id:s,label:a.label,href:x(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,g.useCallback)(e=>i.has(e),[i]),s=(0,g.useCallback)(e=>{if(i.size===0){let t=!1;for(let n of e)if(n.pinned){t=!0;break}if(!t)return e}let t=0,n=e=>e.map(e=>{let r=i.has(e.id)&&t<b;r&&t++;let a=e.children?.length?n(e.children):e.children;return r!==(e.pinned??!1)||a!==e.children?{...e,pinned:r,children:a}:e});return n(e)},[i]),c=(0,g.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,g.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}var w=768,T=1024;function ee(){let{setOpen:e,isMobile:t}=l(),n=(0,g.useRef)(e);(0,g.useEffect)(()=>{n.current=e},[e]),(0,g.useEffect)(()=>{if(t)return;let e=!1;function r(){let t=window.innerWidth,r=t>=w&&t<T;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}function te(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,enabled:e.enabled,fields:t,relationships:e.relationships}}function ne(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var re=class{adapter;constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=te(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(ne)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function ie(){let e=a();return(0,g.useMemo)(()=>e?new re(e):null,[e])}var E=0;function D(e=`nav`){return`${e}_${Date.now()}_${++E}`}function O(e,t){return[...e,t]}function k(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:k(e.children,t,n)}:e)}function A(e,t,n,r){return e.map(e=>{let i=e;return t===`page`&&e.type===`page`&&e.pageName===n?i={...e,pageName:r}:t===`dashboard`&&e.type===`dashboard`&&e.dashboardName===n&&(i={...e,dashboardName:r}),i.children&&i.children.length>0?{...i,children:A(i.children,t,n,r)}:i})}function j(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function ae(e){return typeof e==`string`&&e.startsWith(`sys_`)}function oe(e){if(!e||typeof e!=`object`)return!1;let t=e;return t._packageId!=null||t._provenance===`package`?!0:ae(t.name)}function M(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t._lock??t.protection?.lock;return n!==`full`&&n!==`no-overlay`}function N(){let e=a(),{apps:t,refresh:n}=o(),{t:r}=c(),i=(0,g.useRef)(e);i.current=e;let s=(0,g.useRef)(n);s.current=n;let l=(0,g.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await s.current?.()},[]),d=(0,g.useCallback)(e=>h(t,e),[t]),f=(0,g.useCallback)(async(e,t,n)=>{let i=d(e);if(!i)return;let a=i.navigation??[],o=O(a,{id:D(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),s={...i,navigation:o};try{await l(e,s),u.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...i,navigation:a}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),p=(0,g.useCallback)(async(e,t,n)=>{let i=d(e);if(!i)return;let a=i.navigation??[],o=O(a,{id:D(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),s={...i,navigation:o};try{await l(e,s),u.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...i,navigation:a}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),m=(0,g.useCallback)(async(e,t)=>{let n=d(e);if(!n)return;let i=n.navigation??[],a=k(i,`page`,t);if(j(a,i))return;let o={...n,navigation:a};try{await l(e,o),u.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...n,navigation:i}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),_=(0,g.useCallback)(async(e,t)=>{let n=d(e);if(!n)return;let i=n.navigation??[],a=k(i,`dashboard`,t);if(j(a,i))return;let o={...n,navigation:a};try{await l(e,o),u.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...n,navigation:i}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),v=(0,g.useCallback)(async(e,t,n)=>{let i=d(e);if(!i)return;let a=i.navigation??[],o=A(a,`page`,t,n);if(j(o,a))return;let s={...i,navigation:o};try{await l(e,s),u.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...i,navigation:a}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),y=(0,g.useCallback)(async(e,t,n)=>{let i=d(e);if(!i)return;let a=i.navigation??[],o=A(a,`dashboard`,t,n);if(j(o,a))return;let s={...i,navigation:o};try{await l(e,s),u.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await l(e,{...i,navigation:a}),u.info(r(`navigationSync.undone`))}catch{u.error(r(`navigationSync.undoFailed`))}}}})}catch{u.error(r(`navigationSync.updateFailed`))}},[d,l,r]),b=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:f,syncDashboardCreated:p,syncPageDeleted:m,syncDashboardDeleted:_,syncPageRenamed:v,syncDashboardRenamed:y,syncPageCreatedAllApps:(0,g.useCallback)(async(e,n)=>{for(let r of t){let t=b(r);!t||!M(r)||await f(t,e,n)}},[t,f]),syncDashboardCreatedAllApps:(0,g.useCallback)(async(e,n)=>{for(let r of t){let t=b(r);!t||!M(r)||await p(t,e,n)}},[t,p]),syncPageDeletedAllApps:(0,g.useCallback)(async e=>{for(let n of t){let t=b(n);!t||!M(n)||await m(t,e)}},[t,m]),syncDashboardDeletedAllApps:(0,g.useCallback)(async e=>{for(let n of t){let t=b(n);!t||!M(n)||await _(t,e)}},[t,_]),syncPageRenamedAllApps:(0,g.useCallback)(async(e,n)=>{for(let r of t){let t=b(r);!t||!M(r)||await v(t,e,n)}},[t,v]),syncDashboardRenamedAllApps:(0,g.useCallback)(async(e,n)=>{for(let r of t){let t=b(r);!t||!M(r)||await y(t,e,n)}},[t,y])}}function P(){let{pages:e,dashboards:t,apps:n,getTypeStatus:r}=o(),i=a(),s=(0,g.useRef)(i);s.current=i;let c=d(),{syncPageCreated:l,syncDashboardCreated:u,syncPageDeleted:f,syncDashboardDeleted:p}=N(),m=(0,g.useRef)(null),h=(0,g.useRef)(null),_=(0,g.useRef)(0),v=(0,g.useRef)(!1),y=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,g.useEffect)(()=>{if(v.current)return;if(c){m.current=null,h.current=null;return}if(r&&(r(`page`)!==`ready`||r(`dashboard`)!==`ready`))return;let i=e=>new Set(e.filter(e=>!oe(e)).map(e=>e?.name).filter(e=>typeof e==`string`&&e.length>0)),a=i(e??[]),o=i(t??[]),s=m.current,d=h.current;if(s===null||d===null){m.current=a,h.current=o;return}let g=[...a].filter(e=>!s.has(e)),b=[...s].filter(e=>!a.has(e)),x=[...o].filter(e=>!d.has(e)),S=[...d].filter(e=>!o.has(e));if(g.length===0&&b.length===0&&x.length===0&&S.length===0){m.current=a,h.current=o;return}let C=++_.current;v.current=!0;let w=!1;return(async()=>{try{for(let e of n){if(w||_.current!==C)break;let t=y(e);if(!(!t||!M(e))){for(let e of g){if(w)break;await l(t,e)}for(let e of b){if(w)break;await f(t,e)}for(let e of x){if(w)break;await u(t,e)}for(let e of S){if(w)break;await p(t,e)}}}}finally{_.current===C&&(m.current=a,h.current=o,v.current=!1)}})(),()=>{w=!0}},[e,t,n,c,r,l,u,f,p]),null}var F=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function I(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function L(e){try{return decodeURIComponent(e)}catch{return e}}function se({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=f(),o=(0,g.useRef)(n);o.current=n,(0,g.useEffect)(()=>{if(i||!t)return;let n=e.split(`/`).filter(Boolean);if(n[0]!==r||n[1]!==t)return;let s=n[2],c=n[3],l=`/${r}/${t}`;if(s===`metadata`){let e=n[3],t=n[4];e&&t&&t!==`new`&&a({id:`metadata:${e}:${L(t)}`,label:L(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!F.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:I(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:I(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:I(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}function ce(e){return{status:`drafted`,drafted:e.items,...e.summary?{summary:e.summary}:{},...e.packageId?{packageId:e.packageId}:{},...e.autoPublishable?{autoPublishable:!0}:{},...e.failedCount?{failed:Array.from({length:e.failedCount},()=>null)}:{},...e.materialized?{materialized:!0}:{},...e.verification?{verification:e.verification}:{},...e.issues&&e.issues.length?{issues:e.issues}:{},...e.nextSteps&&e.nextSteps.length?{nextSteps:e.nextSteps}:{}}}function le(e){return{status:`blueprint_proposed`,...e.summary?{summary:e.summary}:{},counts:e.counts,questions:e.questions,...e.targetApp?{targetApp:e.targetApp}:{},blueprint:{objects:e.objects.map(e=>({name:e.name,...e.label?{label:e.label}:{},fields:Array.from({length:e.fieldCount},()=>null)})),assumptions:e.assumptions}}}var R=`objectstack:ai-chat-conversation-id`,z=`objectstack:ai-chat-messages`;function B(e,t){return t?`${R}:${e}:${t}`:`${R}:${e}`}function V(e){try{return localStorage.getItem(e)??void 0}catch{return}}function H(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function U(e){return`${z}:${e}`}function W(e){try{let t=localStorage.getItem(U(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&(e.role===`user`||e.role===`assistant`||e.role===`system`)&&Array.isArray(e.parts)):[]}catch{return[]}}function G(e,t){if(e)try{if(t.length===0){localStorage.removeItem(U(e));return}localStorage.setItem(U(e),JSON.stringify(t))}catch{}}function ue(e){return e.map(e=>{let t=[];if(e.content&&t.push({type:`text`,text:e.content}),e.role===`assistant`)for(let n of e.toolInvocations??[]){let e=n.draftReview?ce(n.draftReview):n.proposedPlan?le(n.proposedPlan):void 0;t.push({type:`tool-${n.toolName}`,toolCallId:n.toolCallId,toolName:n.toolName,state:n.state??(n.errorText?`output-error`:`output-available`),...n.errorText?{errorText:n.errorText}:{},...e===void 0?{}:{output:e}})}if(t.length!==0)return{id:e.id,role:e.role,parts:t}}).filter(e=>!!e)}function K(e){return typeof e==`string`?e?[{type:`text`,text:e}]:[]:Array.isArray(e)?e.map(e=>{if(typeof e==`string`)return e?{type:`text`,text:e}:void 0;if(e&&typeof e==`object`&&`type`in e&&typeof e.type==`string`)return e;if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return{type:`text`,text:e.text}}).filter(e=>!!e):e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts)?K(e.parts):[]}function de(e,t){for(let n of K(e)){let e=typeof n.toolCallId==`string`?n.toolCallId:void 0;if(!e)continue;let r=t.get(e);if(!r)continue;let i=n.output??n.result;if(i===void 0)continue;r.output=i;let a=n.errorText;r.state=n.isError||typeof a==`string`?`output-error`:`output-available`,typeof a==`string`&&(r.errorText=a)}}function q(e){if(!e)return[];let t=[],n=new Map;return e.forEach((e,r)=>{let i=e.role;if(i===`tool`){de(e.content,n);return}if(i!==`user`&&i!==`assistant`&&i!==`system`)return;let a=K(e.content);if(a.length!==0){if(i===`assistant`)for(let e of a){e.type===`tool-call`&&typeof e.toolName==`string`&&e.toolName&&(e.type=`tool-${e.toolName}`);let t=typeof e.toolCallId==`string`?e.toolCallId:void 0;t&&(e.type===`tool-call`||e.type.startsWith(`tool-`))&&n.set(t,e)}t.push({id:e.id??`msg-${r}`,role:i,parts:a})}}),t}function J(e){if(!(typeof e!=`string`||!e))try{let t=JSON.parse(e);return Array.isArray(t)?t:void 0}catch{return}}function fe(e){return e?e.map(e=>{let t=e.id,n=typeof e.content==`string`?e.content:``;if(e.role===`assistant`){let r=J(e.tool_calls);if(r&&r.length>0){let e=[];return n&&e.push({type:`text`,text:n}),e.push(...r),{id:t,role:`assistant`,content:e}}return{id:t,role:`assistant`,content:n}}if(e.role===`tool`){let r=J(e.content);return r&&r.length>0&&r[0]?.type===`tool-result`?{id:t,role:`tool`,content:r}:{id:t,role:`tool`,content:[{type:`tool-result`,toolCallId:e.tool_call_id??``,toolName:`unknown`,output:{type:`text`,value:n}}]}}return{id:t,role:e.role,content:n}}):[]}async function Y(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(n.status===404||n.status===403)return null;if(!n.ok)throw Error(`GET conversation failed: ${n.status}`);return await n.json()}async function X(e){let t=await fetch(`${e}/conversations`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error(`POST conversation failed: ${t.status}`);return await t.json()}async function pe(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function Z(e){let{userId:t,scope:n,apiBase:r,activeId:i,forceNew:a,resumeMode:o=`resume`}=e,[s,c]=(0,g.useState)(void 0),[l,u]=(0,g.useState)([]),[d,f]=(0,g.useState)(!!t),p=(0,g.useRef)(!0),m=(0,g.useRef)(void 0),h=(0,g.useRef)(void 0);(0,g.useEffect)(()=>(p.current=!0,()=>{p.current=!1}),[]),(0,g.useEffect)(()=>{if(!t){c(void 0),u([]),f(!1),m.current=void 0,h.current=void 0;return}let e=h.current!==n;if(!i&&!a&&!e&&m.current===t&&s)return;let l=!1,d=B(t,n);return!i&&(a||e&&m.current===t)&&(c(void 0),u([])),f(!0),(async()=>{try{if(i){let e=await Y(r,i);if(l)return;if(e){H(d,e.id),c(e.id);let r=q(e.messages);u(r.length>0?r:W(e.id)),m.current=t,h.current=n;return}H(d,void 0),G(i,[])}else if(!a){let e=V(d);if(e){let i=await Y(r,e);if(l)return;if(i){let e=q(i.messages);if(o!==`fresh`||e.length===0){c(i.id),u(o===`fresh`?[]:e.length>0?e:W(i.id)),m.current=t,h.current=n;return}}else H(d,void 0),G(e,[])}}let e=await X(r);if(l)return;H(d,e.id),c(e.id),u(q(e.messages)),m.current=t,h.current=n}catch{l||(c(void 0),u([]))}finally{l||f(!1)}})(),()=>{l=!0}},[t,n,r,i,a,o]);let _=(0,g.useCallback)(async()=>{if(!t)return;let e=B(t,n);f(!0);try{s&&await pe(r,s),G(s,[]),H(e,void 0);let t=await X(r);if(H(e,t.id),G(t.id,[]),!p.current)return;c(t.id),u([])}catch{p.current&&(c(void 0),u([]))}finally{p.current&&f(!1)}},[s,t,n,r]),v=(0,g.useCallback)(async()=>{if(!t)return;let e=B(t,n);f(!0);try{let i=await X(r);if(H(e,i.id),G(i.id,[]),!p.current)return;c(i.id),u([]),m.current=t,h.current=n}catch{}finally{p.current&&f(!1)}},[t,n,r]);return{conversationId:s,conversationScope:h.current,initialMessages:l,isLoading:d,reset:_,startNew:v}}var me=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function he(e){let t=e?.trim().toLowerCase();return!t||me.has(t)}function ge(e){let t=e.messages;if(!t||t.length===0)return;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`user`){let e=Q(n.content);if(e)return e}}let n=t[t.length-1];return Q(n?.content)}function Q(e){if(typeof e==`string`)return e.slice(0,140);if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return e.text.slice(0,140);if(e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts))return Q(e.parts);if(Array.isArray(e)){let t=e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``);return t?t.slice(0,140):void 0}}function $(e){let t=e.title?.trim(),n=ge(e)??Q(e.preview);return{id:e.id,title:he(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function _e(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return $(`conversation`in r&&r.conversation?r.conversation:r)}function ve(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,g.useState)([]),[s,c]=(0,g.useState)(!!t),[l,u]=(0,g.useState)(void 0),[d,f]=(0,g.useState)(0),p=(0,g.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,g.useCallback)(async e=>{try{await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`})}finally{o(t=>t.filter(t=>t.id!==e))}},[n]),h=(0,g.useCallback)(async(e,t)=>{let r=t.trim();o(t=>t.map(t=>t.id===e?{...t,title:r||void 0}:t));let i=await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r})});if(!i.ok)throw f(e=>e+1),Error(`PATCH conversation failed: ${i.status}`)},[n]);return(0,g.useEffect)(()=>{if(!t){o([]),c(!1),u(void 0);return}let e=!1;return c(!0),u(void 0),(async()=>{try{let t=await fetch(`${n}/conversations?limit=${encodeURIComponent(String(r))}`,{credentials:`include`});if(!t.ok)throw Error(`GET conversations failed: ${t.status}`);let i=await t.json(),a=Array.isArray(i)?i:i.conversations??i.items??[];if(e)return;let s=a.map($).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));o(s);let c=s.filter(e=>!e.title&&!e.preview).slice(0,20);if(c.length>0){let t=await Promise.all(c.map(e=>_e(n,e.id).catch(()=>void 0)));if(e)return;let r=new Map(t.filter(e=>!!(e?.preview||e?.title)).map(e=>[e.id,e]));r.size>0&&o(e=>e.map(e=>{let t=r.get(e.id);return t?{...e,title:e.title??t.title,preview:e.preview??t.preview}:e}))}}catch(t){if(e)return;u(t instanceof Error?t:Error(String(t))),o([])}finally{e||c(!1)}})(),()=>{e=!0}},[t,n,r,d,i]),{conversations:a,isLoading:s,error:l,refetch:p,remove:m,rename:h}}async function ye(e){let t=await fetch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`_drafts HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.drafts??n?.data?.drafts??[];return Array.isArray(r)?r.length:0}function be(e){if(!e||e.length===0)return!1;let t=e[e.length-1];return!t||t.role!==`assistant`?!1:t.parts.some(e=>e.type===`text`&&String(e.text??``).trim().length>0)}function xe(e){let{chatApi:t,conversationId:n}=e,[r,i]=(0,g.useState)(!1),a=(0,g.useRef)(void 0);return{errorSuppressed:r,handleChatError:(0,g.useCallback)(async e=>{if(e?.notSent){i(!1);return}let r=t?.replace(/\/agents\/[^/]+\/chat$/,``);if(!n||!r){i(!1);return}try{let e=q((await Y(r,n))?.messages);if(be(e)&&a.current){a.current(e),i(!0);return}}catch{}i(!1)},[n,t]),setMessagesRef:a,resetSuppression:(0,g.useCallback)(()=>i(!1),[])}}export{Y as a,Z as c,P as d,ie as f,_ as g,y as h,fe as i,G as l,C as m,ye as n,ue as o,ee as p,ve as r,q as s,xe as t,se as u};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,t as n}from"./vendor-react-slxo-5GC.js";import{f as r}from"./infrastructure-BySW-NB0.js";import{M as i,U as a}from"./framework-CAn_0ZHj.js";import{Cr as o,Dn as s,En as c,Gn as l,Gt as u,Ht as d,Kn as f,On as p,Tn as m,Ut as h,Vt as g,Wt as _,Xn as v,Yn as ee,jc as y,qn as b,wn as te}from"./ui-components-BNnJ5f3_.js";import{n as x}from"./plugin-form-BefVAcDj.js";import{t as S}from"./recordFormNavigation-CXt3jCB4.js";var C=e(t(),1),w=n(),T=(0,C.createContext)({favorites:null,recent:null}),E=(0,C.createContext)(null);function D({children:e}){let[t,n]=(0,C.useState)({favorites:null,recent:null}),r=(0,C.useRef)({attach:(e,t)=>{n(n=>n[e]===t?n:{...n,[e]:t})}});return(0,w.jsx)(E.Provider,{value:r.current,children:(0,w.jsx)(T.Provider,{value:t,children:e})})}function O(e){return(0,C.useContext)(T)[e]}function k(){let e=(0,C.useContext)(E);return(0,C.useCallback)((t,n)=>{e?.attach(t,n)},[e])}function A(e,t){return t?`${e}:u:${t}`:e}function j(e,t){let n=(0,C.useRef)(t);n.current=t,(0,C.useEffect)(()=>{if(typeof window>`u`)return;let t=t=>{if(!(t.key!==e||t.storageArea!==localStorage)){if(t.newValue==null){n.current(null);return}try{n.current(JSON.parse(t.newValue))}catch{n.current(null)}}};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e])}function M(e,t=500){let n=null,r=null,i=!1,a=async()=>{if(n&&=(clearTimeout(n),null),!i)return;let t=r;i=!1,r=null;try{await e(t)}catch{}};return{schedule:e=>{r=e,i=!0,n&&clearTimeout(n),n=setTimeout(()=>{n=null,a()},t)},flush:a,cancel:()=>{n&&clearTimeout(n),n=null,i=!1,r=null}}}var N=`objectui-recent-items`,P=8;function F(e){try{let t=localStorage.getItem(A(N,e));return t?JSON.parse(t):[]}catch{return[]}}function I(e,t){try{localStorage.setItem(A(N,t),JSON.stringify(e))}catch{}}var L=(0,C.createContext)(null);function R({children:e}){let{user:t}=r(),n=t?.id??null,i=O(`recent`),[a,o]=(0,C.useState)(()=>F(n));(0,C.useEffect)(()=>{o(F(n))},[n]),j(A(N,n),e=>{o(Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`).slice(0,P):[])});let s=(0,C.useRef)(0);(0,C.useEffect)(()=>{if(!i)return;let e=++s.current,t=!1;return(async()=>{try{let r=await i.load();if(t||e!==s.current)return;let a=(Array.isArray(r)?r:[]).filter(e=>e&&typeof e.id==`string`).slice(0,P);o(a),I(a,n)}catch{}})(),()=>{t=!0}},[i,n]);let c=(0,C.useMemo)(()=>M(async e=>{i&&await i.save(e)},500),[i]);(0,C.useEffect)(()=>()=>{c.flush()},[c]);let l=(0,C.useCallback)(e=>{I(e,n),i&&c.schedule(e)},[n,i,c]),u=(0,C.useCallback)(e=>{o(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,P);return l(r),r})},[l]),d=(0,C.useCallback)(()=>{o([]),l([])},[l]),f=(0,C.useMemo)(()=>({recentItems:a,addRecentItem:u,clearRecentItems:d}),[a,u,d]);return(0,w.jsx)(L.Provider,{value:f,children:e})}function z(){return(0,C.useContext)(L)||{recentItems:[],addRecentItem:()=>{},clearRecentItems:()=>{}}}var B={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},V={lg:`sm:max-w-2xl`,xl:`sm:max-w-3xl`,full:`sm:max-w-[95vw]`};function H(e){if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);return t?{objectName:t[2],mode:t[1]===`edit`||t[1]===`update`?`edit`:`create`}:{objectName:e,mode:`create`}}return e&&typeof e==`object`?e.type&&!e.content&&!e.objectName&&!e.placement?{content:e}:e:{}}function U(e){let[t,n]=(0,C.useState)(null),{objects:r}=i(),T=(0,C.useCallback)(e=>{n(t=>(t?.resolve(e),null))},[]),E=(0,C.useCallback)(e=>new Promise(t=>{n({d:H(e),resolve:t})}),[]),D=null;if(t){let n=t.d,i=e=>{e||T({success:!1})};if(n.objectName&&!n.content){let t=n.fields||n.sections?{}:S(r.find(e=>e?.name===n.objectName));D=(0,w.jsx)(x,{schema:{type:`object-form`,formType:`modal`,objectName:n.objectName,mode:n.mode||`create`,recordId:n.recordId,title:n.title,description:n.description,fields:n.fields,...t,modalSize:n.size,open:!0,onOpenChange:i,onSuccess:e=>T({success:!0,reload:!0,data:e}),onCancel:()=>T({success:!1}),showSubmit:!0,showCancel:!0},dataSource:e})}else{let e=n.placement||`center`,t=n.content?(0,w.jsx)(a,{schema:n.content}):n.description?(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description}):null;D=e===`side`?(0,w.jsx)(g,{open:!0,onOpenChange:i,children:(0,w.jsxs)(d,{side:n.side||`right`,className:y(`w-full overflow-y-auto`,V[n.size||`default`]),children:[n.title&&(0,w.jsxs)(_,{children:[(0,w.jsx)(u,{children:n.title}),n.description&&(0,w.jsx)(h,{children:n.description})]}),(0,w.jsx)(`div`,{className:`py-3`,children:t})]})}):e===`bottom`?(0,w.jsx)(te,{open:!0,onOpenChange:i,children:(0,w.jsxs)(m,{children:[n.title&&(0,w.jsxs)(s,{children:[(0,w.jsx)(p,{children:n.title}),n.description&&(0,w.jsx)(c,{children:n.description})]}),(0,w.jsx)(`div`,{className:`max-h-[75vh] overflow-y-auto px-4 pb-6`,children:t})]})}):(0,w.jsx)(l,{open:!0,onOpenChange:i,children:(0,w.jsxs)(f,{className:y(e===`fullscreen`?`h-[95vh] w-full max-w-[98vw] overflow-y-auto`:B[n.size||`default`]),children:[n.title&&(0,w.jsxs)(ee,{children:[(0,w.jsx)(v,{children:n.title}),n.description&&(0,w.jsx)(b,{children:n.description})]}),(0,w.jsx)(`div`,{children:t}),!n.content&&(0,w.jsx)(`div`,{className:`flex justify-end`,children:(0,w.jsx)(o,{onClick:()=>T({success:!0}),children:`OK`})})]})})}}return{modalHandler:E,modalElement:D,closeModal:T}}var W=`objectui-favorites`,G=`objectui-nav-pins`,K=20,q=20;function J(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>q&&(r=!0)):(t++,t>K&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<q&&(i.push(t),o++):a<K&&(i.push(t),a++);return i}function Y(e){try{let t=localStorage.getItem(A(W,e));return t?JSON.parse(t):[]}catch{return[]}}function X(e,t){try{localStorage.setItem(A(W,t),JSON.stringify(e))}catch{}}function Z(e){let t;try{t=localStorage.getItem(G)}catch{return{migrated:e,didMigrate:!1}}if(!t)return{migrated:e,didMigrate:!1};let n=[];try{let e=JSON.parse(t);Array.isArray(e)&&(n=e.filter(e=>typeof e==`string`))}catch{}try{localStorage.removeItem(G)}catch{}if(n.length===0)return{migrated:e,didMigrate:!1};let r=new Set(e.filter(e=>e.type===`nav`&&e.navId).map(e=>e.navId)),i=new Date().toISOString(),a=[];for(let e of n)r.has(e)||a.push({id:`nav:${e}`,label:e,href:``,type:`nav`,navId:e,pinned:!0,favoritedAt:i});return a.length===0?{migrated:e,didMigrate:!0}:{migrated:[...e,...a],didMigrate:!0}}var Q=(0,C.createContext)(null);function ne({children:e}){let{user:t}=r(),n=t?.id??null,i=O(`favorites`),[a,o]=(0,C.useState)(()=>Y(n));(0,C.useEffect)(()=>{o(Y(n))},[n]),j(A(W,n),e=>{o(Array.isArray(e)?J(e.filter(e=>e&&typeof e.id==`string`)):[])});let s=(0,C.useRef)(0);(0,C.useEffect)(()=>{if(!i)return;let e=++s.current,t=!1;return(async()=>{try{let r=await i.load();if(t||e!==s.current)return;let a=J((Array.isArray(r)?r:[]).filter(e=>e&&typeof e.id==`string`)),l=Y(n),u=new Set(a.filter(e=>e.type===`nav`&&e.navId).map(e=>e.navId)),d=l.filter(e=>e.type===`nav`&&e.navId&&!u.has(e.navId)),f=a,p=!1;d.length>0&&(f=J([...a,...d]),p=!0);let{migrated:m,didMigrate:h}=Z(f);h&&(f=J(m),p=!0),o(f),X(f,n),p&&c.schedule(f)}catch{}})(),()=>{t=!0}},[i,n]),(0,C.useEffect)(()=>{i||o(e=>{let{migrated:t,didMigrate:r}=Z(e);if(!r)return e;let i=J(t);return X(i,n),i})},[i,n]);let c=(0,C.useMemo)(()=>M(async e=>{i&&await i.save(e)},500),[i]);(0,C.useEffect)(()=>()=>{c.flush()},[c]);let l=(0,C.useCallback)(e=>{X(e,n),i&&c.schedule(e)},[n,i,c]),u=(0,C.useCallback)(e=>{o(t=>{if(t.some(t=>t.id===e.id))return t;let n=J([{...e,favoritedAt:new Date().toISOString()},...t]);return l(n),n})},[l]),d=(0,C.useCallback)(e=>{o(t=>{let n=t.filter(t=>t.id!==e);return l(n),n})},[l]),f=(0,C.useCallback)(e=>{o(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):J([{...e,favoritedAt:new Date().toISOString()},...t]);return l(n),n})},[l]),p=(0,C.useCallback)(()=>{o([]),l([])},[l]),m=(0,C.useCallback)((e,t)=>{!e||!t||o(n=>{let r=!1,i=n.map(n=>n.id===e&&n.label!==t?(r=!0,{...n,label:t}):n);return r?(l(i),i):n})},[l]),h=(0,C.useCallback)((e,t)=>{o(n=>{let r=!1,i=n.map(n=>n.id!==e||!!n.pinned===t?n:(r=!0,{...n,pinned:t}));return r?(l(i),i):n})},[l]),g=(0,C.useMemo)(()=>{let e=new Set;for(let t of a)t.pinned&&t.type===`nav`&&t.navId&&e.add(t.navId);return{favorites:a,addFavorite:u,removeFavorite:d,toggleFavorite:f,isFavorite:e=>a.some(t=>t.id===e),clearFavorites:p,refreshLabel:m,setPinned:h,isPinned:e=>a.some(t=>t.id===e&&!!t.pinned),pinnedNavIds:e}},[a,u,d,f,p,m,h]);return(0,w.jsx)(Q.Provider,{value:g,children:e})}function re(){return(0,C.useContext)(Q)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}function ie(){return`${``.replace(/\/$/,``)}/api/v1`}async function $(e,t){let n=await fetch(`${ie()}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers||{}},...t}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=Error(r?.error||`HTTP ${n.status}`);throw e.code=r?.code??`HTTP_${n.status}`,e.status=n.status,e}return r}function ae(e,t,n){let[r,i]=(0,C.useState)(!1),[a,o]=(0,C.useState)(!0),[s,c]=(0,C.useState)([]),l=(0,C.useRef)(!1),u=(0,C.useCallback)(async()=>{if(!(!e||!t)&&!l.current){i(!0);try{c((await $(`/approvals/requests?object=${encodeURIComponent(e)}&recordId=${encodeURIComponent(t)}`))?.data??[]),o(!0)}catch(e){(e?.status===404||e?.status===501)&&(l.current=!0,o(!1))}finally{i(!1)}}},[e,t]);(0,C.useEffect)(()=>{if(!e||!t){c([]);return}u()},[e,t,u]);let d=(0,C.useMemo)(()=>s.find(e=>e.status===`pending`)??null,[s]),f=(0,C.useMemo)(()=>s.length===0?null:[...s].sort((e,t)=>{let n=e.submitted_at||e.completed_at||``;return(t.submitted_at||t.completed_at||``).localeCompare(n)})[0]??null,[s]),p=!!d&&!!n&&(d.pending_approvers??[]).includes(n),m=(0,C.useCallback)(async(e,t)=>{if(!d)throw Error(`No pending request`);let r=await $(`/approvals/requests/${encodeURIComponent(d.id)}/${e}`,{method:`POST`,body:JSON.stringify({...n?{actorId:n}:{},...t?.comment?{comment:t.comment}:{}})});return await u(),r?.request},[d,n,u]);return{loading:r,available:a,pendingRequest:d,latestRequest:f,canDecide:p,approve:(0,C.useCallback)(e=>m(`approve`,e),[m]),reject:(0,C.useCallback)(e=>m(`reject`,e),[m]),refresh:u}}export{R as a,k as c,U as i,ne as n,z as o,re as r,D as s,ae as t};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,t as n}from"./vendor-react-slxo-5GC.js";import{f as r}from"./infrastructure-BySW-NB0.js";import{G as i,P as a}from"./framework-Bn8ShCi0.js";import{Ac as o,Bt as s,Cn as c,Dn as l,En as u,Gn as d,Ht as f,Jn as p,Kn as m,Sr as h,Tn as g,Ut as _,Vt as v,Wn as ee,Wt as te,Yn as y,wn as b}from"./ui-components-DlauVk27.js";import{n as x}from"./plugin-form-BUDPowXG.js";import{t as S}from"./recordFormNavigation-CXt3jCB4.js";var C=e(t(),1),w=n(),T=(0,C.createContext)({favorites:null,recent:null}),E=(0,C.createContext)(null);function D({children:e}){let[t,n]=(0,C.useState)({favorites:null,recent:null}),r=(0,C.useRef)({attach:(e,t)=>{n(n=>n[e]===t?n:{...n,[e]:t})}});return(0,w.jsx)(E.Provider,{value:r.current,children:(0,w.jsx)(T.Provider,{value:t,children:e})})}function O(e){return(0,C.useContext)(T)[e]}function k(){let e=(0,C.useContext)(E);return(0,C.useCallback)((t,n)=>{e?.attach(t,n)},[e])}function A(e,t){return t?`${e}:u:${t}`:e}function j(e,t){let n=(0,C.useRef)(t);n.current=t,(0,C.useEffect)(()=>{if(typeof window>`u`)return;let t=t=>{if(!(t.key!==e||t.storageArea!==localStorage)){if(t.newValue==null){n.current(null);return}try{n.current(JSON.parse(t.newValue))}catch{n.current(null)}}};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e])}function M(e,t=500){let n=null,r=null,i=!1,a=async()=>{if(n&&=(clearTimeout(n),null),!i)return;let t=r;i=!1,r=null;try{await e(t)}catch{}};return{schedule:e=>{r=e,i=!0,n&&clearTimeout(n),n=setTimeout(()=>{n=null,a()},t)},flush:a,cancel:()=>{n&&clearTimeout(n),n=null,i=!1,r=null}}}var N=`objectui-recent-items`,P=8;function F(e){try{let t=localStorage.getItem(A(N,e));return t?JSON.parse(t):[]}catch{return[]}}function I(e,t){try{localStorage.setItem(A(N,t),JSON.stringify(e))}catch{}}var L=(0,C.createContext)(null);function R({children:e}){let{user:t}=r(),n=t?.id??null,i=O(`recent`),[a,o]=(0,C.useState)(()=>F(n));(0,C.useEffect)(()=>{o(F(n))},[n]),j(A(N,n),e=>{o(Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`).slice(0,P):[])});let s=(0,C.useRef)(0);(0,C.useEffect)(()=>{if(!i)return;let e=++s.current,t=!1;return(async()=>{try{let r=await i.load();if(t||e!==s.current)return;let a=(Array.isArray(r)?r:[]).filter(e=>e&&typeof e.id==`string`).slice(0,P);o(a),I(a,n)}catch{}})(),()=>{t=!0}},[i,n]);let c=(0,C.useMemo)(()=>M(async e=>{i&&await i.save(e)},500),[i]);(0,C.useEffect)(()=>()=>{c.flush()},[c]);let l=(0,C.useCallback)(e=>{I(e,n),i&&c.schedule(e)},[n,i,c]),u=(0,C.useCallback)(e=>{o(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,P);return l(r),r})},[l]),d=(0,C.useCallback)(()=>{o([]),l([])},[l]),f=(0,C.useMemo)(()=>({recentItems:a,addRecentItem:u,clearRecentItems:d}),[a,u,d]);return(0,w.jsx)(L.Provider,{value:f,children:e})}function z(){return(0,C.useContext)(L)||{recentItems:[],addRecentItem:()=>{},clearRecentItems:()=>{}}}var B={sm:`sm:max-w-sm`,default:`sm:max-w-lg`,lg:`sm:max-w-2xl`,xl:`sm:max-w-5xl`,full:`sm:max-w-[95vw] sm:w-full`},V={lg:`sm:max-w-2xl`,xl:`sm:max-w-3xl`,full:`sm:max-w-[95vw]`};function H(e){if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);return t?{objectName:t[2],mode:t[1]===`edit`||t[1]===`update`?`edit`:`create`}:{objectName:e,mode:`create`}}return e&&typeof e==`object`?e.type&&!e.content&&!e.objectName&&!e.placement?{content:e}:e:{}}function U(e){let[t,n]=(0,C.useState)(null),{objects:r}=a(),T=(0,C.useCallback)(e=>{n(t=>(t?.resolve(e),null))},[]),E=(0,C.useCallback)(e=>new Promise(t=>{n({d:H(e),resolve:t})}),[]),D=null;if(t){let n=t.d,a=e=>{e||T({success:!1})};if(n.objectName&&!n.content){let t=n.fields||n.sections?{}:S(r.find(e=>e?.name===n.objectName));D=(0,w.jsx)(x,{schema:{type:`object-form`,formType:`modal`,objectName:n.objectName,mode:n.mode||`create`,recordId:n.recordId,title:n.title,description:n.description,fields:n.fields,...t,modalSize:n.size,open:!0,onOpenChange:a,onSuccess:e=>T({success:!0,reload:!0,data:e}),onCancel:()=>T({success:!1}),showSubmit:!0,showCancel:!0},dataSource:e})}else{let e=n.placement||`center`,t=n.content?(0,w.jsx)(i,{schema:n.content}):n.description?(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n.description}):null;D=e===`side`?(0,w.jsx)(s,{open:!0,onOpenChange:a,children:(0,w.jsxs)(v,{side:n.side||`right`,className:o(`w-full overflow-y-auto`,V[n.size||`default`]),children:[n.title&&(0,w.jsxs)(_,{children:[(0,w.jsx)(te,{children:n.title}),n.description&&(0,w.jsx)(f,{children:n.description})]}),(0,w.jsx)(`div`,{className:`py-3`,children:t})]})}):e===`bottom`?(0,w.jsx)(c,{open:!0,onOpenChange:a,children:(0,w.jsxs)(b,{children:[n.title&&(0,w.jsxs)(u,{children:[(0,w.jsx)(l,{children:n.title}),n.description&&(0,w.jsx)(g,{children:n.description})]}),(0,w.jsx)(`div`,{className:`max-h-[75vh] overflow-y-auto px-4 pb-6`,children:t})]})}):(0,w.jsx)(ee,{open:!0,onOpenChange:a,children:(0,w.jsxs)(d,{className:o(e===`fullscreen`?`h-[95vh] w-full max-w-[98vw] overflow-y-auto`:B[n.size||`default`]),children:[n.title&&(0,w.jsxs)(p,{children:[(0,w.jsx)(y,{children:n.title}),n.description&&(0,w.jsx)(m,{children:n.description})]}),(0,w.jsx)(`div`,{children:t}),!n.content&&(0,w.jsx)(`div`,{className:`flex justify-end`,children:(0,w.jsx)(h,{onClick:()=>T({success:!0}),children:`OK`})})]})})}}return{modalHandler:E,modalElement:D,closeModal:T}}var W=`objectui-favorites`,G=`objectui-nav-pins`,K=20,q=20;function J(e){let t=0,n=0,r=!1;for(let i of e)i.type===`nav`?(n++,n>q&&(r=!0)):(t++,t>K&&(r=!0));if(!r)return e;let i=[],a=0,o=0;for(let t of e)t.type===`nav`?o<q&&(i.push(t),o++):a<K&&(i.push(t),a++);return i}function Y(e){try{let t=localStorage.getItem(A(W,e));return t?JSON.parse(t):[]}catch{return[]}}function X(e,t){try{localStorage.setItem(A(W,t),JSON.stringify(e))}catch{}}function Z(e){let t;try{t=localStorage.getItem(G)}catch{return{migrated:e,didMigrate:!1}}if(!t)return{migrated:e,didMigrate:!1};let n=[];try{let e=JSON.parse(t);Array.isArray(e)&&(n=e.filter(e=>typeof e==`string`))}catch{}try{localStorage.removeItem(G)}catch{}if(n.length===0)return{migrated:e,didMigrate:!1};let r=new Set(e.filter(e=>e.type===`nav`&&e.navId).map(e=>e.navId)),i=new Date().toISOString(),a=[];for(let e of n)r.has(e)||a.push({id:`nav:${e}`,label:e,href:``,type:`nav`,navId:e,pinned:!0,favoritedAt:i});return a.length===0?{migrated:e,didMigrate:!0}:{migrated:[...e,...a],didMigrate:!0}}var Q=(0,C.createContext)(null);function ne({children:e}){let{user:t}=r(),n=t?.id??null,i=O(`favorites`),[a,o]=(0,C.useState)(()=>Y(n));(0,C.useEffect)(()=>{o(Y(n))},[n]),j(A(W,n),e=>{o(Array.isArray(e)?J(e.filter(e=>e&&typeof e.id==`string`)):[])});let s=(0,C.useRef)(0);(0,C.useEffect)(()=>{if(!i)return;let e=++s.current,t=!1;return(async()=>{try{let r=await i.load();if(t||e!==s.current)return;let a=J((Array.isArray(r)?r:[]).filter(e=>e&&typeof e.id==`string`)),l=Y(n),u=new Set(a.filter(e=>e.type===`nav`&&e.navId).map(e=>e.navId)),d=l.filter(e=>e.type===`nav`&&e.navId&&!u.has(e.navId)),f=a,p=!1;d.length>0&&(f=J([...a,...d]),p=!0);let{migrated:m,didMigrate:h}=Z(f);h&&(f=J(m),p=!0),o(f),X(f,n),p&&c.schedule(f)}catch{}})(),()=>{t=!0}},[i,n]),(0,C.useEffect)(()=>{i||o(e=>{let{migrated:t,didMigrate:r}=Z(e);if(!r)return e;let i=J(t);return X(i,n),i})},[i,n]);let c=(0,C.useMemo)(()=>M(async e=>{i&&await i.save(e)},500),[i]);(0,C.useEffect)(()=>()=>{c.flush()},[c]);let l=(0,C.useCallback)(e=>{X(e,n),i&&c.schedule(e)},[n,i,c]),u=(0,C.useCallback)(e=>{o(t=>{if(t.some(t=>t.id===e.id))return t;let n=J([{...e,favoritedAt:new Date().toISOString()},...t]);return l(n),n})},[l]),d=(0,C.useCallback)(e=>{o(t=>{let n=t.filter(t=>t.id!==e);return l(n),n})},[l]),f=(0,C.useCallback)(e=>{o(t=>{let n=t.some(t=>t.id===e.id)?t.filter(t=>t.id!==e.id):J([{...e,favoritedAt:new Date().toISOString()},...t]);return l(n),n})},[l]),p=(0,C.useCallback)(()=>{o([]),l([])},[l]),m=(0,C.useCallback)((e,t)=>{!e||!t||o(n=>{let r=!1,i=n.map(n=>n.id===e&&n.label!==t?(r=!0,{...n,label:t}):n);return r?(l(i),i):n})},[l]),h=(0,C.useCallback)((e,t)=>{o(n=>{let r=!1,i=n.map(n=>n.id!==e||!!n.pinned===t?n:(r=!0,{...n,pinned:t}));return r?(l(i),i):n})},[l]),g=(0,C.useMemo)(()=>{let e=new Set;for(let t of a)t.pinned&&t.type===`nav`&&t.navId&&e.add(t.navId);return{favorites:a,addFavorite:u,removeFavorite:d,toggleFavorite:f,isFavorite:e=>a.some(t=>t.id===e),clearFavorites:p,refreshLabel:m,setPinned:h,isPinned:e=>a.some(t=>t.id===e&&!!t.pinned),pinnedNavIds:e}},[a,u,d,f,p,m,h]);return(0,w.jsx)(Q.Provider,{value:g,children:e})}function re(){return(0,C.useContext)(Q)||{favorites:[],addFavorite:()=>{},removeFavorite:()=>{},toggleFavorite:()=>{},isFavorite:()=>!1,clearFavorites:()=>{},refreshLabel:()=>{},setPinned:()=>{},isPinned:()=>!1,pinnedNavIds:new Set}}function ie(){return`${``.replace(/\/$/,``)}/api/v1`}async function $(e,t){let n=await fetch(`${ie()}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers||{}},...t}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=Error(r?.error||`HTTP ${n.status}`);throw e.code=r?.code??`HTTP_${n.status}`,e.status=n.status,e}return r}function ae(e,t,n){let[r,i]=(0,C.useState)(!1),[a,o]=(0,C.useState)(!0),[s,c]=(0,C.useState)([]),l=(0,C.useRef)(!1),u=(0,C.useCallback)(async()=>{if(!(!e||!t)&&!l.current){i(!0);try{c((await $(`/approvals/requests?object=${encodeURIComponent(e)}&recordId=${encodeURIComponent(t)}`))?.data??[]),o(!0)}catch(e){(e?.status===404||e?.status===501)&&(l.current=!0,o(!1))}finally{i(!1)}}},[e,t]);(0,C.useEffect)(()=>{if(!e||!t){c([]);return}u()},[e,t,u]);let d=(0,C.useMemo)(()=>s.find(e=>e.status===`pending`)??null,[s]),f=(0,C.useMemo)(()=>s.length===0?null:[...s].sort((e,t)=>{let n=e.submitted_at||e.completed_at||``;return(t.submitted_at||t.completed_at||``).localeCompare(n)})[0]??null,[s]),p=!!d&&!!n&&(d.pending_approvers??[]).includes(n),m=(0,C.useCallback)(async(e,t)=>{if(!d)throw Error(`No pending request`);let r=await $(`/approvals/requests/${encodeURIComponent(d.id)}/${e}`,{method:`POST`,body:JSON.stringify({...n?{actorId:n}:{},...t?.comment?{comment:t.comment}:{}})});return await u(),r?.request},[d,n,u]);return{loading:r,available:a,pendingRequest:d,latestRequest:f,canDecide:p,approve:(0,C.useCallback)(e=>m(`approve`,e),[m]),reject:(0,C.useCallback)(e=>m(`reject`,e),[m]),refresh:u}}export{R as a,k as c,U as i,ne as n,z as o,re as r,D as s,ae as t};
@@ -0,0 +1 @@
1
+ var e=new Set([`created_by`,`updated_by`,`owner_id`]);function t(e){return e?Array.isArray(e)?e.filter(e=>e&&e.name!=null).map(e=>[String(e.name),e]):Object.entries(e):[]}function n(n,r){if(!n?.name||!Array.isArray(r)||r.length===0)return[];let i=n.name,a=[],o=[];for(let n of r)if(n?.name)for(let[r,s]of t(n.fields)){if(!s)continue;let t=s.type;if(t!==`lookup`&&t!==`master_detail`||(s.reference_to||s.reference)!==i||e.has(r)||s.relatedList===!1)continue;let c={childObject:n.name,childLabel:n.label||n.name,referenceField:r,isOwned:t===`master_detail`,isPrimary:s.relatedList===`primary`,_fkLabel:typeof s.label==`string`&&s.label||r,...typeof s.relatedListTitle==`string`&&s.relatedListTitle?{title:s.relatedListTitle}:{},...Array.isArray(s.relatedListColumns)&&s.relatedListColumns.length>0?{columns:s.relatedListColumns}:{}};(c.isOwned?a:o).push(c)}let s=[...a,...o],c={};for(let e of s)c[e.childObject]=(c[e.childObject]||0)+1;return s.map(({_fkLabel:e,...t})=>!t.title&&c[t.childObject]>1?{...t,title:`${t.childLabel} · ${e}`}:t)}function r(e,t){if(e!=null){if(typeof e==`string`)return e;if(t){let n=t(e.key,{defaultValue:e.defaultValue,...e.params});if(n&&n!==e.key)return n}return e.defaultValue||e.key}}export{n,r as t};
package/dist/index.html CHANGED
@@ -18,12 +18,12 @@
18
18
  <script>
19
19
  window.process = window.process || { env: { NODE_ENV: 'development' }, version: '', platform: 'browser' };
20
20
  </script>
21
- <script type="module" crossorigin src="./assets/index-Dw-VsD8-.js"></script>
21
+ <script type="module" crossorigin src="./assets/index-BecTd5hZ.js"></script>
22
22
  <link rel="stylesheet" crossorigin href="./assets/ui-components-BL3SEdAz.css">
23
23
  <link rel="stylesheet" crossorigin href="./assets/plugin-dashboard-DnNKJB60.css">
24
24
  <link rel="stylesheet" crossorigin href="./assets/index-Ci5dbUDe.css">
25
- <link rel="modulepreload" href="./assets/framework-CAn_0ZHj.js" />
26
- <link rel="modulepreload" href="./assets/ui-components-BNnJ5f3_.js" />
25
+ <link rel="modulepreload" href="./assets/framework-Bn8ShCi0.js" />
26
+ <link rel="modulepreload" href="./assets/ui-components-DlauVk27.js" />
27
27
  <link rel="modulepreload" href="./assets/vendor-radix-DniuRzL-.js" />
28
28
  <link rel="modulepreload" href="./assets/vendor-react-slxo-5GC.js" />
29
29
  </head>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@objectstack/console",
3
- "version": "11.10.0",
3
+ "version": "12.0.0",
4
4
  "description": "Prebuilt Console SPA pinned to this @objectstack/framework release. Source of truth: @object-ui/console (https://github.com/objectstack-ai/objectui).",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/objectstack-ai/framework/tree/main/packages/console",
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,t as n}from"./vendor-react-slxo-5GC.js";import{j as r}from"./framework-CAn_0ZHj.js";import{$i as i,$n as a,Ai as o,Ar as s,Gs as c,Hs as l,Qn as u,Ui as d,Va as f,Ws as p,Yr as m,Zi as h,Zn as g,bo as _,sr as v,us as ee,vs as te}from"./ui-components-BNnJ5f3_.js";import"./src-CnWu84r5.js";var y=e(t(),1),b=[`plugin`,`plugins`,`kind`,`package`];function x(e){return[{method:`POST`,path:`${e}/sign-in/email`,desc:`Sign in (email)`,group:`Auth`,bodyTemplate:{email:`user@example.com`,password:``}},{method:`POST`,path:`${e}/sign-up/email`,desc:`Sign up (email)`,group:`Auth`,bodyTemplate:{email:``,password:``,name:``}},{method:`POST`,path:`${e}/sign-out`,desc:`Sign out`,group:`Auth`},{method:`GET`,path:`${e}/get-session`,desc:`Get session`,group:`Auth`}]}var S={ai:{group:`AI`,defaultRoute:`/api/v1/ai`,endpoints:[{method:`POST`,path:`/chat`,desc:`Chat completion`,bodyTemplate:{messages:[{role:`user`,content:``}]}},{method:`POST`,path:`/chat/stream`,desc:`Streaming chat (SSE)`,bodyTemplate:{messages:[{role:`user`,content:``}]}},{method:`POST`,path:`/complete`,desc:`Text completion`,bodyTemplate:{prompt:``}},{method:`GET`,path:`/models`,desc:`List available models`},{method:`POST`,path:`/nlq`,desc:`Natural language query`,bodyTemplate:{query:``}},{method:`POST`,path:`/suggest`,desc:`AI-powered suggestions`,bodyTemplate:{object:``,field:``,context:{}}},{method:`POST`,path:`/insights`,desc:`AI-generated insights`,bodyTemplate:{object:``,recordIds:[]}},{method:`POST`,path:`/conversations`,desc:`Create conversation`,bodyTemplate:{}},{method:`GET`,path:`/conversations`,desc:`List conversations`},{method:`POST`,path:`/conversations/:id/messages`,desc:`Add message to conversation`,bodyTemplate:{role:`user`,content:``}},{method:`DELETE`,path:`/conversations/:id`,desc:`Delete conversation`}]},workflow:{group:`Workflow`,defaultRoute:`/api/v1/workflow`,endpoints:[{method:`GET`,path:`/:object/config`,desc:`Get workflow configuration`},{method:`GET`,path:`/:object/:recordId/state`,desc:`Get workflow state`},{method:`POST`,path:`/:object/:recordId/transition`,desc:`Execute workflow transition`,bodyTemplate:{targetState:``}},{method:`POST`,path:`/:object/:recordId/approve`,desc:`Approve workflow step`,bodyTemplate:{comment:``}},{method:`POST`,path:`/:object/:recordId/reject`,desc:`Reject workflow step`,bodyTemplate:{comment:``}}]},realtime:{group:`Realtime`,defaultRoute:`/api/v1/realtime`,endpoints:[{method:`POST`,path:`/connect`,desc:`Establish realtime connection`,bodyTemplate:{transport:`websocket`}},{method:`POST`,path:`/disconnect`,desc:`Close realtime connection`,bodyTemplate:{connectionId:``}},{method:`POST`,path:`/subscribe`,desc:`Subscribe to channel`,bodyTemplate:{channel:``}},{method:`POST`,path:`/unsubscribe`,desc:`Unsubscribe from channel`,bodyTemplate:{channel:``}},{method:`PUT`,path:`/presence/:channel`,desc:`Set presence state`,bodyTemplate:{status:`online`}},{method:`GET`,path:`/presence/:channel`,desc:`Get channel presence`}]},notification:{group:`Notifications`,defaultRoute:`/api/v1/notifications`,endpoints:[{method:`GET`,path:``,desc:`List notifications`},{method:`POST`,path:`/devices`,desc:`Register device for push`,bodyTemplate:{token:``,platform:`web`}},{method:`DELETE`,path:`/devices/:deviceId`,desc:`Unregister device`},{method:`GET`,path:`/preferences`,desc:`Get notification preferences`},{method:`PATCH`,path:`/preferences`,desc:`Update notification preferences`,bodyTemplate:{email:!0,push:!0}},{method:`POST`,path:`/read`,desc:`Mark notifications as read`,bodyTemplate:{ids:[]}},{method:`POST`,path:`/read/all`,desc:`Mark all as read`}]},analytics:{group:`Analytics`,defaultRoute:`/api/v1/analytics`,endpoints:[{method:`POST`,path:`/query`,desc:`Execute analytics query`,bodyTemplate:{measures:[],dimensions:[]}},{method:`GET`,path:`/meta`,desc:`Get analytics metadata`}]},automation:{group:`Automation`,defaultRoute:`/api/v1/automation`,endpoints:[{method:`POST`,path:`/trigger`,desc:`Trigger automation`,bodyTemplate:{name:``,params:{}}}]},i18n:{group:`i18n`,defaultRoute:`/api/v1/i18n`,endpoints:[{method:`GET`,path:`/locales`,desc:`Get available locales`},{method:`GET`,path:`/translations/:locale`,desc:`Get translations for locale`},{method:`GET`,path:`/labels/:object/:locale`,desc:`Get translated field labels`}]},ui:{group:`UI`,defaultRoute:`/api/v1/ui`,endpoints:[{method:`GET`,path:`/views`,desc:`List views`},{method:`GET`,path:`/views/:id`,desc:`Get view by ID`},{method:`POST`,path:`/views`,desc:`Create view`,bodyTemplate:{name:``,object:``,type:`list`}},{method:`PATCH`,path:`/views/:id`,desc:`Update view`,bodyTemplate:{name:``}},{method:`DELETE`,path:`/views/:id`,desc:`Delete view`}]},feed:{group:`Feed`,defaultRoute:`/api/v1/feed`,endpoints:[{method:`GET`,path:`/:object/:recordId`,desc:`Get feed items`},{method:`POST`,path:`/:object/:recordId`,desc:`Post feed item`,bodyTemplate:{body:``}}]},storage:{group:`Storage`,defaultRoute:`/api/v1/storage`,endpoints:[{method:`POST`,path:`/upload`,desc:`Upload file (multipart/form-data)`},{method:`GET`,path:`/:fileId`,desc:`Download file`},{method:`DELETE`,path:`/:fileId`,desc:`Delete file`}]}};function C(e,t){let n=S[e];return n?n.endpoints.map(e=>({method:e.method,path:`${t}${e.path}`,desc:e.desc,group:n.group,...e.bodyTemplate?{bodyTemplate:e.bodyTemplate}:{}})):[]}function ne(){let e=r(),[t,n]=(0,y.useState)([]),[i,a]=(0,y.useState)([]),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(null),u=(0,y.useCallback)(async()=>{s(!0),l(null);let t=`/api/v1`,r=`${t}/discovery`,i=[{method:`GET`,path:r,desc:`API Discovery`,group:`System`},{method:`GET`,path:`${t}/meta/types`,desc:`List metadata types`,group:`Metadata`},{method:`GET`,path:`${t}/packages`,desc:`List packages`,group:`System`},{method:`GET`,path:`/api/v1/health`,desc:`Health check`,group:`System`}];try{let o=`/api/v1/auth`,s={},c={};try{let e=await fetch(r);if(e.ok){let t=await e.json(),n=t?.data??t;c=n?.routes??{},s=n?.services??{},c.auth&&(o=c.auth)}}catch{}let l=[];for(let[e,t]of Object.entries(S)){let n=s[e],r=n?.enabled??!1,i=n?.handlerReady??(n?.status===`available`||n?.status===`degraded`),a=n?.route??c[e]??t.defaultRoute;r&&i&&l.push(...C(e,a))}let u=e?.getClient?.(),d=[];try{let e=await u?.meta?.getTypes?.();e&&Array.isArray(e.types)?d=e.types:Array.isArray(e)&&(d=e)}catch{}let f=[];try{let e=d.includes(`object`)?`object`:null;if(e&&u?.meta?.getItems){let t=await u.meta.getItems(e),n=[];Array.isArray(t)?n=t:t&&Array.isArray(t.items)?n=t.items:t&&Array.isArray(t.value)&&(n=t.value),f=n.map(e=>e.name||e.id).filter(Boolean)}}catch{}let p=f.flatMap(e=>{let n=e.startsWith(`sys_`)?`Data: system tables`:`Data: ${e}`;return[{method:`GET`,path:`${t}/data/${e}`,desc:`List ${e}`,group:n},{method:`POST`,path:`${t}/data/${e}`,desc:`Create ${e}`,group:n,bodyTemplate:{name:`example`}},{method:`GET`,path:`${t}/data/${e}/:id`,desc:`Get ${e} by ID`,group:n},{method:`PATCH`,path:`${t}/data/${e}/:id`,desc:`Update ${e}`,group:n,bodyTemplate:{name:`updated`}},{method:`DELETE`,path:`${t}/data/${e}/:id`,desc:`Delete ${e}`,group:n}]}),m=d.filter(e=>!b.includes(e)).map(e=>({method:`GET`,path:`${t}/meta/${e}`,desc:`List ${e} metadata`,group:`Metadata`})),h=f.map(e=>({method:`GET`,path:`${t}/meta/object/${e}`,desc:`${e} schema`,group:`Metadata`})),g=[...i,...x(o),...l,...m,...h,...p],_=new Map;for(let e of g){let t=_.get(e.group)||[];t.push(e),_.set(e.group,t)}let v=[`System`,`Auth`,`AI`,`Workflow`,`Realtime`,`Notifications`,`Analytics`,`Automation`,`i18n`,`UI`,`Feed`,`Storage`,`Metadata`];n(Array.from(_.entries()).sort(([e],[t])=>{let n=v.indexOf(e),r=v.indexOf(t);return n!==-1&&r!==-1?n-r:n===-1?r===-1?e.localeCompare(t):1:-1}).map(([e,t])=>({key:e,label:e,endpoints:t}))),a(g)}catch(e){l(e.message||`Failed to discover APIs`)}finally{s(!1)}},[e]);return(0,y.useEffect)(()=>{u()},[u]),{groups:t,allEndpoints:i,loading:o,error:c,refresh:u}}var w=n(),T={GET:`text-emerald-600 bg-emerald-50 border-emerald-200 dark:text-emerald-400 dark:bg-emerald-950/50`,POST:`text-blue-600 bg-blue-50 border-blue-200 dark:text-blue-400 dark:bg-blue-950/50`,PATCH:`text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950/50`,PUT:`text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950/50`,DELETE:`text-red-600 bg-red-50 border-red-200 dark:text-red-400 dark:bg-red-950/50`},E={2:`text-emerald-600 dark:text-emerald-400`,3:`text-blue-600 dark:text-blue-400`,4:`text-amber-600 dark:text-amber-400`,5:`text-red-600 dark:text-red-400`},re=[{key:`$top`,placeholder:`10`,hint:`limit`},{key:`$skip`,placeholder:`0`,hint:`offset`},{key:`$sort`,placeholder:`name`,hint:`sort field`},{key:`$select`,placeholder:`name,email`,hint:`fields`},{key:`$count`,placeholder:`true`,hint:`total count`},{key:`$filter`,placeholder:`status eq 'active'`,hint:`OData filter`}],D=1;function O(){let e=r()?.getClient?.(),{groups:t,loading:n,refresh:b}=ne(),[x,S]=(0,y.useState)(``),[C,O]=(0,y.useState)(new Set),[k,A]=(0,y.useState)(null),[ie,j]=(0,y.useState)(``),[ae,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(``),[F,I]=(0,y.useState)([]),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,H]=(0,y.useState)([]),[U,oe]=(0,y.useState)(null),[W,G]=(0,y.useState)(!1),K=(0,y.useMemo)(()=>{if(!x)return t;let e=x.toLowerCase();return t.map(t=>({...t,endpoints:t.endpoints.filter(t=>t.desc.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)||t.method.toLowerCase().includes(e))})).filter(e=>e.endpoints.length>0)},[t,x]),se=(0,y.useCallback)(e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=(0,y.useCallback)(e=>{A(e),j(e.method),M(e.path),P(e.bodyTemplate?JSON.stringify(e.bodyTemplate,null,2):``),I([]),B(null)},[]),q=ie||k?.method||`GET`,J=ae||k?.path||``,Y=(0,y.useMemo)(()=>{let e=F.filter(e=>e.enabled&&e.key.trim());return e.length===0?J:`${J}?${e.map(e=>`${encodeURIComponent(e.key)}=${encodeURIComponent(e.value)}`).join(`&`)}`},[J,F]),X=(0,y.useCallback)((e=``,t=``)=>{I(n=>[...n,{id:D++,key:e,value:t,enabled:!0}])},[]),le=(0,y.useCallback)(e=>{I(t=>t.filter(t=>t.id!==e))},[]),Z=(0,y.useCallback)((e,t,n)=>{I(r=>r.map(r=>r.id===e?{...r,[t]:n}:r))},[]),ue=(0,y.useCallback)(e=>{I(t=>t.map(t=>t.id===e?{...t,enabled:!t.enabled}:t))},[]),Q=(0,y.useCallback)(async()=>{if(L||!Y)return;let t=`${e?.baseUrl??``}${Y}`;R(!0);let n=performance.now();try{let e={method:q,headers:{"Content-Type":`application/json`}};[`POST`,`PATCH`,`PUT`].includes(q)&&N.trim()&&(e.body=N);let r=await fetch(t,e),i=Math.round(performance.now()-n),a;if((r.headers.get(`content-type`)??``).includes(`json`)){let e=await r.json();a=JSON.stringify(e,null,2)}else a=await r.text();B({status:r.status,body:a,duration:i}),H(e=>[{id:Date.now(),method:q,url:Y,body:N||void 0,status:r.status,duration:i,response:a,timestamp:new Date},...e].slice(0,50))}catch(e){let t=Math.round(performance.now()-n);B({status:0,body:`Network Error: ${e.message}`,duration:t})}finally{R(!1)}},[e,Y,q,N,L]),de=(0,y.useCallback)(e=>{j(e.method);let[t,n]=e.url.split(`?`);if(M(t),P(e.body||``),n){let e=new URLSearchParams(n),t=[];e.forEach((e,n)=>{t.push({id:D++,key:n,value:e,enabled:!0})}),I(t)}else I([]);B(null),A(null)},[]),fe=(0,y.useCallback)(()=>{z?.body&&(navigator.clipboard.writeText(z.body),G(!0),setTimeout(()=>G(!1),1500))},[z]),$=e=>E[String(e)[0]]??`text-muted-foreground`;return(0,w.jsxs)(`div`,{className:`flex flex-1 min-h-0 overflow-hidden`,children:[(0,w.jsxs)(`div`,{className:`w-72 shrink-0 border-r flex flex-col overflow-hidden`,children:[(0,w.jsxs)(`div`,{className:`p-3 border-b space-y-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-semibold text-foreground flex-1`,children:`API Endpoints`}),(0,w.jsx)(`button`,{onClick:b,disabled:n,className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,title:`Refresh endpoints`,children:(0,w.jsx)(d,{className:`h-3.5 w-3.5 ${n?`animate-spin`:``}`})})]}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(o,{className:`absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,w.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`Search endpoints...`,className:`w-full rounded-md border bg-background pl-8 pr-3 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-ring`})]})]}),(0,w.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:n?(0,w.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,w.jsx)(f,{className:`h-4 w-4 animate-spin mr-2`}),`Discovering APIs...`]}):K.length===0?(0,w.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,w.jsx)(_,{className:`h-6 w-6 opacity-30 mb-2`}),(0,w.jsx)(`span`,{children:x?`No matching endpoints`:`No endpoints found`})]}):K.map(e=>{let t=C.has(e.key)||!!x;return(0,w.jsxs)(g,{open:t,onOpenChange:()=>se(e.key),children:[(0,w.jsx)(a,{asChild:!0,children:(0,w.jsxs)(`button`,{className:`w-full flex items-center gap-1.5 px-2 py-1.5 rounded-md text-xs font-medium text-muted-foreground hover:bg-muted/50 hover:text-foreground transition-colors`,children:[(0,w.jsx)(l,{className:`h-3 w-3 shrink-0 transition-transform duration-200 ${t?`rotate-90`:``}`}),(0,w.jsx)(`span`,{className:`flex-1 text-left truncate`,children:e.label}),(0,w.jsx)(`span`,{className:`shrink-0 text-[10px] tabular-nums opacity-60`,children:e.endpoints.length})]})}),(0,w.jsx)(u,{children:(0,w.jsx)(`div`,{className:`ml-3 space-y-0.5 mt-0.5`,children:e.endpoints.map((e,t)=>(0,w.jsxs)(`button`,{onClick:()=>ce(e),className:`w-full text-left flex items-center gap-1.5 px-2 py-1 rounded text-xs transition-colors ${k===e?`bg-accent text-accent-foreground`:`hover:bg-muted/50 text-muted-foreground hover:text-foreground`}`,children:[(0,w.jsx)(v,{variant:`outline`,className:`font-mono text-[9px] shrink-0 px-1 py-0 ${T[e.method]||``}`,children:e.method}),(0,w.jsx)(`span`,{className:`truncate`,children:e.desc})]},`${e.method}-${e.path}-${t}`))})})]},e.key)})}),(0,w.jsxs)(`div`,{className:`p-3 border-t space-y-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,w.jsx)(`h4`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:`Query Parameters`}),(0,w.jsxs)(`button`,{onClick:()=>X(),className:`inline-flex items-center gap-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,w.jsx)(h,{className:`h-3 w-3`}),`Add`]})]}),(0,w.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:re.map(e=>(0,w.jsx)(`button`,{onClick:()=>X(e.key,``),className:`text-[10px] px-1.5 py-0.5 rounded border bg-muted/30 text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors font-mono`,title:e.hint,children:e.key},e.key))}),F.length>0&&(0,w.jsx)(`div`,{className:`space-y-1`,children:F.map(e=>(0,w.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>ue(e.id),className:`h-3 w-3 shrink-0 rounded border accent-primary`}),(0,w.jsx)(`input`,{type:`text`,value:e.key,onChange:t=>Z(e.id,`key`,t.target.value),placeholder:`key`,className:`flex-1 min-w-0 rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono focus:outline-none focus:ring-1 focus:ring-ring`}),(0,w.jsx)(`input`,{type:`text`,value:e.value,onChange:t=>Z(e.id,`value`,t.target.value),placeholder:`value`,className:`flex-1 min-w-0 rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono focus:outline-none focus:ring-1 focus:ring-ring`}),(0,w.jsx)(`button`,{onClick:()=>le(e.id),className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-destructive transition-colors`,children:(0,w.jsx)(s,{className:`h-3 w-3`})})]},e.id))})]})]}),(0,w.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 overflow-hidden`,children:[(0,w.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`select`,{value:q,onChange:e=>j(e.target.value),className:`rounded-md border bg-background px-2 py-1.5 font-mono text-xs font-semibold focus:outline-none focus:ring-1 focus:ring-ring ${T[q]||``}`,children:[`GET`,`POST`,`PATCH`,`PUT`,`DELETE`].map(e=>(0,w.jsx)(`option`,{value:e,children:e},e))}),(0,w.jsx)(`input`,{type:`text`,value:J,onChange:e=>M(e.target.value),className:`flex-1 rounded-md border bg-background px-3 py-1.5 font-mono text-sm focus:outline-none focus:ring-1 focus:ring-ring`,placeholder:`/api/v1/...`,onKeyDown:e=>{e.key===`Enter`&&Q()}}),(0,w.jsxs)(`button`,{onClick:Q,disabled:L||!Y,className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-4 py-1.5 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:[L?(0,w.jsx)(f,{className:`h-3.5 w-3.5 animate-spin`}):(0,w.jsx)(i,{className:`h-3.5 w-3.5`}),`Send`]})]}),F.some(e=>e.enabled&&e.key.trim())&&(0,w.jsxs)(`div`,{className:`text-[10px] font-mono text-muted-foreground truncate pl-1`,children:[`→ `,Y]})]}),(0,w.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 overflow-auto`,children:[[`POST`,`PATCH`,`PUT`].includes(q)&&(0,w.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,w.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Request Body (JSON)`}),(0,w.jsx)(`textarea`,{value:N,onChange:e=>P(e.target.value),rows:5,className:`w-full rounded-md border bg-background px-3 py-2 font-mono text-xs focus:outline-none focus:ring-1 focus:ring-ring resize-y`,placeholder:`{ "key": "value" }`})]}),L&&(0,w.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,w.jsx)(f,{className:`h-4 w-4 animate-spin mr-2`}),`Sending request...`]}),z&&!L&&(0,w.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-muted/30 border-b`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,w.jsx)(`span`,{className:`font-mono font-semibold ${$(z.status)}`,children:z.status||`ERR`}),(0,w.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1`,children:[(0,w.jsx)(te,{className:`h-3 w-3`}),z.duration,`ms`]})]}),(0,w.jsxs)(`button`,{onClick:fe,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[W?(0,w.jsx)(c,{className:`h-3 w-3`}):(0,w.jsx)(ee,{className:`h-3 w-3`}),W?`Copied`:`Copy`]})]}),(0,w.jsx)(`pre`,{className:`flex-1 overflow-auto p-3 text-xs font-mono bg-muted/10 whitespace-pre-wrap break-all`,children:z.body})]}),!z&&!L&&(0,w.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-muted-foreground text-sm`,children:(0,w.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,w.jsx)(_,{className:`h-10 w-10 mx-auto opacity-20`}),(0,w.jsxs)(`p`,{children:[`Select an endpoint or type a URL and click `,(0,w.jsx)(`strong`,{children:`Send`})]}),(0,w.jsx)(`p`,{className:`text-xs opacity-60`,children:`All registered APIs are auto-discovered from the platform`})]})}),V.length>0&&(0,w.jsxs)(`div`,{className:`border-t`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2`,children:[(0,w.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:[`History (`,V.length,`)`]}),(0,w.jsxs)(`button`,{onClick:()=>H([]),className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,w.jsx)(m,{className:`h-3 w-3`}),`Clear`]})]}),(0,w.jsx)(`div`,{className:`space-y-0.5 px-2 pb-2 max-h-60 overflow-auto`,children:V.map(e=>(0,w.jsxs)(`div`,{className:`rounded border`,children:[(0,w.jsxs)(`button`,{onClick:()=>oe(U===e.id?null:e.id),className:`w-full flex items-center gap-2 px-2 py-1.5 text-xs hover:bg-muted/30 transition-colors`,children:[U===e.id?(0,w.jsx)(p,{className:`h-3 w-3 shrink-0`}):(0,w.jsx)(l,{className:`h-3 w-3 shrink-0`}),(0,w.jsx)(v,{variant:`outline`,className:`font-mono text-[9px] shrink-0 ${T[e.method]||``}`,children:e.method}),(0,w.jsx)(`span`,{className:`font-mono truncate text-left flex-1`,children:e.url}),(0,w.jsx)(`span`,{className:`ml-auto shrink-0 font-mono ${$(e.status)}`,children:e.status}),(0,w.jsxs)(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.duration,`ms`]}),(0,w.jsx)(`button`,{onClick:t=>{t.stopPropagation(),de(e)},className:`shrink-0 p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors`,title:`Replay request`,children:(0,w.jsx)(i,{className:`h-2.5 w-2.5`})})]}),U===e.id&&(0,w.jsx)(`pre`,{className:`px-3 py-2 text-xs font-mono bg-muted/10 border-t overflow-auto max-h-40 whitespace-pre-wrap break-all`,children:e.response})]},e.id))})]})]})]})]})}export{O as ApiConsolePage};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,f as n,r,t as i}from"./vendor-react-slxo-5GC.js";import{d as a,f as ee}from"./infrastructure-BySW-NB0.js";import{a as te}from"./framework-CAn_0ZHj.js";import{Ai as ne,Ar as re,Cr as o,G as ie,Gs as ae,Gt as oe,Hs as se,Ht as ce,Is as le,Jt as ue,K as de,Kt as fe,Ns as pe,Os as me,Sr as he,Ui as ge,Us as _e,Ut as ve,Vt as ye,Wr as be,Wt as xe,Xo as Se,Xt as Ce,Y as we,Yt as s,Zt as Te,_r as c,_t as Ee,br as l,ct as De,dr as Oe,dt as ke,er as Ae,fr as je,ft as Me,gr as u,gt as d,hc as Ne,hi as Pe,hr as f,ht as p,jc as m,ki as Fe,ln as Ie,lt as Le,mr as h,mt as Re,nr as ze,pn as Be,pt as Ve,qt as He,sr as Ue,ss as We,tr as Ge,us as Ke,ut as qe,vr as g,vs as Je,vt as Ye,wc as Xe,ws as Ze,xr as _,yr as v,zr as Qe,zt as y}from"./ui-components-BNnJ5f3_.js";import{r as b}from"./vendor-ui-utils-C1OpMExs.js";var x=e(t(),1),$e=`${``.replace(/\/$/,``)}/api/v1`;async function S(e,t){let n=await fetch(`${$e}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers||{}},...t}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=r?.code??`HTTP_${n.status}`,t=r?.message??r?.error??n.statusText,i=Error(`${e}: ${t}`);throw i.code=e,i.status=n.status,i.details=r,i}return r}var C={listProcesses(e={}){let t=new URLSearchParams;e.object&&t.set(`object`,e.object),e.activeOnly&&t.set(`activeOnly`,`true`);let n=t.toString();return S(`/approvals/processes${n?`?${n}`:``}`)},listRequests(e={}){let t=new URLSearchParams;e.status&&t.set(`status`,e.status),e.object&&t.set(`object`,e.object),e.recordId&&t.set(`recordId`,e.recordId);let n=Array.isArray(e.approverId)?e.approverId.filter(Boolean).join(`,`):e.approverId;n&&t.set(`approverId`,n),e.submitterId&&t.set(`submitterId`,e.submitterId),e.q?.trim()&&t.set(`q`,e.q.trim()),e.limit!=null&&t.set(`limit`,String(e.limit)),e.offset!=null&&t.set(`offset`,String(e.offset));let r=t.toString();return S(`/approvals/requests${r?`?${r}`:``}`)},async getRequest(e){return{data:await S(`/approvals/requests/${encodeURIComponent(e)}`)}},listActions(e){return S(`/approvals/requests/${encodeURIComponent(e)}/actions`)},async approve(e,t){let n=await S(`/approvals/requests/${encodeURIComponent(e)}/approve`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,finalized:n.finalized}},async reject(e,t){let n=await S(`/approvals/requests/${encodeURIComponent(e)}/reject`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,finalized:n.finalized}},async recall(e,t){return{data:(await S(`/approvals/requests/${encodeURIComponent(e)}/recall`,{method:`POST`,body:JSON.stringify(t)})).request,finalized:!0}},async reassign(e,t){return{data:(await S(`/approvals/requests/${encodeURIComponent(e)}/reassign`,{method:`POST`,body:JSON.stringify(t)})).request}},async remind(e,t={}){let n=await S(`/approvals/requests/${encodeURIComponent(e)}/remind`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,notified:n.notified}},async requestInfo(e,t){return{data:(await S(`/approvals/requests/${encodeURIComponent(e)}/request-info`,{method:`POST`,body:JSON.stringify(t)})).request}},async sendBack(e,t){let n=await S(`/approvals/requests/${encodeURIComponent(e)}/revise`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,autoRejected:n.autoRejected===!0}},async resubmit(e,t={}){let n=await S(`/approvals/requests/${encodeURIComponent(e)}/resubmit`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,resumed:n.resumed===!0}},async comment(e,t){return{data:(await S(`/approvals/requests/${encodeURIComponent(e)}/comment`,{method:`POST`,body:JSON.stringify(t)})).request}},async submit(e){return S(`/approvals/requests`,{method:`POST`,body:JSON.stringify(e)})}};function et(e){if(!e)return[];let t=new Set;e.id&&t.add(e.id),e.email&&t.add(e.email);let n=[...e.roles||[],...typeof e.role==`string`?e.role.split(`,`):[]];for(let e of n){let n=String(e).trim();n&&t.add(`role:${n}`)}return Array.from(t)}var w=i(),tt=50,nt={pending:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-400`,approved:`border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-500/30 dark:bg-emerald-500/10 dark:text-emerald-400`,rejected:`border-red-200 bg-red-50 text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-400`,recalled:`border-border bg-muted text-muted-foreground`,returned:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-500/30 dark:bg-violet-500/10 dark:text-violet-400`};function rt(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function T(e){return e?e.includes(`@`)?e:e.startsWith(`role:`)?`Role: ${e.slice(5)}`:e.length>14?`${e.slice(0,6)}…${e.slice(-4)}`:e:`—`}function E(e){return e&&String(e).replace(/^flow:/,``).trim().split(/[_\-\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)||`—`}function it(e){return e.process_label||E(e.process_name)}function at(e){return e.step_label?e.step_label:e.current_step?E(e.current_step):null}function ot(e){return e.submitter_name||T(e.submitter_id)}function st(e,t){return t.pending_approver_names?.[e]||T(e)}function ct(e){return e.object_label||e.object_name}function D(e){return e.submitted_at||e.created_at||void 0}function O(e){let t=D(e);if(!t)return null;let n=Date.parse(t);return Number.isNaN(n)?null:(Date.now()-n)/36e5}function lt(e){if(e.status!==`pending`)return`text-muted-foreground`;let t=O(e);return t==null?`text-muted-foreground`:t>72?`text-red-600 dark:text-red-400 font-medium`:t>24?`text-amber-600 dark:text-amber-400`:`text-muted-foreground`}function ut(e){let t=Math.max(1,Math.round(Math.abs(e)/36e5));return t<48?`${t}h`:`${Math.round(t/24)}d`}var dt=new Set([`id`,`created_at`,`updated_at`,`created_by`,`updated_by`,`organization_id`]);function k(e){return e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function A(e,t){if(typeof t==`boolean`)return t?`✓`:`—`;if(typeof t==`number`){if(t>0xe8d4a51000&&/(_at$|_date$|^date_|_time$)/.test(e))try{return new Date(t).toLocaleDateString()}catch{}return t.toLocaleString()}let n=String(t);if(/^\d{4}-\d{2}-\d{2}T\d{2}/.test(n))try{return new Date(n).toLocaleString()}catch{}return n}var ft=/^[A-Za-z0-9_-]{15,}$/;function pt(e,t,n=6){if(!e||typeof e!=`object`||Array.isArray(e))return[];let r=[];for(let[i,a]of Object.entries(e)){if(dt.has(i)||a==null||typeof a==`object`||String(a).trim()===``)continue;let e=t?.[i];if(!(!e&&typeof a==`string`&&ft.test(a.trim())&&!/^\d+$/.test(a.trim()))&&(r.push([k(i),e??A(i,a)]),r.length>=n))break}return r}function mt(){let{t:e,language:t}=te(),{user:i}=ee(),$e=a(),{appName:S}=n(),E=(0,x.useMemo)(()=>et(i),[i]),O=(0,x.useCallback)((t,n,r)=>String(e(`approvalsInbox.${t}`,{defaultValue:n,...r})),[e]),dt=(0,x.useCallback)(e=>{if(!e)return`—`;let n=Date.parse(e);if(Number.isNaN(n))return e;let r=Math.round((Date.now()-n)/1e3);if(r<45)return O(`justNow`,`just now`);let i=Math.round(r/60);if(i<60)return O(`minutesAgo`,`{{count}}m ago`,{count:i});let a=Math.round(i/60);if(a<24)return O(`hoursAgo`,`{{count}}h ago`,{count:a});let ee=Math.round(a/24);if(ee<30)return O(`daysAgo`,`{{count}}d ago`,{count:ee});try{return new Date(e).toLocaleDateString(t)}catch{return e}},[O,t]),k=(0,x.useCallback)(e=>{switch(e){case`pending`:return O(`statusPending`,`Pending`);case`approved`:return O(`statusApproved`,`Approved`);case`rejected`:return O(`statusRejected`,`Rejected`);case`recalled`:return O(`statusRecalled`,`Recalled`);case`returned`:return O(`statusReturned`,`Returned for revision`);default:return e}},[O]),A=(0,x.useCallback)((e,t)=>{let n=e?.code??``,r=e?.status??0;return n===`NOT_IMPLEMENTED`||r===501?O(`recallUnavailable`,`Recall is not available on this deployment.`):n===`THROTTLED`||r===429?O(`remindThrottled`,`A reminder was sent recently — try again later.`):r===404?O(`requestGone`,`This request no longer exists. Refresh the list.`):n===`FORBIDDEN`||r===403?O(`notAllowed`,`You are not allowed to perform this action.`):n===`INVALID_STATE`||r===409?O(`alreadyDecided`,`This request was already decided. Refresh the list.`):e?.message||t},[O]);function ft({status:e}){return(0,w.jsx)(Ue,{variant:`outline`,className:m(`font-medium`,nt[e]??``),children:k(e)})}let mt=(0,x.useCallback)(e=>`/apps/${S||`setup`}/${encodeURIComponent(e.object_name)}/record/${encodeURIComponent(e.record_id)}`,[S]),[j,ht]=(0,x.useState)(`pending`),[M,gt]=(0,x.useState)([]),[_t,vt]=(0,x.useState)(!1),[yt,bt]=(0,x.useState)(!1),[xt,St]=(0,x.useState)(null),[Ct,wt]=(0,x.useState)(null),[Tt,Et]=(0,x.useState)(0),[N,Dt]=(0,x.useState)(null),[P,Ot]=(0,x.useState)(null),[kt,At]=(0,x.useState)([]),[jt,Mt]=(0,x.useState)(!1),[F,I]=(0,x.useState)(``),[L,Nt]=(0,x.useState)(``),[R,Pt]=(0,x.useState)(null),[z,Ft]=(0,x.useState)(``),[It,Lt]=(0,x.useState)(``),[Rt,zt]=(0,x.useState)(`all`),[Bt,Vt]=(0,x.useState)(`all`),[B,Ht]=(0,x.useState)(`all`),[V,Ut]=(0,x.useState)(new Set),[Wt,Gt]=(0,x.useState)(!1),[H,Kt]=(0,x.useState)(null),[qt,Jt]=(0,x.useState)(null),[Yt,Xt]=(0,x.useState)(!1),[Zt,Qt]=(0,x.useState)(``),[$t,en]=(0,x.useState)(!1),[tn,nn]=(0,x.useState)(``),[rn,an]=(0,x.useState)(!1),[on,sn]=(0,x.useState)(``),[cn,ln]=(0,x.useState)(!1),[un,dn]=(0,x.useState)(``),[U,W]=(0,x.useState)(!1),[fn,pn]=(0,x.useState)([]),[mn,hn]=(0,x.useState)(-1);(0,x.useEffect)(()=>{if(j===`pending`)return;let e=window.setTimeout(()=>Lt(z),350);return()=>window.clearTimeout(e)},[z,j]);let G=(0,x.useCallback)(async()=>{vt(!0),wt(null);try{let e=[];if(j===`pending`)e=E.length?(await C.listRequests({status:`pending`,approverId:E})).data:[],Et(e.length),St(null);else{let t={q:It||void 0,status:B===`all`?void 0:B,limit:tt,offset:0};if(j===`submitted`){let n=i?.id;if(n){let r=await C.listRequests({submitterId:n,...t});e=r.data,St(r.total??r.data.length)}else e=[],St(0)}else{let n=await C.listRequests(t);e=n.data,St(n.total??n.data.length)}E.length&&C.listRequests({status:`pending`,approverId:E}).then(e=>Et(e.data.length)).catch(()=>{})}e.sort((e,t)=>(D(t)||``).localeCompare(D(e)||``)),gt(e)}catch(e){wt(e?.message||String(e)),gt([])}finally{vt(!1)}},[j,E,i?.id,It,B]);(0,x.useEffect)(()=>{G()},[G]);let gn=(0,x.useCallback)(async()=>{if(!(j===`pending`||yt)){bt(!0);try{let e=await C.listRequests({submitterId:j===`submitted`?i?.id??void 0:void 0,q:It||void 0,status:B===`all`?void 0:B,limit:tt,offset:M.length});gt(t=>{let n=new Set(t.map(e=>e.id));return[...t,...e.data.filter(e=>!n.has(e.id))]}),e.total!=null&&St(e.total)}catch(e){b.error(A(e,O(`loadFailed`,`Failed to load request`)))}finally{bt(!1)}}},[j,yt,i?.id,It,B,M.length,A,O]),K=(0,x.useCallback)(async e=>{Dt(e),Mt(!0),I(``),Nt(``);try{let[t,n]=await Promise.all([C.getRequest(e),C.listActions(e)]);Ot(t.data),At(n.data)}catch(e){b.error(A(e,O(`loadFailed`,`Failed to load request`))),Ot(null),At([])}finally{Mt(!1)}},[A,O]),_n=()=>{Dt(null),Ot(null),At([]),I(``),Nt(``)},q=(0,x.useCallback)(e=>{if(L.trim())return L.trim();if(!e)return i?.id||``;let t=new Set(e.pending_approvers||[]);for(let e of E)if(t.has(e))return e;return i?.id||``},[L,E,i?.id]),J=(0,x.useCallback)(()=>{E.length&&C.listRequests({status:`pending`,approverId:E}).then(e=>Et(e.data.length)).catch(()=>{})},[E]),vn=(0,x.useCallback)(async e=>{if(!P)return;let t=e===`recall`&&i?.id||q(P);if(!t){b.error(O(`noActor`,`Cannot determine the acting identity`));return}Pt(e);try{let n={actor_id:t,comment:F.trim()||void 0},r=await(e===`approve`?C.approve:e===`reject`?C.reject:C.recall)(P.id,n);if(b.success(e===`approve`?r.finalized?O(`approvedFinal`,`Approved`):O(`approvedWaiting`,`Approved — waiting on the remaining approvers`):e===`reject`?O(`rejectedToast`,`Rejected`):O(`recalledToast`,`Request recalled`)),I(``),e!==`recall`&&j===`pending`){let e=Rn.current,t=e.findIndex(e=>e.id===P.id),n=e[t+1]??e[t-1];G(),n&&n.id!==P.id?K(n.id):_n();return}let[i,a]=await Promise.all([C.getRequest(P.id),C.listActions(P.id)]);Ot(i.data),At(a.data),G()}catch(e){b.error(A(e,O(`actionFailed`,`Action failed`)))}finally{Pt(null)}},[P,q,F,G,i?.id,A,O,j,K]),Y=(0,x.useCallback)(async e=>{let[t,n]=await Promise.all([C.getRequest(e),C.listActions(e)]);Ot(t.data),At(n.data),G()},[G]),yn=(0,x.useCallback)(async()=>{if(!(!P||!Zt.trim())){W(!0);try{await C.reassign(P.id,{actor_id:q(P),to:Zt.trim(),comment:F.trim()||void 0}),b.success(O(`reassignSuccess`,`Handed to {{to}}`,{to:Zt.trim()})),Xt(!1),Qt(``),I(``),await Y(P.id),J()}catch(e){b.error(A(e,O(`actionFailed`,`Action failed`)))}finally{W(!1)}}},[P,Zt,F,q,Y,J,A,O]),bn=(0,x.useCallback)(async()=>{if(P){W(!0);try{let e=await C.remind(P.id,{actor_id:i?.id});b.success(O(`remindSuccess`,`Reminder sent to {{count}} approver(s)`,{count:e.notified})),await Y(P.id)}catch(e){b.error(A(e,O(`actionFailed`,`Action failed`)))}finally{W(!1)}}},[P,i?.id,Y,A,O]),xn=(0,x.useCallback)(async()=>{if(!(!P||!tn.trim())){W(!0);try{await C.requestInfo(P.id,{actor_id:q(P),comment:tn.trim()}),b.success(O(`requestInfoSent`,`Sent back to the requester for more information`)),en(!1),nn(``),await Y(P.id)}catch(e){b.error(A(e,O(`actionFailed`,`Action failed`)))}finally{W(!1)}}},[P,tn,q,Y,A,O]),Sn=(0,x.useCallback)(async()=>{if(P){W(!0);try{let e=await C.sendBack(P.id,{actor_id:q(P),comment:on.trim()||void 0});b.success(e.autoRejected?O(`sendBackAutoRejected`,`Revision limit reached — the request was auto-rejected`):O(`sendBackSuccess`,`Sent back for revision — the requester can now edit and resubmit`)),an(!1),sn(``),await Y(P.id),J()}catch(e){b.error(A(e,O(`actionFailed`,`Action failed`)))}finally{W(!1)}}},[P,on,q,Y,J,A,O]),Cn=(0,x.useCallback)(async()=>{if(P){ln(!0);try{await C.resubmit(P.id,{actor_id:i?.id,comment:F.trim()||void 0}),b.success(O(`resubmitSuccess`,`Resubmitted — a new approval round has opened`)),I(``),await Y(P.id),J()}catch(e){b.error(A(e,O(`actionFailed`,`Action failed`)))}finally{ln(!1)}}},[P,F,i?.id,Y,J,A,O]),wn=(0,x.useCallback)(async()=>{if(!(!P||!un.trim())){W(!0);try{await C.comment(P.id,{actor_id:i?.id,comment:un.trim()}),dn(``),await Y(P.id)}catch(e){b.error(A(e,O(`actionFailed`,`Action failed`)))}finally{W(!1)}}},[P,un,i?.id,Y,A,O]),Tn=(0,x.useCallback)(async()=>{if(!fn.length)try{let e=``.replace(/\/$/,``);pn(((await(await fetch(`${e}/api/v1/data/sys_user?limit=100`,{credentials:`include`})).json()).records||[]).filter(e=>e.email&&e.name&&e.id!==i?.id).map(e=>({name:String(e.name),email:String(e.email)})))}catch{}},[fn.length,i?.id]),En=(0,x.useMemo)(()=>{if(!P||P.status!==`pending`)return!1;let e=new Set(P.pending_approvers||[]);return E.some(t=>e.has(t))||L.trim().length>0},[P,E,L]),Dn=(0,x.useMemo)(()=>!P||P.status!==`pending`?!1:P.submitter_id===i?.id||L.trim().length>0,[P,i?.id,L]),On=(0,x.useMemo)(()=>!P||P.status!==`returned`?!1:P.submitter_id===i?.id||L.trim().length>0,[P,i?.id,L]),kn=(0,x.useMemo)(()=>{let e=new Set;for(let t of M)e.add(it(t));return Array.from(e).sort()},[M]),An=(0,x.useMemo)(()=>{let e=new Set;for(let t of M)t.object_name&&e.add(t.object_name);return Array.from(e).sort()},[M]),X=(0,x.useMemo)(()=>{let e=z.trim().toLowerCase();return M.filter(t=>Rt!==`all`&&it(t)!==Rt||Bt!==`all`&&t.object_name!==Bt||B!==`all`&&t.status!==B?!1:j!==`pending`||!e?!0:[t.process_name,t.process_label,t.step_label,t.object_name,t.record_id,t.record_title,t.submitter_id,t.submitter_name,...t.pending_approvers||[]].filter(Boolean).join(` `).toLowerCase().includes(e))},[M,z,Rt,Bt,B,j]),Z=(0,x.useMemo)(()=>N?X.findIndex(e=>e.id===N):-1,[X,N]);(0,x.useEffect)(()=>{if(V.size===0)return;let e=new Set(X.map(e=>e.id)),t=!1,n=new Set;for(let r of V)e.has(r)?n.add(r):t=!0;t&&Ut(n)},[X,V]),(0,x.useEffect)(()=>{mn>=X.length&&hn(X.length-1)},[X.length,mn]);let Q=(0,x.useCallback)(e=>{if(e.status!==`pending`)return!1;let t=new Set(E);return(e.pending_approvers||[]).some(e=>t.has(e))},[E]),$=(0,x.useMemo)(()=>X.filter(e=>V.has(e.id)&&Q(e)),[X,V,Q]),jn=X.filter(e=>e.status===`pending`),Mn=jn.length>0&&jn.every(e=>V.has(e.id)),Nn=(0,x.useCallback)(()=>{Ut(e=>{if(Mn)return new Set;let t=new Set(e);for(let e of jn)t.add(e.id);return t})},[Mn,jn]),Pn=(0,x.useCallback)(e=>{Ut(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),Fn=(0,x.useCallback)(async e=>{let t=$;if(t.length===0)return;Gt(!0);let n=0,r=[];for(let a of t){let t=new Set(a.pending_approvers||[]),ee=E.find(e=>t.has(e))||i?.id||``;try{await(e===`approve`?C.approve:C.reject)(a.id,{actor_id:ee}),n++}catch{r.push(a.record_title||T(a.record_id))}}if(Gt(!1),Ut(new Set),r.length===0)b.success(e===`approve`?O(`bulkApproved`,`Approved {{count}} requests`,{count:n}):O(`bulkRejected`,`Rejected {{count}} requests`,{count:n}));else{let e=r.slice(0,3).join(`, `);b.error(O(`bulkPartial`,`{{ok}} succeeded, {{fail}} failed: {{which}}`,{ok:n,fail:r.length,which:e+(r.length>3?`…`:``)}))}G(),J()},[$,E,i?.id,G,J,O]),In=(0,x.useCallback)(async e=>{if(!Q(e)||qt)return;let t=new Set(e.pending_approvers||[]),n=E.find(e=>t.has(e))||i?.id||``;Jt(e.id);try{let t=await C.approve(e.id,{actor_id:n});b.success(t.finalized?O(`inlineApproved`,`Approved "{{title}}"`,{title:e.record_title||T(e.record_id)}):O(`approvedWaiting`,`Approved — waiting on the remaining approvers`)),G(),J()}catch(e){b.error(A(e,O(`actionFailed`,`Action failed`)))}finally{Jt(null)}},[Q,qt,E,i?.id,G,J,A,O]),Ln=(0,x.useCallback)(async()=>{let e=H;if(!e)return;let t=new Set(e.pending_approvers||[]),n=E.find(e=>t.has(e))||i?.id||``;Jt(e.id),Kt(null);try{await C.reject(e.id,{actor_id:n}),b.success(O(`inlineRejected`,`Rejected "{{title}}"`,{title:e.record_title||T(e.record_id)})),G(),J()}catch(e){b.error(A(e,O(`actionFailed`,`Action failed`)))}finally{Jt(null)}},[H,E,i?.id,G,J,A,O]),Rn=(0,x.useRef)(X);Rn.current=X;let zn=(0,x.useRef)(mn);zn.current=mn,(0,x.useEffect)(()=>{let e=e=>{if(N||H)return;let t=e.target,n=t?.tagName;if(n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t?.isContentEditable||document.querySelector(`[role="alertdialog"]`))return;let r=Rn.current;if(!r.length)return;let i=zn.current;e.key===`j`||e.key===`ArrowDown`?(e.preventDefault(),hn(Math.min(i+1,r.length-1))):e.key===`k`||e.key===`ArrowUp`?(e.preventDefault(),hn(Math.max(i-1,0))):e.key===`Enter`&&i>=0&&r[i]?(e.preventDefault(),K(r[i].id)):(e.key===`x`||e.key===` `)&&i>=0&&r[i]&&j===`pending`?(e.preventDefault(),Pn(r[i].id)):e.key===`a`&&i>=0&&r[i]?(e.preventDefault(),In(r[i])):e.key===`r`&&i>=0&&r[i]&&Q(r[i])&&(e.preventDefault(),Kt(r[i]))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[N,H,j,K,Pn,In,Q]),(0,x.useEffect)(()=>{if(!N)return;let e=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;let t=e.target,n=t?.tagName;if(n===`INPUT`||n===`TEXTAREA`||n===`SELECT`||t?.isContentEditable||document.querySelector(`[role="alertdialog"]`))return;let r=Rn.current,i=r.findIndex(e=>e.id===N);if(i<0)return;let a=e.key===`ArrowLeft`?r[i-1]:r[i+1];a&&(e.preventDefault(),K(a.id))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[N,K]);let Bn=!!z||Rt!==`all`||Bt!==`all`||B!==`all`,Vn=e=>{ht(e),Ht(`all`),zt(`all`),Vt(`all`),Ft(``),hn(-1)};function Hn({r:e}){return(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`div`,{className:`font-medium truncate`,children:it(e)}),(0,w.jsxs)(`div`,{className:`text-xs text-muted-foreground truncate`,children:[at(e)||`—`,(e.round??1)>1&&(0,w.jsx)(`span`,{className:`ml-1.5 text-violet-600 dark:text-violet-400`,children:O(`roundChip`,`Round {{n}}`,{n:e.round})})]})]})}function Un({r:e}){return(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsxs)(r,{to:mt(e),onClick:e=>e.stopPropagation(),className:`inline-flex items-center gap-1 text-sm hover:underline truncate max-w-full`,title:e.record_id,children:[(0,w.jsx)(`span`,{className:`truncate`,children:e.record_title||T(e.record_id)}),(0,w.jsx)(Se,{className:`h-3 w-3 shrink-0 text-muted-foreground`})]}),(0,w.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:ct(e)})]})}function Wn({r:e}){if(!Q(e))return null;let t=qt===e.id;return(0,w.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 focus-within:opacity-100 transition-opacity`,onClick:e=>e.stopPropagation(),children:[(0,w.jsx)(o,{size:`sm`,variant:`ghost`,className:`h-7 px-2 text-emerald-700 hover:text-emerald-800 hover:bg-emerald-50 dark:text-emerald-400`,disabled:t,onClick:()=>void In(e),"aria-label":O(`approve`,`Approve`),children:(0,w.jsx)(pe,{className:`h-4 w-4`})}),(0,w.jsx)(o,{size:`sm`,variant:`ghost`,className:`h-7 px-2 text-red-600 hover:text-red-700 hover:bg-red-50 dark:text-red-400`,disabled:t,onClick:()=>Kt(e),"aria-label":O(`reject`,`Reject`),children:(0,w.jsx)(Ze,{className:`h-4 w-4`})})]})}return(0,w.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-6xl`,children:[(0,w.jsxs)(`header`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`h1`,{className:`text-2xl font-semibold flex items-center gap-2`,children:[(0,w.jsx)(Pe,{className:`h-6 w-6`}),O(`title`,`Approvals Inbox`)]}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:O(`subtitle`,`Review and act on approval requests.`)})]}),(0,w.jsxs)(o,{variant:`outline`,size:`sm`,onClick:G,disabled:_t,className:`self-start sm:self-auto`,children:[(0,w.jsx)(ge,{className:`h-4 w-4 mr-2 ${_t?`animate-spin`:``}`}),O(`refresh`,`Refresh`)]})]}),Ct&&(0,w.jsxs)(Oe,{variant:`destructive`,children:[(0,w.jsx)(le,{className:`h-4 w-4`}),(0,w.jsx)(je,{children:Ct})]}),(0,w.jsxs)(Le,{value:j,onValueChange:Vn,children:[(0,w.jsxs)(ke,{children:[(0,w.jsxs)(Me,{value:`pending`,children:[O(`tabMyPending`,`My Pending`),Tt>0&&(0,w.jsx)(Ue,{variant:`secondary`,className:`ml-2`,children:Tt})]}),(0,w.jsx)(Me,{value:`submitted`,children:O(`tabSubmitted`,`Submitted by me`)}),(0,w.jsx)(Me,{value:`all`,children:O(`tabAll`,`All`)})]}),(0,w.jsxs)(qe,{value:j,className:`mt-4 space-y-3`,children:[!_t&&(M.length>0||j!==`pending`&&(It||B!==`all`))&&(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-sm`,children:[(0,w.jsx)(ne,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,w.jsx)(Ie,{value:z,onChange:e=>Ft(e.target.value),placeholder:O(`searchPlaceholder`,`Search record, process, requester…`),className:`pl-8 h-8 text-sm`}),z&&(0,w.jsx)(`button`,{type:`button`,onClick:()=>Ft(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,"aria-label":O(`clearSearch`,`Clear search`),children:(0,w.jsx)(re,{className:`h-3.5 w-3.5`})})]}),j!==`pending`&&(0,w.jsxs)(He,{value:B,onValueChange:Ht,children:[(0,w.jsx)(Ce,{className:`h-8 w-auto min-w-[130px] text-sm`,children:(0,w.jsx)(Te,{placeholder:O(`statusFilter`,`Status`)})}),(0,w.jsxs)(ue,{children:[(0,w.jsx)(s,{value:`all`,children:O(`allStatuses`,`All statuses`)}),(0,w.jsx)(s,{value:`pending`,children:k(`pending`)}),(0,w.jsx)(s,{value:`approved`,children:k(`approved`)}),(0,w.jsx)(s,{value:`rejected`,children:k(`rejected`)}),(0,w.jsx)(s,{value:`recalled`,children:k(`recalled`)}),(0,w.jsx)(s,{value:`returned`,children:k(`returned`)})]})]}),kn.length>1&&(0,w.jsxs)(He,{value:Rt,onValueChange:zt,children:[(0,w.jsx)(Ce,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,w.jsx)(Te,{placeholder:O(`processFilter`,`Process`)})}),(0,w.jsxs)(ue,{children:[(0,w.jsx)(s,{value:`all`,children:O(`allProcesses`,`All processes`)}),kn.map(e=>(0,w.jsx)(s,{value:e,children:e},e))]})]}),An.length>1&&(0,w.jsxs)(He,{value:Bt,onValueChange:Vt,children:[(0,w.jsx)(Ce,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,w.jsx)(Te,{placeholder:O(`objectFilter`,`Object`)})}),(0,w.jsxs)(ue,{children:[(0,w.jsx)(s,{value:`all`,children:O(`allObjects`,`All objects`)}),An.map(e=>(0,w.jsx)(s,{value:e,children:e},e))]})]}),Bn&&(0,w.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:O(`filterCount`,`{{shown}} of {{total}}`,{shown:X.length,total:M.length})})]}),j===`pending`&&V.size>0&&(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2 rounded-md border bg-accent/30 text-sm`,children:[(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`strong`,{children:V.size}),` `,O(`selected`,`selected`),$.length!==V.size&&(0,w.jsx)(`span`,{className:`text-muted-foreground ml-1`,children:O(`actionableCount`,`({{count}} actionable)`,{count:$.length})})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsxs)(h,{children:[(0,w.jsx)(he,{asChild:!0,children:(0,w.jsxs)(o,{size:`sm`,disabled:Wt||$.length===0,children:[(0,w.jsx)(pe,{className:`h-3.5 w-3.5 mr-1`}),O(`approveN`,`Approve {{count}}`,{count:$.length||``})]})}),(0,w.jsxs)(c,{children:[(0,w.jsxs)(l,{children:[(0,w.jsx)(_,{children:O(`bulkApproveTitle`,`Approve {{count}} requests?`,{count:$.length})}),(0,w.jsx)(g,{children:O(`bulkApproveBody`,`Each request is approved with your identity and its flow continues down the approve branch.`)})]}),(0,w.jsxs)(v,{children:[(0,w.jsx)(u,{children:O(`cancel`,`Cancel`)}),(0,w.jsx)(f,{onClick:()=>Fn(`approve`),children:O(`approveN`,`Approve {{count}}`,{count:$.length})})]})]})]}),(0,w.jsxs)(h,{children:[(0,w.jsx)(he,{asChild:!0,children:(0,w.jsxs)(o,{size:`sm`,variant:`outline`,disabled:Wt||$.length===0,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,w.jsx)(Ze,{className:`h-3.5 w-3.5 mr-1`}),O(`rejectN`,`Reject {{count}}`,{count:$.length||``})]})}),(0,w.jsxs)(c,{children:[(0,w.jsxs)(l,{children:[(0,w.jsx)(_,{children:O(`bulkRejectTitle`,`Reject {{count}} requests?`,{count:$.length})}),(0,w.jsx)(g,{children:O(`bulkRejectBody`,`This rejects the selected requests and notifies their submitters.`)})]}),(0,w.jsxs)(v,{children:[(0,w.jsx)(u,{children:O(`cancel`,`Cancel`)}),(0,w.jsx)(f,{onClick:()=>Fn(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:O(`rejectN`,`Reject {{count}}`,{count:$.length})})]})]})]}),(0,w.jsx)(o,{size:`sm`,variant:`ghost`,onClick:()=>Ut(new Set),disabled:Wt,children:O(`clear`,`Clear`)})]})]}),_t?(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(y,{className:`h-10 w-full`}),(0,w.jsx)(y,{className:`h-10 w-full`}),(0,w.jsx)(y,{className:`h-10 w-full`})]}):M.length===0?(0,w.jsx)(`div`,{className:`flex items-center justify-center min-h-[240px] rounded-md border border-dashed`,children:(0,w.jsxs)(ie,{children:[(0,w.jsx)(we,{children:O(`emptyTitle`,`No requests`)}),(0,w.jsx)(de,{children:j===`pending`?O(`emptyPending`,`You're all caught up — nothing is waiting on you.`):O(`emptyOther`,`Nothing here yet.`)}),j===`pending`&&(0,w.jsx)(o,{variant:`link`,size:`sm`,className:`mt-1`,onClick:()=>Vn(`all`),children:O(`emptyViewAll`,`Browse all requests`)})]})}):X.length===0?(0,w.jsx)(`div`,{className:`flex items-center justify-center min-h-[160px] rounded-md border border-dashed text-sm text-muted-foreground`,children:O(`noMatches`,`No matches for current filters.`)}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(Ge,{className:`hidden md:block`,children:(0,w.jsx)(ze,{className:`p-0`,children:(0,w.jsxs)(Ve,{children:[(0,w.jsx)(Ee,{children:(0,w.jsxs)(Ye,{children:[j===`pending`&&(0,w.jsx)(d,{className:`w-10`,children:(0,w.jsx)(Ae,{checked:Mn,onCheckedChange:Nn,"aria-label":O(`selectAll`,`Select all`),disabled:jn.length===0})}),(0,w.jsx)(d,{children:O(`colRequest`,`Request`)}),(0,w.jsx)(d,{children:O(`colRecord`,`Record`)}),(0,w.jsx)(d,{children:O(`colRequester`,`Requester`)}),(0,w.jsx)(d,{children:O(`colStatus`,`Status`)}),(0,w.jsx)(d,{children:O(`colWaiting`,`Submitted`)}),(0,w.jsx)(d,{className:`w-20`,"aria-label":O(`colActions`,`Actions`)})]})}),(0,w.jsx)(Re,{children:X.map((e,t)=>(0,w.jsxs)(Ye,{className:m(`group cursor-pointer hover:bg-accent/50`,mn===t&&`ring-2 ring-inset ring-ring bg-accent/30`),onClick:()=>{hn(t),K(e.id)},children:[j===`pending`&&(0,w.jsx)(p,{className:`w-10`,onClick:e=>e.stopPropagation(),children:(0,w.jsx)(Ae,{checked:V.has(e.id),onCheckedChange:()=>Pn(e.id),disabled:e.status!==`pending`,"aria-label":O(`selectRow`,`Select request`)})}),(0,w.jsx)(p,{children:(0,w.jsx)(Hn,{r:e})}),(0,w.jsx)(p,{children:(0,w.jsx)(Un,{r:e})}),(0,w.jsx)(p,{children:(0,w.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm`,children:[(0,w.jsx)(Qe,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,w.jsx)(`span`,{className:`truncate`,title:e.submitter_id||``,children:ot(e)})]})}),(0,w.jsx)(p,{children:(0,w.jsx)(ft,{status:e.status})}),(0,w.jsxs)(p,{className:m(`text-xs whitespace-nowrap`,lt(e)),title:rt(D(e)),children:[(0,w.jsx)(Je,{className:`h-3 w-3 inline mr-1`}),dt(D(e)),e.status===`pending`&&e.sla_due_at&&(0,w.jsx)(`div`,{className:m(`mt-0.5 text-[10px] font-medium`,Date.parse(e.sla_due_at)<Date.now()?`text-red-600 dark:text-red-400`:`text-muted-foreground`),children:Date.parse(e.sla_due_at)<Date.now()?O(`slaOverdue`,`SLA overdue {{dur}}`,{dur:ut(Date.now()-Date.parse(e.sla_due_at))}):O(`slaRemaining`,`SLA {{dur}} left`,{dur:ut(Date.parse(e.sla_due_at)-Date.now())})})]}),(0,w.jsx)(p,{className:`w-20`,children:(0,w.jsx)(Wn,{r:e})})]},e.id))})]})})}),(0,w.jsx)(`div`,{className:`md:hidden space-y-2`,children:X.map(e=>(0,w.jsx)(Ge,{className:`cursor-pointer active:bg-accent/50`,onClick:()=>void K(e.id),children:(0,w.jsxs)(ze,{className:`p-3 space-y-1.5`,children:[(0,w.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,w.jsx)(`div`,{className:`font-medium text-sm truncate`,children:it(e)}),(0,w.jsx)(ft,{status:e.status})]}),(0,w.jsxs)(`div`,{className:`text-sm truncate`,children:[e.record_title||T(e.record_id),(0,w.jsx)(`span`,{className:`text-muted-foreground text-xs ml-1.5`,children:ct(e)})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between text-xs text-muted-foreground`,children:[(0,w.jsxs)(`span`,{className:`inline-flex items-center gap-1 truncate`,children:[(0,w.jsx)(Qe,{className:`h-3 w-3`}),ot(e)]}),(0,w.jsxs)(`span`,{className:m(`inline-flex items-center gap-1 whitespace-nowrap`,lt(e)),children:[(0,w.jsx)(Je,{className:`h-3 w-3`}),dt(D(e))]})]}),Q(e)&&(0,w.jsxs)(`div`,{className:`flex gap-2 pt-1`,onClick:e=>e.stopPropagation(),children:[(0,w.jsxs)(o,{size:`sm`,className:`h-7 flex-1`,disabled:qt===e.id,onClick:()=>void In(e),children:[(0,w.jsx)(pe,{className:`h-3.5 w-3.5 mr-1`}),O(`approve`,`Approve`)]}),(0,w.jsxs)(o,{size:`sm`,variant:`outline`,className:`h-7 flex-1 border-destructive text-destructive`,disabled:qt===e.id,onClick:()=>Kt(e),children:[(0,w.jsx)(Ze,{className:`h-3.5 w-3.5 mr-1`}),O(`reject`,`Reject`)]})]})]})},e.id))}),j!==`pending`&&xt!=null&&(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-3 py-1`,children:[(0,w.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:O(`loadedOf`,`Loaded {{loaded}} of {{total}}`,{loaded:M.length,total:xt})}),M.length<xt&&(0,w.jsx)(o,{size:`sm`,variant:`outline`,disabled:yt,onClick:()=>void gn(),children:yt?O(`loadingMore`,`Loading…`):O(`loadMore`,`Load more`)})]}),(0,w.jsx)(`div`,{className:`hidden md:block text-[11px] text-muted-foreground`,children:O(`keyboardHint`,`Keyboard: j/k move · Enter open · x select · a approve · r reject`)})]})]})]}),(0,w.jsx)(h,{open:Yt,onOpenChange:e=>{e||(Xt(!1),Qt(``))},children:(0,w.jsxs)(c,{children:[(0,w.jsxs)(l,{children:[(0,w.jsx)(_,{children:O(`reassignTitle`,`Hand this approval to someone else?`)}),(0,w.jsx)(g,{children:O(`reassignBody`,`Your approver slot moves to the person you pick — they are notified and can act immediately.`)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(Be,{htmlFor:`reassign-to`,className:`text-xs`,children:O(`reassignTo`,`New approver`)}),(0,w.jsx)(Ie,{id:`reassign-to`,list:`reassign-user-options`,value:Zt,onChange:e=>Qt(e.target.value),placeholder:O(`reassignToPlaceholder`,`Pick a user or type an email / role:<name>`),className:`mt-1`}),(0,w.jsx)(`datalist`,{id:`reassign-user-options`,children:fn.map(e=>(0,w.jsx)(`option`,{value:e.email,children:e.name},e.email))})]}),(0,w.jsxs)(v,{children:[(0,w.jsx)(u,{children:O(`cancel`,`Cancel`)}),(0,w.jsx)(f,{disabled:!Zt.trim()||U,onClick:()=>void yn(),children:O(`reassignBtn`,`Reassign`)})]})]})}),(0,w.jsx)(h,{open:$t,onOpenChange:e=>{e||(en(!1),nn(``))},children:(0,w.jsxs)(c,{children:[(0,w.jsxs)(l,{children:[(0,w.jsx)(_,{children:O(`requestInfoTitle`,`Ask the requester for more information?`)}),(0,w.jsx)(g,{children:O(`requestInfoBody`,`The request stays pending; the requester is notified and can reply on the thread.`)})]}),(0,w.jsx)(De,{value:tn,onChange:e=>nn(e.target.value),rows:3,placeholder:O(`requestInfoPlaceholder`,`What do you need from the requester?`)}),(0,w.jsxs)(v,{children:[(0,w.jsx)(u,{children:O(`cancel`,`Cancel`)}),(0,w.jsx)(f,{disabled:!tn.trim()||U,onClick:()=>void xn(),children:O(`requestInfoBtn`,`Request info`)})]})]})}),(0,w.jsx)(h,{open:rn,onOpenChange:e=>{e||(an(!1),sn(``))},children:(0,w.jsxs)(c,{children:[(0,w.jsxs)(l,{children:[(0,w.jsx)(_,{children:O(`sendBackTitle`,`Send this request back for revision?`)}),(0,w.jsx)(g,{children:O(`sendBackBody`,`This round ends and the record unlocks so the requester can fix the data. When they resubmit, a fresh approval round opens for all approvers.`)})]}),(0,w.jsx)(De,{value:on,onChange:e=>sn(e.target.value),rows:3,placeholder:O(`sendBackPlaceholder`,`What needs to be fixed before this can be approved?`)}),(0,w.jsxs)(v,{children:[(0,w.jsx)(u,{children:O(`cancel`,`Cancel`)}),(0,w.jsx)(f,{disabled:U,onClick:()=>void Sn(),children:O(`sendBackBtn`,`Send back`)})]})]})}),(0,w.jsx)(h,{open:!!H,onOpenChange:e=>!e&&Kt(null),children:(0,w.jsxs)(c,{children:[(0,w.jsxs)(l,{children:[(0,w.jsx)(_,{children:O(`rejectOneTitle`,`Reject "{{title}}"?`,{title:H?H.record_title||T(H.record_id):``})}),(0,w.jsx)(g,{children:O(`rejectOneBody`,`This rejects the request and notifies the submitter.`)})]}),(0,w.jsxs)(v,{children:[(0,w.jsx)(u,{children:O(`cancel`,`Cancel`)}),(0,w.jsx)(f,{onClick:()=>void Ln(),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:O(`reject`,`Reject`)})]})]})}),(0,w.jsx)(ye,{open:!!N,onOpenChange:e=>!e&&_n(),children:(0,w.jsxs)(ce,{className:`w-full sm:max-w-xl overflow-y-auto`,children:[(0,w.jsxs)(xe,{children:[(0,w.jsx)(oe,{children:P?it(P):O(`drawerTitle`,`Approval Request`)}),(0,w.jsx)(ve,{children:P?at(P)||ct(P):``})]}),P&&Z>=0&&X.length>1&&(0,w.jsxs)(`div`,{className:`flex items-center justify-between mt-2 text-xs text-muted-foreground`,children:[(0,w.jsxs)(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,disabled:Z<=0,onClick:()=>{let e=X[Z-1];e&&K(e.id)},children:[(0,w.jsx)(_e,{className:`h-4 w-4 mr-0.5`}),O(`prevRequest`,`Previous`)]}),(0,w.jsx)(`span`,{children:O(`positionOf`,`{{index}} of {{total}}`,{index:Z+1,total:X.length})}),(0,w.jsxs)(o,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,disabled:Z>=X.length-1,onClick:()=>{let e=X[Z+1];e&&K(e.id)},children:[O(`nextRequest`,`Next`),(0,w.jsx)(se,{className:`h-4 w-4 ml-0.5`})]})]}),jt?(0,w.jsxs)(`div`,{className:`space-y-2 mt-6`,children:[(0,w.jsx)(y,{className:`h-6 w-3/4`}),(0,w.jsx)(y,{className:`h-6 w-1/2`}),(0,w.jsx)(y,{className:`h-20 w-full`})]}):P?(0,w.jsxs)(`div`,{className:`space-y-4 mt-6`,children:[(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,w.jsx)(ft,{status:P.status}),(P.round??1)>1&&(0,w.jsx)(Ue,{variant:`outline`,className:`text-[10px] border-violet-200 text-violet-700 dark:border-violet-500/30 dark:text-violet-400`,children:O(`roundChip`,`Round {{n}}`,{n:P.round})}),(0,w.jsxs)(`span`,{className:`inline-flex items-center gap-1`,title:rt(D(P)),children:[(0,w.jsx)(Je,{className:`h-3 w-3`}),O(`submittedAgo`,`Submitted {{when}}`,{when:dt(D(P))})]}),P.completed_at&&(0,w.jsxs)(`span`,{children:[`· `,O(`completedAt`,`Completed {{when}}`,{when:dt(P.completed_at)})]}),P.status===`pending`&&P.sla_due_at&&(0,w.jsx)(Ue,{variant:`outline`,className:m(`text-[10px]`,Date.parse(P.sla_due_at)<Date.now()?`border-red-200 bg-red-50 text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-400`:`border-border text-muted-foreground`),children:Date.parse(P.sla_due_at)<Date.now()?O(`slaOverdue`,`SLA overdue {{dur}}`,{dur:ut(Date.now()-Date.parse(P.sla_due_at))}):O(`slaRemaining`,`SLA {{dur}} left`,{dur:ut(Date.parse(P.sla_due_at)-Date.now())})})]}),(0,w.jsx)(Ge,{children:(0,w.jsxs)(ze,{className:`p-4 space-y-3`,children:[(0,w.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsxs)(r,{to:mt(P),className:`text-base font-semibold hover:underline inline-flex items-center gap-1.5`,children:[(0,w.jsx)(`span`,{className:`truncate`,children:P.record_title||T(P.record_id)}),(0,w.jsx)(Se,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),(0,w.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:ct(P)})]}),(0,w.jsx)(`div`,{className:`text-right text-xs text-muted-foreground shrink-0`,children:(0,w.jsxs)(`div`,{className:`inline-flex items-center gap-1`,children:[(0,w.jsx)(Qe,{className:`h-3 w-3`}),(0,w.jsx)(`span`,{title:P.submitter_id||``,children:ot(P)})]})})]}),pt(P.payload,P.payload_display).length>0&&(0,w.jsx)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2 text-sm border-t pt-3`,children:pt(P.payload,P.payload_display).map(([e,t])=>(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e}),(0,w.jsx)(`div`,{className:`truncate`,title:t,children:t})]},e))}),P.status===`pending`&&(P.pending_approvers||[]).length>0&&(0,w.jsxs)(`div`,{className:`border-t pt-3`,children:[(0,w.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1`,children:O(`waitingOn`,`Waiting on`)}),(0,w.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:(P.pending_approvers||[]).map((e,t)=>(0,w.jsx)(Ue,{variant:`outline`,className:`text-[11px]`,title:e,children:st(e,P)},t))})]})]})}),(P.flow_steps?.length??0)>1&&(0,w.jsx)(`div`,{className:`flex items-center px-1`,"aria-label":O(`stepProgress`,`Approval steps`),children:P.flow_steps.map((e,t)=>(0,w.jsxs)(x.Fragment,{children:[t>0&&(0,w.jsx)(`div`,{className:m(`h-px flex-1 mx-2`,e.state===`done`||e.state===`current`?`bg-emerald-300 dark:bg-emerald-700`:`bg-border`)}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[(0,w.jsx)(`span`,{className:m(`flex items-center justify-center h-5 w-5 rounded-full text-[10px] font-semibold`,e.state===`done`&&`bg-emerald-500 text-white`,e.state===`current`&&`bg-amber-500 text-white ring-2 ring-amber-200 dark:ring-amber-500/30`,e.state===`upcoming`&&`bg-muted text-muted-foreground border`),children:e.state===`done`?(0,w.jsx)(ae,{className:`h-3 w-3`}):t+1}),(0,w.jsx)(`span`,{className:m(`text-xs`,e.state===`current`?`font-medium`:`text-muted-foreground`),children:e.label})]})]},e.id))}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:O(`history`,`Activity`)}),kt.length===0?(0,w.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:O(`noActions`,`No actions yet.`)}):(0,w.jsx)(`ol`,{className:`relative space-y-3 pl-5 before:absolute before:left-[7px] before:top-1 before:bottom-1 before:w-px before:bg-border`,children:kt.map(e=>{let t=e.action===`approve`?`bg-emerald-500`:e.action===`reject`?`bg-destructive`:e.action===`submit`?`bg-blue-500`:e.action===`reassign`?`bg-indigo-500`:e.action===`remind`||e.action===`request_info`?`bg-amber-500`:e.action===`comment`?`bg-slate-400`:e.action===`escalate`?`bg-red-500`:e.action===`revise`?`bg-violet-500`:e.action===`resubmit`?`bg-blue-500`:`bg-muted-foreground`,n=e.actor_id===`system:sla`?O(`systemSlaActor`,`System (SLA)`):e.actor_name??(e.actor_id&&e.actor_id===P.submitter_id?ot(P):T(e.actor_id)),r=e.action===`submit`?O(`actSubmit`,`Submitted`):e.action===`approve`?O(`actApprove`,`Approved`):e.action===`reject`?O(`actReject`,`Rejected`):e.action===`recall`?O(`actRecall`,`Recalled`):e.action===`reassign`?O(`actReassign`,`Reassigned`):e.action===`remind`?O(`actRemind`,`Reminder sent`):e.action===`request_info`?O(`actRequestInfo`,`Requested more info`):e.action===`comment`?O(`actComment`,`Commented`):e.action===`escalate`?O(`actEscalate`,`SLA escalated`):e.action===`revise`?O(`actRevise`,`Sent back for revision`):e.action===`resubmit`?O(`actResubmit`,`Resubmitted`):e.action;return(0,w.jsxs)(`li`,{className:`relative text-xs`,children:[(0,w.jsx)(`span`,{className:`absolute -left-[18px] top-1 h-3 w-3 rounded-full ring-2 ring-background ${t}`,"aria-hidden":!0}),(0,w.jsxs)(`div`,{className:`flex items-baseline gap-1.5 flex-wrap`,children:[(0,w.jsx)(`span`,{className:`font-medium`,children:r}),(0,w.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,w.jsx)(`span`,{title:e.actor_id||``,children:n}),(0,w.jsx)(`span`,{className:`ml-auto text-muted-foreground text-[10px]`,title:rt(e.created_at),children:dt(e.created_at)})]}),e.comment&&(0,w.jsxs)(`div`,{className:`text-muted-foreground italic mt-0.5`,children:[`"`,e.comment,`"`]})]},e.id)})}),P.status===`pending`&&(En||Dn)&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 mt-3`,children:[(0,w.jsx)(Ie,{value:un,onChange:e=>dn(e.target.value),onKeyDown:e=>{e.key===`Enter`&&un.trim()&&(e.preventDefault(),wn())},placeholder:O(`replyPlaceholder`,`Reply on this request…`),className:`h-8 text-sm`}),(0,w.jsx)(o,{size:`sm`,variant:`outline`,className:`h-8 px-2 shrink-0`,disabled:!un.trim()||U,onClick:()=>void wn(),children:(0,w.jsx)(Fe,{className:`h-3.5 w-3.5`})})]})]}),P.payload!=null&&(0,w.jsxs)(`details`,{className:`group`,children:[(0,w.jsx)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground hover:text-foreground select-none`,children:O(`rawData`,`Raw data (JSON)`)}),(0,w.jsxs)(`div`,{className:`mt-2`,children:[(0,w.jsx)(`div`,{className:`flex justify-end`,children:(0,w.jsxs)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(JSON.stringify(P.payload,null,2)),b.success(O(`copied`,`Copied`))}catch{b.error(O(`copyFailed`,`Copy failed`))}},className:`text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,w.jsx)(Ke,{className:`h-3 w-3`}),O(`copy`,`Copy`)]})}),(0,w.jsx)(`pre`,{className:`text-[11px] bg-muted/50 rounded p-2 overflow-auto max-h-48 mt-1`,children:JSON.stringify(P.payload,null,2)})]})]}),P.status===`pending`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fe,{}),(0,w.jsxs)(`div`,{className:`space-y-3`,children:[$e&&(0,w.jsxs)(`details`,{className:`group`,children:[(0,w.jsx)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground hover:text-foreground select-none`,children:O(`overrideActor`,`Act as another identity (admin)`)}),(0,w.jsxs)(`div`,{className:`mt-2`,children:[(0,w.jsx)(Be,{htmlFor:`actor-override`,className:`text-xs`,children:O(`actor`,`Actor`)}),(0,w.jsx)(`input`,{id:`actor-override`,type:`text`,value:L,onChange:e=>Nt(e.target.value),placeholder:`${O(`auto`,`Auto`)}: ${q(P)||`—`}`,className:`w-full mt-1 px-3 py-2 text-sm border rounded-md bg-background`}),(0,w.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:O(`overrideHint`,`e.g. role:sales_manager. Leave blank to use the auto-detected identity.`)})]})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(Be,{htmlFor:`comment`,className:`text-xs`,children:O(`comment`,`Comment (optional)`)}),(0,w.jsx)(`div`,{className:`flex flex-wrap gap-1.5 mt-1.5`,children:[O(`quickPhrase1`,`Approved — meets requirements.`),O(`quickPhrase2`,`Approved with conditions — please monitor execution.`),O(`quickPhrase3`,`Please add supporting material and resubmit.`)].map(e=>(0,w.jsx)(`button`,{type:`button`,onClick:()=>I(e),className:`text-[11px] px-2 py-0.5 rounded-full border text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:e},e))}),(0,w.jsx)(De,{id:`comment`,value:F,onChange:e=>I(e.target.value),rows:2,className:`mt-1`})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,w.jsxs)(o,{size:`sm`,onClick:()=>vn(`approve`),disabled:!En||R!==null,children:[(0,w.jsx)(pe,{className:`h-4 w-4 mr-1`}),R===`approve`?O(`approving`,`Approving…`):O(`approve`,`Approve`)]}),(0,w.jsxs)(h,{children:[(0,w.jsx)(he,{asChild:!0,children:(0,w.jsxs)(o,{size:`sm`,variant:`outline`,disabled:!En||R!==null,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,w.jsx)(Ze,{className:`h-4 w-4 mr-1`}),R===`reject`?O(`rejecting`,`Rejecting…`):O(`reject`,`Reject`)]})}),(0,w.jsxs)(c,{children:[(0,w.jsxs)(l,{children:[(0,w.jsx)(_,{children:O(`rejectTitle`,`Reject this request?`)}),(0,w.jsx)(g,{children:O(`rejectBody`,`This marks the request as rejected and notifies the submitter.`)})]}),(0,w.jsxs)(v,{children:[(0,w.jsx)(u,{children:O(`cancel`,`Cancel`)}),(0,w.jsx)(f,{onClick:()=>vn(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:O(`reject`,`Reject`)})]})]})]}),En&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(o,{size:`sm`,variant:`outline`,disabled:R!==null||U,className:`border-violet-300 text-violet-700 hover:bg-violet-50 dark:text-violet-400`,onClick:()=>an(!0),children:[(0,w.jsx)(We,{className:`h-4 w-4 mr-1`}),O(`sendBackBtn`,`Send back`)]}),(0,w.jsxs)(o,{size:`sm`,variant:`outline`,disabled:R!==null||U,className:`border-amber-300 text-amber-700 hover:bg-amber-50 dark:text-amber-400`,onClick:()=>en(!0),children:[(0,w.jsx)(me,{className:`h-4 w-4 mr-1`}),O(`requestInfoBtn`,`Request info`)]}),(0,w.jsxs)(o,{size:`sm`,variant:`outline`,disabled:R!==null||U,onClick:()=>{Tn(),Xt(!0)},children:[(0,w.jsx)(Xe,{className:`h-4 w-4 mr-1`}),O(`reassignBtn`,`Reassign`)]})]}),Dn&&(0,w.jsxs)(o,{size:`sm`,variant:`outline`,disabled:U,onClick:()=>void bn(),children:[(0,w.jsx)(Ne,{className:`h-4 w-4 mr-1`}),O(`remindBtn`,`Send reminder`)]}),Dn&&(0,w.jsxs)(h,{children:[(0,w.jsx)(he,{asChild:!0,children:(0,w.jsxs)(o,{size:`sm`,variant:`outline`,disabled:R!==null,children:[(0,w.jsx)(be,{className:`h-4 w-4 mr-1`}),R===`recall`?O(`recalling`,`Recalling…`):O(`recall`,`Recall`)]})}),(0,w.jsxs)(c,{children:[(0,w.jsxs)(l,{children:[(0,w.jsx)(_,{children:O(`recallTitle`,`Recall this request?`)}),(0,w.jsx)(g,{children:O(`recallBody`,`This withdraws your request. Approvers can no longer act on it, and the record is unlocked.`)})]}),(0,w.jsxs)(v,{children:[(0,w.jsx)(u,{children:O(`cancel`,`Cancel`)}),(0,w.jsx)(f,{onClick:()=>vn(`recall`),children:O(`recall`,`Recall`)})]})]})]})]}),!En&&(0,w.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:Dn?O(`whyDisabledSubmitter`,`You submitted this request, so you can recall it — but only the assigned approvers can approve or reject.`):O(`whyDisabled`,`Only the assigned approvers can act on this request. It is waiting on: {{who}}.`,{who:(P.pending_approvers||[]).map(e=>st(e,P)).join(`, `)||`—`})})]})]}),On&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(fe,{}),(0,w.jsxs)(`div`,{className:`space-y-3`,children:[(0,w.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:O(`returnedHint`,`An approver sent this back to you. The record is unlocked — fix the data, then resubmit to start a new approval round.`)}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(Be,{htmlFor:`resubmit-comment`,className:`text-xs`,children:O(`comment`,`Comment (optional)`)}),(0,w.jsx)(De,{id:`resubmit-comment`,value:F,onChange:e=>I(e.target.value),rows:2,className:`mt-1`,placeholder:O(`resubmitPlaceholder`,`What did you change?`)})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,w.jsx)(o,{asChild:!0,size:`sm`,variant:`outline`,children:(0,w.jsxs)(r,{to:mt(P),children:[(0,w.jsx)(Se,{className:`h-4 w-4 mr-1`}),O(`editRecordBtn`,`Edit record`)]})}),(0,w.jsxs)(o,{size:`sm`,disabled:cn,onClick:()=>void Cn(),children:[(0,w.jsx)(ge,{className:m(`h-4 w-4 mr-1`,cn&&`animate-spin`)}),cn?O(`resubmitting`,`Resubmitting…`):O(`resubmitBtn`,`Resubmit`)]}),(0,w.jsxs)(h,{children:[(0,w.jsx)(he,{asChild:!0,children:(0,w.jsxs)(o,{size:`sm`,variant:`outline`,disabled:cn,children:[(0,w.jsx)(be,{className:`h-4 w-4 mr-1`}),O(`recall`,`Recall`)]})}),(0,w.jsxs)(c,{children:[(0,w.jsxs)(l,{children:[(0,w.jsx)(_,{children:O(`abandonTitle`,`Abandon this revision?`)}),(0,w.jsx)(g,{children:O(`abandonBody`,`This withdraws the request instead of resubmitting it. The approval ends here.`)})]}),(0,w.jsxs)(v,{children:[(0,w.jsx)(u,{children:O(`cancel`,`Cancel`)}),(0,w.jsx)(f,{onClick:()=>vn(`recall`),children:O(`recall`,`Recall`)})]})]})]})]})]})]})]}):null]})})]})}export{mt as ApprovalsInboxPage};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,t as n}from"./vendor-react-slxo-5GC.js";import{Ai as r,Ar as i,Cr as a,G as ee,Gt as te,Ht as o,Is as ne,Jt as re,K as s,Kt as c,Ui as l,Ut as u,Vt as ie,Wt as ae,Xt as d,Y as f,Yt as p,Zt as m,_t as oe,dr as se,fr as ce,gt as h,ht as g,ji as le,ln as _,mt as ue,nr as v,pn as y,pt as de,qt as fe,sr as b,tr as x,vt as S,zt as C}from"./ui-components-BNnJ5f3_.js";var w=e(t(),1),T=n(),E=`${``.replace(/\/$/,``)}/api/v1`,D=[`create`,`update`,`delete`,`restore`,`login`,`logout`,`permission_change`,`config_change`,`export`,`import`],O={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`},k=50;function A(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function j(e,t=24){return e?e.length>t?`${e.slice(0,t-1)}…`:e:`—`}function M(e){if(!e)return``;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function N(){let[e,t]=(0,w.useState)([]),[n,N]=(0,w.useState)(!1),[P,F]=(0,w.useState)(null),[I,L]=(0,w.useState)(`all`),[R,z]=(0,w.useState)(``),[B,V]=(0,w.useState)(``),[H,U]=(0,w.useState)(``),[W,G]=(0,w.useState)(``),[K,q]=(0,w.useState)(0),[J,Y]=(0,w.useState)(!1),[X,Z]=(0,w.useState)(null),Q=(0,w.useCallback)(async()=>{N(!0),F(null);try{let e={};I&&I!==`all`&&(e.action=I),R.trim()&&(e.object_name=R.trim()),B.trim()&&(e.user_id=B.trim()),H&&(e.created_at={...e.created_at||{},$gte:H}),W&&(e.created_at={...e.created_at||{},$lte:`${W}T23:59:59`});let n=new URLSearchParams;Object.keys(e).length>0&&n.set(`$filter`,JSON.stringify(e)),n.set(`$orderby`,`created_at desc`),n.set(`$top`,`51`),n.set(`$skip`,String(K*k));let r=await fetch(`${E}/data/sys_audit_log?${n.toString()}`,{credentials:`include`});if(!r.ok){let e=await r.text().catch(()=>``);throw Error(`HTTP ${r.status}: ${e.slice(0,200)||r.statusText}`)}let i=await r.json(),a=Array.isArray(i)?i:Array.isArray(i?.records)?i.records:Array.isArray(i?.data)?i.data:[];Y(a.length>k),t(a.slice(0,k))}catch(e){console.warn(`[AuditLogPage] load failed:`,e),F(e?.message||`Failed to load audit log`),t([]),Y(!1)}finally{N(!1)}},[I,R,B,H,W,K]);(0,w.useEffect)(()=>{Q()},[Q]);let pe=(0,w.useCallback)(()=>{L(`all`),z(``),V(``),U(``),G(``),q(0)},[]),$=(0,w.useMemo)(()=>{let e=0;return I!==`all`&&(e+=1),R.trim()&&(e+=1),B.trim()&&(e+=1),H&&(e+=1),W&&(e+=1),e},[I,R,B,H,W]);return(0,T.jsxs)(`div`,{className:`p-6 space-y-4 max-w-screen-2xl mx-auto`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,T.jsx)(le,{className:`h-6 w-6 text-muted-foreground`}),(0,T.jsxs)(`div`,{className:`flex-1`,children:[(0,T.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Audit Log`}),(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Read-only system activity and record changes. Newest first.`})]}),(0,T.jsxs)(a,{variant:`outline`,size:`sm`,onClick:Q,disabled:n,children:[(0,T.jsx)(l,{className:`h-4 w-4 mr-1 ${n?`animate-spin`:``}`}),`Refresh`]})]}),(0,T.jsx)(x,{children:(0,T.jsxs)(v,{className:`p-4 grid grid-cols-1 md:grid-cols-5 gap-3`,children:[(0,T.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,T.jsx)(y,{className:`text-xs`,children:`Action`}),(0,T.jsxs)(fe,{value:I,onValueChange:e=>{L(e),q(0)},children:[(0,T.jsx)(d,{className:`h-9`,children:(0,T.jsx)(m,{})}),(0,T.jsxs)(re,{children:[(0,T.jsx)(p,{value:`all`,children:`All actions`}),D.map(e=>(0,T.jsx)(p,{value:e,children:e},e))]})]})]}),(0,T.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,T.jsx)(y,{className:`text-xs`,children:`Object`}),(0,T.jsx)(_,{placeholder:`e.g. account`,value:R,onChange:e=>{z(e.target.value),q(0)},className:`h-9`})]}),(0,T.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,T.jsx)(y,{className:`text-xs`,children:`Actor (user id)`}),(0,T.jsx)(_,{placeholder:`user id`,value:B,onChange:e=>{V(e.target.value),q(0)},className:`h-9`})]}),(0,T.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,T.jsx)(y,{className:`text-xs`,children:`From`}),(0,T.jsx)(_,{type:`date`,value:H,onChange:e=>{U(e.target.value),q(0)},className:`h-9`})]}),(0,T.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,T.jsx)(y,{className:`text-xs`,children:`To`}),(0,T.jsx)(_,{type:`date`,value:W,onChange:e=>{G(e.target.value),q(0)},className:`h-9`})]}),$>0&&(0,T.jsx)(`div`,{className:`md:col-span-5 flex justify-end`,children:(0,T.jsxs)(a,{variant:`ghost`,size:`sm`,onClick:pe,children:[(0,T.jsx)(i,{className:`h-4 w-4 mr-1`}),`Clear filters (`,$,`)`]})})]})}),P&&(0,T.jsxs)(se,{variant:`destructive`,children:[(0,T.jsx)(ne,{className:`h-4 w-4`}),(0,T.jsx)(ce,{children:P})]}),(0,T.jsx)(x,{children:(0,T.jsx)(v,{className:`p-0`,children:n&&e.length===0?(0,T.jsx)(`div`,{className:`p-6 space-y-2`,children:Array.from({length:6}).map((e,t)=>(0,T.jsx)(C,{className:`h-9 w-full`},t))}):e.length===0?(0,T.jsx)(`div`,{className:`p-12`,children:(0,T.jsxs)(ee,{children:[(0,T.jsx)(r,{className:`h-8 w-8 text-muted-foreground mb-3`}),(0,T.jsx)(f,{children:`No audit entries`}),(0,T.jsx)(s,{children:$>0?`Try clearing filters or widening the date range.`:`Events will appear here once tracked objects are modified.`})]})}):(0,T.jsxs)(de,{children:[(0,T.jsx)(oe,{children:(0,T.jsxs)(S,{children:[(0,T.jsx)(h,{className:`w-[180px]`,children:`Timestamp`}),(0,T.jsx)(h,{className:`w-[130px]`,children:`Action`}),(0,T.jsx)(h,{children:`Object`}),(0,T.jsx)(h,{children:`Record`}),(0,T.jsx)(h,{children:`Actor`}),(0,T.jsx)(h,{className:`w-[130px]`,children:`IP`})]})}),(0,T.jsx)(ue,{children:e.map(e=>{let t=O[e.action||``]||`outline`;return(0,T.jsxs)(S,{className:`cursor-pointer`,onClick:()=>Z(e),children:[(0,T.jsx)(g,{className:`font-mono text-xs`,children:A(e.created_at)}),(0,T.jsx)(g,{children:(0,T.jsx)(b,{variant:t,children:e.action||`—`})}),(0,T.jsx)(g,{children:e.object_name||`—`}),(0,T.jsx)(g,{className:`font-mono text-xs`,children:j(e.record_id,18)}),(0,T.jsx)(g,{className:`font-mono text-xs`,children:j(e.user_id,18)}),(0,T.jsx)(g,{className:`font-mono text-xs`,children:e.ip_address||`—`})]},e.id)})})]})})}),(e.length>0||K>0)&&(0,T.jsxs)(`div`,{className:`flex items-center justify-between text-sm text-muted-foreground`,children:[(0,T.jsxs)(`span`,{children:[`Page `,K+1,J?``:` · end`]}),(0,T.jsxs)(`div`,{className:`flex gap-2`,children:[(0,T.jsx)(a,{variant:`outline`,size:`sm`,disabled:K===0||n,onClick:()=>q(e=>Math.max(0,e-1)),children:`Previous`}),(0,T.jsx)(a,{variant:`outline`,size:`sm`,disabled:!J||n,onClick:()=>q(e=>e+1),children:`Next`})]})]}),(0,T.jsx)(ie,{open:!!X,onOpenChange:e=>!e&&Z(null),children:(0,T.jsxs)(o,{side:`right`,className:`sm:max-w-2xl w-full overflow-y-auto`,children:[(0,T.jsxs)(ae,{children:[(0,T.jsxs)(te,{className:`flex items-center gap-2`,children:[(0,T.jsx)(b,{variant:X&&O[X.action||``]||`outline`,children:X?.action||`—`}),X?.object_name||`Audit Event`]}),(0,T.jsx)(u,{children:X?.id?(0,T.jsx)(`span`,{className:`font-mono text-xs`,children:X.id}):null})]}),X&&(0,T.jsxs)(`div`,{className:`mt-6 space-y-5`,children:[(0,T.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-sm`,children:[(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Timestamp`}),(0,T.jsx)(`div`,{className:`font-mono`,children:A(X.created_at)})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`IP Address`}),(0,T.jsx)(`div`,{className:`font-mono`,children:X.ip_address||`—`})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Actor (user_id)`}),(0,T.jsx)(`div`,{className:`font-mono break-all`,children:X.user_id||`—`})]}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Tenant`}),(0,T.jsx)(`div`,{className:`font-mono break-all`,children:X.tenant_id||`—`})]}),(0,T.jsxs)(`div`,{className:`col-span-2`,children:[(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Target record`}),(0,T.jsxs)(`div`,{className:`font-mono text-sm break-all`,children:[X.object_name||`—`,` / `,X.record_id||`—`]})]}),X.user_agent&&(0,T.jsxs)(`div`,{className:`col-span-2`,children:[(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`User Agent`}),(0,T.jsx)(`div`,{className:`font-mono text-xs break-all`,children:X.user_agent})]})]}),(X.old_value||X.new_value)&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(c,{}),(0,T.jsxs)(`div`,{className:`space-y-3`,children:[(0,T.jsx)(`div`,{className:`text-sm font-medium`,children:`Change payload`}),X.old_value&&(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground mb-1`,children:`Before`}),(0,T.jsx)(`pre`,{className:`rounded-md bg-muted p-3 text-xs font-mono whitespace-pre-wrap max-h-64 overflow-auto`,children:M(X.old_value)})]}),X.new_value&&(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-xs text-muted-foreground mb-1`,children:`After`}),(0,T.jsx)(`pre`,{className:`rounded-md bg-muted p-3 text-xs font-mono whitespace-pre-wrap max-h-64 overflow-auto`,children:M(X.new_value)})]})]})]}),X.metadata&&(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)(c,{}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`div`,{className:`text-sm font-medium mb-2`,children:`Metadata`}),(0,T.jsx)(`pre`,{className:`rounded-md bg-muted p-3 text-xs font-mono whitespace-pre-wrap max-h-48 overflow-auto`,children:M(X.metadata)})]})]})]})]})})]})}export{N as AuditLogPage};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,t as n}from"./vendor-react-slxo-5GC.js";import{R as r,l as i,m as a}from"./vendor-objectstack-BGWJwgbT.js";import{Ac as o,Ai as s,Ar as c,Bn as l,Cr as u,Gs as d,Ha as f,Hn as p,Jr as m,Js as h,Jt as g,Ln as _,Qs as v,Rs as y,Un as b,Vn as x,Xs as S,Xt as C,Yt as w,Zi as T,Zs as E,Zt as D,cn as O,ec as k,is as A,jc as j,ln as M,mo as N,oi as P,on as F,pn as I,ps as ee,qs as te,qt as ne,sn as re,sr as ie,ts as ae,vo as oe,zn as se}from"./ui-components-BNnJ5f3_.js";import{G as ce,H as le,J as ue,K as de,Q as L,W as fe,Y as pe,_ as me,a as he,g as ge,i as _e,j as ve,p as ye,q as R,r as be,t as xe,y as z}from"./ReportDefaultInspector-DdZJIfG8.js";var B=e(t(),1),V=n();function Se(e,t){if(!t)return!0;let n=t.toLowerCase();return e.value.toLowerCase().includes(n)||e.label.toLowerCase().includes(n)||(e.group?.toLowerCase().includes(n)??!1)}function H({label:e,value:t,onCommit:n,options:r,placeholder:i=`Select…`,searchPlaceholder:a=`Search or type…`,emptyText:o=`No match — keep typing to use a custom value.`,disabled:s,loading:c,allowCustom:f=!0,mono:m,className:h}){let[g,v]=B.useState(!1),[S,C]=B.useState(``),w=r.find(e=>e.value===t),T=w?w.label:t||(c?`Loading…`:i),E=B.useMemo(()=>r.filter(e=>Se(e,S)),[r,S]),D=B.useMemo(()=>{let e=[],t=new Map;for(let n of E){let r=n.group??``;t.has(r)||(t.set(r,[]),e.push(r)),t.get(r).push(n)}return e.map(e=>({heading:e,items:t.get(e)}))},[E]),k=S.trim(),A=f&&!!k&&!r.some(e=>e.value===k),M=e=>{n(e),v(!1),C(``)},N=(0,V.jsxs)(F,{open:g,onOpenChange:e=>{v(e),e||C(``)},children:[(0,V.jsx)(O,{asChild:!0,children:(0,V.jsxs)(u,{type:`button`,variant:`outline`,role:`combobox`,"aria-expanded":g,disabled:s,className:j(`h-8 w-full justify-between px-2 text-sm font-normal`,h),children:[(0,V.jsx)(`span`,{className:j(`truncate`,m&&`font-mono`,!w&&!t&&`text-muted-foreground`),children:T}),(0,V.jsx)(y,{className:`ml-2 h-3.5 w-3.5 shrink-0 opacity-50`})]})}),(0,V.jsx)(re,{align:`start`,className:`w-[var(--radix-popover-trigger-width)] min-w-[14rem] p-0`,children:(0,V.jsxs)(_,{shouldFilter:!1,children:[(0,V.jsx)(x,{value:S,onValueChange:C,placeholder:a}),(0,V.jsxs)(b,{children:[!A&&E.length===0&&(0,V.jsx)(se,{children:o}),A&&(0,V.jsx)(l,{children:(0,V.jsx)(p,{value:`__custom__${k}`,onSelect:()=>M(k),children:(0,V.jsxs)(`span`,{className:`truncate`,children:[`Use `,(0,V.jsxs)(`span`,{className:`font-mono`,children:[`“`,k,`”`]})]})})}),D.map((e,n)=>(0,V.jsx)(l,{heading:e.heading||void 0,children:e.items.map(e=>(0,V.jsxs)(p,{value:e.value,onSelect:()=>M(e.value),children:[(0,V.jsx)(d,{className:j(`h-3.5 w-3.5`,e.value===t?`opacity-100`:`opacity-0`)}),(0,V.jsx)(`span`,{className:`truncate font-mono`,children:e.value}),e.label&&e.label!==e.value&&(0,V.jsx)(`span`,{className:`ml-1 truncate text-muted-foreground`,children:e.label}),e.hint&&(0,V.jsx)(`span`,{className:`ml-auto pl-2 text-[10px] text-muted-foreground`,children:e.hint})]},e.value))},e.heading||`g${n}`))]})]})})]});return e?(0,V.jsxs)(`div`,{className:`space-y-1`,children:[(0,V.jsx)(I,{className:`text-xs text-muted-foreground`,children:e}),N]}):N}var Ce=new Set([`lookup`,`master_detail`,`masterdetail`,`master-detail`]);function U(e,t){if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=e.default;if(typeof t==`string`&&t)return t}return t}function we(e){let t=e.reference??e.reference_to??e.referenceTo??e.reference_to_object;if(typeof t==`string`&&t)return t;if(Array.isArray(t)&&typeof t[0]==`string`)return t[0];if(t&&typeof t==`object`){let e=t.object;if(typeof e==`string`&&e)return e}}function Te(e){switch(e){case`lookup`:case`master_detail`:case`masterDetail`:case`master-detail`:return`lookup`;case`date`:case`datetime`:case`time`:return`date`;case`number`:case`currency`:case`percent`:case`int`:case`integer`:case`float`:case`double`:case`autonumber`:return`number`;case`boolean`:case`toggle`:return`boolean`;default:return`string`}}function W(e,t){if(!e)return{label:t,fields:[],relationships:[]};let n=U(e.label,t),r=ve(e.fields).entries.map(e=>({name:e.name,label:U(e.def.label,e.name),type:typeof e.def.type==`string`?e.def.type:void 0,def:e.def}));return{label:n,fields:r,relationships:r.filter(e=>e.type&&Ce.has(e.type.toLowerCase())).map(e=>({name:e.name,label:e.label,referenceTo:we(e.def)}))}}function Ee(e,t,n){let r=e,i=[];for(let e of t.split(`.`)){let t=r.relationships.find(t=>t.name===e);if(!t?.referenceTo)return;let a=n[t.referenceTo];if(!a)return;i.push(t.label),r=a}return{target:r,labels:i}}function De(e,t,n){let r=e.fields.map(t=>({value:t.name,label:t.label,type:t.type,group:e.label}));for(let i of t){let t=Ee(e,i,n);if(!t)continue;let a=[...t.labels,t.target.label].join(` → `);for(let e of t.target.fields)r.push({value:`${i}.${e.name}`,label:e.label,type:e.type,group:a})}return r}function G(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e))return e.some(e=>G(e,t));let n=e;return typeof n.dataset==`string`&&n.dataset===t?!0:Object.values(n).some(e=>e&&typeof e==`object`&&G(e,t))}function K(){let e=L(),[t,n]=B.useState({options:[],loading:!0});return B.useEffect(()=>{let t=!1;return n(e=>({...e,loading:!0})),e.list(`object`).then(e=>{t||n({options:(Array.isArray(e)?e:[]).map(e=>({name:typeof e.name==`string`?e.name:``,label:U(e.label,typeof e.name==`string`?e.name:``)})).filter(e=>!!e.name).sort((e,t)=>e.label.localeCompare(t.label)),loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function Oe(e,t){let n=L(),r=t.join(`\0`),[i,a]=B.useState({relationships:[],fieldOptions:[],loading:!!e});return B.useEffect(()=>{if(!e){a({relationships:[],fieldOptions:[],loading:!1});return}let t=!1;return a(e=>({...e,loading:!0})),(async()=>{try{let i=await n.get(`object`,e);if(t)return;let o=W(i,e),s=r?r.split(`\0`):[],c={[e]:o},l=async e=>{if(c[e])return c[e];let t;try{t=W(await n.get(`object`,e),e)}catch{t=W(null,e)}return c[e]=t,t};for(let e of s){let t=o;for(let n of e.split(`.`)){let e=t.relationships.find(e=>e.name===n);if(!e?.referenceTo)break;t=await l(e.referenceTo)}}if(t)return;let u=[...o.relationships];for(let e of s){if(e.split(`.`).length>=3)continue;let t=Ee(o,e,c);if(t)for(let n of t.target.relationships)u.push({name:`${e}.${n.name}`,label:`${e}.${n.name}`,referenceTo:n.referenceTo})}a({relationships:u,fieldOptions:De(o,s,c),loading:!1})}catch{t||a({relationships:[],fieldOptions:[],loading:!1})}})(),()=>{t=!0}},[n,e,r]),i}function ke(e){let t=L(),[n,r]=B.useState({reports:0,dashboards:0,loading:!!e});return B.useEffect(()=>{if(!e){r({reports:0,dashboards:0,loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),(async()=>{let[i,a]=await Promise.all([t.list(`report`).catch(()=>[]),t.list(`dashboard`).catch(()=>[])]);n||r({reports:(Array.isArray(i)?i:[]).filter(t=>G(t,e)).length,dashboards:(Array.isArray(a)?a:[]).filter(t=>G(t,e)).length,loading:!1})})(),()=>{n=!0}},[t,e]),n}var q={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:N},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:E},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:S},line:{id:`line`,label:`Line chart`,category:`chart`,icon:v},area:{id:`area`,label:`Area chart`,category:`chart`,icon:k},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:h},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:ae},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:te},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:m},table:{id:`table`,label:`Data table`,category:`data`,icon:P},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:A},list:{id:`list`,label:`Record list`,category:`data`,icon:f},custom:{id:`custom`,label:`Custom widget`,category:`custom`,icon:ee}},Ae={kpi:`Single value`,chart:`Charts`,data:`Tabular`,custom:`Custom`},J=[`kpi`,`chart`,`data`,`custom`].map(e=>({category:e,types:Object.values(q).filter(t=>t.category===e)})),Y=o;function X({onAdd:e,label:t=`Add widget`}){let[n,r]=B.useState(!1),[i,a]=B.useState(``),o=B.useRef(null),c=B.useRef(null);B.useEffect(()=>{if(!n){a(``);return}let e=e=>{o.current?.contains(e.target)||r(!1)},t=e=>{e.key===`Escape`&&r(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),queueMicrotask(()=>c.current?.focus()),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[n]);let l=B.useMemo(()=>{let e=i.trim().toLowerCase();return e?J.map(t=>({category:t.category,types:t.types.filter(t=>t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))})).filter(e=>e.types.length):J},[i]);return(0,V.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,V.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:()=>r(e=>!e),children:[(0,V.jsx)(T,{className:`h-3 w-3`}),t]}),n&&(0,V.jsxs)(`div`,{className:`absolute right-0 top-full z-40 mt-1 w-72 rounded-md border bg-popover shadow-md`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,V.jsx)(s,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,V.jsx)(`input`,{ref:c,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Search widgets…`,className:`w-full bg-transparent text-xs outline-none placeholder:text-muted-foreground`})]}),(0,V.jsx)(`div`,{className:`max-h-72 overflow-auto py-1`,children:l.length===0?(0,V.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No matches.`}):l.map(t=>(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:Ae[t.category]}),t.types.map(t=>(0,V.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs hover:bg-accent`,onClick:()=>{e(t.id),r(!1)},children:[(0,V.jsx)(q[t.id]?.icon??Y,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,V.jsx)(`span`,{className:`font-medium truncate`,children:t.label}),(0,V.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground`,children:t.id})]},t.id))]},t.category))})]})]})}var je={io:`input`,unrepresentable:`any`},Me=new Set([`widgets`,`label`,`description`,`name`]),Z,Ne=!1;function Pe(){if(Z||Ne)return Z;try{Z=r(i,je)}catch(e){Ne=!0,typeof console<`u`&&console.warn(`[dashboard-schema] failed to derive Dashboard JSONSchema from spec`,e)}return Z}var Q;function Fe(){if(Q)return Q;if(!(!a||typeof a!=`object`)){try{let e=JSON.parse(JSON.stringify(a));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Me.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Q=e}catch(e){typeof console<`u`&&console.warn(`[dashboard-schema] failed to prepare dashboardForm from spec`,e);return}return Q}}var Ie=new Set([`name`,`label`,`description`,`widgets`]);function Le({draft:e,onPatch:t,readOnly:n,locale:r,onSelectionChange:i,serverSchema:a}){let o=B.useCallback(e=>z(e,r),[r]),s=typeof e.label==`string`?e.label:``,l=typeof e.description==`string`?e.description:``,d=B.useMemo(()=>Array.isArray(e.widgets)?e.widgets:[],[e.widgets]),f=e=>{let n=pe(`widget`,d.map(e=>e?.id).filter(Boolean)),r=q[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`;t({widgets:de(d,{id:n,type:e,title:a,...r?.defaults??{}})}),i?.({kind:`widget`,id:n,label:a})},p=e=>{t({widgets:ue(d,e,null)})},m=(e,n)=>{e!==n&&t({widgets:R(d,e,n)})},h=(e,t)=>{e?.id&&i?.({kind:`widget`,id:e.id,label:e.title||e.id||`Widget ${t+1}`})},[g,_]=B.useState(null),[v,y]=B.useState(null),{schema:b,form:x}=B.useMemo(()=>he({bundledSchema:Pe(),bundledForm:Fe(),serverSchema:a,excludeFields:Ie,sectionTitle:z(`engine.inspector.moreFields`,r)}),[a,r]);return(0,V.jsxs)(fe,{kindLabel:o(`engine.inspector.dashboard.kind`),title:String(s||e.name||o(`engine.inspector.dashboard.kind`)),onClose:()=>{},closeLabel:o(`engine.inspector.dashboard.close`),hideClose:!0,children:[(0,V.jsx)(ce,{label:o(`engine.inspector.dashboard.label`),value:s,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.dashboard.labelPlaceholder`),disabled:n}),(0,V.jsx)(ce,{label:o(`engine.inspector.dashboard.description`),value:l,onCommit:e=>t({description:e}),placeholder:o(`engine.inspector.dashboard.descriptionPlaceholder`),disabled:n}),(0,V.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,V.jsx)(I,{className:`text-xs text-muted-foreground`,children:o(`engine.inspector.dashboard.widgets`)}),(0,V.jsx)(ie,{variant:`outline`,className:`text-[10px]`,children:d.length})]}),d.length===0?(0,V.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.widgetsEmpty`)}):(0,V.jsx)(`div`,{className:`space-y-1`,children:d.map((e,t)=>{let r=q[e?.type]?.icon??Y;return(0,V.jsxs)(`div`,{draggable:!n,onDragStart:()=>_(t),onDragEnd:()=>{_(null),y(null)},onDragOver:e=>{e.preventDefault(),y(t)},onDrop:()=>{g!=null&&g!==t&&m(g,t),_(null),y(null)},className:`group flex items-center gap-2 rounded-md border px-2 py-1.5 text-xs hover:bg-accent`+(v===t&&g!==null&&g!==t?` border-primary`:``),children:[!n&&(0,V.jsx)(oe,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground`}),(0,V.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,V.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 truncate text-left font-medium`,onClick:()=>h(e,t),title:e?.title||e?.id,children:e?.title||e?.id||`Widget ${t+1}`}),(0,V.jsx)(`code`,{className:`text-[10px] text-muted-foreground`,children:e?.type}),!n&&(0,V.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 shrink-0 p-0 opacity-0 group-hover:opacity-100`,onClick:()=>p(t),title:o(`engine.inspector.dashboard.removeWidget`),"aria-label":o(`engine.inspector.dashboard.removeWidget`),children:(0,V.jsx)(c,{className:`h-3.5 w-3.5`})})]},e?.id??t)})}),!n&&(0,V.jsx)(X,{onAdd:f,label:o(`engine.inspector.add.widget`)})]}),(0,V.jsx)(`div`,{className:`border-t pt-3`,children:b?(0,V.jsx)(ye,{schema:b,form:x,value:e,hiddenFields:[`name`,`label`,`description`,`widgets`],readOnly:n,onChange:e=>t(e)}):(0,V.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.noSchema`)})})]})}var Re=[{value:`metric`,label:`KPI Metric`},{value:`bar`,label:`Bar Chart`},{value:`line`,label:`Line Chart`},{value:`pie`,label:`Pie Chart`},{value:`table`,label:`Table`},{value:`grid`,label:`Grid`}],ze=[`count`,`sum`,`avg`,`min`,`max`],Be=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function Ve(e,t){let n=Array.isArray(e.widgets)?e.widgets:[],r=n.findIndex(e=>e?.id===t);return r<0?null:{widget:n[r],index:r}}function He({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=Array.isArray(e.widgets)?e.widgets:[],l=t.kind===`widget`?t.id:void 0,d=l?Ve(e,l):null,f=d?.widget??{},p=typeof f.dataset==`string`?f.dataset:``,m=typeof f.object==`string`?f.object:``,h=Array.isArray(f.dimensions)?f.dimensions.filter(e=>typeof e==`string`):[],_=Array.isArray(f.values)?f.values.filter(e=>typeof e==`string`):[],v=be(),y=_e(p||void 0,v),{options:b,loading:x}=K(),{fields:S}=ge(m||void 0),T=B.useMemo(()=>{let e=v.datasets.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return p&&!e.some(e=>e.value===p)&&e.push({value:p,label:p}),e},[v.datasets,p]),E=B.useMemo(()=>b.map(e=>({value:e.name,label:e.label})),[b]),O=B.useMemo(()=>S.map(e=>({value:e.name,label:e.label,hint:e.type})),[S]),k=B.useMemo(()=>y.measures.map(e=>({name:e.name,label:e.aggregate?`${e.name} · ${e.aggregate}`:e.name,type:`number`,hidden:!1})),[y.measures]),A=B.useMemo(()=>y.dimensions.map(e=>({name:e.name,label:e.name,type:e.type??`text`,hidden:!1})),[y.dimensions]);if(t.kind!==`widget`)return(0,V.jsx)(Ue,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});if(!d)return(0,V.jsx)(Ue,{message:`The selected widget was removed from the draft.`,onClose:r,locale:o});let{widget:j,index:N}=d;function P(e){let t=[...s];t[N]={...t[N],...e},n({widgets:t})}function F(e){n({widgets:R(s,N,e)}),j.id&&i?.({kind:`widget`,id:j.id,label:j.title??void 0})}return(0,V.jsxs)(`div`,{className:`space-y-4`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,V.jsxs)(`div`,{className:`min-w-0`,children:[(0,V.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:z(`engine.inspector.widget.kind`,o)}),(0,V.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:j.title||t.label||`Widget ${N+1}`})]}),(0,V.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,V.jsx)(le,{index:N,total:s.length,onMove:F,upLabel:z(`engine.inspector.reorder.up`,o),downLabel:z(`engine.inspector.reorder.down`,o),disabled:a}),(0,V.jsx)(u,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:z(`engine.inspector.widget.close`,o),"aria-label":z(`engine.inspector.widget.close`,o),children:(0,V.jsx)(c,{className:`h-3.5 w-3.5`})})]})]}),(0,V.jsx)($,{id:`widget-title`,label:z(`engine.inspector.widget.title`,o),children:(0,V.jsx)(M,{id:`widget-title`,value:j.title??``,onChange:e=>P({title:e.target.value}),disabled:a})}),(0,V.jsx)($,{id:`widget-type`,label:z(`engine.inspector.widget.type`,o),children:(0,V.jsxs)(ne,{value:j.type??`metric`,onValueChange:e=>P({type:e}),disabled:a,children:[(0,V.jsx)(C,{id:`widget-type`,children:(0,V.jsx)(D,{})}),(0,V.jsx)(g,{children:Re.map(e=>(0,V.jsx)(w,{value:e.value,children:e.label},e.value))})]})}),(0,V.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed border-primary/40 bg-primary/5 p-3`,children:[(0,V.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-primary/80`,children:z(`engine.inspector.widget.datasetSection`,o)}),(0,V.jsxs)($,{id:`widget-dataset`,label:z(`engine.inspector.widget.dataset`,o),children:[(0,V.jsx)(H,{value:p,onCommit:e=>P({dataset:e||void 0}),options:T,loading:v.loading,placeholder:z(`engine.inspector.widget.datasetPlaceholder`,o),searchPlaceholder:z(`engine.inspector.widget.datasetPlaceholder`,o),disabled:a,mono:!0}),(0,V.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:z(`engine.inspector.widget.datasetHint`,o)})]}),p&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(xe,{label:z(`engine.inspector.widget.dimensions`,o),emptyText:z(`engine.inspector.widget.dimensionsHint`,o),names:h,options:A,loading:y.loading,error:y.error,readOnly:a,onCommit:e=>P({dimensions:e})}),(0,V.jsx)(xe,{label:z(`engine.inspector.widget.values`,o),emptyText:z(`engine.inspector.widget.valuesHint`,o),names:_,options:k,loading:y.loading,error:y.error,readOnly:a,onCommit:e=>P({values:e})})]})]}),(0,V.jsx)($,{id:`widget-object`,label:z(`engine.inspector.widget.object`,o),children:(0,V.jsx)(H,{value:j.object??``,onCommit:e=>P({object:e||void 0}),options:E,loading:x,placeholder:`Select an object…`,searchPlaceholder:`Search objects…`,disabled:a,mono:!0})}),(0,V.jsx)($,{id:`widget-value-field`,label:z(`engine.inspector.widget.valueField`,o),children:(0,V.jsx)(H,{value:j.valueField??``,onCommit:e=>P({valueField:e||void 0}),options:O,placeholder:j.object?`Select a field…`:`e.g. amount`,searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),(0,V.jsx)($,{id:`widget-category-field`,label:z(`engine.inspector.widget.categoryField`,o),children:(0,V.jsx)(H,{value:j.categoryField??``,onCommit:e=>P({categoryField:e||void 0}),options:O,placeholder:j.object?`Select a field…`:`e.g. status`,searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),(0,V.jsx)($,{id:`widget-aggregate`,label:z(`engine.inspector.widget.aggregate`,o),children:(0,V.jsxs)(ne,{value:j.aggregate??`count`,onValueChange:e=>P({aggregate:e}),disabled:a,children:[(0,V.jsx)(C,{id:`widget-aggregate`,children:(0,V.jsx)(D,{})}),(0,V.jsx)(g,{children:ze.map(e=>(0,V.jsx)(w,{value:e,children:e},e))})]})}),(0,V.jsx)($,{id:`widget-color`,label:z(`engine.inspector.widget.color`,o),children:(0,V.jsx)(me,{value:j.colorVariant??`default`,onChange:e=>P({colorVariant:e}),disabled:a,options:Be.map(e=>({value:e}))})}),(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,V.jsx)($,{id:`widget-w`,label:z(`engine.inspector.widget.width`,o),children:(0,V.jsx)(M,{id:`widget-w`,type:`number`,min:1,value:j.layout?.w??1,onChange:e=>P({layout:{...j.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,V.jsx)($,{id:`widget-h`,label:z(`engine.inspector.widget.height`,o),children:(0,V.jsx)(M,{id:`widget-h`,type:`number`,min:1,value:j.layout?.h??1,onChange:e=>P({layout:{...j.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,V.jsx)(`div`,{className:`pt-2 border-t`,children:(0,V.jsx)(u,{type:`button`,variant:`outline`,size:`sm`,className:`w-full text-destructive hover:text-destructive`,onClick:()=>{let t=Array.isArray(e.widgets)?[...e.widgets]:[];t.splice(N,1),n({widgets:t}),r()},children:z(`engine.inspector.widget.remove`,o)})})]})}function $({id:e,label:t,children:n}){return(0,V.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,V.jsx)(I,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function Ue({message:e,onClose:t,locale:n}){return(0,V.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[(0,V.jsx)(`p`,{children:e}),(0,V.jsx)(u,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:z(`engine.inspector.widget.close`,n)})]})}export{Te as a,K as c,q as i,H as l,Le as n,Oe as o,X as r,ke as s,He as t};
@@ -1 +0,0 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{_ as t,t as n}from"./vendor-react-slxo-5GC.js";import{j as r}from"./framework-CAn_0ZHj.js";import{$i as i,Cr as a,Gt as o,Ht as s,Is as c,Mr as l,Ns as u,Qt as d,Ui as f,Ut as p,Va as m,Vt as h,Wt as g,_t as _,ar as v,ct as y,gt as b,ht as x,ir as S,ln as C,mt as w,nr as T,pn as E,pt as D,rr as O,sr as k,tr as A,vs as j,vt as M,ws as N,yt as P,zt as F}from"./ui-components-BNnJ5f3_.js";import"./src-CnWu84r5.js";var I=e(t(),1),L=n();function R({status:e}){let t={success:{icon:u,cls:`text-emerald-600 border-emerald-300`},completed:{icon:u,cls:`text-emerald-600 border-emerald-300`},failed:{icon:N,cls:`text-red-600 border-red-300`},error:{icon:N,cls:`text-red-600 border-red-300`},running:{icon:m,cls:`text-blue-600 border-blue-300 animate-pulse`},pending:{icon:j,cls:`text-amber-600 border-amber-300`},skipped:{icon:c,cls:`text-muted-foreground`}}[e]??{icon:c,cls:`text-muted-foreground`},n=t.icon;return(0,L.jsxs)(k,{variant:`outline`,className:`text-[10px] font-mono inline-flex items-center gap-1 ${t.cls}`,children:[(0,L.jsx)(n,{className:`h-3 w-3`}),e]})}function z(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function B(e,t){switch(t){case`number`:{if(e===``)return;let t=Number(e);return Number.isNaN(t)?e:t}case`boolean`:return e===`true`;case`object`:case`list`:case`array`:if(e.trim()===``)return;try{return JSON.parse(e)}catch{return e}default:return e}}function V({data:e}){return(0,L.jsx)(`pre`,{className:`rounded border bg-muted/30 p-2 text-xs font-mono overflow-auto whitespace-pre-wrap break-all max-h-96`,children:JSON.stringify(e,null,2)})}function H(){let e=r()?.getClient?.(),[t,n]=(0,I.useState)([]),[i,o]=(0,I.useState)(!0),[s,c]=(0,I.useState)(null),[u,d]=(0,I.useState)(``),[p,m]=(0,I.useState)(0),h=(0,I.useCallback)(async()=>{if(!e?.meta?.getItems){c(`meta.getItems is not available on this client`),o(!1);return}o(!0),c(null);try{let t=await e.meta.getItems(`flow`),r=(Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[]).map(e=>({name:e?.spec?.name??e?.name,label:e?.spec?.label,spec:e?.spec??e,updatedAt:e?.updatedAt??e?.updated_at})).filter(e=>e.name);n(r),!u&&r.length>0&&d(r[0].name)}catch(e){c(e?.message??String(e))}finally{o(!1)}},[e,u]);(0,I.useEffect)(()=>{h()},[h]);let g=(0,I.useMemo)(()=>t.find(e=>e.name===u)??null,[t,u]);return(0,L.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsxs)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight flex items-center gap-2`,children:[(0,L.jsx)(l,{className:`h-5 w-5`}),`Flow Runs`]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Pick a flow, trigger a test run with sample inputs, and inspect recent run history`})]}),(0,L.jsxs)(A,{children:[(0,L.jsx)(S,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(v,{className:`text-base`,children:`Flow`}),(0,L.jsx)(O,{children:`Select a flow definition to test`})]}),(0,L.jsxs)(a,{variant:`outline`,size:`sm`,onClick:h,disabled:i,children:[(0,L.jsx)(f,{className:`h-3.5 w-3.5 mr-2 ${i?`animate-spin`:``}`}),`Refresh`]})]})}),(0,L.jsxs)(T,{children:[i&&(0,L.jsx)(F,{className:`h-9 w-72`}),s&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:s}),!i&&!s&&t.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No flow definitions found.`}),!i&&!s&&t.length>0&&(0,L.jsx)(`select`,{value:u,onChange:e=>d(e.target.value),className:`flex h-9 w-full max-w-md rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm focus:outline-none focus:ring-1 focus:ring-ring`,children:t.map(e=>(0,L.jsx)(`option`,{value:e.name,children:e.label?`${e.label} (${e.name})`:e.name},e.name))})]})]}),g&&(0,L.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,L.jsx)(U,{client:e,flow:g.spec,onExecuted:()=>m(e=>e+1)}),(0,L.jsx)(W,{client:e,flowName:g.name,refreshKey:p})]})]})}function U({client:e,flow:t,onExecuted:n}){let r=(0,I.useMemo)(()=>(t?.variables??[]).filter(e=>e?.isInput),[t]),[o,s]=(0,I.useState)({}),[c,l]=(0,I.useState)(!1),[d,f]=(0,I.useState)(null),[p,h]=(0,I.useState)(null);(0,I.useEffect)(()=>{s({}),f(null),h(null)},[t?.name]);let g=(e,t)=>s(n=>({...n,[e]:t}));return(0,L.jsxs)(A,{children:[(0,L.jsxs)(S,{className:`pb-3`,children:[(0,L.jsx)(v,{className:`text-base`,children:`Test Run`}),(0,L.jsx)(O,{children:`Provide input values and invoke the flow`})]}),(0,L.jsxs)(T,{className:`space-y-3`,children:[r.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This flow declares no input variables. Click Run to invoke with no parameters.`}),r.map(e=>(0,L.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,L.jsxs)(E,{htmlFor:`var-${e.name}`,className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`font-mono text-xs`,children:e.name}),(0,L.jsx)(k,{variant:`outline`,className:`text-[10px] font-mono`,children:e.type})]}),e.type===`boolean`?(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(P,{id:`var-${e.name}`,checked:o[e.name]===`true`,onCheckedChange:t=>g(e.name,t?`true`:`false`)}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o[e.name]===`true`?`true`:`false`})]}):e.type===`object`||e.type===`list`||e.type===`array`?(0,L.jsx)(y,{id:`var-${e.name}`,placeholder:`JSON ${e.type}`,value:o[e.name]??``,onChange:t=>g(e.name,t.target.value),className:`font-mono text-xs min-h-[80px]`}):(0,L.jsx)(C,{id:`var-${e.name}`,type:e.type===`number`?`number`:`text`,value:o[e.name]??``,onChange:t=>g(e.name,t.target.value)})]},e.name)),(0,L.jsx)(`div`,{className:`pt-1`,children:(0,L.jsxs)(a,{onClick:async()=>{if(!e?.automation?.execute){h(`automation.execute is not available on this client`);return}l(!0),h(null),f(null);try{let i={};for(let e of r){let t=o[e.name];t!==void 0&&(i[e.name]=B(t,e.type))}f(await e.automation.execute(t.name,{params:i})),n?.()}catch(e){h(e?.message??String(e))}finally{l(!1)}},disabled:c,size:`sm`,children:[c?(0,L.jsx)(m,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(i,{className:`h-3.5 w-3.5 mr-2`}),c?`Running…`:`Run Flow`]})}),(d||p)&&(0,L.jsxs)(`div`,{className:`pt-2 border-t mt-2 space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[p||d?.success===!1?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(N,{className:`h-4 w-4 text-red-500`}),` Failed`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(u,{className:`h-4 w-4 text-emerald-500`}),` Result`]}),typeof d?.durationMs==`number`&&(0,L.jsxs)(k,{variant:`secondary`,className:`text-[10px] font-mono`,children:[d.durationMs,` ms`]})]}),p&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:p}),d&&(0,L.jsx)(V,{data:d})]})]})]})}function W({client:e,flowName:t,refreshKey:n}){let[r,i]=(0,I.useState)([]),[c,l]=(0,I.useState)(!0),[u,y]=(0,I.useState)(null),[C,E]=(0,I.useState)(null),[j,N]=(0,I.useState)(null),[P,B]=(0,I.useState)(!1),[H,U]=(0,I.useState)(null),W=(0,I.useCallback)(async()=>{if(!e?.automation?.listRuns){y(`automation.listRuns is not available on this client`),l(!1);return}l(!0),y(null);try{let n=await e.automation.listRuns(t,{limit:20});i(Array.isArray(n)?n:n?.items??n?.runs??[])}catch(e){y(e?.message??String(e))}finally{l(!1)}},[e,t]);(0,I.useEffect)(()=>{W()},[W,n]);let G=async n=>{E(n),N(null),U(null),B(!0);try{let r=await e.automation.getRun(t,n);N(r?.run??r)}catch(e){U(e?.message??String(e))}finally{B(!1)}};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(A,{children:[(0,L.jsx)(S,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(v,{className:`text-base`,children:`Recent Runs`}),(0,L.jsx)(O,{className:`font-mono text-xs`,children:t})]}),(0,L.jsxs)(a,{variant:`outline`,size:`sm`,onClick:W,disabled:c,children:[c?(0,L.jsx)(m,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(f,{className:`h-3.5 w-3.5 mr-2`}),`Refresh`]})]})}),(0,L.jsxs)(T,{children:[c&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(F,{className:`h-8 w-full`}),(0,L.jsx)(F,{className:`h-8 w-full`}),(0,L.jsx)(F,{className:`h-8 w-full`})]}),!c&&u&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:u}),!c&&!u&&r.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground py-6 text-center`,children:`No runs yet. Use the Test Run panel to invoke this flow.`}),!c&&!u&&r.length>0&&(0,L.jsxs)(D,{children:[(0,L.jsx)(_,{children:(0,L.jsxs)(M,{children:[(0,L.jsx)(b,{children:`Run`}),(0,L.jsx)(b,{children:`Status`}),(0,L.jsx)(b,{children:`Started`}),(0,L.jsx)(b,{className:`text-right`,children:`Duration`})]})}),(0,L.jsx)(w,{children:r.map(e=>(0,L.jsxs)(M,{className:`cursor-pointer`,onClick:()=>G(e.id),children:[(0,L.jsxs)(x,{className:`font-mono text-xs`,children:[e.id.slice(0,12),`…`]}),(0,L.jsx)(x,{children:(0,L.jsx)(R,{status:e.status})}),(0,L.jsx)(x,{className:`text-xs text-muted-foreground`,children:z(e.startedAt)}),(0,L.jsx)(x,{className:`text-right font-mono text-xs`,children:typeof e.durationMs==`number`?`${e.durationMs} ms`:`—`})]},e.id))})]})]})]}),(0,L.jsx)(h,{open:!!C,onOpenChange:e=>{e||(E(null),N(null))},children:(0,L.jsxs)(s,{side:`right`,className:`w-full sm:max-w-2xl p-0 flex flex-col`,children:[(0,L.jsxs)(g,{className:`p-4 border-b`,children:[(0,L.jsxs)(o,{className:`font-mono text-sm break-all`,children:[`Run `,C]}),(0,L.jsx)(p,{children:j&&(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(R,{status:j.status}),typeof j.durationMs==`number`&&(0,L.jsxs)(k,{variant:`secondary`,className:`text-[10px] font-mono`,children:[j.durationMs,` ms`]}),(0,L.jsx)(`span`,{className:`text-xs`,children:z(j.startedAt)})]})})]}),(0,L.jsxs)(d,{className:`flex-1 p-4`,children:[P&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(F,{className:`h-16 w-full`}),(0,L.jsx)(F,{className:`h-16 w-full`}),(0,L.jsx)(F,{className:`h-16 w-full`})]}),H&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:H}),!P&&j&&(0,L.jsx)(`div`,{className:`space-y-3`,children:Array.isArray(j.steps)&&j.steps.length>0?j.steps.map((e,t)=>(0,L.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,L.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs`,children:[`#`,t+1]}),(0,L.jsx)(`span`,{className:`font-mono text-sm font-medium`,children:e.nodeLabel||e.nodeId}),e.nodeType&&(0,L.jsx)(k,{variant:`outline`,className:`text-[10px] font-mono`,children:e.nodeType}),(0,L.jsx)(R,{status:e.status}),typeof e.durationMs==`number`&&(0,L.jsxs)(k,{variant:`secondary`,className:`text-[10px] font-mono ml-auto`,children:[e.durationMs,` ms`]})]}),e.input!==void 0&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground mb-1`,children:`Input`}),(0,L.jsx)(V,{data:e.input})]}),e.output!==void 0&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground mb-1`,children:`Output`}),(0,L.jsx)(V,{data:e.output})]}),e.error&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[10px] uppercase text-red-500 mb-1`,children:`Error`}),(0,L.jsx)(V,{data:e.error})]})]},`${e.nodeId}-${t}`)):(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground mb-1`,children:`Run`}),(0,L.jsx)(V,{data:j})]})})]})]})})]})}export{H as FlowRunsPage};