ccdeck 3.45.0 → 3.46.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/README.md +7 -4
- package/bin/cli/startup.js +4 -3
- package/dist/web/assets/BrowserWatchModal-CoX9FIUE.js +1 -0
- package/dist/web/assets/IntegrationModal-B1ypkK-E.js +5 -0
- package/dist/web/assets/RadioPanel-biw_BbZq.js +1 -0
- package/dist/web/assets/TrafficRadar-nhtFoYVv.js +8 -0
- package/dist/web/assets/{UsageHistoryModal-DAhplVju.js → UsageHistoryModal-Bd-JRAa4.js} +1 -1
- package/dist/web/assets/app-BlRY6EME.css +1 -0
- package/dist/web/assets/app-DhGvSH7o.js +319 -0
- package/dist/web/assets/{index-r8Ymr47Q.js → index-DmENqVdt.js} +1 -1
- package/dist/web/index.html +3 -3
- package/package.json +1 -1
- package/release-notes.json +30 -0
- package/src/server/claude-accounts.mjs +35 -19
- package/src/server/claude-login.mjs +111 -0
- package/src/server/cswap-admin.mjs +12 -3
- package/src/server/installer.mjs +24 -7
- package/src/server/login-service.mjs +2 -2
- package/src/server/skill-hook.mjs +28 -22
- package/src/server/system-metrics.mjs +4 -0
- package/src/server/tool-audit-routes.mjs +4 -0
- package/src/server/traffic-radar-config.mjs +33 -0
- package/src/server/traffic-radar-platform.mjs +84 -17
- package/src/server/traffic-radar-service.mjs +6 -3
- package/src/server/traffic-radar.mjs +32 -9
- package/dist/web/assets/BrowserWatchModal-Cbzf3TWa.js +0 -1
- package/dist/web/assets/IntegrationModal-BnnBr0a3.js +0 -5
- package/dist/web/assets/RadioPanel-BIqrMLQN.js +0 -1
- package/dist/web/assets/TrafficRadar-D1gZCIwX.js +0 -8
- package/dist/web/assets/app-BW3NYUYB.js +0 -318
- package/dist/web/assets/app-C5RY_wZ4.css +0 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{j as e,b as l,a3 as Vn,a4 as pn,r as _s,a5 as Ls,w as Ms,a6 as Fn,n as Ks,o as Vs,t as Fs}from"./app-DhGvSH7o.js";const $s={radar:e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M20 12a8 8 0 1 1-8-8v8l5-5"}),e.jsx("path",{d:"M12 8a4 4 0 1 0 4 4"}),e.jsx("circle",{cx:"12",cy:"12",r:"1"})]}),connection:e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M8 8h8v8H8zM12 3v5M12 16v5M3 12h5M16 12h5"}),e.jsx("circle",{cx:"12",cy:"3",r:"1"}),e.jsx("circle",{cx:"21",cy:"12",r:"1"})]}),logs:e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"5",y:"3",width:"14",height:"18",rx:"2"}),e.jsx("path",{d:"M9 8h6M9 12h6M9 16h3"})]}),metrics:e.jsx(e.Fragment,{children:e.jsx("path",{d:"M4 20h16M7 16v-5M12 16V4M17 16V8"})}),traces:e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M7 5h10M7 12h10M7 19h10M12 5v14"}),e.jsx("circle",{cx:"7",cy:"5",r:"2"}),e.jsx("circle",{cx:"17",cy:"12",r:"2"}),e.jsx("circle",{cx:"7",cy:"19",r:"2"})]}),info:e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"12",cy:"12",r:"9"}),e.jsx("path",{d:"M12 11v5M12 7h.01"})]})};function Et({kind:t,...n}){return e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",...n,children:$s[t]})}function Yt({className:t="",children:n,...s}){return e.jsxs("span",{className:"tr-select-wrap",children:[e.jsx("select",{...s,className:`tr-select${t?` ${t}`:""}`,children:n}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})}function cn(t,n=!1){return n||t.active===null?"Visibility unavailable":t.connecting?t.active?"Connecting · no reply yet":"Attempted · no reply seen":t.active?"Active connection":"Previously observed"}function $n(t){return[...new Set(t.filter(n=>n.key.endsWith("ENDPOINT")).map(n=>n.value).filter(n=>/^https?:\/\//.test(n)))]}function Bn(t){return(t==null?void 0:t.status)!=="observing"?[]:[...new Set(t.connections.filter(n=>n.active===!0&&!n.connecting).map(n=>n.destination))]}function kn(t){try{const n=new URL(t);return/^\d+\.\d+\.\d+\.\d+$/.test(n.hostname)?`${n.hostname}:${n.port||(n.protocol==="https:"?"443":"80")}`:null}catch{return null}}function Bs(t){const n=t.filter(o=>o.key==="CLAUDE_CODE_ENABLE_TELEMETRY"),s=n.map(o=>o.value);if(!s.length)return"Unknown";if(new Set(s).size>1)return"Conflicting settings";const r=n.every(o=>o.launch)?"in launch environment":"in settings";return s[0]==="Enabled"?`Enabled ${r}`:s[0]==="Disabled"?`Disabled ${r}`:"Unknown"}function Hs(t){const n=t.replace(/^\uFEFF/,"").trim();if(!n)return[];let s;try{JSON.parse(n),s=[n]}catch{s=t.replace(/^\uFEFF/,"").split(/\r?\n/)}if(s.length>1e4)throw new Error("This file has more than 10,000 lines. Choose a smaller export.");return s.flatMap((r,o)=>{var i;if(!r.trim())return[];try{const p=JSON.parse(r),u=p&&typeof p=="object"?p:{},m=new Set,a=[p];for(;a.length;){const c=a.pop();if(!c||typeof c!="object")continue;if(Array.isArray(c)){for(const h of c)a.push(h);continue}const g=c;for(const h of["session.id","session_id","sessionId"])typeof g[h]=="string"&&m.add(g[h]);if(["session.id","session_id"].includes(String(g.key))){const h=g.value;typeof(h==null?void 0:h.stringValue)=="string"&&m.add(h.stringValue)}for(const h of Object.values(g))a.push(h)}return[{line:o+1,raw:r,sessionIds:[...m],label:String(u.eventName??((i=u.event)==null?void 0:i.name)??u.type??u.model??"JSON record").slice(0,160),sessionId:typeof(u.session_id??u.sessionId??u["session.id"])=="string"?u.session_id??u.sessionId??u["session.id"]:null,timestamp:typeof u.timestamp=="string"?u.timestamp:null,valid:!0}]}catch{return[{line:o+1,raw:r,label:"Invalid JSON",sessionId:null,timestamp:null,sessionIds:[],valid:!1}]}})}function Ws(){const[t,n]=l.useState(null),[s,r]=l.useState(!1),o=l.useRef(0);return l.useEffect(()=>{let p=!0,u,m=null;const a=()=>document.visibilityState!=="hidden",c=()=>{clearTimeout(u),m==null||m.abort(),m=null},g=async()=>{if(!p||!a()||m)return;const v=new AbortController,w=o.current;m=v;try{const C=await fetch("/api/system/traffic-radar",{signal:v.signal});if(!C.ok)throw new Error("radar_unavailable");const S=await C.json();if(!S.ok)throw new Error("radar_unavailable");p&&!v.signal.aborted&&w===o.current&&(n(S),r(!1))}catch{p&&!v.signal.aborted&&w===o.current&&r(!0)}finally{m===v&&(m=null),p&&!v.signal.aborted&&a()&&(u=setTimeout(g,5e3))}},h=()=>{c(),document.visibilityState!=="hidden"&&g()};return g(),document.addEventListener("visibilitychange",h),()=>{p=!1,c(),document.removeEventListener("visibilitychange",h)}},[]),{snapshot:t,failed:s,updateConfig:p=>{o.current++,n(u=>u&&{...u,config:p})}}}function zs(){const[t,n]=l.useState(null),[s,r]=l.useState(!1),[o,i]=l.useState(!1),[p,u]=l.useState(""),[m,a]=l.useState(""),[c,g]=l.useState([]),[h,v]=l.useState(null),[w,C]=l.useState(null),S=l.useRef(null),R=l.useRef(null),P=l.useRef(0);l.useEffect(()=>{let b=!0,f,y=null;const N=()=>document.visibilityState!=="hidden",x=()=>{clearTimeout(f),y==null||y.abort(),y=null},k=async()=>{if(!b||!N()||y)return;if(S.current){f=setTimeout(k,1e3);return}const F=P.current,j=new AbortController;y=j;try{const L=await fetch("/api/system/traffic-radar/capture",{signal:j.signal});if(!L.ok)throw new Error;const A=await L.json();b&&!j.signal.aborted&&F===P.current&&(n(A),r(!1))}catch{b&&!j.signal.aborted&&F===P.current&&r(!0)}finally{y===j&&(y=null),b&&!j.signal.aborted&&N()&&(f=setTimeout(k,1e3))}},B=()=>{x(),document.visibilityState!=="hidden"&&k()};return k(),document.addEventListener("visibilitychange",B),()=>{var F;b=!1,x(),(F=R.current)==null||F.abort(),document.removeEventListener("visibilitychange",B)}},[]);const _=async(b,f)=>{if(!Vn(S.current))return;P.current++,S.current=b,C(b),i(!0),u("");const y=new AbortController;R.current=y;const N=setTimeout(()=>y.abort(),2e4);try{const x=await fetch(`/api/system/traffic-radar/capture/${b}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({destination:f}),signal:y.signal}),k=await x.json();if(!x.ok)throw new Error(k.error||"Capture action failed. Please retry.");b==="prepare"&&(a(k.command),g(k.commands??[{destination:String(f),command:k.command}]),v(k.sessionId)),b==="stop"&&(a(""),g([]));const B=await fetch("/api/system/traffic-radar/capture",{signal:y.signal});B.ok&&(n(await B.json()),r(!1))}catch(x){u(x instanceof Error?x.message:"Capture action failed. Please retry.")}finally{clearTimeout(N),R.current=null,S.current=null,C(null),i(!1)}};return{capture:t,failed:s,busy:o,pendingAction:w,error:p,commands:(t==null?void 0:t.sessionId)===h?c:[],command:(t==null?void 0:t.sessionId)===h?m:"",action:_}}function Us({workspace:t,width:n,onCommit:s}){const r=l.useRef(null),o=a=>Math.max(28,Math.min(65,a)),i=a=>{var c;return(c=t.current)==null?void 0:c.style.setProperty("--tr-feed-width",`${a}%`)},p=a=>{const c=o(a);i(c),s(c)},u=a=>{if(r.current===null||!t.current)return;const c=t.current.getBoundingClientRect();r.current=o((a.clientX-c.left)/c.width*100),i(r.current),a.currentTarget.setAttribute("aria-valuenow",String(Math.round(r.current)))},m=()=>{var c;if(r.current===null)return;const a=r.current;r.current=null,(c=t.current)==null||c.removeAttribute("data-resizing"),p(a)};return e.jsx("div",{className:"tr-splitter",role:"separator","aria-label":"Activity list width","aria-orientation":"vertical","aria-valuemin":28,"aria-valuemax":65,"aria-valuenow":Math.round(n),tabIndex:0,title:"Drag to resize · double-click to reset · arrow keys to adjust",onPointerDown:a=>{var c;a.button===0&&(a.preventDefault(),r.current=n,a.currentTarget.setPointerCapture(a.pointerId),(c=t.current)==null||c.setAttribute("data-resizing",""))},onPointerMove:u,onPointerUp:m,onPointerCancel:m,onLostPointerCapture:m,onDoubleClick:()=>p(34),onKeyDown:a=>{const c=a.key==="ArrowLeft"?n-(a.shiftKey?10:2):a.key==="ArrowRight"?n+(a.shiftKey?10:2):a.key==="Home"?28:a.key==="End"?65:a.key==="Enter"?34:null;c!==null&&(a.preventDefault(),p(c))}})}const en=["prompt_text","user_prompt","prompt","gen_ai.prompt","gen_ai.input.messages"],mn=["response","assistant_response","completion","gen_ai.completion","gen_ai.output.messages"],Hn=["project.name","project_name","project","workspace.name","workspace","repository.name","repo.name"],Wn=["cwd","working_directory","working.directory","process.cwd","process.working_directory","workspace.path","project.path","project_path"],Dt=t=>t&&typeof t=="object"&&!Array.isArray(t)?t:{},Bt=t=>Array.isArray(t)?t:[];function Kt(t){const n=Dt(t);for(const s of["stringValue","intValue","doubleValue","boolValue","bytesValue"])if(n[s]!==void 0)return n[s];return n.arrayValue?Bt(Dt(n.arrayValue).values).map(Kt):n.kvlistValue?Tt(Dt(n.kvlistValue).values):null}function Tt(t){return Object.fromEntries(Bt(t).map(n=>{const s=Dt(n);return[String(s.key),Kt(s.value)]}))}const dn=t=>typeof t=="string"&&/^(?:\[redacted\]|<redacted>|\(redacted\)|redacted)$/i.test(t.trim());function ft(t,n){const s=n.filter(o=>t[o]!==void 0&&t[o]!==null&&t[o]!==""),r=s.find(o=>!dn(t[o]))??s[0];return r?{state:dn(t[r])?"redacted":"included",key:r,value:t[r]}:{state:"absent",key:null,value:null}}function Js(t){let n=!1;const s=Dt(t);for(const[r,o,i]of[["resourceLogs","scopeLogs","logRecords"],["resourceSpans","scopeSpans","spans"],["resourceMetrics","scopeMetrics","metrics"]])for(const p of Bt(s[r]))for(const u of Bt(Dt(p)[o]))for(const m of Bt(Dt(u)[i])){const a=ft(Tt(Dt(m).attributes),en);if(a.state==="redacted"&&(n=!0),a.state==="included"){const c=(typeof a.value=="string"?a.value:JSON.stringify(a.value)).replace(/\s+/g," ").trim();if(c)return c.length>180?`${c.slice(0,180)}…`:c}}return n?"Prompt redacted":null}function Ys(t){const n=Tt(t.attributes);if(/error|fatal/i.test(String(t.severityText??""))||typeof t.severityNumber=="number"&&t.severityNumber>=17||ft(n,["error.message","exception.message","error","error_type"]).state!=="absent"||n.success===!1)return 0;if(ft(n,en).state!=="absent")return 1;if(ft(n,mn).state!=="absent")return 2;if(ft(n,["tool_name","tool.name","gen_ai.tool.name","model","gen_ai.request.model","cost_usd","input_tokens"]).state!=="absent")return 3;const s=String(t.eventName??t.name??n["event.name"]??"");return/^(?:claude_code[._])?(?:plugin[._]loaded|managed[._]settings[._]resolved)$/i.test(s)?4:t.body!==void 0&&Kt(t.body)!==null&&Kt(t.body)!==""?3:4}function Gs(t,n){const s=ft(t,Hn),r=ft(t,Wn);if(s.state!=="absent"||r.state!=="absent")return{source:"export",project:s,directory:r};const o=ft(t,["session.id","session_id","gen_ai.conversation.id"]),i=n.filter(u=>u.id===o.value&&u.workspace);return new Set(i.map(u=>u.workspace)).size===1?{source:"local",project:{state:"included",value:i[0].project??i[0].label,key:null},directory:{state:"included",value:i[0].workspace,key:null}}:{source:"absent",project:s,directory:r}}function qs({event:t}){const n=l.useRef(null),[s,r]=l.useState(null);return l.useEffect(()=>{const o=new AbortController;let i=!1;const p=()=>{i||(i=!0,fetch(`/api/system/traffic-radar/capture/event?id=${t.id}`,{signal:o.signal}).then(async m=>{if(!m.ok)return;const a=await m.json();o.signal.aborted||r(Js(a.payload))}).catch(()=>{}))},u=typeof IntersectionObserver>"u"?null:new IntersectionObserver(m=>{m.some(a=>a.isIntersecting)&&(p(),u==null||u.disconnect())},{rootMargin:"100px"});return n.current&&u?u.observe(n.current):p(),()=>{o.abort(),u==null||u.disconnect()}},[t.id,t.observedAt]),e.jsx("span",{ref:n,className:"tr-prompt-preview",children:s??"Prompt-related fields · open to inspect"})}const Ot=()=>{},fn=t=>Array.isArray(t)?t:[t],ot=t=>t!==null&&typeof t=="object",un=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),zn=t=>t!=null&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function",Un=t=>t&&typeof t=="object"&&"type"in t&&"target"in t&&"preventDefault"in t&&typeof t.preventDefault=="function",Dn=(t,n)=>{if(typeof t!="string")return null;const s=n.filter(r=>r instanceof Object&&r.enum&&r.values.includes(t)&&r.matchPriority);return s.sort((r,o)=>(o.matchPriority??0)-(r.matchPriority??0)),s[0]??null},Jn=t=>{if(t!==Yn){if(t&&typeof t=="object")for(const n in t){const s=t[n],r=Jn(s);r!==s&&(t[n]=r)}return t}},Yn="__undefined__",Gn=t=>t.split(/(\.|\[\d+\])/).filter(n=>n!=="."&&n!=="").map(n=>{const s=/\[(\d+)\]/.exec(n);return s?Number(s[1]):n}),qn=t=>typeof t=="string"?t:typeof t=="number"?String(t):t.reduce((n,s)=>typeof s=="number"?`${n}[${s}]`:n===""?s:`${n}.${s}`,""),it=t=>t.length===1&&t[0]===""?"\0":t.map(n=>encodeURIComponent(String(n))).join("/"),gt=(t,n)=>t.length===n.length&&t.every((s,r)=>s===n[r]),gn=(t,n)=>t.length>=n.length&&n.every((s,r)=>s===t[r]),_t=(t,n,s,r,o)=>{if(!r)throw new Error(o??`Invalid property path: ${n}
|
|
2
|
+
Couldn't access "${s}" in ${JSON.stringify(t)}`)},Gt=t=>Array.isArray(t),Xn=(t,n)=>t.filter((s,r)=>r!==n),Xs=(t,n,s,r={})=>{const{remove:o=!1,createNew:i=!0,noError:p=!1}=r,u=t,m=qn(n),a={...r,remove:o,createNew:i,noError:p,fullData:u,fullPath:m},c=Array.isArray(n)?n:Gn(n);return Gt(t)&&o&&c.length===1?Xn(t,c[0]):$t(t,c,s,a)},$t=(t,n,s,r)=>{const o=un(t)?{...t}:null,i=Gt(t)?[...t]:null;if(n.length===0)return t;if(!o&&!i)throw new Error("Can't assign property -- invalid input object");const{createNew:p,remove:u,noError:m,fullData:a,fullPath:c}=r,g=n[0];if(i&&typeof g=="string")return i.map(C=>$t(C,n,s,r));if(n.length===1)return o&&typeof g=="string"?Zs(o,g,s,r)??o:i&&typeof g=="number"?(Qs(i,g,s,r),i):(_t(a,c,g,m),t);const h=o||i||[];if(u&&n.length===2&&typeof n[1]=="number"){const C=h[g],S=n[1];return Gt(C)?h[g]=Xn(C,S):_t(a,c,g,m,"Trying to remove an indexed item from an object that is not an array"),h}const v=n.slice(1);if(g in t){if(w=h[g],!Gt(w)&&!un(w)){if(!p)return _t(a,c,g,m),h;h[g]={}}return h[g]=$t(h[g],v,s,r),h}var w;if(p){const C=typeof v[0]=="number"?[]:{};if(o)return h[g]=C,h[g]=$t(h[g],v,s,r),h;if(i&&Array.isArray(h)){h.push(C);const S=h.length-1;return h[S]=$t(h[S],v,s,r),h}}return _t(a,c,g,m),h},Zs=(t,n,s,r)=>{const{remove:o,createNew:i,noError:p,insertAfter:u,insertBefore:m,fullData:a,fullPath:c}=r;if(m!==void 0||u!==void 0){const h=Object.entries(t);let v;return v=typeof m=="number"?m:typeof u=="number"?u:h.findIndex(([w])=>w===(m??u)),u!==void 0&&v++,h.splice(v,0,[n,s]),Object.fromEntries(h)}const g=n in t;o?g?delete t[n]:_t(a,c,n,p):i||g?t[n]=s:_t(a,c,n,p)},Qs=(t,n,s,r)=>{const{noError:o,fullData:i,fullPath:p,createNew:u,insert:m}=r;m&&t.splice(n,0,s),n in t?t[n]=s:u?t.push(s):_t(i,p,n,o)},at=(t,n,s)=>{const r=Array.isArray(n)?n:Gn(n);if(r.length===0)return t;const o=r[0];if(Array.isArray(t)&&typeof o!="number"&&t.length>0)return t.map(p=>at(p,r,s));if(typeof t!="object"||t===null||!(o in t))return er(t,o,s);const i=t[o];return r.length===1?i:at(i,r.slice(1),s)},er=(t,n,s)=>{if(s===void 0)throw new Error(`Unable to extract object property
|
|
3
|
+
Looking for property: ${n}
|
|
4
|
+
In object: ${JSON.stringify(t)}`);return s},Ct=(t,n,s="",r)=>{if(n.length===0)return{key:s,path:[],level:0,index:0,value:t,size:ot(t)?Object.keys(t).length:1,parentData:null,fullData:t};const o=n[n.length-1],i=at(t,n),p=at(t,n.slice(0,-1))??null;let u=0;if(Array.isArray(p))u=typeof o=="number"?o:Number(o);else if(p&&typeof p=="object"){const m=Object.entries(p);r==null||r(m,a=>a),u=m.findIndex(([a])=>a===o)}return{key:o,path:n,level:n.length,index:u,value:i,size:ot(i)?Object.keys(i).length:null,parentData:p,fullData:t}},Zn=typeof window<"u"?l.useLayoutEffect:l.useEffect,Qn=({className:t,name:n,value:s,setValue:r,onKeyDown:o,styles:i,textAreaRef:p})=>{const u=l.useRef(null);if(Zn(()=>{const a=u.current;u.current=null;const c=p==null?void 0:p.current;if(!a||!c)return;const g=a.start+s.length-a.sourceLength,h=Math.max(0,Math.min(g,s.length));c.selectionStart!==h&&c.setSelectionRange(h,h)},[s,p]),typeof s!="string")return null;const m=s.slice(-1)===`
|
|
5
|
+
`?s+".":s;return e.jsxs("div",{style:{display:"grid"},children:[e.jsx("textarea",{id:`${n}_textarea`,ref:p,style:{height:"auto",gridArea:"1 / 1 / 2 / 2",overflowY:"auto",whiteSpace:"pre-wrap",...i},rows:1,className:t,name:`${n}_textarea`,value:s,onChange:a=>{const{value:c,selectionStart:g}=a.target;u.current=g!==null&&g<c.length?{start:g,sourceLength:c.length}:null,r(c)},autoFocus:!0,onFocus:a=>{s.length<40&&a.target.select()},onKeyDown:o}),e.jsx("span",{className:t,style:{visibility:"hidden",height:"auto",gridArea:"1 / 1 / 2 / 2",color:"red",opacity:.9,whiteSpace:"pre-wrap",overflowY:"auto",border:"1px solid transparent",...i},children:m})]})},jn=t=>t.shiftKey?"Shift":t.metaKey?"Meta":t.ctrlKey?"Control":t.altKey?"Alt":void 0,tr=(t,n,s)=>{if(!n)return!1;const r=t.key,o=jn(t);if(Array.isArray(n))return!!o&&n.includes(o);const{key:i,modifier:p}=n;return(s!=="stringLineBreak"||r!=="Enter"||o!=="Shift"||i!=="Enter"||!(p!=null&&p.includes("Shift")))&&r===i&&(p===o||Array.isArray(p)&&p.includes(o))},It={key:"Enter"},Tn={confirm:It,cancel:{key:"Escape"},objectConfirm:{...It,modifier:["Meta","Shift","Control"]},objectLineBreak:It,stringConfirm:It,stringLineBreak:{...It,modifier:["Shift"]},numberConfirm:It,numberUp:{key:"ArrowUp"},numberDown:{key:"ArrowDown"},tabForward:{key:"Tab"},tabBack:{key:"Tab",modifier:"Shift"},booleanConfirm:It,booleanToggle:{key:" "},clipboardModifier:["Meta","Control"],collapseModifier:["Alt"]},nr=["stringConfirm","numberConfirm","booleanConfirm"],es=(t,n)=>{const s=t.current,r=s.selectionStart??1/0,o=s.selectionEnd??1/0,i=s.value.slice(0,r)+n+s.value.slice(o);return s.value=i,s.setSelectionRange(r+1,r+1),i},qt=(t,n,s="next",r,o)=>{const i=n.slice(0,n.length-1),p=n.slice(-1)[0];if(p===void 0)return null;const u=at(t,i),m=sr(u);Array.isArray(u)||r(m,({key:h,value:v})=>[h,v]);const a=m.findIndex(h=>h.key===p),c=m[a+(s==="next"?1:-1)];if(!c)return i.length===0?null:qt(t,i,s,r,o);let g;if(ot(c.value)){if(Object.keys(c.value).length===0)return qt(t,[...i,c.key],s,r,o);g=ts(t,[...i,c.key],s,r)}else g=[...i,c.key];return g?o(Ct(t,g,"",r))?g:qt(t,g,s,r,o):null},ts=(t,n,s="next",r)=>{const o=at(t,n);if(!ot(o))return n;const i=Array.isArray(o)?o.map((u,m)=>m):Object.keys(o);r(i,u=>[u,o]);const p=s==="next"?i[0]:i[i.length-1];return ts(t,[...n,p],s,r)},sr=t=>Array.isArray(t)?t.map((n,s)=>({value:n,key:s})):Object.entries(t).map(([n,s])=>({key:n,value:s})),On={fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2},tn={displayName:"Default",icons:{add:{content:e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M13 7h-2v4H7v2h4v4h2v-4h4v-2h-4z"}),e.jsx("path",{d:"M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"})]})},edit:{content:e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M7 17.013l4.413-.015 9.632-9.54c.378-.378.586-.88.586-1.414s-.208-1.036-.586-1.414l-1.586-1.586c-.756-.756-2.075-.752-2.825-.003L7 12.583v4.43zM18.045 4.458l1.589 1.583-1.597 1.582-1.586-1.585 1.594-1.58zM9 13.417l6.03-5.973 1.586 1.586-6.029 5.971L9 15.006v-1.589z"}),e.jsx("path",{d:"M5 21h14c1.103 0 2-.897 2-2v-8.668l-2 2V19H8.158c-.026 0-.053.01-.079.01-.033 0-.066-.009-.1-.01H5V5h6.847l2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2z"})]}),svgProps:{transform:"translate(0, 0.5)"}},delete:{content:e.jsx("path",{d:"M6 19a2 2 0 002 2h8a2 2 0 002-2V7H6v12m2.46-7.12l1.41-1.41L12 12.59l2.12-2.12 1.41 1.41L13.41 14l2.12 2.12-1.41 1.41L12 15.41l-2.12 2.12-1.41-1.41L10.59 14l-2.13-2.12M15.5 4l-1-1h-5l-1 1H5v2h14V4h-3.5z"}),scale:1.04},copy:{content:e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M9 2 H15 A1 1 0 0 1 16 3 V5 A1 1 0 0 1 15 6 H9 A1 1 0 0 1 8 5 V3 A1 1 0 0 1 9 2 z"}),e.jsx("path",{d:"M8 4H6a2 2 0 00-2 2v14a2 2 0 002 2h12a2 2 0 002-2v-2M16 4h2a2 2 0 012 2v4M21 14H11"}),e.jsx("path",{d:"M15 10l-4 4 4 4"})]}),svgProps:On,scale:.86},ok:{content:e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 11-5.93-9.14"}),e.jsx("path",{d:"M22 4L12 14.01l-3-3"})]}),svgProps:On,scale:.9},cancel:{content:e.jsx("path",{d:"M12 4c-4.411 0-8 3.589-8 8s3.589 8 8 8 8-3.589 8-8-3.589-8-8-8zm-5 8c0-.832.224-1.604.584-2.295l6.711 6.711A4.943 4.943 0 0112 17c-2.757 0-5-2.243-5-5zm9.416 2.295L9.705 7.584A4.943 4.943 0 0112 7c2.757 0 5 2.243 5 5 0 .832-.224 1.604-.584 2.295z"}),svgProps:{baseProfile:"tiny"},scale:1.3},collection:{content:e.jsx("path",{d:"M233.4 406.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 338.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"}),viewBox:"0 0 512 512",scale:.7}},styles:{container:{backgroundColor:"#f6f6f6",fontFamily:"monospace"},property:"#292929",bracket:{color:"#002b36",fontWeight:"bold"},itemCount:{color:"#0000004d",fontStyle:"italic"},string:"#cb4b16",number:"#268bd2",boolean:"green",null:{color:"#dc322f",fontVariant:"small-caps",fontWeight:"bold"},input:["#292929"],inputHighlight:"#b3d8ff",error:{fontSize:"0.8em",color:"red",fontWeight:"bold"},iconCollection:"#002b36",iconEdit:"#2aa198",iconDelete:"#cb4b16",iconAdd:"#2aa198",iconCopy:"#268bd2",iconOk:"green",iconCancel:"#cb4b16"}},rr={container:"backgroundColor",collection:"backgroundColor",collectionInner:"backgroundColor",collectionElement:"backgroundColor",headerRow:"backgroundColor",valueRow:"backgroundColor",dropZone:"borderColor",inputHighlight:"backgroundColor"},ns=t=>[tn,...fn(t)].map(n=>"styles"in n?n:{styles:n}),ss=t=>{const n={};for(const{icons:s}of ns(t))s&&Object.assign(n,s);return n},rs=l.createContext({getStyles:()=>({}),icons:ss(tn),cssVars:{}}),or=({theme:t=tn,children:n})=>{const s=l.useMemo(()=>(u=>{var m;const a=ns(u),c={},g={};for(const{fragments:v,styles:w}of a)for(const C in w){const S=C;for(const R of[].concat(w[S]))if(typeof R=="function")(g[S]??(g[S]=[])).push(R);else{const P=typeof R=="string"?(v==null?void 0:v[R])??R:R;c[S]={...c[S],...typeof P=="string"?{[rr[S]??"color"]:P}:P}}}for(const v in g)c[m=v]??(c[m]={});const h={};for(const v in c){const w=v,C=c[w],S=g[w];h[w]=S?R=>S.reduce((P,_)=>({...P,..._(R)??{}}),C):C}return h})(t),[t]),r=l.useMemo(()=>ss(t),[t]),o=l.useMemo(()=>(u=>{const{inputHighlight:m,iconCopy:a}=u,c={};return typeof m!="function"&&(m!=null&&m.backgroundColor)&&(c["--jer-highlight-color"]=m.backgroundColor),typeof a!="function"&&(a!=null&&a.color)&&(c["--jer-icon-copy-color"]=a.color),c})(s),[s]),i=l.useCallback((u,m)=>((a,c,g)=>{const h=a[c];return typeof h=="function"?h(g):h??{}})(s,u,m),[s]),p=l.useMemo(()=>({getStyles:i,icons:r,cssVars:o}),[i,r,o]);return e.jsx(rs.Provider,{value:p,children:n})},jt=()=>l.useContext(rs),ar={edit:{start:"startEdit",submit:"submitEdit",cancel:"cancelEdit",commit:"commitEdit"},add:{start:"startAdd",submit:"submitAdd",cancel:"cancelAdd",commit:"commitAdd"},rename:{start:"startRename",submit:"submitRename",cancel:"cancelRename",commit:"commitRename"},delete:{commit:"delete"},move:{commit:"move"}},Pt=(t,n)=>ar[t][n]??null,Mt=(t,n)=>t!==null&&n!==null&&t.op===n.op&>(t.path,n.path),ir={active:null,settling:{}},os=l.createContext(null),lr=({children:t,onEditEvent:n,buildNodeDataFromPathRef:s,commitRef:r})=>{const o=l.useRef(n);o.current=n;const i=l.useRef(null);return i.current===null&&(i.current=((p,u,m)=>{let a=ir;const c=new Set;let g=null,h=null,v=!1,w=0;const C=b=>{a=b,c.forEach(f=>f())},S=(b,f,y)=>{var N;(N=p.current)==null||N.call(p,{...b,...y,event:f})},R=(b,f,y)=>{var x;if(!p.current)return;let N;try{N=(x=u.current)==null?void 0:x.call(u,b)}catch{return C({...a,active:null}),g=null,void(h=null)}N&&S(N,f,y)},P=(b,f)=>{var x;var y;g=(f==null?void 0:f.cancelOp)??null,h=(f==null?void 0:f.commitOp)??null,y=b,Mt(a.active,y)&&((x=a.active)==null?void 0:x.phase)===(y==null?void 0:y.phase)||C({...a,active:y});const N=Pt(b.op,"start");N&&R(b.path,N)},_=(b,f,y,N,x,k,B,F,j)=>{var A;const L=it(b);if(!B()){if(N.status==="cancel"||N.status==="error"){a.active&>(a.active.path,b)&&(a.active.phase==="held"||a.active.phase==="editing")&&(C({...a,active:null}),g=null,h=null);const O=Pt(f,"cancel");return O&&S(F,O),N.status==="error"&&S(F,"updateError",{operation:f,error:N.error}),N}x()}if(a.settling[L]===y){switch((O=>{if(!(O in a.settling))return;const M={...a.settling};delete M[O],C({...a,settling:M})})(L),N.status){case"cancel":k();break;case"error":k(),S(F,"updateError",{operation:f,error:N.error});break;case"override":(A=m.current)==null||A.applyValue(N.path,N.value),S(F,"updateSuccess",{operation:f,...j});break;case"commit":S(F,"updateSuccess",{operation:f,...j})}return N}};return{subscribe:b=>(c.add(b),()=>c.delete(b)),getSnapshot:()=>a,getServerSnapshot:()=>a,open:(b,f)=>{var B;if(((B=a.active)==null?void 0:B.phase)==="held")return;const y={path:b,op:(f==null?void 0:f.op)??"edit",phase:"editing",force:f==null?void 0:f.force},N=a.active,x=N!==null&&!Mt(N,y);if(x&&h)return void h(()=>P(y,f));const k=g;if(g=null,h=null,k&&k(),x&&Mt(a.active,N)){const F=Pt(N.op,"cancel");F&&R(N.path,F)}P(y,f)},cancel:()=>{var f;if(v||((f=a.active)==null?void 0:f.phase)==="held")return;const b=a.active;v=!0;try{const y=g;if(g=null,h=null,y&&y(),b!==null){a.active!==null&&C({...a,active:null});const N=Pt(b.op,"cancel");N&&R(b.path,N)}}finally{v=!1}},submit:b=>{const{op:f,path:y,instant:N,onCommit:x}=b,k=m.current;let B;try{B=(k==null?void 0:k.buildCommit(b))??null}catch{return Mt(a.active,{path:y,op:f})&&C({...a,active:null}),g=null,h=null,x==null||x(),Promise.resolve(void 0)}const F=B==null?void 0:B.extra,j=it(y),L=++w;if(!N){const de=Pt(f,"submit");de&&R(y,de)}if(!B||B.isNoOp){Mt(a.active,{path:y,op:f})&&C({...a,active:null}),g=null,h=null;const de=Pt(f,"commit");return de&&(B?S(B.nodeData,de,F):R(y,de,F)),x==null||x(),Promise.resolve(void 0)}const{input:A,nodeData:O,apply:M,revert:X}=B,Z=!!(k!=null&&k.runUpdate);let oe=!1,U=!1;const ae=()=>{if(oe)return;oe=!0,M(),g=null,h=null,Mt(a.active,{path:y,op:f})&&C({...a,active:null}),Z&&((G,z)=>{C({...a,settling:{...a.settling,[G]:z}})})(j,L);const de=Pt(f,"commit");de&&S(O,de,F),x==null||x()},Q={hold:()=>{var de;return U=!0,C({...a,active:{path:y,op:f,phase:"held",force:(de=a.active)==null?void 0:de.force}}),()=>ae()}};if(!Z)return ae(),Promise.resolve(void 0);const te=k.runUpdate(A,Q),ge=zn(te);if(!U&&!N&&!ge)return Promise.resolve(_(y,f,L,te,ae,X,()=>oe,O,F));const je=ge?te:Promise.resolve(te);let Le;return U||(N?Le=setTimeout(ae,100):ae()),je.then(de=>(clearTimeout(Le),_(y,f,L,de,ae,X,()=>oe,O,F)))},areChildrenBeingEdited:b=>a.active!==null&&gn(a.active.path,b)}})(o,s,r)),e.jsx(os.Provider,{value:i.current,children:t})},Rt=()=>{const t=l.useContext(os);if(!t)throw new Error("Missing Editing Context Provider");return t},Ht=t=>{const n=Rt();return l.useSyncExternalStore(n.subscribe,()=>t(n.getSnapshot()),()=>t(n.getServerSnapshot()))},as=l.createContext(null),cr=({children:t,onCollapse:n,buildNodeDataFromPathRef:s})=>{const[r,o]=l.useState({commands:null,version:0}),i=l.useRef(n);i.current=n;const p=l.useCallback(m=>{if(m===null)return void o(h=>h.commands===null?h:{commands:null,version:h.version});const a=fn(m),c=a.map(h=>({...h,path:[...h.path]}));o(h=>({commands:c,version:h.version+1}));const g=i.current;g&&a.forEach(h=>{var w;const v=(w=s.current)==null?void 0:w.call(s,h.path);v&&g({...v,collapsed:h.collapsed,includeChildren:h.includeChildren})})},[s]),u=l.useMemo(()=>({commands:r.commands,version:r.version,setCollapseState:p}),[r.commands,r.version,p]);return e.jsx(as.Provider,{value:u,children:t})},Zt=()=>{const t=l.useContext(as);if(!t)throw new Error("Missing Collapse Context Provider");return t},dr=(t,n)=>{if(!n.includeChildren)return n.path.length===t.length&&n.path.every((s,r)=>t[r]===s);for(const[s,r]of n.path.entries())if(r!==t[s])return!1;return!0},is=l.createContext(null),ur=({children:t})=>{const[n,s]=l.useState({path:null,canDelete:!1}),r=l.useRef(!1),o=l.useMemo(()=>({dragSource:n,setDragSource:s,armed:r}),[n]);return e.jsx(is.Provider,{value:o,children:t})},hr=({children:t,onEditEvent:n,onCollapse:s,buildNodeDataFromPathRef:r,commitRef:o})=>e.jsx(lr,{onEditEvent:n,buildNodeDataFromPathRef:r,commitRef:o,children:e.jsx(cr,{onCollapse:s,buildNodeDataFromPathRef:r,children:e.jsx(ur,{children:t})})}),ls=l.createContext(void 0),pr=({value:t,children:n})=>e.jsx(ls.Provider,{value:t,children:n}),yn=()=>{const t=l.useContext(ls);if(t===void 0)throw new Error("Missing FilterStateProvider");return t},cs=t=>{const n=yn();return n===null||n.visiblePaths.has(it(t))},mr=t=>{const n=yn();return n===null?null:n.visibleChildCounts.get(it(t))??null},hn="**INVALID_FUNCTION**",fr=({nodeData:t,showStringQuotes:n=!0,stringTruncateLength:s=200,pathString:r,canEdit:o,setIsEditing:i,styles:p,translate:u,showIconTooltips:m=!1,value:a,TextWrapper:c=({children:g})=>g})=>{const g=a??t.value,[h,v]=l.useState(!1),w=n?'"':"",C=g.length>s,S=()=>{o?i(!0):v(!h)},R=u("SHOW_MORE",t);return e.jsxs("div",{id:`${r}_display`,onDoubleClick:S,onClick:P=>{(P.getModifierState("Control")||P.getModifierState("Meta"))&&S()},className:"jer-value-string",style:p,children:[w,C?e.jsxs(e.Fragment,h?{children:[e.jsx(c,{children:e.jsxs("span",{children:[g,w]})})," ",e.jsx("button",{type:"button",tabIndex:-1,className:"jer-string-expansion jer-show-less",onClick:()=>v(!1),children:u("SHOW_LESS",t)})]}:{children:[e.jsxs(c,{children:[e.jsx("span",{children:g.slice(0,s-2).trimEnd()})," "]}),e.jsx("button",{type:"button",tabIndex:-1,className:"jer-string-expansion jer-ellipsis",onClick:()=>v(!0),"aria-label":R,title:m?R:"",children:"..."}),w]}):e.jsx(c,{children:`${g}${w}`})]})},gr=({styles:t,pathString:n,value:s,setValue:r,handleEdit:o,handleKeyboard:i,keyboardCommon:p})=>{const u=l.useRef(null);return e.jsx(Qn,{className:"jer-input-text",textAreaRef:u,name:n,value:s,setValue:r,onKeyDown:m=>{i(m,{stringConfirm:o,stringLineBreak:()=>{const a=es(u,`
|
|
6
|
+
`);r(a)},...p})},styles:t})},jr=({isEditing:t,path:n,enumType:s,...r})=>{const{getStyles:o}=jt(),i=it(n),{value:p,setValue:u,nodeData:m,handleEdit:a,handleKeyboard:c,keyboardCommon:g,Select:h}=r;return t&&s?e.jsx(h,{name:`${i}-value-select`,value:p,onChange:u,options:s.values,autoFocus:!0,onKeyDown:v=>c(v,{stringConfirm:a,...g})}):t?e.jsx(gr,{styles:o("input",m),pathString:i,...r,setValue:r.setValue}):e.jsx(fr,{pathString:i,styles:o("string",m),...r})},yr=({value:t,setValue:n,isEditing:s,path:r,setIsEditing:o,handleEdit:i,nodeData:p,handleKeyboard:u,keyboardCommon:m})=>{const{getStyles:a}=jt();return s?e.jsx("input",{className:"jer-input-number",type:"text",name:it(r),value:t,onChange:c=>n(c.target.value.replace(/[^0-9.-]/g,"")),autoFocus:!0,onFocus:c=>setTimeout(()=>c.target.select(),10),onKeyDown:c=>u(c,{numberConfirm:i,numberUp:()=>n(Number(t)+1),numberDown:()=>n(Number(t)-1),...m}),style:{width:String(t).length/1.5+2+"em",...a("input",p)}}):e.jsx("span",{onDoubleClick:()=>o(!0),className:"jer-value-number",style:a("number",p),children:t})},xr=({value:t,setValue:n,isEditing:s,path:r,setIsEditing:o,handleEdit:i,nodeData:p,handleKeyboard:u,keyboardCommon:m})=>{const{getStyles:a}=jt();return typeof t!="boolean"?null:s?e.jsx("input",{className:"jer-input-boolean",type:"checkbox",name:it(r),checked:t,onChange:()=>n(!t),onKeyDown:c=>{c.key===" "&&c.preventDefault(),u(c,{booleanConfirm:i,booleanToggle:()=>n(!t),...m})},autoFocus:!0}):e.jsx("span",{onDoubleClick:()=>o(!0),className:"jer-value-boolean",style:a("boolean",p),children:String(t)})},vr=(t,n)=>{const s=l.useRef(void 0),r=l.useRef(n);l.useEffect(()=>{r.current=n},[n]);const o=i=>{r.current(i)};l.useEffect(()=>{if(window.clearTimeout(s.current),t)return s.current=window.setTimeout(()=>{window.addEventListener("keydown",o)},100),()=>{window.clearTimeout(s.current),window.removeEventListener("keydown",o)}},[t])},br=({value:t,isEditing:n,setIsEditing:s,handleEdit:r,nodeData:o,handleKeyboard:i,keyboardCommon:p})=>{const{getStyles:u}=jt();return vr(n,m=>i(m,{confirm:r,...p})),e.jsx("div",{onDoubleClick:()=>s(!0),className:"jer-value-null",style:u("null",o),children:String(t)})},wr=({value:t})=>{let n="Error!";switch(typeof t){case"string":t===hn&&(n="Function");break;case"undefined":n="Undefined";break;case"symbol":n="Symbol"}return e.jsx("span",{className:"jer-value-invalid",children:n})},Cr=({scale:t=1,viewBox:n="0 0 24 24",fill:s="currentColor",children:r,...o})=>{const i=1.4*t+"em";return e.jsx("svg",{viewBox:n,fill:s,width:i,height:i,...o,children:r})},Lt=({name:t,nodeData:n})=>{const{getStyles:s,icons:r}=jt(),o=r[t],i=`icon${t[0].toUpperCase()}${t.slice(1)}`;return e.jsx(Cr,{viewBox:o.viewBox,...o.svgProps,scale:o.scale,className:t==="collection"?void 0:"jer-icon",style:s(i,n),children:o.content})},ds=({startEdit:t,handleDelete:n,handleAdd:s,showClipboardButton:r,onCopy:o,type:i,customButtons:p,handleEdit:u,canEdit:m,nodeData:a,translate:c,keyboardControls:g,handleKeyboard:h,editConfirmRef:v,getNewKeyOptions:w,jsonStringify:C,showIconTooltips:S,Select:R})=>{const{getStyles:P}=jt(),{open:_,cancel:b}=Rt(),[f,y]=l.useState(""),[N,x]=l.useState(!1),{path:k,value:B}=a,F=Ht(A=>{const O=A.active;return O!==null&&O.op==="add"&>(O.path,k)}),j=Array.isArray(N);Zn(()=>{var M;if(!F)return x(!1),void y("");const A=Object.keys(at(a.fullData,k)),O=w?(M=w(a))==null?void 0:M.filter(X=>!A.includes(X)):null;x(O??!0)},[F]);const L=()=>{s&&f&&s(i==="array"?"":f)};return e.jsxs("div",{className:"jer-edit-buttons",style:{opacity:F?1:void 0},onClick:A=>A.stopPropagation(),children:[r&&e.jsx("button",{type:"button",tabIndex:-1,onClick:A=>{var U;A.stopPropagation();let O,M,X="value",Z="",oe=null;if(r){const ae=jn(A);if(ae&&g.clipboardModifier.includes(ae)?(O=qn(k),Z=O,X="path"):(O=B,Z=typeof O=="object"?C(B):String(O)),!navigator.clipboard)return void(o==null?void 0:o({...a,success:!1,stringValue:Z,type:X,error:{code:"CLIPBOARD_ERROR",message:"Can't access clipboard API"}}));(U=navigator.clipboard)==null||U.writeText(Z).then(()=>M=!0).catch(Q=>{M=!1,oe=Q.message}).finally(()=>{o==null||o({...a,success:M,stringValue:Z,type:X,error:M?void 0:{code:"CLIPBOARD_ERROR",message:oe??"Copy failed"}})})}},className:"jer-copy-pulse","aria-label":c("TOOLTIP_COPY",a),title:S?c("TOOLTIP_COPY",a):"",children:e.jsx(Lt,{name:"copy",nodeData:a})}),t&&e.jsx("button",{type:"button",tabIndex:-1,onClick:t,"aria-label":c("TOOLTIP_EDIT",a),title:S?c("TOOLTIP_EDIT",a):"",children:e.jsx(Lt,{name:"edit",nodeData:a})}),n&&e.jsx("button",{type:"button",tabIndex:-1,onClick:n,"aria-label":c("TOOLTIP_DELETE",a),title:S?c("TOOLTIP_DELETE",a):"",children:e.jsx(Lt,{name:"delete",nodeData:a})}),s&&e.jsx("button",{type:"button",tabIndex:-1,onClick:()=>{i==="object"?_(k,{op:"add"}):s("")},"aria-label":c("TOOLTIP_ADD",a),title:S?c("TOOLTIP_ADD",a):"",children:e.jsx(Lt,{name:"add",nodeData:a})}),p==null?void 0:p.map(({Element:A,onClick:O,label:M},X)=>{const Z=oe=>O==null?void 0:O(a,oe,{handleEdit:u,canEdit:m});return M?e.jsx("button",{type:"button",className:"jer-custom-button",tabIndex:-1,onClick:Z,"aria-label":M,title:S?M:"",children:e.jsx(A,{nodeData:a,canEdit:m,handleEdit:u})},X):e.jsx("div",{className:"jer-custom-button",onClick:Z,children:e.jsx(A,{nodeData:a,canEdit:m,handleEdit:u})},X)}),F&&s&&i==="object"&&e.jsxs(e.Fragment,{children:[j?e.jsx(R,{name:"new-key-select",onChange:s,defaultValue:"",autoFocus:!0,onKeyDown:A=>h(A,{cancel:()=>b()}),placeholder:N.length>0?c("KEY_SELECT",a):c("NO_KEY_OPTIONS",a),options:N}):e.jsx("input",{className:"jer-input-text jer-input-new-key",type:"text",name:"new-object-key",value:f,placeholder:c("KEY_NEW",a),onChange:A=>y(A.target.value),autoFocus:!0,onKeyDown:A=>{h(A,{stringConfirm:()=>L(),cancel:()=>b()})},style:P("input",a)}),e.jsx(xn,{onOk:()=>L(),onCancel:()=>b(),nodeData:a,translate:c,showIconTooltips:S,editConfirmRef:v,hideOk:j})]})]})},xn=({onOk:t,onCancel:n,nodeData:s,translate:r,showIconTooltips:o,editConfirmRef:i,hideOk:p=!1})=>e.jsxs("div",{className:"jer-confirm-buttons",children:[!p&&e.jsx("button",{type:"button",tabIndex:-1,onClick:t,"aria-label":r("TOOLTIP_OK",s),title:o?r("TOOLTIP_OK",s):"",ref:i,children:e.jsx(Lt,{name:"ok",nodeData:s})}),e.jsx("button",{type:"button",tabIndex:-1,onClick:n,"aria-label":r("TOOLTIP_CANCEL",s),title:o?r("TOOLTIP_CANCEL",s):"",children:e.jsx(Lt,{name:"cancel",nodeData:s})})]}),us=["string","number","boolean","null"],Nr=["object","array"],Sr=[...us,...Nr],hs=t=>{const{component:n,wrapperComponent:s,keyComponent:r,showKey:o=!0,showEditTools:i=!0,showOnEdit:p=!1,showOnView:u=!0,showCollectionWrapper:m=!0,...a}=t;return{CustomComponent:n,CustomWrapperComponent:s,CustomKeyComponent:r,showKey:o,showEditTools:i,showOnEdit:p,showOnView:u,showCollectionWrapper:m,...a}},ps=(t=[],n)=>{const s=t.find(({condition:r})=>r(n));return s?hs(s):{}},ms=({props:t,collapsed:n})=>{const{nodeData:s,parentData:r,onError:o,getLatestData:i,showErrorMessages:p,allowEditFilter:u,allowDeleteFilter:m,allowAddFilter:a,allowDragFilter:c,canAddHere:g,translate:h,errorDisplayTime:v,sort:w,arrayIndexStart:C,handleKeyboard:S,customNodeData:R}=t,{submit:P}=Rt(),[_,b]=l.useState(null),f={...s,collapsed:n,visibleSize:mr(s.path)},{path:y,key:N,size:x}=f,k=it(y),B=Ht(G=>{const z=G.active;return z!==null&&z.op==="edit"&>(z.path,y)}),F=Ht(G=>{const z=G.active;return z!==null&&z.op==="rename"&>(z.path,y)}),j=Ht(G=>k in G.settling),L=u(f),A=m(f),O=a(f),M=c(f),X=G=>{p&&(b(G),setTimeout(()=>b(null),v)),console.warn("Error",G)},Z=l.useRef(f);Z.current=f;const oe=l.useCallback((G,z)=>{X(G.message),o&&o({...Z.current,fullData:i(),error:G,errorValue:z})},[o,p,i,v]),U=yn(),ae=l.useCallback(G=>(U===null||U.visiblePaths.has(it(G.path)))&&u(G),[U,u]),Q=G=>qt(i(),y,G,w,ae),te=(G,z)=>{r&&(N!==G&&Object.keys(r).includes(G)?oe({code:"KEY_EXISTS",message:h("ERROR_KEY_EXISTS",f)},G):P({op:"rename",path:y,newKey:G,onCommit:z}).then(ie=>{(ie==null?void 0:ie.status)==="error"&&oe(ie.error,G)}))},ge=typeof y.slice(-1)[0]=="number",je=r!==null&&!ge&&A&&g,Le={isEditing:B,isEditingKey:F,isPending:j,isArray:ge,canEditKey:je},de=N===""&&y.length>0?h("EMPTY_STRING",f):null;return{pathString:k,nodeData:f,path:y,name:N,size:x,canEdit:L,canDelete:A,canAdd:O,canDrag:M,error:_,showError:X,onError:oe,setError:b,handleEditKey:te,derivedValues:Le,emptyStringKey:de,getNextOrPreviousAtPath:Q,buildKeyDisplayProps:({handleCancel:G,getStyles:z,keyValueArray:ie,handleClick:Ce})=>({canEditKey:je,isEditingKey:F,pathString:k,path:y,name:N,arrayIndexStart:C,handleKeyboard:S,handleEditKey:te,handleCancel:G,styles:z("property",f),getNextOrPrevious:Q,emptyStringKey:de,nodeData:f,customNodeData:R,getStyles:z,...ie!==void 0?{keyValueArray:ie}:{},...Ce!==void 0?{handleClick:Ce}:{}})}},fs=({canDrag:t,canDelete:n,canDragOnto:s,canAddHere:r,path:o,nodeData:i,onError:p,translate:u})=>{const{getStyles:m}=jt(),{dragSource:a,setDragSource:c,armed:g}=(()=>{const b=l.useContext(is);if(!b)throw new Error("Missing DragSource Context Provider");return b})(),h=Rt(),[v,w]=l.useState(!1),C=()=>a.path!==null&&!gn(o,a.path)&&(gt(a.path.slice(0,-1),o.slice(0,-1))?s:a.canDelete&&r),S=l.useMemo(()=>t?{onMouseDown:b=>{b.button===0&&h.getSnapshot().active===null&&(g.current=!0)},onMouseUp:()=>{g.current=!1},onDragStart:b=>{if(!g.current||h.getSnapshot().active!==null)return b.preventDefault(),void b.stopPropagation();g.current=!1,b.stopPropagation(),c({path:o,canDelete:n})},onDragEnd:b=>{g.current=!1,b.stopPropagation(),c({path:null,canDelete:!1})}}:{},[t,n,o]),R=l.useMemo(()=>b=>s||r?{onDragOver:f=>{f.stopPropagation(),C()&&f.preventDefault()},onDrop:f=>{f.stopPropagation(),_(b),c({path:null,canDelete:!1}),w(!1)},onDragEnter:f=>{f.stopPropagation(),C()&&w(b)},onDragExit:f=>{f.stopPropagation(),w(!1)}}:{},[a,s,r,o]),P=l.useMemo(()=>a.path!==null&&C()?e.jsx("div",{className:"jer-drop-target-bottom",style:{height:"50%",position:"absolute",width:"100%",top:"50%",zIndex:o.length},...R("below")}):null,[a,s,r,o.length]),_=b=>{if(a.path===null||!C())return;const f=a.path.slice(-1)[0],y=a.path.slice(0,-1),N=o.slice(0,-1),{parentData:x}=i;typeof f=="string"&&x&&!Array.isArray(x)&&Object.keys(x).includes(f)&&f in x&&!gt(y,N)?p({code:"KEY_EXISTS",message:u("ERROR_KEY_EXISTS",i)},f):h.submit({op:"move",path:a.path,to:{path:o,position:b},instant:!0})};return{dragSourceProps:S,getDropTargetProps:R,BottomDropTarget:P,DropTargetPadding:({position:b,nodeData:f})=>v===b?e.jsx("div",{className:"jer-drag-n-drop-padding",style:m("dropZone",f)}):null,handleDrop:_}},Qt=({isEditingKey:t,canEditKey:n,pathString:s,path:r,name:o,arrayIndexStart:i,handleKeyboard:p,handleEditKey:u,handleCancel:m,handleClick:a,keyValueArray:c,styles:g,getNextOrPrevious:h,emptyStringKey:v,nodeData:w,customNodeData:C,getStyles:S})=>{const{open:R,cancel:P}=Rt(),_=pn.useRef(null),b=y=>{var N;return u(((N=_.current)==null?void 0:N.value)??String(o),y)},f=typeof o=="number"?String(o+i):o;if(!t){const y={...g,minWidth:`${Math.min(f.length+1,5)}ch`,flexShrink:f.length>10?1:0};if(C!=null&&C.CustomKeyComponent&&w&&S){const{CustomKeyComponent:N,componentProps:x}=C;return e.jsx(N,{nodeData:w,name:v??f,path:r,canEditKey:n,handleEditKey:k=>{n&&u(k)},startEditingKey:()=>{n&&R(r,{op:"rename",commitOp:b})},handleClick:a,styles:y,componentProps:x,getStyles:S})}return e.jsxs("span",{className:"jer-key-text",style:y,onDoubleClick:()=>n&&R(r,{op:"rename",commitOp:b}),onClick:a,children:[v?e.jsx("span",{className:"jer-empty-string",children:v}):f,f!==""||v?e.jsx("span",{className:"jer-key-colon",children:":"}):null]})}return e.jsx("input",{ref:_,className:"jer-input-text jer-key-edit",type:"text",name:s,defaultValue:f,autoFocus:!0,onFocus:y=>y.target.select(),onKeyDown:y=>p(y,{stringConfirm:()=>u(y.target.value),cancel:m,tabForward:()=>{const N=y.target.value;u(N,()=>{if(c){const x=c==null?void 0:c[0][0],k=x?[...r,x]:h("next");k?R(k):P()}else R(r)})},tabBack:()=>{const N=y.target.value;u(N,()=>{const x=h("prev");x?R(x):P()})}}),style:{width:f.length/1.5+.5+"em"}})},Er=new Set(["nodeData","customNodeData"]),gs=(t,n)=>{if(s=t.nodeData,r=n.nodeData,s.key!==r.key||s.index!==r.index||s.level!==r.level||s.size!==r.size||!gt(s.path,r.path))return!1;var s,r;const o=Object.keys(n);if(o.length!==Object.keys(t).length)return!1;for(const i of o)if(!Er.has(i)&&!Object.is(t[i],n[i]))return!1;return!0},kr=t=>{const{data:n,parentData:s,onChange:r,showClipboardButton:o,onCopy:i,canDragOnto:p,canAddHere:u,allowTypeSelection:m,showLabel:a,stringTruncateLength:c,showStringQuotes:g,indent:h,translate:v,customNodeDefinitions:w,customNodeData:C,Select:S,handleKeyboard:R,keyboardControls:P,editConfirmRef:_,jsonStringify:b,showIconTooltips:f,getLatestData:y}=t,{getStyles:N}=jt(),{open:x,cancel:k,submit:B,getSnapshot:F}=Rt(),{setCollapseState:j}=Zt(),[L,A]=l.useState(typeof n=="function"?hn:n),{nodeData:O,path:M,name:X,canEdit:Z,canDelete:oe,canDrag:U,error:ae,onError:Q,setError:te,derivedValues:ge,getNextOrPreviousAtPath:je,buildKeyDisplayProps:Le}=ms({props:t}),{dragSourceProps:de,getDropTargetProps:G,BottomDropTarget:z,DropTargetPadding:ie}=fs({canDrag:U,canDelete:oe,canDragOnto:p,canAddHere:u,path:M,nodeData:O,onError:Q,translate:v}),[Ce,Ae]=l.useState(Xt(n,C)),Ue=l.useRef(L);Ue.current=L;const $=l.useRef(O);$.current=O;const re=l.useCallback(I=>{if(!r)return void A(I);const q=r({...$.current,value:Ue.current,fullData:y(),newValue:I});A(q)},[r,y]),lt=()=>{A(typeof n=="function"?hn:n),Ae(Xt(n,C)),ke(Dn(n,Ie))};l.useEffect(()=>{ge.isEditing||lt()},[n]);const Ie=l.useMemo(()=>{const I=[...Sr,...w.filter(({showInTypeSelector:pe=!1,name:ve})=>pe&&!!ve).map(({name:pe})=>pe)];if(typeof m=="boolean")return m?I:[];if(Array.isArray(m))return m;const q=m(O);return typeof q=="boolean"?q?I:[]:q},[O,m,w]),[ye,ke]=l.useState(Dn(L,Ie)),{isEditing:le,isPending:J}=ge,He=cs(M),yt=l.useRef(Ot);if(!He)return null;const _e=le&&Ce!==Xt(n,C),De=_e?w.find(I=>I.name===Ce&&Rn(I)):void 0,xe=De?hs(De):C,{CustomComponent:Ve,componentProps:ct,showKey:Me=!0,showEditTools:Te=!0,showOnEdit:Ne,showOnView:ce,passOriginalNode:We}=xe,qe=Ve&&(De!==void 0||!_e&&(le&&Ne||!le&&ce)),Je=I=>{j(null);const q=_e&&!De?void 0:xe,pe=q!=null&&q.toStandardType?q.toStandardType(L):L,ve=w.find(we=>we.name===I);if(ve){const we=typeof ve.defaultValue=="function"?ve.defaultValue(O):ve.defaultValue;if(Rn(ve)){let tt=we;if(ve.fromStandardType)try{tt=ve.fromStandardType(pe,O,ve.componentProps)}catch{}return A(tt),Ae(I),void ke(null)}return B({op:"edit",path:M,value:we}).then(xt(we)),void j({path:M,collapsed:!1,includeChildren:!1})}const Pe=Ie.find(we=>we instanceof Object&&we.enum===I);if(Pe)return typeof L=="string"&&Pe.values.includes(L)||A(Pe.values[0]),ke(Pe),void Ae(I);const Oe=Dr(pe,I,v("DEFAULT_NEW_KEY",O));if(I==="object"||I==="array"||I==="null")return B({op:"edit",path:M,value:Oe}).then(xt(Oe)),void(I!=="null"&&j({path:M,collapsed:!1,includeChildren:!1}));A(Oe),Ae(I),ke(null)},xt=I=>q=>{if((q==null?void 0:q.status)==="error"&&Q(q.error,I),(q==null?void 0:q.status)==="error"||(q==null?void 0:q.status)==="cancel"){const pe=F().active;(pe==null?void 0:pe.phase)==="editing"&>(pe.path,M)||lt()}},Se=(I,q)=>{const pe=I!==void 0&&!Un(I);let ve;if(pe)ve=I;else if(qe&&xe.fromStandardType)try{ve=xe.fromStandardType(L,O,xe.componentProps)}catch(Oe){return void Q({code:"UPDATE_ERROR",message:Oe instanceof Error?Oe.message:String(Oe)},L)}else ve=Ce==="number"?ys(L):L;te(null),De&&j({path:M,collapsed:!1,includeChildren:!1});const Pe=pe&&ot(ve)&&!ot(n);B({op:"edit",path:M,value:ve,onCommit:()=>{Pe&&j({path:M,collapsed:!1,includeChildren:!1}),q==null||q()}}).then(xt(ve))};yt.current=Se;const Ye=()=>{te(null),lt(),k()},{isEditingKey:Fe}=ge,dt=!!ae,ut=le&&Ie.length>1,Xe=(Ce!=="invalid"||Ve)&&!ae&&Te,Ze=a&&Me,ht=()=>x(M,{cancelOp:lt,commitOp:I=>yt.current(void 0,I)}),Qe=Z?ht:Ot,vt=I=>()=>{const q=je(I);q&&Se(void 0,()=>x(q))},et={value:L,parentData:s,setValue:re,isEditing:le,canEdit:Z,setIsEditing:Qe,handleEdit:Se,handleCancel:Ye,path:M,stringTruncateLength:c,showStringQuotes:g,showIconTooltips:f,nodeData:O,enumType:ye,translate:v,handleKeyboard:R,keyboardCommon:{cancel:Ye,tabForward:vt("next"),tabBack:vt("prev")},Select:S},pt={...Le({handleCancel:Ye,getStyles:N}),customNodeData:xe},bt=qe?e.jsx(Ve,{...t,value:L,componentProps:ct,setValue:re,handleEdit:Se,handleCancel:Ye,onKeyDown:I=>R(I,{stringConfirm:Se,cancel:Ye}),isEditing:le,isPending:J,setIsEditing:Qe,getStyles:N,originalNode:We?An(n,Ce,et):void 0,originalNodeKey:We?e.jsx(Qt,{...pt,customNodeData:void 0}):void 0,canEdit:Z,keyboardCommon:et.keyboardCommon}):An(n,Ce,et);return e.jsxs("div",{className:"jer-component jer-value-component",style:{marginLeft:s!==null?h/2+"em":0,position:"relative"},draggable:U&&!le&&!Fe,...de,...G("above"),children:[z,e.jsx(ie,{position:"above",nodeData:O}),e.jsxs("div",{className:"jer-value-main-row",style:{...N("valueRow",O),flexWrap:X.length>10?"wrap":"nowrap"},children:[Ze&&e.jsx(Qt,{...pt}),e.jsxs("div",{className:"jer-value-and-buttons",children:[e.jsx("div",{className:"jer-input-component",children:bt}),le?e.jsx(xn,{onOk:Se,onCancel:Ye,nodeData:O,translate:v,showIconTooltips:f,editConfirmRef:_}):Xe&&e.jsx(ds,{startEdit:Z?ht:void 0,handleDelete:oe?()=>{B({op:"delete",path:M,instant:!0}).then(I=>{(I==null?void 0:I.status)==="error"&&Q(I.error,L)})}:void 0,showClipboardButton:o,onCopy:i,translate:v,customButtons:t.customButtons,handleEdit:I=>Se(I),canEdit:Z,nodeData:O,handleKeyboard:R,keyboardControls:P,editConfirmRef:_,jsonStringify:b,showIconTooltips:f,Select:S}),ut&&e.jsx(S,{name:`${X}-type-select`,value:ye?ye.enum:Ce,onChange:I=>Je(I),options:Ie.map(I=>I instanceof Object&&"enum"in I?I.enum:I)}),dt&&e.jsx("span",{className:"jer-error-slug",style:N("error",O),children:ae})]})]}),e.jsx(ie,{position:"below",nodeData:O})]})},js=pn.memo(kr,gs),Rn=t=>!!t.editOnTypeSwitch&&!!t.component&&!!t.showOnEdit,Xt=(t,n)=>n!=null&&n.CustomComponent&&(n!=null&&n.name)&&n.showInTypeSelector?n.name:typeof t=="string"?"string":typeof t=="number"?"number":typeof t=="boolean"?"boolean":t===null?"null":"invalid",An=(t,n,s)=>{const r=us.includes(n)?n:typeof t=="function"?"invalid":Xt(s.value),{value:o}=s;switch(r){case"string":return e.jsx(jr,{...s,value:o});case"number":return e.jsx(yr,{...s,value:o});case"boolean":return e.jsx(xr,{...s,value:o});case"null":return e.jsx(br,{...s});default:return e.jsx(wr,{...s})}},ys=t=>{if(typeof t=="symbol")return 0;const n=Number(t);return isNaN(n)?0:n},Dr=(t,n,s)=>{switch(n){case"string":return t==null?"":String(t);case"number":return ys(t);case"boolean":return!!t;case"null":return null;case"object":return{[s]:t};case"array":return[t];default:return String(t)}},Tr=t=>{const{getStyles:n}=jt(),{open:s,cancel:r,submit:o,areChildrenBeingEdited:i,getSnapshot:p}=Rt(),{setCollapseState:u}=Zt(),{mainContainerRef:m,data:a,nodeData:c,parentData:g,showCollectionCount:h,canDragOnto:v,canAddHere:w,collapseFilter:C,collapseAnimationTime:S,showClipboardButton:R,onCopy:P,showIconTooltips:_,indent:b,sort:f,showArrayIndexes:y,defaultValue:N,newKeyOptions:x,translate:k,customNodeDefinitions:B,customNodeData:F,jsonParse:j,jsonStringify:L,TextEditor:A,Select:O,keyboardControls:M,handleKeyboard:X,insertAtTop:Z,onCollapse:oe,editConfirmRef:U,collapseClickZones:ae,getLatestData:Q}=t,[te,ge]=l.useState(null),{showCollectionWrapper:je=!0}=F,Le=je&&C(c),{contentRef:de,isAnimating:G,maxHeight:z,collapsed:ie,animateCollapse:Ce,cssTransitionValue:Ae}=((E,W,Re,he,fe)=>{const[Be,wt]=l.useState(Re?0:void 0),[At,ks]=l.useState(Re),nn=l.useRef(!1),sn=l.useRef(null),bn=l.useRef(0),wn=l.useRef(0),Ds=W/1e3+"s",Ts=l.useCallback(rn=>{var Cn;if(At!==rn){switch(window.clearTimeout(wn.current),nn.current=!0,rn){case!0:{const Ut=((Cn=sn.current)==null?void 0:Cn.offsetHeight)??0;bn.current=Ut,wt(Ut),setTimeout(()=>{wt(0)},5);break}case!1:wt(bn.current||((Ut,Nn,Os,Rs)=>{var En;if(!Nn.current)return 0;const Sn=parseInt(getComputedStyle(Os.current).getPropertyValue("line-height"))||16,As=(((En=Nn.current)==null?void 0:En.offsetWidth)??0)/(.5*Sn),Is=Rs(Ut).replace(/\\n/g,`
|
|
7
|
+
`).split(`
|
|
8
|
+
`).map(on=>Math.ceil(on.length/As)).reduce((on,Ps)=>on+Ps,0)*Sn;return Math.min(Is+30,window.innerHeight-50)})(E,sn,he,fe))}ks(!At),wn.current=window.setTimeout(()=>{nn.current=!1,rn||wt(void 0)},W)}},[W,At,E,he,fe]);return{contentRef:sn,isAnimating:nn.current,animateCollapse:Ts,maxHeight:Be,collapsed:At,cssTransitionValue:Ds}})(a,S,Le,m,L),{pathString:Ue,nodeData:$,path:re,name:lt,size:Ie,canEdit:ye,canDelete:ke,canAdd:le,canDrag:J,error:He,setError:yt,onError:_e,derivedValues:De,buildKeyDisplayProps:xe}=ms({props:t,collapsed:ie}),{dragSourceProps:Ve,getDropTargetProps:ct,BottomDropTarget:Me,DropTargetPadding:Te}=fs({canDrag:J,canDelete:ke,canDragOnto:v,canAddHere:w,path:re,nodeData:$,onError:_e,translate:k}),Ne=l.useRef(!Le),{isEditing:ce,isEditingKey:We,isPending:qe,isArray:Je}=De,xt=(E=>{const W=l.useRef(E),Re=!Object.is(W.current,E);return l.useEffect(()=>{W.current=E}),Re})(C);l.useEffect(()=>{const E=je&&C($)&&!ce;Ne.current=!E,Ce(E),xt&&u(null)},[C]),((E,W,Re)=>{const{commands:he,version:fe}=Zt(),Be=l.useRef(0);l.useEffect(()=>{if(fe===Be.current||(Be.current=fe,!he))return;let wt;for(const At of he)dr(E,At)&&(wt=At);wt&&(wt.collapsed||(W.current=!0),Re(wt.collapsed))},[fe,he])})(re,Ne,je?Ce:Ot);const Se=l.useRef(null),Ye=l.useCallback(E=>ge(W=>typeof E=="function"?E(W??L(a)):E),[a,L]),Fe=l.useCallback(()=>ge(null),[]),dt=l.useMemo(()=>ce?te??L(a):null,[ce,te,a,L]),ut=l.useCallback((E,W)=>{if(typeof N!="function")return N;const Re=N(E,W);return Re!==void 0?Re:null},[N]),Xe=l.useCallback(E=>x?typeof x!="function"?x:x(E):null,[x]),{CustomComponent:Ze,componentProps:ht,CustomWrapperComponent:Qe,wrapperProps:vt={},showKey:et=!0,showEditTools:pt=!0,showOnEdit:bt,showOnView:I,passOriginalNode:q}=F,pe=Ht(E=>E.active!==null&&gn(E.active.path,re));!pe&&je||!ie||Ce(!1);const ve=cs(re)||$.level===0,Pe=l.useRef(Ot);if(!ve&&!pe)return null;const{visibleSize:Oe}=$,we=Array.isArray(a)?"array":"object",tt=we==="array"?{open:"[",close:"]"}:{open:"{",close:"}"},St=E=>{if(E.key==="Tab"&&!E.getModifierState("Shift")&&E.target===Se.current){E.preventDefault();const W=es(Se," ");return void ge(W)}X(E,{objectConfirm:V,cancel:T})},d=E=>{if(E.stopPropagation(),!je)return;const W=jn(E);if(W&&M.collapseModifier.includes(W))return Ne.current=!0,void u({collapsed:!ie,path:re,includeChildren:!0});i(re)||(Ne.current=!0,oe&&oe({...$,fullData:Q(),collapsed:!ie,includeChildren:!1}),Ce(!ie))},V=(E,W)=>{const Re=E!==void 0&&!Un(E);let he=a;if(Re)he=E;else if(te!==null)try{he=j(te)}catch{return void _e({code:"INVALID_JSON",message:k("ERROR_INVALID_JSON",$)},te)}yt(null),o({op:"edit",path:re,value:he,onCommit:()=>{Fe(),W==null||W()}}).then(fe=>{if((fe==null?void 0:fe.status)==="error"&&_e(fe.error,he),(fe==null?void 0:fe.status)==="error"||(fe==null?void 0:fe.status)==="cancel"){const Be=p().active;(Be==null?void 0:Be.phase)==="editing"&>(Be.path,re)||Fe()}})};Pe.current=V;const ue=E=>V(E),D=re.length>0?()=>{o({op:"delete",path:re,instant:!0}).then(E=>{(E==null?void 0:E.status)==="error"&&_e(E.error,a)})}:void 0,T=()=>{r(),yt(null),Fe()},Y=h==="when-collapsed"?ie:h==="when-collapsed-or-filtered"?ie||Oe!=null:h,me=!ce&&pt,ee=(y||!Je)&&et&<!==void 0,Ee=Ze&&(ce&&bt||!ce&&I),ne=Object.entries(a).map(([E,W])=>[we==="array"?Number(E):E,W]);we==="object"&&f(ne,E=>E);const K=!ce||!!Ze&&bt,H=()=>e.jsxs("div",{className:"jer-collection-text-edit"+(A?"-custom":""),children:[A?e.jsx(A,{value:dt??"",onChange:ge,onKeyDown:E=>X(E,{objectConfirm:V,cancel:T})}):e.jsx(Qn,{textAreaRef:Se,className:"jer-collection-text-area",name:Ue,value:dt??"",setValue:Ye,onKeyDown:St,styles:n("input",$)}),e.jsx("div",{className:"jer-collection-input-button-row",children:e.jsx(xn,{onOk:V,onCancel:T,nodeData:$,translate:k,showIconTooltips:_,editConfirmRef:U})})]}),se=Ne.current?K?ne.map(([E,W],Re)=>{const he={key:E,value:W,path:[...re,E],level:re.length+1,index:Re,size:ot(W)?Object.keys(W).length:null,parentData:a,fullData:$.fullData},fe=ps(B,he);return e.jsx("div",{className:"jer-collection-element",style:n("collectionElement",he),children:ot(W)&&!(fe!=null&&fe.renderCollectionAsValue)?e.jsx(xs,{...t,data:W,parentData:a,nodeData:he,canDragOnto:ye,canAddHere:le,customNodeData:fe},E):e.jsx(js,{...t,data:W,parentData:a,nodeData:he,canDragOnto:ye,canAddHere:le,showLabel:we==="object"||y,customNodeData:fe},E)},E)}):e.jsx(e.Fragment,{children:H()}):null,be=!!je&&ie&&!pe;be||(Ne.current=!0);const ze=k(ie?"TOOLTIP_EXPAND":"TOOLTIP_COLLAPSE",$),nt=()=>({...t,data:a,value:a,parentData:g,nodeData:$,setValue:ue,handleEdit:V,handleCancel:T,onKeyDown:St,isEditing:ce,isPending:qe,setIsEditing:ye?()=>s(re,{cancelOp:Fe,commitOp:E=>Pe.current(void 0,E)}):Ot,getStyles:n,canDragOnto:ye,canAddHere:le,canEdit:ye,keyboardCommon:{}}),Ke=Ee?e.jsx(Ze,{componentProps:ht,...nt(),originalNode:q&&ce?H():void 0,children:se}):se,st=me&&e.jsx(ds,{startEdit:ye?()=>{Ne.current=!0,s(re,{cancelOp:Fe,commitOp:E=>Pe.current(void 0,E)})}:void 0,handleAdd:le?E=>{u(null),Ce(!1);const W=ut($,E);if(we==="array"){const he=Z.array?0:a.length,fe=Z.array?{insert:!0}:{};return void o({op:"add",path:re,key:he,value:W,options:fe,instant:!0}).then(Be=>{(Be==null?void 0:Be.status)==="error"&&_e(Be.error,W)})}if(E in a)return _e({code:"KEY_EXISTS",message:k("ERROR_KEY_EXISTS",$)},E),void r();const Re=Z.object?{insertBefore:0}:{};o({op:"add",path:re,key:E,value:W,options:Re}).then(he=>{(he==null?void 0:he.status)==="error"&&_e(he.error,W)})}:void 0,handleDelete:ke?D:void 0,showClipboardButton:R,onCopy:P,type:we,nodeData:$,translate:k,customButtons:t.customButtons,handleEdit:ue,canEdit:ye,keyboardControls:M,handleKeyboard:X,getNewKeyOptions:Xe,editConfirmRef:U,jsonStringify:L,showIconTooltips:_,Select:O}),$e=xe({handleCancel:T,getStyles:n,keyValueArray:ne,handleClick:ae.includes("property")?d:E=>E.stopPropagation()}),mt=e.jsxs("div",{className:"jer-component jer-collection-component",style:{marginLeft:(re.length===0?0:b/2)+"em",...n("collection",$),position:"relative"},draggable:J&&!ce&&!We&&!pe,...Ve,...ct("above"),children:[je&&e.jsx("div",{className:"jer-clickzone",style:{width:b/2+1+"em",zIndex:10+2*$.level},onClick:ae.includes("left")?d:void 0}),!ce&&Me,e.jsx(Te,{position:"above",nodeData:$}),je?e.jsxs("div",{className:"jer-collection-header-row",style:{...n("headerRow",$),position:"relative"},onClick:ae.includes("header")?d:void 0,children:[e.jsxs("div",{className:"jer-collection-name",children:[e.jsx("button",{type:"button",className:"jer-collapse-icon jer-accordion-icon"+(ie?" jer-rotate-90":""),style:{zIndex:11+2*$.level,transition:Ae},onClick:d,tabIndex:-1,"aria-expanded":!ie,"aria-label":ze,title:_?ze:"",children:e.jsx(Lt,{name:"collection",nodeData:$})}),ee&&e.jsx(Qt,{...$e}),!ce&&e.jsx("span",{className:"jer-brackets jer-bracket-open",style:n("bracket",$),children:tt.open})]}),h!==!1&&!ce&&e.jsx("div",{className:"jer-collection-item-count"+(Y?" jer-visible":" jer-hidden"),style:{...n("itemCount",$),transition:Ae,transitionBehavior:"allow-discrete"},children:Oe!=null&&Oe!==Ie?k("ITEMS_FILTERED",$,{visible:Oe,total:Ie}):Ie===1?k("ITEM_SINGLE",{...$,size:1},1):k("ITEMS_MULTIPLE",$,Ie)}),e.jsx("div",{className:"jer-brackets"+(be?" jer-visible":" jer-hidden"),style:{...n("bracket",$),transition:Ae},children:tt.close}),st]}):et?e.jsxs("div",{className:"jer-collection-header-row",style:{...n("headerRow",$),position:"relative"},children:[e.jsx(Qt,{...$e}),st]}):e.jsx(e.Fragment,{}),e.jsxs("div",{className:"jer-collection-inner",style:{overflowY:be||G?"clip":"visible",maxHeight:pe?void 0:z,...n("collectionInner",$),transition:`max-height ${Ae}`},ref:de,children:[Ke,e.jsx("div",{className:ce?"jer-collection-error-row-edit":"jer-collection-error-row",children:He&&e.jsx("span",{className:"jer-error-slug",style:n("error",$),children:He})}),!ce&&je&&e.jsx("div",{className:"jer-brackets jer-bracket-outside",style:n("bracket",$),children:tt.close})]}),e.jsx(Te,{position:"below",nodeData:$})]});return Qe?e.jsx(Qe,{wrapperProps:vt,...nt(),children:mt}):mt},xs=pn.memo(Tr,gs),Or=({options:t,value:n,defaultValue:s,onChange:r,placeholder:o,className:i,...p})=>e.jsxs("div",{className:"jer-select",children:[e.jsxs("select",{className:i??"jer-select-inner",onChange:u=>r(u.target.value),...p,...n!==void 0?{value:n}:{defaultValue:s??""},children:[o!==void 0&&e.jsx("option",{value:"",disabled:!0,children:o}),t.map(u=>e.jsx("option",{value:u,children:u},u))]}),e.jsx("span",{className:"focus"})]}),zt=(t,n="")=>{const{value:s}=t;if(s===null&&"null".includes(n.toLowerCase()))return!0;switch(typeof s){case"string":return s.toLowerCase().includes(n.toLowerCase());case"number":return!!String(s).includes(n);case"boolean":return s?"true".includes(n.toLowerCase())||n==="1":"false".includes(n.toLowerCase())||n==="0";default:return!1}},In=({key:t,path:n},s="")=>!!zt({value:t},s)||!!n.some(r=>zt({value:r},s)),Rr={ITEM_SINGLE:"{{count}} item",ITEMS_MULTIPLE:"{{count}} items",ITEMS_FILTERED:"{{visible}} of {{total}} items",KEY_NEW:"Enter new key",KEY_SELECT:"Select key",NO_KEY_OPTIONS:"No key options",ERROR_KEY_EXISTS:"Key already exists",ERROR_INVALID_JSON:"Invalid JSON",ERROR_UPDATE:"Update unsuccessful",ERROR_DELETE:"Delete unsuccessful",ERROR_ADD:"Adding node unsuccessful",ERROR_RENAME:"Rename unsuccessful",ERROR_MOVE:"Move unsuccessful",DEFAULT_NEW_KEY:"key",SHOW_LESS:"(Show less)",SHOW_MORE:"Show more",EMPTY_STRING:"<empty string>",TOOLTIP_COPY:"Copy to clipboard",TOOLTIP_EDIT:"Edit",TOOLTIP_DELETE:"Delete",TOOLTIP_ADD:"Add",TOOLTIP_OK:"OK",TOOLTIP_CANCEL:"Cancel",TOOLTIP_COLLAPSE:"Collapse",TOOLTIP_EXPAND:"Expand"};var an=':root,:host{--jer-select-border: #b6b6b6;--jer-select-focus: #777;--jer-select-arrow: #777;--jer-form-border: 1px solid #ededf0;--jer-form-border-focus: 1px solid #e2e2e2;--jer-highlight-color: #b3d8ff;--jer-icon-copy-color: #268bd2}.jer-visible{opacity:1}.jer-hidden{opacity:0}.jer-select select{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:transparent;border:none;padding:0 1em 0 0;margin:0;font-family:inherit;font-size:.8em;color:#000;cursor:inherit;line-height:inherit;z-index:1;outline:none}select::-ms-expand{display:none}.jer-select{display:grid;grid-template-areas:"select";align-items:center;position:relative;min-width:12ch;max-width:15ch;border:1px solid var(--jer-select-border);border-radius:.25em;padding:.25em .5em;cursor:pointer;line-height:1.1;background-color:#fff;background-image:linear-gradient(to top,#f9f9f9,#fff 33%)}.jer-select select,.jer-select:after{grid-area:select}.jer-select:not(.jer-select--multiple):after{content:"";justify-self:end;width:.8em;height:.5em;background-color:var(--jer-select-arrow);clip-path:polygon(100% 0%,0 0%,50% 100%)}select:focus+.focus{position:absolute;inset:-1px;border:1px solid var(--jer-select-focus);border-radius:inherit}.jer-select-inner{width:100%;text-overflow:ellipsis}.jer-editor-container{position:relative;font-size:16px;line-height:1;padding:1em 1em 1em 2em;border-radius:.5em;text-align:left}.jer-editor-container textarea{color:var(--jer-input-color);border:var(--jer-form-border);border-radius:.3em;outline:none}.jer-editor-container textarea:focus{border:var(--jer-form-border-focus)}.jer-editor-container input{border:var(--jer-form-border);border-radius:.3em;outline:none;font-family:inherit}.jer-editor-container input:focus{border:var(--jer-form-border-focus)}.jer-editor-container ::selection{background-color:var(--jer-highlight-color)}.jer-collection-header-row,.jer-value-main-row{display:flex;min-height:1.7em;gap:.3em;align-items:center}.jer-collection-header-row{flex-wrap:wrap}.jer-value-main-row{gap:0}.jer-bracket-outside{padding-left:0}.jer-collection-item-count{display:none}.jer-collection-item-count.jer-visible{display:block}@starting-style{.jer-collection-item-count.jer-visible{opacity:0}}.jer-collapse-icon{position:absolute;left:-1.2em;top:50%;transform:translateY(-50%)}.jer-collapse-icon.jer-rotate-90{transform:translateY(-50%) rotate(-90deg)}.jer-collection-inner{position:relative}.jer-collection-text-edit,.jer-collection-text-edit-custom{display:flex;flex-direction:column;gap:.3em;align-items:flex-start;line-height:1.1em}.jer-collection-text-edit{width:fit-content}.jer-collection-text-area{box-sizing:content-box;resize:both;padding:.2em .5em 0;overflow:hidden;max-height:40em;line-height:1.25em;font-family:inherit;font-size:.85em}.jer-collection-input-button-row{display:flex;justify-content:flex-end;width:100%;font-size:150%;margin-top:.4em}.jer-collection-error-row-edit{position:absolute;bottom:.5em}.jer-error-slug{margin-left:1em}.jer-value-component{position:relative}.jer-value-and-buttons{display:flex;justify-content:flex-start;align-items:center;padding-left:.5em}.jer-value-error-row{position:absolute}.jer-value-string{line-height:1.3em;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word}.jer-string-expansion{cursor:pointer;opacity:.6;filter:saturate(50%)}.jer-string-expansion.jer-show-less{font-size:80%}.jer-hyperlink{text-decoration:underline}.jer-input-text{box-sizing:content-box;resize:none;margin:0;height:1.2em;padding:.25em .5em .2em;min-width:6em;overflow:hidden;line-height:1.2em;font-family:inherit;font-size:.9em}.jer-input-boolean{transform:scale(1.5);margin-left:.3em;margin-right:.3em}.jer-key-text{word-break:break-word;line-height:1.1em;white-space:pre-wrap}.jer-value-invalid{opacity:.5;font-style:italic}.jer-input-number{min-width:3em;font-size:90%}.jer-edit-buttons,.jer-confirm-buttons{display:flex;align-items:center;cursor:pointer;height:1em;margin-right:.2em}.jer-edit-buttons>button,.jer-confirm-buttons>button,button.jer-collapse-icon,button.jer-string-expansion{appearance:none;background:none;border:none;margin:0;padding:0;font:inherit;color:inherit;vertical-align:baseline}.jer-input-buttons{gap:.4em}.jer-edit-buttons{gap:.4em;margin-left:.5em;opacity:0}.jer-custom-button:empty{display:none}.jer-confirm-buttons{gap:.2em;margin-left:.4em}.jer-edit-buttons:hover{opacity:1;position:relative}.jer-collection-header-row:hover>.jer-edit-buttons{opacity:1}.jer-value-main-row:hover>.jer-edit-buttons{opacity:1}.jer-value-and-buttons:hover>.jer-edit-buttons{opacity:1}.jer-copy-pulse{position:relative;transition:.3s}.jer-copy-pulse:hover{opacity:.85;transition:.3s;transform:scale(1.2)}.jer-copy-pulse:after{content:"";display:block;position:absolute;border-radius:50%;left:0;top:0;width:100%;height:100%;opacity:0;transition:all .5s;box-shadow:0 0 15px 5px var(--jer-icon-copy-color)}.jer-copy-pulse:active:after{box-shadow:0 0 0 0 var(--jer-icon-copy-color);position:absolute;border-radius:4em;left:0;top:0;opacity:1;transition:0s}.jer-copy-pulse:active{top:.07em}.jer-icon:hover{opacity:.85;transition:.3s;transform:scale(1.2)}.jer-empty-string{font-style:italic;font-size:90%}.jer-drag-n-drop-padding{height:.5em;border:1px dashed #b4b4b4;border-radius:.3em}.jer-clickzone{position:absolute;left:-1em;top:1.2em;height:calc(100% - .8em)}';const Pn="data-jer-styles",Ar=(t,n)=>JSON.stringify(t,n,2),Ir={edit:"ERROR_UPDATE",add:"ERROR_ADD",delete:"ERROR_DELETE",rename:"ERROR_RENAME",move:"ERROR_MOVE"},Pr={edit:"UPDATE_ERROR",add:"ADD_ERROR",delete:"DELETE_ERROR",rename:"RENAME_ERROR",move:"MOVE_ERROR"},Vt=t=>{const n=l.useRef(t);t&&(n.current=t);const s=l.useRef((...r)=>n.current(...r));return t?s.current:void 0},_r=[],Lr=["header","left"],Mr={},Kr={},Vr={},Fr=[],$r=({data:t,setData:n,buildNodeDataFromPathRef:s,commitRef:r,rootName:o="root",onUpdate:i=Ot,onChange:p,onError:u,onEditEvent:m,showErrorMessages:a=!0,showClipboardButton:c=!0,onCopy:g,indent:h=2,collapse:v=3,collapseAnimationTime:w=300,showCollectionCount:C="when-collapsed-or-filtered",allowEdit:S=!0,allowDelete:R=!0,allowAdd:P=!0,allowTypeSelection:_=!0,allowDrag:b=!1,searchFilter:f,searchText:y,searchDebounceTime:N=350,sortKeys:x=!1,showArrayIndexes:k=!0,arrayIndexStart:B=0,showStringQuotes:F=!0,showIconTooltips:j=!1,defaultValue:L=null,newKeyOptions:A,minWidth:O=250,maxWidth:M="min(600px, 90vw)",baseFontSize:X,stringTruncateLength:Z=250,translations:oe=Mr,className:U,id:ae,customText:Q=Kr,customNodeDefinitions:te=_r,customButtons:ge=Fr,jsonParse:je=JSON.parse,jsonStringify:Le=Ar,TextEditor:de,Select:G=Or,errorDisplayTime:z=2500,keyboardControls:ie=Vr,editorRef:Ce,insertAtTop:Ae=!1,onCollapse:Ue,collapseClickZones:$=Lr})=>{const{getStyles:re,cssVars:lt}=jt(),{open:Ie,cancel:ye,getSnapshot:ke}=Rt(),le=l.useMemo(()=>Ft(v),[v]),J=l.useMemo(()=>((D,T)=>(Y,me,ee)=>((Ee,ne,K,H,se)=>{if(ne[H]){const ze=ne[H](K);if(ze!==null)return ze}let be=H in Ee?Ee[H]:Rr[H];if(se!==void 0){const ze=un(se)?se:{count:se};for(const[nt,Ke]of Object.entries(ze))be=be==null?void 0:be.replace(`{{${nt}}}`,String(Ke))}return be})(D,T,me,Y,ee))(oe,Q),[oe,Q]),[He,yt]=l.useState(y),_e=l.useRef(null);l.useEffect(()=>{ye();const D=setTimeout(()=>yt(y),N);return()=>clearTimeout(D)},[y,N]);const De=Ct(t,[],o),xe=l.useRef(t);xe.current=t;const Ve=l.useRef(n);Ve.current=n;const ct=l.useRef(J);ct.current=J;const Me=l.useRef(De);Me.current=De;const Te=l.useRef(i);Te.current=i;const Ne=l.useRef(o);Ne.current=o;const ce=l.useRef(void 0),We=l.useCallback(()=>xe.current,[]),qe=Vt(p),Je=Vt(u),xt=Vt(Ue),Se=Vt(m),Ye=Vt(g),Fe=l.useCallback(D=>{xe.current=D,Ve.current(D)},[]),dt=l.useCallback((D,T)=>{Fe(rt(xe.current,D,T,"update").newData)},[Fe]),ut=l.useCallback(D=>{const T=xe.current,Y=Ne.current,me=ce.current,ee=Fe,{op:Ee,path:ne}=D;switch(Ee){case"edit":{const{newData:K,currentValue:H,newValue:se}=rt(T,ne,D.value,"update"),be=Ct(T,ne,Y,me);return{input:{...be,newData:K,event:"edit",newValue:se},nodeData:be,isNoOp:H===se,apply:()=>ee(K),revert:()=>ee(rt(xe.current,ne,H,"update").newData)}}case"delete":{const{newData:K,currentValue:H}=rt(T,ne,"","delete"),se=Ct(T,ne,Y,me);return{input:{...se,newData:K,event:"delete"},nodeData:se,isNoOp:!1,apply:()=>ee(K),revert:()=>ee(rt(xe.current,ne,H,"add",{insert:!0,insertBefore:se.index}).newData)}}case"add":{const K=[...ne,D.key],{newData:H,newValue:se}=rt(T,K,D.value,"add",D.options),be=Ct(H,K,Y,me);return{input:{...be,value:void 0,size:null,parentData:at(T,ne)??null,fullData:T,newData:H,event:"add",newValue:se},nodeData:be,isNoOp:!1,apply:()=>ee(H),revert:()=>ee(rt(xe.current,K,"","delete").newData)}}case"rename":{const K=ne.slice(0,-1),H=ne[ne.length-1],{newKey:se}=D,be=at(T,K),ze=Object.fromEntries(Object.entries(be).map(([st,$e])=>st===H?[se,$e]:[st,$e])),{newData:nt}=rt(T,K,ze,"update"),Ke=Ct(T,ne,Y,me);return{input:{...Ke,newData:nt,event:"rename",newKey:se},nodeData:Ke,isNoOp:H===se,apply:()=>ee(nt),revert:()=>ee(rt(xe.current,K,be,"update").newData),extra:{oldKey:H,newKey:se}}}case"move":{const K=ne,{path:H,position:se}=D.to,be=T,{newData:ze,currentValue:nt}=rt(T,K,"","delete"),Ke=K.slice(-1)[0],st=H.slice(0,-1),$e=H.slice(-1)[0];let mt=typeof $e=="number"?se==="above"?$e:$e+1:typeof Ke=="number"?`arr_${Ke}`:Ke;K.slice(0,-1).join(".")===H.slice(0,-1).join(".")&&typeof Ke=="number"&&typeof mt=="number"&&Ke<mt&&(mt-=1);const E=typeof mt=="number"?{insert:!0}:se==="above"?{insertBefore:$e}:{insertAfter:$e},W=[...st,mt],{newData:Re}=rt(ze,W,nt,"add",E),he=Ct(T,K,Y,me);return{input:{...he,newData:Re,event:"move",newPath:W},nodeData:he,isNoOp:!1,apply:()=>ee(Re),revert:()=>ee(be)}}}},[Fe]),Xe=l.useCallback((D,T)=>{const Y=Pr[D.event],me=()=>ct.current(Ir[D.event],Me.current),ee=K=>{const H=K instanceof Error&&K.message?K.message:typeof K=="string"&&K?K:me();return{status:"error",error:{code:Y,message:H}}},Ee=K=>{if(K===!1)return{status:"error",error:{code:Y,message:me()}};if(K===null)return{status:"cancel"};if(K&&typeof K=="object"){if(K.error!==void 0)return typeof K.error=="string"?{status:"error",error:{code:Y,message:K.error}}:{status:"error",error:K.error};const H=K.data!==void 0,se=K.value!==void 0;if(H&&se&&console.warn("json-edit-react: onUpdate returned both { value } and { data }; { data } (whole-document) takes precedence and { value } is ignored."),H)return{status:"override",value:K.data,path:[]};if(se&&(D.event==="edit"||D.event==="add"))return{status:"override",value:K.value,path:D.path}}return{status:"commit"}};let ne;try{ne=Te.current(D,T)}catch(K){return ee(K)}return zn(ne)?ne.then(Ee,ee):Ee(ne)},[]),Ze=l.useMemo(()=>({runUpdate:i===Ot?void 0:Xe,buildCommit:ut,applyValue:dt}),[Xe,ut,dt,i]);r.current=Ze;const ht=l.useMemo(()=>Ft(S),[S]),Qe=l.useMemo(()=>Ft(R),[R]),vt=l.useMemo(()=>Ft(P),[P]),et=l.useMemo(()=>Ft(b),[b]),pt=l.useMemo(()=>Hr(f),[f]),bt=l.useMemo(()=>((D,T,Y)=>{if(!T&&!Y)return null;const me=new Set,ee=new Map,Ee=T??zt,ne=Y??"",K=H=>{let se=Ee(H,ne);if(ot(H.value)){let be=0;const ze=Array.isArray(H.value),nt=Object.entries(H.value);for(const[Ke,st]of nt){const $e=ze?Number(Ke):Ke,mt={key:$e,path:[...H.path,$e],level:H.level+1,index:be,value:st,size:ot(st)?Object.keys(st).length:null,parentData:H.value,fullData:H.fullData};K(mt)&&(se=!0,be++)}ee.set(it(H.path),be)}return se&&me.add(it(H.path)),se};return K(D),{visiblePaths:me,visibleChildCounts:ee}})(De,pt,He),[t,He,pt,o]),I=l.useMemo(()=>(D=>{const T={...Tn};for(const Y of Object.keys(Tn)){const me=Y,ee=D[me];if(ee===void 0)continue;const Ee=Y==="clipboardModifier"||Y==="collapseModifier";if(ee===null){T[me]=Ee?[]:null;continue}const ne=Ee?fn(ee):typeof ee=="string"?{key:ee}:ee;T[me]=ne}return nr.forEach(Y=>{D[Y]===void 0&&D.confirm!==void 0&&(T[Y]=T.confirm)}),T})(ie),[ie]),q=l.useCallback((D,T)=>((Y,me,ee)=>{for(const[Ee,ne]of Object.entries(me))if(tr(ee,Y[Ee],Ee)){ee.preventDefault(),ne();break}})(I,T,D),[I]),pe=l.useMemo(()=>{const D=_n(te,"stringifyReplacer");return T=>Le(T,D)},[te,Le]),ve=l.useMemo(()=>{const D=_n(te,"parseReviver");return T=>{const Y=je(T,D);return Jn(Y)}},[te,je]),Pe=l.useRef(null),{setCollapseState:Oe}=Zt(),we=l.useCallback((D,T)=>{x!==!1&&(typeof x!="function"?D.sort((Y,me)=>{const ee=T(Y)[0],Ee=T(me)[0];return ee<Ee?-1:ee>Ee?1:0}):D.sort((Y,me)=>x(T(Y),T(me))))},[x]);ce.current=we;const tt=l.useCallback(D=>Ct(We(),D,Ne.current,ce.current),[We]);s.current=tt,l.useImperativeHandle(Ce,()=>{const D=Symbol("path-missing");return{collapse:T=>Oe(T),startEdit:({path:T,overrideRestrictions:Y=!1})=>at(We(),T,D)===D?"PATH_NOT_FOUND":Y||ht(Ct(We(),T,o,we))?(Ie(T,{force:!0}),!0):"RESTRICTED",confirm:()=>{var T;Pe.current&&(Pe.current.click(),((T=ke().active)==null?void 0:T.phase)!=="editing"&&ye())},cancel:()=>ye()}},[Oe,Ie,ye,ke,ht,We,o,we]);const St=ps(te,De),d=l.useMemo(()=>({object:Ae===!0||Ae==="object",array:Ae===!0||Ae==="array"}),[Ae]),V={mainContainerRef:_e,name:o,nodeData:De,getLatestData:We,onChange:qe,onError:Je,onEditEvent:Se,showErrorMessages:a,showCollectionCount:C,collapseFilter:le,collapseAnimationTime:w,allowEditFilter:ht,allowDeleteFilter:Qe,allowAddFilter:vt,allowTypeSelection:_,allowDragFilter:et,canDragOnto:!1,canAddHere:!1,showClipboardButton:c,onCopy:Ye,sortKeys:x,sort:we,showArrayIndexes:k,arrayIndexStart:B,showStringQuotes:F,showIconTooltips:j,indent:h,defaultValue:L,newKeyOptions:A,stringTruncateLength:Z,translate:J,customNodeDefinitions:te,customNodeData:St,customButtons:ge,parentData:null,jsonParse:ve,jsonStringify:pe,TextEditor:de,Select:G,errorDisplayTime:z,handleKeyboard:q,keyboardControls:I,insertAtTop:d,onCollapse:xt,editConfirmRef:Pe,collapseClickZones:$},ue={...re("container",De),...lt,minWidth:O,maxWidth:M};return ue.fontSize=X??ue.fontSize,e.jsx("div",{id:ae,ref:_e,className:`jer-editor-container ${U??""}`,style:ue,children:e.jsx(pr,{value:bt,children:ot(t)&&!St.renderCollectionAsValue?e.jsx(xs,{data:t,...V}):e.jsx(js,{data:t,showLabel:!0,...V})})})};function Br(t){l.useInsertionEffect(()=>{(()=>{if(typeof document>"u")return;const o=document.head.querySelector(`style[${Pn}]`);if(o)return void(o.textContent!==an&&(o.textContent=an));const i=document.createElement("style");i.setAttribute(Pn,""),i.textContent=an,document.head.appendChild(i)})()},[]);const n=l.useRef(void 0),s=l.useRef(void 0),r=t;return e.jsx(or,{theme:r.theme??tn,children:e.jsx(hr,{onEditEvent:r.onEditEvent,onCollapse:r.onCollapse,buildNodeDataFromPathRef:n,commitRef:s,children:e.jsx($r,{...r,buildNodeDataFromPathRef:n,commitRef:s})})})}const rt=(t,n,s,r,o={})=>{if(n.length===0)return{currentData:t,newData:s,currentValue:t,newValue:s};const i={remove:r==="delete",...o},p=r!=="add"?at(t,n):void 0;return{currentData:t,newData:Xs(t,n,s,i),currentValue:p,newValue:r!=="delete"?s:void 0}},Ft=t=>typeof t=="boolean"?()=>t:typeof t=="number"?({level:n})=>n>=t:t,Hr=t=>{if(t!==void 0)return t==="value"?zt:t==="key"?In:t==="all"?(n,s)=>zt(n,s)||In(n,s):t},_n=(t,n)=>{const s=n==="stringifyReplacer"?[r=>r===void 0?Yn:r]:[];if(s.push(...t.map(r=>r[n]).filter(r=>!!r)),s.length!==0)return(r,o)=>{let i=o;for(const p of s)i=p(i);return i}};function Wr(t){const{editorRef:n,...s}=t,r=l.useRef(null);return l.useImperativeHandle(n,()=>({collapse:o=>{var i;return(i=r.current)==null?void 0:i.collapse(o)}}),[]),e.jsx(Br,{...s,editorRef:r,setData:Ot,allowEdit:!1,allowAdd:!1,allowDelete:!1,allowDrag:!1})}const Wt=50,zr=2e5,vs=l.createContext(""),bs=l.createContext(null),Ur={container:{backgroundColor:"transparent",color:"var(--text)",fontFamily:"var(--font-mono)",padding:"8px 0 8px 20px"},property:"var(--text)",string:"var(--ok)",number:"var(--accent)",boolean:"var(--accent)",null:"var(--text-secondary)",bracket:"var(--text-secondary)",itemCount:"var(--text-secondary)",iconCollection:"var(--text-secondary)",iconCopy:"var(--text-secondary)",collectionInner:{borderLeft:"1px solid var(--line)"},inputHighlight:"var(--ctl-fill)"},Jr=new Set(["resourceLogs","resourceMetrics","resourceSpans","scopeLogs","scopeMetrics","scopeSpans","logRecords","metrics","spans"]),Yr=({path:t,level:n,size:s})=>s!==null&&s>Wt?n>0:n===0?!1:!t.every(r=>typeof r=="number"||Jr.has(r)),Gr=[{condition:({size:t})=>t!==null&&t>Wt,renderCollectionAsValue:!0,component:({value:t})=>e.jsx(Ns,{value:t,root:!0})}];function ws({name:t}){return e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tr-json-key",children:typeof t=="string"?JSON.stringify(t):t}),": "]})}function Cs({value:t,name:n,root:s=!1}){if(t!==null&&typeof t=="object")return e.jsx(Ns,{value:t,name:n,root:s});const r=t===null?"null":typeof t;return e.jsxs("div",{children:[n!==void 0&&e.jsx(ws,{name:n}),e.jsx("span",{className:`tr-json-${r}`,children:JSON.stringify(t)})]})}function Ns({value:t,name:n,root:s}){const[r,o]=l.useState(s),[i,p]=l.useState(Wt),u=l.useContext(bs);l.useEffect(()=>{u&&o(!u.collapsed&&s)},[u,s]);const m=l.useContext(vs).trim().toLowerCase(),a=Array.isArray(t),c=l.useMemo(()=>Array.isArray(t)?null:Object.keys(t),[t]),g=l.useMemo(()=>m?(c??Array.from({length:t.length},(w,C)=>C)).filter(w=>String(w).toLowerCase().includes(m)||JSON.stringify(Array.isArray(t)?t[Number(w)]:t[w]).toLowerCase().includes(m)):null,[t,c,m]),h=g?g.length:a?t.length:c.length,v=Math.min(i,h);return e.jsxs("details",{open:r,onToggle:w=>{w.target===w.currentTarget&&o(w.currentTarget.open)},children:[e.jsxs("summary",{children:[n!==void 0&&e.jsx(ws,{name:n}),e.jsxs("span",{children:[a?"[":"{",h===0?a?"]":"}":"…"]}),h>0&&e.jsxs("span",{className:"tr-count",children:[h," ",a?h===1?"item":"items":h===1?"key":"keys"]})]}),r&&h>0&&e.jsxs("div",{children:[Array.from({length:v},(w,C)=>{const S=g?g[C]:c?c[C]:C,R=Array.isArray(t)?t[Number(S)]:t[S];return e.jsx(Cs,{name:S,value:R},S)}),v<h&&e.jsxs("button",{type:"button",className:"btn",onClick:()=>p(w=>w+Wt),children:["Show ",Math.min(Wt,h-v)," more (",h-v," remaining)"]}),e.jsx("div",{children:a?"]":"}"})]})]})}function qr({value:t}){const n=l.useMemo(()=>{const s=JSON.stringify(t,null,2);if(s.length>zr)return s;const r=[],o=/"(?:\\.|[^"\\])*"(\s*:)?|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|\b(?:true|false|null)\b/g;let i=0;for(const p of s.matchAll(o)){const u=p.index;u>i&&r.push(s.slice(i,u));const m=p[0],a=p[1]||"",c=a?"key":m[0]==='"'?"string":m==="null"?"null":m==="true"||m==="false"?"boolean":"number";r.push(e.jsx("span",{className:`tr-json-${c}`,children:a?m.slice(0,-a.length):m},u)),a&&r.push(a),i=u+m.length}return i<s.length&&r.push(s.slice(i)),r},[t]);return e.jsx("pre",{className:"tr-value",children:n})}function Ss({value:t,initialMode:n="tree"}){const[s,r]=l.useState(n),[o,i]=l.useState(""),[p,u]=l.useState(!1),m=l.useRef(null),a=l.useRef(null),[c,g]=l.useState(null);return l.useEffect(()=>{const h=a.current;if(!h)return;const v=()=>h.querySelectorAll(".jer-editor-container button[tabindex='-1']").forEach(C=>{C.tabIndex=0});v();const w=new MutationObserver(v);return w.observe(h,{childList:!0,subtree:!0}),()=>w.disconnect()},[s,t]),e.jsxs("div",{children:[e.jsxs("div",{className:"tr-detail-tabs",role:"group","aria-label":"JSON view",children:[e.jsx("button",{type:"button",className:"btn","aria-pressed":s==="tree",onClick:()=>r("tree"),children:"Tree"}),e.jsx("button",{type:"button",className:"btn","aria-pressed":s==="raw",onClick:()=>r("raw"),children:"Raw JSON"})]}),s==="raw"?e.jsx(qr,{value:t}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"tr-json-tools",children:[e.jsxs("label",{className:"tr-json-search",children:["Search JSON",e.jsx("input",{type:"search",className:"tr-input",value:o,placeholder:"Find a key or value…",onChange:h=>i(h.target.value)})]}),e.jsx("button",{type:"button",className:"btn",onClick:()=>{var h;g(v=>({revision:((v==null?void 0:v.revision)??0)+1,collapsed:!0})),(h=m.current)==null||h.collapse({path:[],collapsed:!0,includeChildren:!0})},children:"Collapse all"}),e.jsx("button",{type:"button",className:"btn",onClick:()=>{var h;g(v=>({revision:((v==null?void 0:v.revision)??0)+1,collapsed:!1})),(h=m.current)==null||h.collapse([{path:[],collapsed:!0,includeChildren:!0},{path:[],collapsed:!1,includeChildren:!1}])},children:"Open root"})]}),e.jsx("p",{className:"tr-note",children:"Copy a value with its copy button; hold ⌘ / Ctrl to copy its path."}),p&&e.jsx("p",{role:"alert",className:"tr-capture-error",children:"Clipboard unavailable. Select the value and copy it manually."}),e.jsx(vs.Provider,{value:o,children:e.jsx(bs.Provider,{value:c,children:e.jsx("div",{ref:a,className:"tr-value tr-json-tree",children:t===null||typeof t!="object"?e.jsx(Cs,{value:t}):e.jsx(Wr,{data:t,editorRef:m,theme:Ur,rootName:"",collapse:o?!1:Yr,collapseAnimationTime:0,searchText:o||void 0,searchFilter:o?"all":void 0,searchDebounceTime:200,customNodeDefinitions:Gr,minWidth:0,maxWidth:"100%",baseFontSize:"inherit",indent:2,stringTruncateLength:300,showIconTooltips:!0,onCopy:({success:h})=>u(!h)},o?"search":"browse")})})})]})]})}function Xr(t,n=!1){var c,g,h,v,w;const s=!!t&&(t.featureEnabled??t.enabled??["awaiting","receiving","capturing"].includes(t.state)),r=((c=t==null?void 0:t.sources)==null?void 0:c.filter(C=>C.active).length)??0,o=/permission/i.test((t==null?void 0:t.setupError)??"")||!!((g=t==null?void 0:t.sources)!=null&&g.some(C=>/permission/i.test(C.error??""))),i=(t==null?void 0:t.events.length)??0,p=((h=t==null?void 0:t.observations)==null?void 0:h.length)??0,u=!!(t!=null&&t.bytes)||p>0||i>0;let m="Monitoring stopped",a="neutral";return n?(m="Monitor connection lost",a="error"):t?s&&o?(m="Capture permission needed",a="attention"):t.automatic&&s&&!((v=t.sources)!=null&&v.length)&&t.state!=="error"?m="Waiting for a collector…":t.state==="error"?(m="Capture error",a="error"):s&&r>0&&r<(((w=t.sources)==null?void 0:w.length)??0)?(m="Listening to some destinations",a="attention"):s&&o?(m="Capture permission needed",a="attention"):s&&t.state==="interrupted"?(m="Reconnecting capture…",a="attention"):s&&(r||!t.managed&&["receiving","capturing"].includes(t.state))?(m="Listening for telemetry",a="ok"):s&&(m=t.managed?"Starting monitoring…":"Activation needed"):m="Reading monitor…",{enabled:s,active:r,permission:o,decoded:i,observed:p,traffic:u,title:m,tone:a}}const Ge=t=>t&&typeof t=="object"&&!Array.isArray(t)?t:{},kt=t=>Array.isArray(t)?t:[],Jt=t=>new Date(t).toLocaleTimeString(),Ln="agent-dag.radar-feed-width",Zr=t=>({unconfirmed:"Transfer observed · receipt unconfirmed",accepted:"Collector accepted",partial:"Collector reported partial success",rejected:"Collector rejected",unknown:"Response incomplete",reset:"Stream reset"})[t.outcome],ln={encrypted:"Encrypted traffic observed; contents cannot be read.",joined_midstream:"Capture joined an existing connection. Waiting for a new HTTP/2 connection to decode it reliably.",capture_gap:"Incomplete packets or a gap were observed. Affected contents are not shown as decoded.",decode_failed:"Some payloads could not be decoded. They are not shown as verified events.",payload_limit:"A payload exceeded the inspection limit and was omitted.",stream_limit:"A stream exceeded the inspection limit.",connection_limit:"The connection inspection limit was reached.",unsupported_compression:"A compression format other than gzip was observed.",unsupported_link:"This network capture format is not supported.",unsupported_network:"Some packets used a network protocol this decoder does not support.",fragmented:"Fragmented IP packets cannot be decoded in this version.",unknown_export:"A request could not be identified as an OTLP export.",connection_closed:"An HTTP/2 connection closed.",idle_connection:"An idle connection was removed from the decoder."};function Qr(t){return/prompt/i.test(t)?"Prompt-related field included in this export.":/response|completion/i.test(t)?"Response-related field included in this export.":/tool/i.test(t)?"Tool-related field included in this export.":/session/i.test(t)?"Session identifier or session metadata.":/user|email|account/i.test(t)?"User or account metadata.":/token|cost|duration|latency/i.test(t)?"Usage or timing measurement.":"Attribute included in this export."}function Nt({value:t}){return e.jsx("pre",{className:"tr-value",children:typeof t=="string"?t:JSON.stringify(t,null,2)})}function eo({value:t}){return e.jsx("dl",{className:"tr-attributes",children:kt(t).map((n,s)=>{const r=Ge(n);return e.jsxs("div",{children:[e.jsxs("dt",{children:[e.jsx("code",{children:String(r.key??"Unnamed attribute")}),e.jsx("span",{children:Qr(String(r.key))})]}),e.jsx("dd",{children:e.jsx(Nt,{value:Kt(r.value)})})]},s)})})}const to=[["Error",["error.message","exception.message","error","error_type"]],["Prompt",en],["Response",mn],["Project",Hn],["Working directory",Wn],["Repository",["repository.url","repo_url","vcs.repository.url.full"]],["Branch",["git.branch","branch","vcs.ref.head.name"]],["Tool",["tool_name","tool.name","gen_ai.tool.name"]],["Tool input",["tool_parameters","tool_input","tool.input"]],["Tool result",["tool_result","tool_response","tool.output"]],["Model",["model","gen_ai.request.model","gen_ai.response.model"]],["Input tokens",["input_tokens","gen_ai.usage.input_tokens"]],["Output tokens",["output_tokens","gen_ai.usage.output_tokens"]],["Cache read tokens",["cache_read_tokens"]],["Cache creation tokens",["cache_creation_tokens"]],["Cost (USD)",["cost_usd"]],["Duration (ms)",["duration_ms","interaction.duration_ms"]],["Time to first token (ms)",["ttft_ms"]],["Success",["success"]],["Stop reason",["stop_reason","gen_ai.response.finish_reasons"]],["Token type",["type"]]];function Es({value:t}){const n=Tt(t);return e.jsx("dl",{className:"tr-highlights",children:to.flatMap(([s,r])=>{const o=ft(n,r).key;if(!o)return[];const i=n[o];if(i===null||i==="")return[];if((s==="Prompt"||s==="Response")&&dn(i))return[e.jsxs("div",{"data-field":s,children:[e.jsx("dt",{children:s}),e.jsxs("dd",{children:[e.jsx("span",{className:"tr-evidence-status",children:"Redacted in export"}),e.jsx("p",{className:"tr-note",children:"The export contains a redaction marker, not the original text."})]})]},s)];const p=typeof i=="string"?i:JSON.stringify(i,null,2);return[e.jsxs("div",{"data-field":s,children:[e.jsx("dt",{children:s}),e.jsx("dd",{children:p.length>800?e.jsxs(e.Fragment,{children:[e.jsx(Nt,{value:p.slice(0,800)+"…"}),e.jsxs("details",{className:"tr-details",children:[e.jsxs("summary",{children:["Show full ",s.toLowerCase()]}),e.jsx(Nt,{value:i})]})]}):e.jsx(Nt,{value:i})})]},s)]})})}function vn({label:t,value:n}){const[s,r]=l.useState(!1);return e.jsxs("details",{className:"tr-details",onToggle:o=>{o.target===o.currentTarget&&r(o.currentTarget.open)},children:[e.jsx("summary",{children:t}),s&&e.jsx(Ss,{value:n})]})}function no({record:t}){const n=["gauge","sum","histogram","exponentialHistogram","summary"].find(s=>t[s]);return n?e.jsxs("div",{children:[t.description&&e.jsx("p",{className:"tr-note",children:String(t.description)}),kt(Ge(t[n]).dataPoints).map((s,r)=>{const o=Ge(s);return e.jsxs("section",{children:[e.jsxs("dl",{className:"tr-facts",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Measurement"}),e.jsx("dd",{children:n})]}),o.asInt!==void 0||o.asDouble!==void 0?e.jsxs("div",{children:[e.jsx("dt",{children:"Value"}),e.jsx("dd",{children:e.jsxs("code",{children:[String(o.asInt??o.asDouble)," ",String(t.unit??"")]})})]}):null,o.count!==void 0&&e.jsxs("div",{children:[e.jsx("dt",{children:"Count"}),e.jsx("dd",{children:e.jsx("code",{children:String(o.count)})})]}),o.sum!==void 0&&e.jsxs("div",{children:[e.jsx("dt",{children:"Sum"}),e.jsx("dd",{children:e.jsxs("code",{children:[String(o.sum)," ",String(t.unit??"")]})})]})]}),e.jsx(Es,{value:o.attributes}),e.jsx(vn,{label:"All measurement fields",value:o})]},r)})]}):null}function so({record:t}){let n=null;try{n=`${Number(BigInt(String(t.endTimeUnixNano))-BigInt(String(t.startTimeUnixNano)))/1e6} ms`}catch{n=null}return e.jsxs("dl",{className:"tr-facts",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Duration"}),e.jsx("dd",{children:n??"Not included"})]}),t.kind&&e.jsxs("div",{children:[e.jsx("dt",{children:"Span kind"}),e.jsx("dd",{children:String(t.kind)})]}),t.status&&e.jsxs("div",{children:[e.jsx("dt",{children:"Span status"}),e.jsx("dd",{children:e.jsx(Nt,{value:t.status})})]})]})}const ro=[["Prompt",en],["Response",mn]];function oo({fields:t}){return e.jsx("dl",{className:"tr-content-evidence",children:ro.map(([n,s])=>{const r=t.map(p=>ft(p,s)),o=r.some(p=>p.state==="included"),i=r.some(p=>p.state==="redacted");return e.jsxs("div",{children:[e.jsx("dt",{children:n}),e.jsx("dd",{"data-evidence":o?"included":i?"redacted":"absent",children:o?i?"Included · some records redacted":"Included in export":i?"Redacted in export":"Not included in this export"})]},String(n))})})}function ao({fields:t,sessions:n}){const r=t.map(i=>Gs(i,n)).filter(i=>i.source!=="absent"),o=r.filter((i,p)=>r.findIndex(u=>u.source===i.source&&u.project.value===i.project.value&&u.directory.value===i.directory.value)===p);return e.jsxs("section",{className:"tr-project-context","aria-label":"Project context",children:[e.jsx("h4",{children:"Project / working directory"}),o.length?o.map((i,p)=>e.jsxs("div",{children:[i.project.value!==null&&(i.project.state==="redacted"?e.jsx("p",{className:"tr-note",children:"Project redacted in export"}):e.jsx(Nt,{value:i.project.value})),i.directory.value!==null&&i.directory.value!==i.project.value&&(i.directory.state==="redacted"?e.jsx("p",{className:"tr-note",children:"Working directory redacted in export"}):e.jsx(Nt,{value:i.directory.value})),e.jsx("p",{className:"tr-note",children:i.source==="export"?"Included in export":"Local ccdeck context · exact session match. Project path is not present in the export."})]},p)):e.jsx("p",{className:"tr-note",children:"Not included in this export. No matching local working directory is available."})]})}function Mn({record:t,signal:n}){const s=Tt(t.attributes),r=t.eventName??t.name??s["event.name"]??(n==="logs"?"Log record":"Record"),o=Kt(t.body),i=typeof o=="string"&&(o===r||o===`claude_code.${r}`);return e.jsxs("article",{className:"tr-record",children:[e.jsx("h4",{children:String(r)}),t.body&&!i&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"tr-note",children:"Event body"}),e.jsx(Nt,{value:o})]}),n==="metrics"&&e.jsx(no,{record:t}),n==="traces"&&e.jsx(so,{record:t}),t.attributes&&e.jsx(Es,{value:t.attributes}),t.severityText&&e.jsxs("p",{className:"tr-note",children:["Severity: ",String(t.severityText)]}),e.jsx(vn,{label:"All record fields",value:t})]})}function io({scope:t,signal:n,item:s}){const r=kt(t[s]).map(Ge),o=n==="logs"?r.map((c,g)=>({record:c,index:g,priority:Ys(c)})).sort((c,g)=>c.priority-g.priority||c.index-g.index):[],i=o.some(c=>c.priority<4),p=i?o.filter(c=>c.priority<4).map(({record:c})=>c):r,u=i?o.filter(c=>c.priority===4).map(({record:c})=>c):[],[m,a]=l.useState(!1);return e.jsxs("div",{children:[p.map((c,g)=>e.jsx(Mn,{record:c,signal:n},g)),!!u.length&&e.jsxs("details",{className:"tr-details",onToggle:c=>{c.target===c.currentTarget&&a(c.currentTarget.open)},children:[e.jsxs("summary",{children:["Other events (",u.length,")"]}),m&&u.map((c,g)=>e.jsx(Mn,{record:c,signal:n},g))]}),t.scope&&e.jsx(vn,{label:"Instrumentation details",value:t.scope})]})}function lo({payload:t,signal:n,sessions:s=[]}){const r=n==="traces"?"Spans":n==="logs"?"Logs":"Metrics",o=n==="traces"?"spans":n==="logs"?"logRecords":"metrics",i=kt(t["resource"+r]).map(Ge),p=i.flatMap(u=>{const m=Tt(Ge(u.resource).attributes),a=kt(u["scope"+r]).flatMap(c=>kt(Ge(c)[o]).map(Ge));return a.length?a.flatMap(c=>{const g={...m,...Tt(c.attributes)},h=["gauge","sum","histogram","exponentialHistogram","summary"].find(w=>c[w]),v=h?kt(Ge(c[h]).dataPoints):[];return v.length?v.map(w=>({...g,...Tt(Ge(w).attributes)})):[g]}):[m]});return e.jsxs("div",{className:"tr-decoded",children:[e.jsx(ao,{fields:p,sessions:s}),e.jsx(oo,{fields:p}),e.jsxs("details",{className:"tr-details tr-export-scope",children:[e.jsx("summary",{children:"About captured content"}),e.jsx("p",{className:"tr-note",children:"These are telemetry fields sent to the collector. This view does not capture the full request sent to the AI model. Missing text is not reconstructed from local conversations."})]}),i.map((u,m)=>e.jsxs("section",{children:[kt(u["scope"+r]).map((a,c)=>e.jsx(io,{scope:Ge(a),signal:n,item:o},c)),e.jsxs("details",{className:"tr-details",children:[e.jsx("summary",{children:"Resource metadata"}),e.jsx(eo,{value:Ge(u.resource).attributes})]})]},m))]})}function co({capture:t,radar:n,failed:s,busy:r,pendingAction:o=null,error:i,command:p,commands:u=[],action:m,sessionFilter:a="all",sessions:c=[]}){var vt,et,pt,bt,I,q,pe,ve,Pe,Oe,we,tt,St;const g=$n([...((vt=n==null?void 0:n.config)==null?void 0:vt.variables)??[],...(n==null?void 0:n.environment)??[]]),h=[...new Set(g.map(kn).filter(d=>!!d))],v=Bn(n).filter(d=>!h.includes(d)&&kn(`http://${d}`)),[w,C]=l.useState("all"),[S,R]=l.useState(""),[P,_]=l.useState(null),[b,f]=l.useState(null),[y,N]=l.useState("all"),[x,k]=l.useState("all"),B=l.useRef(null),[F,j]=l.useState(()=>{const d=Number(_s(Ln));return d>=28&&d<=65?d:34}),L=d=>{j(d),Ms(Ln,String(d))},[A,O]=l.useState(!1),[M,X]=l.useState(100),[Z,oe]=l.useState(null),[U,ae]=l.useState(null),[Q,te]=l.useState(null),[ge,je]=l.useState(!1),Le=l.useRef(0),[de,G]=l.useState("summary"),[z,ie]=l.useState(null),[Ce,Ae]=l.useState(0),Ue=l.useRef(null),$=(t==null?void 0:t.events)??[],re=!!($.length||(et=t==null?void 0:t.observations)!=null&&et.length),lt=new Map($.map(d=>[d.id,d])),Ie=U?U.map(d=>lt.get(d.id)).filter(d=>!!d):$,ye=Ie.filter(d=>{var V,ue;return(!A||d.content.includes("Prompt"))&&(x==="all"||d.signal===x)&&(y==="all"||y===d.destination)&&(a==="all"||(a==="unidentified"?!((V=d.sessionIds)!=null&&V.length):(ue=d.sessionIds)==null?void 0:ue.includes(a)))}),ke=((t==null?void 0:t.observations)??[]).filter(d=>!A&&(Z===null||Z.includes(d.id))&&x==="all"&&(a==="all"||a==="unidentified")&&(y==="all"||y===d.destination)),le=ke.find(d=>d.id===P),J=P!==null?void 0:b===null?ye[0]:ye.find(d=>d.id===b),He=[...ye.map(d=>({kind:"export",event:d})),...ke.map(d=>({kind:"observation",event:d}))].sort((d,V)=>V.event.at-d.event.at||V.event.id-d.event.id),yt=new Set(U==null?void 0:U.map(d=>d.id)),_e=new Set(Z),De=U===null?0:$.filter(d=>!yt.has(d.id)).length+((t==null?void 0:t.observations)??[]).filter(d=>!_e.has(d.id)).length,xe=J==null?void 0:J.id;l.useEffect(()=>{f(null),_(null),X(100)},[a,x,y,A]),l.useEffect(()=>{b!==null||P!==null||(ye.length?f(ye[0].id):ke.length&&_(ke[0].id))},[(pt=ye[0])==null?void 0:pt.id,(bt=ke[0])==null?void 0:bt.id,b,P]),l.useEffect(()=>{if(ie(null),te(null),xe===void 0)return;const d=new AbortController;let V=!0;const ue=setTimeout(()=>d.abort(),5e3);return fetch(`/api/system/traffic-radar/capture/event?id=${xe}`,{signal:d.signal}).then(async D=>{if(!D.ok)throw new Error("This message has expired. Select a newer message.");const T=await D.json();V&&!d.signal.aborted&&ie({id:xe,payload:T.payload})}).catch(D=>{V&&ie({id:xe,error:d.signal.aborted?"Loading timed out. Try again.":D instanceof Error?D.message:"Could not read this message."})}).finally(()=>clearTimeout(ue)),()=>{V=!1,clearTimeout(ue),d.abort()}},[xe,P,Ce]),l.useEffect(()=>{if(!Q||Q==="failed")return;const d=setTimeout(()=>te(null),2e3);return()=>clearTimeout(d)},[Q]),l.useEffect(()=>{if(!ge)return;const d=setTimeout(()=>je(!1),5e3);return()=>clearTimeout(d)},[ge]);const Ve=(t==null?void 0:t.shell)??((n==null?void 0:n.platform)==="win32"?"PowerShell":"Terminal"),ct=Ve==="PowerShell",Me=Xr(t,s),Te=Me.enabled,Ne=!!(t!=null&&t.managed),ce=(t==null?void 0:t.automatic)===!0,We=Ne&&Me.permission,qe=Me.active,Je=((I=t==null?void 0:t.sources)==null?void 0:I.length)??1,xt=Me.title,Se=d=>{const V=Fn(o??(r?"capture":null),d);return{disabled:V.disabled,"aria-busy":V.busy}},Ye=d=>{var V,ue,D;_(null),f(d.id),typeof window<"u"&&((V=window.matchMedia)!=null&&V.call(window,"(max-width: 640px)").matches)&&((ue=Ue.current)==null||ue.focus({preventScroll:!0}),(D=Ue.current)==null||D.scrollIntoView({block:"start",behavior:"auto"}))},Fe=()=>{const d=Date.now(),V=Ls({armedFor:ge?"history":null,target:"history",armedAt:Le.current,now:d,gapMs:350});if(V==="arm"){Le.current=d,je(!0);return}V!=="ignore"&&(je(!1),f(null),_(null),ae(null),oe(null),m("clear"))},dt=()=>{var V;te(null),ae(null),oe(null),f(null),_(null);const d=w==="custom"?[S.trim()]:w==="all"?h:[w];m("prepare",d.length?d:((V=t==null?void 0:t.sources)==null?void 0:V.map(ue=>ue.destination))??(t!=null&&t.destination?[t.destination]:[]))},ut=u.length?u:p?[{destination:(t==null?void 0:t.destination)??"Collector",command:p}]:[],Xe=async(d,V)=>{try{await navigator.clipboard.writeText(d),te(V)}catch{te("failed")}},Ze=(d=[])=>d.length?d.map(V=>{var ue;return`${((ue=c.find(D=>D.id===V))==null?void 0:ue.label)??"Session"} · ${V.slice(0,8)}`}).join(", "):"Unidentified session",ht=new Set([...((q=t==null?void 0:t.sources)==null?void 0:q.map(d=>d.destination))??[],...h]),Qe=(n==null?void 0:n.status)==="observing"?n.connections.filter(d=>d.active&&ht.has(d.destination)):[];return e.jsxs("div",{className:"tr-telemetry",children:[e.jsxs("div",{className:"tr-capture-bar",children:[e.jsxs("div",{children:[e.jsxs("h3",{role:"status","aria-live":"polite",children:[e.jsx("span",{className:`tr-live-dot tr-dot-${Me.tone}`}),xt]}),e.jsx("p",{className:"tr-note",children:s?"Showing the last successful read. Reconnecting automatically.":Te?qe?`${qe} of ${Je} destination${Je===1?"":"s"} listening · ${Me.traffic?"Traffic observed":"No traffic observed yet"}`:"Monitoring is enabled; the listener is not ready yet.":"Claude may still be sending telemetry."}),Te&&e.jsxs("div",{className:"tr-active-destinations",role:"group","aria-label":"Monitored destinations",children:[e.jsxs("span",{children:["Destination",Je>1?"s":""]}),(pe=t==null?void 0:t.sources)!=null&&pe.length?t.sources.map(d=>e.jsxs("span",{className:"tr-destination-entry",children:[e.jsx("code",{children:d.destination}),(Je>1||!d.active)&&e.jsx("span",{className:d.active?"tr-source-ready":"tr-source-pending",children:d.active?"Listening":"Not listening"}),!d.active&&d.error&&e.jsx("span",{className:"tr-source-error",children:d.error})]},d.destination)):(t==null?void 0:t.destination)&&e.jsx("code",{children:t.destination})]})]}),!ce&&e.jsx("div",{className:"tr-capture-actions",children:Te?e.jsx("button",{className:"btn",...Se("stop"),onClick:()=>void m("stop"),children:"Stop monitoring"}):e.jsx("button",{className:"btn primary",...Se("prepare"),disabled:Se("prepare").disabled||!t||s||(n==null?void 0:n.status)==="unsupported"||w==="all"&&!h.length||w==="custom"&&!S.trim(),onClick:dt,children:o==="prepare"?"Starting…":"Start monitoring"})})]}),!ce&&!Te&&e.jsxs("div",{className:"tr-destination",children:[e.jsxs("label",{children:["Destination",e.jsxs(Yt,{"aria-label":"Capture destination",value:w,onChange:d=>C(d.target.value),children:[e.jsx("option",{value:"all",children:h.length===1?h[0]:h.length?`All configured destinations (${h.length})`:"Choose a collector…"}),h.map(d=>e.jsx("option",{value:d,children:d},d)),v.length>0&&e.jsx("optgroup",{label:"Observed Claude connections · telemetry unverified",children:v.map(d=>e.jsxs("option",{value:d,children:[d," · observed"]},d))}),e.jsx("option",{value:"custom",children:"Another IPv4 address…"})]})]}),w==="custom"&&e.jsx("input",{className:"tr-input","aria-label":"Collector IPv4 and port",value:S,onChange:d=>R(d.target.value),placeholder:"192.168.1.10:4317"}),!h.length&&w==="all"&&e.jsx("span",{className:"tr-note",children:v.length?"Choose an observed connection or enter your collector address.":"Enter your collector address to monitor traffic. Missing settings do not mean telemetry is off."})]}),(n==null?void 0:n.status)==="unsupported"&&e.jsx("p",{className:"tr-capture-error",role:"status",children:"Live capture is available on macOS, Linux and Windows. You can still inspect a local file."}),(t==null?void 0:t.setupError)&&e.jsx("p",{className:"tr-capture-error",role:"status",children:t.setupError}),i&&e.jsxs("p",{className:"tr-capture-error",role:"alert",children:[i,ct&&i.includes("Npcap")&&e.jsxs(e.Fragment,{children:[" ",e.jsx("a",{href:"https://www.wireshark.org/download.html",target:"_blank",rel:"noreferrer",children:"Get Wireshark"})]})]}),!Ne&&Te&&!ut.length&&(t==null?void 0:t.state)==="awaiting"&&e.jsxs("div",{className:"tr-activation",children:[e.jsxs("p",{children:["Activation is pending. Generate the ",Ve," instructions again to continue."]}),e.jsx("button",{className:"btn",...Se("prepare"),onClick:dt,children:"Show activation instructions"}),e.jsx("p",{className:"tr-note",children:"The previous token will be invalidated."})]}),!Ne&&ut.length>0&&Te&&e.jsxs("details",{className:"tr-activation",open:!qe,children:[e.jsxs("summary",{children:["Activate in ",Ve,Je>1?` · ${qe}/${Je} listening`:""]}),e.jsx("p",{children:ct?"Run each command in a separate PowerShell tab. Wireshark with Npcap is required; use an administrator tab if Npcap restricts capture.":"Run each command in a separate Terminal tab. Only tcpdump asks for administrator permission."}),ut.map(d=>e.jsxs("div",{className:"tr-command-entry",children:[e.jsxs("div",{children:[e.jsx("code",{children:d.destination}),e.jsx("button",{className:"btn",onClick:()=>void Xe(d.command,d.destination),children:Q===d.destination?"Copied":"Copy command"})]}),e.jsx("pre",{className:"tr-command",children:d.command})]},d.destination)),e.jsxs("p",{className:"tr-note",children:["Press Ctrl+C in each ",Ve," tab to stop capture. Monitoring continues until you stop it. Commands contain a local token; do not share them."]})]}),We&&e.jsxs("div",{className:"tr-activation",role:"status",children:[e.jsx("strong",{children:"Allow packet capture once"}),e.jsxs("p",{className:"tr-note",children:[ct?"Npcap is restricting access. Allow this user to capture traffic in Npcap setup.":(t==null?void 0:t.platform)==="darwin"?"Install Wireshark’s ChmodBPF permission helper so tcpdump can capture for this user.":"Grant tcpdump packet capture permissions for this user."," ccdeck retries automatically when access is available."]}),e.jsx("a",{href:"https://wiki.wireshark.org/CaptureSetup/CapturePrivileges",target:"_blank",rel:"noreferrer",children:"Capture permission setup"})]}),Q==="failed"&&e.jsx("p",{className:"tr-capture-error",role:"alert",children:"Clipboard unavailable. Select the text and copy it manually."}),e.jsxs("div",{className:"tr-workspace","data-empty":!re,ref:B,style:{"--tr-feed-width":`${F}%`},children:[e.jsxs("section",{className:"tr-feed","aria-label":"Collector activity",children:[re&&e.jsxs("div",{className:"tr-feed-head",children:[e.jsxs("h3",{children:["Activity ",e.jsx("span",{className:"tr-count",children:He.length})]}),e.jsxs("label",{className:"tr-prompt-filter",title:"Show only exports with prompt-related fields, including redacted prompts",children:[e.jsx("span",{children:"With prompt"}),e.jsx("button",{type:"button",className:"switch",role:"switch","aria-label":"With prompt","aria-checked":A,onClick:()=>O(d=>!d),children:e.jsx("span",{className:"switch-knob"})})]})]}),(re||U!==null||x!=="all"||y!=="all")&&e.jsxs("details",{className:"tr-details tr-feed-options",children:[e.jsxs("summary",{children:["Filters and history",x!=="all"||y!=="all"?" · Filtered":""]}),e.jsxs("div",{className:"tr-filter",children:[e.jsx("label",{children:e.jsxs(Yt,{"aria-label":"Message type",value:x,onChange:d=>{f(null),k(d.target.value)},children:[e.jsx("option",{value:"all",children:"All types"}),e.jsx("option",{value:"logs",children:"Events"}),e.jsx("option",{value:"metrics",children:"Metrics"}),e.jsx("option",{value:"traces",children:"Traces"})]})}),e.jsx("label",{children:e.jsxs(Yt,{"aria-label":"Message destination",value:y,onChange:d=>{f(null),N(d.target.value)},children:[e.jsx("option",{value:"all",children:"All destinations"}),[...new Set([...h,...((ve=t==null?void 0:t.sources)==null?void 0:ve.map(d=>d.destination))??[],...$.map(d=>d.destination),...((t==null?void 0:t.observations)??[]).map(d=>d.destination)])].map(d=>e.jsx("option",{value:d,children:d},d))]})})]}),e.jsxs("div",{className:"tr-history-toolbar",children:[e.jsxs("p",{className:"tr-history",title:"Matching activity retained over the last 24 hours",children:["24h · ",ye.length," decoded · ",ke.length," observed"]}),e.jsxs("div",{className:"tr-capture-actions",children:[e.jsxs("button",{className:"btn","aria-pressed":U!==null,title:U?"Show new entries received while the list was paused":"Freeze the list while monitoring continues",disabled:!Ie.length&&!ke.length&&U===null,onClick:()=>{ae(U?null:[...Ie]),oe(U?null:((t==null?void 0:t.observations)??[]).map(d=>d.id))},children:[e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:U?e.jsx("path",{d:"m9 5 11 7-11 7z"}):e.jsx("path",{d:"M8 5v14M16 5v14"})}),e.jsx("span",{className:"tr-action-label",children:U?"Resume list":"Pause list"})]}),e.jsxs("button",{className:ge?"btn danger armed":"btn",...Se("clear"),disabled:Se("clear").disabled||!(t!=null&&t.events.length)&&!((Pe=t==null?void 0:t.observations)!=null&&Pe.length),title:ge?"Remove decoded messages and observations. Monitoring continues.":"Clear retained messages and connection observations",onBlur:()=>je(!1),onClick:Fe,children:[e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"M3 6h18M9 6V3h6v3M5 6l1 15h12l1-15M10 10v7M14 10v7"})}),e.jsx("span",{className:ge?"":"tr-action-label",children:ge?"Confirm clear history":"Clear history"})]})]})]})]}),U&&e.jsxs("p",{className:"tr-list-notice",role:"status",children:["List paused · Monitoring continues",De>0?` · ${De} new ${De===1?"entry":"entries"}`:""]}),(Oe=t==null?void 0:t.retention)!=null&&Oe.evictedExports?e.jsxs("p",{className:"tr-note",children:[t.retention.evictedExports.toLocaleString()," older messages removed by history limits."]}):null,He.length?e.jsx("ul",{className:"tr-connections",onKeyDown:d=>{var Y;if(!["ArrowDown","ArrowUp","Home","End"].includes(d.key))return;const V=Array.from(d.currentTarget.querySelectorAll(".tr-message")),ue=V.indexOf(document.activeElement);if(ue<0)return;d.preventDefault();const D=d.key==="Home"?0:d.key==="End"?V.length-1:Math.max(0,Math.min(V.length-1,ue+(d.key==="ArrowDown"?1:-1))),T=He[D];T&&(f(T.kind==="export"?T.event.id:null),_(T.kind==="observation"?T.event.id:null)),(Y=V[D])==null||Y.focus()},children:He.slice(0,M).map(d=>d.kind==="export"?e.jsx("li",{children:e.jsxs("button",{className:"tr-message","aria-pressed":(J==null?void 0:J.id)===d.event.id,onClick:()=>Ye(d.event),children:[e.jsx(Et,{kind:d.event.signal,className:"tr-row-icon"}),e.jsxs("span",{className:"tr-event-top",children:[e.jsx("strong",{className:"tr-event-name",title:d.event.name,children:d.event.name}),e.jsx("time",{dateTime:new Date(d.event.at).toISOString(),children:Jt(d.event.at)})]}),d.event.content.includes("Prompt")&&e.jsx(qs,{event:d.event}),e.jsx("span",{className:"tr-event-context",title:Ze(d.event.sessionIds),children:Ze(d.event.sessionIds)}),e.jsxs("span",{className:"tr-event-bottom",children:[e.jsx("span",{className:`tr-receipt ${d.event.outcome==="accepted"?"tr-tone-ok":d.event.outcome==="rejected"?"tr-tone-error":d.event.outcome==="partial"?"tr-tone-enabled":""}`,children:d.event.outcome==="accepted"?"Accepted":d.event.outcome==="unconfirmed"?"Receipt unconfirmed":d.event.outcome==="partial"?"Partially accepted":d.event.outcome==="rejected"?"Rejected":"Receipt unknown"}),e.jsxs("span",{children:[d.event.count," ",d.event.count===1?"record":"records"]})]})]})},`event-${d.event.id}`):e.jsx("li",{children:e.jsxs("button",{className:"tr-message","aria-pressed":P===d.event.id,onClick:()=>{var V,ue,D;f(null),_(d.event.id),(V=window.matchMedia)!=null&&V.call(window,"(max-width: 640px)").matches&&((ue=Ue.current)==null||ue.focus({preventScroll:!0}),(D=Ue.current)==null||D.scrollIntoView({block:"start",behavior:"auto"}))},children:[e.jsx(Et,{kind:"connection",className:"tr-row-icon"}),e.jsxs("span",{className:"tr-event-top",children:[e.jsx("strong",{className:"tr-event-name",children:"Connection observed"}),e.jsx("time",{dateTime:new Date(d.event.at).toISOString(),children:Jt(d.event.at)})]}),e.jsxs("span",{className:"tr-event-context",title:d.event.destination,children:[d.event.destination," · ",d.event.reason==="encrypted"?"Encrypted contents":"Contents not decoded"]})]})},`observation-${d.event.id}`))}):e.jsxs("div",{className:"tr-empty-capture",children:[!re&&e.jsx(Et,{kind:"radar"}),e.jsx("h4",{children:$.length||(we=t==null?void 0:t.observations)!=null&&we.length?"No matching activity":Te||ce?"Waiting for traffic":"Message capture is off"}),e.jsx("p",{className:"tr-note",children:$.length||(tt=t==null?void 0:t.observations)!=null&&tt.length?A?"No exports with prompt fields match your filters. Turn off With prompt to see all activity. Redacted prompts are included.":"Try another session, type or destination.":ce?"Radar monitors automatically when a collector is available. Keep using Claude while Radar listens.":Te?"New collector activity will appear here. Keep using Claude while Radar listens.":"Choose a destination and start monitoring. New collector activity will appear here."})]}),He.length>M&&e.jsx("button",{className:"btn",onClick:()=>X(d=>d+100),children:"Show older messages"}),Qe.length>0&&e.jsxs("details",{className:"tr-details",children:[e.jsxs("summary",{children:["Connections to these collectors (",Qe.length,")"]}),e.jsx("ul",{className:"tr-live-connections",children:Qe.map(d=>e.jsxs("li",{children:[e.jsx("code",{children:d.destination}),e.jsxs("span",{children:["Claude · ",d.connecting&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tr-attempt",children:cn(d)})," · "]}),"PID ",d.pid," · ",d.workspace??"Workspace unknown"]})]},`${d.pid}:${d.destination}`))}),e.jsx("p",{className:"tr-note",children:"A connection alone does not prove a telemetry message was sent. These connections are not filtered by session."})]})]}),re&&e.jsx(Us,{workspace:B,width:F,onCommit:L}),e.jsx("section",{className:"tr-inspector",hidden:!re,"aria-label":"Activity inspector",ref:Ue,tabIndex:-1,children:le?e.jsxs("div",{children:[e.jsx("div",{className:"tr-inspector-head",children:e.jsxs("h3",{children:[e.jsx(Et,{kind:"connection"}),"Connection details"]})}),e.jsxs("dl",{className:"tr-facts",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Destination"}),e.jsxs("dd",{className:"tr-fact-copy",children:[e.jsx("code",{children:le.destination}),e.jsx("button",{className:"tr-inline-copy","aria-label":"Copy destination",onClick:()=>void Xe(le.destination,"destination"),title:Q==="destination"?"Copied destination":"Copy destination",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:Q==="destination"?e.jsx("path",{d:"m5 12 4 4L19 6"}):e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"2"}),e.jsx("path",{d:"M16 8V4H4v12h4"})]})})})]})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Observed"}),e.jsx("dd",{children:e.jsx("time",{dateTime:new Date(le.at).toISOString(),children:new Date(le.at).toLocaleString()})})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Source"}),e.jsx("dd",{children:e.jsx("code",{children:le.source||"Not identified"})})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Contents"}),e.jsx("dd",{children:le.reason==="encrypted"?"Encrypted":"Not decoded"})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Session"}),e.jsx("dd",{children:"Not identified"})]})]}),e.jsxs("div",{className:"tr-inspection-limit",children:[e.jsx(Et,{kind:"info"}),e.jsxs("div",{children:[e.jsx("h4",{children:le.reason==="encrypted"?"Encrypted connection":"Message contents unavailable"}),e.jsx("p",{children:le.reason==="joined_midstream"?"Radar joined an existing connection. Keep listening: new connections may allow decoding.":le.reason==="encrypted"?"Radar cannot decrypt HTTPS. Inspect the collector’s own records for the contents.":ln[le.reason]??"This connection could not be decoded."}),e.jsxs("details",{className:"tr-details",children:[e.jsx("summary",{children:"Technical details"}),e.jsx("p",{className:"tr-note",children:ln[le.reason]??"The decoder could not read this connection."}),e.jsxs("p",{className:"tr-note",children:["There is no decoded JSON or confirmed session ID for this observation. ",le.reason==="joined_midstream"&&"Already captured traffic cannot be reconstructed."]})]})]})]})]}):J?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"tr-inspector-head",children:[e.jsxs("h3",{children:[e.jsx(Et,{kind:J.signal}),J.name]}),e.jsxs("p",{className:"tr-note",children:["Decoded ",J.signal==="logs"?"event":J.signal==="metrics"?"metrics":"trace"," · ",Ze(J.sessionIds)," · ",Jt(J.at)]})]}),e.jsxs("div",{className:"tr-detail-tabs",role:"group","aria-label":"Message format",children:[e.jsx("button",{className:"btn","aria-pressed":de==="summary",onClick:()=>G("summary"),children:"Overview"}),e.jsx("button",{className:"btn","aria-pressed":de==="json",onClick:()=>G("json"),children:"JSON"}),e.jsx("button",{className:"btn tr-copy-json",disabled:!(z!=null&&z.payload)||z.id!==J.id,onClick:()=>void Xe(JSON.stringify(z==null?void 0:z.payload,null,2),"json"),children:Q==="json"?"Copied":"Copy JSON"})]}),(z==null?void 0:z.id)===J.id?z.payload?de==="json"?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"tr-note",children:"Decoded OTLP fields. Unknown protobuf fields and transport headers are excluded."}),e.jsx(Ss,{value:z.payload},J.id)]}):e.jsxs(e.Fragment,{children:[e.jsx(lo,{payload:z.payload,signal:J.signal,sessions:c},J.id),e.jsxs("details",{className:"tr-details",children:[e.jsx("summary",{children:"Transfer details"}),e.jsxs("dl",{className:"tr-facts",children:[e.jsxs("div",{children:[e.jsx("dt",{children:"Destination"}),e.jsxs("dd",{className:"tr-fact-copy",children:[e.jsx("code",{children:J.destination}),e.jsx("button",{className:"tr-inline-copy","aria-label":"Copy destination",onClick:()=>void Xe(J.destination,"destination"),title:Q==="destination"?"Copied destination":"Copy destination",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:Q==="destination"?e.jsx("path",{d:"m5 12 4 4L19 6"}):e.jsxs(e.Fragment,{children:[e.jsx("rect",{x:"8",y:"8",width:"12",height:"12",rx:"2"}),e.jsx("path",{d:"M16 8V4H4v12h4"})]})})})]})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Time"}),e.jsx("dd",{children:Jt(J.at)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Receipt"}),e.jsx("dd",{children:Zr(J)})]}),e.jsxs("div",{children:[e.jsx("dt",{children:"Size"}),e.jsxs("dd",{children:[J.bytes.toLocaleString()," bytes · ",J.count," ",J.count===1?"record":"records"]})]}),((St=J.response)==null?void 0:St.message)&&e.jsxs("div",{children:[e.jsx("dt",{children:"Response"}),e.jsx("dd",{children:e.jsx(Nt,{value:J.response.message})})]})]})]})]}):e.jsxs("div",{role:"alert",children:[e.jsx("p",{children:z.error}),e.jsx("button",{className:"btn",onClick:()=>Ae(Ce+1),children:"Retry"})]}):e.jsx("p",{className:"tr-note",role:"status",children:"Loading message contents…"})]}):e.jsxs("div",{className:"tr-inspector-empty",children:[e.jsx("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.25","aria-hidden":"true",children:e.jsx("path",{d:"M8 4H5a1 1 0 0 0-1 1v14a1 1 0 0 0 1 1h3M16 4h3a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1h-3M10 8l-3 4 3 4M14 8l3 4-3 4"})}),e.jsx("h3",{children:b!==null||P!==null?"Activity no longer available":"Inspect collector activity"}),e.jsx("p",{className:"tr-note",children:b!==null||P!==null?"The selected entry is no longer retained or does not match your filter. Select another entry.":Me.traffic&&!Me.decoded?"Traffic has been observed, but no messages have been decoded. Select a connection observation to see what is known.":"Select an entry to inspect its metadata and any decoded contents."})]})})]}),e.jsxs("footer",{className:"tr-monitor-footer",children:[(Te||re||s)&&e.jsxs("span",{children:[s?"Connection interrupted":Te?Ne?"Continuous local monitoring":"Local capture":"Not monitoring"," · History in local memory"]}),e.jsxs("details",{children:[e.jsx("summary",{children:"Monitoring limits"}),e.jsxs("div",{children:[e.jsx("p",{children:"Plaintext IPv4 OTLP/gRPC only. HTTPS contents cannot be decoded. Traffic to the chosen addresses can come from any process, not only Claude."}),e.jsx("p",{children:"History covers the last 24 hours, up to 2,000 exports and a 32 MiB payload budget. When a limit is reached, the oldest messages are removed."}),e.jsxs("p",{children:["History stays in local memory. Restarting ccdeck or clearing messages removes it. Closing this modal does not stop capture or clear history; stopping monitoring preserves history. No capture file is written. ",ce?e.jsx(e.Fragment,{children:"Turn monitoring off in Settings → Radar."}):e.jsxs(e.Fragment,{children:["Use Stop monitoring",!Ne&&e.jsxs(e.Fragment,{children:[" and Ctrl+C in ",Ve]})," to stop capture."]})]}),t!=null&&t.bytes?e.jsxs("p",{children:["Captured transport bytes: ",t.bytes.toLocaleString(),". This is not a decoded-message count."]}):null,Ne&&(ce?e.jsx("p",{children:"Automatic monitoring is on: it starts with ccdeck and continues in the background. Turn it off in Settings → Radar. The in-memory history is cleared after a restart."}):e.jsx("p",{children:"Enabled monitoring resumes after a ccdeck restart; the in-memory history does not."})),Object.entries((t==null?void 0:t.issues)??{}).map(([d,V])=>e.jsxs("p",{children:[ln[d]??"An inspection limitation was observed."," (",V,")"]},d))]})]})]})]})}function uo({sessionFilter:t="all",onSessions:n}){const[s,r]=l.useState([]),[o,i]=l.useState(""),[p,u]=l.useState(""),[m,a]=l.useState(!1),[c,g]=l.useState(null),[h,v]=l.useState(""),[w,C]=l.useState(!1),S=l.useRef(0),R=async f=>{if(!f)return;const y=++S.current;u(""),a(!0),C(!1);try{if(f.size>10*1024*1024)throw new Error("Choose a file smaller than 10 MB.");const N=await f.text(),x=Hs(N);if(y!==S.current)return;n==null||n([...new Set(x.flatMap(k=>k.sessionIds))]),r(x),i(f.name),g(null),v(""),x.length||u("This file is empty. Choose a JSON or JSONL telemetry file.")}catch(N){y===S.current&&u(N instanceof Error?N.message:"Could not read this file.")}finally{y===S.current&&a(!1)}},P=s.filter(f=>(t==="all"||(t==="unidentified"?!f.sessionIds.length:f.sessionIds.includes(t)))&&(!h||f.raw.toLowerCase().includes(h.toLowerCase()))),_=P.slice(0,200),b=c===null?_[0]:P.find(f=>f.line===c);return e.jsxs("div",{className:"tr-file",children:[e.jsxs("div",{className:"tr-file-toolbar",children:[e.jsxs("div",{children:[e.jsx("h3",{children:"Inspect a telemetry file"}),e.jsx("p",{className:"tr-note",children:"Open a local JSON or JSONL file. It stays in your browser and is not uploaded."})]}),e.jsxs("label",{className:"btn tr-file-picker",children:[m?"Reading…":o?"Choose another file":"Open file",e.jsx("input",{type:"file",accept:".json,.jsonl,.ndjson,application/json","aria-label":"Open telemetry file",onChange:f=>{var y;R((y=f.target.files)==null?void 0:y[0]),f.target.value=""}})]})]}),p&&e.jsx("p",{className:"tr-capture-error",role:"alert",children:p}),e.jsxs("div",{className:"tr-workspace","data-empty":s.length===0,children:[e.jsxs("section",{className:"tr-feed","aria-label":"File records",children:[s.length>0&&e.jsxs("h3",{children:[o||"File records"," ",e.jsx("span",{className:"tr-count",children:P.length})]}),s.length>0&&e.jsx("input",{type:"search",className:"tr-input tr-search","aria-label":"Search file contents",placeholder:"Search contents…",value:h,onChange:f=>{v(f.target.value),g(null)}}),_.length?e.jsx("ul",{className:"tr-connections",children:_.map(f=>e.jsx("li",{children:e.jsxs("button",{className:"tr-message","aria-pressed":(b==null?void 0:b.line)===f.line,onClick:()=>{g(f.line),C(!1)},children:[e.jsxs("span",{className:"tr-event-top",children:[e.jsxs("span",{children:["Line ",f.line]}),e.jsx("span",{className:f.valid?"":"tr-tone-enabled",children:f.valid?"JSON":"Invalid JSON"})]}),e.jsx("strong",{children:f.label}),f.timestamp&&e.jsx("span",{children:f.timestamp}),e.jsx("span",{children:f.sessionIds.join(", ")||"Unidentified session"})]})},f.line))}):e.jsxs("div",{className:"tr-empty-capture",children:[e.jsx("h4",{children:s.length?"No matching records":"Open a telemetry file"}),e.jsx("p",{className:"tr-note",children:s.length?"Try another session or search.":"Choose Open file above to browse a JSON or JSONL file. Its records and original contents will appear here."})]}),P.length>_.length&&e.jsx("p",{className:"tr-note",children:"Showing the first 200 matching rows. Search to narrow the list."})]}),e.jsx("section",{className:"tr-inspector",hidden:!s.length,"aria-label":"File record contents",children:b?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"tr-feed-head",children:[e.jsxs("h3",{children:["Line ",b.line]}),e.jsx("button",{className:"btn",onClick:()=>{navigator.clipboard.writeText(b.raw).then(()=>C(!0),()=>u("Clipboard unavailable. Select the JSON and copy it manually."))},children:w?"Copied":"Copy JSON"})]}),e.jsx("p",{className:"tr-note",children:"Original file contents. This does not prove the record was sent or received."}),e.jsx("pre",{className:"tr-value",children:b.raw})]}):e.jsxs("div",{className:"tr-inspector-empty",children:[e.jsx("h3",{children:"Inspect a record"}),e.jsx("p",{className:"tr-note",children:"Select a row to read its original contents."})]})})]})]})}function fo({onClose:t,sessions:n=[]}){const s=Ks(t),r=Vs(t),{snapshot:o,failed:i,updateConfig:p}=Ws(),u=zs();return e.jsx("div",{className:"modal-backdrop",...r,role:"presentation",children:e.jsx("div",{className:"modal tr-modal",ref:s,role:"dialog","aria-modal":"true","aria-labelledby":"tr-title","aria-describedby":"tr-purpose",onClick:m=>m.stopPropagation(),children:e.jsx(ho,{snapshot:o,failed:i,captureState:u,sessions:n,onConfigChange:p,onClose:t})})})}function ho({snapshot:t,failed:n=!1,captureState:s,sessions:r=[],onConfigChange:o,onClose:i}){var b,f,y,N;const[p,u]=l.useState("monitor"),[m,a]=l.useState([]),[c,g]=l.useState("all"),h=["monitor","configuration","file"],v=x=>{var F;const k=Fs(x,h.indexOf(p),h.length);if(k.kind!=="select")return;x.preventDefault();const B=h[k.index];u(B),(F=document.getElementById(`tr-tab-${B}`))==null||F.focus()},w=[...((b=t==null?void 0:t.config)==null?void 0:b.variables)??[],...(t==null?void 0:t.environment)??[]],C=$n(w),S=Bs(w),R=(f=t==null?void 0:t.config)==null?void 0:f.sources.some(x=>x.status==="unavailable"),P=n?[]:Bn(t),_=new Map(r.map(x=>[x.id,x.label]));for(const x of((y=s==null?void 0:s.capture)==null?void 0:y.events)??[])for(const k of x.sessionIds??[])_.has(k)||_.set(k,"Session");for(const x of m)_.has(x)||_.set(x,"Session");return e.jsxs("div",{className:"tr-body",children:[e.jsxs("header",{className:"modal-head tr-header",children:[e.jsxs("div",{className:"tr-identity",children:[e.jsx(Et,{kind:"radar"}),e.jsxs("div",{children:[e.jsxs("div",{className:"modal-title",children:[e.jsx("span",{className:"modal-tool-name",id:"tr-title",children:"Telemetry Radar"}),e.jsx("span",{className:"tr-beta",title:"Beta feature — still being tested and improved.",children:"Beta"})]}),e.jsx("p",{id:"tr-purpose",children:"Inspect Claude Code’s collector traffic."})]})]}),e.jsxs("div",{className:"tr-navigation",children:[e.jsxs("div",{className:"tr-tabs",role:"tablist","aria-label":"Radar views",onKeyDown:v,children:[e.jsx("button",{id:"tr-tab-monitor",className:"tr-tab",role:"tab","aria-selected":p==="monitor","aria-controls":"tr-panel-monitor",tabIndex:p==="monitor"?0:-1,onClick:()=>u("monitor"),children:"Monitor"}),e.jsx("button",{id:"tr-tab-configuration",className:"tr-tab",role:"tab","aria-selected":p==="configuration","aria-controls":"tr-panel-configuration",tabIndex:p==="configuration"?0:-1,onClick:()=>u("configuration"),children:"Configuration"}),e.jsx("button",{id:"tr-tab-file",className:"tr-tab",role:"tab","aria-selected":p==="file","aria-controls":"tr-panel-file",tabIndex:p==="file"?0:-1,onClick:()=>u("file"),children:"File"})]}),e.jsxs("label",{className:"tr-session-filter",hidden:!_.size&&c==="all"&&!((N=s==null?void 0:s.capture)!=null&&N.events.length),children:["Session",e.jsxs(Yt,{value:c,onChange:x=>g(x.target.value),"aria-label":"Session",children:[e.jsx("option",{value:"all",children:"All sessions"}),[..._].map(([x,k])=>e.jsxs("option",{value:x,children:[k," · ",x.slice(0,8)]},x)),e.jsx("option",{value:"unidentified",children:"Unidentified session"})]})]}),e.jsxs("details",{className:"tr-help",children:[e.jsxs("summary",{children:[e.jsx(Et,{kind:"info"}),e.jsx("span",{className:"tr-help-label",children:"About Radar"})]}),e.jsxs("div",{children:[e.jsx("h3",{children:"What does Radar show?"}),e.jsx("p",{children:"See what Claude Code sends to your telemetry collectors. Destinations can be configured by you or your organization."}),e.jsx("p",{children:"Radar inspects configured OpenTelemetry exports, including prompts or responses when enabled and captured. It does not show everything Claude knows about you, ordinary AI requests, or Anthropic’s separate service telemetry."}),e.jsx("p",{children:"An address does not identify who owns a collector or who can access its data. Encrypted connections can be observed, but their contents cannot be decoded here."}),e.jsx("a",{href:"https://code.claude.com/docs/en/monitoring-usage",target:"_blank",rel:"noreferrer",children:"Claude Code telemetry documentation"})]})]})]}),i&&e.jsx("button",{className:"glyph-btn tr-header-close",onClick:i,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]}),e.jsx("div",{className:"tr-page",id:"tr-panel-monitor",role:"tabpanel","aria-labelledby":"tr-tab-monitor",hidden:p!=="monitor",children:s?e.jsx(co,{...s,radar:n&&t?{...t,status:"unavailable"}:t,sessionFilter:c,sessions:r}):e.jsx("p",{className:"tr-empty",children:"Reading monitor status…"})}),e.jsxs("div",{className:"tr-page tr-configuration-page",id:"tr-panel-configuration",role:"tabpanel","aria-labelledby":"tr-tab-configuration",hidden:p!=="configuration",children:[e.jsxs("div",{className:"tr-summary",children:[e.jsxs("div",{className:"tr-summary-state",children:[e.jsx("span",{className:`tr-state ${n||!t||R?"tr-tone-unknown":S.startsWith("Enabled")?"tr-tone-enabled":"tr-tone-unknown"}`,children:n?"Configuration unavailable":t?R?"Configuration incomplete":S==="Unknown"?"Configuration unknown":S:"Reading settings…"}),e.jsx("span",{className:"tr-note",children:C.length?`${C.length} configured destination${C.length===1?"":"s"}`:"No destination found in the settings files read. Telemetry may still be running."})]}),C.length>0&&e.jsx("div",{className:"tr-endpoints",children:C.map(x=>e.jsx("code",{children:x},x))}),!C.length&&P.length>0&&e.jsxs("div",{className:"tr-observed-summary",children:[e.jsx("span",{className:"tr-state",children:"Claude connections observed"}),e.jsx("div",{className:"tr-endpoints",children:P.map(x=>e.jsx("code",{children:x},x))}),e.jsx("p",{className:"tr-note",children:"These are active connections, not confirmed telemetry messages. Choose an observed address below to inspect its traffic."})]})]}),t?e.jsx(po,{snapshot:t,stale:n,onConfigChange:o,sessionLabel:c==="all"?void 0:_.get(c)??c}):e.jsx("p",{className:"tr-empty",children:n?"Could not read settings. Sampling will retry.":"Reading local settings…"})]}),e.jsx("div",{className:"tr-page",id:"tr-panel-file",role:"tabpanel","aria-labelledby":"tr-tab-file",hidden:p!=="file",children:e.jsx(uo,{onSessions:a,sessionFilter:c})})]})}const Kn="Set in the environment this Claude process started with. Change it where the session is launched.";function po({snapshot:t,sessionLabel:n,stale:s=!1,onConfigChange:r}){var N,x,k,B,F;const[o,i]=l.useState(null),[p,u]=l.useState(null),m=l.useRef(null),[a,c]=l.useState(""),[g,h]=l.useState(""),v=(N=o??t.config)==null?void 0:N.sources.some(j=>j.status==="unavailable");l.useEffect(()=>{i(null)},[t.config]);const w=[...((x=o??t.config)==null?void 0:x.variables)??[],...t.environment??[]],C=t.uninspected??0,S=async(j,L)=>{if(!Vn(m.current)||s)return;m.current=j,u(j),h(""),c("");const A=new AbortController,O=setTimeout(()=>A.abort(),2e4);try{const M=await fetch("/api/system/traffic-radar/configuration",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:j,enabled:L}),signal:A.signal}),X=await M.json();if(!M.ok||!X.ok)throw new Error(X.error??"Could not save this setting.");i(X.config),r==null||r(X.config),c("Saved to user settings. Start a new Claude session to apply the change.")}catch(M){h(A.signal.aborted?"Saving timed out. Check the current setting and try again.":M instanceof Error?M.message:"Could not save this setting. Try again.")}finally{clearTimeout(O),m.current=null,u(null)}},R=w.filter(j=>j.key.endsWith("ENDPOINT")),P={CLAUDE_CODE_ENABLE_TELEMETRY:"Telemetry",OTEL_LOG_USER_PROMPTS:"Your prompts",OTEL_LOG_ASSISTANT_RESPONSES:"Claude responses",OTEL_LOG_TOOL_DETAILS:"Tool details",OTEL_LOG_TOOL_CONTENT:"Tool contents",OTEL_LOG_RAW_API_BODIES:"Full API bodies",OTEL_LOG_MANAGED_SETTINGS:"Managed settings",CLAUDE_CODE_ENHANCED_TELEMETRY_BETA:"Enhanced telemetry",ENABLE_ENHANCED_TELEMETRY_BETA:"Enhanced telemetry"},_=Object.keys(P),b=j=>_.includes(j)?_.indexOf(j):_.length,f=(((k=o??t.config)==null?void 0:k.unsetFlags)??[]).map(j=>({key:j,value:"Not set",source:"User settings",unset:!0,editable:!0})),y=[...w.filter(j=>j.key.startsWith("OTEL_LOG_")||j.key.includes("ENABLE")||j.key.includes("TELEMETRY_BETA")),...f].sort((j,L)=>b(j.key)-b(L.key));return e.jsxs("section",{className:"tr-config","aria-label":"Telemetry configuration",children:[e.jsx("h3",{children:"What Claude is configured to send"}),s&&e.jsx("p",{className:"tr-warning",role:"status",children:"Last successfully read settings. Current configuration could not be verified."}),v&&e.jsx("p",{className:"tr-warning",role:"status",children:"Some settings sources could not be read. Editing is unavailable until they can be verified."}),e.jsx("p",{className:"tr-note",children:(B=t.environment)!=null&&B.length?"Read from local Claude settings and the launch environment of running Claude processes. A running session’s effective values can still differ.":"Read from local Claude settings. The effective environment of a running session is not verified."}),C>0&&e.jsx("p",{className:"tr-note",children:`${C} Claude ${C===1?"process":"processes"} could not be inspected, such as one run by another user. ${C===1?"Its":"Their"} connections and launch environment are not shown.`}),n&&e.jsxs("p",{className:"tr-note",children:["Selected session: ",n,". These shared settings are evidence; this session’s runtime values are unverified."]}),e.jsx("h4",{children:"Destinations"}),R.length?e.jsx("ul",{className:"tr-destinations",children:R.map(j=>e.jsxs("li",{children:[e.jsx("code",{children:j.value}),e.jsxs("span",{children:[j.source," · ",j.key]})]},`${j.source}:${j.key}`))}):e.jsx("p",{className:"tr-note",children:"No destination found in the sources read. This does not mean telemetry is off."}),e.jsx("h4",{children:"Telemetry and content"}),e.jsx("p",{className:"tr-note",children:"Controls save shared user settings for new Claude sessions. Organization and managed flags require an administrator."}),a&&e.jsx("p",{className:"tr-note",role:"status",children:a}),g&&e.jsx("p",{className:"tr-warning",role:"alert",children:g}),y.length?e.jsx("dl",{className:"tr-variables tr-flags",children:y.map(j=>{const L=j.value.startsWith("Enabled"),A=L||j.value==="Disabled"||j.unset,O=Fn(p,j.key),M=j.unset?"Not in any settings file":j.source,X=`${P[j.key]??j.key} (${j.unset?"not set":j.source})`,Z=j.launch===!0,oe=!Z&&(s||v||j.editable!==!0&&!j.blockedReason),U=!Z&&j.editable!==!0&&!oe,ae=(Q,te=j.blockedReason)=>e.jsx("button",{type:"button",className:"switch",role:"switch","data-tone":"warn","aria-checked":L,"aria-label":X,...Q?{disabled:!0,title:te}:{"aria-busy":O.busy,disabled:O.disabled,title:`Turn ${L?"off":"on"} for new Claude sessions`,onClick:()=>void S(j.key,!L)},children:e.jsx("span",{className:"switch-knob"})});return e.jsxs("div",{children:[e.jsxs("dt",{children:[e.jsx("strong",{children:P[j.key]??j.key}),e.jsx("code",{children:j.key}),e.jsx("span",{children:M}),j.blockedReason&&!v&&e.jsx("span",{children:j.blockedReason})]}),e.jsxs("dd",{className:"tr-flag-control",children:[e.jsxs("span",{className:"tr-flag-value",children:[e.jsx("span",{className:`tr-state ${L?"tr-tone-enabled":"tr-tone-unknown"}`,children:j.value}),j.rawValue!==void 0&&e.jsx("code",{className:"tr-raw-flag",children:j.rawValue})]}),e.jsxs("span",{className:"tr-flag-action",children:[Z?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tr-control-note",title:Kn,children:"Read-only"}),A&&ae(!0,Kn)]}):oe?e.jsx("span",{className:"tr-control-note",title:j.blockedReason,children:"Unavailable"}):U?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"tr-control-note",title:j.blockedReason,children:"Managed"}),A&&ae(!0)]}):A?ae(!1):e.jsx("span",{className:"tr-unknown-actions",children:[!0,!1].map(Q=>e.jsx("button",{type:"button",className:"btn","aria-label":`${Q?"Enable":"Disable"} ${X}`,"aria-busy":O.busy,disabled:O.disabled,onClick:()=>void S(j.key,Q),children:Q?"Enable":"Disable"},String(Q)))}),p===j.key&&e.jsx("span",{className:"tr-control-note",role:"status",children:"Saving…"})]})]})]},`${j.source}:${j.key}`)})}):e.jsx("p",{className:"tr-note",children:"No telemetry flags found in the settings read."}),!R.length&&t.connections.length>0&&e.jsxs("details",{className:"tr-details",children:[e.jsxs("summary",{children:["Observed Claude connections (",t.connections.length,")"]}),e.jsx("ul",{className:"tr-live-connections",children:t.connections.map(j=>e.jsxs("li",{children:[e.jsx("code",{children:j.destination}),e.jsxs("span",{children:[j.connecting&&!s&&j.active!==null?e.jsx("span",{className:"tr-attempt",children:cn(j)}):cn(j,s)," · PID ",j.pid," · ",j.workspace??"Workspace unknown"]})]},`${j.pid}:${j.destination}`))}),e.jsx("p",{className:"tr-note",children:"A running process can keep previously loaded settings after a settings file disappears. Connections alone do not identify telemetry or prove a message was sent."})]}),e.jsxs("details",{className:"tr-details",children:[e.jsx("summary",{children:"All variables and sources"}),e.jsx("dl",{className:"tr-variables",children:w.map(j=>e.jsxs("div",{children:[e.jsxs("dt",{children:[e.jsx("code",{children:j.key}),e.jsx("span",{children:j.source})]}),e.jsx("dd",{children:j.value})]},`${j.source}:${j.key}`))}),e.jsx("ul",{className:"tr-sources",children:(F=t.config)==null?void 0:F.sources.map(j=>e.jsxs("li",{children:[e.jsx("span",{children:j.name}),e.jsx("span",{children:j.status==="read"?"Read":j.status==="absent"?"Not found":"Unavailable"})]},j.name))}),e.jsx("p",{className:"tr-note",children:"Endpoint credentials and headers are hidden. Settings can differ from an already running process."})]})]})}export{po as Configuration,ho as TrafficRadarView,fo as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{z as W,B as _,a as c,s as re,C as le,D as L,j as e,E as b,M as q,F as x,G as J,h as ie,i as ce,H as de,J as ue,R as he,g as I,K as me,L as ge}from"./app-BW3NYUYB.js";function pe(t){return!t.answer||t.answer.range!==t.want?{phase:"busy",stale:!1}:t.answer.ok?{phase:t.answer.days>0?"chart":"empty",stale:t.loading}:{phase:"error",stale:t.loading}}function K(t){const s=new Map;for(const n of t)for(const o of n.agents??[]){if(!o||typeof o.agent!="string"||o.agent==="")continue;const l=s.get(o.agent)??{id:o.agent,cost:0,tokens:0};l.cost+=Number.isFinite(o.totalCost)?o.totalCost:0,l.tokens+=Number.isFinite(o.totalTokens)?o.totalTokens:0,s.set(o.agent,l)}return[...s.values()].sort((n,o)=>o.cost-n.cost||n.id.localeCompare(o.id))}function xe(t){const s=K([{agents:t}]);return s.length<2?null:s.map(n=>`${W(n.id)} ${_(n.cost)}`).join(" · ")}function H(t){switch(t.toLowerCase()){case"claude":return"var(--model-opus)";case"codex":return"var(--model-codex)";case"gemini":return"var(--model-gemini)";case"copilot":return"var(--model-haiku)";default:return"var(--model-other)"}}function fe(t,s){if(!(s>0)||!(t>0))return"0%";const n=t/s*100;return n<.1?"<0.1%":`${n.toFixed(1)}%`}const h=t=>typeof t=="number"&&Number.isFinite(t)?t:0,$=t=>typeof t=="string"?t:"",z=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"):[];function je(t){const s=t??{};return{modelName:$(s.modelName),cost:h(s.cost),...typeof s.missingPricing=="boolean"?{missingPricing:s.missingPricing}:{},...typeof s.storedCost=="number"&&Number.isFinite(s.storedCost)&&s.storedCost>=0?{storedCost:Math.min(s.storedCost,Math.max(0,h(s.cost)))}:{},inputTokens:h(s.inputTokens),outputTokens:h(s.outputTokens),cacheCreationTokens:h(s.cacheCreationTokens),cacheReadTokens:h(s.cacheReadTokens)}}function Ne(t){const s=t??{},n=Array.isArray(s.agents)?s.agents.map(o=>{const l=o??{};return{agent:$(l.agent),totalCost:h(l.totalCost),totalTokens:h(l.totalTokens)}}):void 0;return{period:$(s.period),totalCost:h(s.totalCost),totalTokens:h(s.totalTokens),inputTokens:h(s.inputTokens),outputTokens:h(s.outputTokens),cacheCreationTokens:h(s.cacheCreationTokens),cacheReadTokens:h(s.cacheReadTokens),modelsUsed:z(s.modelsUsed),modelBreakdowns:Array.isArray(s.modelBreakdowns)?s.modelBreakdowns.map(je):[],...n?{agents:n}:{},...s.metadata&&typeof s.metadata=="object"?{metadata:{agents:z(s.metadata.agents)}}:{}}}function ke(t){const s=t??{};return{...s,ok:s.ok===!0,days:Array.isArray(s.days)?s.days.map(Ne):void 0}}function R(t){const s=t.toLowerCase();return s.includes("opus")?"var(--model-opus)":s.includes("sonnet")?"var(--model-sonnet)":s.includes("haiku")?"var(--model-haiku)":s.includes("gpt-5")||s.includes("gpt5")?"var(--model-gpt5)":s.includes("gpt")?"var(--model-gpt)":s.includes("gemini")?"var(--model-gemini)":s.includes("codex")?"var(--model-codex)":s.includes("fable")||s.includes("mythos")?"var(--model-fable)":"var(--model-other)"}function ye(t){let s=0,n=0,o=0,l=0;const r=new Map,i=new Set;let p=null;for(const m of t){s+=m.totalCost,n+=m.totalTokens,o+=m.inputTokens+m.outputTokens,l+=m.cacheReadTokens;for(const d of m.modelBreakdowns)r.set(d.modelName,(r.get(d.modelName)??0)+d.cost),d.missingPricing&&i.add(d.modelName),d.storedCost!==void 0&&(p=(p??0)+d.storedCost)}return{totalCost:s,totalTok:n,inOut:o,cacheRead:l,modelCosts:r,missingModels:i,storedCost:p}}function be(t){return Array.from(t.entries()).sort((s,n)=>n[1]-s[1])}function V(t){return t.slice().sort((s,n)=>n.cost-s.cost)}function T(t,s){return s>0?t/s*100:0}function ve(t){var n,o;return xe(t.agents)??((o=(n=t.metadata)==null?void 0:n.agents)!=null&&o.length?t.metadata.agents.join(" · "):null)}function Ce(t){return t<=14?1:t<=31?2:7}function we(){let t=0;return{begin(){const s=++t;return()=>s===t},cancel(){t++}}}function Te(t){const[s,n]=c.useState(null),[o,l]=c.useState(!1),r=c.useState(we)[0],i=c.useRef(!1),p=(m=!1)=>{if(m&&!re(i.current))return;const d=r.begin();i.current=m;const j=t;l(!0);const u=`/api/ccusage?since=${le(j)}${m?"&refresh=1":""}`;fetch(u).then(N=>N.json()).then(N=>{d()&&n({range:j,resp:ke(N)})}).catch(()=>{d()&&n({range:j,resp:{ok:!1,reason:"unreachable"}})}).finally(()=>{d()&&(i.current=!1,l(!1))})};return c.useEffect(()=>(p(!1),()=>r.cancel()),[t]),{landed:s,loading:o,reload:()=>p(!0)}}function Re({selectedDay:t}){const s=ve(t),n=t.modelBreakdowns.some(r=>r.missingPricing),o=t.modelBreakdowns.filter(r=>r.storedCost!==void 0),l=L(o.length?o.reduce((r,i)=>r+i.storedCost,0):null,t.totalCost);return e.jsxs("div",{className:"uh-detail",children:[e.jsxs("div",{className:"uh-detail-head",children:[e.jsx("span",{className:"uh-detail-date",children:t.period}),e.jsx("span",{className:"uh-detail-cost",children:b(t.totalCost,n)}),s&&e.jsx("span",{className:"uh-detail-agents",title:s,children:s})]}),n&&e.jsx("p",{className:"uh-cost-note",children:q}),l&&e.jsx("p",{className:"uh-cost-note",children:l}),e.jsxs("div",{className:"uh-detail-mini",children:[e.jsx(C,{label:"input",val:x(t.inputTokens)}),e.jsx(C,{label:"output",val:x(t.outputTokens)}),e.jsx(C,{label:"cache write",val:x(t.cacheCreationTokens)}),e.jsx(C,{label:"cache read",val:x(t.cacheReadTokens)})]}),e.jsx("div",{className:"uh-detail-models",children:V(t.modelBreakdowns).map(r=>{const i=T(r.cost,t.totalCost);return e.jsxs("div",{className:"uh-model-row",title:r.modelName,children:[e.jsxs("span",{className:"uh-model-name",children:[e.jsx("span",{className:"uh-legend-dot",style:{background:R(r.modelName)}}),e.jsx("span",{className:"uh-model-label",children:J(r.modelName)})]}),e.jsx("span",{className:"uh-model-bar",children:e.jsx("span",{className:"uh-model-bar-fill",style:{width:`${i}%`,background:R(r.modelName)}})}),e.jsx("span",{className:"uh-model-cost",children:b(r.cost,r.missingPricing)})]},r.modelName)})})]})}function C({label:t,val:s}){return e.jsxs("div",{className:"uh-ministat",children:[e.jsx("span",{className:"uh-ministat-val",children:s}),e.jsx("span",{className:"uh-ministat-label",children:t})]})}const Me=[7,14,30,90];function Le({onClose:t,providers:s}){var U;const[n,o]=c.useState(30),[l,r]=c.useState(null),{landed:i,loading:p,reload:m}=Te(n),d=c.useRef(null),j=ie(t,{focusRef:d}),P=ce(t),u=pe({loading:p,want:n,answer:i&&{range:i.range,ok:i.resp.ok===!0,days:((U=i.resp.days)==null?void 0:U.length)??0}}),[N,Q]=c.useState(()=>typeof document<"u"&&document.hidden);c.useEffect(()=>{if(u.phase!=="busy")return;const a=()=>Q(document.hidden);return a(),document.addEventListener("visibilitychange",a),()=>document.removeEventListener("visibilitychange",a)},[u.phase]);const g=u.phase==="chart"?i.resp.days??[]:[],B=c.useRef(null),X=de(u.phase!=="error",B),Y=c.useMemo(()=>g.reduce((a,f)=>Math.max(a,f.totalCost),0),[g]),A=c.useRef(null);c.useLayoutEffect(()=>{const a=A.current;a&&(a.scrollLeft=a.scrollWidth)},[g]);const{totalCost:k,totalTok:Z,inOut:D,cacheRead:ee,modelCosts:E,missingModels:M,storedCost:F}=c.useMemo(()=>ye(g),[g]),se=c.useMemo(()=>be(E),[E]),v=c.useMemo(()=>K(g),[g]),te=v.length>1,O=l?g.find(a=>a.period===l)??null:null,ae=Ce(g.length);return e.jsx("div",{className:"modal-backdrop",...P,role:"presentation",children:e.jsxs("div",{ref:j,className:"modal uh-modal",onClick:a=>a.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Usage history",children:[e.jsxs("header",{className:"uh-head",children:[e.jsxs("div",{className:"uh-titlewrap",children:[e.jsx("div",{className:"uh-title",children:"Usage history"}),e.jsx("div",{className:"uh-sub",children:u.stale?"running ccusage…":ue(s,v.map(a=>a.id))})]}),e.jsx("div",{className:"uh-range",role:"group","aria-label":"Range",children:Me.map(a=>e.jsxs("button",{type:"button","aria-pressed":n===a,className:"uh-range-btn",onClick:()=>{o(a),r(null)},children:[a,"d"]},a))}),e.jsx("button",{ref:B,className:"glyph-btn uh-reload",onClick:m,...I(p),title:"Re-run ccusage","aria-label":"Reload",children:p?"…":e.jsx(he,{})}),e.jsx("button",{ref:d,className:"glyph-btn uh-close",onClick:t,"aria-label":"Close",children:"×"})]}),u.phase==="busy"?e.jsxs("div",{className:"uh-status uh-status-wait",role:"status","aria-label":"Reading usage history","aria-busy":"true","data-paused":N||void 0,children:[e.jsxs("span",{className:"uh-wait-word",children:[e.jsxs("svg",{className:"uh-reading-art",viewBox:"0 0 240 96",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M25 24v-7a4 4 0 0 1 4-4h28a4 4 0 0 1 4 4v43"}),e.jsx("rect",{x:"17",y:"24",width:"36",height:"51",rx:"4"}),e.jsx("path",{d:"M25 36h19M25 44h19M25 52h13M25 64h7"}),e.jsx("path",{className:"uh-reading-link",d:"M69 49h59"}),e.jsxs("g",{className:"uh-reading-packets",children:[e.jsx("rect",{x:"76",y:"46",width:"6",height:"6",rx:"1.5"}),e.jsx("rect",{x:"76",y:"46",width:"6",height:"6",rx:"1.5"}),e.jsx("rect",{x:"76",y:"46",width:"6",height:"6",rx:"1.5"})]}),e.jsx("rect",{x:"145",y:"18",width:"76",height:"57",rx:"5"}),e.jsx("path",{d:"M154 28h21M154 64h57M154 38v26M163 39h47M163 49h47"}),e.jsx("circle",{cx:"209",cy:"28",r:"2"})]}),e.jsx("strong",{className:"uh-reading-title",children:"Reading usage history"}),e.jsx("span",{className:"uh-reading-note",children:"Gathering costs and tokens from local logs…"}),!i&&e.jsx("span",{className:"uh-reading-hint",children:"The first run may download ccusage."})]}),e.jsx("span",{className:"uh-wait-axis","aria-hidden":!0})]}):u.phase==="error"?e.jsxs("div",{className:"uh-status uh-err",title:ge(i.resp)||void 0,children:[me(i.resp,"ccusage did not report usage"),e.jsx("div",{children:e.jsx("button",{className:"btn uh-retry",onClick:()=>{X(),m()},...I(p),children:p?"trying…":"Try again"})})]}):u.phase==="empty"?e.jsx("div",{className:`uh-status${u.stale?" uh-stale":""}`,"aria-busy":u.stale||void 0,children:"no usage in this range"}):e.jsxs("div",{className:u.stale?"uh-stale":void 0,"aria-busy":u.stale||void 0,children:[e.jsxs("div",{className:"uh-totals",children:[e.jsx(w,{label:"total cost",val:b(k,M.size>0),accent:!0}),e.jsx(w,{label:"tokens",val:x(Z)}),e.jsx(w,{label:"input+output",val:x(D)}),e.jsx(w,{label:"cache reads",val:x(ee)})]}),M.size>0&&e.jsx("p",{className:"uh-cost-note",children:q}),L(F,k)&&e.jsx("p",{className:"uh-cost-note",children:L(F,k)}),te&&e.jsxs("div",{className:"uh-agents",role:"group","aria-label":"Cost by CLI",children:[e.jsx("div",{className:"uh-agent-bar","aria-hidden":"true",children:v.map(a=>e.jsx("span",{className:"uh-agent-seg",style:{width:`${T(a.cost,k)}%`,background:H(a.id)}},a.id))}),e.jsx("div",{className:"uh-agent-keys",children:v.map(a=>e.jsxs("span",{className:"uh-agent-key",title:`${a.id} · ${x(a.tokens)} tokens`,children:[e.jsx("span",{className:"uh-legend-dot",style:{background:H(a.id)}}),W(a.id),e.jsx("span",{className:"uh-agent-cost",children:_(a.cost)}),e.jsx("span",{className:"uh-agent-share",children:fe(a.cost,k)})]},a.id))})]}),e.jsx("div",{ref:A,className:"uh-chart",role:"group","aria-label":"Daily cost by model",children:g.map((a,f)=>{const ne=T(a.totalCost,Y),S=a.period===l,G=`${a.period}, ${b(a.totalCost,a.modelBreakdowns.some(y=>y.missingPricing))}`;return e.jsxs("button",{className:`uh-bar-col${S?" sel":""}`,onClick:()=>r(S?null:a.period),"aria-pressed":S,"aria-label":G,title:G,style:{flexBasis:`${100/g.length}%`,"--uh-i":f,"--uh-step":`${Math.min(10,200/Math.max(g.length,1))}ms`},children:[e.jsx("div",{className:"uh-bar",style:{height:`${Math.max(ne,a.totalCost>0?2:0)}%`},children:V(a.modelBreakdowns).map(y=>{const oe=T(y.cost,a.totalCost);return e.jsx("div",{className:"uh-bar-seg",style:{height:`${oe}%`,background:R(y.modelName)}},y.modelName)})}),(g.length-1-f)%ae===0&&e.jsx("span",{className:"uh-bar-label",children:a.period.slice(5)})]},a.period)})}),e.jsx("div",{className:"uh-legend",children:se.map(([a,f])=>e.jsxs("span",{className:"uh-legend-item",title:a,children:[e.jsx("span",{className:"uh-legend-dot",style:{background:R(a)}}),J(a)," ",e.jsx("span",{className:"uh-legend-cost",children:b(f,M.has(a))})]},a))}),O&&e.jsx(Re,{selectedDay:O})]})]})})}function w({label:t,val:s,accent:n}){return e.jsxs("div",{className:"uh-stat",children:[e.jsx("span",{className:`uh-stat-val${n?" accent":""}`,children:s}),e.jsx("span",{className:"uh-stat-label",children:t})]})}export{Le as default};
|
|
1
|
+
import{G as V,H as W,b as c,s as re,J as le,K as L,j as e,L as b,M as _,N as x,O as q,n as ie,o as ce,P as de,Q as ue,R as he,d as I,S as me,V as ge}from"./app-DhGvSH7o.js";function pe(t){return!t.answer||t.answer.range!==t.want?{phase:"busy",stale:!1}:t.answer.ok?{phase:t.answer.days>0?"chart":"empty",stale:t.loading}:{phase:"error",stale:t.loading}}function J(t){const s=new Map;for(const n of t)for(const o of n.agents??[]){if(!o||typeof o.agent!="string"||o.agent==="")continue;const l=s.get(o.agent)??{id:o.agent,cost:0,tokens:0};l.cost+=Number.isFinite(o.totalCost)?o.totalCost:0,l.tokens+=Number.isFinite(o.totalTokens)?o.totalTokens:0,s.set(o.agent,l)}return[...s.values()].sort((n,o)=>o.cost-n.cost||n.id.localeCompare(o.id))}function xe(t){const s=J([{agents:t}]);return s.length<2?null:s.map(n=>`${V(n.id)} ${W(n.cost)}`).join(" · ")}function H(t){switch(t.toLowerCase()){case"claude":return"var(--model-opus)";case"codex":return"var(--model-codex)";case"gemini":return"var(--model-gemini)";case"copilot":return"var(--model-haiku)";default:return"var(--model-other)"}}function fe(t,s){if(!(s>0)||!(t>0))return"0%";const n=t/s*100;return n<.1?"<0.1%":`${n.toFixed(1)}%`}const h=t=>typeof t=="number"&&Number.isFinite(t)?t:0,$=t=>typeof t=="string"?t:"",z=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"):[];function je(t){const s=t??{};return{modelName:$(s.modelName),cost:h(s.cost),...typeof s.missingPricing=="boolean"?{missingPricing:s.missingPricing}:{},...typeof s.storedCost=="number"&&Number.isFinite(s.storedCost)&&s.storedCost>=0?{storedCost:Math.min(s.storedCost,Math.max(0,h(s.cost)))}:{},inputTokens:h(s.inputTokens),outputTokens:h(s.outputTokens),cacheCreationTokens:h(s.cacheCreationTokens),cacheReadTokens:h(s.cacheReadTokens)}}function Ne(t){const s=t??{},n=Array.isArray(s.agents)?s.agents.map(o=>{const l=o??{};return{agent:$(l.agent),totalCost:h(l.totalCost),totalTokens:h(l.totalTokens)}}):void 0;return{period:$(s.period),totalCost:h(s.totalCost),totalTokens:h(s.totalTokens),inputTokens:h(s.inputTokens),outputTokens:h(s.outputTokens),cacheCreationTokens:h(s.cacheCreationTokens),cacheReadTokens:h(s.cacheReadTokens),modelsUsed:z(s.modelsUsed),modelBreakdowns:Array.isArray(s.modelBreakdowns)?s.modelBreakdowns.map(je):[],...n?{agents:n}:{},...s.metadata&&typeof s.metadata=="object"?{metadata:{agents:z(s.metadata.agents)}}:{}}}function ke(t){const s=t??{};return{...s,ok:s.ok===!0,days:Array.isArray(s.days)?s.days.map(Ne):void 0}}function R(t){const s=t.toLowerCase();return s.includes("opus")?"var(--model-opus)":s.includes("sonnet")?"var(--model-sonnet)":s.includes("haiku")?"var(--model-haiku)":s.includes("gpt-5")||s.includes("gpt5")?"var(--model-gpt5)":s.includes("gpt")?"var(--model-gpt)":s.includes("gemini")?"var(--model-gemini)":s.includes("codex")?"var(--model-codex)":s.includes("fable")||s.includes("mythos")?"var(--model-fable)":"var(--model-other)"}function ye(t){let s=0,n=0,o=0,l=0;const r=new Map,i=new Set;let p=null;for(const m of t){s+=m.totalCost,n+=m.totalTokens,o+=m.inputTokens+m.outputTokens,l+=m.cacheReadTokens;for(const d of m.modelBreakdowns)r.set(d.modelName,(r.get(d.modelName)??0)+d.cost),d.missingPricing&&i.add(d.modelName),d.storedCost!==void 0&&(p=(p??0)+d.storedCost)}return{totalCost:s,totalTok:n,inOut:o,cacheRead:l,modelCosts:r,missingModels:i,storedCost:p}}function be(t){return Array.from(t.entries()).sort((s,n)=>n[1]-s[1])}function K(t){return t.slice().sort((s,n)=>n.cost-s.cost)}function T(t,s){return s>0?t/s*100:0}function ve(t){var n,o;return xe(t.agents)??((o=(n=t.metadata)==null?void 0:n.agents)!=null&&o.length?t.metadata.agents.join(" · "):null)}function Ce(t){return t<=14?1:t<=31?2:7}function we(){let t=0;return{begin(){const s=++t;return()=>s===t},cancel(){t++}}}function Te(t){const[s,n]=c.useState(null),[o,l]=c.useState(!1),r=c.useState(we)[0],i=c.useRef(!1),p=(m=!1)=>{if(m&&!re(i.current))return;const d=r.begin();i.current=m;const j=t;l(!0);const u=`/api/ccusage?since=${le(j)}${m?"&refresh=1":""}`;fetch(u).then(N=>N.json()).then(N=>{d()&&n({range:j,resp:ke(N)})}).catch(()=>{d()&&n({range:j,resp:{ok:!1,reason:"unreachable"}})}).finally(()=>{d()&&(i.current=!1,l(!1))})};return c.useEffect(()=>(p(!1),()=>r.cancel()),[t]),{landed:s,loading:o,reload:()=>p(!0)}}function Re({selectedDay:t}){const s=ve(t),n=t.modelBreakdowns.some(r=>r.missingPricing),o=t.modelBreakdowns.filter(r=>r.storedCost!==void 0),l=L(o.length?o.reduce((r,i)=>r+i.storedCost,0):null,t.totalCost);return e.jsxs("div",{className:"uh-detail",children:[e.jsxs("div",{className:"uh-detail-head",children:[e.jsx("span",{className:"uh-detail-date",children:t.period}),e.jsx("span",{className:"uh-detail-cost",children:b(t.totalCost,n)}),s&&e.jsx("span",{className:"uh-detail-agents",title:s,children:s})]}),n&&e.jsx("p",{className:"uh-cost-note",children:_}),l&&e.jsx("p",{className:"uh-cost-note",children:l}),e.jsxs("div",{className:"uh-detail-mini",children:[e.jsx(C,{label:"input",val:x(t.inputTokens)}),e.jsx(C,{label:"output",val:x(t.outputTokens)}),e.jsx(C,{label:"cache write",val:x(t.cacheCreationTokens)}),e.jsx(C,{label:"cache read",val:x(t.cacheReadTokens)})]}),e.jsx("div",{className:"uh-detail-models",children:K(t.modelBreakdowns).map(r=>{const i=T(r.cost,t.totalCost);return e.jsxs("div",{className:"uh-model-row",title:r.modelName,children:[e.jsxs("span",{className:"uh-model-name",children:[e.jsx("span",{className:"uh-legend-dot",style:{background:R(r.modelName)}}),e.jsx("span",{className:"uh-model-label",children:q(r.modelName)})]}),e.jsx("span",{className:"uh-model-bar",children:e.jsx("span",{className:"uh-model-bar-fill",style:{width:`${i}%`,background:R(r.modelName)}})}),e.jsx("span",{className:"uh-model-cost",children:b(r.cost,r.missingPricing)})]},r.modelName)})})]})}function C({label:t,val:s}){return e.jsxs("div",{className:"uh-ministat",children:[e.jsx("span",{className:"uh-ministat-val",children:s}),e.jsx("span",{className:"uh-ministat-label",children:t})]})}const Me=[7,14,30,90];function Le({onClose:t,providers:s}){var U;const[n,o]=c.useState(30),[l,r]=c.useState(null),{landed:i,loading:p,reload:m}=Te(n),d=c.useRef(null),j=ie(t,{focusRef:d}),P=ce(t),u=pe({loading:p,want:n,answer:i&&{range:i.range,ok:i.resp.ok===!0,days:((U=i.resp.days)==null?void 0:U.length)??0}}),[N,Q]=c.useState(()=>typeof document<"u"&&document.hidden);c.useEffect(()=>{if(u.phase!=="busy")return;const a=()=>Q(document.hidden);return a(),document.addEventListener("visibilitychange",a),()=>document.removeEventListener("visibilitychange",a)},[u.phase]);const g=u.phase==="chart"?i.resp.days??[]:[],A=c.useRef(null),X=de(u.phase!=="error",A),Y=c.useMemo(()=>g.reduce((a,f)=>Math.max(a,f.totalCost),0),[g]),B=c.useRef(null);c.useLayoutEffect(()=>{const a=B.current;a&&(a.scrollLeft=a.scrollWidth)},[g]);const{totalCost:k,totalTok:Z,inOut:D,cacheRead:ee,modelCosts:E,missingModels:M,storedCost:F}=c.useMemo(()=>ye(g),[g]),se=c.useMemo(()=>be(E),[E]),v=c.useMemo(()=>J(g),[g]),te=v.length>1,O=l?g.find(a=>a.period===l)??null:null,ae=Ce(g.length);return e.jsx("div",{className:"modal-backdrop",...P,role:"presentation",children:e.jsxs("div",{ref:j,className:"modal uh-modal",onClick:a=>a.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Usage history",children:[e.jsxs("header",{className:"uh-head",children:[e.jsxs("div",{className:"uh-titlewrap",children:[e.jsx("div",{className:"uh-title",children:"Usage history"}),e.jsx("div",{className:"uh-sub",children:u.stale?"running ccusage…":ue(s,v.map(a=>a.id))})]}),e.jsx("div",{className:"uh-range",role:"group","aria-label":"Range",children:Me.map(a=>e.jsxs("button",{type:"button","aria-pressed":n===a,className:"uh-range-btn",onClick:()=>{o(a),r(null)},children:[a,"d"]},a))}),e.jsx("button",{ref:A,className:"glyph-btn uh-reload",onClick:m,...I(p),title:"Re-run ccusage","aria-label":"Reload",children:p?"…":e.jsx(he,{})}),e.jsx("button",{ref:d,className:"glyph-btn uh-close",onClick:t,"aria-label":"Close",children:"×"})]}),u.phase==="busy"?e.jsxs("div",{className:"uh-status uh-status-wait",role:"status","aria-label":"Reading usage history","aria-busy":"true","data-paused":N||void 0,children:[e.jsxs("span",{className:"uh-wait-word",children:[e.jsxs("svg",{className:"uh-reading-art",viewBox:"0 0 240 96",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[e.jsx("path",{d:"M25 24v-7a4 4 0 0 1 4-4h28a4 4 0 0 1 4 4v43"}),e.jsx("rect",{x:"17",y:"24",width:"36",height:"51",rx:"4"}),e.jsx("path",{d:"M25 36h19M25 44h19M25 52h13M25 64h7"}),e.jsx("path",{className:"uh-reading-link",d:"M69 49h59"}),e.jsxs("g",{className:"uh-reading-packets",children:[e.jsx("rect",{x:"76",y:"46",width:"6",height:"6",rx:"1.5"}),e.jsx("rect",{x:"76",y:"46",width:"6",height:"6",rx:"1.5"}),e.jsx("rect",{x:"76",y:"46",width:"6",height:"6",rx:"1.5"})]}),e.jsx("rect",{x:"145",y:"18",width:"76",height:"57",rx:"5"}),e.jsx("path",{d:"M154 28h21M154 64h57M154 38v26M163 39h47M163 49h47"}),e.jsx("circle",{cx:"209",cy:"28",r:"2"})]}),e.jsx("strong",{className:"uh-reading-title",children:"Reading usage history"}),e.jsx("span",{className:"uh-reading-note",children:"Gathering costs and tokens from local logs…"}),!i&&e.jsx("span",{className:"uh-reading-hint",children:"The first run may download ccusage."})]}),e.jsx("span",{className:"uh-wait-axis","aria-hidden":!0})]}):u.phase==="error"?e.jsxs("div",{className:"uh-status uh-err",title:ge(i.resp)||void 0,children:[me(i.resp,"ccusage did not report usage"),e.jsx("div",{children:e.jsx("button",{className:"btn uh-retry",onClick:()=>{X(),m()},...I(p),children:p?"trying…":"Try again"})})]}):u.phase==="empty"?e.jsx("div",{className:`uh-status${u.stale?" uh-stale":""}`,"aria-busy":u.stale||void 0,children:"no usage in this range"}):e.jsxs("div",{className:u.stale?"uh-stale":void 0,"aria-busy":u.stale||void 0,children:[e.jsxs("div",{className:"uh-totals",children:[e.jsx(w,{label:"total cost",val:b(k,M.size>0),accent:!0}),e.jsx(w,{label:"tokens",val:x(Z)}),e.jsx(w,{label:"input+output",val:x(D)}),e.jsx(w,{label:"cache reads",val:x(ee)})]}),M.size>0&&e.jsx("p",{className:"uh-cost-note",children:_}),L(F,k)&&e.jsx("p",{className:"uh-cost-note",children:L(F,k)}),te&&e.jsxs("div",{className:"uh-agents",role:"group","aria-label":"Cost by CLI",children:[e.jsx("div",{className:"uh-agent-bar","aria-hidden":"true",children:v.map(a=>e.jsx("span",{className:"uh-agent-seg",style:{width:`${T(a.cost,k)}%`,background:H(a.id)}},a.id))}),e.jsx("div",{className:"uh-agent-keys",children:v.map(a=>e.jsxs("span",{className:"uh-agent-key",title:`${a.id} · ${x(a.tokens)} tokens`,children:[e.jsx("span",{className:"uh-legend-dot",style:{background:H(a.id)}}),V(a.id),e.jsx("span",{className:"uh-agent-cost",children:W(a.cost)}),e.jsx("span",{className:"uh-agent-share",children:fe(a.cost,k)})]},a.id))})]}),e.jsx("div",{ref:B,className:"uh-chart",role:"group","aria-label":"Daily cost by model",children:g.map((a,f)=>{const ne=T(a.totalCost,Y),S=a.period===l,G=`${a.period}, ${b(a.totalCost,a.modelBreakdowns.some(y=>y.missingPricing))}`;return e.jsxs("button",{className:`uh-bar-col${S?" sel":""}`,onClick:()=>r(S?null:a.period),"aria-pressed":S,"aria-label":G,title:G,style:{flexBasis:`${100/g.length}%`,"--uh-i":f,"--uh-step":`${Math.min(10,200/Math.max(g.length,1))}ms`},children:[e.jsx("div",{className:"uh-bar",style:{height:`${Math.max(ne,a.totalCost>0?2:0)}%`},children:K(a.modelBreakdowns).map(y=>{const oe=T(y.cost,a.totalCost);return e.jsx("div",{className:"uh-bar-seg",style:{height:`${oe}%`,background:R(y.modelName)}},y.modelName)})}),(g.length-1-f)%ae===0&&e.jsx("span",{className:"uh-bar-label",children:a.period.slice(5)})]},a.period)})}),e.jsx("div",{className:"uh-legend",children:se.map(([a,f])=>e.jsxs("span",{className:"uh-legend-item",title:a,children:[e.jsx("span",{className:"uh-legend-dot",style:{background:R(a)}}),q(a)," ",e.jsx("span",{className:"uh-legend-cost",children:b(f,M.has(a))})]},a))}),O&&e.jsx(Re,{selectedDay:O})]})]})})}function w({label:t,val:s,accent:n}){return e.jsxs("div",{className:"uh-stat",children:[e.jsx("span",{className:`uh-stat-val${n?" accent":""}`,children:s}),e.jsx("span",{className:"uh-stat-label",children:t})]})}export{Le as default};
|