ccdeck 3.44.0 → 3.45.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.
Files changed (44) hide show
  1. package/README.md +14 -5
  2. package/THIRD_PARTY_NOTICES.md +27 -0
  3. package/dist/web/assets/BrowserWatchModal-Cbzf3TWa.js +1 -0
  4. package/dist/web/assets/IntegrationModal-BnnBr0a3.js +5 -0
  5. package/dist/web/assets/RadioPanel-BIqrMLQN.js +1 -0
  6. package/dist/web/assets/{TrafficRadar-Ch0LVdSl.js → TrafficRadar-D1gZCIwX.js} +1 -1
  7. package/dist/web/assets/{UsageHistoryModal-Du0ZkIJ1.js → UsageHistoryModal-DAhplVju.js} +1 -1
  8. package/dist/web/assets/app-BW3NYUYB.js +318 -0
  9. package/dist/web/assets/app-C5RY_wZ4.css +1 -0
  10. package/dist/web/assets/{index-BQbOfxbL.js → index-r8Ymr47Q.js} +1 -1
  11. package/dist/web/index.html +3 -3
  12. package/package.json +1 -1
  13. package/release-notes.json +18 -0
  14. package/src/server/account-notify.mjs +68 -6
  15. package/src/server/account-watch.mjs +61 -2
  16. package/src/server/claude-accounts.mjs +12 -2
  17. package/src/server/deck-prefs.mjs +15 -5
  18. package/src/server/feature-use.mjs +11 -1
  19. package/src/server/forge-http.mjs +514 -0
  20. package/src/server/forge-public-fetch.mjs +228 -0
  21. package/src/server/forge-routes.mjs +154 -0
  22. package/src/server/github-api.mjs +1369 -0
  23. package/src/server/gitlab-api.mjs +1271 -0
  24. package/src/server/index.mjs +6 -2
  25. package/src/server/integrations/cache.mjs +42 -0
  26. package/src/server/integrations/errors.mjs +167 -0
  27. package/src/server/integrations/forge.mjs +76 -0
  28. package/src/server/integrations/jira.mjs +1026 -0
  29. package/src/server/integrations/providers.mjs +11 -0
  30. package/src/server/integrations/proxy.mjs +314 -0
  31. package/src/server/integrations/registry.mjs +142 -0
  32. package/src/server/integrations/routes.mjs +498 -0
  33. package/src/server/integrations/store.mjs +226 -0
  34. package/src/server/lan-deck.mjs +7 -0
  35. package/src/server/lan-elsewhere.d.mts +30 -0
  36. package/src/server/lan-elsewhere.mjs +137 -0
  37. package/src/server/org-telemetry.mjs +173 -0
  38. package/src/server/pinned-build.mjs +3 -0
  39. package/src/server/request-gates.mjs +19 -0
  40. package/src/server/usage-day.mjs +2 -0
  41. package/dist/web/assets/BrowserWatchModal-DMIUygWz.js +0 -1
  42. package/dist/web/assets/RadioPanel-DNB_AHSs.js +0 -1
  43. package/dist/web/assets/app-CQIstkMF.js +0 -318
  44. package/dist/web/assets/app-Ch-0CYlK.css +0 -1
