@objectstack/studio 5.2.0 → 9.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.
- package/LICENSE.apache +202 -0
- package/dist/index.d.mts +71 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +138 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +127 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +39 -97
- package/README.md +0 -150
- package/dist/assets/index-81ZhtCq-.js +0 -159
- package/dist/assets/index-CSlaSCb_.css +0 -2
- package/dist/assets/rolldown-runtime-aKtaBQYM.js +0 -1
- package/dist/assets/vendor-charts-CMWbKNvz.js +0 -34
- package/dist/assets/vendor-icons-C-VDCqO9.js +0 -1
- package/dist/assets/vendor-kzrx2K5g.css +0 -1
- package/dist/assets/vendor-object-ui-core-C_SRaIe4.js +0 -59
- package/dist/assets/vendor-object-ui-form-DRRdiS9F.js +0 -1
- package/dist/assets/vendor-object-ui-grid-BvNa3IUR.js +0 -6
- package/dist/assets/vendor-object-ui-views-CyaLQwFl.js +0 -0
- package/dist/assets/vendor-rQmwIIxi.js +0 -152
- package/dist/assets/vendor-radix-DlDjksHy.js +0 -1
- package/dist/assets/vendor-react-CfxtBSJn.js +0 -9
- package/dist/assets/vendor-tanstack-D6oxbowc.js +0 -1
- package/dist/index.html +0 -45
- package/dist/vite.svg +0 -5
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-object-ui-views-CyaLQwFl.js","assets/rolldown-runtime-aKtaBQYM.js","assets/vendor-rQmwIIxi.js","assets/vendor-kzrx2K5g.css","assets/vendor-object-ui-core-C_SRaIe4.js","assets/vendor-charts-CMWbKNvz.js","assets/vendor-icons-C-VDCqO9.js","assets/vendor-object-ui-grid-BvNa3IUR.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{i as e,r as t}from"./rolldown-runtime-aKtaBQYM.js";import{$t as n,Gt as r,Kt as i,Qt as a,Ut as o,Wt as s,Xt as c,Zt as l,_ as u,_t as d,an as f,bn as p,c as m,cn as h,d as g,dn as _,en as v,et as y,f as b,fn as x,g as S,gt as C,hn as w,ht as T,i as ee,in as E,l as te,ln as D,m as ne,mn as O,mt as re,nn as k,o as ie,on as A,pn as j,pt as ae,r as oe,rn as se,rt as ce,s as le,sn as M,tn as N,un as P,v as ue,vn as de,vt as fe,x as pe,yt as me}from"./vendor-rQmwIIxi.js";import{n as he,t as ge}from"./vendor-react-CfxtBSJn.js";import{a as _e,c as ve,i as ye,l as be,n as xe,o as Se,r as Ce,s as we,t as Te,u as Ee}from"./vendor-tanstack-D6oxbowc.js";import{$n as De,An as Oe,At as ke,B as Ae,Bn as je,Bt as Me,Cn as Ne,Ct as Pe,D as Fe,Dn as Ie,Dt as Le,E as Re,En as ze,Fn as Be,Ft as Ve,G as He,Gn as Ue,Hn as We,In as Ge,It as Ke,J as qe,Jn as Je,Jt as Ye,K as Xe,Kt as Ze,L as Qe,Lt as $e,M as et,Mt as tt,N as nt,Nn as rt,Nt as it,On as at,Ot as ot,P as st,Pn as ct,Pt as lt,Qn as ut,R as dt,Rt as ft,S as pt,Sn as mt,St as ht,U as gt,Un as _t,Ut as vt,V as yt,Vt as bt,W as xt,Wn as St,Xn as Ct,Xt as wt,Yn as Tt,Yt as Et,Zn as Dt,Zt as Ot,_t as kt,a as At,an as jt,at as Mt,b as Nt,bt as Pt,c as Ft,cn as It,cr as Lt,ct as Rt,d as zt,dn as Bt,dr as Vt,en as Ht,et as Ut,f as Wt,fn as Gt,fr as Kt,ft as qt,g as Jt,gn as Yt,gt as Xt,h as Zt,i as Qt,in as $t,it as en,j as tn,jn as nn,jt as rn,k as an,kn as on,kt as sn,l as cn,lt as ln,mn as un,o as dn,on as fn,or as pn,p as mn,pt as hn,q as gn,qn as _n,qt as vn,rn as yn,s as bn,sn as xn,sr as Sn,st as Cn,tn as wn,tr as Tn,tt as En,u as Dn,un as On,ur as kn,ut as An,vn as jn,vt as Mn,w as Nn,wn as Pn,y as Fn,yn as In,yt as Ln,zn as Rn,zt as zn}from"./vendor-icons-C-VDCqO9.js";import{$n as Bn,$t as Vn,An as Hn,Bn as Un,Bt as Wn,Dn as Gn,En as Kn,Fn as qn,Ft as Jn,Gn as Yn,Gt as Xn,Hn as Zn,Ht as Qn,In as $n,It as er,Jn as tr,Jt as nr,Kn as rr,Kt as ir,Ln as ar,Lt as or,Mn as sr,Nn as cr,On as lr,Pn as ur,Qn as dr,Qt as fr,Rn as pr,Rt as mr,Tn as hr,Un as gr,Ut as _r,Vn as vr,Vt as yr,Wn as br,Wt as xr,Xn as Sr,Xt as Cr,Yt as wr,Zn as Tr,Zt as Er,a as Dr,c as Or,en as kr,jn as Ar,kn as jr,l as Mr,qn as Nr,qt as Pr,s as Fr,tn as Ir,tr as Lr,wn as Rr,zn as zr,zt as Br}from"./vendor-object-ui-core-C_SRaIe4.js";import{a as Vr,i as Hr,n as Ur,o as Wr,r as Gr,s as Kr,t as qr}from"./vendor-radix-DlDjksHy.js";import{t as Jr}from"./vendor-object-ui-grid-BvNa3IUR.js";import{t as Yr}from"./vendor-object-ui-form-DRRdiS9F.js";import{a as Xr,i as Zr,r as Qr}from"./vendor-object-ui-views-CyaLQwFl.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var F=e(p(),1),$r=e(he(),1);function I(e){if(typeof process<`u`&&{}.OS_EAGER_SCHEMAS===`1`)return e();let t,n=()=>(t===void 0&&(t=e()),t);return new Proxy(function(){},{get(e,t){let r=n(),i=r[t];return typeof i==`function`?i.bind(r):i},set(e,t,r){let i=n();return i[t]=r,!0},has(e,t){return t in n()},ownKeys(){return Reflect.ownKeys(n())},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(n(),t)},getPrototypeOf(){return Reflect.getPrototypeOf(n())}})}var ei=I(()=>D({$field:x().describe(`Field Reference/Column Name`)}));I(()=>D({$eq:v().optional(),$ne:v().optional()})),I(()=>D({$gt:O([h(),E(),ei]).optional(),$gte:O([h(),E(),ei]).optional(),$lt:O([h(),E(),ei]).optional(),$lte:O([h(),E(),ei]).optional()})),I(()=>D({$in:N(v()).optional(),$nin:N(v()).optional()})),I(()=>D({$between:j([O([h(),E(),ei]),O([h(),E(),ei])]).optional()})),I(()=>D({$contains:x().optional(),$notContains:x().optional(),$startsWith:x().optional(),$endsWith:x().optional()})),I(()=>D({$null:k().optional(),$exists:k().optional()}));var ti=I(()=>D({$eq:v().optional(),$ne:v().optional(),$gt:O([h(),E(),ei]).optional(),$gte:O([h(),E(),ei]).optional(),$lt:O([h(),E(),ei]).optional(),$lte:O([h(),E(),ei]).optional(),$in:N(v()).optional(),$nin:N(v()).optional(),$between:j([O([h(),E(),ei]),O([h(),E(),ei])]).optional(),$contains:x().optional(),$notContains:x().optional(),$startsWith:x().optional(),$endsWith:x().optional(),$null:k().optional(),$exists:k().optional()})),ni=A(()=>_(x(),w()).and(D({$and:N(ni).optional(),$or:N(ni).optional(),$not:ni.optional()})));I(()=>D({where:ni.optional()}));var ri=A(()=>D({$and:N(O([_(x(),ti),ri])).optional(),$or:N(O([_(x(),ti),ri])).optional(),$not:O([_(x(),ti),ri]).optional()})),ii=new Set([`=`,`==`,`!=`,`<>`,`>`,`>=`,`<`,`<=`,`in`,`nin`,`not_in`,`contains`,`notcontains`,`not_contains`,`like`,`startswith`,`starts_with`,`endswith`,`ends_with`,`between`,`is_null`,`is_not_null`]);function ai(e){if(!Array.isArray(e)||e.length===0)return!1;let t=e[0];if(typeof t==`string`){let n=t.toLowerCase();if(n===`and`||n===`or`)return e.length>=2&&e.slice(1).every(e=>ai(e));if(e.length>=2&&typeof e[1]==`string`)return ii.has(e[1].toLowerCase())}return e.every(e=>ai(e))?e.length>0:!1}var oi=[`$eq`,`$ne`,`$gt`,`$gte`,`$lt`,`$lte`,`$in`,`$nin`,`$between`,`$contains`,`$notContains`,`$startsWith`,`$endsWith`,`$null`,`$exists`],si=[`$and`,`$or`,`$not`];[...oi,...si];var ci=I(()=>D({field:x(),order:c([`asc`,`desc`]).default(`asc`)})),li=c([`count`,`sum`,`avg`,`min`,`max`,`count_distinct`,`array_agg`,`string_agg`]),ui=c([`day`,`week`,`month`,`quarter`,`year`]),di=I(()=>O([x(),D({field:x().describe(`Field to group by`),dateGranularity:ui.optional().describe(`Bucket date values into uniform periods (day/week/month/quarter/year)`),alias:x().optional().describe(`Alias for the projected group value`)})])),fi=I(()=>D({function:li.describe(`Aggregation function`),field:x().optional().describe(`Field to aggregate (optional for COUNT(*))`),alias:x().describe(`Result column alias`),distinct:k().optional().describe(`Apply DISTINCT before aggregation`),filter:ni.optional().describe(`Filter/Condition to apply to the aggregation (FILTER WHERE clause)`)})),pi=c([`inner`,`left`,`right`,`full`]),mi=c([`auto`,`database`,`hash`,`loop`]),hi=A(()=>D({type:pi.describe(`Join type`),strategy:mi.optional().describe(`Execution strategy hint`),object:x().describe(`Object/table to join`),alias:x().optional().describe(`Table alias`),on:ni.describe(`Join condition`),subquery:A(()=>Si).optional().describe(`Subquery instead of object`)})),gi=c([`row_number`,`rank`,`dense_rank`,`percent_rank`,`lag`,`lead`,`first_value`,`last_value`,`sum`,`avg`,`count`,`min`,`max`]),_i=I(()=>D({partitionBy:N(x()).optional().describe(`PARTITION BY fields`),orderBy:N(ci).optional().describe(`ORDER BY specification`),frame:D({type:c([`rows`,`range`]).optional(),start:x().optional().describe(`Frame start (e.g., "UNBOUNDED PRECEDING", "1 PRECEDING")`),end:x().optional().describe(`Frame end (e.g., "CURRENT ROW", "1 FOLLOWING")`)}).optional().describe(`Window frame specification`)})),vi=I(()=>D({function:gi.describe(`Window function name`),field:x().optional().describe(`Field to operate on (for aggregate window functions)`),alias:x().describe(`Result column alias`),over:_i.describe(`Window specification (OVER clause)`)})),yi=A(()=>O([x(),D({field:x(),fields:N(yi).optional(),alias:x().optional()})])),bi=I(()=>D({query:x().describe(`Search query text`),fields:N(x()).optional().describe(`Fields to search in (if not specified, searches all text fields)`),fuzzy:k().optional().default(!1).describe(`Enable fuzzy matching (tolerates typos)`),operator:c([`and`,`or`]).optional().default(`or`).describe(`Logical operator between terms`),boost:_(x(),h()).optional().describe(`Field-specific relevance boosting (field name -> boost factor)`),minScore:h().optional().describe(`Minimum relevance score threshold`),language:x().optional().describe(`Language for text analysis (e.g., "en", "zh", "es")`),highlight:k().optional().default(!1).describe(`Enable search result highlighting`)})),xi=D({object:x().describe(`Object name (e.g. account)`),fields:N(yi).optional().describe(`Fields to retrieve`),where:ni.optional().describe(`Filtering criteria (WHERE)`),search:bi.optional().describe(`Full-text search configuration ($search parameter)`),orderBy:N(ci).optional().describe(`Sorting instructions (ORDER BY)`),limit:h().optional().describe(`Max records to return (LIMIT)`),offset:h().optional().describe(`Records to skip (OFFSET)`),top:h().optional().describe(`Alias for limit (OData compatibility)`),cursor:_(x(),w()).optional().describe(`Cursor for keyset pagination`),joins:N(hi).optional().describe(`Explicit Table Joins`),aggregations:N(fi).optional().describe(`Aggregation functions`),groupBy:N(di).optional().describe("GROUP BY targets (strings or `{field, dateGranularity?}` objects for date bucketing)"),having:ni.optional().describe(`HAVING clause for aggregation filtering`),windowFunctions:N(vi).optional().describe(`Window functions with OVER clause`),distinct:k().optional().describe(`SELECT DISTINCT flag`)}),Si=I(()=>xi.extend({expand:A(()=>_(x(),Si)).optional().describe(`Recursive relation loading map. Keys are lookup/master_detail field names; values are nested QueryAST objects that control select, filter, sort, and further expansion on the related object. The engine resolves expand via batch $in queries (driver-agnostic) with a default max depth of 3.`)})),Ci=I(()=>x().min(2,{message:`System identifier must be at least 2 characters`}).regex(/^[a-z][a-z0-9_.]*$/,{message:`System identifier must be lowercase, starting with a letter, and may contain letters, numbers, underscores, or dots (e.g., "user_profile" or "order.created")`}).describe(`System identifier (lowercase with underscores or dots)`)),wi=I(()=>x().min(2,{message:`Identifier must be at least 2 characters`}).regex(/^[a-z][a-z0-9_]*$/,{message:`Identifier must be lowercase snake_case, starting with a letter, and may contain only letters, numbers, and underscores (e.g., "user_profile")`}).describe(`Snake case identifier (lowercase with underscores only)`));I(()=>x().min(3,{message:`Event name must be at least 3 characters`}).regex(/^[a-z][a-z0-9_.]*$/,{message:`Event name must be lowercase with dots for namespacing (e.g., "user.created", "order.paid")`}).describe(`Event name (lowercase with dot notation for namespacing)`));var Ti=c([`cel`,`js`,`cron`,`template`]),Ei=D({rationale:x().optional(),generatedBy:x().optional()}),Di=D({dialect:Ti,source:x().min(1).optional(),ast:w().optional(),meta:Ei.optional()}).refine(e=>e.source!==void 0||e.ast!==void 0,{message:"Expression requires at least one of `source` or `ast`"}),Oi=O([x().min(1).transform(e=>({dialect:`cel`,source:e})),Di]);O([x().min(1).transform(e=>({dialect:`cron`,source:e})),Di]);var ki=O([x().min(1).transform(e=>({dialect:`template`,source:e})),Di]),Ai=I(()=>c([`aes-256-gcm`,`aes-256-cbc`,`chacha20-poly1305`]).describe(`Supported encryption algorithm`)),ji=I(()=>c([`local`,`aws-kms`,`azure-key-vault`,`gcp-kms`,`hashicorp-vault`]).describe(`Key management service provider`)),Mi=I(()=>D({enabled:k().default(!1).describe(`Enable automatic key rotation`),frequencyDays:h().min(1).default(90).describe(`Rotation frequency in days`),retainOldVersions:h().default(3).describe(`Number of old key versions to retain`),autoRotate:k().default(!0).describe(`Automatically rotate without manual approval`)}).describe(`Policy for automatic encryption key rotation`)),Ni=I(()=>D({enabled:k().default(!1).describe(`Enable field-level encryption`),algorithm:Ai.default(`aes-256-gcm`).describe(`Encryption algorithm`),keyManagement:D({provider:ji.describe(`Key management service provider`),keyId:x().optional().describe(`Key identifier in the provider`),rotationPolicy:Mi.optional().describe(`Key rotation policy`)}).describe(`Key management configuration`),scope:c([`field`,`record`,`table`,`database`]).describe(`Encryption scope level`),deterministicEncryption:k().default(!1).describe(`Allows equality queries on encrypted data`),searchableEncryption:k().default(!1).describe(`Allows search on encrypted data`)}).describe(`Field-level encryption configuration`));I(()=>D({fieldName:x().describe(`Name of the field to encrypt`),encryptionConfig:Ni.describe(`Encryption settings for this field`),indexable:k().default(!1).describe(`Allow indexing on encrypted field`)}).describe(`Per-field encryption assignment`));var Pi=I(()=>c([`redact`,`partial`,`hash`,`tokenize`,`randomize`,`nullify`,`substitute`]).describe(`Data masking strategy for PII protection`)),Fi=I(()=>D({field:x().describe(`Field name to apply masking to`),strategy:Pi.describe(`Masking strategy to use`),pattern:x().optional().describe(`Regex pattern for partial masking`),preserveFormat:k().default(!0).describe(`Keep the original data format after masking`),preserveLength:k().default(!0).describe(`Keep the original data length after masking`),roles:N(x()).optional().describe(`Roles that see masked data`),exemptRoles:N(x()).optional().describe(`Roles that see unmasked data`)}).describe(`Masking rule for a single field`));I(()=>D({enabled:k().default(!1).describe(`Enable data masking`),rules:N(Fi).describe(`List of field-level masking rules`),auditUnmasking:k().default(!0).describe(`Log when masked data is accessed unmasked`)}).describe(`Top-level data masking configuration for PII protection`));var Ii=c(`text.textarea.email.url.phone.password.markdown.html.richtext.number.currency.percent.date.datetime.time.boolean.toggle.select.multiselect.radio.checkboxes.lookup.master_detail.tree.image.file.avatar.video.audio.formula.summary.autonumber.location.address.code.json.color.rating.slider.signature.qrcode.progress.tags.vector`.split(`.`)),Li=I(()=>D({label:x().describe(`Display label (human-readable, any case allowed)`),value:Ci.describe(`Stored value (lowercase machine identifier)`),color:x().optional().describe(`Color code for badges/charts`),default:k().optional().describe(`Is default option`)}));I(()=>D({latitude:h().min(-90).max(90).describe(`Latitude coordinate`),longitude:h().min(-180).max(180).describe(`Longitude coordinate`),altitude:h().optional().describe(`Altitude in meters`),accuracy:h().optional().describe(`Accuracy in meters`)}));var Ri=I(()=>D({precision:h().int().min(0).max(10).default(2).describe(`Decimal precision (default: 2)`),currencyMode:c([`dynamic`,`fixed`]).default(`dynamic`).describe(`Currency mode: dynamic (user selectable) or fixed (single currency)`),defaultCurrency:x().length(3).default(`CNY`).describe(`Default or fixed currency code (ISO 4217, e.g., USD, CNY, EUR)`)}));I(()=>D({value:h().describe(`Monetary amount`),currency:x().length(3).describe(`Currency code (ISO 4217)`)})),I(()=>D({street:x().optional().describe(`Street address`),city:x().optional().describe(`City name`),state:x().optional().describe(`State/Province`),postalCode:x().optional().describe(`Postal/ZIP code`),country:x().optional().describe(`Country name or code`),countryCode:x().optional().describe(`ISO country code (e.g., US, GB)`),formatted:x().optional().describe(`Formatted address string`)}));var zi=I(()=>D({dimensions:h().int().min(1).max(1e4).describe(`Vector dimensionality (e.g., 1536 for OpenAI embeddings)`),distanceMetric:c([`cosine`,`euclidean`,`dotProduct`,`manhattan`]).default(`cosine`).describe(`Distance/similarity metric for vector search`),normalized:k().default(!1).describe(`Whether vectors are normalized (unit length)`),indexed:k().default(!0).describe(`Whether to create a vector index for fast similarity search`),indexType:c([`hnsw`,`ivfflat`,`flat`]).optional().describe(`Vector index algorithm (HNSW for high accuracy, IVFFlat for large datasets)`)})),Bi=I(()=>D({minSize:h().min(0).optional().describe(`Minimum file size in bytes`),maxSize:h().min(1).optional().describe(`Maximum file size in bytes (e.g., 10485760 = 10MB)`),allowedTypes:N(x()).optional().describe(`Allowed file extensions (e.g., [".pdf", ".docx", ".jpg"])`),blockedTypes:N(x()).optional().describe(`Blocked file extensions (e.g., [".exe", ".bat", ".sh"])`),allowedMimeTypes:N(x()).optional().describe(`Allowed MIME types (e.g., ["image/jpeg", "application/pdf"])`),blockedMimeTypes:N(x()).optional().describe(`Blocked MIME types`),virusScan:k().default(!1).describe(`Enable virus scanning for uploaded files`),virusScanProvider:c([`clamav`,`virustotal`,`metadefender`,`custom`]).optional().describe(`Virus scanning service provider`),virusScanOnUpload:k().default(!0).describe(`Scan files immediately on upload`),quarantineOnThreat:k().default(!0).describe(`Quarantine files if threat detected`),storageProvider:x().optional().describe(`Object storage provider name (references ObjectStorageConfig)`),storageBucket:x().optional().describe(`Target bucket name`),storagePrefix:x().optional().describe(`Storage path prefix (e.g., "uploads/documents/")`),imageValidation:D({minWidth:h().min(1).optional().describe(`Minimum image width in pixels`),maxWidth:h().min(1).optional().describe(`Maximum image width in pixels`),minHeight:h().min(1).optional().describe(`Minimum image height in pixels`),maxHeight:h().min(1).optional().describe(`Maximum image height in pixels`),aspectRatio:x().optional().describe(`Required aspect ratio (e.g., "16:9", "1:1")`),generateThumbnails:k().default(!1).describe(`Auto-generate thumbnails`),thumbnailSizes:N(D({name:x().describe(`Thumbnail variant name (e.g., "small", "medium", "large")`),width:h().min(1).describe(`Thumbnail width in pixels`),height:h().min(1).describe(`Thumbnail height in pixels`),crop:k().default(!1).describe(`Crop to exact dimensions`)})).optional().describe(`Thumbnail size configurations`),preserveMetadata:k().default(!1).describe(`Preserve EXIF metadata`),autoRotate:k().default(!0).describe(`Auto-rotate based on EXIF orientation`)}).optional().describe(`Image-specific validation rules`),allowMultiple:k().default(!1).describe(`Allow multiple file uploads (overrides field.multiple)`),allowReplace:k().default(!0).describe(`Allow replacing existing files`),allowDelete:k().default(!0).describe(`Allow deleting uploaded files`),requireUpload:k().default(!1).describe(`Require at least one file when field is required`),extractMetadata:k().default(!0).describe(`Extract file metadata (name, size, type, etc.)`),extractText:k().default(!1).describe(`Extract text content from documents (OCR/parsing)`),versioningEnabled:k().default(!1).describe(`Keep previous versions of replaced files`),maxVersions:h().min(1).optional().describe(`Maximum number of versions to retain`),publicRead:k().default(!1).describe(`Allow public read access to uploaded files`),presignedUrlExpiry:h().min(60).max(604800).default(3600).describe(`Presigned URL expiration in seconds (default: 1 hour)`)}).refine(e=>!(e.minSize!==void 0&&e.maxSize!==void 0&&e.minSize>e.maxSize),{message:`minSize must be less than or equal to maxSize`}).refine(e=>!(e.virusScanProvider!==void 0&&e.virusScan!==!0),{message:`virusScanProvider requires virusScan to be enabled`})),Vi=I(()=>D({uniqueness:k().default(!1).describe(`Enforce unique values across all records`),completeness:h().min(0).max(1).default(0).describe(`Minimum ratio of non-null values (0-1, default: 0 = no requirement)`),accuracy:D({source:x().describe(`Reference data source for validation (e.g., "api.verify.com", "master_data")`),threshold:h().min(0).max(1).describe(`Minimum accuracy threshold (0-1, e.g., 0.95 = 95% match required)`)}).optional().describe(`Accuracy validation configuration`)})),Hi=I(()=>D({enabled:k().describe(`Enable caching for computed field results`),ttl:h().min(0).describe(`Cache TTL in seconds (0 = no expiration)`),invalidateOn:N(x()).describe(`Field paths that invalidate cache (e.g., ["inventory.quantity", "pricing.base_price"])`)})),Ui=I(()=>D({name:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Machine name (snake_case)`).optional(),label:x().optional().describe(`Human readable label`),type:Ii.describe(`Field Data Type`),description:x().optional().describe(`Tooltip/Help text`),format:x().optional().describe(`Format string (e.g. email, phone)`),columnName:x().optional().describe(`Physical column name in the target datasource. Defaults to the field key when not set.`),required:k().default(!1).describe(`Is required`),searchable:k().default(!1).describe(`Is searchable`),multiple:k().default(!1).describe(`Allow multiple values (Stores as Array/JSON). Applicable for select, lookup, file, image.`),unique:k().default(!1).describe(`Is unique constraint`),defaultValue:w().optional().describe(`Default value`),maxLength:h().optional().describe(`Max character length`),minLength:h().optional().describe(`Min character length`),precision:h().optional().describe(`Total digits`),scale:h().optional().describe(`Decimal places`),min:h().optional().describe(`Minimum value`),max:h().optional().describe(`Maximum value`),options:N(Li).optional().describe(`Static options for select/multiselect`),reference:x().optional().describe(`Target object name (snake_case) for lookup/master_detail fields. Required for relationship types. Used by $expand to resolve foreign key IDs into full objects.`),referenceFilters:N(x()).optional().describe(`Filters applied to lookup dialogs (e.g. "active = true")`),writeRequiresMasterRead:k().optional().describe(`If true, user needs read access to master record to edit this field`),deleteBehavior:c([`set_null`,`cascade`,`restrict`]).optional().default(`set_null`).describe(`What happens if referenced record is deleted`),expression:Oi.optional().describe("Formula expression (CEL). e.g. F`record.amount * 0.1`"),summaryOperations:D({object:x().describe(`Source child object name for roll-up`),field:x().describe(`Field on child object to aggregate`),function:c([`count`,`sum`,`min`,`max`,`avg`]).describe(`Aggregation function to apply`)}).optional().describe(`Roll-up summary definition`),language:x().optional().describe(`Programming language for syntax highlighting (e.g., javascript, python, sql)`),theme:x().optional().describe(`Code editor theme (e.g., dark, light, monokai)`),lineNumbers:k().optional().describe(`Show line numbers in code editor`),maxRating:h().optional().describe(`Maximum rating value (default: 5)`),allowHalf:k().optional().describe(`Allow half-star ratings`),displayMap:k().optional().describe(`Display map widget for location field`),allowGeocoding:k().optional().describe(`Allow address-to-coordinate conversion`),addressFormat:c([`us`,`uk`,`international`]).optional().describe(`Address format template`),colorFormat:c([`hex`,`rgb`,`rgba`,`hsl`]).optional().describe(`Color value format`),allowAlpha:k().optional().describe(`Allow transparency/alpha channel`),presetColors:N(x()).optional().describe(`Preset color options`),step:h().optional().describe(`Step increment for slider (default: 1)`),showValue:k().optional().describe(`Display current value on slider`),marks:_(x(),x()).optional().describe(`Custom marks/labels at specific values (e.g., {0: "Low", 50: "Medium", 100: "High"})`),barcodeFormat:c([`qr`,`ean13`,`ean8`,`code128`,`code39`,`upca`,`upce`]).optional().describe(`Barcode format type`),qrErrorCorrection:c([`L`,`M`,`Q`,`H`]).optional().describe(`QR code error correction level (L=7%, M=15%, Q=25%, H=30%). Only applicable when barcodeFormat is "qr"`),displayValue:k().optional().describe(`Display human-readable value below barcode/QR code`),allowScanning:k().optional().describe(`Enable camera scanning for barcode/QR code input`),currencyConfig:Ri.optional().describe(`Configuration for currency field type`),vectorConfig:zi.optional().describe(`Configuration for vector field type (AI/ML embeddings)`),fileAttachmentConfig:Bi.optional().describe(`Configuration for file and attachment field types`),encryptionConfig:Ni.optional().describe(`Field-level encryption configuration for sensitive data (GDPR/HIPAA/PCI-DSS)`),maskingRule:Fi.optional().describe(`Data masking rules for PII protection`),auditTrail:k().default(!1).describe(`Enable detailed audit trail for this field (tracks all changes with user and timestamp)`),dependencies:N(x()).optional().describe(`Array of field names that this field depends on (for formulas, visibility rules, etc.)`),cached:Hi.optional().describe(`Caching configuration for computed/formula fields`),dataQuality:Vi.optional().describe(`Data quality validation and monitoring rules`),group:x().optional().describe(`Field group name for organizing fields in forms and layouts (e.g., "contact_info", "billing", "system")`),conditionalRequired:Oi.optional().describe("Predicate (CEL) — field is required when TRUE. e.g. P`record.status == 'closed_won'`"),hidden:k().default(!1).describe(`Hidden from default UI`),readonly:k().default(!1).describe(`Read-only in UI`),system:k().optional().describe(`Auto-injected system/audit field (e.g. created_at, updated_by, organization_id). Tools that surface system fields separately from author-declared business fields should branch on this flag.`),sortable:k().optional().default(!0).describe(`Whether field is sortable in list views`),inlineHelpText:x().optional().describe(`Help text displayed below the field in forms`),trackFeedHistory:k().optional().describe(`Track field changes in Chatter/activity feed (Salesforce pattern)`),caseSensitive:k().optional().describe(`Whether text comparisons are case-sensitive`),autonumberFormat:x().optional().describe(`Auto-number display format pattern (e.g., "CASE-{0000}")`),index:k().default(!1).describe(`Create standard database index`),externalId:k().default(!1).describe(`Is external ID for upsert operations`)})),Wi=D({name:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Unique rule name (snake_case)`),label:x().optional().describe(`Human-readable label for the rule listing`),description:x().optional().describe(`Administrative notes explaining the business reason`),active:k().default(!0),events:N(c([`insert`,`update`,`delete`])).default([`insert`,`update`]).describe(`Validation contexts`),priority:h().int().min(0).max(9999).default(100).describe(`Execution priority (lower runs first, default: 100)`),tags:N(x()).optional().describe(`Categorization tags (e.g., "compliance", "billing")`),severity:c([`error`,`warning`,`info`]).default(`error`),message:x().describe(`Error message to display to the user`)}),Gi=I(()=>Wi.extend({type:M(`script`),condition:Oi.describe("Predicate (CEL). If TRUE, validation fails. e.g. P`record.amount < 0`")})),Ki=I(()=>Wi.extend({type:M(`unique`),fields:N(x()).describe(`Fields that must be combined unique`),scope:Oi.optional().describe("Predicate (CEL) limiting uniqueness scope. e.g. P`record.active == true`"),caseSensitive:k().default(!0)})),qi=I(()=>Wi.extend({type:M(`state_machine`),field:x().describe(`State field (e.g. status)`),transitions:_(x(),N(x())).describe(`Map of { OldState: [AllowedNewStates] }`)})),Ji=I(()=>Wi.extend({type:M(`format`),field:x(),regex:x().optional(),format:c([`email`,`url`,`phone`,`json`]).optional()})),Yi=I(()=>Wi.extend({type:M(`cross_field`),condition:Oi.describe("Predicate (CEL) comparing fields. e.g. P`record.end_date > record.start_date`"),fields:N(x()).describe(`Fields involved in the validation`)})),Xi=I(()=>Wi.extend({type:M(`json_schema`),field:x().describe(`JSON field to validate`),schema:_(x(),w()).describe(`JSON Schema object definition`)})),Zi=I(()=>Wi.extend({type:M(`async`),field:x().describe(`Field to validate`),validatorUrl:x().optional().describe(`External API endpoint for validation`),method:c([`GET`,`POST`]).default(`GET`).describe(`HTTP method for external call`),headers:_(x(),x()).optional().describe(`Custom headers for the request`),validatorFunction:x().optional().describe(`Reference to custom validator function`),timeout:h().optional().default(5e3).describe(`Timeout in milliseconds`),debounce:h().optional().describe(`Debounce delay in milliseconds`),params:_(x(),w()).optional().describe(`Additional parameters to pass to validator`)})),Qi=I(()=>Wi.extend({type:M(`custom`),handler:x().describe(`Name of the custom validation function registered in the system`),params:_(x(),w()).optional().describe(`Parameters passed to the custom handler`)})),$i=A(()=>f(`type`,[Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,ea])),ea=I(()=>Wi.extend({type:M(`conditional`),when:Oi.describe("Predicate (CEL). e.g. P`record.type == 'enterprise'`"),then:$i.describe(`Validation rule to apply when condition is true`),otherwise:$i.optional().describe(`Validation rule to apply when condition is false`)})),ta=I(()=>O([x().describe(`Action Name`),D({type:x(),params:_(x(),w()).optional()})])),na=I(()=>O([x().describe(`Guard Name (e.g., "isManager", "amountGT1000")`),D({type:x(),params:_(x(),w()).optional()})])),ra=I(()=>D({target:x().optional().describe(`Target State ID`),cond:na.optional().describe(`Condition (Guard) required to take this path`),actions:N(ta).optional().describe(`Actions to execute during transition`),description:x().optional().describe(`Human readable description of this rule`)}));I(()=>D({type:x().describe(`Event Type (e.g. "APPROVE", "REJECT", "Submit")`),schema:_(x(),w()).optional().describe(`Expected event payload structure`)}));var ia=A(()=>D({type:c([`atomic`,`compound`,`parallel`,`final`,`history`]).default(`atomic`),entry:N(ta).optional().describe(`Actions to run when entering this state`),exit:N(ta).optional().describe(`Actions to run when leaving this state`),on:_(x(),O([x(),ra,N(ra)])).optional().describe(`Map of Event Type -> Transition Definition`),always:N(ra).optional(),initial:x().optional().describe(`Initial child state (if compound)`),states:_(x(),ia).optional(),meta:D({label:x().optional(),description:x().optional(),color:x().optional(),aiInstructions:x().optional().describe(`Specific instructions for AI when in this state`)}).optional()})),aa=I(()=>D({id:wi.describe(`Unique Machine ID`),description:x().optional(),contextSchema:_(x(),w()).optional().describe(`Zod Schema for the machine context/memory`),initial:x().describe(`Initial State ID`),states:_(x(),ia).describe(`State Nodes`),on:_(x(),O([x(),ra,N(ra)])).optional()}));I(()=>D({key:x().describe(`Translation key (e.g., "views.task_list.label")`),defaultValue:x().optional().describe(`Fallback value when translation key is not found`),params:_(x(),O([x(),h(),k()])).optional().describe(`Interpolation parameters (e.g., { count: 5 })`)}));var oa=I(()=>x().describe(`Display label (plain string; i18n keys are auto-generated by the framework)`)),sa=I(()=>D({ariaLabel:oa.optional().describe(`Accessible label for screen readers (WAI-ARIA aria-label)`),ariaDescribedBy:x().optional().describe(`ID of element providing additional description (WAI-ARIA aria-describedby)`),role:x().optional().describe(`WAI-ARIA role attribute (e.g., "dialog", "navigation", "alert")`)}).describe(`ARIA accessibility attributes`));I(()=>D({key:x().describe(`Translation key`),zero:x().optional().describe(`Zero form (e.g., "No items")`),one:x().optional().describe(`Singular form (e.g., "{count} item")`),two:x().optional().describe(`Dual form (e.g., "{count} items" for exactly 2)`),few:x().optional().describe(`Few form (e.g., for 2-4 in some languages)`),many:x().optional().describe(`Many form (e.g., for 5+ in some languages)`),other:x().describe(`Default plural form (e.g., "{count} items")`)}).describe(`ICU plural rules for a translation key`));var ca=I(()=>D({style:c([`decimal`,`currency`,`percent`,`unit`]).default(`decimal`).describe(`Number formatting style`),currency:x().optional().describe(`ISO 4217 currency code (e.g., "USD", "EUR")`),unit:x().optional().describe(`Unit for unit formatting (e.g., "kilometer", "liter")`),minimumFractionDigits:h().optional().describe(`Minimum number of fraction digits`),maximumFractionDigits:h().optional().describe(`Maximum number of fraction digits`),useGrouping:k().optional().describe(`Whether to use grouping separators (e.g., 1,000)`)}).describe(`Number formatting rules`)),la=I(()=>D({dateStyle:c([`full`,`long`,`medium`,`short`]).optional().describe(`Date display style`),timeStyle:c([`full`,`long`,`medium`,`short`]).optional().describe(`Time display style`),timeZone:x().optional().describe(`IANA time zone (e.g., "America/New_York")`),hour12:k().optional().describe(`Use 12-hour format`)}).describe(`Date/time formatting rules`));I(()=>D({code:x().describe(`BCP 47 language code (e.g., "en-US", "zh-CN")`),fallbackChain:N(x()).optional().describe(`Fallback language codes in priority order (e.g., ["zh-TW", "en"])`),direction:c([`ltr`,`rtl`]).default(`ltr`).describe(`Text direction: left-to-right or right-to-left`),numberFormat:ca.optional().describe(`Default number formatting rules`),dateFormat:la.optional().describe(`Default date/time formatting rules`)}).describe(`Locale configuration`));var ua=c([`api.read`,`api.write`,`crypto.uuid`,`crypto.hash`,`log`]),da=f(`language`,[D({language:M(`expression`),source:x().min(1).describe(`Formula expression source`)}).describe(`L1 expression body — pure formula, no IO`),D({language:M(`js`),source:x().min(1).describe(`Function body source`),capabilities:N(ua).default([]).describe(`Granted capability tokens`),timeoutMs:h().int().positive().max(3e4).optional().describe(`Per-invocation timeout (ms)`),memoryMb:h().int().positive().max(256).optional().describe(`Per-invocation memory cap (MB)`)}).describe(`L2 sandboxed JS body — runs inside an isolated VM with declared capabilities`)]).describe(`Hook/Action body — expression (L1) or sandboxed JS (L2)`),fa=I(()=>D({name:x().optional(),field:wi.optional(),objectOverride:wi.optional(),label:oa.optional(),type:Ii.optional(),required:k().optional().default(!1),options:N(D({label:oa,value:x()})).optional(),placeholder:x().optional(),helpText:x().optional(),defaultValue:w().optional(),defaultFromRow:k().optional()}).refine(e=>!!e.name||!!e.field,{message:`ActionParam requires either "name" or "field"`})),pa=c([`script`,`url`,`modal`,`flow`,`api`,`form`]),ma=new Set(pa.options.filter(e=>e!==`script`)),ha=I(()=>D({name:wi.describe(`Machine name (lowercase snake_case)`),label:oa.describe(`Display label`),objectName:x().regex(/^[a-z_][a-z0-9_]*$/).optional().describe(`Target object this action belongs to. When set, the action is auto-merged into the object's actions array by defineStack().`),icon:x().optional().describe(`Icon name`),locations:N(c([`list_toolbar`,`list_item`,`record_header`,`record_more`,`record_related`,`global_nav`])).optional().describe(`Locations where this action is visible`),component:c([`action:button`,`action:icon`,`action:menu`,`action:group`]).optional().describe(`Visual component override`),type:pa.default(`script`).describe(`Action functionality type`),target:x().optional().describe(`URL, Script Name, Flow ID, or API Endpoint`),body:da.optional().describe("Action body — expression (L1) or sandboxed JS (L2). Only used when type is `script`."),execute:x().optional().describe(`@deprecated — Use target instead. Auto-migrated to target during parsing.`),params:N(fa).optional().describe(`Input parameters required from user`),variant:c([`primary`,`secondary`,`danger`,`ghost`,`link`]).optional().describe(`Button visual variant for styling (primary = highlighted, danger = destructive, ghost = transparent)`),confirmText:oa.optional().describe(`Confirmation message before execution`),successMessage:oa.optional().describe(`Success message to show after execution`),refreshAfter:k().default(!1).describe(`Refresh view after execution`),visible:Oi.optional().describe(`Visibility predicate (CEL).`),disabled:O([k(),Oi]).optional().describe(`Boolean or predicate (CEL) — action is disabled when TRUE.`),shortcut:x().optional().describe(`Keyboard shortcut to trigger this action (e.g., "Ctrl+S")`),bulkEnabled:k().optional().describe(`Whether this action can be applied to multiple selected records`),recordIdParam:x().optional().describe(`Body key to inject the row id into when running from a list_item context.`),recordIdField:x().optional().describe(`Row field whose value seeds recordIdParam. Defaults to "id".`),bodyShape:O([M(`flat`),D({wrap:x()})]).optional().describe(`Body wrapping: flat (default) or { wrap: key } to nest user-collected params under a key.`),method:c([`POST`,`PATCH`,`PUT`,`DELETE`]).optional().describe(`HTTP method for type:"api" actions. Defaults to POST.`),bodyExtra:_(x(),w()).optional().describe(`Constant body fields merged into the API request (applied last; overrides user params).`),mode:c([`create`,`edit`,`delete`,`custom`]).optional().describe(`Semantic mode of the action.`),timeout:h().optional().describe(`Maximum execution time in milliseconds for the action`),aria:sa.optional().describe(`ARIA accessibility attributes`)}).transform(e=>e.execute&&!e.target?{...e,target:e.execute}:e).refine(e=>!(ma.has(e.type)&&!e.target),{message:`Action 'target' is required when type is 'url', 'flow', 'modal', 'api', or 'form'.`,path:[`target`]})),ga=I(()=>D({enabled:k().default(!1).describe(`Enable public sharing`),publicLink:x().optional().describe(`Generated public share URL`),password:x().optional().describe(`Password required to access shared link`),allowedDomains:N(x()).optional().describe(`Restrict access to specific email domains (e.g. ["example.com"])`),expiresAt:x().optional().describe(`Expiration date/time in ISO 8601 format`),allowAnonymous:k().optional().default(!1).describe(`Allow access without authentication`)}));I(()=>D({enabled:k().default(!1).describe(`Enable iframe embedding`),allowedOrigins:N(x()).optional().describe(`Allowed iframe parent origins (e.g. ["https://example.com"])`),width:x().optional().default(`100%`).describe(`Embed width (CSS value)`),height:x().optional().default(`600px`).describe(`Embed height (CSS value)`),showHeader:k().optional().default(!0).describe(`Show interface header in embed`),showNavigation:k().optional().default(!1).describe(`Show navigation in embed`),responsive:k().optional().default(!0).describe(`Enable responsive resizing`)}));var _a=c([`xs`,`sm`,`md`,`lg`,`xl`,`2xl`]),va=I(()=>D({xs:h().min(1).max(12).optional(),sm:h().min(1).max(12).optional(),md:h().min(1).max(12).optional(),lg:h().min(1).max(12).optional(),xl:h().min(1).max(12).optional(),"2xl":h().min(1).max(12).optional()}).describe(`Grid columns per breakpoint (1-12)`)),ya=I(()=>D({xs:h().optional(),sm:h().optional(),md:h().optional(),lg:h().optional(),xl:h().optional(),"2xl":h().optional()}).describe(`Display order per breakpoint`)),ba=I(()=>D({breakpoint:_a.optional().describe(`Minimum breakpoint for visibility`),hiddenOn:N(_a).optional().describe(`Hide on these breakpoints`),columns:va.optional().describe(`Grid columns per breakpoint`),order:ya.optional().describe(`Display order per breakpoint`)}).describe(`Responsive layout configuration`)),xa=I(()=>D({lazyLoad:k().optional().describe(`Enable lazy loading (defer rendering until visible)`),virtualScroll:D({enabled:k().default(!1).describe(`Enable virtual scrolling`),itemHeight:h().optional().describe(`Fixed item height in pixels (for estimation)`),overscan:h().optional().describe(`Number of extra items to render outside viewport`)}).optional().describe(`Virtual scrolling configuration`),cacheStrategy:c([`none`,`cache-first`,`network-first`,`stale-while-revalidate`]).optional().describe(`Client-side data caching strategy`),prefetch:k().optional().describe(`Prefetch data before component is visible`),pageSize:h().optional().describe(`Number of items per page for pagination`),debounceMs:h().optional().describe(`Debounce interval for user interactions in milliseconds`)}).describe(`Performance optimization configuration`)),Sa=c([`GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`HEAD`,`OPTIONS`]),Ca=I(()=>c([`GET`,`POST`,`PUT`,`PATCH`,`DELETE`])),wa=I(()=>D({url:x().describe(`API endpoint URL`),method:Ca.optional().default(`GET`).describe(`HTTP method`),headers:_(x(),x()).optional().describe(`Custom HTTP headers`),params:_(x(),w()).optional().describe(`Query parameters`),body:w().optional().describe(`Request body for POST/PUT/PATCH`)}));I(()=>D({enabled:k().default(!0).describe(`Enable CORS`),origins:O([x(),N(x())]).default(`*`).describe(`Allowed origins (* for all)`),methods:N(Sa).optional().describe(`Allowed HTTP methods`),credentials:k().default(!1).describe(`Allow credentials (cookies, authorization headers)`),maxAge:h().int().optional().describe(`Preflight cache duration in seconds`)})),I(()=>D({enabled:k().default(!1).describe(`Enable rate limiting`),windowMs:h().int().default(6e4).describe(`Time window in milliseconds`),maxRequests:h().int().default(100).describe(`Max requests per window`)})),I(()=>D({path:x().describe(`URL path to serve from`),directory:x().describe(`Physical directory to serve`),cacheControl:x().optional().describe(`Cache-Control header value`)}));var Ta=I(()=>f(`provider`,[D({provider:M(`object`),object:x().describe(`Target object name`)}),D({provider:M(`api`),read:wa.optional().describe(`Configuration for fetching data`),write:wa.optional().describe(`Configuration for submitting data (for forms/editable tables)`)}),D({provider:M(`value`),items:N(w()).describe(`Static data array`)})])),Ea=I(()=>D({field:x().describe(`Field name to filter on`),operator:x().describe(`Filter operator (e.g. equals, not_equals, contains, this_quarter)`),value:O([x(),h(),k(),a(),N(O([x(),h()]))]).optional().describe(`Filter value`)}).describe(`View filter rule`)),Da=I(()=>c([`none`,`count`,`count_empty`,`count_filled`,`count_unique`,`percent_empty`,`percent_filled`,`sum`,`avg`,`min`,`max`]).describe(`Aggregation function for column footer summary`)),Oa=I(()=>D({field:x().describe(`Field name (snake_case)`),label:oa.optional().describe(`Display label override`),width:h().positive().optional().describe(`Column width in pixels`),align:c([`left`,`center`,`right`]).optional().describe(`Text alignment`),hidden:k().optional().describe(`Hide column by default`),sortable:k().optional().describe(`Allow sorting by this column`),resizable:k().optional().describe(`Allow resizing this column`),wrap:k().optional().describe(`Allow text wrapping`),type:x().optional().describe(`Renderer type override (e.g., "currency", "date")`),pinned:c([`left`,`right`]).optional().describe(`Pin/freeze column to left or right side`),summary:Da.optional().describe(`Footer aggregation function for this column`),link:k().optional().describe(`Functions as the primary navigation link (triggers View navigation)`),action:x().optional().describe(`Registered Action ID to execute when clicked`)})),ka=I(()=>D({type:c([`none`,`single`,`multiple`]).default(`none`).describe(`Selection mode`)})),Aa=I(()=>D({pageSize:h().int().positive().default(25).describe(`Number of records per page`),pageSizeOptions:N(h().int().positive()).optional().describe(`Available page size options`)})),ja=I(()=>c([`compact`,`short`,`medium`,`tall`,`extra_tall`]).describe(`Row height / density setting for list view`)),Ma=I(()=>D({field:x().describe(`Field name to group by`),order:c([`asc`,`desc`]).default(`asc`).describe(`Group sort order`),collapsed:k().default(!1).describe(`Collapse groups by default`)})),Na=I(()=>D({fields:N(Ma).min(1).describe(`Fields to group by (supports up to 3 levels)`)}).describe(`Record grouping configuration`)),Pa=I(()=>D({coverField:x().optional().describe(`Attachment/image field to display as card cover`),coverFit:c([`cover`,`contain`]).default(`cover`).describe(`Image fit mode for card cover`),cardSize:c([`small`,`medium`,`large`]).default(`medium`).describe(`Card size in gallery view`),titleField:x().optional().describe(`Field to display as card title`),visibleFields:N(x()).optional().describe(`Fields to display on card body`)}).describe(`Gallery/card view configuration`)),Fa=I(()=>D({startDateField:x().describe(`Field for timeline item start date`),endDateField:x().optional().describe(`Field for timeline item end date`),titleField:x().describe(`Field to display as timeline item title`),groupByField:x().optional().describe(`Field to group timeline rows`),colorField:x().optional().describe(`Field to determine item color`),scale:c([`hour`,`day`,`week`,`month`,`quarter`,`year`]).default(`week`).describe(`Default timeline scale`)}).describe(`Timeline view configuration`)),Ia=I(()=>D({type:c([`personal`,`collaborative`]).default(`collaborative`).describe(`View ownership type`),lockedBy:x().optional().describe(`User who locked the view configuration`)}).describe(`View sharing and access configuration`)),La=I(()=>D({field:x().describe(`Field to derive color from (typically a select/status field)`),colors:_(x(),x()).optional().describe(`Map of field value to color (hex/token)`)}).describe(`Row color configuration based on field values`)),Ra=I(()=>c([`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`map`]).describe(`Visualization type that users can switch to`)),za=I(()=>D({sort:k().default(!0).describe(`Allow users to sort records`),search:k().default(!0).describe(`Allow users to search records`),filter:k().default(!0).describe(`Allow users to filter records`),rowHeight:k().default(!0).describe(`Allow users to toggle row height/density`),addRecordForm:k().default(!1).describe(`Add records through a form instead of inline`),buttons:N(x()).optional().describe(`Custom action button IDs to show in the toolbar`)}).describe(`User action toggles for the view toolbar`)),Ba=I(()=>D({showDescription:k().default(!0).describe(`Show the view description text`),allowedVisualizations:N(Ra).optional().describe(`Whitelist of visualization types users can switch between (e.g. ["grid", "gallery", "kanban"])`)}).describe(`Appearance and visualization configuration`)),Va=I(()=>D({name:wi.describe(`Tab identifier (snake_case)`),label:oa.optional().describe(`Display label`),icon:x().optional().describe(`Tab icon name`),view:x().optional().describe(`Referenced list view name from listViews`),filter:N(Ea).optional().describe(`Tab-specific filter criteria`),order:h().int().min(0).optional().describe(`Tab display order`),pinned:k().default(!1).describe(`Pin tab (cannot be removed by users)`),isDefault:k().default(!1).describe(`Set as the default active tab`),visible:k().default(!0).describe(`Tab visibility`)}).describe(`Tab configuration for multi-tab view interface`)),Ha=I(()=>D({enabled:k().default(!0).describe(`Show the add record entry point`),position:c([`top`,`bottom`,`both`]).default(`bottom`).describe(`Position of the add record button`),mode:c([`inline`,`form`,`modal`]).default(`inline`).describe(`How to add a new record`),formView:x().optional().describe(`Named form view to use when mode is "form" or "modal"`)}).describe(`Add record entry point configuration`)),Ua=I(()=>D({groupByField:x().describe(`Field to group columns by (usually status/select)`),summarizeField:x().optional().describe(`Field to sum at top of column (e.g. amount)`),columns:N(x()).describe(`Fields to show on cards`)})),Wa=I(()=>D({chartType:c([`bar`,`line`,`pie`,`area`,`scatter`]).default(`bar`).describe(`Chart visualisation type`),xAxisField:x().describe(`Field used as the X axis / category dimension`),yAxisFields:N(x()).min(1).describe(`Field(s) used as the Y axis / measures`),aggregation:c([`sum`,`avg`,`count`,`min`,`max`]).optional().describe(`Aggregation function applied to Y axis fields`),groupByField:x().optional().describe(`Optional field used to split / stack the chart`)}).describe(`List chart view configuration`)),Ga=I(()=>D({startDateField:x(),endDateField:x().optional(),titleField:x(),colorField:x().optional()})),Ka=I(()=>D({startDateField:x(),endDateField:x(),titleField:x(),progressField:x().optional(),dependenciesField:x().optional()})),qa=I(()=>c([`page`,`drawer`,`modal`,`split`,`popover`,`new_window`,`none`])),Ja=I(()=>D({mode:qa.default(`page`),view:x().optional().describe(`Name of the form view to use for details (e.g. "summary_view", "edit_form")`),preventNavigation:k().default(!1).describe(`Disable standard navigation entirely`),openNewTab:k().default(!1).describe(`Force open in new tab (applies to page mode)`),width:O([x(),h()]).optional().describe(`Width of the drawer/modal (e.g. "600px", "50%")`)})),Ya=I(()=>D({name:wi.optional().describe(`Internal view name (lowercase snake_case)`),label:oa.optional(),type:c([`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`map`,`chart`]).default(`grid`),data:Ta.optional().describe(`Data source configuration (defaults to "object" provider)`),columns:O([N(x()),N(Oa)]).describe(`Fields to display as columns`),filter:N(Ea).optional().describe(`Filter criteria (JSON Rules)`),sort:O([x(),N(D({field:x(),order:c([`asc`,`desc`])}))]).optional(),searchableFields:N(x()).optional().describe(`Fields enabled for search`),filterableFields:N(x()).optional().describe(`Fields enabled for end-user filtering in the top bar`),resizable:k().optional().describe(`Enable column resizing`),striped:k().optional().describe(`Striped row styling`),bordered:k().optional().describe(`Show borders`),compactToolbar:k().optional().describe(`Collapse Group/Color/Density/Hide-fields into a single View settings popover`),selection:ka.optional().describe(`Row selection configuration`),navigation:Ja.optional().describe(`Configuration for item click navigation (page, drawer, modal, etc.)`),pagination:Aa.optional().describe(`Pagination configuration`),kanban:Ua.optional(),calendar:Ga.optional(),gantt:Ka.optional(),gallery:Pa.optional(),timeline:Fa.optional(),chart:Wa.optional(),description:oa.optional().describe(`View description for documentation/tooltips`),sharing:Ia.optional().describe(`View sharing and access configuration`),rowHeight:ja.optional().describe(`Row height / density setting`),grouping:Na.optional().describe(`Group records by one or more fields`),rowColor:La.optional().describe(`Color rows based on field value`),hiddenFields:N(x()).optional().describe(`Fields to hide in this specific view`),fieldOrder:N(x()).optional().describe(`Explicit field display order for this view`),rowActions:N(x()).optional().describe(`Actions available for individual row items`),bulkActions:N(x()).optional().describe(`Actions available when multiple rows are selected`),bulkActionDefs:N(_(x(),v())).optional().describe(`Rich bulk action definitions (schema-driven, executed via BulkActionDialog)`),virtualScroll:k().optional().describe(`Enable virtual scrolling for large datasets`),conditionalFormatting:N(D({condition:Oi.describe(`Predicate (CEL) to evaluate.`),style:_(x(),x()).describe(`CSS styles to apply when condition is true`)})).optional().describe(`Conditional formatting rules for list rows`),inlineEdit:k().optional().describe(`Allow inline editing of records directly in the list view`),exportOptions:N(c([`csv`,`xlsx`,`pdf`,`json`])).optional().describe(`Available export format options`),userActions:za.optional().describe(`User action toggles for the view toolbar`),appearance:Ba.optional().describe(`Appearance and visualization configuration`),tabs:N(Va).optional().describe(`Tab definitions for multi-tab view interface`),addRecord:Ha.optional().describe(`Add record entry point configuration`),showRecordCount:k().optional().describe(`Show record count at the bottom of the list`),allowPrinting:k().optional().describe(`Allow users to print the view`),emptyState:D({title:oa.optional(),message:oa.optional(),icon:x().optional()}).optional().describe(`Empty state configuration when no records found`),aria:sa.optional().describe(`ARIA accessibility attributes for the list view`),responsive:ba.optional().describe(`Responsive layout configuration`),performance:xa.optional().describe(`Performance optimization settings`)})),Xa=I(()=>D({field:x().describe(`Field name (snake_case)`),label:oa.optional().describe(`Display label override`),placeholder:oa.optional().describe(`Placeholder text`),helpText:oa.optional().describe(`Help/hint text`),readonly:k().optional().describe(`Read-only override`),required:k().optional().describe(`Required override`),hidden:k().optional().describe(`Hidden override`),colSpan:h().int().min(1).max(4).optional().describe(`Column span in grid layout (1-4)`),widget:x().optional().describe(`Custom widget/component name`),dependsOn:x().optional().describe(`Parent field name for cascading`),visibleOn:Oi.optional().describe(`Visibility predicate (CEL).`)})),Za=I(()=>D({label:oa.optional(),collapsible:k().default(!1),collapsed:k().default(!1),columns:O([c([`1`,`2`,`3`,`4`]),M(1),M(2),M(3),M(4)]).default(2).transform(e=>typeof e==`string`?parseInt(e):e),fields:N(O([x(),Xa]))})),Qa=I(()=>D({type:c([`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]).default(`simple`),data:Ta.optional().describe(`Data source configuration (defaults to "object" provider)`),sections:N(Za).optional(),groups:N(Za).optional(),defaultSort:N(D({field:x().describe(`Field name to sort by`),order:c([`asc`,`desc`]).default(`desc`).describe(`Sort direction`)})).optional().describe(`Default sort order for related list views within this form`),sharing:ga.optional().describe(`Public sharing configuration for this form`),submitBehavior:O([D({kind:M(`thank-you`),title:x().optional(),message:x().optional()}),D({kind:M(`redirect`),url:x(),delayMs:h().int().min(0).optional()}),D({kind:M(`continue`)}),D({kind:M(`next-record`)})]).optional().describe(`Post-submit behavior`),aria:sa.optional().describe(`ARIA accessibility attributes for the form view`)}));I(()=>D({list:Ya.optional(),form:Qa.optional(),listViews:_(x(),Ya).optional().describe(`Additional named list views`),formViews:_(x(),Qa).optional().describe(`Additional named form views`)}));var $a=c([`get`,`list`,`create`,`update`,`delete`,`upsert`,`bulk`,`aggregate`,`history`,`search`,`restore`,`purge`,`import`,`export`]),eo=D({trackHistory:k().default(!1).describe(`Enable field history tracking for audit compliance`),searchable:k().default(!0).describe(`Index records for global search`),apiEnabled:k().default(!0).describe(`Expose object via automatic APIs`),apiMethods:N($a).optional().describe(`Whitelist of allowed API operations`),files:k().default(!1).describe(`Enable file attachments and document management`),feeds:k().default(!1).describe(`Enable social feed, comments, and mentions (Chatter-like)`),activities:k().default(!1).describe(`Enable standard tasks and events tracking`),trash:k().default(!0).describe(`Enable soft-delete with restore capability`),mru:k().default(!0).describe(`Track Most Recently Used (MRU) list for users`),clone:k().default(!0).describe(`Allow record deep cloning`)}),to=I(()=>D({name:x().optional().describe(`Index name (auto-generated if not provided)`),fields:N(x()).describe(`Fields included in the index`),type:c([`btree`,`hash`,`gin`,`gist`,`fulltext`]).optional().default(`btree`).describe(`Index algorithm type`),unique:k().optional().default(!1).describe(`Whether the index enforces uniqueness`),partial:x().optional().describe(`Partial index condition (SQL WHERE clause for conditional indexes)`)})),no=I(()=>D({fields:N(x()).describe(`Fields to index for full-text search weighting`),displayFields:N(x()).optional().describe(`Fields to display in search result cards`),filters:N(x()).optional().describe(`Default filters for search results`)})),ro=I(()=>D({enabled:k().describe(`Enable multi-tenancy for this object`),strategy:c([`shared`,`isolated`,`hybrid`]).describe(`Tenant isolation strategy: shared (single DB, row-level), isolated (separate DB per tenant), hybrid (mix)`),tenantField:x().default(`tenant_id`).describe(`Field name for tenant identifier`),crossTenantAccess:k().default(!1).describe(`Allow cross-tenant data access (with explicit permission)`)})),io=I(()=>D({enabled:k().describe(`Enable soft delete (trash/recycle bin)`),field:x().default(`deleted_at`).describe(`Field name for soft delete timestamp`),cascadeDelete:k().default(!1).describe(`Cascade soft delete to related records`)})),ao=I(()=>D({enabled:k().describe(`Enable record versioning`),strategy:c([`snapshot`,`delta`,`event-sourcing`]).describe(`Versioning strategy: snapshot (full copy), delta (changes only), event-sourcing (event log)`),retentionDays:h().min(1).optional().describe(`Number of days to retain old versions (undefined = infinite)`),versionField:x().default(`version`).describe(`Field name for version number/timestamp`)})),oo=I(()=>D({enabled:k().describe(`Enable table partitioning`),strategy:c([`range`,`hash`,`list`]).describe(`Partitioning strategy: range (date ranges), hash (consistent hashing), list (predefined values)`),key:x().describe(`Field name to partition by`),interval:x().optional().describe(`Partition interval for range strategy (e.g., "1 month", "1 year")`)}).refine(e=>!(e.strategy===`range`&&!e.interval),{message:`interval is required when strategy is "range"`})),so=I(()=>D({enabled:k().describe(`Enable Change Data Capture`),events:N(c([`insert`,`update`,`delete`])).describe(`Event types to capture`),destination:x().describe(`Destination endpoint (e.g., "kafka://topic", "webhook://url")`)})),co=I(()=>D({key:x().regex(/^[a-z_][a-z0-9_]*$/,{message:`Field group key must be lowercase snake_case (e.g., "contact_info", "billing", "system")`}).describe(`Group machine key (snake_case). Referenced by Field.group.`),label:x().describe(`Group display label`),icon:x().optional().describe(`Icon name (Lucide/Material) for the group header`),description:x().optional().describe(`Optional description shown under the group header`),defaultExpanded:k().optional().default(!0).describe(`Whether the group is expanded by default`),visibleOn:Oi.optional().describe(`Visibility predicate (CEL); group is hidden when FALSE.`)})),lo=D({name:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Machine unique key (snake_case). Immutable.`),label:x().optional().describe(`Human readable singular label (e.g. "Account")`),pluralLabel:x().optional().describe(`Human readable plural label (e.g. "Accounts")`),description:x().optional().describe(`Developer documentation / description`),icon:x().optional().describe(`Icon name (Lucide/Material) for UI representation`),tags:N(x()).optional().describe(`Categorization tags (e.g. "sales", "system", "reference")`),active:k().optional().default(!0).describe(`Is the object active and usable`),isSystem:k().optional().default(!1).describe(`Is system object (protected from deletion)`),abstract:k().optional().default(!1).describe(`Is abstract base object (cannot be instantiated)`),managedBy:c([`platform`,`config`,`system`,`append-only`,`better-auth`]).optional().describe(`Lifecycle bucket — platform (user CRUD) | config (admin authored) | system (engine-managed) | append-only (audit) | better-auth (identity). UI clients honour the resolved affordance matrix.`),userActions:D({create:k().optional().describe(`Show generic "New" button.`),import:k().optional().describe(`Show CSV import wizard entry.`),edit:k().optional().describe(`Allow inline / form edit of existing rows.`),delete:k().optional().describe(`Show row-level delete + bulk delete.`),exportCsv:k().optional().describe(`Show CSV export entry.`)}).optional().describe(`Per-object override of the resolved CRUD affordance matrix.`),systemFields:O([M(!1),D({tenant:k().optional().describe(`Inject organization_id (multi-tenant only). Default true.`),owner:k().optional().describe(`Reserved for future owner_id auto-injection.`),audit:k().optional().describe(`Reserved for future created_by/updated_by auto-injection.`)})]).optional().describe(`Opt out of, or selectively disable, registry-level system-field auto-injection.`),datasource:x().optional().default(`default`).describe(`Target Datasource ID. "default" is the primary DB.`),fields:_(x().regex(/^[a-z_][a-z0-9_]*$/,{message:`Field names must be lowercase snake_case (e.g., "first_name", "company", "annual_revenue")`}),Ui).describe(`Field definitions map. Keys must be snake_case identifiers.`),indexes:N(to).optional().describe(`Database performance indexes`),fieldGroups:N(co).refine(e=>new Set(e.map(e=>e.key)).size===e.length,{message:`fieldGroups[].key must be unique within an object`}).optional().describe(`Ordered list of field groups (array order = display order). See ObjectFieldGroupSchema.`),tenancy:ro.optional().describe(`Multi-tenancy configuration for SaaS applications`),softDelete:io.optional().describe(`Soft delete (trash/recycle bin) configuration`),versioning:ao.optional().describe(`Record versioning and history tracking configuration`),partitioning:oo.optional().describe(`Table partitioning configuration for performance`),cdc:so.optional().describe(`Change Data Capture (CDC) configuration for real-time data streaming`),validations:N($i).optional().describe(`Object-level validation rules`),stateMachines:_(x(),aa).optional().describe(`Named state machines for parallel lifecycles (e.g., status, payment, approval)`),displayNameField:x().optional().describe(`Field to use as the record display name (e.g., "name", "title"). Defaults to "name" if present.`),recordName:D({type:c([`text`,`autonumber`]).describe(`Record name type: text (user-entered) or autonumber (system-generated)`),displayFormat:x().optional().describe(`Auto-number format pattern (e.g., "CASE-{0000}", "INV-{YYYY}-{0000}")`),startNumber:h().int().min(0).optional().describe(`Starting number for autonumber (default: 1)`)}).optional().describe(`Record name generation configuration (Salesforce pattern)`),titleFormat:ki.optional().describe(`Title template — supports {{record.field}} interpolation. Overrides displayNameField.`),compactLayout:N(x()).optional().describe(`Primary fields for hover/cards/lookups`),listViews:_(x(),Ya).optional().describe(`Built-in named list views (segmented tabs) shipped with the object schema`),defaultDetailForm:x().optional().describe(`Name of the default FormView for record detail / edit screens`),search:no.optional().describe(`Search engine configuration`),enable:eo.optional().describe(`Enabled system features modules`),recordTypes:N(x()).optional().describe(`Record type names for this object`),sharingModel:c([`private`,`read`,`read_write`,`full`]).optional().describe(`Default sharing model`),keyPrefix:x().max(5).optional().describe(`Short prefix for record IDs (e.g., "001" for Account)`),detail:D({renderViaSchema:k().optional().describe(`Opt this object out of the schema-driven detail renderer`),hideReferenceRail:k().optional().describe(`Suppress the right-hand reference-rail on the detail page`),hideRelatedTab:k().optional().describe(`Suppress the Related tab on the detail page`)}).passthrough().optional().describe(`Detail-page UI hints consumed by @object-ui/plugin-detail synth`),actions:N(ha).optional().describe(`Actions associated with this object (auto-populated from top-level actions via objectName)`)});function uo(e){return e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}I(()=>Object.assign(lo,{create:e=>{let t={...e,label:e.label??uo(e.name)};return lo.parse(t)}})),c([`own`,`extend`]),I(()=>D({extend:x().describe(`Target object name (FQN) to extend`),fields:_(x(),Ui).optional().describe(`Fields to add/override`),label:x().optional().describe(`Override label for the extended object`),pluralLabel:x().optional().describe(`Override plural label for the extended object`),description:x().optional().describe(`Override description for the extended object`),validations:N($i).optional().describe(`Additional validation rules to merge into the target object`),indexes:N(to).optional().describe(`Additional indexes to merge into the target object`),priority:h().int().min(0).max(999).default(200).describe(`Merge priority (higher = applied later)`)}));var fo=c([`beforeFind`,`afterFind`,`beforeFindOne`,`afterFindOne`,`beforeCount`,`afterCount`,`beforeAggregate`,`afterAggregate`,`beforeInsert`,`afterInsert`,`beforeUpdate`,`afterUpdate`,`beforeDelete`,`afterDelete`,`beforeUpdateMany`,`afterUpdateMany`,`beforeDeleteMany`,`afterDeleteMany`]);I(()=>D({name:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Hook unique name (snake_case)`),label:x().optional().describe(`Description of what this hook does`),object:O([x(),N(x())]).describe(`Target object(s)`),events:N(fo).describe(`Lifecycle events`),handler:O([x(),se(e=>typeof e==`function`,{message:`Expected function`})]).optional().describe("Handler function name (string, post-build) or inline function (pre-build) — DEPRECATED, prefer `body`"),body:da.optional().describe(`Hook body — expression (L1) or sandboxed JS (L2)`),priority:h().default(100).describe(`Execution priority`),async:k().default(!1).describe(`Run specifically as fire-and-forget`),condition:Oi.optional().describe('Predicate (CEL); hook runs only when TRUE. e.g. P`record.status == "closed" && record.amount > 1000`'),description:x().optional().describe(`Human-readable description of what this hook does`),retryPolicy:D({maxRetries:h().default(3).describe(`Maximum retry attempts on failure`),backoffMs:h().default(1e3).describe(`Backoff delay between retries in milliseconds`)}).optional().describe(`Retry policy for failed hook executions`),timeout:h().optional().describe(`Maximum execution time in milliseconds before the hook is aborted`),onError:c([`abort`,`log`]).default(`abort`).describe(`Error handling strategy`)})),I(()=>D({id:x().optional().describe(`Unique execution ID for tracing`),object:x(),event:fo,input:_(x(),w()).describe(`Mutable input parameters`),result:w().optional().describe(`Operation result (After hooks only)`),previous:_(x(),w()).optional().describe(`Record state before operation`),session:D({userId:x().optional(),tenantId:x().optional(),roles:N(x()).optional(),accessToken:x().optional(),isSystem:k().optional().describe(`True when the call was made with an elevated system context (engine self-writes)`)}).optional().describe(`Current session context`),transaction:w().optional().describe(`Database transaction handle`),ql:w().describe(`ObjectQL Engine Reference`),api:w().optional().describe(`Cross-object data access (ScopedContext)`),user:D({id:x().optional(),name:x().optional(),email:x().optional()}).optional().describe(`Current user info shortcut`)}));var po=c([`none`,`constant`,`lookup`,`split`,`join`,`javascript`,`map`]),mo=I(()=>D({source:O([x(),N(x())]).describe(`Source column header(s)`),target:O([x(),N(x())]).describe(`Target object field(s)`),transform:po.default(`none`),params:D({value:w().optional(),object:x().optional(),fromField:x().optional(),toField:x().optional(),autoCreate:k().optional(),valueMap:_(x(),w()).optional(),separator:x().optional()}).optional()}));I(()=>D({name:wi.describe(`Mapping unique name (lowercase snake_case)`),label:x().optional(),sourceFormat:c([`csv`,`json`,`xml`,`sql`]).default(`csv`),targetObject:x().describe(`Target Object Name`),fieldMapping:N(mo),mode:c([`insert`,`update`,`upsert`]).default(`insert`),upsertKey:N(x()).optional().describe(`Fields to match for upsert (e.g. email)`),extractQuery:Si.optional().describe(`Query to run for export only`),errorPolicy:c([`skip`,`abort`,`retry`]).default(`skip`),batchSize:h().default(1e3)}));var ho=I(()=>D({userId:x().optional(),tenantId:x().optional(),roles:N(x()).default([]),permissions:N(x()).default([]),org_user_ids:N(x()).optional(),isSystem:k().default(!1),accessToken:x().optional(),transaction:w().optional(),traceId:x().optional()})),go=I(()=>O([_(x(),w()),ni]).describe(`Data Engine query filter conditions`)),_o=I(()=>O([_(x(),c([`asc`,`desc`])),_(x(),O([M(1),M(-1)])),N(ci)]).describe(`Sort order definition`)),vo=I(()=>D({context:ho.optional()})),yo=I(()=>vo.extend({where:O([_(x(),w()),ni]).optional(),fields:N(yi).optional(),orderBy:N(ci).optional(),limit:h().optional(),offset:h().optional(),top:h().optional(),cursor:_(x(),w()).optional(),search:bi.optional(),expand:A(()=>_(x(),Si)).optional(),distinct:k().optional()}).describe(`QueryAST-aligned query options for IDataEngine.find() operations`));I(()=>vo.extend({filter:go.optional(),select:N(x()).optional(),sort:_o.optional(),limit:h().int().min(1).optional(),skip:h().int().min(0).optional(),top:h().int().min(1).optional(),populate:N(x()).optional()}).describe(`Query options for IDataEngine.find() operations`));var bo=I(()=>vo.extend({returning:k().default(!0).optional()}).describe(`Options for DataEngine.insert operations`)),xo=I(()=>vo.extend({where:O([_(x(),w()),ni]).optional(),upsert:k().default(!1).optional(),multi:k().default(!1).optional(),returning:k().default(!1).optional()}).describe(`QueryAST-aligned options for DataEngine.update operations`));I(()=>vo.extend({filter:go.optional(),upsert:k().default(!1).optional(),multi:k().default(!1).optional(),returning:k().default(!1).optional()}).describe(`Options for DataEngine.update operations`));var So=I(()=>vo.extend({where:O([_(x(),w()),ni]).optional(),multi:k().default(!1).optional()}).describe(`QueryAST-aligned options for DataEngine.delete operations`));I(()=>vo.extend({filter:go.optional(),multi:k().default(!1).optional()}).describe(`Options for DataEngine.delete operations`));var Co=I(()=>vo.extend({where:O([_(x(),w()),ni]).optional(),groupBy:N(x()).optional(),aggregations:N(fi).optional()}).describe(`QueryAST-aligned options for DataEngine.aggregate operations`));I(()=>vo.extend({filter:go.optional(),groupBy:N(x()).optional(),aggregations:N(D({field:x(),method:c([`count`,`sum`,`avg`,`min`,`max`,`count_distinct`]),alias:x().optional()})).optional()}).describe(`Options for DataEngine.aggregate operations`));var wo=I(()=>vo.extend({where:O([_(x(),w()),ni]).optional()}).describe(`QueryAST-aligned options for DataEngine.count operations`));I(()=>vo.extend({filter:go.optional()}).describe(`Options for DataEngine.count operations`)),I(()=>D({find:l().input(j([x(),yo.optional()])).output(P(N(w()))),findOne:l().input(j([x(),yo.optional()])).output(P(w())),insert:l().input(j([x(),O([_(x(),w()),N(_(x(),w()))]),bo.optional()])).output(P(w())),update:l().input(j([x(),_(x(),w()),xo.optional()])).output(P(w())),delete:l().input(j([x(),So.optional()])).output(P(w())),count:l().input(j([x(),wo.optional()])).output(P(h())),aggregate:l().input(j([x(),Co])).output(P(N(w())))}).describe(`Standard Data Engine Contract`));var To={filter:go.optional()},Eo=yo.extend({...To,select:N(x()).optional(),sort:_o.optional(),skip:h().int().min(0).optional(),populate:N(x()).optional()}),Do=I(()=>D({method:M(`find`),object:x(),query:Eo.optional()})),Oo=I(()=>D({method:M(`findOne`),object:x(),query:Eo.optional()})),ko=I(()=>D({method:M(`insert`),object:x(),data:O([_(x(),w()),N(_(x(),w()))]),options:bo.optional()})),Ao=I(()=>D({method:M(`update`),object:x(),data:_(x(),w()),id:O([x(),h()]).optional().describe(`ID for single update, or use where in options`),options:xo.extend(To).optional()})),jo=I(()=>D({method:M(`delete`),object:x(),id:O([x(),h()]).optional().describe(`ID for single delete, or use where in options`),options:So.extend(To).optional()})),Mo=I(()=>D({method:M(`count`),object:x(),query:wo.extend(To).optional()})),No=I(()=>D({method:M(`aggregate`),object:x(),query:Co.extend(To)})),Po=I(()=>D({method:M(`execute`),command:w(),options:_(x(),w()).optional()})),Fo=I(()=>D({method:M(`vectorFind`),object:x(),vector:N(h()),where:O([_(x(),w()),ni]).optional(),fields:N(x()).optional(),limit:h().int().default(5).optional(),threshold:h().optional()})),Io=I(()=>D({method:M(`batch`),requests:N(f(`method`,[Do,Oo,ko,Ao,jo,Mo,No,Po,Fo])),transaction:k().default(!0).optional()}));I(()=>f(`method`,[Do,Oo,ko,Ao,jo,Mo,No,Io,Po,Fo]).describe(`Virtual ObjectQL Request Protocol`)),c([`count`,`sum`,`avg`,`min`,`max`,`count_distinct`,`percentile`,`median`,`stddev`,`variance`]).describe(`Standard aggregation functions`);var Lo=c([`asc`,`desc`]).describe(`Sort order direction`);I(()=>D({field:x().describe(`Field name to sort by`),order:Lo.describe(`Sort direction`)}).describe(`Sort field and direction pair`)),c([`insert`,`update`,`delete`,`upsert`]).describe(`Data mutation event types`);var Ro=c([`read_uncommitted`,`read_committed`,`repeatable_read`,`serializable`,`snapshot`]).describe(`Transaction isolation levels (snake_case standard)`);c([`lru`,`lfu`,`ttl`,`fifo`]).describe(`Cache eviction strategy`);var zo=I(()=>D({transaction:w().optional().describe(`Transaction handle`),timeout:h().optional().describe(`Timeout in ms`),skipCache:k().optional().describe(`Bypass cache`),traceContext:_(x(),x()).optional().describe(`OpenTelemetry context or request ID`),tenantId:x().optional().describe(`Tenant Isolation identifier`)})),Bo=I(()=>D({create:k().default(!0).describe(`Supports CREATE operations`),read:k().default(!0).describe(`Supports READ operations`),update:k().default(!0).describe(`Supports UPDATE operations`),delete:k().default(!0).describe(`Supports DELETE operations`),bulkCreate:k().default(!1).describe(`Supports bulk CREATE operations`),bulkUpdate:k().default(!1).describe(`Supports bulk UPDATE operations`),bulkDelete:k().default(!1).describe(`Supports bulk DELETE operations`),transactions:k().default(!1).describe(`Supports ACID transactions`),savepoints:k().default(!1).describe(`Supports transaction savepoints`),isolationLevels:N(Ro).optional().describe(`Supported isolation levels`),queryFilters:k().default(!0).describe(`Supports WHERE clause filtering`),queryAggregations:k().default(!1).describe(`Supports GROUP BY and aggregation functions`),queryDateGranularity:_(ui,k()).optional().describe(`Per-granularity native date bucketing (day/week/month/quarter/year). Missing keys fall back to in-memory bucketing.`),querySorting:k().default(!0).describe(`Supports ORDER BY sorting`),queryPagination:k().default(!0).describe(`Supports LIMIT/OFFSET pagination`),queryWindowFunctions:k().default(!1).describe(`Supports window functions with OVER clause`),querySubqueries:k().default(!1).describe(`Supports subqueries`),queryCTE:k().default(!1).describe(`Supports Common Table Expressions (WITH clause)`),joins:k().default(!1).describe(`Supports SQL joins`),fullTextSearch:k().default(!1).describe(`Supports full-text search`),jsonQuery:k().default(!1).describe(`Supports JSON field querying`),geospatialQuery:k().default(!1).describe(`Supports geospatial queries`),streaming:k().default(!1).describe(`Supports result streaming (cursors/iterators)`),jsonFields:k().default(!1).describe(`Supports JSON field types`),arrayFields:k().default(!1).describe(`Supports array field types`),vectorSearch:k().default(!1).describe(`Supports vector embeddings and similarity search`),schemaSync:k().default(!1).describe(`Supports automatic schema synchronization`),batchSchemaSync:k().default(!1).describe(`Supports batched schema sync to reduce schema DDL round-trips`),migrations:k().default(!1).describe(`Supports database migrations`),indexes:k().default(!1).describe(`Supports index creation and management`),connectionPooling:k().default(!1).describe(`Supports connection pooling`),preparedStatements:k().default(!1).describe(`Supports prepared statements (SQL injection prevention)`),queryCache:k().default(!1).describe(`Supports query result caching`)}));I(()=>D({name:x().describe(`Driver unique name`),version:x().describe(`Driver version`),supports:Bo,connect:l().input(j([])).output(P(n())).describe(`Establish connection`),disconnect:l().input(j([])).output(P(n())).describe(`Close connection`),checkHealth:l().input(j([])).output(P(k())).describe(`Health check`),getPoolStats:l().input(j([])).output(D({total:h(),idle:h(),active:h(),waiting:h()}).optional()).optional().describe(`Get connection pool statistics`),execute:l().input(j([w(),N(w()).optional(),zo.optional()])).output(P(w())).describe(`Execute raw command`),find:l().input(j([x(),Si,zo.optional()])).output(P(N(_(x(),w())))).describe(`Find records`),findStream:l().input(j([x(),Si,zo.optional()])).output(w()).describe(`Stream records (AsyncIterable)`),findOne:l().input(j([x(),Si,zo.optional()])).output(P(_(x(),w()).nullable())).describe(`Find one record`),create:l().input(j([x(),_(x(),w()),zo.optional()])).output(P(_(x(),w()))).describe(`Create record`),update:l().input(j([x(),x().or(h()),_(x(),w()),zo.optional()])).output(P(_(x(),w()))).describe(`Update record`),upsert:l().input(j([x(),_(x(),w()),N(x()).optional(),zo.optional()])).output(P(_(x(),w()))).describe(`Upsert record`),delete:l().input(j([x(),x().or(h()),zo.optional()])).output(P(k())).describe(`Delete record`),count:l().input(j([x(),Si.optional(),zo.optional()])).output(P(h())).describe(`Count records`),bulkCreate:l().input(j([x(),N(_(x(),w())),zo.optional()])).output(P(N(_(x(),w())))),bulkUpdate:l().input(j([x(),N(D({id:x().or(h()),data:_(x(),w())})),zo.optional()])).output(P(N(_(x(),w())))),bulkDelete:l().input(j([x(),N(x().or(h())),zo.optional()])).output(P(n())),updateMany:l().input(j([x(),Si,_(x(),w()),zo.optional()])).output(P(h())).optional(),deleteMany:l().input(j([x(),Si,zo.optional()])).output(P(h())).optional(),beginTransaction:l().input(j([D({isolationLevel:Ro.optional()}).optional()])).output(P(w())).describe(`Start transaction`),commit:l().input(j([w()])).output(P(n())).describe(`Commit transaction`),rollback:l().input(j([w()])).output(P(n())).describe(`Rollback transaction`),syncSchema:l().input(j([x(),w(),zo.optional()])).output(P(n())).describe(`Sync object schema to DB`),syncSchemasBatch:l().input(j([N(D({object:x(),schema:w()})),zo.optional()])).output(P(n())).optional().describe(`Batch sync multiple schemas in one round-trip`),dropTable:l().input(j([x(),zo.optional()])).output(P(n())),explain:l().input(j([x(),Si,zo.optional()])).output(P(w())).optional()}));var Vo=I(()=>D({min:h().min(0).default(2).describe(`Minimum number of connections in pool`),max:h().min(1).default(10).describe(`Maximum number of connections in pool`),idleTimeoutMillis:h().min(0).default(3e4).describe(`Time in ms before idle connection is closed`),connectionTimeoutMillis:h().min(0).default(5e3).describe(`Time in ms to wait for available connection`)})),Ho=I(()=>D({name:x().describe(`Driver instance name`),type:c([`sql`,`nosql`,`cache`,`search`,`graph`,`timeseries`]).describe(`Driver type category`),capabilities:Bo.describe(`Driver capability flags`),connectionString:x().optional().describe(`Database connection string (driver-specific format)`),poolConfig:Vo.optional().describe(`Connection pool configuration`)})),Uo=I(()=>c([`postgresql`,`mysql`,`sqlite`,`mssql`,`oracle`,`mariadb`])),Wo=I(()=>D({text:x().describe(`SQL type for text fields (e.g., VARCHAR, TEXT)`),number:x().describe(`SQL type for number fields (e.g., NUMERIC, DECIMAL, INT)`),boolean:x().describe(`SQL type for boolean fields (e.g., BOOLEAN, BIT)`),date:x().describe(`SQL type for date fields (e.g., DATE)`),datetime:x().describe(`SQL type for datetime fields (e.g., TIMESTAMP, DATETIME)`),json:x().optional().describe(`SQL type for JSON fields (e.g., JSON, JSONB)`),uuid:x().optional().describe(`SQL type for UUID fields (e.g., UUID, CHAR(36))`),binary:x().optional().describe(`SQL type for binary fields (e.g., BLOB, BYTEA)`)})),Go=I(()=>D({rejectUnauthorized:k().default(!0).describe(`Reject connections with invalid certificates`),ca:x().optional().describe(`CA certificate file path or content`),cert:x().optional().describe(`Client certificate file path or content`),key:x().optional().describe(`Client private key file path or content`)}).refine(e=>e.cert!==void 0==(e.key!==void 0),{message:`Client certificate (cert) and private key (key) must be provided together`}));I(()=>Ho.extend({type:M(`sql`).describe(`Driver type must be "sql"`),dialect:Uo.describe(`SQL database dialect`),dataTypeMapping:Wo.describe(`SQL data type mapping configuration`),ssl:k().default(!1).describe(`Enable SSL/TLS connection`),sslConfig:Go.optional().describe(`SSL/TLS configuration (required when ssl is true)`)}).refine(e=>!(e.ssl&&!e.sslConfig),{message:`sslConfig is required when ssl is true`}));var Ko=I(()=>c([`mongodb`,`couchdb`,`dynamodb`,`cassandra`,`redis`,`elasticsearch`,`neo4j`,`orientdb`]));I(()=>c([`find`,`findOne`,`insert`,`update`,`delete`,`aggregate`,`mapReduce`,`count`,`distinct`,`createIndex`,`dropIndex`]));var qo=I(()=>c([`all`,`quorum`,`one`,`local_quorum`,`each_quorum`,`eventual`])),Jo=I(()=>c([`single`,`compound`,`unique`,`text`,`geospatial`,`hashed`,`ttl`,`sparse`])),Yo=I(()=>D({enabled:k().default(!1).describe(`Enable sharding`),shardKey:x().optional().describe(`Field to use as shard key`),shardingStrategy:c([`hash`,`range`,`zone`]).optional().describe(`Sharding strategy`),numShards:h().int().positive().optional().describe(`Number of shards`)})),Xo=I(()=>D({enabled:k().default(!1).describe(`Enable replication`),replicaSetName:x().optional().describe(`Replica set name`),replicas:h().int().positive().optional().describe(`Number of replicas`),readPreference:c([`primary`,`primaryPreferred`,`secondary`,`secondaryPreferred`,`nearest`]).optional().describe(`Read preference for replica set`),writeConcern:c([`majority`,`acknowledged`,`unacknowledged`]).optional().describe(`Write concern level`)})),Zo=I(()=>D({enabled:k().default(!1).describe(`Enable schema validation`),validationLevel:c([`strict`,`moderate`,`off`]).optional().describe(`Validation strictness`),validationAction:c([`error`,`warn`]).optional().describe(`Action on validation failure`),jsonSchema:_(x(),w()).optional().describe(`JSON Schema for validation`)})),Qo=I(()=>D({text:x().describe(`NoSQL type for text fields`),number:x().describe(`NoSQL type for number fields`),boolean:x().describe(`NoSQL type for boolean fields`),date:x().describe(`NoSQL type for date fields`),datetime:x().describe(`NoSQL type for datetime fields`),json:x().optional().describe(`NoSQL type for JSON/object fields`),uuid:x().optional().describe(`NoSQL type for UUID fields`),binary:x().optional().describe(`NoSQL type for binary fields`),array:x().optional().describe(`NoSQL type for array fields`),objectId:x().optional().describe(`NoSQL type for ObjectID fields (MongoDB)`),geopoint:x().optional().describe(`NoSQL type for geospatial point fields`)}));I(()=>Ho.extend({type:M(`nosql`).describe(`Driver type must be "nosql"`),databaseType:Ko.describe(`Specific NoSQL database type`),dataTypeMapping:Qo.describe(`NoSQL data type mapping configuration`),consistency:qo.optional().describe(`Consistency level for operations`),replication:Xo.optional().describe(`Replication configuration`),sharding:Yo.optional().describe(`Sharding configuration`),schemaValidation:Zo.optional().describe(`Document schema validation`),region:x().optional().describe(`AWS region (for managed NoSQL services)`),accessKeyId:x().optional().describe(`AWS access key ID`),secretAccessKey:x().optional().describe(`AWS secret access key`),ttlField:x().optional().describe(`Field name for TTL (auto-deletion)`),maxDocumentSize:h().int().positive().optional().describe(`Maximum document size in bytes`),collectionPrefix:x().optional().describe(`Prefix for collection/table names`)}));var $o=I(()=>D({consistency:qo.optional().describe(`Consistency level override`),readFromSecondary:k().optional().describe(`Allow reading from secondary replicas`),projection:_(x(),O([M(0),M(1)])).optional().describe(`Field projection`),timeout:h().int().positive().optional().describe(`Query timeout (ms)`),useCursor:k().optional().describe(`Use cursor instead of loading all results`),batchSize:h().int().positive().optional().describe(`Cursor batch size`),profile:k().optional().describe(`Enable query profiling`),hint:x().optional().describe(`Index hint for query optimization`)})),es=I(()=>D({operator:x().describe(`Aggregation operator (e.g., $match, $group, $sort)`),options:_(x(),w()).describe(`Stage-specific options`)}));I(()=>D({collection:x().describe(`Collection/table name`),stages:N(es).describe(`Aggregation pipeline stages`),options:$o.optional().describe(`Query options`)})),I(()=>D({name:x().describe(`Index name`),type:Jo.describe(`Index type`),fields:N(D({field:x().describe(`Field name`),order:c([`asc`,`desc`,`text`,`2dsphere`]).optional().describe(`Index order or type`)})).describe(`Fields to index`),unique:k().default(!1).describe(`Enforce uniqueness`),sparse:k().default(!1).describe(`Sparse index`),expireAfterSeconds:h().int().positive().optional().describe(`TTL in seconds`),partialFilterExpression:_(x(),w()).optional().describe(`Partial index filter`),background:k().default(!1).describe(`Create index in background`)})),I(()=>D({readConcern:c([`local`,`majority`,`linearizable`,`snapshot`]).optional().describe(`Read concern level`),writeConcern:c([`majority`,`acknowledged`,`unacknowledged`]).optional().describe(`Write concern level`),readPreference:c([`primary`,`primaryPreferred`,`secondary`,`secondaryPreferred`,`nearest`]).optional().describe(`Read preference`),maxCommitTimeMS:h().int().positive().optional().describe(`Transaction commit timeout (ms)`)}));var ts=c([`insert`,`update`,`upsert`,`replace`,`ignore`]),ns=I(()=>D({object:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Target Object Name`),externalId:x().default(`name`).describe(`Field match for uniqueness check`),mode:ts.default(`upsert`).describe(`Conflict resolution strategy`),env:N(c([`prod`,`dev`,`test`])).default([`prod`,`dev`,`test`]).describe(`Applicable environments`),records:N(_(x(),w())).describe(`Data records`)})),rs=I(()=>D({field:x().describe(`Source field name containing the reference value`),targetObject:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Target object name (snake_case)`),targetField:x().default(`name`).describe(`Field on target object used for matching`),fieldType:c([`lookup`,`master_detail`]).describe(`Relationship field type`)}).describe(`Describes how a field reference is resolved during seed loading`)),is=I(()=>D({object:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Object name (snake_case)`),dependsOn:N(x()).describe(`Objects this object depends on`),references:N(rs).describe(`Field-level reference details`)}).describe(`Object node in the seed data dependency graph`)),as=I(()=>D({nodes:N(is).describe(`All objects in the dependency graph`),insertOrder:N(x()).describe(`Topologically sorted insert order`),circularDependencies:N(N(x())).default([]).describe(`Circular dependency chains (e.g., [["a", "b", "a"]])`)}).describe(`Complete object dependency graph for seed data loading`)),os=I(()=>D({sourceObject:x().describe(`Object with the broken reference`),field:x().describe(`Field name with unresolved reference`),targetObject:x().describe(`Target object searched for the reference`),targetField:x().describe(`ExternalId field used for matching`),attemptedValue:w().describe(`Value that failed to resolve`),recordIndex:h().int().min(0).describe(`Index of the record in the dataset`),message:x().describe(`Human-readable error description`)}).describe(`Actionable error for a failed reference resolution`)),ss=I(()=>D({dryRun:k().default(!1).describe(`Validate references without writing data`),haltOnError:k().default(!1).describe(`Stop on first reference resolution error`),multiPass:k().default(!0).describe(`Enable multi-pass loading for circular dependencies`),defaultMode:ts.default(`upsert`).describe(`Default conflict resolution strategy`),batchSize:h().int().min(1).default(1e3).describe(`Maximum records per batch insert/upsert`),transaction:k().default(!1).describe(`Wrap entire load in a transaction (all-or-nothing)`),env:c([`prod`,`dev`,`test`]).optional().describe(`Only load datasets matching this environment`),organizationId:x().min(1).optional().describe(`Target organization id for per-tenant seed replay`)}).describe(`Seed data loader configuration`)),cs=I(()=>D({object:x().describe(`Object that was loaded`),mode:ts.describe(`Import mode used`),inserted:h().int().min(0).describe(`Records inserted`),updated:h().int().min(0).describe(`Records updated`),skipped:h().int().min(0).describe(`Records skipped`),errored:h().int().min(0).describe(`Records with errors`),total:h().int().min(0).describe(`Total records in dataset`),referencesResolved:h().int().min(0).describe(`References resolved via externalId`),referencesDeferred:h().int().min(0).describe(`References deferred to second pass`),errors:N(os).default([]).describe(`Reference resolution errors`)}).describe(`Result of loading a single dataset`));I(()=>D({success:k().describe(`Overall success status`),dryRun:k().describe(`Whether this was a dry-run`),dependencyGraph:as.describe(`Object dependency graph`),results:N(cs).describe(`Per-object load results`),errors:N(os).describe(`All reference resolution errors`),summary:D({objectsProcessed:h().int().min(0).describe(`Total objects processed`),totalRecords:h().int().min(0).describe(`Total records across all objects`),totalInserted:h().int().min(0).describe(`Total records inserted`),totalUpdated:h().int().min(0).describe(`Total records updated`),totalSkipped:h().int().min(0).describe(`Total records skipped`),totalErrored:h().int().min(0).describe(`Total records with errors`),totalReferencesResolved:h().int().min(0).describe(`Total references resolved`),totalReferencesDeferred:h().int().min(0).describe(`Total references deferred`),circularDependencyCount:h().int().min(0).describe(`Circular dependency chains detected`),durationMs:h().min(0).describe(`Load duration in milliseconds`)}).describe(`Summary statistics`)}).describe(`Complete seed loader result`)),I(()=>D({datasets:N(ns).min(1).describe(`Datasets to load`),config:ss.default(()=>ss.parse({})).describe(`Loader configuration`)}).describe(`Seed loader request with datasets and configuration`));var ls=I(()=>D({versionNumber:h().describe(`Version number`),createdAt:h().describe(`Creation timestamp`),createdBy:x().describe(`Creator user ID`),size:h().describe(`File size in bytes`),checksum:x().describe(`File checksum`),downloadUrl:x().url().describe(`Download URL`),isLatest:k().optional().default(!1).describe(`Is latest version`)})),us=I(()=>D({id:x().describe(`Template ID`),name:x().describe(`Template name`),description:x().optional().describe(`Template description`),fileUrl:x().url().describe(`Template file URL`),fileType:x().describe(`File MIME type`),placeholders:N(D({key:x().describe(`Placeholder key`),label:x().describe(`Placeholder label`),type:c([`text`,`number`,`date`,`image`]).describe(`Placeholder type`),required:k().optional().default(!1).describe(`Is required`)})).describe(`Template placeholders`)})),ds=I(()=>D({provider:c([`docusign`,`adobe-sign`,`hellosign`,`custom`]).describe(`E-signature provider`),enabled:k().optional().default(!1).describe(`E-signature enabled`),signers:N(D({email:x().email().describe(`Signer email`),name:x().describe(`Signer name`),role:x().describe(`Signer role`),order:h().describe(`Signing order`)})).describe(`Document signers`),expirationDays:h().optional().default(30).describe(`Expiration days`),reminderDays:h().optional().default(7).describe(`Reminder interval days`)}));I(()=>D({id:x().describe(`Document ID`),name:x().describe(`Document name`),description:x().optional().describe(`Document description`),fileType:x().describe(`File MIME type`),fileSize:h().describe(`File size in bytes`),category:x().optional().describe(`Document category`),tags:N(x()).optional().describe(`Document tags`),versioning:D({enabled:k().describe(`Versioning enabled`),versions:N(ls).describe(`Version history`),majorVersion:h().describe(`Major version`),minorVersion:h().describe(`Minor version`)}).optional().describe(`Version control`),template:us.optional().describe(`Document template`),eSignature:ds.optional().describe(`E-signature config`),access:D({isPublic:k().optional().default(!1).describe(`Public access`),sharedWith:N(x()).optional().describe(`Shared with`),expiresAt:h().optional().describe(`Access expiration`)}).optional().describe(`Access control`),metadata:_(x(),w()).optional().describe(`Custom metadata`)}));var fs=I(()=>f(`type`,[D({type:M(`constant`),value:w().describe(`Constant value to use`)}).describe(`Set a constant value`),D({type:M(`cast`),targetType:c([`string`,`number`,`boolean`,`date`]).describe(`Target data type`)}).describe(`Cast to a specific data type`),D({type:M(`lookup`),table:x().describe(`Lookup table name`),keyField:x().describe(`Field to match on`),valueField:x().describe(`Field to retrieve`)}).describe(`Lookup value from another table`),D({type:M(`javascript`),expression:Oi.describe(`JS expression (dialect="js" recommended). e.g. value.toUpperCase()`)}).describe(`Custom JavaScript transformation`),D({type:M(`map`),mappings:_(x(),w()).describe(`Value mappings (e.g., {"Active": "active"})`)}).describe(`Map values using a dictionary`)])),ps=I(()=>D({source:x().describe(`Source field name`),target:x().describe(`Target field name`),transform:fs.optional().describe(`Transformation to apply`),defaultValue:w().optional().describe(`Default if source is null/undefined`)})),ms=I(()=>D({id:x().describe(`Data source ID`),name:x().describe(`Data source name`),type:c([`odata`,`rest-api`,`graphql`,`custom`]).describe(`Protocol type`),endpoint:x().url().describe(`API endpoint URL`),authentication:D({type:c([`oauth2`,`api-key`,`basic`,`none`]).describe(`Auth type`),config:_(x(),w()).describe(`Auth configuration`)}).describe(`Authentication`)})),hs=I(()=>ps.extend({type:x().optional().describe(`Field type`),readonly:k().optional().default(!0).describe(`Read-only field`)}));I(()=>D({fieldName:x().describe(`Field name`),dataSource:ms.describe(`External data source`),query:D({endpoint:x().describe(`Query endpoint path`),method:c([`GET`,`POST`]).optional().default(`GET`).describe(`HTTP method`),parameters:_(x(),w()).optional().describe(`Query parameters`)}).describe(`Query configuration`),fieldMappings:N(hs).describe(`Field mappings`),caching:D({enabled:k().optional().default(!0).describe(`Cache enabled`),ttl:h().optional().default(300).describe(`Cache TTL (seconds)`),strategy:c([`lru`,`lfu`,`ttl`]).optional().default(`ttl`).describe(`Cache strategy`)}).optional().describe(`Caching configuration`),fallback:D({enabled:k().optional().default(!0).describe(`Fallback enabled`),defaultValue:w().optional().describe(`Default fallback value`),showError:k().optional().default(!0).describe(`Show error to user`)}).optional().describe(`Fallback configuration`),rateLimit:D({requestsPerSecond:h().describe(`Requests per second limit`),burstSize:h().optional().describe(`Burst size`)}).optional().describe(`Rate limiting`),retry:D({maxRetries:h().min(0).default(3).describe(`Maximum retry attempts`),initialDelayMs:h().default(1e3).describe(`Initial retry delay in milliseconds`),maxDelayMs:h().default(3e4).describe(`Maximum retry delay in milliseconds`),backoffMultiplier:h().default(2).describe(`Exponential backoff multiplier`),retryableStatusCodes:N(h()).default([429,500,502,503,504]).describe(`HTTP status codes that are retryable`)}).optional().describe(`Retry configuration with exponential backoff`),transform:D({request:D({headers:_(x(),x()).optional().describe(`Additional request headers`),queryParams:_(x(),x()).optional().describe(`Additional query parameters`)}).optional().describe(`Request transformation`),response:D({dataPath:x().optional().describe(`JSONPath to extract data (e.g., "$.data.results")`),totalPath:x().optional().describe(`JSONPath to extract total count (e.g., "$.meta.total")`)}).optional().describe(`Response transformation`)}).optional().describe(`Request/response transformation pipeline`),pagination:D({type:c([`offset`,`cursor`,`page`]).default(`offset`).describe(`Pagination type`),pageSize:h().default(100).describe(`Items per page`),maxPages:h().optional().describe(`Maximum number of pages to fetch`)}).optional().describe(`Pagination configuration for external data`)}));var gs=x().describe(`Underlying driver identifier`);I(()=>D({id:x().describe(`Unique driver identifier (e.g. "postgres")`),label:x().describe(`Display label (e.g. "PostgreSQL")`),description:x().optional(),icon:x().optional(),configSchema:_(x(),w()).describe(`JSON Schema for connection configuration`),capabilities:A(()=>_s).optional()}));var _s=D({transactions:k().default(!1),queryFilters:k().default(!1),queryAggregations:k().default(!1),querySorting:k().default(!1),queryPagination:k().default(!1),queryWindowFunctions:k().default(!1),querySubqueries:k().default(!1),joins:k().default(!1),fullTextSearch:k().default(!1),readOnly:k().default(!1),dynamicSchema:k().default(!1)});I(()=>D({name:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Unique datasource identifier`),label:x().optional().describe(`Display label`),driver:gs.describe(`Underlying driver type`),config:_(x(),w()).describe(`Driver specific configuration`),pool:D({min:h().default(0).describe(`Minimum connections`),max:h().default(10).describe(`Maximum connections`),idleTimeoutMillis:h().default(3e4).describe(`Idle timeout`),connectionTimeoutMillis:h().default(3e3).describe(`Connection establishment timeout`)}).optional().describe(`Connection pool settings`),readReplicas:N(_(x(),w())).optional().describe(`Read-only replica configurations`),capabilities:_s.optional().describe(`Capability overrides`),healthCheck:D({enabled:k().default(!0).describe(`Enable health check endpoint`),intervalMs:h().default(3e4).describe(`Health check interval in milliseconds`),timeoutMs:h().default(5e3).describe(`Health check timeout in milliseconds`)}).optional().describe(`Datasource health check configuration`),ssl:D({enabled:k().default(!1).describe(`Enable SSL/TLS for database connection`),rejectUnauthorized:k().default(!0).describe(`Reject connections with invalid/self-signed certificates`),ca:x().optional().describe(`CA certificate (PEM format or path to file)`),cert:x().optional().describe(`Client certificate (PEM format or path to file)`),key:x().optional().describe(`Client private key (PEM format or path to file)`)}).optional().describe(`SSL/TLS configuration for secure database connections`),retryPolicy:D({maxRetries:h().default(3).describe(`Maximum number of retry attempts`),baseDelayMs:h().default(1e3).describe(`Base delay between retries in milliseconds`),maxDelayMs:h().default(3e4).describe(`Maximum delay between retries in milliseconds`),backoffMultiplier:h().default(2).describe(`Exponential backoff multiplier`)}).optional().describe(`Connection retry policy for transient failures`),description:x().optional().describe(`Internal description`),active:k().default(!0).describe(`Is datasource enabled`)}));var vs=c([`count`,`sum`,`avg`,`min`,`max`,`count_distinct`,`number`,`string`,`boolean`]),ys=c([`string`,`number`,`boolean`,`time`,`geo`]),bs=c([`second`,`minute`,`hour`,`day`,`week`,`month`,`quarter`,`year`]),xs=I(()=>D({name:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Unique metric ID`),label:x().describe(`Human readable label`),description:x().optional(),type:vs,sql:x().describe(`SQL expression or field reference`),filters:N(D({sql:x()})).optional(),format:x().optional()})),Ss=I(()=>D({name:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Unique dimension ID`),label:x().describe(`Human readable label`),description:x().optional(),type:ys,sql:x().describe(`SQL expression or column reference`),granularities:N(bs).optional()})),Cs=I(()=>D({name:x().describe(`Target cube name`),relationship:c([`one_to_one`,`one_to_many`,`many_to_one`]).default(`many_to_one`),sql:x().describe(`Join condition (ON clause)`)}));I(()=>D({name:x().regex(/^[a-z_][a-z0-9_]*$/).describe(`Cube name (snake_case)`),title:x().optional(),description:x().optional(),sql:x().describe(`Base SQL statement or Table Name`),measures:_(x(),xs).describe(`Quantitative metrics`),dimensions:_(x(),Ss).describe(`Qualitative attributes`),joins:_(x(),Cs).optional(),refreshKey:D({every:x().optional(),sql:x().optional()}).optional(),public:k().default(!1)})),I(()=>D({cube:x().optional().describe(`Target cube name (optional when provided externally, e.g. in API request wrapper)`),measures:N(x()).describe(`List of metrics to calculate`),dimensions:N(x()).optional().describe(`List of dimensions to group by`),where:ni.optional().describe(`Filtering criteria (canonical Query DSL FilterCondition)`),timeDimensions:N(D({dimension:x(),granularity:bs.optional(),dateRange:O([x(),N(x())]).optional()})).optional(),order:_(x(),c([`asc`,`desc`])).optional(),limit:h().optional(),offset:h().optional(),timezone:x().optional().default(`UTC`)}));var ws=c([`comment`,`field_change`,`task`,`event`,`email`,`call`,`note`,`file`,`record_create`,`record_delete`,`approval`,`sharing`,`system`]),Ts=I(()=>D({type:c([`user`,`team`,`record`]).describe(`Mention target type`),id:x().describe(`Target ID`),name:x().describe(`Display name for rendering`),offset:h().int().min(0).describe(`Character offset in body text`),length:h().int().min(1).describe(`Length of mention token in body text`)})),Es=I(()=>D({field:x().describe(`Field machine name`),fieldLabel:x().optional().describe(`Field display label`),oldValue:w().optional().describe(`Previous value`),newValue:w().optional().describe(`New value`),oldDisplayValue:x().optional().describe(`Human-readable old value`),newDisplayValue:x().optional().describe(`Human-readable new value`)})),Ds=I(()=>D({emoji:x().describe(`Emoji character or shortcode (e.g., "👍", ":thumbsup:")`),userIds:N(x()).describe(`Users who reacted`),count:h().int().min(1).describe(`Total reaction count`)})),Os=I(()=>D({type:c([`user`,`system`,`service`,`automation`]).describe(`Actor type`),id:x().describe(`Actor ID`),name:x().optional().describe(`Actor display name`),avatarUrl:x().url().optional().describe(`Actor avatar URL`),source:x().optional().describe(`Source application (e.g., "Omni", "API", "Studio")`)})),ks=c([`public`,`internal`,`private`]);I(()=>D({id:x().describe(`Feed item ID`),type:ws.describe(`Activity type`),object:x().describe(`Object name (e.g., "account")`),recordId:x().describe(`Record ID this feed item belongs to`),actor:Os.describe(`Who performed this action`),body:x().optional().describe(`Rich text body (Markdown supported)`),mentions:N(Ts).optional().describe(`Mentioned users/teams/records`),changes:N(Es).optional().describe(`Field-level changes`),reactions:N(Ds).optional().describe(`Emoji reactions on this item`),parentId:x().optional().describe(`Parent feed item ID for threaded replies`),replyCount:h().int().min(0).default(0).describe(`Number of replies`),pinned:k().default(!1).describe(`Whether the feed item is pinned to the top of the timeline`),pinnedAt:x().datetime().optional().describe(`Timestamp when the item was pinned`),pinnedBy:x().optional().describe(`User ID who pinned the item`),starred:k().default(!1).describe(`Whether the feed item is starred/bookmarked by the current user`),starredAt:x().datetime().optional().describe(`Timestamp when the item was starred`),visibility:ks.default(`public`).describe(`Visibility: public (all users), internal (team only), private (author + mentioned)`),createdAt:x().datetime().describe(`Creation timestamp`),updatedAt:x().datetime().optional().describe(`Last update timestamp`),editedAt:x().datetime().optional().describe(`When comment was last edited`),isEdited:k().default(!1).describe(`Whether comment has been edited`)})),c([`all`,`comments_only`,`changes_only`,`tasks_only`]);var As=c([`comment`,`mention`,`field_change`,`task`,`approval`,`all`]),js=c([`in_app`,`email`,`push`,`slack`]);I(()=>D({object:x().describe(`Object name`),recordId:x().describe(`Record ID`),userId:x().describe(`Subscribing user ID`),events:N(As).default([`all`]).describe(`Event types to receive notifications for`),channels:N(js).default([`in_app`]).describe(`Notification delivery channels`),active:k().default(!0).describe(`Whether the subscription is active`),createdAt:x().datetime().describe(`Subscription creation timestamp`)}));var Ms=I(()=>c([`header`,`subdomain`,`path`,`token`,`lookup`]).describe(`Strategy for resolving tenant identity from request context`)),Ns=I(()=>D({name:x().min(1).describe(`Turso database group name`),primaryLocation:x().min(2).describe(`Primary Turso region code (e.g., iad, lhr, nrt)`),replicaLocations:N(x().min(2)).default([]).describe(`Additional replica region codes`),schemaDatabase:x().optional().describe(`Schema database name for multi-db schemas`)}).describe(`Turso database group configuration`)),Ps=I(()=>D({onTenantCreate:D({autoCreate:k().default(!0).describe(`Auto-create database on tenant registration`),group:x().optional().describe(`Turso group for the new database`),applyGroupSchema:k().default(!0).describe(`Apply shared schema from group`),seedData:k().default(!1).describe(`Populate seed data on creation`)}).describe(`Tenant creation hook`),onTenantDelete:D({immediate:k().default(!1).describe(`Destroy database immediately`),gracePeriodHours:h().int().min(0).default(72).describe(`Grace period before permanent deletion`),createBackup:k().default(!0).describe(`Create backup before deletion`)}).describe(`Tenant deletion hook`),onTenantSuspend:D({revokeTokens:k().default(!0).describe(`Revoke auth tokens on suspension`),readOnly:k().default(!0).describe(`Set database to read-only on suspension`)}).describe(`Tenant suspension hook`)}).describe(`Tenant database lifecycle hooks`));I(()=>D({organizationSlug:x().min(1).describe(`Turso organization slug`),urlTemplate:x().min(1).describe(`URL template with {tenant_id} placeholder`),groupAuthToken:x().min(1).describe(`Group-level auth token for platform operations`),tenantResolverStrategy:Ms.default(`token`),group:Ns.optional().describe(`Database group configuration`),lifecycle:Ps.optional().describe(`Lifecycle hooks`),maxCachedConnections:h().int().min(1).default(100).describe(`Max cached tenant connections (LRU)`),connectionCacheTTL:h().int().min(0).default(300).describe(`Connection cache TTL in seconds`)}).describe(`Turso multi-tenant router configuration`));var Fs=(e=>t===void 0?typeof Proxy<`u`?new Proxy(e,{get:(e,n)=>(t===void 0?e:t)[n]}):e:t)(function(e){if(t!==void 0)return t.apply(this,arguments);throw Error(`Dynamic require of "`+e+`" is not supported`)}),Is={debug:0,info:1,warn:2,error:3,fatal:4,silent:5},Ls={debug:`\x1B[36m`,info:`\x1B[32m`,warn:`\x1B[33m`,error:`\x1B[31m`,fatal:`\x1B[35m`,silent:``},Rs=`\x1B[0m`,zs=class e{constructor(e={},t={}){this.config={name:e.name,level:e.level??`info`,format:e.format??`pretty`,redact:e.redact??[`password`,`token`,`secret`,`key`],sourceLocation:e.sourceLocation??!1,file:e.file,rotation:e.rotation??{maxSize:`10m`,maxFiles:5}},this.bindings=t,this.config.file&&typeof process<`u`&&this.openFileStream(this.config.file)}openFileStream(e){try{let t=Fs(`fs`),n=Fs(`path`).dirname(e);t.mkdirSync(n,{recursive:!0}),this.fileStream=t.createWriteStream(e,{flags:`a`})}catch{}}isEnabled(e){return Is[e]>=Is[this.config.level]}redactSensitive(e){if(!e||typeof e!=`object`)return e;let t=Array.isArray(e)?[...e]:{...e};for(let e in t){let n=e.toLowerCase();this.config.redact.some(e=>n.includes(e.toLowerCase()))?t[e]=`***REDACTED***`:typeof t[e]==`object`&&t[e]!==null&&(t[e]=this.redactSensitive(t[e]))}return t}write(e,t,n,r){if(!this.isEnabled(e))return;let i=this.redactSensitive({...this.bindings,...n,...r?{error:{message:r.message,stack:r.stack}}:{}}),a=Object.keys(i).length>0,o=new Date().toISOString(),s;if(this.config.format===`json`)s=JSON.stringify({time:o,level:e,...this.config.name?{name:this.config.name}:{},msg:t,...i});else if(this.config.format===`text`){let n=[o,e.toUpperCase(),t];a&&n.push(JSON.stringify(i)),s=n.join(` | `)}else{let n=Ls[e]||``,r=this.config.name?`[${this.config.name}] `:``;s=`${n}${o} ${e.toUpperCase()}${Rs} ${r}${t}`,a&&(s+=` ${JSON.stringify(i)}`)}let c=s+`
|
|
3
|
-
`;typeof process<`u`&&process.stderr?e===`error`||e===`fatal`?process.stderr.write(c):process.stdout?.write(c):typeof console<`u`&&(e===`error`||e===`fatal`?console.error:e===`warn`?console.warn:e===`debug`?console.debug:console.log)(s),this.fileStream&&this.fileStream.write(c)}debug(e,t){this.write(`debug`,e,t)}info(e,t){this.write(`info`,e,t)}warn(e,t){this.write(`warn`,e,t)}error(e,t,n){t instanceof Error?this.write(`error`,e,n,t):this.write(`error`,e,t)}fatal(e,t,n){t instanceof Error?this.write(`fatal`,e,n,t):this.write(`fatal`,e,t)}log(e,...t){this.info(e,t.length>0?{args:t}:void 0)}child(t){let n=new e(this.config,{...this.bindings,...t});return n.fileStream=this.fileStream,n}withTrace(e,t){return this.child({traceId:e,spanId:t})}async destroy(){this.fileStream&&=(await new Promise(e=>this.fileStream.end(e)),void 0)}};function Bs(e){return new zs(e)}var Vs=class{constructor(e,t){this.subscriptions=new Map,this.eventBuffer=[],this._baseUrl=e,this._token=t}subscribeMetadata(e,t,n){let r=`metadata-${e}-${Date.now()}`;return this.subscriptions.set(r,{filter:{type:e,packageId:n?.packageId,eventTypes:[`metadata.${e}.created`,`metadata.${e}.updated`,`metadata.${e}.deleted`]},handler:e=>{e.type.startsWith(`metadata.`)&&t(e)}}),this.startPolling(),()=>{this.subscriptions.delete(r),this.subscriptions.size===0&&this.stopPolling()}}subscribeData(e,t,n){let r=`data-${e}-${Date.now()}`;return this.subscriptions.set(r,{filter:{type:e,recordId:n?.recordId,eventTypes:[`data.record.created`,`data.record.updated`,`data.record.deleted`]},handler:r=>{r.type.startsWith(`data.`)&&r.object===e&&(!n?.recordId||r.payload?.recordId===n.recordId)&&t(r)}}),this.startPolling(),()=>{this.subscriptions.delete(r),this.subscriptions.size===0&&this.stopPolling()}}emitEvent(e){for(let t of this.subscriptions.values()){let n=!t.filter.type||e.type.includes(t.filter.type)||e.object===t.filter.type,r=!t.filter.eventTypes?.length||t.filter.eventTypes.includes(e.type),i=!t.filter.packageId||e.payload?.packageId===t.filter.packageId;if(n&&r&&i)try{t.handler(e)}catch(e){console.error(`Error in realtime event handler:`,e)}}}startPolling(){this.pollInterval||=setInterval(()=>{for(;this.eventBuffer.length>0;){let e=this.eventBuffer.shift();e&&this.emitEvent(e)}},2e3)}stopPolling(){this.pollInterval&&=(clearInterval(this.pollInterval),void 0)}_bufferEvent(e){this.eventBuffer.push(e)}disconnect(){this.stopPolling(),this.subscriptions.clear(),this.eventBuffer=[]}},Hs=class{constructor(e){this.meta={getTypes:async()=>{let e=this.getRoute(`metadata`),t=await this.fetch(`${this.baseUrl}${e}`);return this.unwrapResponse(t)},getItems:async(e,t)=>{let n=this.getRoute(`metadata`),r=new URLSearchParams;t?.packageId&&r.set(`package`,t.packageId);let i=r.toString(),a=`${this.baseUrl}${n}/${e}${i?`?${i}`:``}`,o=await this.fetch(a);return this.unwrapResponse(o)},getItem:async(e,t,n)=>{let r=this.getRoute(`metadata`),i=new URLSearchParams;n?.packageId&&i.set(`package`,n.packageId);let a=i.toString(),o=`${this.baseUrl}${r}/${e}/${t}${a?`?${a}`:``}`,s=await this.fetch(o);return this.unwrapResponse(s)},saveItem:async(e,t,n)=>{let r=this.getRoute(`metadata`),i=await this.fetch(`${this.baseUrl}${r}/${e}/${t}`,{method:`PUT`,body:JSON.stringify(n)});return this.unwrapResponse(i)},deleteItem:async(e,t)=>{let n=this.getRoute(`metadata`),r=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`});return this.unwrapResponse(r)},getHistory:async(e,t,n)=>{let r=this.getRoute(`metadata`),i=new URLSearchParams;n?.sinceSeq!==void 0&&i.set(`sinceSeq`,String(n.sinceSeq)),n?.limit!==void 0&&i.set(`limit`,String(n.limit));let a=i.toString(),o=`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/history${a?`?${a}`:``}`,s=await this.fetch(o);return this.unwrapResponse(s)},getCached:async(e,t)=>{let n=this.getRoute(`metadata`),r={};t?.ifNoneMatch&&(r[`If-None-Match`]=t.ifNoneMatch),t?.ifModifiedSince&&(r[`If-Modified-Since`]=t.ifModifiedSince);let i=await this.fetch(`${this.baseUrl}${n}/object/${e}`,{headers:r});if(i.status===304)return{notModified:!0,etag:t?.ifNoneMatch?{value:t.ifNoneMatch.replace(/^W\/|"/g,``),weak:t.ifNoneMatch.startsWith(`W/`)}:void 0};let a=await i.json(),o=i.headers.get(`ETag`),s=i.headers.get(`Last-Modified`);return{data:a,etag:o?{value:o.replace(/^W\/|"/g,``),weak:o.startsWith(`W/`)}:void 0,lastModified:s||void 0,notModified:!1}},getView:async(e,t=`list`)=>{let n=this.getRoute(`ui`),r=await this.fetch(`${this.baseUrl}${n}/view/${e}?type=${t}`);return this.unwrapResponse(r)}},this.analytics={query:async e=>{let t=this.getRoute(`analytics`);return(await this.fetch(`${this.baseUrl}${t}/query`,{method:`POST`,body:JSON.stringify(e)})).json()},meta:async e=>{let t=this.getRoute(`analytics`);return(await this.fetch(`${this.baseUrl}${t}/meta/${e}`)).json()},explain:async e=>{let t=this.getRoute(`analytics`);return(await this.fetch(`${this.baseUrl}${t}/explain`,{method:`POST`,body:JSON.stringify(e)})).json()}},this.packages={list:async e=>{let t=this.getRoute(`packages`),n=new URLSearchParams;e?.status&&n.set(`status`,e.status),e?.type&&n.set(`type`,e.type),e?.enabled!==void 0&&n.set(`enabled`,String(e.enabled));let r=n.toString(),i=`${this.baseUrl}${t}${r?`?`+r:``}`,a=await this.fetch(i);return this.unwrapResponse(a)},get:async e=>{let t=this.getRoute(`packages`),n=await this.fetch(`${this.baseUrl}${t}/${encodeURIComponent(e)}`);return this.unwrapResponse(n)},install:async(e,t)=>{let n=this.getRoute(`packages`),r=await this.fetch(`${this.baseUrl}${n}`,{method:`POST`,body:JSON.stringify({manifest:e,settings:t?.settings,enableOnInstall:t?.enableOnInstall})});return this.unwrapResponse(r)},uninstall:async e=>{let t=this.getRoute(`packages`),n=await this.fetch(`${this.baseUrl}${t}/${encodeURIComponent(e)}`,{method:`DELETE`});return this.unwrapResponse(n)},enable:async e=>{let t=this.getRoute(`packages`),n=await this.fetch(`${this.baseUrl}${t}/${encodeURIComponent(e)}/enable`,{method:`PATCH`});return this.unwrapResponse(n)},disable:async e=>{let t=this.getRoute(`packages`),n=await this.fetch(`${this.baseUrl}${t}/${encodeURIComponent(e)}/disable`,{method:`PATCH`});return this.unwrapResponse(n)}},this.projects={list:async e=>{let t=new URLSearchParams;e?.organization_id&&t.set(`organizationId`,e.organization_id),e?.env_type&&t.set(`envType`,e.env_type),e?.status&&t.set(`status`,e.status);let n=t.toString(),r=`${this.baseUrl}/api/v1/cloud/projects${n?`?`+n:``}`,i=await this.fetch(r);return this.unwrapResponse(i)},get:async e=>{let t=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}`);return this.unwrapResponse(t)},create:async e=>{let t=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects`,{method:`POST`,body:JSON.stringify(e)});return this.unwrapResponse(t)},update:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}`,{method:`PATCH`,body:JSON.stringify(t)});return this.unwrapResponse(n)},delete:async(e,t)=>{let n=t?.force?`?force=1`:``,r=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}${n}`,{method:`DELETE`});return this.unwrapResponse(r)},activate:async e=>{let t=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/activate`,{method:`POST`});return this.unwrapResponse(t)},rotateCredential:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/credentials/rotate`,{method:`POST`,body:JSON.stringify({plaintext:t})});return this.unwrapResponse(n)},updateHostname:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/hostname`,{method:`POST`,body:JSON.stringify({hostname:t})});return this.unwrapResponse(n)},updateVisibility:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}`,{method:`PATCH`,body:JSON.stringify({visibility:t})});return this.unwrapResponse(n)},listRevisions:async(e,t)=>{let n=new URLSearchParams;t?.limit&&n.set(`limit`,String(t.limit)),t?.cursor&&n.set(`cursor`,t.cursor),t?.branch&&n.set(`branch`,t.branch);let r=n.toString(),i=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/revisions${r?`?${r}`:``}`);return this.unwrapResponse(i)},listBranches:async e=>{let t=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/branches`);return this.unwrapResponse(t)},renameBranch:async(e,t,n)=>{let r=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/branches/${encodeURIComponent(t)}/rename`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({newName:n})});return this.unwrapResponse(r)},deleteBranch:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/branches/${encodeURIComponent(t)}`,{method:`DELETE`});return this.unwrapResponse(n)},activateRevision:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/revisions/${encodeURIComponent(t)}/activate`,{method:`POST`});return this.unwrapResponse(n)},retryProvisioning:async e=>{let t=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/retry`,{method:`POST`});return this.unwrapResponse(t)},listMembers:async e=>{let t=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/members`);return this.unwrapResponse(t)},addMember:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/members`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)});return this.unwrapResponse(n)},updateMemberRole:async(e,t,n)=>{let r=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`,{method:`PATCH`,headers:{"content-type":`application/json`},body:JSON.stringify({role:n})});return this.unwrapResponse(r)},removeMember:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/members/${encodeURIComponent(t)}`,{method:`DELETE`});return this.unwrapResponse(n)},listDrivers:async()=>{let e=await this.fetch(`${this.baseUrl}/api/v1/cloud/drivers`);return this.unwrapResponse(e)},listTemplates:async()=>{let e=await this.fetch(`${this.baseUrl}/api/v1/cloud/templates`);return this.unwrapResponse(e)},packages:{list:async e=>{let t=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/packages`);return this.unwrapResponse(t)},install:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/packages`,{method:`POST`,body:JSON.stringify(t)});return this.unwrapResponse(n)},get:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/packages/${encodeURIComponent(t)}`);return this.unwrapResponse(n)},enable:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/packages/${encodeURIComponent(t)}/enable`,{method:`PATCH`});return this.unwrapResponse(n)},disable:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/packages/${encodeURIComponent(t)}/disable`,{method:`PATCH`});return this.unwrapResponse(n)},uninstall:async(e,t)=>{let n=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/packages/${encodeURIComponent(t)}`,{method:`DELETE`});return this.unwrapResponse(n)},upgrade:async(e,t,n)=>{let r=await this.fetch(`${this.baseUrl}/api/v1/cloud/projects/${encodeURIComponent(e)}/packages/${encodeURIComponent(t)}/upgrade`,{method:`POST`,body:JSON.stringify({targetVersion:n})});return this.unwrapResponse(r)}}},this.organizations={list:async()=>{let e=this.getRoute(`auth`),t=await(await this.fetch(`${this.baseUrl}${e}/organization/list`)).json();return{organizations:Array.isArray(t)?t:t?.data??[]}},create:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/create`,{method:`POST`,body:JSON.stringify(e)})).json()},update:async(e,t)=>{let n=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${n}/organization/update`,{method:`POST`,body:JSON.stringify({organizationId:e,data:t})})).json()},setActive:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/set-active`,{method:`POST`,body:JSON.stringify({organizationId:e})})).json()},get:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/get-full-organization?organizationId=${encodeURIComponent(e)}`)).json()},listMembers:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/list-members?organizationId=${encodeURIComponent(e)}`)).json()},invite:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/invite-member`,{method:`POST`,body:JSON.stringify(e)})).json()},leave:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/leave`,{method:`POST`,body:JSON.stringify({organizationId:e})})).json()},delete:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/delete`,{method:`POST`,body:JSON.stringify({organizationId:e})})).json()},removeMember:async(e,t)=>{let n=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${n}/organization/remove-member`,{method:`POST`,body:JSON.stringify({memberIdOrEmail:t.memberIdOrEmail,organizationId:e})})).json()},updateMemberRole:async(e,t)=>{let n=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${n}/organization/update-member-role`,{method:`POST`,body:JSON.stringify({memberId:t.memberId,role:t.role,organizationId:e})})).json()},getActiveMember:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/get-active-member?organizationId=${encodeURIComponent(e)}`)).json()},invitations:{list:async e=>{let t=this.getRoute(`auth`),n=await(await this.fetch(`${this.baseUrl}${t}/organization/list-invitations?organizationId=${encodeURIComponent(e)}`)).json();return{invitations:Array.isArray(n)?n:n?.data??n?.invitations??[]}},listMine:async()=>{let e=this.getRoute(`auth`),t=await(await this.fetch(`${this.baseUrl}${e}/organization/list-user-invitations`)).json();return{invitations:Array.isArray(t)?t:t?.data??t?.invitations??[]}},cancel:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/cancel-invitation`,{method:`POST`,body:JSON.stringify({invitationId:e})})).json()},accept:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/accept-invitation`,{method:`POST`,body:JSON.stringify({invitationId:e})})).json()},reject:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/reject-invitation`,{method:`POST`,body:JSON.stringify({invitationId:e})})).json()},resend:async e=>{if(e.id)try{await this.organizations.invitations.cancel(e.id)}catch{}return this.organizations.invite({email:e.email,role:e.role??`member`,organizationId:e.organizationId})}},teams:{list:async e=>{let t=this.getRoute(`auth`),n=await(await this.fetch(`${this.baseUrl}${t}/organization/list-teams?organizationId=${encodeURIComponent(e)}`)).json();return{teams:Array.isArray(n)?n:n?.data??n?.teams??[]}},create:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/create-team`,{method:`POST`,body:JSON.stringify(e)})).json()},update:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/update-team`,{method:`POST`,body:JSON.stringify(e)})).json()},delete:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/remove-team`,{method:`POST`,body:JSON.stringify(e)})).json()},listMembers:async e=>{let t=this.getRoute(`auth`),n=await(await this.fetch(`${this.baseUrl}${t}/organization/list-team-members?teamId=${encodeURIComponent(e)}`)).json();return{members:Array.isArray(n)?n:n?.data??n?.members??[]}},addMember:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/add-team-member`,{method:`POST`,body:JSON.stringify(e)})).json()},removeMember:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/organization/remove-team-member`,{method:`POST`,body:JSON.stringify(e)})).json()}}},this.oauth={applications:{register:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/oauth2/create-client`,{method:`POST`,body:JSON.stringify(e)})).json()},get:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/oauth2/get-client?client_id=${encodeURIComponent(e)}`)).json()},getPublic:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/oauth2/public-client?client_id=${encodeURIComponent(e)}`)).json()},list:async()=>{let e=this.getRoute(`auth`),t=await(await this.fetch(`${this.baseUrl}${e}/oauth2/get-clients`)).json();return{applications:Array.isArray(t)?t:t?.clients??t?.data??[]}},delete:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/oauth2/delete-client`,{method:`POST`,body:JSON.stringify({client_id:e})})).json()}},consent:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/oauth2/consent`,{method:`POST`,body:JSON.stringify(e)})).json()}},this.auth={getConfig:async()=>{let e=this.getRoute(`auth`),t=await this.fetch(`${this.baseUrl}${e}/config`);return this.unwrapResponse(t)},login:async e=>{let t=this.getRoute(`auth`),n=await(await this.fetch(`${this.baseUrl}${t}/sign-in/email`,{method:`POST`,headers:{Origin:this.baseUrl},body:JSON.stringify(e)})).json(),r=n&&(n.data??(n.token||n.user?{token:n.token,user:n.user}:void 0)),i=r?{...n,data:r}:n;return i.data?.token&&(this.token=i.data.token),i},logout:async()=>{let e=this.getRoute(`auth`);await this.fetch(`${this.baseUrl}${e}/sign-out`,{method:`POST`,headers:{"Content-Type":`application/json`,Origin:this.baseUrl},body:`{}`}),this.token=void 0},me:async()=>{let e=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${e}/get-session`,{headers:{Origin:this.baseUrl}})).json()},register:async e=>{let t=this.getRoute(`auth`),n=await(await this.fetch(`${this.baseUrl}${t}/sign-up/email`,{method:`POST`,headers:{Origin:this.baseUrl},body:JSON.stringify(e)})).json(),r=n&&(n.data??(n.token||n.user?{token:n.token,user:n.user}:void 0)),i=r?{...n,data:r}:n;return i.data?.token&&(this.token=i.data.token),i},signInWithProvider:async(e,t)=>{if(typeof window>`u`)throw Error(`signInWithProvider requires a browser environment`);let n=this.getRoute(`auth`),r=t?.callbackURL??window.location.origin+`/login`,i=t?.type===`oidc`,a=i?`/sign-in/oauth2`:`/sign-in/social`,o=i?{providerId:e,callbackURL:r}:{provider:e,callbackURL:r};t?.errorCallbackURL&&(o.errorCallbackURL=t.errorCallbackURL);let s=await(await this.fetch(`${this.baseUrl}${n}${a}`,{method:`POST`,body:JSON.stringify(o)})).json(),c=s?.url??s?.data?.url;if(c)window.location.assign(c);else throw Error(`signInWithProvider: no redirect URL returned for provider "${e}"`)},refreshToken:async e=>{let t=this.getRoute(`auth`),n=await(await this.fetch(`${this.baseUrl}${t}/get-session`,{method:`GET`})).json();return n.data?.token&&(this.token=n.data.token),n},bootstrapStatus:async()=>{let e=this.getRoute(`auth`),t=await(await this.fetch(`${this.baseUrl}${e}/bootstrap-status`)).json();return{hasOwner:!!(t?.data??t)?.hasOwner}},updateUser:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/update-user`,{method:`POST`,body:JSON.stringify(e)})).json()},changePassword:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/change-password`,{method:`POST`,body:JSON.stringify(e)})).json()},changeEmail:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/change-email`,{method:`POST`,body:JSON.stringify(e)})).json()},sendVerificationEmail:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/send-verification-email`,{method:`POST`,body:JSON.stringify(e)})).json()},verifyEmail:async e=>{let t=this.getRoute(`auth`),n=new URL(`${this.baseUrl}${t}/verify-email`);return n.searchParams.set(`token`,e.token),e.callbackURL&&n.searchParams.set(`callbackURL`,e.callbackURL),(await this.fetch(n.toString())).json()},deleteUser:async e=>{let t=this.getRoute(`auth`),n=await this.fetch(`${this.baseUrl}${t}/delete-user`,{method:`POST`,body:JSON.stringify(e)});return this.token=void 0,n.json()},sessions:{list:async()=>{let e=this.getRoute(`auth`),t=await(await this.fetch(`${this.baseUrl}${e}/list-sessions`)).json();return{sessions:Array.isArray(t)?t:t?.data??t?.sessions??[]}},revoke:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/revoke-session`,{method:`POST`,body:JSON.stringify({token:e})})).json()},revokeOthers:async()=>{let e=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${e}/revoke-other-sessions`,{method:`POST`,body:`{}`})).json()},revokeAll:async()=>{let e=this.getRoute(`auth`),t=await this.fetch(`${this.baseUrl}${e}/revoke-sessions`,{method:`POST`,body:`{}`});return this.token=void 0,t.json()}},twoFactor:{enable:async e=>{let t=this.getRoute(`auth`),n=await(await this.fetch(`${this.baseUrl}${t}/two-factor/enable`,{method:`POST`,body:JSON.stringify(e)})).json();return n?.data??n},verifyTotp:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/two-factor/verify-totp`,{method:`POST`,body:JSON.stringify(e)})).json()},disable:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/two-factor/disable`,{method:`POST`,body:JSON.stringify(e)})).json()},generateBackupCodes:async e=>{let t=this.getRoute(`auth`),n=await(await this.fetch(`${this.baseUrl}${t}/two-factor/generate-backup-codes`,{method:`POST`,body:JSON.stringify(e)})).json();return n?.data??n},verifyBackupCode:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/two-factor/verify-backup-code`,{method:`POST`,body:JSON.stringify(e)})).json()}},accounts:{list:async()=>{let e=this.getRoute(`auth`),t=await(await this.fetch(`${this.baseUrl}${e}/list-accounts`)).json();return{accounts:Array.isArray(t)?t:t?.data??t?.accounts??[]}},unlink:async e=>{let t=this.getRoute(`auth`);return(await this.fetch(`${this.baseUrl}${t}/unlink-account`,{method:`POST`,body:JSON.stringify(e)})).json()},linkSocial:async e=>{let t=this.getRoute(`auth`),n=e.callbackURL??(typeof window<`u`?window.location.href:void 0),r=await(await this.fetch(`${this.baseUrl}${t}/link-social`,{method:`POST`,body:JSON.stringify({provider:e.provider,callbackURL:n})})).json();return r?.data??r}}},this.storage={upload:async(e,t=`user`)=>{let n={filename:e.name,mimeType:e.type,size:e.size,scope:t},r=this.getRoute(`storage`),{data:i}=await(await this.fetch(`${this.baseUrl}${r}/upload/presigned`,{method:`POST`,body:JSON.stringify(n)})).json(),a=await this.fetchImpl(i.uploadUrl,{method:i.method,headers:i.headers,body:e});if(!a.ok)throw Error(`Storage Upload Failed: ${a.statusText}`);let o={fileId:i.fileId};return(await this.fetch(`${this.baseUrl}${r}/upload/complete`,{method:`POST`,body:JSON.stringify(o)})).json()},getDownloadUrl:async e=>{let t=this.getRoute(`storage`);return(await(await this.fetch(`${this.baseUrl}${t}/files/${e}/url`)).json()).url},getPresignedUrl:async e=>{let t=this.getRoute(`storage`);return(await this.fetch(`${this.baseUrl}${t}/upload/presigned`,{method:`POST`,body:JSON.stringify(e)})).json()},initChunkedUpload:async e=>{let t=this.getRoute(`storage`);return(await this.fetch(`${this.baseUrl}${t}/upload/chunked`,{method:`POST`,body:JSON.stringify(e)})).json()},uploadPart:async(e,t,n,r)=>{let i=this.getRoute(`storage`);return(await this.fetch(`${this.baseUrl}${i}/upload/chunked/${e}/chunk/${t}`,{method:`PUT`,headers:{"x-resume-token":n},body:r})).json()},completeChunkedUpload:async e=>{let t=this.getRoute(`storage`);return(await this.fetch(`${this.baseUrl}${t}/upload/chunked/${e.uploadId}/complete`,{method:`POST`,body:JSON.stringify(e)})).json()},resumeUpload:async(e,t,n,r)=>{let i=this.getRoute(`storage`),{totalChunks:a,uploadedChunks:o}=(await(await this.fetch(`${this.baseUrl}${i}/upload/chunked/${e}/progress`)).json()).data,s=[],c=t instanceof ArrayBuffer?t:await t.arrayBuffer();for(let t=o;t<a;t++){let i=t*n,a=Math.min(i+n,c.byteLength),o=new Blob([c.slice(i,a)]),l=await this.storage.uploadPart(e,t,r,o);s.push({chunkIndex:t,eTag:l.data.eTag})}return this.storage.completeChunkedUpload({uploadId:e,parts:s})}},this.automation={trigger:async(e,t)=>{let n=this.getRoute(`automation`);return(await this.fetch(`${this.baseUrl}${n}/trigger/${e}`,{method:`POST`,body:JSON.stringify(t)})).json()},list:async()=>{let e=this.getRoute(`automation`),t=await this.fetch(`${this.baseUrl}${e}`);return this.unwrapResponse(t)},get:async e=>{let t=this.getRoute(`automation`),n=await this.fetch(`${this.baseUrl}${t}/${e}`);return this.unwrapResponse(n)},create:async(e,t)=>{let n=this.getRoute(`automation`),r=await this.fetch(`${this.baseUrl}${n}`,{method:`POST`,body:JSON.stringify({name:e,...t})});return this.unwrapResponse(r)},update:async(e,t)=>{let n=this.getRoute(`automation`),r=await this.fetch(`${this.baseUrl}${n}/${e}`,{method:`PUT`,body:JSON.stringify({definition:t})});return this.unwrapResponse(r)},delete:async e=>{let t=this.getRoute(`automation`),n=await this.fetch(`${this.baseUrl}${t}/${e}`,{method:`DELETE`});return this.unwrapResponse(n)},toggle:async(e,t)=>{let n=this.getRoute(`automation`),r=await this.fetch(`${this.baseUrl}${n}/${e}/toggle`,{method:`POST`,body:JSON.stringify({enabled:t})});return this.unwrapResponse(r)},runs:{list:async(e,t)=>{let n=this.getRoute(`automation`),r=new URLSearchParams;t?.limit&&r.set(`limit`,String(t.limit)),t?.cursor&&r.set(`cursor`,t.cursor);let i=r.toString(),a=await this.fetch(`${this.baseUrl}${n}/${e}/runs${i?`?${i}`:``}`);return this.unwrapResponse(a)},get:async(e,t)=>{let n=this.getRoute(`automation`),r=await this.fetch(`${this.baseUrl}${n}/${e}/runs/${t}`);return this.unwrapResponse(r)}},getFlow:async e=>{let t=this.getRoute(`automation`),n=await this.fetch(`${this.baseUrl}${t}/${encodeURIComponent(e)}`);return this.unwrapResponse(n)},execute:async(e,t)=>{let n=this.getRoute(`automation`),r=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}/trigger`,{method:`POST`,body:JSON.stringify(t??{})});return this.unwrapResponse(r)},listRuns:async(e,t)=>{let n=this.getRoute(`automation`),r=new URLSearchParams;t?.limit!=null&&r.set(`limit`,String(t.limit)),t?.cursor&&r.set(`cursor`,t.cursor);let i=r.toString(),a=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}/runs${i?`?${i}`:``}`);return this.unwrapResponse(a)},getRun:async(e,t)=>{let n=this.getRoute(`automation`),r=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}/runs/${encodeURIComponent(t)}`);return this.unwrapResponse(r)}},this.permissions={check:async e=>{let t=this.getRoute(`permissions`),n=new URLSearchParams({object:e.object,action:e.action});e.recordId!==void 0&&n.set(`recordId`,e.recordId),e.field!==void 0&&n.set(`field`,e.field);let r=await this.fetch(`${this.baseUrl}${t}/check?${n.toString()}`);return this.unwrapResponse(r)},getObjectPermissions:async e=>{let t=this.getRoute(`permissions`),n=await this.fetch(`${this.baseUrl}${t}/objects/${encodeURIComponent(e)}`);return this.unwrapResponse(n)},getEffectivePermissions:async()=>{let e=this.getRoute(`permissions`),t=await this.fetch(`${this.baseUrl}${e}/effective`);return this.unwrapResponse(t)}},this.realtime={connect:async e=>{let t=this.getRoute(`realtime`),n=await this.fetch(`${this.baseUrl}${t}/connect`,{method:`POST`,body:JSON.stringify(e||{})});return this.unwrapResponse(n)},disconnect:async()=>{let e=this.getRoute(`realtime`);await this.fetch(`${this.baseUrl}${e}/disconnect`,{method:`POST`})},subscribe:async e=>{let t=this.getRoute(`realtime`),n=await this.fetch(`${this.baseUrl}${t}/subscribe`,{method:`POST`,body:JSON.stringify(e)});return this.unwrapResponse(n)},unsubscribe:async e=>{let t=this.getRoute(`realtime`);await this.fetch(`${this.baseUrl}${t}/unsubscribe`,{method:`POST`,body:JSON.stringify({subscriptionId:e})})},setPresence:async(e,t)=>{let n=this.getRoute(`realtime`);await this.fetch(`${this.baseUrl}${n}/presence`,{method:`PUT`,body:JSON.stringify({channel:e,state:t})})},getPresence:async e=>{let t=this.getRoute(`realtime`),n=await this.fetch(`${this.baseUrl}${t}/presence/${encodeURIComponent(e)}`);return this.unwrapResponse(n)}},this.workflow={getConfig:async e=>{let t=this.getRoute(`workflow`),n=await this.fetch(`${this.baseUrl}${t}/${encodeURIComponent(e)}/config`);return this.unwrapResponse(n)},getState:async(e,t)=>{let n=this.getRoute(`workflow`),r=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/state`);return this.unwrapResponse(r)},transition:async e=>{let t=this.getRoute(`workflow`),n=await this.fetch(`${this.baseUrl}${t}/${encodeURIComponent(e.object)}/${encodeURIComponent(e.recordId)}/transition`,{method:`POST`,body:JSON.stringify({transition:e.transition,comment:e.comment,data:e.data})});return this.unwrapResponse(n)},approve:async e=>{let t=this.getRoute(`workflow`),n=await this.fetch(`${this.baseUrl}${t}/${encodeURIComponent(e.object)}/${encodeURIComponent(e.recordId)}/approve`,{method:`POST`,body:JSON.stringify({comment:e.comment,data:e.data})});return this.unwrapResponse(n)},reject:async e=>{let t=this.getRoute(`workflow`),n=await this.fetch(`${this.baseUrl}${t}/${encodeURIComponent(e.object)}/${encodeURIComponent(e.recordId)}/reject`,{method:`POST`,body:JSON.stringify({reason:e.reason,comment:e.comment})});return this.unwrapResponse(n)}},this.views={list:async(e,t)=>{let n=this.getRoute(`views`),r=new URLSearchParams;t&&r.set(`type`,t);let i=r.toString(),a=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}${i?`?${i}`:``}`);return this.unwrapResponse(a)},get:async(e,t)=>{let n=this.getRoute(`views`),r=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`);return this.unwrapResponse(r)},create:async(e,t)=>{let n=this.getRoute(`views`),r=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}`,{method:`POST`,body:JSON.stringify({object:e,data:t})});return this.unwrapResponse(r)},update:async(e,t,n)=>{let r=this.getRoute(`views`),i=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`PUT`,body:JSON.stringify({object:e,viewId:t,data:n})});return this.unwrapResponse(i)},delete:async(e,t)=>{let n=this.getRoute(`views`),r=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}/${encodeURIComponent(t)}`,{method:`DELETE`});return this.unwrapResponse(r)}},this.notifications={registerDevice:async e=>{let t=this.getRoute(`notifications`),n=await this.fetch(`${this.baseUrl}${t}/devices`,{method:`POST`,body:JSON.stringify(e)});return this.unwrapResponse(n)},unregisterDevice:async e=>{let t=this.getRoute(`notifications`),n=await this.fetch(`${this.baseUrl}${t}/devices/${encodeURIComponent(e)}`,{method:`DELETE`});return this.unwrapResponse(n)},getPreferences:async()=>{let e=this.getRoute(`notifications`),t=await this.fetch(`${this.baseUrl}${e}/preferences`);return this.unwrapResponse(t)},updatePreferences:async e=>{let t=this.getRoute(`notifications`),n=await this.fetch(`${this.baseUrl}${t}/preferences`,{method:`PUT`,body:JSON.stringify({preferences:e})});return this.unwrapResponse(n)},list:async e=>{let t=this.getRoute(`notifications`),n=new URLSearchParams;e?.read!==void 0&&n.set(`read`,String(e.read)),e?.type&&n.set(`type`,e.type),e?.limit&&n.set(`limit`,String(e.limit)),e?.cursor&&n.set(`cursor`,e.cursor);let r=n.toString(),i=await this.fetch(`${this.baseUrl}${t}${r?`?${r}`:``}`);return this.unwrapResponse(i)},markRead:async e=>{let t=this.getRoute(`notifications`),n=await this.fetch(`${this.baseUrl}${t}/read`,{method:`POST`,body:JSON.stringify({ids:e})});return this.unwrapResponse(n)},markAllRead:async()=>{let e=this.getRoute(`notifications`),t=await this.fetch(`${this.baseUrl}${e}/read/all`,{method:`POST`});return this.unwrapResponse(t)}},this.ai={nlq:async e=>{let t=this.getRoute(`ai`),n=await this.fetch(`${this.baseUrl}${t}/nlq`,{method:`POST`,body:JSON.stringify(e)});return this.unwrapResponse(n)},suggest:async e=>{let t=this.getRoute(`ai`),n=await this.fetch(`${this.baseUrl}${t}/suggest`,{method:`POST`,body:JSON.stringify(e)});return this.unwrapResponse(n)},insights:async e=>{let t=this.getRoute(`ai`),n=await this.fetch(`${this.baseUrl}${t}/insights`,{method:`POST`,body:JSON.stringify(e)});return this.unwrapResponse(n)}},this.i18n={getLocales:async()=>{let e=this.getRoute(`i18n`),t=await this.fetch(`${this.baseUrl}${e}/locales`);return this.unwrapResponse(t)},getTranslations:async(e,t)=>{let n=this.getRoute(`i18n`),r=new URLSearchParams;r.set(`locale`,e),t?.namespace&&r.set(`namespace`,t.namespace),t?.keys&&r.set(`keys`,t.keys.join(`,`));let i=await this.fetch(`${this.baseUrl}${n}/translations?${r.toString()}`);return this.unwrapResponse(i)},getFieldLabels:async(e,t)=>{let n=this.getRoute(`i18n`),r=await this.fetch(`${this.baseUrl}${n}/labels/${encodeURIComponent(e)}?locale=${encodeURIComponent(t)}`);return this.unwrapResponse(r)}},this.feed={list:async(e,t,n)=>{let r=this.getRoute(`data`),i=new URLSearchParams;n?.type&&i.set(`type`,n.type),n?.limit&&i.set(`limit`,String(n.limit)),n?.cursor&&i.set(`cursor`,n.cursor);let a=i.toString(),o=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed${a?`?${a}`:``}`);return this.unwrapResponse(o)},create:async(e,t,n)=>{let r=this.getRoute(`data`),i=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed`,{method:`POST`,body:JSON.stringify(n)});return this.unwrapResponse(i)},update:async(e,t,n,r)=>{let i=this.getRoute(`data`),a=await this.fetch(`${this.baseUrl}${i}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed/${encodeURIComponent(n)}`,{method:`PUT`,body:JSON.stringify(r)});return this.unwrapResponse(a)},delete:async(e,t,n)=>{let r=this.getRoute(`data`),i=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed/${encodeURIComponent(n)}`,{method:`DELETE`});return this.unwrapResponse(i)},addReaction:async(e,t,n,r)=>{let i=this.getRoute(`data`),a=await this.fetch(`${this.baseUrl}${i}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed/${encodeURIComponent(n)}/reactions`,{method:`POST`,body:JSON.stringify({emoji:r})});return this.unwrapResponse(a)},removeReaction:async(e,t,n,r)=>{let i=this.getRoute(`data`),a=await this.fetch(`${this.baseUrl}${i}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed/${encodeURIComponent(n)}/reactions/${encodeURIComponent(r)}`,{method:`DELETE`});return this.unwrapResponse(a)},pin:async(e,t,n)=>{let r=this.getRoute(`data`),i=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed/${encodeURIComponent(n)}/pin`,{method:`POST`});return this.unwrapResponse(i)},unpin:async(e,t,n)=>{let r=this.getRoute(`data`),i=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed/${encodeURIComponent(n)}/pin`,{method:`DELETE`});return this.unwrapResponse(i)},star:async(e,t,n)=>{let r=this.getRoute(`data`),i=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed/${encodeURIComponent(n)}/star`,{method:`POST`});return this.unwrapResponse(i)},unstar:async(e,t,n)=>{let r=this.getRoute(`data`),i=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed/${encodeURIComponent(n)}/star`,{method:`DELETE`});return this.unwrapResponse(i)},search:async(e,t,n,r)=>{let i=this.getRoute(`data`),a=new URLSearchParams;a.set(`query`,n),r?.type&&a.set(`type`,r.type),r?.actorId&&a.set(`actorId`,r.actorId),r?.dateFrom&&a.set(`dateFrom`,r.dateFrom),r?.dateTo&&a.set(`dateTo`,r.dateTo),r?.limit&&a.set(`limit`,String(r.limit)),r?.cursor&&a.set(`cursor`,r.cursor);let o=await this.fetch(`${this.baseUrl}${i}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/feed/search?${a.toString()}`);return this.unwrapResponse(o)},getChangelog:async(e,t,n)=>{let r=this.getRoute(`data`),i=new URLSearchParams;n?.field&&i.set(`field`,n.field),n?.actorId&&i.set(`actorId`,n.actorId),n?.dateFrom&&i.set(`dateFrom`,n.dateFrom),n?.dateTo&&i.set(`dateTo`,n.dateTo),n?.limit&&i.set(`limit`,String(n.limit)),n?.cursor&&i.set(`cursor`,n.cursor);let a=i.toString(),o=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/changelog${a?`?${a}`:``}`);return this.unwrapResponse(o)},subscribe:async(e,t,n)=>{let r=this.getRoute(`data`),i=await this.fetch(`${this.baseUrl}${r}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/subscribe`,{method:`POST`,body:JSON.stringify(n||{})});return this.unwrapResponse(i)},unsubscribe:async(e,t)=>{let n=this.getRoute(`data`),r=await this.fetch(`${this.baseUrl}${n}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/subscribe`,{method:`DELETE`});return this.unwrapResponse(r)}},this.data={query:async(e,t)=>{let n=this.getRoute(`data`),r=await this.fetch(`${this.baseUrl}${n}/${e}/query`,{method:`POST`,body:JSON.stringify(t)});return this.unwrapResponse(r)},find:async(e,t={})=>{let n=this.getRoute(`data`),r=new URLSearchParams,i=t,a={};if(`where`in t||`fields`in t||`orderBy`in t||`offset`in t?(i.where&&(a.filter=i.where),i.fields&&(a.select=i.fields),i.orderBy&&(a.sort=i.orderBy),i.limit!=null&&(a.top=i.limit),i.offset!=null&&(a.skip=i.offset),i.aggregations&&(a.aggregations=i.aggregations),i.groupBy&&(a.groupBy=i.groupBy)):Object.assign(a,t),a.top&&r.set(`top`,a.top.toString()),a.skip&&r.set(`skip`,a.skip.toString()),a.sort)if(Array.isArray(a.sort)&&typeof a.sort[0]==`object`)r.set(`sort`,JSON.stringify(a.sort));else{let e=Array.isArray(a.sort)?a.sort.join(`,`):a.sort;r.set(`sort`,e)}a.select&&r.set(`select`,a.select.join(`,`));let o=a.filter??a.filters;o&&(this.isFilterAST(o)||Array.isArray(o)?r.set(`filter`,JSON.stringify(o)):typeof o==`object`&&o&&Object.entries(o).forEach(([e,t])=>{t!=null&&r.append(e,String(t))})),a.aggregations&&r.set(`aggregations`,JSON.stringify(a.aggregations)),a.groupBy&&r.set(`groupBy`,a.groupBy.join(`,`));let s=await this.fetch(`${this.baseUrl}${n}/${e}?${r.toString()}`);return this.unwrapResponse(s)},get:async(e,t)=>{let n=this.getRoute(`data`),r=await this.fetch(`${this.baseUrl}${n}/${e}/${t}`);return this.unwrapResponse(r)},create:async(e,t)=>{let n=this.getRoute(`data`),r=await this.fetch(`${this.baseUrl}${n}/${e}`,{method:`POST`,body:JSON.stringify(t)});return this.unwrapResponse(r)},createMany:async(e,t)=>{let n=this.getRoute(`data`),r=await this.fetch(`${this.baseUrl}${n}/${e}/createMany`,{method:`POST`,body:JSON.stringify(t)});return this.unwrapResponse(r)},update:async(e,t,n,r)=>{let i=this.getRoute(`data`),a={};r?.ifMatch&&(a[`If-Match`]=String(r.ifMatch));let o=await this.fetch(`${this.baseUrl}${i}/${e}/${t}`,{method:`PATCH`,body:JSON.stringify(n),...Object.keys(a).length?{headers:a}:{}});return this.unwrapResponse(o)},batch:async(e,t)=>{let n=this.getRoute(`data`),r=await this.fetch(`${this.baseUrl}${n}/${e}/batch`,{method:`POST`,body:JSON.stringify(t)});return this.unwrapResponse(r)},updateMany:async(e,t,n)=>{let r=this.getRoute(`data`),i={records:t,options:n},a=await this.fetch(`${this.baseUrl}${r}/${e}/updateMany`,{method:`POST`,body:JSON.stringify(i)});return this.unwrapResponse(a)},delete:async(e,t,n)=>{let r=this.getRoute(`data`),i={};n?.ifMatch&&(i[`If-Match`]=String(n.ifMatch));let a=await this.fetch(`${this.baseUrl}${r}/${e}/${t}`,{method:`DELETE`,...Object.keys(i).length?{headers:i}:{}});return this.unwrapResponse(a)},deleteMany:async(e,t,n)=>{let r=this.getRoute(`data`),i={ids:t,options:n},a=await this.fetch(`${this.baseUrl}${r}/${e}/deleteMany`,{method:`POST`,body:JSON.stringify(i)});return this.unwrapResponse(a)}},this.baseUrl=e.baseUrl.replace(/\/$/,``),this.token=e.token,this.projectId=e.projectId,this.fetchImpl=e.fetch||globalThis.fetch.bind(globalThis),this.logger=e.logger||Bs({level:e.debug?`debug`:`info`,format:`pretty`}),this.realtimeAPI=new Vs(this.baseUrl,this.token),this.logger.debug(`ObjectStack client created`,{baseUrl:this.baseUrl})}async connect(){this.logger.debug(`Connecting to ObjectStack server`,{baseUrl:this.baseUrl});try{let e;try{let t=`${this.baseUrl}/api/v1/discovery`;this.logger.debug(`Probing protocol-standard discovery endpoint`,{url:t});let n=await this.fetchImpl(t);if(n.ok){let t=await n.json();e=t.data||t,this.logger.debug(`Discovered via /api/v1/discovery`)}}catch(e){this.logger.debug(`Protocol-standard discovery probe failed`,{error:e.message})}if(!e){let t;try{t=`${new URL(this.baseUrl).origin}/.well-known/objectstack`}catch{t=`/.well-known/objectstack`}this.logger.debug(`Falling back to .well-known discovery`,{url:t});let n=await this.fetchImpl(t);if(!n.ok)throw Error(`Failed to connect to ${t}: ${n.statusText}`);let r=await n.json();e=r.data||r}if(!e)throw Error(`Connection failed: No discovery data returned`);return this.discoveryInfo=e,this.logger.info(`Connected to ObjectStack server`,{version:e.version,apiName:e.apiName,services:e.services}),e}catch(e){throw this.logger.error(`Failed to connect to ObjectStack server`,e,{baseUrl:this.baseUrl}),e}}get capabilities(){let e=this.discoveryInfo?.capabilities;if(!e)return;let t={};for(let[n,r]of Object.entries(e))t[n]=typeof r==`object`&&r?!!r.enabled:!!r;return t}project(e){if(!e)throw Error(`[ObjectStack] project(id): projectId is required`);return new Us(this,e)}_baseUrl(){return this.baseUrl}_fetch(e,t){return this.fetch(e,t)}_unwrap(e){return this.unwrapResponse(e)}_isFilterAST(e){return this.isFilterAST(e)}setProjectId(e){this.projectId=e,this.logger.debug(`Active project changed`,{projectId:e})}getProjectId(){return this.projectId}get events(){return this.realtimeAPI}isFilterAST(e){return ai(e)}async unwrapResponse(e){let t=await e.json();return t&&typeof t.success==`boolean`&&`data`in t?t.data:t}async fetch(e,t={}){this.logger.debug(`HTTP request`,{method:t.method||`GET`,url:e,hasBody:!!t.body});let n={"Content-Type":`application/json`,...t.headers||{}};this.token&&(n.Authorization=`Bearer ${this.token}`),this.projectId&&(n[`X-Project-Id`]=this.projectId);let r=await this.fetchImpl(e,{...t,headers:n});if(this.logger.debug(`HTTP response`,{method:t.method||`GET`,url:e,status:r.status,ok:r.ok}),!r.ok){let n;try{n=await r.json()}catch{n={message:r.statusText}}this.logger.error(`HTTP request failed`,void 0,{method:t.method||`GET`,url:e,status:r.status,error:n});let i=n?.message??n?.error?.message??(typeof n?.error==`string`?n.error:void 0)??r.statusText,a=n?.code||n?.error?.code,o=Error(`[ObjectStack] ${a?`${a}: `:``}${i}`);throw o.code=a,o.category=n?.category,o.httpStatus=r.status,o.retryable=n?.retryable,o.details=n?.details||n,o}return r}getRoute(e){let t=this.discoveryInfo?.routes;if(t){let n=t[e];if(n)return n}return{data:`/api/v1/data`,metadata:`/api/v1/meta`,discovery:`/api/v1/discovery`,ui:`/api/v1/ui`,auth:`/api/v1/auth`,analytics:`/api/v1/analytics`,storage:`/api/v1/storage`,automation:`/api/v1/automation`,packages:`/api/v1/packages`,permissions:`/api/v1/permissions`,realtime:`/api/v1/realtime`,workflow:`/api/v1/workflow`,views:`/api/v1/ui/views`,notifications:`/api/v1/notifications`,ai:`/api/v1/ai`,i18n:`/api/v1/i18n`,feed:`/api/v1/feed`,graphql:`/graphql`}[e]||`/api/v1/${e}`}},Us=class{constructor(e,t){this.meta={getTypes:async()=>{let e=await this.parent._fetch(this.url(`/meta`));return this.parent._unwrap(e)},getItems:async(e,t)=>{let n=new URLSearchParams;t?.packageId&&n.set(`package`,t.packageId);let r=n.toString(),i=await this.parent._fetch(this.url(`/meta/${e}${r?`?${r}`:``}`));return this.parent._unwrap(i)},getItem:async(e,t,n)=>{let r=new URLSearchParams;n?.packageId&&r.set(`package`,n.packageId);let i=r.toString(),a=await this.parent._fetch(this.url(`/meta/${e}/${t}${i?`?${i}`:``}`));return this.parent._unwrap(a)},saveItem:async(e,t,n)=>{let r=await this.parent._fetch(this.url(`/meta/${e}/${t}`),{method:`PUT`,body:JSON.stringify(n)});return this.parent._unwrap(r)},deleteItem:async(e,t)=>{let n=await this.parent._fetch(this.url(`/meta/${encodeURIComponent(e)}/${encodeURIComponent(t)}`),{method:`DELETE`});return this.parent._unwrap(n)},getHistory:async(e,t,n)=>{let r=new URLSearchParams;n?.sinceSeq!==void 0&&r.set(`sinceSeq`,String(n.sinceSeq)),n?.limit!==void 0&&r.set(`limit`,String(n.limit));let i=r.toString(),a=await this.parent._fetch(this.url(`/meta/${encodeURIComponent(e)}/${encodeURIComponent(t)}/history${i?`?${i}`:``}`));return this.parent._unwrap(a)}},this.data={query:async(e,t)=>{let n=await this.parent._fetch(this.url(`/data/${e}/query`),{method:`POST`,body:JSON.stringify(t)});return this.parent._unwrap(n)},find:async(e,t={})=>{let n=new URLSearchParams,r=t,i={};if(`where`in t||`fields`in t||`orderBy`in t||`offset`in t?(r.where&&(i.filter=r.where),r.fields&&(i.select=r.fields),r.orderBy&&(i.sort=r.orderBy),r.limit!=null&&(i.top=r.limit),r.offset!=null&&(i.skip=r.offset),r.aggregations&&(i.aggregations=r.aggregations),r.groupBy&&(i.groupBy=r.groupBy)):Object.assign(i,t),i.top&&n.set(`top`,i.top.toString()),i.skip&&n.set(`skip`,i.skip.toString()),i.sort)if(Array.isArray(i.sort)&&typeof i.sort[0]==`object`)n.set(`sort`,JSON.stringify(i.sort));else{let e=Array.isArray(i.sort)?i.sort.join(`,`):i.sort;n.set(`sort`,e)}i.select&&n.set(`select`,i.select.join(`,`));let a=i.filter??i.filters;a&&(this.parent._isFilterAST(a)||Array.isArray(a)?n.set(`filter`,JSON.stringify(a)):typeof a==`object`&&a&&Object.entries(a).forEach(([e,t])=>{t!=null&&n.append(e,String(t))})),i.aggregations&&n.set(`aggregations`,JSON.stringify(i.aggregations)),i.groupBy&&n.set(`groupBy`,i.groupBy.join(`,`));let o=n.toString(),s=await this.parent._fetch(this.url(`/data/${e}${o?`?${o}`:``}`));return this.parent._unwrap(s)},get:async(e,t)=>{let n=await this.parent._fetch(this.url(`/data/${e}/${t}`));return this.parent._unwrap(n)},create:async(e,t)=>{let n=await this.parent._fetch(this.url(`/data/${e}`),{method:`POST`,body:JSON.stringify(t)});return this.parent._unwrap(n)},createMany:async(e,t)=>{let n=await this.parent._fetch(this.url(`/data/${e}/createMany`),{method:`POST`,body:JSON.stringify(t)});return this.parent._unwrap(n)},update:async(e,t,n)=>{let r=await this.parent._fetch(this.url(`/data/${e}/${t}`),{method:`PATCH`,body:JSON.stringify(n)});return this.parent._unwrap(r)},batch:async(e,t)=>{let n=await this.parent._fetch(this.url(`/data/${e}/batch`),{method:`POST`,body:JSON.stringify(t)});return this.parent._unwrap(n)},updateMany:async(e,t,n)=>{let r={records:t,options:n},i=await this.parent._fetch(this.url(`/data/${e}/updateMany`),{method:`POST`,body:JSON.stringify(r)});return this.parent._unwrap(i)},delete:async(e,t)=>{let n=await this.parent._fetch(this.url(`/data/${e}/${t}`),{method:`DELETE`});return this.parent._unwrap(n)},deleteMany:async(e,t,n)=>{let r={ids:t,options:n},i=await this.parent._fetch(this.url(`/data/${e}/deleteMany`),{method:`POST`,body:JSON.stringify(r)});return this.parent._unwrap(i)}},this.packages={list:async()=>{let e=await this.parent._fetch(this.url(`/packages`));return this.parent._unwrap(e)},get:async(e,t)=>{let n=t?`?version=${encodeURIComponent(t)}`:``,r=await this.parent._fetch(this.url(`/packages/${encodeURIComponent(e)}${n}`));return this.parent._unwrap(r)}},this.automation={getFlow:async e=>{let t=await this.parent._fetch(this.url(`/automation/${encodeURIComponent(e)}`));return this.parent._unwrap(t)},execute:async(e,t)=>{let n=await this.parent._fetch(this.url(`/automation/${encodeURIComponent(e)}/trigger`),{method:`POST`,body:JSON.stringify(t??{})});return this.parent._unwrap(n)},listRuns:async(e,t)=>{let n=new URLSearchParams;t?.limit!=null&&n.set(`limit`,String(t.limit)),t?.cursor&&n.set(`cursor`,t.cursor);let r=n.toString(),i=await this.parent._fetch(this.url(`/automation/${encodeURIComponent(e)}/runs${r?`?${r}`:``}`));return this.parent._unwrap(i)},getRun:async(e,t)=>{let n=await this.parent._fetch(this.url(`/automation/${encodeURIComponent(e)}/runs/${encodeURIComponent(t)}`));return this.parent._unwrap(n)}},this.parent=e,this.projectId=t}getProjectId(){return this.projectId}scope(){return`/api/v1/projects/${encodeURIComponent(this.projectId)}`}url(e){return`${this.parent._baseUrl()}${this.scope()}${e}`}},Ws=(0,F.createContext)(null);function Gs({client:e,children:t}){return F.createElement(Ws.Provider,{value:e},t)}function L(){let e=(0,F.useContext)(Ws);if(!e)throw Error(`useClient must be used within an ObjectStackProvider. Make sure your component is wrapped with <ObjectStackProvider client={...}>.`);return e}function Ks(e,t,n){let r=L();(0,F.useEffect)(()=>{if(!r)return;let i=r.events.subscribeMetadata(e,t,n);return()=>{i()}},[r,e,t,n?.packageId])}var R=de(),qs=class extends F.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary] Uncaught error:`,e,t.componentStack)}handleReset=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError?this.props.fallback?this.props.fallback:(0,R.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background p-6`,children:(0,R.jsxs)(`div`,{className:`max-w-md w-full space-y-4 text-center`,children:[(0,R.jsx)(`div`,{className:`mx-auto flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,R.jsx)(Be,{className:`h-6 w-6 text-destructive`})}),(0,R.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Something went wrong`}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:this.state.error?.message||`An unexpected error occurred.`}),(0,R.jsx)(`pre`,{className:`mt-2 max-h-40 overflow-auto rounded-lg bg-muted p-3 text-left text-xs font-mono text-muted-foreground`,children:this.state.error?.stack?.split(`
|
|
4
|
-
`).slice(0,6).join(`
|
|
5
|
-
`)}),(0,R.jsxs)(`button`,{onClick:this.handleReset,className:`inline-flex items-center gap-2 rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 transition-colors`,children:[(0,R.jsx)(Ut,{className:`h-4 w-4`}),`Try Again`]})]})}):this.props.children}},Js=768;function Ys(){let[e,t]=F.useState(void 0);return F.useEffect(()=>{let e=window.matchMedia(`(max-width: ${Js-1}px)`),n=()=>{t(window.innerWidth<Js)};return e.addEventListener(`change`,n),t(window.innerWidth<Js),()=>e.removeEventListener(`change`,n)},[]),!!e}function z(...e){return o(r(e))}var Xs=s(`inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,{variants:{variant:{default:`bg-primary text-primary-foreground shadow hover:bg-primary/90`,destructive:`bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90`,outline:`border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground`,secondary:`bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-9 px-4 py-2`,sm:`h-8 rounded-md px-3 text-xs`,lg:`h-10 rounded-md px-8`,icon:`h-9 w-9`}},defaultVariants:{variant:`default`,size:`default`}}),B=F.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...a},o)=>(0,R.jsx)(r?i:`button`,{className:z(Xs({variant:t,size:n,className:e})),ref:o,...a}));B.displayName=`Button`;var V=F.forwardRef(({className:e,type:t,...n},r)=>(0,R.jsx)(`input`,{type:t,className:z(`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));V.displayName=`Input`;var Zs=F.forwardRef(({className:e,orientation:t=`horizontal`,decorative:n=!0,...r},i)=>(0,R.jsx)(Lr,{ref:i,decorative:n,orientation:t,className:z(`shrink-0 bg-border`,t===`horizontal`?`h-[1px] w-full`:`h-full w-[1px]`,e),...r}));Zs.displayName=Lr.displayName;var Qs=fe,$s=d,ec=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(C,{className:z(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t,ref:n}));ec.displayName=C.displayName;var tc=s(`fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:duration-500`,{variants:{side:{top:`inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top`,bottom:`inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom`,left:`inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm`,right:`inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm`}},defaultVariants:{side:`right`}}),nc=F.forwardRef(({side:e=`right`,className:t,children:n,...r},i)=>(0,R.jsxs)($s,{children:[(0,R.jsx)(ec,{}),(0,R.jsxs)(re,{ref:i,className:z(tc({side:e}),t),...r,children:[n,(0,R.jsxs)(ae,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary`,children:[(0,R.jsx)(At,{className:`h-4 w-4`}),(0,R.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));nc.displayName=re.displayName;var rc=({className:e,...t})=>(0,R.jsx)(`div`,{className:z(`flex flex-col space-y-2 text-center sm:text-left`,e),...t});rc.displayName=`SheetHeader`;var ic=({className:e,...t})=>(0,R.jsx)(`div`,{className:z(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});ic.displayName=`SheetFooter`;var ac=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(me,{ref:n,className:z(`text-lg font-semibold text-foreground`,e),...t}));ac.displayName=me.displayName;var oc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(T,{ref:n,className:z(`text-sm text-muted-foreground`,e),...t}));oc.displayName=T.displayName;function H({className:e,...t}){return(0,R.jsx)(`div`,{className:z(`bg-muted animate-pulse rounded-md`,e),...t})}var sc=Tr,cc=dr,lc=Bn,uc=F.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,R.jsx)(Sr,{ref:r,sideOffset:t,className:z(`z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n}));uc.displayName=Sr.displayName;var dc=`sidebar_state`,fc=3600*24*7,pc=`16rem`,mc=`18rem`,hc=`3rem`,gc=`b`,_c=F.createContext(null);function vc(){let e=F.useContext(_c);if(!e)throw Error(`useSidebar must be used within a SidebarProvider`);return e}var yc=F.forwardRef(({defaultOpen:e=!0,open:t,onOpenChange:n,className:r,style:i,children:a,...o},s)=>{let c=Ys(),[l,u]=F.useState(!1),[d,f]=F.useState(e),p=t??d,m=F.useCallback(e=>{let t=typeof e==`function`?e(p):e;n?n(t):f(t),document.cookie=`${dc}=${t}; path=/; max-age=${fc}`},[n,p]),h=F.useCallback(()=>c?u(e=>!e):m(e=>!e),[c,m,u]);F.useEffect(()=>{let e=e=>{e.key===gc&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),h())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[h]);let g=p?`expanded`:`collapsed`,_=F.useMemo(()=>({state:g,open:p,setOpen:m,isMobile:c,openMobile:l,setOpenMobile:u,toggleSidebar:h}),[g,p,m,c,l,u,h]);return(0,R.jsx)(_c.Provider,{value:_,children:(0,R.jsx)(sc,{delayDuration:0,children:(0,R.jsx)(`div`,{style:{"--sidebar-width":pc,"--sidebar-width-icon":hc,...i},className:z(`group/sidebar-wrapper has-data-[variant=inset]:bg-sidebar flex min-h-0 w-full`,r),ref:s,...o,children:a})})})});yc.displayName=`SidebarProvider`;var bc=F.forwardRef(({side:e=`left`,variant:t=`sidebar`,collapsible:n=`offcanvas`,className:r,children:i,...a},o)=>{let{isMobile:s,state:c,openMobile:l,setOpenMobile:u}=vc();return n===`none`?(0,R.jsx)(`div`,{className:z(`bg-sidebar text-sidebar-foreground flex h-full w-[var(--sidebar-width)] flex-col`,r),ref:o,...a,children:i}):s?(0,R.jsx)(Qs,{open:l,onOpenChange:u,...a,children:(0,R.jsx)(nc,{"data-sidebar":`sidebar`,"data-mobile":`true`,className:`bg-sidebar text-sidebar-foreground w-[var(--sidebar-width)] p-0 [&>button]:hidden`,style:{"--sidebar-width":mc},side:e,children:(0,R.jsx)(`div`,{className:`flex h-full w-full flex-col`,children:i})})}):(0,R.jsx)(`div`,{ref:o,className:z(`bg-sidebar text-sidebar-foreground hidden md:flex h-svh w-[var(--sidebar-width)] shrink-0 flex-col border-r transition-[width] duration-200 ease-linear overflow-hidden`,c===`collapsed`&&n===`offcanvas`&&`w-0 border-0`,c===`collapsed`&&n===`icon`&&`w-[var(--sidebar-width-icon)]`,r),"data-state":c,"data-collapsible":c===`collapsed`?n:``,"data-variant":t,"data-side":e,...a,children:i})});bc.displayName=`Sidebar`;var xc=F.forwardRef(({className:e,onClick:t,...n},r)=>{let{toggleSidebar:i}=vc();return(0,R.jsxs)(B,{ref:r,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:z(`h-7 w-7`,e),onClick:e=>{t?.(e),i()},...n,children:[(0,R.jsx)(Xt,{}),(0,R.jsx)(`span`,{className:`sr-only`,children:`Toggle Sidebar`})]})});xc.displayName=`SidebarTrigger`;var Sc=F.forwardRef(({className:e,...t},n)=>{let{toggleSidebar:r}=vc();return(0,R.jsx)(`button`,{ref:n,"data-sidebar":`rail`,"aria-label":`Toggle Sidebar`,tabIndex:-1,onClick:r,title:`Toggle Sidebar`,className:z(`hover:after:bg-sidebar-border absolute inset-y-0 z-20 hidden w-4 -translate-x-1/2 transition-all ease-linear after:absolute after:inset-y-0 after:left-1/2 after:w-[2px] group-data-[side=left]:-right-4 group-data-[side=right]:left-0 sm:flex`,`[[data-side=left]_&]:cursor-w-resize [[data-side=right]_&]:cursor-e-resize`,`[[data-side=left][data-state=collapsed]_&]:cursor-e-resize [[data-side=right][data-state=collapsed]_&]:cursor-w-resize`,`group-data-[collapsible=offcanvas]:translate-x-0 group-data-[collapsible=offcanvas]:after:left-full group-data-[collapsible=offcanvas]:hover:bg-sidebar`,`[[data-side=left][data-collapsible=offcanvas]_&]:-right-2`,`[[data-side=right][data-collapsible=offcanvas]_&]:-left-2`,e),...t})});Sc.displayName=`SidebarRail`;var Cc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`main`,{ref:n,className:z(`relative flex min-h-svh flex-1 flex-col bg-background`,`peer-data-[variant=inset]:min-h-[calc(100svh-theme(spacing.4))] md:peer-data-[variant=inset]:m-2 md:peer-data-[state=collapsed]:peer-data-[variant=inset]:ml-2 md:peer-data-[variant=inset]:ml-0 md:peer-data-[variant=inset]:rounded-xl md:peer-data-[variant=inset]:shadow`,e),...t}));Cc.displayName=`SidebarInset`;var wc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(V,{ref:n,"data-sidebar":`input`,className:z(`h-8 w-full bg-background shadow-none focus-visible:ring-2 focus-visible:ring-sidebar-ring`,e),...t}));wc.displayName=`SidebarInput`;var Tc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,"data-sidebar":`header`,className:z(`flex flex-col gap-2 p-2`,e),...t}));Tc.displayName=`SidebarHeader`;var Ec=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,"data-sidebar":`footer`,className:z(`flex flex-col gap-2 p-2`,e),...t}));Ec.displayName=`SidebarFooter`;var Dc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Zs,{ref:n,"data-sidebar":`separator`,className:z(`mx-2 w-auto bg-sidebar-border`,e),...t}));Dc.displayName=`SidebarSeparator`;var Oc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,"data-sidebar":`content`,className:z(`flex min-h-0 flex-1 flex-col gap-2 overflow-auto`,e),...t}));Oc.displayName=`SidebarContent`;var kc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,"data-sidebar":`group`,className:z(`relative flex w-full min-w-0 flex-col p-2`,e),...t}));kc.displayName=`SidebarGroup`;var Ac=F.forwardRef(({className:e,asChild:t=!1,...n},r)=>(0,R.jsx)(t?i:`div`,{ref:r,"data-sidebar":`group-label`,className:z(`text-xs/6 font-medium text-sidebar-foreground/70 ring-sidebar-ring flex h-8 shrink-0 items-center rounded-md px-2 outline-none transition-[margin,opacity] duration-200 ease-linear focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0 [[data-collapsible=icon]_&]:-mt-8 [[data-collapsible=icon]_&]:opacity-0 [[data-collapsible=icon]_&]:overflow-hidden`,e),...n}));Ac.displayName=`SidebarGroupLabel`;var jc=F.forwardRef(({className:e,asChild:t=!1,...n},r)=>(0,R.jsx)(t?i:`button`,{ref:r,"data-sidebar":`group-action`,className:z(`absolute right-3 top-3.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0`,`after:absolute after:-inset-2 after:md:hidden`,`group-data-[collapsible=icon]:hidden`,e),...n}));jc.displayName=`SidebarGroupAction`;var Mc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,"data-sidebar":`group-content`,className:z(`w-full text-sm`,e),...t}));Mc.displayName=`SidebarGroupContent`;var Nc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`ul`,{ref:n,"data-sidebar":`menu`,className:z(`flex w-full min-w-0 flex-col gap-1`,e),...t}));Nc.displayName=`SidebarMenu`;var Pc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`li`,{ref:n,"data-sidebar":`menu-item`,className:z(`group/menu-item relative`,e),...t}));Pc.displayName=`SidebarMenuItem`;var Fc=F.forwardRef(({asChild:e=!1,isActive:t=!1,variant:n=`default`,size:r=`default`,tooltip:a,className:o,...s},c)=>{let l=e?i:`button`,{isMobile:u,state:d}=vc(),f=(0,R.jsx)(l,{ref:c,"data-sidebar":`menu-button`,"data-size":r,"data-active":t,className:z(Ic({variant:n,size:r}),o),...s});return a?(typeof a==`string`&&(a={children:a}),(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:f}),(0,R.jsx)(uc,{side:`right`,align:`center`,hidden:d!==`collapsed`||u,...a})]})):f});Fc.displayName=`SidebarMenuButton`;var Ic=s(`peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0`,{variants:{variant:{default:`hover:bg-sidebar-accent hover:text-sidebar-accent-foreground`,outline:`bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]`},size:{default:`h-8 text-sm`,sm:`h-7 text-xs`,lg:`h-12 text-sm group-data-[collapsible=icon]:!p-0`}},defaultVariants:{variant:`default`,size:`default`}}),Lc=F.forwardRef(({className:e,asChild:t=!1,showOnHover:n=!1,...r},a)=>(0,R.jsx)(t?i:`button`,{ref:a,"data-sidebar":`menu-action`,className:z(`absolute right-1 top-1.5 flex aspect-square w-5 items-center justify-center rounded-md p-0 text-sidebar-foreground outline-none ring-sidebar-ring transition-transform hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0`,`after:absolute after:-inset-2 after:md:hidden`,`peer-data-[size=sm]/menu-button:top-1`,`peer-data-[size=default]/menu-button:top-1.5`,`peer-data-[size=lg]/menu-button:top-2.5`,`group-data-[collapsible=icon]:hidden`,n&&`group-focus-within/menu-item:opacity-100 group-hover/menu-item:opacity-100 data-[state=open]:opacity-100 peer-data-[active=true]/menu-button:text-sidebar-accent-foreground md:opacity-0`,e),...r}));Lc.displayName=`SidebarMenuAction`;var Rc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,"data-sidebar":`menu-badge`,className:z(`text-sidebar-foreground pointer-events-none absolute right-1 flex h-5 min-w-5 items-center justify-center rounded-md px-1 text-xs font-medium tabular-nums select-none`,`peer-hover/menu-button:text-sidebar-accent-foreground peer-data-[active=true]/menu-button:text-sidebar-accent-foreground`,`peer-data-[size=sm]/menu-button:top-1`,`peer-data-[size=default]/menu-button:top-1.5`,`peer-data-[size=lg]/menu-button:top-2.5`,`group-data-[collapsible=icon]:hidden`,e),...t}));Rc.displayName=`SidebarMenuBadge`;var zc=F.forwardRef(({className:e,showIcon:t=!1,...n},r)=>{let i=F.useMemo(()=>`${Math.floor(Math.random()*40)+50}%`,[]);return(0,R.jsxs)(`div`,{ref:r,"data-sidebar":`menu-skeleton`,className:z(`rounded-md h-8 flex gap-2 px-2 items-center`,e),...n,children:[t&&(0,R.jsx)(H,{className:`size-4 rounded-md`,"data-sidebar":`menu-skeleton-icon`}),(0,R.jsx)(H,{className:`h-4 flex-1 max-w-[var(--skeleton-width)]`,"data-sidebar":`menu-skeleton-text`,style:{"--skeleton-width":i}})]})});zc.displayName=`SidebarMenuSkeleton`;var Bc=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`ul`,{ref:n,"data-sidebar":`menu-sub`,className:z(`mx-3.5 flex min-w-0 translate-x-px flex-col gap-1 border-l border-sidebar-border px-2.5 py-0.5`,`group-data-[collapsible=icon]:hidden`,e),...t}));Bc.displayName=`SidebarMenuSub`;var Vc=F.forwardRef(({...e},t)=>(0,R.jsx)(`li`,{ref:t,...e}));Vc.displayName=`SidebarMenuSubItem`;var Hc=F.forwardRef(({asChild:e=!1,size:t=`md`,isActive:n,className:r,...a},o)=>(0,R.jsx)(e?i:`a`,{ref:o,"data-sidebar":`menu-sub-button`,"data-size":t,"data-active":n,className:z(`flex h-7 min-w-0 -translate-x-px items-center gap-2 overflow-hidden rounded-md px-2 text-sidebar-foreground outline-none ring-sidebar-ring hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&>span:last-child]:truncate [&>svg]:size-4 [&>svg]:shrink-0 [&>svg]:text-sidebar-accent-foreground`,`data-[active=true]:bg-sidebar-accent data-[active=true]:text-sidebar-accent-foreground`,t===`sm`&&`text-xs`,t===`md`&&`text-sm`,r),...a}));Hc.displayName=`SidebarMenuSubButton`;var Uc=1,Wc=1e6,Gc=0;function Kc(){return Gc=(Gc+1)%(2**53-1),Gc.toString()}var qc=new Map,Jc=e=>{if(qc.has(e))return;let t=setTimeout(()=>{qc.delete(e),Qc({type:`REMOVE_TOAST`,toastId:e})},Wc);qc.set(e,t)},Yc=(e,t)=>{switch(t.type){case`ADD_TOAST`:return{...e,toasts:[t.toast,...e.toasts].slice(0,Uc)};case`UPDATE_TOAST`:return{...e,toasts:e.toasts.map(e=>e.id===t.toast.id?{...e,...t.toast}:e)};case`DISMISS_TOAST`:{let{toastId:n}=t;return n?Jc(n):e.toasts.forEach(e=>{Jc(e.id)}),{...e,toasts:e.toasts.map(e=>e.id===n||n===void 0?{...e,open:!1}:e)}}case`REMOVE_TOAST`:return t.toastId===void 0?{...e,toasts:[]}:{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}},Xc=[],Zc={toasts:[]};function Qc(e){Zc=Yc(Zc,e),Xc.forEach(e=>{e(Zc)})}function U({...e}){let t=Kc(),n=e=>Qc({type:`UPDATE_TOAST`,toast:{...e,id:t}}),r=()=>Qc({type:`DISMISS_TOAST`,toastId:t});return Qc({type:`ADD_TOAST`,toast:{...e,id:t,open:!0,onOpenChange:e=>{e||r()}}}),{id:t,dismiss:r,update:n}}function $c(){let[e,t]=F.useState(Zc);return F.useEffect(()=>(Xc.push(t),()=>{let e=Xc.indexOf(t);e>-1&&Xc.splice(e,1)}),[e]),{...e,toast:U,dismiss:e=>Qc({type:`DISMISS_TOAST`,toastId:e})}}var el=Hr,tl=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Kr,{ref:n,className:z(`fixed top-0 z-[100] flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]`,e),...t}));tl.displayName=Kr.displayName;var nl=s(`group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full`,{variants:{variant:{default:`border bg-background text-foreground`,destructive:`destructive group border-destructive bg-destructive text-destructive-foreground`}},defaultVariants:{variant:`default`}}),rl=F.forwardRef(({className:e,variant:t,...n},r)=>(0,R.jsx)(Vr,{ref:r,className:z(nl({variant:t}),e),...n}));rl.displayName=Vr.displayName;var il=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(qr,{ref:n,className:z(`inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive`,e),...t}));il.displayName=qr.displayName;var al=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Ur,{ref:n,className:z(`absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600`,e),"toast-close":``,...t,children:(0,R.jsx)(At,{className:`h-4 w-4`})}));al.displayName=Ur.displayName;var ol=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Wr,{ref:n,className:z(`text-sm font-semibold`,e),...t}));ol.displayName=Wr.displayName;var sl=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Gr,{ref:n,className:z(`text-sm opacity-90`,e),...t}));sl.displayName=Gr.displayName;function cl(){let{toasts:e}=$c();return(0,R.jsxs)(el,{children:[e.map(function({id:e,title:t,description:n,action:r,...i}){return(0,R.jsxs)(rl,{...i,children:[(0,R.jsxs)(`div`,{className:`grid gap-1`,children:[t&&(0,R.jsx)(ol,{children:t}),n&&(0,R.jsx)(sl,{children:n})]}),r,(0,R.jsx)(al,{})]},e)}),(0,R.jsx)(tl,{})]})}var ll=F.forwardRef(({className:e,children:t,...n},r)=>(0,R.jsxs)(Yn,{ref:r,className:z(`relative overflow-hidden`,e),...n,children:[(0,R.jsx)(tr,{className:`h-full w-full rounded-[inherit]`,children:t}),(0,R.jsx)(ul,{}),(0,R.jsx)(br,{})]}));ll.displayName=Yn.displayName;var ul=F.forwardRef(({className:e,orientation:t=`vertical`,...n},r)=>(0,R.jsx)(rr,{ref:r,orientation:t,className:z(`flex touch-none select-none transition-colors`,t===`vertical`&&`h-full w-2.5 border-l border-l-transparent p-[1px]`,t===`horizontal`&&`h-2.5 flex-col border-t border-t-transparent p-[1px]`,e),...n,children:(0,R.jsx)(Nr,{className:`relative flex-1 rounded-full bg-border`})}));ul.displayName=rr.displayName;var dl=`objectstack:ai-chat-messages`,fl=`objectstack:ai-chat-panel-open`;function pl(){try{let e=localStorage.getItem(dl);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}}function ml(e){try{localStorage.setItem(dl,JSON.stringify(e))}catch{}}function hl(){try{return localStorage.getItem(fl)===`true`}catch{return!1}}function gl(){let[e,t]=(0,F.useState)(hl),n=(0,F.useCallback)(e=>{t(e);try{localStorage.setItem(fl,String(e))}catch{}},[]),r=(0,F.useCallback)(()=>{t(e=>{let t=!e;try{localStorage.setItem(fl,String(t))}catch{}return t})},[]);return(0,F.useEffect)(()=>{function e(e){e.shiftKey&&(e.ctrlKey||e.metaKey)&&e.key===`I`&&(e.preventDefault(),r())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r]),{isOpen:e,setOpen:n,toggle:r}}function _l(){let e=be({strict:!1}),t=Te();return(0,F.useMemo)(()=>{let n={appName:`studio`};return e.projectId&&(n.projectId=e.projectId),e.package&&(n.packageName=e.package),e.type&&e.name?(n.objectName=e.type,n.recordId=e.name):e.name&&t.pathname.includes(`/objects/`)&&(n.objectName=`object`,n.recordId=e.name),n.route=t.pathname,n},[e.projectId,e.package,e.type,e.name,t.pathname])}function vl(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r==null||r===``||t.set(n,String(r));return t}function yl(){return``}var bl={serverUrl:yl(),singleProject:!1,defaultProjectId:null,defaultOrgId:null};async function xl(){let e=Sl();try{let t=await fetch(`${e}/api/v1/studio/runtime-config`,{credentials:`include`});if(!t.ok)return;let n=await t.json();if(!n||typeof n!=`object`)return;n.singleProject&&(bl.singleProject=!0,bl.defaultProjectId=n.defaultProjectId??`proj_local`,bl.defaultOrgId=n.defaultOrgId??`org_local`)}catch{}}function Sl(){return bl.serverUrl}function Cl(){console.log(`[Studio Config]`,{apiBaseUrl:Sl(),serverUrl:bl.serverUrl,singleProject:bl.singleProject,defaultProjectId:bl.defaultProjectId,defaultOrgId:bl.defaultOrgId})}var wl=`metadata_assistant`;function Tl(e){let t=Sl(),[n,r]=(0,F.useState)({skills:[],loading:!0}),i=vl(e);i.set(`agent`,wl);let a=i.toString();return(0,F.useEffect)(()=>{let e=!1;return r(e=>({...e,loading:!0,error:void 0})),fetch(`${t}/api/v1/ai/assistant?${a}`,{credentials:`include`}).then(async e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(t=>{e||r({agent:t.agent,skills:t.skills??[],loading:!1})}).catch(t=>{e||r({skills:[],loading:!1,error:String(t?.message??t)})}),()=>{e=!0}},[t,a]),n}var El=380,Dl=`/api/v1/ai/assistant/chat`,Ol=`objectstack:ai-chat-skill`;function kl(e){return(e.parts??[]).filter(e=>e.type===`text`).map(e=>e.text).join(``)}function Al(e){return e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function jl(e){if(!e||typeof e!=`object`)return``;let t=Object.entries(e);return t.length===0?``:t.slice(0,4).map(([e,t])=>{let n;try{n=typeof t==`string`?t:JSON.stringify(t)??String(t)}catch{n=String(t)}return`${e}: ${n.length>30?n.slice(0,30)+`…`:n}`}).join(`, `)}function Ml(e){return e.type===`dynamic-tool`}function Nl(e,t=80){let n;try{n=typeof e==`string`?e:JSON.stringify(e)??``}catch{n=String(e??``)}return n.length>t?n.slice(0,t)+`…`:n}function Pl(e){return`${e}${Dl}`}function Fl(){try{return localStorage.getItem(Ol)}catch{return null}}function Il(e){try{e?localStorage.setItem(Ol,e):localStorage.removeItem(Ol)}catch{}}function Ll(e){let t=/^\/([a-z][a-z0-9_]*)(?:\s+(.*))?$/is.exec(e.trim());return t?{skill:t[1].toLowerCase(),rest:(t[2]??``).trim()}:null}function Rl({reasoning:e}){let[t,n]=(0,F.useState)(!1);return e.length===0?null:(0,R.jsxs)(`div`,{"data-testid":`reasoning-display`,className:`flex flex-col gap-1 rounded-md border border-border/30 bg-muted/30 px-2.5 py-2 text-xs`,children:[(0,R.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1.5 text-left text-muted-foreground hover:text-foreground transition-colors`,children:[t?(0,R.jsx)(We,{className:`h-3 w-3 shrink-0`}):(0,R.jsx)(je,{className:`h-3 w-3 shrink-0`}),(0,R.jsx)(Tt,{className:`h-3 w-3 shrink-0`}),(0,R.jsx)(`span`,{className:`font-medium`,children:`Thinking`}),(0,R.jsxs)(`span`,{className:`text-[10px] opacity-60`,children:[`(`,e.length,` step`,e.length===1?``:`s`,`)`]})]}),t&&(0,R.jsx)(`div`,{className:`mt-1 space-y-1 pl-5 text-muted-foreground italic border-l-2 border-border/30`,children:e.map((e,t)=>(0,R.jsx)(`p`,{className:`text-[11px] leading-relaxed`,children:e},t))})]})}function zl({activeSteps:e,completedSteps:t}){if(e.size===0)return null;let n=t.length+e.size,r=t.length+1;return(0,R.jsxs)(`div`,{"data-testid":`step-progress`,className:`flex flex-col gap-1.5 rounded-md border border-blue-500/30 bg-blue-500/5 px-2.5 py-2 text-xs`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(Qt,{className:`h-3 w-3 shrink-0 text-blue-600 dark:text-blue-400`}),(0,R.jsxs)(`span`,{className:`font-medium text-blue-700 dark:text-blue-300`,children:[`Step `,r,` of `,n]})]}),Array.from(e.values()).map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center gap-2 pl-5`,children:[(0,R.jsx)(tt,{className:`h-3 w-3 shrink-0 animate-spin text-blue-600 dark:text-blue-400`}),(0,R.jsx)(`span`,{className:`text-blue-700 dark:text-blue-300`,children:e.stepName})]},t))]})}function Bl({part:e,onApprove:t,onDeny:n}){let r=Al(e.toolName),i=jl(e.input);switch(e.state){case`input-streaming`:return(0,R.jsxs)(`div`,{"data-testid":`tool-invocation-planning`,className:`flex items-start gap-2 rounded-md border border-blue-500/40 bg-blue-500/10 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(tt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin text-blue-600 dark:text-blue-400`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`span`,{className:`font-medium text-blue-700 dark:text-blue-300`,children:[`Planning to call `,r]}),i&&(0,R.jsx)(`p`,{className:`mt-0.5 truncate text-blue-600/80 dark:text-blue-300/80`,children:i})]})]});case`input-available`:return(0,R.jsxs)(`div`,{"data-testid":`tool-invocation-calling`,className:`flex items-start gap-2 rounded-md border border-border/50 bg-muted/50 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(tt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin text-primary`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`span`,{className:`font-medium`,children:[`Calling `,r]}),i&&(0,R.jsx)(`p`,{className:`mt-0.5 truncate text-muted-foreground`,children:i})]})]});case`approval-requested`:return(0,R.jsxs)(`div`,{"data-testid":`tool-invocation-confirm`,className:`flex flex-col gap-2 rounded-md border border-yellow-500/40 bg-yellow-500/10 px-2.5 py-2 text-xs`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,R.jsx)(Ae,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-yellow-600 dark:text-yellow-400`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`span`,{className:`font-medium`,children:[`Confirm: `,r]}),i&&(0,R.jsx)(`p`,{className:`mt-0.5 text-muted-foreground`,children:i})]})]}),e.approval&&t&&n&&(0,R.jsxs)(`div`,{className:`flex gap-2 pl-5`,children:[(0,R.jsxs)(B,{size:`sm`,variant:`outline`,className:`h-6 px-2 text-xs`,onClick:()=>t(e.approval.id),children:[(0,R.jsx)(ct,{className:`mr-1 h-3 w-3`}),`Approve`]}),(0,R.jsxs)(B,{size:`sm`,variant:`ghost`,className:`h-6 px-2 text-xs text-destructive hover:text-destructive`,onClick:()=>n(e.approval.id),children:[(0,R.jsx)(Oe,{className:`mr-1 h-3 w-3`}),`Deny`]})]})]});case`output-available`:return(0,R.jsxs)(`div`,{"data-testid":`tool-invocation-result`,className:`flex items-start gap-2 rounded-md border border-green-500/30 bg-green-500/10 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(ct,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-green-600 dark:text-green-400`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:r}),(0,R.jsx)(`p`,{className:`mt-0.5 text-muted-foreground truncate`,children:Nl(e.output)})]})]});case`output-error`:return(0,R.jsxs)(`div`,{"data-testid":`tool-invocation-error`,className:`flex items-start gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(Oe,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`span`,{className:`font-medium`,children:[r,` failed`]}),(0,R.jsx)(`p`,{className:`mt-0.5 text-destructive/80`,children:e.errorText})]})]});case`output-denied`:return(0,R.jsxs)(`div`,{"data-testid":`tool-invocation-denied`,className:`flex items-start gap-2 rounded-md border border-border/50 bg-muted/50 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(Oe,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,R.jsxs)(`span`,{className:`font-medium text-muted-foreground`,children:[r,` — denied`]})]});default:return(0,R.jsxs)(`div`,{"data-testid":`tool-invocation-unknown`,className:`flex items-start gap-2 rounded-md border border-border/50 bg-muted/50 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(dn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`font-medium`,children:r})]})}}function Vl(){let{isOpen:e,setOpen:t,toggle:n}=gl(),[r,i]=(0,F.useState)(``),[a,o]=(0,F.useState)(Fl),[s,c]=(0,F.useState)(!1),[l,u]=(0,F.useState)({reasoning:[],activeSteps:new Map,completedSteps:[]}),d=(0,F.useRef)(null),f=(0,F.useRef)(null),p=Sl(),m=_l(),{agent:h,skills:g,loading:_}=Tl(m),v=(0,F.useMemo)(()=>pl(),[]),{messages:y,sendMessage:b,setMessages:x,status:S,error:C,addToolApprovalResponse:w}=ge({transport:(0,F.useMemo)(()=>new ce({api:Pl(p),credentials:`include`,prepareSendMessagesRequest:({messages:e,body:t})=>({body:{...t,messages:e,context:m,agent:wl,...a?{skill:a}:{}}})}),[p,m,a]),messages:v,onFinish:()=>{u({reasoning:[],activeSteps:new Map,completedSteps:[]})}}),T=S===`streaming`||S===`submitted`;(0,F.useEffect)(()=>{if(!T||y.length===0)return;let e=y[y.length-1];if(e.role!==`assistant`)return;let t=[],n=new Map,r=[];(e.parts||[]).forEach(e=>{e.type===`reasoning-delta`||e.type===`reasoning`?t.push(e.text):e.type===`step-start`?n.set(e.stepId,{stepName:e.stepName,startedAt:Date.now()}):e.type===`step-finish`&&r.push(e.stepName)}),u({reasoning:t,activeSteps:n,completedSteps:r})},[y,T]),(0,F.useEffect)(()=>{y.length>0&&ml(y)},[y]),(0,F.useEffect)(()=>{d.current&&(d.current.scrollTop=d.current.scrollHeight)},[y]),(0,F.useEffect)(()=>{e&&f.current&&f.current.focus()},[e]);let ee=()=>{x([]),ml([])},E=(0,F.useCallback)(()=>{o(null),Il(null)},[]),te=(0,F.useCallback)(e=>{o(e),Il(e),c(!1),f.current?.focus()},[]),D=r.startsWith(`/`)?r.slice(1).toLowerCase():``,ne=(0,F.useMemo)(()=>s?g.filter(e=>e.name.toLowerCase().includes(D)||e.label.toLowerCase().includes(D)):[],[g,D,s]),O=()=>{let e=r.trim();if(!e||T)return;let t=Ll(e);if(t){let e=g.find(e=>e.name===t.skill);if(e){if(te(e.name),!t.rest){i(``);return}i(``),c(!1),b({text:t.rest});return}}i(``),c(!1),b({text:e})};return e?(0,R.jsxs)(`aside`,{"data-testid":`ai-chat-panel`,className:z(`fixed right-0 top-0 z-50 h-full`,`flex flex-col border-l border-border`,`bg-background shadow-xl`,`animate-in slide-in-from-right duration-200`),style:{width:El},children:[(0,R.jsxs)(`div`,{className:`shrink-0 border-b`,children:[(0,R.jsxs)(`div`,{className:`flex h-12 items-center justify-between px-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,R.jsx)(ut,{className:`h-4 w-4 text-primary`}),`AI Chat`]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(sc,{children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsxs)(B,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:ee,children:[(0,R.jsx)(Fn,{className:`h-3.5 w-3.5`}),(0,R.jsx)(`span`,{className:`sr-only`,children:`Clear chat`})]})}),(0,R.jsx)(uc,{children:(0,R.jsx)(`p`,{children:`Clear history`})})]})}),(0,R.jsxs)(B,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,onClick:()=>t(!1),children:[(0,R.jsx)(At,{className:`h-4 w-4`}),(0,R.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}),(0,R.jsx)(`div`,{className:`px-3 pb-2`,"data-testid":`assistant-status`,children:_?(0,R.jsxs)(`div`,{className:`flex h-7 items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,R.jsx)(tt,{className:`h-3 w-3 animate-spin`}),`Resolving assistant…`]}):h?(0,R.jsxs)(`div`,{className:`flex h-7 items-center gap-1.5 overflow-hidden text-xs`,children:[(0,R.jsx)(ut,{className:`h-3 w-3 shrink-0 text-primary`}),(0,R.jsx)(`span`,{className:`font-medium`,"data-testid":`assistant-agent-label`,children:h.label}),g.length>0&&(0,R.jsxs)(`span`,{className:`truncate text-muted-foreground`,"data-testid":`assistant-active-skills`,title:g.map(e=>e.label).join(`, `),children:[`· `,g.length,` skill`,g.length===1?``:`s`]}),a&&(0,R.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 rounded-full bg-primary/15 px-2 py-0.5 text-[10px] font-medium text-primary`,"data-testid":`assistant-skill-override`,children:[`/`,a,(0,R.jsx)(`button`,{onClick:E,className:`hover:text-primary/70`,"aria-label":`Clear skill override`,children:(0,R.jsx)(At,{className:`h-2.5 w-2.5`})})]})]}):(0,R.jsxs)(`div`,{className:`flex h-7 items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,R.jsx)(Ae,{className:`h-3 w-3`}),`No assistant available`]})})]}),(0,R.jsx)(ll,{className:`flex-1 overflow-hidden`,children:(0,R.jsxs)(`div`,{ref:d,className:`flex flex-col gap-3 p-3 overflow-y-auto h-full`,children:[y.length===0&&(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 py-12 text-center text-muted-foreground`,children:[(0,R.jsx)(st,{className:`h-8 w-8 opacity-40`}),(0,R.jsx)(`p`,{className:`text-sm`,children:`Ask anything about your project.`}),(0,R.jsxs)(`p`,{className:`text-xs opacity-60`,children:[(0,R.jsx)(`kbd`,{children:`⌘⇧I`}),` to toggle this panel`]})]}),y.map(e=>{let t=kl(e),n=(e.parts??[]).filter(Ml);return!(t||n.length>0)&&e.role!==`user`?null:(0,R.jsxs)(`div`,{className:z(`flex flex-col gap-1.5 rounded-lg px-3 py-2 text-sm`,e.role===`user`?`ml-8 bg-primary text-primary-foreground`:`mr-8 bg-muted text-foreground`),children:[(0,R.jsx)(`span`,{className:`text-[10px] font-medium opacity-60 uppercase`,children:e.role===`user`?`You`:`Assistant`}),t&&(0,R.jsx)(`div`,{className:`whitespace-pre-wrap break-words`,children:t}),n.map(e=>(0,R.jsx)(Bl,{part:e,onApprove:e=>w({id:e,approved:!0}),onDeny:e=>w({id:e,approved:!1,reason:`User denied the operation`})},e.toolCallId))]},e.id)}),T&&(0,R.jsxs)(R.Fragment,{children:[l.reasoning.length>0&&(0,R.jsx)(`div`,{className:`mr-8`,children:(0,R.jsx)(Rl,{reasoning:l.reasoning})}),l.activeSteps.size>0&&(0,R.jsx)(`div`,{className:`mr-8`,children:(0,R.jsx)(zl,{activeSteps:l.activeSteps,completedSteps:l.completedSteps})}),l.reasoning.length===0&&l.activeSteps.size===0&&(0,R.jsxs)(`div`,{className:`mr-8 flex items-center gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground`,children:[(0,R.jsx)(`span`,{className:`inline-block h-2 w-2 animate-pulse rounded-full bg-primary`}),`Thinking…`]})]}),C&&(0,R.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/50 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:[(0,R.jsx)(Ae,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`p`,{className:`font-medium`,children:`Chat Error`}),(0,R.jsx)(`p`,{className:`mt-0.5 text-xs opacity-80`,children:C.message||`Something went wrong`}),C.message&&/unexpected|json|parse|stream/i.test(C.message)&&(0,R.jsx)(`p`,{className:`mt-1 text-xs opacity-70`,children:`The server may not be returning the expected Vercel AI Data Stream format. Ensure the backend endpoint supports SSE streaming.`})]})]})]})}),(0,R.jsxs)(`div`,{className:`shrink-0 border-t p-3 relative`,children:[s&&(0,R.jsx)(`div`,{"data-testid":`skill-palette`,className:`absolute bottom-full left-3 right-3 mb-1 max-h-56 overflow-auto rounded-md border border-border bg-popover shadow-lg`,children:ne.length===0?(0,R.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground`,children:`No matching skills for the current context.`}):ne.map(e=>(0,R.jsxs)(`button`,{type:`button`,"data-testid":`skill-palette-item-${e.name}`,onClick:()=>te(e.name),className:`flex w-full flex-col items-start gap-0.5 border-b border-border/50 px-3 py-2 text-left text-xs last:border-b-0 hover:bg-accent`,children:[(0,R.jsxs)(`span`,{className:`font-medium`,children:[`/`,e.name]}),(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),e.description&&(0,R.jsx)(`span`,{className:`line-clamp-2 text-[10px] opacity-70`,children:e.description})]},e.name))}),(0,R.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,R.jsx)(`textarea`,{ref:f,"data-testid":`ai-chat-input`,value:r,onChange:e=>{let t=e.target.value;i(t),c(t.startsWith(`/`))},onKeyDown:e=>{if(e.key===`Escape`&&s){e.preventDefault(),c(!1);return}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),O())},placeholder:a?`Ask /${a}…`:`Ask AI… (type / for skills)`,rows:1,className:z(`flex-1 resize-none rounded-md border border-input bg-transparent px-3 py-2 text-sm`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`max-h-32 min-h-[36px]`)}),(0,R.jsxs)(B,{type:`button`,size:`icon`,className:`h-9 w-9 shrink-0`,disabled:!r.trim()||T,onClick:O,children:[(0,R.jsx)(He,{className:`h-4 w-4`}),(0,R.jsx)(`span`,{className:`sr-only`,children:`Send`})]})]})]})]}):null}var Hl=fe,Ul=d,Wl=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(C,{ref:n,className:z(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));Wl.displayName=C.displayName;var Gl=F.forwardRef(({className:e,children:t,...n},r)=>(0,R.jsxs)(Ul,{children:[(0,R.jsx)(Wl,{}),(0,R.jsxs)(re,{ref:r,className:z(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-1/2 data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-1/2 sm:rounded-lg`,e),...n,children:[t,(0,R.jsxs)(ae,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`,children:[(0,R.jsx)(At,{className:`h-4 w-4`}),(0,R.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));Gl.displayName=re.displayName;var Kl=({className:e,...t})=>(0,R.jsx)(`div`,{className:z(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});Kl.displayName=`DialogHeader`;var ql=({className:e,...t})=>(0,R.jsx)(`div`,{className:z(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});ql.displayName=`DialogFooter`;var Jl=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(me,{ref:n,className:z(`text-lg font-semibold leading-none tracking-tight`,e),...t}));Jl.displayName=me.displayName;var Yl=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(T,{ref:n,className:z(`text-sm text-muted-foreground`,e),...t}));Yl.displayName=T.displayName;var Xl=s(`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`),W=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(gr,{ref:n,className:z(Xl(),e),...t}));W.displayName=gr.displayName;var Zl={production:`border-red-500/40 bg-red-500/10 text-red-700 dark:text-red-300`,staging:`border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300`,sandbox:`border-yellow-500/40 bg-yellow-500/10 text-yellow-700 dark:text-yellow-300`,development:`border-sky-500/40 bg-sky-500/10 text-sky-700 dark:text-sky-300`,test:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`,preview:`border-violet-500/40 bg-violet-500/10 text-violet-700 dark:text-violet-300`,trial:`border-muted bg-muted text-muted-foreground`},Ql={production:`PROD`,staging:`STG`,sandbox:`SBX`,development:`DEV`,test:`TEST`,preview:`PRE`,trial:`TRIAL`};function $l({projectType:e,full:t,className:n}){return(0,R.jsx)(`span`,{className:z(`inline-flex h-4 items-center rounded border px-1.5 text-[10px] font-mono font-semibold uppercase tracking-wider`,Zl[e],n),title:e,children:t?e:Ql[e]})}var eu=(0,F.createContext)(null);function tu({children:e}){let[t,n]=(0,F.useState)({projectType:void 0}),[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)(null),[s,c]=(0,F.useState)(``),l=(0,F.useRef)(null),u=(0,F.useCallback)(e=>t.projectType===`production`?(o(e),c(``),i(!0),new Promise(e=>{l.current=e})):Promise.resolve(!0),[t.projectType]),d=(0,F.useCallback)(e=>{l.current?.(e),l.current=null,i(!1),o(null),c(``)},[]),f=(0,F.useMemo)(()=>({confirm:u,setActiveProject:n,activeProjectType:t.projectType}),[u,t.projectType]),p=a?.typedConfirmationValue??t.display_name??``,m=!a?.requireTypedConfirmation||s.trim()===p.trim();return(0,R.jsxs)(eu.Provider,{value:f,children:[e,(0,R.jsx)(Hl,{open:r,onOpenChange:e=>{e||d(!1)},children:(0,R.jsxs)(Gl,{className:`sm:max-w-md`,children:[(0,R.jsxs)(Kl,{children:[(0,R.jsxs)(Jl,{className:`flex items-center gap-2`,children:[(0,R.jsx)(Jt,{className:`h-5 w-5 text-red-600`}),a?.title??`Confirm production action`]}),(0,R.jsx)(Yl,{children:a?.description??`This action runs against live production data and cannot be undone from the client.`})]}),(0,R.jsxs)(`div`,{className:`my-2 flex items-center gap-2 rounded-md border border-red-500/30 bg-red-500/5 p-3 text-sm`,children:[(0,R.jsx)($l,{projectType:`production`}),(0,R.jsx)(`span`,{className:`font-medium`,children:t.display_name??`Production project`})]}),a?.requireTypedConfirmation&&(0,R.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,R.jsxs)(W,{htmlFor:`prod-guard-typed`,children:[`Type`,` `,(0,R.jsx)(`code`,{className:`font-mono text-xs`,children:p}),` `,`to confirm`]}),(0,R.jsx)(V,{id:`prod-guard-typed`,value:s,onChange:e=>c(e.target.value),autoComplete:`off`,autoFocus:!0})]}),(0,R.jsxs)(ql,{children:[(0,R.jsx)(B,{variant:`ghost`,onClick:()=>d(!1),children:`Cancel`}),(0,R.jsx)(B,{variant:a?.confirmVariant??`destructive`,disabled:!m,onClick:()=>d(!0),children:a?.confirmLabel??`Continue`})]})]})})]})}var nu=s(`text-muted-foreground flex flex-wrap items-center gap-1.5 break-words text-sm sm:gap-2.5`),ru=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`nav`,{ref:n,"aria-label":`breadcrumb`,className:z(nu(),e),...t}));ru.displayName=`Breadcrumb`;var iu=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`ol`,{ref:n,className:z(`text-muted-foreground flex flex-wrap items-center gap-1.5 break-words text-sm sm:gap-2.5`,e),...t}));iu.displayName=`BreadcrumbList`;var au=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`li`,{ref:n,className:z(`inline-flex items-center gap-1.5`,e),...t}));au.displayName=`BreadcrumbItem`;var ou=F.forwardRef(({asChild:e,className:t,...n},r)=>(0,R.jsx)(e?i:`a`,{ref:r,className:z(`hover:text-foreground transition-colors`,t),...n}));ou.displayName=`BreadcrumbLink`;var su=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`span`,{ref:n,role:`link`,"aria-disabled":`true`,"aria-current":`page`,className:z(`text-foreground font-normal`,e),...t}));su.displayName=`BreadcrumbPage`;var cu=({children:e,className:t,...n})=>(0,R.jsx)(`li`,{role:`presentation`,"aria-hidden":`true`,className:z(`[&>svg]:size-3.5`,t),...n,children:e??(0,R.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`size-4`,children:(0,R.jsx)(`path`,{d:`m9 18 6-6-6-6`})})});cu.displayName=`BreadcrumbSeparator`;var lu=({className:e,...t})=>(0,R.jsxs)(`span`,{role:`presentation`,"aria-hidden":`true`,className:z(`flex h-9 w-9 items-center justify-center`,e),...t,children:[(0,R.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,className:`size-4`,children:[(0,R.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,R.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`}),(0,R.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`})]}),(0,R.jsx)(`span`,{className:`sr-only`,children:`More`})]});lu.displayName=`BreadcrumbElipssis`;var uu=pr,du=Zn,fu=F.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,R.jsxs)(vr,{ref:i,className:z(`flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,t&&`pl-8`,e),...r,children:[n,(0,R.jsx)(je,{className:`ml-auto`})]}));fu.displayName=vr.displayName;var pu=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Un,{ref:n,className:z(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...t}));pu.displayName=Un.displayName;var mu=F.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,R.jsx)($n,{children:(0,R.jsx)(sr,{ref:r,sideOffset:t,className:z(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n})}));mu.displayName=sr.displayName;var hu=F.forwardRef(({className:e,inset:t,...n},r)=>(0,R.jsx)(cr,{ref:r,className:z(`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0`,t&&`pl-8`,e),...n}));hu.displayName=cr.displayName;var gu=F.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,R.jsxs)(Ar,{ref:i,className:z(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),checked:n,...r,children:[(0,R.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,R.jsx)(ur,{children:(0,R.jsx)(_t,{className:`h-4 w-4`})})}),t]}));gu.displayName=Ar.displayName;var _u=F.forwardRef(({className:e,children:t,...n},r)=>(0,R.jsxs)(ar,{ref:r,className:z(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,R.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,R.jsx)(ur,{children:(0,R.jsx)(on,{className:`h-2 w-2 fill-current`})})}),t]}));_u.displayName=ar.displayName;var vu=F.forwardRef(({className:e,inset:t,...n},r)=>(0,R.jsx)(qn,{ref:r,className:z(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));vu.displayName=qn.displayName;var yu=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(zr,{ref:n,className:z(`-mx-1 my-1 h-px bg-muted`,e),...t}));yu.displayName=zr.displayName;var bu=({className:e,...t})=>(0,R.jsx)(`span`,{className:z(`ml-auto text-xs tracking-widest opacity-60`,e),...t});bu.displayName=`DropdownMenuShortcut`;function xu(){let[e,t]=(0,F.useState)(`light`);(0,F.useEffect)(()=>{let e=localStorage.getItem(`theme`);if(e)t(e),n(e);else{let e=window.matchMedia(`(prefers-color-scheme: dark)`).matches;t(`system`),n(e?`dark`:`light`)}},[]);function n(e){let t=document.documentElement;e===`dark`?t.classList.add(`dark`):t.classList.remove(`dark`)}function r(e){if(t(e),localStorage.setItem(`theme`,e),e===`system`){let e=window.matchMedia(`(prefers-color-scheme: dark)`).matches;n(e?`dark`:`light`)}else n(e)}return(0,R.jsxs)(uu,{children:[(0,R.jsx)(du,{asChild:!0,children:(0,R.jsxs)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,R.jsx)(Fe,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,R.jsx)(Pe,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,R.jsx)(`span`,{className:`sr-only`,children:`Toggle theme`})]})}),(0,R.jsxs)(mu,{align:`end`,children:[(0,R.jsxs)(hu,{onClick:()=>r(`light`),children:[(0,R.jsx)(Fe,{className:`mr-2 h-4 w-4`}),`Light`]}),(0,R.jsxs)(hu,{onClick:()=>r(`dark`),children:[(0,R.jsx)(Pe,{className:`mr-2 h-4 w-4`}),`Dark`]}),(0,R.jsx)(hu,{onClick:()=>r(`system`),children:`System`})]})]})}var Su=s(`inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground hover:bg-primary/80`,secondary:`border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80`,destructive:`border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80`,outline:`text-foreground`}},defaultVariants:{variant:`default`}});function G({className:e,variant:t,...n}){return(0,R.jsx)(`div`,{className:z(Su({variant:t}),e),...n})}var Cu={app:kn,plugin:zn,driver:In,server:wt,ui:st,theme:st,agent:ut,module:Pt,objectql:In,adapter:Qt};function wu({packages:e,selectedPackage:t,onSelectPackage:n}){return(0,R.jsxs)(uu,{children:[(0,R.jsx)(du,{asChild:!0,children:(0,R.jsxs)(B,{variant:`ghost`,size:`sm`,className:`h-8 gap-2 px-2 text-sm font-medium`,children:[(0,R.jsx)(t?Cu[t.manifest?.type]||Pt:st,{className:`h-3.5 w-3.5 text-muted-foreground`}),t?(0,R.jsx)(`span`,{className:`max-w-[140px] truncate`,children:t.manifest?.name||t.manifest?.id}):(0,R.jsx)(`span`,{children:`全部 (All packages)`}),(0,R.jsx)(Ge,{className:`h-3.5 w-3.5 opacity-60`})]})}),(0,R.jsxs)(mu,{className:`w-[280px]`,align:`start`,sideOffset:4,children:[(0,R.jsx)(vu,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:`Installed Packages`}),(0,R.jsx)(yu,{}),(0,R.jsxs)(hu,{onSelect:e=>{e.preventDefault(),n(null)},className:`gap-2 py-2`,children:[(0,R.jsx)(`div`,{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded bg-primary/10 text-primary`,children:(0,R.jsx)(st,{className:`h-3.5 w-3.5`})}),(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col leading-tight`,children:[(0,R.jsx)(`span`,{className:`text-sm font-medium`,children:`全部`}),(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Show metadata from all packages`})]}),t===null&&(0,R.jsx)(_t,{className:`h-4 w-4 text-primary`})]}),(0,R.jsx)(yu,{}),e.map(e=>{let r=Cu[e.manifest?.type]||Pt,i=t?.manifest?.id===e.manifest?.id;return(0,R.jsxs)(hu,{onSelect:t=>{t.preventDefault(),n(e)},className:`gap-2 py-2`,children:[(0,R.jsx)(`div`,{className:`flex h-6 w-6 shrink-0 items-center justify-center rounded bg-primary/10 text-primary`,children:(0,R.jsx)(r,{className:`h-3.5 w-3.5`})}),(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col leading-tight`,children:[(0,R.jsx)(`span`,{className:`text-sm font-medium`,children:e.manifest?.name||e.manifest?.id}),(0,R.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`v`,e.manifest?.version,` · `,e.manifest?.type,!e.enabled&&` · disabled`]})]}),i&&(0,R.jsx)(_t,{className:`h-4 w-4 text-primary`})]},e.manifest?.id)}),e.length===0&&(0,R.jsx)(`div`,{className:`px-2 py-4 text-center text-xs text-muted-foreground`,children:`No packages installed`})]})]})}var Tu=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Hn,{ref:n,className:z(`relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full`,e),...t}));Tu.displayName=Hn.displayName;var Eu=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(jr,{ref:n,className:z(`aspect-square h-full w-full`,e),...t}));Eu.displayName=jr.displayName;var Du=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(lr,{ref:n,className:z(`flex h-full w-full items-center justify-center rounded-full bg-muted`,e),...t}));Du.displayName=lr.displayName;var Ou=(0,F.createContext)(null);function ku(e){if(!e)return{user:null,session:null};let t=e.data===void 0?e:e.data;return t?{user:t.user??null,session:t.session??null}:{user:null,session:null}}function Au({children:e}){let t=L(),[n,r]=(0,F.useState)(null),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!0),[c,l]=(0,F.useState)(null),u=(0,F.useCallback)(async()=>{if(t?.auth){s(!0),l(null);try{let{user:e,session:n}=ku(await t.auth.me());r(e),a(n)}catch(e){l(e),r(null),a(null)}finally{s(!1)}}},[t]);(0,F.useEffect)(()=>{u()},[u]);let d=(0,F.useCallback)(async()=>{if(t?.auth)try{await t.auth.logout()}finally{r(null),a(null)}},[t]),f=(0,F.useMemo)(()=>({user:n,session:i,loading:o,error:c,refresh:u,logout:d}),[n,i,o,c,u,d]);return(0,F.createElement)(Ou.Provider,{value:f},e)}function ju(){let e=(0,F.useContext)(Ou);if(!e)throw Error(`useSession must be used inside <SessionProvider>.`);return e}var Mu=`/_account`;function Nu(){return typeof window>`u`?`/`:window.location.pathname+window.location.search}function Pu(e){let t=e??Nu(),n=`${Mu}/login?redirect=${encodeURIComponent(t)}`;window.location.assign(n)}function Fu(e){let t=e.startsWith(`/`)?e:`/${e}`;window.location.assign(`${Mu}${t}`)}function Iu(e,t){let n=(e||t||`?`).trim(),r=n.split(/\s+/);return r.length>=2?(r[0][0]+r[1][0]).toUpperCase():n.slice(0,2).toUpperCase()}function Lu(){let{user:e,loading:t,logout:n}=ju();return t&&!e?(0,R.jsx)(`div`,{className:`h-8 w-8 animate-pulse rounded-full bg-muted`,"aria-hidden":!0}):e?(0,R.jsxs)(uu,{children:[(0,R.jsx)(du,{asChild:!0,children:(0,R.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8 rounded-full`,children:(0,R.jsxs)(Tu,{className:`h-7 w-7`,children:[e.image?(0,R.jsx)(Eu,{src:e.image,alt:e.name??e.email??`User`}):null,(0,R.jsx)(Du,{className:`text-[11px]`,children:Iu(e.name,e.email)})]})})}),(0,R.jsxs)(mu,{align:`end`,className:`w-64`,children:[(0,R.jsx)(vu,{children:(0,R.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,R.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.name||e.email}),e.email&&(0,R.jsx)(`span`,{className:`text-[11px] text-muted-foreground truncate`,children:e.email})]})}),(0,R.jsx)(yu,{}),(0,R.jsxs)(hu,{onSelect:()=>Fu(`/account`),children:[(0,R.jsx)(Wt,{className:`mr-2 h-3.5 w-3.5`}),`Account settings`]}),(0,R.jsx)(yu,{}),(0,R.jsxs)(hu,{onSelect:async()=>{try{await n()}finally{Pu(`/`)}},children:[(0,R.jsx)(ke,{className:`mr-2 h-3.5 w-3.5`}),`Sign out`]})]})]}):(0,R.jsx)(B,{variant:`outline`,size:`sm`,className:`h-8`,onClick:()=>Pu(),children:`Sign in`})}var Ru=(0,F.createContext)({version:0,lastEvent:null,state:`disabled`,lastEventAt:null,lastSeq:void 0,subscribe:()=>()=>{}});function zu({url:e=`/api/v1/dev/metadata-events`,enabled:t=!0,reconnectDelayMs:n=2e3,children:r}){let[i,a]=(0,F.useState)(0),[o,s]=(0,F.useState)(null),[c,l]=(0,F.useState)(t?`connecting`:`disabled`),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(void 0),m=(0,F.useRef)(new Set),h=(0,F.useCallback)(e=>(m.current.add(e),()=>{m.current.delete(e)}),[]);(0,F.useEffect)(()=>{if(!t){l(`disabled`);return}if(typeof window>`u`||typeof EventSource>`u`){l(`disabled`);return}let r=null,i=null,o=!1,c=e=>{try{let t=JSON.parse(e.data);s(t),d(t.timestamp??Date.now()),a(e=>e+1),typeof t.seq==`number`&&p(e=>e===void 0||t.seq>e?t.seq:e);for(let e of m.current)try{e(t)}catch{}}catch{}},u=()=>{l(`connected`)},f=()=>{if(!o)try{r=new EventSource(e),l(`connecting`),r.addEventListener(`open`,()=>{o||l(`connected`)}),r.addEventListener(`ready`,u),r.addEventListener(`metadata-change`,c),r.addEventListener(`reload`,(e=>{let t=`reload`,n=Date.now();try{let r=JSON.parse(e.data);t=r.reason??t,n=r.timestamp??n}catch{}let r={type:`changed`,metadataType:`*`,name:t,timestamp:n};s(r),d(n),a(e=>e+1);for(let e of m.current)try{e(r)}catch{}})),r.addEventListener(`error`,()=>{o||(r?.readyState===EventSource.CLOSED?(l(`disconnected`),r=null,i=setTimeout(f,n)):l(`error`))})}catch{l(`error`),i=setTimeout(f,n)}};return f(),()=>{if(o=!0,i&&clearTimeout(i),r)try{r.close()}catch{}}},[t,e,n]);let g=(0,F.useMemo)(()=>({version:i,lastEvent:o,state:c,lastEventAt:u,lastSeq:f,subscribe:h}),[i,o,c,u,f,h]);return(0,R.jsx)(Ru.Provider,{value:g,children:r})}function Bu(){return(0,F.useContext)(Ru)}var Vu={connecting:{label:`HMR`,icon:tt,badgeClass:`border-blue-200 text-blue-700 bg-blue-50 dark:border-blue-800 dark:text-blue-400 dark:bg-blue-950/50`,dotClass:`bg-blue-500`,animate:!0},connected:{label:`HMR`,icon:Ft,badgeClass:`border-emerald-200 text-emerald-700 bg-emerald-50 dark:border-emerald-800 dark:text-emerald-400 dark:bg-emerald-950/50`,dotClass:`bg-emerald-500`,animate:!1},disconnected:{label:`HMR off`,icon:cn,badgeClass:`border-gray-200 text-gray-600 bg-gray-50 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-900`,dotClass:`bg-gray-400`,animate:!1},disabled:{label:`HMR off`,icon:cn,badgeClass:`border-gray-200 text-gray-600 bg-gray-50 dark:border-gray-700 dark:text-gray-400 dark:bg-gray-900`,dotClass:`bg-gray-400`,animate:!1},error:{label:`HMR err`,icon:cn,badgeClass:`border-red-200 text-red-700 bg-red-50 dark:border-red-800 dark:text-red-400 dark:bg-red-950/50`,dotClass:`bg-red-500`,animate:!1}};function Hu(){let{state:e,version:t,lastEvent:n,lastEventAt:r,lastSeq:i}=Bu(),[a,o]=(0,F.useState)(!1);(0,F.useEffect)(()=>{if(t===0)return;o(!0);let e=setTimeout(()=>o(!1),700);return()=>clearTimeout(e)},[t]);let s=Vu[e],c=a?Qt:s.icon,l=r?new Date(r).toLocaleTimeString(void 0,{hour:`2-digit`,minute:`2-digit`,second:`2-digit`}):`—`;return(0,R.jsx)(sc,{children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsxs)(G,{variant:`outline`,className:`gap-1.5 text-[10px] font-normal cursor-default hidden md:inline-flex ${s.badgeClass} ${a?`ring-2 ring-emerald-400/50`:``}`,children:[(0,R.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5`,children:[e===`connected`&&(0,R.jsx)(`span`,{className:`animate-ping absolute inline-flex h-full w-full rounded-full ${s.dotClass} opacity-40`}),(0,R.jsx)(`span`,{className:`relative inline-flex rounded-full h-1.5 w-1.5 ${s.dotClass}`})]}),(0,R.jsx)(c,{className:`h-3 w-3 ${s.animate?`animate-spin`:``}`}),(0,R.jsx)(`span`,{className:`font-mono`,children:s.label})]})}),(0,R.jsx)(uc,{side:`bottom`,className:`text-xs`,children:(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`p`,{className:`font-medium`,children:`Metadata HMR`}),(0,R.jsxs)(`p`,{className:`text-muted-foreground`,children:[`State: `,e]}),(0,R.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Events: `,t]}),typeof i==`number`&&(0,R.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Repo seq: #`,i]}),(0,R.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Last: `,l]}),n&&(0,R.jsxs)(`p`,{className:`text-muted-foreground`,children:[n.type,` `,n.metadataType,`/`,n.name]}),e!==`connected`&&e!==`connecting`&&(0,R.jsx)(`p`,{className:`text-muted-foreground`,children:`Source edits won't auto-refresh previews.`})]})})]})})}function Uu(e){let t=L(),[n,r]=(0,F.useState)([]),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(null),[c,l]=(0,F.useState)(null),u=(0,F.useCallback)(async()=>{if(t?.packages?.list){a(!0),s(null);try{let e=await t.packages.list();r(Array.isArray(e)?e:e?.packages??e?.items??[])}catch(e){s(e),r([])}finally{a(!1)}}},[t]);return(0,F.useEffect)(()=>{u()},[u]),(0,F.useEffect)(()=>{if(!e){c&&l(null);return}if(!n.length)return;let t=n.find(t=>t.manifest?.id===e||t.manifest?.id?.split(`.`).pop()===e);t&&t!==c&&l(t)},[e,n,c]),(0,F.useMemo)(()=>({packages:n,loading:i,error:o,reload:u,selectedPackage:c,setSelectedPackage:l}),[n,i,o,u,c])}var Wu=[{key:`home`,label:`Home`,icon:Ze,types:[],hint:`Project overview & quick links`},{key:`objects`,label:`Objects`,icon:Pt,types:[`object`],hint:`Data model — tables, fields, relations`},{key:`forms`,label:`Forms`,icon:En,types:[`view`],hint:`Public + internal forms with publish controls`},{key:`views`,label:`Views & Apps`,icon:kn,types:[`view`,`app`,`page`,`dashboard`,`report`],hint:`Grids, kanbans, dashboards, app navigation`},{key:`automations`,label:`Automations`,icon:bn,types:[`flow`,`workflow`,`approval`,`hook`,`trigger`,`function`],hint:`Flows, workflows, hooks, triggers, functions`},{key:`ai`,label:`AI`,icon:ut,types:[`agent`,`tool`,`skill`],hint:`Agents, tools, skills`},{key:`security`,label:`Security`,icon:dt,types:[`role`,`profile`,`permission`],hint:`Roles, profiles, permissions`},{key:`apis`,label:`APIs`,icon:wt,types:[],hint:`REST endpoints auto-generated from objects, forms, flows & AI`},{key:`playground`,label:`Playground`,icon:wn,types:[],hint:`Try REST, ObjectQL, formulas, forms & agents live`},{key:`logs`,label:`Logs`,icon:gn,types:[],hint:`Request log · event log · audit trail`}];function Gu(e){return Wu.find(t=>t.types.includes(e))??null}var Ku={object:`Object`,view:`View`,app:`App`,page:`Page`,dashboard:`Dashboard`,report:`Report`,flow:`Flow`,workflow:`Workflow`,approval:`Approval`,hook:`Hook`,trigger:`Trigger`,function:`Function`,agent:`Agent`,tool:`Tool`,skill:`Skill`,role:`Role`,profile:`Profile`,permission:`Permission`,policy:`Policy`,action:`Action`,api:`API`,webhook:`Webhook`,connector:`Connector`,mapping:`Mapping`,theme:`Theme`,ragPipeline:`RAG Pipeline`,sharingRule:`Sharing Rule`,analyticsCube:`Analytics Cube`,data:`Seed Data`};function qu(e){return Ku[e]??e.charAt(0).toUpperCase()+e.slice(1)}var Ju={object:In,view:Nn,app:kn,page:yn,dashboard:ft,report:It,flow:at,workflow:bn,approval:ct,hook:Dn,trigger:Qt,function:dn,agent:ut,tool:dn,skill:st,role:Wt,profile:Wt,permission:bt,policy:dt,sharingRule:yt};function Yu(e){return Ju[e]??Gu(e)?.icon}var Xu=new Set([`plugin`,`kind`]);function Zu(e){return typeof e==`string`?e:e&&typeof e==`object`&&`defaultValue`in e?String(e.defaultValue):e&&typeof e==`object`&&`key`in e?String(e.key):``}function Qu({selectedPackage:e}){let t=L(),n=ve(),[r,i]=(0,F.useState)(!1),[a,o]=(0,F.useState)([]),[s,c]=(0,F.useState)(!1),l=e?.manifest?.id;(0,F.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`k`&&(e.preventDefault(),i(e=>!e))},t=()=>i(!0);return window.addEventListener(`keydown`,e),window.addEventListener(`studio:command-palette:open`,t),()=>{window.removeEventListener(`keydown`,e),window.removeEventListener(`studio:command-palette:open`,t)}},[]);let u=(0,F.useCallback)(async()=>{if(l)try{let e=await t.meta.getTypes(),n=e?.types||(Array.isArray(e)?e:[]);o((await Promise.all(n.filter(e=>!Xu.has(e)).map(async e=>{try{let n=await t.meta.getItems(e,{packageId:l});return(n?.items||(Array.isArray(n)?n:[])).map(t=>({type:e,name:t.name||t.id||`unknown`,label:Zu(t.label)||t.name||`Untitled`,packageId:l}))}catch{return[]}}))).flat()),c(!0)}catch(e){console.error(`[CommandPalette] load failed`,e)}},[t,l]);(0,F.useEffect)(()=>{r&&!s&&u()},[r,s,u]),Ks(`object`,()=>c(!1)),Ks(`view`,()=>c(!1)),Ks(`flow`,()=>c(!1)),Ks(`agent`,()=>c(!1));let d=e=>{i(!1),n({to:e})},f=(0,F.useMemo)(()=>{let e=new Map;for(let t of a){let n=Gu(t.type),r=n?.key??`other`,i=n?.label??`Other`,a=e.get(r)??{label:i,hits:[]};a.hits.push(t),e.set(r,a)}let t=[];for(let n of Wu){let r=e.get(n.key);r&&t.push([n.key,r])}let n=e.get(`other`);return n&&t.push([`other`,n]),t},[a]);return(0,R.jsx)(Hl,{open:r,onOpenChange:i,children:(0,R.jsxs)(Gl,{className:`overflow-hidden p-0 max-w-2xl`,children:[(0,R.jsx)(Jl,{className:`sr-only`,children:`Command palette`}),(0,R.jsxs)(y,{loop:!0,className:`[&_[cmdk-group-heading]]:px-3 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-[11px] [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wider [&_[cmdk-group-heading]]:text-muted-foreground`,children:[(0,R.jsx)(y.Input,{placeholder:`Search objects, forms, views, flows… or type a route`,className:`flex h-12 w-full border-b border-border bg-transparent px-4 py-3 text-sm outline-none placeholder:text-muted-foreground`}),(0,R.jsxs)(y.List,{className:`max-h-[480px] overflow-y-auto p-2`,children:[(0,R.jsx)(y.Empty,{className:`py-10 text-center text-sm text-muted-foreground`,children:s?(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`p`,{children:`No matches.`}),(0,R.jsxs)(`p`,{className:`text-xs`,children:[`Try an object name (e.g. `,(0,R.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono`,children:`account`}),`), a metadata type, or a route name.`]})]}):`Loading…`}),(0,R.jsx)(y.Group,{heading:`Go to`,children:Wu.map(e=>{let t=e.icon;return(0,R.jsxs)(y.Item,{value:`go ${e.label} ${e.hint}`,onSelect:()=>{l&&d(e.key===`home`?`/${l}`:`/${l}/${e.key}`)},className:`flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm aria-selected:bg-accent`,children:[(0,R.jsx)(t,{className:`h-4 w-4 text-muted-foreground`}),(0,R.jsx)(`span`,{children:e.label}),(0,R.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:e.hint})]},`nav-${e.key}`)})}),f.map(([e,t])=>{let n=Wu.find(t=>t.key===e)?.icon;return(0,R.jsx)(y.Group,{heading:t.label,children:t.hits.slice(0,50).map(e=>(0,R.jsxs)(y.Item,{value:`${e.type} ${e.name} ${e.label}`,onSelect:()=>{e.type===`object`?d(`/${e.packageId}/objects/${e.name}`):d(`/${e.packageId}/metadata/${e.type}/${e.name}`)},className:`flex cursor-pointer items-center gap-2 rounded-md px-3 py-2 text-sm aria-selected:bg-accent`,children:[n&&(0,R.jsx)(n,{className:`h-4 w-4 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:e.label}),(0,R.jsxs)(`span`,{className:`ml-auto flex items-center gap-2 truncate font-mono text-xs text-muted-foreground`,children:[(0,R.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase tracking-wide`,children:e.type}),(0,R.jsx)(`span`,{children:e.name})]})]},`${e.type}-${e.name}`))},`nav-group-${e}`)})]}),(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-t border-border px-3 py-2 text-[11px] text-muted-foreground`,children:[(0,R.jsx)(`span`,{children:`↑↓ navigate · ⏎ open · esc close`}),(0,R.jsx)(`span`,{children:`⌘K`})]})]})]})})}var $u={action:`Actions`,dashboard:`Dashboards`,report:`Reports`,flow:`Flows`,agent:`Agents`,api:`APIs`,ragPipeline:`RAG Pipelines`,profile:`Profiles`,sharingRule:`Sharing Rules`,data:`Seed Data`,view:`Views`,app:`Apps`,tool:`Tools`,skill:`Skills`,workflow:`Workflows`,approval:`Approvals`,webhook:`Webhooks`,role:`Roles`,permission:`Permissions`,policy:`Policies`,connector:`Connectors`,object:`Objects`,hook:`Hooks`,trigger:`Triggers`,function:`Functions`,mapping:`Mappings`,analyticsCube:`Analytics Cubes`,page:`Pages`,theme:`Themes`};function ed(e){if($u[e])return $u[e];let t=e.replace(/([A-Z])/g,` $1`).replace(/[_-]+/g,` `).trim(),n=t.charAt(0).toUpperCase()+t.slice(1);return n.endsWith(`s`)?n:`${n}s`}function td(){return(0,R.jsx)(we,{to:`/`,className:`flex h-7 w-7 items-center justify-center rounded-md bg-primary text-primary-foreground hover:opacity-90`,children:(0,R.jsx)(Dt,{className:`h-4 w-4`})})}function nd(){return(0,R.jsx)(`span`,{"aria-hidden":!0,className:`text-muted-foreground/50 select-none`,children:`/`})}function rd({rightSlot:e}={}){let t=Te(),n=ve(),r=be({strict:!1}),{packages:i,selectedPackage:a}=Uu(r.package),o=(0,F.useCallback)(e=>{if(e===null){n({to:`/`});return}let t=e.manifest?.id;t&&n({to:`/$package`,params:{package:t}})},[n]),s=(0,F.useMemo)(()=>{if(t.pathname===`/`)return`home`;if(r.package&&r.name&&!r.type)return`object`;if(r.package&&r.type&&r.name)return`metadata`;if(r.package){let e=t.pathname.replace(RegExp(`^/+${r.package}/?`),``).replace(/\/.*$/,``);if(e&&[`objects`,`forms`,`views`,`automations`,`ai`,`security`,`apis`,`playground`,`logs`].includes(e))return`nav:${e}`}return r.package&&!r.name&&!r.type?`package-overview`:`default`},[t.pathname,r]),c={objects:`Objects`,forms:`Forms`,views:`Views & Apps`,automations:`Automations`,ai:`AI`,security:`Security`,apis:`APIs`,playground:`Playground`,logs:`Logs`},l=(0,F.useMemo)(()=>{let e=[];if(s.startsWith(`nav:`)){let t=s.slice(4);return e.push({label:c[t]??t}),e}switch(s){case`home`:e.push({label:`Home`});break;case`package-overview`:e.push({label:`Overview`});break;case`object`:e.push({label:`Objects`}),r.name&&e.push({label:r.name});break;case`metadata`:r.type&&e.push({label:ed(r.type)}),r.name&&e.push({label:r.name});break;default:e.push({label:`Studio`})}return e},[s,r]),u=(0,F.useMemo)(()=>null,[s,r]);return(0,R.jsxs)(`header`,{className:`flex h-12 shrink-0 items-center justify-between gap-2 border-b px-2 sm:px-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-1.5 min-w-0`,children:[(0,R.jsx)(`div`,{className:`sm:hidden`,children:(0,R.jsx)(xc,{className:`h-9 w-9`})}),(0,R.jsx)(td,{}),r.package&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(nd,{}),(0,R.jsx)(`div`,{className:`hidden sm:flex items-center gap-1.5`,children:(0,R.jsx)(wu,{packages:i,selectedPackage:a,onSelectPackage:o})})]}),(0,R.jsx)(`div`,{className:`sm:hidden min-w-0 flex-1`,children:l.length>0&&(0,R.jsx)(`span`,{className:`text-sm font-medium truncate`,children:l[l.length-1].label})}),(0,R.jsxs)(`div`,{className:`hidden sm:flex items-center gap-2`,children:[(0,R.jsx)(Zs,{orientation:`vertical`,className:`mx-2 h-4`}),(0,R.jsx)(ru,{children:(0,R.jsx)(iu,{children:l.map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center`,children:[t>0&&(0,R.jsx)(cu,{}),(0,R.jsx)(au,{className:t===0?`hidden md:block`:``,children:e.href?(0,R.jsx)(ou,{href:e.href,children:e.label}):(0,R.jsx)(su,{className:`font-medium`,children:e.label})})]},t))})})]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1 sm:gap-2`,children:[(0,R.jsxs)(`div`,{className:`relative hidden lg:flex items-center cursor-pointer`,onClick:()=>window.dispatchEvent(new CustomEvent(`studio:command-palette:open`)),children:[(0,R.jsx)(Xe,{className:`absolute left-2.5 h-3.5 w-3.5 text-muted-foreground pointer-events-none`}),(0,R.jsx)(V,{placeholder:`Search… objects, forms, views`,className:`h-8 w-[260px] pl-8 pr-10 text-sm cursor-pointer`,readOnly:!0}),(0,R.jsxs)(`kbd`,{className:`absolute right-2 pointer-events-none inline-flex h-5 select-none items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground opacity-100`,children:[(0,R.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),u&&(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[10px] gap-1 hidden sm:flex`,children:u}),(0,R.jsx)(Hu,{}),(0,R.jsx)(`div`,{className:`hidden sm:block`,children:(0,R.jsx)(xu,{})}),e,(0,R.jsx)(Lu,{})]}),(0,R.jsx)(Qu,{selectedPackage:a})]})}function id(e){if(!e)return``;try{let t=new Date(e).getTime();if(Number.isNaN(t))return``;let n=Math.round((Date.now()-t)/1e3);if(n<5)return`just now`;if(n<60)return`${n}s ago`;let r=Math.round(n/60);if(r<60)return`${r}m ago`;let i=Math.round(r/60);if(i<24)return`${i}h ago`;let a=Math.round(i/24);return a<30?`${a}d ago`:new Date(e).toLocaleDateString()}catch{return``}}var ad=Kn,od=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(hr,{ref:n,className:z(`inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground`,e),...t}));od.displayName=hr.displayName;var K=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Gn,{ref:n,className:z(`inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow`,e),...t}));K.displayName=Gn.displayName;var sd=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Rr,{ref:n,className:z(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));sd.displayName=Rr.displayName;var cd=(0,F.createContext)(null);function ld({children:e}){let[t,n]=(0,F.useState)(null),[r,i]=(0,F.useState)(!1),a=(0,F.useCallback)(()=>i(e=>!e),[]),o=(0,F.useMemo)(()=>({target:t,open:r,setTarget:n,setOpen:i,toggle:a}),[t,r,a]);return(0,R.jsx)(cd.Provider,{value:o,children:e})}function ud(){let e=(0,F.useContext)(cd);if(!e)throw Error(`useInspector must be used inside <InspectorProvider>`);return e}function dd(e){let{setTarget:t}=ud();(0,F.useEffect)(()=>(t(e),()=>t(null)),[e?.type,e?.name,e?.packageId])}function fd(e,t){return e===`object`?`/api/v1/data/${t}`:e===`view`||e===`form`?`/api/v1/forms/${t}`:`/api/v1/meta/${e}/${t}`}function pd(e,t,n){let r=[`curl -X ${e} '${typeof window<`u`?window.location.origin:`http://localhost:3000`}${t}' \\`,` -H 'Content-Type: application/json'`];return n&&r.push(` -d '${n}'`),r.join(`
|
|
6
|
-
`)}async function md(e,t){try{await navigator.clipboard.writeText(t),U({title:`Copied ${e}`})}catch{U({title:`Clipboard unavailable`,variant:`destructive`})}}function hd(){let{target:e,open:t,setOpen:n}=ud(),r=L(),[i,a]=(0,F.useState)(`api`),[o,s]=(0,F.useState)(``),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(!1),m=e?fd(e.type,e.name):``;(0,F.useEffect)(()=>{!e||!t||i!==`source`||(p(!0),r.meta.getItem(e.type,e.name).then(e=>s(JSON.stringify(e?.spec??e,null,2))).catch(e=>s(`// failed to load: ${e?.message??e}`)).finally(()=>p(!1)))},[e?.type,e?.name,i,t,r]),(0,F.useEffect)(()=>{if(!e||!t||i!==`refs`)return;let n=!1;return p(!0),(async()=>{let t=[],i=async e=>{try{let t=await r.meta.getItems(e);return Array.isArray(t)?t:Array.isArray(t?.items)?t.items:[]}catch{return[]}};if(e.type===`object`){let[n,r,a]=await Promise.all([i(`view`),i(`hook`),i(`flow`)]);for(let r of n){let n=r?.spec??r;n?.object===e.name&&t.push({type:`view`,name:n?.name??r?.name,packageId:r?.packageId,reason:`view.object = "${e.name}"`})}for(let n of r){let r=n?.spec??n;r?.object===e.name&&t.push({type:`hook`,name:r?.name??n?.name,packageId:n?.packageId,reason:`hook.object = "${e.name}"`})}for(let n of a){let r=n?.spec??n;r?.trigger?.object===e.name&&t.push({type:`flow`,name:r?.name??n?.name,packageId:n?.packageId,reason:`flow.trigger.object = "${e.name}"`})}}n||(l(t),p(!1))})(),()=>{n=!0}},[e?.type,e?.name,i,t,r]),(0,F.useEffect)(()=>{if(!e||!t||i!==`history`||u!==null)return;let n=!1;return p(!0),(async()=>{try{let t=await r.meta.getHistory(e.type,e.name);n||d(Array.isArray(t?.events)?t.events:[])}catch(e){n||(U({title:`Failed to load history`,description:e?.message??String(e),variant:`destructive`}),d([]))}finally{n||p(!1)}})(),()=>{n=!0}},[e?.type,e?.name,i,t,r,u]),(0,F.useEffect)(()=>{d(null)},[e?.type,e?.name]);let h=(0,F.useMemo)(()=>e&&e.type===`object`?`{ "name": "Sample" }`:``,[e]);return(0,R.jsx)(Qs,{open:t,onOpenChange:n,children:(0,R.jsxs)(nc,{side:`right`,className:`w-full sm:max-w-md md:max-w-lg flex flex-col p-0`,children:[(0,R.jsxs)(rc,{className:`px-4 py-3 border-b`,children:[(0,R.jsxs)(ac,{className:`text-base flex items-center gap-2`,children:[(0,R.jsx)(ze,{className:`h-4 w-4`}),`Inspector`,e&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(G,{variant:`secondary`,className:`font-mono text-[10px]`,children:e.type}),(0,R.jsx)(`span`,{className:`font-mono text-sm text-foreground`,children:e.name})]})]}),(0,R.jsx)(oc,{children:e?`API, source, and references for the resource you’re editing.`:`Open a resource detail page to populate the inspector.`})]}),!e&&(0,R.jsxs)(`div`,{className:`flex-1 flex items-center justify-center p-8 text-sm text-muted-foreground text-center`,children:[`Navigate to an Object, View, Flow, or other metadata detail page and the Inspector will show its API, source, and references here.`,(0,R.jsx)(`br`,{}),(0,R.jsx)(`br`,{}),`Toggle anytime with `,(0,R.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted text-xs`,children:`]`}),`.`]}),e&&(0,R.jsxs)(ad,{value:i,onValueChange:a,className:`flex-1 flex flex-col min-h-0`,children:[(0,R.jsx)(`div`,{className:`px-4 pt-3`,children:(0,R.jsxs)(od,{className:`grid w-full grid-cols-4`,children:[(0,R.jsx)(K,{value:`api`,children:`API`}),(0,R.jsx)(K,{value:`source`,children:`Source`}),(0,R.jsx)(K,{value:`refs`,children:`Refs`}),(0,R.jsx)(K,{value:`history`,children:`History`})]})}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-auto px-4 py-3 space-y-3`,children:[(0,R.jsxs)(sd,{value:`api`,className:`m-0 space-y-3`,children:[(0,R.jsx)(gd,{title:`Endpoint`,children:(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`code`,{className:`text-xs font-mono flex-1 break-all bg-muted px-2 py-1.5 rounded`,children:m}),(0,R.jsx)(B,{size:`sm`,variant:`ghost`,onClick:()=>md(`endpoint`,m),title:`Copy`,children:(0,R.jsx)(mt,{className:`h-3.5 w-3.5`})})]})}),(0,R.jsx)(gd,{title:`Sample curl (GET)`,children:(0,R.jsx)(_d,{value:pd(`GET`,m)})}),e.type===`object`&&(0,R.jsx)(gd,{title:`Sample curl (POST)`,children:(0,R.jsx)(_d,{value:pd(`POST`,m,h)})}),(e.type===`view`||e.type===`form`)&&(0,R.jsx)(gd,{title:`Sample curl (submit)`,children:(0,R.jsx)(_d,{value:pd(`POST`,m,`{}`)})})]}),(0,R.jsxs)(sd,{value:`source`,className:`m-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Raw metadata JSON`}),(0,R.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,R.jsx)(B,{size:`sm`,variant:`ghost`,onClick:()=>md(`source JSON`,o),disabled:!o,children:(0,R.jsx)(mt,{className:`h-3.5 w-3.5`})})})]}),f?(0,R.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Loading…`}):(0,R.jsx)(_d,{value:o||`(empty)`,multiline:!0})]}),(0,R.jsxs)(sd,{value:`refs`,className:`m-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Other metadata that references this resource`}),(0,R.jsx)(B,{size:`sm`,variant:`ghost`,onClick:()=>l(null),title:`Refresh`,children:(0,R.jsx)(Ut,{className:`h-3.5 w-3.5`})})]}),f&&(0,R.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Scanning…`}),!f&&c&&c.length===0&&(0,R.jsx)(`div`,{className:`text-xs text-muted-foreground rounded border border-dashed p-4 text-center`,children:`No references found.`}),!f&&c&&c.length>0&&(0,R.jsx)(`ul`,{className:`space-y-1.5`,children:c.map(e=>(0,R.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded border px-2 py-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[10px]`,children:e.type}),(0,R.jsx)(`code`,{className:`text-xs truncate`,children:e.name})]}),e.packageId&&(0,R.jsx)(we,{to:`/$package/metadata/$type/$name`,params:{package:e.packageId,type:e.type,name:e.name},className:`text-muted-foreground hover:text-foreground`,onClick:()=>n(!1),children:(0,R.jsx)(Gt,{className:`h-3.5 w-3.5`})})]},`${e.type}:${e.name}`))}),e.type!==`object`&&!f&&(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground mt-3`,children:`Ref scanning currently runs for objects. View/flow/agent refs coming soon.`})]}),(0,R.jsxs)(sd,{value:`history`,className:`m-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Durable change log (sys_metadata_history)`}),(0,R.jsx)(B,{size:`sm`,variant:`ghost`,onClick:()=>d(null),title:`Refresh`,children:(0,R.jsx)(Ut,{className:`h-3.5 w-3.5`})})]}),f&&(0,R.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Loading…`}),!f&&u&&u.length===0&&(0,R.jsxs)(`div`,{className:`text-xs text-muted-foreground rounded border border-dashed p-4 text-center`,children:[`No history yet — this item has no overlay changes recorded.`,!yd(e.type)&&(0,R.jsxs)(`div`,{className:`mt-2 text-[10px]`,children:[`(`,e.type,` is not an overlay-tracked metadata type.)`]})]}),!f&&u&&u.length>0&&(0,R.jsx)(`ol`,{className:`space-y-2 relative before:absolute before:left-[7px] before:top-1.5 before:bottom-1.5 before:w-px before:bg-border`,children:u.slice().reverse().map(e=>(0,R.jsxs)(`li`,{className:`relative pl-6`,children:[(0,R.jsx)(`span`,{className:`absolute left-0 top-1.5 inline-block h-3.5 w-3.5 rounded-full border-2 border-background ${bd(e.op)}`,"aria-hidden":!0}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[10px] uppercase`,children:e.op}),(0,R.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground`,children:[`#`,e.seq]}),(0,R.jsx)(`span`,{className:`text-xs`,children:e.actor}),(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:id(e.ts)})]}),e.message&&(0,R.jsx)(`div`,{className:`text-xs mt-1 italic text-foreground`,children:e.message}),(0,R.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1 font-mono break-all`,children:[e.hash?(0,R.jsxs)(`span`,{title:e.hash,children:[e.hash.slice(0,17),`…`]}):(0,R.jsx)(`span`,{className:`opacity-60`,children:`∅ (tombstone)`}),e.parentHash&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`mx-1`,children:`←`}),(0,R.jsxs)(`span`,{title:e.parentHash,children:[e.parentHash.slice(0,17),`…`]})]}),(0,R.jsxs)(`span`,{className:`ml-2`,children:[`via `,e.source]})]})]},e.seq))}),!f&&u===null&&(0,R.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,R.jsx)(vn,{className:`h-3.5 w-3.5`}),` Loading history…`]})]})]})]})]})})}function gd({title:e,children:t}){return(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-muted-foreground mb-1`,children:e}),t]})}function _d({value:e,multiline:t}){return(0,R.jsx)(`pre`,{className:`text-xs font-mono bg-muted rounded p-2 overflow-auto ${t?`max-h-[50vh]`:`max-h-32`} whitespace-pre`,children:e})}var vd=new Set([`view`,`dashboard`,`report`,`email_template`]);function yd(e){let t=e.endsWith(`s`)?e.slice(0,-1):e;return vd.has(t)||vd.has(e)}function bd(e){switch(e){case`create`:return`bg-emerald-500`;case`update`:return`bg-sky-500`;case`delete`:return`bg-rose-500`;case`publish`:return`bg-violet-500`;case`revert`:return`bg-amber-500`;default:return`bg-muted-foreground`}}var xd=(0,F.createContext)(null);function Sd(e){return!!(e?.sections||e?.groups||e?.type===`simple`||e?.type===`tabbed`||e?.type===`wizard`||e?.viewType===`form`)}function Cd(e){let t=new Set,n=e=>{if(!(!e||typeof e!=`object`)){if(typeof e.field==`string`&&t.add(e.field),typeof e.name==`string`&&e.field===void 0&&e.type===void 0&&(`label`in e||`required`in e||`placeholder`in e)&&t.add(e.name),Array.isArray(e)){for(let t of e)n(t);return}for(let t of Object.keys(e))n(e[t])}};return n(e),[...t]}function wd({children:e}){let t=L(),[n,r]=(0,F.useState)([]),[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(null),u=(0,F.useCallback)(()=>s(e=>!e),[]),d=(0,F.useCallback)(async()=>{if(t){a(!0);try{let e=[],n=async e=>{try{let n=await t.meta.getItems(e);return Array.isArray(n)?n:Array.isArray(n?.items)?n.items:[]}catch{return[]}},[i,a,o,s]=await Promise.all([n(`object`),n(`view`),n(`hook`),n(`flow`)]),c=new Map;for(let e of i){let t=e?.spec??e,n=t?.name??e?.name;n&&c.set(n,t)}let u=e=>{let t=new Set,n=e?.fields;if(Array.isArray(n))for(let e of n)e?.name&&t.add(e.name);else if(n&&typeof n==`object`)for(let e of Object.keys(n))t.add(e);return[`id`,`created_at`,`updated_at`,`created_by`,`updated_by`].forEach(e=>t.add(e)),t};for(let t of a){let n=t?.spec??t,r=n?.name??t?.name??`?`,i=t?.packageId,a=n?.object;if(a&&!c.has(a)){e.push({id:`view:${r}:obj:${a}`,severity:`error`,type:`view`,name:r,packageId:i,message:`references object "${a}" which does not exist`,hint:"Create the object or update the view’s `object` property."});continue}if(a&&Sd(n)){let t=u(c.get(a)),o=Cd(n);for(let n of o)t.has(n)||e.push({id:`view:${r}:fld:${n}`,severity:`warning`,type:`view`,name:r,packageId:i,message:`references field "${n}" not declared on "${a}"`,hint:`Did you rename the field? Update the form to match.`})}}for(let t of o){let n=t?.spec??t,r=n?.name??t?.name??`?`,i=t?.packageId,a=n?.object;a&&!c.has(a)&&e.push({id:`hook:${r}:obj:${a}`,severity:`error`,type:`hook`,name:r,packageId:i,message:`hook references object "${a}" which does not exist`})}for(let t of s){let n=t?.spec??t,r=n?.name??t?.name??`?`,i=t?.packageId,a=n?.trigger?.object;a&&!c.has(a)&&e.push({id:`flow:${r}:obj:${a}`,severity:`warning`,type:`flow`,name:r,packageId:i,message:`flow trigger references object "${a}" which does not exist`})}r(e),l(Date.now())}finally{a(!1)}}},[t]);(0,F.useEffect)(()=>{d()},[d]),Ks(`object`,()=>{d()}),Ks(`view`,()=>{d()}),Ks(`flow`,()=>{d()}),Ks(`hook`,()=>{d()});let f=(0,F.useMemo)(()=>({problems:n,loading:i,open:o,setOpen:s,toggle:u,refresh:d,lastRun:c}),[n,i,o,u,d,c]);return(0,R.jsx)(xd.Provider,{value:f,children:e})}function Td(){let e=(0,F.useContext)(xd);if(!e)throw Error(`useProblems must be used inside <ProblemsProvider>`);return e}function Ed(e){return e===`error`?(0,R.jsx)(Be,{className:`h-3.5 w-3.5 text-destructive`}):e===`warning`?(0,R.jsx)(Jt,{className:`h-3.5 w-3.5 text-amber-500`}):(0,R.jsx)(vt,{className:`h-3.5 w-3.5 text-muted-foreground`})}function Dd(){let{problems:e,loading:t,open:n,toggle:r}=Td(),i=e.filter(e=>e.severity===`error`).length,a=e.filter(e=>e.severity===`warning`).length;return(0,R.jsxs)(`button`,{onClick:r,className:`h-6 px-2 inline-flex items-center gap-2 text-xs hover:bg-muted/60 rounded transition-colors`,"aria-pressed":n,title:`${e.length} problem(s). Toggle with [`,children:[(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,R.jsx)(Be,{className:`h-3 w-3`}),i]}),(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,R.jsx)(Jt,{className:`h-3 w-3`}),a]}),(0,R.jsxs)(`span`,{className:`text-muted-foreground hidden sm:inline`,children:[`Problems`,t?`…`:``]}),(0,R.jsx)(`kbd`,{className:`hidden md:inline px-1 rounded bg-muted text-[10px]`,children:`[`})]})}function Od(){let{problems:e,loading:t,open:n,setOpen:r,refresh:i}=Td();if(!n)return null;let a=new Map;for(let t of e)a.has(t.severity)||a.set(t.severity,[]),a.get(t.severity).push(t);return(0,R.jsxs)(`div`,{className:`border-t bg-background flex flex-col max-h-[40vh]`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 border-b`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:`Problems`}),(0,R.jsx)(G,{variant:`outline`,children:e.length})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(B,{size:`sm`,variant:`ghost`,onClick:()=>i(),disabled:t,title:`Re-scan`,children:(0,R.jsx)(Ut,{className:`h-3.5 w-3.5 ${t?`animate-spin`:``}`})}),(0,R.jsx)(B,{size:`sm`,variant:`ghost`,onClick:()=>r(!1),title:`Close`,children:(0,R.jsx)(At,{className:`h-3.5 w-3.5`})})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-auto`,children:[e.length===0&&(0,R.jsx)(`div`,{className:`p-6 text-center text-sm text-muted-foreground`,children:`✨ No problems detected. Cross-reference scan clean.`}),[`error`,`warning`,`info`].map(e=>{let t=a.get(e)??[];return t.length===0?null:(0,R.jsx)(`div`,{children:t.map(e=>(0,R.jsxs)(`div`,{className:`flex items-start gap-2 px-3 py-1.5 border-b hover:bg-muted/40 text-sm`,children:[(0,R.jsx)(`div`,{className:`pt-0.5`,children:Ed(e.severity)}),(0,R.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[10px]`,children:e.type}),e.packageId?(0,R.jsx)(we,{to:`/$package/metadata/$type/$name`,params:{package:e.packageId,type:e.type,name:e.name},className:`font-mono text-xs hover:underline underline-offset-2`,onClick:()=>r(!1),children:e.name}):(0,R.jsx)(`span`,{className:`font-mono text-xs`,children:e.name})]}),(0,R.jsx)(`div`,{className:`text-foreground/90`,children:e.message}),e.hint&&(0,R.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]},e.id))},e)})]})]})}function kd(e){if(!(e instanceof HTMLElement))return!1;let t=e.tagName;return!!(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`||e.isContentEditable)}function Ad({toggleInspector:e,toggleProblems:t,openHelp:n}){let r=ve(),i=Te(),a=be({strict:!1}),o=(0,F.useRef)(0);(0,F.useEffect)(()=>{function i(i){if(i.metaKey||i.ctrlKey||i.altKey||kd(i.target))return;let s=Date.now();if(i.key.toLowerCase()===`g`){o.current=s;return}if(s-o.current<1200&&o.current>0){let e=a.package,t={o:`objects`,f:`forms`,v:`views`,a:`automations`,i:`ai`,s:`security`,p:`playground`,l:`logs`,h:``}[i.key.toLowerCase()];if(e&&t!==void 0){o.current=0,i.preventDefault(),r({to:t?`/${e}/${t}`:`/${e}`});return}}if(i.key===`]`){i.preventDefault(),e();return}if(i.key===`[`){i.preventDefault(),t();return}if(i.key===`?`){i.preventDefault(),n();return}}return window.addEventListener(`keydown`,i),()=>window.removeEventListener(`keydown`,i)},[r,a.package,e,t,n,i.pathname])}var jd=[{keys:`⌘K`,label:`Open command palette`,group:`Global`},{keys:`?`,label:`Show this help`,group:`Global`},{keys:`]`,label:`Toggle Inspector drawer`,group:`Layout`},{keys:`[`,label:`Toggle Problems panel`,group:`Layout`},{keys:`g h`,label:`Go to Home`,group:`Navigation`},{keys:`g o`,label:`Go to Objects`,group:`Navigation`},{keys:`g f`,label:`Go to Forms`,group:`Navigation`},{keys:`g v`,label:`Go to Views & Apps`,group:`Navigation`},{keys:`g a`,label:`Go to Automations`,group:`Navigation`},{keys:`g i`,label:`Go to AI`,group:`Navigation`},{keys:`g s`,label:`Go to Security`,group:`Navigation`},{keys:`g p`,label:`Go to Playground`,group:`Navigation`},{keys:`g l`,label:`Go to Logs`,group:`Navigation`}];function Md({open:e,onOpenChange:t}){let n=new Map;for(let e of jd)n.has(e.group)||n.set(e.group,[]),n.get(e.group).push(e);return(0,R.jsx)(Hl,{open:e,onOpenChange:t,children:(0,R.jsxs)(Gl,{className:`sm:max-w-md`,children:[(0,R.jsxs)(Kl,{children:[(0,R.jsx)(Jl,{children:`Keyboard shortcuts`}),(0,R.jsxs)(Yl,{children:[`Most shortcuts use the `,(0,R.jsx)(`kbd`,{className:`px-1 rounded bg-muted text-xs`,children:`g`}),` `,`prefix for "go to". Keys are ignored while typing.`]})]}),(0,R.jsx)(`div`,{className:`space-y-4 max-h-[60vh] overflow-auto`,children:[...n.entries()].map(([e,t])=>(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-muted-foreground mb-1`,children:e}),(0,R.jsx)(`ul`,{className:`space-y-1`,children:t.map(e=>(0,R.jsxs)(`li`,{className:`flex items-center justify-between text-sm py-1`,children:[(0,R.jsx)(`span`,{children:e.label}),(0,R.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted text-xs font-mono`,children:e.keys})]},e.keys+e.label))})]},e))})]})})}function Nd({children:e}){let{toggle:t}=ud(),{toggle:n}=Td(),{toggle:r,isOpen:i}=gl(),[a,o]=(0,F.useState)(!1);return Ad({toggleInspector:t,toggleProblems:n,openHelp:()=>o(!0)}),(0,R.jsx)(sc,{delayDuration:500,children:(0,R.jsxs)(`div`,{className:`flex min-h-screen w-full flex-col`,children:[(0,R.jsx)(rd,{rightSlot:(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(B,{size:`sm`,variant:`ghost`,className:`h-8 w-8 p-0 ${i?`text-primary`:``}`,onClick:r,"aria-label":`Toggle AI Chat`,children:(0,R.jsx)(st,{className:`h-4 w-4`})})}),(0,R.jsxs)(uc,{children:[`AI Chat `,(0,R.jsx)(`kbd`,{className:`ml-1 px-1 rounded bg-muted text-[10px]`,children:`⌘⇧I`})]})]}),(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(B,{size:`sm`,variant:`ghost`,className:`h-8 w-8 p-0`,onClick:t,"aria-label":`Toggle Inspector`,children:(0,R.jsx)(hn,{className:`h-4 w-4`})})}),(0,R.jsxs)(uc,{children:[`Inspector `,(0,R.jsx)(`kbd`,{className:`ml-1 px-1 rounded bg-muted text-[10px]`,children:`]`})]})]}),(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(B,{size:`sm`,variant:`ghost`,className:`h-8 w-8 p-0`,onClick:()=>o(!0),"aria-label":`Keyboard shortcuts`,children:(0,R.jsx)(nn,{className:`h-4 w-4`})})}),(0,R.jsxs)(uc,{children:[`Shortcuts `,(0,R.jsx)(`kbd`,{className:`ml-1 px-1 rounded bg-muted text-[10px]`,children:`?`})]})]})]})}),(0,R.jsx)(`div`,{className:`flex flex-1 w-full overflow-hidden`,children:(0,R.jsx)(`main`,{className:`flex flex-1 min-w-0 overflow-hidden`,children:e})}),(0,R.jsx)(Od,{}),(0,R.jsx)(Pd,{}),(0,R.jsx)(hd,{}),(0,R.jsx)(Md,{open:a,onOpenChange:o})]})})}function Pd(){return(0,R.jsxs)(`div`,{className:`h-6 border-t flex items-center justify-between px-2 text-xs bg-muted/30`,children:[(0,R.jsx)(Dd,{}),(0,R.jsxs)(`div`,{className:`text-muted-foreground`,children:[(0,R.jsx)(`kbd`,{className:`px-1 rounded bg-muted text-[10px]`,children:`?`}),` shortcuts ·`,` `,(0,R.jsx)(`kbd`,{className:`px-1 rounded bg-muted text-[10px]`,children:`⌘K`}),` palette`]})]})}function Fd({children:e}){return(0,R.jsx)(ld,{children:(0,R.jsx)(wd,{children:(0,R.jsx)(Nd,{children:e})})})}function Id({user:e,onSwitchAccount:t}){return(0,R.jsx)(`div`,{className:`flex min-h-screen w-full items-center justify-center bg-background p-6`,children:(0,R.jsxs)(`div`,{className:`w-full max-w-md space-y-6 text-center`,children:[(0,R.jsx)(`div`,{className:`mx-auto flex h-14 w-14 items-center justify-center rounded-full bg-destructive/10`,children:(0,R.jsx)(Ae,{className:`h-7 w-7 text-destructive`})}),(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Studio is for admins only`}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Studio is the developer console for ObjectStack — schema design, runtime inspection, and metadata editing. Your account doesn't have admin access on this server.`})]}),(0,R.jsxs)(`div`,{className:`rounded-md border bg-muted/30 px-4 py-3 text-left text-xs`,children:[(0,R.jsx)(`div`,{className:`text-muted-foreground`,children:`Signed in as`}),(0,R.jsxs)(`div`,{className:`mt-0.5 font-medium`,children:[e.name??e.email??e.id,e.email&&e.name?(0,R.jsxs)(`span`,{className:`ml-2 text-muted-foreground`,children:[`(`,e.email,`)`]}):null]}),(0,R.jsxs)(`div`,{className:`mt-2 text-muted-foreground`,children:[`Role: `,(0,R.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5`,children:e.role??`user`})]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,R.jsx)(B,{asChild:!0,className:`w-full gap-2`,children:(0,R.jsxs)(`a`,{href:`/_console/`,children:[`Go to Console`,(0,R.jsx)(pn,{className:`h-4 w-4`})]})}),(0,R.jsxs)(B,{variant:`outline`,onClick:t,className:`w-full gap-2`,children:[(0,R.jsx)(ke,{className:`h-4 w-4`}),`Sign out & switch account`]})]}),(0,R.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Need access? Ask a platform admin to grant you the`,` `,(0,R.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5`,children:`admin_full_access`}),` `,`permission set, or make you an owner/admin of your organization.`]})]})})}function Ld(){return{plugins:new Map,viewers:new Map,panels:new Map,actions:new Map,commands:new Map,metadataIcons:new Map,activated:new Set}}var Rd=class{state;listeners=new Set;constructor(){this.state=Ld()}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}getSnapshot(){return this.state}notify(){this.state={...this.state},this.listeners.forEach(e=>e())}register(e){let{id:t}=e.manifest;this.state.plugins.has(t)&&(console.warn(`[PluginRegistry] Plugin "${t}" is already registered, replacing.`),this.deactivate(t)),this.state.plugins.set(t,e),this.notify()}async registerAndActivate(e){this.register(e),await this.activate(e.manifest.id)}async activate(e){let t=this.state.plugins.get(e);if(!t){console.error(`[PluginRegistry] Cannot activate unknown plugin "${e}"`);return}if(this.state.activated.has(e))return;let n=this.createPluginAPI(e,t);try{await t.activate(n),this.state.activated.add(e),console.log(`[PluginRegistry] Activated plugin "${e}"`),this.notify()}catch(t){console.error(`[PluginRegistry] Failed to activate "${e}":`,t)}}deactivate(e){let t=this.state.plugins.get(e);if(t){try{t.deactivate?.()}catch(t){console.error(`[PluginRegistry] Error deactivating "${e}":`,t)}for(let[t,n]of this.state.viewers)n.pluginId===e&&this.state.viewers.delete(t);for(let[t,n]of this.state.panels)n.pluginId===e&&this.state.panels.delete(t);for(let[t,n]of this.state.actions)n.pluginId===e&&this.state.actions.delete(t);for(let[t,n]of this.state.commands)n.pluginId===e&&this.state.commands.delete(t);for(let[e,n]of this.state.metadataIcons)n.metadataType&&t.manifest.contributes.metadataIcons?.some(t=>t.metadataType===e)&&this.state.metadataIcons.delete(e);this.state.activated.delete(e),this.state.plugins.delete(e),this.notify()}}getViewer(e,t=`preview`){let n=null;for(let r of this.state.viewers.values())!r.metadataTypes.includes(e)&&!r.metadataTypes.includes(`*`)||r.modes.includes(t)&&(!n||r.priority>n.priority)&&(n=r);return n}getViewers(e){return Array.from(this.state.viewers.values()).filter(t=>t.metadataTypes.includes(e)||t.metadataTypes.includes(`*`)).sort((e,t)=>t.priority-e.priority)}getAvailableModes(e){let t=new Set;for(let n of this.state.viewers.values())(n.metadataTypes.includes(e)||n.metadataTypes.includes(`*`))&&n.modes.forEach(e=>t.add(e));return Array.from(t)}getActions(e,t){return Array.from(this.state.actions.values()).filter(n=>t&&n.location!==t?!1:n.metadataTypes.length===0||n.metadataTypes.includes(e))}getCommands(){return Array.from(this.state.commands.values())}getPanels(e){return Array.from(this.state.panels.values()).filter(t=>!e||t.location===e)}getPlugins(){return Array.from(this.state.plugins.values())}getSidebarGroups(){let e=new Map;for(let t of this.state.plugins.values())for(let n of t.manifest.contributes.sidebarGroups){let t=e.get(n.key);if(t){let e=new Set([...t.metadataTypes,...n.metadataTypes]);t.metadataTypes=Array.from(e),n.order<t.order&&(t.order=n.order,t.label=n.label,t.icon=n.icon||t.icon)}else e.set(n.key,{...n})}return Array.from(e.values()).sort((e,t)=>e.order-t.order)}getMetadataIcon(e){return this.state.metadataIcons.get(e)||null}getAllMetadataIcons(){return new Map(this.state.metadataIcons)}isActivated(e){return this.state.activated.has(e)}createPluginAPI(e,t){let n=this;return{registerViewer(r,i){let a=t.manifest.contributes.metadataViewers.find(e=>e.id===r);if(!a){console.warn(`[PluginRegistry] Viewer "${r}" not declared in manifest of "${e}"`);return}let o={id:r,pluginId:e,label:a.label,metadataTypes:a.metadataTypes,modes:a.modes,priority:a.priority,component:i};n.state.viewers.set(r,o),n.notify()},registerPanel(r,i){let a=t.manifest.contributes.panels.find(e=>e.id===r);if(!a){console.warn(`[PluginRegistry] Panel "${r}" not declared in manifest of "${e}"`);return}n.state.panels.set(r,{id:r,pluginId:e,label:a.label,icon:a.icon,location:a.location,component:i}),n.notify()},registerAction(r,i){let a=t.manifest.contributes.actions.find(e=>e.id===r);if(!a){console.warn(`[PluginRegistry] Action "${r}" not declared in manifest of "${e}"`);return}n.state.actions.set(r,{id:r,pluginId:e,label:a.label,icon:a.icon,location:a.location,metadataTypes:a.metadataTypes,handler:i}),n.notify()},registerCommand(r,i){let a=t.manifest.contributes.commands.find(e=>e.id===r);if(!a){console.warn(`[PluginRegistry] Command "${r}" not declared in manifest of "${e}"`);return}n.state.commands.set(r,{id:r,pluginId:e,label:a.label,shortcut:a.shortcut,icon:a.icon,handler:i}),n.notify()},registerMetadataIcon(e,r,i){let a=t.manifest.contributes.metadataIcons.find(t=>t.metadataType===e);n.state.metadataIcons.set(e,{metadataType:e,label:i||a?.label||e,icon:r}),n.notify()}}}},zd=null;function Bd(){return zd||=new Rd,zd}var Vd=(0,F.createContext)(null);function Hd(){let e=(0,F.useContext)(Vd);if(!e)throw Error(`usePluginRegistry must be used within a <PluginRegistryProvider>`);return e}function Ud({plugins:e=[],registry:t,children:n}){let r=(0,F.useMemo)(()=>t||Bd(),[t]),[i,a]=(0,F.useState)(!1);return(0,F.useEffect)(()=>{let t=!1;async function n(){for(let n of e){if(t)break;try{await r.registerAndActivate(n)}catch(e){console.error(`[PluginRegistryProvider] Failed to init plugin "${n.manifest.id}":`,e)}}t||a(!0)}return n(),()=>{t=!0}},[r,e]),i?(0,R.jsx)(Vd.Provider,{value:r,children:n}):(0,R.jsx)(Vd.Provider,{value:r,children:(0,R.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background`,children:(0,R.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,R.jsx)(`div`,{className:`h-8 w-8 mx-auto animate-spin rounded-full border-4 border-muted border-t-primary`}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Loading plugins…`})]})})})}function Wd(){let e=Hd();return(0,F.useSyncExternalStore)((0,F.useCallback)(t=>e.subscribe(t),[e]),(0,F.useCallback)(()=>e.getSnapshot(),[e]))}function Gd(e,t=`preview`){let n=Hd();return Wd(),(0,F.useMemo)(()=>n.getViewer(e,t),[n,e,t])}function Kd(e){let t=Hd();return Wd(),(0,F.useMemo)(()=>t.getViewers(e),[t,e])}function qd(e){let t=Hd();return Wd(),(0,F.useMemo)(()=>t.getAvailableModes(e),[t,e])}function Jd(e,t){let n=Hd();return Wd(),(0,F.useMemo)(()=>n.getActions(e,t),[n,e,t])}var Yd={preview:{icon:On,label:`Preview`},design:{icon:An,label:`Design`},code:{icon:ze,label:`Code`},data:{icon:Re,label:`Data`},history:{icon:vn,label:`History`}},Xd={object:{data:`Records`,design:`Fields`,code:`API`}},Zd={object:`data`},Qd={object:[`data`,`design`,`code`,`history`]};function $d(e,t){return Xd[e]?.[t]??Yd[t].label}function ef({metadataType:e,metadataName:t,data:n,packageId:r}){let[i,a]=(0,F.useState)(Zd[e]??`preview`),o=qd(e),s=(0,F.useMemo)(()=>{let t=Qd[e];return t?t.filter(e=>o.includes(e)):o},[o,e]),c=Kd(e),l=Gd(e,i),u=Jd(e,`toolbar`),d=s.includes(i)?i:s[0]||`preview`,f=(0,F.useMemo)(()=>c.filter(e=>e.modes.includes(d)),[c,d]),[p,m]=(0,F.useState)(0),h=f[p]||l;if(!h)return(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-muted-foreground`,children:(0,R.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,R.jsxs)(`p`,{className:`text-sm`,children:[`No viewer available for `,(0,R.jsx)(G,{variant:`outline`,children:e})]}),(0,R.jsx)(`p`,{className:`text-xs`,children:`Install a plugin that supports this metadata type.`})]})});let g=h.component;return(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-4 bg-muted/30 min-h-10`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-0.5`,children:s.map(t=>{let n=Yd[t].icon,r=t===d,i=$d(e,t);return(0,R.jsxs)(`button`,{onClick:()=>{a(t),m(0)},className:`
|
|
7
|
-
flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-md transition-colors
|
|
8
|
-
${r?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground hover:bg-background/50`}
|
|
9
|
-
`,children:[(0,R.jsx)(n,{className:`h-3.5 w-3.5`}),i]},t)})}),f.length>1&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`div`,{className:`mx-2 h-4 w-px bg-border`}),(0,R.jsxs)(uu,{children:[(0,R.jsx)(du,{asChild:!0,children:(0,R.jsxs)(B,{variant:`ghost`,size:`sm`,className:`h-7 gap-1 text-xs`,children:[h.label,(0,R.jsx)(We,{className:`h-3 w-3`})]})}),(0,R.jsx)(mu,{align:`start`,children:f.map((e,t)=>(0,R.jsx)(hu,{onClick:()=>m(t),className:t===p?`bg-accent`:``,children:(0,R.jsx)(`span`,{className:`text-xs`,children:e.label})},e.id))})]})]}),(0,R.jsx)(`div`,{className:`flex-1`}),u.map(r=>(0,R.jsx)(B,{variant:`ghost`,size:`sm`,className:`h-7 text-xs`,onClick:()=>r.handler({metadataType:e,metadataName:t,data:n}),children:r.label},r.id))]}),(0,R.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,R.jsx)(g,{metadataType:e,metadataName:t,data:n,mode:d,packageId:r})})]})}function q(e){if(typeof process<`u`&&{}.OS_EAGER_SCHEMAS===`1`)return e();let t,n=()=>(t===void 0&&(t=e()),t);return new Proxy(function(){},{get(e,t){let r=n(),i=r[t];return typeof i==`function`?i.bind(r):i},set(e,t,r){let i=n();return i[t]=r,!0},has(e,t){return t in n()},ownKeys(){return Reflect.ownKeys(n())},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(n(),t)},getPrototypeOf(){return Reflect.getPrototypeOf(n())}})}var tf=q(()=>c([`preview`,`design`,`code`,`data`,`history`])),nf=q(()=>D({id:x().describe(`Unique viewer identifier`),metadataTypes:N(x()).min(1).describe(`Metadata types this viewer can handle`),label:x().describe(`Viewer display label`),priority:h().default(0).describe(`Viewer priority (higher wins)`),modes:N(tf).default([`preview`]).describe(`Supported view modes`)})),rf=q(()=>D({key:x().describe(`Unique group key`),label:x().describe(`Group display label`),icon:x().optional().describe(`Lucide icon name`),metadataTypes:N(x()).describe(`Metadata types in this group`),order:h().default(100).describe(`Sort order (lower = higher)`)})),af=q(()=>c([`toolbar`,`contextMenu`,`commandPalette`])),of=q(()=>D({id:x().describe(`Unique action identifier`),label:x().describe(`Action display label`),icon:x().optional().describe(`Lucide icon name`),location:af.describe(`UI location`),metadataTypes:N(x()).default([]).describe(`Applicable metadata types`)})),sf=q(()=>D({metadataType:x().describe(`Metadata type`),label:x().describe(`Display label`),icon:x().describe(`Lucide icon name`)})),cf=q(()=>c([`bottom`,`right`,`modal`])),lf=q(()=>D({id:x().describe(`Unique panel identifier`),label:x().describe(`Panel display label`),icon:x().optional().describe(`Lucide icon name`),location:cf.default(`bottom`).describe(`Panel location`)})),uf=q(()=>D({id:x().describe(`Unique command identifier`),label:x().describe(`Command display label`),shortcut:x().optional().describe(`Keyboard shortcut`),icon:x().optional().describe(`Lucide icon name`)})),df=q(()=>D({metadataViewers:N(nf).default([]),sidebarGroups:N(rf).default([]),actions:N(of).default([]),metadataIcons:N(sf).default([]),panels:N(lf).default([]),commands:N(uf).default([])})),ff=q(()=>x().describe(`Activation event pattern`)),pf=q(()=>D({id:x().regex(/^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)*$/).describe(`Plugin ID (dot-separated lowercase)`),name:x().describe(`Plugin display name`),version:x().default(`0.0.1`).describe(`Plugin version`),description:x().optional().describe(`Plugin description`),author:x().optional().describe(`Author`),contributes:df.default({metadataViewers:[],sidebarGroups:[],actions:[],metadataIcons:[],panels:[],commands:[]}),activationEvents:N(ff).default([`*`])}));function mf(e){return pf.parse(e)}var hf=q(()=>D({key:x().describe(`Section key (e.g., "basics", "constraints", "security")`),label:x().describe(`Section display label`),icon:x().optional().describe(`Lucide icon name`),defaultExpanded:k().default(!0).describe(`Whether section is expanded by default`),order:h().default(0).describe(`Sort order (lower = higher)`)})),gf=q(()=>D({key:x().describe(`Group key matching field.group values`),label:x().describe(`Group display label`),icon:x().optional().describe(`Lucide icon name`),defaultExpanded:k().default(!0).describe(`Whether group is expanded by default`),order:h().default(0).describe(`Sort order (lower = higher)`)})),_f=q(()=>D({inlineEditing:k().default(!0).describe(`Enable inline editing of field properties`),dragReorder:k().default(!0).describe(`Enable drag-and-drop field reordering`),showFieldGroups:k().default(!0).describe(`Show field group headers`),showPropertyPanel:k().default(!0).describe(`Show the right-side property panel`),propertySections:N(hf).default([{key:`basics`,label:`Basic Properties`,defaultExpanded:!0,order:0},{key:`constraints`,label:`Constraints & Validation`,defaultExpanded:!0,order:10},{key:`relationship`,label:`Relationship Config`,defaultExpanded:!0,order:20},{key:`display`,label:`Display & UI`,defaultExpanded:!1,order:30},{key:`security`,label:`Security & Compliance`,defaultExpanded:!1,order:40},{key:`advanced`,label:`Advanced`,defaultExpanded:!1,order:50}]).describe(`Property panel section definitions`),fieldGroups:N(gf).default([]).describe(`Field group definitions`),paginationThreshold:h().default(50).describe(`Number of fields before pagination is enabled`),batchOperations:k().default(!0).describe(`Enable batch add/remove field operations`),showUsageStats:k().default(!1).describe(`Show field usage statistics`)})),vf=q(()=>D({type:c([`lookup`,`master_detail`,`tree`]).describe(`Relationship type`),lineStyle:c([`solid`,`dashed`,`dotted`]).default(`solid`).describe(`Line style in diagrams`),color:x().default(`#94a3b8`).describe(`Line color (CSS value)`),highlightColor:x().default(`#0891b2`).describe(`Highlighted color on hover/select`),cardinalityLabel:x().default(`1:N`).describe(`Cardinality label (e.g., "1:N", "1:1", "N:M")`)})),yf=q(()=>D({visualCreation:k().default(!0).describe(`Enable drag-to-create relationships`),showReverseRelationships:k().default(!0).describe(`Show reverse/child-to-parent relationships`),showCascadeWarnings:k().default(!0).describe(`Show cascade delete behavior warnings`),displayConfig:N(vf).default([{type:`lookup`,lineStyle:`dashed`,color:`#0891b2`,highlightColor:`#06b6d4`,cardinalityLabel:`1:N`},{type:`master_detail`,lineStyle:`solid`,color:`#ea580c`,highlightColor:`#f97316`,cardinalityLabel:`1:N`},{type:`tree`,lineStyle:`dotted`,color:`#8b5cf6`,highlightColor:`#a78bfa`,cardinalityLabel:`1:N`}]).describe(`Visual config per relationship type`)})),bf=q(()=>c([`force`,`hierarchy`,`grid`,`circular`]).describe(`ER diagram layout algorithm`)),xf=q(()=>D({showFields:k().default(!0).describe(`Show field list inside entity nodes`),maxFieldsVisible:h().default(8).describe(`Max fields visible before "N more..." collapse`),showFieldTypes:k().default(!0).describe(`Show field type badges`),showRequiredIndicator:k().default(!0).describe(`Show required field indicators`),showRecordCount:k().default(!1).describe(`Show live record count on nodes`),showIcon:k().default(!0).describe(`Show object icon on node header`),showDescription:k().default(!0).describe(`Show description tooltip on hover`)})),Sf=q(()=>D({enabled:k().default(!0).describe(`Enable ER diagram panel`),layout:bf.default(`force`).describe(`Default layout algorithm`),nodeDisplay:xf.default({showFields:!0,maxFieldsVisible:8,showFieldTypes:!0,showRequiredIndicator:!0,showRecordCount:!1,showIcon:!0,showDescription:!0}).describe(`Node display configuration`),showMinimap:k().default(!0).describe(`Show minimap for large diagrams`),zoomControls:k().default(!0).describe(`Show zoom in/out/fit controls`),minZoom:h().default(.1).describe(`Minimum zoom level`),maxZoom:h().default(3).describe(`Maximum zoom level`),showEdgeLabels:k().default(!0).describe(`Show cardinality labels on relationship edges`),highlightOnHover:k().default(!0).describe(`Highlight connected entities on node hover`),clickToNavigate:k().default(!0).describe(`Click node to navigate to object detail`),dragToConnect:k().default(!0).describe(`Drag between nodes to create relationships`),hideOrphans:k().default(!1).describe(`Hide objects with no relationships`),autoFit:k().default(!0).describe(`Auto-fit diagram to viewport on load`),exportFormats:N(c([`png`,`svg`,`json`])).default([`png`,`svg`]).describe(`Available export formats for diagram`)})),Cf=q(()=>c([`table`,`cards`,`tree`]).describe(`Object list display mode`)),wf=q(()=>c([`name`,`label`,`fieldCount`,`updatedAt`]).describe(`Object list sort field`)),Tf=q(()=>D({package:x().optional().describe(`Filter by owning package`),tags:N(x()).optional().describe(`Filter by object tags`),includeSystem:k().default(!0).describe(`Include system-level objects`),includeAbstract:k().default(!1).describe(`Include abstract base objects`),hasFieldType:x().optional().describe(`Filter to objects containing a specific field type`),hasRelationships:k().optional().describe(`Filter to objects with lookup/master_detail fields`),searchQuery:x().optional().describe(`Free-text search across name, label, and description`)})),Ef=q(()=>D({defaultDisplayMode:Cf.default(`table`).describe(`Default list display mode`),defaultSortField:wf.default(`label`).describe(`Default sort field`),defaultSortDirection:c([`asc`,`desc`]).default(`asc`).describe(`Default sort direction`),defaultFilter:Tf.default({includeSystem:!0,includeAbstract:!1}).describe(`Default filter configuration`),showFieldCount:k().default(!0).describe(`Show field count badge`),showRelationshipCount:k().default(!0).describe(`Show relationship count badge`),showQuickPreview:k().default(!0).describe(`Show quick field preview tooltip on hover`),enableComparison:k().default(!1).describe(`Enable side-by-side object comparison`),showERDiagramToggle:k().default(!0).describe(`Show ER diagram toggle in toolbar`),showCreateAction:k().default(!0).describe(`Show create object action`),showStatsSummary:k().default(!0).describe(`Show statistics summary bar`)})),Df=q(()=>D({key:x().describe(`Tab key`),label:x().describe(`Tab display label`),icon:x().optional().describe(`Lucide icon name`),enabled:k().default(!0).describe(`Whether this tab is available`),order:h().default(0).describe(`Sort order (lower = higher)`)})),Of=q(()=>D({tabs:N(Df).default([{key:`fields`,label:`Fields`,icon:`list`,enabled:!0,order:0},{key:`relationships`,label:`Relationships`,icon:`link`,enabled:!0,order:10},{key:`indexes`,label:`Indexes`,icon:`zap`,enabled:!0,order:20},{key:`validations`,label:`Validations`,icon:`shield-check`,enabled:!0,order:30},{key:`capabilities`,label:`Capabilities`,icon:`settings`,enabled:!0,order:40},{key:`data`,label:`Data`,icon:`table-2`,enabled:!0,order:50},{key:`api`,label:`API`,icon:`globe`,enabled:!0,order:60},{key:`code`,label:`Code`,icon:`code-2`,enabled:!0,order:70}]).describe(`Object detail preview tabs`),defaultTab:x().default(`fields`).describe(`Default active tab key`),showHeader:k().default(!0).describe(`Show object summary header`),showBreadcrumbs:k().default(!0).describe(`Show navigation breadcrumbs`)})),kf=q(()=>c([`field-editor`,`relationship-mapper`,`er-diagram`,`object-manager`]).describe(`Default view when entering the Object Designer`));q(()=>D({defaultView:kf.default(`field-editor`).describe(`Default view`),fieldEditor:_f.default({inlineEditing:!0,dragReorder:!0,showFieldGroups:!0,showPropertyPanel:!0,propertySections:[{key:`basics`,label:`Basic Properties`,defaultExpanded:!0,order:0},{key:`constraints`,label:`Constraints & Validation`,defaultExpanded:!0,order:10},{key:`relationship`,label:`Relationship Config`,defaultExpanded:!0,order:20},{key:`display`,label:`Display & UI`,defaultExpanded:!1,order:30},{key:`security`,label:`Security & Compliance`,defaultExpanded:!1,order:40},{key:`advanced`,label:`Advanced`,defaultExpanded:!1,order:50}],fieldGroups:[],paginationThreshold:50,batchOperations:!0,showUsageStats:!1}).describe(`Field editor configuration`),relationshipMapper:yf.default({visualCreation:!0,showReverseRelationships:!0,showCascadeWarnings:!0,displayConfig:[{type:`lookup`,lineStyle:`dashed`,color:`#0891b2`,highlightColor:`#06b6d4`,cardinalityLabel:`1:N`},{type:`master_detail`,lineStyle:`solid`,color:`#ea580c`,highlightColor:`#f97316`,cardinalityLabel:`1:N`},{type:`tree`,lineStyle:`dotted`,color:`#8b5cf6`,highlightColor:`#a78bfa`,cardinalityLabel:`1:N`}]}).describe(`Relationship mapper configuration`),erDiagram:Sf.default({enabled:!0,layout:`force`,nodeDisplay:{showFields:!0,maxFieldsVisible:8,showFieldTypes:!0,showRequiredIndicator:!0,showRecordCount:!1,showIcon:!0,showDescription:!0},showMinimap:!0,zoomControls:!0,minZoom:.1,maxZoom:3,showEdgeLabels:!0,highlightOnHover:!0,clickToNavigate:!0,dragToConnect:!0,hideOrphans:!1,autoFit:!0,exportFormats:[`png`,`svg`]}).describe(`ER diagram configuration`),objectManager:Ef.default({defaultDisplayMode:`table`,defaultSortField:`label`,defaultSortDirection:`asc`,defaultFilter:{includeSystem:!0,includeAbstract:!1},showFieldCount:!0,showRelationshipCount:!0,showQuickPreview:!0,enableComparison:!1,showERDiagramToggle:!0,showCreateAction:!0,showStatsSummary:!0}).describe(`Object manager configuration`),objectPreview:Of.default({tabs:[{key:`fields`,label:`Fields`,icon:`list`,enabled:!0,order:0},{key:`relationships`,label:`Relationships`,icon:`link`,enabled:!0,order:10},{key:`indexes`,label:`Indexes`,icon:`zap`,enabled:!0,order:20},{key:`validations`,label:`Validations`,icon:`shield-check`,enabled:!0,order:30},{key:`capabilities`,label:`Capabilities`,icon:`settings`,enabled:!0,order:40},{key:`data`,label:`Data`,icon:`table-2`,enabled:!0,order:50},{key:`api`,label:`API`,icon:`globe`,enabled:!0,order:60},{key:`code`,label:`Code`,icon:`code-2`,enabled:!0,order:70}],defaultTab:`fields`,showHeader:!0,showBreadcrumbs:!0}).describe(`Object preview configuration`)}));var Af=q(()=>D({enabled:k().default(!0).describe(`Enable snap-to-grid`),gridSize:h().int().min(1).default(8).describe(`Snap grid size in pixels`),showGrid:k().default(!0).describe(`Show grid overlay on canvas`),showGuides:k().default(!0).describe(`Show alignment guides when dragging`)})),jf=q(()=>D({min:h().min(.1).default(.25).describe(`Minimum zoom level`),max:h().max(10).default(3).describe(`Maximum zoom level`),default:h().default(1).describe(`Default zoom level`),step:h().default(.1).describe(`Zoom step increment`)})),Mf=q(()=>D({type:x().describe(`Component type (e.g. "element:button", "element:text")`),label:x().describe(`Display label in palette`),icon:x().optional().describe(`Icon name for palette display`),category:c([`content`,`interactive`,`data`,`layout`]).describe(`Palette category grouping`),defaultWidth:h().int().min(1).default(4).describe(`Default width in grid columns`),defaultHeight:h().int().min(1).default(2).describe(`Default height in grid rows`)})),Nf=q(()=>D({snap:Af.optional().describe(`Canvas snap settings`),zoom:jf.optional().describe(`Canvas zoom settings`),palette:N(Mf).optional().describe(`Custom element palette (defaults to all registered elements)`),showLayerPanel:k().default(!0).describe(`Show layer ordering panel`),showPropertyPanel:k().default(!0).describe(`Show property inspector panel`),undoLimit:h().int().min(1).default(50).describe(`Maximum undo history steps`)}));q(()=>Nf);var Pf=q(()=>c([`rounded_rect`,`circle`,`diamond`,`parallelogram`,`hexagon`,`diamond_thick`,`attached_circle`,`screen_rect`]).describe(`Visual shape for rendering a flow node on the canvas`)),Ff=q(()=>D({action:x().describe(`FlowNodeAction value (e.g., "parallel_gateway")`),shape:Pf.describe(`Shape to render`),icon:x().describe(`Lucide icon name`),defaultLabel:x().describe(`Default display label`),defaultWidth:h().int().min(20).default(120).describe(`Default width in pixels`),defaultHeight:h().int().min(20).default(60).describe(`Default height in pixels`),fillColor:x().default(`#ffffff`).describe(`Node fill color (CSS value)`),borderColor:x().default(`#94a3b8`).describe(`Node border color (CSS value)`),allowBoundaryEvents:k().default(!1).describe(`Whether boundary events can be attached to this node type`),paletteCategory:c([`event`,`gateway`,`activity`,`data`,`subflow`]).describe(`Palette category for grouping`)}).describe(`Visual render descriptor for a flow node type`));q(()=>D({nodeId:x().describe(`Corresponding FlowNode.id`),x:h().describe(`X position on canvas`),y:h().describe(`Y position on canvas`),width:h().int().min(20).optional().describe(`Width override in pixels`),height:h().int().min(20).optional().describe(`Height override in pixels`),collapsed:k().default(!1).describe(`Whether the node is collapsed`),fillColor:x().optional().describe(`Fill color override`),borderColor:x().optional().describe(`Border color override`),annotation:x().optional().describe(`User annotation displayed near the node`)}).describe(`Canvas layout data for a flow node`));var If=q(()=>c([`solid`,`dashed`,`dotted`,`bold`]).describe(`Edge line style`));q(()=>D({edgeId:x().describe(`Corresponding FlowEdge.id`),style:If.default(`solid`).describe(`Line style`),color:x().default(`#94a3b8`).describe(`Edge line color`),labelPosition:h().min(0).max(1).default(.5).describe(`Position of the condition label along the edge`),waypoints:N(D({x:h().describe(`Waypoint X`),y:h().describe(`Waypoint Y`)})).optional().describe(`Manual waypoints for edge routing`),animated:k().default(!1).describe(`Show animated flow indicator`)}).describe(`Canvas layout and visual data for a flow edge`));var Lf=q(()=>c([`dagre`,`elk`,`force`,`manual`]).describe(`Auto-layout algorithm for the flow canvas`)),Rf=q(()=>c([`TB`,`BT`,`LR`,`RL`]).describe(`Auto-layout direction`));q(()=>D({snap:D({enabled:k().default(!0).describe(`Enable snap-to-grid`),gridSize:h().int().min(1).default(16).describe(`Snap grid size in pixels`),showGrid:k().default(!0).describe(`Show grid overlay`)}).default({enabled:!0,gridSize:16,showGrid:!0}).describe(`Canvas snap-to-grid settings`),zoom:D({min:h().min(.1).default(.25).describe(`Minimum zoom level`),max:h().max(10).default(3).describe(`Maximum zoom level`),default:h().default(1).describe(`Default zoom level`),step:h().default(.1).describe(`Zoom step`)}).default({min:.25,max:3,default:1,step:.1}).describe(`Canvas zoom settings`),layoutAlgorithm:Lf.default(`dagre`).describe(`Default auto-layout algorithm`),layoutDirection:Rf.default(`TB`).describe(`Default auto-layout direction`),nodeDescriptors:N(Ff).optional().describe(`Custom node render descriptors (merged with built-in defaults)`),showMinimap:k().default(!0).describe(`Show minimap panel`),showPropertyPanel:k().default(!0).describe(`Show property panel`),showPalette:k().default(!0).describe(`Show node palette sidebar`),undoLimit:h().int().min(1).default(50).describe(`Maximum undo history steps`),animateExecution:k().default(!0).describe(`Animate edges during execution preview`),connectionValidation:k().default(!0).describe(`Validate connections before creating edges`)}).describe(`Studio Flow Builder configuration`));function zf(){let[e,t]=(0,F.useState)(null);return(0,F.useEffect)(()=>{let e=Sl();console.log(`[Studio] Connecting to API: ${e||`(same-origin / proxy)`}`),t(new Hs({baseUrl:e}))},[]),e}function Bf(e){return L()}var Vf=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{className:`relative w-full overflow-auto`,children:(0,R.jsx)(`table`,{ref:n,className:z(`w-full caption-bottom text-sm`,e),...t})}));Vf.displayName=`Table`;var Hf=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`thead`,{ref:n,className:z(`[&_tr]:border-b`,e),...t}));Hf.displayName=`TableHeader`;var Uf=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`tbody`,{ref:n,className:z(`[&_tr:last-child]:border-0`,e),...t}));Uf.displayName=`TableBody`;var Wf=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`tfoot`,{ref:n,className:z(`border-t bg-muted/50 font-medium [&>tr]:last:border-b-0`,e),...t}));Wf.displayName=`TableFooter`;var Gf=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`tr`,{ref:n,className:z(`border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted`,e),...t}));Gf.displayName=`TableRow`;var J=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`th`,{ref:n,className:z(`h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t}));J.displayName=`TableHead`;var Y=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`td`,{ref:n,className:z(`p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]`,e),...t}));Y.displayName=`TableCell`;var Kf=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`caption`,{ref:n,className:z(`mt-4 text-sm text-muted-foreground`,e),...t}));Kf.displayName=`TableCaption`;var qf=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Er,{ref:n,className:z(`peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground`,e),...t,children:(0,R.jsx)(fr,{className:z(`flex items-center justify-center text-current`),children:(0,R.jsx)(_t,{className:`h-3.5 w-3.5`})})}));qf.displayName=Er.displayName;function Jf(e){return e==null?`—`:typeof e==`boolean`?e?`true`:`false`:typeof e==`string`?e:typeof e==`number`?String(e):JSON.stringify(e,null,2)}function Yf(e){let t=[`name`,`label`,`type`,`required`,`multiple`,`maxLength`,`defaultValue`,`options`,`reference`,`formula`,`description`],n={};for(let r of t)e[r]!==void 0&&(n[r]=e[r]);for(let r of Object.keys(e))!t.includes(r)&&e[r]!==void 0&&(n[r]=e[r]);let r=JSON.stringify(n,null,2);return`${e.name}: ${r},`}function Xf({field:e,objectName:t,packageId:n,onClose:r}){let[i,a]=(0,F.useState)(!1),[o,s]=(0,F.useState)(!1),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(null);(0,F.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=n&&n!==`all`?`/_studio/api/metadata/layout?package=${encodeURIComponent(n)}`:`/_studio/api/metadata/layout`,r=await fetch(e);if(!r.ok){t||d(null);return}let i=await r.json().catch(()=>null);t||d(i?.srcRoot??null)}catch{t||d(null)}})(),()=>{t=!0}},[e,n]);let[f,p]=(0,F.useState)(``),[m,h]=(0,F.useState)(``),[g,_]=(0,F.useState)(!1);(0,F.useEffect)(()=>{e&&(p(e.label??``),h(e.description??``),_(!!e.required),s(!1),a(!1))},[e]);let v=(0,F.useMemo)(()=>e?o?{...e,label:f,description:m||void 0,required:g||void 0}:e:null,[e,o,f,m,g]),y=(0,F.useMemo)(()=>!e||!o?!1:f!==(e.label??``)||m!==(e.description??``)||g!==!!e.required,[e,o,f,m,g]),b=(0,F.useCallback)(()=>{if(!e)return;let r=`vscode://objectstack.vscode-objectstack/open?type=object&name=${encodeURIComponent(t)}${n?`&package=${encodeURIComponent(n)}`:``}&field=${encodeURIComponent(e.name)}`;window.location.href=r},[e,t,n]),x=(0,F.useCallback)(async()=>{if(v)try{await navigator.clipboard.writeText(Yf(v)),a(!0),setTimeout(()=>a(!1),1500),U({title:y?`Copied edited ${v.name} snippet`:`Copied ${v.name} snippet`,description:y?`Paste over the existing field definition in the .object.ts file.`:void 0})}catch{U({title:`Clipboard unavailable`,variant:`destructive`})}},[v,y]),S=u!=null&&y&&e!=null,C=(0,F.useCallback)(async()=>{if(!(!S||!e)){l(!0);try{let n=`${u}/objects/${t}.object.ts`,r={};f!==(e.label??``)&&(r.label=f||null),m!==(e.description??``)&&(r.description=m||null),g!==!!e.required&&(r.required=g);let i=await fetch(`/_studio/api/metadata/field-patch`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:n,field:e.name,patch:r})}),a=await i.json().catch(()=>({}));if(!i.ok||!a?.ok){U({title:`Save failed`,description:a?.error??`HTTP ${i.status}`,variant:`destructive`});return}U({title:`Field updated`,description:`${n} — HMR will reload momentarily.`}),s(!1)}catch(e){U({title:`Save failed`,description:e?.message??String(e),variant:`destructive`})}finally{l(!1)}}},[S,e,u,t,f,m,g]);if(!e||!v)return null;let w=new Set([`name`,`label`,`type`]),T=o?new Set([`description`,`required`]):new Set,ee=Object.entries(e).filter(([e,t])=>!w.has(e)&&!T.has(e)&&t!==void 0&&t!==!1&&t!==null&&t!==``);return(0,R.jsx)(Qs,{open:!!e,onOpenChange:e=>{e||r()},children:(0,R.jsxs)(nc,{className:`w-[440px] sm:max-w-[440px] overflow-y-auto`,children:[(0,R.jsxs)(rc,{className:`space-y-2 pb-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,R.jsx)(`code`,{className:`truncate rounded bg-muted px-1.5 py-0.5 font-mono text-sm font-medium`,children:e.name}),(0,R.jsxs)(G,{variant:`outline`,className:`shrink-0 text-[10px]`,children:[e.type,e.multiple?`[]`:``]}),v.required&&(0,R.jsx)(G,{className:`shrink-0 bg-amber-100 text-[10px] text-amber-700 border-amber-200 hover:bg-amber-100 dark:bg-amber-950 dark:text-amber-400 dark:border-amber-800`,children:`Required`})]}),(0,R.jsxs)(B,{variant:o?`secondary`:`ghost`,size:`sm`,onClick:()=>s(e=>!e),className:`h-6 gap-1 px-2 text-[11px]`,title:o?`Exit edit mode`:`Edit label / description / required`,children:[(0,R.jsx)(ln,{className:`h-3 w-3`}),o?`Done`:`Edit`]})]}),o?(0,R.jsxs)(`div`,{className:`space-y-3 pt-1`,children:[(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(W,{htmlFor:`fd-label`,className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Label`}),(0,R.jsx)(V,{id:`fd-label`,value:f,onChange:e=>p(e.target.value),className:`h-8 text-sm`})]}),(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(W,{htmlFor:`fd-desc`,className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:`Description`}),(0,R.jsx)(`textarea`,{id:`fd-desc`,value:m,onChange:e=>h(e.target.value),rows:3,placeholder:`Help text shown under the label in forms.`,className:`block w-full resize-y rounded-md border border-input bg-background px-2.5 py-1.5 text-xs ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1`})]}),(0,R.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-xs`,children:[(0,R.jsx)(qf,{checked:g,onCheckedChange:e=>_(e===!0)}),(0,R.jsx)(`span`,{children:`Required`}),(0,R.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Forms reject blank values for required fields.`})]})]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(ac,{className:`text-base font-medium`,children:e.label}),e.description?(0,R.jsx)(oc,{className:`text-xs`,children:e.description}):(0,R.jsx)(oc,{className:`sr-only`,children:`Field details`})]})]}),(0,R.jsx)(`div`,{className:`border-t pt-4`,children:(0,R.jsx)(`dl`,{className:`space-y-2.5`,children:ee.length===0?(0,R.jsxs)(`p`,{className:`text-xs italic text-muted-foreground`,children:[`No additional configuration. This is a plain `,e.type,` field.`]}):ee.map(([e,t])=>(0,R.jsxs)(`div`,{className:`grid grid-cols-[120px_1fr] items-start gap-2 text-xs`,children:[(0,R.jsx)(`dt`,{className:`font-medium text-muted-foreground`,children:e}),(0,R.jsx)(`dd`,{className:`min-w-0 break-words font-mono`,children:e===`options`&&Array.isArray(t)?(0,R.jsx)(`ul`,{className:`space-y-0.5`,children:t.map((e,t)=>(0,R.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 text-[10px]`,children:typeof e==`string`?e:e.value}),typeof e!=`string`&&e.label&&(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:e.label})]},t))}):(0,R.jsx)(`pre`,{className:`whitespace-pre-wrap text-[11px]`,children:Jf(t)})})]},e))})}),o&&y&&(0,R.jsxs)(`div`,{className:`mt-4 rounded-md border border-amber-200 bg-amber-50 p-2.5 text-[11px] dark:border-amber-900 dark:bg-amber-950/30`,children:[(0,R.jsx)(`p`,{className:`font-medium text-amber-900 dark:text-amber-200`,children:`Unsaved changes`}),(0,R.jsx)(`p`,{className:`mt-0.5 text-amber-800/80 dark:text-amber-300/80`,children:u==null?(0,R.jsxs)(R.Fragment,{children:[`Click `,(0,R.jsx)(`span`,{className:`font-medium`,children:`Copy snippet`}),` then paste over the existing`,(0,R.jsx)(`code`,{className:`mx-0.5 rounded bg-amber-100/60 px-1 dark:bg-amber-900/30`,children:e.name}),`definition in the `,(0,R.jsx)(`code`,{className:`rounded bg-amber-100/60 px-1 dark:bg-amber-900/30`,children:`.object.ts`}),` file.`]}):(0,R.jsxs)(R.Fragment,{children:[`Click `,(0,R.jsx)(`span`,{className:`font-medium`,children:`Save`}),` to write changes to the`,(0,R.jsx)(`code`,{className:`mx-0.5 rounded bg-amber-100/60 px-1 dark:bg-amber-900/30`,children:`.object.ts`}),`source file. HMR will reload Studio in < 1 s.`]})})]}),(0,R.jsxs)(`div`,{className:`mt-6 flex gap-2 border-t pt-4`,children:[(0,R.jsxs)(B,{variant:`outline`,size:`sm`,onClick:b,className:`flex-1 gap-1.5`,children:[(0,R.jsx)(Gt,{className:`h-3.5 w-3.5`}),`Open in VS Code`]}),(0,R.jsxs)(B,{variant:y&&!S?`default`:`outline`,size:`sm`,onClick:x,className:`flex-1 gap-1.5`,children:[i?(0,R.jsx)(_t,{className:`h-3.5 w-3.5 text-green-600`}):(0,R.jsx)(mt,{className:`h-3.5 w-3.5`}),i?`Copied`:y?`Copy edited snippet`:`Copy snippet`]}),u!=null&&(0,R.jsxs)(B,{variant:`default`,size:`sm`,onClick:C,disabled:!S||c,className:`flex-1 gap-1.5`,title:y?`Write changes to the .object.ts file`:`No edits to save`,children:[c?(0,R.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-r-transparent`}):(0,R.jsx)(qe,{className:`h-3.5 w-3.5`}),c?`Saving…`:`Save`]})]}),o&&y&&u==null&&(0,R.jsx)(`p`,{className:`mt-2 text-[10px] text-muted-foreground`,children:`Save unavailable — host runtime doesn't expose the dev write API. Use Copy snippet instead.`}),(0,R.jsxs)(`p`,{className:`mt-4 text-[10px] text-muted-foreground`,children:[`Field definitions live in the object's `,(0,R.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5`,children:`.object.ts`}),` source. Edit there and HMR will reload Studio in < 1 s.`]})]})})}var Zf=[{type:`text`,label:`Single-line text`,icon:Zt,description:`Short string up to 255 chars`,extraProps:()=>[`type: 'text'`,`maxLength: 255`]},{type:`longtext`,label:`Long text`,icon:yn,description:`Multi-paragraph text, no length cap`,extraProps:()=>[`type: 'longtext'`]},{type:`number`,label:`Number`,icon:Ye,description:`Integer or decimal`,extraProps:()=>[`type: 'number'`]},{type:`currency`,label:`Currency`,icon:jn,description:`Monetary amount (locale-aware)`,extraProps:()=>[`type: 'currency'`]},{type:`percent`,label:`Percent`,icon:Rt,description:`0–100 with % display`,extraProps:()=>[`type: 'percent'`]},{type:`boolean`,label:`Boolean`,icon:Nt,description:`true / false toggle`,extraProps:()=>[`type: 'boolean'`,`defaultValue: false`]},{type:`select`,label:`Single-select`,icon:it,description:`Pick one from a fixed option list`,extraProps:()=>[`type: 'select'`,`options: [{ value: 'option_a', label: 'Option A' }, { value: 'option_b', label: 'Option B' }]`]},{type:`multiselect`,label:`Multi-select`,icon:it,description:`Pick many from a fixed option list`,extraProps:()=>[`type: 'multiselect'`,`options: [{ value: 'tag_a', label: 'Tag A' }, { value: 'tag_b', label: 'Tag B' }]`]},{type:`lookup`,label:`Lookup / Reference`,icon:Ve,description:`Link to another object`,extraProps:()=>[`type: 'lookup'`,`reference: 'TARGET_OBJECT_NAME'`]},{type:`formula`,label:`Formula`,icon:Je,description:`Computed value (CEL expression)`,extraProps:()=>[`type: 'formula'`,`formula: '// CEL expression'`]},{type:`date`,label:`Date`,icon:_n,description:`Day, no time component`,extraProps:()=>[`type: 'date'`]},{type:`datetime`,label:`Date & time`,icon:_n,description:`Instant with timezone`,extraProps:()=>[`type: 'datetime'`]},{type:`time`,label:`Time`,icon:Ie,description:`Clock time, no date`,extraProps:()=>[`type: 'time'`]},{type:`email`,label:`Email`,icon:sn,description:`Validated email address`,extraProps:()=>[`type: 'email'`]},{type:`phone`,label:`Phone`,icon:Cn,description:`Phone number (free-form)`,extraProps:()=>[`type: 'phone'`]},{type:`url`,label:`URL`,icon:Ve,description:`Validated http(s) URL`,extraProps:()=>[`type: 'url'`]},{type:`address`,label:`Address`,icon:ot,description:`Structured postal address`,extraProps:()=>[`type: 'address'`]},{type:`json`,label:`JSON`,icon:Ct,description:`Arbitrary JSON blob`,extraProps:()=>[`type: 'json'`]}];function Qf(e,t,n){return` ${t}: {\n${[`name: '${t}'`,`label: '${n}'`,...e.extraProps(t,n)].map(e=>` ${e}`).join(`,
|
|
10
|
-
`)},\n },`}function $f(e,t,n){return`{ ${[`name: '${t}'`,`label: '${n}'`,...e.extraProps(t,n)].join(`, `)} }`}function ep(e){return e.trim().replace(/([a-z])([A-Z])/g,`$1_$2`).replace(/[^a-zA-Z0-9]+/g,`_`).replace(/^_+|_+$/g,``).toLowerCase()}function tp({open:e,onOpenChange:t,objectName:n,packageId:r}){let[i,a]=(0,F.useState)(`text`),[o,s]=(0,F.useState)(`New field`),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(null),m=(0,F.useMemo)(()=>ep(o)||`new_field`,[o]),h=Zf.find(e=>e.type===i)||Zf[0],g=(0,F.useMemo)(()=>Qf(h,m,o||`New field`),[h,m,o]),_=(0,F.useMemo)(()=>$f(h,m,o||`New field`),[h,m,o]);(0,F.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=r?`/_studio/api/metadata/layout?package=${encodeURIComponent(r)}`:`/_studio/api/metadata/layout`,n=await fetch(e);if(!n.ok){t||p(null);return}let i=await n.json().catch(()=>null);t||p(i?.srcRoot??null)}catch{t||p(null)}})(),()=>{t=!0}},[e,r]);let v=(0,F.useMemo)(()=>f?`${f}/objects/${n}.object.ts`:null,[f,n]),y=(0,F.useCallback)(async()=>{try{await navigator.clipboard.writeText(g),l(!0),setTimeout(()=>l(!1),1500),U({title:`Copied ${m} snippet`})}catch{U({title:`Clipboard unavailable`,variant:`destructive`})}},[g,m]),b=(0,F.useCallback)(async()=>{if(v){d(!0);try{let e=await fetch(`/_studio/api/metadata/field-add`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:v,fieldName:m,initializer:_})}),r=await e.json().catch(()=>({}));if(!e.ok||!r?.ok){e.status===409?U({title:`Field already exists`,description:`\`${m}\` is already defined on ${n}.`,variant:`destructive`}):e.status===404?U({title:`Object source not found`,description:`Expected ${v} — open it in your editor and paste manually.`,variant:`destructive`}):U({title:`Add failed`,description:r?.error??`HTTP ${e.status}`,variant:`destructive`});return}U({title:`Field added`,description:`${m} appended to ${n} — HMR will reload shortly.`}),t(!1)}catch(e){U({title:`Add failed`,description:e?.message??String(e),variant:`destructive`})}finally{d(!1)}}},[v,m,_,n,t]),x=(0,F.useCallback)(()=>{let e=`vscode://objectstack.vscode-objectstack/open?type=object&name=${encodeURIComponent(n)}${r?`&package=${encodeURIComponent(r)}`:``}`;window.location.href=e},[n,r]),S=!!v;return(0,R.jsx)(Hl,{open:e,onOpenChange:t,children:(0,R.jsxs)(Gl,{className:`max-w-2xl`,children:[(0,R.jsxs)(Kl,{children:[(0,R.jsxs)(Jl,{className:`flex items-center gap-2`,children:[`Add field to `,(0,R.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-sm`,children:n})]}),(0,R.jsxs)(Yl,{children:[`ObjectStack is metadata-as-code. Pick a type, copy the snippet, paste into your `,(0,R.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-[10px]`,children:`.object.ts`}),` file. HMR reloads Studio in < 1 s.`]})]}),(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:[(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`field-label`,className:`text-xs`,children:`Display label`}),(0,R.jsx)(V,{id:`field-label`,value:o,onChange:e=>s(e.target.value),placeholder:`e.g. Customer name`,className:`h-8 text-sm`})]}),(0,R.jsxs)(`div`,{className:`space-y-1.5 col-span-2`,children:[(0,R.jsxs)(W,{className:`text-xs`,children:[`Machine name `,(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`(snake_case, derived)`})]}),(0,R.jsx)(`code`,{className:`block h-8 rounded border bg-muted/30 px-2 py-1.5 font-mono text-sm`,children:m})]})]}),(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{className:`text-xs`,children:`Field type`}),(0,R.jsx)(`div`,{className:`grid max-h-56 grid-cols-2 gap-1.5 overflow-y-auto rounded border p-2 sm:grid-cols-3`,children:Zf.map(e=>{let t=e.icon;return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>a(e.type),className:`flex flex-col items-start gap-0.5 rounded border px-2 py-1.5 text-left text-xs transition ${i===e.type?`border-primary bg-primary/5 ring-1 ring-primary/30`:`border-transparent hover:bg-accent`}`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium`,children:[(0,R.jsx)(t,{className:`h-3 w-3`}),e.label]}),(0,R.jsx)(`span`,{className:`text-[10px] leading-tight text-muted-foreground`,children:e.description})]},e.type)})})]}),(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(W,{className:`text-xs`,children:`Snippet preview`}),(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[10px]`,children:h.type})]}),(0,R.jsx)(`pre`,{className:`max-h-40 overflow-auto rounded border bg-muted/20 p-2.5 font-mono text-[11px] leading-relaxed`,children:g})]})]}),(0,R.jsxs)(ql,{className:`gap-2 sm:gap-2`,children:[(0,R.jsxs)(B,{variant:`ghost`,size:`sm`,onClick:x,className:`gap-1.5`,children:[(0,R.jsx)(Gt,{className:`h-3.5 w-3.5`}),`Open in VS Code`]}),(0,R.jsxs)(B,{variant:`outline`,size:`sm`,onClick:y,className:`gap-1.5`,children:[c?(0,R.jsx)(_t,{className:`h-3.5 w-3.5`}):(0,R.jsx)(mt,{className:`h-3.5 w-3.5`}),c?`Copied`:`Copy snippet`]}),(0,R.jsxs)(B,{size:`sm`,onClick:b,disabled:!S||u,className:`gap-1.5`,title:S?`Append ${m} to ${n}.object.ts`:`Dev write API unavailable`,children:[u?(0,R.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-r-transparent`}):(0,R.jsx)(jt,{className:`h-3.5 w-3.5`}),u?`Adding…`:`Add to object`]})]})]})})}var np={text:Zt,longtext:yn,textarea:yn,richtext:yn,number:Ye,currency:jn,percent:Rt,autonumber:Qe,boolean:Nt,select:it,multiselect:it,lookup:Ve,reference:Ve,formula:Je,date:_n,datetime:_n,time:Ie,email:sn,phone:Cn,url:Ve,address:ot,json:Ct,object:Ct,markdown:fn,location:Le},rp={text:`text-blue-600 bg-blue-50 border-blue-200 dark:text-blue-400 dark:bg-blue-950 dark:border-blue-800`,longtext:`text-blue-600 bg-blue-50 border-blue-200 dark:text-blue-400 dark:bg-blue-950 dark:border-blue-800`,textarea:`text-blue-600 bg-blue-50 border-blue-200 dark:text-blue-400 dark:bg-blue-950 dark:border-blue-800`,richtext:`text-blue-600 bg-blue-50 border-blue-200 dark:text-blue-400 dark:bg-blue-950 dark:border-blue-800`,number:`text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950 dark:border-amber-800`,currency:`text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950 dark:border-amber-800`,percent:`text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950 dark:border-amber-800`,autonumber:`text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950 dark:border-amber-800`,boolean:`text-emerald-600 bg-emerald-50 border-emerald-200 dark:text-emerald-400 dark:bg-emerald-950 dark:border-emerald-800`,select:`text-purple-600 bg-purple-50 border-purple-200 dark:text-purple-400 dark:bg-purple-950 dark:border-purple-800`,multiselect:`text-purple-600 bg-purple-50 border-purple-200 dark:text-purple-400 dark:bg-purple-950 dark:border-purple-800`,lookup:`text-cyan-600 bg-cyan-50 border-cyan-200 dark:text-cyan-400 dark:bg-cyan-950 dark:border-cyan-800`,reference:`text-cyan-600 bg-cyan-50 border-cyan-200 dark:text-cyan-400 dark:bg-cyan-950 dark:border-cyan-800`,formula:`text-orange-600 bg-orange-50 border-orange-200 dark:text-orange-400 dark:bg-orange-950 dark:border-orange-800`,date:`text-pink-600 bg-pink-50 border-pink-200 dark:text-pink-400 dark:bg-pink-950 dark:border-pink-800`,datetime:`text-pink-600 bg-pink-50 border-pink-200 dark:text-pink-400 dark:bg-pink-950 dark:border-pink-800`,time:`text-pink-600 bg-pink-50 border-pink-200 dark:text-pink-400 dark:bg-pink-950 dark:border-pink-800`,email:`text-indigo-600 bg-indigo-50 border-indigo-200 dark:text-indigo-400 dark:bg-indigo-950 dark:border-indigo-800`,phone:`text-indigo-600 bg-indigo-50 border-indigo-200 dark:text-indigo-400 dark:bg-indigo-950 dark:border-indigo-800`,url:`text-indigo-600 bg-indigo-50 border-indigo-200 dark:text-indigo-400 dark:bg-indigo-950 dark:border-indigo-800`,address:`text-rose-600 bg-rose-50 border-rose-200 dark:text-rose-400 dark:bg-rose-950 dark:border-rose-800`,json:`text-slate-600 bg-slate-50 border-slate-200 dark:text-slate-400 dark:bg-slate-950 dark:border-slate-800`,object:`text-slate-600 bg-slate-50 border-slate-200 dark:text-slate-400 dark:bg-slate-950 dark:border-slate-800`,markdown:`text-slate-600 bg-slate-50 border-slate-200 dark:text-slate-400 dark:bg-slate-950 dark:border-slate-800`,location:`text-rose-600 bg-rose-50 border-rose-200 dark:text-rose-400 dark:bg-rose-950 dark:border-rose-800`},ip={text:`Short string up to 255 characters.`,longtext:`Multi-paragraph text, no length cap.`,textarea:`Multi-line plain text.`,richtext:`Rich-text HTML body.`,number:`Integer or decimal value.`,currency:`Monetary amount (locale-aware display).`,percent:`Percentage 0–100, rendered with % suffix.`,autonumber:`Auto-incrementing sequential number.`,boolean:`True / false toggle.`,select:`Pick one value from a fixed option list.`,multiselect:`Pick many values from a fixed option list.`,lookup:`Reference to a record in another object.`,reference:`Reference to a record in another object.`,formula:`Computed value from a CEL expression.`,date:`Calendar day, no time component.`,datetime:`Instant in time with timezone.`,time:`Clock time, no date component.`,email:`Validated email address.`,phone:`Phone number, free-form.`,url:`Validated http(s) URL.`,address:`Structured postal address.`,json:`Arbitrary JSON blob (free shape).`,object:`Embedded JSON object.`,markdown:`Markdown-formatted body text.`,location:`Latitude / longitude pair.`};function ap({text:e}){let[t,n]=(0,F.useState)(!1);return(0,R.jsx)(sc,{children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:t=>{t.stopPropagation(),navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)},children:t?(0,R.jsx)(_t,{className:`h-3 w-3 text-emerald-500`}):(0,R.jsx)(mt,{className:`h-3 w-3`})})}),(0,R.jsx)(uc,{children:`Copy field name`})]})})}function op({objectApiName:e}){let t=L(),n=be({strict:!1}),r=Bf(n.projectId)??t,[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!0),[c,l]=(0,F.useState)(``),[d,f]=(0,F.useState)(null),[p,h]=(0,F.useState)(!1),[_,v]=(0,F.useState)(null),[y,x]=(0,F.useState)(!1),[C,w]=(0,F.useState)(null),T=n?.package,E=u(S(b,{activationConstraint:{distance:5}}),S(g,{coordinateGetter:ie}));if((0,F.useEffect)(()=>{let e=!1;return(async()=>{try{let t=T?`/_studio/api/metadata/layout?package=${encodeURIComponent(T)}`:`/_studio/api/metadata/layout`,n=await fetch(t);if(!n.ok){e||w(null);return}let r=await n.json().catch(()=>null);e||w(r?.srcRoot??null)}catch{e||w(null)}})(),()=>{e=!0}},[T]),(0,F.useEffect)(()=>{let t=!0;s(!0);async function n(){try{let n=await r.meta.getItem(`object`,e);t&&n&&(a(n.item||n),v(null))}catch(e){console.error(`Failed to load schema:`,e)}finally{t&&s(!1)}}return n(),()=>{t=!1}},[r,e]),o)return(0,R.jsxs)(`div`,{className:`space-y-3 p-4`,children:[(0,R.jsx)(H,{className:`h-8 w-full`}),(0,R.jsx)(H,{className:`h-10 w-full`}),(0,R.jsx)(H,{className:`h-10 w-full`}),(0,R.jsx)(H,{className:`h-10 w-full`})]});if(!i)return(0,R.jsxs)(`div`,{className:`flex flex-1 items-center justify-center py-12 text-center text-sm text-muted-foreground`,children:[`Object definition not found: `,(0,R.jsx)(`code`,{className:`ml-1 font-mono`,children:e})]});let D=i.fields||{},O=Object.fromEntries(Object.entries(D).map(([e,t])=>[t.name||e,{...t,name:t.name||e,label:t.label||e,type:t.type||`text`,required:t.required||!1,multiple:t.multiple||!1,reference:t.reference,defaultValue:t.defaultValue,description:t.description,options:t.options,formula:t.formula,maxLength:t.maxLength,sortOrder:t.sortOrder}])),re=Object.keys(O),k=(_??re).filter(e=>O[e]);for(let e of re)k.includes(e)||k.push(e);let A=k.map(e=>O[e]),j=i.name||e,ae=c?A.filter(e=>e.name.toLowerCase().includes(c.toLowerCase())||e.label.toLowerCase().includes(c.toLowerCase())||e.type.toLowerCase().includes(c.toLowerCase())):A,se=!!C&&!c;return(0,R.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3 border-b bg-muted/20 px-4 py-2`,children:[(0,R.jsxs)(`div`,{className:`relative flex-1 max-w-md`,children:[(0,R.jsx)(Xe,{className:`absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,R.jsx)(V,{placeholder:`Filter fields by name, label, or type…`,value:c,onChange:e=>l(e.target.value),className:`h-8 pl-9 text-sm`})]}),(0,R.jsx)(`span`,{className:`ml-auto whitespace-nowrap text-[11px] tabular-nums text-muted-foreground`,children:c?`${ae.length} of ${A.length}`:`${A.length} fields`}),(0,R.jsxs)(B,{size:`sm`,variant:`default`,onClick:()=>h(!0),className:`h-7 gap-1.5 px-2.5 text-xs`,children:[(0,R.jsx)(en,{className:`h-3.5 w-3.5`}),`Add field`]})]}),(0,R.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,R.jsxs)(Vf,{children:[(0,R.jsx)(Hf,{children:(0,R.jsxs)(Gf,{className:`sticky top-0 z-10 bg-background hover:bg-transparent`,children:[(0,R.jsx)(J,{className:`w-7`}),(0,R.jsx)(J,{className:`w-8`}),(0,R.jsx)(J,{className:`font-medium`,children:`Field Name`}),(0,R.jsx)(J,{className:`font-medium`,children:`Label`}),(0,R.jsx)(J,{className:`font-medium`,children:`Type`}),(0,R.jsx)(J,{className:`font-medium`,children:`Required`}),(0,R.jsx)(J,{className:`font-medium`,children:`Details`}),(0,R.jsx)(J,{className:`w-8`})]})}),(0,R.jsx)(te,{sensors:E,collisionDetection:ne,onDragEnd:async e=>{let{active:t,over:n}=e;if(!n||t.id===n.id)return;let r=k.slice(),i=r.indexOf(String(t.id)),a=r.indexOf(String(n.id));if(i<0||a<0)return;let o=ee(r,i,a);v(o),x(!0);try{let e=`${C}/objects/${j}.object.ts`,t=await fetch(`/_studio/api/metadata/field-reorder`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:e,order:o})}),n=await t.json().catch(()=>({}));if(!t.ok||!n?.ok){U({title:`Reorder failed`,description:n?.error??`HTTP ${t.status}`,variant:`destructive`}),v(r);return}U({title:`Field order saved`,description:`HMR will reload shortly.`})}catch(e){U({title:`Reorder failed`,description:e?.message??String(e),variant:`destructive`}),v(r)}finally{x(!1)}},children:(0,R.jsx)(oe,{items:ae.map(e=>e.name),strategy:m,children:(0,R.jsxs)(Uf,{children:[ae.map((e,t)=>(0,R.jsx)(sp,{field:e,idx:t,onSelect:f,dragEnabled:se&&!y},e.name)),ae.length===0&&(0,R.jsx)(Gf,{children:(0,R.jsx)(Y,{colSpan:8,className:`h-24 text-center text-muted-foreground text-sm`,children:c?`No fields matching filter`:`No fields defined`})})]})})})]})}),(0,R.jsx)(Xf,{field:d,objectName:j,packageId:T,onClose:()=>f(null)}),(0,R.jsx)(tp,{open:p,onOpenChange:h,objectName:j,packageId:T})]})}function sp({field:e,idx:t,onSelect:n,dragEnabled:r}){let{attributes:i,listeners:a,setNodeRef:o,transform:s,transition:c,isDragging:l}=le({id:e.name,disabled:!r}),u=np[e.type]||rt,d=rp[e.type]||`text-gray-600 bg-gray-50 border-gray-200 dark:text-gray-400 dark:bg-gray-950 dark:border-gray-800`;return(0,R.jsxs)(Gf,{ref:o,style:{transform:ue.Transform.toString(s),transition:c,opacity:l?.6:1},className:`group cursor-pointer ${l?`relative z-10 bg-accent shadow-md`:``}`,onClick:()=>n(e),children:[(0,R.jsx)(Y,{className:`w-7 px-0 py-2 text-center align-middle`,children:(0,R.jsx)(`button`,{type:`button`,onClick:e=>e.stopPropagation(),...i,...a,"aria-label":r?`Drag to reorder ${e.name}`:`Drag disabled — clear filter or enable dev mode`,className:`inline-flex h-5 w-5 items-center justify-center rounded transition ${r?`cursor-grab text-muted-foreground/50 hover:bg-muted hover:text-foreground active:cursor-grabbing`:`cursor-not-allowed text-muted-foreground/20`}`,disabled:!r,children:(0,R.jsx)(Et,{className:`h-3.5 w-3.5`})})}),(0,R.jsx)(Y,{className:`py-2 text-center text-xs text-muted-foreground tabular-nums`,children:t+1}),(0,R.jsx)(Y,{className:`py-2`,children:(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`code`,{className:`font-mono text-sm font-medium`,children:e.name}),(0,R.jsx)(ap,{text:e.name}),e.required&&(0,R.jsx)(Me,{className:`h-3 w-3 text-amber-500`})]})}),(0,R.jsx)(Y,{className:`py-2 text-sm`,children:e.label}),(0,R.jsx)(Y,{className:`py-2`,children:(0,R.jsx)(sc,{delayDuration:250,children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsxs)(G,{variant:`outline`,className:`gap-1 text-xs cursor-help ${d}`,children:[(0,R.jsx)(u,{className:`h-3 w-3`}),e.type,e.multiple&&`[]`]})}),(0,R.jsx)(uc,{side:`top`,className:`max-w-xs`,children:(0,R.jsxs)(`p`,{className:`text-xs`,children:[(0,R.jsxs)(`span`,{className:`font-mono font-medium`,children:[e.type,e.multiple?`[]`:``]}),` — `,ip[e.type]||`Custom field type.`]})})]})})}),(0,R.jsx)(Y,{className:`py-2`,children:e.required?(0,R.jsx)(G,{variant:`default`,className:`text-[10px] bg-amber-100 text-amber-700 border-amber-200 hover:bg-amber-100 dark:bg-amber-950 dark:text-amber-400 dark:border-amber-800`,children:`Required`}):(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground/40`,children:`—`})}),(0,R.jsx)(Y,{className:`py-2`,children:(0,R.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.reference&&(0,R.jsxs)(G,{variant:`outline`,className:`text-[10px] font-mono gap-1`,children:[(0,R.jsx)(Ve,{className:`h-2.5 w-2.5`}),` → `,e.reference]}),e.defaultValue!==void 0&&(0,R.jsxs)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:[`default: `,JSON.stringify(e.defaultValue)]}),e.maxLength&&(0,R.jsxs)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:[`max: `,e.maxLength]}),e.options&&(0,R.jsxs)(G,{variant:`outline`,className:`text-[10px]`,children:[e.options.length,` options`]}),e.formula&&(0,R.jsxs)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:[`ƒ `,String(e.formula).slice(0,30)]})]})}),(0,R.jsx)(Y,{className:`py-2 pr-3 text-right`,children:(0,R.jsx)(je,{className:`h-4 w-4 text-muted-foreground/40 transition group-hover:translate-x-0.5 group-hover:text-foreground`})})]})}var cp={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`,DELETE:`text-red-600 bg-red-50 border-red-200 dark:text-red-400 dark:bg-red-950/50`},lp={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`};function up({objectApiName:e}){let t=L(),n=[{method:`GET`,path:`/api/v1/data/${e}`,desc:`List records`},{method:`POST`,path:`/api/v1/data/${e}`,desc:`Create record`,bodyTemplate:{name:`example`}},{method:`GET`,path:`/api/v1/data/${e}/:id`,desc:`Get by ID`},{method:`PATCH`,path:`/api/v1/data/${e}/:id`,desc:`Update record`,bodyTemplate:{name:`updated`}},{method:`DELETE`,path:`/api/v1/data/${e}/:id`,desc:`Delete record`},{method:`GET`,path:`/api/v1/meta/object/${e}`,desc:`Object schema`}],[r,i]=(0,F.useState)(n[0]),[a,o]=(0,F.useState)(``),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(!1),[d,f]=(0,F.useState)(null),[p,m]=(0,F.useState)([]),[h,g]=(0,F.useState)(null),[_,v]=(0,F.useState)(!1),y=a||r.path,b=(0,F.useCallback)(e=>{i(e),o(e.path),c(e.bodyTemplate?JSON.stringify(e.bodyTemplate,null,2):``),f(null)},[]),x=(0,F.useCallback)(async()=>{if(l)return;let e=`${t?.baseUrl??``}${y}`;u(!0);let n=performance.now();try{let t={method:r.method,headers:{"Content-Type":`application/json`}};[`POST`,`PATCH`].includes(r.method)&&s.trim()&&(t.body=s);let i=await fetch(e,t),a=Math.round(performance.now()-n),o;if((i.headers.get(`content-type`)??``).includes(`json`)){let e=await i.json();o=JSON.stringify(e,null,2)}else o=await i.text();f({status:i.status,body:o,duration:a}),m(e=>[{id:Date.now(),method:r.method,url:y,body:s||void 0,status:i.status,duration:a,response:o,timestamp:new Date},...e].slice(0,20))}catch(e){let t=Math.round(performance.now()-n);f({status:0,body:`Network Error: ${e.message}`,duration:t})}finally{u(!1)}},[t,y,r,s,l]),S=(0,F.useCallback)(()=>{d?.body&&(navigator.clipboard.writeText(d.body),v(!0),setTimeout(()=>v(!1),1500))},[d]),C=e=>lp[String(e)[0]]??`text-muted-foreground`;return(0,R.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-[280px_1fr] gap-4 h-full`,children:[(0,R.jsxs)(`div`,{className:`space-y-3 lg:border-r lg:pr-4`,children:[(0,R.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:`Endpoints`}),(0,R.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,R.jsxs)(`button`,{onClick:()=>b(e),className:`w-full text-left flex items-center gap-2 px-3 py-2 rounded-md text-sm transition-colors ${e===r?`bg-accent text-accent-foreground`:`hover:bg-muted/50 text-muted-foreground hover:text-foreground`}`,children:[(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[10px] shrink-0 ${cp[e.method]}`,children:e.method}),(0,R.jsx)(`span`,{className:`truncate text-xs`,children:e.desc})]},t))}),(0,R.jsxs)(`div`,{className:`pt-3 border-t`,children:[(0,R.jsx)(`h4`,{className:`text-xs font-medium text-muted-foreground mb-2`,children:`Query Parameters`}),(0,R.jsxs)(`div`,{className:`space-y-1 text-xs text-muted-foreground`,children:[(0,R.jsxs)(`p`,{children:[(0,R.jsx)(`code`,{className:`text-foreground`,children:`?$top=10`}),` — limit`]}),(0,R.jsxs)(`p`,{children:[(0,R.jsx)(`code`,{className:`text-foreground`,children:`?$skip=20`}),` — offset`]}),(0,R.jsxs)(`p`,{children:[(0,R.jsx)(`code`,{className:`text-foreground`,children:`?$sort=name`}),` — sort`]}),(0,R.jsxs)(`p`,{children:[(0,R.jsx)(`code`,{className:`text-foreground`,children:`?$select=name,email`}),` — fields`]}),(0,R.jsxs)(`p`,{children:[(0,R.jsx)(`code`,{className:`text-foreground`,children:`?$count=true`}),` — total count`]})]})]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col gap-3 min-w-0`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-xs shrink-0 ${cp[r.method]}`,children:r.method}),(0,R.jsx)(`input`,{type:`text`,value:a||y,onChange:e=>o(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:r.path}),(0,R.jsxs)(`button`,{onClick:x,disabled:l,className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-4 py-1.5 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:[l?(0,R.jsx)(tt,{className:`h-3.5 w-3.5 animate-spin`}):(0,R.jsx)(Mt,{className:`h-3.5 w-3.5`}),`Send`]})]}),[`POST`,`PATCH`].includes(r.method)&&(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Request Body (JSON)`}),(0,R.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),rows:4,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:`{ "name": "value" }`})]}),d&&(0,R.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col rounded-lg border overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-muted/30 border-b`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,R.jsx)(`span`,{className:`font-mono font-semibold ${C(d.status)}`,children:d.status||`ERR`}),(0,R.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1`,children:[(0,R.jsx)(Ie,{className:`h-3 w-3`}),d.duration,`ms`]})]}),(0,R.jsxs)(`button`,{onClick:S,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[_?(0,R.jsx)(_t,{className:`h-3 w-3`}):(0,R.jsx)(mt,{className:`h-3 w-3`}),_?`Copied`:`Copy`]})]}),(0,R.jsx)(`pre`,{className:`flex-1 overflow-auto p-3 text-xs font-mono bg-muted/10 whitespace-pre-wrap break-all`,children:d.body})]}),!d&&!l&&(0,R.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-muted-foreground text-sm`,children:(0,R.jsxs)(`div`,{className:`text-center space-y-1`,children:[(0,R.jsx)(wt,{className:`h-8 w-8 mx-auto opacity-30`}),(0,R.jsxs)(`p`,{children:[`Select an endpoint and click `,(0,R.jsx)(`strong`,{children:`Send`}),` to test`]})]})}),p.length>0&&(0,R.jsxs)(`div`,{className:`border-t pt-3 space-y-1`,children:[(0,R.jsx)(`h4`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:`History`}),(0,R.jsx)(`div`,{className:`space-y-1 max-h-48 overflow-auto`,children:p.map(e=>(0,R.jsxs)(`div`,{className:`rounded border`,children:[(0,R.jsxs)(`button`,{onClick:()=>g(h===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:[h===e.id?(0,R.jsx)(We,{className:`h-3 w-3 shrink-0`}):(0,R.jsx)(je,{className:`h-3 w-3 shrink-0`}),(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[9px] shrink-0 ${cp[e.method]}`,children:e.method}),(0,R.jsx)(`span`,{className:`font-mono truncate`,children:e.url}),(0,R.jsx)(`span`,{className:`ml-auto shrink-0 font-mono ${C(e.status)}`,children:e.status}),(0,R.jsxs)(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.duration,`ms`]})]}),h===e.id&&(0,R.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))})]})]})]})}var dp=null;function fp(e){if(typeof e!=`string`)return e;let t=e.split(`,`).map(e=>e.trim()).filter(Boolean);if(t.length!==0)return t.map(e=>{let[t,n]=e.split(/\s+/);return t?(n||``).toLowerCase()===`desc`?`-${t}`:t:e})}function pp(e){let t=Object.create(e),n=e=>{if(!e||typeof e!=`object`)return e;let t={...e};return t.$orderby!==void 0&&(t.$orderby=fp(t.$orderby)),t};for(let r of[`find`,`findOne`,`count`]){let i=e[r];typeof i==`function`&&(t[r]=function(t,...a){let o=a[0];return r===`findOne`?a[1]=n(a[1]):a[0]=n(o),i.apply(e,[t,...a])})}return t}function mp(){return(0,F.useMemo)(()=>dp||(dp=pp(Dr({baseUrl:Sl()})),dp),[])}function hp(e,t){if(!e)return`Record`;let n=t?.fields||{};for(let t of[`name`,`title`,`subject`,`label`,`company_name`,`full_name`,`first_name`]){if(e[t])return String(e[t]);let r=Object.keys(n).find(e=>n[e]?.name===t);if(r&&e[r])return String(e[r])}let r=new Set([`id`,`created_at`,`updated_at`,`created_by`,`updated_by`]);for(let t of Object.keys(e)){if(r.has(t))continue;let n=e[t];if(typeof n==`string`&&n.trim())return n}return String(e.id??e._id??`Record`)}function gp({objectApiName:e}){let t=mp(),n=L(),r=Bf(be({strict:!1}).projectId)??n,[i,a]=(0,F.useState)(void 0),[o,s]=(0,F.useState)(null),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)(0),m=(0,F.useRef)(null),h=`objectstack.hiddenFields.${e}`,[g,_]=(0,F.useState)(()=>{if(typeof window>`u`)return new Set;try{let e=window.localStorage.getItem(h);return e?new Set(JSON.parse(e)):new Set}catch{return new Set}});(0,F.useEffect)(()=>{if(!(typeof window>`u`))try{window.localStorage.setItem(h,JSON.stringify([...g]))}catch{}},[g,h]);let v=(0,F.useCallback)(e=>{_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),y=(0,F.useCallback)(()=>_(new Set),[]),b=(0,F.useMemo)(()=>i?.filter(e=>!g.has(e)),[i,g]);(0,F.useEffect)(()=>{let t=!0;return(async()=>{try{let n=await r.meta.getItem(`object`,e),i=n?.item||n?.spec||n,o=i?.fields||{},c=Object.keys(o).map(e=>o[e]?.name||e).filter(e=>e&&e!==`formatted_summary`);t&&(a(c),s(i))}catch{t&&a(void 0)}})(),()=>{t=!1}},[r,e]);let x=(0,F.useCallback)(()=>{m.current&&window.clearTimeout(m.current),m.current=window.setTimeout(()=>{p(e=>e+1),m.current=null},100)},[]),S=(0,F.useCallback)(e=>{l(e)},[]),C=(0,F.useCallback)(()=>{d(!0)},[]),w=(0,F.useCallback)(async n=>{try{let r=t,i=r?.create||r?.createRecord;if(!i){U({title:`Adapter has no create method`,variant:`destructive`});return}await i.call(r,e,n),U({title:`Created ${e} record`}),d(!1),x()}catch(e){U({title:`Create failed`,description:e?.message??String(e),variant:`destructive`})}},[t,e,x]),T=c?.id??c?._id??``,ee=(0,F.useMemo)(()=>c?hp(c,o):``,[c,o]);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,R.jsxs)(uu,{children:[(0,R.jsx)(du,{asChild:!0,children:(0,R.jsxs)(B,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5 text-xs`,children:[g.size>0?(0,R.jsx)(Bt,{className:`h-3.5 w-3.5`}):(0,R.jsx)(On,{className:`h-3.5 w-3.5`}),`Hide fields`,g.size>0&&(0,R.jsx)(`span`,{className:`ml-1 rounded bg-muted px-1 text-[10px] tabular-nums`,children:g.size})]})}),(0,R.jsxs)(mu,{align:`start`,className:`max-h-[60vh] w-64 overflow-y-auto`,children:[(0,R.jsxs)(vu,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`span`,{children:`Field visibility`}),g.size>0&&(0,R.jsx)(`button`,{type:`button`,onClick:y,className:`text-xs font-normal text-muted-foreground hover:text-foreground`,children:`Show all`})]}),(0,R.jsx)(yu,{}),(i??[]).length===0?(0,R.jsx)(hu,{disabled:!0,className:`text-xs text-muted-foreground`,children:`Loading schema…`}):(i??[]).map(e=>(0,R.jsx)(gu,{checked:!g.has(e),onCheckedChange:()=>v(e),onSelect:e=>e.preventDefault(),children:(0,R.jsx)(`span`,{className:`truncate font-mono text-xs`,children:e})},e))]})]})}),(0,R.jsxs)(B,{size:`sm`,onClick:C,className:`h-7 gap-1.5 text-xs`,children:[(0,R.jsx)(en,{className:`h-3.5 w-3.5`}),`New record`]})]}),(0,R.jsx)(Jr,{schema:{type:`object-grid`,objectName:e,showSearch:!0,showFilters:!0,showPagination:!0,resizable:!0,...b?{columns:b}:{}},dataSource:t,className:`h-full`,onRowClick:S,onAddRecord:C},f),c&&(0,R.jsx)(Or,{open:!!c,onClose:()=>l(null),title:ee,record:c,objectName:e,recordId:T,dataSource:t,objectSchema:o,onFieldSave:()=>x(),onDelete:()=>{x(),l(null)},fullPageHref:Fr(e,T)??void 0}),(0,R.jsx)(Qs,{open:u,onOpenChange:d,children:(0,R.jsxs)(nc,{className:`w-[480px] overflow-y-auto sm:max-w-[480px]`,children:[(0,R.jsxs)(rc,{children:[(0,R.jsxs)(ac,{children:[`New `,e,` record`]}),(0,R.jsx)(oc,{children:`Fields marked required must be filled. Submit to persist via the same data source the grid uses.`})]}),(0,R.jsx)(`div`,{className:`mt-4`,children:(0,R.jsx)(Yr,{schema:{type:`object-form`,objectName:e,mode:`create`,submitLabel:`Create record`,onSubmit:w},dataSource:t})})]})})]})}function _p({objectApiName:e,mode:t=`data`}){let n=t===`design`?`design`:t===`code`?`code`:`data`;return(0,R.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:(0,R.jsxs)(`div`,{className:`flex-1 overflow-auto`,children:[n===`data`&&(0,R.jsx)(gp,{objectApiName:e}),n===`design`&&(0,R.jsx)(op,{objectApiName:e}),n===`code`&&(0,R.jsx)(up,{objectApiName:e})]})})}function vp({metadataName:e,mode:t}){return(0,R.jsx)(_p,{objectApiName:e,mode:t})}var yp={manifest:mf({id:`objectstack.object-designer`,name:`Object Designer`,version:`1.0.0`,description:`Schema inspector, data table, and API reference for Object metadata.`,contributes:{metadataViewers:[{id:`object-explorer`,metadataTypes:[`object`],label:`Object Explorer`,priority:100,modes:[`data`,`design`,`code`]}],sidebarGroups:[{key:`data`,label:`Data`,icon:`database`,metadataTypes:[`object`,`hook`,`mapping`,`analyticsCube`,`data`],order:10}],metadataIcons:[{metadataType:`object`,label:`Objects`,icon:`package`},{metadataType:`hook`,label:`Hooks`,icon:`anchor`},{metadataType:`mapping`,label:`Mappings`,icon:`map`},{metadataType:`analyticsCube`,label:`Analytics Cubes`,icon:`pie-chart`},{metadataType:`data`,label:`Seed Data`,icon:`database`}]}}),activate(e){e.registerViewer(`object-explorer`,vp),e.registerMetadataIcon(`object`,Pt,`Objects`),e.registerMetadataIcon(`hook`,Vt,`Hooks`),e.registerMetadataIcon(`mapping`,Le,`Mappings`),e.registerMetadataIcon(`analyticsCube`,St,`Analytics Cubes`),e.registerMetadataIcon(`data`,In,`Seed Data`)}},X=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,className:z(`rounded-lg border bg-card text-card-foreground shadow-sm`,e),...t}));X.displayName=`Card`;var Z=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,className:z(`flex flex-col space-y-1.5 p-6`,e),...t}));Z.displayName=`CardHeader`;var Q=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`h3`,{ref:n,className:z(`text-2xl font-semibold leading-none tracking-tight`,e),...t}));Q.displayName=`CardTitle`;var bp=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`p`,{ref:n,className:z(`text-sm text-muted-foreground`,e),...t}));bp.displayName=`CardDescription`;var $=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,className:z(`p-6 pt-0`,e),...t}));$.displayName=`CardContent`;var xp=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,className:z(`flex items-center p-6 pt-0`,e),...t}));xp.displayName=`CardFooter`;var Sp={actions:Qt,dashboards:Ue,reports:yn,flows:bn,agent:ut,agents:ut,tool:dn,tools:dn,apis:wt,ragPipeline:De,ragPipelines:De,profiles:dt,sharingRules:dt},Cp={actions:`Action`,dashboards:`Dashboard`,reports:`Report`,flows:`Flow`,agent:`Agent`,agents:`Agent`,tool:`Tool`,tools:`Tool`,apis:`API`,ragPipeline:`RAG Pipeline`,ragPipelines:`RAG Pipeline`,profiles:`Profile`,sharingRules:`Sharing Rule`};function wp({text:e}){let[t,n]=(0,F.useState)(!1);return(0,R.jsx)(sc,{children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>{navigator.clipboard.writeText(e),n(!0),setTimeout(()=>n(!1),1500)},children:t?(0,R.jsx)(_t,{className:`h-3 w-3 text-emerald-500`}):(0,R.jsx)(mt,{className:`h-3 w-3`})})}),(0,R.jsx)(uc,{children:`Copy`})]})})}function Tp({data:e,depth:t=0}){let[n,r]=(0,F.useState)({});if(e==null)return(0,R.jsx)(`span`,{className:`text-muted-foreground italic`,children:`null`});if(typeof e==`boolean`)return(0,R.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono ${e?`text-emerald-600 border-emerald-300`:`text-red-500 border-red-300`}`,children:String(e)});if(typeof e==`number`)return(0,R.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 font-mono text-sm`,children:e});if(typeof e==`string`)return e.length>120?(0,R.jsxs)(`span`,{className:`text-emerald-700 dark:text-emerald-400 font-mono text-sm break-all`,children:[`"`,e.slice(0,120),`…"`]}):(0,R.jsxs)(`span`,{className:`text-emerald-700 dark:text-emerald-400 font-mono text-sm`,children:[`"`,e,`"`]});if(Array.isArray(e))return e.length===0?(0,R.jsx)(`span`,{className:`text-muted-foreground font-mono text-sm`,children:`[]`}):e.length<=5&&e.every(e=>typeof e!=`object`)?(0,R.jsxs)(`span`,{className:`font-mono text-sm`,children:[`[`,e.map((e,n)=>(0,R.jsxs)(`span`,{children:[n>0&&`, `,(0,R.jsx)(Tp,{data:e,depth:t+1})]},n)),`]`]}):(0,R.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,R.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs`,children:[`Array(`,e.length,`)`]}),(0,R.jsx)(`div`,{className:`ml-4 border-l pl-3 space-y-0.5`,children:e.map((e,n)=>(0,R.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,R.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs shrink-0 mt-0.5`,children:[`[`,n,`]`]}),(0,R.jsx)(Tp,{data:e,depth:t+1})]},n))})]});if(typeof e==`object`){let i=Object.keys(e);return i.length===0?(0,R.jsx)(`span`,{className:`text-muted-foreground font-mono text-sm`,children:`{}`}):(0,R.jsx)(`div`,{className:`space-y-0.5`,children:i.map(i=>{let a=e[i],o=typeof a==`object`&&!!a,s=n[i]??(t>1&&o);return(0,R.jsx)(`div`,{children:(0,R.jsxs)(`div`,{className:`flex items-start gap-1 group`,children:[o?(0,R.jsx)(`button`,{onClick:()=>r(e=>({...e,[i]:!s})),className:`shrink-0 mt-0.5 p-0.5 rounded hover:bg-muted`,children:s?(0,R.jsx)(je,{className:`h-3 w-3 text-muted-foreground`}):(0,R.jsx)(We,{className:`h-3 w-3 text-muted-foreground`})}):(0,R.jsx)(`span`,{className:`w-4 shrink-0`}),(0,R.jsxs)(`span`,{className:`text-blue-600 dark:text-blue-400 font-mono text-sm shrink-0`,children:[i,`:`]}),o&&s?(0,R.jsx)(`span`,{className:`text-muted-foreground font-mono text-xs`,children:Array.isArray(a)?`Array(${a.length})`:`{${Object.keys(a).length} keys}`}):(0,R.jsx)(`div`,{className:`min-w-0`,children:(0,R.jsx)(Tp,{data:a,depth:t+1})})]})},i)})})}return(0,R.jsx)(`span`,{className:`font-mono text-sm`,children:String(e)})}function Ep({metaType:e,metaName:t,packageId:n}){let r=Bf(be({strict:!1}).projectId),[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!0),[c,l]=(0,F.useState)(``);Sp[e];let u=Cp[e]||e.charAt(0).toUpperCase()+e.slice(1);if((0,F.useEffect)(()=>{if(!r)return;let i=!0;s(!0),a(null);async function o(){try{let o=await r.meta.getItem(e,t,n?{packageId:n}:void 0);i&&a(o?.item||o)}catch(n){console.error(`[MetadataInspector] Failed to load ${e}/${t}:`,n)}finally{i&&s(!1)}}return o(),()=>{i=!1}},[r,e,t,n]),o)return(0,R.jsx)(`div`,{className:`space-y-4 p-4`,children:(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{children:(0,R.jsx)(H,{className:`h-6 w-48`})}),(0,R.jsxs)($,{className:`space-y-3`,children:[(0,R.jsx)(H,{className:`h-10 w-full`}),(0,R.jsx)(H,{className:`h-10 w-full`}),(0,R.jsx)(H,{className:`h-10 w-full`})]})]})});if(!i)return(0,R.jsx)(`div`,{className:`p-4`,children:(0,R.jsx)(X,{children:(0,R.jsxs)($,{className:`py-12 text-center text-sm text-muted-foreground`,children:[(0,R.jsxs)(`p`,{className:`font-medium text-foreground`,children:[u,` not found`]}),(0,R.jsxs)(`p`,{className:`mt-1`,children:[`We couldn't load`,` `,(0,R.jsx)(`code`,{className:`font-mono text-xs`,children:t}),`. It may have been deleted or moved to another package.`]})]})})});let d=Object.keys(i).filter(e=>!e.startsWith(`_`)),f=c?d.filter(e=>e.toLowerCase().includes(c.toLowerCase())||JSON.stringify(i[e]).toLowerCase().includes(c.toLowerCase())):d;return(0,R.jsx)(`div`,{className:`space-y-4 p-4`,children:(0,R.jsxs)(X,{children:[(0,R.jsxs)(Z,{className:`pb-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(Q,{className:`text-base`,children:`Properties`}),(0,R.jsxs)(G,{variant:`secondary`,className:`text-xs`,children:[f.length,` / `,d.length,` keys`]})]}),(0,R.jsxs)(`div`,{className:`relative mt-2`,children:[(0,R.jsx)(Xe,{className:`absolute left-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,R.jsx)(V,{placeholder:`Filter properties...`,value:c,onChange:e=>l(e.target.value),className:`pl-9 h-8 text-sm`})]})]}),(0,R.jsx)($,{children:(0,R.jsx)(ll,{className:`max-h-[60vh]`,children:(0,R.jsxs)(`div`,{className:`space-y-3`,children:[f.map(e=>(0,R.jsxs)(`div`,{className:`group rounded-md border p-3 hover:bg-muted/30 transition-colors`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,R.jsx)(`span`,{className:`text-blue-600 dark:text-blue-400 font-mono text-sm font-medium`,children:e}),(0,R.jsx)(wp,{text:JSON.stringify(i[e],null,2)}),(0,R.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono ml-auto`,children:Array.isArray(i[e])?`array(${i[e].length})`:typeof i[e]})]}),(0,R.jsx)(`div`,{className:`pl-1`,children:(0,R.jsx)(Tp,{data:i[e]})})]},e)),f.length===0&&(0,R.jsx)(`p`,{className:`text-sm text-center text-muted-foreground py-8`,children:c?`No properties match filter`:`No properties`})]})})})]})})}var Dp={object:{label:`Object`,icon:In},view:{label:`View`,icon:qt},flow:{label:`Flow`,icon:bn},agent:{label:`Agent`,icon:ut},tool:{label:`Tool`,icon:dn},app:{label:`App`,icon:kn}};function Op(e,t){let n=` `.repeat(t);return e.split(`
|
|
11
|
-
`).map(e=>e.trim()?n+e:e).join(`
|
|
12
|
-
`)}function kp(e,t=0){if(e==null)return`undefined`;if(typeof e==`string`)return`'${e.replace(/'/g,`\\'`)}'`;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(Array.isArray(e)){if(e.length===0)return`[]`;let n=e.map(e=>kp(e,t+1));return n.join(`, `).length<60?`[${n.join(`, `)}]`:`[\n${n.map(e=>Op(e,t+1)).join(`,
|
|
13
|
-
`)}\n${Op(`]`,t)}`}if(typeof e==`object`){let n=Object.entries(e).filter(([e])=>!e.startsWith(`_`));if(n.length===0)return`{}`;let r=n.map(([e,n])=>`${Op(`${e}: ${kp(n,t+1)}`,t+1)}`);return r.join(`, `).length<60&&!r.some(e=>e.includes(`
|
|
14
|
-
`))?`{ ${n.map(([e,n])=>`${e}: ${kp(n,t+1)}`).join(`, `)} }`:`{\n${r.join(`,
|
|
15
|
-
`)}\n${Op(`}`,t)}`}return String(e)}function Ap(e,t){return[`import { defineStack } from '@objectstack/spec';`,``,`export default defineStack({`,` objects: {`,` ${t||e.name||`my_object`}: ${kp(e,2)},`,` },`,`});`].join(`
|
|
16
|
-
`)}function jp(e,t){return[`import { defineStack } from '@objectstack/spec';`,``,`export default defineStack({`,` views: {`,` ${t||e.name||`my_view`}: ${kp(e,2)},`,` },`,`});`].join(`
|
|
17
|
-
`)}function Mp(e,t){return[`import { defineStack } from '@objectstack/spec';`,``,`export default defineStack({`,` flows: {`,` ${t||e.name||`my_flow`}: ${kp(e,2)},`,` },`,`});`].join(`
|
|
18
|
-
`)}function Np(e,t){return[`import { defineStack } from '@objectstack/spec';`,``,`export default defineStack({`,` agents: {`,` ${t||e.name||`my_agent`}: ${kp(e,2)},`,` },`,`});`].join(`
|
|
19
|
-
`)}function Pp(e,t){return[`import { defineStack } from '@objectstack/spec';`,``,`export default defineStack({`,` apps: {`,` ${t||e.name||`my_app`}: ${kp(e,2)},`,` },`,`});`].join(`
|
|
20
|
-
`)}function Fp(e,t){return[`import { defineStack } from '@objectstack/spec';`,``,`export default defineStack({`,` tools: {`,` ${t||e.name||`my_tool`}: ${kp(e,2)},`,` },`,`});`].join(`
|
|
21
|
-
`)}var Ip={object:Ap,view:jp,flow:Mp,agent:Np,tool:Fp,app:Pp};function Lp({type:e,definition:t,name:n}){let[r,i]=(0,F.useState)(`typescript`),[a,o]=(0,F.useState)(!1),s=(0,F.useMemo)(()=>{let r=Ip[e];return r?r(t,n):`// Unknown export type`},[e,t,n]),c=(0,F.useMemo)(()=>{function e(t){if(Array.isArray(t))return t.map(e);if(t&&typeof t==`object`){let n={};for(let[r,i]of Object.entries(t))r.startsWith(`_`)||(n[r]=e(i));return n}return t}return JSON.stringify(e(t),null,2)},[t]),l=r===`typescript`?s:c,u=(0,F.useCallback)(()=>{navigator.clipboard.writeText(l),o(!0),setTimeout(()=>o(!1),1500)},[l]),d=Dp[e]?.icon??ze;return(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{className:`pb-3`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsxs)(Q,{className:`text-base flex items-center gap-2`,children:[(0,R.jsx)(ze,{className:`h-4 w-4`}),`Export as Code`]}),(0,R.jsxs)(bp,{className:`flex items-center gap-1.5`,children:[(0,R.jsxs)(G,{variant:`outline`,className:`text-[10px] gap-1`,children:[(0,R.jsx)(d,{className:`h-3 w-3`}),Dp[e]?.label??e]}),n&&(0,R.jsx)(`code`,{className:`text-xs font-mono bg-muted px-1 py-0.5 rounded`,children:n})]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(ad,{value:r,onValueChange:e=>i(e),children:(0,R.jsxs)(od,{className:`h-7`,children:[(0,R.jsx)(K,{value:`typescript`,className:`text-xs px-2 py-0.5`,children:`TypeScript`}),(0,R.jsx)(K,{value:`json`,className:`text-xs px-2 py-0.5`,children:`JSON`})]})}),(0,R.jsxs)(B,{variant:`outline`,size:`sm`,onClick:u,className:`h-7 gap-1 text-xs`,children:[a?(0,R.jsx)(_t,{className:`h-3 w-3`}):(0,R.jsx)(mt,{className:`h-3 w-3`}),a?`Copied!`:`Copy to Clipboard`]})]})]})}),(0,R.jsx)($,{className:`p-0`,children:(0,R.jsx)(`pre`,{className:`overflow-auto p-4 text-xs font-mono bg-muted/30 rounded-b-lg whitespace-pre max-h-[60vh]`,children:(0,R.jsx)(`code`,{children:l})})})]})}var Rp={object:`object`,view:`view`,flow:`flow`,agent:`agent`,tool:`tool`,app:`app`};function zp({metadataType:e,metadataName:t,packageId:n}){return(0,R.jsx)(Ep,{metaType:e,metaName:t,packageId:n})}function Bp({metadataType:e,metadataName:t,data:n,packageId:r}){let i=L(),a=Bf(be({strict:!1}).projectId)??i,[o,s]=(0,F.useState)(n??null),[c,l]=(0,F.useState)(!n);return(0,F.useEffect)(()=>{if(n){s(n),l(!1);return}let i=!0;l(!0);async function o(){try{let n=await a.meta.getItem(e,t,r?{packageId:r}:void 0);i&&s(n?.item||n)}catch(n){console.error(`[CodeViewer] Failed to load ${e}/${t}:`,n)}finally{i&&l(!1)}}return o(),()=>{i=!1}},[a,e,t,n,r]),c?(0,R.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading definition…`}):o?(0,R.jsx)(`div`,{className:`p-4`,children:(0,R.jsx)(Lp,{type:Rp[e]??`object`,definition:o,name:t})}):(0,R.jsxs)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:[`Definition not found: `,(0,R.jsx)(`code`,{className:`font-mono`,children:t})]})}var Vp={manifest:mf({id:`objectstack.default-inspector`,name:`Default Metadata Inspector`,version:`1.0.0`,description:`JSON tree viewer and code exporter for any metadata type. Fallback when no specialized viewer is available.`,contributes:{metadataViewers:[{id:`json-inspector`,metadataTypes:[`*`],label:`JSON Inspector`,priority:-1,modes:[`preview`]},{id:`code-exporter`,metadataTypes:[`*`],label:`Code Export`,priority:-1,modes:[`code`]}]}}),activate(e){e.registerViewer(`json-inspector`,zp),e.registerViewer(`code-exporter`,Bp)}},Hp=e=>`objectstack:agent-playground:${e}`;function Up(e){return(e.parts??[]).filter(e=>e.type===`text`).map(e=>e.text).join(``)}function Wp(e){return e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Gp(e){if(!e||typeof e!=`object`)return``;let t=Object.entries(e);return t.length===0?``:t.slice(0,4).map(([e,t])=>{let n;try{n=typeof t==`string`?t:JSON.stringify(t)??String(t)}catch{n=String(t)}return`${e}: ${n.length>30?n.slice(0,30)+`…`:n}`}).join(`, `)}function Kp(e){return e.type===`dynamic-tool`}function qp(e,t=80){let n;try{n=typeof e==`string`?e:JSON.stringify(e)??``}catch{n=String(e??``)}return n.length>t?n.slice(0,t)+`…`:n}function Jp({reasoning:e}){let[t,n]=(0,F.useState)(!1);return e.length===0?null:(0,R.jsxs)(`div`,{"data-testid":`reasoning-display`,className:`flex flex-col gap-1 rounded-md border border-border/30 bg-muted/30 px-2.5 py-2 text-xs`,children:[(0,R.jsxs)(`button`,{onClick:()=>n(!t),className:`flex items-center gap-1.5 text-left text-muted-foreground hover:text-foreground transition-colors`,children:[t?(0,R.jsx)(We,{className:`h-3 w-3 shrink-0`}):(0,R.jsx)(je,{className:`h-3 w-3 shrink-0`}),(0,R.jsx)(Tt,{className:`h-3 w-3 shrink-0`}),(0,R.jsx)(`span`,{className:`font-medium`,children:`Thinking`}),(0,R.jsxs)(`span`,{className:`text-[10px] opacity-60`,children:[`(`,e.length,` step`,e.length===1?``:`s`,`)`]})]}),t&&(0,R.jsx)(`div`,{className:`mt-1 space-y-1 pl-5 text-muted-foreground italic border-l-2 border-border/30`,children:e.map((e,t)=>(0,R.jsx)(`p`,{className:`text-[11px] leading-relaxed`,children:e},t))})]})}function Yp({activeSteps:e,completedSteps:t}){if(e.size===0)return null;let n=t.length+e.size,r=t.length+1;return(0,R.jsxs)(`div`,{"data-testid":`step-progress`,className:`flex flex-col gap-1.5 rounded-md border border-blue-500/30 bg-blue-500/5 px-2.5 py-2 text-xs`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(Qt,{className:`h-3 w-3 shrink-0 text-blue-600 dark:text-blue-400`}),(0,R.jsxs)(`span`,{className:`font-medium text-blue-700 dark:text-blue-300`,children:[`Step `,r,` of `,n]})]}),Array.from(e.values()).map((e,t)=>(0,R.jsxs)(`div`,{className:`flex items-center gap-2 pl-5`,children:[(0,R.jsx)(tt,{className:`h-3 w-3 shrink-0 animate-spin text-blue-600 dark:text-blue-400`}),(0,R.jsx)(`span`,{className:`text-blue-700 dark:text-blue-300`,children:e.stepName})]},t))]})}function Xp({part:e,onApprove:t,onDeny:n}){let r=Wp(e.toolName),i=Gp(e.input);switch(e.state){case`input-streaming`:return(0,R.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-blue-500/40 bg-blue-500/10 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(tt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin text-blue-600 dark:text-blue-400`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`span`,{className:`font-medium text-blue-700 dark:text-blue-300`,children:[`Planning to call `,r]}),i&&(0,R.jsx)(`p`,{className:`mt-0.5 truncate text-blue-600/80 dark:text-blue-300/80`,children:i})]})]});case`input-available`:return(0,R.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-border/50 bg-muted/50 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(tt,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 animate-spin text-primary`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`span`,{className:`font-medium`,children:[`Calling `,r]}),i&&(0,R.jsx)(`p`,{className:`mt-0.5 truncate text-muted-foreground`,children:i})]})]});case`approval-requested`:return(0,R.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-md border border-yellow-500/40 bg-yellow-500/10 px-2.5 py-2 text-xs`,children:[(0,R.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,R.jsx)(Ae,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-yellow-600 dark:text-yellow-400`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`span`,{className:`font-medium`,children:[`Confirm: `,r]}),i&&(0,R.jsx)(`p`,{className:`mt-0.5 text-muted-foreground`,children:i})]})]}),e.approval&&t&&n&&(0,R.jsxs)(`div`,{className:`flex gap-2 pl-5`,children:[(0,R.jsxs)(B,{size:`sm`,variant:`outline`,className:`h-6 px-2 text-xs`,onClick:()=>t(e.approval.id),children:[(0,R.jsx)(ct,{className:`mr-1 h-3 w-3`}),`Approve`]}),(0,R.jsxs)(B,{size:`sm`,variant:`ghost`,className:`h-6 px-2 text-xs text-destructive hover:text-destructive`,onClick:()=>n(e.approval.id),children:[(0,R.jsx)(Oe,{className:`mr-1 h-3 w-3`}),`Deny`]})]})]});case`output-available`:return(0,R.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-green-500/30 bg-green-500/10 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(ct,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-green-600 dark:text-green-400`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:r}),(0,R.jsx)(`p`,{className:`mt-0.5 text-muted-foreground truncate`,children:qp(e.output)})]})]});case`output-error`:return(0,R.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/30 bg-destructive/10 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(Oe,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`span`,{className:`font-medium`,children:[r,` failed`]}),(0,R.jsx)(`p`,{className:`mt-0.5 text-destructive/80`,children:e.errorText})]})]});case`output-denied`:return(0,R.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-border/50 bg-muted/50 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(Oe,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,R.jsxs)(`span`,{className:`font-medium text-muted-foreground`,children:[r,` — denied`]})]});default:return(0,R.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-border/50 bg-muted/50 px-2.5 py-2 text-xs`,children:[(0,R.jsx)(dn,{className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`font-medium`,children:r})]})}}function Zp({metadataType:e,metadataName:t,data:n,packageId:r}){let i=L(),a=Bf(be({strict:!1}).projectId)??i,[o,s]=(0,F.useState)(n??null),[c,l]=(0,F.useState)(!n),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)({reasoning:[],activeSteps:new Map,completedSteps:[]}),[m,h]=(0,F.useState)(!1),g=(0,F.useRef)(null),_=(0,F.useRef)(null),v=Sl();(0,F.useEffect)(()=>{if(n){s(n),l(!1);return}let i=!0;l(!0);async function o(){try{let n=await a.meta.getItem(e,t,r?{packageId:r}:void 0);i&&s(n?.item||n)}catch(e){console.error(`[AgentPlayground] Failed to load agent ${t}:`,e)}finally{i&&l(!1)}}return o(),()=>{i=!1}},[a,e,t,n,r]);let y=(0,F.useCallback)(()=>{try{let e=Hp(t),n=localStorage.getItem(e);return n?JSON.parse(n):[]}catch{return[]}},[t]),b=(0,F.useCallback)(e=>{try{let n=Hp(t);localStorage.setItem(n,JSON.stringify(e))}catch{}},[t]),x=(0,F.useMemo)(()=>y(),[y]),{messages:S,sendMessage:C,setMessages:w,status:T,error:ee,addToolApprovalResponse:E}=ge({transport:(0,F.useMemo)(()=>new ce({api:`${v}/api/v1/ai/agents/${t}/chat`}),[v,t]),messages:x,onFinish:()=>{p({reasoning:[],activeSteps:new Map,completedSteps:[]})}}),te=T===`streaming`||T===`submitted`;(0,F.useEffect)(()=>{if(!te||S.length===0)return;let e=S[S.length-1];if(e.role!==`assistant`)return;let t=[],n=new Map,r=[];(e.parts||[]).forEach(e=>{e.type===`reasoning-delta`||e.type===`reasoning`?t.push(e.text):e.type===`step-start`?n.set(e.stepId,{stepName:e.stepName,startedAt:Date.now()}):e.type===`step-finish`&&r.push(e.stepName)}),p({reasoning:t,activeSteps:n,completedSteps:r})},[S,te]),(0,F.useEffect)(()=>{S.length>0&&b(S)},[S,b]),(0,F.useEffect)(()=>{g.current&&(g.current.scrollTop=g.current.scrollHeight)},[S]);let D=()=>{w([]),b([])},ne=()=>{let e=new Blob([JSON.stringify(S,null,2)],{type:`application/json`}),n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=`agent-${t}-conversation-${Date.now()}.json`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},O=()=>{let e=u.trim();!e||te||(d(``),C({text:e}))};return c?(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,R.jsx)(tt,{className:`h-4 w-4 animate-spin`}),(0,R.jsx)(`span`,{children:`Loading agent...`})]})}):o?(0,R.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,R.jsxs)(`div`,{className:`shrink-0 border-b bg-background`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-end gap-1 px-4 py-2`,children:[(0,R.jsx)(sc,{children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>h(!m),children:(0,R.jsx)(We,{className:z(`h-4 w-4 transition-transform`,m&&`rotate-180`)})})}),(0,R.jsx)(uc,{children:(0,R.jsxs)(`p`,{children:[m?`Hide`:`Show`,` metadata`]})})]})}),(0,R.jsx)(sc,{children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:ne,disabled:S.length===0,children:(0,R.jsx)(Yt,{className:`h-4 w-4`})})}),(0,R.jsx)(uc,{children:(0,R.jsx)(`p`,{children:`Download conversation`})})]})}),(0,R.jsx)(sc,{children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:D,children:(0,R.jsx)(Fn,{className:`h-4 w-4`})})}),(0,R.jsx)(uc,{children:(0,R.jsx)(`p`,{children:`Clear history`})})]})})]}),m&&(0,R.jsx)(`div`,{className:`px-4 pb-3 border-t`,children:(0,R.jsxs)(`div`,{className:`mt-3 text-xs space-y-2`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`Instructions:`}),(0,R.jsx)(`p`,{className:`mt-1 text-foreground whitespace-pre-wrap`,children:o.instructions})]}),o.model&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`Model:`}),(0,R.jsx)(`span`,{className:`ml-2 font-mono`,children:o.model.model})]}),o.skills&&o.skills.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`Skills:`}),(0,R.jsx)(`span`,{className:`ml-2`,children:o.skills.join(`, `)})]}),o.tools&&o.tools.length>0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`Tools:`}),(0,R.jsx)(`span`,{className:`ml-2`,children:o.tools.map(e=>e.name).join(`, `)})]})]})})]}),(0,R.jsx)(ll,{className:`flex-1`,children:(0,R.jsxs)(`div`,{ref:g,className:`flex flex-col gap-3 p-4 overflow-y-auto h-full`,children:[S.length===0&&(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 py-12 text-center text-muted-foreground`,children:[(0,R.jsx)(st,{className:`h-8 w-8 opacity-40`}),(0,R.jsxs)(`p`,{className:`text-sm`,children:[`Start testing `,o.label]}),(0,R.jsx)(`p`,{className:`text-xs opacity-60`,children:`Send a message to begin the conversation`})]}),S.map(e=>{let t=Up(e),n=(e.parts??[]).filter(Kp);return!(t||n.length>0)&&e.role!==`user`?null:(0,R.jsxs)(`div`,{className:z(`flex flex-col gap-1.5 rounded-lg px-3 py-2 text-sm`,e.role===`user`?`ml-8 bg-primary text-primary-foreground`:`mr-8 bg-muted text-foreground`),children:[(0,R.jsx)(`span`,{className:`text-[10px] font-medium opacity-60 uppercase`,children:e.role===`user`?`You`:`Assistant`}),t&&(0,R.jsx)(`div`,{className:`whitespace-pre-wrap break-words`,children:t}),n.map(e=>(0,R.jsx)(Xp,{part:e,onApprove:e=>E({id:e,approved:!0}),onDeny:e=>E({id:e,approved:!1,reason:`User denied the operation`})},e.toolCallId))]},e.id)}),te&&(0,R.jsxs)(R.Fragment,{children:[f.reasoning.length>0&&(0,R.jsx)(`div`,{className:`mr-8`,children:(0,R.jsx)(Jp,{reasoning:f.reasoning})}),f.activeSteps.size>0&&(0,R.jsx)(`div`,{className:`mr-8`,children:(0,R.jsx)(Yp,{activeSteps:f.activeSteps,completedSteps:f.completedSteps})}),f.reasoning.length===0&&f.activeSteps.size===0&&(0,R.jsxs)(`div`,{className:`mr-8 flex items-center gap-2 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground`,children:[(0,R.jsx)(`span`,{className:`inline-block h-2 w-2 animate-pulse rounded-full bg-primary`}),`Thinking…`]})]}),ee&&(0,R.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-destructive/50 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:[(0,R.jsx)(Ae,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`p`,{className:`font-medium`,children:`Error`}),(0,R.jsx)(`p`,{className:`mt-0.5 text-xs opacity-80`,children:ee.message||`Something went wrong`})]})]})]})}),(0,R.jsx)(`div`,{className:`shrink-0 border-t p-4`,children:(0,R.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,R.jsx)(`textarea`,{ref:_,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),O())},placeholder:`Type your message...`,rows:1,className:z(`flex-1 resize-none rounded-md border border-input bg-transparent px-3 py-2 text-sm`,`placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,`max-h-32 min-h-[36px]`)}),(0,R.jsx)(B,{type:`button`,size:`icon`,className:`h-9 w-9 shrink-0`,disabled:!u.trim()||te,onClick:O,children:(0,R.jsx)(He,{className:`h-4 w-4`})})]})})]}):(0,R.jsxs)(`div`,{className:`p-8 text-center text-muted-foreground`,children:[(0,R.jsx)(ut,{className:`h-12 w-12 mx-auto mb-4 opacity-40`}),(0,R.jsxs)(`p`,{className:`text-sm`,children:[`Agent not found: `,(0,R.jsx)(`code`,{className:`font-mono`,children:t})]})]})}var Qp={manifest:mf({id:`objectstack.agent-playground`,name:`Agent Playground`,version:`1.0.0`,description:`Interactive testing environment for AI agents with embedded chat interface.`,contributes:{metadataViewers:[{id:`agent-playground`,metadataTypes:[`agent`],label:`Playground`,priority:10,modes:[`preview`]}]}}),activate(e){e.registerViewer(`agent-playground`,Zp)}},$p=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`textarea`,{className:z(`flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50`,e),ref:n,...t}));$p.displayName=`Textarea`;var em=xr,tm=wr,nm=F.forwardRef(({className:e,children:t,...n},r)=>(0,R.jsxs)(nr,{ref:r,className:z(`flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1`,e),...n,children:[t,(0,R.jsx)(mr,{asChild:!0,children:(0,R.jsx)(We,{className:`h-4 w-4 opacity-50`})})]}));nm.displayName=nr.displayName;var rm=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(ir,{ref:n,className:z(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,R.jsx)(Rn,{className:`h-4 w-4`})}));rm.displayName=ir.displayName;var im=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Xn,{ref:n,className:z(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,R.jsx)(We,{className:`h-4 w-4`})}));im.displayName=Xn.displayName;var am=F.forwardRef(({className:e,children:t,position:n=`popper`,...r},i)=>(0,R.jsx)(_r,{children:(0,R.jsxs)(or,{ref:i,className:z(`relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,n===`popper`&&`data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1`,e),position:n,...r,children:[(0,R.jsx)(rm,{}),(0,R.jsx)(Cr,{className:z(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]`),children:t}),(0,R.jsx)(im,{})]})}));am.displayName=or.displayName;var om=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Qn,{ref:n,className:z(`px-2 py-1.5 text-sm font-semibold`,e),...t}));om.displayName=Qn.displayName;var sm=F.forwardRef(({className:e,children:t,...n},r)=>(0,R.jsxs)(Br,{ref:r,className:z(`relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,R.jsx)(`span`,{className:`absolute right-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,R.jsx)(Wn,{children:(0,R.jsx)(_t,{className:`h-4 w-4`})})}),(0,R.jsx)(yr,{children:t})]}));sm.displayName=Br.displayName;var cm=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Pr,{ref:n,className:z(`-mx-1 my-1 h-px bg-muted`,e),...t}));cm.displayName=Pr.displayName;var lm=e=>`objectstack:tool-playground:${e}`;function um(e){return{properties:e.properties||{},required:e.required||[]}}function dm({name:e,property:t,value:n,onChange:r,required:i}){let{type:a,description:o,enum:s}=t,c=e.replace(/_/g,` `).replace(/\b\w/g,e=>e.toUpperCase());return s&&s.length>0?(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(W,{htmlFor:e,children:[c,i&&(0,R.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),o&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}),(0,R.jsxs)(em,{value:n||``,onValueChange:r,children:[(0,R.jsx)(nm,{id:e,children:(0,R.jsx)(tm,{placeholder:`Select ${c}`})}),(0,R.jsx)(am,{children:s.map(e=>(0,R.jsx)(sm,{value:String(e),children:String(e)},String(e)))})]})]}):a===`boolean`?(0,R.jsxs)(`div`,{className:`flex items-start space-x-2`,children:[(0,R.jsx)(qf,{id:e,checked:!!n,onCheckedChange:e=>r(e)}),(0,R.jsxs)(`div`,{className:`grid gap-1.5 leading-none`,children:[(0,R.jsxs)(W,{htmlFor:e,className:`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,children:[c,i&&(0,R.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),o&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o})]})]}):a===`number`||a===`integer`?(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(W,{htmlFor:e,children:[c,i&&(0,R.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),o&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}),(0,R.jsx)(V,{id:e,type:`number`,value:n??``,onChange:e=>{let t=e.target.value;r(t===``?void 0:a===`integer`?parseInt(t,10):parseFloat(t))},placeholder:`Enter ${c}`})]}):a===`array`?(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(W,{htmlFor:e,children:[c,i&&(0,R.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),o&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}),(0,R.jsx)($p,{id:e,value:n?JSON.stringify(n,null,2):``,onChange:e=>{try{r(JSON.parse(e.target.value))}catch{}},placeholder:`Enter JSON array`,rows:3,className:`font-mono text-xs`})]}):a===`object`?(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(W,{htmlFor:e,children:[c,i&&(0,R.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),o&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}),(0,R.jsx)($p,{id:e,value:n?JSON.stringify(n,null,2):``,onChange:e=>{try{r(JSON.parse(e.target.value))}catch{}},placeholder:`Enter JSON object`,rows:4,className:`font-mono text-xs`})]}):(o?.length||0)>100?(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(W,{htmlFor:e,children:[c,i&&(0,R.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),o&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}),(0,R.jsx)($p,{id:e,value:n||``,onChange:e=>r(e.target.value),placeholder:`Enter ${c}`,rows:3})]}):(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsxs)(W,{htmlFor:e,children:[c,i&&(0,R.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),o&&(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o}),(0,R.jsx)(V,{id:e,type:`text`,value:n||``,onChange:e=>r(e.target.value),placeholder:`Enter ${c}`})]})}function fm({entry:e}){let[t,n]=(0,F.useState)(!1),[r,i]=(0,F.useState)(!1),a=e=>{navigator.clipboard.writeText(e),i(!0),setTimeout(()=>i(!1),2e3)};return(0,R.jsxs)(`div`,{className:`border rounded-md overflow-hidden`,children:[(0,R.jsxs)(`button`,{onClick:()=>n(!t),className:`w-full flex items-center justify-between px-3 py-2 bg-muted/50 hover:bg-muted transition-colors text-left`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[t?(0,R.jsx)(We,{className:`h-3 w-3 shrink-0`}):(0,R.jsx)(je,{className:`h-3 w-3 shrink-0`}),e.status===`success`?(0,R.jsx)(ct,{className:`h-3 w-3 shrink-0 text-green-600 dark:text-green-400`}):(0,R.jsx)(Oe,{className:`h-3 w-3 shrink-0 text-destructive`}),(0,R.jsx)(Ie,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:new Date(e.timestamp).toLocaleTimeString()}),e.duration&&(0,R.jsxs)(`span`,{className:`text-muted-foreground`,children:[`(`,e.duration,`ms)`]})]}),(0,R.jsx)(`div`,{className:`flex items-center gap-1`,children:r?(0,R.jsx)(_t,{className:`h-3 w-3 text-green-600`}):(0,R.jsx)(sc,{children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(`button`,{onClick:t=>{t.stopPropagation(),a(JSON.stringify(e.status===`success`?e.result:e.error,null,2))},className:`p-1 hover:bg-background rounded`,children:(0,R.jsx)(mt,{className:`h-3 w-3`})})}),(0,R.jsx)(uc,{children:(0,R.jsx)(`p`,{children:`Copy result`})})]})})})]}),t&&(0,R.jsxs)(`div`,{className:`px-3 py-2 border-t space-y-2`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground mb-1`,children:`Parameters:`}),(0,R.jsx)(`pre`,{className:`text-xs bg-background rounded p-2 overflow-auto max-h-32`,children:JSON.stringify(e.parameters,null,2)})]}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground mb-1`,children:e.status===`success`?`Result:`:`Error:`}),(0,R.jsx)(`pre`,{className:z(`text-xs rounded p-2 overflow-auto max-h-48`,e.status===`success`?`bg-green-500/10 text-green-700 dark:text-green-300`:`bg-destructive/10 text-destructive`),children:e.status===`success`?JSON.stringify(e.result,null,2):e.error})]})]})]})}function pm({metadataType:e,metadataName:t,data:n,packageId:r}){let i=L(),a=Bf(be({strict:!1}).projectId)??i,[o,s]=(0,F.useState)(n??null),[c,l]=(0,F.useState)(!n),[u,d]=(0,F.useState)(!1),[f,p]=(0,F.useState)({}),[m,h]=(0,F.useState)([]),g=(0,F.useRef)(null),_=Sl();(0,F.useEffect)(()=>{if(n){s(n),l(!1);return}let i=!0;l(!0);async function o(){try{let n=await a.meta.getItem(e,t,r?{packageId:r}:void 0);i&&s(n?.item||n)}catch(e){console.error(`[ToolPlayground] Failed to load tool ${t}:`,e)}finally{i&&l(!1)}}return o(),()=>{i=!1}},[a,e,t,n,r]),(0,F.useEffect)(()=>{try{let e=lm(t),n=localStorage.getItem(e);n&&h(JSON.parse(n))}catch{}},[t]);let v=e=>{try{let n=lm(t),r=e.slice(-50);localStorage.setItem(n,JSON.stringify(r)),h(r)}catch{}},y=()=>{try{let e=lm(t);localStorage.removeItem(e),h([])}catch{}},b=async()=>{if(!o||u)return;d(!0);let e=Date.now(),n=`exec-${Date.now()}`;try{let r=await fetch(`${_}/api/v1/ai/tools/${t}/execute`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({parameters:f})}),i=Date.now()-e;if(r.ok){let e=await r.json(),t={id:n,timestamp:Date.now(),parameters:{...f},status:`success`,result:e.result||e,duration:i};v([...m,t])}else{let e=await r.json().catch(()=>({error:r.statusText})),t={id:n,timestamp:Date.now(),parameters:{...f},status:`error`,error:e.error||`Tool execution failed`,duration:i};v([...m,t])}}catch(t){let r=Date.now()-e,i={id:n,timestamp:Date.now(),parameters:{...f},status:`error`,error:t instanceof Error?t.message:`Unknown error`,duration:r};v([...m,i])}finally{d(!1)}},x=()=>{p({})};if(c)return(0,R.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,R.jsx)(tt,{className:`h-4 w-4 animate-spin`}),(0,R.jsx)(`span`,{children:`Loading tool...`})]})});if(!o)return(0,R.jsxs)(`div`,{className:`p-8 text-center text-muted-foreground`,children:[(0,R.jsx)(dn,{className:`h-12 w-12 mx-auto mb-4 opacity-40`}),(0,R.jsxs)(`p`,{className:`text-sm`,children:[`Tool not found: `,(0,R.jsx)(`code`,{className:`font-mono`,children:t})]})]});let{properties:S,required:C}=um(o.parameters),w=Object.keys(S);return(0,R.jsxs)(`div`,{className:`grid grid-cols-2 h-full divide-x`,children:[(0,R.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`shrink-0 border-b bg-background px-4 py-3`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsx)(dn,{className:`h-5 w-5 text-primary`}),(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h2`,{className:`text-sm font-semibold`,children:o.label}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:o.category||`Tool`})]})]}),o.description&&(0,R.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:o.description})]}),(0,R.jsx)(ll,{className:`flex-1`,children:(0,R.jsx)(`div`,{className:`p-4 space-y-4`,children:(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`h3`,{className:`text-sm font-medium mb-3`,children:`Parameters`}),w.length===0?(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This tool has no parameters.`}):(0,R.jsx)(`div`,{className:`space-y-4`,children:w.map(e=>(0,R.jsx)(dm,{name:e,property:S[e],value:f[e],onChange:t=>p({...f,[e]:t}),required:C.includes(e)},e))})]})})}),(0,R.jsxs)(`div`,{className:`shrink-0 border-t p-4 flex gap-2`,children:[(0,R.jsx)(B,{onClick:b,disabled:u,className:`flex-1`,children:u?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(tt,{className:`mr-2 h-4 w-4 animate-spin`}),`Executing...`]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Mt,{className:`mr-2 h-4 w-4`}),`Execute Tool`]})}),(0,R.jsx)(B,{variant:`outline`,onClick:x,children:`Reset`})]})]}),(0,R.jsxs)(`div`,{className:`flex flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`shrink-0 border-b bg-background px-4 py-3 flex items-center justify-between`,children:[(0,R.jsx)(`h3`,{className:`text-sm font-medium`,children:`Execution History`}),(0,R.jsx)(sc,{children:(0,R.jsxs)(cc,{children:[(0,R.jsx)(lc,{asChild:!0,children:(0,R.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:y,disabled:m.length===0,children:(0,R.jsx)(Fn,{className:`h-4 w-4`})})}),(0,R.jsx)(uc,{children:(0,R.jsx)(`p`,{children:`Clear history`})})]})})]}),(0,R.jsx)(ll,{className:`flex-1`,children:(0,R.jsx)(`div`,{ref:g,className:`p-4 space-y-2`,children:m.length===0?(0,R.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center text-muted-foreground`,children:[(0,R.jsx)(Ie,{className:`h-8 w-8 opacity-40 mb-2`}),(0,R.jsx)(`p`,{className:`text-sm`,children:`No executions yet`}),(0,R.jsx)(`p`,{className:`text-xs opacity-60`,children:`Execute the tool to see results here`})]}):m.slice().reverse().map(e=>(0,R.jsx)(fm,{entry:e},e.id))})})]})]})}var mm={manifest:mf({id:`objectstack.tool-playground`,name:`Tool Playground`,version:`1.0.0`,description:`Interactive testing environment for AI tools with auto-generated parameter forms.`,contributes:{metadataViewers:[{id:`tool-playground`,metadataTypes:[`tool`],label:`Playground`,priority:10,modes:[`preview`]}]}}),activate(e){e.registerViewer(`tool-playground`,pm)}},hm=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(Jn,{className:z(`peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input`,e),...t,ref:n,children:(0,R.jsx)(er,{className:z(`pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0`)})}));hm.displayName=Jn.displayName;function gm(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 _m({flow:e,onExecuted:t}){let n=be({strict:!1}),r=L(),i=Bf(n.projectId)??r,a=(0,F.useMemo)(()=>(e?.variables??[]).filter(e=>e?.isInput),[e]),[o,s]=(0,F.useState)({}),[c,l]=(0,F.useState)(!1),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(null),m=(e,t)=>s(n=>({...n,[e]:t}));return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{className:`pb-3`,children:(0,R.jsx)(Q,{className:`text-base`,children:`Inputs`})}),(0,R.jsxs)($,{className:`space-y-3`,children:[a.length===0&&(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This flow declares no input variables. Click Run to invoke with no parameters.`}),a.map(e=>(0,R.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,R.jsxs)(W,{htmlFor:`var-${e.name}`,className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`font-mono text-xs`,children:e.name}),(0,R.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:e.type})]}),e.type===`boolean`?(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(hm,{id:`var-${e.name}`,checked:o[e.name]===`true`,onCheckedChange:t=>m(e.name,t?`true`:`false`)}),(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o[e.name]===`true`?`true`:`false`})]}):e.type===`object`||e.type===`list`||e.type===`array`?(0,R.jsx)($p,{id:`var-${e.name}`,placeholder:`JSON ${e.type}`,value:o[e.name]??``,onChange:t=>m(e.name,t.target.value),className:`font-mono text-xs min-h-[80px]`}):(0,R.jsx)(V,{id:`var-${e.name}`,type:e.type===`number`?`number`:`text`,value:o[e.name]??``,onChange:t=>m(e.name,t.target.value)})]},e.name)),(0,R.jsx)(`div`,{className:`pt-1`,children:(0,R.jsxs)(B,{onClick:async()=>{if(!i?.automation?.execute){p(`automation.execute is not available on this client`);return}l(!0),p(null),d(null);try{let n={};for(let e of a){let t=o[e.name];t!==void 0&&(n[e.name]=gm(t,e.type))}d(await i.automation.execute(e.name,{params:n})),t?.()}catch(e){p(e?.message??String(e))}finally{l(!1)}},disabled:c,size:`sm`,children:[c?(0,R.jsx)(tt,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,R.jsx)(Mt,{className:`h-3.5 w-3.5 mr-2`}),c?`Running…`:`Run Flow`]})})]})]}),(u||f)&&(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{className:`pb-3`,children:(0,R.jsxs)(Q,{className:`text-base flex items-center gap-2`,children:[f||u?.success===!1?(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(Oe,{className:`h-4 w-4 text-red-500`}),` Failed`]}):(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(ct,{className:`h-4 w-4 text-emerald-500`}),` Result`]}),typeof u?.durationMs==`number`&&(0,R.jsxs)(G,{variant:`secondary`,className:`ml-2 text-[10px] font-mono`,children:[u.durationMs,` ms`]})]})}),(0,R.jsxs)($,{children:[f&&(0,R.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:f}),u&&(0,R.jsx)(`div`,{className:`text-sm`,children:(0,R.jsx)(Tp,{data:u})})]})]})]})}function vm({status:e}){let t={success:{variant:`outline`,icon:ct,cls:`text-emerald-600 border-emerald-300`},completed:{variant:`outline`,icon:ct,cls:`text-emerald-600 border-emerald-300`},failed:{variant:`outline`,icon:Oe,cls:`text-red-600 border-red-300`},error:{variant:`outline`,icon:Oe,cls:`text-red-600 border-red-300`},running:{variant:`outline`,icon:tt,cls:`text-blue-600 border-blue-300 animate-pulse`},pending:{variant:`outline`,icon:Ie,cls:`text-amber-600 border-amber-300`},skipped:{variant:`outline`,icon:Be,cls:`text-muted-foreground`}}[e]??{variant:`outline`,icon:Be,cls:`text-muted-foreground`},n=t.icon;return(0,R.jsxs)(G,{variant:t.variant,className:`text-[10px] font-mono inline-flex items-center gap-1 ${t.cls}`,children:[(0,R.jsx)(n,{className:`h-3 w-3`}),e]})}function ym(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function bm({flowName:e,refreshKey:t}){let n=be({strict:!1}),r=L(),i=Bf(n.projectId)??r,[a,o]=(0,F.useState)([]),[s,c]=(0,F.useState)(!0),[l,u]=(0,F.useState)(null),[d,f]=(0,F.useState)(null),[p,m]=(0,F.useState)(null),[h,g]=(0,F.useState)(!1),[_,v]=(0,F.useState)(null),y=(0,F.useCallback)(async()=>{if(!i?.automation?.listRuns){u(`automation.listRuns is not available on this client`),c(!1);return}c(!0),u(null);try{let t=await i.automation.listRuns(e,{limit:20});o(Array.isArray(t)?t:t?.items??t?.runs??[])}catch(e){u(e?.message??String(e))}finally{c(!1)}},[i,e]);(0,F.useEffect)(()=>{y()},[y,t]);let b=async t=>{f(t),m(null),v(null),g(!0);try{let n=await i.automation.getRun(e,t);m(n?.run??n)}catch(e){v(e?.message??String(e))}finally{g(!1)}};return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{className:`pb-3`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(Q,{className:`text-base`,children:`Recent Runs`}),(0,R.jsxs)(B,{variant:`outline`,size:`sm`,onClick:y,disabled:s,children:[s?(0,R.jsx)(tt,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,R.jsx)(Ut,{className:`h-3.5 w-3.5 mr-2`}),`Refresh`]})]})}),(0,R.jsxs)($,{children:[s&&(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsx)(H,{className:`h-8 w-full`}),(0,R.jsx)(H,{className:`h-8 w-full`}),(0,R.jsx)(H,{className:`h-8 w-full`})]}),!s&&l&&(0,R.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:l}),!s&&!l&&a.length===0&&(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground py-6 text-center`,children:`No runs yet. Use the Test Run tab to invoke this flow.`}),!s&&!l&&a.length>0&&(0,R.jsxs)(Vf,{children:[(0,R.jsx)(Hf,{children:(0,R.jsxs)(Gf,{children:[(0,R.jsx)(J,{children:`Run`}),(0,R.jsx)(J,{children:`Status`}),(0,R.jsx)(J,{children:`Started`}),(0,R.jsx)(J,{className:`text-right`,children:`Duration`})]})}),(0,R.jsx)(Uf,{children:a.map(e=>(0,R.jsxs)(Gf,{className:`cursor-pointer`,onClick:()=>b(e.id),children:[(0,R.jsxs)(Y,{className:`font-mono text-xs`,children:[e.id.slice(0,12),`…`]}),(0,R.jsx)(Y,{children:(0,R.jsx)(vm,{status:e.status})}),(0,R.jsx)(Y,{className:`text-xs text-muted-foreground`,children:ym(e.startedAt)}),(0,R.jsx)(Y,{className:`text-right font-mono text-xs`,children:typeof e.durationMs==`number`?`${e.durationMs} ms`:`—`})]},e.id))})]})]})]}),(0,R.jsx)(Qs,{open:!!d,onOpenChange:e=>{e||(f(null),m(null))},children:(0,R.jsxs)(nc,{side:`right`,className:`w-full sm:max-w-2xl p-0 flex flex-col`,children:[(0,R.jsxs)(rc,{className:`p-4 border-b`,children:[(0,R.jsxs)(ac,{className:`font-mono text-sm break-all`,children:[`Run `,d]}),(0,R.jsx)(oc,{children:p&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,R.jsx)(vm,{status:p.status}),typeof p.durationMs==`number`&&(0,R.jsxs)(G,{variant:`secondary`,className:`text-[10px] font-mono`,children:[p.durationMs,` ms`]}),(0,R.jsx)(`span`,{className:`text-xs`,children:ym(p.startedAt)})]})})]}),(0,R.jsxs)(ll,{className:`flex-1 p-4`,children:[h&&(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsx)(H,{className:`h-16 w-full`}),(0,R.jsx)(H,{className:`h-16 w-full`}),(0,R.jsx)(H,{className:`h-16 w-full`})]}),_&&(0,R.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:_}),!h&&p&&(0,R.jsx)(`div`,{className:`space-y-3`,children:Array.isArray(p.steps)&&p.steps.length>0?p.steps.map((e,t)=>(0,R.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,R.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs`,children:[`#`,t+1]}),(0,R.jsx)(`span`,{className:`font-mono text-sm font-medium`,children:e.nodeLabel||e.nodeId}),e.nodeType&&(0,R.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:e.nodeType}),(0,R.jsx)(vm,{status:e.status}),typeof e.durationMs==`number`&&(0,R.jsxs)(G,{variant:`secondary`,className:`text-[10px] font-mono ml-auto`,children:[e.durationMs,` ms`]})]}),e.input!==void 0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground mb-1`,children:`Input`}),(0,R.jsx)(Tp,{data:e.input})]}),e.output!==void 0&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground mb-1`,children:`Output`}),(0,R.jsx)(Tp,{data:e.output})]}),e.error&&(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-[10px] uppercase text-red-500 mb-1`,children:`Error`}),(0,R.jsx)(Tp,{data:e.error})]})]},`${e.nodeId}-${t}`)):(0,R.jsxs)(`div`,{children:[(0,R.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground mb-1`,children:`Run`}),(0,R.jsx)(Tp,{data:p})]})})]})]})})]})}function xm(e){return typeof e==`string`?e:e&&typeof e==`object`&&`defaultValue`in e?String(e.defaultValue):e&&typeof e==`object`&&`key`in e?String(e.key):``}var Sm={autolaunched:Qt,record_change:In,schedule:_n,screen:ht,api:wt},Cm={autolaunched:`Autolaunched`,record_change:`Record Change`,schedule:`Schedule`,screen:`Screen`,api:`API`};function wm({metadataName:e,data:t,packageId:n}){let r=be({strict:!1}),i=L(),a=Bf(r.projectId)??i,[o,s]=(0,F.useState)(t??null),[c,l]=(0,F.useState)(!t),[u,d]=(0,F.useState)(null),[f,p]=(0,F.useState)(0);if((0,F.useEffect)(()=>{if(t){s(t),l(!1);return}if(!a?.meta?.getItem)return;let r=!0;return l(!0),d(null),(async()=>{try{let t=await a.meta.getItem(`flow`,e,n?{packageId:n}:void 0);r&&s(t?.item??t)}catch(e){r&&d(e?.message??String(e))}finally{r&&l(!1)}})(),()=>{r=!1}},[a,e,n,t]),c)return(0,R.jsx)(`div`,{className:`space-y-4 p-4`,children:(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{children:(0,R.jsx)(H,{className:`h-6 w-48`})}),(0,R.jsxs)($,{className:`space-y-3`,children:[(0,R.jsx)(H,{className:`h-10 w-full`}),(0,R.jsx)(H,{className:`h-10 w-full`})]})]})});if(u||!o)return(0,R.jsx)(`div`,{className:`p-4`,children:(0,R.jsx)(X,{children:(0,R.jsxs)($,{className:`py-12 text-center text-sm text-muted-foreground`,children:[(0,R.jsx)(`p`,{className:`font-medium text-foreground`,children:`Flow not found`}),(0,R.jsxs)(`p`,{className:`mt-1`,children:[`We couldn't load`,` `,(0,R.jsx)(`code`,{className:`font-mono text-xs`,children:e}),`. It may have been deleted or moved to another package.`]})]})})});let m=o.name||e,h=o.status,g=h===`active`,_=o.type||`autolaunched`,v=Sm[_]||bn,y=Cm[_]||_,b=Array.isArray(o.variables)?o.variables:[],x=Array.isArray(o.nodes)?o.nodes:[],S=Array.isArray(o.edges)?o.edges:[];return(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(typeof o.version==`number`||g||h)&&(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[typeof o.version==`number`&&(0,R.jsxs)(G,{variant:`secondary`,className:`text-[10px] font-mono`,children:[`v`,o.version]}),g?(0,R.jsxs)(G,{variant:`outline`,className:`text-[10px] font-mono text-emerald-600 border-emerald-300 inline-flex items-center gap-1`,children:[(0,R.jsx)(ct,{className:`h-3 w-3`}),` Enabled`]}):h?(0,R.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono text-muted-foreground`,children:h}):null]}),(0,R.jsxs)(ad,{defaultValue:`overview`,className:`w-full`,children:[(0,R.jsxs)(od,{children:[(0,R.jsx)(K,{value:`overview`,children:`Overview`}),(0,R.jsx)(K,{value:`test`,children:`Test Run`}),(0,R.jsx)(K,{value:`runs`,children:`Runs`}),(0,R.jsx)(K,{value:`raw`,children:`Raw JSON`})]}),(0,R.jsxs)(sd,{value:`overview`,className:`space-y-4 mt-4`,children:[(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{className:`pb-3`,children:(0,R.jsxs)(Q,{className:`text-base flex items-center gap-2`,children:[(0,R.jsx)(v,{className:`h-4 w-4 text-muted-foreground`}),`Trigger`]})}),(0,R.jsxs)($,{className:`text-sm space-y-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`Type:`}),(0,R.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:y})]}),o.trigger&&(0,R.jsx)(`div`,{className:`mt-2`,children:(0,R.jsx)(Tp,{data:o.trigger})})]})]}),(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{className:`pb-3`,children:(0,R.jsxs)(Q,{className:`text-base`,children:[`Variables (`,b.length,`)`]})}),(0,R.jsx)($,{children:b.length===0?(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No variables defined.`}):(0,R.jsxs)(Vf,{children:[(0,R.jsx)(Hf,{children:(0,R.jsxs)(Gf,{children:[(0,R.jsx)(J,{children:`Name`}),(0,R.jsx)(J,{children:`Type`}),(0,R.jsx)(J,{className:`text-center`,children:`Input`}),(0,R.jsx)(J,{className:`text-center`,children:`Output`})]})}),(0,R.jsx)(Uf,{children:b.map((e,t)=>(0,R.jsxs)(Gf,{children:[(0,R.jsx)(Y,{className:`font-mono text-xs`,children:e.name}),(0,R.jsx)(Y,{children:(0,R.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:e.type})}),(0,R.jsx)(Y,{className:`text-center text-xs`,children:e.isInput?`✓`:`—`}),(0,R.jsx)(Y,{className:`text-center text-xs`,children:e.isOutput?`✓`:`—`})]},`${e.name}-${t}`))})]})})]}),(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{className:`pb-3`,children:(0,R.jsxs)(Q,{className:`text-base`,children:[`Nodes (`,x.length,`)`]})}),(0,R.jsx)($,{children:x.length===0?(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No nodes defined.`}):(0,R.jsxs)(Vf,{children:[(0,R.jsx)(Hf,{children:(0,R.jsxs)(Gf,{children:[(0,R.jsx)(J,{children:`ID`}),(0,R.jsx)(J,{children:`Type`}),(0,R.jsx)(J,{children:`Label`})]})}),(0,R.jsx)(Uf,{children:x.map((e,t)=>(0,R.jsxs)(Gf,{children:[(0,R.jsx)(Y,{className:`font-mono text-xs`,children:e.id}),(0,R.jsx)(Y,{children:(0,R.jsx)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:e.type})}),(0,R.jsx)(Y,{className:`text-xs`,children:xm(e.label)||`—`})]},`${e.id}-${t}`))})]})})]}),(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{className:`pb-3`,children:(0,R.jsxs)(Q,{className:`text-base`,children:[`Edges (`,S.length,`)`]})}),(0,R.jsx)($,{children:S.length===0?(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No edges defined.`}):(0,R.jsxs)(Vf,{children:[(0,R.jsx)(Hf,{children:(0,R.jsxs)(Gf,{children:[(0,R.jsx)(J,{children:`From → To`}),(0,R.jsx)(J,{children:`Condition`}),(0,R.jsx)(J,{children:`Default`})]})}),(0,R.jsx)(Uf,{children:S.map((e,t)=>(0,R.jsxs)(Gf,{children:[(0,R.jsxs)(Y,{className:`font-mono text-xs`,children:[e.source,` `,(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),` `,e.target]}),(0,R.jsx)(Y,{className:`font-mono text-xs text-muted-foreground break-all`,children:(()=>{let t=e.condition;if(t==null)return`—`;if(typeof t==`string`)return t;if(typeof t==`object`&&`source`in t){let e=t.source;return typeof e==`string`?e:JSON.stringify(t)}return JSON.stringify(t)})()}),(0,R.jsx)(Y,{className:`text-xs`,children:e.isDefault?`✓`:`—`})]},`${e.id??t}`))})]})})]})]}),(0,R.jsx)(sd,{value:`test`,className:`mt-4`,children:(0,R.jsx)(_m,{flow:o,onExecuted:()=>p(e=>e+1)})}),(0,R.jsx)(sd,{value:`runs`,className:`mt-4`,children:(0,R.jsx)(bm,{flowName:m,refreshKey:f})}),(0,R.jsx)(sd,{value:`raw`,className:`mt-4`,children:(0,R.jsxs)(X,{children:[(0,R.jsx)(Z,{className:`pb-3`,children:(0,R.jsx)(Q,{className:`text-base`,children:`Raw Flow Definition`})}),(0,R.jsx)($,{children:(0,R.jsx)(Tp,{data:o})})]})})]})]})}var Tm={manifest:mf({id:`objectstack.flow-viewer`,name:`Flow Viewer`,version:`1.0.0`,description:`View flow metadata, run interactive tests, and inspect run history.`,contributes:{metadataViewers:[{id:`flow-viewer`,metadataTypes:[`flow`],label:`Flow`,priority:10,modes:[`preview`]}]}}),activate(e){e.registerViewer(`flow-viewer`,wm)}};function Em({objectName:e}){let t=(Sl()||(typeof window<`u`?window.location.origin:``)).replace(/^https?:\/\//,``);return(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t border-dashed bg-muted/20 px-4 py-1.5 text-[10px] font-mono text-muted-foreground`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsxs)(`span`,{className:`relative flex h-1.5 w-1.5`,children:[(0,R.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400 opacity-75`}),(0,R.jsx)(`span`,{className:`relative inline-flex h-1.5 w-1.5 rounded-full bg-emerald-500`})]}),(0,R.jsx)(Kt,{className:`h-3 w-3`}),(0,R.jsx)(`span`,{children:`LIVE`}),(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{title:`Backend`,children:t||`same-origin`}),e&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsx)(`span`,{title:`Resource`,children:e})]}),bl.singleProject&&bl.defaultProjectId&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(`span`,{className:`text-muted-foreground/60`,children:`·`}),(0,R.jsxs)(`span`,{children:[`project=`,bl.defaultProjectId]})]})]}),(0,R.jsx)(`div`,{className:`text-muted-foreground/60`,children:`real data · real validation · real submit`})]})}function Dm({spec:e,objectName:t,initialMode:n=`create`,className:r}){let i=mp(),{version:a}=Bu(),[o,s]=(0,F.useState)(n),[c,l]=(0,F.useState)([]),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(!1),[m,h]=(0,F.useState)(null),[g,_]=(0,F.useState)(0);(0,F.useEffect)(()=>{if(o===`create`||!t){l([]),d(``),h(null);return}let e=!1;return p(!0),h(null),(async()=>{try{let n=await i.find(t,{pagination:{page:1,perPage:10},sort:{field:`updatedAt`,order:`DESC`}});if(e)return;let r=(n?.data??[]).map(e=>({id:e.id,label:Om(e)}));l(r),r.length>0&&!u&&d(String(r[0].id))}catch(t){if(e)return;h(t?.message??String(t)),l([])}finally{e||p(!1)}})(),()=>{e=!0}},[o,t,i,g,a]);let v=o===`create`?void 0:u||void 0,y=(0,F.useMemo)(()=>({type:`object-form`,objectName:t,mode:o,...v?{recordId:v}:{},readOnly:o===`view`,...e}),[t,o,v,e]),b=e=>{o===`create`?(U({title:`Created record`,description:e?.id?`id: ${e.id}`:void 0}),_(e=>e+1)):U({title:`Saved`})},x=e=>{U({title:`Submission failed`,description:e.message,variant:`destructive`})};return(0,R.jsxs)(`div`,{className:[`flex h-full flex-col`,r].filter(Boolean).join(` `),children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-dashed px-4 py-2`,children:[(0,R.jsx)(`div`,{className:`flex items-center gap-1 rounded-md border bg-muted/30 p-0.5 text-xs`,children:[`create`,`edit`,`view`].map(e=>(0,R.jsxs)(B,{size:`sm`,variant:o===e?`default`:`ghost`,className:`h-7 gap-1 px-2 text-[11px]`,onClick:()=>s(e),children:[e===`create`&&(0,R.jsx)(en,{className:`h-3 w-3`}),e===`edit`&&(0,R.jsx)(ln,{className:`h-3 w-3`}),e===`view`&&(0,R.jsx)(On,{className:`h-3 w-3`}),e===`create`?`New`:e===`edit`?`Edit`:`Read-only`]},e))}),o!==`create`&&(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsxs)(em,{value:u,onValueChange:e=>d(e),disabled:f||c.length===0,children:[(0,R.jsx)(nm,{className:`h-8 w-[260px] text-xs`,children:(0,R.jsx)(tm,{placeholder:f?`Loading…`:c.length===0?`No records yet`:`Pick a record`})}),(0,R.jsx)(am,{children:c.map(e=>(0,R.jsx)(sm,{value:String(e.id),children:e.label},String(e.id)))})]}),(0,R.jsx)(B,{size:`sm`,variant:`ghost`,className:`h-8 w-8 p-0`,onClick:()=>_(e=>e+1),title:`Refresh records`,children:(0,R.jsx)(Ut,{className:`h-3.5 w-3.5`})})]})]}),(0,R.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:[m&&(0,R.jsxs)(`div`,{className:`mb-3 rounded border border-destructive/40 bg-destructive/5 p-2 text-xs text-destructive`,children:[`Failed to load records: `,m]}),o!==`create`&&!f&&c.length===0&&!m&&(0,R.jsxs)(`div`,{className:`mb-3 rounded border border-dashed p-3 text-xs text-muted-foreground`,children:[`No records exist for `,(0,R.jsx)(`code`,{children:t}),`. Switch to`,` `,(0,R.jsx)(`button`,{className:`underline underline-offset-2`,onClick:()=>s(`create`),children:`New`}),` `,`to create one.`]}),(0,R.jsx)(Yr,{schema:{...y,onSuccess:b,onError:x},dataSource:i},`${o}:${v??`new`}:${g}:hmr-${a}`)]}),(0,R.jsx)(Em,{objectName:t})]})}function Om(e){let t=e?.name??e?.label??e?.title??e?.subject??e?.email??e?.code;return t?`${t} (${e.id})`:String(e?.id??``)}var km=s(`relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7`,{variants:{variant:{default:`bg-background text-foreground`,destructive:`border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive`}},defaultVariants:{variant:`default`}}),Am=F.forwardRef(({className:e,variant:t,...n},r)=>(0,R.jsx)(`div`,{ref:r,role:`alert`,className:z(km({variant:t}),e),...n}));Am.displayName=`Alert`;var jm=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`h5`,{ref:n,className:z(`mb-1 font-medium leading-none tracking-tight`,e),...t}));jm.displayName=`AlertTitle`;var Mm=F.forwardRef(({className:e,...t},n)=>(0,R.jsx)(`div`,{ref:n,className:z(`text-sm [&_p]:leading-relaxed`,e),...t}));Mm.displayName=`AlertDescription`;var Nm=[`list`,`grid`,`table`,`kanban`,`board`,`calendar`,`form`,`detail`],Pm={list:`List`,grid:`Grid`,table:`Table`,kanban:`Kanban`,board:`Board`,calendar:`Calendar`,timeline:`Timeline`,gallery:`Gallery`,map:`Map`,gantt:`Gantt`,form:`Form`,detail:`Detail`},Fm={list:lt,grid:$e,table:$e,kanban:tn,board:tn,calendar:_n,timeline:_n,gallery:$e,map:$e,gantt:$e,form:yn,detail:yn};function Im(e,t){return e?.type?.replace(/^object-/,``)||e?.viewType||t||`form`}function Lm(e,t,n){return typeof e?.label==`string`?e.label:e?.label&&typeof e.label==`object`&&`defaultValue`in e.label?String(e.label.defaultValue):Pm[t]||n}var Rm=(0,F.lazy)(async()=>({default:(await pe(()=>import(`./vendor-object-ui-views-CyaLQwFl.js`).then(e=>e.n),__vite__mapDeps([0,1,2,3,4,5,6,7]))).ObjectCalendar})),zm=(0,F.lazy)(async()=>({default:(await pe(()=>import(`./vendor-object-ui-views-CyaLQwFl.js`).then(e=>e.t),__vite__mapDeps([0,1,2,3,4,5,6,7]))).ObjectTimeline}));function Bm({type:e,name:t,spec:n,objectName:r,className:i}){let a=mp(),{version:o}=Bu(),s=(0,F.useMemo)(()=>{if(e!==`view`||!n||typeof n!=`object`)return[];let t=[];for(let e of Nm){let r=n[e];if(r&&typeof r==`object`){let n=Im(r,e);t.push({key:e,label:Lm(r,n,e),icon:Fm[n]??$e,viewType:n,spec:r})}}let r=n.listViews;if(r&&typeof r==`object`)for(let[e,n]of Object.entries(r)){if(!n||typeof n!=`object`)continue;let r=Im(n);t.push({key:`listViews.${e}`,label:Lm(n,r,e),icon:Fm[r]??$e,viewType:r,spec:n})}return t},[e,n]),[c,l]=(0,F.useState)(null),u=(0,F.useMemo)(()=>s.length===0?null:s.find(e=>e.key===c)??s[0],[s,c]),d=(0,F.useMemo)(()=>{if(e===`object`&&t)return(0,R.jsx)(Jr,{schema:{type:`object-grid`,objectName:t,mode:`read`},dataSource:a,className:i});if(e===`dashboard`&&n)return(0,R.jsx)(Zr,{schema:{type:`dashboard`,...n},dataSource:a,className:i});if(e===`report`&&n)return(0,R.jsx)(Qr,{schema:n,dataSource:a,className:i});if(e!==`view`||!n)return(0,R.jsx)(Hm,{type:e,spec:n});let o=u?u.spec:n,s=u?u.viewType:Im(n,`form`),c=o?.data?.object||o?.objectName||n?.data?.object||n?.objectName||r||t||``;switch(s){case`form`:return(0,R.jsx)(Dm,{spec:o,objectName:c,className:i});case`kanban`:case`board`:{let e=o?.kanban??{},t=e.groupByField??e.groupBy??o?.groupBy??o?.groupByField,n=Array.isArray(e.columns)?e.columns:Array.isArray(o?.columns)&&o.columns.every(e=>typeof e==`string`)?o.columns:void 0,{columns:r,kanban:s,data:l,...u}=o??{};return(0,R.jsx)(Xr,{schema:{type:`object-kanban`,objectName:c,...u,...t?{groupBy:t}:{},...n?{cardFields:n}:{}},dataSource:a,className:i})}case`grid`:case`list`:case`table`:return(0,R.jsx)(Jr,{schema:{type:`object-grid`,objectName:c,mode:`read`,...o},dataSource:a,className:i});case`detail`:return(0,R.jsx)(Mr,{schema:{type:`object-detail`,objectName:c,...o},dataSource:a,className:i});case`calendar`:{let e=o?.calendar??{},{data:t,...n}=o??{};return(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(Vm,{}),children:(0,R.jsx)(Rm,{schema:{type:`object-calendar`,objectName:c,...n,...e.startDateField?{startDateField:e.startDateField}:{},...e.endDateField?{endDateField:e.endDateField}:{},...e.titleField?{titleField:e.titleField}:{},...e.colorField?{colorField:e.colorField}:{}},dataSource:a,className:i})})}case`timeline`:{let e=o?.timeline??{},{data:t,...n}=o??{};return(0,R.jsx)(F.Suspense,{fallback:(0,R.jsx)(Vm,{}),children:(0,R.jsx)(zm,{schema:{type:`object-timeline`,objectName:c,...n,...e.startDateField?{startDateField:e.startDateField}:{},...e.endDateField?{endDateField:e.endDateField}:{},...e.titleField?{titleField:e.titleField}:{},...e.descriptionField?{descriptionField:e.descriptionField}:{},...e.groupByField?{groupByField:e.groupByField}:{},...e.colorField?{colorField:e.colorField}:{},...e.scale?{scale:e.scale}:{}},dataSource:a,className:i})})}default:return(0,R.jsx)(Hm,{type:`view/${s}`,spec:o})}},[e,t,n,r,i,a,u]),f=u?.viewType===`form`||e===`view`&&!u&&(n?.viewType===`form`||!n?.viewType&&(n?.sections||n?.groups)),p=(0,F.useMemo)(()=>{if(e===`object`)return t??``;let i=u?u.spec:n;return i?.data?.object||i?.objectName||n?.data?.object||n?.objectName||r||t||``},[e,t,n,r,u]);return(0,R.jsxs)(`div`,{className:`flex h-full flex-col`,children:[s.length>1&&(0,R.jsx)(`div`,{className:`border-b`,children:(0,R.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto px-3 py-1.5 scrollbar-thin`,children:s.map(e=>{let t=e.icon;return(0,R.jsxs)(B,{size:`sm`,variant:e.key===u?.key?`default`:`ghost`,className:`h-6 shrink-0 gap-1 px-2 text-[11px]`,onClick:()=>l(e.key),title:e.viewType,children:[(0,R.jsx)(t,{className:`h-3 w-3`}),e.label]},e.key)})})}),(0,R.jsx)(`div`,{className:f?`min-h-0 flex-1 overflow-hidden`:`min-h-0 flex-1 overflow-auto p-4`,children:(0,R.jsx)(`div`,{className:`h-full`,children:d},`hmr-${o}`)}),!f&&(0,R.jsx)(Em,{objectName:p})]})}function Vm(){return(0,R.jsx)(`div`,{className:`flex h-40 items-center justify-center text-sm text-muted-foreground`,children:`Loading preview…`})}function Hm({type:e,spec:t}){return(0,R.jsxs)(Am,{children:[(0,R.jsx)(Be,{className:`h-4 w-4`}),(0,R.jsxs)(jm,{children:[`No live preview for `,e]}),(0,R.jsxs)(Mm,{className:`mt-2 text-xs`,children:[`Studio doesn't render this metadata type yet. The raw spec is shown below for reference.`,(0,R.jsx)(`pre`,{className:`mt-3 max-h-64 overflow-auto rounded bg-muted/40 p-3 font-mono text-[11px] leading-relaxed`,children:JSON.stringify(t??null,null,2)})]})]})}function Um({metadataType:e,metadataName:t,data:n,packageId:r}){let i=L(),a=Bf(be({strict:!1}).projectId)??i,{version:o}=Bu(),[s,c]=(0,F.useState)(n??null),[l,u]=(0,F.useState)(!n),[d,f]=(0,F.useState)(null);(0,F.useEffect)(()=>{if(n){c(n),u(!1);return}let i=!0;return u(!0),f(null),a.meta.getItem(e,t,r?{packageId:r}:void 0).then(e=>{i&&c(e?.item??e??null)}).catch(e=>{i&&f(e instanceof Error?e.message:String(e))}).finally(()=>{i&&u(!1)}),()=>{i=!1}},[a,e,t,r,n,o]);let{spec:p,objectName:m}=(0,F.useMemo)(()=>{if(!s)return{spec:null,objectName:void 0};let e=s?.spec??s;return{spec:e,objectName:e?.data?.object??e?.objectName??e?.list?.data?.object??e?.form?.data?.object??void 0}},[s]);return l?(0,R.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:`Loading preview…`}):d||!p?(0,R.jsx)(`div`,{className:`flex h-full items-center justify-center p-6`,children:(0,R.jsxs)(`div`,{className:`max-w-md rounded-md border border-dashed bg-muted/30 p-6 text-center text-sm text-muted-foreground`,children:[(0,R.jsx)(`p`,{className:`font-medium text-foreground`,children:`Nothing to preview`}),(0,R.jsxs)(`p`,{className:`mt-1`,children:[`We couldn't find a definition for`,` `,(0,R.jsx)(`code`,{className:`font-mono text-xs`,children:t}),`. It may have been deleted or never existed in this package.`]})]})}):(0,R.jsx)(`div`,{className:`flex h-full flex-col`,children:(0,R.jsx)(Bm,{type:e,name:t,spec:p,objectName:m})})}var Wm={manifest:mf({id:`objectstack.view-preview`,name:`View Live Preview`,version:`1.0.0`,description:`Renders view, page, report, and dashboard metadata as a live preview via @object-ui.`,contributes:{metadataViewers:[{id:`view-live-preview`,metadataTypes:[`view`,`page`,`report`,`dashboard`],label:`Live Preview`,priority:50,modes:[`preview`]}]}}),activate(e){e.registerViewer(`view-live-preview`,Um)}},Gm=new Set([`flow`,`workflow`,`approval`]),Km={create:{icon:en,color:`text-green-600 dark:text-green-400`,label:`Created`},update:{icon:ln,color:`text-blue-600 dark:text-blue-400`,label:`Updated`},delete:{icon:Fn,color:`text-red-600 dark:text-red-400`,label:`Deleted`},rename:{icon:Sn,color:`text-amber-600 dark:text-amber-400`,label:`Renamed`}};function qm(e){if(!e)return`—`;let t=e.indexOf(`:`);return(t>=0?e.slice(t+1):e).slice(0,8)}function Jm(e){try{return new Date(e).toLocaleString()}catch{return e}}function Ym(e){try{let t=new Date(e).getTime(),n=Date.now()-t,r=Math.round(n/1e3);if(r<60)return`${r}s ago`;let i=Math.round(r/60);if(i<60)return`${i}m ago`;let a=Math.round(i/60);return a<24?`${a}h ago`:`${Math.round(a/24)}d ago`}catch{return``}}function Xm({event:e,isLast:t}){let[n,r]=(0,F.useState)(!1),i=Km[e.op]??{icon:nn,color:`text-muted-foreground`,label:e.op},a=i.icon;return(0,R.jsxs)(`div`,{className:`relative pl-10`,children:[!t&&(0,R.jsx)(`div`,{className:`absolute left-[18px] top-9 bottom-0 w-px bg-border`,"aria-hidden":!0}),(0,R.jsx)(`div`,{className:`absolute left-2 top-2 grid h-8 w-8 place-items-center rounded-full border border-border bg-background ${i.color}`,children:(0,R.jsx)(a,{className:`h-4 w-4`})}),(0,R.jsxs)(`div`,{className:`pb-4`,children:[(0,R.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`group flex w-full items-start justify-between rounded border border-transparent px-2 py-1 text-left hover:border-border hover:bg-accent/40`,children:[(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:i.label}),(0,R.jsxs)(G,{variant:`outline`,className:`text-[10px] font-mono`,children:[`#`,e.seq]}),(0,R.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 text-[11px]`,children:qm(e.hash)}),(0,R.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by `,e.actor]}),(0,R.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`· via `,e.source]})]}),(0,R.jsxs)(`div`,{className:`mt-0.5 text-xs text-muted-foreground`,children:[(0,R.jsx)(`time`,{dateTime:e.ts,title:Jm(e.ts),children:Ym(e.ts)}),(0,R.jsx)(`span`,{className:`ml-2`,children:Jm(e.ts)}),e.message&&(0,R.jsxs)(`span`,{className:`ml-2 italic`,children:[`— `,e.message]}),e.previousName&&(0,R.jsxs)(`span`,{className:`ml-2`,children:[`(was: `,(0,R.jsx)(`code`,{className:`text-[11px]`,children:e.previousName}),`)`]})]})]}),n?(0,R.jsx)(We,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground`}):(0,R.jsx)(je,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground`})]}),n&&(0,R.jsxs)(`div`,{className:`mt-2 ml-2 grid grid-cols-2 gap-x-4 gap-y-1 rounded border bg-muted/30 px-3 py-2 text-xs`,children:[(0,R.jsx)(`div`,{className:`text-muted-foreground`,children:`hash`}),(0,R.jsx)(`code`,{className:`break-all`,children:e.hash??`—`}),(0,R.jsx)(`div`,{className:`text-muted-foreground`,children:`parent hash`}),(0,R.jsx)(`code`,{className:`break-all`,children:e.parentHash??`—`}),(0,R.jsx)(`div`,{className:`text-muted-foreground`,children:`ref`}),(0,R.jsxs)(`code`,{children:[e.ref.org?`${e.ref.org}/`:``,e.ref.type,`/`,e.ref.name]}),(0,R.jsx)(`div`,{className:`text-muted-foreground`,children:`actor`}),(0,R.jsx)(`code`,{children:e.actor}),(0,R.jsx)(`div`,{className:`text-muted-foreground`,children:`source`}),(0,R.jsx)(`code`,{children:e.source}),(0,R.jsx)(`div`,{className:`text-muted-foreground`,children:`timestamp`}),(0,R.jsx)(`code`,{children:e.ts})]})]})]})}function Zm({metadataType:e,metadataName:t}){let n=L(),r=Bf(be({strict:!1}).projectId)??n,[i,a]=(0,F.useState)(null),[o,s]=(0,F.useState)(!0),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(0),f=Gm.has(e);(0,F.useEffect)(()=>{let n=!1;return s(!0),l(null),(async()=>{try{let i=await r.meta.getHistory(e,t,{limit:200});if(n)return;let o=Array.isArray(i?.events)?i.events:[];o.sort((e,t)=>t.seq-e.seq),a(o)}catch(e){if(n)return;l(e?.message??String(e)),a([])}finally{n||s(!1)}})(),()=>{n=!0}},[r,e,t,u]);let p=(0,F.useMemo)(()=>{if(!i?.length)return null;let e=i.find(e=>e.op===`create`),t=i[0];return{total:i.length,created:e,latest:t}},[i]);return(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b px-4 py-2`,children:[(0,R.jsx)(`h2`,{className:`text-sm font-semibold`,children:`History`}),f&&(0,R.jsxs)(G,{variant:`secondary`,className:`gap-1`,children:[(0,R.jsx)(rn,{className:`h-3 w-3`}),` Pinned`]}),p&&(0,R.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[p.total,` event`,p.total===1?``:`s`,p.latest&&(0,R.jsxs)(R.Fragment,{children:[` · last change `,Ym(p.latest.ts)]})]}),(0,R.jsx)(`div`,{className:`ml-auto`,children:(0,R.jsx)(B,{variant:`outline`,size:`sm`,onClick:()=>d(e=>e+1),disabled:o,children:`Refresh`})})]}),f&&(0,R.jsxs)(`div`,{className:`border-b bg-muted/30 px-4 py-2 text-xs text-muted-foreground`,children:[`This metadata type is `,(0,R.jsx)(`strong`,{children:`execution-pinned`}),` (ADR-0009): in-flight transactions may reference any version below by its content hash, so history rows for this item are retained indefinitely and never garbage-collected.`]}),(0,R.jsx)(ll,{className:`flex-1`,children:(0,R.jsxs)(`div`,{className:`px-4 py-4`,children:[o&&(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsx)(H,{className:`h-12 w-full`}),(0,R.jsx)(H,{className:`h-12 w-full`}),(0,R.jsx)(H,{className:`h-12 w-full`})]}),!o&&c&&(0,R.jsxs)(`div`,{className:`rounded border border-destructive/50 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:[`Failed to load history: `,c]}),!o&&!c&&i&&i.length===0&&(0,R.jsxs)(`div`,{className:`rounded border border-dashed px-4 py-8 text-center text-sm text-muted-foreground`,children:[(0,R.jsx)(`p`,{children:`No history events recorded for this item.`}),(0,R.jsx)(`p`,{className:`mt-1 text-xs`,children:`Edits to this metadata appear here. Some built-in types (e.g. objects) keep their history in source control instead.`})]}),!o&&!c&&i&&i.length>0&&(0,R.jsx)(`div`,{className:`relative`,children:i.map((e,t)=>(0,R.jsx)(Xm,{event:e,isLast:t===i.length-1},`${e.seq}-${e.hash??`null`}`))})]})})]})}var Qm=[Vp,yp,Qp,mm,Tm,Wm,{manifest:mf({id:`objectstack.history`,name:`History Timeline`,description:`Audit timeline of sys_metadata_history events for any metadata item`,contributes:{metadataViewers:[{id:`history-timeline`,metadataTypes:[`*`],label:`History`,priority:5,modes:[`history`]}]}}),activate(e){e.registerViewer(`history-timeline`,Zm)}},{manifest:mf({id:`objectstack.ui-protocol`,name:`UI Protocol`,version:`1.0.0`,description:`Sidebar groups and icons for UI metadata types.`,contributes:{sidebarGroups:[{key:`ui`,label:`UI`,icon:`app-window`,metadataTypes:[`action`,`view`,`page`,`dashboard`,`report`,`theme`],order:20}],metadataIcons:[{metadataType:`action`,label:`Actions`,icon:`zap`},{metadataType:`view`,label:`Views`,icon:`eye`},{metadataType:`page`,label:`Pages`,icon:`file-code`},{metadataType:`dashboard`,label:`Dashboards`,icon:`bar-chart-3`},{metadataType:`report`,label:`Reports`,icon:`file-text`},{metadataType:`theme`,label:`Themes`,icon:`palette`}]}}),activate(e){e.registerMetadataIcon(`action`,Qt,`Actions`),e.registerMetadataIcon(`view`,On,`Views`),e.registerMetadataIcon(`page`,fn,`Pages`),e.registerMetadataIcon(`dashboard`,Ue,`Dashboards`),e.registerMetadataIcon(`report`,yn,`Reports`),e.registerMetadataIcon(`theme`,Ln,`Themes`)}},{manifest:mf({id:`objectstack.automation-protocol`,name:`Automation Protocol`,version:`1.0.0`,description:`Sidebar groups and icons for automation metadata types.`,contributes:{sidebarGroups:[{key:`automation`,label:`Automation`,icon:`workflow`,metadataTypes:[`flow`,`workflow`,`approval`,`webhook`],order:30}],metadataIcons:[{metadataType:`flow`,label:`Flows`,icon:`workflow`},{metadataType:`workflow`,label:`Workflows`,icon:`workflow`},{metadataType:`approval`,label:`Approvals`,icon:`check-square`},{metadataType:`webhook`,label:`Webhooks`,icon:`webhook`}]}}),activate(e){e.registerMetadataIcon(`flow`,bn,`Flows`),e.registerMetadataIcon(`workflow`,bn,`Workflows`),e.registerMetadataIcon(`approval`,nt,`Approvals`),e.registerMetadataIcon(`webhook`,Dn,`Webhooks`)}},{manifest:mf({id:`objectstack.security-protocol`,name:`Security Protocol`,version:`1.0.0`,description:`Sidebar groups and icons for security metadata types.`,contributes:{sidebarGroups:[{key:`security`,label:`Security`,icon:`shield`,metadataTypes:[`role`,`permission`,`profile`,`sharingRule`,`policy`],order:40}],metadataIcons:[{metadataType:`role`,label:`Roles`,icon:`user-cog`},{metadataType:`permission`,label:`Permissions`,icon:`lock`},{metadataType:`profile`,label:`Profiles`,icon:`shield`},{metadataType:`sharingRule`,label:`Sharing Rules`,icon:`shield`},{metadataType:`policy`,label:`Policies`,icon:`shield`}]}}),activate(e){e.registerMetadataIcon(`role`,mn,`Roles`),e.registerMetadataIcon(`permission`,rn,`Permissions`),e.registerMetadataIcon(`profile`,dt,`Profiles`),e.registerMetadataIcon(`sharingRule`,dt,`Sharing Rules`),e.registerMetadataIcon(`policy`,dt,`Policies`)}},{manifest:mf({id:`objectstack.ai-protocol`,name:`AI Protocol`,version:`1.0.0`,description:`Sidebar groups and icons for AI metadata types.`,contributes:{sidebarGroups:[{key:`ai`,label:`AI`,icon:`bot`,metadataTypes:[`agent`,`tool`,`ragPipeline`],order:50}],metadataIcons:[{metadataType:`agent`,label:`Agents`,icon:`bot`},{metadataType:`tool`,label:`Tools`,icon:`wrench`},{metadataType:`ragPipeline`,label:`RAG Pipelines`,icon:`book-open`}]}}),activate(e){e.registerMetadataIcon(`agent`,ut,`Agents`),e.registerMetadataIcon(`tool`,dn,`Tools`),e.registerMetadataIcon(`ragPipeline`,De,`RAG Pipelines`)}},{manifest:mf({id:`objectstack.api-protocol`,name:`API Protocol`,version:`1.0.0`,description:`Sidebar groups and icons for API metadata types.`,contributes:{sidebarGroups:[{key:`api`,label:`API`,icon:`globe`,metadataTypes:[`api`,`connector`],order:60}],metadataIcons:[{metadataType:`api`,label:`APIs`,icon:`globe`},{metadataType:`connector`,label:`Connectors`,icon:`link-2`}]}}),activate(e){e.registerMetadataIcon(`api`,wt,`APIs`),e.registerMetadataIcon(`connector`,Ke,`Connectors`)}}];function $m({children:e}){let{user:t,loading:n,logout:r}=ju();return(0,F.useEffect)(()=>{n||t||Pu(window.location.pathname+window.location.search)},[t,n]),n?(0,R.jsx)(`div`,{className:`flex min-h-screen w-full flex-1 items-center justify-center bg-background`,children:(0,R.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted border-t-primary`})}):t?t.role===`admin`?(0,R.jsx)(yc,{children:(0,R.jsx)(Fd,{children:e})}):(0,R.jsx)(Id,{user:t,onSwitchAccount:async()=>{await r(),Pu(window.location.pathname+window.location.search)}}):null}function eh(){let{user:e}=ju();return!e||e.role!==`admin`?null:(0,R.jsx)(Vl,{})}function th(){let e=zf();return e?(0,R.jsx)(Gs,{client:e,children:(0,R.jsx)(Au,{children:(0,R.jsx)(Ud,{plugins:Qm,children:(0,R.jsx)(qs,{children:(0,R.jsxs)(tu,{children:[(0,R.jsx)($m,{children:(0,R.jsx)(ye,{})}),(0,R.jsx)(cl,{}),(0,R.jsx)(eh,{})]})})})})}):(0,R.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-background`,children:(0,R.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,R.jsx)(`div`,{className:`h-8 w-8 mx-auto animate-spin rounded-full border-4 border-muted border-t-primary`}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Connecting to ObjectStack…`})]})})}var nh=Se({component:th});function rh({packages:e,selectedPackage:t,...n}){let r=ve(),i=Te();sh(i.pathname);let a=i.pathname.split(`/`).filter(Boolean)[0],o=t?.manifest?.id??(a===`all`?`all`:e[0]?.manifest?.id)??null,s=e=>{let t=i.pathname.replace(/\/$/,``),n=a??``,r=n?`/${n}`:``;return n?e===`home`?t===r:t.startsWith(`${r}/${e}`):!1};return(0,R.jsxs)(bc,{collapsible:`icon`,...n,children:[(0,R.jsx)(Tc,{className:`border-b`,children:(0,R.jsx)(Nc,{children:(0,R.jsx)(Pc,{children:(0,R.jsx)(ih,{})})})}),(0,R.jsx)(Oc,{children:(0,R.jsx)(kc,{children:(0,R.jsx)(Mc,{children:(0,R.jsx)(Nc,{children:Wu.map(e=>{let t=e.icon,n=s(e.key);return(0,R.jsx)(Pc,{children:(0,R.jsxs)(Fc,{tooltip:e.hint,isActive:n,onClick:()=>{o&&r({to:e.key===`home`?`/${o}`:`/${o}/${e.key}`})},children:[(0,R.jsx)(t,{className:`h-4 w-4`}),(0,R.jsx)(`span`,{children:e.label})]})},e.key)})})})})}),(0,R.jsx)(Ec,{})]})}function ih(){let{state:e,toggleSidebar:t}=vc(),n=e===`collapsed`;return(0,R.jsxs)(Fc,{size:`sm`,onClick:t,tooltip:n?`Expand sidebar (⌘B)`:`Collapse sidebar (⌘B)`,"aria-label":n?`Expand sidebar`:`Collapse sidebar`,className:`h-7 text-muted-foreground hover:text-foreground`,children:[(0,R.jsx)(n?kt:Mn,{className:`size-4`}),(0,R.jsx)(`span`,{className:`text-xs`,children:n?`Expand`:`Collapse`})]})}var ah=[/^\/[^/]+\/objects\/[^/]+/,/^\/[^/]+\/metadata\/[^/]+\/[^/]+/];function oh(e){return ah.some(t=>t.test(e))}function sh(e){let{open:t,setOpen:n}=vc(),r=(0,F.useRef)(null);(0,F.useEffect)(()=>{if(oh(e))r.current===null&&(r.current=t,t&&n(!1));else if(r.current!==null){let e=r.current;r.current=null,e!==t&&n(e)}},[e])}function ch(){let{package:e}=be({from:`/$package`}),t=ve(),{packages:n,selectedPackage:r}=Uu(e);return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsx)(rh,{packages:n,selectedPackage:r,onSelectPackage:(0,F.useCallback)(e=>{let n=e.manifest?.id;n&&t({to:`/$package`,params:{package:n}})},[t])}),(0,R.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden bg-background`,children:(0,R.jsx)(ye,{})})]})}var lh=_e(`/$package`)({component:ch});function uh(){let e=ve(),{user:t,loading:n}=ju(),{packages:r,loading:i}=Uu();return(0,F.useEffect)(()=>{if(n||!t||i)return;let a=r[0];a?.manifest?.id&&e({to:`/$package`,params:{package:a.manifest.id},replace:!0})},[t,n,r,i,e]),n||i?(0,R.jsx)(`div`,{className:`flex min-h-screen w-full items-center justify-center bg-background`,children:(0,R.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted border-t-primary`})}):r.length?null:(0,R.jsx)(`div`,{className:`flex min-h-screen w-full items-center justify-center bg-background p-8`,children:(0,R.jsxs)(`div`,{className:`max-w-md space-y-3 text-center`,children:[(0,R.jsx)(`h1`,{className:`text-lg font-semibold`,children:`No packages installed`}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Studio browses metadata from packages installed on the connected backend. Install a package (for example an app or a built-in module) and refresh this page.`})]})})}var dh=_e(`/`)({component:uh}),fh=12;function ph(e){return`objectstack.recent.${e??`global`}`}function mh(e){try{let t=localStorage.getItem(ph(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>e&&e.type&&e.name):[]}catch{return[]}}function hh(e){let[t,n]=(0,F.useState)(()=>mh(e));return(0,F.useEffect)(()=>{n(mh(e))},[e]),(0,F.useEffect)(()=>{let t=t=>{t.key===ph(e)&&n(mh(e))};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e]),{items:t,record:(0,F.useCallback)(t=>{if(!t.type||!t.name)return;let r=mh(e).filter(e=>!(e.type===t.type&&e.name===t.name));r.unshift({...t,ts:Date.now()});let i=r.slice(0,fh);try{localStorage.setItem(ph(e),JSON.stringify(i))}catch{}n(i)},[e]),clear:(0,F.useCallback)(()=>{try{localStorage.removeItem(ph(e))}catch{}n([])},[e])}}function gh({packageId:e}){return(0,R.jsx)(`div`,{className:`flex flex-1 items-start justify-center p-4 md:p-8 overflow-auto`,children:(0,R.jsxs)(`div`,{className:`w-full max-w-3xl space-y-6`,children:[(0,R.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,R.jsx)(`div`,{className:`inline-flex items-center justify-center h-12 w-12 rounded-xl bg-primary/10 text-primary`,children:(0,R.jsx)(st,{className:`h-6 w-6`})}),(0,R.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Welcome to Studio`}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-prose mx-auto`,children:`This package looks empty. Pick a starting point — every option below produces real metadata you can edit, preview, and deploy.`})]}),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,R.jsxs)(X,{className:`flex flex-col`,children:[(0,R.jsxs)(Z,{children:[(0,R.jsx)(`div`,{className:`h-9 w-9 rounded-md bg-primary/10 text-primary inline-flex items-center justify-center mb-2`,children:(0,R.jsx)(In,{className:`h-4 w-4`})}),(0,R.jsx)(Q,{className:`text-base`,children:`Create your first object`}),(0,R.jsx)(bp,{children:`Start with a table. Add fields, relations, validations.`})]}),(0,R.jsx)($,{className:`mt-auto`,children:(0,R.jsx)(B,{asChild:!0,className:`w-full`,size:`sm`,children:(0,R.jsx)(we,{to:`/$package/objects`,params:{package:e},children:`New object`})})})]}),(0,R.jsxs)(X,{className:`flex flex-col`,children:[(0,R.jsxs)(Z,{children:[(0,R.jsx)(`div`,{className:`h-9 w-9 rounded-md bg-primary/10 text-primary inline-flex items-center justify-center mb-2`,children:(0,R.jsx)(zt,{className:`h-4 w-4`})}),(0,R.jsx)(Q,{className:`text-base`,children:`Try the Playground`}),(0,R.jsx)(bp,{children:`Issue REST / ObjectQL calls and preview forms live.`})]}),(0,R.jsx)($,{className:`mt-auto`,children:(0,R.jsx)(B,{asChild:!0,variant:`outline`,className:`w-full`,size:`sm`,children:(0,R.jsx)(we,{to:`/$package/playground`,params:{package:e},children:`Open Playground`})})})]}),(0,R.jsxs)(X,{className:`flex flex-col`,children:[(0,R.jsxs)(Z,{children:[(0,R.jsx)(`div`,{className:`h-9 w-9 rounded-md bg-primary/10 text-primary inline-flex items-center justify-center mb-2`,children:(0,R.jsx)(De,{className:`h-4 w-4`})}),(0,R.jsx)(Q,{className:`text-base`,children:`Browse examples`}),(0,R.jsx)(bp,{children:`Read defineStack() recipes for todo, CRM, and BI apps.`})]}),(0,R.jsx)($,{className:`mt-auto`,children:(0,R.jsx)(B,{asChild:!0,variant:`outline`,className:`w-full`,size:`sm`,children:(0,R.jsx)(`a`,{href:`/docs/getting-started`,target:`_blank`,rel:`noreferrer`,children:`Open docs`})})})]})]}),(0,R.jsxs)(`div`,{className:`text-center text-xs text-muted-foreground`,children:[`Tip — press `,(0,R.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted`,children:`?`}),` to see all keyboard shortcuts. Press`,` `,(0,R.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted`,children:`⌘K`}),` for the command palette.`]})]})})}var _h={sky:{bg:`bg-sky-50 dark:bg-sky-950/40`,fg:`text-sky-600 dark:text-sky-400`},amber:{bg:`bg-amber-50 dark:bg-amber-950/40`,fg:`text-amber-600 dark:text-amber-400`},violet:{bg:`bg-violet-50 dark:bg-violet-950/40`,fg:`text-violet-600 dark:text-violet-400`},emerald:{bg:`bg-emerald-50 dark:bg-emerald-950/40`,fg:`text-emerald-600 dark:text-emerald-400`},rose:{bg:`bg-rose-50 dark:bg-rose-950/40`,fg:`text-rose-600 dark:text-rose-400`},slate:{bg:`bg-slate-100 dark:bg-slate-900/40`,fg:`text-slate-600 dark:text-slate-400`}};function vh({icon:e,title:t,description:n,badge:r,tone:i=`sky`,onClick:a}){let o=_h[i];return(0,R.jsxs)(X,{onClick:a,className:`group relative cursor-pointer overflow-hidden border-border/60 p-4 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-md`,children:[(0,R.jsx)(`div`,{className:`mb-3 inline-flex h-9 w-9 items-center justify-center rounded-lg ${o.bg} ${o.fg} ring-1 ring-inset ring-current/10 transition group-hover:scale-110`,children:(0,R.jsx)(e,{className:`h-4 w-4`})}),(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,R.jsx)(`h3`,{className:`text-sm font-semibold tracking-tight`,children:t}),r&&(0,R.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[9px] font-medium uppercase tracking-wide text-muted-foreground`,children:r})]}),(0,R.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:n})]})}var yh=e=>e?``:` // ⚠ replace with your object`,bh=[{type:`object`,label:`Object`,icon:In,description:`A table of records with fields, validations, and permissions.`,dir:`objects`,suffix:`.object.ts`,snippet:(e,t)=>`import { defineObject } from '@objectstack/spec';
|
|
22
|
-
|
|
23
|
-
export default defineObject({
|
|
24
|
-
name: '${e}',
|
|
25
|
-
label: '${t}',
|
|
26
|
-
fields: {
|
|
27
|
-
name: { name: 'name', type: 'text', label: 'Name', required: true, maxLength: 255 },
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
`},{type:`view`,label:`Grid view`,icon:Nn,description:`A data table over an existing object.`,dir:`views`,suffix:`.view.ts`,snippet:(e,t,n)=>`import { defineView } from '@objectstack/spec';
|
|
31
|
-
|
|
32
|
-
export default defineView({
|
|
33
|
-
name: '${e}',
|
|
34
|
-
label: '${t}',
|
|
35
|
-
objectName: '${n??`account`}',${yh(n)}
|
|
36
|
-
viewType: 'grid',
|
|
37
|
-
columns: ['name'],
|
|
38
|
-
});
|
|
39
|
-
`},{type:`app`,label:`App`,icon:zn,description:`Top-level navigation container with tabs.`,dir:`apps`,suffix:`.app.ts`,snippet:(e,t,n)=>`import { defineApp } from '@objectstack/spec';
|
|
40
|
-
|
|
41
|
-
export default defineApp({
|
|
42
|
-
name: '${e}',
|
|
43
|
-
label: '${t}',
|
|
44
|
-
tabs: [
|
|
45
|
-
{ type: 'object', objectName: '${n??`account`}' },
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
`},{type:`page`,label:`Page`,icon:yn,description:`A custom screen composed of SDUI blocks.`,dir:`pages`,suffix:`.page.ts`,snippet:(e,t)=>`import { definePage } from '@objectstack/spec';
|
|
49
|
-
|
|
50
|
-
export default definePage({
|
|
51
|
-
name: '${e}',
|
|
52
|
-
label: '${t}',
|
|
53
|
-
route: '/${e.replace(/_/g,`-`)}',
|
|
54
|
-
blocks: [
|
|
55
|
-
{ type: 'heading', level: 1, text: '${t}' },
|
|
56
|
-
],
|
|
57
|
-
});
|
|
58
|
-
`},{type:`dashboard`,label:`Dashboard`,icon:ft,description:`A grid of widgets, charts, and KPIs.`,dir:`dashboards`,suffix:`.dashboard.ts`,snippet:(e,t)=>`import { defineDashboard } from '@objectstack/spec';
|
|
59
|
-
|
|
60
|
-
export default defineDashboard({
|
|
61
|
-
name: '${e}',
|
|
62
|
-
label: '${t}',
|
|
63
|
-
widgets: [],
|
|
64
|
-
});
|
|
65
|
-
`},{type:`report`,label:`Report`,icon:Ue,description:`A saved query with columns, filters, sorts, and grouping.`,dir:`reports`,suffix:`.report.ts`,snippet:(e,t,n)=>`import { defineReport } from '@objectstack/spec';
|
|
66
|
-
|
|
67
|
-
export default defineReport({
|
|
68
|
-
name: '${e}',
|
|
69
|
-
label: '${t}',
|
|
70
|
-
objectName: '${n??`account`}',${yh(n)}
|
|
71
|
-
columns: ['name'],
|
|
72
|
-
});
|
|
73
|
-
`},{type:`flow`,label:`Flow`,icon:bn,description:`A multi-step automation triggered by events or schedules.`,dir:`flows`,suffix:`.flow.ts`,snippet:(e,t)=>`import { defineFlow } from '@objectstack/spec';
|
|
74
|
-
|
|
75
|
-
export default defineFlow({
|
|
76
|
-
name: '${e}',
|
|
77
|
-
label: '${t}',
|
|
78
|
-
trigger: { type: 'manual' },
|
|
79
|
-
steps: [],
|
|
80
|
-
});
|
|
81
|
-
`},{type:`hook`,label:`Hook`,icon:Dn,description:`A side-effect that fires on object lifecycle events.`,dir:`hooks`,suffix:`.hook.ts`,snippet:(e,t,n)=>`import { defineHook } from '@objectstack/spec';
|
|
82
|
-
|
|
83
|
-
export default defineHook({
|
|
84
|
-
name: '${e}',
|
|
85
|
-
label: '${t}',
|
|
86
|
-
objectName: '${n??`account`}',${yh(n)}
|
|
87
|
-
on: 'after-create',
|
|
88
|
-
run: async (ctx) => {
|
|
89
|
-
// your side-effect here
|
|
90
|
-
},
|
|
91
|
-
});
|
|
92
|
-
`},{type:`approval`,label:`Approval`,icon:an,description:`A multi-step approval chain on an object.`,dir:`approvals`,suffix:`.approval.ts`,snippet:(e,t,n)=>`import { defineApproval } from '@objectstack/spec';
|
|
93
|
-
|
|
94
|
-
export default defineApproval({
|
|
95
|
-
name: '${e}',
|
|
96
|
-
label: '${t}',
|
|
97
|
-
objectName: '${n??`account`}',${yh(n)}
|
|
98
|
-
entryCriteria: { all: [] },
|
|
99
|
-
steps: [],
|
|
100
|
-
});
|
|
101
|
-
`},{type:`agent`,label:`Agent`,icon:ut,description:`An LLM-backed assistant with tools and instructions.`,dir:`agents`,suffix:`.agent.ts`,snippet:(e,t)=>`import { defineAgent } from '@objectstack/spec';
|
|
102
|
-
|
|
103
|
-
export default defineAgent({
|
|
104
|
-
name: '${e}',
|
|
105
|
-
label: '${t}',
|
|
106
|
-
model: 'openai/gpt-4',
|
|
107
|
-
instructions: 'You are a helpful assistant.',
|
|
108
|
-
tools: [],
|
|
109
|
-
});
|
|
110
|
-
`},{type:`tool`,label:`Tool`,icon:dn,description:`A typed function an Agent can invoke.`,dir:`tools`,suffix:`.tool.ts`,snippet:(e,t)=>`import { defineTool } from '@objectstack/spec';
|
|
111
|
-
import { z } from 'zod';
|
|
112
|
-
|
|
113
|
-
export default defineTool({
|
|
114
|
-
name: '${e}',
|
|
115
|
-
label: '${t}',
|
|
116
|
-
description: 'Describe what this tool does.',
|
|
117
|
-
parameters: z.object({}),
|
|
118
|
-
run: async (input, ctx) => {
|
|
119
|
-
return { ok: true };
|
|
120
|
-
},
|
|
121
|
-
});
|
|
122
|
-
`},{type:`skill`,label:`Skill`,icon:st,description:`A composable agent capability.`,dir:`skills`,suffix:`.skill.ts`,snippet:(e,t)=>`import { defineSkill } from '@objectstack/spec';
|
|
123
|
-
|
|
124
|
-
export default defineSkill({
|
|
125
|
-
name: '${e}',
|
|
126
|
-
label: '${t}',
|
|
127
|
-
description: '',
|
|
128
|
-
tools: [],
|
|
129
|
-
});
|
|
130
|
-
`},{type:`permission`,label:`Permission`,icon:rn,description:`A capability that can be granted to a role.`,dir:`security`,suffix:`.permission.ts`,snippet:(e,t)=>`import { definePermission } from '@objectstack/spec';
|
|
131
|
-
|
|
132
|
-
export default definePermission({
|
|
133
|
-
name: '${e}',
|
|
134
|
-
label: '${t}',
|
|
135
|
-
});
|
|
136
|
-
`},{type:`role`,label:`Role`,icon:dt,description:`A set of permissions assigned to users.`,dir:`security`,suffix:`.role.ts`,snippet:(e,t)=>`import { defineRole } from '@objectstack/spec';
|
|
137
|
-
|
|
138
|
-
export default defineRole({
|
|
139
|
-
name: '${e}',
|
|
140
|
-
label: '${t}',
|
|
141
|
-
permissions: [],
|
|
142
|
-
});
|
|
143
|
-
`},{type:`api`,label:`API endpoint`,icon:wt,description:`A custom REST endpoint.`,dir:`apis`,suffix:`.api.ts`,snippet:(e,t)=>`import { defineEndpoint } from '@objectstack/spec';
|
|
144
|
-
|
|
145
|
-
export default defineEndpoint({
|
|
146
|
-
name: '${e}',
|
|
147
|
-
label: '${t}',
|
|
148
|
-
method: 'GET',
|
|
149
|
-
path: '/${e.replace(/_/g,`-`)}',
|
|
150
|
-
handler: async (ctx) => ({ ok: true }),
|
|
151
|
-
});
|
|
152
|
-
`}];function xh(e){return e.trim().replace(/[A-Z]/g,e=>`_`+e.toLowerCase()).replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``).replace(/_+/g,`_`)}function Sh({open:e,onOpenChange:t,types:n,packageId:r,prefillObjectName:i}){let a=(0,F.useMemo)(()=>bh.filter(e=>n.includes(e.type)),[n]),[o,s]=(0,F.useState)(a[0]?.type??``),[c,l]=(0,F.useState)(``),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(!1),[m,h]=(0,F.useState)(null),[g,_]=(0,F.useState)(!1),[v,y]=(0,F.useState)(null);(0,F.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=r&&r!==`all`?`/_studio/api/metadata/layout?package=${encodeURIComponent(r)}`:`/_studio/api/metadata/layout`,n=await fetch(e);if(!n.ok){t||y(null);return}let i=await n.json().catch(()=>null);t||y(i?.srcRoot??null)}catch{t||y(null)}})(),()=>{t=!0}},[e,r]),(0,F.useEffect)(()=>{a.length!==0&&(a.find(e=>e.type===o)||s(a[0].type))},[a,o]),(0,F.useEffect)(()=>{e&&(l(``),d(``),p(!1),h(null))},[e]),(0,F.useEffect)(()=>{f||d(xh(c))},[c,f]);let b=a.find(e=>e.type===o),x=u||`new_item`,S=c||`New Item`,C=(0,F.useMemo)(()=>b?.snippet(x,S,i)??``,[b,x,S,i]),w=(0,F.useMemo)(()=>b?v?`${v}/${b.dir}/${x}${b.suffix}`:`packages/${r&&r!==`all`?r:`<package>`}/src/${b.dir}/${x}${b.suffix}`:``,[b,r,x,v]),T=(0,F.useCallback)(async()=>{try{await navigator.clipboard.writeText(C),h(`snippet`),U({title:`Snippet copied to clipboard`}),window.setTimeout(()=>h(null),1500)}catch(e){U({title:`Copy failed`,description:e?.message??String(e),variant:`destructive`})}},[C]),ee=(0,F.useCallback)(async()=>{try{await navigator.clipboard.writeText(w),h(`path`),U({title:`File path copied to clipboard`}),window.setTimeout(()=>h(null),1500)}catch(e){U({title:`Copy failed`,description:e?.message??String(e),variant:`destructive`})}},[w]),E=v!=null&&b!=null,te=(0,F.useCallback)(async()=>{if(E){_(!0);try{let e=await fetch(`/_studio/api/metadata/file`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({path:w,content:C,mode:`create`})}),n=await e.json().catch(()=>({}));if(!e.ok||!n?.ok){e.status===409?U({title:`File already exists`,description:`${w} is already on disk — pick a different name or open the existing file.`,variant:`destructive`}):e.status===404?U({title:`Write API unavailable`,description:`Run the studio in dev mode (objectstack dev) to enable filesystem writes.`,variant:`destructive`}):U({title:`Create failed`,description:n?.error??`HTTP ${e.status}`,variant:`destructive`});return}U({title:`File created`,description:`${w} — HMR will reload momentarily.`}),t(!1)}catch(e){U({title:`Create failed`,description:e?.message??String(e),variant:`destructive`})}finally{_(!1)}}},[E,w,C,t]);return a.length===0?null:(0,R.jsx)(Hl,{open:e,onOpenChange:t,children:(0,R.jsxs)(Gl,{className:`max-w-3xl`,children:[(0,R.jsxs)(Kl,{children:[(0,R.jsx)(Jl,{children:i?`Create related metadata for ${i}`:`Create new metadata`}),(0,R.jsx)(Yl,{children:i?(0,R.jsxs)(R.Fragment,{children:[`Scaffold a new view, dashboard, hook, approval or flow that already references `,(0,R.jsx)(`code`,{className:`rounded bg-muted px-1 font-mono text-[11px]`,children:i}),`. Fill in a name & label, click `,(0,R.jsx)(`strong`,{children:`Create file`}),` and HMR picks it up.`]}):(0,R.jsx)(R.Fragment,{children:`ObjectStack treats metadata as code. Fill in a name & label below to generate a runnable snippet — paste it into the suggested file path and HMR will pick up your change immediately.`})})]}),a.length>1&&(0,R.jsxs)(`div`,{className:`space-y-2`,children:[(0,R.jsx)(W,{className:`text-xs uppercase tracking-wide text-muted-foreground`,children:`Type`}),(0,R.jsx)(`div`,{className:`grid grid-cols-2 gap-1.5 sm:grid-cols-3`,children:a.map(e=>{let t=e.icon;return(0,R.jsxs)(`button`,{type:`button`,onClick:()=>s(e.type),className:`flex items-start gap-2 rounded-md border px-2.5 py-1.5 text-left text-xs transition-colors ${e.type===o?`border-foreground/40 bg-accent text-accent-foreground`:`hover:bg-accent/40`}`,children:[(0,R.jsx)(t,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsx)(`div`,{className:`truncate font-medium`,children:e.label}),(0,R.jsx)(`div`,{className:`truncate text-[10px] text-muted-foreground`,children:e.description})]})]},e.type)})})]}),(0,R.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`cmd-label`,className:`text-xs`,children:`Label`}),(0,R.jsx)(V,{id:`cmd-label`,value:c,onChange:e=>l(e.target.value),placeholder:b?`My new ${b.label.toLowerCase()}`:`My new item`,autoFocus:!0}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Human-readable display name. Anything you like.`})]}),(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`cmd-name`,className:`text-xs`,children:`Machine name`}),(0,R.jsx)(V,{id:`cmd-name`,value:u,onChange:e=>{d(xh(e.target.value)),p(!0)},placeholder:b?`my_new_${b.type}`:`my_new_item`,className:`font-mono`}),(0,R.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`snake_case, used everywhere (URL, ObjectQL, file name).`})]})]}),(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(W,{className:`text-xs`,children:`File path`}),(0,R.jsxs)(B,{size:`sm`,variant:`ghost`,onClick:ee,className:`h-6 gap-1 text-[10px]`,children:[m===`path`?(0,R.jsx)(_t,{className:`h-3 w-3`}):(0,R.jsx)(mt,{className:`h-3 w-3`}),`Copy path`]})]}),(0,R.jsx)(`code`,{className:`block truncate rounded border bg-muted/40 px-2 py-1.5 font-mono text-[11px]`,children:w})]}),(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(W,{className:`text-xs`,children:`Snippet`}),(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[10px]`,children:b?.type})]}),(0,R.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded border bg-muted/40 p-2 font-mono text-[11px] leading-relaxed`,children:C})]}),(0,R.jsxs)(ql,{className:`gap-2 sm:gap-2`,children:[(0,R.jsx)(B,{variant:`ghost`,onClick:()=>t(!1),children:`Cancel`}),(0,R.jsxs)(B,{variant:`outline`,onClick:T,className:`gap-1.5`,children:[m===`snippet`?(0,R.jsx)(_t,{className:`h-3.5 w-3.5`}):(0,R.jsx)(mt,{className:`h-3.5 w-3.5`}),`Copy snippet`]}),(0,R.jsxs)(B,{onClick:te,disabled:!E||g,className:`gap-1.5`,children:[g?(0,R.jsx)(`span`,{className:`inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-r-transparent`}):(0,R.jsx)(yn,{className:`h-3.5 w-3.5`}),g?`Creating…`:`Create file`]})]})]})})}function Ch(e,t){let n=new Map,r=e=>e.replace(/_/g,``).toLowerCase(),i=e=>!e.includes(`_`);for(let a of e){let e=r(a),o=t[a]??0,s=n.get(e);if(!s){n.set(e,{name:a,count:o});continue}let c=i(a)&&!i(s.name)?a:s.name;n.set(e,{name:c,count:s.count+o})}return Array.from(n.values()).map(({name:e,count:t})=>[e,t])}function wh(){let e=new Date().getHours();return e<5?`Working late`:e<12?`Good morning`:e<18?`Good afternoon`:`Good evening`}function Th(e){let t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);if(r<24)return`${r}h ago`;let i=Math.floor(r/24);return i<7?`${i}d ago`:new Date(e).toLocaleDateString()}function Eh({packages:e,selectedPackage:t,onNavigate:n=()=>{}}){let r=Bf(be({strict:!1}).projectId),i=t?.manifest?.id,{items:a,clear:o}=hh(i),[s,c]=(0,F.useState)(null),[l,u]=(0,F.useState)({packages:{total:0,enabled:0},metadata:{types:[],counts:{}},loading:!0}),d=(0,F.useCallback)(async()=>{if(r){u(e=>({...e,loading:!0}));try{let t=await r.meta.getTypes(),n=t?.types||(Array.isArray(t)?t:[]),a=await Promise.all(n.map(async e=>{try{let t=await r.meta.getItems(e,i?{packageId:i}:void 0);return[e,(t?.items||(Array.isArray(t)?t:[])).length]}catch{return[e,0]}})),o=Object.fromEntries(a),s=e.filter(e=>e.enabled).length;u({packages:{total:e.length,enabled:s},metadata:{types:n,counts:o},loading:!1})}catch(e){console.error(`[DeveloperOverview] Failed to load stats:`,e),u(e=>({...e,loading:!1}))}}},[r,e,i]);(0,F.useEffect)(()=>{d()},[d]);let f=(0,F.useMemo)(()=>Object.values(l.metadata.counts).reduce((e,t)=>e+t,0),[l.metadata.counts]),p=l.metadata.counts.object||0;if(!l.loading&&f===0&&t?.manifest?.id)return(0,R.jsx)(gh,{packageId:t.manifest.id});let m=Ch(l.metadata.types,l.metadata.counts).filter(([,e])=>e>0).sort((e,t)=>t[1]-e[1]);return(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-auto`,children:[(0,R.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl space-y-8 p-6 lg:p-8`,children:[(0,R.jsxs)(`header`,{className:`flex items-end justify-between gap-4`,children:[(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsxs)(`p`,{className:`text-xs uppercase tracking-wide text-muted-foreground`,children:[wh(),` · `,t?.manifest?.id||`ObjectStack Studio`]}),(0,R.jsx)(`h1`,{className:`text-3xl font-semibold tracking-tight`,children:t?.manifest?.name||`Welcome back`}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`What would you like to build today?`})]}),(0,R.jsxs)(B,{variant:`ghost`,size:`sm`,onClick:d,disabled:l.loading,className:`gap-1.5 text-xs text-muted-foreground`,children:[(0,R.jsx)(Ut,{className:`h-3 w-3 ${l.loading?`animate-spin`:``}`}),`Refresh`]})]}),(0,R.jsxs)(`section`,{children:[(0,R.jsx)(`h2`,{className:`mb-3 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:`Quick start`}),(0,R.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,R.jsx)(vh,{icon:In,tone:`sky`,title:`Object`,description:`Define a new data model with fields, validations, and relationships.`,onClick:()=>c(`object`)}),(0,R.jsx)(vh,{icon:$e,tone:`violet`,title:`View`,description:`Lay out a grid, kanban, calendar, or gantt for any object.`,onClick:()=>c(`view`)}),(0,R.jsx)(vh,{icon:$t,tone:`emerald`,title:`Form`,description:`Build a form to collect data — internal record entry or public intake.`,onClick:()=>c(`view`)}),(0,R.jsx)(vh,{icon:bn,tone:`amber`,title:`Flow`,description:`Wire trigger-based automation across objects, services, and AI.`,onClick:()=>c(`flow`)})]})]}),(0,R.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-5`,children:[(0,R.jsxs)(`section`,{className:`lg:col-span-3`,children:[(0,R.jsxs)(`div`,{className:`mb-3 flex items-baseline justify-between`,children:[(0,R.jsx)(`h2`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:`Recent`}),a.length>0&&(0,R.jsx)(`button`,{type:`button`,onClick:o,className:`text-[11px] text-muted-foreground hover:text-foreground`,children:`Clear`})]}),(0,R.jsx)(X,{className:`border-border/60`,children:(0,R.jsx)($,{className:`p-1.5`,children:a.length===0?(0,R.jsxs)(`div`,{className:`flex flex-col items-center gap-1 px-3 py-8 text-center`,children:[(0,R.jsx)(vn,{className:`h-5 w-5 text-muted-foreground/40`}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No recent items yet`}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground/70`,children:`Items you open will appear here.`})]}):(0,R.jsx)(`ul`,{className:`grid gap-0.5 sm:grid-cols-2`,children:a.map(e=>{let t=Yu(e.type)??ze,r=e.type===`object`?`object:${e.name}`:`metadata:${e.type}:${e.name}`;return(0,R.jsx)(`li`,{children:(0,R.jsxs)(`button`,{type:`button`,onClick:()=>{e.type===`object`?n(`object`,e.name):n(`metadata:${e.type}`,e.name)},className:`group flex w-full items-center gap-2.5 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-muted/60`,children:[(0,R.jsx)(t,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsx)(`div`,{className:`truncate text-sm font-medium`,children:e.label||e.name}),(0,R.jsxs)(`div`,{className:`truncate text-[10px] text-muted-foreground`,children:[qu(e.type),` · `,Th(e.ts)]})]}),(0,R.jsx)(pn,{className:`h-3 w-3 shrink-0 text-muted-foreground/0 transition group-hover:translate-x-0.5 group-hover:text-muted-foreground`})]})},r)})})})})]}),(0,R.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,R.jsxs)(`div`,{className:`mb-3 flex items-baseline justify-between`,children:[(0,R.jsx)(`h2`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:`Browse by type`}),(0,R.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[f,` items`]})]}),(0,R.jsx)(X,{className:`border-border/60`,children:(0,R.jsx)($,{className:`p-1.5`,children:l.loading&&m.length===0?(0,R.jsx)(`p`,{className:`px-3 py-6 text-center text-xs text-muted-foreground`,children:`Loading…`}):(0,R.jsx)(`ul`,{className:`grid gap-0.5`,children:m.slice(0,12).map(([e,t])=>{let r=Yu(e)??ze,i=qu(e),a=Gu(e),o=!!a;return(0,R.jsx)(`li`,{children:(0,R.jsxs)(`button`,{type:`button`,disabled:!o,onClick:o?()=>n(a.key):void 0,className:`group flex w-full items-center justify-between gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors `+(o?`hover:bg-muted/60`:`opacity-60 cursor-default`),children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2.5`,children:[(0,R.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate text-sm`,children:i})]}),(0,R.jsx)(G,{variant:`secondary`,className:`shrink-0 font-mono text-[10px]`,children:t})]})},e)})})})})]})]}),(0,R.jsxs)(`footer`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2 border-t pt-4 text-xs text-muted-foreground`,children:[(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,R.jsx)(zn,{className:`h-3 w-3`}),(0,R.jsx)(`span`,{className:`tabular-nums`,children:l.packages.total}),` packages`,(0,R.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[`(`,l.packages.enabled,` enabled)`]})]}),(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,R.jsx)(In,{className:`h-3 w-3`}),(0,R.jsx)(`span`,{className:`tabular-nums`,children:p}),` objects`]}),(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,R.jsx)(st,{className:`h-3 w-3`}),(0,R.jsx)(`span`,{className:`tabular-nums`,children:l.metadata.types.length}),` metadata types`]}),(0,R.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1.5`,children:[(0,R.jsx)(wt,{className:`h-3 w-3 text-emerald-500`}),`REST API `,(0,R.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-[10px]`,children:`/api/v1`}),` live`]})]})]}),(0,R.jsx)(Sh,{open:s!==null,onOpenChange:e=>{e||c(null)},types:s?[s]:[],packageId:i})]})}function Dh(){let{package:e}=Oh.useParams(),{packages:t,selectedPackage:n}=Uu(e),r=ve();return(0,R.jsx)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:(0,R.jsx)(Eh,{packages:t,selectedPackage:n,onNavigate:(t,n)=>{let i=e;if(t.startsWith(`metadata:`)&&n){r({to:`/${i}/metadata/${t.slice(9)}/${n}`});return}switch(t){case`home`:case`overview`:r({to:`/${i}`});return;case`objects`:r({to:`/${i}/objects`});return;case`object`:n&&r({to:`/${i}/objects/${n}`});return;case`views`:case`apps`:case`forms`:case`automations`:case`ai`:case`security`:case`apis`:case`playground`:case`logs`:r({to:`/${i}/${t}`});return;default:return}}})})}var Oh=_e(`/$package/`)({component:Dh}),kh=_e(`/$package/public-forms`)({beforeLoad:({params:e})=>{throw Ee({to:`/$package/forms`,params:{package:e.package}})},component:()=>null});function Ah(e){return typeof e==`string`?e:e&&typeof e==`object`&&`defaultValue`in e?String(e.defaultValue):e&&typeof e==`object`&&`key`in e?String(e.key):``}function jh(e){return e?e.replace(/[_-]+/g,` `).replace(/\s+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase()):``}function Mh(e){return Ah(e?.label)||Ah(e?.list?.label)||Ah(e?.form?.label)||Ah(e?.spec?.label)||jh(e?.name)||`Untitled`}function Nh(e,t){let n=Ah(e?.description);if(n)return n;switch(t){case`view`:{let t=[];e?.list&&t.push(`list`),e?.form&&t.push(`form`);let n=(e?.listViews?.length??0)+(e?.formViews?.length??0);n>0&&t.push(`${n} variant${n===1?``:`s`}`);let r=e?.object??e?.data?.object??e?.list?.data?.object??e?.form?.data?.object??e?.name;return t.length?r?`Default ${t.join(` + `)} for ${r}`:`Default ${t.join(` + `)}`:void 0}case`agent`:{let t=e?.model,n=typeof t==`string`?t:t&&typeof t==`object`?[t.provider,t.model].filter(Boolean).join(`/`):void 0,r=e?.role,i=typeof r==`string`&&r?r.charAt(0).toUpperCase()+r.slice(1):void 0;return n&&i?`${i} agent · ${n}`:n?`Model: ${n}`:i?`${i} agent`:void 0}case`hook`:{let t=e?.object,n=Array.isArray(e?.events)?e.events.join(`, `):e?.events;return t&&n?`${t} · ${n}`:t?`Listens on ${t}`:void 0}case`flow`:{let t=e?.object||e?.trigger?.object;return t?`Flow on ${t}`:void 0}default:return}}var Ph=new Set([`object`,`view`,`dashboard`]);function Fh({title:e,subtitle:t,types:n,packageId:r,filterItem:i,rightSlot:a,emptyCta:o,iconForType:s}){let c=L(),l=ve(),[u,d]=(0,F.useState)([]),[f,p]=(0,F.useState)(!0),[m,h]=(0,F.useState)(null),[g,_]=(0,F.useState)(``),[v,y]=(0,F.useState)(null),[b,x]=(0,F.useState)(!1),[S,C]=(0,F.useState)(new Set),[w,T]=(0,F.useState)(()=>typeof window>`u`?`cards`:localStorage.getItem(`studio.listViewMode`)||`cards`);(0,F.useEffect)(()=>{typeof window<`u`&&localStorage.setItem(`studio.listViewMode`,w)},[w]);let ee=(0,F.useCallback)(async()=>{p(!0),h(null);try{let e=[],t=r&&r!==`all`?{packageId:r}:void 0;for(let r of n)try{let n=await c.meta.getItems(r,t),a=n?.items||(Array.isArray(n)?n:[]);for(let t of a)i&&!i(t,r)||e.push({type:r,name:t.name||t.id||`unknown`,label:Mh(t),description:Nh(t,r),updatedAt:t.updatedAt||t._updatedAt,raw:t})}catch(e){console.warn(`[MetadataListPage] failed to load ${r}`,e)}d(e)}catch(e){h(e instanceof Error?e.message:String(e))}finally{p(!1)}},[c,r,n,i]);(0,F.useEffect)(()=>{ee()},[ee]),Ks(`object`,ee),Ks(`view`,ee),Ks(`flow`,ee),Ks(`agent`,ee);let E=(0,F.useMemo)(()=>{let e=g.trim().toLowerCase();return u.filter(t=>S.size>0&&!S.has(t.type)?!1:e?t.label.toLowerCase().includes(e)||t.name.toLowerCase().includes(e)||t.type.toLowerCase().includes(e):!0)},[u,g,S]),te=(0,F.useMemo)(()=>{let e={};for(let t of u)e[t.type]=(e[t.type]??0)+1;return e},[u]),D=e=>{C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ne=e=>{let t=r||`all`;e.type===`object`?l({to:`/${t}/objects/${e.name}`}):l({to:`/${t}/metadata/${e.type}/${e.name}`})};return(0,R.jsxs)(`div`,{className:`flex h-full flex-1 flex-col overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`border-b px-6 py-2.5`,children:(0,R.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-3`,children:[(0,R.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight`,children:e}),(0,R.jsx)(`p`,{className:`hidden truncate text-xs text-muted-foreground lg:block`,children:t})]}),(0,R.jsxs)(`div`,{className:`relative ml-auto w-64 max-w-sm flex-1`,children:[(0,R.jsx)(Xe,{className:`pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,R.jsx)(V,{value:g,onChange:e=>_(e.target.value),placeholder:`Search ${e.toLowerCase()}…`,className:`h-8 pl-8 text-sm`,autoFocus:!0})]}),n.length>1&&(0,R.jsx)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:n.map(e=>{let t=te[e]??0;if(t===0)return null;let n=S.has(e),r=qu(e);return(0,R.jsxs)(B,{variant:n?`default`:`outline`,size:`sm`,onClick:()=>D(e),className:`h-7 gap-1.5 text-xs`,children:[r,` `,(0,R.jsx)(`span`,{className:`opacity-60`,children:t})]},e)})}),(0,R.jsxs)(`div`,{className:`inline-flex rounded-md border bg-background p-0.5`,children:[(0,R.jsx)(B,{variant:w===`cards`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1 px-2`,onClick:()=>T(`cards`),title:`Card view`,"aria-label":`Card view`,"aria-pressed":w===`cards`,children:(0,R.jsx)($e,{className:`h-3.5 w-3.5`})}),(0,R.jsx)(B,{variant:w===`compact`?`secondary`:`ghost`,size:`sm`,className:`h-7 gap-1 px-2`,onClick:()=>T(`compact`),title:`Compact list`,"aria-label":`Compact list`,"aria-pressed":w===`compact`,children:(0,R.jsx)(it,{className:`h-3.5 w-3.5`})})]}),(0,R.jsxs)(B,{size:`sm`,className:`h-7 gap-1.5 text-xs`,onClick:()=>x(!0),children:[(0,R.jsx)(en,{className:`h-3.5 w-3.5`}),`New`]}),a&&(0,R.jsx)(`div`,{className:`flex items-center gap-2`,children:a})]})}),(0,R.jsx)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:f?(0,R.jsx)(`div`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`Loading…`}):m?(0,R.jsxs)(`div`,{className:`py-12 text-center text-sm text-destructive`,children:[`Failed: `,m]}):E.length===0?(0,R.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-4 py-20 text-center`,children:[(0,R.jsx)(`div`,{className:`grid h-14 w-14 place-items-center rounded-2xl bg-gradient-to-br from-muted to-muted/40 ring-1 ring-border`,children:(()=>{let e=s?.(n[0])??Yu(n[0]);return e?(0,R.jsx)(e,{className:`h-6 w-6 text-muted-foreground`}):(0,R.jsx)(en,{className:`h-6 w-6 text-muted-foreground`})})()}),(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(`p`,{className:`text-base font-semibold`,children:u.length===0?r&&r!==`all`?`No ${e.toLowerCase()} in this package yet`:`No ${e.toLowerCase()} yet`:`No ${e.toLowerCase()} match "${g}"`}),u.length===0?(0,R.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:t}):(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Try adjusting your search or type filter.`})]}),u.length===0&&(0,R.jsxs)(B,{size:`sm`,className:`gap-1.5`,onClick:()=>x(!0),children:[(0,R.jsx)(en,{className:`h-3.5 w-3.5`}),`Create your first `,n.length===1?qu(n[0]):e.toLowerCase().replace(/s$/,``)]}),o]}):w===`compact`?(0,R.jsx)(Ih,{rows:E,showTypeBadge:n.length>1,iconForType:s,onOpen:ne,onPreview:y}):(0,R.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:E.map(e=>{let t=s?.(e.type)??Yu(e.type),r=Ph.has(e.type),i=n.length>1;return(0,R.jsx)(X,{className:`group cursor-pointer transition hover:border-primary hover:shadow-sm`,onClick:()=>ne(e),children:(0,R.jsxs)($,{className:`flex flex-col gap-1.5 p-4`,children:[(0,R.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[t&&(0,R.jsx)(t,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`line-clamp-2 break-words font-medium leading-snug`,title:e.label,children:e.label})]}),(0,R.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[i&&(0,R.jsx)(G,{variant:`secondary`,className:`text-[10px]`,children:qu(e.type)}),r&&(0,R.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-40 transition group-hover:opacity-100`,title:`Preview`,"aria-label":`Preview ${e.label}`,onClick:t=>{t.stopPropagation(),y(e)},children:(0,R.jsx)(On,{className:`h-3.5 w-3.5`})})]})]}),e.description?(0,R.jsx)(`p`,{className:`line-clamp-2 text-xs text-muted-foreground`,title:e.description,children:e.description}):null,(0,R.jsxs)(`div`,{className:`mt-auto flex items-center justify-between gap-2 pt-1`,children:[(0,R.jsx)(`code`,{className:`truncate text-[11px] text-muted-foreground/70`,title:e.name,children:e.name}),e.updatedAt&&(0,R.jsx)(`span`,{className:`shrink-0 text-[10px] text-muted-foreground/70`,title:e.updatedAt,children:id(e.updatedAt)})]})]})},`${e.type}:${e.name}`)})})}),(0,R.jsx)(Hl,{open:!!v,onOpenChange:e=>!e&&y(null),children:(0,R.jsxs)(Gl,{className:`max-w-5xl`,children:[(0,R.jsxs)(Kl,{children:[(0,R.jsx)(Jl,{children:v?.label??v?.name}),(0,R.jsx)(Yl,{children:`Live preview rendered with @object-ui against the configured backend.`})]}),v&&(0,R.jsx)(`div`,{className:`h-[70vh] overflow-hidden`,children:(0,R.jsx)(Bm,{type:v.type,name:v.name,spec:v.raw?.spec??v.raw})})]})}),(0,R.jsx)(Sh,{open:b,onOpenChange:x,types:n,packageId:r})]})}function Ih({rows:e,showTypeBadge:t,iconForType:n,onOpen:r,onPreview:i}){return(0,R.jsx)(`div`,{className:`divide-y rounded-md border bg-card`,children:e.map(e=>{let a=n?.(e.type)??Yu(e.type),o=Ph.has(e.type);return(0,R.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>r(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),r(e))},className:`group grid cursor-pointer grid-cols-[auto_minmax(0,2fr)_minmax(0,3fr)_auto_auto] items-center gap-3 px-3 py-2 text-sm transition hover:bg-muted/40 focus:bg-muted/40 focus:outline-none`,children:[a?(0,R.jsx)(a,{className:`h-4 w-4 shrink-0 text-muted-foreground`}):(0,R.jsx)(`span`,{className:`w-4`}),(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsx)(`div`,{className:`truncate font-medium`,title:e.label,children:e.label}),(0,R.jsx)(`code`,{className:`truncate text-[11px] text-muted-foreground/70`,title:e.name,children:e.name})]}),(0,R.jsx)(`p`,{className:`line-clamp-1 text-xs text-muted-foreground`,title:e.description??``,children:e.description??``}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&(0,R.jsx)(G,{variant:`secondary`,className:`text-[10px]`,children:qu(e.type)}),e.updatedAt&&(0,R.jsx)(`span`,{className:`hidden text-[10px] text-muted-foreground/70 md:inline`,title:e.updatedAt,children:id(e.updatedAt)})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[o&&(0,R.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-6 w-6 opacity-0 transition group-hover:opacity-100 group-focus:opacity-100`,title:`Preview`,"aria-label":`Preview ${e.label}`,onClick:t=>{t.stopPropagation(),i(e)},children:(0,R.jsx)(On,{className:`h-3.5 w-3.5`})}),(0,R.jsx)(je,{"aria-hidden":!0,className:`h-4 w-4 shrink-0 text-muted-foreground/40 transition group-hover:translate-x-0.5 group-hover:text-foreground`})]})]},`${e.type}:${e.name}`)})})}function Lh(){let{package:e}=Rh.useParams();return(0,R.jsx)(Fh,{title:`Views & Apps`,subtitle:`Grids, kanbans, dashboards, reports, pages, and app navigation. Form views have their own page under Forms.`,filterItem:(e,t)=>t===`view`?(e?.spec?.viewType??e?.viewType)!==`form`:!0,types:[`app`,`view`,`page`,`dashboard`,`report`],packageId:e})}var Rh=_e(`/$package/views/`)({component:Lh});function zh(){let{package:e}=Bh.useParams();return(0,R.jsx)(Fh,{title:`Security`,subtitle:`Roles, profiles, and permission definitions for this package.`,types:[`role`,`profile`,`permission`],packageId:e})}var Bh=_e(`/$package/security/`)({component:zh}),Vh=[`plugin`,`plugins`,`kind`,`package`];function Hh(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 Uh={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 Wh(e,t){let n=Uh[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 Gh(e){let t=L(),n=Bf(e),r=n??t,[i,a]=(0,F.useState)([]),[o,s]=(0,F.useState)([]),[c,l]=(0,F.useState)(!0),[u,d]=(0,F.useState)(null),f=(0,F.useCallback)(async()=>{l(!0),d(null);let t=`/api/v1`,n=`${t}/discovery`,i=[{method:`GET`,path:n,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`,c={},l={};try{let e=await fetch(n);if(e.ok){let t=await e.json(),n=t?.data??t;l=n?.routes??{},c=n?.services??{},l.auth&&(o=l.auth)}}catch{}let u=[];for(let[t,n]of Object.entries(Uh)){let r=c[t],i=r?.enabled??!1,a=r?.handlerReady??(r?.status===`available`||r?.status===`degraded`),o=r?.route??l[t]??n.defaultRoute,s=e&&o.startsWith(`/api/v1/`)&&!o.includes(`/projects/`)?o.replace(`/api/v1/`,`/api/v1/projects/${e}/`):o;i&&a&&u.push(...Wh(t,s))}let d=[];try{let e=await r.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){let t=await r.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=>!Vh.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,...Hh(o),...u,...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`];a(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}))),s(g)}catch(e){d(e.message||`Failed to discover APIs`)}finally{l(!1)}},[r,e,n]);return(0,F.useEffect)(()=>{f()},[f]),{groups:i,allEndpoints:o,loading:c,error:u,refresh:f}}var Kh=Ir,qh=kr,Jh=Vn,Yh={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`},Xh={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`},Zh=[{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`}],Qh=1;function $h({projectId:e}={}){let t=L(),[n,r]=(0,F.useState)(e?`project`:`system`),{groups:i,loading:a,refresh:o}=Gh(e&&n===`project`?e:void 0),[s,c]=(0,F.useState)(``),[l,u]=(0,F.useState)(new Set),[d,f]=(0,F.useState)(null),[p,m]=(0,F.useState)(``),[h,g]=(0,F.useState)(``),[_,v]=(0,F.useState)(``),[y,b]=(0,F.useState)([]),[x,S]=(0,F.useState)(!1),[C,w]=(0,F.useState)(null),[T,ee]=(0,F.useState)([]),[E,te]=(0,F.useState)(null),[D,ne]=(0,F.useState)(!1),O=(0,F.useMemo)(()=>{if(!s)return i;let e=s.toLowerCase();return i.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)},[i,s]),re=(0,F.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),k=(0,F.useCallback)(e=>{f(e),m(e.method),g(e.path),v(e.bodyTemplate?JSON.stringify(e.bodyTemplate,null,2):``),b([]),w(null)},[]),ie=p||d?.method||`GET`,A=h||d?.path||``,j=(0,F.useMemo)(()=>{let e=y.filter(e=>e.enabled&&e.key.trim());return e.length===0?A:`${A}?${e.map(e=>`${encodeURIComponent(e.key)}=${encodeURIComponent(e.value)}`).join(`&`)}`},[A,y]),ae=(0,F.useCallback)((e=``,t=``)=>{b(n=>[...n,{id:Qh++,key:e,value:t,enabled:!0}])},[]),oe=(0,F.useCallback)(e=>{b(t=>t.filter(t=>t.id!==e))},[]),se=(0,F.useCallback)((e,t,n)=>{b(r=>r.map(r=>r.id===e?{...r,[t]:n}:r))},[]),ce=(0,F.useCallback)(e=>{b(t=>t.map(t=>t.id===e?{...t,enabled:!t.enabled}:t))},[]),le=(0,F.useCallback)(async()=>{if(x||!j)return;let e=`${t?.baseUrl??``}${j}`;S(!0);let n=performance.now();try{let t={method:ie,headers:{"Content-Type":`application/json`}};[`POST`,`PATCH`,`PUT`].includes(ie)&&_.trim()&&(t.body=_);let r=await fetch(e,t),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();w({status:r.status,body:a,duration:i}),ee(e=>[{id:Date.now(),method:ie,url:j,body:_||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);w({status:0,body:`Network Error: ${e.message}`,duration:t})}finally{S(!1)}},[t,j,ie,_,x]),M=(0,F.useCallback)(e=>{m(e.method);let[t,n]=e.url.split(`?`);if(g(t),v(e.body||``),n){let e=new URLSearchParams(n),t=[];e.forEach((e,n)=>{t.push({id:Qh++,key:n,value:e,enabled:!0})}),b(t)}else b([]);w(null),f(null)},[]),N=(0,F.useCallback)(()=>{C?.body&&(navigator.clipboard.writeText(C.body),ne(!0),setTimeout(()=>ne(!1),1500))},[C]),P=e=>Xh[String(e)[0]]??`text-muted-foreground`;return(0,R.jsxs)(`div`,{className:`flex flex-1 min-h-0 overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`w-72 shrink-0 border-r flex flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`p-3 border-b space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`h3`,{className:`text-sm font-semibold text-foreground flex-1`,children:`API Endpoints`}),(0,R.jsx)(`button`,{onClick:o,disabled:a,className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,title:`Refresh endpoints`,children:(0,R.jsx)(Ut,{className:`h-3.5 w-3.5 ${a?`animate-spin`:``}`})})]}),e&&(0,R.jsxs)(`div`,{className:`flex items-center rounded-md border bg-muted/30 p-0.5 gap-0.5`,children:[(0,R.jsxs)(`button`,{onClick:()=>r(`project`),className:`flex-1 flex items-center justify-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors ${n===`project`?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:[(0,R.jsx)(Ht,{className:`h-3 w-3`}),`Project API`]}),(0,R.jsxs)(`button`,{onClick:()=>r(`system`),className:`flex-1 flex items-center justify-center gap-1 rounded px-2 py-1 text-[10px] font-medium transition-colors ${n===`system`?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`}`,children:[(0,R.jsx)(xt,{className:`h-3 w-3`}),`System API`]})]}),(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsx)(Xe,{className:`absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,R.jsx)(`input`,{type:`text`,value:s,onChange:e=>c(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,R.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:a?(0,R.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,R.jsx)(tt,{className:`h-4 w-4 animate-spin mr-2`}),`Discovering APIs...`]}):O.length===0?(0,R.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,R.jsx)(wt,{className:`h-6 w-6 opacity-30 mb-2`}),(0,R.jsx)(`span`,{children:s?`No matching endpoints`:`No endpoints found`})]}):O.map(e=>{let t=l.has(e.key)||!!s;return(0,R.jsxs)(Kh,{open:t,onOpenChange:()=>re(e.key),children:[(0,R.jsx)(qh,{asChild:!0,children:(0,R.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,R.jsx)(je,{className:`h-3 w-3 shrink-0 transition-transform duration-200 ${t?`rotate-90`:``}`}),(0,R.jsx)(`span`,{className:`flex-1 text-left truncate`,children:e.label}),(0,R.jsx)(`span`,{className:`shrink-0 text-[10px] tabular-nums opacity-60`,children:e.endpoints.length})]})}),(0,R.jsx)(Jh,{children:(0,R.jsx)(`div`,{className:`ml-3 space-y-0.5 mt-0.5`,children:e.endpoints.map((e,t)=>(0,R.jsxs)(`button`,{onClick:()=>k(e),className:`w-full text-left flex items-center gap-1.5 px-2 py-1 rounded text-xs transition-colors ${d===e?`bg-accent text-accent-foreground`:`hover:bg-muted/50 text-muted-foreground hover:text-foreground`}`,children:[(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[9px] shrink-0 px-1 py-0 ${Yh[e.method]||``}`,children:e.method}),(0,R.jsx)(`span`,{className:`truncate`,children:e.desc})]},`${e.method}-${e.path}-${t}`))})})]},e.key)})}),(0,R.jsxs)(`div`,{className:`p-3 border-t space-y-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,R.jsx)(`h4`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:`Query Parameters`}),(0,R.jsxs)(`button`,{onClick:()=>ae(),className:`inline-flex items-center gap-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,R.jsx)(en,{className:`h-3 w-3`}),`Add`]})]}),(0,R.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Zh.map(e=>(0,R.jsx)(`button`,{onClick:()=>ae(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))}),y.length>0&&(0,R.jsx)(`div`,{className:`space-y-1`,children:y.map(e=>(0,R.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,R.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>ce(e.id),className:`h-3 w-3 shrink-0 rounded border accent-primary`}),(0,R.jsx)(`input`,{type:`text`,value:e.key,onChange:t=>se(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,R.jsx)(`input`,{type:`text`,value:e.value,onChange:t=>se(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,R.jsx)(`button`,{onClick:()=>oe(e.id),className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-destructive transition-colors`,children:(0,R.jsx)(At,{className:`h-3 w-3`})})]},e.id))})]})]}),(0,R.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`select`,{value:ie,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 ${Yh[ie]||``}`,children:[`GET`,`POST`,`PATCH`,`PUT`,`DELETE`].map(e=>(0,R.jsx)(`option`,{value:e,children:e},e))}),(0,R.jsx)(`input`,{type:`text`,value:A,onChange:e=>g(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`&&le()}}),(0,R.jsxs)(`button`,{onClick:le,disabled:x||!j,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:[x?(0,R.jsx)(tt,{className:`h-3.5 w-3.5 animate-spin`}):(0,R.jsx)(Mt,{className:`h-3.5 w-3.5`}),`Send`]})]}),y.some(e=>e.enabled&&e.key.trim())&&(0,R.jsxs)(`div`,{className:`text-[10px] font-mono text-muted-foreground truncate pl-1`,children:[`→ `,j]})]}),(0,R.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 overflow-auto`,children:[[`POST`,`PATCH`,`PUT`].includes(ie)&&(0,R.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,R.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Request Body (JSON)`}),(0,R.jsx)(`textarea`,{value:_,onChange:e=>v(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" }`})]}),x&&(0,R.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,R.jsx)(tt,{className:`h-4 w-4 animate-spin mr-2`}),`Sending request...`]}),C&&!x&&(0,R.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-muted/30 border-b`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,R.jsx)(`span`,{className:`font-mono font-semibold ${P(C.status)}`,children:C.status||`ERR`}),(0,R.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1`,children:[(0,R.jsx)(Ie,{className:`h-3 w-3`}),C.duration,`ms`]})]}),(0,R.jsxs)(`button`,{onClick:N,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[D?(0,R.jsx)(_t,{className:`h-3 w-3`}):(0,R.jsx)(mt,{className:`h-3 w-3`}),D?`Copied`:`Copy`]})]}),(0,R.jsx)(`pre`,{className:`flex-1 overflow-auto p-3 text-xs font-mono bg-muted/10 whitespace-pre-wrap break-all`,children:C.body})]}),!C&&!x&&(0,R.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-muted-foreground text-sm`,children:(0,R.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,R.jsx)(wt,{className:`h-10 w-10 mx-auto opacity-20`}),(0,R.jsxs)(`p`,{children:[`Select an endpoint or type a URL and click `,(0,R.jsx)(`strong`,{children:`Send`})]}),(0,R.jsx)(`p`,{className:`text-xs opacity-60`,children:`All registered APIs are auto-discovered from the platform`})]})}),T.length>0&&(0,R.jsxs)(`div`,{className:`border-t`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2`,children:[(0,R.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:[`History (`,T.length,`)`]}),(0,R.jsxs)(`button`,{onClick:()=>ee([]),className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,R.jsx)(Fn,{className:`h-3 w-3`}),`Clear`]})]}),(0,R.jsx)(`div`,{className:`space-y-0.5 px-2 pb-2 max-h-60 overflow-auto`,children:T.map(e=>(0,R.jsxs)(`div`,{className:`rounded border`,children:[(0,R.jsxs)(`button`,{onClick:()=>te(E===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:[E===e.id?(0,R.jsx)(We,{className:`h-3 w-3 shrink-0`}):(0,R.jsx)(je,{className:`h-3 w-3 shrink-0`}),(0,R.jsx)(G,{variant:`outline`,className:`font-mono text-[9px] shrink-0 ${Yh[e.method]||``}`,children:e.method}),(0,R.jsx)(`span`,{className:`font-mono truncate text-left flex-1`,children:e.url}),(0,R.jsx)(`span`,{className:`ml-auto shrink-0 font-mono ${P(e.status)}`,children:e.status}),(0,R.jsxs)(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.duration,`ms`]}),(0,R.jsx)(`button`,{onClick:t=>{t.stopPropagation(),M(e)},className:`shrink-0 p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors`,title:`Replay request`,children:(0,R.jsx)(Mt,{className:`h-2.5 w-2.5`})})]}),E===e.id&&(0,R.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))})]})]})]})]})}function eg({title:e,hint:t}){return(0,R.jsxs)(X,{children:[(0,R.jsxs)(Z,{children:[(0,R.jsx)(Q,{className:`flex items-center gap-2 text-base`,children:e}),(0,R.jsx)(bp,{children:t})]}),(0,R.jsx)($,{children:(0,R.jsx)(`div`,{className:`rounded-md border border-dashed bg-muted/30 p-6 text-center text-sm text-muted-foreground`,children:`Coming soon.`})})]})}function tg(){let{package:e}=ng.useParams(),[t,n]=(0,F.useState)(`rest`);return(0,R.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`border-b px-6 py-4`,children:[(0,R.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold tracking-tight`,children:[(0,R.jsx)(wn,{className:`h-5 w-5`}),`Playground`]}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Try REST, ObjectQL, formulas, forms, and AI agents against your running backend without leaving Studio.`})]}),(0,R.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,R.jsxs)(ad,{value:t,onValueChange:n,className:`flex h-full flex-col`,children:[(0,R.jsxs)(od,{className:`mx-6 mt-3 self-start`,children:[(0,R.jsxs)(K,{value:`rest`,className:`gap-1.5`,children:[(0,R.jsx)(pt,{className:`h-3.5 w-3.5`}),` REST`]}),(0,R.jsxs)(K,{value:`objectql`,className:`gap-1.5`,children:[(0,R.jsx)(Xe,{className:`h-3.5 w-3.5`}),` ObjectQL`]}),(0,R.jsxs)(K,{value:`formula`,className:`gap-1.5`,children:[(0,R.jsx)(et,{className:`h-3.5 w-3.5`}),` Formula`]}),(0,R.jsxs)(K,{value:`agent`,className:`gap-1.5`,children:[(0,R.jsx)(ut,{className:`h-3.5 w-3.5`}),` Agent`]}),(0,R.jsxs)(K,{value:`tool`,className:`gap-1.5`,children:[(0,R.jsx)(dn,{className:`h-3.5 w-3.5`}),` Tool`]}),(0,R.jsxs)(K,{value:`form`,className:`gap-1.5`,children:[(0,R.jsx)(En,{className:`h-3.5 w-3.5`}),` Form preview`]})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-auto p-6`,children:[(0,R.jsx)(sd,{value:`rest`,className:`mt-0`,children:(0,R.jsx)($h,{})}),(0,R.jsx)(sd,{value:`objectql`,className:`mt-0`,children:(0,R.jsx)(eg,{title:`ObjectQL playground`,hint:`Build filter / sort / pagination queries against any object and inspect the raw response.`})}),(0,R.jsx)(sd,{value:`formula`,className:`mt-0`,children:(0,R.jsx)(eg,{title:`Formula REPL (CEL)`,hint:`Try expressions, predicates, and seed-value formulas against sample data.`})}),(0,R.jsx)(sd,{value:`agent`,className:`mt-0`,children:(0,R.jsx)(X,{children:(0,R.jsxs)(Z,{children:[(0,R.jsx)(Q,{className:`text-base`,children:`Agent playground`}),(0,R.jsxs)(bp,{children:[`Pick an agent from the`,` `,(0,R.jsx)(we,{to:`/$package/ai`,params:{package:e},className:`underline underline-offset-2`,children:`AI list`}),` `,`and use the assistant panel on the right to chat with it.`]})]})})}),(0,R.jsx)(sd,{value:`tool`,className:`mt-0`,children:(0,R.jsx)(eg,{title:`Tool playground`,hint:`Invoke any registered Tool with arbitrary input and see the response + telemetry.`})}),(0,R.jsx)(sd,{value:`form`,className:`mt-0`,children:(0,R.jsx)(rg,{})})]})]})})]})}var ng=_e(`/$package/playground/`)({component:tg});function rg(){let e=L(),{version:t}=Bu(),[n,r]=(0,F.useState)([]),[i,a]=(0,F.useState)(``),[o,s]=(0,F.useState)(!0);(0,F.useEffect)(()=>{let t=!1;return(async()=>{s(!0);try{let n=await e.meta.getItems(`view`),o=(Array.isArray(n)?n:Array.isArray(n?.items)?n.items:Array.isArray(n?.data?.items)?n.data.items:[]).map(e=>({name:e.name,label:e.label??e.spec?.label,object:e.spec?.object,spec:e.spec??e})).filter(e=>{let t=e.spec??{};return t.viewType===`form`||!!t.sections||!!t.groups||!!t.form||[`simple`,`tabbed`,`wizard`].includes(t.type)});t||(r(o),o[0]&&!i&&a(o[0].name))}finally{t||s(!1)}})(),()=>{t=!0}},[e,t]);let c=(0,F.useMemo)(()=>n.find(e=>e.name===i),[n,i]);return o?(0,R.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:`Loading forms…`}):n.length?(0,R.jsxs)(`div`,{className:`space-y-4`,children:[(0,R.jsx)(X,{children:(0,R.jsxs)(Z,{className:`space-y-2`,children:[(0,R.jsx)(Q,{className:`text-base`,children:`Form preview`}),(0,R.jsx)(bp,{children:`Read-only render of any FormView spec. Pick a form and see exactly what the user would see — without leaving Studio.`}),(0,R.jsx)(`div`,{className:`pt-2`,children:(0,R.jsxs)(em,{value:i,onValueChange:a,children:[(0,R.jsx)(nm,{className:`max-w-md`,children:(0,R.jsx)(tm,{placeholder:`Pick a form…`})}),(0,R.jsx)(am,{children:n.map(e=>(0,R.jsxs)(sm,{value:e.name,children:[e.label??e.name,e.object&&(0,R.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`→ `,e.object]})]},e.name))})]})})]})}),c&&(0,R.jsx)(`div`,{className:`h-[640px] overflow-hidden rounded-lg border`,children:(0,R.jsx)(Dm,{spec:c.spec?.form??c.spec,objectName:c.object??c.spec?.object??``})})]}):(0,R.jsx)(X,{children:(0,R.jsxs)(Z,{children:[(0,R.jsx)(Q,{className:`text-base`,children:`No forms yet`}),(0,R.jsxs)(bp,{children:[`Create a view with `,(0,R.jsx)(`code`,{className:`text-xs`,children:`viewType: 'form'`}),` (or with `,(0,R.jsx)(`code`,{className:`text-xs`,children:`sections`}),` / `,(0,R.jsx)(`code`,{className:`text-xs`,children:`groups`}),`) to preview it here.`]})]})})}function ig(){let{package:e}=ag.useParams();return(0,R.jsx)(Fh,{title:`Objects`,subtitle:`Data model — every object you can query, edit, and bind UI to.`,types:[`object`],packageId:e})}var ag=_e(`/$package/objects/`)({component:ig}),og=[{key:`audit`,label:`Audit trail`,icon:Ae,objectName:`sys_audit_log`,columns:[`created_at`,`action`,`object_name`,`record_id`,`user_id`,`ip_address`],description:`Every metadata mutation and record write persisted to sys_audit_log — who changed what, when, and from where.`},{key:`jobs`,label:`Background jobs`,icon:Dn,objectName:`sys_job_run`,columns:[`started_at`,`job_name`,`status`,`trigger`,`attempt`,`duration_ms`,`error`],description:`Every queued or scheduled job the runtime executed — its status, attempt count, trigger, latency, and error if any.`},{key:`approvals`,label:`Approvals`,icon:gn,objectName:`sys_approval_request`,columns:[`created_at`,`object_name`,`record_id`,`status`,`process_name`,`current_step`,`submitter_id`],description:`Every approval process in flight or recently resolved — surfaces what is currently blocked on a human decision.`}];function sg(){let e=mp(),[t,n]=(0,F.useState)(`audit`),r=og.find(e=>e.key===t)??og[0];return(0,R.jsxs)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`border-b px-6 py-4`,children:[(0,R.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold tracking-tight`,children:[(0,R.jsx)(gn,{className:`h-5 w-5`}),` Logs`]}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`See what your runtime is doing right now — every write, every job run, every approval.`})]}),(0,R.jsxs)(ad,{value:t,onValueChange:e=>n(e),className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`border-b px-6 pt-3`,children:[(0,R.jsx)(od,{children:og.map(e=>{let t=e.icon;return(0,R.jsxs)(K,{value:e.key,className:`gap-1.5`,children:[(0,R.jsx)(t,{className:`h-3.5 w-3.5`}),e.label]},e.key)})}),(0,R.jsx)(`p`,{className:`pb-3 pt-2 text-xs text-muted-foreground`,children:r.description})]}),og.map(t=>(0,R.jsx)(sd,{value:t.key,className:`m-0 flex-1 overflow-hidden data-[state=inactive]:hidden`,children:(0,R.jsx)(Jr,{schema:{type:`object-grid`,objectName:t.objectName,columns:t.columns,sort:[{field:t.columns[0],direction:`desc`}]},dataSource:e,className:`h-full`})},t.key))]})]})}var cg=_e(`/$package/logs/`)({component:sg});function lg(e){return e?e.replace(/^\/+/,``).match(/^forms\/([^/?#]+)/i)?.[1]??null:null}function ug(){let e=L(),t=dg.useParams().package,{version:n}=Bu(),[r,i]=(0,F.useState)([]),[a,o]=(0,F.useState)([]),[s,c]=(0,F.useState)(!0),[l,u]=(0,F.useState)(null),[d,f]=(0,F.useState)(!1),[p,m]=(0,F.useState)(``),[h,g]=(0,F.useState)(``),[_,v]=(0,F.useState)(!1),[y,b]=(0,F.useState)(!1),[x,S]=(0,F.useState)(null),[C,w]=(0,F.useState)(``),[T,ee]=(0,F.useState)(`thank-you`),[E,te]=(0,F.useState)(``),[D,ne]=(0,F.useState)(``),[O,re]=(0,F.useState)(``),[k,ie]=(0,F.useState)(!1),A=async()=>{c(!0),u(null);try{let t=await e.meta.getItems(`view`),n=Array.isArray(t)?t:Array.isArray(t?.items)?t.items:[],r=[],a=[];for(let e of n){let t=e?.spec??e;if(!(t?.sections||t?.groups||t?.form||t?.type===`simple`||t?.type===`tabbed`||t?.type===`wizard`||t?.viewType===`form`))continue;let n=t?.sharing,i=n?.publicLink,o=lg(i);n?.allowAnonymous&&o&&i?r.push({name:t?.name??e?.name,label:t?.label,object:t?.object,slug:o,publicLink:i,updatedAt:e?.updatedAt??e?.updated_at,spec:t}):a.push({name:t?.name??e?.name,label:t?.label,object:t?.object,spec:t})}i(r),o(a)}catch(e){u(e?.message??String(e))}finally{c(!1)}};(0,F.useEffect)(()=>{A()},[n]);let j=typeof window<`u`?window.location.origin:``,ae=e=>`${j}/console/f/${e}`,oe=e=>`<iframe src="${ae(e)}" width="100%" height="640" frameborder="0" style="border:0;"></iframe>`,se=e=>`<iframe\n src={\`${ae(e)}\`}\n title="Public form"\n style={{ width: '100%', height: 640, border: 0 }}\n/>`,ce=async(e,t)=>{try{await navigator.clipboard.writeText(t),U({title:`Copied ${e}`})}catch{U({title:`Clipboard unavailable`,variant:`destructive`})}},le=e=>e.trim().toLowerCase().replace(/[^a-z0-9-_]+/g,`-`).replace(/^-+|-+$/g,``),M=async()=>{if(!p||!h)return;let t=a.find(e=>e.name===p);if(!t)return;let n=le(h);if(!n){U({title:`Invalid slug`,variant:`destructive`});return}let r={...t.spec,sharing:{...t.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${n}`}};v(!0);try{await e.meta.saveItem(`view`,t.name,r),U({title:`Published ${t.name}`}),f(!1),m(``),g(``),await A()}catch(e){U({title:`Publish failed: ${e?.message??e}`,variant:`destructive`})}finally{v(!1)}},N=e=>{S(e),w(e.slug);let t=e.spec?.submitBehavior;ee(t?.kind??`thank-you`),te(t?.title??``),ne(t?.message??``),re(t?.url??``),b(!0)},P=async()=>{if(!x)return;let t=le(C);if(!t){U({title:`Invalid slug`,variant:`destructive`});return}let n;switch(T){case`thank-you`:n={kind:`thank-you`},E&&(n.title=E),D&&(n.message=D);break;case`redirect`:if(!O){U({title:`Redirect URL is required`,variant:`destructive`});return}n={kind:`redirect`,url:O};break;case`continue`:case`next-record`:n={kind:T};break}let r={...x.spec,sharing:{...x.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${t}`},submitBehavior:n};ie(!0);try{await e.meta.saveItem(`view`,x.name,r),U({title:`Saved ${x.name}`}),b(!1),S(null),await A()}catch(e){U({title:`Save failed: ${e?.message??e}`,variant:`destructive`})}finally{ie(!1)}},ue=r.length>0;return(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col gap-4 p-4 md:p-6 overflow-auto`,children:[(0,R.jsxs)(X,{children:[(0,R.jsxs)(Z,{className:`flex flex-row items-start justify-between gap-4 space-y-0`,children:[(0,R.jsxs)(`div`,{children:[(0,R.jsxs)(Q,{className:`flex items-center gap-2`,children:[(0,R.jsx)(En,{className:`h-4 w-4`}),`Forms`]}),(0,R.jsxs)(bp,{children:[`Forms anyone can fill out — no login required. Publish a form to get a shareable link; submissions land directly in the bound object.`,` `,(0,R.jsx)(`a`,{href:`/docs/guides/public-forms`,className:`underline underline-offset-2`,target:`_blank`,rel:`noreferrer`,children:`Read the guide →`})]})]}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsxs)(B,{variant:`default`,size:`sm`,onClick:()=>f(!0),disabled:a.length===0,title:a.length===0?`No non-public FormViews available`:`Publish a FormView`,children:[(0,R.jsx)(en,{className:`h-3.5 w-3.5`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:`Publish form…`})]}),(0,R.jsxs)(B,{variant:`outline`,size:`sm`,onClick:A,disabled:s,children:[(0,R.jsx)(Ut,{className:`h-3.5 w-3.5 ${s?`animate-spin`:``}`}),(0,R.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]})]}),(0,R.jsxs)($,{children:[l&&(0,R.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:l}),!s&&!ue&&(0,R.jsxs)(`div`,{className:`rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground`,children:[(0,R.jsx)(`p`,{className:`font-medium text-foreground`,children:`No public forms yet`}),(0,R.jsxs)(`p`,{className:`mt-1`,children:[`Click `,(0,R.jsx)(`strong`,{children:`Publish form…`}),` above to share an existing form, or build a new one in Views & Apps and mark it public.`]})]}),ue&&(0,R.jsxs)(Vf,{children:[(0,R.jsx)(Hf,{children:(0,R.jsxs)(Gf,{children:[(0,R.jsx)(J,{children:`Name`}),(0,R.jsx)(J,{children:`Object`}),(0,R.jsx)(J,{children:`Slug`}),(0,R.jsx)(J,{children:`Public URL`}),(0,R.jsx)(J,{className:`text-right`,children:`Actions`})]})}),(0,R.jsx)(Uf,{children:r.map(e=>{let n=ae(e.slug);return(0,R.jsxs)(Gf,{children:[(0,R.jsx)(Y,{children:(0,R.jsxs)(`div`,{className:`flex flex-col`,children:[(0,R.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),(0,R.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.name})]})}),(0,R.jsx)(Y,{children:e.object?(0,R.jsx)(G,{variant:`secondary`,children:e.object}):(0,R.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,R.jsx)(Y,{children:(0,R.jsx)(`code`,{className:`text-xs`,children:e.slug})}),(0,R.jsx)(Y,{children:(0,R.jsxs)(`a`,{href:n,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary underline-offset-2 hover:underline`,children:[n,(0,R.jsx)(Gt,{className:`h-3 w-3`})]})}),(0,R.jsx)(Y,{className:`text-right`,children:(0,R.jsxs)(`div`,{className:`inline-flex gap-1`,children:[(0,R.jsx)(B,{variant:`ghost`,size:`sm`,title:`Copy URL`,onClick:()=>ce(`URL`,n),children:(0,R.jsx)(Ke,{className:`h-3.5 w-3.5`})}),(0,R.jsx)(B,{variant:`ghost`,size:`sm`,title:`Copy <iframe> embed`,onClick:()=>ce(`iframe snippet`,oe(e.slug)),children:(0,R.jsx)(ze,{className:`h-3.5 w-3.5`})}),(0,R.jsx)(B,{variant:`ghost`,size:`sm`,title:`Copy React snippet`,onClick:()=>ce(`React snippet`,se(e.slug)),children:(0,R.jsx)(mt,{className:`h-3.5 w-3.5`})}),(0,R.jsx)(B,{variant:`ghost`,size:`sm`,title:`Edit sharing & post-submit behavior`,onClick:()=>N(e),children:(0,R.jsx)(gt,{className:`h-3.5 w-3.5`})}),(0,R.jsx)(B,{asChild:!0,variant:`ghost`,size:`sm`,title:`Open metadata`,children:(0,R.jsx)(Link,{to:`/$package/metadata/$type/$name`,params:{package:t,type:`view`,name:e.name},children:(0,R.jsx)(En,{className:`h-3.5 w-3.5`})})})]})})]},e.name)})})]})]})]}),(0,R.jsx)(Hl,{open:d,onOpenChange:f,children:(0,R.jsxs)(Gl,{className:`sm:max-w-md`,children:[(0,R.jsxs)(Kl,{children:[(0,R.jsx)(Jl,{children:`Publish a FormView`}),(0,R.jsxs)(Yl,{children:[`Picks an existing FormView and turns it into a public form by enabling `,(0,R.jsx)(`code`,{className:`text-xs`,children:`sharing.allowAnonymous`}),` `,`and setting `,(0,R.jsx)(`code`,{className:`text-xs`,children:`publicLink`}),`.`]})]}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`publish-view`,children:`FormView`}),(0,R.jsxs)(`select`,{id:`publish-view`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:p,onChange:e=>m(e.target.value),children:[(0,R.jsx)(`option`,{value:``,children:`— Select a FormView —`}),a.map(e=>(0,R.jsxs)(`option`,{value:e.name,children:[e.label??e.name,` (`,e.name,`) `,e.object?`· ${e.object}`:``]},e.name))]})]}),(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`publish-slug`,children:`URL slug`}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,R.jsx)(V,{id:`publish-slug`,placeholder:`contact-us`,value:h,onChange:e=>g(e.target.value)})]}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase letters, digits, dashes and underscores only.`})]})]}),(0,R.jsxs)(ql,{children:[(0,R.jsx)(B,{variant:`ghost`,onClick:()=>f(!1),disabled:_,children:`Cancel`}),(0,R.jsx)(B,{onClick:M,disabled:_||!p||!h,children:_?`Publishing…`:`Publish`})]})]})}),(0,R.jsx)(Hl,{open:y,onOpenChange:b,children:(0,R.jsxs)(Gl,{className:`sm:max-w-lg`,children:[(0,R.jsxs)(Kl,{children:[(0,R.jsx)(Jl,{children:x?`Edit ${x.label??x.name}`:`Edit form`}),(0,R.jsx)(Yl,{children:`Configure the public URL and what happens after submit.`})]}),(0,R.jsxs)(`div`,{className:`space-y-3`,children:[(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`edit-slug`,children:`URL slug`}),(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,R.jsx)(V,{id:`edit-slug`,value:C,onChange:e=>w(e.target.value)})]})]}),(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`edit-behavior`,children:`After submit`}),(0,R.jsxs)(`select`,{id:`edit-behavior`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:T,onChange:e=>ee(e.target.value),children:[(0,R.jsx)(`option`,{value:`thank-you`,children:`Show a thank-you panel`}),(0,R.jsx)(`option`,{value:`redirect`,children:`Redirect to a URL`}),(0,R.jsx)(`option`,{value:`continue`,children:`Reset for another response`}),(0,R.jsx)(`option`,{value:`next-record`,children:`Advance to next record (internal queues)`})]})]}),T===`thank-you`&&(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`edit-tytitle`,children:`Title`}),(0,R.jsx)(V,{id:`edit-tytitle`,placeholder:`Thanks!`,value:E,onChange:e=>te(e.target.value)})]}),(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`edit-tymsg`,children:`Message`}),(0,R.jsx)(V,{id:`edit-tymsg`,placeholder:`Your submission has been received.`,value:D,onChange:e=>ne(e.target.value)})]})]}),T===`redirect`&&(0,R.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,R.jsx)(W,{htmlFor:`edit-url`,children:`Redirect URL`}),(0,R.jsx)(V,{id:`edit-url`,type:`url`,placeholder:`https://example.com/thanks`,value:O,onChange:e=>re(e.target.value)})]})]}),(0,R.jsxs)(ql,{children:[(0,R.jsx)(B,{variant:`ghost`,onClick:()=>b(!1),disabled:k,children:`Cancel`}),(0,R.jsx)(B,{onClick:P,disabled:k||!C,children:k?`Saving…`:`Save`})]})]})})]})}var dg=_e(`/$package/forms/`)({component:ug});function fg(){let{package:e}=pg.useParams();return(0,R.jsx)(Fh,{title:`Automations`,subtitle:`Flows, workflows, approvals, hooks, and triggers — every metadata item that reacts to events.`,types:[`flow`,`workflow`,`approval`,`hook`,`trigger`,`function`],packageId:e})}var pg=_e(`/$package/automations/`)({component:fg});function mg(){let{package:e}=hg.useParams(),t=[{icon:In,label:`Objects`,hint:`Every object exposes /api/v1/data/:name with CRUD + filter/sort/page.`,to:`/${e}/objects`},{icon:En,label:`Public forms`,hint:`Each published FormView gets a /api/v1/forms/:slug endpoint (GET + POST).`,to:`/${e}/forms`},{icon:bn,label:`Automations`,hint:`Flows and webhooks can register their own /api/v1/flow/:id triggers.`,to:`/${e}/automations`},{icon:ut,label:`AI agents & tools`,hint:`Every Tool becomes /api/v1/ai/tools/:name; every Agent /api/v1/ai/agents/:name.`,to:`/${e}/ai`}];return(0,R.jsxs)(`div`,{className:`flex h-full flex-col overflow-auto`,children:[(0,R.jsxs)(`div`,{className:`border-b px-6 py-4`,children:[(0,R.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold tracking-tight`,children:[(0,R.jsx)(wt,{className:`h-5 w-5`}),`APIs`]}),(0,R.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`REST endpoints in ObjectStack are auto-generated from metadata — there is no separate "API" object to design. Pick a source below to see (and edit) the metadata that produces its endpoints, or try them live in the Playground.`})]}),(0,R.jsxs)(`div`,{className:`grid gap-4 p-6 md:grid-cols-2`,children:[(0,R.jsxs)(X,{children:[(0,R.jsxs)(Z,{children:[(0,R.jsxs)(Q,{className:`flex items-center gap-2 text-base`,children:[(0,R.jsx)(pt,{className:`h-4 w-4`}),`Try it live`]}),(0,R.jsx)(bp,{children:`The REST console under Playground groups every mounted endpoint — data, meta, packages, auth, AI, automation, i18n — and lets you fire real requests against the running backend.`})]}),(0,R.jsx)($,{children:(0,R.jsx)(B,{asChild:!0,size:`sm`,className:`gap-1.5`,children:(0,R.jsxs)(we,{to:`/$package/playground`,params:{package:e},children:[(0,R.jsx)(pt,{className:`h-3.5 w-3.5`}),`Open Playground → REST`]})})})]}),(0,R.jsxs)(X,{children:[(0,R.jsxs)(Z,{children:[(0,R.jsxs)(Q,{className:`flex items-center gap-2 text-base`,children:[(0,R.jsx)(Gt,{className:`h-4 w-4`}),`Specs`]}),(0,R.jsx)(bp,{children:`OpenAPI / GraphQL contracts auto-generated from the same metadata.`})]}),(0,R.jsxs)($,{className:`flex flex-wrap gap-2`,children:[(0,R.jsx)(B,{asChild:!0,size:`sm`,variant:`outline`,className:`gap-1.5`,children:(0,R.jsxs)(`a`,{href:`/api/v1/openapi.json`,target:`_blank`,rel:`noreferrer`,children:[`OpenAPI JSON`,(0,R.jsx)(Gt,{className:`h-3 w-3`})]})}),(0,R.jsx)(B,{asChild:!0,size:`sm`,variant:`outline`,className:`gap-1.5`,children:(0,R.jsxs)(`a`,{href:`/docs/protocol/api`,target:`_blank`,rel:`noreferrer`,children:[`Protocol docs`,(0,R.jsx)(Gt,{className:`h-3 w-3`})]})})]})]})]}),(0,R.jsxs)(`div`,{className:`px-6 pb-6`,children:[(0,R.jsx)(`h2`,{className:`mb-3 text-sm font-semibold uppercase tracking-wider text-muted-foreground`,children:`Endpoints come from`}),(0,R.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:t.map(e=>(0,R.jsx)(we,{to:e.to,className:`group rounded-md border bg-card p-4 transition hover:border-primary hover:shadow-sm`,children:(0,R.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,R.jsx)(e.icon,{className:`mt-0.5 h-5 w-5 shrink-0 text-muted-foreground group-hover:text-primary`}),(0,R.jsxs)(`div`,{className:`space-y-1`,children:[(0,R.jsx)(`p`,{className:`font-medium`,children:e.label}),(0,R.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]})},e.label))})]})]})}var hg=_e(`/$package/apis/`)({component:mg});function gg(){let{package:e}=_g.useParams();return(0,R.jsx)(Fh,{title:`AI`,subtitle:`Agents, tools, and skills. Pick an agent and chat with it from the right-hand assistant panel, or invoke a tool from Playground → Tool.`,types:[`agent`,`tool`,`skill`],packageId:e})}var _g=_e(`/$package/ai/`)({component:gg}),vg=[{type:`view`,label:`Views & Forms`,domain:`ui`,previewable:!0},{type:`dashboard`,label:`Dashboards`,domain:`ui`,previewable:!0},{type:`report`,label:`Reports`,domain:`ui`,previewable:!0},{type:`action`,label:`Actions`,domain:`ui`,previewable:!1},{type:`hook`,label:`Hooks`,domain:`data`,previewable:!1},{type:`trigger`,label:`Triggers`,domain:`data`,previewable:!1},{type:`validation`,label:`Validations`,domain:`data`,previewable:!1},{type:`flow`,label:`Flows`,domain:`automation`,previewable:!1},{type:`workflow`,label:`Workflows`,domain:`automation`,previewable:!1},{type:`approval`,label:`Approvals`,domain:`automation`,previewable:!1},{type:`email_template`,label:`Email Templates`,domain:`system`,previewable:!1},{type:`agent`,label:`AI Agents`,domain:`ai`,previewable:!1},{type:`tool`,label:`AI Tools`,domain:`ai`,previewable:!1}];function yg(e,t,n=0){if(n>4||e==null||typeof e==`string`)return!1;if(Array.isArray(e)){for(let r of e)if(yg(r,t,n+1))return!0;return!1}if(typeof e!=`object`)return!1;for(let[r,i]of Object.entries(e))if((r===`object`||r===`objectName`||r===`object_name`||r===`target`)&&i===t||typeof i==`object`&&yg(i,t,n+1))return!0;return!1}function bg(e,t,n){let r=t?.spec??t;if(!r||typeof r!=`object`)return!1;switch(e){case`view`:{if((r.object??r.spec?.object??r.list?.data?.object??r.form?.data?.object??r.data?.object??r.objectName)===n)return!0;let e=r.listViews;if(e&&typeof e==`object`){for(let t of Object.values(e))if(t?.data?.object===n||t?.objectName===n)return!0}return!1}case`hook`:case`trigger`:case`validation`:case`action`:case`approval`:return r.object===n||r.objectName===n||r.object_name===n||r.target===n;case`flow`:case`workflow`:return r.object===n||r.objectName===n||r.trigger?.object===n||r.trigger?.objectName===n||r.trigger?.config?.objectName===n||yg(r.steps,n)||yg(r.states,n);case`dashboard`:case`report`:return r.objectName===n||r.object===n||yg(r.widgets,n)||yg(r.queries,n)||yg(r.dataSource,n);case`agent`:case`tool`:case`email_template`:return yg(r,n);default:return!1}}function xg(e){return e?!!(e.sections||e.groups||e.form||e.type===`simple`||e.type===`tabbed`||e.type===`wizard`||e.viewType===`form`):!1}var Sg={view:On,form:En,dashboard:Ue,report:yn,action:Qt,hook:bn,trigger:Tn,validation:lt,flow:Ot,workflow:Ot,approval:dt,email_template:sn,agent:ut,tool:dn},Cg=[`ui`,`data`,`automation`,`ai`,`system`,`security`],wg={ui:`Interface`,data:`Data`,automation:`Automation`,ai:`AI`,system:`System`,security:`Security`};function Tg(e){return typeof e==`string`?e:e&&typeof e==`object`&&`defaultValue`in e?String(e.defaultValue):``}function Eg({packageId:e,objectName:t}){let n=L(),{version:r}=Bu(),[i,a]=(0,F.useState)([]),[o,s]=(0,F.useState)(!0),[c,l]=(0,F.useState)(null),[u,d]=(0,F.useState)(``),[f,p]=(0,F.useState)(!1),m=(0,F.useMemo)(()=>[`view`,`dashboard`,`report`,`hook`,`approval`,`flow`,`app`],[]);(0,F.useEffect)(()=>{let r=!1;async function i(){s(!0);let i=[];await Promise.all(vg.map(async({type:r})=>{try{let a=await n.meta.getItems(r,{packageId:e}),o=a?.items||(Array.isArray(a)?a:[]);for(let e of o){if(!bg(r,e,t))continue;let n=e.spec??e,a=r===`view`&&xg(n)?`form`:r;i.push({type:r,bucket:a,name:e.name,label:Tg(e.label)||Tg(n?.label)||e.name,spec:n})}}catch{}})),r||(i.sort((e,t)=>e.label.localeCompare(t.label)),a(i),s(!1))}return i(),()=>{r=!0}},[n,e,t,r]);let h=(0,F.useMemo)(()=>{let e=u.trim().toLowerCase();return e?i.filter(t=>t.name.toLowerCase().includes(e)||t.label.toLowerCase().includes(e)):i},[i,u]),g=(0,F.useMemo)(()=>{let e=new Map;for(let t of h){let n=vg.find(e=>e.type===t.type)?.domain??`system`;e.has(n)||e.set(n,new Map);let r=e.get(n),i=t.bucket;r.has(i)||r.set(i,[]),r.get(i).push(t)}return e},[h]);(0,F.useEffect)(()=>{c&&h.some(e=>`${e.type}:${e.name}`===c)||(h.length>0?l(`${h[0].type}:${h[0].name}`):l(null))},[h,c]);let _=(0,F.useMemo)(()=>h.find(e=>`${e.type}:${e.name}`===c)??null,[h,c]),v=e=>e===`form`?`Forms`:vg.find(t=>t.type===e)?.label??e,y=e=>Sg[e]??yn;return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`div`,{className:`flex h-full overflow-hidden`,children:[(0,R.jsxs)(`aside`,{className:`flex w-72 flex-shrink-0 flex-col border-r bg-muted/20`,children:[(0,R.jsxs)(`div`,{className:`border-b p-3`,children:[(0,R.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,R.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wider text-muted-foreground`,children:`Related`}),(0,R.jsxs)(B,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>p(!0),className:`h-6 gap-1 px-2 text-[11px]`,title:`Create new metadata that references ${t}`,children:[(0,R.jsx)(en,{className:`h-3 w-3`}),`New`]})]}),(0,R.jsxs)(`div`,{className:`relative`,children:[(0,R.jsx)(Xe,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,R.jsx)(V,{value:u,onChange:e=>d(e.target.value),placeholder:`Filter related…`,className:`h-8 pl-7 text-xs`})]}),(0,R.jsx)(`div`,{className:`mt-2 text-[11px] text-muted-foreground`,children:o?`Scanning metadata…`:`${i.length} item${i.length===1?``:`s`} reference this object`})]}),(0,R.jsx)(ll,{className:`flex-1`,children:(0,R.jsxs)(`div`,{className:`p-2`,children:[Cg.map(e=>{let t=g.get(e);return!t||t.size===0?null:(0,R.jsxs)(`div`,{className:`mb-3`,children:[(0,R.jsx)(`div`,{className:`px-2 pb-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:wg[e]}),Array.from(t.entries()).map(([e,t])=>(0,R.jsxs)(`div`,{className:`mb-2`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 text-[11px] font-medium text-muted-foreground`,children:[(0,R.jsx)(y(e),{className:`h-3 w-3`}),(0,R.jsx)(`span`,{children:v(e)}),(0,R.jsx)(G,{variant:`secondary`,className:`ml-auto h-4 px-1 text-[10px]`,children:t.length})]}),(0,R.jsx)(`ul`,{children:t.map(e=>{let t=`${e.type}:${e.name}`,n=t===c;return(0,R.jsx)(`li`,{children:(0,R.jsxs)(`button`,{type:`button`,onClick:()=>l(t),className:`group relative flex w-full flex-col gap-0.5 rounded-md py-1.5 pl-3 pr-2 text-left text-xs transition focus:outline-none focus-visible:ring-1 focus-visible:ring-primary ${n?`bg-primary/10 text-primary`:`hover:bg-muted-foreground/10`}`,children:[n&&(0,R.jsx)(`span`,{className:`absolute left-0 top-1.5 bottom-1.5 w-[3px] rounded-r bg-primary`}),(0,R.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),e.label!==e.name&&(0,R.jsx)(`code`,{className:`truncate text-[10px] text-muted-foreground`,children:e.name})]})},t)})})]},e))]},e)}),!o&&i.length===0&&(0,R.jsxs)(`div`,{className:`rounded-md border border-dashed p-4 text-center text-xs text-muted-foreground`,children:[(0,R.jsxs)(`p`,{children:[`Nothing references `,(0,R.jsx)(`code`,{children:t}),` yet.`]}),(0,R.jsxs)(B,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>p(!0),className:`mt-3 h-7 gap-1 text-[11px]`,children:[(0,R.jsx)(en,{className:`h-3 w-3`}),`Create the first one`]})]})]})})]}),(0,R.jsx)(`main`,{className:`flex flex-1 flex-col overflow-hidden`,children:_?(0,R.jsx)(Dg,{packageId:e,objectName:t,item:_}):(0,R.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-8 text-sm text-muted-foreground`,children:`Select an item to preview.`})})]}),(0,R.jsx)(Sh,{open:f,onOpenChange:p,types:m,packageId:e,prefillObjectName:t})]})}function Dg({packageId:e,objectName:t,item:n}){let r=!!vg.find(e=>e.type===n.type)?.previewable;return(0,R.jsxs)(R.Fragment,{children:[(0,R.jsxs)(`header`,{className:`flex items-center gap-3 border-b px-5 py-3`,children:[(0,R.jsx)(Sg[n.bucket]??yn,{className:`h-4 w-4 text-muted-foreground`}),(0,R.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,R.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,R.jsx)(`h2`,{className:`truncate text-sm font-semibold`,children:n.label}),(0,R.jsx)(G,{variant:`outline`,className:`text-[10px]`,children:n.bucket})]}),(0,R.jsx)(`code`,{className:`text-[11px] text-muted-foreground`,children:n.name})]}),(0,R.jsx)(B,{asChild:!0,size:`sm`,className:`gap-1.5`,children:(0,R.jsxs)(we,{to:`/$package/metadata/$type/$name`,params:{package:e,type:n.type,name:n.name},children:[(0,R.jsx)(ze,{className:`h-3.5 w-3.5`}),`Open editor`,(0,R.jsx)(Gt,{className:`ml-0.5 h-3 w-3`})]})})]}),(0,R.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:r?(0,R.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,R.jsx)(Bm,{type:n.type,name:n.name,spec:n.spec,objectName:t})}):(0,R.jsx)(ll,{className:`h-full`,children:(0,R.jsx)(`div`,{className:`p-5`,children:(0,R.jsx)(Og,{spec:n.spec})})})})]})}function Og({spec:e}){let[t,n]=(0,F.useState)(!1),r=(0,F.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]);async function i(){try{await navigator.clipboard.writeText(r),n(!0),setTimeout(()=>n(!1),1500)}catch{}}return(0,R.jsxs)(`div`,{className:`overflow-hidden rounded-md border bg-muted/30`,children:[(0,R.jsxs)(`div`,{className:`flex items-center justify-between border-b bg-muted/30 px-2 py-1 text-[10px] font-medium uppercase tracking-wider text-muted-foreground`,children:[(0,R.jsx)(`span`,{children:`Spec`}),(0,R.jsxs)(B,{type:`button`,onClick:i,size:`sm`,variant:`ghost`,className:`mr-8 h-6 gap-1 text-[11px]`,children:[t?(0,R.jsx)(_t,{className:`h-3 w-3`}):(0,R.jsx)(mt,{className:`h-3 w-3`}),t?`Copied`:`Copy`]})]}),(0,R.jsx)(`pre`,{className:`overflow-auto p-3 text-[11px] leading-relaxed`,children:(0,R.jsx)(`code`,{children:r})})]})}function kg(e,t){return e===`object`?`/api/v1/data/${t}`:e===`view`||e===`form`?`/api/v1/forms/${t}`:`/api/v1/meta/${e}/${t}`}function Ag(e){return{object:`defineObject`,view:`defineView`,flow:`defineFlow`,agent:`defineAgent`,tool:`defineTool`,app:`defineApp`,workflow:`defineWorkflow`,skill:`defineSkill`}[e]??null}async function jg(e,t){try{await navigator.clipboard.writeText(t),U({title:`Copied ${e}`})}catch{U({title:`Clipboard unavailable`,variant:`destructive`})}}function Mg({type:e,name:t,packageId:n}){let r=L(),i=kg(e,t),a=typeof window<`u`?window.location.origin:`http://localhost:3000`,o=(0,F.useCallback)(()=>{jg(`curl`,`curl -X GET '${a}${i}' \\\n -H 'Content-Type: application/json'`)},[a,i]),s=(0,F.useCallback)(()=>{jg(`fetch`,`await fetch('${a}${i}', {\n headers: { 'Content-Type': 'application/json' },\n credentials: 'include',\n}).then((r) => r.json());`)},[a,i]),c=(0,F.useCallback)(async()=>{let n=Ag(e);if(!n){U({title:`No defineX() helper for type "${e}"`,variant:`destructive`});return}try{let i=await r.meta.getItem(e,t),a=i?.spec??i??{},o=`import { ${n} } from '@objectstack/spec';\n\nexport const ${t} = ${n}(\n${JSON.stringify(a,null,2).split(`
|
|
153
|
-
`).map(e=>` `+e).join(`
|
|
154
|
-
`)},\n);\n`;jg(`${n}() TS`,o)}catch(e){U({title:`Failed: ${e?.message??e}`,variant:`destructive`})}},[r,e,t]),l=(0,F.useCallback)(async()=>{try{let n=await r.meta.getItem(e,t);jg(`metadata JSON`,JSON.stringify(n?.spec??n,null,2))}catch(e){U({title:`Failed: ${e?.message??e}`,variant:`destructive`})}},[r,e,t]),u=(0,F.useCallback)(()=>{let r=`vscode://objectstack.vscode-objectstack/open?type=${encodeURIComponent(e)}&name=${encodeURIComponent(t)}${n?`&package=${encodeURIComponent(n)}`:``}`;window.location.href=r},[e,t,n]),d=(0,F.useCallback)(()=>{window.open(i,`_blank`,`noopener,noreferrer`)},[i]);return(0,R.jsxs)(uu,{children:[(0,R.jsx)(du,{asChild:!0,children:(0,R.jsx)(B,{variant:`outline`,size:`sm`,title:`Resource actions`,children:(0,R.jsx)(un,{className:`h-3.5 w-3.5`})})}),(0,R.jsxs)(mu,{align:`end`,className:`w-56`,children:[(0,R.jsx)(hu,{asChild:!0,children:(0,R.jsxs)(we,{to:`/$package/metadata/$type/$name`,params:{package:n??``,type:e,name:t},children:[(0,R.jsx)(xn,{className:`h-3.5 w-3.5 mr-2`}),`View source`]})}),(0,R.jsx)(yu,{}),(0,R.jsx)(vu,{children:`Copy as…`}),(0,R.jsxs)(hu,{onClick:o,children:[(0,R.jsx)(pt,{className:`h-3.5 w-3.5 mr-2`}),`curl`]}),(0,R.jsxs)(hu,{onClick:s,children:[(0,R.jsx)(ze,{className:`h-3.5 w-3.5 mr-2`}),`fetch()`]}),(0,R.jsxs)(hu,{onClick:c,children:[(0,R.jsx)(ze,{className:`h-3.5 w-3.5 mr-2`}),Ag(e)??`defineX`,`() TypeScript`]}),(0,R.jsxs)(hu,{onClick:l,children:[(0,R.jsx)(mt,{className:`h-3.5 w-3.5 mr-2`}),`Metadata JSON`]}),(0,R.jsx)(yu,{}),(0,R.jsxs)(hu,{onClick:u,children:[(0,R.jsx)(Gt,{className:`h-3.5 w-3.5 mr-2`}),`Open in VS Code`]}),(0,R.jsxs)(hu,{onClick:d,children:[(0,R.jsx)(Gt,{className:`h-3.5 w-3.5 mr-2`}),`Open API endpoint`]})]})]})}function Ng(e){return typeof e==`string`?e:e&&typeof e==`object`&&`defaultValue`in e?String(e.defaultValue):``}function Pg(){let{package:e,name:t}=Fg.useParams(),n=L(),{selectedPackage:r}=Uu(e),i=r?.manifest?.id??e,{version:a}=Bu(),[o,s]=(0,F.useState)(`designer`),[c,l]=(0,F.useState)(()=>typeof window>`u`?!1:sessionStorage.getItem(`studio:object-related-nudge:${t}`)===`1`),u=()=>{l(!0);try{sessionStorage.setItem(`studio:object-related-nudge:${t}`,`1`)}catch{}},[d,f]=(0,F.useState)(null),[p,m]=(0,F.useState)(null),[h,g]=(0,F.useState)(null),[_,v]=(0,F.useState)(!1);dd({type:`object`,name:t,packageId:i});let{record:y}=hh(i);(0,F.useEffect)(()=>{let e=!1;return n.meta.getItem(`object`,t).then(n=>{if(e)return;let r=n?.spec??n??null;f(r),y({type:`object`,name:t,label:Ng(r?.label)||r?.name||t})}).catch(()=>{e||f(null)}),()=>{e=!0}},[n,t,a,y]),(0,F.useEffect)(()=>{let e=!1;m(null),g(null),v(!1);async function r(){let r=0;await Promise.all(vg.map(async({type:e})=>{try{let a=await n.meta.getItems(e,{packageId:i}),o=a?.items||(Array.isArray(a)?a:[]);for(let n of o)bg(e,n,t)&&(r+=1)}catch{}})),e||m(r);try{let r=await n.data.find(t,{});e||(typeof r?.total==`number`?g(r.total):Array.isArray(r?.records)&&(g(r.records.length),r.hasMore&&v(!0)))}catch{}}return r(),()=>{e=!0}},[n,t,i,a]);let b=(0,F.useMemo)(()=>Ng(d?.label)||t,[d,t]),x=(0,F.useMemo)(()=>{let e=d?.fields;return Array.isArray(e)?e.length:e&&typeof e==`object`?Object.keys(e).length:null},[d]);return(0,R.jsx)(`div`,{className:`flex h-full flex-col overflow-hidden`,children:(0,R.jsxs)(ad,{value:o,onValueChange:e=>{s(e),e===`related`&&u()},className:`flex h-full flex-col overflow-hidden`,children:[(0,R.jsxs)(`div`,{className:`border-b`,children:[(0,R.jsx)(`div`,{className:`px-6 pt-3 pb-2`,children:(0,R.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,R.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:[(0,R.jsx)(In,{className:`h-5 w-5 flex-shrink-0 text-muted-foreground`}),(0,R.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,R.jsx)(`h1`,{className:`truncate text-lg font-semibold tracking-tight`,title:d?.description||void 0,children:b}),(0,R.jsx)(`code`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground`,children:t})]}),(0,R.jsxs)(`div`,{className:`hidden items-center gap-3 text-[11px] text-muted-foreground lg:flex`,children:[x!==null&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,R.jsx)(Pn,{className:`h-3 w-3`}),(0,R.jsx)(`span`,{className:`font-medium tabular-nums text-foreground`,children:x}),(0,R.jsx)(`span`,{children:`fields`})]}),h!==null&&(0,R.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,R.jsx)(Ye,{className:`h-3 w-3`}),(0,R.jsxs)(`span`,{className:`font-medium tabular-nums text-foreground`,children:[h.toLocaleString(),_?`+`:``]}),(0,R.jsx)(`span`,{children:`records`})]})]})]}),(0,R.jsx)(Mg,{type:`object`,name:t,packageId:e})]})}),(0,R.jsx)(`div`,{className:`px-6`,children:(0,R.jsxs)(od,{className:`h-auto rounded-none border-0 bg-transparent p-0`,children:[(0,R.jsxs)(K,{value:`designer`,className:`relative h-9 gap-1.5 rounded-none border-b-2 border-transparent bg-transparent px-4 text-sm font-medium text-muted-foreground transition data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:text-foreground data-[state=active]:shadow-none`,children:[(0,R.jsx)(In,{className:`h-4 w-4`}),`Designer`]}),(0,R.jsxs)(K,{value:`related`,className:`relative h-9 gap-1.5 rounded-none border-b-2 border-transparent bg-transparent px-4 text-sm font-medium text-muted-foreground transition data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:text-foreground data-[state=active]:shadow-none`,children:[(0,R.jsx)(zn,{className:`h-4 w-4`}),`Related`,p!==null&&p>0&&(0,R.jsx)(`span`,{className:`ml-1.5 inline-flex h-5 min-w-[20px] items-center justify-center rounded-full bg-primary px-1.5 text-[10px] font-semibold tabular-nums text-primary-foreground`,children:p})]})]})})]}),(0,R.jsxs)(`div`,{className:`flex-1 overflow-hidden`,children:[(0,R.jsxs)(sd,{value:`designer`,className:`m-0 flex h-full flex-col overflow-hidden`,children:[o===`designer`&&p!==null&&p>0&&!c&&(0,R.jsxs)(`div`,{className:`flex items-center gap-3 border-b bg-primary/5 px-6 py-2 text-xs`,children:[(0,R.jsx)(st,{className:`h-4 w-4 flex-shrink-0 text-primary`}),(0,R.jsxs)(`span`,{className:`flex-1 text-foreground/80`,children:[(0,R.jsxs)(`span`,{className:`font-medium text-foreground`,children:[p,` item`,p===1?``:`s`]}),` `,`reference this object — view its forms, dashboards, hooks, flows and more.`]}),(0,R.jsxs)(`button`,{type:`button`,onClick:()=>s(`related`),className:`inline-flex items-center gap-1 rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground transition hover:bg-primary/90`,children:[`View Related`,(0,R.jsx)(pn,{className:`h-3 w-3`})]}),(0,R.jsx)(`button`,{type:`button`,onClick:u,className:`rounded-md p-1 text-muted-foreground transition hover:bg-muted hover:text-foreground`,"aria-label":`Dismiss`,title:`Dismiss`,children:(0,R.jsx)(At,{className:`h-3 w-3`})})]}),(0,R.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,R.jsx)(ef,{metadataType:`object`,metadataName:t,packageId:e})})]}),(0,R.jsx)(sd,{value:`related`,className:`m-0 h-full overflow-hidden`,children:(0,R.jsx)(Eg,{packageId:i,objectName:t})})]})]})})}var Fg=_e(`/$package/objects/$name`)({component:Pg});function Ig(){let{package:e,type:t,name:n}=Lg.useParams(),{selectedPackage:r}=Uu(e),i=r?.manifest?.id??e;dd({type:t,name:n,packageId:i});let{record:a}=hh(i),o=L(),[s,c]=(0,F.useState)(null);(0,F.useEffect)(()=>{let e=!1;return(async()=>{try{let r=await o.meta.getItem(t,n,i?{packageId:i}:void 0);if(e)return;c(r),a({type:t,name:n,label:Mh({...r||{},name:n})||jh(n)||n})}catch{e||c(null)}})(),()=>{e=!0}},[o,t,n,i,a]);let l=s?Mh({...s,name:n}):jh(n)||n,u=s?Nh(s,t):void 0,d=Yu(t),f=(t===`view`&&(s?.list?.name||s?.form?.name)||s?.spec?.name)??void 0,p=t===`view`?s?.object??s?.data?.object??s?.list?.data?.object??s?.form?.data?.object:void 0,m=f&&f!==n?f:n,h=!!(p&&p!==m);return(0,R.jsxs)(`div`,{className:`flex flex-1 flex-col overflow-hidden`,children:[(0,R.jsx)(`div`,{className:`border-b px-6 pt-4 pb-3`,children:(0,R.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,R.jsxs)(`div`,{className:`min-w-0`,children:[(0,R.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold tracking-tight`,title:l,children:[d&&(0,R.jsx)(d,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,R.jsx)(`span`,{className:`truncate`,children:l}),l!==m&&(0,R.jsx)(`code`,{className:`ml-1 rounded bg-muted px-1.5 py-0.5 font-mono text-xs text-muted-foreground`,children:m}),(0,R.jsx)(G,{variant:`secondary`,className:`text-[10px]`,children:qu(t)}),h&&(0,R.jsxs)(G,{variant:`outline`,className:`text-[10px] font-mono text-muted-foreground`,children:[`on `,p]})]}),u&&(0,R.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-muted-foreground`,children:u})]}),(0,R.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:(0,R.jsx)(Mg,{type:t,name:n,packageId:i})})]})}),(0,R.jsx)(ef,{metadataType:t,metadataName:n,packageId:i})]})}var Lg=_e(`/$package/metadata/$type/$name`)({component:Ig}),Rg=lh.update({id:`/$package`,path:`/$package`,getParentRoute:()=>nh}),zg=dh.update({id:`/`,path:`/`,getParentRoute:()=>nh}),Bg=Oh.update({id:`/`,path:`/`,getParentRoute:()=>Rg}),Vg=kh.update({id:`/public-forms`,path:`/public-forms`,getParentRoute:()=>Rg}),Hg=Rh.update({id:`/views/`,path:`/views/`,getParentRoute:()=>Rg}),Ug=Bh.update({id:`/security/`,path:`/security/`,getParentRoute:()=>Rg}),Wg=ng.update({id:`/playground/`,path:`/playground/`,getParentRoute:()=>Rg}),Gg=ag.update({id:`/objects/`,path:`/objects/`,getParentRoute:()=>Rg}),Kg=cg.update({id:`/logs/`,path:`/logs/`,getParentRoute:()=>Rg}),qg=dg.update({id:`/forms/`,path:`/forms/`,getParentRoute:()=>Rg}),Jg=pg.update({id:`/automations/`,path:`/automations/`,getParentRoute:()=>Rg}),Yg=hg.update({id:`/apis/`,path:`/apis/`,getParentRoute:()=>Rg}),Xg=_g.update({id:`/ai/`,path:`/ai/`,getParentRoute:()=>Rg}),Zg={PackagePublicFormsRoute:Vg,PackageIndexRoute:Bg,PackageObjectsNameRoute:Fg.update({id:`/objects/$name`,path:`/objects/$name`,getParentRoute:()=>Rg}),PackageAiIndexRoute:Xg,PackageApisIndexRoute:Yg,PackageAutomationsIndexRoute:Jg,PackageFormsIndexRoute:qg,PackageLogsIndexRoute:Kg,PackageObjectsIndexRoute:Gg,PackagePlaygroundIndexRoute:Wg,PackageSecurityIndexRoute:Ug,PackageViewsIndexRoute:Hg,PackageMetadataTypeNameRoute:Lg.update({id:`/metadata/$type/$name`,path:`/metadata/$type/$name`,getParentRoute:()=>Rg})},Qg={IndexRoute:zg,PackageRoute:Rg._addFileChildren(Zg)},$g=nh._addFileChildren(Qg)._addFileTypes();function e_({packageId:e}){let t=e?`/${e}`:`/`;return(0,R.jsx)(`div`,{className:`flex h-full min-h-[60vh] w-full items-center justify-center p-8`,children:(0,R.jsxs)(`div`,{className:`flex max-w-md flex-col items-center text-center`,children:[(0,R.jsx)(`div`,{className:`mb-6 flex h-16 w-16 items-center justify-center rounded-full bg-muted`,children:(0,R.jsx)(Ne,{className:`h-8 w-8 text-muted-foreground`})}),(0,R.jsx)(`h1`,{className:`mb-2 text-2xl font-semibold tracking-tight`,children:`Page not found`}),(0,R.jsx)(`p`,{className:`mb-6 text-sm text-muted-foreground`,children:`The URL you opened doesn’t match anything in Studio. It may have moved, been removed, or simply mistyped.`}),(0,R.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,R.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>window.history.back(),children:[(0,R.jsx)(Lt,{className:`mr-2 h-4 w-4`}),`Go back`]}),(0,R.jsx)(B,{asChild:!0,size:`sm`,children:(0,R.jsxs)(we,{to:t,children:[(0,R.jsx)(Ze,{className:`mr-2 h-4 w-4`}),e?`Package home`:`Studio home`]})})]}),(0,R.jsxs)(`p`,{className:`mt-6 text-xs text-muted-foreground`,children:[`Tip: press `,(0,R.jsx)(`kbd`,{className:`rounded border bg-muted px-1.5 py-0.5 font-mono text-[10px]`,children:`⌘K`}),` to jump to anything.`]})]})})}function t_(){let e=`/_studio/`;return e.endsWith(`/`)?e.slice(0,-1):e}var n_=Ce({routeTree:$g,basepath:t_(),defaultNotFoundComponent:()=>{let e=t_(),t=typeof window<`u`?window.location.pathname:``,n=(e!==`/`&&t.startsWith(e)?t.slice(e.length):t).split(`/`).filter(Boolean);return(0,R.jsx)(e_,{packageId:n[0]&&n[0].includes(`.`)?n[0]:void 0})}});function r_(){return(0,R.jsx)(zu,{children:(0,R.jsx)(xe,{router:n_})})}async function i_(){await xl(),Cl(),$r.createRoot(document.getElementById(`root`)).render((0,R.jsx)(F.StrictMode,{children:(0,R.jsx)(r_,{})}))}i_().catch(e=>{console.error(`[Studio] ❌ Fatal bootstrap error:`,e);let t=document.getElementById(`root`);t&&(t.innerHTML=`
|
|
155
|
-
<div style="padding:2rem;font-family:system-ui;color:#ef4444">
|
|
156
|
-
<h1>Failed to start</h1>
|
|
157
|
-
<pre style="background:#1e1e2e;color:#cdd6f4;padding:1rem;border-radius:8px;overflow:auto">${e instanceof Error?e.stack||e.message:String(e)}</pre>
|
|
158
|
-
</div>
|
|
159
|
-
`)});
|