@antfly/cli-darwin-arm64 0.2.2 → 0.2.3-rc.1

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/bin/antfly CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/antfly
3
- size: 89005384 bytes
4
- sha256: 3e35384f72ed1bbbe4bd7602cf65320ad5ec08b41a100609e33986f05816cc65
3
+ size: 89136712 bytes
4
+ sha256: 581c5947f8b8f29b0c0370a23720055828f0dd82d50ec4c3105d6785c44abe7a
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antfly/cli-darwin-arm64",
3
- "version": "0.2.2",
3
+ "version": "0.2.3-rc.1",
4
4
  "description": "Native Antfly CLI binary for macOS arm64",
5
5
  "license": "Elastic-2.0",
6
6
  "repository": {
@@ -4862,7 +4862,7 @@ to another part of the input.`,order:8}},e.inferenceFlagNames=Object.getOwnPrope
4862
4862
  `);return o?`${i} [data-graph="${e}"] {
4863
4863
  ${o}
4864
4864
  }`:""}).filter(Boolean).join(`
4865
- `)}}):null}UKt();function mHa(e,t,n,a){let r=a?.ticks??300,i=a?.linkDistance??100,o=a?.linkStrength??.3,s=a?.chargeStrength??-200,l=a?.collideRadius??30,u=e.nodes.map(g=>({id:g.id})),d=new Set(u.map(g=>g.id)),p=e.edges.filter(g=>d.has(g.source)&&d.has(g.target)).map(g=>({source:g.source,target:g.target,weight:g.weight??1})),m=zua(u).force("link",Fua(p).id(g=>g.id).distance(i).strength(g=>Math.min(1,g.weight*o))).force("charge",qua().strength(s)).force("center",eua(t/2,n/2)).force("collide",Lua(l)).stop();for(let g=0;g<r;g++)m.tick();let A=new Map;for(let g of u)A.set(g.id,{x:g.x??0,y:g.y??0});return A}function AHa(e){let[t,n]=(0,z.useState)({width:0,height:0}),a=(0,z.useRef)(0);return(0,z.useEffect)(()=>{let r=e.current;if(!r)return;let i=new ResizeObserver(o=>{cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{let s=o[0];if(s){let{width:l,height:u}=s.contentRect;n(d=>d.width===l&&d.height===u?d:{width:l,height:u})}})});return i.observe(r),()=>{cancelAnimationFrame(a.current),i.disconnect()}},[e]),t}var gHa=12,hHa=32;function fHa(e,t){let n=t?.minRadius??gHa,a=t?.maxRadius??hHa;if(!e.length)return()=>n;let r=1/0,i=-1/0;for(let s of e){let l=Math.sqrt((s.metric??0)+1);l<r&&(r=l),l>i&&(i=l)}let o=i-r;if(o<1e-9){let s=(n+a)/2;return()=>s}return s=>n+(Math.sqrt((s??0)+1)-r)/o*(a-n)}function bHa(e){let t=new Set,n=[];for(let a of e)t.has(a.type)||(t.add(a.type),n.push(a.type));return n}function yHa(e,t){let n=new Map;for(let a=0;a<e.length;a++){let r=e[a],i=t?.[r];i?.color?n.set(r,i.color):i?.theme?n.set(r,`var(--graph-color-${r})`):n.set(r,`var(--chart-${a%6+1})`)}return n}var BQt=["#9A94FF","#8B8B96","#C9A834","#477F4F","#F7978D","#4A82B0"];function wHa(e){return BQt[e%BQt.length]}function vHa(e){return Math.min(5,1+(e??1)*.5)}var kHa={graphNode:d1n};function _Ha({data:e,colorConfig:t,layoutOptions:n,nodeSize:a,width:r,height:i,minHeight:o=400,showMinimap:s=!0,showControls:l=!0,showSearch:u=!0,showLegend:d=!0,renderNode:p,renderTooltip:m,renderLegend:A,onNodeClick:g,className:h}){let f=z.useRef(null),y=AHa(f),w=Mce(),v=`graph-${z.useId().replace(/:/g,"")}`,k=r??y.width,_=i??(y.height>0?y.height:o),[x,E]=z.useState(null),S=z.useRef(g);S.current=g;let D=z.useMemo(()=>bHa(e.nodes),[e.nodes]),L=z.useMemo(()=>yHa(D,t),[D,t]),F=z.useMemo(()=>{let W=new Map;return D.forEach((Z,X)=>{W.set(Z,X)}),W},[D]),{rfNodes:M,rfEdges:Q}=z.useMemo(()=>{if(k<=0||_<=0||!e.nodes.length)return{rfNodes:[],rfEdges:[]};let W=mHa(e,k,_,n),Z=fHa(e.nodes,a),X=e.nodes.map(ae=>{let oe=W.get(ae.id)??{x:0,y:0},se=L.get(ae.type)??"var(--chart-1)";return{id:ae.id,type:"graphNode",position:oe,data:{graphNode:ae,radius:Z(ae.metric??0),colorVar:se,selected:ae.id===x,renderNode:p,renderTooltip:m}}}),re=new Set(e.nodes.map(ae=>ae.id));return{rfNodes:X,rfEdges:e.edges.filter(ae=>re.has(ae.source)&&re.has(ae.target)).map((ae,oe)=>({id:`e-${oe}`,source:ae.source,target:ae.target,type:"straight",style:{stroke:"var(--graph-edge-stroke, var(--muted-foreground))",strokeWidth:vHa(ae.weight),opacity:.4}}))}},[e,k,_,n,a,L,x,p,m]),[B,I,R]=RUa([]),[N,O,G]=QUa([]);z.useEffect(()=>{I(M),O(Q),M.length>0&&setTimeout(()=>{w.fitView({padding:.15,duration:300})},50)},[M,Q,I,O,w]);let P=z.useCallback((W,Z)=>{let X=Z.data;E(Z.id),S.current?.(X.graphNode)},[]),Y=z.useCallback(W=>{E(W);let Z=M.find(X=>X.id===W);Z&&w.setCenter(Z.position.x,Z.position.y,{zoom:1.5,duration:400})},[M,w]),U=z.useCallback(W=>{let Z=W.data;return Z?.graphNode?wHa(F.get(Z.graphNode.type)??0):"#6b7280"},[F]);return e.nodes.length?(0,b.jsxs)("div",{"data-graph":v,ref:f,className:on("antfly-graph relative w-full overflow-hidden rounded-none border-(length:--border-width) border-border-strong bg-muted/30",!i&&"h-full",h),style:{height:i??void 0,minHeight:o},children:[(0,b.jsx)(pHa,{id:v,colorConfig:t,typeOrder:D}),u&&(0,b.jsx)(uHa,{nodes:e.nodes,onSelect:Y}),d&&(A?A(L):(0,b.jsx)(zza,{typeColors:L,typeLabels:t?Object.entries(t).reduce((W,[Z,X])=>(X.label&&(W[Z]=X.label),W),{}):void 0,className:"absolute bottom-3 left-3 z-[5]"})),(0,b.jsxs)(LUa,{nodes:B,edges:N,onNodesChange:R,onEdgesChange:G,onNodeClick:P,nodeTypes:kHa,fitView:!0,fitViewOptions:{padding:.15},minZoom:.1,maxZoom:4,proOptions:{hideAttribution:!0},nodesDraggable:!0,panOnDrag:!0,zoomOnScroll:!0,zoomOnPinch:!0,defaultEdgeOptions:{type:"straight",style:{stroke:"var(--graph-edge-stroke, var(--muted-foreground))",strokeWidth:1.5,opacity:.4}},children:[(0,b.jsx)(jUa,{variant:wk.Dots,gap:16,size:1}),l&&(0,b.jsx)(WUa,{position:"bottom-right",showInteractive:!1,style:{transform:"scale(0.85)",transformOrigin:"bottom right"}}),s&&(0,b.jsx)(oHa,{position:"top-right",nodeColor:U,maskColor:"rgba(0,0,0,0.08)",pannable:!0,zoomable:!0,style:{width:80,height:56}})]})]}):(0,b.jsx)("div",{ref:f,className:on("antfly-graph flex items-center justify-center rounded-none border-(length:--border-width) border-border-strong bg-muted/30 text-sm text-muted-foreground",h),style:{minHeight:o},children:"No graph data"})}function CHa(e){return(0,b.jsx)(s1n,{children:(0,b.jsx)(_Ha,{...e})})}var gQe=28;function JL(e){return e.length>gQe?`${e.slice(0,12)}...${e.slice(-10)}`:e}function xHa(e,t){if(!t)return JL(e);for(const n of["title","name","label","text","content"]){const a=t[n];if(typeof a=="string"&&a.trim())return a.length>gQe?`${a.slice(0,gQe-1)}...`:a}return JL(e)}function p1n(e,t){const n=xHa(e.key,t);return e.table?JL(`${e.table}/${n}`):n}function lO(e,t="-"){return e===void 0||Number.isNaN(e)?t:Intl.NumberFormat(void 0,{maximumFractionDigits:3}).format(e)}function EHa(e){return e.filter(t=>t.config.type==="graph")}function BHa(e){return e?.config.edge_types?.map(t=>t.name).filter(Boolean)??[]}function IHa(e,t){return`${e}-${t.replace(/[^a-zA-Z0-9_-]/g,"-")}`}function IQt(e,t,n=!1){const a=e.from.key,r=e.to.key;if(!a||!r)return null;const i=Nae(e.from),o=Nae(e.to);return{id:`${i}->${o}:${e.type??"edge"}:${t}`,source:i,target:o,weight:e.weight??1,type:e.type,metadata:e.metadata,pathEdge:n}}function Nae(e){return JSON.stringify([e.table??null,e.key])}function Y1(e,t,n){const a=typeof t=="string"?{key:t}:t,r=Nae(a),i={...e.get(r)?.metadata??a,...a,...n};e.set(r,{id:r,label:p1n(a,i.document),type:i.depth===0?"start":"document",metric:i.resultCount??(i.depth!==void 0?1/(i.depth+1):1),metadata:i})}function SHa(e){return e?.kind==="nodes"||e?.kind==="paths"?e:null}function THa(e,t){const n=new Map,a=new Map;t&&Y1(n,t,{depth:0});const r=SHa(e);for(const i of r?.kind==="nodes"?r.nodes:[]){if(!i.key)continue;const o={key:i.key,table:i.table},s=i.path??[];Y1(n,o,{depth:i.depth,document:i.document,path:s,resultCount:1});for(const l of s)Y1(n,l);for(const l of i.path_edges??[]){const u=IQt(l,a.size,!0);u&&(a.set(u.id,u),n.has(u.source)||Y1(n,l.from),n.has(u.target)||Y1(n,l.to))}}for(const i of r?.kind==="paths"?r.paths:[]){const o=i.path,s=o.nodes??[];for(const l of s)Y1(n,l,{resultCount:1});for(const l of o.edges??[]){const u=IQt(l,a.size,!0);u&&(a.set(u.id,u),n.has(u.source)||Y1(n,l.from),n.has(u.target)||Y1(n,l.to))}}return{nodes:Array.from(n.values()),edges:Array.from(a.values())}}function DHa(){return{start:{label:"Start",color:"var(--chart-1)"},document:{label:"Document",color:"var(--chart-6)"}}}function NHa(e){if(!e)return{total:0,paths:0};switch(e.kind){case"nodes":return{total:e.stats.returned_items,paths:0};case"paths":return{total:e.stats.returned_items,paths:e.paths.length};case"bindings":return{total:e.rows.length,paths:0};case"aggregates":return{total:Object.keys(e.aggregates).length,paths:0}}}function SQt(e,t,n,a){const r=Number.parseInt(e,10);return Number.isNaN(r)?t:Math.min(a,Math.max(n,r))}function LHa(e,t,n){const a=Number.parseFloat(e);return Number.isNaN(a)?t:Math.max(n,a)}function RHa({tableName:e,indexes:t,onRefreshIndexes:n,initialMode:a="traverse",initialStartKey:r="",initialTargetKey:i="",initialResult:o=null}){const s=dh(),l=(0,z.useMemo)(()=>EHa(t),[t]),[u,d]=(0,z.useState)(""),p=l.find(le=>le.config.name===u),m=(0,z.useMemo)(()=>BHa(p),[p]),[A,g]=(0,z.useState)([]),[h,f]=(0,z.useState)(a),[y,w]=(0,z.useState)("min_hops"),[v,k]=(0,z.useState)(r),[_,x]=(0,z.useState)(i),[E,S]=(0,z.useState)(2),[D,L]=(0,z.useState)(100),[F,M]=(0,z.useState)(0),[Q,B]=(0,z.useState)(!0),[I,R]=(0,z.useState)(!1),[N,O]=(0,z.useState)(!1),[G,P]=(0,z.useState)(null),[Y,U]=(0,z.useState)(o),[W,Z]=(0,z.useState)([]),[X,re]=(0,z.useState)(null);(0,z.useEffect)(()=>{l.length>0&&!l.some(le=>le.config.name===u)&&d(l[0].config.name)},[l,u]),(0,z.useEffect)(()=>{g(le=>le.filter(_e=>m.includes(_e)))},[m]);const ae=(0,z.useMemo)(()=>THa(Y,v.trim()),[Y,v]),oe=NHa(Y),se=(0,z.useCallback)(async()=>{if(e){O(!0),P(null);try{const le=(await s.tables.query(e,{filter_query:{match_all:{}},limit:20}))?.responses?.[0]?.hits?.hits?.map(_e=>_e._id).filter(Boolean)??[];Z(le),!v&&le[0]&&k(le[0])}catch(le){P(le instanceof Error?le.message:"Failed to load sample keys")}finally{O(!1)}}},[s,v,e]),ue=(0,z.useCallback)(async()=>{if(!p||!v.trim()){P("Choose a graph index and start key.");return}if(h==="shortest_path"&&!_.trim()){P("Shortest path needs a target key.");return}R(!0),P(null),re(null);const le=h==="shortest_path"?{index:p.config.name,shortest_path:{from:{key:v.trim()},to:{key:_.trim()},edge_types:A.length>0?A:void 0,max_depth:E,edge_weight:F>0?{min:F}:void 0,objective:y,include_documents:!0}}:{index:p.config.name,traverse:{start:{keys:[v.trim()]},edge_types:A.length>0?A:void 0,max_depth:h==="neighbors"?1:E,limit:D,edge_weight:F>0?{min:F}:void 0,include_paths:Q,include_documents:!0}};try{U((await s.tables.query(e,{graph_queries:{explorer:le},limit:10}))?.responses?.[0]?.graph_results?.explorer??null)}catch(_e){P(_e instanceof Error?_e.message:"Graph query failed")}finally{R(!1)}},[s,Q,E,D,F,h,y,A,p,v,e,_]),ge=(le,_e)=>{g(Se=>_e?[...new Set([...Se,le])]:Se.filter(ye=>ye!==le))};return l.length===0?(0,b.jsxs)(jn,{children:[(0,b.jsx)(Hn,{children:(0,b.jsx)(Wn,{className:"text-lg",children:"Graph Explorer"})}),(0,b.jsx)($n,{className:"text-sm text-muted-foreground",children:"This table does not have a graph index yet."})]}):(0,b.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,b.jsxs)(bo,{className:"items-center justify-between gap-3",children:[(0,b.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,b.jsx)(g0,{className:"size-4 text-muted-foreground"}),(0,b.jsx)("h2",{className:"font-display text-xl tracking-tight",children:"Graph Explorer"}),p?.status?.rebuilding&&(0,b.jsx)(cn,{className:"af-status-badge-warning",children:"Rebuilding"})]}),(0,b.jsxs)(Ct,{variant:"outline",size:"sm",onClick:n,children:[(0,b.jsx)(_x,{className:"size-3.5"}),"Refresh"]})]}),G&&(0,b.jsx)(ei,{variant:"destructive",children:(0,b.jsx)(lo,{children:G})}),(0,b.jsxs)("div",{className:"grid gap-3 md:grid-cols-4",children:[(0,b.jsx)(Lm,{label:"Total edges",value:lO(p?.status?.total_edges),icon:(0,b.jsx)(Fee,{className:"size-4"})}),(0,b.jsx)(Lm,{label:"Edge types",value:m.length,icon:(0,b.jsx)(g0,{className:"size-4"})}),(0,b.jsx)(Lm,{label:"Result nodes",value:lO(oe.total),icon:(0,b.jsx)(N0,{className:"size-4"})}),(0,b.jsx)(Lm,{label:"Paths",value:lO(oe.paths),icon:(0,b.jsx)(Pqe,{className:"size-4"})})]}),(0,b.jsxs)("div",{className:"grid gap-6 xl:grid-cols-[320px_minmax(0,1fr)_320px]",children:[(0,b.jsxs)(jn,{className:"h-fit",children:[(0,b.jsx)(Hn,{children:(0,b.jsx)(Wn,{className:"text-lg",children:"Query"})}),(0,b.jsxs)($n,{className:"space-y-4",children:[(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{children:"Graph index"}),(0,b.jsxs)(Gr,{value:u,onValueChange:d,children:[(0,b.jsx)(Hr,{children:(0,b.jsx)(Ur,{})}),(0,b.jsx)(Wr,{children:l.map(le=>(0,b.jsx)(ra,{value:le.config.name,children:le.config.name},le.config.name))})]})]}),(0,b.jsx)(mT,{value:h,onValueChange:le=>f(le),children:(0,b.jsxs)(AT,{className:"grid w-full grid-cols-3",children:[(0,b.jsx)(Ql,{value:"neighbors",children:"Neighbors"}),(0,b.jsx)(Ql,{value:"traverse",children:"Traverse"}),(0,b.jsx)(Ql,{value:"shortest_path",children:"Path"})]})}),(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-start-key",children:"Start key"}),(0,b.jsxs)(Ct,{variant:"ghost",size:"xs",onClick:se,disabled:N,className:"shrink-0",children:[N?(0,b.jsx)(_0,{className:"size-3.5 animate-spin"}):(0,b.jsx)(nm,{className:"size-3.5"}),"Load keys"]})]}),(0,b.jsx)(an,{id:"graph-start-key",value:v,onChange:le=>k(le.target.value),placeholder:"doc-key"}),W.length>0&&(0,b.jsx)("div",{className:"flex flex-wrap gap-1",children:W.slice(0,5).map(le=>(0,b.jsx)(Ct,{variant:"outline",size:"xs",className:"max-w-full",onClick:()=>k(le),children:JL(le)},le))})]}),h==="shortest_path"&&(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-target-key",children:"Target key"}),(0,b.jsx)(an,{id:"graph-target-key",value:_,onChange:le=>x(le.target.value),placeholder:"target-key"})]}),(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-max-depth",children:"Outgoing depth"}),(0,b.jsx)(an,{id:"graph-max-depth",type:"number",min:1,max:12,value:E,onChange:le=>S(SQt(le.target.value,2,1,12))})]}),h==="shortest_path"?(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{children:"Path score"}),(0,b.jsxs)(Gr,{value:y,onValueChange:le=>w(le),children:[(0,b.jsx)(Hr,{children:(0,b.jsx)(Ur,{})}),(0,b.jsxs)(Wr,{children:[(0,b.jsx)(ra,{value:"min_hops",children:"Min hops"}),(0,b.jsx)(ra,{value:"min_weight_sum",children:"Minimum total weight"}),(0,b.jsx)(ra,{value:"max_weight_product",children:"Maximum weight product"})]})]})]}):(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-max-results",children:"Limit"}),(0,b.jsx)(an,{id:"graph-max-results",type:"number",min:1,max:500,value:D,onChange:le=>L(SQt(le.target.value,100,1,500))})]}),(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-min-weight",children:"Min weight"}),(0,b.jsx)(an,{id:"graph-min-weight",type:"number",min:0,step:.05,value:F,onChange:le=>M(LHa(le.target.value,0,0))})]})]}),m.length>0&&(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{children:"Edge types"}),(0,b.jsx)("div",{className:"grid gap-2 rounded-none border-(length:--border-width) border-border-strong bg-muted/30 p-2",children:m.map(le=>{const _e=IHa("graph-edge-type",le);return(0,b.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,b.jsx)(lk,{id:_e,checked:A.includes(le),onCheckedChange:Se=>ge(le,Se===!0)}),(0,b.jsx)(Yt,{htmlFor:_e,className:"font-normal",children:le}),(0,b.jsx)(cn,{className:"ml-auto",children:lO(p?.status?.edge_types?.[le],"0")})]},le)})})]}),(0,b.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,b.jsx)(lk,{id:"graph-include-paths",checked:Q,onCheckedChange:le=>B(le===!0)}),(0,b.jsx)(Yt,{htmlFor:"graph-include-paths",className:"font-normal",children:"Include paths"})]}),(0,b.jsxs)(Ct,{className:"w-full",onClick:ue,disabled:I,children:[I?(0,b.jsx)(_0,{className:"size-4 animate-spin"}):(0,b.jsx)(Fee,{className:"size-4"}),"Run graph query"]})]})]}),(0,b.jsxs)(jn,{className:"min-h-[620px] overflow-hidden",children:[(0,b.jsxs)(Hn,{className:"flex flex-row items-center justify-between",children:[(0,b.jsxs)(Wn,{className:"flex items-center gap-2 text-lg",children:[(0,b.jsx)(Pqe,{className:"size-4"}),u||"Graph"]}),(0,b.jsxs)("div",{className:"flex gap-2",children:[(0,b.jsxs)(cn,{children:[ae.nodes.length," nodes"]}),(0,b.jsxs)(cn,{children:[ae.edges.length," edges"]})]})]}),(0,b.jsx)($n,{className:"h-[560px] p-0",children:(0,b.jsx)(CHa,{data:ae,colorConfig:DHa(),minHeight:560,className:"border-0",showLegend:!0,showMinimap:!0,showSearch:!0,onNodeClick:re,renderTooltip:le=>(0,b.jsxs)("div",{className:"space-y-1",children:[(0,b.jsx)("div",{className:"font-medium",children:le.label}),(0,b.jsx)("div",{className:"text-xs text-muted-foreground",children:le.metadata?.key}),le.metadata?.depth!==void 0&&(0,b.jsxs)("div",{className:"text-xs",children:["Depth ",le.metadata.depth]})]})})})]}),(0,b.jsxs)(jn,{className:"h-fit",children:[(0,b.jsx)(Hn,{children:(0,b.jsx)(Wn,{className:"text-lg",children:"Inspector"})}),(0,b.jsxs)($n,{className:"space-y-4",children:[X?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-xs text-muted-foreground",children:"Key"}),(0,b.jsx)("div",{className:"break-all font-mono text-sm",children:X.metadata?.key})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-xs text-muted-foreground",children:"Depth"}),(0,b.jsx)("div",{className:"font-medium",children:X.metadata?.depth??"-"})]}),X.metadata?.path&&X.metadata.path.length>0&&(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"mb-1 text-xs text-muted-foreground",children:"Path"}),(0,b.jsx)("div",{className:"space-y-1",children:X.metadata.path.map(le=>(0,b.jsx)(cn,{className:"mr-1 max-w-full",children:p1n(le)},Nae(le)))})]}),X.metadata?.document&&(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"mb-2 text-xs text-muted-foreground",children:"Document"}),(0,b.jsx)(sh,{json:X.metadata.document})]})]}):(0,b.jsx)("div",{className:"text-sm text-muted-foreground",children:"Select a node to inspect it."}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"mb-2 text-xs text-muted-foreground",children:"Edges"}),ae.edges.length>0?(0,b.jsx)("div",{className:"max-h-80 space-y-2 overflow-auto pr-1",children:ae.edges.slice(0,40).map(le=>(0,b.jsxs)("div",{className:"rounded-none border-(length:--border-width) border-border-strong bg-muted/30 p-2 text-xs",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)(cn,{variant:(le.pathEdge,"default"),children:le.type??"edge"}),(0,b.jsxs)("span",{className:"text-muted-foreground",children:["w ",lO(le.weight)]})]}),(0,b.jsxs)("div",{className:"mt-2 break-all font-mono",children:[JL(le.source)," ","->"," ",JL(le.target)]})]},le.id))}):(0,b.jsx)("div",{className:"text-sm text-muted-foreground",children:"No edges in the current view."})]})]})]})]}),(0,b.jsxs)(jn,{children:[(0,b.jsx)(Hn,{children:(0,b.jsx)(Wn,{className:"text-lg",children:"Index configuration"})}),(0,b.jsx)($n,{children:p?(0,b.jsx)(sh,{json:p.config}):null})]})]})}var QHa=Nm({jsonFile:MQa().refine(e=>e?.length===1,"File is required."),idField:_r().min(1,"ID Field is required.")}),FHa=({tableName:e})=>{const[t,n]=(0,z.useState)(""),[a,r]=(0,z.useState)(null),[i,o]=(0,z.useState)(null),[s,l]=(0,z.useState)(!1),u=(0,z.useRef)(null),d=(0,z.useRef)(null),[p,m]=(0,z.useState)([]),A=Y$({resolver:Yse(QHa)}),{watch:g,setValue:h}=A,f=g("idField"),y=g("jsonFile");(0,z.useEffect)(()=>{(async()=>{if(e)try{const x=await cQe.tables.get(e);if(x.schema&&Object.keys(x.schema).length>0){const E=x.schema,S=E.default_type;if(S&&E.document_schemas){const D=E.document_schemas[S];D?.key&&h("idField",D.key)}}}catch{}})()},[e,h]);const w=_=>{const x=_.target.files?.[0];if(x){h("jsonFile",_.target.files);const E=new FileReader;E.onload=()=>{const S=E.result;if(n(S),S)try{const D=S.split(`
4865
+ `)}}):null}UKt();function mHa(e,t,n,a){let r=a?.ticks??300,i=a?.linkDistance??100,o=a?.linkStrength??.3,s=a?.chargeStrength??-200,l=a?.collideRadius??30,u=e.nodes.map(g=>({id:g.id})),d=new Set(u.map(g=>g.id)),p=e.edges.filter(g=>d.has(g.source)&&d.has(g.target)).map(g=>({source:g.source,target:g.target,weight:g.weight??1})),m=zua(u).force("link",Fua(p).id(g=>g.id).distance(i).strength(g=>Math.min(1,g.weight*o))).force("charge",qua().strength(s)).force("center",eua(t/2,n/2)).force("collide",Lua(l)).stop();for(let g=0;g<r;g++)m.tick();let A=new Map;for(let g of u)A.set(g.id,{x:g.x??0,y:g.y??0});return A}function AHa(e){let[t,n]=(0,z.useState)({width:0,height:0}),a=(0,z.useRef)(0);return(0,z.useEffect)(()=>{let r=e.current;if(!r)return;let i=new ResizeObserver(o=>{cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{let s=o[0];if(s){let{width:l,height:u}=s.contentRect;n(d=>d.width===l&&d.height===u?d:{width:l,height:u})}})});return i.observe(r),()=>{cancelAnimationFrame(a.current),i.disconnect()}},[e]),t}var gHa=12,hHa=32;function fHa(e,t){let n=t?.minRadius??gHa,a=t?.maxRadius??hHa;if(!e.length)return()=>n;let r=1/0,i=-1/0;for(let s of e){let l=Math.sqrt((s.metric??0)+1);l<r&&(r=l),l>i&&(i=l)}let o=i-r;if(o<1e-9){let s=(n+a)/2;return()=>s}return s=>n+(Math.sqrt((s??0)+1)-r)/o*(a-n)}function bHa(e){let t=new Set,n=[];for(let a of e)t.has(a.type)||(t.add(a.type),n.push(a.type));return n}function yHa(e,t){let n=new Map;for(let a=0;a<e.length;a++){let r=e[a],i=t?.[r];i?.color?n.set(r,i.color):i?.theme?n.set(r,`var(--graph-color-${r})`):n.set(r,`var(--chart-${a%6+1})`)}return n}var BQt=["#9A94FF","#8B8B96","#C9A834","#477F4F","#F7978D","#4A82B0"];function wHa(e){return BQt[e%BQt.length]}function vHa(e){return Math.min(5,1+(e??1)*.5)}var kHa={graphNode:d1n};function _Ha({data:e,colorConfig:t,layoutOptions:n,nodeSize:a,width:r,height:i,minHeight:o=400,showMinimap:s=!0,showControls:l=!0,showSearch:u=!0,showLegend:d=!0,renderNode:p,renderTooltip:m,renderLegend:A,onNodeClick:g,className:h}){let f=z.useRef(null),y=AHa(f),w=Mce(),v=`graph-${z.useId().replace(/:/g,"")}`,k=r??y.width,_=i??(y.height>0?y.height:o),[x,E]=z.useState(null),S=z.useRef(g);S.current=g;let D=z.useMemo(()=>bHa(e.nodes),[e.nodes]),L=z.useMemo(()=>yHa(D,t),[D,t]),F=z.useMemo(()=>{let W=new Map;return D.forEach((Z,X)=>{W.set(Z,X)}),W},[D]),{rfNodes:M,rfEdges:Q}=z.useMemo(()=>{if(k<=0||_<=0||!e.nodes.length)return{rfNodes:[],rfEdges:[]};let W=mHa(e,k,_,n),Z=fHa(e.nodes,a),X=e.nodes.map(ae=>{let oe=W.get(ae.id)??{x:0,y:0},se=L.get(ae.type)??"var(--chart-1)";return{id:ae.id,type:"graphNode",position:oe,data:{graphNode:ae,radius:Z(ae.metric??0),colorVar:se,selected:ae.id===x,renderNode:p,renderTooltip:m}}}),re=new Set(e.nodes.map(ae=>ae.id));return{rfNodes:X,rfEdges:e.edges.filter(ae=>re.has(ae.source)&&re.has(ae.target)).map((ae,oe)=>({id:`e-${oe}`,source:ae.source,target:ae.target,type:"straight",style:{stroke:"var(--graph-edge-stroke, var(--muted-foreground))",strokeWidth:vHa(ae.weight),opacity:.4}}))}},[e,k,_,n,a,L,x,p,m]),[B,I,R]=RUa([]),[N,O,G]=QUa([]);z.useEffect(()=>{I(M),O(Q),M.length>0&&setTimeout(()=>{w.fitView({padding:.15,duration:300})},50)},[M,Q,I,O,w]);let P=z.useCallback((W,Z)=>{let X=Z.data;E(Z.id),S.current?.(X.graphNode)},[]),Y=z.useCallback(W=>{E(W);let Z=M.find(X=>X.id===W);Z&&w.setCenter(Z.position.x,Z.position.y,{zoom:1.5,duration:400})},[M,w]),U=z.useCallback(W=>{let Z=W.data;return Z?.graphNode?wHa(F.get(Z.graphNode.type)??0):"#6b7280"},[F]);return e.nodes.length?(0,b.jsxs)("div",{"data-graph":v,ref:f,className:on("antfly-graph relative w-full overflow-hidden rounded-none border-(length:--border-width) border-border-strong bg-muted/30",!i&&"h-full",h),style:{height:i??void 0,minHeight:o},children:[(0,b.jsx)(pHa,{id:v,colorConfig:t,typeOrder:D}),u&&(0,b.jsx)(uHa,{nodes:e.nodes,onSelect:Y}),d&&(A?A(L):(0,b.jsx)(zza,{typeColors:L,typeLabels:t?Object.entries(t).reduce((W,[Z,X])=>(X.label&&(W[Z]=X.label),W),{}):void 0,className:"absolute bottom-3 left-3 z-[5]"})),(0,b.jsxs)(LUa,{nodes:B,edges:N,onNodesChange:R,onEdgesChange:G,onNodeClick:P,nodeTypes:kHa,fitView:!0,fitViewOptions:{padding:.15},minZoom:.1,maxZoom:4,proOptions:{hideAttribution:!0},nodesDraggable:!0,panOnDrag:!0,zoomOnScroll:!0,zoomOnPinch:!0,defaultEdgeOptions:{type:"straight",style:{stroke:"var(--graph-edge-stroke, var(--muted-foreground))",strokeWidth:1.5,opacity:.4}},children:[(0,b.jsx)(jUa,{variant:wk.Dots,gap:16,size:1}),l&&(0,b.jsx)(WUa,{position:"bottom-right",showInteractive:!1,style:{transform:"scale(0.85)",transformOrigin:"bottom right"}}),s&&(0,b.jsx)(oHa,{position:"top-right",nodeColor:U,maskColor:"rgba(0,0,0,0.08)",pannable:!0,zoomable:!0,style:{width:80,height:56}})]})]}):(0,b.jsx)("div",{ref:f,className:on("antfly-graph flex items-center justify-center rounded-none border-(length:--border-width) border-border-strong bg-muted/30 text-sm text-muted-foreground",h),style:{minHeight:o},children:"No graph data"})}function CHa(e){return(0,b.jsx)(s1n,{children:(0,b.jsx)(_Ha,{...e})})}var gQe=28;function JL(e){return e.length>gQe?`${e.slice(0,12)}...${e.slice(-10)}`:e}function xHa(e,t){if(!t)return JL(e);for(const n of["title","name","label","text","content"]){const a=t[n];if(typeof a=="string"&&a.trim())return a.length>gQe?`${a.slice(0,gQe-1)}...`:a}return JL(e)}function p1n(e,t){const n=xHa(e.key,t);return e.table?JL(`${e.table}/${n}`):n}function lO(e,t="-"){return e===void 0||Number.isNaN(e)?t:Intl.NumberFormat(void 0,{maximumFractionDigits:3}).format(e)}function EHa(e){return e.filter(t=>t.config.type==="graph")}function BHa(e){return e?.config.edge_types?.map(t=>t.name).filter(Boolean)??[]}function IHa(e,t){return`${e}-${t.replace(/[^a-zA-Z0-9_-]/g,"-")}`}function IQt(e,t,n=!1){const a=e.from.key,r=e.to.key;if(!a||!r)return null;const i=Nae(e.from),o=Nae(e.to);return{id:`${i}->${o}:${e.type??"edge"}:${t}`,source:i,target:o,weight:e.weight??1,type:e.type,metadata:e.metadata,pathEdge:n}}function Nae(e){return JSON.stringify([e.table??null,e.key])}function Y1(e,t,n){const a=typeof t=="string"?{key:t}:t,r=Nae(a),i={...e.get(r)?.metadata??a,...a,...n};e.set(r,{id:r,label:p1n(a,i.document),type:i.depth===0?"start":"document",metric:i.resultCount??(i.depth!==void 0?1/(i.depth+1):1),metadata:i})}function SHa(e){return e?.kind==="nodes"||e?.kind==="paths"?e:null}function THa(e,t){const n=new Map,a=new Map;t&&Y1(n,t,{depth:0});const r=SHa(e);for(const i of r?.kind==="nodes"?r.nodes:[]){if(!i.key)continue;const o={key:i.key,table:i.table},s=i.path??[];Y1(n,o,{depth:i.depth,document:i.document,path:s,resultCount:1});for(const l of s)Y1(n,l);for(const l of i.path_edges??[]){const u=IQt(l,a.size,!0);u&&(a.set(u.id,u),n.has(u.source)||Y1(n,l.from),n.has(u.target)||Y1(n,l.to))}}for(const i of r?.kind==="paths"?r.paths:[]){const o=i.path,s=o.nodes??[];for(const l of s)Y1(n,l,{resultCount:1});for(const l of o.edges??[]){const u=IQt(l,a.size,!0);u&&(a.set(u.id,u),n.has(u.source)||Y1(n,l.from),n.has(u.target)||Y1(n,l.to))}}return{nodes:Array.from(n.values()),edges:Array.from(a.values())}}function DHa(){return{start:{label:"Start",color:"var(--chart-1)"},document:{label:"Document",color:"var(--chart-6)"}}}function NHa(e){if(!e)return{total:0,paths:0};switch(e.kind){case"nodes":return{total:e.stats.returned_items,paths:0};case"paths":return{total:e.stats.returned_items,paths:e.paths.length};case"bindings":return{total:e.rows.length,paths:0};case"aggregates":return{total:Object.keys(e.aggregates).length,paths:0}}}function SQt(e,t,n,a){const r=Number.parseInt(e,10);return Number.isNaN(r)?t:Math.min(a,Math.max(n,r))}function LHa(e,t,n){const a=Number.parseFloat(e);return Number.isNaN(a)?t:Math.max(n,a)}function RHa({tableName:e,indexes:t,onRefreshIndexes:n,initialMode:a="traverse",initialStartKey:r="",initialTargetKey:i="",initialResult:o=null}){const s=dh(),l=(0,z.useMemo)(()=>EHa(t),[t]),[u,d]=(0,z.useState)(""),p=l.find(le=>le.config.name===u),m=(0,z.useMemo)(()=>BHa(p),[p]),[A,g]=(0,z.useState)([]),[h,f]=(0,z.useState)(a),[y,w]=(0,z.useState)("min_hops"),[v,k]=(0,z.useState)(r),[_,x]=(0,z.useState)(i),[E,S]=(0,z.useState)(2),[D,L]=(0,z.useState)(100),[F,M]=(0,z.useState)(0),[Q,B]=(0,z.useState)(!0),[I,R]=(0,z.useState)(!1),[N,O]=(0,z.useState)(!1),[G,P]=(0,z.useState)(null),[Y,U]=(0,z.useState)(o),[W,Z]=(0,z.useState)([]),[X,re]=(0,z.useState)(null);(0,z.useEffect)(()=>{l.length>0&&!l.some(le=>le.config.name===u)&&d(l[0].config.name)},[l,u]),(0,z.useEffect)(()=>{g(le=>le.filter(_e=>m.includes(_e)))},[m]);const ae=(0,z.useMemo)(()=>THa(Y,v.trim()),[Y,v]),oe=NHa(Y),se=(0,z.useCallback)(async()=>{if(e){O(!0),P(null);try{const le=(await s.tables.query(e,{filter_query:{match_all:{}},limit:20}))?.responses?.[0]?.hits?.hits?.map(_e=>_e._id).filter(Boolean)??[];Z(le),!v&&le[0]&&k(le[0])}catch(le){P(le instanceof Error?le.message:"Failed to load sample keys")}finally{O(!1)}}},[s,v,e]),ue=(0,z.useCallback)(async()=>{if(!p||!v.trim()){P("Choose a graph index and start key.");return}if(h==="shortest_path"&&!_.trim()){P("Shortest path needs a target key.");return}R(!0),P(null),re(null);const le=h==="shortest_path"?{index:p.config.name,shortest_path:{from:{key:v.trim()},to:{key:_.trim()},edge_types:A.length>0?A:void 0,max_depth:E,...F>0?{edge_weight:{min:F}}:{},objective:y,include_documents:!0}}:{index:p.config.name,traverse:{start:{keys:[v.trim()]},edge_types:A.length>0?A:void 0,max_depth:h==="neighbors"?1:E,limit:D,...F>0?{edge_weight:{min:F}}:{},include_paths:Q,include_documents:!0}};try{U((await s.tables.query(e,{graph_queries:{explorer:le},limit:10}))?.responses?.[0]?.graph_results?.explorer??null)}catch(_e){P(_e instanceof Error?_e.message:"Graph query failed")}finally{R(!1)}},[s,Q,E,D,F,h,y,A,p,v,e,_]),ge=(le,_e)=>{g(Se=>_e?[...new Set([...Se,le])]:Se.filter(ye=>ye!==le))};return l.length===0?(0,b.jsxs)(jn,{children:[(0,b.jsx)(Hn,{children:(0,b.jsx)(Wn,{className:"text-lg",children:"Graph Explorer"})}),(0,b.jsx)($n,{className:"text-sm text-muted-foreground",children:"This table does not have a graph index yet."})]}):(0,b.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,b.jsxs)(bo,{className:"items-center justify-between gap-3",children:[(0,b.jsxs)("div",{className:"flex min-w-0 items-center gap-2",children:[(0,b.jsx)(g0,{className:"size-4 text-muted-foreground"}),(0,b.jsx)("h2",{className:"font-display text-xl tracking-tight",children:"Graph Explorer"}),p?.status?.rebuilding&&(0,b.jsx)(cn,{className:"af-status-badge-warning",children:"Rebuilding"})]}),(0,b.jsxs)(Ct,{variant:"outline",size:"sm",onClick:n,children:[(0,b.jsx)(_x,{className:"size-3.5"}),"Refresh"]})]}),G&&(0,b.jsx)(ei,{variant:"destructive",children:(0,b.jsx)(lo,{children:G})}),(0,b.jsxs)("div",{className:"grid gap-3 md:grid-cols-4",children:[(0,b.jsx)(Lm,{label:"Total edges",value:lO(p?.status?.total_edges),icon:(0,b.jsx)(Fee,{className:"size-4"})}),(0,b.jsx)(Lm,{label:"Edge types",value:m.length,icon:(0,b.jsx)(g0,{className:"size-4"})}),(0,b.jsx)(Lm,{label:"Result nodes",value:lO(oe.total),icon:(0,b.jsx)(N0,{className:"size-4"})}),(0,b.jsx)(Lm,{label:"Paths",value:lO(oe.paths),icon:(0,b.jsx)(Pqe,{className:"size-4"})})]}),(0,b.jsxs)("div",{className:"grid gap-6 xl:grid-cols-[320px_minmax(0,1fr)_320px]",children:[(0,b.jsxs)(jn,{className:"h-fit",children:[(0,b.jsx)(Hn,{children:(0,b.jsx)(Wn,{className:"text-lg",children:"Query"})}),(0,b.jsxs)($n,{className:"space-y-4",children:[(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{children:"Graph index"}),(0,b.jsxs)(Gr,{value:u,onValueChange:d,children:[(0,b.jsx)(Hr,{children:(0,b.jsx)(Ur,{})}),(0,b.jsx)(Wr,{children:l.map(le=>(0,b.jsx)(ra,{value:le.config.name,children:le.config.name},le.config.name))})]})]}),(0,b.jsx)(mT,{value:h,onValueChange:le=>f(le),children:(0,b.jsxs)(AT,{className:"grid w-full grid-cols-3",children:[(0,b.jsx)(Ql,{value:"neighbors",children:"Neighbors"}),(0,b.jsx)(Ql,{value:"traverse",children:"Traverse"}),(0,b.jsx)(Ql,{value:"shortest_path",children:"Path"})]})}),(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-start-key",children:"Start key"}),(0,b.jsxs)(Ct,{variant:"ghost",size:"xs",onClick:se,disabled:N,className:"shrink-0",children:[N?(0,b.jsx)(_0,{className:"size-3.5 animate-spin"}):(0,b.jsx)(nm,{className:"size-3.5"}),"Load keys"]})]}),(0,b.jsx)(an,{id:"graph-start-key",value:v,onChange:le=>k(le.target.value),placeholder:"doc-key"}),W.length>0&&(0,b.jsx)("div",{className:"flex flex-wrap gap-1",children:W.slice(0,5).map(le=>(0,b.jsx)(Ct,{variant:"outline",size:"xs",className:"max-w-full",onClick:()=>k(le),children:JL(le)},le))})]}),h==="shortest_path"&&(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-target-key",children:"Target key"}),(0,b.jsx)(an,{id:"graph-target-key",value:_,onChange:le=>x(le.target.value),placeholder:"target-key"})]}),(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-max-depth",children:"Outgoing depth"}),(0,b.jsx)(an,{id:"graph-max-depth",type:"number",min:1,max:12,value:E,onChange:le=>S(SQt(le.target.value,2,1,12))})]}),h==="shortest_path"?(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{children:"Path score"}),(0,b.jsxs)(Gr,{value:y,onValueChange:le=>w(le),children:[(0,b.jsx)(Hr,{children:(0,b.jsx)(Ur,{})}),(0,b.jsxs)(Wr,{children:[(0,b.jsx)(ra,{value:"min_hops",children:"Min hops"}),(0,b.jsx)(ra,{value:"min_weight_sum",children:"Minimum total weight"}),(0,b.jsx)(ra,{value:"max_weight_product",children:"Maximum weight product"})]})]})]}):(0,b.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-max-results",children:"Limit"}),(0,b.jsx)(an,{id:"graph-max-results",type:"number",min:1,max:500,value:D,onChange:le=>L(SQt(le.target.value,100,1,500))})]}),(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{htmlFor:"graph-min-weight",children:"Min weight"}),(0,b.jsx)(an,{id:"graph-min-weight",type:"number",min:0,step:.05,value:F,onChange:le=>M(LHa(le.target.value,0,0))})]})]}),m.length>0&&(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsx)(Yt,{children:"Edge types"}),(0,b.jsx)("div",{className:"grid gap-2 rounded-none border-(length:--border-width) border-border-strong bg-muted/30 p-2",children:m.map(le=>{const _e=IHa("graph-edge-type",le);return(0,b.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,b.jsx)(lk,{id:_e,checked:A.includes(le),onCheckedChange:Se=>ge(le,Se===!0)}),(0,b.jsx)(Yt,{htmlFor:_e,className:"font-normal",children:le}),(0,b.jsx)(cn,{className:"ml-auto",children:lO(p?.status?.edge_types?.[le],"0")})]},le)})})]}),(0,b.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,b.jsx)(lk,{id:"graph-include-paths",checked:Q,onCheckedChange:le=>B(le===!0)}),(0,b.jsx)(Yt,{htmlFor:"graph-include-paths",className:"font-normal",children:"Include paths"})]}),(0,b.jsxs)(Ct,{className:"w-full",onClick:ue,disabled:I,children:[I?(0,b.jsx)(_0,{className:"size-4 animate-spin"}):(0,b.jsx)(Fee,{className:"size-4"}),"Run graph query"]})]})]}),(0,b.jsxs)(jn,{className:"min-h-[620px] overflow-hidden",children:[(0,b.jsxs)(Hn,{className:"flex flex-row items-center justify-between",children:[(0,b.jsxs)(Wn,{className:"flex items-center gap-2 text-lg",children:[(0,b.jsx)(Pqe,{className:"size-4"}),u||"Graph"]}),(0,b.jsxs)("div",{className:"flex gap-2",children:[(0,b.jsxs)(cn,{children:[ae.nodes.length," nodes"]}),(0,b.jsxs)(cn,{children:[ae.edges.length," edges"]})]})]}),(0,b.jsx)($n,{className:"h-[560px] p-0",children:(0,b.jsx)(CHa,{data:ae,colorConfig:DHa(),minHeight:560,className:"border-0",showLegend:!0,showMinimap:!0,showSearch:!0,onNodeClick:re,renderTooltip:le=>(0,b.jsxs)("div",{className:"space-y-1",children:[(0,b.jsx)("div",{className:"font-medium",children:le.label}),(0,b.jsx)("div",{className:"text-xs text-muted-foreground",children:le.metadata?.key}),le.metadata?.depth!==void 0&&(0,b.jsxs)("div",{className:"text-xs",children:["Depth ",le.metadata.depth]})]})})})]}),(0,b.jsxs)(jn,{className:"h-fit",children:[(0,b.jsx)(Hn,{children:(0,b.jsx)(Wn,{className:"text-lg",children:"Inspector"})}),(0,b.jsxs)($n,{className:"space-y-4",children:[X?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-xs text-muted-foreground",children:"Key"}),(0,b.jsx)("div",{className:"break-all font-mono text-sm",children:X.metadata?.key})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"text-xs text-muted-foreground",children:"Depth"}),(0,b.jsx)("div",{className:"font-medium",children:X.metadata?.depth??"-"})]}),X.metadata?.path&&X.metadata.path.length>0&&(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"mb-1 text-xs text-muted-foreground",children:"Path"}),(0,b.jsx)("div",{className:"space-y-1",children:X.metadata.path.map(le=>(0,b.jsx)(cn,{className:"mr-1 max-w-full",children:p1n(le)},Nae(le)))})]}),X.metadata?.document&&(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"mb-2 text-xs text-muted-foreground",children:"Document"}),(0,b.jsx)(sh,{json:X.metadata.document})]})]}):(0,b.jsx)("div",{className:"text-sm text-muted-foreground",children:"Select a node to inspect it."}),(0,b.jsxs)("div",{children:[(0,b.jsx)("div",{className:"mb-2 text-xs text-muted-foreground",children:"Edges"}),ae.edges.length>0?(0,b.jsx)("div",{className:"max-h-80 space-y-2 overflow-auto pr-1",children:ae.edges.slice(0,40).map(le=>(0,b.jsxs)("div",{className:"rounded-none border-(length:--border-width) border-border-strong bg-muted/30 p-2 text-xs",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,b.jsx)(cn,{variant:(le.pathEdge,"default"),children:le.type??"edge"}),(0,b.jsxs)("span",{className:"text-muted-foreground",children:["w ",lO(le.weight)]})]}),(0,b.jsxs)("div",{className:"mt-2 break-all font-mono",children:[JL(le.source)," ","->"," ",JL(le.target)]})]},le.id))}):(0,b.jsx)("div",{className:"text-sm text-muted-foreground",children:"No edges in the current view."})]})]})]})]}),(0,b.jsxs)(jn,{children:[(0,b.jsx)(Hn,{children:(0,b.jsx)(Wn,{className:"text-lg",children:"Index configuration"})}),(0,b.jsx)($n,{children:p?(0,b.jsx)(sh,{json:p.config}):null})]})]})}var QHa=Nm({jsonFile:MQa().refine(e=>e?.length===1,"File is required."),idField:_r().min(1,"ID Field is required.")}),FHa=({tableName:e})=>{const[t,n]=(0,z.useState)(""),[a,r]=(0,z.useState)(null),[i,o]=(0,z.useState)(null),[s,l]=(0,z.useState)(!1),u=(0,z.useRef)(null),d=(0,z.useRef)(null),[p,m]=(0,z.useState)([]),A=Y$({resolver:Yse(QHa)}),{watch:g,setValue:h}=A,f=g("idField"),y=g("jsonFile");(0,z.useEffect)(()=>{(async()=>{if(e)try{const x=await cQe.tables.get(e);if(x.schema&&Object.keys(x.schema).length>0){const E=x.schema,S=E.default_type;if(S&&E.document_schemas){const D=E.document_schemas[S];D?.key&&h("idField",D.key)}}}catch{}})()},[e,h]);const w=_=>{const x=_.target.files?.[0];if(x){h("jsonFile",_.target.files);const E=new FileReader;E.onload=()=>{const S=E.result;if(n(S),S)try{const D=S.split(`
4866
4866
  `)[0];if(D){const L=JSON.parse(D);m(Object.keys(L))}}catch(D){console.error("Failed to parse first line of file:",D),m([])}},E.onerror=()=>{console.error("Failed to read file."),m([])},E.readAsText(x)}},v=(0,z.useCallback)(_=>{const x=d.current,E=`{{${_}}}`;if(x){const S=x.selectionStart??x.value.length,D=x.selectionEnd??S;h("idField",x.value.slice(0,S)+E+x.value.slice(D),{shouldValidate:!0}),requestAnimationFrame(()=>{const L=S+E.length;x.focus(),x.setSelectionRange(L,L)})}else h("idField",(A.getValues("idField")??"")+E,{shouldValidate:!0})},[h,A]),k=(0,z.useCallback)(async()=>{if(!y||!f||!e){r("Please select a file and specify the ID field.");return}l(!0),r(null),o(null);const _=new FileReader;_.onload=async()=>{const x=_.result;if(!x){r("Failed to read file content."),l(!1);return}try{const E=x.split(`