@@ -1,4 +1,4 @@
1
- import{j as e,r as l,B as Mn,C as hn,D as Is,E as Ps,F as _s,G as Kn,u as Ls,g as Ms,H as Ks}from"./app-CQIstkMF.js";const Vs={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:Vs[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 Vn(t){return[...new Set(t.filter(n=>n.key.endsWith("ENDPOINT")).map(n=>n.value).filter(n=>/^https?:\/\//.test(n)))]}function Fn(t){return(t==null?void 0:t.status)!=="observing"?[]:[...new Set(t.connections.filter(n=>n.active===!0).map(n=>n.destination))]}function En(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 Fs(t){const n=t.filter(s=>s.key==="CLAUDE_CODE_ENABLE_TELEMETRY").map(s=>s.value);return n.length?new Set(n).size>1?"Conflicting settings":n[0]==="Enabled"?"Enabled in settings":n[0]==="Disabled"?"Disabled in settings":"Unknown":"Unknown"}function $s(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 Bs(){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 Hs(){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 _=P.current,J=new AbortController;y=J;try{const M=await fetch("/api/system/traffic-radar/capture",{signal:J.signal});if(!M.ok)throw new Error;const A=await M.json();b&&!J.signal.aborted&&_===P.current&&(n(A),r(!1))}catch{b&&!J.signal.aborted&&_===P.current&&r(!0)}finally{y===J&&(y=null),b&&!J.signal.aborted&&N()&&(f=setTimeout(k,1e3))}},j=()=>{x(),document.visibilityState!=="hidden"&&k()};return k(),document.addEventListener("visibilitychange",j),()=>{var _;b=!1,x(),(_=R.current)==null||_.abort(),document.removeEventListener("visibilitychange",j)}},[]);const L=async(b,f)=>{if(!Mn(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 j=await fetch("/api/system/traffic-radar/capture",{signal:y.signal});j.ok&&(n(await j.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:L}}function Ws({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"],pn=["response","assistant_response","completion","gen_ai.completion","gen_ai.output.messages"],$n=["project.name","project_name","project","workspace.name","workspace","repository.name","repo.name"],Bn=["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 cn=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=>!cn(t[o]))??s[0];return r?{state:cn(t[r])?"redacted":"included",key:r,value:t[r]}:{state:"absent",key:null,value:null}}function zs(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 Us(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,pn).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 Js(t,n){const s=ft(t,$n),r=ft(t,Bn);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 Ys({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(zs(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=()=>{},mn=t=>Array.isArray(t)?t:[t],ot=t=>t!==null&&typeof t=="object",dn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Hn=t=>t!=null&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function",Wn=t=>t&&typeof t=="object"&&"type"in t&&"target"in t&&"preventDefault"in t&&typeof t.preventDefault=="function",kn=(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},zn=t=>{if(t!==Un){if(t&&typeof t=="object")for(const n in t){const s=t[n],r=zn(s);r!==s&&(t[n]=r)}return t}},Un="__​undefined__",Jn=t=>t.split(/(\.|\[\d+\])/).filter(n=>n!=="."&&n!=="").map(n=>{const s=/\[(\d+)\]/.exec(n);return s?Number(s[1]):n}),Yn=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]),fn=(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}
1
+ import{j as e,a as l,X as Mn,Y as hn,r as Is,Z as Ps,w as _s,_ as Kn,h as Ls,i as Ms,t as Ks}from"./app-BW3NYUYB.js";const Vs={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:Vs[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 Vn(t){return[...new Set(t.filter(n=>n.key.endsWith("ENDPOINT")).map(n=>n.value).filter(n=>/^https?:\/\//.test(n)))]}function Fn(t){return(t==null?void 0:t.status)!=="observing"?[]:[...new Set(t.connections.filter(n=>n.active===!0).map(n=>n.destination))]}function En(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 Fs(t){const n=t.filter(s=>s.key==="CLAUDE_CODE_ENABLE_TELEMETRY").map(s=>s.value);return n.length?new Set(n).size>1?"Conflicting settings":n[0]==="Enabled"?"Enabled in settings":n[0]==="Disabled"?"Disabled in settings":"Unknown":"Unknown"}function $s(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 Bs(){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 Hs(){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 _=P.current,J=new AbortController;y=J;try{const M=await fetch("/api/system/traffic-radar/capture",{signal:J.signal});if(!M.ok)throw new Error;const A=await M.json();b&&!J.signal.aborted&&_===P.current&&(n(A),r(!1))}catch{b&&!J.signal.aborted&&_===P.current&&r(!0)}finally{y===J&&(y=null),b&&!J.signal.aborted&&N()&&(f=setTimeout(k,1e3))}},j=()=>{x(),document.visibilityState!=="hidden"&&k()};return k(),document.addEventListener("visibilitychange",j),()=>{var _;b=!1,x(),(_=R.current)==null||_.abort(),document.removeEventListener("visibilitychange",j)}},[]);const L=async(b,f)=>{if(!Mn(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 j=await fetch("/api/system/traffic-radar/capture",{signal:y.signal});j.ok&&(n(await j.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:L}}function Ws({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"],pn=["response","assistant_response","completion","gen_ai.completion","gen_ai.output.messages"],$n=["project.name","project_name","project","workspace.name","workspace","repository.name","repo.name"],Bn=["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 cn=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=>!cn(t[o]))??s[0];return r?{state:cn(t[r])?"redacted":"included",key:r,value:t[r]}:{state:"absent",key:null,value:null}}function zs(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 Us(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,pn).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 Js(t,n){const s=ft(t,$n),r=ft(t,Bn);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 Ys({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(zs(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=()=>{},mn=t=>Array.isArray(t)?t:[t],ot=t=>t!==null&&typeof t=="object",dn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Hn=t=>t!=null&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function",Wn=t=>t&&typeof t=="object"&&"type"in t&&"target"in t&&"preventDefault"in t&&typeof t.preventDefault=="function",kn=(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},zn=t=>{if(t!==Un){if(t&&typeof t=="object")for(const n in t){const s=t[n],r=zn(s);r!==s&&(t[n]=r)}return t}},Un="__​undefined__",Jn=t=>t.split(/(\.|\[\d+\])/).filter(n=>n!=="."&&n!=="").map(n=>{const s=/\[(\d+)\]/.exec(n);return s?Number(s[1]):n}),Yn=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]),fn=(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
2
  Couldn't access "${s}" in ${JSON.stringify(t)}`)},Gt=t=>Array.isArray(t),Gn=(t,n)=>t.filter((s,r)=>r!==n),Gs=(t,n,s,r={})=>{const{remove:o=!1,createNew:i=!0,noError:p=!1}=r,u=t,m=Yn(n),a={...r,remove:o,createNew:i,noError:p,fullData:u,fullPath:m},c=Array.isArray(n)?n:Jn(n);return Gt(t)&&o&&c.length===1?Gn(t,c[0]):$t(t,c,s,a)},$t=(t,n,s,r)=>{const o=dn(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"?qs(o,g,s,r)??o:i&&typeof g=="number"?(Xs(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]=Gn(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)&&!dn(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},qs=(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)},Xs=(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:Jn(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 Zs(t,o,s);const i=t[o];return r.length===1?i:at(i,r.slice(1),s)},Zs=(t,n,s)=>{if(s===void 0)throw new Error(`Unable to extract object property
3
3
  Looking for property: ${n}
4
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}},qn=typeof window<"u"?l.useLayoutEffect:l.useEffect,Xn=({className:t,name:n,value:s,setValue:r,onKeyDown:o,styles:i,textAreaRef:p})=>{const u=l.useRef(null);if(qn(()=>{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)===`
@@ -1 +1 @@
1
- import{a as W,f as _,r as c,s as re,p as le,b as $,j as e,c as b,M as q,d as f,e as V,u as ie,g as ce,h as de,i as ue,R as he,k as G,l as me,m as ge}from"./app-CQIstkMF.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 fe(t){const s=J([{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 xe(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,L=t=>typeof t=="string"?t:"",z=t=>Array.isArray(t)?t.filter(s=>typeof s=="string"):[];function je(t){const s=t??{};return{modelName:L(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(l.agent),totalCost:h(l.totalCost),totalTokens:h(l.totalTokens)}}):void 0;return{period:L(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 fe(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=$(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:f(t.inputTokens)}),e.jsx(C,{label:"output",val:f(t.outputTokens)}),e.jsx(C,{label:"cache write",val:f(t.cacheCreationTokens)}),e.jsx(C,{label:"cache read",val:f(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:V(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 $e({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,x)=>Math.max(a,x.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,...G(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()},...G(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:f(Z)}),e.jsx(w,{label:"input+output",val:f(D)}),e.jsx(w,{label:"cache reads",val:f(ee)})]}),M.size>0&&e.jsx("p",{className:"uh-cost-note",children:q}),$(F,k)&&e.jsx("p",{className:"uh-cost-note",children:$(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} · ${f(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:xe(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,x)=>{const ne=T(a.totalCost,Y),S=a.period===l,I=`${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":I,title:I,style:{flexBasis:`${100/g.length}%`,"--uh-i":x,"--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-x)%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,x])=>e.jsxs("span",{className:"uh-legend-item",title:a,children:[e.jsx("span",{className:"uh-legend-dot",style:{background:R(a)}}),V(a)," ",e.jsx("span",{className:"uh-legend-cost",children:b(x,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{$e as default};
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};