mirror of
https://github.com/dmduran12/pymc_console-dist.git
synced 2026-07-06 18:01:13 +02:00
2d961cef1a
Automated sync from private repository. Built with obfuscation enabled.
2 lines
16 KiB
JavaScript
2 lines
16 KiB
JavaScript
import{r as f,ef as Z,j as e,a7 as K,aa as X,c4 as M,ct as U,cF as V,ew as G,eB as ee,aC as ae,aL as se,aD as te,a2 as J,bZ as ne,B as w,c as g,aF as le}from"./index-DeL-WnAD.js";import{C as ie}from"./PageLayout-B5m1JzIf.js";import{W as re}from"./wand-sparkles-VdsMsmFL.js";import{A as oe}from"./arrow-right-BZ63wpfW.js";const ce={0:"1-byte",1:"2-byte",2:"3-byte"};function de(s){return ce[s]??`${s+1}-byte`}function ke({nodeName:s,publicKey:a,pathHashMode:r}){const[c,n]=f.useState(null),[o,m]=f.useState(null);f.useEffect(()=>{let l=!1;return(async()=>{try{const p=await Z();if(l)return;if(p.success&&p.data){const h=p.data;n(Array.isArray(h.configured)?h.configured:[]),m(Array.isArray(h.configured_companions)?h.configured_companions:[])}}catch{}})(),()=>{l=!0}},[]);const y=l=>{var p;return((p=l.settings)==null?void 0:p.node_name)||l.name};return e.jsxs(ie,{neomorphic:!0,children:[e.jsx(K,{icon:e.jsx(X,{}),title:"Node Information"}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4 sm:gap-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Repeater Name"}),e.jsx("div",{className:"mt-0.5 sm:mt-1 space-y-2",children:e.jsxs("div",{children:[e.jsx("p",{className:"type-data text-fg-primary truncate font-mono",title:s,children:s}),a&&e.jsx("div",{className:"mt-1 min-w-0",children:e.jsx(M,{copy:!0,truncate:"css",className:"w-full",size:"responsive",children:a})})]})}),r!=null&&e.jsxs("div",{className:"mt-4",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Path Hash Size"}),e.jsx("p",{className:"type-data text-fg-primary mt-0.5 font-mono",children:de(r)})]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Room Servers"}),e.jsx("div",{className:"mt-0.5 sm:mt-1 space-y-2",children:c===null?e.jsx("span",{className:"type-data text-fg-muted",children:"—"}):c.length===0?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(U,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-muted",children:"None"})]}):c.map(l=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(U,{className:"w-3.5 h-3.5 text-sys-indigo flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-primary truncate",title:y(l),children:y(l)})]}),(l.public_key||l.identity_key)&&e.jsx("div",{className:"mt-1 pl-5 min-w-0",children:e.jsx(M,{copy:!0,truncate:"css",className:"w-full",size:"responsive",children:l.public_key||l.identity_key})})]},l.name))})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"type-label text-fg-secondary",children:"Companions"}),e.jsx("div",{className:"mt-0.5 sm:mt-1 space-y-2",children:o===null?e.jsx("span",{className:"type-data text-fg-muted",children:"—"}):o.length===0?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(V,{className:"w-3.5 h-3.5 text-sys-cyan flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-muted",children:"None"})]}):o.map(l=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(V,{className:"w-3.5 h-3.5 text-sys-cyan flex-shrink-0"}),e.jsx("span",{className:"type-data text-fg-primary truncate",title:y(l),children:y(l)})]}),(l.public_key||l.identity_key)&&e.jsx("div",{className:"mt-1 pl-5 min-w-0",children:e.jsx(M,{copy:!0,truncate:"css",className:"w-full",size:"responsive",children:l.public_key||l.identity_key})})]},l.name))})]})]})]})}const j=168,S={sparse:50,light:200,moderate:500,dense:1e3},me={sparse:{bucketCapacity:3,refillTokens:1,refillIntervalHours:1,minIntervalSeconds:15,violationThreshold:2,basePenaltyMinutes:30,penaltyMultiplier:2,maxPenaltyHours:12,violationDecayHours:2,ewmaAlpha:.15,hysteresisMinutes:8},light:{bucketCapacity:2,refillTokens:1,refillIntervalHours:1,minIntervalSeconds:20,violationThreshold:2,basePenaltyMinutes:60,penaltyMultiplier:3,maxPenaltyHours:24,violationDecayHours:2,ewmaAlpha:.12,hysteresisMinutes:6},moderate:{bucketCapacity:2,refillTokens:1,refillIntervalHours:2,minIntervalSeconds:30,violationThreshold:1,basePenaltyMinutes:120,penaltyMultiplier:4,maxPenaltyHours:48,violationDecayHours:4,ewmaAlpha:.1,hysteresisMinutes:5},dense:{bucketCapacity:1,refillTokens:1,refillIntervalHours:4,minIntervalSeconds:60,violationThreshold:1,basePenaltyMinutes:180,penaltyMultiplier:4,maxPenaltyHours:72,violationDecayHours:6,ewmaAlpha:.08,hysteresisMinutes:3},congested:{bucketCapacity:1,refillTokens:1,refillIntervalHours:8,minIntervalSeconds:120,violationThreshold:1,basePenaltyMinutes:360,penaltyMultiplier:4,maxPenaltyHours:168,violationDecayHours:12,ewmaAlpha:.03,hysteresisMinutes:2}};function pe(s){return s<S.sparse?"sparse":s<S.light?"light":s<S.moderate?"moderate":s<S.dense?"dense":"congested"}async function xe(){var h,N,_;const s=await G(`/api/packet_stats?hours=${j}`);if(!s.success||!s.data)throw new Error("Failed to fetch packet stats");const a=s.data,r=((h=a.packet_types.find(i=>i.type===4))==null?void 0:h.count)??0,c=a.drop_reasons??[],n=((N=c.find(i=>i.reason==="advert rate limit exceeded"))==null?void 0:N.count)??0,o=c.filter(i=>i.reason.startsWith("advert penalty box")).reduce((i,d)=>i+d.count,0),m=((_=c.find(i=>i.reason==="Duplicate"))==null?void 0:_.count)??0;let y=0;try{const i=await G("/api/advert_rate_limit_stats");i.success&&i.data&&(y=i.data.tracked_pubkeys??Object.keys(i.data.bucket_states??{}).length)}catch{y=Math.max(1,Math.round(r/j/12))}const l=a.total_packets/j,p=r/j;return{hours:j,totalPackets:a.total_packets,transmittedPackets:a.transmitted_packets,droppedPackets:a.dropped_packets,packetsPerHour:l,advertsPerHour:p,advertPercent:a.total_packets>0?r/a.total_packets*100:0,advertCount:r,trackedSources:Math.max(1,y),advertsPerSourcePerHour:p/Math.max(1,y),rateLimitDrops:n,penaltyBoxDrops:o,duplicateDrops:m,meshDensity:pe(l)}}function ue(s){const a=me[s.meshDensity],r=s.packetsPerHour/60,c=Math.max(.01,B(r*.2)),n=Math.max(c+.01,B(r*.5)),o=Math.max(n+.01,B(r*.9));return{tokenBucket:{enabled:!0,bucket_capacity:a.bucketCapacity,refill_tokens:a.refillTokens,refill_interval_seconds:a.refillIntervalHours*3600,min_interval_seconds:a.minIntervalSeconds},penaltyBox:{enabled:!0,violation_threshold:a.violationThreshold,base_penalty_seconds:a.basePenaltyMinutes*60,penalty_multiplier:a.penaltyMultiplier,max_penalty_seconds:a.maxPenaltyHours*3600,violation_decay_seconds:a.violationDecayHours*3600},adaptive:{enabled:!0,ewma_alpha:a.ewmaAlpha,hysteresis_seconds:a.hysteresisMinutes*60,thresholds:{quiet_max:c,normal_max:n,busy_max:o}}}}async function ye(s){const a=await xe(),r=ue(a);return{analysis:a,recommended:r,current:{tokenBucket:s.tokenBucket??null,penaltyBox:s.penaltyBox??null,adaptive:s.adaptive??null}}}function B(s){return Math.round(s*100)/100}function k(s){if(s<60)return`${s}s`;if(s<3600)return`${Math.floor(s/60)}m`;const a=s/3600;return a===Math.floor(a)?`${a}h`:`${a.toFixed(1)}h`}function A(s){return s.toLocaleString(void 0,{maximumFractionDigits:1})}const he={sparse:"Sparse",light:"Light",moderate:"Moderate",dense:"Dense",congested:"Congested"},fe={sparse:"text-sys-green",light:"text-sys-cyan",moderate:"text-sys-blue",dense:"text-sys-amber",congested:"text-sys-red"},ge={rate_limit_enabled:!1,bucket_capacity:10,refill_tokens:5,refill_interval_seconds:3600,min_interval_seconds:0,penalty_enabled:!1,violation_threshold:5,base_penalty_seconds:1800,penalty_multiplier:2,max_penalty_seconds:86400,violation_decay_seconds:21600,adaptive_enabled:!1,ewma_alpha:.1,hysteresis_seconds:300,quiet_max:2,normal_max:6,busy_max:10},Ne=["rate_limit_enabled","bucket_capacity","refill_tokens","refill_interval_seconds","min_interval_seconds","penalty_enabled","violation_threshold","base_penalty_seconds","penalty_multiplier","max_penalty_seconds","violation_decay_seconds","adaptive_enabled","ewma_alpha","hysteresis_seconds","quiet_max","normal_max","busy_max"];function D({title:s,enabled:a,defaultOpen:r=!1,children:c}){const[n,o]=f.useState(r);return e.jsxs("div",{className:"bg-subtle-fill radius-inner overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>o(!n),className:"w-full flex items-center justify-between px-4 py-3 hover:bg-subtle-fill-hover transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"type-label text-fg-muted",children:s}),e.jsx("span",{className:g("type-data-xs px-1.5 py-0.5 rounded-full font-medium uppercase tracking-wide",a?"bg-sys-green/15 text-sys-green":"bg-sys-red/15 text-sys-red"),children:a?"On":"Off"})]}),e.jsx(le,{className:g("w-4 h-4 text-fg-muted transition-transform",n&&"rotate-180")})]}),n&&e.jsx("div",{className:"px-4 pb-4 pt-1 space-y-1",children:c})]})}function u({label:s,current:a,recommended:r,format:c=n=>String(n)}){const n=a!=null?c(a):"—",o=c(r),m=a!=null&&n!==o;return e.jsxs("div",{className:"flex items-center justify-between gap-2 py-1",children:[e.jsx("span",{className:"type-body-sm text-fg-muted flex-1 min-w-0 truncate",children:s}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("span",{className:g("data-box data-box-compact",m?"text-fg-muted line-through opacity-60":"text-fg-secondary"),children:n}),m&&e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-3 h-3 text-fg-muted"}),e.jsx("span",{className:"data-box data-box-compact text-sys-blue font-medium",children:o})]})]})]})}function we({open:s,onClose:a,currentConfig:r,onApplied:c}){var C,H,P,T,I,R,L,E,$,z,F,O,q,Y;const[n,o]=f.useState("idle"),[m,y]=f.useState(null),[l,p]=f.useState(null),h=f.useCallback(async()=>{o("analyzing"),p(null);try{const t=await ye(r);y(t),o("ready")}catch(t){p(t instanceof Error?t.message:"Analysis failed"),o("error")}},[r]),N=f.useCallback(async()=>{if(!m)return;o("applying"),p(null);const{tokenBucket:t,penaltyBox:b,adaptive:v}=m.recommended,Q={rate_limit_enabled:t.enabled,bucket_capacity:t.bucket_capacity,refill_tokens:t.refill_tokens,refill_interval_seconds:t.refill_interval_seconds,min_interval_seconds:t.min_interval_seconds,penalty_enabled:b.enabled,violation_threshold:b.violation_threshold,base_penalty_seconds:b.base_penalty_seconds,penalty_multiplier:b.penalty_multiplier,max_penalty_seconds:b.max_penalty_seconds,violation_decay_seconds:b.violation_decay_seconds,adaptive_enabled:v.enabled,ewma_alpha:v.ewma_alpha,hysteresis_seconds:v.hysteresis_seconds,quiet_max:v.thresholds.quiet_max,normal_max:v.thresholds.normal_max,busy_max:v.thresholds.busy_max};try{const W=await ee(Q);W.success?(o("applied"),c==null||c()):(p(W.error||"Failed to apply settings"),o("error"))}catch{p("Failed to apply settings"),o("error")}},[m,c]),_=f.useCallback(()=>{a(),setTimeout(()=>{o("idle"),y(null),p(null)},300)},[a]);s&&n==="idle"&&h();const i=m==null?void 0:m.analysis,d=m==null?void 0:m.recommended,x=m==null?void 0:m.current;return e.jsxs(ae,{open:s,onClose:_,size:"lg",children:[e.jsx(se,{icon:e.jsx(re,{size:20}),title:"Auto-Configure",onClose:_}),e.jsxs(te,{className:"flex flex-col gap-5 max-h-[70vh] overflow-y-auto",children:[n==="analyzing"&&e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-12",children:[e.jsx(J,{className:"w-6 h-6 text-sys-blue animate-spin"}),e.jsx("p",{className:"type-body-sm text-fg-muted",children:"Analyzing 7 days of mesh traffic…"})]}),n==="error"&&e.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-8",children:[e.jsx(ne,{className:"w-6 h-6 text-sys-amber"}),e.jsx("p",{className:"type-body-sm text-fg-secondary",children:l}),e.jsx(w,{plain:!0,onClick:h,className:"text-sys-blue",children:"Retry"})]}),(n==="ready"||n==="applying"||n==="applied")&&i&&d&&x&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("div",{className:"type-micro mb-3",children:"7-DAY ANALYSIS"}),e.jsxs("div",{className:"grid grid-cols-4 gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Pkts/hr"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:A(i.packetsPerHour)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Adverts/hr"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:A(i.advertsPerHour)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Sources"}),e.jsx("div",{className:"data-box data-box-fill data-box-left",children:i.trackedSources})]}),e.jsxs("div",{children:[e.jsx("div",{className:"data-box-label",children:"Density"}),e.jsx("div",{className:g("data-box data-box-fill data-box-left",fe[i.meshDensity]),children:he[i.meshDensity]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(D,{title:"Token Bucket of Shame",enabled:d.tokenBucket.enabled,defaultOpen:!0,children:[e.jsx(u,{label:"Bucket Capacity",current:(C=x.tokenBucket)==null?void 0:C.bucket_capacity,recommended:d.tokenBucket.bucket_capacity,format:t=>`${t} tokens`}),e.jsx(u,{label:"Refill Tokens",current:(H=x.tokenBucket)==null?void 0:H.refill_tokens,recommended:d.tokenBucket.refill_tokens,format:t=>`${t} tokens`}),e.jsx(u,{label:"Refill Interval",current:(P=x.tokenBucket)==null?void 0:P.refill_interval_seconds,recommended:d.tokenBucket.refill_interval_seconds,format:t=>k(t)}),e.jsx(u,{label:"Min Interval",current:(T=x.tokenBucket)==null?void 0:T.min_interval_seconds,recommended:d.tokenBucket.min_interval_seconds,format:t=>`${t}s`})]}),e.jsxs(D,{title:"Jail",enabled:d.penaltyBox.enabled,children:[e.jsx(u,{label:"Violation Threshold",current:(I=x.penaltyBox)==null?void 0:I.violation_threshold,recommended:d.penaltyBox.violation_threshold,format:t=>`${t} violations`}),e.jsx(u,{label:"Base Penalty",current:(R=x.penaltyBox)==null?void 0:R.base_penalty_seconds,recommended:d.penaltyBox.base_penalty_seconds,format:t=>k(t)}),e.jsx(u,{label:"Multiplier",current:(L=x.penaltyBox)==null?void 0:L.penalty_multiplier,recommended:d.penaltyBox.penalty_multiplier,format:t=>`${t}×`}),e.jsx(u,{label:"Max Penalty",current:(E=x.penaltyBox)==null?void 0:E.max_penalty_seconds,recommended:d.penaltyBox.max_penalty_seconds,format:t=>k(t)}),e.jsx(u,{label:"Violation Decay",current:($=x.penaltyBox)==null?void 0:$.violation_decay_seconds,recommended:d.penaltyBox.violation_decay_seconds,format:t=>k(t)})]}),e.jsxs(D,{title:"Adaptive Tiers",enabled:d.adaptive.enabled,children:[e.jsx(u,{label:"EWMA α",current:(z=x.adaptive)==null?void 0:z.ewma_alpha,recommended:d.adaptive.ewma_alpha}),e.jsx(u,{label:"Hysteresis",current:(F=x.adaptive)==null?void 0:F.hysteresis_seconds,recommended:d.adaptive.hysteresis_seconds,format:t=>k(t)}),e.jsx(u,{label:"Quiet Max",current:(O=x.adaptive)==null?void 0:O.thresholds.quiet_max,recommended:d.adaptive.thresholds.quiet_max,format:t=>`${t} pkts/min`}),e.jsx(u,{label:"Normal Max",current:(q=x.adaptive)==null?void 0:q.thresholds.normal_max,recommended:d.adaptive.thresholds.normal_max,format:t=>`${t} pkts/min`}),e.jsx(u,{label:"Busy Max",current:(Y=x.adaptive)==null?void 0:Y.thresholds.busy_max,recommended:d.adaptive.thresholds.busy_max,format:t=>`${t} pkts/min`})]})]}),e.jsxs("div",{className:g("flex justify-between gap-4 pt-1",n==="applied"?"items-center":"items-end"),children:[n==="applied"?e.jsx("span",{className:"type-body-sm text-zinc-500",children:"Settings applied"}):e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"data-box-label",children:"Analyzed"}),e.jsxs("div",{className:"data-box data-box-fill data-box-left",children:[A(i.totalPackets)," packets"]})]}),e.jsx("div",{className:"flex items-center gap-2",children:n==="applied"?e.jsx(w,{color:"primary",onClick:_,children:"Done"}):e.jsxs(e.Fragment,{children:[e.jsx(w,{plain:!0,onClick:_,children:"Cancel"}),e.jsx(w,{color:"primary",onClick:N,disabled:n==="applying",children:n==="applying"?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(J,{className:"w-4 h-4 animate-spin"}),"Applying…"]}):"Apply All"})]})})]})]})]})]})}export{we as A,ke as N,ge as S,Ne as a};
|