@objectstack/console 12.4.0 → 12.5.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 (34) hide show
  1. package/dist/.objectui-sha +1 -1
  2. package/dist/assets/{AdapterProvider-DYYVhErE.js → AdapterProvider-qwVfmAEk.js} +1 -1
  3. package/dist/assets/{ApiConsolePage-DqCLFtg6.js → ApiConsolePage-V6XcLsX4.js} +1 -1
  4. package/dist/assets/{AppDocsIndex-ChTjYsgs.js → AppDocsIndex-C4IIeN6V.js} +1 -1
  5. package/dist/assets/{AppManagementPage-CpBtMYk7.js → AppManagementPage-WCLo2V17.js} +1 -1
  6. package/dist/assets/{ConsoleFloatingChatbot-BtSnKZ5C.js → ConsoleFloatingChatbot-mf-pVd3G.js} +1 -1
  7. package/dist/assets/{DashboardView-DTeb8b6a.js → DashboardView-CPFt6TBZ.js} +1 -1
  8. package/dist/assets/{DashboardWidgetInspector-CUJFDeER.js → DashboardWidgetInspector-DknOds9r.js} +1 -1
  9. package/dist/assets/{FlowRunsPage-BCTyVNQV.js → FlowRunsPage-QMVLQvu7.js} +1 -1
  10. package/dist/assets/{InterfaceListPage-CaG6oJ3-.js → InterfaceListPage-Dbt7lZbl.js} +1 -1
  11. package/dist/assets/{MarketplacePackagePage-CxoOdisY.js → MarketplacePackagePage-CiRyU-vK.js} +1 -1
  12. package/dist/assets/{MetadataProvider-BpQl3Bw2.js → MetadataProvider-DKJsxrNu.js} +1 -1
  13. package/dist/assets/{ObjectDataPage-CnMdpBNe.js → ObjectDataPage-CAJf6Pu3.js} +1 -1
  14. package/dist/assets/{PageView-Ckvi7QO6.js → PageView-GYrk78oW.js} +1 -1
  15. package/dist/assets/{PublicFormsPage-xWq9jZzJ.js → PublicFormsPage-DmpEEcq4.js} +1 -1
  16. package/dist/assets/{RecordFormPage-DTyNzewM.js → RecordFormPage-DadWkJyX.js} +1 -1
  17. package/dist/assets/ReportDefaultInspector-CJGXWwWN.js +11 -0
  18. package/dist/assets/{ReportView-CHBbT7mP.js → ReportView-CIZjxMSJ.js} +1 -1
  19. package/dist/assets/{SearchResultsPage-BIuFjDoa.js → SearchResultsPage-BPDjxMw8.js} +1 -1
  20. package/dist/assets/{SystemHubPage-f4hYqDoI.js → SystemHubPage-2aGKeHcn.js} +1 -1
  21. package/dist/assets/data-adapter-Bm8GGtft.js +7 -0
  22. package/dist/assets/index-BXgUF5nO.css +2 -0
  23. package/dist/assets/{index-TdJi7kFM.js → index-PrzZHiAk.js} +1 -1
  24. package/dist/assets/{metadata-admin-DJAg5WLs.js → metadata-admin-CleGXds3.js} +1 -1
  25. package/dist/assets/src-BBieSqPB.js +16 -0
  26. package/dist/assets/{useMetadata-Eb5o6ihl.js → useMetadata-Ily0JuNR.js} +1 -1
  27. package/dist/assets/{useOpenRecordList-DIo7M1au.js → useOpenRecordList-tyj2_1bm.js} +1 -1
  28. package/dist/assets/{useReconcileOnError-4is_Tic6.js → useReconcileOnError-_XnUvYJA.js} +1 -1
  29. package/dist/index.html +2 -2
  30. package/package.json +1 -1
  31. package/dist/assets/ReportDefaultInspector-BA-D9th_.js +0 -11
  32. package/dist/assets/data-adapter-DLOPVTZ2.js +0 -7
  33. package/dist/assets/index-B-sF8xtC.css +0 -2
  34. package/dist/assets/src-6xqJEeiC.js +0 -15
