ccdeck 3.81.2 → 3.81.3

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.
@@ -1,4 +1,4 @@
1
- import{j as e,t as pt,b as d,a7 as zn,a6 as nn,a8 as Be,o as rn,u as Oe,a9 as yn,r as Vr,g as un,e as $n,aa as Fr,w as Hr,ab as Wn,C as Br,D as zr,z as $r}from"./app-uL65pD1B.js";const Wr={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 Lt({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:Wr[t]})}function mn({className:t="",children:n,...r}){return e.jsxs("span",{className:"tr-select-wrap",children:[e.jsx("select",{...r,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 fn(t,n=!1,r=pt){return n||t.active===null?r("radar.conn.unavailable"):t.connecting?t.active?r("radar.conn.connecting"):r("radar.conn.attempted"):t.active?r("radar.conn.active"):r("radar.conn.previous")}function Un(t){return[...new Set(t.filter(n=>n.key.endsWith("ENDPOINT")).map(n=>n.value).filter(n=>/^https?:\/\//.test(n)))]}function Ur(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 Yr(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 Jr(t){const n=t.filter(r=>r.key==="CLAUDE_CODE_ENABLE_TELEMETRY").map(r=>r.value);return n.length?new Set(n).size>1?"conflict":n[0]==="Enabled"?"enabled":n[0]==="Disabled"?"disabled":"unknown":"unknown"}function Gr(t,n=pt){const r=t.filter(i=>i.key==="CLAUDE_CODE_ENABLE_TELEMETRY"),s=r.map(i=>i.value);if(!s.length)return n("radar.state.unknown");if(new Set(s).size>1)return n("radar.state.conflict");const o=r.every(i=>i.launch);return s[0]==="Enabled"?n(o?"radar.state.enabledLaunch":"radar.state.enabledSettings"):s[0]==="Disabled"?n(o?"radar.state.disabledLaunch":"radar.state.disabledSettings"):n("radar.state.unknown")}function qr(t){const n=t.replace(/^\uFEFF/,"").trim();if(!n)return[];let r;try{JSON.parse(n),r=[n]}catch{r=t.replace(/^\uFEFF/,"").split(/\r?\n/)}if(r.length>1e4)throw new Error(pt("radar.file.tooLong"));return r.flatMap((s,o)=>{var i;if(!s.trim())return[];try{const c=JSON.parse(s),u=c&&typeof c=="object"?c:{},m=new Set,l=[c];for(;l.length;){const a=l.pop();if(!a||typeof a!="object")continue;if(Array.isArray(a)){for(const f of a)l.push(f);continue}const p=a;for(const f of["session.id","session_id","sessionId"])typeof p[f]=="string"&&m.add(p[f]);if(["session.id","session_id"].includes(String(p.key))){const f=p.value;typeof(f==null?void 0:f.stringValue)=="string"&&m.add(f.stringValue)}for(const f of Object.values(p))l.push(f)}return[{line:o+1,raw:s,sessionIds:[...m],label:String(u.eventName??((i=u.event)==null?void 0:i.name)??u.type??u.model??pt("radar.file.jsonRecord")).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:s,label:pt("radar.invalidJson"),sessionId:null,timestamp:null,sessionIds:[],valid:!1}]}})}function Xr(){const[t,n]=d.useState(null),[r,s]=d.useState(!1),o=d.useRef(0);return d.useEffect(()=>{let c=!0,u,m=null;const l=()=>document.visibilityState!=="hidden",a=()=>{clearTimeout(u),m==null||m.abort(),m=null},p=async()=>{if(!c||!l()||m)return;const x=new AbortController,w=o.current;m=x;try{const b=await fetch("/api/system/traffic-radar",{signal:x.signal});if(!b.ok)throw new Error("radar_unavailable");const v=await b.json();if(!v.ok)throw new Error("radar_unavailable");c&&!x.signal.aborted&&w===o.current&&(n(v),s(!1))}catch{c&&!x.signal.aborted&&w===o.current&&s(!0)}finally{m===x&&(m=null),c&&!x.signal.aborted&&l()&&(u=setTimeout(p,5e3))}},f=()=>{a(),document.visibilityState!=="hidden"&&p()};return p(),document.addEventListener("visibilitychange",f),()=>{c=!1,a(),document.removeEventListener("visibilitychange",f)}},[]),{snapshot:t,failed:r,updateConfig:c=>{o.current++,n(u=>u&&{...u,config:c})}}}function Zr(){const[t,n]=d.useState(null),[r,s]=d.useState(!1),[o,i]=d.useState(!1),[c,u]=d.useState(""),[m,l]=d.useState(null),[a,p]=d.useState(null),f=d.useRef(null),x=d.useRef(null),w=d.useRef(0);return d.useEffect(()=>{let v=!0,C,I=null;const A=()=>document.visibilityState!=="hidden",E=()=>{clearTimeout(C),I==null||I.abort(),I=null},g=async()=>{if(!v||!A()||I)return;if(f.current){C=setTimeout(g,1e3);return}const N=w.current,S=new AbortController;I=S;try{const O=await fetch("/api/system/traffic-radar/capture",{signal:S.signal});if(!O.ok)throw new Error;const T=await O.json();v&&!S.signal.aborted&&N===w.current&&(n(T),s(!1))}catch{v&&!S.signal.aborted&&N===w.current&&s(!0)}finally{I===S&&(I=null),v&&!S.signal.aborted&&A()&&(C=setTimeout(g,1e3))}},y=()=>{E(),document.visibilityState!=="hidden"&&g()};return g(),document.addEventListener("visibilitychange",y),()=>{var N;v=!1,E(),(N=x.current)==null||N.abort(),document.removeEventListener("visibilitychange",y)}},[]),{capture:t,failed:r,busy:o,pendingAction:a,error:c,permission:m,action:async v=>{if(!zn(f.current))return;w.current++,f.current=v,p(v),i(!0),u(""),v==="permission"&&l(null);const C=new AbortController;x.current=C;const I=setTimeout(()=>C.abort(),v==="permission"?3e5:2e4);try{const A=await fetch(`/api/system/traffic-radar/capture/${v}`,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}",signal:C.signal}),E=await A.json();if(!A.ok)throw new nn(Be(E.error)||pt("radar.srv.captureActionFailed"));v==="permission"&&l(E);const g=await fetch("/api/system/traffic-radar/capture",{signal:C.signal});g.ok&&(n(await g.json()),s(!1))}catch(A){u(rn(A,pt("radar.srv.captureActionFailed")))}finally{clearTimeout(I),x.current=null,f.current=null,p(null),i(!1)}}}}function Qr({workspace:t,width:n,onCommit:r}){const s=Oe(),o=d.useRef(null),i=a=>Math.max(28,Math.min(65,a)),c=a=>{var p;return(p=t.current)==null?void 0:p.style.setProperty("--tr-feed-width",`${a}%`)},u=a=>{const p=i(a);c(p),r(p)},m=a=>{if(o.current===null||!t.current)return;const p=t.current.getBoundingClientRect();o.current=i((a.clientX-p.left)/p.width*100),c(o.current),a.currentTarget.setAttribute("aria-valuenow",String(Math.round(o.current)))},l=()=>{var p;if(o.current===null)return;const a=o.current;o.current=null,(p=t.current)==null||p.removeAttribute("data-resizing"),u(a)};return e.jsx("div",{className:"tr-splitter",role:"separator","aria-label":s("radar.splitter.label"),"aria-orientation":"vertical","aria-valuemin":28,"aria-valuemax":65,"aria-valuenow":Math.round(n),tabIndex:0,title:s("radar.splitter.hint"),onPointerDown:a=>{var p;a.button===0&&(a.preventDefault(),o.current=n,a.currentTarget.setPointerCapture(a.pointerId),(p=t.current)==null||p.setAttribute("data-resizing",""))},onPointerMove:m,onPointerUp:l,onPointerCancel:l,onLostPointerCapture:l,onDoubleClick:()=>u(34),onKeyDown:a=>{const p=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;p!==null&&(a.preventDefault(),u(p))}})}const an=["prompt_text","user_prompt","prompt","gen_ai.prompt","gen_ai.input.messages"],vn=["response","assistant_response","completion","gen_ai.completion","gen_ai.output.messages"],Yn=["project.name","project_name","project","workspace.name","workspace","repository.name","repo.name"],Jn=["cwd","working_directory","working.directory","process.cwd","process.working_directory","workspace.path","project.path","project_path"],St=t=>t&&typeof t=="object"&&!Array.isArray(t)?t:{},Wt=t=>Array.isArray(t)?t:[];function Ht(t){const n=St(t);for(const r of["stringValue","intValue","doubleValue","boolValue","bytesValue"])if(n[r]!==void 0)return n[r];return n.arrayValue?Wt(St(n.arrayValue).values).map(Ht):n.kvlistValue?Dt(St(n.kvlistValue).values):null}function Dt(t){return Object.fromEntries(Wt(t).map(n=>{const r=St(n);return[String(r.key),Ht(r.value)]}))}const gn=t=>typeof t=="string"&&/^(?:\[redacted\]|<redacted>|\(redacted\)|redacted)$/i.test(t.trim());function ut(t,n){const r=n.filter(o=>t[o]!==void 0&&t[o]!==null&&t[o]!==""),s=r.find(o=>!gn(t[o]))??r[0];return s?{state:gn(t[s])?"redacted":"included",key:s,value:t[s]}:{state:"absent",key:null,value:null}}function ea(t){let n=!1;const r=St(t);for(const[s,o,i]of[["resourceLogs","scopeLogs","logRecords"],["resourceSpans","scopeSpans","spans"],["resourceMetrics","scopeMetrics","metrics"]])for(const c of Wt(r[s]))for(const u of Wt(St(c)[o]))for(const m of Wt(St(u)[i])){const l=ut(Dt(St(m).attributes),an);if(l.state==="redacted"&&(n=!0),l.state==="included"){const a=(typeof l.value=="string"?l.value:JSON.stringify(l.value)).replace(/\s+/g," ").trim();if(a)return a.length>180?`${a.slice(0,180)}…`:a}}return n?pt("radar.payload.promptRedacted"):null}function ta(t){const n=Dt(t.attributes);if(/error|fatal/i.test(String(t.severityText??""))||typeof t.severityNumber=="number"&&t.severityNumber>=17||ut(n,["error.message","exception.message","error","error_type"]).state!=="absent"||n.success===!1)return 0;if(ut(n,an).state!=="absent")return 1;if(ut(n,vn).state!=="absent")return 2;if(ut(n,["tool_name","tool.name","gen_ai.tool.name","model","gen_ai.request.model","cost_usd","input_tokens"]).state!=="absent")return 3;const r=String(t.eventName??t.name??n["event.name"]??"");return/^(?:claude_code[._])?(?:plugin[._]loaded|managed[._]settings[._]resolved)$/i.test(r)?4:t.body!==void 0&&Ht(t.body)!==null&&Ht(t.body)!==""?3:4}function na(t,n){const r=ut(t,Yn),s=ut(t,Jn);if(r.state!=="absent"||s.state!=="absent")return{source:"export",project:r,directory:s};const o=ut(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:r,directory:s}}function ra({event:t}){const n=Oe(),r=d.useRef(null),[s,o]=d.useState(null);return d.useEffect(()=>{const i=new AbortController;let c=!1;const u=()=>{c||(c=!0,fetch(`/api/system/traffic-radar/capture/event?id=${t.id}`,{signal:i.signal}).then(async l=>{if(!l.ok)return;const a=await l.json();i.signal.aborted||o(ea(a.payload))}).catch(()=>{}))},m=typeof IntersectionObserver>"u"?null:new IntersectionObserver(l=>{l.some(a=>a.isIntersecting)&&(u(),m==null||m.disconnect())},{rootMargin:"100px"});return r.current&&m?m.observe(r.current):u(),()=>{i.abort(),m==null||m.disconnect()}},[t.id,t.observedAt]),e.jsx("span",{ref:r,className:"tr-prompt-preview",children:s??n("radar.feed.preview")})}const Tt=()=>{},bn=t=>Array.isArray(t)?t:[t],et=t=>t!==null&&typeof t=="object",jn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Gn=t=>t!=null&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function",qn=t=>t&&typeof t=="object"&&"type"in t&&"target"in t&&"preventDefault"in t&&typeof t.preventDefault=="function",An=(t,n)=>{if(typeof t!="string")return null;const r=n.filter(s=>s instanceof Object&&s.enum&&s.values.includes(t)&&s.matchPriority);return r.sort((s,o)=>(o.matchPriority??0)-(s.matchPriority??0)),r[0]??null},Xn=t=>{if(t!==Zn){if(t&&typeof t=="object")for(const n in t){const r=t[n],s=Xn(r);s!==r&&(t[n]=s)}return t}},Zn="__​undefined__",Qn=t=>t.split(/(\.|\[\d+\])/).filter(n=>n!=="."&&n!=="").map(n=>{const r=/\[(\d+)\]/.exec(n);return r?Number(r[1]):n}),er=t=>typeof t=="string"?t:typeof t=="number"?String(t):t.reduce((n,r)=>typeof r=="number"?`${n}[${r}]`:n===""?r:`${n}.${r}`,""),nt=t=>t.length===1&&t[0]===""?"\0":t.map(n=>encodeURIComponent(String(n))).join("/"),ht=(t,n)=>t.length===n.length&&t.every((r,s)=>r===n[s]),wn=(t,n)=>t.length>=n.length&&n.every((r,s)=>r===t[s]),Pt=(t,n,r,s,o)=>{if(!s)throw new Error(o??`Invalid property path: ${n}
1
+ import{j as e,t as pt,b as d,a7 as zn,a6 as nn,a8 as Be,o as rn,u as Oe,a9 as yn,r as Vr,g as un,e as $n,aa as Fr,w as Hr,ab as Wn,C as Br,D as zr,z as $r}from"./app-BWU-3pHs.js";const Wr={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 Lt({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:Wr[t]})}function mn({className:t="",children:n,...r}){return e.jsxs("span",{className:"tr-select-wrap",children:[e.jsx("select",{...r,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 fn(t,n=!1,r=pt){return n||t.active===null?r("radar.conn.unavailable"):t.connecting?t.active?r("radar.conn.connecting"):r("radar.conn.attempted"):t.active?r("radar.conn.active"):r("radar.conn.previous")}function Un(t){return[...new Set(t.filter(n=>n.key.endsWith("ENDPOINT")).map(n=>n.value).filter(n=>/^https?:\/\//.test(n)))]}function Ur(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 Yr(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 Jr(t){const n=t.filter(r=>r.key==="CLAUDE_CODE_ENABLE_TELEMETRY").map(r=>r.value);return n.length?new Set(n).size>1?"conflict":n[0]==="Enabled"?"enabled":n[0]==="Disabled"?"disabled":"unknown":"unknown"}function Gr(t,n=pt){const r=t.filter(i=>i.key==="CLAUDE_CODE_ENABLE_TELEMETRY"),s=r.map(i=>i.value);if(!s.length)return n("radar.state.unknown");if(new Set(s).size>1)return n("radar.state.conflict");const o=r.every(i=>i.launch);return s[0]==="Enabled"?n(o?"radar.state.enabledLaunch":"radar.state.enabledSettings"):s[0]==="Disabled"?n(o?"radar.state.disabledLaunch":"radar.state.disabledSettings"):n("radar.state.unknown")}function qr(t){const n=t.replace(/^\uFEFF/,"").trim();if(!n)return[];let r;try{JSON.parse(n),r=[n]}catch{r=t.replace(/^\uFEFF/,"").split(/\r?\n/)}if(r.length>1e4)throw new Error(pt("radar.file.tooLong"));return r.flatMap((s,o)=>{var i;if(!s.trim())return[];try{const c=JSON.parse(s),u=c&&typeof c=="object"?c:{},m=new Set,l=[c];for(;l.length;){const a=l.pop();if(!a||typeof a!="object")continue;if(Array.isArray(a)){for(const f of a)l.push(f);continue}const p=a;for(const f of["session.id","session_id","sessionId"])typeof p[f]=="string"&&m.add(p[f]);if(["session.id","session_id"].includes(String(p.key))){const f=p.value;typeof(f==null?void 0:f.stringValue)=="string"&&m.add(f.stringValue)}for(const f of Object.values(p))l.push(f)}return[{line:o+1,raw:s,sessionIds:[...m],label:String(u.eventName??((i=u.event)==null?void 0:i.name)??u.type??u.model??pt("radar.file.jsonRecord")).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:s,label:pt("radar.invalidJson"),sessionId:null,timestamp:null,sessionIds:[],valid:!1}]}})}function Xr(){const[t,n]=d.useState(null),[r,s]=d.useState(!1),o=d.useRef(0);return d.useEffect(()=>{let c=!0,u,m=null;const l=()=>document.visibilityState!=="hidden",a=()=>{clearTimeout(u),m==null||m.abort(),m=null},p=async()=>{if(!c||!l()||m)return;const x=new AbortController,w=o.current;m=x;try{const b=await fetch("/api/system/traffic-radar",{signal:x.signal});if(!b.ok)throw new Error("radar_unavailable");const v=await b.json();if(!v.ok)throw new Error("radar_unavailable");c&&!x.signal.aborted&&w===o.current&&(n(v),s(!1))}catch{c&&!x.signal.aborted&&w===o.current&&s(!0)}finally{m===x&&(m=null),c&&!x.signal.aborted&&l()&&(u=setTimeout(p,5e3))}},f=()=>{a(),document.visibilityState!=="hidden"&&p()};return p(),document.addEventListener("visibilitychange",f),()=>{c=!1,a(),document.removeEventListener("visibilitychange",f)}},[]),{snapshot:t,failed:r,updateConfig:c=>{o.current++,n(u=>u&&{...u,config:c})}}}function Zr(){const[t,n]=d.useState(null),[r,s]=d.useState(!1),[o,i]=d.useState(!1),[c,u]=d.useState(""),[m,l]=d.useState(null),[a,p]=d.useState(null),f=d.useRef(null),x=d.useRef(null),w=d.useRef(0);return d.useEffect(()=>{let v=!0,C,I=null;const A=()=>document.visibilityState!=="hidden",E=()=>{clearTimeout(C),I==null||I.abort(),I=null},g=async()=>{if(!v||!A()||I)return;if(f.current){C=setTimeout(g,1e3);return}const N=w.current,S=new AbortController;I=S;try{const O=await fetch("/api/system/traffic-radar/capture",{signal:S.signal});if(!O.ok)throw new Error;const T=await O.json();v&&!S.signal.aborted&&N===w.current&&(n(T),s(!1))}catch{v&&!S.signal.aborted&&N===w.current&&s(!0)}finally{I===S&&(I=null),v&&!S.signal.aborted&&A()&&(C=setTimeout(g,1e3))}},y=()=>{E(),document.visibilityState!=="hidden"&&g()};return g(),document.addEventListener("visibilitychange",y),()=>{var N;v=!1,E(),(N=x.current)==null||N.abort(),document.removeEventListener("visibilitychange",y)}},[]),{capture:t,failed:r,busy:o,pendingAction:a,error:c,permission:m,action:async v=>{if(!zn(f.current))return;w.current++,f.current=v,p(v),i(!0),u(""),v==="permission"&&l(null);const C=new AbortController;x.current=C;const I=setTimeout(()=>C.abort(),v==="permission"?3e5:2e4);try{const A=await fetch(`/api/system/traffic-radar/capture/${v}`,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}",signal:C.signal}),E=await A.json();if(!A.ok)throw new nn(Be(E.error)||pt("radar.srv.captureActionFailed"));v==="permission"&&l(E);const g=await fetch("/api/system/traffic-radar/capture",{signal:C.signal});g.ok&&(n(await g.json()),s(!1))}catch(A){u(rn(A,pt("radar.srv.captureActionFailed")))}finally{clearTimeout(I),x.current=null,f.current=null,p(null),i(!1)}}}}function Qr({workspace:t,width:n,onCommit:r}){const s=Oe(),o=d.useRef(null),i=a=>Math.max(28,Math.min(65,a)),c=a=>{var p;return(p=t.current)==null?void 0:p.style.setProperty("--tr-feed-width",`${a}%`)},u=a=>{const p=i(a);c(p),r(p)},m=a=>{if(o.current===null||!t.current)return;const p=t.current.getBoundingClientRect();o.current=i((a.clientX-p.left)/p.width*100),c(o.current),a.currentTarget.setAttribute("aria-valuenow",String(Math.round(o.current)))},l=()=>{var p;if(o.current===null)return;const a=o.current;o.current=null,(p=t.current)==null||p.removeAttribute("data-resizing"),u(a)};return e.jsx("div",{className:"tr-splitter",role:"separator","aria-label":s("radar.splitter.label"),"aria-orientation":"vertical","aria-valuemin":28,"aria-valuemax":65,"aria-valuenow":Math.round(n),tabIndex:0,title:s("radar.splitter.hint"),onPointerDown:a=>{var p;a.button===0&&(a.preventDefault(),o.current=n,a.currentTarget.setPointerCapture(a.pointerId),(p=t.current)==null||p.setAttribute("data-resizing",""))},onPointerMove:m,onPointerUp:l,onPointerCancel:l,onLostPointerCapture:l,onDoubleClick:()=>u(34),onKeyDown:a=>{const p=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;p!==null&&(a.preventDefault(),u(p))}})}const an=["prompt_text","user_prompt","prompt","gen_ai.prompt","gen_ai.input.messages"],vn=["response","assistant_response","completion","gen_ai.completion","gen_ai.output.messages"],Yn=["project.name","project_name","project","workspace.name","workspace","repository.name","repo.name"],Jn=["cwd","working_directory","working.directory","process.cwd","process.working_directory","workspace.path","project.path","project_path"],St=t=>t&&typeof t=="object"&&!Array.isArray(t)?t:{},Wt=t=>Array.isArray(t)?t:[];function Ht(t){const n=St(t);for(const r of["stringValue","intValue","doubleValue","boolValue","bytesValue"])if(n[r]!==void 0)return n[r];return n.arrayValue?Wt(St(n.arrayValue).values).map(Ht):n.kvlistValue?Dt(St(n.kvlistValue).values):null}function Dt(t){return Object.fromEntries(Wt(t).map(n=>{const r=St(n);return[String(r.key),Ht(r.value)]}))}const gn=t=>typeof t=="string"&&/^(?:\[redacted\]|<redacted>|\(redacted\)|redacted)$/i.test(t.trim());function ut(t,n){const r=n.filter(o=>t[o]!==void 0&&t[o]!==null&&t[o]!==""),s=r.find(o=>!gn(t[o]))??r[0];return s?{state:gn(t[s])?"redacted":"included",key:s,value:t[s]}:{state:"absent",key:null,value:null}}function ea(t){let n=!1;const r=St(t);for(const[s,o,i]of[["resourceLogs","scopeLogs","logRecords"],["resourceSpans","scopeSpans","spans"],["resourceMetrics","scopeMetrics","metrics"]])for(const c of Wt(r[s]))for(const u of Wt(St(c)[o]))for(const m of Wt(St(u)[i])){const l=ut(Dt(St(m).attributes),an);if(l.state==="redacted"&&(n=!0),l.state==="included"){const a=(typeof l.value=="string"?l.value:JSON.stringify(l.value)).replace(/\s+/g," ").trim();if(a)return a.length>180?`${a.slice(0,180)}…`:a}}return n?pt("radar.payload.promptRedacted"):null}function ta(t){const n=Dt(t.attributes);if(/error|fatal/i.test(String(t.severityText??""))||typeof t.severityNumber=="number"&&t.severityNumber>=17||ut(n,["error.message","exception.message","error","error_type"]).state!=="absent"||n.success===!1)return 0;if(ut(n,an).state!=="absent")return 1;if(ut(n,vn).state!=="absent")return 2;if(ut(n,["tool_name","tool.name","gen_ai.tool.name","model","gen_ai.request.model","cost_usd","input_tokens"]).state!=="absent")return 3;const r=String(t.eventName??t.name??n["event.name"]??"");return/^(?:claude_code[._])?(?:plugin[._]loaded|managed[._]settings[._]resolved)$/i.test(r)?4:t.body!==void 0&&Ht(t.body)!==null&&Ht(t.body)!==""?3:4}function na(t,n){const r=ut(t,Yn),s=ut(t,Jn);if(r.state!=="absent"||s.state!=="absent")return{source:"export",project:r,directory:s};const o=ut(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:r,directory:s}}function ra({event:t}){const n=Oe(),r=d.useRef(null),[s,o]=d.useState(null);return d.useEffect(()=>{const i=new AbortController;let c=!1;const u=()=>{c||(c=!0,fetch(`/api/system/traffic-radar/capture/event?id=${t.id}`,{signal:i.signal}).then(async l=>{if(!l.ok)return;const a=await l.json();i.signal.aborted||o(ea(a.payload))}).catch(()=>{}))},m=typeof IntersectionObserver>"u"?null:new IntersectionObserver(l=>{l.some(a=>a.isIntersecting)&&(u(),m==null||m.disconnect())},{rootMargin:"100px"});return r.current&&m?m.observe(r.current):u(),()=>{i.abort(),m==null||m.disconnect()}},[t.id,t.observedAt]),e.jsx("span",{ref:r,className:"tr-prompt-preview",children:s??n("radar.feed.preview")})}const Tt=()=>{},bn=t=>Array.isArray(t)?t:[t],et=t=>t!==null&&typeof t=="object",jn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Gn=t=>t!=null&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function",qn=t=>t&&typeof t=="object"&&"type"in t&&"target"in t&&"preventDefault"in t&&typeof t.preventDefault=="function",An=(t,n)=>{if(typeof t!="string")return null;const r=n.filter(s=>s instanceof Object&&s.enum&&s.values.includes(t)&&s.matchPriority);return r.sort((s,o)=>(o.matchPriority??0)-(s.matchPriority??0)),r[0]??null},Xn=t=>{if(t!==Zn){if(t&&typeof t=="object")for(const n in t){const r=t[n],s=Xn(r);s!==r&&(t[n]=s)}return t}},Zn="__​undefined__",Qn=t=>t.split(/(\.|\[\d+\])/).filter(n=>n!=="."&&n!=="").map(n=>{const r=/\[(\d+)\]/.exec(n);return r?Number(r[1]):n}),er=t=>typeof t=="string"?t:typeof t=="number"?String(t):t.reduce((n,r)=>typeof r=="number"?`${n}[${r}]`:n===""?r:`${n}.${r}`,""),nt=t=>t.length===1&&t[0]===""?"\0":t.map(n=>encodeURIComponent(String(n))).join("/"),ht=(t,n)=>t.length===n.length&&t.every((r,s)=>r===n[s]),wn=(t,n)=>t.length>=n.length&&n.every((r,s)=>r===t[s]),Pt=(t,n,r,s,o)=>{if(!s)throw new Error(o??`Invalid property path: ${n}
2
2
  Couldn't access "${r}" in ${JSON.stringify(t)}`)},Xt=t=>Array.isArray(t),tr=(t,n)=>t.filter((r,s)=>s!==n),aa=(t,n,r,s={})=>{const{remove:o=!1,createNew:i=!0,noError:c=!1}=s,u=t,m=er(n),l={...s,remove:o,createNew:i,noError:c,fullData:u,fullPath:m},a=Array.isArray(n)?n:Qn(n);return Xt(t)&&o&&a.length===1?tr(t,a[0]):$t(t,a,r,l)},$t=(t,n,r,s)=>{const o=jn(t)?{...t}:null,i=Xt(t)?[...t]:null;if(n.length===0)return t;if(!o&&!i)throw new Error("Can't assign property -- invalid input object");const{createNew:c,remove:u,noError:m,fullData:l,fullPath:a}=s,p=n[0];if(i&&typeof p=="string")return i.map(b=>$t(b,n,r,s));if(n.length===1)return o&&typeof p=="string"?sa(o,p,r,s)??o:i&&typeof p=="number"?(oa(i,p,r,s),i):(Pt(l,a,p,m),t);const f=o||i||[];if(u&&n.length===2&&typeof n[1]=="number"){const b=f[p],v=n[1];return Xt(b)?f[p]=tr(b,v):Pt(l,a,p,m,"Trying to remove an indexed item from an object that is not an array"),f}const x=n.slice(1);if(p in t){if(w=f[p],!Xt(w)&&!jn(w)){if(!c)return Pt(l,a,p,m),f;f[p]={}}return f[p]=$t(f[p],x,r,s),f}var w;if(c){const b=typeof x[0]=="number"?[]:{};if(o)return f[p]=b,f[p]=$t(f[p],x,r,s),f;if(i&&Array.isArray(f)){f.push(b);const v=f.length-1;return f[v]=$t(f[v],x,r,s),f}}return Pt(l,a,p,m),f},sa=(t,n,r,s)=>{const{remove:o,createNew:i,noError:c,insertAfter:u,insertBefore:m,fullData:l,fullPath:a}=s;if(m!==void 0||u!==void 0){const f=Object.entries(t);let x;return x=typeof m=="number"?m:typeof u=="number"?u:f.findIndex(([w])=>w===(m??u)),u!==void 0&&x++,f.splice(x,0,[n,r]),Object.fromEntries(f)}const p=n in t;o?p?delete t[n]:Pt(l,a,n,c):i||p?t[n]=r:Pt(l,a,n,c)},oa=(t,n,r,s)=>{const{noError:o,fullData:i,fullPath:c,createNew:u,insert:m}=s;m&&t.splice(n,0,r),n in t?t[n]=r:u?t.push(r):Pt(i,c,n,o)},tt=(t,n,r)=>{const s=Array.isArray(n)?n:Qn(n);if(s.length===0)return t;const o=s[0];if(Array.isArray(t)&&typeof o!="number"&&t.length>0)return t.map(c=>tt(c,s,r));if(typeof t!="object"||t===null||!(o in t))return ia(t,o,r);const i=t[o];return s.length===1?i:tt(i,s.slice(1),r)},ia=(t,n,r)=>{if(r===void 0)throw new Error(`Unable to extract object property
3
3
  Looking for property: ${n}
4
4
  In object: ${JSON.stringify(t)}`);return r},wt=(t,n,r="",s)=>{if(n.length===0)return{key:r,path:[],level:0,index:0,value:t,size:et(t)?Object.keys(t).length:1,parentData:null,fullData:t};const o=n[n.length-1],i=tt(t,n),c=tt(t,n.slice(0,-1))??null;let u=0;if(Array.isArray(c))u=typeof o=="number"?o:Number(o);else if(c&&typeof c=="object"){const m=Object.entries(c);s==null||s(m,l=>l),u=m.findIndex(([l])=>l===o)}return{key:o,path:n,level:n.length,index:u,value:i,size:et(i)?Object.keys(i).length:null,parentData:c,fullData:t}},nr=typeof window<"u"?d.useLayoutEffect:d.useEffect,rr=({className:t,name:n,value:r,setValue:s,onKeyDown:o,styles:i,textAreaRef:c})=>{const u=d.useRef(null);if(nr(()=>{const l=u.current;u.current=null;const a=c==null?void 0:c.current;if(!l||!a)return;const p=l.start+r.length-l.sourceLength,f=Math.max(0,Math.min(p,r.length));a.selectionStart!==f&&a.setSelectionRange(f,f)},[r,c]),typeof r!="string")return null;const m=r.slice(-1)===`
@@ -1 +1 @@
1
- import{P as V,Q as q,b as c,s as le,S as ce,u as I,U as P,j as e,V as b,W as Q,X as x,Y as X,C as de,D as ue,Z as he,_ as me,R as ge,i as H,$ as pe,a0 as xe}from"./app-uL65pD1B.js";function fe(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 Y(t){const s=new Map;for(const a of t)for(const o of a.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((a,o)=>o.cost-a.cost||a.id.localeCompare(o.id))}function je(t){const s=Y([{agents:t}]);return s.length<2?null:s.map(a=>`${V(a.id)} ${q(a.cost)}`).join(" · ")}function z(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 Ne(t,s){if(!(s>0)||!(t>0))return"0%";const a=t/s*100;return a<.1?"<0.1%":`${a.toFixed(1)}%`}const m=t=>typeof t=="number"&&Number.isFinite(t)?t:0,$=t=>typeof t=="string"?t:"",G=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"):[];function ke(t){const s=t??{};return{modelName:$(s.modelName),cost:m(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,m(s.cost)))}:{},inputTokens:m(s.inputTokens),outputTokens:m(s.outputTokens),cacheCreationTokens:m(s.cacheCreationTokens),cacheReadTokens:m(s.cacheReadTokens)}}function be(t){const s=t??{},a=Array.isArray(s.agents)?s.agents.map(o=>{const l=o??{};return{agent:$(l.agent),totalCost:m(l.totalCost),totalTokens:m(l.totalTokens)}}):void 0;return{period:$(s.period),totalCost:m(s.totalCost),totalTokens:m(s.totalTokens),inputTokens:m(s.inputTokens),outputTokens:m(s.outputTokens),cacheCreationTokens:m(s.cacheCreationTokens),cacheReadTokens:m(s.cacheReadTokens),modelsUsed:G(s.modelsUsed),modelBreakdowns:Array.isArray(s.modelBreakdowns)?s.modelBreakdowns.map(ke):[],...a?{agents:a}:{},...s.metadata&&typeof s.metadata=="object"?{metadata:{agents:G(s.metadata.agents)}}:{}}}function ve(t){const s=t??{};return{...s,ok:s.ok===!0,days:Array.isArray(s.days)?s.days.map(be):void 0}}function T(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,a=0,o=0,l=0;const g=new Map,i=new Set;let r=null;for(const d of t){s+=d.totalCost,a+=d.totalTokens,o+=d.inputTokens+d.outputTokens,l+=d.cacheReadTokens;for(const h of d.modelBreakdowns)g.set(h.modelName,(g.get(h.modelName)??0)+h.cost),h.missingPricing&&i.add(h.modelName),h.storedCost!==void 0&&(r=(r??0)+h.storedCost)}return{totalCost:s,totalTok:a,inOut:o,cacheRead:l,modelCosts:g,missingModels:i,storedCost:r}}function Ce(t){return Array.from(t.entries()).sort((s,a)=>a[1]-s[1])}function Z(t){return t.slice().sort((s,a)=>a.cost-s.cost)}function w(t,s){return s>0?t/s*100:0}function we(t){var a,o;return je(t.agents)??((o=(a=t.metadata)==null?void 0:a.agents)!=null&&o.length?t.metadata.agents.join(" · "):null)}function Te(t){return t<=14?1:t<=31?2:7}function Re(){let t=0;return{begin(){const s=++t;return()=>s===t},cancel(){t++}}}function Me(t){const[s,a]=c.useState(null),[o,l]=c.useState(!1),g=c.useState(Re)[0],i=c.useRef(!1),r=(d=!1)=>{if(d&&!le(i.current))return;const h=g.begin();i.current=d;const f=t;l(!0);const R=`/api/ccusage?since=${ce(f)}${d?"&refresh=1":""}`;fetch(R).then(u=>u.json()).then(u=>{h()&&a({range:f,resp:ve(u)})}).catch(()=>{h()&&a({range:f,resp:{ok:!1,reason:"unreachable"}})}).finally(()=>{h()&&(i.current=!1,l(!1))})};return c.useEffect(()=>(r(!1),()=>g.cancel()),[t]),{landed:s,loading:o,reload:()=>r(!0)}}function Se({selectedDay:t}){const s=I(),a=we(t),o=t.modelBreakdowns.some(i=>i.missingPricing),l=t.modelBreakdowns.filter(i=>i.storedCost!==void 0),g=P(l.length?l.reduce((i,r)=>i+r.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,o)}),a&&e.jsx("span",{className:"uh-detail-agents",title:a,children:a})]}),o&&e.jsx("p",{className:"uh-cost-note",children:Q()}),g&&e.jsx("p",{className:"uh-cost-note",children:g}),e.jsxs("div",{className:"uh-detail-mini",children:[e.jsx(y,{label:s("insights.cost.input"),val:x(t.inputTokens)}),e.jsx(y,{label:s("insights.cost.output"),val:x(t.outputTokens)}),e.jsx(y,{label:s("insights.usage.cacheWrite"),val:x(t.cacheCreationTokens)}),e.jsx(y,{label:s("insights.usage.cacheRead"),val:x(t.cacheReadTokens)})]}),e.jsx("div",{className:"uh-detail-models",children:Z(t.modelBreakdowns).map(i=>{const r=w(i.cost,t.totalCost);return e.jsxs("div",{className:"uh-model-row",title:i.modelName,children:[e.jsxs("span",{className:"uh-model-name",children:[e.jsx("span",{className:"uh-legend-dot",style:{background:T(i.modelName)}}),e.jsx("span",{className:"uh-model-label",children:X(i.modelName)})]}),e.jsx("span",{className:"uh-model-bar",children:e.jsx("span",{className:"uh-model-bar-fill",style:{width:`${r}%`,background:T(i.modelName)}})}),e.jsx("span",{className:"uh-model-cost",children:b(i.cost,i.missingPricing)})]},i.modelName)})})]})}function y({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 Pe=[7,14,30,90];function Le({onClose:t,providers:s}){var U;const a=I(),[o,l]=c.useState(30),[g,i]=c.useState(null),{landed:r,loading:d,reload:h}=Me(o),f=c.useRef(null),L=de(t,{focusRef:f}),R=ue(t),u=fe({loading:d,want:o,answer:r&&{range:r.range,ok:r.resp.ok===!0,days:((U=r.resp.days)==null?void 0:U.length)??0}}),[_,J]=c.useState(()=>typeof document<"u"&&document.hidden);c.useEffect(()=>{if(u.phase!=="busy")return;const n=()=>J(document.hidden);return n(),document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[u.phase]);const p=u.phase==="chart"?r.resp.days??[]:[],A=c.useRef(null),K=he(u.phase!=="error",A),D=c.useMemo(()=>p.reduce((n,j)=>Math.max(n,j.totalCost),0),[p]),B=c.useRef(null);c.useLayoutEffect(()=>{const n=B.current;n&&(n.scrollLeft=n.scrollWidth)},[p]);const{totalCost:N,totalTok:ee,inOut:se,cacheRead:te,modelCosts:E,missingModels:M,storedCost:F}=c.useMemo(()=>ye(p),[p]),ae=c.useMemo(()=>Ce(E),[E]),v=c.useMemo(()=>Y(p),[p]),ne=v.length>1,O=g?p.find(n=>n.period===g)??null:null,oe=Te(p.length);return e.jsx("div",{className:"modal-backdrop",...R,role:"presentation",children:e.jsxs("div",{ref:L,className:"modal uh-modal",onClick:n=>n.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":a("insights.usage.title"),children:[e.jsxs("header",{className:"modal-head uh-head",children:[e.jsxs("div",{className:"uh-titlewrap",children:[e.jsx("div",{className:"modal-tool-name",children:a("insights.usage.title")}),e.jsx("div",{className:"uh-sub",children:u.stale?a("insights.usage.running"):me(s,v.map(n=>n.id))})]}),e.jsx("div",{className:"uh-range",role:"group","aria-label":a("insights.usage.range"),children:Pe.map(n=>e.jsx("button",{type:"button","aria-pressed":o===n,className:"uh-range-btn",onClick:()=>{l(n),i(null)},children:a("insights.usage.days",{n})},n))}),e.jsx("button",{ref:A,className:"glyph-btn uh-reload",onClick:h,...H(d),title:a("insights.usage.rerun"),"aria-label":a("insights.usage.reload"),children:d?"…":e.jsx(ge,{})}),e.jsx("button",{ref:f,className:"glyph-btn uh-close",onClick:t,"aria-label":a("insights.usage.close"),children:"×"})]}),u.phase==="busy"?e.jsxs("div",{className:"uh-status uh-status-wait",role:"status","aria-label":a("insights.usage.reading"),"aria-busy":"true","data-paused":_||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:a("insights.usage.reading")}),e.jsx("span",{className:"uh-reading-note",children:a("insights.usage.gathering")}),!r&&e.jsx("span",{className:"uh-reading-hint",children:a("insights.usage.firstRun")})]}),e.jsx("span",{className:"uh-wait-axis","aria-hidden":!0})]}):u.phase==="error"?e.jsxs("div",{className:"uh-status uh-err",title:xe(r.resp)||void 0,children:[pe(r.resp,a("insights.usage.noReport")),e.jsx("div",{children:e.jsx("button",{className:"btn uh-retry",onClick:()=>{K(),h()},...H(d),children:a(d?"insights.usage.trying":"insights.audit.tryAgain")})})]}):u.phase==="empty"?e.jsx("div",{className:`uh-status${u.stale?" uh-stale":""}`,"aria-busy":u.stale||void 0,children:a("insights.usage.empty")}):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(C,{label:a("insights.usage.totalCost"),val:b(N,M.size>0),accent:!0}),e.jsx(C,{label:a("insights.usage.tokens"),val:x(ee)}),e.jsx(C,{label:a("insights.usage.inOut"),val:x(se)}),e.jsx(C,{label:a("insights.usage.cacheReads"),val:x(te)})]}),M.size>0&&e.jsx("p",{className:"uh-cost-note",children:Q()}),P(F,N)&&e.jsx("p",{className:"uh-cost-note",children:P(F,N)}),ne&&e.jsxs("div",{className:"uh-agents",role:"group","aria-label":a("insights.usage.byCli"),children:[e.jsx("div",{className:"uh-agent-bar","aria-hidden":"true",children:v.map(n=>e.jsx("span",{className:"uh-agent-seg",style:{width:`${w(n.cost,N)}%`,background:z(n.id)}},n.id))}),e.jsx("div",{className:"uh-agent-keys",children:v.map(n=>e.jsxs("span",{className:"uh-agent-key",title:a("insights.usage.agentTokens",{id:n.id,tokens:x(n.tokens)}),children:[e.jsx("span",{className:"uh-legend-dot",style:{background:z(n.id)}}),V(n.id),e.jsx("span",{className:"uh-agent-cost",children:q(n.cost)}),e.jsx("span",{className:"uh-agent-share",children:Ne(n.cost,N)})]},n.id))})]}),e.jsx("div",{ref:B,className:"uh-chart",role:"group","aria-label":a("insights.usage.daily"),children:p.map((n,j)=>{const ie=w(n.totalCost,D),S=n.period===g,W=`${n.period}, ${b(n.totalCost,n.modelBreakdowns.some(k=>k.missingPricing))}`;return e.jsxs("button",{className:`uh-bar-col${S?" sel":""}`,onClick:()=>i(S?null:n.period),"aria-pressed":S,"aria-label":W,title:W,style:{flexBasis:`${100/p.length}%`,"--uh-i":j,"--uh-step":`${Math.min(10,200/Math.max(p.length,1))}ms`},children:[e.jsx("div",{className:"uh-bar",style:{height:`${Math.max(ie,n.totalCost>0?2:0)}%`},children:Z(n.modelBreakdowns).map(k=>{const re=w(k.cost,n.totalCost);return e.jsx("div",{className:"uh-bar-seg",style:{height:`${re}%`,background:T(k.modelName)}},k.modelName)})}),(p.length-1-j)%oe===0&&e.jsx("span",{className:"uh-bar-label",children:n.period.slice(5)})]},n.period)})}),e.jsx("div",{className:"uh-legend",children:ae.map(([n,j])=>e.jsxs("span",{className:"uh-legend-item",title:n,children:[e.jsx("span",{className:"uh-legend-dot",style:{background:T(n)}}),X(n)," ",e.jsx("span",{className:"uh-legend-cost",children:b(j,M.has(n))})]},n))}),O&&e.jsx(Se,{selectedDay:O})]})]})})}function C({label:t,val:s,accent:a}){return e.jsxs("div",{className:"uh-stat",children:[e.jsx("span",{className:`uh-stat-val${a?" accent":""}`,children:s}),e.jsx("span",{className:"uh-stat-label",children:t})]})}export{Le as default};
1
+ import{P as V,Q as q,b as c,s as le,S as ce,u as I,U as P,j as e,V as b,W as Q,X as x,Y as X,C as de,D as ue,Z as he,_ as me,R as ge,i as H,$ as pe,a0 as xe}from"./app-BWU-3pHs.js";function fe(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 Y(t){const s=new Map;for(const a of t)for(const o of a.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((a,o)=>o.cost-a.cost||a.id.localeCompare(o.id))}function je(t){const s=Y([{agents:t}]);return s.length<2?null:s.map(a=>`${V(a.id)} ${q(a.cost)}`).join(" · ")}function z(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 Ne(t,s){if(!(s>0)||!(t>0))return"0%";const a=t/s*100;return a<.1?"<0.1%":`${a.toFixed(1)}%`}const m=t=>typeof t=="number"&&Number.isFinite(t)?t:0,$=t=>typeof t=="string"?t:"",G=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"):[];function ke(t){const s=t??{};return{modelName:$(s.modelName),cost:m(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,m(s.cost)))}:{},inputTokens:m(s.inputTokens),outputTokens:m(s.outputTokens),cacheCreationTokens:m(s.cacheCreationTokens),cacheReadTokens:m(s.cacheReadTokens)}}function be(t){const s=t??{},a=Array.isArray(s.agents)?s.agents.map(o=>{const l=o??{};return{agent:$(l.agent),totalCost:m(l.totalCost),totalTokens:m(l.totalTokens)}}):void 0;return{period:$(s.period),totalCost:m(s.totalCost),totalTokens:m(s.totalTokens),inputTokens:m(s.inputTokens),outputTokens:m(s.outputTokens),cacheCreationTokens:m(s.cacheCreationTokens),cacheReadTokens:m(s.cacheReadTokens),modelsUsed:G(s.modelsUsed),modelBreakdowns:Array.isArray(s.modelBreakdowns)?s.modelBreakdowns.map(ke):[],...a?{agents:a}:{},...s.metadata&&typeof s.metadata=="object"?{metadata:{agents:G(s.metadata.agents)}}:{}}}function ve(t){const s=t??{};return{...s,ok:s.ok===!0,days:Array.isArray(s.days)?s.days.map(be):void 0}}function T(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,a=0,o=0,l=0;const g=new Map,i=new Set;let r=null;for(const d of t){s+=d.totalCost,a+=d.totalTokens,o+=d.inputTokens+d.outputTokens,l+=d.cacheReadTokens;for(const h of d.modelBreakdowns)g.set(h.modelName,(g.get(h.modelName)??0)+h.cost),h.missingPricing&&i.add(h.modelName),h.storedCost!==void 0&&(r=(r??0)+h.storedCost)}return{totalCost:s,totalTok:a,inOut:o,cacheRead:l,modelCosts:g,missingModels:i,storedCost:r}}function Ce(t){return Array.from(t.entries()).sort((s,a)=>a[1]-s[1])}function Z(t){return t.slice().sort((s,a)=>a.cost-s.cost)}function w(t,s){return s>0?t/s*100:0}function we(t){var a,o;return je(t.agents)??((o=(a=t.metadata)==null?void 0:a.agents)!=null&&o.length?t.metadata.agents.join(" · "):null)}function Te(t){return t<=14?1:t<=31?2:7}function Re(){let t=0;return{begin(){const s=++t;return()=>s===t},cancel(){t++}}}function Me(t){const[s,a]=c.useState(null),[o,l]=c.useState(!1),g=c.useState(Re)[0],i=c.useRef(!1),r=(d=!1)=>{if(d&&!le(i.current))return;const h=g.begin();i.current=d;const f=t;l(!0);const R=`/api/ccusage?since=${ce(f)}${d?"&refresh=1":""}`;fetch(R).then(u=>u.json()).then(u=>{h()&&a({range:f,resp:ve(u)})}).catch(()=>{h()&&a({range:f,resp:{ok:!1,reason:"unreachable"}})}).finally(()=>{h()&&(i.current=!1,l(!1))})};return c.useEffect(()=>(r(!1),()=>g.cancel()),[t]),{landed:s,loading:o,reload:()=>r(!0)}}function Se({selectedDay:t}){const s=I(),a=we(t),o=t.modelBreakdowns.some(i=>i.missingPricing),l=t.modelBreakdowns.filter(i=>i.storedCost!==void 0),g=P(l.length?l.reduce((i,r)=>i+r.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,o)}),a&&e.jsx("span",{className:"uh-detail-agents",title:a,children:a})]}),o&&e.jsx("p",{className:"uh-cost-note",children:Q()}),g&&e.jsx("p",{className:"uh-cost-note",children:g}),e.jsxs("div",{className:"uh-detail-mini",children:[e.jsx(y,{label:s("insights.cost.input"),val:x(t.inputTokens)}),e.jsx(y,{label:s("insights.cost.output"),val:x(t.outputTokens)}),e.jsx(y,{label:s("insights.usage.cacheWrite"),val:x(t.cacheCreationTokens)}),e.jsx(y,{label:s("insights.usage.cacheRead"),val:x(t.cacheReadTokens)})]}),e.jsx("div",{className:"uh-detail-models",children:Z(t.modelBreakdowns).map(i=>{const r=w(i.cost,t.totalCost);return e.jsxs("div",{className:"uh-model-row",title:i.modelName,children:[e.jsxs("span",{className:"uh-model-name",children:[e.jsx("span",{className:"uh-legend-dot",style:{background:T(i.modelName)}}),e.jsx("span",{className:"uh-model-label",children:X(i.modelName)})]}),e.jsx("span",{className:"uh-model-bar",children:e.jsx("span",{className:"uh-model-bar-fill",style:{width:`${r}%`,background:T(i.modelName)}})}),e.jsx("span",{className:"uh-model-cost",children:b(i.cost,i.missingPricing)})]},i.modelName)})})]})}function y({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 Pe=[7,14,30,90];function Le({onClose:t,providers:s}){var U;const a=I(),[o,l]=c.useState(30),[g,i]=c.useState(null),{landed:r,loading:d,reload:h}=Me(o),f=c.useRef(null),L=de(t,{focusRef:f}),R=ue(t),u=fe({loading:d,want:o,answer:r&&{range:r.range,ok:r.resp.ok===!0,days:((U=r.resp.days)==null?void 0:U.length)??0}}),[_,J]=c.useState(()=>typeof document<"u"&&document.hidden);c.useEffect(()=>{if(u.phase!=="busy")return;const n=()=>J(document.hidden);return n(),document.addEventListener("visibilitychange",n),()=>document.removeEventListener("visibilitychange",n)},[u.phase]);const p=u.phase==="chart"?r.resp.days??[]:[],A=c.useRef(null),K=he(u.phase!=="error",A),D=c.useMemo(()=>p.reduce((n,j)=>Math.max(n,j.totalCost),0),[p]),B=c.useRef(null);c.useLayoutEffect(()=>{const n=B.current;n&&(n.scrollLeft=n.scrollWidth)},[p]);const{totalCost:N,totalTok:ee,inOut:se,cacheRead:te,modelCosts:E,missingModels:M,storedCost:F}=c.useMemo(()=>ye(p),[p]),ae=c.useMemo(()=>Ce(E),[E]),v=c.useMemo(()=>Y(p),[p]),ne=v.length>1,O=g?p.find(n=>n.period===g)??null:null,oe=Te(p.length);return e.jsx("div",{className:"modal-backdrop",...R,role:"presentation",children:e.jsxs("div",{ref:L,className:"modal uh-modal",onClick:n=>n.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":a("insights.usage.title"),children:[e.jsxs("header",{className:"modal-head uh-head",children:[e.jsxs("div",{className:"uh-titlewrap",children:[e.jsx("div",{className:"modal-tool-name",children:a("insights.usage.title")}),e.jsx("div",{className:"uh-sub",children:u.stale?a("insights.usage.running"):me(s,v.map(n=>n.id))})]}),e.jsx("div",{className:"uh-range",role:"group","aria-label":a("insights.usage.range"),children:Pe.map(n=>e.jsx("button",{type:"button","aria-pressed":o===n,className:"uh-range-btn",onClick:()=>{l(n),i(null)},children:a("insights.usage.days",{n})},n))}),e.jsx("button",{ref:A,className:"glyph-btn uh-reload",onClick:h,...H(d),title:a("insights.usage.rerun"),"aria-label":a("insights.usage.reload"),children:d?"…":e.jsx(ge,{})}),e.jsx("button",{ref:f,className:"glyph-btn uh-close",onClick:t,"aria-label":a("insights.usage.close"),children:"×"})]}),u.phase==="busy"?e.jsxs("div",{className:"uh-status uh-status-wait",role:"status","aria-label":a("insights.usage.reading"),"aria-busy":"true","data-paused":_||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:a("insights.usage.reading")}),e.jsx("span",{className:"uh-reading-note",children:a("insights.usage.gathering")}),!r&&e.jsx("span",{className:"uh-reading-hint",children:a("insights.usage.firstRun")})]}),e.jsx("span",{className:"uh-wait-axis","aria-hidden":!0})]}):u.phase==="error"?e.jsxs("div",{className:"uh-status uh-err",title:xe(r.resp)||void 0,children:[pe(r.resp,a("insights.usage.noReport")),e.jsx("div",{children:e.jsx("button",{className:"btn uh-retry",onClick:()=>{K(),h()},...H(d),children:a(d?"insights.usage.trying":"insights.audit.tryAgain")})})]}):u.phase==="empty"?e.jsx("div",{className:`uh-status${u.stale?" uh-stale":""}`,"aria-busy":u.stale||void 0,children:a("insights.usage.empty")}):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(C,{label:a("insights.usage.totalCost"),val:b(N,M.size>0),accent:!0}),e.jsx(C,{label:a("insights.usage.tokens"),val:x(ee)}),e.jsx(C,{label:a("insights.usage.inOut"),val:x(se)}),e.jsx(C,{label:a("insights.usage.cacheReads"),val:x(te)})]}),M.size>0&&e.jsx("p",{className:"uh-cost-note",children:Q()}),P(F,N)&&e.jsx("p",{className:"uh-cost-note",children:P(F,N)}),ne&&e.jsxs("div",{className:"uh-agents",role:"group","aria-label":a("insights.usage.byCli"),children:[e.jsx("div",{className:"uh-agent-bar","aria-hidden":"true",children:v.map(n=>e.jsx("span",{className:"uh-agent-seg",style:{width:`${w(n.cost,N)}%`,background:z(n.id)}},n.id))}),e.jsx("div",{className:"uh-agent-keys",children:v.map(n=>e.jsxs("span",{className:"uh-agent-key",title:a("insights.usage.agentTokens",{id:n.id,tokens:x(n.tokens)}),children:[e.jsx("span",{className:"uh-legend-dot",style:{background:z(n.id)}}),V(n.id),e.jsx("span",{className:"uh-agent-cost",children:q(n.cost)}),e.jsx("span",{className:"uh-agent-share",children:Ne(n.cost,N)})]},n.id))})]}),e.jsx("div",{ref:B,className:"uh-chart",role:"group","aria-label":a("insights.usage.daily"),children:p.map((n,j)=>{const ie=w(n.totalCost,D),S=n.period===g,W=`${n.period}, ${b(n.totalCost,n.modelBreakdowns.some(k=>k.missingPricing))}`;return e.jsxs("button",{className:`uh-bar-col${S?" sel":""}`,onClick:()=>i(S?null:n.period),"aria-pressed":S,"aria-label":W,title:W,style:{flexBasis:`${100/p.length}%`,"--uh-i":j,"--uh-step":`${Math.min(10,200/Math.max(p.length,1))}ms`},children:[e.jsx("div",{className:"uh-bar",style:{height:`${Math.max(ie,n.totalCost>0?2:0)}%`},children:Z(n.modelBreakdowns).map(k=>{const re=w(k.cost,n.totalCost);return e.jsx("div",{className:"uh-bar-seg",style:{height:`${re}%`,background:T(k.modelName)}},k.modelName)})}),(p.length-1-j)%oe===0&&e.jsx("span",{className:"uh-bar-label",children:n.period.slice(5)})]},n.period)})}),e.jsx("div",{className:"uh-legend",children:ae.map(([n,j])=>e.jsxs("span",{className:"uh-legend-item",title:n,children:[e.jsx("span",{className:"uh-legend-dot",style:{background:T(n)}}),X(n)," ",e.jsx("span",{className:"uh-legend-cost",children:b(j,M.has(n))})]},n))}),O&&e.jsx(Se,{selectedDay:O})]})]})})}function C({label:t,val:s,accent:a}){return e.jsxs("div",{className:"uh-stat",children:[e.jsx("span",{className:`uh-stat-val${a?" accent":""}`,children:s}),e.jsx("span",{className:"uh-stat-label",children:t})]})}export{Le as default};