ccdeck 3.50.0 → 3.51.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 (96) hide show
  1. package/README.md +2 -0
  2. package/THIRD_PARTY_NOTICES.md +28 -0
  3. package/dist/web/assets/BrowserWatchModal-CDpunrq9.js +1 -0
  4. package/dist/web/assets/IntegrationModal-BctMcNU8.js +7 -0
  5. package/dist/web/assets/{RadioPanel-D3JLkVYu.js → RadioPanel-DQNFtYOx.js} +1 -1
  6. package/dist/web/assets/{TrafficRadar-Cuk5tXfL.js → TrafficRadar-DRt3Al7E.js} +1 -1
  7. package/dist/web/assets/UsageHistoryModal-DlgPufgs.js +1 -0
  8. package/dist/web/assets/{app-BRaZrImF.js → app-4x4wTE-L.js} +70 -70
  9. package/dist/web/assets/{app-DfGYllmZ.css → app-o4kL0FgZ.css} +1 -1
  10. package/dist/web/assets/{index-DSIUCKoe.js → index-CWUj8Kqh.js} +1 -1
  11. package/dist/web/index.html +3 -3
  12. package/node_modules/bare-addon-resolve/LICENSE +201 -0
  13. package/node_modules/bare-addon-resolve/README.md +226 -0
  14. package/node_modules/bare-addon-resolve/index.d.ts +100 -0
  15. package/node_modules/bare-addon-resolve/index.js +531 -0
  16. package/node_modules/bare-addon-resolve/lib/errors.d.ts +16 -0
  17. package/node_modules/bare-addon-resolve/lib/errors.js +21 -0
  18. package/node_modules/bare-addon-resolve/package.json +57 -0
  19. package/node_modules/bare-module-resolve/LICENSE +201 -0
  20. package/node_modules/bare-module-resolve/README.md +322 -0
  21. package/node_modules/bare-module-resolve/index.d.ts +171 -0
  22. package/node_modules/bare-module-resolve/index.js +899 -0
  23. package/node_modules/bare-module-resolve/lib/errors.d.ts +31 -0
  24. package/node_modules/bare-module-resolve/lib/errors.js +37 -0
  25. package/node_modules/bare-module-resolve/package.json +56 -0
  26. package/node_modules/bare-semver/LICENSE +201 -0
  27. package/node_modules/bare-semver/README.md +147 -0
  28. package/node_modules/bare-semver/index.d.ts +61 -0
  29. package/node_modules/bare-semver/index.js +13 -0
  30. package/node_modules/bare-semver/lib/comparator.js +37 -0
  31. package/node_modules/bare-semver/lib/constants.js +7 -0
  32. package/node_modules/bare-semver/lib/errors.js +22 -0
  33. package/node_modules/bare-semver/lib/range.js +256 -0
  34. package/node_modules/bare-semver/lib/version.js +240 -0
  35. package/node_modules/bare-semver/package.json +43 -0
  36. package/node_modules/fs-native-extensions/CMakeLists.txt +118 -0
  37. package/node_modules/fs-native-extensions/LICENSE +201 -0
  38. package/node_modules/fs-native-extensions/README.md +160 -0
  39. package/node_modules/fs-native-extensions/binding.c +1825 -0
  40. package/node_modules/fs-native-extensions/binding.js +3 -0
  41. package/node_modules/fs-native-extensions/include/fs-ext.h +193 -0
  42. package/node_modules/fs-native-extensions/index.js +356 -0
  43. package/node_modules/fs-native-extensions/package.json +72 -0
  44. package/node_modules/fs-native-extensions/prebuilds/android-arm/fs-native-extensions.bare +0 -0
  45. package/node_modules/fs-native-extensions/prebuilds/android-arm/fs-native-extensions.node +0 -0
  46. package/node_modules/fs-native-extensions/prebuilds/android-arm64/fs-native-extensions.bare +0 -0
  47. package/node_modules/fs-native-extensions/prebuilds/android-arm64/fs-native-extensions.node +0 -0
  48. package/node_modules/fs-native-extensions/prebuilds/android-ia32/fs-native-extensions.bare +0 -0
  49. package/node_modules/fs-native-extensions/prebuilds/android-ia32/fs-native-extensions.node +0 -0
  50. package/node_modules/fs-native-extensions/prebuilds/android-x64/fs-native-extensions.bare +0 -0
  51. package/node_modules/fs-native-extensions/prebuilds/android-x64/fs-native-extensions.node +0 -0
  52. package/node_modules/fs-native-extensions/prebuilds/darwin-arm64/fs-native-extensions.bare +0 -0
  53. package/node_modules/fs-native-extensions/prebuilds/darwin-arm64/fs-native-extensions.node +0 -0
  54. package/node_modules/fs-native-extensions/prebuilds/darwin-x64/fs-native-extensions.bare +0 -0
  55. package/node_modules/fs-native-extensions/prebuilds/darwin-x64/fs-native-extensions.node +0 -0
  56. package/node_modules/fs-native-extensions/prebuilds/ios-arm64/fs-native-extensions.bare +0 -0
  57. package/node_modules/fs-native-extensions/prebuilds/ios-arm64-simulator/fs-native-extensions.bare +0 -0
  58. package/node_modules/fs-native-extensions/prebuilds/ios-x64-simulator/fs-native-extensions.bare +0 -0
  59. package/node_modules/fs-native-extensions/prebuilds/linux-arm64/fs-native-extensions.bare +0 -0
  60. package/node_modules/fs-native-extensions/prebuilds/linux-arm64/fs-native-extensions.node +0 -0
  61. package/node_modules/fs-native-extensions/prebuilds/linux-x64/fs-native-extensions.bare +0 -0
  62. package/node_modules/fs-native-extensions/prebuilds/linux-x64/fs-native-extensions.node +0 -0
  63. package/node_modules/fs-native-extensions/prebuilds/win32-arm64/fs-native-extensions.bare +0 -0
  64. package/node_modules/fs-native-extensions/prebuilds/win32-arm64/fs-native-extensions.node +0 -0
  65. package/node_modules/fs-native-extensions/prebuilds/win32-x64/fs-native-extensions.bare +0 -0
  66. package/node_modules/fs-native-extensions/prebuilds/win32-x64/fs-native-extensions.node +0 -0
  67. package/node_modules/fs-native-extensions/src/apple.c +197 -0
  68. package/node_modules/fs-native-extensions/src/linux.c +146 -0
  69. package/node_modules/fs-native-extensions/src/platform.h +51 -0
  70. package/node_modules/fs-native-extensions/src/posix.c +33 -0
  71. package/node_modules/fs-native-extensions/src/shared.c +397 -0
  72. package/node_modules/fs-native-extensions/src/win32/nt.h +226 -0
  73. package/node_modules/fs-native-extensions/src/win32.c +531 -0
  74. package/node_modules/require-addon/LICENSE +201 -0
  75. package/node_modules/require-addon/README.md +19 -0
  76. package/node_modules/require-addon/lib/bare.js +1 -0
  77. package/node_modules/require-addon/lib/default.js +7 -0
  78. package/node_modules/require-addon/lib/node.js +79 -0
  79. package/node_modules/require-addon/package.json +64 -0
  80. package/node_modules/which-runtime/LICENSE +201 -0
  81. package/node_modules/which-runtime/README.md +29 -0
  82. package/node_modules/which-runtime/index.js +36 -0
  83. package/node_modules/which-runtime/package.json +32 -0
  84. package/package.json +8 -2
  85. package/release-notes.json +19 -0
  86. package/src/server/integrations/jira-comment.mjs +37 -0
  87. package/src/server/integrations/jira-move.mjs +37 -11
  88. package/src/server/integrations/jira-transition.mjs +43 -0
  89. package/src/server/integrations/jira-write-guard.mjs +218 -0
  90. package/src/server/integrations/jira.mjs +16 -0
  91. package/src/server/integrations/routes.mjs +70 -7
  92. package/src/server/static-cache.mjs +34 -16
  93. package/src/server/traffic-radar-wire.mjs +6 -0
  94. package/dist/web/assets/BrowserWatchModal-CSckhvRP.js +0 -1
  95. package/dist/web/assets/IntegrationModal-CT8_QnAx.js +0 -7
  96. package/dist/web/assets/UsageHistoryModal-DiEH73iz.js +0 -1