@@ -1 +1 @@
1
- 6cbccf386cf3fe15d1b8e79ab69fcf8f08c4cadf
1
+ c27bd3264f394bec5f5f71326118bfb115fbe884
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{m as r}from"./infrastructure-Bcx6-8du.js";import{F as i}from"./framework-B3O15Lsq.js";import{t as a}from"./data-adapter-DLOPVTZ2.js";var o=e(n(),1),s=0,c=new Set,l=[];function u(){for(let e of c)try{e(s)}catch{}if(s===0&&l.length>0){let e=l;l=[];for(let t of e)try{t()}catch{}}}function d(){s+=1,u()}function f(){s=Math.max(0,s-1),u()}function p(){return s}function m(){return s===0}function h(e){return c.add(e),()=>{c.delete(e)}}function g(e=1e4){return s===0?Promise.resolve():new Promise(t=>{let n=!1,r=()=>{n||(n=!0,t())};l.push(r),e>0&&typeof setTimeout<`u`&&setTimeout(r,e)})}function _(e){return(async(...t)=>{d();try{return await e(...t)}finally{f()}})}function v(){if(typeof window>`u`)return;let e=window,t=e.__objectui??={};Object.defineProperty(t,"pendingRequests",{get:p,configurable:!0}),Object.defineProperty(t,"idle",{get:m,configurable:!0}),t.whenIdle=g,t.subscribe=h}var y=t();function b({children:e,adapter:t}){let[n,s]=(0,o.useState)(t??null);return(0,o.useEffect)(()=>{if(t){s(t);return}let e=!1;v();async function n(){try{let t=new a({baseUrl:``,fetch:_(r()),autoReconnect:!0,maxReconnectAttempts:5,reconnectDelay:1e3,cache:{maxSize:50,ttl:3e5}});await t.connect(),e||s(t)}catch(t){e||console.error(`[Console] Failed to initialize:`,t)}}return n(),()=>{e=!0}},[t]),(0,y.jsx)(i.Provider,{value:n,children:e})}export{b as t};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{m as r}from"./infrastructure-Bcx6-8du.js";import{F as i}from"./framework-B3O15Lsq.js";import{t as a}from"./data-adapter-Bm8GGtft.js";var o=e(n(),1),s=0,c=new Set,l=[];function u(){for(let e of c)try{e(s)}catch{}if(s===0&&l.length>0){let e=l;l=[];for(let t of e)try{t()}catch{}}}function d(){s+=1,u()}function f(){s=Math.max(0,s-1),u()}function p(){return s}function m(){return s===0}function h(e){return c.add(e),()=>{c.delete(e)}}function g(e=1e4){return s===0?Promise.resolve():new Promise(t=>{let n=!1,r=()=>{n||(n=!0,t())};l.push(r),e>0&&typeof setTimeout<`u`&&setTimeout(r,e)})}function _(e){return(async(...t)=>{d();try{return await e(...t)}finally{f()}})}function v(){if(typeof window>`u`)return;let e=window,t=e.__objectui??={};Object.defineProperty(t,"pendingRequests",{get:p,configurable:!0}),Object.defineProperty(t,"idle",{get:m,configurable:!0}),t.whenIdle=g,t.subscribe=h}var y=t();function b({children:e,adapter:t}){let[n,s]=(0,o.useState)(t??null);return(0,o.useEffect)(()=>{if(t){s(t);return}let e=!1;v();async function n(){try{let t=new a({baseUrl:``,fetch:_(r()),autoReconnect:!0,maxReconnectAttempts:5,reconnectDelay:1e3,cache:{maxSize:50,ttl:3e5}});await t.connect(),e||s(t)}catch(t){e||console.error(`[Console] Failed to initialize:`,t)}}return n(),()=>{e=!0}},[t]),(0,y.jsx)(i.Provider,{value:n,children:e})}export{b as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{L as r}from"./framework-B3O15Lsq.js";import{Bs as i,Hs as a,Oi as o,Or as s,Us as c,Vi as l,Xn as u,Yi as d,Yn as f,Zi as p,Zn as m,ar as h,cs as g,gs as _,qr as v,vo as y,za as b}from"./ui-components-rkvkkTxO.js";import"./src-6xqJEeiC.js";var x=e(n(),1),S=[`plugin`,`plugins`,`kind`,`package`];function C(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 w={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 T(e,t){let n=w[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 ee(){let e=r(),[t,n]=(0,x.useState)([]),[i,a]=(0,x.useState)([]),[o,s]=(0,x.useState)(!0),[c,l]=(0,x.useState)(null),u=(0,x.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(w)){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(...T(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=>!S.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,...C(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`],y=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}));n(y),a(g)}catch(e){l(e.message||`Failed to discover APIs`)}finally{s(!1)}},[e]);return(0,x.useEffect)(()=>{u()},[u]),{groups:t,allEndpoints:i,loading:o,error:c,refresh:u}}var E=t(),D={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`},te={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`},ne=[{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`}],O=1;function k(){let e=r()?.getClient?.(),{groups:t,loading:n,refresh:S}=ee(),[C,w]=(0,x.useState)(``),[T,k]=(0,x.useState)(new Set),[A,j]=(0,x.useState)(null),[re,M]=(0,x.useState)(``),[ie,N]=(0,x.useState)(``),[P,F]=(0,x.useState)(``),[I,L]=(0,x.useState)([]),[R,z]=(0,x.useState)(!1),[B,V]=(0,x.useState)(null),[H,U]=(0,x.useState)([]),[W,ae]=(0,x.useState)(null),[G,K]=(0,x.useState)(!1),q=(0,x.useMemo)(()=>{if(!C)return t;let e=C.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,C]),oe=(0,x.useCallback)(e=>{k(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=(0,x.useCallback)(e=>{j(e),M(e.method),N(e.path),F(e.bodyTemplate?JSON.stringify(e.bodyTemplate,null,2):``),L([]),V(null)},[]),J=re||A?.method||`GET`,Y=ie||A?.path||``,X=(0,x.useMemo)(()=>{let e=I.filter(e=>e.enabled&&e.key.trim());if(e.length===0)return Y;let t=e.map(e=>`${encodeURIComponent(e.key)}=${encodeURIComponent(e.value)}`).join(`&`);return`${Y}?${t}`},[Y,I]),Z=(0,x.useCallback)((e=``,t=``)=>{L(n=>[...n,{id:O++,key:e,value:t,enabled:!0}])},[]),ce=(0,x.useCallback)(e=>{L(t=>t.filter(t=>t.id!==e))},[]),Q=(0,x.useCallback)((e,t,n)=>{L(r=>r.map(r=>r.id===e?{...r,[t]:n}:r))},[]),le=(0,x.useCallback)(e=>{L(t=>t.map(t=>t.id===e?{...t,enabled:!t.enabled}:t))},[]),$=(0,x.useCallback)(async()=>{if(R||!X)return;let t=`${e?.baseUrl??``}${X}`;z(!0);let n=performance.now();try{let e={method:J,headers:{"Content-Type":`application/json`}};[`POST`,`PATCH`,`PUT`].includes(J)&&P.trim()&&(e.body=P);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();let o={status:r.status,body:a,duration:i};V(o),U(e=>[{id:Date.now(),method:J,url:X,body:P||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);V({status:0,body:`Network Error: ${e.message}`,duration:t})}finally{z(!1)}},[e,X,J,P,R]),ue=(0,x.useCallback)(e=>{M(e.method);let[t,n]=e.url.split(`?`);if(N(t),F(e.body||``),n){let e=new URLSearchParams(n),t=[];e.forEach((e,n)=>{t.push({id:O++,key:n,value:e,enabled:!0})}),L(t)}else L([]);V(null),j(null)},[]),de=(0,x.useCallback)(()=>{B?.body&&(navigator.clipboard.writeText(B.body),K(!0),setTimeout(()=>K(!1),1500))},[B]),fe=e=>te[String(e)[0]]??`text-muted-foreground`;return(0,E.jsxs)(`div`,{className:`flex flex-1 min-h-0 overflow-hidden`,children:[(0,E.jsxs)(`div`,{className:`w-72 shrink-0 border-r flex flex-col overflow-hidden`,children:[(0,E.jsxs)(`div`,{className:`p-3 border-b space-y-2`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`h3`,{className:`text-sm font-semibold text-foreground flex-1`,children:`API Endpoints`}),(0,E.jsx)(`button`,{onClick:S,disabled:n,className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,title:`Refresh endpoints`,children:(0,E.jsx)(l,{className:`h-3.5 w-3.5 ${n?`animate-spin`:``}`})})]}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(o,{className:`absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,E.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(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,E.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:n?(0,E.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,E.jsx)(b,{className:`h-4 w-4 animate-spin mr-2`}),`Discovering APIs...`]}):q.length===0?(0,E.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,E.jsx)(y,{className:`h-6 w-6 opacity-30 mb-2`}),(0,E.jsx)(`span`,{children:C?`No matching endpoints`:`No endpoints found`})]}):q.map(e=>{let t=T.has(e.key)||!!C;return(0,E.jsxs)(f,{open:t,onOpenChange:()=>oe(e.key),children:[(0,E.jsx)(m,{asChild:!0,children:(0,E.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,E.jsx)(i,{className:`h-3 w-3 shrink-0 transition-transform duration-200 ${t?`rotate-90`:``}`}),(0,E.jsx)(`span`,{className:`flex-1 text-left truncate`,children:e.label}),(0,E.jsx)(`span`,{className:`shrink-0 text-[10px] tabular-nums opacity-60`,children:e.endpoints.length})]})}),(0,E.jsx)(u,{children:(0,E.jsx)(`div`,{className:`ml-3 space-y-0.5 mt-0.5`,children:e.endpoints.map((e,t)=>(0,E.jsxs)(`button`,{onClick:()=>se(e),className:`w-full text-left flex items-center gap-1.5 px-2 py-1 rounded text-xs transition-colors ${A===e?`bg-accent text-accent-foreground`:`hover:bg-muted/50 text-muted-foreground hover:text-foreground`}`,children:[(0,E.jsx)(h,{variant:`outline`,className:`font-mono text-[9px] shrink-0 px-1 py-0 ${D[e.method]||``}`,children:e.method}),(0,E.jsx)(`span`,{className:`truncate`,children:e.desc})]},`${e.method}-${e.path}-${t}`))})})]},e.key)})}),(0,E.jsxs)(`div`,{className:`p-3 border-t space-y-2`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(`h4`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:`Query Parameters`}),(0,E.jsxs)(`button`,{onClick:()=>Z(),className:`inline-flex items-center gap-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,E.jsx)(d,{className:`h-3 w-3`}),`Add`]})]}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:ne.map(e=>(0,E.jsx)(`button`,{onClick:()=>Z(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))}),I.length>0&&(0,E.jsx)(`div`,{className:`space-y-1`,children:I.map(e=>(0,E.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,E.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>le(e.id),className:`h-3 w-3 shrink-0 rounded border accent-primary`}),(0,E.jsx)(`input`,{type:`text`,value:e.key,onChange:t=>Q(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,E.jsx)(`input`,{type:`text`,value:e.value,onChange:t=>Q(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,E.jsx)(`button`,{onClick:()=>ce(e.id),className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-destructive transition-colors`,children:(0,E.jsx)(s,{className:`h-3 w-3`})})]},e.id))})]})]}),(0,E.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 overflow-hidden`,children:[(0,E.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`select`,{value:J,onChange:e=>M(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 ${D[J]||``}`,children:[`GET`,`POST`,`PATCH`,`PUT`,`DELETE`].map(e=>(0,E.jsx)(`option`,{value:e,children:e},e))}),(0,E.jsx)(`input`,{type:`text`,value:Y,onChange:e=>N(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`&&$()}}),(0,E.jsxs)(`button`,{onClick:$,disabled:R||!X,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:[R?(0,E.jsx)(b,{className:`h-3.5 w-3.5 animate-spin`}):(0,E.jsx)(p,{className:`h-3.5 w-3.5`}),`Send`]})]}),I.some(e=>e.enabled&&e.key.trim())&&(0,E.jsxs)(`div`,{className:`text-[10px] font-mono text-muted-foreground truncate pl-1`,children:[`→ `,X]})]}),(0,E.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 overflow-auto`,children:[[`POST`,`PATCH`,`PUT`].includes(J)&&(0,E.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,E.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Request Body (JSON)`}),(0,E.jsx)(`textarea`,{value:P,onChange:e=>F(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" }`})]}),R&&(0,E.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,E.jsx)(b,{className:`h-4 w-4 animate-spin mr-2`}),`Sending request...`]}),B&&!R&&(0,E.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-muted/30 border-b`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,E.jsx)(`span`,{className:`font-mono font-semibold ${fe(B.status)}`,children:B.status||`ERR`}),(0,E.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1`,children:[(0,E.jsx)(_,{className:`h-3 w-3`}),B.duration,`ms`]})]}),(0,E.jsxs)(`button`,{onClick:de,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[G?(0,E.jsx)(c,{className:`h-3 w-3`}):(0,E.jsx)(g,{className:`h-3 w-3`}),G?`Copied`:`Copy`]})]}),(0,E.jsx)(`pre`,{className:`flex-1 overflow-auto p-3 text-xs font-mono bg-muted/10 whitespace-pre-wrap break-all`,children:B.body})]}),!B&&!R&&(0,E.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-muted-foreground text-sm`,children:(0,E.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,E.jsx)(y,{className:`h-10 w-10 mx-auto opacity-20`}),(0,E.jsxs)(`p`,{children:[`Select an endpoint or type a URL and click `,(0,E.jsx)(`strong`,{children:`Send`})]}),(0,E.jsx)(`p`,{className:`text-xs opacity-60`,children:`All registered APIs are auto-discovered from the platform`})]})}),H.length>0&&(0,E.jsxs)(`div`,{className:`border-t`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2`,children:[(0,E.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:[`History (`,H.length,`)`]}),(0,E.jsxs)(`button`,{onClick:()=>U([]),className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,E.jsx)(v,{className:`h-3 w-3`}),`Clear`]})]}),(0,E.jsx)(`div`,{className:`space-y-0.5 px-2 pb-2 max-h-60 overflow-auto`,children:H.map(e=>(0,E.jsxs)(`div`,{className:`rounded border`,children:[(0,E.jsxs)(`button`,{onClick:()=>ae(W===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:[W===e.id?(0,E.jsx)(a,{className:`h-3 w-3 shrink-0`}):(0,E.jsx)(i,{className:`h-3 w-3 shrink-0`}),(0,E.jsx)(h,{variant:`outline`,className:`font-mono text-[9px] shrink-0 ${D[e.method]||``}`,children:e.method}),(0,E.jsx)(`span`,{className:`font-mono truncate text-left flex-1`,children:e.url}),(0,E.jsx)(`span`,{className:`ml-auto shrink-0 font-mono ${fe(e.status)}`,children:e.status}),(0,E.jsxs)(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.duration,`ms`]}),(0,E.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ue(e)},className:`shrink-0 p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors`,title:`Replay request`,children:(0,E.jsx)(p,{className:`h-2.5 w-2.5`})})]}),W===e.id&&(0,E.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{k as ApiConsolePage};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{L as r}from"./framework-B3O15Lsq.js";import{Bs as i,Hs as a,Oi as o,Or as s,Us as c,Vi as l,Xn as u,Yi as d,Yn as f,Zi as p,Zn as m,ar as h,cs as g,gs as _,qr as v,vo as y,za as b}from"./ui-components-rkvkkTxO.js";import"./src-BBieSqPB.js";var x=e(n(),1),S=[`plugin`,`plugins`,`kind`,`package`];function C(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 w={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 T(e,t){let n=w[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 ee(){let e=r(),[t,n]=(0,x.useState)([]),[i,a]=(0,x.useState)([]),[o,s]=(0,x.useState)(!0),[c,l]=(0,x.useState)(null),u=(0,x.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(w)){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(...T(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=>!S.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,...C(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`],y=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}));n(y),a(g)}catch(e){l(e.message||`Failed to discover APIs`)}finally{s(!1)}},[e]);return(0,x.useEffect)(()=>{u()},[u]),{groups:t,allEndpoints:i,loading:o,error:c,refresh:u}}var E=t(),D={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`},te={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`},ne=[{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`}],O=1;function k(){let e=r()?.getClient?.(),{groups:t,loading:n,refresh:S}=ee(),[C,w]=(0,x.useState)(``),[T,k]=(0,x.useState)(new Set),[A,j]=(0,x.useState)(null),[re,M]=(0,x.useState)(``),[ie,N]=(0,x.useState)(``),[P,F]=(0,x.useState)(``),[I,L]=(0,x.useState)([]),[R,z]=(0,x.useState)(!1),[B,V]=(0,x.useState)(null),[H,U]=(0,x.useState)([]),[W,ae]=(0,x.useState)(null),[G,K]=(0,x.useState)(!1),q=(0,x.useMemo)(()=>{if(!C)return t;let e=C.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,C]),oe=(0,x.useCallback)(e=>{k(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),se=(0,x.useCallback)(e=>{j(e),M(e.method),N(e.path),F(e.bodyTemplate?JSON.stringify(e.bodyTemplate,null,2):``),L([]),V(null)},[]),J=re||A?.method||`GET`,Y=ie||A?.path||``,X=(0,x.useMemo)(()=>{let e=I.filter(e=>e.enabled&&e.key.trim());if(e.length===0)return Y;let t=e.map(e=>`${encodeURIComponent(e.key)}=${encodeURIComponent(e.value)}`).join(`&`);return`${Y}?${t}`},[Y,I]),Z=(0,x.useCallback)((e=``,t=``)=>{L(n=>[...n,{id:O++,key:e,value:t,enabled:!0}])},[]),ce=(0,x.useCallback)(e=>{L(t=>t.filter(t=>t.id!==e))},[]),Q=(0,x.useCallback)((e,t,n)=>{L(r=>r.map(r=>r.id===e?{...r,[t]:n}:r))},[]),le=(0,x.useCallback)(e=>{L(t=>t.map(t=>t.id===e?{...t,enabled:!t.enabled}:t))},[]),$=(0,x.useCallback)(async()=>{if(R||!X)return;let t=`${e?.baseUrl??``}${X}`;z(!0);let n=performance.now();try{let e={method:J,headers:{"Content-Type":`application/json`}};[`POST`,`PATCH`,`PUT`].includes(J)&&P.trim()&&(e.body=P);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();let o={status:r.status,body:a,duration:i};V(o),U(e=>[{id:Date.now(),method:J,url:X,body:P||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);V({status:0,body:`Network Error: ${e.message}`,duration:t})}finally{z(!1)}},[e,X,J,P,R]),ue=(0,x.useCallback)(e=>{M(e.method);let[t,n]=e.url.split(`?`);if(N(t),F(e.body||``),n){let e=new URLSearchParams(n),t=[];e.forEach((e,n)=>{t.push({id:O++,key:n,value:e,enabled:!0})}),L(t)}else L([]);V(null),j(null)},[]),de=(0,x.useCallback)(()=>{B?.body&&(navigator.clipboard.writeText(B.body),K(!0),setTimeout(()=>K(!1),1500))},[B]),fe=e=>te[String(e)[0]]??`text-muted-foreground`;return(0,E.jsxs)(`div`,{className:`flex flex-1 min-h-0 overflow-hidden`,children:[(0,E.jsxs)(`div`,{className:`w-72 shrink-0 border-r flex flex-col overflow-hidden`,children:[(0,E.jsxs)(`div`,{className:`p-3 border-b space-y-2`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`h3`,{className:`text-sm font-semibold text-foreground flex-1`,children:`API Endpoints`}),(0,E.jsx)(`button`,{onClick:S,disabled:n,className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,title:`Refresh endpoints`,children:(0,E.jsx)(l,{className:`h-3.5 w-3.5 ${n?`animate-spin`:``}`})})]}),(0,E.jsxs)(`div`,{className:`relative`,children:[(0,E.jsx)(o,{className:`absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,E.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(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,E.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:n?(0,E.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,E.jsx)(b,{className:`h-4 w-4 animate-spin mr-2`}),`Discovering APIs...`]}):q.length===0?(0,E.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,E.jsx)(y,{className:`h-6 w-6 opacity-30 mb-2`}),(0,E.jsx)(`span`,{children:C?`No matching endpoints`:`No endpoints found`})]}):q.map(e=>{let t=T.has(e.key)||!!C;return(0,E.jsxs)(f,{open:t,onOpenChange:()=>oe(e.key),children:[(0,E.jsx)(m,{asChild:!0,children:(0,E.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,E.jsx)(i,{className:`h-3 w-3 shrink-0 transition-transform duration-200 ${t?`rotate-90`:``}`}),(0,E.jsx)(`span`,{className:`flex-1 text-left truncate`,children:e.label}),(0,E.jsx)(`span`,{className:`shrink-0 text-[10px] tabular-nums opacity-60`,children:e.endpoints.length})]})}),(0,E.jsx)(u,{children:(0,E.jsx)(`div`,{className:`ml-3 space-y-0.5 mt-0.5`,children:e.endpoints.map((e,t)=>(0,E.jsxs)(`button`,{onClick:()=>se(e),className:`w-full text-left flex items-center gap-1.5 px-2 py-1 rounded text-xs transition-colors ${A===e?`bg-accent text-accent-foreground`:`hover:bg-muted/50 text-muted-foreground hover:text-foreground`}`,children:[(0,E.jsx)(h,{variant:`outline`,className:`font-mono text-[9px] shrink-0 px-1 py-0 ${D[e.method]||``}`,children:e.method}),(0,E.jsx)(`span`,{className:`truncate`,children:e.desc})]},`${e.method}-${e.path}-${t}`))})})]},e.key)})}),(0,E.jsxs)(`div`,{className:`p-3 border-t space-y-2`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,E.jsx)(`h4`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:`Query Parameters`}),(0,E.jsxs)(`button`,{onClick:()=>Z(),className:`inline-flex items-center gap-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,E.jsx)(d,{className:`h-3 w-3`}),`Add`]})]}),(0,E.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:ne.map(e=>(0,E.jsx)(`button`,{onClick:()=>Z(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))}),I.length>0&&(0,E.jsx)(`div`,{className:`space-y-1`,children:I.map(e=>(0,E.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,E.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>le(e.id),className:`h-3 w-3 shrink-0 rounded border accent-primary`}),(0,E.jsx)(`input`,{type:`text`,value:e.key,onChange:t=>Q(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,E.jsx)(`input`,{type:`text`,value:e.value,onChange:t=>Q(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,E.jsx)(`button`,{onClick:()=>ce(e.id),className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-destructive transition-colors`,children:(0,E.jsx)(s,{className:`h-3 w-3`})})]},e.id))})]})]}),(0,E.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 overflow-hidden`,children:[(0,E.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`select`,{value:J,onChange:e=>M(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 ${D[J]||``}`,children:[`GET`,`POST`,`PATCH`,`PUT`,`DELETE`].map(e=>(0,E.jsx)(`option`,{value:e,children:e},e))}),(0,E.jsx)(`input`,{type:`text`,value:Y,onChange:e=>N(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`&&$()}}),(0,E.jsxs)(`button`,{onClick:$,disabled:R||!X,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:[R?(0,E.jsx)(b,{className:`h-3.5 w-3.5 animate-spin`}):(0,E.jsx)(p,{className:`h-3.5 w-3.5`}),`Send`]})]}),I.some(e=>e.enabled&&e.key.trim())&&(0,E.jsxs)(`div`,{className:`text-[10px] font-mono text-muted-foreground truncate pl-1`,children:[`→ `,X]})]}),(0,E.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 overflow-auto`,children:[[`POST`,`PATCH`,`PUT`].includes(J)&&(0,E.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,E.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Request Body (JSON)`}),(0,E.jsx)(`textarea`,{value:P,onChange:e=>F(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" }`})]}),R&&(0,E.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,E.jsx)(b,{className:`h-4 w-4 animate-spin mr-2`}),`Sending request...`]}),B&&!R&&(0,E.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-muted/30 border-b`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,E.jsx)(`span`,{className:`font-mono font-semibold ${fe(B.status)}`,children:B.status||`ERR`}),(0,E.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1`,children:[(0,E.jsx)(_,{className:`h-3 w-3`}),B.duration,`ms`]})]}),(0,E.jsxs)(`button`,{onClick:de,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[G?(0,E.jsx)(c,{className:`h-3 w-3`}):(0,E.jsx)(g,{className:`h-3 w-3`}),G?`Copied`:`Copy`]})]}),(0,E.jsx)(`pre`,{className:`flex-1 overflow-auto p-3 text-xs font-mono bg-muted/10 whitespace-pre-wrap break-all`,children:B.body})]}),!B&&!R&&(0,E.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-muted-foreground text-sm`,children:(0,E.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,E.jsx)(y,{className:`h-10 w-10 mx-auto opacity-20`}),(0,E.jsxs)(`p`,{children:[`Select an endpoint or type a URL and click `,(0,E.jsx)(`strong`,{children:`Send`})]}),(0,E.jsx)(`p`,{className:`text-xs opacity-60`,children:`All registered APIs are auto-discovered from the platform`})]})}),H.length>0&&(0,E.jsxs)(`div`,{className:`border-t`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2`,children:[(0,E.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:[`History (`,H.length,`)`]}),(0,E.jsxs)(`button`,{onClick:()=>U([]),className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,E.jsx)(v,{className:`h-3 w-3`}),`Clear`]})]}),(0,E.jsx)(`div`,{className:`space-y-0.5 px-2 pb-2 max-h-60 overflow-auto`,children:H.map(e=>(0,E.jsxs)(`div`,{className:`rounded border`,children:[(0,E.jsxs)(`button`,{onClick:()=>ae(W===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:[W===e.id?(0,E.jsx)(a,{className:`h-3 w-3 shrink-0`}):(0,E.jsx)(i,{className:`h-3 w-3 shrink-0`}),(0,E.jsx)(h,{variant:`outline`,className:`font-mono text-[9px] shrink-0 ${D[e.method]||``}`,children:e.method}),(0,E.jsx)(`span`,{className:`font-mono truncate text-left flex-1`,children:e.url}),(0,E.jsx)(`span`,{className:`ml-auto shrink-0 font-mono ${fe(e.status)}`,children:e.status}),(0,E.jsxs)(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.duration,`ms`]}),(0,E.jsx)(`button`,{onClick:t=>{t.stopPropagation(),ue(e)},className:`shrink-0 p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors`,title:`Replay request`,children:(0,E.jsx)(p,{className:`h-2.5 w-2.5`})})]}),W===e.id&&(0,E.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{k as ApiConsolePage};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{a as t,m as n,r,s as i,y as a}from"./vendor-react-BGDDiZfJ.js";import{uc as o,za as s}from"./ui-components-rkvkkTxO.js";import{a as c,i as l,n as u,r as d}from"./index-TdJi7kFM.js";var f=e(a(),1),p=r();function m(){let{appName:e}=n(),{books:r,docs:a,state:m}=u(),h=(0,f.useMemo)(()=>r.filter(t=>l(t)===e),[r,e]),g=(0,f.useMemo)(()=>d(h,a),[h,a]);return m===`loading`?(0,p.jsx)(`div`,{className:`flex h-full items-center justify-center p-10 text-muted-foreground`,children:(0,p.jsx)(s,{className:`h-5 w-5 animate-spin`,"aria-label":`Loading documentation`})}):g.length===1?(0,p.jsx)(i,{to:`/apps/${e}/docs/${g[0].slug}`,replace:!0}):(0,p.jsx)(c,{children:(0,p.jsx)(`div`,{className:`mx-auto max-w-3xl p-4 sm:p-6`,children:g.length===0?(0,p.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-16 text-center text-muted-foreground`,children:[(0,p.jsx)(o,{className:`h-10 w-10`}),(0,p.jsx)(`p`,{className:`text-sm`,children:`This app does not ship any documentation yet.`}),(0,p.jsx)(t,{to:`/docs`,className:`text-sm font-medium text-primary hover:underline`,children:`Browse all documentation`})]}):(0,p.jsx)(`ul`,{className:`grid gap-3 sm:grid-cols-2`,children:g.map(n=>(0,p.jsx)(`li`,{children:(0,p.jsxs)(t,{to:`/apps/${e}/docs/${n.slug}`,className:`flex h-full items-start gap-3 rounded-md border border-border p-3 hover:bg-muted/50`,children:[(0,p.jsx)(o,{className:`mt-0.5 h-5 w-5 shrink-0 text-muted-foreground`}),(0,p.jsxs)(`div`,{className:`min-w-0`,children:[(0,p.jsx)(`div`,{className:`text-sm font-semibold`,children:n.label}),n.description?(0,p.jsx)(`div`,{className:`mt-0.5 line-clamp-2 text-xs text-muted-foreground`,children:n.description}):n.subtitle?(0,p.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-muted-foreground/70`,children:n.subtitle}):null,(0,p.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground/80`,children:[n.docCount,` `,n.docCount===1?`article`:`articles`]})]})]})},n.name))})})})}export{m as default};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{a as t,m as n,r,s as i,y as a}from"./vendor-react-BGDDiZfJ.js";import{uc as o,za as s}from"./ui-components-rkvkkTxO.js";import{a as c,i as l,n as u,r as d}from"./index-PrzZHiAk.js";var f=e(a(),1),p=r();function m(){let{appName:e}=n(),{books:r,docs:a,state:m}=u(),h=(0,f.useMemo)(()=>r.filter(t=>l(t)===e),[r,e]),g=(0,f.useMemo)(()=>d(h,a),[h,a]);return m===`loading`?(0,p.jsx)(`div`,{className:`flex h-full items-center justify-center p-10 text-muted-foreground`,children:(0,p.jsx)(s,{className:`h-5 w-5 animate-spin`,"aria-label":`Loading documentation`})}):g.length===1?(0,p.jsx)(i,{to:`/apps/${e}/docs/${g[0].slug}`,replace:!0}):(0,p.jsx)(c,{children:(0,p.jsx)(`div`,{className:`mx-auto max-w-3xl p-4 sm:p-6`,children:g.length===0?(0,p.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-16 text-center text-muted-foreground`,children:[(0,p.jsx)(o,{className:`h-10 w-10`}),(0,p.jsx)(`p`,{className:`text-sm`,children:`This app does not ship any documentation yet.`}),(0,p.jsx)(t,{to:`/docs`,className:`text-sm font-medium text-primary hover:underline`,children:`Browse all documentation`})]}):(0,p.jsx)(`ul`,{className:`grid gap-3 sm:grid-cols-2`,children:g.map(n=>(0,p.jsx)(`li`,{children:(0,p.jsxs)(t,{to:`/apps/${e}/docs/${n.slug}`,className:`flex h-full items-start gap-3 rounded-md border border-border p-3 hover:bg-muted/50`,children:[(0,p.jsx)(o,{className:`mt-0.5 h-5 w-5 shrink-0 text-muted-foreground`}),(0,p.jsxs)(`div`,{className:`min-w-0`,children:[(0,p.jsx)(`div`,{className:`text-sm font-semibold`,children:n.label}),n.description?(0,p.jsx)(`div`,{className:`mt-0.5 line-clamp-2 text-xs text-muted-foreground`,children:n.description}):n.subtitle?(0,p.jsx)(`div`,{className:`mt-0.5 truncate font-mono text-[11px] text-muted-foreground/70`,children:n.subtitle}):null,(0,p.jsxs)(`div`,{className:`mt-1 text-xs text-muted-foreground/80`,children:[n.docCount,` `,n.docCount===1?`article`:`articles`]})]})]})},n.name))})})})}export{m as default};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{f as t,m as n,r,y as i}from"./vendor-react-BGDDiZfJ.js";import{R as a}from"./framework-B3O15Lsq.js";import{$n as o,Jo as s,Jr as c,Oi as l,Qn as u,Ya as d,Yi as f,Yr as p,ar as m,ci as h,er as g,hi as _,na as v,qr as y,sn as b,xr as x}from"./ui-components-rkvkkTxO.js";import{r as S}from"./vendor-ui-utils-BzQBRdq3.js";import"./src-6xqJEeiC.js";var C=e(i(),1);function w(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}}var T=r();function E(){let e=t(),{appName:r}=n(),i=r?`/apps/${r}`:``,{apps:E,refresh:D}=a(),[O,k]=(0,C.useState)(``),[A,j]=(0,C.useState)(new Set),[M,N]=(0,C.useState)(null),[P,F]=(0,C.useState)(!1),I=(E||[]).filter(e=>{if(!O)return!0;let t=O.toLowerCase();return(e.name||``).toLowerCase().includes(t)||(e.label||``).toLowerCase().includes(t)||(e.description||``).toLowerCase().includes(t)}),L=(0,C.useCallback)(e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),R=(0,C.useCallback)(()=>{A.size===I.length?j(new Set):j(new Set(I.map(e=>e.name)))},[A.size,I]),z=(0,C.useCallback)(async e=>{F(!0);try{let t=e.active===!1;S.success(`${e.label||e.name} ${t?`enabled`:`disabled`}`),await D()}catch{S.error(`Failed to toggle app status`)}finally{F(!1)}},[D]),B=(0,C.useCallback)(async e=>{F(!0);try{S.success(`${e.label||e.name} set as default`),await D()}catch{S.error(`Failed to set default app`)}finally{F(!1)}},[D]),V=(0,C.useCallback)(async e=>{if(M!==e.name){N(e.name);return}F(!0);try{S.success(`${e.label||e.name} deleted`),N(null),await D()}catch{S.error(`Failed to delete app`)}finally{F(!1)}},[M,D]),H=(0,C.useCallback)(async e=>{F(!0);try{S.success(`${A.size} apps ${e?`enabled`:`disabled`}`),j(new Set),await D()}catch{S.error(`Bulk operation failed`)}finally{F(!1)}},[A,D]);return(0,T.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,children:[(0,T.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Applications`}),(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage all configured applications`})]}),(0,T.jsxs)(x,{onClick:()=>e(`${i}/create-app`),"data-testid":`create-app-btn`,children:[(0,T.jsx)(f,{className:`h-4 w-4 mr-2`}),`New App`]})]}),(0,T.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,T.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,T.jsx)(`label`,{htmlFor:`app-search`,className:`sr-only`,children:`Search apps`}),(0,T.jsx)(l,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,T.jsx)(b,{id:`app-search`,placeholder:`Search apps...`,value:O,onChange:e=>k(e.target.value),className:`pl-8`,"data-testid":`app-search-input`})]}),A.size>0&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsxs)(m,{variant:`secondary`,children:[A.size,` selected`]}),(0,T.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>H(!0),disabled:P,children:`Enable`}),(0,T.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>H(!1),disabled:P,children:`Disable`})]})]}),I.length>0&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,T.jsx)(u,{id:`select-all-apps`,checked:A.size===I.length&&I.length>0,onCheckedChange:()=>R()}),(0,T.jsxs)(`label`,{htmlFor:`select-all-apps`,className:`cursor-pointer`,children:[`Select all (`,I.length,`)`]})]}),I.length===0?(0,T.jsxs)(`div`,{className:`text-center py-12 text-muted-foreground`,"data-testid":`no-apps-message`,children:[(0,T.jsx)(d,{className:`h-12 w-12 mx-auto mb-3 opacity-30`}),(0,T.jsx)(`p`,{children:`No apps found.`})]}):(0,T.jsx)(`div`,{className:`grid gap-3`,children:I.map(t=>{let n=t.active!==!1,r=t.isDefault===!0,a=M===t.name;return(0,T.jsx)(o,{className:n?``:`opacity-60`,"data-testid":`app-card-${t.name}`,children:(0,T.jsxs)(g,{className:`flex items-center gap-3 py-3 px-4`,children:[(0,T.jsx)(u,{id:`select-app-${t.name}`,checked:A.has(t.name),onCheckedChange:()=>L(t.name),"aria-label":`Select ${t.label||t.name}`,className:`shrink-0`}),(0,T.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,T.jsx)(d,{className:`h-4 w-4`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`span`,{className:`font-medium truncate`,children:w(t.label)||t.name}),r&&(0,T.jsx)(m,{variant:`default`,className:`text-xs`,children:`Default`}),(0,T.jsx)(m,{variant:n?`secondary`:`outline`,className:`text-xs`,children:n?`Active`:`Inactive`})]}),t.description&&(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:w(t.description)})]}),(0,T.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:`Open app`,"aria-label":`Open ${t.label||t.name}`,onClick:()=>e(`/apps/${t._packageId??t.name}`),children:(0,T.jsx)(s,{className:`h-4 w-4`})}),(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:`Edit app`,"aria-label":`Edit ${t.label||t.name}`,onClick:()=>e(`${i}/edit-app/${t.name}`),children:(0,T.jsx)(v,{className:`h-4 w-4`})}),t._packageId?(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:`Edit with AI`,"aria-label":`Edit ${t.label||t.name} with AI`,onClick:()=>e(`/ai/build?package=${encodeURIComponent(t._packageId)}&new=1`),children:(0,T.jsx)(_,{className:`h-4 w-4`})}):null,(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:n?`Disable app`:`Enable app`,"aria-label":n?`Disable ${t.label||t.name}`:`Enable ${t.label||t.name}`,onClick:()=>z(t),disabled:P,children:n?(0,T.jsx)(c,{className:`h-4 w-4`}):(0,T.jsx)(p,{className:`h-4 w-4`})}),(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:`Set as default`,"aria-label":`Set ${t.label||t.name} as default`,onClick:()=>B(t),disabled:P||r,children:(0,T.jsx)(h,{className:`h-4 w-4 ${r?`fill-current text-yellow-500`:``}`})}),(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:a?`Click again to confirm delete`:`Delete app`,"aria-label":a?`Confirm delete ${t.label||t.name}`:`Delete ${t.label||t.name}`,onClick:()=>V(t),disabled:P,className:a?`text-destructive`:``,children:(0,T.jsx)(y,{className:`h-4 w-4`})})]})]})},t.name)})})]})}export{E as AppManagementPage};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{f as t,m as n,r,y as i}from"./vendor-react-BGDDiZfJ.js";import{R as a}from"./framework-B3O15Lsq.js";import{$n as o,Jo as s,Jr as c,Oi as l,Qn as u,Ya as d,Yi as f,Yr as p,ar as m,ci as h,er as g,hi as _,na as v,qr as y,sn as b,xr as x}from"./ui-components-rkvkkTxO.js";import{r as S}from"./vendor-ui-utils-BzQBRdq3.js";import"./src-BBieSqPB.js";var C=e(i(),1);function w(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}}var T=r();function E(){let e=t(),{appName:r}=n(),i=r?`/apps/${r}`:``,{apps:E,refresh:D}=a(),[O,k]=(0,C.useState)(``),[A,j]=(0,C.useState)(new Set),[M,N]=(0,C.useState)(null),[P,F]=(0,C.useState)(!1),I=(E||[]).filter(e=>{if(!O)return!0;let t=O.toLowerCase();return(e.name||``).toLowerCase().includes(t)||(e.label||``).toLowerCase().includes(t)||(e.description||``).toLowerCase().includes(t)}),L=(0,C.useCallback)(e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),R=(0,C.useCallback)(()=>{A.size===I.length?j(new Set):j(new Set(I.map(e=>e.name)))},[A.size,I]),z=(0,C.useCallback)(async e=>{F(!0);try{let t=e.active===!1;S.success(`${e.label||e.name} ${t?`enabled`:`disabled`}`),await D()}catch{S.error(`Failed to toggle app status`)}finally{F(!1)}},[D]),B=(0,C.useCallback)(async e=>{F(!0);try{S.success(`${e.label||e.name} set as default`),await D()}catch{S.error(`Failed to set default app`)}finally{F(!1)}},[D]),V=(0,C.useCallback)(async e=>{if(M!==e.name){N(e.name);return}F(!0);try{S.success(`${e.label||e.name} deleted`),N(null),await D()}catch{S.error(`Failed to delete app`)}finally{F(!1)}},[M,D]),H=(0,C.useCallback)(async e=>{F(!0);try{S.success(`${A.size} apps ${e?`enabled`:`disabled`}`),j(new Set),await D()}catch{S.error(`Bulk operation failed`)}finally{F(!1)}},[A,D]);return(0,T.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,children:[(0,T.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Applications`}),(0,T.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage all configured applications`})]}),(0,T.jsxs)(x,{onClick:()=>e(`${i}/create-app`),"data-testid":`create-app-btn`,children:[(0,T.jsx)(f,{className:`h-4 w-4 mr-2`}),`New App`]})]}),(0,T.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,T.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,T.jsx)(`label`,{htmlFor:`app-search`,className:`sr-only`,children:`Search apps`}),(0,T.jsx)(l,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,T.jsx)(b,{id:`app-search`,placeholder:`Search apps...`,value:O,onChange:e=>k(e.target.value),className:`pl-8`,"data-testid":`app-search-input`})]}),A.size>0&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsxs)(m,{variant:`secondary`,children:[A.size,` selected`]}),(0,T.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>H(!0),disabled:P,children:`Enable`}),(0,T.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>H(!1),disabled:P,children:`Disable`})]})]}),I.length>0&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,T.jsx)(u,{id:`select-all-apps`,checked:A.size===I.length&&I.length>0,onCheckedChange:()=>R()}),(0,T.jsxs)(`label`,{htmlFor:`select-all-apps`,className:`cursor-pointer`,children:[`Select all (`,I.length,`)`]})]}),I.length===0?(0,T.jsxs)(`div`,{className:`text-center py-12 text-muted-foreground`,"data-testid":`no-apps-message`,children:[(0,T.jsx)(d,{className:`h-12 w-12 mx-auto mb-3 opacity-30`}),(0,T.jsx)(`p`,{children:`No apps found.`})]}):(0,T.jsx)(`div`,{className:`grid gap-3`,children:I.map(t=>{let n=t.active!==!1,r=t.isDefault===!0,a=M===t.name;return(0,T.jsx)(o,{className:n?``:`opacity-60`,"data-testid":`app-card-${t.name}`,children:(0,T.jsxs)(g,{className:`flex items-center gap-3 py-3 px-4`,children:[(0,T.jsx)(u,{id:`select-app-${t.name}`,checked:A.has(t.name),onCheckedChange:()=>L(t.name),"aria-label":`Select ${t.label||t.name}`,className:`shrink-0`}),(0,T.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,T.jsx)(d,{className:`h-4 w-4`})}),(0,T.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`span`,{className:`font-medium truncate`,children:w(t.label)||t.name}),r&&(0,T.jsx)(m,{variant:`default`,className:`text-xs`,children:`Default`}),(0,T.jsx)(m,{variant:n?`secondary`:`outline`,className:`text-xs`,children:n?`Active`:`Inactive`})]}),t.description&&(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:w(t.description)})]}),(0,T.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:`Open app`,"aria-label":`Open ${t.label||t.name}`,onClick:()=>e(`/apps/${t._packageId??t.name}`),children:(0,T.jsx)(s,{className:`h-4 w-4`})}),(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:`Edit app`,"aria-label":`Edit ${t.label||t.name}`,onClick:()=>e(`${i}/edit-app/${t.name}`),children:(0,T.jsx)(v,{className:`h-4 w-4`})}),t._packageId?(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:`Edit with AI`,"aria-label":`Edit ${t.label||t.name} with AI`,onClick:()=>e(`/ai/build?package=${encodeURIComponent(t._packageId)}&new=1`),children:(0,T.jsx)(_,{className:`h-4 w-4`})}):null,(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:n?`Disable app`:`Enable app`,"aria-label":n?`Disable ${t.label||t.name}`:`Enable ${t.label||t.name}`,onClick:()=>z(t),disabled:P,children:n?(0,T.jsx)(c,{className:`h-4 w-4`}):(0,T.jsx)(p,{className:`h-4 w-4`})}),(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:`Set as default`,"aria-label":`Set ${t.label||t.name} as default`,onClick:()=>B(t),disabled:P||r,children:(0,T.jsx)(h,{className:`h-4 w-4 ${r?`fill-current text-yellow-500`:``}`})}),(0,T.jsx)(x,{variant:`ghost`,size:`icon`,title:a?`Click again to confirm delete`:`Delete app`,"aria-label":a?`Confirm delete ${t.label||t.name}`:`Delete ${t.label||t.name}`,onClick:()=>V(t),disabled:P,className:a?`text-destructive`:``,children:(0,T.jsx)(y,{className:`h-4 w-4`})})]})]})},t.name)})})]})}export{E as AppManagementPage};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{d as t,f as n,r,y as i}from"./vendor-react-BGDDiZfJ.js";import{l as a}from"./framework-B3O15Lsq.js";import{Jt as o,Kt as s,Xt as c,Yt as l,ct as u,di as d,dt as f,k as p,qt as m,ut as h,wi as g,xr as _}from"./ui-components-rkvkkTxO.js";import{r as v}from"./vendor-ui-utils-BzQBRdq3.js";import{i as y,s as b,t as x}from"./assistantBus-BFk4fCbM.js";import{c as S,l as ee,n as te,o as ne,t as re}from"./useReconcileOnError-4is_Tic6.js";import{C as ie,a as ae,d as C,f as w,g as T,h as E,m as D,r as oe,t as se,u as ce,y as O}from"./plugin-chatbot-D2Uv-hn9.js";import{n as le,x as k}from"./marketplaceApi-zYQofLEk.js";var A=e(i(),1);function j(e){return e.some(e=>E(e.name))&&e.some(e=>T(e.name))}function M({agents:e,showAgentPickerProp:t,envOptIn:n=!1,aiStudioEnabled:r=!0}){return t===void 0?n?!0:r&&j(e):t}var N=r(),P={ask:{zh:`智能助手`,en:`Assistant`},build:{zh:`构建助手`,en:`Build assistant`}};function F(e,t,n){let r=t?P[D(t)]:void 0;return r?e?r.zh:r.en:n}function ue(e,t,n,r,i){let a=(e??``).toLowerCase().startsWith(`zh`),o=F(a,n,r),s=i.slice(0,2).map(e=>e.label||e.name);if(a){let e=[s[0]?`查询最近创建的${s[0]}`:`帮我查询最近的数据`,s[0]?`统计${s[0]}的总数量`:`统计各对象的记录数量`,s[1]?`${s[1]}有哪些字段?`:`当前应用里有哪些数据对象?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`你好,我是${o}`,emptyDescription:`随时帮你查询和分析「${t}」中的数据。试试下面的问题,或直接输入你的需求。`,clear:`清空对话`,sendHint:`发送`,agentActivity:`执行过程`,toolCompleted:`已完成`,toolRunning:`运行中`,toolAwaitingApproval:`等待确认`,toolFailed:`失败`,connectionWaiting:`正在等待服务器响应…`,connectionStalledLabel:`仍在处理中…`,connectionOfflineLabel:`网络已断开,正在重连…`,designingPlanLabel:`正在为你设计方案…`,designingPlanHints:[`梳理需要记录的数据…`,`设计对象与字段…`,`关联相关记录…`,`配置关系与查找字段…`,`规划页面与视图…`,`布置表单与列表…`,`补充默认值与校验…`,`规划一个看板来跟踪…`,`复核整体结构是否自洽…`,`汇总成完整方案…`],toolDetailsHidden:`已隐藏工具参数和原始结果,仅保留过程摘要。`,copy:`复制`,copied:`已复制`,regenerate:`重新生成`,model:`模型`,submit:`发送`,uploadFiles:`上传文件`,stopResponse:`停止生成`,sendFailedRateLimited:`发送过于频繁,请稍候再试。你的消息已保留在输入框中。`,sendFailedGeneric:`消息发送失败,请重试。你的消息已保留在输入框中。`,trace:`调试 trace`,viewTrace:`查看调试 trace`},placeholder:`向${o}提问…`,loadingPlaceholder:`正在加载助手…`,title:`${t} 智能助手`,newChat:`开启新对话`,share:`分享对话`,reviewDraft:e=>`查看 ${e} 项变更`,publishDrafts:`发布`,published:`已发布`,nextSteps:`下一步`,planTitle:`方案预览`,planQuestions:`搭建前请确认`,planAssumptions:`假设`,planDeferred:`待补 / 暂未搭建`,planApproveHint:`回复以确认或调整该方案。`,planApprove:`开始搭建`,planAdjust:`调整方案`,planBuilt:`已搭建`,planReady:`方案已就绪。点击开始搭建,或告诉我需要调整什么。`,planApproveMessage:`确认,开始搭建。`,planApproveDefaultsMessage:`确认搭建,未决问题按你的合理假设和默认处理。`,planAnswer:(e,t)=>`关于「${e}」,我选择「${t}」。`,publishOk:`已发布,对象已生效。`,publishFailed:`发布失败`,seedWarn:`已发布,但部分示例数据未能载入。`,openBuiltApp:`打开应用`,suggestions:e}}let c=[s[0]?`Show the latest ${s[0]}`:`Show my most recent records`,s[0]?`How many ${s[0]} are there?`:`Count records by status`,s[1]?`What fields does ${s[1]} have?`:`What data can I work with here?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`Hi, I'm ${o}`,emptyDescription:`I can help you query and analyze your ${t} data. Try a prompt below, or just type your question.`,clear:`Clear`,sendHint:`to send`,agentActivity:`Agent activity`,toolCompleted:`Completed`,toolRunning:`Running`,toolAwaitingApproval:`Awaiting approval`,toolFailed:`Failed`,connectionWaiting:`Waiting for server…`,connectionStalledLabel:`Still working…`,connectionOfflineLabel:`Connection lost — reconnecting…`,designingPlanLabel:`Designing your app…`,designingPlanHints:[`Mapping out the data you’ll track…`,`Shaping objects and their fields…`,`Connecting related records…`,`Setting up relationships and lookups…`,`Planning the screens and views…`,`Laying out forms and lists…`,`Adding sensible defaults and validations…`,`Sketching a dashboard to track it…`,`Double-checking the structure hangs together…`,`Pulling the plan together…`],toolDetailsHidden:`Tool inputs and raw results are hidden in this view.`,copy:`Copy`,copied:`Copied`,regenerate:`Regenerate`,model:`Model`,submit:`Submit`,uploadFiles:`Upload files`,stopResponse:`Stop response`,sendFailedRateLimited:`You're sending messages too quickly. Your message is kept below — wait a moment and try again.`,sendFailedGeneric:`Couldn't send your message. It's kept below — please try again.`,trace:`trace`,viewTrace:`View trace`},placeholder:`Ask ${o}...`,loadingPlaceholder:`Loading assistant...`,title:`${t} Assistant`,newChat:`New chat`,share:`Share conversation`,reviewDraft:e=>`Review ${e} change${e===1?``:`s`}`,publishDrafts:`Publish`,published:`Published`,nextSteps:`What's next`,planTitle:`Proposed plan`,planQuestions:`Confirm before building`,planAssumptions:`Assumptions`,planDeferred:`Not yet built`,planApproveHint:`Reply to approve or adjust this plan.`,planApprove:`Build it`,planAdjust:`Adjust`,planBuilt:`Built`,planReady:`The plan is ready. Build it now, or tell me what to adjust.`,planApproveMessage:`Looks good — build it as proposed.`,planApproveDefaultsMessage:`Build it with your best assumptions; use sensible defaults for the open questions.`,planAnswer:(e,t)=>`For "${e}", go with: ${t}.`,publishOk:`Published — objects are now live.`,publishFailed:`Publish failed`,seedWarn:`Published, but some sample data failed to load.`,openBuiltApp:`Open app`,suggestions:c}}var I=`/api/v1/ai`;function L(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${I}`}function de(e,t){if(!e||e.type!==`object`)return null;let n=e.label||e.name||`this object`;return(t??``).toLowerCase().startsWith(`zh`)?[`为「${n}」补充字段`,`为「${n}」建议校验规则`,`添加一个状态选项字段`]:[`Add fields to ${n}`,`Suggest validations for ${n}`,`Add a status picklist field`]}var R=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`,`metadata`]);function z(e){try{return decodeURIComponent(e)}catch{return e}}function fe(e,t){let n=e.split(`/`).filter(Boolean),r=n.indexOf(`apps`);if(r===-1||n.length<r+3)return{};let i=z(n[r+2]);if(R.has(i)||!t.some(e=>e.name===i))return{};let a=n[r+3]?z(n[r+3]):void 0,o=a&&a!==`new`?a:void 0;return{objectName:i,...o?{recordId:o}:{}}}function B({appLabel:e,appName:r,objects:i,agents:S,agentsLoading:C,activeAgent:w,onAgentChange:T,showAgentPicker:E,chatApi:D,apiBase:j,defaultOpen:M=!1,conversationId:P,initialMessages:I,onNewChat:L}){let{language:R}=a(),z=n(),B=t(),V=A.useMemo(()=>fe(B.pathname,i),[B.pathname,i]),{editor:H}=b(),{models:pe,defaultModelId:me}=ce({apiBase:j}),[he,ge]=A.useState(void 0),U=he??me,_e=A.useMemo(()=>!I||I.length===0?[]:ie(I),[I]),W=A.useMemo(()=>S.find(e=>e.name===w)?.label??w??e,[S,w,e]),G=A.useMemo(()=>ue(R,e,w,W,i),[R,e,w,W,i]),ve=A.useMemo(()=>de(H,R),[H,R]),{errorSuppressed:ye,handleChatError:be,setMessagesRef:xe,resetSuppression:K}=re({chatApi:D,conversationId:P}),{messages:q,isLoading:J,error:Se,sendMessage:Y,stop:Ce,reload:we,clear:Te,setMessages:X}=O({api:D,conversationId:P,model:U,onError:be,body:{context:{activeApp:e,appName:r,objects:i.map(e=>({name:e.name,label:e.label})),agentName:w,autoPublishAiBuilds:k().features.autoPublishAiBuilds,...V.objectName?{objectName:V.objectName}:{},...V.recordId?{recordId:V.recordId}:{},...H?{editing:H}:{}}},initialMessages:_e,autoResponse:!D,autoResponseText:i.length>0?`I can help you work with ${i.map(e=>e.label||e.name).join(`, `)}. What would you like to do?`:`Thanks for your message! I'm here to help you navigate and manage your data.`,autoResponseDelay:600});A.useEffect(()=>{xe.current=X},[X]),A.useEffect(()=>{ee(P,ne(q))},[P,q]);let Z=se({messages:q,apiBase:j,continueConversation:e=>{K(),Y(e)}}),Q=(R??``).toLowerCase().startsWith(`zh`),Ee=E&&S.length>1?S.length<=3?(0,N.jsx)(u,{value:w,onValueChange:T,children:(0,N.jsx)(h,{className:`h-7 gap-0.5 p-0.5`,"data-testid":`floating-chatbot-agent-picker`,children:S.map(e=>(0,N.jsx)(f,{value:e.name,disabled:C,title:e.description||void 0,className:`h-6 px-2.5 text-xs`,children:F(Q,e.name,e.label)},e.name))})}):(0,N.jsxs)(s,{value:w,onValueChange:T,disabled:C,children:[(0,N.jsx)(l,{className:`h-7 w-[180px] text-xs`,"data-testid":`floating-chatbot-agent-picker`,children:(0,N.jsx)(c,{placeholder:`Choose agent...`})}),(0,N.jsx)(m,{align:`end`,children:S.map(e=>(0,N.jsxs)(o,{value:e.name,className:`text-xs`,children:[(0,N.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,N.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[220px]`,children:e.description}):null]},e.name))})]}):null,[De,$]=A.useState(!1),Oe=A.useMemo(()=>j.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[j]),ke=(0,N.jsxs)(N.Fragment,{children:[q.length>0?(0,N.jsx)(_,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":G.newChat,title:G.newChat,"data-testid":`floating-chatbot-new`,onClick:L,children:(0,N.jsx)(d,{className:`h-4 w-4`})}):null,P?(0,N.jsx)(_,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":G.share,title:G.share,"data-testid":`floating-chatbot-share`,onClick:()=>$(!0),children:(0,N.jsx)(g,{className:`h-4 w-4`})}):null]});return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(oe,{onUpgrade:()=>window.open(le(),`_blank`,`noopener,noreferrer`),floatingConfig:{position:`bottom-right`,defaultOpen:M,panelWidth:420,panelHeight:560,title:G.title,triggerSize:56},headerExtra:Ee,headerActions:ke,messages:q,labels:G.labels,models:pe,selectedModelId:U,onModelChange:ge,showAvatars:!0,hideClearBar:!0,assistantAvatarFallback:G.agentLabel,suggestions:q.length===0?ve??G.suggestions:void 0,placeholder:w?G.placeholder:C?G.loadingPlaceholder:G.placeholder,onSendMessage:e=>{K(),Y(e)},onClear:Te,onStop:J?Ce:void 0,onReload:we,isLoading:J,error:ye?void 0:Se,enableMarkdown:!0,onToolApprove:Z.decide,toolDecisions:Z.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onReviewDraft:e=>{e[0]&&y(e[0])},toolReviewLabel:G.reviewDraft,onOpenBuiltApp:e=>z(`/apps/${encodeURIComponent(e)}`),openBuiltAppLabel:G.openBuiltApp,onPreviewDraftApp:(e,t)=>z(t?.materialized?`/apps/${encodeURIComponent(e)}`:`/apps/${encodeURIComponent(e)}?preview=draft`),onDraftArtifacts:e=>{for(let t of e)x(t)},fetchPendingDraftCount:te,onPublishDrafts:async e=>{try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);let r=n?.data?.failedCount??n?.failedCount??0;if(r)throw Error(String(r));let i=n?.data?.seedApplied??n?.seedApplied;i&&i.success===!1?v.warning(G.seedWarn,{description:i.error??(Array.isArray(i.errors)&&i.errors.length?String(i.errors[0]):void 0)}):v.success(G.publishOk);let a=(n?.data?.published??n?.published??[]).find(e=>e?.type===`app`&&e?.name);return a?.name&&z(`/apps/${encodeURIComponent(a.name)}`),{ok:!0,health:ae(n)}}catch(e){return v.error(G.publishFailed,{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:G.publishDrafts,nextStepsLabel:G.nextSteps,planTitleLabel:G.planTitle,planQuestionsLabel:G.planQuestions,planAssumptionsLabel:G.planAssumptions,planDeferredLabel:G.planDeferred,planApproveHintLabel:G.planApproveHint,planApproveLabel:G.planApprove,planAdjustLabel:G.planAdjust,planBuiltLabel:G.planBuilt,planReadyLabel:G.planReady,planApproveMessage:G.planApproveMessage,planApproveDefaultsMessage:G.planApproveDefaultsMessage,planAnswerMessage:G.planAnswer,publishedLabel:G.published,autoPublishDrafts:k().features.autoPublishAiBuilds}),P&&(0,N.jsx)(p,{open:De,onOpenChange:$,objectName:`ai_conversations`,recordId:P,recordLabel:`this conversation`,apiBase:Oe})]})}function V({appLabel:e,appName:t,objects:n,apiBase:r,defaultAgent:i,showAgentPicker:a,defaultOpen:o=!1,userId:s}){let c=A.useMemo(()=>L(r),[r]),l={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},u=l.VITE_AI_DEFAULT_AGENT,{agents:d,isLoading:f,error:p}=w({apiBase:c}),m=M({agents:d,showAgentPickerProp:a,envOptIn:l.VITE_AI_SHOW_AGENT_PICKER===`true`,aiStudioEnabled:k().features.aiStudio!==!1}),[h,g]=A.useState(void 0);A.useEffect(()=>{if(!h&&d.length>0){let e=C(d,i??u);e&&g(e)}},[d,h,i,u]);let _=h?`${c}/agents/${encodeURIComponent(h)}/chat`:void 0,v=h?D(h)===`build`:!1,{conversationId:y,initialMessages:b,startNew:x}=S({userId:h?s:void 0,scope:h,apiBase:c,resumeMode:v?`resume`:`fresh`});return(0,N.jsx)(B,{appLabel:e,appName:t,objects:n,agents:d,agentsLoading:f,agentsError:p,activeAgent:h,onAgentChange:g,showAgentPicker:m,chatApi:_,apiBase:c,defaultOpen:o,conversationId:y,initialMessages:b,onNewChat:x},`${_??`local`}:${y??`pending`}`)}export{V as default};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{d as t,f as n,r,y as i}from"./vendor-react-BGDDiZfJ.js";import{l as a}from"./framework-B3O15Lsq.js";import{Jt as o,Kt as s,Xt as c,Yt as l,ct as u,di as d,dt as f,k as p,qt as m,ut as h,wi as g,xr as _}from"./ui-components-rkvkkTxO.js";import{r as v}from"./vendor-ui-utils-BzQBRdq3.js";import{i as y,s as b,t as x}from"./assistantBus-BFk4fCbM.js";import{c as S,l as ee,n as te,o as ne,t as re}from"./useReconcileOnError-_XnUvYJA.js";import{C as ie,a as ae,d as C,f as w,g as T,h as E,m as D,r as oe,t as se,u as ce,y as O}from"./plugin-chatbot-D2Uv-hn9.js";import{n as le,x as k}from"./marketplaceApi-zYQofLEk.js";var A=e(i(),1);function j(e){return e.some(e=>E(e.name))&&e.some(e=>T(e.name))}function M({agents:e,showAgentPickerProp:t,envOptIn:n=!1,aiStudioEnabled:r=!0}){return t===void 0?n?!0:r&&j(e):t}var N=r(),P={ask:{zh:`智能助手`,en:`Assistant`},build:{zh:`构建助手`,en:`Build assistant`}};function F(e,t,n){let r=t?P[D(t)]:void 0;return r?e?r.zh:r.en:n}function ue(e,t,n,r,i){let a=(e??``).toLowerCase().startsWith(`zh`),o=F(a,n,r),s=i.slice(0,2).map(e=>e.label||e.name);if(a){let e=[s[0]?`查询最近创建的${s[0]}`:`帮我查询最近的数据`,s[0]?`统计${s[0]}的总数量`:`统计各对象的记录数量`,s[1]?`${s[1]}有哪些字段?`:`当前应用里有哪些数据对象?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`你好,我是${o}`,emptyDescription:`随时帮你查询和分析「${t}」中的数据。试试下面的问题,或直接输入你的需求。`,clear:`清空对话`,sendHint:`发送`,agentActivity:`执行过程`,toolCompleted:`已完成`,toolRunning:`运行中`,toolAwaitingApproval:`等待确认`,toolFailed:`失败`,connectionWaiting:`正在等待服务器响应…`,connectionStalledLabel:`仍在处理中…`,connectionOfflineLabel:`网络已断开,正在重连…`,designingPlanLabel:`正在为你设计方案…`,designingPlanHints:[`梳理需要记录的数据…`,`设计对象与字段…`,`关联相关记录…`,`配置关系与查找字段…`,`规划页面与视图…`,`布置表单与列表…`,`补充默认值与校验…`,`规划一个看板来跟踪…`,`复核整体结构是否自洽…`,`汇总成完整方案…`],toolDetailsHidden:`已隐藏工具参数和原始结果,仅保留过程摘要。`,copy:`复制`,copied:`已复制`,regenerate:`重新生成`,model:`模型`,submit:`发送`,uploadFiles:`上传文件`,stopResponse:`停止生成`,sendFailedRateLimited:`发送过于频繁,请稍候再试。你的消息已保留在输入框中。`,sendFailedGeneric:`消息发送失败,请重试。你的消息已保留在输入框中。`,trace:`调试 trace`,viewTrace:`查看调试 trace`},placeholder:`向${o}提问…`,loadingPlaceholder:`正在加载助手…`,title:`${t} 智能助手`,newChat:`开启新对话`,share:`分享对话`,reviewDraft:e=>`查看 ${e} 项变更`,publishDrafts:`发布`,published:`已发布`,nextSteps:`下一步`,planTitle:`方案预览`,planQuestions:`搭建前请确认`,planAssumptions:`假设`,planDeferred:`待补 / 暂未搭建`,planApproveHint:`回复以确认或调整该方案。`,planApprove:`开始搭建`,planAdjust:`调整方案`,planBuilt:`已搭建`,planReady:`方案已就绪。点击开始搭建,或告诉我需要调整什么。`,planApproveMessage:`确认,开始搭建。`,planApproveDefaultsMessage:`确认搭建,未决问题按你的合理假设和默认处理。`,planAnswer:(e,t)=>`关于「${e}」,我选择「${t}」。`,publishOk:`已发布,对象已生效。`,publishFailed:`发布失败`,seedWarn:`已发布,但部分示例数据未能载入。`,openBuiltApp:`打开应用`,suggestions:e}}let c=[s[0]?`Show the latest ${s[0]}`:`Show my most recent records`,s[0]?`How many ${s[0]} are there?`:`Count records by status`,s[1]?`What fields does ${s[1]} have?`:`What data can I work with here?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`Hi, I'm ${o}`,emptyDescription:`I can help you query and analyze your ${t} data. Try a prompt below, or just type your question.`,clear:`Clear`,sendHint:`to send`,agentActivity:`Agent activity`,toolCompleted:`Completed`,toolRunning:`Running`,toolAwaitingApproval:`Awaiting approval`,toolFailed:`Failed`,connectionWaiting:`Waiting for server…`,connectionStalledLabel:`Still working…`,connectionOfflineLabel:`Connection lost — reconnecting…`,designingPlanLabel:`Designing your app…`,designingPlanHints:[`Mapping out the data you’ll track…`,`Shaping objects and their fields…`,`Connecting related records…`,`Setting up relationships and lookups…`,`Planning the screens and views…`,`Laying out forms and lists…`,`Adding sensible defaults and validations…`,`Sketching a dashboard to track it…`,`Double-checking the structure hangs together…`,`Pulling the plan together…`],toolDetailsHidden:`Tool inputs and raw results are hidden in this view.`,copy:`Copy`,copied:`Copied`,regenerate:`Regenerate`,model:`Model`,submit:`Submit`,uploadFiles:`Upload files`,stopResponse:`Stop response`,sendFailedRateLimited:`You're sending messages too quickly. Your message is kept below — wait a moment and try again.`,sendFailedGeneric:`Couldn't send your message. It's kept below — please try again.`,trace:`trace`,viewTrace:`View trace`},placeholder:`Ask ${o}...`,loadingPlaceholder:`Loading assistant...`,title:`${t} Assistant`,newChat:`New chat`,share:`Share conversation`,reviewDraft:e=>`Review ${e} change${e===1?``:`s`}`,publishDrafts:`Publish`,published:`Published`,nextSteps:`What's next`,planTitle:`Proposed plan`,planQuestions:`Confirm before building`,planAssumptions:`Assumptions`,planDeferred:`Not yet built`,planApproveHint:`Reply to approve or adjust this plan.`,planApprove:`Build it`,planAdjust:`Adjust`,planBuilt:`Built`,planReady:`The plan is ready. Build it now, or tell me what to adjust.`,planApproveMessage:`Looks good — build it as proposed.`,planApproveDefaultsMessage:`Build it with your best assumptions; use sensible defaults for the open questions.`,planAnswer:(e,t)=>`For "${e}", go with: ${t}.`,publishOk:`Published — objects are now live.`,publishFailed:`Publish failed`,seedWarn:`Published, but some sample data failed to load.`,openBuiltApp:`Open app`,suggestions:c}}var I=`/api/v1/ai`;function L(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${I}`}function de(e,t){if(!e||e.type!==`object`)return null;let n=e.label||e.name||`this object`;return(t??``).toLowerCase().startsWith(`zh`)?[`为「${n}」补充字段`,`为「${n}」建议校验规则`,`添加一个状态选项字段`]:[`Add fields to ${n}`,`Suggest validations for ${n}`,`Add a status picklist field`]}var R=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`,`metadata`]);function z(e){try{return decodeURIComponent(e)}catch{return e}}function fe(e,t){let n=e.split(`/`).filter(Boolean),r=n.indexOf(`apps`);if(r===-1||n.length<r+3)return{};let i=z(n[r+2]);if(R.has(i)||!t.some(e=>e.name===i))return{};let a=n[r+3]?z(n[r+3]):void 0,o=a&&a!==`new`?a:void 0;return{objectName:i,...o?{recordId:o}:{}}}function B({appLabel:e,appName:r,objects:i,agents:S,agentsLoading:C,activeAgent:w,onAgentChange:T,showAgentPicker:E,chatApi:D,apiBase:j,defaultOpen:M=!1,conversationId:P,initialMessages:I,onNewChat:L}){let{language:R}=a(),z=n(),B=t(),V=A.useMemo(()=>fe(B.pathname,i),[B.pathname,i]),{editor:H}=b(),{models:pe,defaultModelId:me}=ce({apiBase:j}),[he,ge]=A.useState(void 0),U=he??me,_e=A.useMemo(()=>!I||I.length===0?[]:ie(I),[I]),W=A.useMemo(()=>S.find(e=>e.name===w)?.label??w??e,[S,w,e]),G=A.useMemo(()=>ue(R,e,w,W,i),[R,e,w,W,i]),ve=A.useMemo(()=>de(H,R),[H,R]),{errorSuppressed:ye,handleChatError:be,setMessagesRef:xe,resetSuppression:K}=re({chatApi:D,conversationId:P}),{messages:q,isLoading:J,error:Se,sendMessage:Y,stop:Ce,reload:we,clear:Te,setMessages:X}=O({api:D,conversationId:P,model:U,onError:be,body:{context:{activeApp:e,appName:r,objects:i.map(e=>({name:e.name,label:e.label})),agentName:w,autoPublishAiBuilds:k().features.autoPublishAiBuilds,...V.objectName?{objectName:V.objectName}:{},...V.recordId?{recordId:V.recordId}:{},...H?{editing:H}:{}}},initialMessages:_e,autoResponse:!D,autoResponseText:i.length>0?`I can help you work with ${i.map(e=>e.label||e.name).join(`, `)}. What would you like to do?`:`Thanks for your message! I'm here to help you navigate and manage your data.`,autoResponseDelay:600});A.useEffect(()=>{xe.current=X},[X]),A.useEffect(()=>{ee(P,ne(q))},[P,q]);let Z=se({messages:q,apiBase:j,continueConversation:e=>{K(),Y(e)}}),Q=(R??``).toLowerCase().startsWith(`zh`),Ee=E&&S.length>1?S.length<=3?(0,N.jsx)(u,{value:w,onValueChange:T,children:(0,N.jsx)(h,{className:`h-7 gap-0.5 p-0.5`,"data-testid":`floating-chatbot-agent-picker`,children:S.map(e=>(0,N.jsx)(f,{value:e.name,disabled:C,title:e.description||void 0,className:`h-6 px-2.5 text-xs`,children:F(Q,e.name,e.label)},e.name))})}):(0,N.jsxs)(s,{value:w,onValueChange:T,disabled:C,children:[(0,N.jsx)(l,{className:`h-7 w-[180px] text-xs`,"data-testid":`floating-chatbot-agent-picker`,children:(0,N.jsx)(c,{placeholder:`Choose agent...`})}),(0,N.jsx)(m,{align:`end`,children:S.map(e=>(0,N.jsxs)(o,{value:e.name,className:`text-xs`,children:[(0,N.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,N.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[220px]`,children:e.description}):null]},e.name))})]}):null,[De,$]=A.useState(!1),Oe=A.useMemo(()=>j.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[j]),ke=(0,N.jsxs)(N.Fragment,{children:[q.length>0?(0,N.jsx)(_,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":G.newChat,title:G.newChat,"data-testid":`floating-chatbot-new`,onClick:L,children:(0,N.jsx)(d,{className:`h-4 w-4`})}):null,P?(0,N.jsx)(_,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":G.share,title:G.share,"data-testid":`floating-chatbot-share`,onClick:()=>$(!0),children:(0,N.jsx)(g,{className:`h-4 w-4`})}):null]});return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(oe,{onUpgrade:()=>window.open(le(),`_blank`,`noopener,noreferrer`),floatingConfig:{position:`bottom-right`,defaultOpen:M,panelWidth:420,panelHeight:560,title:G.title,triggerSize:56},headerExtra:Ee,headerActions:ke,messages:q,labels:G.labels,models:pe,selectedModelId:U,onModelChange:ge,showAvatars:!0,hideClearBar:!0,assistantAvatarFallback:G.agentLabel,suggestions:q.length===0?ve??G.suggestions:void 0,placeholder:w?G.placeholder:C?G.loadingPlaceholder:G.placeholder,onSendMessage:e=>{K(),Y(e)},onClear:Te,onStop:J?Ce:void 0,onReload:we,isLoading:J,error:ye?void 0:Se,enableMarkdown:!0,onToolApprove:Z.decide,toolDecisions:Z.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onReviewDraft:e=>{e[0]&&y(e[0])},toolReviewLabel:G.reviewDraft,onOpenBuiltApp:e=>z(`/apps/${encodeURIComponent(e)}`),openBuiltAppLabel:G.openBuiltApp,onPreviewDraftApp:(e,t)=>z(t?.materialized?`/apps/${encodeURIComponent(e)}`:`/apps/${encodeURIComponent(e)}?preview=draft`),onDraftArtifacts:e=>{for(let t of e)x(t)},fetchPendingDraftCount:te,onPublishDrafts:async e=>{try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);let r=n?.data?.failedCount??n?.failedCount??0;if(r)throw Error(String(r));let i=n?.data?.seedApplied??n?.seedApplied;i&&i.success===!1?v.warning(G.seedWarn,{description:i.error??(Array.isArray(i.errors)&&i.errors.length?String(i.errors[0]):void 0)}):v.success(G.publishOk);let a=(n?.data?.published??n?.published??[]).find(e=>e?.type===`app`&&e?.name);return a?.name&&z(`/apps/${encodeURIComponent(a.name)}`),{ok:!0,health:ae(n)}}catch(e){return v.error(G.publishFailed,{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:G.publishDrafts,nextStepsLabel:G.nextSteps,planTitleLabel:G.planTitle,planQuestionsLabel:G.planQuestions,planAssumptionsLabel:G.planAssumptions,planDeferredLabel:G.planDeferred,planApproveHintLabel:G.planApproveHint,planApproveLabel:G.planApprove,planAdjustLabel:G.planAdjust,planBuiltLabel:G.planBuilt,planReadyLabel:G.planReady,planApproveMessage:G.planApproveMessage,planApproveDefaultsMessage:G.planApproveDefaultsMessage,planAnswerMessage:G.planAnswer,publishedLabel:G.published,autoPublishDrafts:k().features.autoPublishAiBuilds}),P&&(0,N.jsx)(p,{open:De,onOpenChange:$,objectName:`ai_conversations`,recordId:P,recordLabel:`this conversation`,apiBase:Oe})]})}function V({appLabel:e,appName:t,objects:n,apiBase:r,defaultAgent:i,showAgentPicker:a,defaultOpen:o=!1,userId:s}){let c=A.useMemo(()=>L(r),[r]),l={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},u=l.VITE_AI_DEFAULT_AGENT,{agents:d,isLoading:f,error:p}=w({apiBase:c}),m=M({agents:d,showAgentPickerProp:a,envOptIn:l.VITE_AI_SHOW_AGENT_PICKER===`true`,aiStudioEnabled:k().features.aiStudio!==!1}),[h,g]=A.useState(void 0);A.useEffect(()=>{if(!h&&d.length>0){let e=C(d,i??u);e&&g(e)}},[d,h,i,u]);let _=h?`${c}/agents/${encodeURIComponent(h)}/chat`:void 0,v=h?D(h)===`build`:!1,{conversationId:y,initialMessages:b,startNew:x}=S({userId:h?s:void 0,scope:h,apiBase:c,resumeMode:v?`resume`:`fresh`});return(0,N.jsx)(B,{appLabel:e,appName:t,objects:n,agents:d,agentsLoading:f,agentsError:p,activeAgent:h,onAgentChange:g,showAgentPicker:m,chatApi:_,apiBase:c,defaultOpen:o,conversationId:y,initialMessages:b,onNewChat:x},`${_??`local`}:${y??`pending`}`)}export{V as default};
@@ -1 +1 @@
1
- import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{m as n,r,y as i}from"./vendor-react-BGDDiZfJ.js";import{d as a}from"./infrastructure-Bcx6-8du.js";import{E as o,L as s,R as c,l}from"./framework-B3O15Lsq.js";import{Cc as u,Fc as d,G as f,Gn as p,Gr as m,J as h,Jn as g,Kn as _,Ks as v,Or as y,Un as b,W as x,Wn as S,Xa as C,Xs as w,Ya as T,Yi as E,Zs as D,ii as O,na as ee,qn as te,qr as k,xr as A}from"./ui-components-rkvkkTxO.js";import{r as j}from"./vendor-ui-utils-BzQBRdq3.js";import"./AdapterProvider-DYYVhErE.js";import{n as ne}from"./plugin-form-FeZEoC2R.js";import"./MetadataProvider-BpQl3Bw2.js";import{r as re}from"./ExpressionProvider-ODpzkcN3.js";import{r as ie}from"./useMetadata-Eb5o6ihl.js";import{v as M}from"./ReportDefaultInspector-BA-D9th_.js";import{t as N}from"./utils-Bixzg6Bz.js";import{n as ae,r as oe,t as se}from"./MetadataInspector-RvnQ-QOT.js";import{n as P,t as F}from"./DashboardWidgetInspector-CUJFDeER.js";import{r as ce}from"./runtime-metadata-persistence-D1KKivGr.js";import{n as I,t as le}from"./useOpenRecordList-DIo7M1au.js";import{n as ue}from"./skeletons-CzC0fiXD.js";import{n as de}from"./plugin-dashboard-CRFZp7gC.js";var L=e(i(),1),R=r();function fe({open:e,onClose:t,schema:n,selectedWidgetId:r,onSelectWidget:i,onSave:a,onChange:o,onRemoveWidget:s,name:c,metadataClient:d,onAfterChange:f}){let{t:p}=l(),m=(0,L.useMemo)(()=>M(),[]),[h,g]=(0,L.useState)(!1),[_,v]=(0,L.useState)(0),b=(0,L.useCallback)(e=>{g(!0),o({...n??{},...e})},[n,o]),x=(0,L.useCallback)(e=>{o(e),g(!1)},[o]),S=(0,L.useCallback)(e=>{i(e&&e.kind===`widget`?e.id:null)},[i]),C=Array.isArray(n?.widgets)?n.widgets:[],w=r?C.find(e=>e?.id===r):null;if(!e)return null;let T=typeof n?.name==`string`?n.name:``,E=w?p(`widget.editor.title`,{defaultValue:`Edit widget`}):p(`dashboard.editor.title`,{defaultValue:`Edit dashboard`});return(0,R.jsxs)(`aside`,{className:`hidden sm:flex w-[440px] shrink-0 flex-col border-l bg-background h-full`,"data-testid":`dashboard-config-panel`,role:`complementary`,"aria-label":E,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-4 py-2.5 shrink-0`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[w&&(0,R.jsx)(A,{variant:`ghost`,size:`sm`,onClick:()=>i(null),className:`h-7 w-7 p-0`,"aria-label":p(`dashboard.editor.backToDashboard`,{defaultValue:`Back to dashboard`}),title:p(`dashboard.editor.backToDashboard`,{defaultValue:`Back to dashboard`}),"data-testid":`dashboard-config-back`,children:(0,R.jsx)(u,{className:`h-4 w-4`})}),(0,R.jsx)(`div`,{className:`text-sm font-medium truncate`,children:E})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[w&&s&&(0,R.jsx)(A,{variant:`ghost`,size:`sm`,onClick:()=>s(r),className:`h-7 w-7 p-0 text-destructive hover:text-destructive`,"aria-label":p(`widget.editor.delete`,{defaultValue:`Delete widget`}),title:p(`widget.editor.delete`,{defaultValue:`Delete widget`}),"data-testid":`widget-delete-button`,children:(0,R.jsx)(k,{className:`h-3.5 w-3.5`})}),(0,R.jsx)(A,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 w-7 p-0`,"aria-label":p(`common.close`,{defaultValue:`Close`}),"data-testid":`dashboard-config-close`,children:(0,R.jsx)(y,{className:`h-4 w-4`})})]})]}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:w?(0,R.jsx)(F,{type:`dashboard`,name:T,draft:n??{},selection:{kind:`widget`,id:r},onPatch:b,onClearSelection:()=>i(null),onSelectionChange:S,readOnly:!1,locale:m}):(0,R.jsx)(P,{type:`dashboard`,name:T,draft:n??{},onPatch:b,onSelectionChange:S,readOnly:!1,locale:m})}),(0,R.jsxs)(`div`,{"data-testid":`dashboard-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5 shrink-0`,children:[(0,R.jsx)(I,{type:`dashboard`,name:c||T||void 0,metadataClient:d,dirty:h,onResume:x,savedSignal:_,onAfterChange:f}),(0,R.jsx)(A,{size:`sm`,onClick:()=>{a(n??{}),g(!1),v(e=>e+1)},"data-testid":`dashboard-config-save`,children:p(`common.save`,{defaultValue:`Save`})})]})]})}var z=t({DashboardView:()=>U}),B=[{type:`metric`,label:`KPI Metric`,Icon:m},{type:`bar`,label:`Bar Chart`,Icon:D},{type:`line`,label:`Line Chart`,Icon:w},{type:`pie`,label:`Pie Chart`,Icon:v},{type:`table`,label:`Table`,Icon:O},{type:`pivot`,label:`Pivot`,Icon:T}],V=0;function H(){return V+=1,`widget_${Date.now()}_${V}`}function pe(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:H()})}}function me(e){let t=B.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}function U({dataSource:e}){let t=le(),{dashboardName:r}=n(),{showDebug:i}=ae(),u=s(),m=ie(),{t:v}=l(),{dashboardLabel:y,dashboardDescription:w}=d(),T=a(),[D,O]=(0,L.useState)(!0),[k,M]=(0,L.useState)(!1),[P,F]=(0,L.useState)(null),[I,z]=(0,L.useState)(null),V=(0,L.useCallback)(e=>{z(t=>(t&&t.resolve(e),null))},[]),U=(0,L.useCallback)(e=>new Promise(t=>{let n;if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);if(t){let e=t[1];n={objectName:t[2],mode:e===`edit`||e===`update`?`edit`:`create`}}else n={objectName:e,mode:`create`}}else n=e;z({schema:n,resolve:t})}),[]),he=(0,L.useMemo)(()=>({export_dashboard_pdf:async()=>{j.info(v(`dashboardActions.pdfPreparing`));try{return window.print(),{success:!0}}catch(e){return j.error(v(`dashboardActions.exportFailed`,{message:e?.message||String(e)})),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(j.info(v(`dashboardActions.forecastSoon`)),{success:!0})}),[v]);(0,L.useEffect)(()=>{O(!0),J(null),M(!1),F(null),queueMicrotask(()=>O(!1))},[r]);let{dashboards:ge,objects:W,refresh:G}=c(),{app:_e}=re(),K=oe(ge,r,_e?._packageId),[q,J]=(0,L.useState)(null);(0,L.useEffect)(()=>{k||J(null)},[K]);let Y=(0,L.useCallback)(async e=>{try{m&&await ce(`dashboard`,r,e,{metadataClient:m}),G().catch(()=>{})}catch(e){let t=e instanceof Error?e.message:String(e);console.warn(`[DashboardView] Auto-save failed:`,e),j.error(`Failed to save dashboard: ${t}`)}},[m,r,G]),ve=(0,L.useCallback)(()=>{J(pe(K)),M(!0)},[K]),ye=(0,L.useCallback)(()=>{M(!1),F(null)},[]),X=(0,L.useCallback)(e=>{if(!q)return;let t=H(),n={id:t,title:me(e),type:e,layout:{x:0,y:q.widgets?.length??0,w:q.columns??2,h:1}},r={...q,widgets:[...q.widgets||[],n]};J(r),Y(r),F(t)},[q,Y]),be=(0,L.useCallback)(e=>{if(!q)return;let t={...q,widgets:q.widgets.filter(t=>t.id!==e)};J(t),Y(t),P===e&&F(null)},[q,P,Y]),xe=(0,L.useCallback)(e=>{let t=q||K;if(!t)return;let n={...t,widgets:e};J(n),Y(n)},[q,K,Y]),Se=(q||K)??null,Z=(0,L.useMemo)(()=>new Set((W||[]).map(e=>e?.name).filter(Boolean)),[W]),Q=q||K,$=(0,L.useMemo)(()=>{if(!Q||Z.size===0)return Q;let e=Q.widgets;if(!Array.isArray(e)||e.length===0)return Q;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?Z.has(t):!0});return t.length===e.length?Q:{...Q,widgets:t}},[Q,Z]);return D?(0,R.jsx)(ue,{}):K?(0,R.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,R.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between sm:items-center gap-3 sm:gap-4 p-4 sm:p-6 border-b shrink-0`,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(()=>{let e=N(($||K).title,v),t=N(K.label,v),n=y({name:K.name,label:t});return(0,R.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:e||n||K.name})})(),(()=>{let e=($||K).description??K.description,t=w({name:K.name,description:N(e,v)});return t?(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:t}):null})()]}),(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:[k&&(0,R.jsx)(`div`,{className:`flex items-center gap-1 mr-2`,role:`toolbar`,"aria-label":`Add widgets`,"data-testid":`dashboard-widget-toolbar`,children:B.map(({type:e,label:t,Icon:n})=>(0,R.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>X(e),className:`inline-flex items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,title:`Add ${t}`,"aria-label":`Add ${t} widget`,children:[(0,R.jsx)(E,{className:`h-3 w-3`}),(0,R.jsx)(n,{className:`h-3 w-3`})]},e))}),T&&(0,R.jsxs)(`button`,{type:`button`,onClick:ve,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`dashboard-edit-button`,children:[(0,R.jsx)(ee,{className:`h-3.5 w-3.5`}),v(`common.edit`,{defaultValue:`Edit`})]})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-2 sm:p-4 md:p-6`,children:(0,R.jsx)(o,{value:{openRecordList:t},children:(0,R.jsx)(de,{schema:$,dataSource:e,designMode:k,selectedWidgetId:P,onWidgetClick:F,onWidgetsReorder:xe,modalHandler:U,scriptHandlers:he,hideHeaderText:!0})})}),(0,R.jsx)(fe,{open:k&&T,onClose:ye,schema:Se,selectedWidgetId:P,onSelectWidget:F,onSave:Y,onChange:J,onRemoveWidget:be,name:r,metadataClient:m,onAfterChange:()=>G().catch(()=>{})}),(0,R.jsx)(se,{open:i,sections:[{title:`Dashboard Configuration`,data:$}]})]}),I&&I.schema?.objectName?(0,R.jsx)(ne,{schema:{type:`object-form`,formType:`modal`,objectName:I.schema.objectName,mode:I.schema.mode||`create`,recordId:I.schema.recordId,title:I.schema.title,description:I.schema.description,fields:I.schema.fields,open:!0,onOpenChange:e=>{e||V({success:!1})},onSuccess:e=>{V({success:!0,reload:!0,data:e})},onCancel:()=>{V({success:!1})},showSubmit:!0,showCancel:!0},dataSource:u}):I?(0,R.jsx)(b,{open:!0,onOpenChange:e=>{e||V({success:!1})},children:(0,R.jsxs)(S,{children:[(0,R.jsxs)(te,{children:[(0,R.jsx)(g,{children:I.schema?.title||v(`actionDialog.defaultActionTitle`)}),I.schema?.description&&(0,R.jsx)(p,{children:I.schema.description})]}),(0,R.jsxs)(_,{children:[(0,R.jsx)(A,{variant:`outline`,onClick:()=>V({success:!1}),children:v(`actionDialog.cancel`)}),(0,R.jsx)(A,{onClick:()=>V({success:!0}),children:v(`actionDialog.ok`)})]})]})}):null]}):(0,R.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,R.jsxs)(x,{children:[(0,R.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,R.jsx)(C,{className:`h-6 w-6 text-muted-foreground`})}),(0,R.jsx)(h,{children:v(`empty.dashboardNotFound`)}),(0,R.jsx)(f,{children:v(`empty.dashboardNotFoundDescription`,{name:r})})]})})}export{z as t};
1
+ import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{m as n,r,y as i}from"./vendor-react-BGDDiZfJ.js";import{d as a}from"./infrastructure-Bcx6-8du.js";import{E as o,L as s,R as c,l}from"./framework-B3O15Lsq.js";import{Cc as u,Fc as d,G as f,Gn as p,Gr as m,J as h,Jn as g,Kn as _,Ks as v,Or as y,Un as b,W as x,Wn as S,Xa as C,Xs as w,Ya as T,Yi as E,Zs as D,ii as O,na as ee,qn as te,qr as k,xr as A}from"./ui-components-rkvkkTxO.js";import{r as j}from"./vendor-ui-utils-BzQBRdq3.js";import"./AdapterProvider-qwVfmAEk.js";import{n as ne}from"./plugin-form-FeZEoC2R.js";import"./MetadataProvider-DKJsxrNu.js";import{r as re}from"./ExpressionProvider-ODpzkcN3.js";import{r as ie}from"./useMetadata-Ily0JuNR.js";import{v as M}from"./ReportDefaultInspector-CJGXWwWN.js";import{t as N}from"./utils-Bixzg6Bz.js";import{n as ae,r as oe,t as se}from"./MetadataInspector-RvnQ-QOT.js";import{n as P,t as F}from"./DashboardWidgetInspector-DknOds9r.js";import{r as ce}from"./runtime-metadata-persistence-D1KKivGr.js";import{n as I,t as le}from"./useOpenRecordList-tyj2_1bm.js";import{n as ue}from"./skeletons-CzC0fiXD.js";import{n as de}from"./plugin-dashboard-CRFZp7gC.js";var L=e(i(),1),R=r();function fe({open:e,onClose:t,schema:n,selectedWidgetId:r,onSelectWidget:i,onSave:a,onChange:o,onRemoveWidget:s,name:c,metadataClient:d,onAfterChange:f}){let{t:p}=l(),m=(0,L.useMemo)(()=>M(),[]),[h,g]=(0,L.useState)(!1),[_,v]=(0,L.useState)(0),b=(0,L.useCallback)(e=>{g(!0),o({...n??{},...e})},[n,o]),x=(0,L.useCallback)(e=>{o(e),g(!1)},[o]),S=(0,L.useCallback)(e=>{i(e&&e.kind===`widget`?e.id:null)},[i]),C=Array.isArray(n?.widgets)?n.widgets:[],w=r?C.find(e=>e?.id===r):null;if(!e)return null;let T=typeof n?.name==`string`?n.name:``,E=w?p(`widget.editor.title`,{defaultValue:`Edit widget`}):p(`dashboard.editor.title`,{defaultValue:`Edit dashboard`});return(0,R.jsxs)(`aside`,{className:`hidden sm:flex w-[440px] shrink-0 flex-col border-l bg-background h-full`,"data-testid":`dashboard-config-panel`,role:`complementary`,"aria-label":E,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-4 py-2.5 shrink-0`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[w&&(0,R.jsx)(A,{variant:`ghost`,size:`sm`,onClick:()=>i(null),className:`h-7 w-7 p-0`,"aria-label":p(`dashboard.editor.backToDashboard`,{defaultValue:`Back to dashboard`}),title:p(`dashboard.editor.backToDashboard`,{defaultValue:`Back to dashboard`}),"data-testid":`dashboard-config-back`,children:(0,R.jsx)(u,{className:`h-4 w-4`})}),(0,R.jsx)(`div`,{className:`text-sm font-medium truncate`,children:E})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[w&&s&&(0,R.jsx)(A,{variant:`ghost`,size:`sm`,onClick:()=>s(r),className:`h-7 w-7 p-0 text-destructive hover:text-destructive`,"aria-label":p(`widget.editor.delete`,{defaultValue:`Delete widget`}),title:p(`widget.editor.delete`,{defaultValue:`Delete widget`}),"data-testid":`widget-delete-button`,children:(0,R.jsx)(k,{className:`h-3.5 w-3.5`})}),(0,R.jsx)(A,{variant:`ghost`,size:`sm`,onClick:t,className:`h-7 w-7 p-0`,"aria-label":p(`common.close`,{defaultValue:`Close`}),"data-testid":`dashboard-config-close`,children:(0,R.jsx)(y,{className:`h-4 w-4`})})]})]}),(0,R.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:w?(0,R.jsx)(F,{type:`dashboard`,name:T,draft:n??{},selection:{kind:`widget`,id:r},onPatch:b,onClearSelection:()=>i(null),onSelectionChange:S,readOnly:!1,locale:m}):(0,R.jsx)(P,{type:`dashboard`,name:T,draft:n??{},onPatch:b,onSelectionChange:S,readOnly:!1,locale:m})}),(0,R.jsxs)(`div`,{"data-testid":`dashboard-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5 shrink-0`,children:[(0,R.jsx)(I,{type:`dashboard`,name:c||T||void 0,metadataClient:d,dirty:h,onResume:x,savedSignal:_,onAfterChange:f}),(0,R.jsx)(A,{size:`sm`,onClick:()=>{a(n??{}),g(!1),v(e=>e+1)},"data-testid":`dashboard-config-save`,children:p(`common.save`,{defaultValue:`Save`})})]})]})}var z=t({DashboardView:()=>U}),B=[{type:`metric`,label:`KPI Metric`,Icon:m},{type:`bar`,label:`Bar Chart`,Icon:D},{type:`line`,label:`Line Chart`,Icon:w},{type:`pie`,label:`Pie Chart`,Icon:v},{type:`table`,label:`Table`,Icon:O},{type:`pivot`,label:`Pivot`,Icon:T}],V=0;function H(){return V+=1,`widget_${Date.now()}_${V}`}function pe(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:H()})}}function me(e){let t=B.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}function U({dataSource:e}){let t=le(),{dashboardName:r}=n(),{showDebug:i}=ae(),u=s(),m=ie(),{t:v}=l(),{dashboardLabel:y,dashboardDescription:w}=d(),T=a(),[D,O]=(0,L.useState)(!0),[k,M]=(0,L.useState)(!1),[P,F]=(0,L.useState)(null),[I,z]=(0,L.useState)(null),V=(0,L.useCallback)(e=>{z(t=>(t&&t.resolve(e),null))},[]),U=(0,L.useCallback)(e=>new Promise(t=>{let n;if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);if(t){let e=t[1];n={objectName:t[2],mode:e===`edit`||e===`update`?`edit`:`create`}}else n={objectName:e,mode:`create`}}else n=e;z({schema:n,resolve:t})}),[]),he=(0,L.useMemo)(()=>({export_dashboard_pdf:async()=>{j.info(v(`dashboardActions.pdfPreparing`));try{return window.print(),{success:!0}}catch(e){return j.error(v(`dashboardActions.exportFailed`,{message:e?.message||String(e)})),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(j.info(v(`dashboardActions.forecastSoon`)),{success:!0})}),[v]);(0,L.useEffect)(()=>{O(!0),J(null),M(!1),F(null),queueMicrotask(()=>O(!1))},[r]);let{dashboards:ge,objects:W,refresh:G}=c(),{app:_e}=re(),K=oe(ge,r,_e?._packageId),[q,J]=(0,L.useState)(null);(0,L.useEffect)(()=>{k||J(null)},[K]);let Y=(0,L.useCallback)(async e=>{try{m&&await ce(`dashboard`,r,e,{metadataClient:m}),G().catch(()=>{})}catch(e){let t=e instanceof Error?e.message:String(e);console.warn(`[DashboardView] Auto-save failed:`,e),j.error(`Failed to save dashboard: ${t}`)}},[m,r,G]),ve=(0,L.useCallback)(()=>{J(pe(K)),M(!0)},[K]),ye=(0,L.useCallback)(()=>{M(!1),F(null)},[]),X=(0,L.useCallback)(e=>{if(!q)return;let t=H(),n={id:t,title:me(e),type:e,layout:{x:0,y:q.widgets?.length??0,w:q.columns??2,h:1}},r={...q,widgets:[...q.widgets||[],n]};J(r),Y(r),F(t)},[q,Y]),be=(0,L.useCallback)(e=>{if(!q)return;let t={...q,widgets:q.widgets.filter(t=>t.id!==e)};J(t),Y(t),P===e&&F(null)},[q,P,Y]),xe=(0,L.useCallback)(e=>{let t=q||K;if(!t)return;let n={...t,widgets:e};J(n),Y(n)},[q,K,Y]),Se=(q||K)??null,Z=(0,L.useMemo)(()=>new Set((W||[]).map(e=>e?.name).filter(Boolean)),[W]),Q=q||K,$=(0,L.useMemo)(()=>{if(!Q||Z.size===0)return Q;let e=Q.widgets;if(!Array.isArray(e)||e.length===0)return Q;let t=e.filter(e=>{let t=e?.requiresObject??e?.object;return t?Z.has(t):!0});return t.length===e.length?Q:{...Q,widgets:t}},[Q,Z]);return D?(0,R.jsx)(ue,{}):K?(0,R.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,R.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between sm:items-center gap-3 sm:gap-4 p-4 sm:p-6 border-b shrink-0`,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(()=>{let e=N(($||K).title,v),t=N(K.label,v),n=y({name:K.name,label:t});return(0,R.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:e||n||K.name})})(),(()=>{let e=($||K).description??K.description,t=w({name:K.name,description:N(e,v)});return t?(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:t}):null})()]}),(0,R.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:[k&&(0,R.jsx)(`div`,{className:`flex items-center gap-1 mr-2`,role:`toolbar`,"aria-label":`Add widgets`,"data-testid":`dashboard-widget-toolbar`,children:B.map(({type:e,label:t,Icon:n})=>(0,R.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>X(e),className:`inline-flex items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,title:`Add ${t}`,"aria-label":`Add ${t} widget`,children:[(0,R.jsx)(E,{className:`h-3 w-3`}),(0,R.jsx)(n,{className:`h-3 w-3`})]},e))}),T&&(0,R.jsxs)(`button`,{type:`button`,onClick:ve,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`dashboard-edit-button`,children:[(0,R.jsx)(ee,{className:`h-3.5 w-3.5`}),v(`common.edit`,{defaultValue:`Edit`})]})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,R.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-2 sm:p-4 md:p-6`,children:(0,R.jsx)(o,{value:{openRecordList:t},children:(0,R.jsx)(de,{schema:$,dataSource:e,designMode:k,selectedWidgetId:P,onWidgetClick:F,onWidgetsReorder:xe,modalHandler:U,scriptHandlers:he,hideHeaderText:!0})})}),(0,R.jsx)(fe,{open:k&&T,onClose:ye,schema:Se,selectedWidgetId:P,onSelectWidget:F,onSave:Y,onChange:J,onRemoveWidget:be,name:r,metadataClient:m,onAfterChange:()=>G().catch(()=>{})}),(0,R.jsx)(se,{open:i,sections:[{title:`Dashboard Configuration`,data:$}]})]}),I&&I.schema?.objectName?(0,R.jsx)(ne,{schema:{type:`object-form`,formType:`modal`,objectName:I.schema.objectName,mode:I.schema.mode||`create`,recordId:I.schema.recordId,title:I.schema.title,description:I.schema.description,fields:I.schema.fields,open:!0,onOpenChange:e=>{e||V({success:!1})},onSuccess:e=>{V({success:!0,reload:!0,data:e})},onCancel:()=>{V({success:!1})},showSubmit:!0,showCancel:!0},dataSource:u}):I?(0,R.jsx)(b,{open:!0,onOpenChange:e=>{e||V({success:!1})},children:(0,R.jsxs)(S,{children:[(0,R.jsxs)(te,{children:[(0,R.jsx)(g,{children:I.schema?.title||v(`actionDialog.defaultActionTitle`)}),I.schema?.description&&(0,R.jsx)(p,{children:I.schema.description})]}),(0,R.jsxs)(_,{children:[(0,R.jsx)(A,{variant:`outline`,onClick:()=>V({success:!1}),children:v(`actionDialog.cancel`)}),(0,R.jsx)(A,{onClick:()=>V({success:!0}),children:v(`actionDialog.ok`)})]})]})}):null]}):(0,R.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,R.jsxs)(x,{children:[(0,R.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,R.jsx)(C,{className:`h-6 w-6 text-muted-foreground`})}),(0,R.jsx)(h,{children:v(`empty.dashboardNotFound`)}),(0,R.jsx)(f,{children:v(`empty.dashboardNotFoundDescription`,{name:r})})]})})}export{z as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{U as r,f as i,v as a}from"./vendor-objectstack-Bw0HRuFa.js";import{$o as o,Ba as s,Bn as c,Fn as l,Gs as u,Is as d,Js as f,Jt as p,Kr as m,Ks as h,Kt as g,Ln as _,Oc as v,Oi as y,Or as b,Qs as x,Rn as S,Us as ee,Vn as te,Xs as C,Xt as w,Yi as T,Ys as E,Yt as D,an as O,ar as k,dn as A,ds as j,fo as ne,go as re,ii as ie,in as M,kc as N,ns as ae,on as P,qt as F,sn as I,xr as L,zn as oe}from"./ui-components-rkvkkTxO.js";import{r as R}from"./useMetadata-Eb5o6ihl.js";import{F as se,I as ce,M as z,N as le,P as B,W as ue,_ as de,a as fe,g as pe,i as me,j as he,k as ge,p as _e,r as ve,t as V,y as H}from"./ReportDefaultInspector-BA-D9th_.js";var U=e(n(),1),W=t();function ye(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 G({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:u,allowCustom:f=!0,mono:p,className:m}){let[h,g]=U.useState(!1),[v,y]=U.useState(``),b=r.find(e=>e.value===t),x=b?b.label:t||(u?`Loading…`:i),C=U.useMemo(()=>r.filter(e=>ye(e,v)),[r,v]),w=U.useMemo(()=>{let e=[],t=new Map;for(let n of C){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)}))},[C]),T=v.trim(),E=f&&!!T&&!r.some(e=>e.value===T),D=e=>{n(e),g(!1),y(``)},k=(0,W.jsxs)(M,{open:h,onOpenChange:e=>{g(e),e||y(``)},children:[(0,W.jsx)(P,{asChild:!0,children:(0,W.jsxs)(L,{type:`button`,variant:`outline`,role:`combobox`,"aria-expanded":h,disabled:s,className:N(`h-8 w-full justify-between px-2 text-sm font-normal`,m),children:[(0,W.jsx)(`span`,{className:N(`truncate`,p&&`font-mono`,!b&&!t&&`text-muted-foreground`),children:x}),(0,W.jsx)(d,{className:`ml-2 h-3.5 w-3.5 shrink-0 opacity-50`})]})}),(0,W.jsx)(O,{align:`start`,className:`w-[var(--radix-popover-trigger-width)] min-w-[14rem] p-0`,children:(0,W.jsxs)(l,{shouldFilter:!1,children:[(0,W.jsx)(oe,{value:v,onValueChange:y,placeholder:a}),(0,W.jsxs)(te,{children:[!E&&C.length===0&&(0,W.jsx)(_,{children:o}),E&&(0,W.jsx)(S,{children:(0,W.jsx)(c,{value:`__custom__${T}`,onSelect:()=>D(T),children:(0,W.jsxs)(`span`,{className:`truncate`,children:[`Use `,(0,W.jsxs)(`span`,{className:`font-mono`,children:[`“`,T,`”`]})]})})}),w.map((e,n)=>(0,W.jsx)(S,{heading:e.heading||void 0,children:e.items.map(e=>(0,W.jsxs)(c,{value:e.value,onSelect:()=>D(e.value),children:[(0,W.jsx)(ee,{className:N(`h-3.5 w-3.5`,e.value===t?`opacity-100`:`opacity-0`)}),(0,W.jsx)(`span`,{className:`truncate font-mono`,children:e.value}),e.label&&e.label!==e.value&&(0,W.jsx)(`span`,{className:`ml-1 truncate text-muted-foreground`,children:e.label}),e.hint&&(0,W.jsx)(`span`,{className:`ml-auto pl-2 text-[10px] text-muted-foreground`,children:e.hint})]},e.value))},e.heading||`g${n}`))]})]})})]});return e?(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsx)(A,{className:`text-xs text-muted-foreground`,children:e}),k]}):k}var be=new Set([`lookup`,`master_detail`,`masterdetail`,`master-detail`]);function K(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 xe(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 Se(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 q(e,t){if(!e)return{label:t,fields:[],relationships:[]};let n=K(e.label,t),r=ue(e.fields).entries.map(e=>({name:e.name,label:K(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&&be.has(e.type.toLowerCase())).map(e=>({name:e.name,label:e.label,referenceTo:xe(e.def)}))}}function J(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 Ce(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=J(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 Y(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e))return e.some(e=>Y(e,t));let n=e;return typeof n.dataset==`string`&&n.dataset===t?!0:Object.values(n).some(e=>e&&typeof e==`object`&&Y(e,t))}function we(){let e=R(),[t,n]=U.useState({options:[],loading:!0});return U.useEffect(()=>{let t=!1;return n(e=>({...e,loading:!0})),e.list(`object`).then(e=>{if(t)return;let r=(Array.isArray(e)?e:[]).map(e=>({name:typeof e.name==`string`?e.name:``,label:K(e.label,typeof e.name==`string`?e.name:``)})).filter(e=>!!e.name).sort((e,t)=>e.label.localeCompare(t.label));n({options:r,loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function Te(e,t){let n=R(),r=t.join(`\0`),[i,a]=U.useState({relationships:[],fieldOptions:[],loading:!!e});return U.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=q(i,e),s=r?r.split(`\0`):[],c={[e]:o},l=async e=>{if(c[e])return c[e];let t;try{t=q(await n.get(`object`,e),e)}catch{t=q(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=J(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:Ce(o,s,c),loading:!1})}catch{t||a({relationships:[],fieldOptions:[],loading:!1})}})(),()=>{t=!0}},[n,e,r]),i}function Ee(e){let t=R(),[n,r]=U.useState({reports:0,dashboards:0,loading:!!e});return U.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=>Y(t,e)).length,dashboards:(Array.isArray(a)?a:[]).filter(t=>Y(t,e)).length,loading:!1})})(),()=>{n=!0}},[t,e]),n}var X={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:ne},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:E},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:f},line:{id:`line`,label:`Line chart`,category:`chart`,icon:C},area:{id:`area`,label:`Area chart`,category:`chart`,icon:x},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:h},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:o},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:u},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:m},table:{id:`table`,label:`Data table`,category:`data`,icon:ie},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:ae},list:{id:`list`,label:`Record list`,category:`data`,icon:s},custom:{id:`custom`,label:`Custom widget`,category:`custom`,icon:j}},De={kpi:`Single value`,chart:`Charts`,data:`Tabular`,custom:`Custom`},Oe=[`kpi`,`chart`,`data`,`custom`].map(e=>({category:e,types:Object.values(X).filter(t=>t.category===e)})),ke=v;function Ae({onAdd:e,label:t=`Add widget`}){let[n,r]=U.useState(!1),[i,a]=U.useState(``),o=U.useRef(null),s=U.useMemo(()=>{let e=i.trim().toLowerCase();return e?Oe.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):Oe},[i]);return(0,W.jsxs)(M,{open:n,onOpenChange:e=>{r(e),e||a(``)},children:[(0,W.jsx)(P,{asChild:!0,children:(0,W.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`,children:[(0,W.jsx)(T,{className:`h-3 w-3`}),t]})}),(0,W.jsxs)(O,{align:`end`,sideOffset:4,className:`w-72 p-0`,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,W.jsx)(y,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,W.jsx)(`input`,{ref:o,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,W.jsx)(`div`,{className:`max-h-72 overflow-auto py-1`,children:s.length===0?(0,W.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No matches.`}):s.map(t=>(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:De[t.category]}),t.types.map(t=>(0,W.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,W.jsx)(X[t.id]?.icon??ke,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,W.jsx)(`span`,{className:`font-medium truncate`,children:t.label}),(0,W.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=U.useCallback(e=>H(e,r),[r]),s=typeof e.label==`string`?e.label:``,c=typeof e.description==`string`?e.description:``,l=U.useMemo(()=>Array.isArray(e.widgets)?e.widgets:[],[e.widgets]),u=e=>{let n=ce(`widget`,l.map(e=>e?.id).filter(Boolean)),r=X[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:n,type:e,title:a,...r?.defaults??{}};t({widgets:le(l,o)}),i?.({kind:`widget`,id:n,label:a})},d=e=>{t({widgets:se(l,e,null)})},f=(e,n)=>{e!==n&&t({widgets:B(l,e,n)})},p=(e,t)=>{e?.id&&i?.({kind:`widget`,id:e.id,label:e.title||e.id||`Widget ${t+1}`})},[m,h]=U.useState(null),[g,_]=U.useState(null),{schema:v,form:y}=U.useMemo(()=>fe({bundledSchema:Pe(),bundledForm:Fe(),serverSchema:a,excludeFields:Ie,sectionTitle:H(`engine.inspector.moreFields`,r)}),[a,r]);return(0,W.jsxs)(he,{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,W.jsx)(z,{label:o(`engine.inspector.dashboard.label`),value:s,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.dashboard.labelPlaceholder`),disabled:n}),(0,W.jsx)(z,{label:o(`engine.inspector.dashboard.description`),value:c,onCommit:e=>t({description:e}),placeholder:o(`engine.inspector.dashboard.descriptionPlaceholder`),disabled:n}),(0,W.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(A,{className:`text-xs text-muted-foreground`,children:o(`engine.inspector.dashboard.widgets`)}),(0,W.jsx)(k,{variant:`outline`,className:`text-[10px]`,children:l.length})]}),l.length===0?(0,W.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,W.jsx)(`div`,{className:`space-y-1`,children:l.map((e,t)=>{let r=X[e?.type]?.icon??ke;return(0,W.jsxs)(`div`,{draggable:!n,onDragStart:()=>h(t),onDragEnd:()=>{h(null),_(null)},onDragOver:e=>{e.preventDefault(),_(t)},onDrop:()=>{m!=null&&m!==t&&f(m,t),h(null),_(null)},className:`group flex items-center gap-2 rounded-md border px-2 py-1.5 text-xs hover:bg-accent`+(g===t&&m!==null&&m!==t?` border-primary`:``),children:[!n&&(0,W.jsx)(re,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground`}),(0,W.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,W.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 truncate text-left font-medium`,onClick:()=>p(e,t),title:e?.title||e?.id,children:e?.title||e?.id||`Widget ${t+1}`}),(0,W.jsx)(`code`,{className:`text-[10px] text-muted-foreground`,children:e?.type}),!n&&(0,W.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 shrink-0 p-0 opacity-0 group-hover:opacity-100`,onClick:()=>d(t),title:o(`engine.inspector.dashboard.removeWidget`),"aria-label":o(`engine.inspector.dashboard.removeWidget`),children:(0,W.jsx)(b,{className:`h-3.5 w-3.5`})})]},e?.id??t)})}),!n&&(0,W.jsx)(Ae,{onAdd:u,label:o(`engine.inspector.add.widget`)})]}),(0,W.jsx)(`div`,{className:`border-t pt-3`,children:v?(0,W.jsx)(_e,{schema:v,form:y,value:e,hiddenFields:[`name`,`label`,`description`,`widgets`],readOnly:n,onChange:e=>t(e)}):(0,W.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:[],c=t.kind===`widget`?t.id:void 0,l=c?Ve(e,c):null,u=l?.widget??{},d=typeof u.dataset==`string`?u.dataset:``,f=typeof u.object==`string`?u.object:``,m=Array.isArray(u.dimensions)?u.dimensions.filter(e=>typeof e==`string`):[],h=Array.isArray(u.values)?u.values.filter(e=>typeof e==`string`):[],_=ve(),v=me(d||void 0,_),{options:y,loading:x}=we(),{fields:S}=pe(f||void 0),ee=U.useMemo(()=>{let e=_.datasets.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return d&&!e.some(e=>e.value===d)&&e.push({value:d,label:d}),e},[_.datasets,d]),te=U.useMemo(()=>y.map(e=>({value:e.name,label:e.label})),[y]),C=U.useMemo(()=>S.map(e=>({value:e.name,label:e.label,hint:e.type})),[S]),T=U.useMemo(()=>v.measures.map(e=>({name:e.name,label:e.aggregate?`${e.name} · ${e.aggregate}`:e.name,type:`number`,hidden:!1})),[v.measures]),E=U.useMemo(()=>v.dimensions.map(e=>({name:e.name,label:e.name,type:e.type??`text`,hidden:!1})),[v.dimensions]);if(t.kind!==`widget`)return(0,W.jsx)(Ue,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});if(!l)return(0,W.jsx)(Ue,{message:`The selected widget was removed from the draft.`,onClose:r,locale:o});let{widget:O,index:k}=l;function A(e){let t=[...s];t[k]={...t[k],...e},n({widgets:t})}function j(e){n({widgets:B(s,k,e)}),O.id&&i?.({kind:`widget`,id:O.id,label:O.title??void 0})}return(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:H(`engine.inspector.widget.kind`,o)}),(0,W.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:O.title||t.label||`Widget ${k+1}`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,W.jsx)(ge,{index:k,total:s.length,onMove:j,upLabel:H(`engine.inspector.reorder.up`,o),downLabel:H(`engine.inspector.reorder.down`,o),disabled:a}),(0,W.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:H(`engine.inspector.widget.close`,o),"aria-label":H(`engine.inspector.widget.close`,o),children:(0,W.jsx)(b,{className:`h-3.5 w-3.5`})})]})]}),(0,W.jsx)($,{id:`widget-title`,label:H(`engine.inspector.widget.title`,o),children:(0,W.jsx)(I,{id:`widget-title`,value:O.title??``,onChange:e=>A({title:e.target.value}),disabled:a})}),(0,W.jsx)($,{id:`widget-type`,label:H(`engine.inspector.widget.type`,o),children:(0,W.jsxs)(g,{value:O.type??`metric`,onValueChange:e=>A({type:e}),disabled:a,children:[(0,W.jsx)(D,{id:`widget-type`,children:(0,W.jsx)(w,{})}),(0,W.jsx)(F,{children:Re.map(e=>(0,W.jsx)(p,{value:e.value,children:e.label},e.value))})]})}),(0,W.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed border-primary/40 bg-primary/5 p-3`,children:[(0,W.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-primary/80`,children:H(`engine.inspector.widget.datasetSection`,o)}),(0,W.jsxs)($,{id:`widget-dataset`,label:H(`engine.inspector.widget.dataset`,o),children:[(0,W.jsx)(G,{value:d,onCommit:e=>A({dataset:e||void 0}),options:ee,loading:_.loading,placeholder:H(`engine.inspector.widget.datasetPlaceholder`,o),searchPlaceholder:H(`engine.inspector.widget.datasetPlaceholder`,o),disabled:a,mono:!0}),(0,W.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:H(`engine.inspector.widget.datasetHint`,o)})]}),d&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(V,{label:H(`engine.inspector.widget.dimensions`,o),emptyText:H(`engine.inspector.widget.dimensionsHint`,o),names:m,options:E,loading:v.loading,error:v.error,readOnly:a,onCommit:e=>A({dimensions:e})}),(0,W.jsx)(V,{label:H(`engine.inspector.widget.values`,o),emptyText:H(`engine.inspector.widget.valuesHint`,o),names:h,options:T,loading:v.loading,error:v.error,readOnly:a,onCommit:e=>A({values:e})})]})]}),(0,W.jsx)($,{id:`widget-object`,label:H(`engine.inspector.widget.object`,o),children:(0,W.jsx)(G,{value:O.object??``,onCommit:e=>A({object:e||void 0}),options:te,loading:x,placeholder:`Select an object…`,searchPlaceholder:`Search objects…`,disabled:a,mono:!0})}),(0,W.jsx)($,{id:`widget-value-field`,label:H(`engine.inspector.widget.valueField`,o),children:(0,W.jsx)(G,{value:O.valueField??``,onCommit:e=>A({valueField:e||void 0}),options:C,placeholder:O.object?`Select a field…`:`e.g. amount`,searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),(0,W.jsx)($,{id:`widget-category-field`,label:H(`engine.inspector.widget.categoryField`,o),children:(0,W.jsx)(G,{value:O.categoryField??``,onCommit:e=>A({categoryField:e||void 0}),options:C,placeholder:O.object?`Select a field…`:`e.g. status`,searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),(0,W.jsx)($,{id:`widget-aggregate`,label:H(`engine.inspector.widget.aggregate`,o),children:(0,W.jsxs)(g,{value:O.aggregate??`count`,onValueChange:e=>A({aggregate:e}),disabled:a,children:[(0,W.jsx)(D,{id:`widget-aggregate`,children:(0,W.jsx)(w,{})}),(0,W.jsx)(F,{children:ze.map(e=>(0,W.jsx)(p,{value:e,children:e},e))})]})}),(0,W.jsx)($,{id:`widget-color`,label:H(`engine.inspector.widget.color`,o),children:(0,W.jsx)(de,{value:O.colorVariant??`default`,onChange:e=>A({colorVariant:e}),disabled:a,options:Be.map(e=>({value:e}))})}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,W.jsx)($,{id:`widget-w`,label:H(`engine.inspector.widget.width`,o),children:(0,W.jsx)(I,{id:`widget-w`,type:`number`,min:1,value:O.layout?.w??1,onChange:e=>A({layout:{...O.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,W.jsx)($,{id:`widget-h`,label:H(`engine.inspector.widget.height`,o),children:(0,W.jsx)(I,{id:`widget-h`,type:`number`,min:1,value:O.layout?.h??1,onChange:e=>A({layout:{...O.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,W.jsx)(`div`,{className:`pt-2 border-t`,children:(0,W.jsx)(L,{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(k,1),n({widgets:t}),r()},children:H(`engine.inspector.widget.remove`,o)})})]})}function $({id:e,label:t,children:n}){return(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(A,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function Ue({message:e,onClose:t,locale:n}){return(0,W.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[(0,W.jsx)(`p`,{children:e}),(0,W.jsx)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:H(`engine.inspector.widget.close`,n)})]})}export{Se as a,we as c,X as i,G as l,Le as n,Te as o,Ae as r,Ee as s,He as t};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{U as r,f as i,v as a}from"./vendor-objectstack-Bw0HRuFa.js";import{$o as o,Ba as s,Bn as c,Fn as l,Gs as u,Is as d,Js as f,Jt as p,Kr as m,Ks as h,Kt as g,Ln as _,Oc as v,Oi as y,Or as b,Qs as x,Rn as S,Us as ee,Vn as te,Xs as C,Xt as w,Yi as T,Ys as E,Yt as D,an as O,ar as k,dn as A,ds as j,fo as ne,go as re,ii as ie,in as M,kc as N,ns as ae,on as P,qt as F,sn as I,xr as L,zn as oe}from"./ui-components-rkvkkTxO.js";import{r as R}from"./useMetadata-Ily0JuNR.js";import{F as se,I as ce,M as z,N as le,P as B,W as ue,_ as de,a as fe,g as pe,i as me,j as he,k as ge,p as _e,r as ve,t as V,y as H}from"./ReportDefaultInspector-CJGXWwWN.js";var U=e(n(),1),W=t();function ye(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 G({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:u,allowCustom:f=!0,mono:p,className:m}){let[h,g]=U.useState(!1),[v,y]=U.useState(``),b=r.find(e=>e.value===t),x=b?b.label:t||(u?`Loading…`:i),C=U.useMemo(()=>r.filter(e=>ye(e,v)),[r,v]),w=U.useMemo(()=>{let e=[],t=new Map;for(let n of C){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)}))},[C]),T=v.trim(),E=f&&!!T&&!r.some(e=>e.value===T),D=e=>{n(e),g(!1),y(``)},k=(0,W.jsxs)(M,{open:h,onOpenChange:e=>{g(e),e||y(``)},children:[(0,W.jsx)(P,{asChild:!0,children:(0,W.jsxs)(L,{type:`button`,variant:`outline`,role:`combobox`,"aria-expanded":h,disabled:s,className:N(`h-8 w-full justify-between px-2 text-sm font-normal`,m),children:[(0,W.jsx)(`span`,{className:N(`truncate`,p&&`font-mono`,!b&&!t&&`text-muted-foreground`),children:x}),(0,W.jsx)(d,{className:`ml-2 h-3.5 w-3.5 shrink-0 opacity-50`})]})}),(0,W.jsx)(O,{align:`start`,className:`w-[var(--radix-popover-trigger-width)] min-w-[14rem] p-0`,children:(0,W.jsxs)(l,{shouldFilter:!1,children:[(0,W.jsx)(oe,{value:v,onValueChange:y,placeholder:a}),(0,W.jsxs)(te,{children:[!E&&C.length===0&&(0,W.jsx)(_,{children:o}),E&&(0,W.jsx)(S,{children:(0,W.jsx)(c,{value:`__custom__${T}`,onSelect:()=>D(T),children:(0,W.jsxs)(`span`,{className:`truncate`,children:[`Use `,(0,W.jsxs)(`span`,{className:`font-mono`,children:[`“`,T,`”`]})]})})}),w.map((e,n)=>(0,W.jsx)(S,{heading:e.heading||void 0,children:e.items.map(e=>(0,W.jsxs)(c,{value:e.value,onSelect:()=>D(e.value),children:[(0,W.jsx)(ee,{className:N(`h-3.5 w-3.5`,e.value===t?`opacity-100`:`opacity-0`)}),(0,W.jsx)(`span`,{className:`truncate font-mono`,children:e.value}),e.label&&e.label!==e.value&&(0,W.jsx)(`span`,{className:`ml-1 truncate text-muted-foreground`,children:e.label}),e.hint&&(0,W.jsx)(`span`,{className:`ml-auto pl-2 text-[10px] text-muted-foreground`,children:e.hint})]},e.value))},e.heading||`g${n}`))]})]})})]});return e?(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsx)(A,{className:`text-xs text-muted-foreground`,children:e}),k]}):k}var be=new Set([`lookup`,`master_detail`,`masterdetail`,`master-detail`]);function K(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 xe(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 Se(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 q(e,t){if(!e)return{label:t,fields:[],relationships:[]};let n=K(e.label,t),r=ue(e.fields).entries.map(e=>({name:e.name,label:K(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&&be.has(e.type.toLowerCase())).map(e=>({name:e.name,label:e.label,referenceTo:xe(e.def)}))}}function J(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 Ce(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=J(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 Y(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e))return e.some(e=>Y(e,t));let n=e;return typeof n.dataset==`string`&&n.dataset===t?!0:Object.values(n).some(e=>e&&typeof e==`object`&&Y(e,t))}function we(){let e=R(),[t,n]=U.useState({options:[],loading:!0});return U.useEffect(()=>{let t=!1;return n(e=>({...e,loading:!0})),e.list(`object`).then(e=>{if(t)return;let r=(Array.isArray(e)?e:[]).map(e=>({name:typeof e.name==`string`?e.name:``,label:K(e.label,typeof e.name==`string`?e.name:``)})).filter(e=>!!e.name).sort((e,t)=>e.label.localeCompare(t.label));n({options:r,loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function Te(e,t){let n=R(),r=t.join(`\0`),[i,a]=U.useState({relationships:[],fieldOptions:[],loading:!!e});return U.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=q(i,e),s=r?r.split(`\0`):[],c={[e]:o},l=async e=>{if(c[e])return c[e];let t;try{t=q(await n.get(`object`,e),e)}catch{t=q(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=J(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:Ce(o,s,c),loading:!1})}catch{t||a({relationships:[],fieldOptions:[],loading:!1})}})(),()=>{t=!0}},[n,e,r]),i}function Ee(e){let t=R(),[n,r]=U.useState({reports:0,dashboards:0,loading:!!e});return U.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=>Y(t,e)).length,dashboards:(Array.isArray(a)?a:[]).filter(t=>Y(t,e)).length,loading:!1})})(),()=>{n=!0}},[t,e]),n}var X={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:ne},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:E},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:f},line:{id:`line`,label:`Line chart`,category:`chart`,icon:C},area:{id:`area`,label:`Area chart`,category:`chart`,icon:x},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:h},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:o},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:u},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:m},table:{id:`table`,label:`Data table`,category:`data`,icon:ie},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:ae},list:{id:`list`,label:`Record list`,category:`data`,icon:s},custom:{id:`custom`,label:`Custom widget`,category:`custom`,icon:j}},De={kpi:`Single value`,chart:`Charts`,data:`Tabular`,custom:`Custom`},Oe=[`kpi`,`chart`,`data`,`custom`].map(e=>({category:e,types:Object.values(X).filter(t=>t.category===e)})),ke=v;function Ae({onAdd:e,label:t=`Add widget`}){let[n,r]=U.useState(!1),[i,a]=U.useState(``),o=U.useRef(null),s=U.useMemo(()=>{let e=i.trim().toLowerCase();return e?Oe.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):Oe},[i]);return(0,W.jsxs)(M,{open:n,onOpenChange:e=>{r(e),e||a(``)},children:[(0,W.jsx)(P,{asChild:!0,children:(0,W.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`,children:[(0,W.jsx)(T,{className:`h-3 w-3`}),t]})}),(0,W.jsxs)(O,{align:`end`,sideOffset:4,className:`w-72 p-0`,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,W.jsx)(y,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,W.jsx)(`input`,{ref:o,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,W.jsx)(`div`,{className:`max-h-72 overflow-auto py-1`,children:s.length===0?(0,W.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No matches.`}):s.map(t=>(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:De[t.category]}),t.types.map(t=>(0,W.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,W.jsx)(X[t.id]?.icon??ke,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,W.jsx)(`span`,{className:`font-medium truncate`,children:t.label}),(0,W.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=U.useCallback(e=>H(e,r),[r]),s=typeof e.label==`string`?e.label:``,c=typeof e.description==`string`?e.description:``,l=U.useMemo(()=>Array.isArray(e.widgets)?e.widgets:[],[e.widgets]),u=e=>{let n=ce(`widget`,l.map(e=>e?.id).filter(Boolean)),r=X[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:n,type:e,title:a,...r?.defaults??{}};t({widgets:le(l,o)}),i?.({kind:`widget`,id:n,label:a})},d=e=>{t({widgets:se(l,e,null)})},f=(e,n)=>{e!==n&&t({widgets:B(l,e,n)})},p=(e,t)=>{e?.id&&i?.({kind:`widget`,id:e.id,label:e.title||e.id||`Widget ${t+1}`})},[m,h]=U.useState(null),[g,_]=U.useState(null),{schema:v,form:y}=U.useMemo(()=>fe({bundledSchema:Pe(),bundledForm:Fe(),serverSchema:a,excludeFields:Ie,sectionTitle:H(`engine.inspector.moreFields`,r)}),[a,r]);return(0,W.jsxs)(he,{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,W.jsx)(z,{label:o(`engine.inspector.dashboard.label`),value:s,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.dashboard.labelPlaceholder`),disabled:n}),(0,W.jsx)(z,{label:o(`engine.inspector.dashboard.description`),value:c,onCommit:e=>t({description:e}),placeholder:o(`engine.inspector.dashboard.descriptionPlaceholder`),disabled:n}),(0,W.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(A,{className:`text-xs text-muted-foreground`,children:o(`engine.inspector.dashboard.widgets`)}),(0,W.jsx)(k,{variant:`outline`,className:`text-[10px]`,children:l.length})]}),l.length===0?(0,W.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,W.jsx)(`div`,{className:`space-y-1`,children:l.map((e,t)=>{let r=X[e?.type]?.icon??ke;return(0,W.jsxs)(`div`,{draggable:!n,onDragStart:()=>h(t),onDragEnd:()=>{h(null),_(null)},onDragOver:e=>{e.preventDefault(),_(t)},onDrop:()=>{m!=null&&m!==t&&f(m,t),h(null),_(null)},className:`group flex items-center gap-2 rounded-md border px-2 py-1.5 text-xs hover:bg-accent`+(g===t&&m!==null&&m!==t?` border-primary`:``),children:[!n&&(0,W.jsx)(re,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground`}),(0,W.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,W.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 truncate text-left font-medium`,onClick:()=>p(e,t),title:e?.title||e?.id,children:e?.title||e?.id||`Widget ${t+1}`}),(0,W.jsx)(`code`,{className:`text-[10px] text-muted-foreground`,children:e?.type}),!n&&(0,W.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 shrink-0 p-0 opacity-0 group-hover:opacity-100`,onClick:()=>d(t),title:o(`engine.inspector.dashboard.removeWidget`),"aria-label":o(`engine.inspector.dashboard.removeWidget`),children:(0,W.jsx)(b,{className:`h-3.5 w-3.5`})})]},e?.id??t)})}),!n&&(0,W.jsx)(Ae,{onAdd:u,label:o(`engine.inspector.add.widget`)})]}),(0,W.jsx)(`div`,{className:`border-t pt-3`,children:v?(0,W.jsx)(_e,{schema:v,form:y,value:e,hiddenFields:[`name`,`label`,`description`,`widgets`],readOnly:n,onChange:e=>t(e)}):(0,W.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:[],c=t.kind===`widget`?t.id:void 0,l=c?Ve(e,c):null,u=l?.widget??{},d=typeof u.dataset==`string`?u.dataset:``,f=typeof u.object==`string`?u.object:``,m=Array.isArray(u.dimensions)?u.dimensions.filter(e=>typeof e==`string`):[],h=Array.isArray(u.values)?u.values.filter(e=>typeof e==`string`):[],_=ve(),v=me(d||void 0,_),{options:y,loading:x}=we(),{fields:S}=pe(f||void 0),ee=U.useMemo(()=>{let e=_.datasets.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return d&&!e.some(e=>e.value===d)&&e.push({value:d,label:d}),e},[_.datasets,d]),te=U.useMemo(()=>y.map(e=>({value:e.name,label:e.label})),[y]),C=U.useMemo(()=>S.map(e=>({value:e.name,label:e.label,hint:e.type})),[S]),T=U.useMemo(()=>v.measures.map(e=>({name:e.name,label:e.aggregate?`${e.name} · ${e.aggregate}`:e.name,type:`number`,hidden:!1})),[v.measures]),E=U.useMemo(()=>v.dimensions.map(e=>({name:e.name,label:e.name,type:e.type??`text`,hidden:!1})),[v.dimensions]);if(t.kind!==`widget`)return(0,W.jsx)(Ue,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});if(!l)return(0,W.jsx)(Ue,{message:`The selected widget was removed from the draft.`,onClose:r,locale:o});let{widget:O,index:k}=l;function A(e){let t=[...s];t[k]={...t[k],...e},n({widgets:t})}function j(e){n({widgets:B(s,k,e)}),O.id&&i?.({kind:`widget`,id:O.id,label:O.title??void 0})}return(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:H(`engine.inspector.widget.kind`,o)}),(0,W.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:O.title||t.label||`Widget ${k+1}`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,W.jsx)(ge,{index:k,total:s.length,onMove:j,upLabel:H(`engine.inspector.reorder.up`,o),downLabel:H(`engine.inspector.reorder.down`,o),disabled:a}),(0,W.jsx)(L,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:H(`engine.inspector.widget.close`,o),"aria-label":H(`engine.inspector.widget.close`,o),children:(0,W.jsx)(b,{className:`h-3.5 w-3.5`})})]})]}),(0,W.jsx)($,{id:`widget-title`,label:H(`engine.inspector.widget.title`,o),children:(0,W.jsx)(I,{id:`widget-title`,value:O.title??``,onChange:e=>A({title:e.target.value}),disabled:a})}),(0,W.jsx)($,{id:`widget-type`,label:H(`engine.inspector.widget.type`,o),children:(0,W.jsxs)(g,{value:O.type??`metric`,onValueChange:e=>A({type:e}),disabled:a,children:[(0,W.jsx)(D,{id:`widget-type`,children:(0,W.jsx)(w,{})}),(0,W.jsx)(F,{children:Re.map(e=>(0,W.jsx)(p,{value:e.value,children:e.label},e.value))})]})}),(0,W.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed border-primary/40 bg-primary/5 p-3`,children:[(0,W.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-primary/80`,children:H(`engine.inspector.widget.datasetSection`,o)}),(0,W.jsxs)($,{id:`widget-dataset`,label:H(`engine.inspector.widget.dataset`,o),children:[(0,W.jsx)(G,{value:d,onCommit:e=>A({dataset:e||void 0}),options:ee,loading:_.loading,placeholder:H(`engine.inspector.widget.datasetPlaceholder`,o),searchPlaceholder:H(`engine.inspector.widget.datasetPlaceholder`,o),disabled:a,mono:!0}),(0,W.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:H(`engine.inspector.widget.datasetHint`,o)})]}),d&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(V,{label:H(`engine.inspector.widget.dimensions`,o),emptyText:H(`engine.inspector.widget.dimensionsHint`,o),names:m,options:E,loading:v.loading,error:v.error,readOnly:a,onCommit:e=>A({dimensions:e})}),(0,W.jsx)(V,{label:H(`engine.inspector.widget.values`,o),emptyText:H(`engine.inspector.widget.valuesHint`,o),names:h,options:T,loading:v.loading,error:v.error,readOnly:a,onCommit:e=>A({values:e})})]})]}),(0,W.jsx)($,{id:`widget-object`,label:H(`engine.inspector.widget.object`,o),children:(0,W.jsx)(G,{value:O.object??``,onCommit:e=>A({object:e||void 0}),options:te,loading:x,placeholder:`Select an object…`,searchPlaceholder:`Search objects…`,disabled:a,mono:!0})}),(0,W.jsx)($,{id:`widget-value-field`,label:H(`engine.inspector.widget.valueField`,o),children:(0,W.jsx)(G,{value:O.valueField??``,onCommit:e=>A({valueField:e||void 0}),options:C,placeholder:O.object?`Select a field…`:`e.g. amount`,searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),(0,W.jsx)($,{id:`widget-category-field`,label:H(`engine.inspector.widget.categoryField`,o),children:(0,W.jsx)(G,{value:O.categoryField??``,onCommit:e=>A({categoryField:e||void 0}),options:C,placeholder:O.object?`Select a field…`:`e.g. status`,searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),(0,W.jsx)($,{id:`widget-aggregate`,label:H(`engine.inspector.widget.aggregate`,o),children:(0,W.jsxs)(g,{value:O.aggregate??`count`,onValueChange:e=>A({aggregate:e}),disabled:a,children:[(0,W.jsx)(D,{id:`widget-aggregate`,children:(0,W.jsx)(w,{})}),(0,W.jsx)(F,{children:ze.map(e=>(0,W.jsx)(p,{value:e,children:e},e))})]})}),(0,W.jsx)($,{id:`widget-color`,label:H(`engine.inspector.widget.color`,o),children:(0,W.jsx)(de,{value:O.colorVariant??`default`,onChange:e=>A({colorVariant:e}),disabled:a,options:Be.map(e=>({value:e}))})}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,W.jsx)($,{id:`widget-w`,label:H(`engine.inspector.widget.width`,o),children:(0,W.jsx)(I,{id:`widget-w`,type:`number`,min:1,value:O.layout?.w??1,onChange:e=>A({layout:{...O.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,W.jsx)($,{id:`widget-h`,label:H(`engine.inspector.widget.height`,o),children:(0,W.jsx)(I,{id:`widget-h`,type:`number`,min:1,value:O.layout?.h??1,onChange:e=>A({layout:{...O.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,W.jsx)(`div`,{className:`pt-2 border-t`,children:(0,W.jsx)(L,{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(k,1),n({widgets:t}),r()},children:H(`engine.inspector.widget.remove`,o)})})]})}function $({id:e,label:t,children:n}){return(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(A,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function Ue({message:e,onClose:t,locale:n}){return(0,W.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[(0,W.jsx)(`p`,{children:e}),(0,W.jsx)(L,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:H(`engine.inspector.widget.close`,n)})]})}export{Se as a,we as c,X as i,G as l,Le as n,Te as o,Ae as r,Ee as s,He as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{L as r}from"./framework-B3O15Lsq.js";import{$n as i,Ar as a,Bt as o,Ht as s,Ps as c,Rt as l,Ss as u,Ut as d,Vi as f,Vt as p,Wt as m,Zi as h,Zt as g,_t as _,ar as v,dn as y,er as b,ft as x,gs as S,gt as C,ht as w,js as T,mt as E,nr as D,pt as O,rr as k,sn as A,st as j,tr as M,vt as N,xr as P,za as F}from"./ui-components-rkvkkTxO.js";import"./src-6xqJEeiC.js";var I=e(n(),1),L=t();function R({status:e}){let t={success:{icon:T,cls:`text-emerald-600 border-emerald-300`},completed:{icon:T,cls:`text-emerald-600 border-emerald-300`},failed:{icon:u,cls:`text-red-600 border-red-300`},error:{icon:u,cls:`text-red-600 border-red-300`},running:{icon:F,cls:`text-blue-600 border-blue-300 animate-pulse`},pending:{icon:S,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)(v,{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)([]),[o,s]=(0,I.useState)(!0),[c,u]=(0,I.useState)(null),[d,p]=(0,I.useState)(``),[m,h]=(0,I.useState)(0),g=(0,I.useCallback)(async()=>{if(!e?.meta?.getItems){u(`meta.getItems is not available on this client`),s(!1);return}s(!0),u(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),!d&&r.length>0&&p(r[0].name)}catch(e){u(e?.message??String(e))}finally{s(!1)}},[e,d]);(0,I.useEffect)(()=>{g()},[g]);let _=(0,I.useMemo)(()=>t.find(e=>e.name===d)??null,[t,d]);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)(a,{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)(i,{children:[(0,L.jsx)(D,{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)(k,{className:`text-base`,children:`Flow`}),(0,L.jsx)(M,{children:`Select a flow definition to test`})]}),(0,L.jsxs)(P,{variant:`outline`,size:`sm`,onClick:g,disabled:o,children:[(0,L.jsx)(f,{className:`h-3.5 w-3.5 mr-2 ${o?`animate-spin`:``}`}),`Refresh`]})]})}),(0,L.jsxs)(b,{children:[o&&(0,L.jsx)(l,{className:`h-9 w-72`}),c&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:c}),!o&&!c&&t.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No flow definitions found.`}),!o&&!c&&t.length>0&&(0,L.jsx)(`select`,{value:d,onChange:e=>p(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))})]})]}),_&&(0,L.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,L.jsx)(U,{client:e,flow:_.spec,onExecuted:()=>h(e=>e+1)}),(0,L.jsx)(W,{client:e,flowName:_.name,refreshKey:m})]})]})}function U({client:e,flow:t,onExecuted:n}){let r=(0,I.useMemo)(()=>(t?.variables??[]).filter(e=>e?.isInput),[t]),[a,o]=(0,I.useState)({}),[s,c]=(0,I.useState)(!1),[l,d]=(0,I.useState)(null),[f,p]=(0,I.useState)(null);(0,I.useEffect)(()=>{o({}),d(null),p(null)},[t?.name]);let m=(e,t)=>o(n=>({...n,[e]:t}));return(0,L.jsxs)(i,{children:[(0,L.jsxs)(D,{className:`pb-3`,children:[(0,L.jsx)(k,{className:`text-base`,children:`Test Run`}),(0,L.jsx)(M,{children:`Provide input values and invoke the flow`})]}),(0,L.jsxs)(b,{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)(y,{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)(v,{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)(N,{id:`var-${e.name}`,checked:a[e.name]===`true`,onCheckedChange:t=>m(e.name,t?`true`:`false`)}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a[e.name]===`true`?`true`:`false`})]}):e.type===`object`||e.type===`list`||e.type===`array`?(0,L.jsx)(j,{id:`var-${e.name}`,placeholder:`JSON ${e.type}`,value:a[e.name]??``,onChange:t=>m(e.name,t.target.value),className:`font-mono text-xs min-h-[80px]`}):(0,L.jsx)(A,{id:`var-${e.name}`,type:e.type===`number`?`number`:`text`,value:a[e.name]??``,onChange:t=>m(e.name,t.target.value)})]},e.name)),(0,L.jsx)(`div`,{className:`pt-1`,children:(0,L.jsxs)(P,{onClick:async()=>{if(!e?.automation?.execute){p(`automation.execute is not available on this client`);return}c(!0),p(null),d(null);try{let i={};for(let e of r){let t=a[e.name];t!==void 0&&(i[e.name]=B(t,e.type))}let o=await e.automation.execute(t.name,{params:i});d(o),n?.()}catch(e){p(e?.message??String(e))}finally{c(!1)}},disabled:s,size:`sm`,children:[s?(0,L.jsx)(F,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(h,{className:`h-3.5 w-3.5 mr-2`}),s?`Running…`:`Run Flow`]})}),(l||f)&&(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:[f||l?.success===!1?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(u,{className:`h-4 w-4 text-red-500`}),` Failed`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(T,{className:`h-4 w-4 text-emerald-500`}),` Result`]}),typeof l?.durationMs==`number`&&(0,L.jsxs)(v,{variant:`secondary`,className:`text-[10px] font-mono`,children:[l.durationMs,` ms`]})]}),f&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:f}),l&&(0,L.jsx)(V,{data:l})]})]})]})}function W({client:e,flowName:t,refreshKey:n}){let[r,a]=(0,I.useState)([]),[c,u]=(0,I.useState)(!0),[h,y]=(0,I.useState)(null),[S,T]=(0,I.useState)(null),[A,j]=(0,I.useState)(null),[N,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`),u(!1);return}u(!0),y(null);try{let n=await e.automation.listRuns(t,{limit:20}),r=Array.isArray(n)?n:n?.items??n?.runs??[];a(r)}catch(e){y(e?.message??String(e))}finally{u(!1)}},[e,t]);(0,I.useEffect)(()=>{W()},[W,n]);let G=async n=>{T(n),j(null),U(null),B(!0);try{let r=await e.automation.getRun(t,n);j(r?.run??r)}catch(e){U(e?.message??String(e))}finally{B(!1)}};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(i,{children:[(0,L.jsx)(D,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(k,{className:`text-base`,children:`Recent Runs`}),(0,L.jsx)(M,{className:`font-mono text-xs`,children:t})]}),(0,L.jsxs)(P,{variant:`outline`,size:`sm`,onClick:W,disabled:c,children:[c?(0,L.jsx)(F,{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)(b,{children:[c&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(l,{className:`h-8 w-full`}),(0,L.jsx)(l,{className:`h-8 w-full`}),(0,L.jsx)(l,{className:`h-8 w-full`})]}),!c&&h&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:h}),!c&&!h&&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&&!h&&r.length>0&&(0,L.jsxs)(x,{children:[(0,L.jsx)(C,{children:(0,L.jsxs)(_,{children:[(0,L.jsx)(w,{children:`Run`}),(0,L.jsx)(w,{children:`Status`}),(0,L.jsx)(w,{children:`Started`}),(0,L.jsx)(w,{className:`text-right`,children:`Duration`})]})}),(0,L.jsx)(O,{children:r.map(e=>(0,L.jsxs)(_,{className:`cursor-pointer`,onClick:()=>G(e.id),children:[(0,L.jsxs)(E,{className:`font-mono text-xs`,children:[e.id.slice(0,12),`…`]}),(0,L.jsx)(E,{children:(0,L.jsx)(R,{status:e.status})}),(0,L.jsx)(E,{className:`text-xs text-muted-foreground`,children:z(e.startedAt)}),(0,L.jsx)(E,{className:`text-right font-mono text-xs`,children:typeof e.durationMs==`number`?`${e.durationMs} ms`:`—`})]},e.id))})]})]})]}),(0,L.jsx)(o,{open:!!S,onOpenChange:e=>{e||(T(null),j(null))},children:(0,L.jsxs)(p,{side:`right`,className:`w-full sm:max-w-2xl p-0 flex flex-col`,children:[(0,L.jsxs)(d,{className:`p-4 border-b`,children:[(0,L.jsxs)(m,{className:`font-mono text-sm break-all`,children:[`Run `,S]}),(0,L.jsx)(s,{children:A&&(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(R,{status:A.status}),typeof A.durationMs==`number`&&(0,L.jsxs)(v,{variant:`secondary`,className:`text-[10px] font-mono`,children:[A.durationMs,` ms`]}),(0,L.jsx)(`span`,{className:`text-xs`,children:z(A.startedAt)})]})})]}),(0,L.jsxs)(g,{className:`flex-1 p-4`,children:[N&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(l,{className:`h-16 w-full`}),(0,L.jsx)(l,{className:`h-16 w-full`}),(0,L.jsx)(l,{className:`h-16 w-full`})]}),H&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:H}),!N&&A&&(0,L.jsx)(`div`,{className:`space-y-3`,children:Array.isArray(A.steps)&&A.steps.length>0?A.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)(v,{variant:`outline`,className:`text-[10px] font-mono`,children:e.nodeType}),(0,L.jsx)(R,{status:e.status}),typeof e.durationMs==`number`&&(0,L.jsxs)(v,{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:A})]})})]})]})})]})}export{H as FlowRunsPage};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{r as t,y as n}from"./vendor-react-BGDDiZfJ.js";import{L as r}from"./framework-B3O15Lsq.js";import{$n as i,Ar as a,Bt as o,Ht as s,Ps as c,Rt as l,Ss as u,Ut as d,Vi as f,Vt as p,Wt as m,Zi as h,Zt as g,_t as _,ar as v,dn as y,er as b,ft as x,gs as S,gt as C,ht as w,js as T,mt as E,nr as D,pt as O,rr as k,sn as A,st as j,tr as M,vt as N,xr as P,za as F}from"./ui-components-rkvkkTxO.js";import"./src-BBieSqPB.js";var I=e(n(),1),L=t();function R({status:e}){let t={success:{icon:T,cls:`text-emerald-600 border-emerald-300`},completed:{icon:T,cls:`text-emerald-600 border-emerald-300`},failed:{icon:u,cls:`text-red-600 border-red-300`},error:{icon:u,cls:`text-red-600 border-red-300`},running:{icon:F,cls:`text-blue-600 border-blue-300 animate-pulse`},pending:{icon:S,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)(v,{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)([]),[o,s]=(0,I.useState)(!0),[c,u]=(0,I.useState)(null),[d,p]=(0,I.useState)(``),[m,h]=(0,I.useState)(0),g=(0,I.useCallback)(async()=>{if(!e?.meta?.getItems){u(`meta.getItems is not available on this client`),s(!1);return}s(!0),u(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),!d&&r.length>0&&p(r[0].name)}catch(e){u(e?.message??String(e))}finally{s(!1)}},[e,d]);(0,I.useEffect)(()=>{g()},[g]);let _=(0,I.useMemo)(()=>t.find(e=>e.name===d)??null,[t,d]);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)(a,{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)(i,{children:[(0,L.jsx)(D,{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)(k,{className:`text-base`,children:`Flow`}),(0,L.jsx)(M,{children:`Select a flow definition to test`})]}),(0,L.jsxs)(P,{variant:`outline`,size:`sm`,onClick:g,disabled:o,children:[(0,L.jsx)(f,{className:`h-3.5 w-3.5 mr-2 ${o?`animate-spin`:``}`}),`Refresh`]})]})}),(0,L.jsxs)(b,{children:[o&&(0,L.jsx)(l,{className:`h-9 w-72`}),c&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:c}),!o&&!c&&t.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No flow definitions found.`}),!o&&!c&&t.length>0&&(0,L.jsx)(`select`,{value:d,onChange:e=>p(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))})]})]}),_&&(0,L.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,L.jsx)(U,{client:e,flow:_.spec,onExecuted:()=>h(e=>e+1)}),(0,L.jsx)(W,{client:e,flowName:_.name,refreshKey:m})]})]})}function U({client:e,flow:t,onExecuted:n}){let r=(0,I.useMemo)(()=>(t?.variables??[]).filter(e=>e?.isInput),[t]),[a,o]=(0,I.useState)({}),[s,c]=(0,I.useState)(!1),[l,d]=(0,I.useState)(null),[f,p]=(0,I.useState)(null);(0,I.useEffect)(()=>{o({}),d(null),p(null)},[t?.name]);let m=(e,t)=>o(n=>({...n,[e]:t}));return(0,L.jsxs)(i,{children:[(0,L.jsxs)(D,{className:`pb-3`,children:[(0,L.jsx)(k,{className:`text-base`,children:`Test Run`}),(0,L.jsx)(M,{children:`Provide input values and invoke the flow`})]}),(0,L.jsxs)(b,{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)(y,{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)(v,{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)(N,{id:`var-${e.name}`,checked:a[e.name]===`true`,onCheckedChange:t=>m(e.name,t?`true`:`false`)}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a[e.name]===`true`?`true`:`false`})]}):e.type===`object`||e.type===`list`||e.type===`array`?(0,L.jsx)(j,{id:`var-${e.name}`,placeholder:`JSON ${e.type}`,value:a[e.name]??``,onChange:t=>m(e.name,t.target.value),className:`font-mono text-xs min-h-[80px]`}):(0,L.jsx)(A,{id:`var-${e.name}`,type:e.type===`number`?`number`:`text`,value:a[e.name]??``,onChange:t=>m(e.name,t.target.value)})]},e.name)),(0,L.jsx)(`div`,{className:`pt-1`,children:(0,L.jsxs)(P,{onClick:async()=>{if(!e?.automation?.execute){p(`automation.execute is not available on this client`);return}c(!0),p(null),d(null);try{let i={};for(let e of r){let t=a[e.name];t!==void 0&&(i[e.name]=B(t,e.type))}let o=await e.automation.execute(t.name,{params:i});d(o),n?.()}catch(e){p(e?.message??String(e))}finally{c(!1)}},disabled:s,size:`sm`,children:[s?(0,L.jsx)(F,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(h,{className:`h-3.5 w-3.5 mr-2`}),s?`Running…`:`Run Flow`]})}),(l||f)&&(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:[f||l?.success===!1?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(u,{className:`h-4 w-4 text-red-500`}),` Failed`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(T,{className:`h-4 w-4 text-emerald-500`}),` Result`]}),typeof l?.durationMs==`number`&&(0,L.jsxs)(v,{variant:`secondary`,className:`text-[10px] font-mono`,children:[l.durationMs,` ms`]})]}),f&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:f}),l&&(0,L.jsx)(V,{data:l})]})]})]})}function W({client:e,flowName:t,refreshKey:n}){let[r,a]=(0,I.useState)([]),[c,u]=(0,I.useState)(!0),[h,y]=(0,I.useState)(null),[S,T]=(0,I.useState)(null),[A,j]=(0,I.useState)(null),[N,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`),u(!1);return}u(!0),y(null);try{let n=await e.automation.listRuns(t,{limit:20}),r=Array.isArray(n)?n:n?.items??n?.runs??[];a(r)}catch(e){y(e?.message??String(e))}finally{u(!1)}},[e,t]);(0,I.useEffect)(()=>{W()},[W,n]);let G=async n=>{T(n),j(null),U(null),B(!0);try{let r=await e.automation.getRun(t,n);j(r?.run??r)}catch(e){U(e?.message??String(e))}finally{B(!1)}};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(i,{children:[(0,L.jsx)(D,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(k,{className:`text-base`,children:`Recent Runs`}),(0,L.jsx)(M,{className:`font-mono text-xs`,children:t})]}),(0,L.jsxs)(P,{variant:`outline`,size:`sm`,onClick:W,disabled:c,children:[c?(0,L.jsx)(F,{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)(b,{children:[c&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(l,{className:`h-8 w-full`}),(0,L.jsx)(l,{className:`h-8 w-full`}),(0,L.jsx)(l,{className:`h-8 w-full`})]}),!c&&h&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:h}),!c&&!h&&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&&!h&&r.length>0&&(0,L.jsxs)(x,{children:[(0,L.jsx)(C,{children:(0,L.jsxs)(_,{children:[(0,L.jsx)(w,{children:`Run`}),(0,L.jsx)(w,{children:`Status`}),(0,L.jsx)(w,{children:`Started`}),(0,L.jsx)(w,{className:`text-right`,children:`Duration`})]})}),(0,L.jsx)(O,{children:r.map(e=>(0,L.jsxs)(_,{className:`cursor-pointer`,onClick:()=>G(e.id),children:[(0,L.jsxs)(E,{className:`font-mono text-xs`,children:[e.id.slice(0,12),`…`]}),(0,L.jsx)(E,{children:(0,L.jsx)(R,{status:e.status})}),(0,L.jsx)(E,{className:`text-xs text-muted-foreground`,children:z(e.startedAt)}),(0,L.jsx)(E,{className:`text-right font-mono text-xs`,children:typeof e.durationMs==`number`?`${e.durationMs} ms`:`—`})]},e.id))})]})]})]}),(0,L.jsx)(o,{open:!!S,onOpenChange:e=>{e||(T(null),j(null))},children:(0,L.jsxs)(p,{side:`right`,className:`w-full sm:max-w-2xl p-0 flex flex-col`,children:[(0,L.jsxs)(d,{className:`p-4 border-b`,children:[(0,L.jsxs)(m,{className:`font-mono text-sm break-all`,children:[`Run `,S]}),(0,L.jsx)(s,{children:A&&(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(R,{status:A.status}),typeof A.durationMs==`number`&&(0,L.jsxs)(v,{variant:`secondary`,className:`text-[10px] font-mono`,children:[A.durationMs,` ms`]}),(0,L.jsx)(`span`,{className:`text-xs`,children:z(A.startedAt)})]})})]}),(0,L.jsxs)(g,{className:`flex-1 p-4`,children:[N&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(l,{className:`h-16 w-full`}),(0,L.jsx)(l,{className:`h-16 w-full`}),(0,L.jsx)(l,{className:`h-16 w-full`})]}),H&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:H}),!N&&A&&(0,L.jsx)(`div`,{className:`space-y-3`,children:Array.isArray(A.steps)&&A.steps.length>0?A.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)(v,{variant:`outline`,className:`text-[10px] font-mono`,children:e.nodeType}),(0,L.jsx)(R,{status:e.status}),typeof e.durationMs==`number`&&(0,L.jsxs)(v,{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:A})]})})]})]})})]})}export{H as FlowRunsPage};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{f as t,h as n,r,y as i}from"./vendor-react-BGDDiZfJ.js";import{L as a,R as o,Y as s,l as c,q as l}from"./framework-B3O15Lsq.js";import{G as u,J as d,V as f,W as p,ns as m}from"./ui-components-rkvkkTxO.js";import"./MetadataProvider-BpQl3Bw2.js";import{t as h}from"./RecordDetailView-CzR6BAUv.js";import{l as g}from"./plugins-views-CibWNUsP.js";var _=e(i(),1),v=`uf_`;function y(e){let t={};return e.forEach((e,n)=>{if(n.startsWith(v)&&e!==``){let r=n.slice(3);t[r]=e.split(`,`).map(e=>{try{return decodeURIComponent(e)}catch{return e}})}}),Object.keys(t).length>0?t:void 0}function b(e,t){let n=new URLSearchParams(e);for(let[e,r]of Object.entries(t)){let t=v+e;r&&r.length>0?n.set(t,r.map(e=>encodeURIComponent(String(e))).join(`,`)):n.delete(t)}return n}var x=r();function S(e){return Array.isArray(e?.columns)&&e.columns.length>0}function C(e,t){let n=e?.listViews||e?.list_views||{},r=(t?[n[`${e?.name}.${t}`],n[t],...t==="default"||t===`list`?[e?.list]:[]]:[e?.list,...Object.values(n)]).filter(Boolean);return r.find(S)??r[0]}var w=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]);function T(e){let t=e?.highlightFields;if(Array.isArray(t)&&t.length>0)return t.filter(t=>e.fields?.[t]);let n=e?.fields;return n&&typeof n==`object`?Object.entries(n).filter(([e,t])=>t&&!t.hidden&&!w.has(e)).map(([e])=>e).slice(0,6):[]}function E(e,t){let n=e?.fields;if(!(!n||typeof n!=`object`))return Object.entries(n).find(([e,n])=>n&&!n.hidden&&!w.has(e)&&t(e,n))?.[0]}var D=new Set([`select`,`multiselect`,`radio`,`enum`,`boolean`]),O=new Set([`date`,`datetime`,`time`]),k=new Set([`image`,`file`,`attachment`,`avatar`,`photo`]);function A(e){let t=E(e,(e,t)=>D.has(t.type))??E(e,e=>/status|stage|state|priority|category|kind/i.test(e));return t?{groupField:t,groupByField:t}:void 0}function j(e){return E(e,(e,t)=>O.has(t.type))??E(e,e=>/date|due|start|end|deadline|schedule/i.test(e))}function M(e){let t=j(e);return t?{startDateField:t}:void 0}function N(e){let t=E(e,(e,t)=>k.has(t.type));return t?{coverField:t}:void 0}var P=new Set([`location`,`geo`,`geolocation`,`geopoint`,`point`]);function F(e){let t=E(e,(e,t)=>O.has(t.type)&&/start|begin|kickoff/i.test(e))??E(e,(e,t)=>O.has(t.type));if(!t)return;let n=E(e,(e,n)=>O.has(n.type)&&e!==t&&/end|due|finish|deadline|close/i.test(e))??E(e,(e,n)=>O.has(n.type)&&e!==t);if(!n)return;let r=E(e,(e,t)=>(t.type===`number`||t.type===`percent`)&&/progress|percent|complete/i.test(e));return{startDateField:t,endDateField:n,...r?{progressField:r}:{}}}function I(e){let t=E(e,(e,t)=>P.has(t.type))??E(e,e=>/location|address|geo|coords?|place|venue/i.test(e));return t?{locationField:t}:void 0}function L({page:e,className:r,onConfigChange:i,reserveEditAffordance:v}){let{t:w}=c(),{objects:E}=o(),D=a(),O=t(),[k,j]=n(),[P]=_.useState(()=>y(new URLSearchParams(window.location.search))),L=_.useCallback(e=>{j(t=>b(t,e),{replace:!0})},[j]),R=e?.interfaceConfig||{},z=_.useMemo(()=>(E||[]).find(e=>e.name===R.source),[E,R.source]),B=_.useMemo(()=>C(z,R.sourceView),[z,R.sourceView]),V=R.recordAction===`page`||R.recordAction===`modal`||R.recordAction===`none`?R.recordAction:`drawer`,H=_.useCallback(e=>`/apps/${window.location.pathname.split(`/`)[2]||``}/${R.source}/record/${encodeURIComponent(String(e))}`,[R.source]),U=l({navigation:{mode:V===`none`?`none`:V},objectName:R.source,onNavigate:e=>O(H(e))}),W=k.get(`recordId`),G=_.useCallback((e,t)=>{if(V===`none`)return;let n=e?.id??e?._id;if(t&&(t.metaKey||t.ctrlKey||t.button===1)&&n!=null){window.open(H(n),`_blank`);return}if((V===`drawer`||V===`modal`)&&n!=null){j(e=>{let t=new URLSearchParams(e);return t.set(`recordId`,String(n)),t});return}U.handleClick(e,t)},[V,H,U,j]),ee=_.useCallback(()=>{j(e=>{let t=new URLSearchParams(e);return t.delete(`recordId`),t})},[j]);_.useEffect(()=>{W&&!U.isOpen?U.open({id:W}):!W&&U.isOpen&&U.close()},[W]);let K=z?.name,q=!!B&&!S(B),J=B?.name??(R.sourceView?`${R.source}.${R.sourceView}`:void 0),[Y,X]=_.useState(null);_.useEffect(()=>{let e=!1;if(X(null),!(!K||!R.source||!q||!J))return(async()=>{try{let t=D,n=null;typeof t?.listViewOverrides==`function`&&(n=(await t.listViewOverrides(R.source))?.[J]??null),!S(n)&&typeof t?.getView==`function`&&(n=await t.getView(R.source,J)),!e&&n&&typeof n==`object`&&X(n)}catch{}})(),()=>{e=!0}},[K,R.source,R.sourceView,q,J,D]);let Z=_.useMemo(()=>Y?{...B,...Y}:B,[B,Y]),te=JSON.stringify(Z??null),Q=_.useMemo(()=>{if(!z)return;let e=Z||{},t=R.appearance??e.appearance,n=t?.allowedVisualizations||[],r=new Set(n),i=R.userActions||{},a=e.kanban??(r.has(`kanban`)?A(z):void 0),o=e.calendar??(r.has(`calendar`)?M(z):void 0),s=e.timeline??(r.has(`timeline`)?M(z):void 0),c=e.gallery??(r.has(`gallery`)?N(z):void 0),l=e.gantt??(r.has(`gantt`)?F(z):void 0),u=e.options?.map??(r.has(`map`)?I(z):void 0),d=[...Array.isArray(e.filter)?e.filter:[],...Array.isArray(R.filterBy)?R.filterBy:[]],f=S(R)?R.columns:S(e)?e.columns:T(z),p=Array.isArray(R.sort)&&R.sort.length?R.sort:e.sort;return{type:`list-view`,objectName:z.name,viewType:n[0]??e.type??`grid`,fields:f,...d.length?{filters:d}:{},...p?.length?{sort:p}:{},grouping:e.grouping,rowColor:e.rowColor,pagination:e.pagination,searchableFields:e.searchableFields,emptyState:e.emptyState,kanban:a,calendar:o,gallery:c,timeline:s,gantt:l,...u||e.options?{options:{...e.options??{},...u?{map:u}:{}}}:{},userFilters:R.userFilters??e.userFilters,appearance:t,showViewSwitcher:n.length>1,showRecordCount:R.showRecordCount,addRecord:R.addRecord,showSearch:i.search!==!1,showSort:i.sort!==!1,showFilters:i.filter===!0,showDensity:i.rowHeight===!0,showHideFields:!1,showGroup:!1,showColor:!1,allowExport:!1,inlineEdit:i.editInline===!0}},[K,te,R]);if(!z||!Q)return(0,x.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,x.jsxs)(p,{children:[(0,x.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,x.jsx)(m,{className:`h-6 w-6 text-muted-foreground`})}),(0,x.jsx)(d,{children:w(`empty.objectNotFound`,{defaultValue:`Source object not found`})}),(0,x.jsx)(u,{children:w(`empty.interfacePageSourceMissing`,{defaultValue:`This interface page references "{{name}}", which is not available.`,name:R.source||`?`})})]})});let $=Array.isArray(R.buttons)&&R.buttons.length?R.buttons.map(e=>(z.actions||[]).find(t=>t?.name===e)).filter(Boolean).map(e=>({...e,locations:[`list_toolbar`]})):[];return(0,x.jsxs)(`div`,{className:r??`h-full flex flex-col`,"data-testid":`interface-list-page`,children:[(0,x.jsxs)(`div`,{className:`pl-4 pt-4 pb-2 shrink-0 flex items-start justify-between gap-3 ${v?`pr-12`:`pr-4`}`,children:[(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`h1`,{className:`text-lg font-semibold leading-tight`,children:typeof e.label==`string`?e.label:e.name}),typeof e.description==`string`&&e.description&&(0,x.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:e.description})]}),$.length>0&&(0,x.jsx)(`div`,{className:`shrink-0`,"data-testid":`interface-page-buttons`,children:(0,x.jsx)(s,{schema:{type:`action:bar`,location:`list_toolbar`,actions:$,size:`sm`,variant:`outline`}})})]}),(0,x.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:(0,x.jsx)(g,{schema:Q,dataSource:D,userFilterSelections:P,onUserFilterSelectionsChange:L,onSortChange:i?e=>i({sort:e}):void 0,onColumnStateChange:i?e=>{e?.order?.length&&i({columns:e.order})}:void 0,onRowClick:V===`none`?void 0:G})}),U.isOverlay&&(0,x.jsx)(f,{...U,setIsOpen:e=>{e||ee()},title:typeof e.label==`string`?e.label:R.source||`Record`,children:e=>(0,x.jsx)(h,{objectNameOverride:R.source,recordIdOverride:String(e?.id??e?._id??W??``),embedded:!0,dataSource:D,objects:E,onEdit:()=>{}})})]})}export{A as a,N as i,M as n,b as o,T as r,y as s,L as t};
1
+ import{o as e}from"./rolldown-runtime-DAXXjFlN.js";import{f as t,h as n,r,y as i}from"./vendor-react-BGDDiZfJ.js";import{L as a,R as o,Y as s,l as c,q as l}from"./framework-B3O15Lsq.js";import{G as u,J as d,V as f,W as p,ns as m}from"./ui-components-rkvkkTxO.js";import"./MetadataProvider-DKJsxrNu.js";import{t as h}from"./RecordDetailView-CzR6BAUv.js";import{l as g}from"./plugins-views-CibWNUsP.js";var _=e(i(),1),v=`uf_`;function y(e){let t={};return e.forEach((e,n)=>{if(n.startsWith(v)&&e!==``){let r=n.slice(3);t[r]=e.split(`,`).map(e=>{try{return decodeURIComponent(e)}catch{return e}})}}),Object.keys(t).length>0?t:void 0}function b(e,t){let n=new URLSearchParams(e);for(let[e,r]of Object.entries(t)){let t=v+e;r&&r.length>0?n.set(t,r.map(e=>encodeURIComponent(String(e))).join(`,`)):n.delete(t)}return n}var x=r();function S(e){return Array.isArray(e?.columns)&&e.columns.length>0}function C(e,t){let n=e?.listViews||e?.list_views||{},r=(t?[n[`${e?.name}.${t}`],n[t],...t==="default"||t===`list`?[e?.list]:[]]:[e?.list,...Object.values(n)]).filter(Boolean);return r.find(S)??r[0]}var w=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]);function T(e){let t=e?.highlightFields;if(Array.isArray(t)&&t.length>0)return t.filter(t=>e.fields?.[t]);let n=e?.fields;return n&&typeof n==`object`?Object.entries(n).filter(([e,t])=>t&&!t.hidden&&!w.has(e)).map(([e])=>e).slice(0,6):[]}function E(e,t){let n=e?.fields;if(!(!n||typeof n!=`object`))return Object.entries(n).find(([e,n])=>n&&!n.hidden&&!w.has(e)&&t(e,n))?.[0]}var D=new Set([`select`,`multiselect`,`radio`,`enum`,`boolean`]),O=new Set([`date`,`datetime`,`time`]),k=new Set([`image`,`file`,`attachment`,`avatar`,`photo`]);function A(e){let t=E(e,(e,t)=>D.has(t.type))??E(e,e=>/status|stage|state|priority|category|kind/i.test(e));return t?{groupField:t,groupByField:t}:void 0}function j(e){return E(e,(e,t)=>O.has(t.type))??E(e,e=>/date|due|start|end|deadline|schedule/i.test(e))}function M(e){let t=j(e);return t?{startDateField:t}:void 0}function N(e){let t=E(e,(e,t)=>k.has(t.type));return t?{coverField:t}:void 0}var P=new Set([`location`,`geo`,`geolocation`,`geopoint`,`point`]);function F(e){let t=E(e,(e,t)=>O.has(t.type)&&/start|begin|kickoff/i.test(e))??E(e,(e,t)=>O.has(t.type));if(!t)return;let n=E(e,(e,n)=>O.has(n.type)&&e!==t&&/end|due|finish|deadline|close/i.test(e))??E(e,(e,n)=>O.has(n.type)&&e!==t);if(!n)return;let r=E(e,(e,t)=>(t.type===`number`||t.type===`percent`)&&/progress|percent|complete/i.test(e));return{startDateField:t,endDateField:n,...r?{progressField:r}:{}}}function I(e){let t=E(e,(e,t)=>P.has(t.type))??E(e,e=>/location|address|geo|coords?|place|venue/i.test(e));return t?{locationField:t}:void 0}function L({page:e,className:r,onConfigChange:i,reserveEditAffordance:v}){let{t:w}=c(),{objects:E}=o(),D=a(),O=t(),[k,j]=n(),[P]=_.useState(()=>y(new URLSearchParams(window.location.search))),L=_.useCallback(e=>{j(t=>b(t,e),{replace:!0})},[j]),R=e?.interfaceConfig||{},z=_.useMemo(()=>(E||[]).find(e=>e.name===R.source),[E,R.source]),B=_.useMemo(()=>C(z,R.sourceView),[z,R.sourceView]),V=R.recordAction===`page`||R.recordAction===`modal`||R.recordAction===`none`?R.recordAction:`drawer`,H=_.useCallback(e=>`/apps/${window.location.pathname.split(`/`)[2]||``}/${R.source}/record/${encodeURIComponent(String(e))}`,[R.source]),U=l({navigation:{mode:V===`none`?`none`:V},objectName:R.source,onNavigate:e=>O(H(e))}),W=k.get(`recordId`),G=_.useCallback((e,t)=>{if(V===`none`)return;let n=e?.id??e?._id;if(t&&(t.metaKey||t.ctrlKey||t.button===1)&&n!=null){window.open(H(n),`_blank`);return}if((V===`drawer`||V===`modal`)&&n!=null){j(e=>{let t=new URLSearchParams(e);return t.set(`recordId`,String(n)),t});return}U.handleClick(e,t)},[V,H,U,j]),ee=_.useCallback(()=>{j(e=>{let t=new URLSearchParams(e);return t.delete(`recordId`),t})},[j]);_.useEffect(()=>{W&&!U.isOpen?U.open({id:W}):!W&&U.isOpen&&U.close()},[W]);let K=z?.name,q=!!B&&!S(B),J=B?.name??(R.sourceView?`${R.source}.${R.sourceView}`:void 0),[Y,X]=_.useState(null);_.useEffect(()=>{let e=!1;if(X(null),!(!K||!R.source||!q||!J))return(async()=>{try{let t=D,n=null;typeof t?.listViewOverrides==`function`&&(n=(await t.listViewOverrides(R.source))?.[J]??null),!S(n)&&typeof t?.getView==`function`&&(n=await t.getView(R.source,J)),!e&&n&&typeof n==`object`&&X(n)}catch{}})(),()=>{e=!0}},[K,R.source,R.sourceView,q,J,D]);let Z=_.useMemo(()=>Y?{...B,...Y}:B,[B,Y]),te=JSON.stringify(Z??null),Q=_.useMemo(()=>{if(!z)return;let e=Z||{},t=R.appearance??e.appearance,n=t?.allowedVisualizations||[],r=new Set(n),i=R.userActions||{},a=e.kanban??(r.has(`kanban`)?A(z):void 0),o=e.calendar??(r.has(`calendar`)?M(z):void 0),s=e.timeline??(r.has(`timeline`)?M(z):void 0),c=e.gallery??(r.has(`gallery`)?N(z):void 0),l=e.gantt??(r.has(`gantt`)?F(z):void 0),u=e.options?.map??(r.has(`map`)?I(z):void 0),d=[...Array.isArray(e.filter)?e.filter:[],...Array.isArray(R.filterBy)?R.filterBy:[]],f=S(R)?R.columns:S(e)?e.columns:T(z),p=Array.isArray(R.sort)&&R.sort.length?R.sort:e.sort;return{type:`list-view`,objectName:z.name,viewType:n[0]??e.type??`grid`,fields:f,...d.length?{filters:d}:{},...p?.length?{sort:p}:{},grouping:e.grouping,rowColor:e.rowColor,pagination:e.pagination,searchableFields:e.searchableFields,emptyState:e.emptyState,kanban:a,calendar:o,gallery:c,timeline:s,gantt:l,...u||e.options?{options:{...e.options??{},...u?{map:u}:{}}}:{},userFilters:R.userFilters??e.userFilters,appearance:t,showViewSwitcher:n.length>1,showRecordCount:R.showRecordCount,addRecord:R.addRecord,showSearch:i.search!==!1,showSort:i.sort!==!1,showFilters:i.filter===!0,showDensity:i.rowHeight===!0,showHideFields:!1,showGroup:!1,showColor:!1,allowExport:!1,inlineEdit:i.editInline===!0}},[K,te,R]);if(!z||!Q)return(0,x.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,x.jsxs)(p,{children:[(0,x.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,x.jsx)(m,{className:`h-6 w-6 text-muted-foreground`})}),(0,x.jsx)(d,{children:w(`empty.objectNotFound`,{defaultValue:`Source object not found`})}),(0,x.jsx)(u,{children:w(`empty.interfacePageSourceMissing`,{defaultValue:`This interface page references "{{name}}", which is not available.`,name:R.source||`?`})})]})});let $=Array.isArray(R.buttons)&&R.buttons.length?R.buttons.map(e=>(z.actions||[]).find(t=>t?.name===e)).filter(Boolean).map(e=>({...e,locations:[`list_toolbar`]})):[];return(0,x.jsxs)(`div`,{className:r??`h-full flex flex-col`,"data-testid":`interface-list-page`,children:[(0,x.jsxs)(`div`,{className:`pl-4 pt-4 pb-2 shrink-0 flex items-start justify-between gap-3 ${v?`pr-12`:`pr-4`}`,children:[(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`h1`,{className:`text-lg font-semibold leading-tight`,children:typeof e.label==`string`?e.label:e.name}),typeof e.description==`string`&&e.description&&(0,x.jsx)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:e.description})]}),$.length>0&&(0,x.jsx)(`div`,{className:`shrink-0`,"data-testid":`interface-page-buttons`,children:(0,x.jsx)(s,{schema:{type:`action:bar`,location:`list_toolbar`,actions:$,size:`sm`,variant:`outline`}})})]}),(0,x.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:(0,x.jsx)(g,{schema:Q,dataSource:D,userFilterSelections:P,onUserFilterSelectionsChange:L,onSortChange:i?e=>i({sort:e}):void 0,onColumnStateChange:i?e=>{e?.order?.length&&i({columns:e.order})}:void 0,onRowClick:V===`none`?void 0:G})}),U.isOverlay&&(0,x.jsx)(f,{...U,setIsOpen:e=>{e||ee()},title:typeof e.label==`string`?e.label:R.source||`Record`,children:e=>(0,x.jsx)(h,{objectNameOverride:R.source,recordIdOverride:String(e?.id??e?._id??W??``),embedded:!0,dataSource:D,objects:E,onEdit:()=>{}})})]})}export{A as a,N as i,M as n,b as o,T as r,y as s,L as t};
@@ -1,4 +1,4 @@
1
- import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{f as n,m as r,r as i,y as a}from"./vendor-react-BGDDiZfJ.js";import{d as ee}from"./infrastructure-Bcx6-8du.js";import{R as te,l as ne}from"./framework-B3O15Lsq.js";import{$n as re,Cc as ie,Ci as o,Do as ae,Gn as oe,Jn as se,Jo as ce,Jt as le,Kn as ue,Kt as de,Mr as s,Ns as fe,Ps as c,Qn as l,Qo as pe,Rt as u,Si as d,Un as me,Wn as he,Xt as ge,Yo as _e,Yt as ve,ar as f,dn as p,ds as m,er as ye,fn as be,ga as xe,hn as h,js as g,nr as Se,ns as Ce,oc as we,pn as Te,qn as Ee,qr as _,qt as De,rr as Oe,va as ke,xn as Ae,xr as v,za as y}from"./ui-components-rkvkkTxO.js";import"./MetadataProvider-BpQl3Bw2.js";import{n as je}from"./assistantBus-BFk4fCbM.js";import{_ as Me,a as Ne,c as Pe,g as Fe,h as Ie,i as Le,m as Re,o as ze,p as Be,r as b,s as Ve,t as He,u as Ue,x}from"./marketplaceApi-zYQofLEk.js";import{n as We,t as Ge}from"./usePackageL10n-CiFMHfKe.js";import{t as Ke}from"./MarketplaceAccessDenied-CAuxNcMw.js";var S=e(a(),1),C=i();function qe(e){let t=e.replace(/\r\n/g,`
1
+ import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{f as n,m as r,r as i,y as a}from"./vendor-react-BGDDiZfJ.js";import{d as ee}from"./infrastructure-Bcx6-8du.js";import{R as te,l as ne}from"./framework-B3O15Lsq.js";import{$n as re,Cc as ie,Ci as o,Do as ae,Gn as oe,Jn as se,Jo as ce,Jt as le,Kn as ue,Kt as de,Mr as s,Ns as fe,Ps as c,Qn as l,Qo as pe,Rt as u,Si as d,Un as me,Wn as he,Xt as ge,Yo as _e,Yt as ve,ar as f,dn as p,ds as m,er as ye,fn as be,ga as xe,hn as h,js as g,nr as Se,ns as Ce,oc as we,pn as Te,qn as Ee,qr as _,qt as De,rr as Oe,va as ke,xn as Ae,xr as v,za as y}from"./ui-components-rkvkkTxO.js";import"./MetadataProvider-DKJsxrNu.js";import{n as je}from"./assistantBus-BFk4fCbM.js";import{_ as Me,a as Ne,c as Pe,g as Fe,h as Ie,i as Le,m as Re,o as ze,p as Be,r as b,s as Ve,t as He,u as Ue,x}from"./marketplaceApi-zYQofLEk.js";import{n as We,t as Ge}from"./usePackageL10n-CiFMHfKe.js";import{t as Ke}from"./MarketplaceAccessDenied-CAuxNcMw.js";var S=e(a(),1),C=i();function qe(e){let t=e.replace(/\r\n/g,`
2
2
  `).split(`
3
3
  `),n=[],r=0;for(;r<t.length;){let e=t[r];if(e.startsWith("```")){let i=e.slice(3).trim();r++;let a=[];for(;r<t.length&&!t[r].startsWith("```");)a.push(t[r]),r++;r++,n.push({type:`code`,text:a.join(`
4
4
  `),lang:i});continue}let i=/^(#{1,3})\s+(.*)$/.exec(e);if(i){let e=i[1].length;n.push({type:`h${e}`,text:i[2].trim()}),r++;continue}if(/^[-*]\s+/.test(e)){let e=[];for(;r<t.length&&/^[-*]\s+/.test(t[r]);)e.push(t[r].replace(/^[-*]\s+/,``)),r++;n.push({type:`ul`,items:e});continue}if(/^\d+\.\s+/.test(e)){let e=[];for(;r<t.length&&/^\d+\.\s+/.test(t[r]);)e.push(t[r].replace(/^\d+\.\s+/,``)),r++;n.push({type:`ol`,items:e});continue}if(!e.trim()){r++;continue}let a=[];for(;r<t.length&&t[r].trim()&&!/^#{1,3}\s+/.test(t[r])&&!/^[-*]\s+/.test(t[r])&&!/^\d+\.\s+/.test(t[r])&&!t[r].startsWith("```");)a.push(t[r]),r++;n.push({type:`p`,text:a.join(` `)})}return n}function w(e){let t=[],n=e,r=0,i=[{re:/`([^`]+)`/,render:e=>(0,C.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[0.85em]`,children:e[1]},`k${r++}`)},{re:/\*\*([^*]+)\*\*/,render:e=>(0,C.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e[1]},`k${r++}`)},{re:/\*([^*]+)\*/,render:e=>(0,C.jsx)(`em`,{children:e[1]},`k${r++}`)},{re:/\[([^\]]+)\]\(([^)]+)\)/,render:e=>(0,C.jsx)(`a`,{href:e[2],target:`_blank`,rel:`noopener noreferrer`,className:`text-violet-600 underline-offset-2 hover:underline dark:text-violet-400`,children:e[1]},`k${r++}`)}];for(;n;){let e=-1,r=null,a=null;for(let t of i){let i=t.re.exec(n);i&&(e===-1||i.index<e)&&(e=i.index,r=i,a=t)}if(!r||!a){t.push(n);break}e>0&&t.push(n.slice(0,e)),t.push(a.render(r)),n=n.slice(e+r[0].length)}return(0,C.jsx)(C.Fragment,{children:t.map((e,t)=>(0,C.jsx)(S.Fragment,{children:e},t))})}function Je({source:e,className:t}){let n=qe(e);return(0,C.jsx)(`div`,{className:`flex flex-col gap-4 text-sm leading-relaxed text-foreground/90 ${t??``}`,children:n.map((e,t)=>{switch(e.type){case`h1`:return(0,C.jsx)(`h2`,{className:`mt-2 text-xl font-bold tracking-tight`,children:w(e.text??``)},t);case`h2`:return(0,C.jsx)(`h3`,{className:`mt-3 text-base font-semibold tracking-tight`,children:w(e.text??``)},t);case`h3`:return(0,C.jsx)(`h4`,{className:`mt-2 text-sm font-semibold tracking-tight text-foreground/80`,children:w(e.text??``)},t);case`p`:return(0,C.jsx)(`p`,{children:w(e.text??``)},t);case`ul`:return(0,C.jsx)(`ul`,{className:`ml-1 flex list-none flex-col gap-1.5`,children:(e.items??[]).map((e,t)=>(0,C.jsxs)(`li`,{className:`flex gap-2`,children:[(0,C.jsx)(`span`,{"aria-hidden":`true`,className:`mt-1.5 inline-block h-1.5 w-1.5 shrink-0 rounded-full bg-violet-500/70`}),(0,C.jsx)(`span`,{children:w(e)})]},t))},t);case`ol`:return(0,C.jsx)(`ol`,{className:`ml-5 flex list-decimal flex-col gap-1.5 marker:text-muted-foreground`,children:(e.items??[]).map((e,t)=>(0,C.jsx)(`li`,{className:`pl-1`,children:w(e)},t))},t);case`code`:return(0,C.jsx)(`pre`,{className:`overflow-x-auto rounded-lg border bg-muted/40 p-3 text-xs leading-relaxed`,children:(0,C.jsx)(`code`,{className:`font-mono`,children:e.text})},t)}return null})})}var T={node:`In-process · full trust`,sandbox:`Sandboxed`,worker:`Out-of-process`};function E({icon:e,label:t,items:n}){return!n||n.length===0?null:(0,C.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,C.jsx)(e,{className:`h-3.5 w-3.5 mt-0.5 text-muted-foreground shrink-0`,"aria-hidden":`true`}),(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsx)(`div`,{className:`text-xs font-medium`,children:t}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-0.5`,children:n.map(e=>(0,C.jsx)(`code`,{className:`font-mono text-[11px] px-1 py-0.5 rounded bg-muted break-all`,children:e},e))})]})]})}function Ye({version:e}){let{t}=ne();if(!e?.contains_code)return null;let n=e.permissions??{},r=(n.services?.length??0)+(n.hooks?.length??0)+(n.network?.length??0)+(n.fs?.length??0)>0;return(0,C.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-3 space-y-3 text-sm`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 font-medium`,children:[(0,C.jsx)(m,{className:`h-4 w-4 text-amber-600 shrink-0`,"aria-hidden":`true`}),t(`marketplace.disclosure.containsCode`,{defaultValue:`This package contains code`})]}),(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[e.runtime&&(0,C.jsx)(f,{variant:`outline`,children:t(`marketplace.disclosure.runtime.${e.runtime}`,{defaultValue:T[e.runtime]??e.runtime})}),e.platform_verified?(0,C.jsxs)(f,{variant:`outline`,className:`gap-1 border-green-500/40 text-green-700 dark:text-green-400`,children:[(0,C.jsx)(d,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.reviewed`,{defaultValue:`Reviewed & approved`})]}):(0,C.jsxs)(f,{variant:`outline`,className:`gap-1 border-amber-500/40 text-amber-700 dark:text-amber-400`,children:[(0,C.jsx)(o,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.unreviewed`,{defaultValue:`Not yet reviewed`})]}),e.signed&&(0,C.jsxs)(f,{variant:`outline`,className:`gap-1`,children:[(0,C.jsx)(g,{className:`h-3 w-3`,"aria-hidden":`true`}),t(`marketplace.disclosure.signed`,{defaultValue:`Signed`})]})]}),r?(0,C.jsxs)(`div`,{className:`space-y-2`,children:[(0,C.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t(`marketplace.disclosure.grantsIntro`,{defaultValue:`On install, this package will be granted:`})}),(0,C.jsx)(E,{icon:we,label:t(`marketplace.disclosure.services`,{defaultValue:`Platform services`}),items:n.services??void 0}),(0,C.jsx)(E,{icon:s,label:t(`marketplace.disclosure.hooks`,{defaultValue:`Lifecycle hooks`}),items:n.hooks??void 0}),(0,C.jsx)(E,{icon:ke,label:t(`marketplace.disclosure.network`,{defaultValue:`Network access`}),items:n.network??void 0}),(0,C.jsx)(E,{icon:ae,label:t(`marketplace.disclosure.fs`,{defaultValue:`Filesystem access`}),items:n.fs??void 0})]}):(0,C.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t(`marketplace.disclosure.noPermissions`,{defaultValue:`Requests no special permissions.`})})]})}var D=t({MarketplacePackagePage:()=>O});function O(){let e=n(),{packageId:t,appName:i}=r(),a=ee(),{t:o,language:ae}=ne(),s=i?`/apps/${i}`:``,{refresh:d}=te(),[m,we]=(0,S.useState)(null),[ke,qe]=(0,S.useState)(!0),[w,T]=(0,S.useState)(null),[E,D]=(0,S.useState)(!1),[O,Xe]=(0,S.useState)([]),[Ze,k]=(0,S.useState)(!1),[A,j]=(0,S.useState)(null),[M,N]=(0,S.useState)(``),[Qe,$e]=(0,S.useState)({}),[P,et]=(0,S.useState)(!1),[tt,nt]=(0,S.useState)(!1),[F,rt]=(0,S.useState)(!1),[I,L]=(0,S.useState)(null),[R,it]=(0,S.useState)(null),[z,B]=(0,S.useState)(null),[V,H]=(0,S.useState)(null),[U,W]=(0,S.useState)(null),[at,G]=(0,S.useState)([]),[K,q]=(0,S.useState)(!1),[J,Y]=(0,S.useState)(null);(0,S.useEffect)(()=>{if(!x().features.installLocal)return;let e=!1;return(async()=>{let t=await Ue();e||G(t)})(),()=>{e=!0}},[t,J]),(0,S.useEffect)(()=>{if(!t)return;let e=x().defaultEnvironmentId??``,n=!1;return(async()=>{let r=await b(t,e);n||!r||(B(r),it(r.version))})(),()=>{n=!0}},[t]),(0,S.useEffect)(()=>{let e=!1;return(async()=>{if(t){qe(!0),T(null);try{let n=await Le(t);e||we(n)}catch(t){e||T(t?.message??String(t))}finally{e||qe(!1)}}})(),()=>{e=!0}},[t]);let ot=async()=>{D(!0),L(null),j(null);let e=x().defaultEnvironmentId;if(e){k(!1),N(e),Xe([]);return}k(!0);try{let[e,n]=await Promise.all([Ve(),Pe()]),r=e.filter(e=>{let t=e.organization_id;return t?n.has(String(t)):!1});Xe(r),$e({});let i=t;i&&Promise.all(r.map(async e=>{try{let t=await b(i,e.id);return t?[e.id,t.version]:null}catch{return null}})).then(e=>{let t={};for(let n of e)n&&(t[n[0]]=n[1]);$e(t)}),e.length>0&&r.length===0?j(o(`marketplace.install.noPermission`)):r.length===1&&N(r[0].id)}catch(e){let t=e?.status;j(t===401||t===403?o(`marketplace.install.signInFirst`):e?.message??String(e))}finally{k(!1)}},st=async()=>{if(!(!t||!M)){rt(!0),L(null);try{let e=(await ze({packageId:t,environmentId:M,seedSampleData:P}))?.installation?.version??m?.package?.latest_version?.version??m?.versions?.[0]?.version??``;it(e||`installed`);try{let e=x().defaultEnvironmentId||M;if(e){let n=await b(t,e);n&&B(n)}}catch{}let n=x().defaultEnvironmentId;if(!n||n===M)try{if(typeof sessionStorage<`u`)for(let e of Object.keys(sessionStorage))e.startsWith(`objectui:metadata:`)&&sessionStorage.removeItem(e);await d()}catch{}L({ok:!0,message:o(`marketplace.install.success`)}),je()}catch(e){L({ok:!1,message:e?.message??String(e)})}finally{rt(!1)}}},ct=async()=>{if(t){q(!0),Y(null);try{let e=await Ne({packageId:t});try{await d(`app`)}catch{}Y({ok:!0,message:o(`marketplace.install.localSuccess`,{version:e.version,name:m?.package?Ge(m.package,ae).displayName:e.manifestId})}),je()}catch(e){let t=e?.code,n=e?.message??String(e);t===`manifest_conflict`?n=o(`marketplace.install.localManifestConflict`,{message:n}):t===`unauthorized`?n=o(`marketplace.install.localUnauthorized`):t===`marketplace_unavailable`&&(n=o(`marketplace.install.localMarketplaceUnavailable`)),Y({ok:!1,message:n})}finally{q(!1)}}},lt=async()=>{if($&&confirm(o(`marketplace.uninstall.confirm`,{manifestId:$.manifestId,version:$.version}))){q(!0),Y(null);try{await Me($.manifestId);try{await d(`app`)}catch{}Y({ok:!0,message:o(`marketplace.uninstall.successInDetail`,{manifestId:$.manifestId})})}catch(e){Y({ok:!1,message:e?.message??String(e)})}finally{q(!1)}}},ut=async()=>{if(z){H(`reseed`),W(null);try{let e=await Fe(z.installationId);e.ok?(B({...z,withSampleData:!0}),W({ok:!0,text:o(`marketplace.detail.reseedQueued`)||`Sample data will be re-seeded on next environment access.`})):W({ok:!1,text:e.error||`Re-seed failed`})}finally{H(null)}}},dt=async()=>{if(z&&confirm(o(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){H(`purge`),W(null);try{let e=await Re(z.installationId);if(e.ok){B({...z,withSampleData:!1});let t=e.deleted??0;W({ok:!0,text:t>0?o(`marketplace.detail.purgeSuccess`,{count:t})||`Removed ${t} sample record(s).`:o(`marketplace.detail.purgeNoData`)||`No sample records found to purge.`})}else W({ok:!1,text:e.error||`Purge failed`})}finally{H(null)}}},ft=async()=>{if($){H(`reseed`),W(null);try{let e=await Ie($.manifestId);G(e=>e.map(e=>e.manifestId===$.manifestId?{...e,withSampleData:!0}:e));let t=e.inserted??0,n=e.updated??0,r=e.errors??0,i=o(`marketplace.detail.reseedLocalSuccess`,{inserted:t,updated:n})||`Sample data re-seeded (inserted=${t}, updated=${n}).`;W(r>0?{ok:!1,text:`${i} ${o(`marketplace.detail.reseedPartialErrors`,{count:r})||`(${r} record(s) failed to write)`}`}:{ok:!0,text:i})}catch(e){W({ok:!1,text:e?.message||`Re-seed failed`})}finally{H(null)}}},pt=async()=>{if($&&confirm(o(`marketplace.detail.purgeConfirm`)||`Delete all sample records seeded by this package? User-added records will NOT be touched.`)){H(`purge`),W(null);try{let e=await Be($.manifestId);G(e=>e.map(e=>e.manifestId===$.manifestId?{...e,withSampleData:!1}:e));let t=e.deleted??0;W({ok:!0,text:t>0?o(`marketplace.detail.purgeSuccess`,{count:t})||`Removed ${t} sample record(s).`:o(`marketplace.detail.purgeNoData`)||`No sample records found to purge.`})}catch(e){W({ok:!1,text:e?.message||`Purge failed`})}finally{H(null)}}};if(ke)return(0,C.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,C.jsx)(u,{className:`h-8 w-32`}),(0,C.jsx)(u,{className:`h-16 w-full`}),(0,C.jsx)(u,{className:`h-64 w-full`})]});if(w||!m)return(0,C.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,C.jsxs)(v,{variant:`ghost`,size:`sm`,onClick:()=>e(`${s}/system/marketplace`),children:[(0,C.jsx)(ie,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),o(`marketplace.back`)]}),(0,C.jsxs)(`div`,{className:`flex items-start gap-3 rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm`,children:[(0,C.jsx)(c,{className:`h-4 w-4 mt-0.5 text-destructive`,"aria-hidden":`true`}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`div`,{className:`font-medium text-destructive`,children:o(`marketplace.load.packageFailed`)}),(0,C.jsx)(`div`,{className:`text-muted-foreground mt-1`,children:w??o(`marketplace.load.notFound`)})]})]})]});let X=m.package,Z=Ge(X,ae),Q=X.latest_version?.version??m.versions[0]?.version??null,$=at.find(e=>e.manifestId===X.manifest_id)??null,mt=!!X.latest_version?.contains_code,ht=!!R&&R!==`installed`&&!!Q&&R!==Q,gt=x().features.installLocal,_t=!Q||K||F||!gt&&!!R&&!ht,vt=gt?{label:o(K?`marketplace.action.working`:$?`marketplace.action.reinstall`:`marketplace.action.install`),onClick:ct}:{label:F?o(`marketplace.action.installing`):R?ht?o(`marketplace.action.updateTo`,{defaultValue:`Update`,version:Q}):o(`marketplace.action.installed`,{defaultValue:`Installed`}):o(`marketplace.action.installToCloud`),onClick:ot},yt=X.category?o(`marketplace.category.${X.category}`,{defaultValue:X.category}):null;return a?(0,C.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl flex flex-col gap-6 p-4 sm:p-6`,children:[(0,C.jsxs)(v,{variant:`ghost`,size:`sm`,className:`self-start -ml-2 text-muted-foreground hover:text-foreground`,onClick:()=>e(`${s}/system/marketplace`),children:[(0,C.jsx)(ie,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),o(`marketplace.back`)]}),(0,C.jsxs)(`div`,{className:`flex items-start gap-5 flex-wrap sm:flex-nowrap rounded-2xl border bg-gradient-to-br from-primary/5 via-background to-background p-6 sm:p-8`,children:[(0,C.jsx)(We,{iconUrl:X.icon_url,displayName:Z.displayName,manifestId:X.manifest_id,className:`h-20 w-20 rounded-2xl shadow-sm ring-1 ring-border shrink-0`,initialClassName:`text-3xl font-bold`}),(0,C.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,C.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight truncate`,children:Z.displayName||X.manifest_id}),X.homepage_url&&(0,C.jsxs)(`a`,{href:X.homepage_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,title:o(`marketplace.detail.homepage`),children:[(0,C.jsx)(ce,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),(0,C.jsx)(`span`,{className:`hidden sm:inline`,children:o(`marketplace.detail.homepage`)})]})]}),(0,C.jsxs)(`div`,{className:`text-sm text-muted-foreground mt-2 flex flex-wrap items-center gap-1.5`,children:[(0,C.jsx)(`code`,{className:`font-mono text-xs px-1.5 py-0.5 rounded bg-muted`,children:X.manifest_id}),Q&&(0,C.jsx)(f,{variant:`outline`,children:o(`marketplace.versionBadge`,{version:Q})}),X.publisher&&X.publisher!==`private`&&(0,C.jsx)(f,{variant:X.publisher===`objectstack`?`default`:`secondary`,children:X.publisher}),yt&&(0,C.jsx)(f,{variant:`outline`,children:yt}),X.license&&(0,C.jsx)(f,{variant:`outline`,className:`font-normal`,children:X.license}),$&&(0,C.jsxs)(f,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,C.jsx)(g,{className:`h-3 w-3`,"aria-hidden":`true`}),o(`marketplace.detail.installedV`,{version:$.version})]}),!$&&R&&(0,C.jsxs)(f,{variant:`default`,className:`bg-green-600 hover:bg-green-600 gap-1`,children:[(0,C.jsx)(g,{className:`h-3 w-3`,"aria-hidden":`true`}),o(`marketplace.detail.installedV`,{version:R})]}),ht&&(0,C.jsxs)(f,{variant:`default`,className:`bg-amber-500 hover:bg-amber-500 gap-1`,children:[(0,C.jsx)(fe,{className:`h-3 w-3`,"aria-hidden":`true`}),o(`marketplace.detail.updateAvailable`,{defaultValue:`Update available`}),` → v`,Q]})]}),Z.description&&(0,C.jsx)(`p`,{className:`text-sm sm:text-base text-foreground/80 mt-3 max-w-2xl leading-relaxed`,children:Z.description})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0 self-start`,children:[(0,C.jsxs)(v,{onClick:vt.onClick,disabled:_t,size:`lg`,className:`min-w-[8rem]`,children:[(0,C.jsx)(pe,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),vt.label]}),$&&(0,C.jsxs)(be,{children:[(0,C.jsx)(Ae,{asChild:!0,children:(0,C.jsx)(v,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":o(`marketplace.detail.moreOptions`),children:(0,C.jsx)(_e,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,C.jsxs)(Te,{align:`end`,className:`w-56`,children:[(0,C.jsxs)(h,{onSelect:ft,disabled:V!==null,children:[V===`reseed`?(0,C.jsx)(y,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,C.jsx)(Ce,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),$.withSampleData?o(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:o(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,C.jsxs)(h,{onSelect:pt,disabled:V!==null||!$.withSampleData,className:`text-destructive focus:text-destructive`,children:[V===`purge`?(0,C.jsx)(y,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,C.jsx)(_,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),o(`marketplace.detail.purgeSampleData`)||`Purge sample data`]}),(0,C.jsxs)(h,{onSelect:lt,disabled:K,className:`text-destructive focus:text-destructive`,children:[(0,C.jsx)(_,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),o(`marketplace.detail.uninstallFromRuntime`)]})]})]}),!$&&z&&!x().cloudUrl&&(0,C.jsxs)(be,{children:[(0,C.jsx)(Ae,{asChild:!0,children:(0,C.jsx)(v,{variant:`outline`,size:`lg`,className:`px-2.5`,"aria-label":o(`marketplace.detail.moreOptions`)||`More options`,children:(0,C.jsx)(_e,{className:`h-4 w-4`,"aria-hidden":`true`})})}),(0,C.jsxs)(Te,{align:`end`,className:`w-56`,children:[(0,C.jsxs)(h,{onSelect:ut,disabled:V!==null,children:[V===`reseed`?(0,C.jsx)(y,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,C.jsx)(Ce,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),z.withSampleData?o(`marketplace.detail.reseedAgain`)||`Re-seed sample data`:o(`marketplace.detail.addSampleData`)||`Add sample data`]}),(0,C.jsxs)(h,{onSelect:dt,disabled:V!==null||!z.withSampleData,className:`text-destructive focus:text-destructive`,children:[V===`purge`?(0,C.jsx)(y,{className:`h-4 w-4 mr-2 animate-spin`,"aria-hidden":`true`}):(0,C.jsx)(_,{className:`h-4 w-4 mr-2`,"aria-hidden":`true`}),o(`marketplace.detail.purgeSampleData`)||`Purge sample data`]})]})]})]})]}),U&&(0,C.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm ${U.ok?`border-green-500/30 bg-green-500/5 text-green-700 dark:text-green-400`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:[U.ok?(0,C.jsx)(g,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,C.jsx)(c,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,C.jsx)(`div`,{className:`flex-1`,children:U.text}),(0,C.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>W(null),children:o(`marketplace.action.dismiss`)})]}),J&&(0,C.jsxs)(`div`,{role:`status`,className:`flex items-start gap-2 rounded-md border p-3 text-sm whitespace-pre-wrap ${J.ok?`border-green-500/30 bg-green-500/5 text-green-700 dark:text-green-400`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:[J.ok?(0,C.jsx)(g,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}):(0,C.jsx)(c,{className:`h-4 w-4 mt-0.5 shrink-0`,"aria-hidden":`true`}),(0,C.jsx)(`div`,{className:`flex-1`,children:J.message}),(0,C.jsx)(`button`,{type:`button`,className:`text-xs underline opacity-60 hover:opacity-100`,onClick:()=>Y(null),children:o(`marketplace.action.dismiss`)})]}),(0,C.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-3`,children:[(0,C.jsx)(`div`,{className:`lg:col-span-2 space-y-4`,children:(0,C.jsxs)(re,{children:[(0,C.jsx)(Se,{children:(0,C.jsx)(Oe,{className:`text-base`,children:o(`marketplace.detail.about`)})}),(0,C.jsx)(ye,{children:Z.readme?(0,C.jsx)(Je,{source:Z.readme}):(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o(`marketplace.detail.noReadme`)})})]})}),(0,C.jsx)(`div`,{className:`space-y-4`,children:(0,C.jsxs)(re,{children:[(0,C.jsx)(Se,{children:(0,C.jsx)(Oe,{className:`text-base`,children:o(`marketplace.detail.versions`)})}),(0,C.jsx)(ye,{children:m.versions.length===0?(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o(`marketplace.detail.noApprovedVersions`)}):(0,C.jsx)(`ul`,{className:`space-y-3`,children:m.versions.map(e=>(0,C.jsxs)(`li`,{className:`space-y-1 text-sm`,children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,C.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,C.jsx)(xe,{className:`h-3.5 w-3.5 text-muted-foreground`,"aria-hidden":`true`}),(0,C.jsxs)(`code`,{className:`font-mono`,children:[`v`,e.version]}),e.is_prerelease&&(0,C.jsx)(f,{variant:`outline`,className:`text-xs`,children:o(`marketplace.detail.prerelease`)})]}),(0,C.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.published_at?new Date(e.published_at).toLocaleDateString():`—`})]}),e.release_notes&&e.release_notes.trim()&&(0,C.jsx)(`p`,{className:`whitespace-pre-line pl-5 text-xs text-muted-foreground`,children:e.release_notes.trim()})]},e.id))})})]})})]}),(0,C.jsx)(me,{open:E,onOpenChange:e=>{D(e),e||(L(null),nt(!1))},children:(0,C.jsxs)(he,{children:[(0,C.jsxs)(Ee,{children:[(0,C.jsx)(se,{children:o(`marketplace.install.dialogTitle`,{name:Z.displayName||X.manifest_id})}),(0,C.jsx)(oe,{children:x().defaultEnvironmentId?o(`marketplace.install.dialogDescCurrent`,{host:typeof window<`u`?window.location.host:``}):o(`marketplace.install.dialogDescPicker`)})]}),Ze?(0,C.jsx)(u,{className:`h-10 w-full`}):A?(0,C.jsxs)(`div`,{className:`rounded-md border border-amber-500/30 bg-amber-500/5 p-3 text-sm space-y-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,C.jsx)(c,{className:`h-4 w-4 mt-0.5 text-amber-600`,"aria-hidden":`true`}),(0,C.jsx)(`div`,{className:`flex-1`,children:A})]}),(0,C.jsx)(`a`,{href:He(X.id),target:`_blank`,rel:`noopener noreferrer`,children:(0,C.jsxs)(v,{variant:`outline`,size:`sm`,className:`w-full`,children:[(0,C.jsx)(ce,{className:`h-4 w-4 mr-1.5`,"aria-hidden":`true`}),o(`marketplace.action.openOnCloud`)]})})]}):x().defaultEnvironmentId?(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(l,{id:`seed`,checked:P,onCheckedChange:e=>et(e===!0)}),(0,C.jsx)(p,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:o(`marketplace.install.includeSampleData`)})]}):O.length===0?(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o(`marketplace.install.noEnvs`)}):(0,C.jsxs)(`div`,{className:`space-y-4`,children:[(0,C.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,C.jsx)(p,{htmlFor:`env-select`,children:o(`marketplace.install.environment`)}),(0,C.jsxs)(de,{value:M,onValueChange:N,children:[(0,C.jsx)(ve,{id:`env-select`,children:(0,C.jsx)(ge,{placeholder:o(`marketplace.install.environmentPlaceholder`)})}),(0,C.jsx)(De,{children:O.map(e=>{let t=Qe[e.id],n=!!t&&!!Q&&t!==`installed`&&t!==Q;return(0,C.jsxs)(le,{value:e.id,children:[e.display_name||e.hostname||e.id,e.plan&&(0,C.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.plan]}),t&&(n?(0,C.jsxs)(`span`,{className:`text-amber-600`,children:[` · `,o(`marketplace.install.updateTo`,{defaultValue:`Update → v{{version}}`,version:Q})]}):(0,C.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,o(`marketplace.install.installedVersion`,{defaultValue:`Installed v{{version}}`,version:t})]}))]},e.id)})})]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsx)(l,{id:`seed`,checked:P,onCheckedChange:e=>et(e===!0)}),(0,C.jsx)(p,{htmlFor:`seed`,className:`text-sm font-normal cursor-pointer`,children:o(`marketplace.install.includeSampleData`)})]})]}),mt&&!A&&(0,C.jsxs)(`div`,{className:`space-y-3`,children:[(0,C.jsx)(Ye,{version:X.latest_version}),(0,C.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,C.jsx)(l,{id:`ack-perms`,checked:tt,onCheckedChange:e=>nt(e===!0)}),(0,C.jsx)(p,{htmlFor:`ack-perms`,className:`text-sm font-normal cursor-pointer leading-snug`,children:o(`marketplace.disclosure.acknowledge`,{defaultValue:`I understand this package runs code and grants the permissions above.`})})]})]}),I&&(0,C.jsx)(`div`,{className:`rounded-md border p-3 text-sm ${I.ok?`border-green-500/30 bg-green-500/5 text-green-700`:`border-destructive/30 bg-destructive/5 text-destructive`}`,children:I.message}),(0,C.jsxs)(ue,{children:[(0,C.jsx)(v,{variant:`outline`,onClick:()=>D(!1),children:o(`marketplace.action.close`)}),!A&&(0,C.jsx)(v,{onClick:st,disabled:!M||F||I?.ok===!0||mt&&!tt,children:o(F?`marketplace.action.installing`:`marketplace.action.install`)})]})]})})]}):(0,C.jsx)(Ke,{})}export{D as t};