import{aa as T,j as e,ae as _,Q as A,af as F,L as M,an as G,r as v,ap as Q,T as $,p as z,B as w,I as B,ar as O}from"./index-Dbk1Plmn.js";import{u as V,b as H,c as U}from"./use_schemas-DMLDIw9M.js";import{u as D}from"./use_agents-DbRumskw.js";import{j as q}from"./use_mutations-BiggAKwe.js";import{P as f}from"./page_shell-C0CL85dt.js";import{a as j,s as g}from"./query_loading-BFETHugg.js";import{Q as I}from"./query_refresh_indicator-1_XqkpX1.js";import{T as J,a as K,b as h,c as u}from"./tabs-C_pkkbCq.js";import{C as c,a as y,b as N,c as o}from"./card-CfjWPSFY.js";import{L as k}from"./label-BKULM0qV.js";import{S as Y,a as W,b as X,c as Z,d as ee}from"./select-B273iZTf.js";import{D as se,a as ae,b as te,c as ne,d as re,e as ie,f as de}from"./dialog-CIA-8Qg9.js";import{J as p}from"./json_viewer-ClIBr-BE.js";import{g as le,a as ce,f as oe}from"./agent_grant_key-BDL9K-EB.js";import{P as me}from"./plus-DrFK9jPU.js";import"./relationships-D_VYvxI6.js";import"./index-Bi9XbTox.js";import"./index-dCMWtMMp.js";import"./Combination-DUY7QPO8.js";import"./index-D3OXdV3z.js";import"./chevron-down-BMaycUN9.js";import"./check-C3ZzJelL.js";import"./chevron-right-L2MnFoxW.js";/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const xe=[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"M18 17V9",key:"2bz60n"}],["path",{d:"M13 17V5",key:"1frdt8"}],["path",{d:"M8 17v-3",key:"17ska0"}]],he=T("ChartColumn",xe);/**
 * @license lucide-react v0.475.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ue=[["path",{d:"M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5",key:"1gvzjb"}],["path",{d:"M9 18h6",key:"x1upvd"}],["path",{d:"M10 22h4",key:"ceow96"}]],pe=T("Lightbulb",ue);function je({entityType:n}){var d;const a=D({status:"all"}),r=((d=a.data)==null?void 0:d.grants)??[],i=le(r,n);return e.jsxs(c,{id:"admission-grants",className:"mb-6 scroll-mt-4",children:[e.jsxs(y,{className:"flex flex-row flex-wrap items-center justify-between gap-2 space-y-0 pb-2",children:[e.jsx(N,{className:"text-base",children:"Admission grants"}),j(a)?e.jsx(I,{}):null]}),e.jsxs(o,{className:"space-y-3",children:[e.jsxs("p",{className:"text-xs text-muted-foreground leading-relaxed",children:[e.jsx("code",{className:"text-[11px]",children:"agent_grant"})," capabilities that include this"," ",e.jsx("code",{className:"text-[11px]",children:n})," in ",e.jsx("code",{className:"text-[11px]",children:"entity_types"})," ","(or ",e.jsx("code",{className:"text-[11px]",children:"*"}),"). These gate permissioned operations for admitted agents; ordinary user-authenticated writes may still proceed without a grant for non-protected types."]}),g(a)?e.jsx(_,{className:"h-20 w-full max-w-xl"}):a.error?e.jsx(A,{title:"Could not load grants",children:a.error.message}):i.length===0?e.jsxs("p",{className:"text-sm text-muted-foreground",children:["No grants reference ",e.jsx("span",{className:"font-mono",children:n}),". Add capabilities on an"," ",e.jsx("code",{className:"text-xs",children:"agent_grant"})," entity if agents should be admitted for this type."]}):e.jsx("ul",{className:"divide-y divide-border rounded-md border border-border text-sm",children:i.map(t=>{const m=ce(t),x=m!=="anonymous"?`/agents/${encodeURIComponent(m)}`:null;return e.jsxs("li",{className:"flex flex-col gap-1 px-3 py-2.5 sm:flex-row sm:flex-wrap sm:items-baseline sm:gap-x-3",children:[e.jsx("span",{className:"font-medium",children:t.label}),e.jsx(F,{variant:"outline",className:"w-fit text-xs font-normal",children:t.status}),e.jsx("span",{className:"text-xs text-muted-foreground font-mono break-all",children:t.match_thumbprint?`thumb:${t.match_thumbprint}`:t.match_sub?`sub:${t.match_sub}${t.match_iss?` @ ${t.match_iss}`:""}`:"—"}),e.jsx("span",{className:"text-xs text-muted-foreground w-full sm:flex-1 sm:min-w-[12rem]",children:oe(t)}),x?e.jsx(M,{to:x,className:"text-xs text-primary hover:underline shrink-0",children:"Agent directory →"}):null]},t.grant_id)})})]})]})}const fe={closed:"No guest access. Only admitted agents with grants can interact.",read_only:"Guests can read entities of this type but cannot write.",submit_only:"Guests can submit new entities but cannot read.",submitter_scoped:"Guests can submit and read only their own entities.",open:"Guests can read and write all entities of this type."};function ge({policy:n,entityType:a}){const r=n||"closed",i=r==="closed"?"secondary":r==="open"?"destructive":"default";return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{variant:i,children:r}),!n&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"(default)"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:fe[r]??`Unknown mode: ${r}`}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Manage via CLI: ",e.jsxs("code",{className:"text-xs",children:["neotoma access set ",a," <mode>"]})]})]})}function Be(){var S;const{entityType:n}=G(),a=V(n),r=D({status:"all"}),i=H(n),d=U(n),t=q(),[m,x]=v.useState(""),[C,L]=v.useState("string"),[P]=v.useState(!1),s=a.data;if(g(a))return e.jsx(f,{title:"Loading…",children:e.jsx(Q,{})});if(a.error)return e.jsx(f,{title:"Error",children:e.jsx(A,{title:"Could not load schema",children:a.error.message})});if(!s)return e.jsx(f,{title:"Not Found",children:e.jsx("div",{className:"text-muted-foreground",children:"Schema not found."})});const b=((S=s.schema_definition)==null?void 0:S.fields)??s.field_summary??{},R=j(a)||j(i)||j(d)||j(r);return e.jsxs(f,{title:s.entity_type,description:`Schema v${s.schema_version||"?"}`,actions:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[R?e.jsx(I,{}):null,e.jsxs(se,{children:[e.jsx(ae,{asChild:!0,children:e.jsxs(w,{size:"sm",children:[e.jsx(me,{className:"h-3 w-3 mr-1"})," Add Field"]})}),e.jsxs(te,{children:[e.jsxs(ne,{children:[e.jsx(re,{children:"Add Field to Schema"}),e.jsx(ie,{children:"Incrementally add a field and bump the schema version."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx(k,{children:"Field Name"}),e.jsx(B,{value:m,onChange:l=>x(l.target.value)})]}),e.jsxs("div",{children:[e.jsx(k,{children:"Field Type"}),e.jsxs(Y,{value:C,onValueChange:L,children:[e.jsx(W,{children:e.jsx(X,{})}),e.jsx(Z,{children:["string","number","date","boolean","array","object"].map(l=>e.jsx(ee,{value:l,children:l},l))})]})]})]}),e.jsx(de,{children:e.jsx(w,{onClick:()=>{!m||!n||t.mutate({entity_type:n,fields_to_add:[{field_name:m,field_type:C,required:P}]},{onSuccess:()=>{O.success("Field added"),x("")}})},children:"Add Field"})})]})]})]}),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx($,{type:s.entity_type}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:["v",s.schema_version]}),s.active!==!1&&e.jsx("span",{className:"text-xs text-green-600 font-medium",children:"Active"})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 mb-4",children:[e.jsxs(c,{children:[e.jsx(y,{className:"pb-2",children:e.jsxs(N,{className:"text-base flex items-center gap-2",children:[e.jsx(z,{className:"h-4 w-4"})," Guest Access Policy"]})}),e.jsx(o,{children:e.jsx(ge,{policy:typeof s.metadata=="object"&&s.metadata!==null?s.metadata.guest_access_policy:void 0,entityType:s.entity_type})})]}),e.jsx(je,{entityType:s.entity_type})]}),e.jsxs(J,{defaultValue:"fields",children:[e.jsxs(K,{children:[e.jsxs(h,{value:"fields",children:["Fields (",Object.keys(b).length,")"]}),e.jsx(h,{value:"reducer",children:"Reducer Config"}),e.jsx(h,{value:"metadata",children:"Metadata"}),e.jsx(h,{value:"candidates",children:"Candidates"}),e.jsx(h,{value:"recommendations",children:"Recommendations"})]}),e.jsx(u,{value:"fields",children:e.jsx(c,{children:e.jsx(o,{className:"pt-6",children:Object.keys(b).length>0?e.jsx("div",{className:"space-y-1",children:Object.entries(b).map(([l,E])=>e.jsxs("div",{className:"flex items-start gap-4 py-2 border-b last:border-0",children:[e.jsx("span",{className:"font-mono text-sm text-purple-600 min-w-[160px]",children:l}),e.jsx("div",{className:"flex-1",children:e.jsx(p,{data:E})})]},l))}):e.jsx("p",{className:"text-muted-foreground text-sm",children:"No field definitions."})})})}),e.jsx(u,{value:"reducer",children:e.jsx(c,{children:e.jsx(o,{className:"pt-6",children:e.jsx(p,{data:s.reducer_config,defaultExpanded:!0})})})}),e.jsx(u,{value:"metadata",children:e.jsx(c,{children:e.jsx(o,{className:"pt-6",children:e.jsx(p,{data:s.metadata,defaultExpanded:!0})})})}),e.jsx(u,{value:"candidates",children:e.jsxs(c,{children:[e.jsxs(y,{className:"flex flex-row items-center justify-between",children:[e.jsxs(N,{className:"text-base flex items-center gap-2",children:[e.jsx(he,{className:"h-4 w-4"})," Schema Candidates"]}),e.jsx(w,{variant:"outline",size:"sm",onClick:()=>d.refetch(),children:"Analyze"})]}),e.jsx(o,{children:g(d)?e.jsx(_,{className:"h-24 w-full max-w-lg"}):d.data?e.jsx(p,{data:d.data,defaultExpanded:!0}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Click Analyze to discover candidate fields from raw fragments."})})]})}),e.jsx(u,{value:"recommendations",children:e.jsxs(c,{children:[e.jsx(y,{children:e.jsxs(N,{className:"text-base flex items-center gap-2",children:[e.jsx(pe,{className:"h-4 w-4"})," Recommendations"]})}),e.jsx(o,{children:g(i)?e.jsx(_,{className:"h-24 w-full max-w-lg"}):i.data?e.jsx(p,{data:i.data,defaultExpanded:!0}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No recommendations available."})})]})})]})]})}export{Be as default};