@@ -1,4 +1,4 @@
1
- import{j as e,b as c,a3 as Kn,a4 as pn,r as _s,a5 as Is,w as Ps,a6 as Vn,n as Ls,o as Ms,k as Ks}from"./app-BRaZrImF.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 Rt({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 ln({className:t="",children:n,...s}){return e.jsxs("span",{className:"tr-select-wrap",children:[e.jsx("select",{...s,className:`tr-select${t?` ${t}`:""}`,children:n}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})}function cn(t,n=!1){return n||t.active===null?"Visibility unavailable":t.connecting?t.active?"Connecting · no reply yet":"Attempted · no reply seen":t.active?"Active connection":"Previously observed"}function Fn(t){return[...new Set(t.filter(n=>n.key.endsWith("ENDPOINT")).map(n=>n.value).filter(n=>/^https?:\/\//.test(n)))]}function Fs(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 $s(t){try{const n=new URL(t);return/^\d+\.\d+\.\d+\.\d+$/.test(n.hostname)?`${n.hostname}:${n.port||(n.protocol==="https:"?"443":"80")}`:null}catch{return null}}function Bs(t){const n=t.filter(o=>o.key==="CLAUDE_CODE_ENABLE_TELEMETRY"),s=n.map(o=>o.value);if(!s.length)return"Unknown";if(new Set(s).size>1)return"Conflicting settings";const r=n.every(o=>o.launch)?"in launch environment":"in settings";return s[0]==="Enabled"?`Enabled ${r}`:s[0]==="Disabled"?`Disabled ${r}`:"Unknown"}function Ws(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 h=JSON.parse(r),d=h&&typeof h=="object"?h:{},m=new Set,a=[h];for(;a.length;){const l=a.pop();if(!l||typeof l!="object")continue;if(Array.isArray(l)){for(const p of l)a.push(p);continue}const g=l;for(const p of["session.id","session_id","sessionId"])typeof g[p]=="string"&&m.add(g[p]);if(["session.id","session_id"].includes(String(g.key))){const p=g.value;typeof(p==null?void 0:p.stringValue)=="string"&&m.add(p.stringValue)}for(const p of Object.values(g))a.push(p)}return[{line:o+1,raw:r,sessionIds:[...m],label:String(d.eventName??((i=d.event)==null?void 0:i.name)??d.type??d.model??"JSON record").slice(0,160),sessionId:typeof(d.session_id??d.sessionId??d["session.id"])=="string"?d.session_id??d.sessionId??d["session.id"]:null,timestamp:typeof d.timestamp=="string"?d.timestamp:null,valid:!0}]}catch{return[{line:o+1,raw:r,label:"Invalid JSON",sessionId:null,timestamp:null,sessionIds:[],valid:!1}]}})}function Hs(){const[t,n]=c.useState(null),[s,r]=c.useState(!1),o=c.useRef(0);return c.useEffect(()=>{let h=!0,d,m=null;const a=()=>document.visibilityState!=="hidden",l=()=>{clearTimeout(d),m==null||m.abort(),m=null},g=async()=>{if(!h||!a()||m)return;const y=new AbortController,w=o.current;m=y;try{const b=await fetch("/api/system/traffic-radar",{signal:y.signal});if(!b.ok)throw new Error("radar_unavailable");const v=await b.json();if(!v.ok)throw new Error("radar_unavailable");h&&!y.signal.aborted&&w===o.current&&(n(v),r(!1))}catch{h&&!y.signal.aborted&&w===o.current&&r(!0)}finally{m===y&&(m=null),h&&!y.signal.aborted&&a()&&(d=setTimeout(g,5e3))}},p=()=>{l(),document.visibilityState!=="hidden"&&g()};return g(),document.addEventListener("visibilitychange",p),()=>{h=!1,l(),document.removeEventListener("visibilitychange",p)}},[]),{snapshot:t,failed:s,updateConfig:h=>{o.current++,n(d=>d&&{...d,config:h})}}}function zs(){const[t,n]=c.useState(null),[s,r]=c.useState(!1),[o,i]=c.useState(!1),[h,d]=c.useState(""),[m,a]=c.useState(null),[l,g]=c.useState(null),p=c.useRef(null),y=c.useRef(null),w=c.useRef(0);return c.useEffect(()=>{let v=!0,D,O=null;const L=()=>document.visibilityState!=="hidden",C=()=>{clearTimeout(D),O==null||O.abort(),O=null},f=async()=>{if(!v||!L()||O)return;if(p.current){D=setTimeout(f,1e3);return}const N=w.current,x=new AbortController;O=x;try{const T=await fetch("/api/system/traffic-radar/capture",{signal:x.signal});if(!T.ok)throw new Error;const z=await T.json();v&&!x.signal.aborted&&N===w.current&&(n(z),r(!1))}catch{v&&!x.signal.aborted&&N===w.current&&r(!0)}finally{O===x&&(O=null),v&&!x.signal.aborted&&L()&&(D=setTimeout(f,1e3))}},E=()=>{C(),document.visibilityState!=="hidden"&&f()};return f(),document.addEventListener("visibilitychange",E),()=>{var N;v=!1,C(),(N=y.current)==null||N.abort(),document.removeEventListener("visibilitychange",E)}},[]),{capture:t,failed:s,busy:o,pendingAction:l,error:h,permission:m,action:async v=>{if(!Kn(p.current))return;w.current++,p.current=v,g(v),i(!0),d(""),v==="permission"&&a(null);const D=new AbortController;y.current=D;const O=setTimeout(()=>D.abort(),v==="permission"?3e5:2e4);try{const L=await fetch(`/api/system/traffic-radar/capture/${v}`,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}",signal:D.signal}),C=await L.json();if(!L.ok)throw new Error(C.error||"Capture action failed. Please retry.");v==="permission"&&a(C);const f=await fetch("/api/system/traffic-radar/capture",{signal:D.signal});f.ok&&(n(await f.json()),r(!1))}catch(L){d(L instanceof Error?L.message:"Capture action failed. Please retry.")}finally{clearTimeout(O),y.current=null,p.current=null,g(null),i(!1)}}}}function Us({workspace:t,width:n,onCommit:s}){const r=c.useRef(null),o=a=>Math.max(28,Math.min(65,a)),i=a=>{var l;return(l=t.current)==null?void 0:l.style.setProperty("--tr-feed-width",`${a}%`)},h=a=>{const l=o(a);i(l),s(l)},d=a=>{if(r.current===null||!t.current)return;const l=t.current.getBoundingClientRect();r.current=o((a.clientX-l.left)/l.width*100),i(r.current),a.currentTarget.setAttribute("aria-valuenow",String(Math.round(r.current)))},m=()=>{var l;if(r.current===null)return;const a=r.current;r.current=null,(l=t.current)==null||l.removeAttribute("data-resizing"),h(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 l;a.button===0&&(a.preventDefault(),r.current=n,a.currentTarget.setPointerCapture(a.pointerId),(l=t.current)==null||l.setAttribute("data-resizing",""))},onPointerMove:d,onPointerUp:m,onPointerCancel:m,onLostPointerCapture:m,onDoubleClick:()=>h(34),onKeyDown:a=>{const l=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;l!==null&&(a.preventDefault(),h(l))}})}const Qt=["prompt_text","user_prompt","prompt","gen_ai.prompt","gen_ai.input.messages"],mn=["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"],Nt=t=>t&&typeof t=="object"&&!Array.isArray(t)?t:{},Bt=t=>Array.isArray(t)?t:[];function Mt(t){const n=Nt(t);for(const s of["stringValue","intValue","doubleValue","boolValue","bytesValue"])if(n[s]!==void 0)return n[s];return n.arrayValue?Bt(Nt(n.arrayValue).values).map(Mt):n.kvlistValue?Et(Nt(n.kvlistValue).values):null}function Et(t){return Object.fromEntries(Bt(t).map(n=>{const s=Nt(n);return[String(s.key),Mt(s.value)]}))}const dn=t=>typeof t=="string"&&/^(?:\[redacted\]|<redacted>|\(redacted\)|redacted)$/i.test(t.trim());function it(t,n){const s=n.filter(o=>t[o]!==void 0&&t[o]!==null&&t[o]!==""),r=s.find(o=>!dn(t[o]))??s[0];return r?{state:dn(t[r])?"redacted":"included",key:r,value:t[r]}:{state:"absent",key:null,value:null}}function Js(t){let n=!1;const s=Nt(t);for(const[r,o,i]of[["resourceLogs","scopeLogs","logRecords"],["resourceSpans","scopeSpans","spans"],["resourceMetrics","scopeMetrics","metrics"]])for(const h of Bt(s[r]))for(const d of Bt(Nt(h)[o]))for(const m of Bt(Nt(d)[i])){const a=it(Et(Nt(m).attributes),Qt);if(a.state==="redacted"&&(n=!0),a.state==="included"){const l=(typeof a.value=="string"?a.value:JSON.stringify(a.value)).replace(/\s+/g," ").trim();if(l)return l.length>180?`${l.slice(0,180)}…`:l}}return n?"Prompt redacted":null}function Ys(t){const n=Et(t.attributes);if(/error|fatal/i.test(String(t.severityText??""))||typeof t.severityNumber=="number"&&t.severityNumber>=17||it(n,["error.message","exception.message","error","error_type"]).state!=="absent"||n.success===!1)return 0;if(it(n,Qt).state!=="absent")return 1;if(it(n,mn).state!=="absent")return 2;if(it(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&&Mt(t.body)!==null&&Mt(t.body)!==""?3:4}function qs(t,n){const s=it(t,$n),r=it(t,Bn);if(s.state!=="absent"||r.state!=="absent")return{source:"export",project:s,directory:r};const o=it(t,["session.id","session_id","gen_ai.conversation.id"]),i=n.filter(d=>d.id===o.value&&d.workspace);return new Set(i.map(d=>d.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 Gs({event:t}){const n=c.useRef(null),[s,r]=c.useState(null);return c.useEffect(()=>{const o=new AbortController;let i=!1;const h=()=>{i||(i=!0,fetch(`/api/system/traffic-radar/capture/event?id=${t.id}`,{signal:o.signal}).then(async m=>{if(!m.ok)return;const a=await m.json();o.signal.aborted||r(Js(a.payload))}).catch(()=>{}))},d=typeof IntersectionObserver>"u"?null:new IntersectionObserver(m=>{m.some(a=>a.isIntersecting)&&(h(),d==null||d.disconnect())},{rootMargin:"100px"});return n.current&&d?d.observe(n.current):h(),()=>{o.abort(),d==null||d.disconnect()}},[t.id,t.observedAt]),e.jsx("span",{ref:n,className:"tr-prompt-preview",children:s??"Prompt-related fields · open to inspect"})}const St=()=>{},fn=t=>Array.isArray(t)?t:[t],Xe=t=>t!==null&&typeof t=="object",un=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Wn=t=>t!=null&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function",Hn=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}`,""),Qe=t=>t.length===1&&t[0]===""?"\0":t.map(n=>encodeURIComponent(String(n))).join("/"),lt=(t,n)=>t.length===n.length&&t.every((s,r)=>s===n[r]),gn=(t,n)=>t.length>=n.length&&n.every((s,r)=>s===t[r]),At=(t,n,s,r,o)=>{if(!r)throw new Error(o??`Invalid property path: ${n}
1
+ import{j as e,b as c,a4 as Kn,a5 as pn,r as _s,a6 as Is,w as Ps,a7 as Vn,o as Ls,v as Ms,l as Ks}from"./app-4x4wTE-L.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 Rt({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 ln({className:t="",children:n,...s}){return e.jsxs("span",{className:"tr-select-wrap",children:[e.jsx("select",{...s,className:`tr-select${t?` ${t}`:""}`,children:n}),e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]})}function cn(t,n=!1){return n||t.active===null?"Visibility unavailable":t.connecting?t.active?"Connecting · no reply yet":"Attempted · no reply seen":t.active?"Active connection":"Previously observed"}function Fn(t){return[...new Set(t.filter(n=>n.key.endsWith("ENDPOINT")).map(n=>n.value).filter(n=>/^https?:\/\//.test(n)))]}function Fs(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 $s(t){try{const n=new URL(t);return/^\d+\.\d+\.\d+\.\d+$/.test(n.hostname)?`${n.hostname}:${n.port||(n.protocol==="https:"?"443":"80")}`:null}catch{return null}}function Bs(t){const n=t.filter(o=>o.key==="CLAUDE_CODE_ENABLE_TELEMETRY"),s=n.map(o=>o.value);if(!s.length)return"Unknown";if(new Set(s).size>1)return"Conflicting settings";const r=n.every(o=>o.launch)?"in launch environment":"in settings";return s[0]==="Enabled"?`Enabled ${r}`:s[0]==="Disabled"?`Disabled ${r}`:"Unknown"}function Ws(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 h=JSON.parse(r),d=h&&typeof h=="object"?h:{},m=new Set,a=[h];for(;a.length;){const l=a.pop();if(!l||typeof l!="object")continue;if(Array.isArray(l)){for(const p of l)a.push(p);continue}const g=l;for(const p of["session.id","session_id","sessionId"])typeof g[p]=="string"&&m.add(g[p]);if(["session.id","session_id"].includes(String(g.key))){const p=g.value;typeof(p==null?void 0:p.stringValue)=="string"&&m.add(p.stringValue)}for(const p of Object.values(g))a.push(p)}return[{line:o+1,raw:r,sessionIds:[...m],label:String(d.eventName??((i=d.event)==null?void 0:i.name)??d.type??d.model??"JSON record").slice(0,160),sessionId:typeof(d.session_id??d.sessionId??d["session.id"])=="string"?d.session_id??d.sessionId??d["session.id"]:null,timestamp:typeof d.timestamp=="string"?d.timestamp:null,valid:!0}]}catch{return[{line:o+1,raw:r,label:"Invalid JSON",sessionId:null,timestamp:null,sessionIds:[],valid:!1}]}})}function Hs(){const[t,n]=c.useState(null),[s,r]=c.useState(!1),o=c.useRef(0);return c.useEffect(()=>{let h=!0,d,m=null;const a=()=>document.visibilityState!=="hidden",l=()=>{clearTimeout(d),m==null||m.abort(),m=null},g=async()=>{if(!h||!a()||m)return;const y=new AbortController,w=o.current;m=y;try{const b=await fetch("/api/system/traffic-radar",{signal:y.signal});if(!b.ok)throw new Error("radar_unavailable");const v=await b.json();if(!v.ok)throw new Error("radar_unavailable");h&&!y.signal.aborted&&w===o.current&&(n(v),r(!1))}catch{h&&!y.signal.aborted&&w===o.current&&r(!0)}finally{m===y&&(m=null),h&&!y.signal.aborted&&a()&&(d=setTimeout(g,5e3))}},p=()=>{l(),document.visibilityState!=="hidden"&&g()};return g(),document.addEventListener("visibilitychange",p),()=>{h=!1,l(),document.removeEventListener("visibilitychange",p)}},[]),{snapshot:t,failed:s,updateConfig:h=>{o.current++,n(d=>d&&{...d,config:h})}}}function zs(){const[t,n]=c.useState(null),[s,r]=c.useState(!1),[o,i]=c.useState(!1),[h,d]=c.useState(""),[m,a]=c.useState(null),[l,g]=c.useState(null),p=c.useRef(null),y=c.useRef(null),w=c.useRef(0);return c.useEffect(()=>{let v=!0,D,O=null;const L=()=>document.visibilityState!=="hidden",C=()=>{clearTimeout(D),O==null||O.abort(),O=null},f=async()=>{if(!v||!L()||O)return;if(p.current){D=setTimeout(f,1e3);return}const N=w.current,x=new AbortController;O=x;try{const T=await fetch("/api/system/traffic-radar/capture",{signal:x.signal});if(!T.ok)throw new Error;const z=await T.json();v&&!x.signal.aborted&&N===w.current&&(n(z),r(!1))}catch{v&&!x.signal.aborted&&N===w.current&&r(!0)}finally{O===x&&(O=null),v&&!x.signal.aborted&&L()&&(D=setTimeout(f,1e3))}},E=()=>{C(),document.visibilityState!=="hidden"&&f()};return f(),document.addEventListener("visibilitychange",E),()=>{var N;v=!1,C(),(N=y.current)==null||N.abort(),document.removeEventListener("visibilitychange",E)}},[]),{capture:t,failed:s,busy:o,pendingAction:l,error:h,permission:m,action:async v=>{if(!Kn(p.current))return;w.current++,p.current=v,g(v),i(!0),d(""),v==="permission"&&a(null);const D=new AbortController;y.current=D;const O=setTimeout(()=>D.abort(),v==="permission"?3e5:2e4);try{const L=await fetch(`/api/system/traffic-radar/capture/${v}`,{method:"POST",headers:{"Content-Type":"application/json"},body:"{}",signal:D.signal}),C=await L.json();if(!L.ok)throw new Error(C.error||"Capture action failed. Please retry.");v==="permission"&&a(C);const f=await fetch("/api/system/traffic-radar/capture",{signal:D.signal});f.ok&&(n(await f.json()),r(!1))}catch(L){d(L instanceof Error?L.message:"Capture action failed. Please retry.")}finally{clearTimeout(O),y.current=null,p.current=null,g(null),i(!1)}}}}function Us({workspace:t,width:n,onCommit:s}){const r=c.useRef(null),o=a=>Math.max(28,Math.min(65,a)),i=a=>{var l;return(l=t.current)==null?void 0:l.style.setProperty("--tr-feed-width",`${a}%`)},h=a=>{const l=o(a);i(l),s(l)},d=a=>{if(r.current===null||!t.current)return;const l=t.current.getBoundingClientRect();r.current=o((a.clientX-l.left)/l.width*100),i(r.current),a.currentTarget.setAttribute("aria-valuenow",String(Math.round(r.current)))},m=()=>{var l;if(r.current===null)return;const a=r.current;r.current=null,(l=t.current)==null||l.removeAttribute("data-resizing"),h(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 l;a.button===0&&(a.preventDefault(),r.current=n,a.currentTarget.setPointerCapture(a.pointerId),(l=t.current)==null||l.setAttribute("data-resizing",""))},onPointerMove:d,onPointerUp:m,onPointerCancel:m,onLostPointerCapture:m,onDoubleClick:()=>h(34),onKeyDown:a=>{const l=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;l!==null&&(a.preventDefault(),h(l))}})}const Qt=["prompt_text","user_prompt","prompt","gen_ai.prompt","gen_ai.input.messages"],mn=["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"],Nt=t=>t&&typeof t=="object"&&!Array.isArray(t)?t:{},Bt=t=>Array.isArray(t)?t:[];function Mt(t){const n=Nt(t);for(const s of["stringValue","intValue","doubleValue","boolValue","bytesValue"])if(n[s]!==void 0)return n[s];return n.arrayValue?Bt(Nt(n.arrayValue).values).map(Mt):n.kvlistValue?Et(Nt(n.kvlistValue).values):null}function Et(t){return Object.fromEntries(Bt(t).map(n=>{const s=Nt(n);return[String(s.key),Mt(s.value)]}))}const dn=t=>typeof t=="string"&&/^(?:\[redacted\]|<redacted>|\(redacted\)|redacted)$/i.test(t.trim());function it(t,n){const s=n.filter(o=>t[o]!==void 0&&t[o]!==null&&t[o]!==""),r=s.find(o=>!dn(t[o]))??s[0];return r?{state:dn(t[r])?"redacted":"included",key:r,value:t[r]}:{state:"absent",key:null,value:null}}function Js(t){let n=!1;const s=Nt(t);for(const[r,o,i]of[["resourceLogs","scopeLogs","logRecords"],["resourceSpans","scopeSpans","spans"],["resourceMetrics","scopeMetrics","metrics"]])for(const h of Bt(s[r]))for(const d of Bt(Nt(h)[o]))for(const m of Bt(Nt(d)[i])){const a=it(Et(Nt(m).attributes),Qt);if(a.state==="redacted"&&(n=!0),a.state==="included"){const l=(typeof a.value=="string"?a.value:JSON.stringify(a.value)).replace(/\s+/g," ").trim();if(l)return l.length>180?`${l.slice(0,180)}…`:l}}return n?"Prompt redacted":null}function Ys(t){const n=Et(t.attributes);if(/error|fatal/i.test(String(t.severityText??""))||typeof t.severityNumber=="number"&&t.severityNumber>=17||it(n,["error.message","exception.message","error","error_type"]).state!=="absent"||n.success===!1)return 0;if(it(n,Qt).state!=="absent")return 1;if(it(n,mn).state!=="absent")return 2;if(it(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&&Mt(t.body)!==null&&Mt(t.body)!==""?3:4}function qs(t,n){const s=it(t,$n),r=it(t,Bn);if(s.state!=="absent"||r.state!=="absent")return{source:"export",project:s,directory:r};const o=it(t,["session.id","session_id","gen_ai.conversation.id"]),i=n.filter(d=>d.id===o.value&&d.workspace);return new Set(i.map(d=>d.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 Gs({event:t}){const n=c.useRef(null),[s,r]=c.useState(null);return c.useEffect(()=>{const o=new AbortController;let i=!1;const h=()=>{i||(i=!0,fetch(`/api/system/traffic-radar/capture/event?id=${t.id}`,{signal:o.signal}).then(async m=>{if(!m.ok)return;const a=await m.json();o.signal.aborted||r(Js(a.payload))}).catch(()=>{}))},d=typeof IntersectionObserver>"u"?null:new IntersectionObserver(m=>{m.some(a=>a.isIntersecting)&&(h(),d==null||d.disconnect())},{rootMargin:"100px"});return n.current&&d?d.observe(n.current):h(),()=>{o.abort(),d==null||d.disconnect()}},[t.id,t.observedAt]),e.jsx("span",{ref:n,className:"tr-prompt-preview",children:s??"Prompt-related fields · open to inspect"})}const St=()=>{},fn=t=>Array.isArray(t)?t:[t],Xe=t=>t!==null&&typeof t=="object",un=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Wn=t=>t!=null&&(typeof t=="object"||typeof t=="function")&&typeof t.then=="function",Hn=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}`,""),Qe=t=>t.length===1&&t[0]===""?"\0":t.map(n=>encodeURIComponent(String(n))).join("/"),lt=(t,n)=>t.length===n.length&&t.every((s,r)=>s===n[r]),gn=(t,n)=>t.length>=n.length&&n.every((s,r)=>s===t[r]),At=(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)}`)},Yt=t=>Array.isArray(t),qn=(t,n)=>t.filter((s,r)=>r!==n),Xs=(t,n,s,r={})=>{const{remove:o=!1,createNew:i=!0,noError:h=!1}=r,d=t,m=Yn(n),a={...r,remove:o,createNew:i,noError:h,fullData:d,fullPath:m},l=Array.isArray(n)?n:Jn(n);return Yt(t)&&o&&l.length===1?qn(t,l[0]):$t(t,l,s,a)},$t=(t,n,s,r)=>{const o=un(t)?{...t}:null,i=Yt(t)?[...t]:null;if(n.length===0)return t;if(!o&&!i)throw new Error("Can't assign property -- invalid input object");const{createNew:h,remove:d,noError:m,fullData:a,fullPath:l}=r,g=n[0];if(i&&typeof g=="string")return i.map(b=>$t(b,n,s,r));if(n.length===1)return o&&typeof g=="string"?Zs(o,g,s,r)??o:i&&typeof g=="number"?(Qs(i,g,s,r),i):(At(a,l,g,m),t);const p=o||i||[];if(d&&n.length===2&&typeof n[1]=="number"){const b=p[g],v=n[1];return Yt(b)?p[g]=qn(b,v):At(a,l,g,m,"Trying to remove an indexed item from an object that is not an array"),p}const y=n.slice(1);if(g in t){if(w=p[g],!Yt(w)&&!un(w)){if(!h)return At(a,l,g,m),p;p[g]={}}return p[g]=$t(p[g],y,s,r),p}var w;if(h){const b=typeof y[0]=="number"?[]:{};if(o)return p[g]=b,p[g]=$t(p[g],y,s,r),p;if(i&&Array.isArray(p)){p.push(b);const v=p.length-1;return p[v]=$t(p[v],y,s,r),p}}return At(a,l,g,m),p},Zs=(t,n,s,r)=>{const{remove:o,createNew:i,noError:h,insertAfter:d,insertBefore:m,fullData:a,fullPath:l}=r;if(m!==void 0||d!==void 0){const p=Object.entries(t);let y;return y=typeof m=="number"?m:typeof d=="number"?d:p.findIndex(([w])=>w===(m??d)),d!==void 0&&y++,p.splice(y,0,[n,s]),Object.fromEntries(p)}const g=n in t;o?g?delete t[n]:At(a,l,n,h):i||g?t[n]=s:At(a,l,n,h)},Qs=(t,n,s,r)=>{const{noError:o,fullData:i,fullPath:h,createNew:d,insert:m}=r;m&&t.splice(n,0,s),n in t?t[n]=s:d?t.push(s):At(i,h,n,o)},Ze=(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(h=>Ze(h,r,s));if(typeof t!="object"||t===null||!(o in t))return er(t,o,s);const i=t[o];return r.length===1?i:Ze(i,r.slice(1),s)},er=(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},xt=(t,n,s="",r)=>{if(n.length===0)return{key:s,path:[],level:0,index:0,value:t,size:Xe(t)?Object.keys(t).length:1,parentData:null,fullData:t};const o=n[n.length-1],i=Ze(t,n),h=Ze(t,n.slice(0,-1))??null;let d=0;if(Array.isArray(h))d=typeof o=="number"?o:Number(o);else if(h&&typeof h=="object"){const m=Object.entries(h);r==null||r(m,a=>a),d=m.findIndex(([a])=>a===o)}return{key:o,path:n,level:n.length,index:d,value:i,size:Xe(i)?Object.keys(i).length:null,parentData:h,fullData:t}},Gn=typeof window<"u"?c.useLayoutEffect:c.useEffect,Xn=({className:t,name:n,value:s,setValue:r,onKeyDown:o,styles:i,textAreaRef:h})=>{const d=c.useRef(null);if(Gn(()=>{const a=d.current;d.current=null;const l=h==null?void 0:h.current;if(!a||!l)return;const g=a.start+s.length-a.sourceLength,p=Math.max(0,Math.min(g,s.length));l.selectionStart!==p&&l.setSelectionRange(p,p)},[s,h]),typeof s!="string")return null;const m=s.slice(-1)===`
@@ -0,0 +1 @@
1
+ import{J as z,K as V,b as c,s as re,L as le,M as L,j as e,N as b,O as _,P as x,Q as q,o as ie,v as ce,S as de,U as ue,R as he,e as G,V as me,W as ge}from"./app-4x4wTE-L.js";function pe(t){return!t.answer||t.answer.range!==t.want?{phase:"busy",stale:!1}:t.answer.ok?{phase:t.answer.days>0?"chart":"empty",stale:t.loading}:{phase:"error",stale:t.loading}}function J(t){const s=new Map;for(const n of t)for(const o of n.agents??[]){if(!o||typeof o.agent!="string"||o.agent==="")continue;const l=s.get(o.agent)??{id:o.agent,cost:0,tokens:0};l.cost+=Number.isFinite(o.totalCost)?o.totalCost:0,l.tokens+=Number.isFinite(o.totalTokens)?o.totalTokens:0,s.set(o.agent,l)}return[...s.values()].sort((n,o)=>o.cost-n.cost||n.id.localeCompare(o.id))}function xe(t){const s=J([{agents:t}]);return s.length<2?null:s.map(n=>`${z(n.id)} ${V(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:"",W=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:W(s.modelsUsed),modelBreakdowns:Array.isArray(s.modelBreakdowns)?s.modelBreakdowns.map(je):[],...n?{agents:n}:{},...s.metadata&&typeof s.metadata=="object"?{metadata:{agents:W(s.metadata.agents)}}:{}}}function ke(t){const s=t??{};return{...s,ok:s.ok===!0,days:Array.isArray(s.days)?s.days.map(Ne):void 0}}function R(t){const s=t.toLowerCase();return s.includes("opus")?"var(--model-opus)":s.includes("sonnet")?"var(--model-sonnet)":s.includes("haiku")?"var(--model-haiku)":s.includes("gpt-5")||s.includes("gpt5")?"var(--model-gpt5)":s.includes("gpt")?"var(--model-gpt)":s.includes("gemini")?"var(--model-gemini)":s.includes("codex")?"var(--model-codex)":s.includes("fable")||s.includes("mythos")?"var(--model-fable)":"var(--model-other)"}function ye(t){let s=0,n=0,o=0,l=0;const r=new Map,i=new Set;let p=null;for(const m of t){s+=m.totalCost,n+=m.totalTokens,o+=m.inputTokens+m.outputTokens,l+=m.cacheReadTokens;for(const d of m.modelBreakdowns)r.set(d.modelName,(r.get(d.modelName)??0)+d.cost),d.missingPricing&&i.add(d.modelName),d.storedCost!==void 0&&(p=(p??0)+d.storedCost)}return{totalCost:s,totalTok:n,inOut:o,cacheRead:l,modelCosts:r,missingModels:i,storedCost:p}}function be(t){return Array.from(t.entries()).sort((s,n)=>n[1]-s[1])}function K(t){return t.slice().sort((s,n)=>n.cost-s.cost)}function T(t,s){return s>0?t/s*100:0}function ve(t){var n,o;return xe(t.agents)??((o=(n=t.metadata)==null?void 0:n.agents)!=null&&o.length?t.metadata.agents.join(" · "):null)}function Ce(t){return t<=14?1:t<=31?2:7}function we(){let t=0;return{begin(){const s=++t;return()=>s===t},cancel(){t++}}}function Te(t){const[s,n]=c.useState(null),[o,l]=c.useState(!1),r=c.useState(we)[0],i=c.useRef(!1),p=(m=!1)=>{if(m&&!re(i.current))return;const d=r.begin();i.current=m;const j=t;l(!0);const u=`/api/ccusage?since=${le(j)}${m?"&refresh=1":""}`;fetch(u).then(N=>N.json()).then(N=>{d()&&n({range:j,resp:ke(N)})}).catch(()=>{d()&&n({range:j,resp:{ok:!1,reason:"unreachable"}})}).finally(()=>{d()&&(i.current=!1,l(!1))})};return c.useEffect(()=>(p(!1),()=>r.cancel()),[t]),{landed:s,loading:o,reload:()=>p(!0)}}function Re({selectedDay:t}){const s=ve(t),n=t.modelBreakdowns.some(r=>r.missingPricing),o=t.modelBreakdowns.filter(r=>r.storedCost!==void 0),l=L(o.length?o.reduce((r,i)=>r+i.storedCost,0):null,t.totalCost);return e.jsxs("div",{className:"uh-detail",children:[e.jsxs("div",{className:"uh-detail-head",children:[e.jsx("span",{className:"uh-detail-date",children:t.period}),e.jsx("span",{className:"uh-detail-cost",children:b(t.totalCost,n)}),s&&e.jsx("span",{className:"uh-detail-agents",title:s,children:s})]}),n&&e.jsx("p",{className:"uh-cost-note",children:_}),l&&e.jsx("p",{className:"uh-cost-note",children:l}),e.jsxs("div",{className:"uh-detail-mini",children:[e.jsx(C,{label:"input",val:x(t.inputTokens)}),e.jsx(C,{label:"output",val:x(t.outputTokens)}),e.jsx(C,{label:"cache write",val:x(t.cacheCreationTokens)}),e.jsx(C,{label:"cache read",val:x(t.cacheReadTokens)})]}),e.jsx("div",{className:"uh-detail-models",children:K(t.modelBreakdowns).map(r=>{const i=T(r.cost,t.totalCost);return e.jsxs("div",{className:"uh-model-row",title:r.modelName,children:[e.jsxs("span",{className:"uh-model-name",children:[e.jsx("span",{className:"uh-legend-dot",style:{background:R(r.modelName)}}),e.jsx("span",{className:"uh-model-label",children:q(r.modelName)})]}),e.jsx("span",{className:"uh-model-bar",children:e.jsx("span",{className:"uh-model-bar-fill",style:{width:`${i}%`,background:R(r.modelName)}})}),e.jsx("span",{className:"uh-model-cost",children:b(r.cost,r.missingPricing)})]},r.modelName)})})]})}function C({label:t,val:s}){return e.jsxs("div",{className:"uh-ministat",children:[e.jsx("span",{className:"uh-ministat-val",children:s}),e.jsx("span",{className:"uh-ministat-label",children:t})]})}const Me=[7,14,30,90];function Le({onClose:t,providers:s}){var U;const[n,o]=c.useState(30),[l,r]=c.useState(null),{landed:i,loading:p,reload:m}=Te(n),d=c.useRef(null),j=ie(t,{focusRef:d}),P=ce(t),u=pe({loading:p,want:n,answer:i&&{range:i.range,ok:i.resp.ok===!0,days:((U=i.resp.days)==null?void 0:U.length)??0}}),[N,Q]=c.useState(()=>typeof document<"u"&&document.hidden);c.useEffect(()=>{if(u.phase!=="busy")return;const a=()=>Q(document.hidden);return a(),document.addEventListener("visibilitychange",a),()=>document.removeEventListener("visibilitychange",a)},[u.phase]);const g=u.phase==="chart"?i.resp.days??[]:[],A=c.useRef(null),X=de(u.phase!=="error",A),Y=c.useMemo(()=>g.reduce((a,f)=>Math.max(a,f.totalCost),0),[g]),B=c.useRef(null);c.useLayoutEffect(()=>{const a=B.current;a&&(a.scrollLeft=a.scrollWidth)},[g]);const{totalCost:k,totalTok:Z,inOut:D,cacheRead:ee,modelCosts:E,missingModels:M,storedCost:F}=c.useMemo(()=>ye(g),[g]),se=c.useMemo(()=>be(E),[E]),v=c.useMemo(()=>J(g),[g]),te=v.length>1,O=l?g.find(a=>a.period===l)??null:null,ae=Ce(g.length);return e.jsx("div",{className:"modal-backdrop",...P,role:"presentation",children:e.jsxs("div",{ref:j,className:"modal uh-modal",onClick:a=>a.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Usage history",children:[e.jsxs("header",{className:"modal-head uh-head",children:[e.jsxs("div",{className:"uh-titlewrap",children:[e.jsx("div",{className:"modal-tool-name",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:x(Z)}),e.jsx(w,{label:"input+output",val:x(D)}),e.jsx(w,{label:"cache reads",val:x(ee)})]}),M.size>0&&e.jsx("p",{className:"uh-cost-note",children:_}),L(F,k)&&e.jsx("p",{className:"uh-cost-note",children:L(F,k)}),te&&e.jsxs("div",{className:"uh-agents",role:"group","aria-label":"Cost by CLI",children:[e.jsx("div",{className:"uh-agent-bar","aria-hidden":"true",children:v.map(a=>e.jsx("span",{className:"uh-agent-seg",style:{width:`${T(a.cost,k)}%`,background:H(a.id)}},a.id))}),e.jsx("div",{className:"uh-agent-keys",children:v.map(a=>e.jsxs("span",{className:"uh-agent-key",title:`${a.id} · ${x(a.tokens)} tokens`,children:[e.jsx("span",{className:"uh-legend-dot",style:{background:H(a.id)}}),z(a.id),e.jsx("span",{className:"uh-agent-cost",children:V(a.cost)}),e.jsx("span",{className:"uh-agent-share",children:fe(a.cost,k)})]},a.id))})]}),e.jsx("div",{ref:B,className:"uh-chart",role:"group","aria-label":"Daily cost by model",children:g.map((a,f)=>{const ne=T(a.totalCost,Y),S=a.period===l,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":f,"--uh-step":`${Math.min(10,200/Math.max(g.length,1))}ms`},children:[e.jsx("div",{className:"uh-bar",style:{height:`${Math.max(ne,a.totalCost>0?2:0)}%`},children:K(a.modelBreakdowns).map(y=>{const oe=T(y.cost,a.totalCost);return e.jsx("div",{className:"uh-bar-seg",style:{height:`${oe}%`,background:R(y.modelName)}},y.modelName)})}),(g.length-1-f)%ae===0&&e.jsx("span",{className:"uh-bar-label",children:a.period.slice(5)})]},a.period)})}),e.jsx("div",{className:"uh-legend",children:se.map(([a,f])=>e.jsxs("span",{className:"uh-legend-item",title:a,children:[e.jsx("span",{className:"uh-legend-dot",style:{background:R(a)}}),q(a)," ",e.jsx("span",{className:"uh-legend-cost",children:b(f,M.has(a))})]},a))}),O&&e.jsx(Re,{selectedDay:O})]})]})})}function w({label:t,val:s,accent:n}){return e.jsxs("div",{className:"uh-stat",children:[e.jsx("span",{className:`uh-stat-val${n?" accent":""}`,children:s}),e.jsx("span",{className:"uh-stat-label",children:t})]})}export{Le as default};