4867
4867
  `).filter(F=>F.trim()!==""),S={},D=f.includes("{{");for(const F of E){const M=JSON.parse(F);let Q;if(D?Q=f.replace(/\{\{(\w+)\}\}/g,(B,I)=>{const R=M[I];if(R==null)throw new Error(`Template field "{{${I}}}" not found in document: ${F.slice(0,100)}`);return String(R)}):Q=M[f],!Q)throw new Error(`ID field "${f}" produced an empty ID for document: ${F.slice(0,100)}`);S[Q]=M}const L={inserts:S};await cQe.tables.batch(e,L),o(`Successfully inserted ${Object.keys(S).length} documents.`),A.reset(),n(""),m([]),u.current&&(u.current.value="")}catch(E){E instanceof Error?r(`Failed to process file: ${E.message}`):r("An unknown error occurred."),console.error(E)}finally{l(!1)}},_.onerror=()=>{r("Failed to read file."),l(!1)},_.readAsText(y[0])},[y,f,e,A]);return(0,b.jsxs)("div",{className:"space-y-4",children:[(0,b.jsxs)(jn,{children:[(0,b.jsx)(Hn,{children:(0,b.jsx)(Wn,{children:"Insert from File"})}),(0,b.jsx)($n,{children:(0,b.jsxs)(V$,{form:A,onSubmit:A.handleSubmit(k),children:[(0,b.jsxs)("p",{className:"text-muted-foreground",children:["Upload a newline-delimited JSON file. Each line should be a valid JSON object. The ID field supports Handlebars-style templates like"," ",(0,b.jsx)("code",{className:"text-xs bg-muted px-1 py-0.5 rounded-none",children:"{{category}}-{{slug}}"})," ","to compose IDs from multiple fields."]}),(0,b.jsx)(ya,{control:A.control,name:"jsonFile",render:()=>(0,b.jsxs)(na,{children:[(0,b.jsx)(ea,{children:"JSON File"}),(0,b.jsx)(aa,{children:(0,b.jsx)("input",{type:"file",accept:".json,.jsonl",onChange:w,ref:u,className:"block w-full max-w-full truncate text-sm text-muted-foreground file:mr-4 file:rounded-full file:border-0 file:bg-accent file:px-4 file:py-2 file:text-sm file:font-semibold file:text-accent-foreground hover:file:bg-accent/80"})}),(0,b.jsx)(er,{})]})}),t&&(0,b.jsx)(ec,{value:t,readOnly:!0,placeholder:"File content will appear here",rows:8,className:"w-full max-h-64 overflow-auto break-all whitespace-pre-wrap"}),(0,b.jsx)(ya,{control:A.control,name:"idField",render:({field:_})=>(0,b.jsxs)(na,{children:[(0,b.jsx)(ea,{children:"ID Field"}),(0,b.jsx)(aa,{children:(0,b.jsx)(an,{..._,ref:x=>{_.ref(x),d.current=x},placeholder:"e.g. id or {{category}}-{{slug}}"})}),(0,b.jsxs)(Kv,{children:["A field name (e.g. ",(0,b.jsx)("code",{className:"text-xs",children:"id"}),") or a template (e.g."," ",(0,b.jsx)("code",{className:"text-xs",children:"{{category}}-{{slug}}"}),")."]}),p.length>0&&(0,b.jsx)("div",{className:"flex flex-wrap gap-1 pt-1",children:p.map(x=>(0,b.jsx)(cn,{className:"cursor-pointer hover:bg-secondary/80",onClick:()=>v(x),children:x},x))}),(0,b.jsx)(er,{})]})}),(0,b.jsx)(om,{className:"justify-start",children:(0,b.jsx)(Ct,{type:"submit",disabled:!y||!f||s,children:s?(0,b.jsx)(hje,{}):"Upload File"})})]})})]}),a&&(0,b.jsxs)(ei,{variant:"destructive",children:[(0,b.jsx)(Ire,{className:"h-4 w-4"}),(0,b.jsx)(PP,{children:"Error"}),(0,b.jsx)(lo,{children:a})]}),i&&(0,b.jsxs)(ei,{children:[(0,b.jsx)(DOt,{className:"h-4 w-4"}),(0,b.jsx)(PP,{children:"Success"}),(0,b.jsx)(lo,{children:i})]})]})},jce=({availableFields:e=[],onFieldSelect:t,label:n="Available fields from schema:",className:a})=>{if(e.length===0)return null;const r=i=>"searchField"in i;return(0,b.jsxs)("div",{className:a,children:[(0,b.jsx)(Yt,{className:"text-sm font-medium text-muted-foreground",children:n}),(0,b.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:e.map(i=>{const o=r(i),s=o?i.searchField:i.fieldName,l=i.displayName;return(0,b.jsxs)(cn,{className:"cursor-pointer hover:bg-accent hover:text-accent-foreground transition-colors",onClick:()=>t(s),title:o?`Search field: ${i.searchField}
4868
4868
  Schema types: ${i.schemaTypes.join(", ")}
@@ -11,7 +11,7 @@
11
11
  href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Roboto+Mono:wght@400;500;700&family=Silkscreen:wght@400;700&display=swap"
12
12
  rel="stylesheet"
13
13
  />
14
- <script type="module" crossorigin src="/assets/index-CzrJXyaN.js"></script>
14
+ <script type="module" crossorigin src="/assets/index-D94Ct5Jd.js"></script>
15
15
  <link rel="stylesheet" crossorigin href="/assets/index-B9-BVv7X.css">
16
16
  </head>
17
17
  <body>