@kenz1117/dsh-ui-usage-billing 1.8.3-alpha.1 → 1.8.3-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +3 -3
- package/README.md +3 -3
- package/lib/client.js +1 -1
- package/package.json +64 -63
package/README.en.md
CHANGED
|
@@ -118,7 +118,7 @@ Overview / Queue / Billing / Usage / Trends / Agents / Rates / Settings. The her
|
|
|
118
118
|
|
|
119
119
|
## 🚀 Quick start
|
|
120
120
|
|
|
121
|
-
One codebase currently supports DSH `0.1.2-alpha.1` through `0.2.2-
|
|
121
|
+
One codebase currently supports DSH `0.1.2-alpha.1` through `0.2.2-rc.1`. Stable and preview releases share the same compatibility matrix: stable releases use npm `latest`, while previews use `alpha`. npm `latest` currently points to the stable `1.8.2` release; `alpha` points to `1.8.3-alpha.2` (host `0.2.2-rc.1` compatibility and the composer-hover flicker fix).
|
|
122
122
|
|
|
123
123
|
`dsh plugin add` requires an explicit `--profile`. Pinning an exact version is recommended so a package manager's release cooldown cannot resolve a different version. Install the current stable release with:
|
|
124
124
|
|
|
@@ -261,7 +261,7 @@ For on-machine debugging: `dsh plugin --profile web add "link:<absolute path to
|
|
|
261
261
|
|
|
262
262
|
## 📦 Release
|
|
263
263
|
|
|
264
|
-
This standalone npm package maintains one `main` codebase. Stable releases use non-prerelease versions and npm `latest`; previews use prerelease versions and npm `alpha`. npm `latest` currently points to the stable `1.8.2` release, while `alpha` points to `1.8.3-alpha.
|
|
264
|
+
This standalone npm package maintains one `main` codebase. Stable releases use non-prerelease versions and npm `latest`; previews use prerelease versions and npm `alpha`. npm `latest` currently points to the stable `1.8.2` release, while `alpha` points to `1.8.3-alpha.2`; see [COMPATIBILITY.md](COMPATIBILITY.md).
|
|
265
265
|
|
|
266
266
|
```sh
|
|
267
267
|
pnpm test && pnpm run build # full tests + build before release
|
|
@@ -276,7 +276,7 @@ The host discovers the browser side automatically via the `dsh.client` declarati
|
|
|
276
276
|
|
|
277
277
|
- **Permission level: high**: reads durable Session logs, calls vendor / subscription / balance / pricing APIs, reads `apiKeyEnv` through the credentials seam, and writes the ledger, snapshots and task queue under the harness home. The plugin itself has **no** command-execution / shell capability; only explicit enqueueing creates a host Session and submits a Prompt, while Agent tools remain governed by the host's existing permissions and approvals.
|
|
278
278
|
- **Update channel: `user-reviewed`**: with file / network / credential capabilities, DSH STORE requires local manual confirmation on every install; review the repo, pinned commit, lifecycle scripts, and impact scope before installing.
|
|
279
|
-
- **Compatibility**: stable and preview releases from the current `main` share one matrix covering DSH `0.1.2-alpha.1` through `0.2.2-
|
|
279
|
+
- **Compatibility**: stable and preview releases from the current `main` share one matrix covering DSH `0.1.2-alpha.1` through `0.2.2-rc.1`, with 34 per-version declarations. The current stable release is `1.8.2` (npm `latest`); the preview channel is `1.8.3-alpha.2` (npm `alpha`, host `0.2.2-rc.1` compatibility and the composer-hover flicker fix). Release channels and monitoring are documented in [COMPATIBILITY.md](COMPATIBILITY.md). Node.js `^22.19.0 || >=24.0.0`.
|
|
280
280
|
- **Lifecycle**: no `preinstall` / `install` / `postinstall` / `prepare` (ready on install).
|
|
281
281
|
- **No impersonation**: adds only its own entry id `ui-usage-billing`; `@deepseek-ai/dsh-*` packages are `peerDependencies` only (no reinstall / replace / shadowing of official components); the package uses the third-party namespace `@kenz1117/*`.
|
|
282
282
|
- **Build artifacts**: runtime files `lib/*` and `cordis.patch.yml` are committed at the pinned commit and declared in `files`.
|
package/README.md
CHANGED
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
|
|
119
119
|
## 🚀 快速开始
|
|
120
120
|
|
|
121
|
-
当前维护 DSH `0.1.2-alpha.1` ~ `0.2.2-
|
|
121
|
+
当前维护 DSH `0.1.2-alpha.1` ~ `0.2.2-rc.1` 的一份代码。正式版与预览版共享同一兼容矩阵:正式版使用 npm `latest`,预览版使用 `alpha`。当前 `latest` 指向 `1.8.2` 正式版;`alpha` 指向 `1.8.3-alpha.2`(宿主 0.2.2-rc.1 兼容 + 输入栏悬浮闪烁修复,下一轮预览从 `1.8.3-alpha.3` 起)。
|
|
122
122
|
|
|
123
123
|
`dsh plugin add` 需要显式 `--profile`,且建议钉具体版本号,避免包管理器的发布冷静期解析到其他版本。当前正式版安装命令:
|
|
124
124
|
|
|
@@ -269,7 +269,7 @@ pnpm run build # tsc -b && tsdown,产出 lib/index.js 与 lib/client.js
|
|
|
269
269
|
|
|
270
270
|
## 📦 发布
|
|
271
271
|
|
|
272
|
-
本包为独立 npm 包,只维护一份 `main` 代码。正式版使用非预发布版本号并切 `latest`,预览版使用预发布版本号并切 `alpha`;当前 `latest` 指向 `1.8.2` 正式版,`alpha` 指向 `1.8.3-alpha.
|
|
272
|
+
本包为独立 npm 包,只维护一份 `main` 代码。正式版使用非预发布版本号并切 `latest`,预览版使用预发布版本号并切 `alpha`;当前 `latest` 指向 `1.8.2` 正式版,`alpha` 指向 `1.8.3-alpha.2`,详见 [COMPATIBILITY.md](COMPATIBILITY.md)。
|
|
273
273
|
|
|
274
274
|
```sh
|
|
275
275
|
pnpm test && pnpm run build # 发版前全量测试 + 构建
|
|
@@ -284,7 +284,7 @@ npm dist-tag add @kenz1117/dsh-ui-usage-billing@<版本> latest # 正式版
|
|
|
284
284
|
|
|
285
285
|
- **权限等级:high**:读取持久会话日志(文件)、访问多厂商官方 / 订阅 / 余额 / 定价 API(网络)、经凭据 seam 读取 `apiKeyEnv`(凭据)、写入 harness home 下的账本、快照与任务队列(持久状态)。插件自身**不含**命令执行 / Shell;仅用户显式入队时才经宿主创建会话并提交 Prompt,Agent 的工具调用仍由宿主原有权限与审批控制。
|
|
286
286
|
- **更新通道:`user-reviewed`**:本插件具备文件 / 网络 / 凭据能力,DSH STORE 采用每次安装需本机人工确认的通道;安装前请复核仓库、固定 Commit、生命周期脚本与影响范围。
|
|
287
|
-
- **兼容范围**:当前 `main` 的正式版与预览版共享同一兼容矩阵,适配 DSH `0.1.2-alpha.1` ~ `0.2.2-
|
|
287
|
+
- **兼容范围**:当前 `main` 的正式版与预览版共享同一兼容矩阵,适配 DSH `0.1.2-alpha.1` ~ `0.2.2-rc.1`,共 34 项逐版本声明。当前正式版为 `1.8.2`(npm `latest`),预览通道为 `1.8.3-alpha.2`(npm `alpha`,宿主 0.2.2-rc.1 兼容 + 输入栏悬浮闪烁修复)。发行通道与监控机制见 [COMPATIBILITY.md](COMPATIBILITY.md)。Node.js `^22.19.0 || >=24.0.0`。
|
|
288
288
|
- **生命周期**:无 `preinstall` / `install` / `postinstall` / `prepare`(安装即用)。
|
|
289
289
|
- **不冒用官方**:仅新增自有 entry id `ui-usage-billing`;对 `@deepseek-ai/dsh-*` 仅为 `peerDependencies` 依赖(不重复安装 / 不替换 / 不遮蔽官方组件),包名使用第三方命名空间 `@kenz1117/*`。
|
|
290
290
|
- **打包产物**:运行文件 `lib/*` 与 `cordis.patch.yml` 已随固定 Commit 提交并声明在 `files`。
|
package/lib/client.js
CHANGED
|
@@ -2,5 +2,5 @@ window.__ModuleLoader__.load({id:`@kenz1117/dsh-ui-usage-billing`,factory:e=>{va
|
|
|
2
2
|
`)}function yn(e){return[`site,kind,calls,cost_cny`,...Object.entries(e).map(([e,t])=>{let n=e.startsWith(`site:`)?e.slice(5):e.startsWith(`direct:`)?e.slice(7):`unknown`,r=e.startsWith(`site:`)?`site`:e.startsWith(`direct:`)?`direct`:`unknown`;return[hn(gn(n)),r,t.calls,_n(t.cost)].join(`,`)})].join(`
|
|
3
3
|
`)}function bn(e){return e===void 0?``:e.split(/[\\/]/).filter(Boolean).pop()??e}function xn(e){return[`session_id,title,project,calls,cost_cny,last_active,parent_id,sub_calls,sub_cost_cny`,...e.map(e=>[hn(gn(e.id)),hn(gn(e.title??``)),hn(gn(bn(e.cwd))),e.calls,_n(e.cost),e.lastActive>0?new Date(e.lastActive).toISOString():``,e.parentId??``,e.subCalls??``,e.subCost===void 0?``:_n(e.subCost)].join(`,`))].join(`
|
|
4
4
|
`)}function Sn(e,t,n){let r=[...n].sort(),i=r[0],a=r.at(-1);return`${e}${i!==void 0&&a!==void 0?`-${i}_${a}`:``}.${t}`}function Cn(e,t,n){let r=URL.createObjectURL(new Blob([t],{type:n})),i=document.createElement(`a`);i.href=r,i.download=e,i.click(),setTimeout(()=>URL.revokeObjectURL(r),0)}function wn(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(Math.round(e))}let J={top:14,right:18,bottom:22,left:46},Tn=`var(--ds-blue)`,En=`var(--ds-cyan)`,Dn=`var(--ds-amber)`;function On(e,t,n,r){return JSON.stringify({days:e,models:t,dayModels:n,total:r},null,2)}function kn(e){let{stats:t,trendDays:n,onTrendDays:r,t:i}=e,a=e.money,o=e.models??[],{byDay:s,byModel:c,total:l}=t,[u,f]=(0,d.useState)(null),[p,h]=(0,d.useState)(`structure`),[g,_]=(0,d.useState)(null),v=t.byDayModels!==void 0,b=e=>{h(e),_(null)},x=(0,d.useMemo)(()=>{let e=t.byRole;if(e===void 0)return[];let n=e.user+e.assistant+e.tool;return n<=0?[]:[{label:i(`roleUser`),value:e.user,seg:z.shareSegUser},{label:i(`roleAssistant`),value:e.assistant,seg:z.shareSegAssistant},{label:i(`roleTool`),value:e.tool,seg:z.shareSegTool}].map(e=>({...e,pct:e.value/n*100}))},[t.byRole,i]),S=(0,d.useMemo)(()=>{let e=[];for(let t=n-1;t>=0;--t){let n=new Date;n.setDate(n.getDate()-t);let r=K(n.getTime()),i=s[r];e.push({date:r,miss:i?.cacheMiss??0,hit:i?.cacheHit??0,output:i?.output??0,reasoning:i?.reasoning??0})}return e},[s,n]),C=(0,d.useMemo)(()=>{let e=[];for(let r=n-1;r>=0;--r){let n=new Date;n.setDate(n.getDate()-r);let i=K(n.getTime()),a=t.byDayModels?.[i],o={},s=0;if(a!==void 0)for(let[e,t]of Object.entries(a)){let n=t.cacheHit??0,r=t.cacheMiss??0,i=t.output??0,a=n+r+i;a<=0||(o[e]={hit:n,miss:r,output:i,total:a},s+=a)}e.push({date:i,models:o,total:s})}return e},[t.byDayModels,n]),w=(0,d.useMemo)(()=>{let e=new Map;for(let t of C)for(let[n,r]of Object.entries(t.models))e.set(n,(e.get(n)??0)+r.total);return[...e.entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>({key:e,name:o.find(t=>t.key===e)?.name??tn(e).name,color:o.find(t=>t.key===e)?.color??`#8b95a3`}))},[C,o]),T=g!==null&&w.some(e=>e.key===g)?g:null,ee=e=>{if(v){if(p!==`model`){h(`model`),_(e);return}_(t=>t===e?null:e)}},E=(0,d.useMemo)(()=>{let e=0;return Object.entries(c).filter(([,e])=>e.calls>0).map(([t,n])=>{let r=n.input+n.output;e+=r;let i=n.cacheHit+n.cacheMiss;return{key:t,name:tn(t).name,input:n.input,output:n.output,reasoning:n.reasoning??0,calls:n.calls,cacheHit:n.cacheHit,cacheMiss:n.cacheMiss,cacheHitRate:i>0?n.cacheHit/i*100:0,total:r,share:0}}).sort((e,t)=>t.total-e.total).map(t=>({...t,share:e>0?t.total/e:0}))},[c]),D=(0,d.useMemo)(()=>{let e=Object.entries(t.byTool??{}),n=e.slice(0,8),r=e.slice(8).reduce((e,[,t])=>e+t,0),i=e.reduce((e,[,t])=>e+t,0);return{top:n,rest:r>0?[[`…`,r]]:[],totalCalls:i}},[t.byTool]),O=(0,d.useMemo)(()=>{let e=S.length;if(e===0)return null;let t=680-J.left-J.right,n=200-J.top-J.bottom,r=Math.max(...p===`model`?C.map(e=>e.total):S.map(e=>e.miss+e.hit+e.output),1),i=e=>J.top+n-e/r*n,a=t/e,o=Math.min(20,a*.6),s=n=>e===1?J.left+t/2:J.left+t*n/(e-1),c=Math.max(1,Math.ceil(e/8)),l=[];for(let t=0;t<e;t+=c)l.push(t);return e>0&&l[l.length-1]!==e-1&&l.push(e-1),{n:e,plotW:t,plotH:n,max:r,y:i,barW:o,inner:s,indices:l,groupW:a}},[S,C,p]),k=()=>{Cn(`token-daily-${K()}.csv`,An(S),`text/csv`)},A=()=>{Cn(`token-${K()}.json`,On(S,E,C,l),`application/json`)},j=u===null?void 0:S[u],M=u===null?void 0:C[u],te=O===null?0:Math.ceil(80/Math.max(O.groupW,1)),ne=u===null||O===null?void 0:u>=O.n-te?z.chartTooltipAlignRight:u<te?z.chartTooltipAlignLeft:void 0;return(0,m.jsxs)(`div`,{className:z.tokenPanel,"data-testid":`billing-token-panel`,children:[(0,m.jsxs)(`div`,{className:z.exportBar,role:`group`,"aria-label":i(`tokenExport`),children:[(0,m.jsx)(`span`,{className:z.exportLabel,children:i(`export`)}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-token-export-csv`,onClick:k,children:i(`tokenExportCsv`)}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-token-export-json`,onClick:A,children:i(`exportJson`)})]}),(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-token-daily`,children:[(0,m.jsxs)(`div`,{className:z.panelHead,children:[(0,m.jsx)(`h3`,{className:z.panelTitle,children:i(`tokenDaily`)}),(0,m.jsxs)(`span`,{className:z.panelHeadControls,children:[v&&(0,m.jsx)(`span`,{className:z.rangeToggle,role:`group`,"aria-label":i(`tokenDaily`),children:[`structure`,`model`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.rangeButton,p===e&&z.rangeButtonActive),"aria-pressed":p===e,onClick:()=>{b(e)},"data-testid":`billing-token-view-${e}`,children:i(e===`structure`?`tokenViewStructure`:`tokenViewModel`)},e))}),(0,m.jsx)(`span`,{className:z.rangeToggle,role:`group`,"aria-label":i(`tokenDaily`),children:[7,30].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.rangeButton,n===e&&z.rangeButtonActive),"aria-pressed":n===e,onClick:()=>{r(e)},"data-testid":`billing-token-${e}d`,children:i(e===7?`trend7d`:`trend30d`)},e))})]})]}),O===null||p===`model`&&w.length===0?(0,m.jsx)(`div`,{className:z.chartEmpty,children:i(`trendEmpty`)}):(0,m.jsxs)(`div`,{className:z.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 200`,className:z.chartSvg,role:`img`,"aria-label":i(`tokenDaily`),onMouseLeave:()=>{f(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-J.left)/O.plotW,r=Math.round(n*(O.n-1));f(Math.min(Math.max(r,0),O.n-1))},children:[[0,.5,1].map(e=>{let t=O.max*e,n=O.y(t);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:J.left,x2:680-J.right,y1:n,y2:n,className:z.chartGrid}),(0,m.jsx)(`text`,{x:J.left-8,y:n+3,textAnchor:`end`,className:z.chartAxisLabel,children:wn(t)})]},e)}),p===`structure`?S.map((e,t)=>{let n=O.inner(t)-O.barW/2,r=O.y(0),i=O.y(e.miss),a=O.y(e.miss+e.hit),o=O.y(e.miss+e.hit+e.output);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`rect`,{x:n,y:i,width:O.barW,height:r-i,fill:Tn}),(0,m.jsx)(`rect`,{x:n,y:a,width:O.barW,height:i-a,fill:En}),(0,m.jsx)(`rect`,{x:n,y:o,width:O.barW,height:a-o,fill:Dn})]},e.date)}):C.map((e,t)=>{let n=O.inner(t)-O.barW/2,r=0;return(0,m.jsx)(`g`,{children:w.map(t=>{let i=e.models[t.key];if(i===void 0)return null;let a=O.y(r);r+=i.total;let o=O.y(r),s=T!==null&&t.key!==T;return(0,m.jsx)(`rect`,{x:n,y:o,width:O.barW,height:a-o,fill:t.color,opacity:s?.15:1},t.key)})},e.date)}),O.indices.map(e=>{let t=S[e];return t===void 0?null:(0,m.jsx)(`text`,{x:O.inner(e),y:194,textAnchor:`middle`,className:z.chartAxisLabel,children:t.date.slice(5)},t.date)}),u!==null&&(0,m.jsx)(`line`,{x1:O.inner(u),x2:O.inner(u),y1:J.top,y2:J.top+O.plotH,className:z.chartCrosshair})]}),u!==null&&p===`structure`&&j!==void 0&&(0,m.jsxs)(`div`,{className:y(z.chartTooltip,ne),"data-testid":`billing-token-tooltip`,style:{left:`${O.inner(u)/680*100}%`,top:`${O.y(j.miss+j.hit+j.output)/200*100}%`},children:[(0,m.jsxs)(`div`,{className:z.chartTooltipHead,children:[(0,m.jsx)(`span`,{className:z.chartTooltipDate,children:j.date}),(0,m.jsx)(`strong`,{children:(j.miss+j.hit+j.output).toLocaleString()})]}),(0,m.jsxs)(`div`,{className:y(z.chartTooltipRow,z.chartTooltipSplit),children:[(0,m.jsxs)(`span`,{className:z.chartTooltipLabel,children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:En}}),i(`tokenHit`)]}),(0,m.jsx)(`strong`,{children:j.hit.toLocaleString()})]}),(0,m.jsxs)(`div`,{className:y(z.chartTooltipRow,z.chartTooltipSplit),children:[(0,m.jsxs)(`span`,{className:z.chartTooltipLabel,children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:Tn}}),i(`tokenMiss`)]}),(0,m.jsx)(`strong`,{children:j.miss.toLocaleString()})]}),(0,m.jsxs)(`div`,{className:y(z.chartTooltipRow,z.chartTooltipSplit),children:[(0,m.jsxs)(`span`,{className:z.chartTooltipLabel,children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:Dn}}),i(`tokenOutput`)]}),(0,m.jsx)(`strong`,{children:j.output.toLocaleString()})]})]}),u!==null&&p===`model`&&M!==void 0&&(0,m.jsxs)(`div`,{className:y(z.chartTooltip,ne),"data-testid":`billing-token-tooltip`,style:{left:`${O.inner(u)/680*100}%`,top:`${O.y(M.total)/200*100}%`},children:[(0,m.jsxs)(`div`,{className:z.chartTooltipHead,children:[(0,m.jsx)(`span`,{className:z.chartTooltipDate,children:M.date}),(0,m.jsx)(`strong`,{children:M.total.toLocaleString()})]}),w.map(e=>{let t=M.models[e.key];return t===void 0?null:(0,m.jsxs)(`div`,{children:[(0,m.jsxs)(`div`,{className:y(z.chartTooltipRow,z.chartTooltipSplit),children:[(0,m.jsxs)(`span`,{className:z.chartTooltipLabel,children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:e.color}}),e.name]}),(0,m.jsx)(`strong`,{children:t.total.toLocaleString()})]}),(0,m.jsxs)(`div`,{className:z.chartTooltipModelDetail,children:[i(`tokenHitShort`),` `,t.hit.toLocaleString(),` · `,i(`tokenMissShort`),` `,t.miss.toLocaleString(),` · `,i(`tokenOutput`),` `,t.output.toLocaleString()]})]},e.key)})]}),(0,m.jsx)(`div`,{className:z.chartLegend,children:p===`structure`?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:Tn}}),i(`tokenMiss`)]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:En}}),i(`tokenHit`)]}),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:Dn}}),i(`tokenOutput`)]})]}):w.map(e=>(0,m.jsxs)(`button`,{type:`button`,className:y(z.chartLegendItem,T===e.key&&z.chartLegendItemActive),"aria-pressed":T===e.key,"data-testid":`billing-token-legend-${e.key}`,onClick:()=>{ee(e.key)},children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:e.color}}),e.name]},e.key))})]})]}),(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-token-models`,children:[(0,m.jsx)(`div`,{className:z.panelHead,children:(0,m.jsx)(`h3`,{className:z.panelTitle,children:i(`tokenByModel`)})}),E.length===0?(0,m.jsx)(`div`,{className:z.emptyRow,children:i(`noData`)}):(0,m.jsx)(`div`,{className:z.tableScroll,children:(0,m.jsxs)(`table`,{className:z.modelTable,"data-testid":`billing-token-model-table`,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:i(`model`)}),(0,m.jsx)(`th`,{className:z.numCol,children:i(`inputTokens`)}),(0,m.jsx)(`th`,{className:z.numCol,children:i(`outputTokens`)}),(0,m.jsx)(`th`,{className:z.numCol,children:i(`tokenReasoningShort`)}),(0,m.jsx)(`th`,{className:z.numCol,children:i(`cacheHitRate`)}),(0,m.jsx)(`th`,{className:z.numCol,children:i(`tokenTotal`)}),(0,m.jsx)(`th`,{className:z.numCol,children:i(`tokenShare`)}),(0,m.jsx)(`th`,{className:z.numCol,children:i(`calls`)})]})}),(0,m.jsx)(`tbody`,{children:E.map(e=>(0,m.jsxs)(`tr`,{"data-testid":`billing-token-model`,className:y(v&&z.modelRowFocusable,T===e.key&&z.modelRowActive),"aria-selected":v?T===e.key:void 0,onClick:v?()=>{ee(e.key)}:void 0,tabIndex:v?0:void 0,onKeyDown:v?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),ee(e.key))}:void 0,children:[(0,m.jsx)(`td`,{children:(0,m.jsx)(`span`,{className:z.modelName,children:e.name})}),(0,m.jsx)(`td`,{className:z.numCol,children:q(e.input)}),(0,m.jsx)(`td`,{className:z.numCol,children:q(e.output)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.reasoning>0?q(e.reasoning):(0,m.jsx)(`span`,{className:z.na,children:`—`})}),(0,m.jsxs)(`td`,{className:z.numCol,children:[e.cacheHitRate.toFixed(1),`%`]}),(0,m.jsx)(`td`,{className:z.numCol,children:q(e.total)}),(0,m.jsx)(`td`,{className:z.numCol,children:(0,m.jsxs)(`span`,{className:z.tokenModelShareRow,children:[(0,m.jsx)(`span`,{className:z.tokenModelBar,children:(0,m.jsxs)(`span`,{className:z.tokenModelParts,style:{width:`${(e.share*100).toFixed(2)}%`},children:[(0,m.jsx)(`span`,{className:z.tokenModelPartIn,style:{width:`${e.total>0?e.input/e.total*100:0}%`}}),(0,m.jsx)(`span`,{className:z.tokenModelPartOut,style:{width:`${e.total>0?e.output/e.total*100:0}%`}})]})}),(e.share*100).toFixed(1),`%`]})}),(0,m.jsx)(`td`,{className:z.numCol,children:e.calls.toLocaleString()})]},e.key))})]})})]}),D.totalCalls>0&&(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-token-tools`,children:[(0,m.jsx)(`div`,{className:z.panelHead,children:(0,m.jsx)(`h3`,{className:z.panelTitle,children:i(`toolRank`)})}),(0,m.jsx)(`div`,{className:z.tableScroll,children:(0,m.jsxs)(`table`,{className:z.modelTable,"data-testid":`billing-tool-table`,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:i(`toolName`)}),(0,m.jsx)(`th`,{className:z.numCol,children:i(`calls`)}),(0,m.jsx)(`th`,{className:z.numCol,children:i(`tokenShare`)})]})}),(0,m.jsx)(`tbody`,{children:[...D.top,...D.rest].map(([e,t])=>(0,m.jsxs)(`tr`,{"data-testid":`billing-tool-row`,children:[(0,m.jsx)(`td`,{children:(0,m.jsx)(`span`,{className:z.modelName,children:e})}),(0,m.jsx)(`td`,{className:z.numCol,children:t.toLocaleString()}),(0,m.jsxs)(`td`,{className:z.numCol,children:[(t/D.totalCalls*100).toFixed(1),`%`]})]},e))})]})})]}),x.length>0&&(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-panel-roles`,children:[(0,m.jsxs)(`div`,{className:z.panelHead,children:[(0,m.jsx)(`h3`,{className:z.panelTitle,children:i(`roleCost`)}),(0,m.jsx)(`span`,{className:z.panelHint,children:i(`roleHint`)})]}),(0,m.jsx)(`div`,{className:z.shareTrack,"data-testid":`billing-role-track`,children:x.map(e=>(0,m.jsx)(`div`,{className:y(z.shareSeg,e.seg),style:{width:`${e.pct}%`}},e.label))}),(0,m.jsx)(`div`,{className:z.shareLegend,children:x.map(e=>(0,m.jsxs)(`span`,{className:z.shareItem,children:[(0,m.jsx)(`span`,{className:y(z.shareDot,e.seg)}),e.label,(0,m.jsxs)(`span`,{className:z.shareValue,children:[a(e.value),` · `,e.pct.toFixed(1),`%`]})]},e.label))})]})]})}function An(e){return[`date,missInput,cacheHit,output,reasoning,total`,...e.map(e=>`${e.date},${e.miss},${e.hit},${e.output},${e.reasoning},${e.miss+e.hit+e.output}`)].join(`
|
|
5
|
-
`)}function jn(){let e=new Date,t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}let Y={top:18,right:40,bottom:26,left:46};function Mn(e){let[,t,n]=e.split(`-`);return`${Number(t)}/${Number(n)}`}function Nn(e,t){let n=[];for(let r=0;r<e;r+=t)n.push(r);return e>0&&n[n.length-1]!==e-1&&n.push(e-1),n}let Pn={key:`__total__`,name:``,color:``};function Fn({data:e,models:t=[],currency:n=`cny`,metric:r=`cost`,t:i}){let a=i??(e=>et[e]),[o,s]=(0,d.useState)(null),c=e=>dn(un(e,n),n),l=e=>r===`tokens`?wn(e):c(e),u=e=>r===`tokens`?e.tokens??0:e.cost,f=(0,d.useMemo)(()=>{let n=e.length;if(n===0)return null;let i=680-Y.left-Y.right,a=220-Y.top-Y.bottom,o=e=>n===1?Y.left+i/2:Y.left+i*e/(n-1),s=Math.max(...r===`tokens`?e.map(e=>e.tokens??0):e.map(e=>Math.max(e.cost,Object.values(e.byModel??{}).reduce((e,t)=>e+t,0))),1e-4),c=e=>Y.top+a-e/s*a,l=Math.max(...e.map(e=>e.calls),1),d=e=>Y.top+a-e/l*a,f=i/n,p=Math.min(18,f*.6);return{n,plotW:i,plotH:a,inner:o,yCost:c,yCalls:d,barW:p,bars:e.flatMap((e,n)=>{let i=o(n)-p/2;if(t.length===0||r===`tokens`)return[{date:e.date,model:Pn,x:i,base:0,value:u(e),topRounded:!0}];let a=null;for(let n of t)(e.byModel?.[n.key]??0)>0&&(a=n.key);let s=0;return t.map(t=>{let n=e.byModel?.[t.key]??0,r={date:e.date,model:t,x:i,base:s,value:n,topRounded:t.key===a};return s+=n,r})}),costTicks:[0,.25,.5,.75,1].map(e=>s*e).reverse(),callsTicks:[0,.25,.5,.75,1].map(e=>l*e).reverse(),linePath:e.map((e,t)=>{let n=d(e.calls);return`${t===0?`M`:`L`}${o(t)} ${n}`}).join(` `)}},[e,t,r]);if(f===null)return(0,m.jsx)(`div`,{className:z.chartEmpty,children:a(`trendEmpty`)});let{n:p,plotW:h,plotH:g,inner:_,yCost:v,yCalls:y,barW:b,bars:x,costTicks:S,callsTicks:C,linePath:w}=f,T=o===null?void 0:e[o],ee=Nn(p,Math.max(1,Math.ceil(p/8)));return(0,m.jsxs)(`div`,{className:z.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 220`,className:z.chartSvg,role:`img`,"aria-label":`Daily cost by model and total calls`,onMouseLeave:()=>{s(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-Y.left)/h,r=Math.round(n*(p-1));s(Math.min(Math.max(r,0),p-1))},children:[S.map((e,t)=>{let n=v(e);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:Y.left,x2:680-Y.right,y1:n,y2:n,className:z.chartGrid}),(0,m.jsx)(`text`,{x:Y.left-8,y:n+3,textAnchor:`end`,className:z.chartAxisLabel,children:l(e)})]},`cost-${t}`)}),x.map(t=>{if(t.value>0)return(0,m.jsx)(`rect`,{x:t.x,y:v(t.base+t.value),width:b,height:v(t.base)-v(t.base+t.value),rx:t.topRounded?2:0,className:t.model.color===``?z.chartBar:z.chartStack,style:t.model.color===``?void 0:{fill:t.model.color}},`${t.date}-${t.model.key}`);let n=e.find(e=>e.date===t.date);return n!==void 0&&n.calls>0&&t.base===0?(0,m.jsx)(`rect`,{x:t.x,y:v(0)-1,width:b,height:1,rx:0,className:z.chartBarPlaceholder},`${t.date}-${t.model.key}-placeholder`):null}),(0,m.jsx)(`path`,{d:w,fill:`none`,className:z.chartLine}),(()=>{let t=jn(),n=e.findIndex(e=>e.date===t);return n>=0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`defs`,{children:(0,m.jsxs)(`linearGradient`,{id:`chartAreaGrad`,x1:`0%`,y1:`0%`,x2:`0%`,y2:`100%`,children:[(0,m.jsx)(`stop`,{offset:`0%`,stopColor:`var(--ds-blue)`,stopOpacity:`0.35`}),(0,m.jsx)(`stop`,{offset:`100%`,stopColor:`var(--ds-blue)`,stopOpacity:`0`})]})}),(0,m.jsx)(`path`,{d:`${w} L ${_(e.length-1)} ${y(0)} L ${_(0)} ${y(0)} Z`,fill:`url(#chartAreaGrad)`}),(0,m.jsx)(`line`,{x1:_(n),x2:_(n),y1:Y.top,y2:Y.top+g,stroke:`var(--ds-amber)`,strokeWidth:`1`,strokeDasharray:`3 3`,opacity:`0.6`}),(0,m.jsx)(`text`,{x:_(n)+4,y:Y.top-6,fill:`var(--ds-amber)`,fontSize:`10`,fontFamily:`var(--font-num)`,children:Mn(t)})]}):null})(),C.map((e,t)=>{let n=y(e);return(0,m.jsx)(`text`,{x:680-Y.right+8,y:n+3,textAnchor:`start`,className:z.chartAxisLabel,children:wn(e)},`calls-${t}`)}),ee.map(t=>{let n=e[t];return n===void 0?null:(0,m.jsx)(`text`,{x:_(t),y:214,textAnchor:`middle`,className:z.chartAxisLabel,children:Mn(n.date)},n.date)}),o!==null&&(0,m.jsx)(`line`,{x1:_(o),x2:_(o),y1:Y.top,y2:Y.top+g,className:z.chartCrosshair})]}),T!==void 0&&o!==null&&(0,m.jsxs)(`div`,{className:z.chartTooltip,style:{left:`${_(o)/680*100}%`,top:`${v(T.cost)/220*100}%`},children:[(0,m.jsx)(`div`,{className:z.chartTooltipDate,children:T.date}),r!==`tokens`&&t.filter(e=>(T.byModel?.[e.key]??0)>0).map(e=>(0,m.jsxs)(`div`,{className:z.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:e.color}}),e.name,` `,(0,m.jsx)(`strong`,{children:c(T.byModel?.[e.key]??0)})]},e.key)),(0,m.jsxs)(`div`,{className:z.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:z.chartLegendBar}),a(`trendTotal`),` `,(0,m.jsx)(`strong`,{children:r===`tokens`?wn(T.tokens??0):c(T.cost)})]}),(0,m.jsxs)(`div`,{className:z.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:z.chartLegendLine}),a(`calls`),` `,(0,m.jsx)(`strong`,{children:T.calls.toLocaleString()})]})]}),t.length>0&&r!==`tokens`&&(0,m.jsxs)(`div`,{className:z.chartLegend,children:[t.map(e=>(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:e.color}}),e.name]},e.key)),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:z.chartLegendLine}),a(`calls`)]})]})]})}let X={top:14,right:42,bottom:22,left:46};function In(e){return e.slice(5,13).replace(`T`,` `)}function Ln(e){return String(e>=100?Math.round(e):Number(e.toFixed(1)))}function Rn(e){return e<1e4?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:`${(e/6e4).toFixed(1)} min`}function zn(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:e.toFixed(1)}function Bn(e,t,n){return t===`ttft`?`${Math.round(e)} ms`:`${e.toFixed(1)} ${n(`perfTpsUnit`)}`}function Vn({perf:e,models:t,t:n}){let[r,i]=(0,d.useState)(()=>Re()),[a,o]=(0,d.useState)(null),s=e=>{i(e),ze(e)},c=e=>t.find(t=>t.key===e)?.color??`#8b95a3`,l=(0,d.useMemo)(()=>e===void 0?[]:Object.entries(e.byModel).map(([e,n])=>({key:e,name:t.find(t=>t.key===e)?.name??e,color:c(e),samples:n.samples,ttftAvg:n.ttftAvg,ttftP50:n.ttftP50,ttftP90:n.ttftP90,...n.ttftMax===void 0?{}:{ttftMax:n.ttftMax},...n.ttftSpikes===void 0?{}:{ttftSpikes:n.ttftSpikes},...n.tpsAvg===void 0?{}:{tpsAvg:n.tpsAvg},latencyAvg:n.latencyAvg,estimatedSamples:n.estimatedSamples})).sort((e,t)=>t.samples-e.samples||t.ttftP90-e.ttftP90),[e,t]),u=(0,d.useMemo)(()=>{if(e===void 0)return[];if(r.models!==void 0){let t=new Set(Object.keys(e.byModel));return r.models.filter(e=>t.has(e))}return l.slice(0,5).map(e=>e.key)},[e,l,r.models]),f=(0,d.useMemo)(()=>{if(e===void 0)return null;let t=Object.keys(e.byHourModel).sort().slice(-48);if(t.length===0)return null;let n=t.length,i=680-X.left-X.right,a=180-X.top-X.bottom,o=e=>n===1?X.left+i/2:X.left+i*e/(n-1),s=new Set(u),c=e=>r.metric===`ttft`?e?.ttftAvg:e?.tpsAvg,d=[],f=0;for(let r of l){if(!s.has(r.key))continue;let i=[];for(let a=0;a<n;a++){let n=t[a];if(n===void 0)continue;let s=c(e.byHourModel[n]?.[r.key]);s===void 0||!Number.isFinite(s)||(i.push({i:a,x:o(a),y:0,v:s}),s>f&&(f=s))}d.push({key:r.key,name:r.name,color:r.color,segments:[],points:i})}let p=d.reduce((e,t)=>e+t.points.length,0);f=Math.max(f,1);let m=e=>X.top+a-e/f*a;for(let e of d){let t=``,n=-2;for(let r of e.points)r.y=m(r.v),t!==``&&r.i!==n+1&&(e.segments.push(t),t=``),t+=`${t===``?`M`:`L`}${r.x} ${r.y} `,n=r.i;t!==``&&e.segments.push(t)}let h=Math.max(1,Math.ceil(n/8)),g=[];for(let e=0;e<n;e+=h)g.push(e);return g[g.length-1]!==n-1&&g.push(n-1),{hourKeys:t,n,plotW:i,plotH:a,inner:o,yOf:m,series:d,ticks:[0,.5,1].map(e=>f*e).reverse(),xTicks:g,totalPoints:p}},[e,l,u,r.metric]);if(e===void 0||l.length===0)return(0,m.jsx)(`div`,{className:z.chartEmpty,"data-testid":`billing-perf-empty`,children:n(`perfEmpty`)});let p=e=>{let t=u.includes(e)?u.filter(t=>t!==e):[...u,e];s({metric:r.metric,models:t})},h=e=>{s({metric:e,...r.models===void 0?{}:{models:r.models}})},g=a===null||f===null?[]:f.series.flatMap(e=>{let t=e.points.find(e=>e.i===a);return t===void 0?[]:[{key:e.key,name:e.name,color:e.color,v:t.v}]});return(0,m.jsxs)(`div`,{"data-testid":`billing-perf-panel`,children:[l.length>0&&(()=>{let e=Math.max(...l.map(e=>e.ttftAvg),1),t=Math.max(...l.filter(e=>e.tpsAvg!==void 0).map(e=>e.tpsAvg??0),1),r=Math.max(...l.map(e=>e.latencyAvg),1),i=l.reduce((e,t)=>e+t.samples,0),a=l.length>0?l.reduce((e,t)=>e+t.ttftAvg,0)/l.length:0,o=l.map(e=>e.tpsAvg).filter(e=>e!==void 0),s=o.length>0?o.reduce((e,t)=>e+t,0)/o.length:0,c=l.length>0?l.reduce((e,t)=>e+t.latencyAvg,0)/l.length:0,u=[{lbl:n(`perfSamples`),val:i.toLocaleString(),unit:``,pct:65,color:`var(--ds-blue)`},{lbl:n(`perfTtft`),val:Rn(a),unit:``,pct:a/e*100,color:`var(--ds-green)`},{lbl:n(`perfTps`),val:o.length>0?zn(s):`—`,unit:``,pct:s/t*100,color:`var(--ds-blue)`},{lbl:n(`perfLatency`),val:Rn(c),unit:``,pct:c/r*100,color:`var(--ds-amber)`}];return(0,m.jsx)(`div`,{className:z.perfHero,"data-testid":`billing-perf-hero`,children:u.map((e,t)=>(0,m.jsxs)(`div`,{className:z.perfHeroCell,children:[(0,m.jsx)(`div`,{className:z.perfHeroLbl,children:e.lbl}),(0,m.jsxs)(`div`,{className:z.perfHeroVal,children:[e.val,e.unit!==``&&(0,m.jsx)(`span`,{className:z.perfHeroUnit,children:e.unit})]}),(0,m.jsx)(`div`,{className:z.perfHeroBar,children:(0,m.jsx)(`i`,{style:{width:`${Math.min(100,e.pct)}%`,background:e.color}})})]},t))})})(),(0,m.jsx)(`div`,{className:z.tableScroll,"data-testid":`billing-perf-table`,children:(0,m.jsxs)(`table`,{className:z.modelTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:n(`model`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfSamples`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfTtft`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfP50`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfP90`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfMax`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfTps`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfLatency`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfEstimated`)})]})}),(0,m.jsx)(`tbody`,{children:l.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:(0,m.jsxs)(`span`,{className:z.modelCell,children:[(0,m.jsx)(`span`,{className:z.modelDot,style:{background:e.color}}),(0,m.jsx)(`span`,{className:z.modelName,children:e.name})]})}),(0,m.jsx)(`td`,{className:z.numCol,children:e.samples.toLocaleString()}),(0,m.jsx)(`td`,{className:z.numCol,children:Rn(e.ttftAvg)}),(0,m.jsx)(`td`,{className:z.numCol,children:Rn(e.ttftP50)}),(0,m.jsx)(`td`,{className:z.numCol,children:Rn(e.ttftP90)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.ttftMax===void 0?(0,m.jsx)(`span`,{className:z.na,children:`—`}):(0,m.jsxs)(`span`,{children:[Rn(e.ttftMax),e.ttftSpikes!==void 0&&e.ttftSpikes>0?` (${e.ttftSpikes}↑)`:``]})}),(0,m.jsx)(`td`,{className:z.numCol,children:e.tpsAvg===void 0?(0,m.jsx)(`span`,{className:z.na,children:`—`}):zn(e.tpsAvg)}),(0,m.jsx)(`td`,{className:z.numCol,children:Rn(e.latencyAvg)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.estimatedSamples>0?e.estimatedSamples:(0,m.jsx)(`span`,{className:z.na,children:`—`})})]},e.key))})]})}),l.length>0&&(()=>{let e=Math.max(...l.map(e=>e.ttftP50),1),t=e=>e<.8?`var(--ds-green)`:e<2?`var(--ds-amber)`:`var(--ds-red)`;return(0,m.jsx)(`div`,{className:z.perfCompareList,"data-testid":`billing-perf-compare`,children:l.map(n=>(0,m.jsxs)(`div`,{className:z.perfCompareRow,children:[(0,m.jsxs)(`div`,{className:z.perfCompareName,children:[(0,m.jsx)(`span`,{className:z.perfCompareDot,style:{background:n.color}}),(0,m.jsx)(`span`,{children:n.name})]}),(0,m.jsx)(`div`,{className:z.perfCompareBar,children:(0,m.jsx)(`i`,{style:{width:`${n.ttftP50/e*100}%`,background:t(n.ttftP50)}})}),(0,m.jsx)(`div`,{className:z.perfCompareNum,children:Rn(n.ttftP50)}),(0,m.jsx)(`div`,{className:z.perfCompareNum,children:n.tpsAvg===void 0?`—`:zn(n.tpsAvg)})]},n.key))})})(),f!==null&&(0,m.jsxs)(`div`,{"data-testid":`billing-perf-hour`,children:[(0,m.jsx)(`div`,{className:z.perfBar,children:(0,m.jsx)(`span`,{className:z.rangeToggle,role:`group`,"aria-label":n(`perfTitle`),children:[`ttft`,`tps`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.rangeButton,r.metric===e&&z.rangeButtonActive),"aria-pressed":r.metric===e,"data-testid":`billing-perf-tab-${e}`,onClick:()=>{h(e)},children:e===`ttft`?`${n(`perfTtft`)} (ms)`:`${n(`perfTps`)} (${n(`perfTpsUnit`)})`},e))})}),(0,m.jsxs)(`div`,{className:z.perfChips,role:`group`,"aria-label":n(`model`),children:[(0,m.jsx)(`button`,{type:`button`,className:z.perfChip,"data-testid":`billing-perf-chip-all`,onClick:()=>{s({metric:r.metric,models:l.map(e=>e.key)})},children:n(`perfAll`)}),l.map(e=>{let t=u.includes(e.key);return(0,m.jsxs)(`button`,{type:`button`,className:y(z.perfChip,!t&&z.perfChipOff),style:t?{color:e.color,borderColor:`color-mix(in srgb, ${e.color} 45%, transparent)`}:void 0,"aria-pressed":t,"data-testid":`billing-perf-chip-${e.key}`,onClick:()=>{p(e.key)},children:[(0,m.jsx)(`span`,{className:z.perfChipDot,style:{background:t?e.color:`var(--dsw-alias-label-dimmed)`}}),e.name]},e.key)})]}),f.totalPoints>0?(0,m.jsxs)(`div`,{className:z.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 180`,className:z.chartSvg,role:`img`,"aria-label":`Hourly perf comparison by model`,onMouseLeave:()=>{o(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-X.left)/f.plotW,r=Math.round(n*(f.n-1));o(Math.min(Math.max(r,0),f.n-1))},children:[f.ticks.map((e,t)=>{let n=f.yOf(e);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:X.left,x2:680-X.right,y1:n,y2:n,className:z.chartGrid}),(0,m.jsx)(`text`,{x:X.left-8,y:n+3,textAnchor:`end`,className:z.chartAxisLabel,children:Ln(e)})]},`tick-${t}`)}),f.series.map(e=>e.segments.map((t,n)=>(0,m.jsx)(`path`,{d:t,fill:`none`,className:z.chartLine,style:{stroke:e.color}},`${e.key}-${n}`))),f.xTicks.map(e=>{let t=f.hourKeys[e];return t===void 0?null:(0,m.jsx)(`text`,{x:f.inner(e),y:174,textAnchor:`middle`,className:z.chartAxisLabel,children:In(t)},t)}),a!==null&&(0,m.jsx)(`line`,{x1:f.inner(a),x2:f.inner(a),y1:X.top,y2:X.top+f.plotH,className:z.chartCrosshair}),a!==null&&f.series.map(e=>{let t=e.points.find(e=>e.i===a);return t===void 0?null:(0,m.jsx)(`circle`,{cx:t.x,cy:t.y,r:3.5,fill:e.color,className:z.chartHoverDot},`${e.key}-dot`)})]}),a!==null&&g.length>0&&(0,m.jsxs)(`div`,{className:z.chartTooltip,"data-testid":`billing-perf-tooltip`,style:{left:`${f.inner(a)/680*100}%`,top:`${(X.top+f.plotH/2)/180*100}%`},children:[(0,m.jsx)(`div`,{className:z.chartTooltipDate,children:In(f.hourKeys[a]??``)}),g.map(e=>(0,m.jsxs)(`div`,{className:z.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:e.color}}),e.name,` `,(0,m.jsx)(`strong`,{children:Bn(e.v,r.metric,n)})]},e.key))]})]}):(0,m.jsx)(`div`,{className:z.chartEmpty,"data-testid":`billing-perf-chart-empty`,children:n(`perfChartEmpty`)})]}),f===null&&(0,m.jsx)(`div`,{className:z.chartEmpty,"data-testid":`billing-perf-chart-empty`,children:n(`perfChartEmpty`)})]})}let Hn=`@kenz1117/dsh-ui-usage-billing`,Un=`kenz1117`;function Wn({t:e,version:t}){return(0,m.jsxs)(`section`,{className:z.setCard,"data-testid":`billing-plugin-info`,children:[(0,m.jsxs)(`div`,{className:z.plgHead,children:[(0,m.jsx)(`span`,{className:z.plgIcon,"aria-hidden":`true`,children:(0,m.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,m.jsx)(`path`,{d:`M10 3a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a2 2 0 0 0 4 0V4a1 1 0 0 1 1-1h1a1 1 0 0 1 1 1v1a2 2 0 0 0 4 0 1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-1a2 2 0 0 0 0 4h1a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-1a2 2 0 0 0-4 0v1a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1v-2a2 2 0 0 0-4 0v1a1 1 0 0 1-1 1h-1a1 1 0 0 1-1-1v-1a2 2 0 0 0-4 0 1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1h1a2 2 0 0 0 0-4H3a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1h1a2 2 0 0 0 4 0z`})})}),(0,m.jsxs)(`div`,{className:z.plgTitle,children:[(0,m.jsxs)(`div`,{className:z.plgNameRow,children:[(0,m.jsx)(`h3`,{className:z.plgName,children:Hn}),(0,m.jsx)(`span`,{className:z.plgTag,children:t===void 0?`—`:`v${t}`})]}),(0,m.jsx)(`p`,{className:z.plgDesc,children:`Usage billing dashboard for DeepSeek Harness`})]})]}),(0,m.jsxs)(`div`,{className:z.plgGrid,children:[(0,m.jsxs)(`div`,{className:z.plgItem,children:[(0,m.jsx)(`span`,{className:z.plgLabel,children:e(`pluginAuthor`)}),(0,m.jsxs)(`a`,{className:z.plgLink,href:`https://github.com/${Un}`,target:`_blank`,rel:`noreferrer`,children:[`KenZ`,` (`,Un,`)`]})]}),(0,m.jsxs)(`div`,{className:z.plgItem,children:[(0,m.jsx)(`span`,{className:z.plgLabel,children:e(`pluginRepository`)}),(0,m.jsx)(`a`,{className:z.plgLink,href:`https://github.com/kenz1117/dsh-ui-usage-billing`,target:`_blank`,rel:`noreferrer`,children:`GitHub`})]}),(0,m.jsxs)(`div`,{className:z.plgItem,children:[(0,m.jsx)(`span`,{className:z.plgLabel,children:e(`pluginNpm`)}),(0,m.jsx)(`a`,{className:z.plgLink,href:`https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing`,target:`_blank`,rel:`noreferrer`,children:Hn})]}),(0,m.jsxs)(`div`,{className:z.plgItem,children:[(0,m.jsx)(`span`,{className:z.plgLabel,children:e(`pluginLicense`)}),(0,m.jsx)(`span`,{className:z.plgVal,children:`MIT`})]})]})]})}function Gn(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}`}function Kn(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function qn(e){let t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m${String(t%60).padStart(2,`0`)}s`}function Jn({rounds:e,flags:t,currency:n,t:r}){let i=(0,d.useMemo)(()=>e.slice(-40),[e]),a=(0,d.useMemo)(()=>new Set(t.map(e=>`${e.sessionId}:${e.turn}`)),[t]),o=(0,d.useMemo)(()=>Math.max(1e-4,...i.map(e=>e.cost)),[i]);if(i.length===0)return(0,m.jsxs)(`div`,{className:z.roundsEmpty,children:[r(`model`),` —`]});let s=e=>dn(un(e,n),n);return(0,m.jsxs)(`div`,{className:z.rounds,children:[(0,m.jsx)(`div`,{className:z.roundsBars,role:`img`,"aria-label":`cost per turn`,children:i.map(e=>{let t=a.has(`${e.sessionId}:${e.turn}`),n=Math.max(1,e.cost/o*100),i=Pt(e.model,!1)===`deepseek-metered`&&Tt(e.startedAt)===`peak`;return(0,m.jsxs)(`div`,{className:y(z.roundsBarCol,i?z.roundsBarColPeak:z.roundsBarColOff),children:[(0,m.jsx)(`span`,{className:z.roundsBarLabel,style:{bottom:`${n}%`},children:s(e.cost)}),(0,m.jsx)(`div`,{className:z.roundsBarWrap,children:(0,m.jsx)(`div`,{className:t?z.roundsBarFlagged:z.roundsBar,style:{height:`${n}%`},"data-testid":`round-bar`,title:`${r(`model`)} ${e.model} · ${s(e.cost)} · ${Kn(e.startedAt)}${e.endedAt===void 0?``:` → ${Gn(e.endedAt)} (${qn(e.endedAt-e.startedAt)})`}`,children:t&&(0,m.jsx)(`span`,{className:z.roundsFlagMark,"aria-hidden":`true`})})})]},`${e.sessionId}:${e.turn}`)})}),(0,m.jsxs)(`div`,{className:z.roundsAxis,children:[(0,m.jsxs)(`span`,{children:[r(`costAbbr`),` `,s(o)]}),(0,m.jsxs)(`span`,{children:[i.length,` `,r(`roundsUnit`)]})]})]})}let Z=[`color-mix(in srgb, var(--dsb-3) 70%, transparent)`,`color-mix(in srgb, var(--ds-cyan) 30%, var(--dsb-3))`,`color-mix(in srgb, var(--ds-blue) 60%, var(--dsb-3))`,`var(--ds-blue)`,`var(--ds-amber)`],Yn=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Xn=e=>K(e.getTime());function Zn(e,t){let n=new Map;for(let t of e)n.set(t.date,t.value);let r=0;for(let e of n.values())e>r&&(r=e);let i=t.getFullYear(),a=t.getMonth(),o=t.getDate(),s=new Date(i,a+1,0).getDate(),c=new Date(i,a,1).getDay(),l=c+s,u=Math.ceil(l/7),d=[];for(let e=0;e<u;e+=1){let t=[];for(let l=0;l<7;l+=1){let u=e*7+l-c+1;if(u<1){let e=new Date(i,a,u);t.push({date:Xn(e),dayNum:e.getDate(),value:0,level:0,placeholder:!0});continue}if(u>s){let e=new Date(i,a+1,u-s);t.push({date:Xn(e),dayNum:e.getDate(),value:0,level:0,placeholder:!0});continue}let d=new Date(i,a,u),f=Xn(d),p=n.get(f)??0,m=0;if(p>0&&r>0){let e=Math.ceil(p/r*4);m=Math.min(4,Math.max(1,e))}let h=u>o;t.push({date:f,dayNum:u,value:h?0:p,level:h?0:m,placeholder:h})}d.push(t)}return d}function Qn(e,t,n=52){let r=new Map;for(let t of e)r.set(t.date,t.value);let i=0;for(let e of r.values())e>i&&(i=e);let a=Xn(t),o=new Date(t);o.setHours(0,0,0,0),o.setDate(o.getDate()-o.getDay());let s=new Date(o);s.setDate(o.getDate()-(n-1)*7);let c=[];for(let e=0;e<n;e+=1){let t=[];for(let n=0;n<7;n+=1){let o=new Date(s);o.setDate(s.getDate()+e*7+n);let c=Xn(o),l=c>a,u=l?0:r.get(c)??0,d=0;if(!l&&u>0&&i>0){let e=Math.ceil(u/i*4);d=Math.min(4,Math.max(1,e))}t.push({date:c,dayNum:o.getDate(),value:u,level:d,placeholder:l})}c.push(t)}return c}function $n({days:e,currency:t,now:n,t:r,range:i=`month`,unit:a=`cost`}){let[o,s]=(0,d.useState)(null),c=e=>dn(un(e,t),t),l=e=>a===`tokens`?q(e):c(e),u=(0,d.useMemo)(()=>Zn(e,n??new Date),[e,n]),f=Xn(n??new Date);if(i!==`month`){let t=Qn(e,n??new Date,i===`half`?26:52),a=[],o=-1;return t.forEach((e,t)=>{let n=Number(e[0]?.date.slice(5,7)??0);n!==o&&(a.push({index:t,label:Yn[n-1]??``}),o=n)}),(0,m.jsxs)(`div`,{className:z.heatmapYear+(i===`half`?` `+z.heatmapHalf:``),"data-testid":i===`half`?`heatmap-half`:`heatmap-year`,children:[(0,m.jsxs)(`div`,{className:z.heatmapYearBody,children:[(0,m.jsx)(`div`,{className:z.heatmapYearWeekdays,"aria-hidden":`true`,children:[{label:`Mon`,row:1},{label:`Wed`,row:3},{label:`Fri`,row:5}].map(e=>(0,m.jsx)(`span`,{className:z.heatmapYearWeekday,style:{gridRow:e.row},children:e.label},e.label))}),(0,m.jsxs)(`div`,{className:z.heatmapYearScroll,children:[(0,m.jsx)(`div`,{className:z.heatmapYearMonths,"aria-hidden":`true`,"data-testid":`heatmap-year-months`,children:a.map(e=>(0,m.jsx)(`span`,{className:z.heatmapYearMonth,style:{gridColumn:e.index+1},children:e.label},e.index))}),(0,m.jsx)(`div`,{className:z.heatmapYearGrid,role:`img`,"aria-label":`yearly cost heatmap`,"data-testid":`heatmap-year-grid`,children:t.flat().map(e=>(0,m.jsx)(`button`,{type:`button`,className:z.heatmapYearCell,"data-testid":`heatmap-year-cell`,"data-level":e.level,"data-today":e.date===f?`true`:void 0,style:{background:Z[e.level]},title:`${e.date} · ${l(e.value)}`,"aria-label":`${e.date}: ${l(e.value)}`,tabIndex:-1},e.date))})]})]}),(0,m.jsxs)(`div`,{className:z.heatmapFooter,children:[(0,m.jsx)(`span`,{children:r(`heatmapLess`)}),(0,m.jsx)(`span`,{className:z.heatmapLegend,children:Z.map((e,t)=>(0,m.jsx)(`i`,{style:{background:e}},t))}),(0,m.jsx)(`span`,{children:r(`heatmapMore`)})]})]})}return(0,m.jsxs)(`div`,{className:z.heatmap,children:[(0,m.jsx)(`div`,{className:z.heatmapGrid,role:`img`,"aria-label":`daily cost heatmap`,children:u.map(e=>e.map(e=>e.placeholder?(0,m.jsx)(`div`,{className:z.heatmapCellEmpty,children:e.dayNum},e.date):(0,m.jsx)(`button`,{type:`button`,className:z.heatmapCell,"data-testid":`heatmap-cell`,"data-level":e.level,"data-today":e.date===f?`true`:void 0,style:{background:Z[e.level]},title:`${e.date} · ${l(e.value)}`,"aria-label":`${e.date}: ${l(e.value)}`,onMouseEnter:()=>{s(e)},onMouseLeave:()=>{s(null)},onFocus:()=>{s(e)},onBlur:()=>{s(null)},children:e.dayNum},e.date)))}),(0,m.jsxs)(`div`,{className:z.heatmapFooter,children:[(0,m.jsx)(`span`,{children:r(`heatmapLess`)}),(0,m.jsx)(`span`,{className:z.heatmapLegend,children:Z.map((e,t)=>(0,m.jsx)(`i`,{style:{background:e}},t))}),(0,m.jsx)(`span`,{children:r(`heatmapMore`)}),o!==null&&(0,m.jsxs)(`span`,{className:z.heatmapHover,"data-testid":`heatmap-hover`,children:[o.date,` · `,l(o.value)]})]})]})}let er={window:6,threshold:2,reasonFactor:1.8,reasonHitDropPp:15};function tr(e){if(e.length===0)return null;let t=0;for(let n of e)t+=n;return t/e.length}function nr(e){let t=e.cacheHit+e.cacheMiss;return t<=0?null:e.cacheHit/t*100}function rr(e,t){let n=t?.window??er.window,r=t?.threshold??er.threshold,i=t?.reasonFactor??er.reasonFactor,a=t?.reasonHitDropPp??er.reasonHitDropPp,o=[];if(n<=0||r<=0)return o;let s=[],c=[],l=[],u=[];for(let t of e){if(t.cost<=0)continue;let e=t.output,d=t.input,f=nr(t),p=tr(s),m=[];if(p!==null&&p>0&&t.cost>p*r){let n=tr(c),r=tr(l),s=tr(u);n!==null&&n>0&&e>n*i&&m.push(`output-growth`),r!==null&&r>0&&d>r*i&&m.push(`context-bloat`),s!==null&&f!==null&&f<s-a&&m.push(`cache-hit-drop`),o.push({sessionId:t.sessionId,turn:t.turn,cost:t.cost,reasons:m})}for(s.push(t.cost),c.push(e),l.push(d),f!==null&&u.push(f);s.length>n;)s.shift();for(;c.length>n;)c.shift();for(;l.length>n;)l.shift();for(;u.length>n;)u.shift()}return o}let ir={},ar={};function or(){return(0,h.defineStore)({init:()=>({enabled:!1,amount:0,tierAlertDays:{},lastBalanceAlertDay:``,lastTierSwitchAt:0,modelBudgets:{},modelTierAlertDays:{}}),persist:`dsh.ui-usage-billing.budget`,actions:{setEnabled:(e,t)=>{e.enabled=t},setAmount:(e,t)=>{e.amount=Number.isFinite(t)&&t>0?t:0},markTierAlerted:(e,t,n)=>{e.tierAlertDays??={};for(let r of t)e.tierAlertDays[String(r)]=n},markBalanceAlerted:(e,t)=>{e.lastBalanceAlertDay=t},markTierSwitchAlerted:(e,t)=>{e.lastTierSwitchAt=t},setModelBudget:(e,t,n)=>{e.modelBudgets??={},Number.isFinite(n)&&n>0?e.modelBudgets[t]=n:delete e.modelBudgets[t]},markModelTierAlerted:(e,t,n)=>{e.modelTierAlertDays??={};for(let r of t)e.modelTierAlertDays[r]=n}}})}function sr(e,t){return e==null?null:Number.isFinite(e.nextSwitchInMs)&&e.nextSwitchInMs<=t?`soon`:e.tier===`peak`?`peak`:`offPeak`}let cr={显式缓存创建:`Explicit cache write`,显式缓存命中:`Explicit cache hit`,长期半价:`Half price`,与标准价一致:`Same as standard`,"限时 5 折":`Limited-time 50% off`};function lr(e,t){return e===void 0||t!==`en`?e:cr[e]??e}function ur(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>e.key.toLowerCase().includes(n)||(e.name??``).toLowerCase().includes(n)||(e.provider??``).toLowerCase().includes(n))}let dr={"智谱 AI":`Zhipu AI`,阿里通义:`Alibaba Qwen`,字节豆包:`ByteDance Doubao`,月之暗面:`Moonshot AI`,小米:`Xiaomi`,百度文心:`Baidu ERNIE`,腾讯混元:`Tencent Hunyuan`,零一万物:`01.AI`,阶跃星辰:`StepFun`,科大讯飞:`iFlytek Spark`,商汤:`SenseNova`,百川智能:`Baichuan`,"小米 Token Plan(海外)":`Xiaomi Token Plan (Global)`,"小米 Token Plan(国内)":`Xiaomi Token Plan (CN)`,"小米 Token Plan(新加坡)":`Xiaomi Token Plan (SG)`,"火山引擎 Token Plan":`Volcengine Token Plan`,"火山方舟 Token Plan":`Volcengine Ark Token Plan`,"豆包 Token Plan":`Doubao Token Plan`,"百度文心 Plan":`Baidu ERNIE Plan`,"MiniMax Token Plan(国内)":`MiniMax Token Plan (CN)`};function fr(e,t){return t===`en`?dr[e]??e:e}let pr={workbuddy:`WorkBuddy`,"workbuddy-ai":`WorkBuddy AI`},mr={"https://tokenhub.tencentmaas.com":`腾讯云 TokenHub`,"https://api.lkeap.cloud.tencent.com":`腾讯云 Token Plan`,"https://api.deepseek.com":`DeepSeek 官方`},hr={"腾讯云 TokenHub":`Tencent Cloud TokenHub`,"腾讯云 Token Plan":`Tencent Cloud Token Plan`,"DeepSeek 官方":`DeepSeek Official`};function gr(e){try{return new URL(e).host}catch{return e}}function _r(e,t=`zh`){if(e.startsWith(`site:`)){let n=e.slice(5),r=mr[n];return r===void 0?gr(n):t===`en`?hr[r]??r:r}if(e.startsWith(`direct:`)){let n=e.slice(7);if(/^deepseek(?:-[a-z0-9-]+)?$/i.test(n))return t===`en`?`DeepSeek Official`:`DeepSeek 官方`;let r=pr[n.trim().toLowerCase()];return r===void 0?`${t===`en`?`Direct`:`直连`} · ${n}`:`${t===`en`?`Direct`:`直连`} · ${r}`}}let vr=[`直连 · `,`Direct · `];function yr(e){for(let t of vr)if(e.startsWith(t))return e.slice(t.length)}let br=`dsh-billing-peak-alert-v1`,xr={enabled:!1,leadMin:2,position:`bottom-right`,webNotify:!0,mode:`both`};function Sr(e,t,n){return t===null||n<=0?e:e===null?{...t,queueCount:n}:e.atMs===t.atMs&&e.entering===t.entering?{...e,queueCount:n}:e}function Cr(e,t){if(e===null||e.queueCount===void 0)return e;if(t>0)return e.queueCount===t?e:{...e,queueCount:t};let{queueCount:n,...r}=e;return r}function wr(){try{let e=localStorage.getItem(br);if(e===null)return{...xr};let t=JSON.parse(e),n=t.mode===`peak`||t.mode===`offPeak`?t.mode:xr.mode,r=t.position===`center`?`center`:`bottom-right`;return{enabled:t.enabled===!0,leadMin:typeof t.leadMin==`number`&&Number.isFinite(t.leadMin)?Math.min(30,Math.max(1,Math.round(t.leadMin))):xr.leadMin,position:r,webNotify:t.webNotify!==!1,mode:n}}catch{return{...xr}}}function Tr(e){try{localStorage.setItem(br,JSON.stringify(e))}catch{x(`peak-config-storage-unavailable`)}}function Er(e,t,n,r){if(!t.enabled)return null;let i=It(e,r,t.leadMin*6e4);return i===null||t.mode===`peak`&&i.entering!==`peak`||t.mode===`offPeak`&&i.entering!==`offPeak`||i.atMs===n?null:{...i,channel:r}}function Dr({hit:e,config:t,t:n,onDismiss:r}){let[i,a]=(0,d.useState)(()=>Date.now());if((0,d.useEffect)(()=>{let e=setInterval(()=>a(Date.now()),3e4);return()=>clearInterval(e)},[]),(0,d.useEffect)(()=>{i>=e.atMs&&r()},[i,e.atMs,r]),i>=e.atMs)return null;let o=Math.max(1,Math.round((e.atMs-i)/6e4)),s=e.entering,c=n(s===`peak`?`tierPeak`:`tierOff`),l=n(e.channel===`zhipu-coding-plan`?s===`peak`?`peakAlertDescPeakZhipu`:`peakAlertDescOffZhipu`:s===`peak`?`peakAlertDescPeak`:`peakAlertDescOff`),u=s===`peak`;return(0,m.jsxs)(`div`,{className:y(z.peakCard,u?z.peakCardPeak:z.peakCardOff,t.position===`center`?z.peakCardCenter:z.peakCardCorner),"data-testid":`billing-peak-alert`,role:`alert`,children:[(0,m.jsxs)(`div`,{className:z.peakHead,children:[(0,m.jsxs)(`span`,{className:y(z.peakTag,u?z.peakTagPrimary:z.peakTagSuccess),children:[(0,m.jsx)(`span`,{className:y(z.peakDot,u?z.peakDotPrimary:z.peakDotSuccess),"aria-hidden":`true`}),c]}),(0,m.jsx)(`button`,{type:`button`,className:z.peakClose,onClick:r,"aria-label":n(`close`),children:`×`})]}),(0,m.jsxs)(`div`,{className:y(z.peakCount,u?z.peakCountPrimary:z.peakCountSuccess),children:[o,`min`]}),(0,m.jsx)(`p`,{className:z.peakDesc,children:l}),e.queueCount!==void 0&&e.queueCount>0&&(0,m.jsx)(`p`,{className:z.peakDesc,"data-testid":`billing-peak-queue-note`,children:n(s===`peak`?`peakAlertQueuePeak`:`peakAlertQueueOff`,{count:e.queueCount})})]})}let Or=[50,80,100],kr=3e4,Ar={total:{calls:0,input:0,output:0,cacheHit:0,cacheMiss:0,cost:0,reasoning:0},byModel:{},byDay:{},byDayModels:{}},jr=[`#4f8cff`,`#2dd4bf`,`#a78bfa`,`#f59e0b`,`#f472b6`,`#fbbf24`,`#38bdf8`,`#6366f1`,`#f97316`,`#14b8a6`],Mr={checked:!1,available:!1,models:0,failures:0,okProviders:[],badProviders:[]},Nr=[{id:`overview`,labelKey:`tabOverview`},{id:`queue`,labelKey:`tabQueue`},{id:`providers`,labelKey:`tabProviders`},{id:`token`,labelKey:`tabToken`},{id:`trends`,labelKey:`tabTrends`},{id:`agents`,labelKey:`tabAgents`},{id:`pricing`,labelKey:`tabPricing`},{id:`settings`,labelKey:`tabSettings`}],Pr={fill:`none`,"aria-hidden":!0,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`},Fr={overview:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:(0,m.jsx)(`path`,{d:`M2 13V3M2 13H14M4 10l4-3 2 2 4-5`})}),queue:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`path`,{d:`M3 4h10M3 8h10M3 12h6`}),(0,m.jsx)(`path`,{d:`M12 10v4m-2-2h4`})]}),agents:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`3.5`,r:`2`}),(0,m.jsx)(`circle`,{cx:`3.5`,cy:`12.5`,r:`2`}),(0,m.jsx)(`circle`,{cx:`12.5`,cy:`12.5`,r:`2`}),(0,m.jsx)(`path`,{d:`M8 5.5v2.5M6.5 10.5L5 11.5M9.5 10.5L11 11.5`})]}),providers:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`rect`,{x:`2`,y:`3`,width:`12`,height:`10`,rx:`1.5`}),(0,m.jsx)(`path`,{d:`M5 7l2 2 4-4`})]}),token:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`circle`,{cx:`6`,cy:`6`,r:`3`}),(0,m.jsx)(`circle`,{cx:`11`,cy:`11`,r:`3`})]}),trends:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:(0,m.jsx)(`path`,{d:`M2 4l4 4 3-3 5 5M11 10h3V7`})}),pricing:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`path`,{d:`M8 2l6 3v6l-6 3-6-3V5z`}),(0,m.jsx)(`path`,{d:`M8 2v12M2 5h12`})]}),settings:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`2.5`}),(0,m.jsx)(`path`,{d:`M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2`})]})},Ir=p,Lr=Ir.IconChevronDownOutlineMedium??Ir.IconChevronDownOutline14;function Rr(e,t){let n=Object.keys(e).filter(e=>e<=t).sort().slice(-7);return n.length===0?0:n.reduce((t,n)=>t+(e[n]?.cost??0),0)/n.length}function zr(e,t){let n=t.split(`-`),r=new Date(Number(n[0]),Number(n[1])-1,Number(n[2])),i=0;for(let t=0;t<7;t+=1){let t=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`;i+=e[t]?.cost??0,r.setDate(r.getDate()-1)}return i/7}function Br(e,t,n){let r=Object.keys(e).filter(e=>e.startsWith(t)).reduce((t,n)=>t+(e[n]?.cost??0),0),i=t.split(`-`),a=new Date(Number(i[0]),Number(i[1]),0).getDate(),o=n.startsWith(t)?Number(n.slice(8,10)):a,s=Math.max(0,a-o);return r<=0?Rr(e,n)*s:r+zr(e,n)*s}function Vr(e){return Object.keys(e).length}function Hr(e,t=Date.now()){let n=0,r=new Date(t);for(;K(r.getTime())in e;)n+=1,r.setDate(r.getDate()-1);return n}function Ur(e){return e.input+e.output}function Wr(e){let t=[];for(let n=6;n>=0;--n){let r=new Date;r.setDate(r.getDate()-n);let i=K(r.getTime());t.push({date:i,cost:e[i]?.cost??0})}return t}function Gr(e,t,n=e=>e.cost){let r=new Date(`${t}T00:00:00`),i=(r.getDay()+6)%7,a=0;for(let t=0;t<=i;t+=1){let i=new Date(r);i.setDate(i.getDate()-t);let o=e[K(i.getTime())];o!==void 0&&(a+=n(o))}return a}function Kr(e,t,n){let r=new Date(`${t}T00:00:00`),i=(r.getDay()+6)%7,a=new Date(r);a.setDate(a.getDate()-i);let o=K(a.getTime()),s=new Date(r);s.setDate(s.getDate()-6);let c=K(s.getTime());return Jr(e,e=>n===`today`?e===t:n===`7d`?e>=c&&e<=t:n===`week`?e>=o&&e<=t:e.startsWith(t.slice(0,7)))}function qr(e,t,n){return Jr(e,e=>e>=t&&e<=n)}function Jr(e,t){let n=0,r=0,i=0,a=0,o=0,s=0,c=0,l=0,u,d=0;for(let[f,p]of Object.entries(e)){if(!t(f))continue;n+=p.cost,r+=p.calls,i+=p.input,a+=p.output,o+=p.cacheHit,s+=p.cacheMiss,c+=p.cacheWrite??0,l+=p.reasoning??0;let e=Ur(p);e>d&&(d=e,u=f)}return{cost:n,calls:r,input:i,output:a,cacheHit:o,cacheMiss:s,cacheWrite:c,reasoning:l,peakDay:u,peakTokens:d}}function Yr(e,t){let n={};if(e===void 0)return n;for(let[r,i]of Object.entries(e))if(r.startsWith(t))for(let[e,t]of Object.entries(i))n[e]=(n[e]??0)+t.cost;return n}let Xr=[80,100];function Zr(e,t){if(!(t>0)||!(e>0))return[];let n=e/t*100;return Xr.filter(e=>n>=e)}let Qr={DeepSeek:[`deepseek`],"智谱 AI":[`zhipu`,`glm`,`z.ai`],阿里通义:[`qwen`,`tongyi`,`dashscope`,`aliyun`],字节豆包:[`doubao`,`volcengine`,`ark`],月之暗面:[`moonshot`,`kimi`],小米:[`xiaomi`,`mi`,`mimo`],MiniMax:[`minimax`],百度文心:[`ernie`,`wenxin`,`qianfan`,`baidu`],腾讯混元:[`hunyuan`,`tencent`],零一万物:[`01.ai`,`lingyi`,`yi`],阶跃星辰:[`step`,`stepfun`,`step-3.7`],科大讯飞:[`spark`,`xfyun`,`iflytek`],商汤:[`sensenova`,`sensetime`],百川智能:[`baichuan`],OpenAI:[`openai`],Google:[`google`,`gemini`],xAI:[`xai`,`grok`],Meta:[`meta`,`llama`],Anthropic:[`claude`,`anthropic`],"Mistral AI":[`mistral`,`ministral`,`devstral`],Cohere:[`cohere`,`command`],美团:[`longcat`,`meituan`],面壁智能:[`minicpm`,`modelbest`],小红书:[`dots`,`rednote`,`xiaohongshu`],云知声:[`unisound`,`u2`]};function Q(e){return e.trim().toLowerCase().replace(/[\s_/-]+/g,``)}function $r(e,t){if(e.length===0||t.length===0)return!1;if(e===t)return!0;let[n,r]=e.length<=t.length?[e,t]:[t,e];return n.length>=3&&r.includes(n)}function ei(e,t){let n=Q(e),r=Q(t);if($r(n,r))return!0;let i=Qr[e];return i!==void 0&&i.some(e=>$r(Q(e),r))}function ti(e){let t=e.trim().toLowerCase(),n=t.replace(/[\s_/-]+/g,``);if(n.length!==0){for(let[e,n]of Object.entries(Qr))for(let r of n){let n=Q(r);if(n.length!==0&&(t===n||t.startsWith(`${n}-`)||t.startsWith(`${n}/`)||t.startsWith(`${n}_`)||t.includes(`${n}-`)||t.includes(`${n}/`)||t.includes(`${n}_`)))return e}for(let[e,t]of Object.entries(Qr))for(let r of t){let t=Q(r);if(!(t.length<4)&&n.includes(t))return e}}}let ni={"kimi-coding":`月之暗面`,"zai-coding-cn":`智谱 AI`,"zai-coding":`智谱 AI`,"qwen-token-plan":`阿里通义`,"qwen-token-plan-cn":`阿里通义`,"xiaomi-token-plan-ams":`小米`,"xiaomi-token-plan-cn":`小米`,"xiaomi-token-plan-sgp":`小米`,"volcengine-token-plan":`字节豆包`,"ark-token-plan":`字节豆包`,"doubao-token-plan":`字节豆包`,ernie:`百度文心`,baidu:`百度文心`,wenxin:`百度文心`,minimax:`MiniMax`,"minimax-cn":`MiniMax`,"minimax-token-plan":`MiniMax`,"minimax-token-plan-cn":`MiniMax`,"hunyuan-token-plan":`腾讯混元`,"tencent-token-plan":`腾讯混元`,"hy-token-plan":`腾讯混元`,"xinghuo-token-plan":`讯飞星火`,"xfyun-coding":`讯飞星火`,"spark-coding":`讯飞星火`,"huawei-token-plan":`华为云`,"pangu-token-plan":`华为云`,"huawei-maas-token-plan":`华为云`,"volcengine-agent-plan":`字节豆包`,"ark-agent-plan":`字节豆包`,"baidu-token-plan":`百度文心`,"ernie-token-plan":`百度文心`,"wenxin-token-plan":`百度文心`,opencode:`OpenCode`,"opencode-go":`OpenCode`};function ri(e){let t=ni[e];return t===void 0?ti(e)??e:t}let ii=`https://platform.kimi.com/console/pay`,ai=`https://open.bigmodel.cn/finance-center/finance/pay`,oi=`https://bailian.console.aliyun.com/`,si=`https://console.volcengine.com/ark`,ci=`https://console.anthropic.com/settings/billing`,li=`https://console.cloud.google.com/billing`,ui=`https://console.x.ai/`,di=`https://platform.xiaomimimo.com/console/balance`,fi=`https://console.cloud.tencent.com/expense/recharge`,pi={deepseek:`https://platform.deepseek.com/top_up`,minimax:`https://platform.minimax.cn/console/recharge-records`,moonshot:ii,kimi:ii,zhipu:ai,bigmodel:ai,qwen:oi,dashscope:oi,doubao:si,volcengine:si,ark:si,openai:`https://platform.openai.com/settings/organization/billing`,anthropic:ci,claude:ci,google:li,gemini:li,xai:ui,grok:ui,siliconflow:`https://cloud.siliconflow.cn/account/charge`,hunyuan:fi,tencent:fi,腾讯云:fi,xiaomi:di,mimo:di,mi:di,qianfan:`https://console.bce.baidu.com/qianfan/overview`};function mi(e){let t=pi[e];if(t!==void 0)return t;let n=Object.keys(pi).find(t=>e.startsWith(t));return n===void 0?void 0:pi[n]}function hi(e){let t=Q(e),n=mi(t);if(n!==void 0)return n;for(let[e,n]of Object.entries(Qr))if($r(Q(e),t))for(let e of n){let t=mi(Q(e));if(t!==void 0)return t}}function gi(e){let t=pt();if(t===void 0||e.byDayModels===void 0)return e;let n=St().rate,r=e.byDayModelsSite!==void 0,i={},a={},o=new Map,s=0,c=e=>t.some(t=>t.origin!==void 0&&t.origin!==``&&(t.key===e||G(t.key)===G(e))),l=(e,t,r)=>{if(e===void 0)return r;let i=Math.min(t.cacheHit,t.cacheMiss+t.cacheHit),a=r=>{let a=(t.cacheMiss*r.input+i*r.cacheHit+t.output*r.output)/1e6;return e.currency===`USD`?a*n:a};return e.offPeak===void 0?a(e):a(e)*wt+a(e.offPeak)*.5};for(let[t,n]of Object.entries(e.byDayModels)){let u=0,d={};for(let[i,a]of Object.entries(n)){let n=ht(i)??_t(i),s=r&&c(i),f;if(s&&e.byDayModelsSite?.[t]?.[i]!==void 0){let r=0;for(let[a,o]of Object.entries(e.byDayModelsSite[t][i])){let e=a.startsWith(`site:`)?a.slice(5):void 0,t=e===void 0?void 0:ht(i,e);r+=l(t??n,o,o.cost)}f=r}else f=l(n,a,a.cost);u+=f,d[i]={...a,cost:f},o.set(i,(o.get(i)??0)+f)}let f=e.byDay[t];f!==void 0&&(i[t]={...f,cost:u}),a[t]=d,s+=u}return{...e,total:{...e.total,cost:s},byDay:i,byDayModels:a,byModel:Object.fromEntries(Object.entries(e.byModel).map(([e,t])=>{let n=o.get(e);return[e,n===void 0?t:{...t,cost:n}]})),unpricedModels:(e.unpricedModels??[]).filter(e=>!ht(e)&&!_t(e))}}async function _i(e,t={}){let{timeoutMs:n=12e3,signal:r,...i}=t,a=new AbortController,o=setTimeout(()=>{a.abort()},n),s=()=>{a.abort()};r!=null&&(r.aborted?a.abort():r.addEventListener(`abort`,s,{once:!0}));try{return await fetch(e,{...i,signal:a.signal})}finally{clearTimeout(o),r?.removeEventListener(`abort`,s)}}let vi=new Set;function yi(){return typeof Notification<`u`&&Notification.permission===`granted`}function bi(e,t){vi.has(e)||(vi.add(e),_i(`/api/billing/notify-claim`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({key:e})}).then(e=>e.json()).then(e=>{e.claimed!==!1&&t()}).catch(()=>t()))}function xi(e){let t=new Map,n=[];for(let r of e){if(r.title===void 0||r.title===``){n.push(r);continue}let e=t.get(r.title);if(e===void 0){let e={...r,mergedCount:1};t.set(r.title,e),n.push(e);continue}e.children===void 0&&(e.children=[{...e}]),e.children.push({...r}),e.calls+=r.calls,e.cost+=r.cost,e.lastActive=Math.max(e.lastActive,r.lastActive),r.stale===!0&&(e.stale=!0),e.mergedCount=(e.mergedCount??1)+1}return n.sort((e,t)=>t.cost-e.cost||t.lastActive-e.lastActive)}function Si(e){let t=new Map(e.map(e=>[e.id,e])),n=xi(e.filter(e=>e.parentId===void 0)),r=new Map;for(let e of n){r.set(e.id,e);for(let t of e.children??[])r.set(t.id,e)}let i=new Set,a=new Map,o=(e,t)=>{e.subs===void 0?e.subs=[t]:e.subs.push(t),i.add(t.id),a.set(t.id,e.id)};for(let n of e){if(n.parentId===void 0)continue;let e=t.get(n.parentId);if(e!==void 0&&e.parentId!==void 0&&e.id!==n.id){let t=e.id,r=new Set,i=!1;for(;t!==void 0&&!r.has(t);){if(r.add(t),t===n.id){i=!0;break}t=a.get(t)}if(!i){o(e,n);continue}}let s=new Set,c=n.parentId;for(;c!==void 0&&!s.has(c);){s.add(c);let e=r.get(c);if(e!==void 0){i.has(n.id)||o(e,n);break}c=t.get(c)?.parentId}}let s=e=>e.cost+(e.subCost??0),c=e=>{e.subs?.sort((e,t)=>s(t)-s(e)||t.lastActive-e.lastActive);for(let t of e.subs??[])c(t)};for(let e of n)c(e);let l=e.filter(e=>e.parentId!==void 0&&!i.has(e.id));for(let e of l)c(e);return[...n,...l].sort((e,t)=>t.cost-e.cost||t.lastActive-e.lastActive)}function Ci(e){let t=new Map;for(let n of e)t.has(n.id)||t.set(n.id,n);let n=new Map,r=[];for(let i of e){let e=i.parentId;if(e===void 0||!t.has(e)||wi(t,i.id)){r.push(i);continue}let a=n.get(e);a===void 0?n.set(e,[i]):a.push(i)}let i=(e,t,r)=>{let a=new Set(r);a.add(e.id);let o=(n.get(e.id)??[]).filter(e=>!r.has(e.id)).map(e=>i(e,t+1,a)).sort((e,t)=>t.chainCost-e.chainCost),s={id:e.id,...e.title===void 0?{}:{title:e.title},...e.cwd===void 0?{}:{cwd:e.cwd},calls:e.calls,cost:e.cost,lastActive:e.lastActive,chainCost:e.cost,chainCalls:e.calls,children:o,depth:t};for(let e of o)s.chainCost+=e.chainCost,s.chainCalls+=e.chainCalls;return s};return r.map(e=>i(e,0,new Set)).sort((e,t)=>t.chainCost-e.chainCost)}function wi(e,t){let n=new Set([t]),r=e.get(t)?.parentId;for(;r!==void 0;){if(n.has(r))return!0;n.add(r),r=e.get(r)?.parentId}return!1}function Ti(e){let t=0,n=0,r,i=e=>{t+=1,n+=e.children.length,(r===void 0||e.chainCost>r.chainCost)&&(r=e);for(let t of e.children)i(t)};for(let t of e)i(t);return{agents:t,delegations:n,roots:e.length,...r===void 0?{}:{costliest:r}}}function Ei(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>(e.title??``).toLowerCase().includes(n)||(e.cwd??``).toLowerCase().includes(n)||e.id.toLowerCase().includes(n))}function Di(e,t){let n=e.trim().toLowerCase();return n!==``&&!t.some(e=>e.toLowerCase().includes(n))}function Oi(e,t){return e.checked?e.okProviders.some(e=>ei(t,e))?z.healthOk:e.badProviders.some(e=>ei(t,e))?z.healthBad:z.healthIdle:z.healthIdle}function ki(e,t){switch(e){case`ok`:return``;case`not-configured`:return t(`subscriptionNotConfigured`);case`unauthorized`:return t(`subscriptionUnauthorized`);case`rate-limited`:return t(`subscriptionRateLimited`);case`invalid-response`:return t(`subscriptionInvalid`);default:return t(`subscriptionUnavailable`)}}function Ai(e,t){switch(e){case`session`:return t(`subscriptionSession`);case`weekly`:return t(`subscriptionWeekly`);case`monthly`:return t(`subscriptionMonthly`);case`billing`:return t(`subscriptionBilling`)}}function ji(e,t){switch(e){case`new-api`:return t(`relayKindNewApi`);case`sub2api`:return t(`relayKindSub2Api`);default:return t(`relayKindUnknown`)}}let Mi={"new-api":z.siteKindSite,sub2api:z.siteKindDirect,unknown:z.siteKindUnknown},Ni=e=>e.models.reduce((e,t)=>e+(t.actual??(t.plan===!0?0:t.estimated)),0);function Pi(e){return e.children===void 0?{cost:e.subCost??0,calls:e.subCalls??0}:(e.children??[]).reduce((e,t)=>({cost:e.cost+(t.subCost??0),calls:e.calls+(t.subCalls??0)}),{cost:0,calls:0})}function Fi(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}async function Ii(){try{let e=await _i(`/api/billing/usage-stats`);if(!e.ok)return null;let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n||!(`total`in n))return null;let r=n,i=e=>typeof e==`object`&&!!e;return{total:r.total??Ar.total,byModel:r.byModel??{},byDay:r.byDay??{},...r.byDayModels===void 0?{}:{byDayModels:r.byDayModels},...i(r.byDayModelsSite)?{byDayModelsSite:r.byDayModelsSite}:{},...r.updatedAt===void 0?{}:{updatedAt:r.updatedAt},...r.staleSnapshot===!0?{staleSnapshot:!0}:{},...typeof r.budget==`number`?{budget:r.budget}:{},...typeof r.lowBalanceThreshold==`number`?{lowBalanceThreshold:r.lowBalanceThreshold}:{},...Array.isArray(r.bySession)?{bySession:r.bySession}:{},...Array.isArray(r.byTurn)?{byTurn:r.byTurn}:{},...Array.isArray(r.byWorkspace)?{byWorkspace:r.byWorkspace}:{},...i(r.bySite)?{bySite:r.bySite}:{},...i(r.byTier)?{byTier:r.byTier}:{},...i(r.byTool)?{byTool:r.byTool}:{},...Array.isArray(r.unpricedModels)?{unpricedModels:r.unpricedModels}:{},...typeof r.staleLedgerSessions==`number`?{staleLedgerSessions:r.staleLedgerSessions}:{},...typeof r.unreadableSessions==`number`?{unreadableSessions:r.unreadableSessions}:{},...typeof r.unreadableFormatSessions==`number`?{unreadableFormatSessions:r.unreadableFormatSessions}:{},...typeof r.unreadableNoLedgerSessions==`number`?{unreadableNoLedgerSessions:r.unreadableNoLedgerSessions}:{},...typeof r.searchCallEstimateCny==`number`?{searchCallEstimateCny:r.searchCallEstimateCny}:{},...r.byRole!==null&&typeof r.byRole==`object`?{byRole:r.byRole}:{},...r.perf!==null&&typeof r.perf==`object`&&r.perf.byModel!==null&&typeof r.perf.byModel==`object`&&r.perf.byHourModel!==null&&typeof r.perf.byHourModel==`object`?{perf:r.perf}:{},...typeof r.pluginVersion==`string`?{pluginVersion:r.pluginVersion}:{}}}catch{return null}}async function Li(){try{let e=await _i(`/api/billing/balance`);if(!e.ok)return{balances:[]};let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n)return{balances:[]};let r=n;return{balances:Array.isArray(r.balances)?r.balances:[],...r.reconcile===void 0?{}:{reconcile:r.reconcile},...r.stale===!0?{stale:!0}:{}}}catch{return{balances:[]}}}async function Ri(){let e=await _i(`/api/billing/subscriptions`);if(!e.ok)throw Error(`subscriptions HTTP ${String(e.status)}`);let t=await e.text(),n=JSON.parse(t);if(typeof n==`object`&&n&&`quotas`in n){let e=n;return{quotas:e.quotas,...e.stale===!0?{stale:!0}:{}}}throw Error(`subscriptions: invalid response`)}async function zi(){let e=await _i(`/api/billing/relay-quotas`);if(!e.ok)throw Error(`relay-quotas HTTP ${String(e.status)}`);let t=await e.text(),n=JSON.parse(t);if(typeof n==`object`&&n&&`quotas`in n)return n.quotas;throw Error(`relay-quotas: invalid response`)}async function Bi(){try{let e=await _i(`/api/billing/usage-tool`);if(!e.ok)return;let t=JSON.parse(await e.text());return typeof t.enabled==`boolean`?t.enabled:void 0}catch{return}}async function Vi(e){try{let t=await _i(`/api/billing/usage-tool`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({enabled:e})});return t.ok?JSON.parse(await t.text()).ok===!0:!1}catch{return!1}}let Hi=!1,Ui=0;async function Wi(e=0){try{let t=await _i(`/api/billing/pricing`);if(!t.ok){Hi=!1;return}let n=await t.text(),r=JSON.parse(n);if(typeof r!=`object`||!r||!(`source`in r)){Hi=!1;return}let i=r;Array.isArray(i.catalog)&&i.catalog.length>0&&i.aliases!==null&&typeof i.aliases==`object`&&W(i.catalog,i.aliases);let a=r;if(a.source===`builtin`&&e<3){if(e===0){if(Hi)return;Hi=!0}setTimeout(()=>{Wi(e+1)},2e3);return}Hi=!1,Ui=a.syncedAt??0,vt(a)}catch{Hi=!1}}async function Gi(){try{return(await _i(`/api/billing/pricing/refresh`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`,timeoutMs:3e4})).ok?(await Wi(),!0):!1}catch{return!1}}async function Ki(e){try{let t=JSON.parse(await e.text());return typeof t.error==`string`?t.error:`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}async function qi(e=!1){let t=await _i(`/api/billing/task-queue${e?`?refresh=1`:``}`);if(!t.ok)throw Error(await Ki(t));return await t.json()}async function Ji(){let e=await _i(`/api/billing/task-queue-summary`);if(!e.ok)throw Error(await Ki(e));return await e.json()}async function Yi(e){let t=await _i(`/api/billing/task-queue`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Ki(t));return(await t.json()).snapshot}let Xi=`@kenz1117/dsh-ui-usage-billing/TaskQueuePanel.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Xi)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@kenz1117/dsh-ui-usage-billing`,e.dataset.pluginCss=Xi,e.textContent=`.cQSERa_queuePanel{color:var(--ds-t-1);flex-direction:column;flex-shrink:0;gap:12px;display:flex}.cQSERa_queuePanel *{box-sizing:border-box}.cQSERa_queueHero,.cQSERa_queueComposer,.cQSERa_queueListSection,.cQSERa_queueUnsupported{border:1px solid var(--ds-border);border-radius:var(--ds-r-2);background:var(--dsb-2);flex-shrink:0}.cQSERa_queueHero{justify-content:space-between;align-items:center;gap:16px;padding:16px;display:flex}.cQSERa_queueTitleRow{align-items:center;gap:8px;display:flex}.cQSERa_queueTitle,.cQSERa_queueListHead h3,.cQSERa_queueUnsupported h3{margin:0;font-size:15px;font-weight:650}.cQSERa_queuePreview{background:var(--ds-violet-soft);color:var(--ds-violet);text-transform:uppercase;border-radius:5px;padding:2px 6px;font-size:10px;font-weight:700}.cQSERa_queueSubtitle{color:var(--ds-t-2);margin:5px 0 0;font-size:12px;line-height:1.6}.cQSERa_queueBand{color:var(--ds-t-2);flex-direction:column;flex-shrink:0;align-items:flex-end;gap:3px;font-size:11px;display:flex}.cQSERa_queueBand strong{font-size:13px}.cQSERa_queueBandOff strong{color:var(--ds-green)}.cQSERa_queueBandPeak strong{color:var(--ds-amber)}.cQSERa_queueComposer{flex-direction:column;gap:12px;padding:14px;display:flex}.cQSERa_queueSafety{border-radius:var(--ds-r-1);background:color-mix(in srgb, var(--ds-amber) 8%, transparent);color:var(--ds-t-2);padding:9px 11px;font-size:11px;line-height:1.65}.cQSERa_queueSelectors{grid-template-columns:1fr 1fr;gap:10px;display:grid}.cQSERa_queueField,.cQSERa_queuePromptField{color:var(--ds-t-2);flex-direction:column;gap:6px;font-size:11px;display:flex}.cQSERa_queueField select,.cQSERa_queuePromptField textarea{border:1px solid var(--ds-border);border-radius:var(--ds-r-1);background:var(--dsb);width:100%;color:var(--ds-t-1);font:inherit}.cQSERa_queueField select{height:34px;padding:0 9px}.cQSERa_queuePromptField textarea{resize:vertical;min-height:112px;padding:10px;line-height:1.55}.cQSERa_queueField select:focus,.cQSERa_queuePromptField textarea:focus{outline:2px solid color-mix(in srgb, var(--ds-blue) 35%, transparent);border-color:var(--ds-blue)}.cQSERa_queueField select:disabled,.cQSERa_queuePromptField textarea:disabled{opacity:.55}.cQSERa_queueComposerFooter{color:var(--ds-t-3);justify-content:space-between;align-items:center;gap:12px;font-size:10px;line-height:1.5;display:flex}.cQSERa_queueComposerActions{flex-shrink:0;align-items:center;gap:8px;display:flex}.cQSERa_queueFileInput{display:none}.cQSERa_queuePrimary,.cQSERa_queueSecondary{border-radius:var(--ds-r-1);cursor:pointer;flex-shrink:0;min-height:34px;padding:0 16px;font-weight:600}.cQSERa_queuePrimary{background:var(--ds-blue);color:#fff;border:0}.cQSERa_queueSecondary{border:1px solid var(--ds-border);background:var(--dsb);color:var(--ds-t-1)}.cQSERa_queuePrimary:disabled,.cQSERa_queueSecondary:disabled{opacity:.45;cursor:not-allowed}.cQSERa_queueListSection{padding:12px 14px}.cQSERa_queueListHead{justify-content:space-between;align-items:center;margin-bottom:8px;display:flex}.cQSERa_queueListHead h3 span{color:var(--ds-t-3);margin-left:4px;font-size:11px;font-weight:500}.cQSERa_queueList{flex-direction:column;gap:8px;margin:0;padding:0;list-style:none;display:flex}.cQSERa_queueTask{border:1px solid var(--ds-border);border-radius:var(--ds-r-1);background:var(--dsb);padding:10px}.cQSERa_queueTaskHead{align-items:center;gap:8px;min-width:0;display:flex}.cQSERa_queueStatus{background:var(--dsb-3);color:var(--ds-t-2);border-radius:5px;flex-shrink:0;padding:2px 6px;font-size:10px;font-weight:650}.cQSERa_queueStatus_running,.cQSERa_queueStatus_starting{color:var(--ds-blue);background:color-mix(in srgb, var(--ds-blue) 12%, transparent)}.cQSERa_queueStatus_completed{color:var(--ds-green);background:color-mix(in srgb, var(--ds-green) 12%, transparent)}.cQSERa_queueStatus_failed{color:var(--ds-red);background:color-mix(in srgb, var(--ds-red) 10%, transparent)}.cQSERa_queueTaskMeta{text-overflow:ellipsis;white-space:nowrap;min-width:0;color:var(--ds-t-2);font-size:11px;overflow:hidden}.cQSERa_queueTaskTime{color:var(--ds-t-3);flex-shrink:0;margin-left:auto;font-size:10px}.cQSERa_queuePrompt{color:var(--ds-t-1);margin-top:8px;font-size:12px;line-height:1.55}.cQSERa_queuePrompt summary{text-overflow:ellipsis;white-space:nowrap;cursor:pointer;overflow:hidden}.cQSERa_queuePrompt pre{background:var(--dsb-2);white-space:pre-wrap;overflow-wrap:anywhere;max-height:240px;font-family:var(--mono);border-radius:6px;margin:8px 0 0;padding:9px;font-size:11px;line-height:1.55;overflow:auto}.cQSERa_queueTaskError{color:var(--ds-red);overflow-wrap:anywhere;margin-top:8px;font-size:11px;line-height:1.5}.cQSERa_queueTaskActions{justify-content:flex-end;gap:10px;margin-top:5px;display:flex}.cQSERa_queueLinkButton{color:var(--ds-blue);cursor:pointer;background:0 0;border:0;padding:2px 0;font-size:11px}.cQSERa_queueLinkButton:disabled{opacity:.45;cursor:not-allowed}.cQSERa_queueEmpty{color:var(--ds-t-3);text-align:center;padding:26px 12px;font-size:12px}.cQSERa_queueUnsupported{padding:22px}.cQSERa_queueUnsupported p{color:var(--ds-t-2);margin:8px 0 0;font-size:12px;line-height:1.7}.cQSERa_queueNotice,.cQSERa_queueNoticeError{border-radius:var(--ds-r-1);overflow-wrap:anywhere;flex-shrink:0;padding:9px 11px;font-size:11px;line-height:1.5}.cQSERa_queueNotice{background:var(--dsb-2);color:var(--ds-t-2)}.cQSERa_queueNoticeError{background:color-mix(in srgb, var(--ds-red) 10%, transparent);color:var(--ds-red)}@media (width<=640px){.cQSERa_queueHero{align-items:flex-start}.cQSERa_queueSelectors{grid-template-columns:1fr}.cQSERa_queueComposerFooter{flex-direction:column;align-items:stretch}.cQSERa_queueComposerActions{flex-wrap:wrap;justify-content:flex-end}.cQSERa_queueTaskTime{display:none}}`,document.head.appendChild(e)}var $={queueBand:`cQSERa_queueBand`,queueBandOff:`cQSERa_queueBandOff`,queueBandPeak:`cQSERa_queueBandPeak`,queueComposer:`cQSERa_queueComposer`,queueComposerActions:`cQSERa_queueComposerActions`,queueComposerFooter:`cQSERa_queueComposerFooter`,queueEmpty:`cQSERa_queueEmpty`,queueField:`cQSERa_queueField`,queueFileInput:`cQSERa_queueFileInput`,queueHero:`cQSERa_queueHero`,queueLinkButton:`cQSERa_queueLinkButton`,queueList:`cQSERa_queueList`,queueListHead:`cQSERa_queueListHead`,queueListSection:`cQSERa_queueListSection`,queueNotice:`cQSERa_queueNotice`,queueNoticeError:`cQSERa_queueNoticeError`,queuePanel:`cQSERa_queuePanel`,queuePreview:`cQSERa_queuePreview`,queuePrimary:`cQSERa_queuePrimary`,queuePrompt:`cQSERa_queuePrompt`,queuePromptField:`cQSERa_queuePromptField`,queueSafety:`cQSERa_queueSafety`,queueSecondary:`cQSERa_queueSecondary`,queueSelectors:`cQSERa_queueSelectors`,queueStatus:`cQSERa_queueStatus`,queueStatus_completed:`cQSERa_queueStatus_completed`,queueStatus_failed:`cQSERa_queueStatus_failed`,queueStatus_running:`cQSERa_queueStatus_running`,queueStatus_starting:`cQSERa_queueStatus_starting`,queueSubtitle:`cQSERa_queueSubtitle`,queueTask:`cQSERa_queueTask`,queueTaskActions:`cQSERa_queueTaskActions`,queueTaskError:`cQSERa_queueTaskError`,queueTaskHead:`cQSERa_queueTaskHead`,queueTaskMeta:`cQSERa_queueTaskMeta`,queueTaskTime:`cQSERa_queueTaskTime`,queueTitle:`cQSERa_queueTitle`,queueTitleRow:`cQSERa_queueTitleRow`,queueUnsupported:`cQSERa_queueUnsupported`};let Zi={queued:`queueStatusQueued`,starting:`queueStatusStarting`,running:`queueStatusRunning`,completed:`queueStatusCompleted`,failed:`queueStatusFailed`};function Qi(e){return e.status===`completed`||e.status===`failed`}function $i(e,t){return JSON.stringify([e,t])}function ea(e,t){let n;try{n=JSON.parse(e)}catch{throw Error(`invalid task import`)}if(!Array.isArray(n)||n.length===0)throw Error(`invalid task import`);return n.map(e=>{if(typeof e==`string`)return{prompt:e,...t};if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`invalid task import`);let n=e;return{prompt:n.prompt,cwd:n.cwd??t.cwd,provider:n.provider??t.provider,model:n.model??t.model}})}function ta({t:e,language:t,navigateToSession:n}){let[r,i]=(0,d.useState)(),[a,o]=(0,d.useState)(``),[s,c]=(0,d.useState)(``),[l,u]=(0,d.useState)(``),[f,p]=(0,d.useState)(!1),[h,g]=(0,d.useState)(),[_,v]=(0,d.useState)(),b=(0,d.useRef)(!0),x=(0,d.useRef)(!1),S=(0,d.useRef)(!1),C=(0,d.useRef)(null),w=(0,d.useCallback)(async()=>{if(!x.current){x.current=!0;try{let e=await qi();b.current&&i(e)}catch(e){b.current&&g(e instanceof Error?e.message:String(e))}finally{x.current=!1}}},[]),[T,ee]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{ee(!document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[]),(0,d.useEffect)(()=>{if(b.current=!0,!T)return;w();let e=setInterval(()=>{w()},5e3);return()=>{b.current=!1,clearInterval(e)}},[w,T]),(0,d.useEffect)(()=>{if(h===void 0)return;let e=window.setTimeout(()=>{g(void 0)},8e3);return()=>{window.clearTimeout(e)}},[h]),(0,d.useEffect)(()=>{if(_===void 0)return;let e=window.setTimeout(()=>{v(void 0)},4e3);return()=>{window.clearTimeout(e)}},[_]),(0,d.useEffect)(()=>{r!==void 0&&(r.workspaces.some(e=>e.path===s)||c(r.workspaces[0]?.path??``),r.models.some(e=>$i(e.provider,e.id)===l)||u(r.models[0]===void 0?``:$i(r.models[0].provider,r.models[0].id)))},[r,s,l]);let E=(0,d.useCallback)(async(e,t=!1)=>{if(f||S.current)return!1;S.current=!0,p(!0),g(void 0),v(void 0);try{let n=await Yi(e);return b.current?(i(n),t&&o(``),!0):!1}catch(e){return b.current&&g(e instanceof Error?e.message:String(e)),!1}finally{S.current=!1,p(!1)}},[f]),D=(0,d.useMemo)(()=>r?.tasks.filter(e=>!Qi(e))??[],[r]),O=(0,d.useMemo)(()=>r?.tasks.filter(Qi).slice().reverse()??[],[r]),k=r!==void 0&&r.supported&&r.workspaces.length>0&&r.models.length>0,A=e=>new Date(e).toLocaleString(t===`en`?`en-US`:`zh-CN`),j=()=>{if(a.trim()===``||s===``||l===``)return;let[e,t]=JSON.parse(l);E({action:`enqueue`,prompt:a,cwd:s,provider:e,model:t},!0)},M=async t=>{if(!(t===void 0||!k||f||l===``)){g(void 0),v(void 0);try{if(t.size>10485760){g(e(`queueImportTooLarge`));return}let[n,r]=JSON.parse(l),i=ea(await t.text(),{cwd:s,provider:n,model:r});await E({action:`enqueueMany`,tasks:i})&&b.current&&v(e(`queueImported`,{count:i.length}))}catch{b.current&&g(e(`queueImportFormat`))}}},te=t=>{let r=n(t);v(r===`opened`?void 0:e(r===`unavailable`?`sessionOpenUnavailable`:`sessionOpenFailed`))},ne=t=>{let n=r?.workspaces.find(e=>e.path===t.cwd);return(0,m.jsxs)(`li`,{className:$.queueTask,"data-testid":`queue-task-${t.id}`,children:[(0,m.jsxs)(`div`,{className:$.queueTaskHead,children:[(0,m.jsx)(`span`,{className:y($.queueStatus,$[`queueStatus_${t.status}`]),children:e(Zi[t.status])}),(0,m.jsxs)(`span`,{className:$.queueTaskMeta,children:[n?.title??t.cwd,` · `,t.model]}),(0,m.jsx)(`time`,{className:$.queueTaskTime,dateTime:new Date(t.createdAt).toISOString(),children:A(t.createdAt)})]}),(0,m.jsxs)(`details`,{className:$.queuePrompt,children:[(0,m.jsx)(`summary`,{children:t.prompt.trim().slice(0,180)||t.prompt.slice(0,180)}),(0,m.jsx)(`pre`,{children:t.prompt})]}),t.error!==void 0&&(0,m.jsx)(`div`,{className:$.queueTaskError,role:`note`,children:t.error}),(0,m.jsxs)(`div`,{className:$.queueTaskActions,children:[t.sessionId!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:$.queueLinkButton,onClick:()=>{te(t.sessionId)},children:e(`queueOpenSession`)}),(t.status===`queued`||Qi(t))&&(0,m.jsx)(`button`,{type:`button`,className:$.queueLinkButton,disabled:f,onClick:()=>{E({action:`remove`,id:t.id})},children:e(t.status===`queued`?`queueRemoveQueued`:`queueRemoveHistory`)})]})]},t.id)};return(0,m.jsxs)(`div`,{className:$.queuePanel,"data-testid":`billing-tab-panel-queue`,children:[(0,m.jsxs)(`section`,{className:$.queueHero,children:[(0,m.jsxs)(`div`,{children:[(0,m.jsxs)(`div`,{className:$.queueTitleRow,children:[(0,m.jsx)(`h2`,{className:$.queueTitle,children:e(`tabQueue`)}),(0,m.jsx)(`span`,{className:$.queuePreview,children:`Preview`})]}),(0,m.jsx)(`p`,{className:$.queueSubtitle,children:e(`queueSubtitle`)})]}),r?.supported&&(0,m.jsxs)(`div`,{className:y($.queueBand,r.tier===`offPeak`?$.queueBandOff:$.queueBandPeak),children:[(0,m.jsx)(`strong`,{children:e(r.tier===`offPeak`?`offPeak`:`peak`)}),(0,m.jsxs)(`span`,{children:[e(r.tier===`offPeak`?`queueUntilPeak`:`queueUntilOffPeak`),` `,Lt(r.nextSwitchInMs)]})]})]}),h!==void 0&&(0,m.jsx)(`div`,{className:$.queueNoticeError,role:`alert`,children:h}),_!==void 0&&(0,m.jsx)(`div`,{className:$.queueNotice,role:`status`,children:_}),r===void 0?(0,m.jsx)(`div`,{className:$.queueEmpty,children:e(`queueLoading`)}):r.supported?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`section`,{className:$.queueComposer,children:[(0,m.jsx)(`div`,{className:$.queueSafety,children:e(`queueSafety`)}),(0,m.jsxs)(`div`,{className:$.queueSelectors,children:[(0,m.jsxs)(`label`,{className:$.queueField,children:[(0,m.jsx)(`span`,{children:e(`queueWorkspace`)}),(0,m.jsx)(`select`,{value:s,disabled:!k||f,onChange:e=>{c(e.target.value)},children:r.workspaces.map(e=>(0,m.jsx)(`option`,{value:e.path,children:e.title},e.path))})]}),(0,m.jsxs)(`label`,{className:$.queueField,children:[(0,m.jsx)(`span`,{children:e(`queueModel`)}),(0,m.jsx)(`select`,{value:l,disabled:!k||f,onChange:e=>{u(e.target.value)},children:r.models.map(e=>(0,m.jsxs)(`option`,{value:$i(e.provider,e.id),children:[e.providerName,` / `,e.name]},$i(e.provider,e.id)))})]})]}),!k&&(0,m.jsx)(`div`,{className:$.queueNotice,children:r.optionsError??e(`queueNoOptions`)}),(0,m.jsxs)(`label`,{className:$.queuePromptField,children:[(0,m.jsx)(`span`,{children:e(`queuePromptLabel`)}),(0,m.jsx)(`textarea`,{value:a,disabled:!k||f,maxLength:32e3,rows:5,placeholder:e(`queuePromptPlaceholder`),onChange:e=>{o(e.target.value)}})]}),(0,m.jsxs)(`div`,{className:$.queueComposerFooter,children:[(0,m.jsx)(`span`,{children:e(`queuePrivacy`)}),(0,m.jsxs)(`div`,{className:$.queueComposerActions,children:[(0,m.jsx)(`input`,{ref:C,className:$.queueFileInput,"data-testid":`queue-import-file`,type:`file`,accept:`application/json,.json`,disabled:!k||f,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,M(t)}}),(0,m.jsx)(`button`,{type:`button`,className:$.queueSecondary,title:e(`queueImportHint`),disabled:!k||f,onClick:()=>{C.current?.click()},children:e(`queueImport`)}),(0,m.jsx)(`button`,{type:`button`,className:$.queuePrimary,disabled:!k||f||a.trim()===``,onClick:j,children:e(`queueEnqueue`)})]})]})]}),(0,m.jsxs)(`section`,{className:$.queueListSection,children:[(0,m.jsxs)(`div`,{className:$.queueListHead,children:[(0,m.jsxs)(`h3`,{children:[e(`queueActive`),` `,(0,m.jsx)(`span`,{children:D.length})]}),O.length>0&&(0,m.jsx)(`button`,{type:`button`,className:$.queueLinkButton,disabled:f,onClick:()=>{E({action:`clearFinished`})},children:e(`queueClearFinished`)})]}),D.length===0&&O.length===0?(0,m.jsx)(`div`,{className:$.queueEmpty,children:e(`queueEmpty`)}):(0,m.jsxs)(`ul`,{className:$.queueList,children:[D.map(ne),O.map(ne)]})]})]}):(0,m.jsxs)(`section`,{className:$.queueUnsupported,"data-testid":`queue-unsupported`,children:[(0,m.jsx)(`h3`,{children:e(`queueUnsupportedTitle`)}),(0,m.jsx)(`p`,{children:e(`queueUnsupportedBody`)})]})]})}function na({window:e,t}){let n=Math.min(100,Math.max(0,e.usedPercent)),r=Math.min(100,Math.max(0,e.remainingPercent))<=0;return(0,m.jsxs)(`div`,{className:z.subscriptionWindow,children:[(0,m.jsx)(`span`,{className:z.subscriptionWindowLabel,children:Ai(e.kind,t)}),(0,m.jsx)(`span`,{className:z.subscriptionTrack,"aria-hidden":`true`,children:(0,m.jsx)(`span`,{className:y(z.subscriptionFill,n>=100&&z.subscriptionFillOver,n>=80&&n<100&&z.subscriptionFillWarn),style:{width:`${n}%`}})}),(0,m.jsxs)(`span`,{className:z.subscriptionMeta,children:[(0,m.jsx)(`span`,{className:y(z.subscriptionPct,r&&z.subscriptionExhausted),children:r?t(`subscriptionExhausted`):t(`subscriptionRemaining`).replace(`{pct}`,String(e.remainingPercent))}),e.resetsAt!==void 0&&(0,m.jsx)(`span`,{className:z.subscriptionReset,children:t(`subscriptionReset`).replace(`{date}`,`${K(new Date(e.resetsAt).getTime())} ${Fi(new Date(e.resetsAt).getTime())}`)})]})]})}function ra({label:e,t}){return(0,m.jsx)(p.Tooltip,{label:e,side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.helpTip,role:`note`,"aria-label":e,children:`?`})})}function ia(e,t){return e===z.healthOk?t(`healthDotLive`):e===z.healthBad?t(`healthDotFailed`):t(`healthDotUnknown`)}function aa(e){let t=t=>dn(un(t,e.currency),e.currency),{wide:n,t:r,onOpen:i,monthCost:a,todayCost:o,weekCost:s,days:c,vendorStatus:l,dash:u,floatPrefs:p,subscriptions:h,cardPrefs:g,monthTokens:_,todayTokens:v,weekTokens:b,budgetPressure:x,deltaPct:S=0}=e,C=(0,d.useMemo)(()=>p.targets.map(e=>h.find(t=>t.provider===e)).filter(e=>e!==void 0),[p.targets,h]),[w,T]=(0,d.useState)(0),ee=C.length===0?0:Math.min(w,C.length-1),E=C[ee],D=(0,d.useRef)(null),[O,k]=(0,d.useState)(!1),[A,j]=(0,d.useState)({left:0,top:0});(0,d.useEffect)(()=>{if(!O||p.mode!==`subscription`||C.length<2)return;let e=setInterval(()=>T(e=>(e+1)%C.length),1500);return()=>clearInterval(e)},[O,p.mode,C.length]);let M=(0,d.useRef)(void 0),te=(0,d.useCallback)(()=>{window.clearTimeout(M.current),k(!0)},[]),ne=(0,d.useCallback)(()=>{window.clearTimeout(M.current),M.current=window.setTimeout(()=>k(!1),120)},[]);(0,d.useEffect)(()=>()=>window.clearTimeout(M.current),[]);let N=(0,d.useCallback)(()=>{let e=D.current?.getBoundingClientRect();e!==void 0&&j({left:e.left,top:e.top-8})},[]);(0,d.useEffect)(()=>{if(!O)return;let e=()=>N();return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,{capture:!0}),window.removeEventListener(`resize`,e)}},[O,N]);let re=c.length>0?c.reduce((e,t)=>e+t.cost,0)/c.length:0,ie=re>0?Math.max(0,Math.min(1,o/re)):0,ae=-80+ie*160,oe=(0,m.jsxs)(`svg`,{viewBox:`3.5 10 34 22`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,m.jsx)(`path`,{d:`M5.23 26.4A15 15 0 0 1 34.77 26.4`,strokeWidth:3,opacity:.16}),(0,m.jsx)(`path`,{d:`M5.23 26.4A15 15 0 0 1 34.77 26.4`,strokeWidth:3,strokeDasharray:`${(41.9*ie).toFixed(2)} 41.9`,className:z.triggerGaugeArc}),(0,m.jsx)(`path`,{d:`M5.23 26.4 8.18 26.92M10.36 17.51 12.29 19.81M20 14v3M27.71 19.81 29.64 17.51M31.82 26.92 34.77 26.4`,strokeWidth:1.6,opacity:.7}),(0,m.jsx)(`path`,{d:`M7.01 21.5 8.31 22.25M14.87 14.91 15.38 16.31M24.62 16.31 25.13 14.91M31.69 22.25 32.99 21.5`,strokeWidth:1.2,opacity:.38}),(0,m.jsx)(`line`,{x1:`20`,y1:`29`,x2:`20`,y2:`19.5`,strokeWidth:2,className:z.triggerGaugeNeedle,style:{transform:`rotate(${ae}deg)`,transformOrigin:`20px 29px`}}),(0,m.jsx)(`circle`,{cx:`20`,cy:`29`,r:`1.5`,fill:`currentColor`,stroke:`none`})]});if(g.mode===`hidden`)return null;if(!n||g.mode===`compact`)return(0,m.jsx)(`button`,{type:`button`,className:y(z.railButton,x!==`none`&&z.triggerBudgetPulse,x===`over`&&z.triggerBudgetOver),"data-testid":`billing-rail-button`,onClick:i,title:`${r(`title`)} · ${t(g.span===`day`?o:g.span===`week`?s:a)}`,children:oe});let se=g.metric===`tokens`,ce=c.map(e=>se?e.tokens:e.cost),le=Math.max(...ce,0),ue=ce.map(e=>le>0?4+e/le*12:4);return(0,m.jsxs)(`span`,{ref:D,className:z.triggerWrap,onMouseEnter:()=>{N(),te()},onMouseLeave:ne,onFocusCapture:()=>{N(),te()},onBlurCapture:()=>k(!1),children:[(0,m.jsxs)(`button`,{type:`button`,className:y(z.trigger,x!==`none`&&z.triggerBudgetPulse,x===`over`&&z.triggerBudgetOver),"data-testid":`billing-trigger`,onClick:i,title:`${r(`title`)} · ${t(g.span===`day`?o:g.span===`week`?s:a)}`,children:[(0,m.jsx)(`span`,{className:y(z.triggerIcon,x!==`none`&&z.triggerBudgetHot),"data-testid":`billing-trigger-icon`,children:oe}),(0,m.jsx)(`span`,{className:z.triggerMain,children:(0,m.jsxs)(`span`,{className:z.triggerPrimary,children:[(0,m.jsx)(`span`,{className:z.triggerLabel,children:se?g.span===`day`?r(`triggerTodayTokens`):g.span===`week`?r(`triggerWeekTokens`):r(`triggerMonthTokens`):g.span===`day`?r(`triggerToday`):g.span===`week`?r(`weekCost`):r(`triggerMonth`)}),(()=>{let e=g.span===`day`?se?v:o:g.span===`week`?se?b:s:se?_:a,n=g.span===`day`?S:0;return se?(0,m.jsx)(`span`,{className:z.triggerMetric,"data-testid":`billing-trigger-span-tokens`,children:q(e)}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`span`,{className:z.triggerValueRow,children:[(0,m.jsx)(`span`,{className:z.triggerYen,"aria-hidden":`true`,children:t(e).charAt(0)}),(0,m.jsx)(`span`,{className:z.triggerMetric,"data-testid":`billing-trigger-span-money`,children:t(e).slice(1)})]}),g.showDelta&&n!==0&&(0,m.jsxs)(`span`,{className:y(z.triggerDelta,n>0?z.triggerDeltaUp:z.triggerDeltaDown),"data-testid":`billing-trigger-delta`,children:[n>0?`▲`:`▼`,` `,Math.abs(n).toFixed(1),`%`]}),(0,m.jsx)(`span`,{className:z.triggerGlow,"aria-hidden":`true`})]})})()]})}),(0,m.jsx)(`span`,{className:z.triggerSpark,"data-testid":`billing-trigger-spark`,"aria-hidden":`true`,children:ue.map((e,t)=>(0,m.jsx)(`span`,{className:t===ue.length-1?z.triggerSparkHot:z.triggerSparkBar,style:{height:`${e}px`}},c[t]?.date??String(t)))})]}),(0,f.createPortal)((0,m.jsx)(`span`,{className:y(z.triggerPop,O&&z.triggerPopShown),style:{left:`${A.left}px`,top:`${A.top}px`},"data-testid":`billing-trigger-pop`,"aria-hidden":!O,onMouseEnter:te,onMouseLeave:ne,children:p.mode===`subscription`?(0,m.jsx)(m.Fragment,{children:C.length===0?(0,m.jsx)(`span`,{className:z.triggerPopEmpty,children:r(`floatNoTargets`)}):(0,m.jsxs)(m.Fragment,{children:[E!==void 0&&(0,m.jsxs)(`div`,{className:z.floatSub,"data-testid":`billing-float-subscription`,children:[(0,m.jsxs)(`div`,{className:z.floatSubHead,children:[(0,m.jsx)(`span`,{className:z.floatSubName,children:E.displayName}),E.plan!==void 0&&(0,m.jsx)(`span`,{className:z.floatSubPlan,children:E.plan})]}),E.windows.map(e=>(0,m.jsx)(na,{window:e,t:r},e.kind))]}),C.length>1&&(0,m.jsx)(`span`,{className:z.triggerPopSwitcher,"data-testid":`billing-float-switcher`,children:(0,m.jsxs)(`span`,{className:z.triggerPopSwitchCount,children:[ee+1,`/`,C.length]})})]})}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:z.popHead,children:(0,m.jsx)(`span`,{className:z.popTitle,children:r(`popTitle`)})}),(0,m.jsxs)(`span`,{className:z.metricGrid,children:[(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`floatPrimaryToday`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:t(o)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`floatPrimaryWeek`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:t(s)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`floatPrimaryMonth`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:t(a)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`input`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:q(u.input)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`output`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:q(u.output)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`cacheHit`)}),(0,m.jsx)(`span`,{className:y(z.metricValue,z.metricValueSuccess),children:mn(u.cacheRead+u.cacheMiss>0?u.cacheRead/(u.cacheRead+u.cacheMiss)*100:0)})]})]}),(0,m.jsxs)(`span`,{className:z.popModel,children:[(0,m.jsx)(`span`,{className:z.popModelLabel,children:r(`popTodayModel`)}),l.direct!==void 0||l.sub!==void 0?(0,m.jsxs)(m.Fragment,{children:[l.direct!==void 0&&(0,m.jsxs)(`span`,{className:z.popModelRow,children:[(0,m.jsx)(`span`,{className:y(z.popDot,z.popDotDirect),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:z.popTagPrimary,children:r(`popDirectLead`)}),(0,m.jsx)(`span`,{className:z.popModelName,children:l.direct.name}),(0,m.jsx)(`span`,{className:y(z.popModelStatus,l.direct.low&&z.popModelStatusLow),children:l.direct.text})]}),l.sub!==void 0&&(0,m.jsxs)(`span`,{className:z.popModelRow,children:[(0,m.jsx)(`span`,{className:y(z.popDot,z.popDotSub),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:z.popTagSub,children:r(`popSubLead`)}),(0,m.jsx)(`span`,{className:z.popModelName,children:l.sub.name}),(0,m.jsx)(`span`,{className:y(z.popModelStatus,l.sub.low&&z.popModelStatusLow),children:l.sub.text})]})]}):(0,m.jsxs)(`span`,{className:z.popModelRow,children:[(0,m.jsx)(`span`,{className:y(z.popDot,z.popDotNeutral),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:z.popModelStatus,children:r(`popNoConsumption`)})]})]})]})}),document.body)]})}function oa({balance:e,days:t,dailyBurn:n,money:r,t:i,onClose:a}){let o=t=>t===void 0?void 0:e.currency===`USD`?`$${t.toFixed(2)}`:r(t),s=o(e.totalBalance),c=o(e.grantedBalance),l=o(e.toppedUpBalance);return(0,m.jsxs)(`span`,{className:z.balanceDetailPop,"data-testid":`billing-balance-detail-pop`,onClick:e=>{e.stopPropagation()},children:[(0,m.jsxs)(`span`,{className:z.balanceDetailHead,children:[(0,m.jsx)(`span`,{className:z.balanceDetailTitle,children:e.displayName}),(0,m.jsx)(`button`,{type:`button`,className:z.balanceDetailClose,"aria-label":i(`close`),onClick:a,children:`×`})]}),(0,m.jsxs)(`span`,{className:z.balanceDetailGrid,children:[s!==void 0&&(0,m.jsx)(sa,{label:i(`balance`),value:s}),c!==void 0&&(0,m.jsx)(sa,{label:i(`balanceGranted`),value:c}),l!==void 0&&(0,m.jsx)(sa,{label:i(`balanceTopped`),value:l}),(0,m.jsx)(sa,{label:i(`balanceDaily`),value:r(n)}),(0,m.jsx)(sa,{label:i(`balanceDaysLong`),value:`${t} ${i(`balanceDaysUnit`)}`})]})]})}function sa({label:e,value:t}){return(0,m.jsxs)(`span`,{className:z.balanceDetailRow,children:[(0,m.jsx)(`span`,{className:z.balanceDetailLabel,children:e}),(0,m.jsx)(`span`,{className:z.balanceDetailValue,children:t})]})}function ca({userPrices:e,onUserPrices:t,t:n}){let[r,i]=(0,d.useState)(()=>[...e]),[a,o]=(0,d.useState)(new Set),s=e=>o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),c=()=>{i(e=>e.filter((e,t)=>!a.has(t))),o(new Set)},l=(e,t)=>i(n=>n.map((n,r)=>r===e?{...n,...t}:n)),u=()=>i(e=>[...e,{key:``,input:0,cacheHit:0,output:0}]),f=e=>{let t=r[e]?.offPeak;return{input:t===void 0?``:String(t.input),cacheHit:t===void 0?``:String(t.cacheHit),output:t===void 0?``:String(t.output)}},p=(e,t,n)=>i(r=>r.map((r,i)=>{if(i!==e)return r;let a=r.offPeak,o={input:a===void 0?``:String(a.input),cacheHit:a===void 0?``:String(a.cacheHit),output:a===void 0?``:String(a.output),[t]:n},s=[o.input,o.cacheHit,o.output].some(e=>e.trim()!==``),c=[o.input,o.cacheHit,o.output].map(e=>Number(e)),l=s&&c.every(e=>Number.isFinite(e)&&e>=0)&&c.some(e=>e>0),{offPeak:u,...d}=r;return l?{...d,offPeak:{input:c[0]??0,cacheHit:c[1]??0,output:c[2]??0}}:d})),h=()=>t(r.filter(e=>e.key.trim()!==``).map(e=>({...e,key:e.key.trim(),...e.origin===void 0||e.origin.trim()===``?{}:{origin:ut(e.origin.trim())}}))),g=on().map(e=>e.key),_=(e,t)=>i(n=>n.map((n,r)=>{if(r!==e)return n;let{currency:i,...a}=n;return t===`USD`?{...a,currency:`USD`}:a})),[v,b]=(0,d.useState)({}),x=(e,t,n)=>`${e}:${t}:${n}`,S=(e,t,n)=>b(r=>{let i=x(e,t,n);if(r[i]===void 0)return r;let a={...r};return delete a[i],a}),C=e=>Number.isFinite(e)&&e!==0?String(e):``,w=(e,t,n)=>{if(b(r=>({...r,[x(e,`main`,t)]:n})),n===``){l(e,{[t]:0});return}let r=Number(n);Number.isFinite(r)&&r>=0&&l(e,{[t]:r})};return(0,m.jsxs)(`section`,{className:z.setCard,"data-testid":`billing-user-prices`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[n(`userPrices`),(0,m.jsx)(ra,{label:n(`userPricesHint`),t:n})]})})}),(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsx)(`datalist`,{id:`billing-price-model-keys`,children:g.map(e=>(0,m.jsx)(`option`,{value:e},e))}),r.map((e,t)=>(0,m.jsxs)(`div`,{className:z.userPriceRow,"data-testid":`billing-user-price-row`,children:[(0,m.jsx)(`input`,{type:`checkbox`,className:z.userPriceCheck,"data-testid":`billing-user-price-select`,checked:a.has(t),"aria-label":n(`userPriceSelect`),onChange:()=>s(t)}),(0,m.jsxs)(`div`,{className:z.userPriceBody,children:[(0,m.jsxs)(`div`,{className:z.userPriceLineMeta,children:[(0,m.jsxs)(`div`,{className:z.userPriceField,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:n(`userPriceModel`)}),(0,m.jsx)(`input`,{className:z.userPriceInput,"data-testid":`billing-user-price-model`,type:`text`,list:`billing-price-model-keys`,value:e.key,placeholder:`flash`,"aria-label":n(`userPriceModel`),onChange:e=>l(t,{key:e.target.value})})]}),(0,m.jsxs)(`div`,{className:z.userPriceField,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:n(`userPriceSource`)}),(0,m.jsx)(`input`,{className:z.userPriceInput,"data-testid":`billing-user-price-origin`,type:`text`,value:e.origin??``,placeholder:n(`userPriceSourceHint`),"aria-label":n(`userPriceSource`),onChange:e=>l(t,{origin:e.target.value.trim()})})]}),(0,m.jsxs)(`div`,{className:z.userPriceField,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:n(`userPriceCurrency`)}),(0,m.jsxs)(`div`,{className:z.ctlGroup,children:[(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,e.currency!==`USD`&&z.floatModeBtnOn),onClick:()=>_(t,`CNY`),children:`CNY`}),(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,e.currency===`USD`&&z.floatModeBtnOn),onClick:()=>_(t,`USD`),children:`USD`})]})]})]}),[{scope:`main`,label:n(`userPriceNormal`),testid:`billing-user-price-normal`,valueOf:n=>v[x(t,`main`,n)]??C(e[n]),onChange:(e,n)=>w(t,e,n)},{scope:`off`,label:n(`userPriceOffPeak`),testid:`billing-user-price-offpeak`,valueOf:e=>v[x(t,`off`,e)]??f(t)[e],onChange:(e,n)=>{b(r=>({...r,[x(t,`off`,e)]:n})),p(t,e,n)}}].map(e=>(0,m.jsxs)(`div`,{className:z.userPricePriceLine,"data-testid":e.testid,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:e.label}),[`input`,`cacheHit`,`output`].map(r=>{let i=n(r===`input`?`tokenMiss`:r===`cacheHit`?`tokenHit`:`tokenOutput`);return(0,m.jsx)(`input`,{className:z.userPriceInputNum,type:`number`,min:0,step:.01,placeholder:i,"aria-label":`${e.label} ${i}`,value:e.valueOf(r),onChange:t=>e.onChange(r,t.target.value),onBlur:()=>S(t,e.scope,r)},r)})]},e.testid))]})]},t)),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-user-price-add`,onClick:u,children:n(`userPriceAdd`)}),(0,m.jsxs)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-user-price-remove-selected`,disabled:a.size===0,onClick:c,children:[n(`userPriceRemoveSelected`),a.size>0?` (${a.size})`:``]}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-user-price-save`,onClick:h,children:n(`userPriceSave`)})]})]})]})}function la({stats:e,t,onClose:n,embeddedSettings:r=!1,userPrices:i,onUserPrices:a,health:o,balances:s,reconcile:c,quotas:l,relayQuotas:u,currency:f,onCurrency:h,language:g,onLanguage:_,turns:v,renderSlot:b,budgetEnabled:x,budgetAmount:S,onToggleBudget:C,onBudgetAmount:w,modelBudgets:T,monthModelCost:ee,onModelBudget:E,peakConfig:D,onPeakConfig:O,onPreviewPeak:k,floatPrefs:A,onFloatPrefs:j,cardPrefs:M,onCardPrefs:te,recoveryEntryAvailable:ne,sitePrefs:N,onSitePrefs:re,liveCostPrefs:oe,onLiveCostPrefs:se,quickQueuePrefs:ue,onQuickQueuePrefs:de,quotasStale:fe,balanceStale:pe,navigateToSession:me}){let he=(0,d.useRef)(null),ge=(0,d.useMemo)(()=>Ci(e.bySession??[]),[e.bySession]),_e=(0,d.useMemo)(()=>Ti(ge),[ge]),[ve,ye]=(0,d.useState)(void 0),be=(0,d.useCallback)(e=>{let n=me(e);if(n===`opened`){ye(void 0);return}ye(t(n===`unavailable`?`sessionOpenUnavailable`:`sessionOpenFailed`))},[me,t]),[xe,Se]=(0,d.useState)(`cost`),{total:Ce,byModel:we,byDay:P}=e,[F,Oe]=(0,d.useState)(r?`settings`:`overview`),[je,Me]=(0,d.useState)(7),[Ne,I]=(0,d.useState)(()=>{try{return window.localStorage.getItem(`dsh-billing:reconcile-dismissed`)??``}catch{return``}}),Fe=()=>{let e=new Date,t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`},Ie=(0,d.useCallback)(()=>{let e=Fe();I(e);try{window.localStorage.setItem(`dsh-billing:reconcile-dismissed`,e)}catch{}},[]),[Le,L]=(0,d.useState)(()=>{let e=[`unpriced`,`search-estimate`,`unreadable`],t=new Set,n=new Date,r=e=>String(e).padStart(2,`0`),i=`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())}`;try{for(let n of e)window.localStorage.getItem(`dsh-billing:notice-${n}-dismissed`)===i&&t.add(n)}catch{}return t}),Re=(0,d.useCallback)(e=>{let t=Fe();L(t=>new Set(t).add(e));try{window.localStorage.setItem(`dsh-billing:notice-${e}-dismissed`,t)}catch{}},[]),[ze,Be]=(0,d.useState)(`month`),[We,qe]=(0,d.useState)(`cost`),[Je,Ye]=(0,d.useState)(He),[Xe,Ze]=(0,d.useState)(R),[Qe,$e]=(0,d.useState)(`budget`),[et,tt]=(0,d.useState)(``),nt=e=>Di(et,e);(0,d.useEffect)(()=>{let e=he.current;if(F!==`settings`||e===null||typeof IntersectionObserver>`u`)return;let t=Array.from(e.querySelectorAll(`[id^="settings-"]`)).filter(e=>!e.closest(`[hidden]`));if(t.length===0)return;let n=new IntersectionObserver(e=>{let t,n=1/0;for(let r of e){if(!r.isIntersecting)continue;let e=r.boundingClientRect.top;e<n&&(n=e,t=r.target.id)}t!==void 0&&$e(t.slice(9))},{rootMargin:`-80px 0px -55% 0px`});for(let e of t)n.observe(e);return()=>{n.disconnect()}},[F]);let rt=(0,d.useCallback)(e=>{$e(e);let t=he.current?.querySelector(`[id="settings-${e}"]`);if(t==null)return;if(r){t.scrollIntoView({block:`start`,behavior:`smooth`});return}let n=t.closest(`.${z.dashboardBody}`);if(n===null)return;let i=t.getBoundingClientRect().top-n.getBoundingClientRect().top;n.scrollTo({top:n.scrollTop+i,behavior:`smooth`})},[r]),it=(0,d.useCallback)(e=>{Ye(e),Ue(e)},[]),ot=(0,d.useCallback)(e=>{Ze(e),Ke(e)},[]);(0,d.useEffect)(()=>{typeof document>`u`||(document.documentElement.dataset.density=Je,document.documentElement.dataset.motion=Xe)},[Je,Xe]),(0,d.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;t?.density!==void 0&&Ye(t.density)},t=e=>{let t=e.detail;t?.motion!==void 0&&Ze(t.motion)};return window.addEventListener(Ve,e),window.addEventListener(Ge,t),()=>{window.removeEventListener(Ve,e),window.removeEventListener(Ge,t)}},[]);let[B,st]=(0,d.useState)(ie),[V,ct]=(0,d.useState)(ce),H=e=>{let t={...V,...e};t.start!==``&&t.end!==``&&(t.start>t.end&&(e.start===void 0?t.start=t.end:t.end=t.start),ct(t),le(t))},lt=(0,d.useMemo)(()=>l.filter(e=>e.status===`ok`&&e.windows.length>0).map(e=>({id:e.provider,label:e.displayName})),[l]),[ut,dt]=(0,d.useState)(),[ft,pt]=(0,d.useState)(new Set),[mt,ht]=(0,d.useState)(!1),[gt,_t]=(0,d.useState)(``),vt=(0,d.useCallback)(e=>{pt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),yt=(0,d.useMemo)(()=>Si(e.bySession??[]),[e.bySession]),bt=e=>(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`td`,{className:z.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:z.numCol,children:W(e.cost)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.lastActive>0?`${K(e.lastActive)} ${Fi(e.lastActive)}`:`—`})]}),xt=(e,n)=>(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{className:y(z.sessionChildRow,n>0&&z.sessionSubDeepRow),"data-testid":`billing-session-sub-row`,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),children:t(`sessionSubRow`)}),(e.subCalls??0)>0&&(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),"data-testid":`billing-session-sub-chain`,children:e.subCost!==void 0&&e.subCost>0?t(`sessionSubCost`).replace(`{cost}`,W(e.subCost)):t(`sessionSubCalls`).replace(`{calls}`,(e.subCalls??0).toLocaleString())}),(0,m.jsx)(`span`,{className:z.modelProvider,children:e.title??e.id.slice(0,8)})]}),bt(e)]}),e.subs?.map(e=>xt(e,n+1))]},e.id),Ct=(0,d.useMemo)(()=>Ei(e.bySession??[],gt),[e.bySession,gt]),wt=(0,d.useMemo)(()=>[...new Set([...Object.keys(ee),...Object.keys(T)])].map(e=>{let t=tn(e);return{key:e,name:t.key===`other`?void 0:t.name,cost:ee[e]??0}}).sort((e,t)=>t.cost-e.cost),[ee,T]),[Tt,Et]=(0,d.useState)(()=>new Set(Ee())),Dt=(0,d.useCallback)(e=>{Et(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),De([...n]),n})},[]),[U,Ot]=(0,d.useState)(()=>ke()),kt=(0,d.useCallback)(()=>{Ot(e=>{let t=!e;return Ae(t),t})},[]),[At,jt]=(0,d.useState)(!1);(0,d.useEffect)(()=>{let e=!0;return Bi().then(t=>{e&&t!==void 0&&jt(t)}),()=>{e=!1}},[]);let Mt=(0,d.useCallback)(()=>{let e=!At;jt(e),Vi(e).then(t=>{t||jt(!e)})},[At]),Nt=St(),[It,Lt]=(0,d.useState)(!1),Rt=(0,d.useCallback)(()=>{It||(Lt(!0),Gi().finally(()=>{Lt(!1)}))},[It]),zt=Ui,W=e=>dn(un(e,f),f),Bt=f===`usd`?`$`:f===`eur`?`€`:`¥`,Vt=g,Ht=e=>fr(e,Vt),[G,Ut]=(0,d.useState)(``),[Wt,Gt]=(0,d.useState)(()=>Te()),[Kt,qt]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{let e=setInterval(()=>{qt(Date.now())},3e4);return()=>{clearInterval(e)}},[]);let Jt=l.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`),Yt=D.leadMin*6e4,Xt=(e,n)=>e===0?t(`free`):fn(pn(e,n,f,Nt.rate),f===`usd`?`USD`:f===`eur`?`EUR`:`CNY`),Zt=(0,d.useMemo)(()=>rr([...v].reverse()),[v]),Qt={peak:e.byTier?.peak.cost??0,offPeak:e.byTier?.offPeak.cost??0},$t=Qt.peak/2,en=Rr(P,K()),nn=e=>s.find(t=>Q(t.provider)===Q(e)),an=e=>e.balance?.error===`unconfigured`&&e.models.length>0&&e.models.every(e=>e.plan),sn=e=>{if(e===void 0)return(0,m.jsx)(`span`,{className:z.na,children:`—`});if(e.error===`unconfigured`)return t(`balanceUnconfigured`);if(e.error===`unauthorized`)return t(`balanceUnauthorized`);if(e.error===`unreachable`)return t(`balanceUnreachable`);if(e.totalBalance===void 0)return(0,m.jsx)(`span`,{className:z.na,children:`—`});let n=e.currency===`USD`?`$${e.totalBalance.toFixed(2)}`:W(e.totalBalance),r=e.currency===`USD`?e.totalBalance*Nt.rate:e.totalBalance,i=en>0?Math.floor(r/en):void 0;return(0,m.jsxs)(`span`,{className:z.balanceCell,children:[(0,m.jsx)(`span`,{children:n}),i!==void 0&&i>=0&&(0,m.jsx)(`button`,{type:`button`,className:y(z.balanceDaysBadge,i<=3&&z.balanceDaysBadgeLow),"data-testid":`billing-balance-days-badge`,title:t(`balanceDays`).replace(`{days}`,String(i)),"aria-label":`${e.displayName} ${t(`balanceDays`).replace(`{days}`,String(i))}`,onClick:t=>{t.stopPropagation(),dt(ut===e.provider?void 0:e.provider)},children:`?`}),ut===e.provider&&(0,m.jsx)(oa,{balance:e,days:i??0,dailyBurn:en,money:W,t,onClose:()=>{dt(void 0)}})]})},ln=Object.keys(P).sort(),hn=K(),gn=P[hn]?.cost??0,_n=hn.slice(0,7),bn=hn.slice(0,4),J=ln.reduce((e,t)=>e+(t.startsWith(_n)?P[t]?.cost??0:0),0),Tn=ln.reduce((e,t)=>e+(t.startsWith(bn)?P[t]?.cost??0:0),0),En=(0,d.useMemo)(()=>Br(P,_n,hn)+l.reduce((e,t)=>e+(t.planType===`code`?t.subscriptionAmount??0:0),0),[P,_n,hn,l]),Dn=(0,d.useMemo)(()=>{if(!(x&&S>0))return null;let e=S-J;return{over:e<=0,remainRatio:Math.max(0,Math.min(1,e/S)),remainCny:Math.max(0,e)}},[x,S,J]),On=(0,d.useMemo)(()=>{let e=[];for(let t=je-1;t>=0;--t){let n=new Date;n.setDate(n.getDate()-t),e.push(K(n.getTime()))}return e},[je]),An=On.at(-1)??hn,jn=(0,d.useMemo)(()=>Object.entries(P).map(([e,t])=>({date:e,value:We===`tokens`?Ur(t):t.cost})),[P,We]),Y=(0,d.useMemo)(()=>jn.reduce((e,t)=>e+t.value,0),[jn]),Mn=Vr(P),Nn=Hr(P),Pn=(0,d.useMemo)(()=>On.map(t=>{let n={},r=e.byDayModels?.[t];if(r!==void 0)for(let[e,t]of Object.entries(r))t.cost>0&&(n[e]=t.cost);let i=P[t];return{date:t,cost:i?.cost??0,calls:i?.calls??0,byModel:n,tokens:i===void 0?0:Ur(i)}}),[On,P,e.byDayModels]),X=(0,d.useMemo)(()=>Object.entries(we).filter(([,e])=>e.calls>0).map(([e,t])=>{let n=tn(e),r=n.key===`other`,i=r?ti(e):void 0,a={input:t.input,cacheHit:t.cacheHit,cacheMiss:t.cacheMiss,output:t.output};return{key:e,name:r?e:n.name,provider:i??n.provider,calls:t.calls,input:t.input,output:t.output,cacheHitRate:t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0,estimated:cn(n,a),plan:t.plan===!0,...t.cost>0?{actual:t.cost}:{},uncatalogued:r,estimatedPricing:n.estimated===!0,officialCalls:t.officialCalls??0,officialCost:t.officialCost??0}}).sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated)).map((e,t)=>({...e,color:jr[t%jr.length]??`#8b95a3`})),[we]),In=(0,d.useMemo)(()=>N.hideUnidentified?u.filter(e=>e.kind!==`unknown`):u,[u,N.hideUnidentified]),Ln=(0,d.useMemo)(()=>{let n=e.byDayModelsSite;if(U){let t=K();n={[t]:e.byDayModelsSite?.[t]??{}}}let r=new Map;for(let t of Object.values(n??{}))for(let[n,i]of Object.entries(t))for(let[t,a]of Object.entries(i)){let i=r.get(t);i===void 0&&(i=new Map,r.set(t,i));let o=i.get(n)??{calls:0,input:0,output:0,cacheHit:0,cacheMiss:0,cost:0,allPlan:!0};o.calls+=a.calls,o.input+=a.input,o.output+=a.output,o.cacheHit+=a.cacheHit,o.cacheMiss+=a.cacheMiss,o.cost+=a.cost,o.allPlan=o.allPlan&&(a.plan??e.byModel?.[n]?.plan===!0),i.set(n,o)}let i=new Map;for(let[e,t]of r){let n=!e.startsWith(`direct:`)&&!e.startsWith(`site:`),r=[...t.entries()].filter(([,e])=>e.calls>0).map(([e,t],r)=>{let i=tn(e),a=i.key===`other`,o=a?ti(e)??i.provider:i.provider;return{key:e,name:a?e:i.name,provider:o,color:jr[r%jr.length]??`#8b95a3`,calls:t.calls,input:t.input,output:t.output,cacheHitRate:t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0,estimated:n?0:cn(i,{input:t.input,cacheHit:t.cacheHit,cacheMiss:t.cacheMiss,output:t.output}),plan:t.allPlan,...t.cost>0?{actual:t.cost}:{},uncatalogued:a,estimatedPricing:i.estimated===!0,officialCalls:0,officialCost:0}}).sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated));r.length>0&&i.set(e,r)}let a=e=>_r(e,Vt)??t(`channelUnknown`),c=new Map,u=new Map,d=new Map,f=e=>e.startsWith(`direct:`)?`direct`:e.startsWith(`site:`)?`site`:`unknown`,p={direct:2,site:1,unknown:0,vendor:0};for(let[e,t]of i){let n=a(e),r=c.get(n);if(r===void 0)c.set(n,[...t]),u.set(n,f(e)),d.set(n,e);else{r.push(...t),r.sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated));let i=u.get(n)??`unknown`,a=f(e);p[a]>p[i]&&(u.set(n,a),d.set(n,e))}}let m=new Map,h=new Map;for(let e of l){if(e.status===`not-configured`)continue;let t=e.displayName??ri(e.provider),n=a(`direct:${e.provider}`),r=c.has(t)?t:c.has(n)?n:void 0,i=r??`sub:${ri(e.provider)}`;h.set(i,r??ri(e.provider));let o=m.get(i);o===void 0?m.set(i,[e]):o.push(e)}let g=e=>e===a(`direct:deepseek`)||e===a(`site:https://api.deepseek.com`)?nn(`deepseek`)??nn(e):nn(e),_=[];for(let[e,t]of c)_.push({id:`ch:${d.get(e)??e}`,name:e,models:t,subscriptions:m.get(e)??[],balance:g(e),dot:Oi(o,t[0]?.provider??``),channelKind:u.get(e)??`unknown`});for(let[e,t]of h)c.has(e)||_.push({id:e,name:t,models:[],subscriptions:m.get(e)??[],balance:nn(t),dot:Oi(o,t),channelKind:`vendor`});let v=new Set(_.flatMap(e=>[Q(e.name),...e.balance===void 0?[]:[Q(e.balance.provider)]]));for(let e of s)v.has(Q(e.provider))||(e.error===void 0||e.provider.startsWith(`custom:`))&&_.push({id:`bal:${e.provider}`,name:e.displayName,models:[],subscriptions:[],balance:e,dot:Oi(o,e.displayName),channelKind:`vendor`});return _.filter(e=>N.hideUnidentified&&e.channelKind===`unknown`?!1:!U||e.models.length>0).sort((e,t)=>{let n=Ni(t)-Ni(e);return n===0?e.models.length===0&&t.models.length===0?0:t.models.length===0?-1:e.models.length===0?1:e.name.localeCompare(t.name,`zh`):n})},[e.byDayModelsSite,e.byModel,l,s,o,Vt,t,U,N.hideUnidentified]),Rn=(0,d.useMemo)(()=>Ln.filter(e=>e.models.length>0||e.subscriptions.length>0).map(e=>e.id),[Ln]),zn=Rn.length>0&&Rn.every(e=>Tt.has(e)),Bn=()=>{let e=new Set(zn?[]:Rn);Et(e),De([...e])},Hn=(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`model`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`inputTokens`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`outputTokens`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`cacheHitRate`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`actual`)})]})}),Un=e=>(0,m.jsx)(`span`,{className:z.modelCell,children:(0,m.jsxs)(`span`,{children:[(0,m.jsxs)(`span`,{className:z.modelName,children:[e.name,e.uncatalogued&&(0,m.jsx)(`span`,{className:z.uncataloguedTag,"data-testid":`billing-uncatalogued-tag`,children:t(`uncatalogued`)}),e.estimatedPricing&&(0,m.jsx)(`span`,{className:z.estimatedTag,"data-testid":`billing-estimated-tag`,children:t(`estimatedPricing`)})]}),(0,m.jsx)(`span`,{className:z.modelProvider,children:Ht(e.provider)})]})}),Gn=e.bySite?.unknown?.calls??0,Kn=X.reduce((e,t)=>e+t.estimated,0),qn=Ce.cost>0||Gn>0?Ce.cost:Kn,Z=(0,d.useMemo)(()=>{if(B===`all`){let e,t=0;for(let[n,r]of Object.entries(P)){let i=Ur(r);i>t&&(t=i,e=n)}return{cost:qn,calls:Ce.calls,input:Ce.input,output:Ce.output,cacheHit:Ce.cacheHit,cacheMiss:Ce.cacheMiss,cacheWrite:Ce.cacheWrite??0,reasoning:Ce.reasoning??0,peakDay:e,peakTokens:t}}return B===`custom`?qr(P,V.start,V.end):Kr(P,K(),B)},[B,V,qn,Ce,P]),Yn=B===`custom`?V.start===V.end?V.start:`${V.start} – ${V.end}`:t({today:`avgRangeToday`,"7d":`avgRange7d`,week:`avgRangeWeek`,month:`avgRangeMonth`,all:`avgRangeAll`}[B]),Xn=(0,d.useMemo)(()=>X.map(e=>({key:e.key,name:e.name,color:e.color})),[X]),Zn=Pn.length>=2?Pn.at(-2)?.cost??0:0,Qn=Zn>0?(gn-Zn)/Zn*100:0,er=(0,m.jsxs)(`div`,{ref:he,className:y(z.dashboard,r&&z.nativeSettingsDashboard),"data-testid":r?`native-billing-settings-dashboard`:`billing-dashboard`,children:[!r&&(0,m.jsxs)(`div`,{className:z.dashboardHead,"data-testid":`billing-dashboard-head`,children:[(0,m.jsxs)(`div`,{children:[b(`billing.dashboard.decor`,{position:`head`}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`h2`,{className:z.dashboardTitle,children:t(`title`)}),b(`billing.dashboard.decor`,{position:`headTitle`})]}),(0,m.jsxs)(`p`,{className:z.dashboardSubtitle,children:[t(`lastUpdated`),` `,An,e.timezone===void 0?null:` · ${e.timezone.name} (${e.timezone.offset})`]})]}),(0,m.jsxs)(`div`,{className:z.dashboardRight,children:[(0,m.jsx)(`span`,{className:z.currencyToggle,role:`group`,"aria-label":t(`language`),children:[`en`,`zh`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.currencyButton,g===e&&z.currencyButtonActive),"aria-pressed":g===e,"data-testid":`billing-language-${e}`,onClick:()=>{_(e)},children:e===`en`?`EN`:`中`},e))}),(0,m.jsx)(`span`,{className:z.currencyToggle,role:`group`,"aria-label":t(`currency`),children:[`cny`,`usd`,`eur`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.currencyButton,f===e&&z.currencyButtonActive),"aria-pressed":f===e,"data-testid":`billing-currency-${e}`,title:t(e===`cny`?`currencyCny`:e===`usd`?`currencyUsd`:`currencyEur`),onClick:()=>{h(e)},children:e===`cny`?`¥ CNY`:e===`usd`?`$ USD`:`€ EUR`},e))}),o.checked&&(0,m.jsxs)(`span`,{className:y(z.healthBadge,o.available?z.healthBadgeOk:z.healthBadgeBad),children:[(0,m.jsx)(`span`,{className:y(z.healthDot,o.available?z.healthOk:z.healthBad),role:`img`,"aria-label":o.available?t(`healthDotLive`):t(`healthDotFailed`),title:o.available?t(`healthDotLive`):t(`healthDotFailed`)}),o.available?`${t(`healthModelsLive`).replace(`{n}`,String(o.models))}${o.failures>0?` · ${t(`healthVendorsDown`).replace(`{n}`,String(o.failures))}`:``}`:t(`healthVendorsUnavailable`).replace(`{n}`,String(o.failures))]}),(0,m.jsx)(`button`,{type:`button`,className:z.closeButton,"aria-label":t(`close`),"data-testid":`billing-close`,onClick:n,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"aria-hidden":`true`,children:[(0,m.jsx)(`path`,{d:`M18 6 6 18`}),(0,m.jsx)(`path`,{d:`m6 6 12 12`})]})})]})]}),!r&&e.staleSnapshot===!0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-stale-snapshot`,children:t(`staleSnapshotNotice`)}),!r&&(0,m.jsx)(`nav`,{className:z.tabNav,"data-testid":`billing-tab-nav`,role:`tablist`,"aria-label":t(`title`),children:Nr.map(e=>(0,m.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":F===e.id,"aria-controls":`billing-tab-panel-${e.id}`,className:y(z.tabButton,F===e.id&&z.tabButtonActive),"data-testid":`billing-tab-${e.id}`,onClick:()=>{Oe(e.id)},children:[(0,m.jsx)(`span`,{className:z.tabRailIcon,"aria-hidden":`true`,children:Fr[e.id]}),(0,m.jsx)(`span`,{className:z.tabNavLabel,children:t(e.labelKey)})]},e.id))}),(0,m.jsxs)(`div`,{className:y(z.dashboardBody,r&&z.nativeSettingsBody),children:[F===`queue`&&(0,m.jsx)(ta,{t,language:g,navigateToSession:me}),F===`overview`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-overview`,children:[c?.kind===`drift`&&c.spent!==void 0&&Ne!==Fe()&&(0,m.jsxs)(`div`,{className:z.reconcileNotice,"data-testid":`billing-reconcile-notice`,role:`note`,children:[(0,m.jsx)(`span`,{className:z.reconcileIcon,"aria-hidden":`true`,children:(0,m.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,m.jsx)(`line`,{x1:`12`,y1:`10`,x2:`12`,y2:`16`}),(0,m.jsx)(`line`,{x1:`12`,y1:`7.5`,x2:`12.01`,y2:`7.5`})]})}),(0,m.jsx)(`span`,{className:z.reconcileText,children:t(`reconcileDrift`).replace(`{provider}`,c.provider??``).replace(`{spent}`,W(c.spent)).replace(`{today}`,W(c.todayOfficialCost??0))}),(0,m.jsx)(`button`,{type:`button`,className:z.reconcileDismiss,"data-testid":`billing-reconcile-dismiss`,onClick:Ie,children:t(`reconcileDismiss`)})]}),pe===!0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-balance-stale`,children:t(`balanceStaleNotice`)}),(0,m.jsxs)(`section`,{className:z.hero,"data-testid":`billing-hero`,children:[b(`billing.dashboard.decor`,{position:`hero`}),(0,m.jsxs)(`div`,{className:z.heroTop,children:[(0,m.jsxs)(`div`,{className:z.heroMain,children:[(0,m.jsx)(`span`,{className:z.heroLabel,"data-testid":`billing-hero-range-label`,children:Yn}),(0,m.jsxs)(`div`,{className:z.heroReadout,children:[(0,m.jsx)(`span`,{className:z.heroCurrency,"aria-hidden":`true`,children:Bt}),(0,m.jsx)(`span`,{className:z.heroValue,"data-testid":`billing-hero-range-value`,children:W(Z.cost).slice(1)})]}),(0,m.jsxs)(`span`,{className:z.heroMeta,children:[Z.calls.toLocaleString(),` `,t(`calls`),B===`month`&&En>0&&(0,m.jsxs)(`span`,{className:z.heroPred,children:[` `,t(`monthProjected`),` `,W(En)]})]})]}),Dn!==null&&(0,m.jsxs)(`div`,{className:z.heroGauge,"data-testid":`billing-hero-gauge`,children:[(0,m.jsxs)(`div`,{className:z.heroGaugeDial,children:[(0,m.jsxs)(`svg`,{className:z.heroGaugeSvg,viewBox:`0 0 120 120`,"aria-hidden":`true`,children:[(0,m.jsx)(`defs`,{children:(0,m.jsxs)(`linearGradient`,{id:`heroRingGrad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,m.jsx)(`stop`,{offset:`0%`,stopColor:`var(--ds-cyan)`}),(0,m.jsx)(`stop`,{offset:`55%`,stopColor:`var(--ds-blue)`}),(0,m.jsx)(`stop`,{offset:`100%`,stopColor:`var(--ds-amber)`})]})}),(0,m.jsx)(`circle`,{className:z.heroGaugeTrack,cx:`60`,cy:`60`,r:`52`}),(0,m.jsx)(`circle`,{className:y(z.heroGaugeArc,Dn.over&&z.heroGaugeArcOver),cx:`60`,cy:`60`,r:`52`,style:{strokeDasharray:`${Dn.remainRatio*326.7} 326.7`},stroke:Dn.over?void 0:`url(#heroRingGrad)`})]}),(0,m.jsxs)(`span`,{className:z.heroGaugeCenter,children:[(0,m.jsxs)(`span`,{className:y(z.heroGaugeRemain,Dn.over&&z.heroGaugeRemainOver),children:[Bt,un(Dn.remainCny,f).toFixed(2)]}),(0,m.jsx)(`span`,{className:z.heroGaugeLabel,children:t(`budgetRemain`)})]})]}),(0,m.jsxs)(`span`,{className:z.heroGaugeSub,children:[W(J),` / `,W(S)]})]})]}),(0,m.jsxs)(`div`,{className:z.heroSide,children:[(0,m.jsxs)(`div`,{className:z.heroSideItem,children:[(0,m.jsx)(`span`,{className:z.heroSideLabel,children:t(`yearCost`)}),(0,m.jsx)(`span`,{className:z.heroSideValue,children:W(Tn)})]}),(0,m.jsxs)(`div`,{className:z.heroSideItem,children:[(0,m.jsx)(`span`,{className:z.heroSideLabel,children:t(`todayCost`)}),(0,m.jsxs)(`span`,{className:z.heroSideValue,children:[W(gn),(0,m.jsxs)(`span`,{className:y(z.delta,Qn>=0?z.deltaUp:z.deltaDown),children:[Qn>=0?`▲`:`▼`,` `,Math.abs(Qn).toFixed(1),`%`]})]})]}),En>0&&(0,m.jsxs)(`div`,{className:z.heroSideItem,title:t(`monthProjectedHint`),children:[(0,m.jsx)(`span`,{className:z.heroSideLabel,children:t(`monthProjected`)}),(0,m.jsx)(`span`,{className:z.heroSideValue,children:W(En)})]}),En<=0&&(0,m.jsx)(`span`,{className:z.heroSideSpacer,"aria-hidden":`true`})]})]}),(e.unpricedModels?.length??0)>0&&!Le.has(`unpriced`)&&(0,m.jsxs)(`div`,{className:z.unpricedHint,"data-testid":`billing-unpriced-hint`,children:[(0,m.jsx)(`span`,{className:z.unpricedHintBody,children:t(`unpricedHint`).replace(`{count}`,String(e.unpricedModels?.length??0))}),(0,m.jsx)(`button`,{type:`button`,className:z.noticeDismiss,"data-testid":`billing-unpriced-dismiss`,"aria-label":t(`close`),onClick:()=>{Re(`unpriced`)},children:`×`})]}),(e.total.searchCalls??0)>0&&!Le.has(`search-estimate`)&&(0,m.jsxs)(`div`,{className:z.unpricedHint,"data-testid":`billing-search-estimate-hint`,children:[(0,m.jsx)(`span`,{className:z.unpricedHintBody,children:t(`searchEstimateHint`).replace(`{count}`,String(e.total.searchCalls??0)).replace(`{each}`,W(e.searchCallEstimateCny??0))}),(0,m.jsx)(`button`,{type:`button`,className:z.noticeDismiss,"data-testid":`billing-search-estimate-dismiss`,"aria-label":t(`close`),onClick:()=>{Re(`search-estimate`)},children:`×`})]}),(e.unreadableSessions??0)>0&&!Le.has(`unreadable`)&&(0,m.jsxs)(`div`,{className:z.staleNotice,"data-testid":`billing-sessions-unreadable`,children:[(0,m.jsxs)(`div`,{className:z.staleNoticeBody,children:[t(`unreadableNotice`).replace(`{count}`,String(e.unreadableSessions)),(e.unreadableNoLedgerSessions??0)>0&&(0,m.jsx)(`div`,{className:z.staleNoticeSub,"data-testid":`billing-sessions-no-ledger`,children:t(`unreadableNoLedgerNotice`).replace(`{count}`,String(e.unreadableNoLedgerSessions))}),(e.unreadableFormatSessions??0)>0&&(0,m.jsx)(`div`,{className:z.staleNoticeSub,"data-testid":`billing-sessions-format-unsupported`,children:t(`unreadableFormatNotice`).replace(`{count}`,String(e.unreadableFormatSessions))})]}),(0,m.jsx)(`button`,{type:`button`,className:z.noticeDismiss,"data-testid":`billing-unreadable-dismiss`,"aria-label":t(`close`),onClick:()=>{Re(`unreadable`)},children:`×`})]}),(0,m.jsxs)(`div`,{className:z.kpiZone,children:[(0,m.jsxs)(`div`,{className:z.kpiZoneHead,children:[(0,m.jsx)(`span`,{className:z.kpiZoneLabel,children:t(`kpiRange`)}),(0,m.jsx)(`div`,{className:z.heatmapRangeSwitch,"data-testid":`billing-kpi-range`,role:`group`,"aria-label":t(`kpiRange`),children:[[`today`,`avgRangeToday`],[`7d`,`avgRange7d`],[`week`,`avgRangeWeek`],[`month`,`avgRangeMonth`],[`all`,`avgRangeAll`],[`custom`,`avgRangeCustom`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(z.heatmapRangeButton,B===e&&z.heatmapRangeButtonActive),"data-testid":`billing-kpi-range-${e}`,"aria-pressed":B===e,onClick:()=>{st(e),ae(e)},children:t(n)},e))})]}),B===`custom`&&(0,m.jsxs)(`div`,{className:z.kpiCustomRange,"data-testid":`billing-kpi-custom-range`,children:[(0,m.jsxs)(`label`,{children:[t(`customRangeStart`),(0,m.jsx)(`input`,{type:`date`,value:V.start,max:K(),"data-testid":`billing-kpi-custom-start`,onChange:e=>{H({start:e.target.value})}})]}),(0,m.jsxs)(`label`,{children:[t(`customRangeEnd`),(0,m.jsx)(`input`,{type:`date`,value:V.end,max:K(),"data-testid":`billing-kpi-custom-end`,onChange:e=>{H({end:e.target.value})}})]})]}),(0,m.jsx)(`section`,{className:z.kpiGrid,"data-testid":`billing-kpi-grid`,children:(()=>{let e=Object.keys(P).sort().slice(-7),n=K(),r=e.indexOf(n),i=(e,t)=>e[t]??0,a=e.map(e=>P[e]?.cost??0),o=e.map(e=>P[e]?.calls??0),s=e.map(e=>{let t=P[e];return t===void 0?0:Ur(t)}),c=e.map(e=>{let t=P[e];return t!==void 0&&t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0}),l=r>0&&i(a,r-1)>0?(i(a,r)-i(a,r-1))/i(a,r-1)*100:0,u=r>0&&i(o,r-1)>0?(i(o,r)-i(o,r-1))/i(o,r-1)*100:0,d=r>0&&i(s,r-1)>0?(i(s,r)-i(s,r-1))/i(s,r-1)*100:0,f=r>0&&i(c,r-1)>0?i(c,r)-i(c,r-1):0,h=(e,t)=>B===`custom`?null:(0,m.jsx)(`svg`,{viewBox:`0 0 28 12`,preserveAspectRatio:`none`,style:{display:`block`,width:`100%`,height:`12px`},children:e.map((n,r)=>{let i=n/Math.max(...e,1)*10,a=r*4;return(0,m.jsx)(`rect`,{x:a,y:12-i,width:`2.5`,height:i,fill:t,opacity:r===e.length-1?1:.6},r)})}),g=e=>B===`custom`?null:(0,m.jsxs)(`span`,{className:y(z.kpiDelta,e>0?z.kpiDeltaUp:e<0?z.kpiDeltaDown:z.kpiDeltaFlat),children:[e>0?`▲`:e<0?`▼`:``,` `,Math.abs(e).toFixed(1),`%`]});return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-tile`,children:[(0,m.jsxs)(`div`,{className:z.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescCacheHit`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`cacheHitRate`)})}),g(f)]}),(0,m.jsx)(`span`,{className:y(z.kpiValue,z.kpiGreen),children:mn(Z.cacheHit+Z.cacheMiss>0?Z.cacheHit/(Z.cacheHit+Z.cacheMiss)*100:0)}),(0,m.jsx)(`div`,{className:z.kpiSpark,children:h(c,`var(--ds-cyan)`)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[q(Z.cacheHit),` / `,q(Z.cacheHit+Z.cacheMiss),Z.cacheWrite>0?` · ${t(`tokenCacheWrite`)} ${q(Z.cacheWrite)}`:``]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,children:[(0,m.jsxs)(`div`,{className:z.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescTokens`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`tokens`)})}),g(d)]}),(0,m.jsx)(`span`,{className:z.kpiValue,children:q(Z.input+Z.output)}),(0,m.jsx)(`div`,{className:z.kpiSpark,children:h(s,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[t(`inputTokens`),` `,q(Z.input),` · `,t(`outputTokens`),` `,q(Z.output)]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-avg`,children:[(0,m.jsxs)(`div`,{className:z.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescAvgCost`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`avgCost`)})}),g(l)]}),(0,m.jsx)(`span`,{className:z.kpiValue,children:W(Z.calls>0?Z.cost/Z.calls:0)}),(0,m.jsx)(`div`,{className:z.kpiSpark,children:h(a,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[t(`calls`),` `,Z.calls.toLocaleString()]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,children:[(0,m.jsxs)(`div`,{className:z.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescCalls`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`calls`)})}),g(u)]}),(0,m.jsx)(`span`,{className:z.kpiValue,children:Z.calls.toLocaleString()}),(0,m.jsx)(`div`,{className:z.kpiSpark,children:h(o,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[X.length,` `,t(`models`)]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-think`,children:[(0,m.jsx)(`div`,{className:z.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescReasoning`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`tokenReasoningShare`)})})}),(0,m.jsx)(`span`,{className:y(z.kpiValue,z.kpiGreen),children:mn(Z.output>0?Z.reasoning/Z.output*100:0)}),(0,m.jsx)(`span`,{className:z.kpiDetail,children:q(Z.reasoning)})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-io`,children:[(0,m.jsx)(`div`,{className:z.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescIo`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`tokenIo`)})})}),(0,m.jsx)(`span`,{className:z.kpiValue,children:(Z.output>0?Z.input/Z.output:0).toFixed(2)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[q(Z.input),` / `,q(Z.output)]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-peak`,children:[(0,m.jsx)(`div`,{className:z.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescPeak`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`tokenPeak`)})})}),(0,m.jsx)(`span`,{className:z.kpiValue,children:Z.peakTokens>0?wn(Z.peakTokens):`—`}),(0,m.jsx)(`span`,{className:z.kpiDetail,children:Z.peakDay??`—`})]})]})})()})]}),(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-panel-heatmap`,children:[(0,m.jsxs)(`div`,{className:z.panelHead,children:[(0,m.jsx)(`h3`,{className:z.panelTitle,children:t(`heatmap`)}),(0,m.jsx)(`div`,{className:z.heatmapRangeSwitch,"data-testid":`billing-heatmap-metric`,role:`group`,"aria-label":t(`heatmap`),children:[`cost`,`tokens`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.heatmapRangeButton,We===e&&z.heatmapRangeButtonActive),"data-testid":`billing-heatmap-metric-${e}`,"aria-pressed":We===e,onClick:()=>{qe(e)},children:t(e===`cost`?`metricCost`:`metricTokens`)},e))}),(0,m.jsx)(`div`,{className:z.heatmapRangeSwitch,"data-testid":`billing-heatmap-range`,role:`group`,"aria-label":t(`heatmap`),children:[`month`,`half`,`year`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.heatmapRangeButton,ze===e&&z.heatmapRangeButtonActive),"data-testid":`billing-heatmap-range-${e}`,"aria-pressed":ze===e,onClick:()=>{Be(e)},children:t(e===`month`?`heatmapMonth`:e===`half`?`heatmapHalf`:`heatmapYear`)},e))}),(0,m.jsxs)(`span`,{className:z.panelHint,"data-testid":`billing-heatmap-summary`,children:[t(`heatmapTotal`),` `,We===`tokens`?q(Y):W(Y),` · `,t(`activeDays`),` `,Mn,` · `,t(`streakDays`),` `,Nn]})]}),(0,m.jsx)($n,{days:jn,currency:f,t,range:ze,unit:We})]})]}),F===`agents`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-agents`,children:[(0,m.jsxs)(`section`,{className:z.agentSummary,"data-testid":`billing-agent-summary`,children:[(0,m.jsxs)(`span`,{className:z.agentSummaryItem,children:[(0,m.jsx)(`span`,{className:z.agentSummaryValue,children:String(_e.agents)}),(0,m.jsx)(`span`,{className:z.agentSummaryLabel,children:t(`agentsCount`)})]}),(0,m.jsxs)(`span`,{className:z.agentSummaryItem,children:[(0,m.jsx)(`span`,{className:z.agentSummaryValue,children:String(_e.delegations)}),(0,m.jsx)(`span`,{className:z.agentSummaryLabel,children:t(`agentsDelegations`)})]}),(0,m.jsxs)(`span`,{className:z.agentSummaryItem,children:[(0,m.jsx)(`span`,{className:z.agentSummaryValue,children:String(_e.roots)}),(0,m.jsx)(`span`,{className:z.agentSummaryLabel,children:t(`agentsRoots`)})]}),_e.costliest!==void 0&&_e.costliest.chainCost>0&&(0,m.jsxs)(`span`,{className:z.agentSummaryItem,children:[(0,m.jsx)(`span`,{className:z.agentSummaryValue,children:W(_e.costliest.chainCost)}),(0,m.jsx)(`span`,{className:z.agentSummaryLabel,children:t(`agentsMostExpensive`)})]})]}),ge.length===0||_e.delegations===0?(0,m.jsx)(`p`,{className:z.contextEmpty,"data-testid":`billing-agents-empty`,children:t(`agentsNoData`)}):(0,m.jsx)(`div`,{className:z.agentTree,"data-testid":`billing-agent-tree`,children:(()=>{let e=n=>(0,m.jsxs)(`div`,{className:z.agentNode,children:[(0,m.jsxs)(`div`,{className:z.agentRow,style:{paddingLeft:`${String(n.depth*16)}px`},children:[(0,m.jsx)(`span`,{className:z.agentKind,children:n.depth===0?t(`agentsRoot`):t(`agentsSubagent`)}),(0,m.jsx)(`span`,{className:z.agentTitle,children:n.title??`${t(`sessionUntitled`)} · ${n.id.slice(0,8)}`}),(0,m.jsx)(`span`,{className:z.agentCalls,children:n.calls.toLocaleString()}),(0,m.jsx)(`span`,{className:z.agentCost,children:W(n.cost)}),n.children.length>0&&(0,m.jsxs)(`span`,{className:y(z.ubTag,z.ubTagNeutral),"data-testid":`billing-agent-chain`,children:[t(`agentsChainTotal`),` `,W(n.chainCost)]})]}),n.children.map(e)]},n.id);return ge.map(e)})()})]}),F===`settings`&&(0,m.jsx)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-settings`,children:(0,m.jsxs)(`div`,{className:y(z.settingsLayout,r&&z.nativeSettingsLayout),children:[!r&&(0,m.jsx)(`aside`,{className:z.settingsNav,"data-testid":`billing-settings-nav`,role:`navigation`,"aria-label":`settings`,children:[{id:`display-pref`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:[(0,m.jsx)(`path`,{d:`M5 3v10M11 3v10`}),(0,m.jsx)(`circle`,{cx:`5`,cy:`6.5`,r:`1.8`}),(0,m.jsx)(`circle`,{cx:`11`,cy:`9.5`,r:`1.8`})]}),label:t(`settingsNavDisplayPref`)},{id:`budget`,icon:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:(0,m.jsx)(`path`,{d:`M5 3l3 4 3-4M8 7v6M5.5 9.5h5M5.5 12h5`})}),label:t(`settingsNavBudget`)},{id:`alert`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`path`,{d:`M8 2a4 4 0 0 1 4 4v3l1.5 2.5h-11L4 9V6a4 4 0 0 1 4-4z`}),(0,m.jsx)(`path`,{d:`M6.5 13.5a1.5 1.5 0 0 0 3 0`})]}),label:t(`settingsNavAlert`)},{id:`display`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`}),(0,m.jsx)(`path`,{d:`M8 2a6 6 0 0 1 0 12z`,fill:`currentColor`,stroke:`none`})]}),label:t(`settingsNavDisplay`)},{id:`advanced`,icon:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:(0,m.jsx)(`path`,{d:`M8 2v12M2.8 5l10.4 6M13.2 5L2.8 11`})}),label:t(`settingsNavAdvanced`),advanced:!0},{id:`about`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`}),(0,m.jsx)(`path`,{d:`M8 7.5V11`}),(0,m.jsx)(`circle`,{cx:`8`,cy:`5.2`,r:`0.9`,fill:`currentColor`,stroke:`none`})]}),label:t(`settingsNavAbout`)}].map(e=>(0,m.jsxs)(`button`,{type:`button`,className:y(z.settingsNavItem,Qe===e.id&&z.settingsNavItemActive,e.advanced&&z.settingsNavItemAdvanced),"data-testid":`billing-settings-nav-${e.id}`,onClick:()=>{rt(e.id)},children:[(0,m.jsx)(`span`,{className:z.settingsNavIcon,"aria-hidden":`true`,children:e.icon}),e.label]},e.id))}),(0,m.jsxs)(`div`,{className:z.settingsPane,children:[(0,m.jsx)(`input`,{className:y(z.ubSearch,z.settingsSearch),type:`search`,value:et,placeholder:t(`settingsSearchPlaceholder`),"aria-label":t(`settingsSearchPlaceholder`),"data-testid":`billing-settings-search`,onChange:e=>{tt(e.target.value)}}),et.trim()!==``&&fa(et)&&(0,m.jsx)(`p`,{className:z.setCardDesc,"data-testid":`billing-settings-search-empty`,children:t(`settingsSearchEmpty`).replace(`{query}`,et.trim())}),(0,m.jsxs)(`div`,{hidden:nt(da.display),className:z.setCard,id:`settings-display-pref`,"data-testid":`billing-density-motion-card`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsx)(`h3`,{className:z.setCardTitle,children:t(`settingsSectionDisplay`)})})}),(0,m.jsxs)(`div`,{className:z.densityRow,children:[(0,m.jsxs)(`div`,{className:z.densityLeft,children:[(0,m.jsx)(`strong`,{children:t(`densityLabel`)}),(0,m.jsx)(`span`,{children:t(`densityHint`)})]}),(0,m.jsx)(`div`,{className:z.densityButtons,"data-testid":`billing-density-buttons`,children:[`compact`,`default`,`comfortable`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.densityButton,Je===e&&z.densityButtonActive,e===`comfortable`&&z.densityButtonComfortable),"data-testid":`billing-density-${e}`,onClick:()=>{it(e)},children:t(e===`compact`?`densityCompact`:e==="default"?`densityDefault`:`densityComfortable`)},e))})]}),(0,m.jsxs)(`div`,{className:z.densityRow,children:[(0,m.jsxs)(`div`,{className:z.densityLeft,children:[(0,m.jsx)(`strong`,{children:t(`motionLabel`)}),(0,m.jsx)(`span`,{children:t(`motionHint`)})]}),(0,m.jsx)(`div`,{className:z.densityButtons,"data-testid":`billing-motion-buttons`,children:[`off`,`subtle`,`rich`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.densityButton,Xe===e&&z.densityButtonActive),"data-testid":`billing-motion-${e}`,onClick:()=>{ot(e)},children:t(e===`off`?`motionOff`:e===`subtle`?`motionSubtle`:`motionRich`)},e))})]})]}),(0,m.jsxs)(`section`,{hidden:nt(da.budget),className:z.setCard,"data-testid":`billing-budget`,id:`settings-budget`,children:[(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`budget`),(0,m.jsx)(ra,{label:t(`budgetHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":x,"aria-label":t(`budget`),"data-testid":`billing-budget-toggle`,className:y(z.switch,x&&z.switchOn),onClick:C,children:(0,m.jsx)(`span`,{className:z.switchKnob})})]}),x&&(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`budgetAmount`)}),(0,m.jsxs)(`span`,{className:z.inp,"data-testid":`billing-budget-input-wrap`,children:[(0,m.jsx)(`span`,{className:z.affix,"aria-hidden":`true`,children:`¥`}),(0,m.jsx)(`input`,{className:z.budgetInput,"data-testid":`billing-budget-input`,type:`number`,min:0,step:1,value:S===0?``:S,placeholder:e.budget===void 0?`0`:String(e.budget),"aria-label":`${t(`budget`)}(${f===`usd`?`USD`:f===`eur`?`EUR`:`CNY`})`,title:`${t(`budget`)}(${f===`usd`?`USD`:f===`eur`?`EUR`:`CNY`})`,onChange:e=>{w(e.target.valueAsNumber)}})]})]}),S>0&&(()=>{let e=J/S*100;return(0,m.jsx)(`div`,{className:z.ctlRowStretch,children:(0,m.jsx)(`div`,{className:z.prog,role:`progressbar`,"aria-valuenow":Math.min(e,100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":t(`budget`),"data-testid":`billing-budget-track`,children:(0,m.jsx)(`div`,{className:y(z.progFill,e>=100&&z.budgetFillOver,e>=80&&e<100&&z.budgetFillWarn),style:{width:`${Math.min(e,100)}%`}})})})})(),S>0&&(0,m.jsx)(`p`,{className:z.setCardDesc,"data-testid":`billing-budget-value`,children:t(`budgetSummary`).replace(`{used}`,W(J)).replace(`{total}`,W(S))})]}),(0,m.jsxs)(`div`,{className:z.ctlCol,"data-testid":`billing-model-budgets`,children:[(0,m.jsxs)(`span`,{className:z.modelBudgetTitle,children:[t(`modelBudgetTitle`),(0,m.jsx)(ra,{label:t(`modelBudgetHint`),t})]}),wt.length===0&&(0,m.jsx)(`p`,{className:z.modelBudgetHint,children:t(`emptyHint`)}),(0,m.jsx)(`div`,{className:z.modelBudgetList,children:wt.map(e=>(0,m.jsxs)(`div`,{className:z.modelBudgetRow,children:[(0,m.jsx)(`span`,{className:z.modelBudgetName,title:e.name??e.key,children:e.name??e.key}),(0,m.jsx)(`span`,{className:z.modelBudgetCost,"data-testid":`billing-model-budget-cost-${e.key}`,children:W(e.cost)}),(0,m.jsxs)(`span`,{className:z.inp,children:[(0,m.jsx)(`span`,{className:z.affix,"aria-hidden":`true`,children:`¥`}),(0,m.jsx)(`input`,{className:z.budgetInput,type:`number`,min:0,step:1,value:T[e.key]??``,placeholder:t(`modelBudgetPlaceholder`),"aria-label":`${t(`modelBudgetTitle`)} · ${e.name??e.key}`,"data-testid":`billing-model-budget-${e.key}`,onChange:t=>{E(e.key,t.target.valueAsNumber)}})]})]},e.key))})]})]}),(0,m.jsxs)(`section`,{hidden:nt(da.alert),className:z.setCard,"data-testid":`billing-peak-alert-settings`,id:`settings-alert`,children:[(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`peakAlert`),(0,m.jsx)(ra,{label:t(`peakAlertHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":D.enabled,"aria-label":t(`peakAlert`),"data-testid":`billing-peak-alert-toggle`,className:y(z.switch,D.enabled&&z.switchOn),onClick:()=>{O({...D,enabled:!D.enabled})},children:(0,m.jsx)(`span`,{className:z.switchKnob})})]}),D.enabled&&(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsxs)(`label`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`peakAlertLeadMin`)}),(0,m.jsx)(`span`,{className:z.inp,children:(0,m.jsx)(`input`,{type:`number`,min:1,max:30,step:1,value:D.leadMin,className:z.budgetInput,"aria-label":t(`peakAlertLeadMin`),onChange:e=>{let t=Number(e.target.valueAsNumber);O({...D,leadMin:Number.isFinite(t)?Math.min(30,Math.max(1,Math.round(t))):D.leadMin})}})})]}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`peakAlertPos`)}),(0,m.jsx)(`div`,{className:z.ctlGroup,role:`radiogroup`,"aria-label":t(`peakAlertPos`),children:[`bottom-right`,`center`].map(e=>(0,m.jsxs)(`label`,{className:z.rdo,children:[(0,m.jsx)(`input`,{type:`radio`,name:`peak-pos`,checked:D.position===e,onChange:()=>O({...D,position:e})}),(0,m.jsx)(`span`,{className:z.rdoDot,"aria-hidden":`true`}),t(e===`bottom-right`?`peakAlertPosCorner`:`peakAlertPosCenter`)]},e))})]}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`peakAlertMode`)}),(0,m.jsx)(`div`,{className:z.ctlGroup,role:`radiogroup`,"aria-label":t(`peakAlertMode`),children:[`both`,`peak`,`offPeak`].map(e=>(0,m.jsxs)(`label`,{className:z.rdo,children:[(0,m.jsx)(`input`,{type:`radio`,name:`peak-mode`,checked:D.mode===e,onChange:()=>O({...D,mode:e})}),(0,m.jsx)(`span`,{className:z.rdoDot,"aria-hidden":`true`}),t(e===`both`?`peakAlertModeBoth`:e===`peak`?`peakAlertModePeak`:`peakAlertModeOff`)]},e))})]}),(0,m.jsxs)(`label`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`peakAlertWebNotify`)}),(0,m.jsx)(`input`,{type:`checkbox`,checked:D.webNotify,"aria-label":t(`peakAlertWebNotify`),onChange:e=>{O({...D,webNotify:e.target.checked})}})]}),(0,m.jsx)(`div`,{className:z.ctlRow,children:(0,m.jsx)(`button`,{type:`button`,className:z.btn,onClick:k,children:t(`peakAlertPreview`)})})]})]}),(0,m.jsx)(`section`,{hidden:nt(da.toggles),className:z.setCard,"data-testid":`billing-toggle-setting`,id:`settings-display`,children:(0,m.jsxs)(`div`,{className:z.setGrid3,children:[(0,m.jsx)(`div`,{className:z.setCell,"data-testid":`billing-usage-stats-tool-setting`,children:(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`usageStatsTool`),(0,m.jsx)(ra,{label:t(`usageStatsToolHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":At,"aria-label":t(`usageStatsTool`),"data-testid":`billing-usage-stats-tool-toggle`,className:y(z.switch,At&&z.switchOn),onClick:Mt,children:(0,m.jsx)(`span`,{className:z.switchKnob})})]})}),(0,m.jsxs)(`div`,{className:z.setCell,"data-testid":`billing-livecost-setting`,children:[(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`liveCostBar`),(0,m.jsx)(ra,{label:t(`liveCostBarHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":oe.show,"aria-label":t(`liveCostBar`),"data-testid":`billing-livecost-toggle`,className:y(z.switch,oe.show&&z.switchOn),onClick:()=>se({...oe,show:!oe.show}),children:(0,m.jsx)(`span`,{className:z.switchKnob})})]}),oe.show&&(0,m.jsxs)(`div`,{className:z.rdoRow,"data-testid":`billing-livecost-position`,children:[(0,m.jsx)(`span`,{className:z.rdoLabel,children:t(`liveCostBarPosition`)}),(0,m.jsx)(ma,{liveCostPrefs:oe,onLiveCostPrefs:se,t})]})]}),(0,m.jsx)(`div`,{className:z.setCell,"data-testid":`billing-site-list-setting`,children:(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`siteListDisplay`),(0,m.jsx)(ra,{label:t(`siteListDisplayHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":N.hideUnidentified,"aria-label":t(`siteListDisplay`),"data-testid":`billing-site-hide-unidentified`,className:y(z.switch,N.hideUnidentified&&z.switchOn),onClick:()=>re({hideUnidentified:!N.hideUnidentified}),children:(0,m.jsx)(`span`,{className:z.switchKnob})})]})}),(0,m.jsx)(`div`,{className:z.setCell,"data-testid":`billing-quick-queue-entry-setting`,children:(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`quickQueueEntry`),(0,m.jsx)(ra,{label:t(`quickQueueEntryHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":ue.showEntry,"aria-label":t(`quickQueueEntry`),"data-testid":`billing-quick-queue-entry-toggle`,className:y(z.switch,ue.showEntry&&z.switchOn),onClick:()=>de({...ue,showEntry:!ue.showEntry}),children:(0,m.jsx)(`span`,{className:z.switchKnob})})]})})]})}),(0,m.jsx)(`section`,{hidden:nt(da.displayExtra),className:z.setCard,"data-testid":`billing-display-setting`,id:`settings-display-extra`,children:(0,m.jsxs)(`div`,{className:z.setGrid2,children:[(0,m.jsxs)(`div`,{className:z.setCell,"data-testid":`billing-float-setting`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`floatWindow`),(0,m.jsx)(ra,{label:t(`floatWindowHint`),t})]})})}),(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`cardMode`)}),(0,m.jsx)(`div`,{className:z.ctlGroup,"data-testid":`billing-card-mode`,children:[[`full`,`cardModeFull`],[`compact`,`cardModeCompact`],[`hidden`,`cardModeHidden`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.mode===e&&z.floatModeBtnOn),"data-testid":`billing-card-mode-${e}`,"aria-pressed":M.mode===e,disabled:e===`hidden`&&!ne,title:e===`hidden`&&!ne?t(`cardModeFallback`):void 0,onClick:()=>te({...M,mode:e}),children:t(n)},e))})]}),!ne&&(0,m.jsx)(`p`,{className:z.setCardDesc,"data-testid":`billing-card-mode-fallback`,children:t(`cardModeFallback`)}),ne&&M.mode===`hidden`&&(0,m.jsx)(`p`,{className:z.setCardDesc,"data-testid":`billing-card-mode-hidden-hint`,children:t(`cardModeHiddenHint`)}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`floatMode`)}),(0,m.jsxs)(`div`,{className:z.ctlGroup,"data-testid":`billing-float-mode`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,A.mode===`combined`&&z.floatModeBtnOn),"data-testid":`billing-float-mode-combined`,onClick:()=>j({mode:`combined`,targets:A.targets}),children:t(`floatModeCombined`)}),(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,A.mode===`subscription`&&z.floatModeBtnOn),"data-testid":`billing-float-mode-subscription`,onClick:()=>j({mode:`subscription`,targets:A.targets}),children:t(`floatModeSubscription`)})]})]}),A.mode===`subscription`&&(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`floatTargets`)}),(0,m.jsxs)(`span`,{className:z.ctlGroup,"data-testid":`billing-float-targets`,children:[lt.map(e=>{let t=A.targets.includes(e.id);return(0,m.jsxs)(`label`,{className:z.floatTarget,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:t,"data-testid":`billing-float-target-${e.id}`,onChange:()=>j({mode:`subscription`,targets:t?A.targets.filter(t=>t!==e.id):[...A.targets,e.id]})}),(0,m.jsx)(`span`,{className:z.floatTargetLabel,children:e.label})]},e.id)}),lt.length===0&&(0,m.jsx)(`span`,{className:z.setCardDesc,children:t(`floatNoTargetsHint`)})]})]})]})]}),(0,m.jsxs)(`div`,{className:z.setCell,"data-testid":`billing-card-setting`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`cardDisplay`),(0,m.jsx)(ra,{label:t(`cardDisplayHint`),t})]})})}),(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`cardMetric`)}),(0,m.jsxs)(`div`,{className:z.ctlGroup,"data-testid":`billing-card-metric`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.metric===`money`&&z.floatModeBtnOn),"data-testid":`billing-card-money`,onClick:()=>te({...M,metric:`money`}),children:t(`cardMetricMoney`)}),(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.metric===`tokens`&&z.floatModeBtnOn),"data-testid":`billing-card-tokens`,onClick:()=>te({...M,metric:`tokens`}),children:t(`cardMetricTokens`)})]})]}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`cardSpan`)}),(0,m.jsx)(`div`,{className:z.ctlGroup,"data-testid":`billing-card-span`,children:[[`day`,`cardSpanDay`],[`week`,`cardSpanWeek`],[`month`,`cardSpanMonth`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.span===e&&z.floatModeBtnOn),"data-testid":`billing-card-span-${e}`,"aria-pressed":M.span===e,onClick:()=>te({...M,span:e}),children:t(n)},e))})]}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`cardDeltaBadge`)}),(0,m.jsxs)(`div`,{className:z.ctlGroup,"data-testid":`billing-card-delta`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.showDelta&&z.floatModeBtnOn),"data-testid":`billing-card-delta-show`,"aria-pressed":M.showDelta,onClick:()=>te({...M,showDelta:!0}),children:t(`cardDeltaShow`)}),(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,!M.showDelta&&z.floatModeBtnOn),"data-testid":`billing-card-delta-hide`,"aria-pressed":!M.showDelta,onClick:()=>te({...M,showDelta:!1}),children:t(`cardDeltaHide`)})]})]})]})]})]})}),(0,m.jsx)(`div`,{hidden:nt(da.advanced),id:`settings-advanced`,children:(0,m.jsx)(ca,{userPrices:i,onUserPrices:a,t})}),(0,m.jsx)(`div`,{hidden:nt(da.about),id:`settings-about`,children:(0,m.jsx)(Wn,{t,version:e.pluginVersion})}),(0,m.jsxs)(`section`,{hidden:nt(da.about),className:z.setCard,"data-testid":`billing-more-works`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsx)(`h3`,{className:z.setCardTitle,children:t(`moreWorksTitle`)})})}),(0,m.jsxs)(`div`,{className:z.moreWorkList,children:[(0,m.jsxs)(`a`,{className:z.moreWorkRow,href:`https://github.com/kenz1117/dsh-engram`,target:`_blank`,rel:`noreferrer`,"data-testid":`billing-ad-engram`,children:[(0,m.jsx)(`span`,{className:z.moreWorkName,children:t(`adEngramName`)}),(0,m.jsx)(`span`,{className:z.moreWorkDesc,children:t(`adEngramDesc`)})]}),(0,m.jsxs)(`a`,{className:z.moreWorkRow,href:`https://github.com/kenz1117/dsh-ui-rainbowspeak`,target:`_blank`,rel:`noreferrer`,"data-testid":`billing-ad-rainbowspeak`,children:[(0,m.jsx)(`span`,{className:z.moreWorkName,children:t(`adRainbowName`)}),(0,m.jsx)(`span`,{className:z.moreWorkDesc,children:t(`adRainbowDesc`)})]})]})]})]})]})}),F===`trends`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-trends`,children:[(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-trend`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`trend`)}),b(`billing.dashboard.decor`,{position:`trend`}),(0,m.jsxs)(`span`,{className:z.ubCardControlGroup,children:[(0,m.jsx)(`span`,{className:z.rangeToggle,role:`group`,"aria-label":t(`trend`),children:[7,30].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.rangeButton,je===e&&z.rangeButtonActive),"aria-pressed":je===e,"data-testid":`billing-trend-${e}d`,onClick:()=>{Me(e)},children:t(e===7?`trend7d`:`trend30d`)},e))}),(0,m.jsx)(`span`,{className:z.rangeToggle,role:`group`,"aria-label":t(`trendMetric`),children:[`cost`,`tokens`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.rangeButton,xe===e&&z.rangeButtonActive),"aria-pressed":xe===e,"data-testid":`billing-trend-metric-${e}`,onClick:()=>{Se(e)},children:t(e===`cost`?`trendMetricCost`:`trendMetricTokens`)},e))})]}),(0,m.jsx)(`span`,{className:z.ubCardSub,children:An})]}),(0,m.jsx)(Fn,{data:Pn,models:Xn,currency:f,metric:xe,t})]}),v.length>0&&(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-rounds`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`rounds`)}),Zt.length>0&&(0,m.jsxs)(`span`,{className:z.ubTagError,"data-testid":`billing-rounds-flag-count`,children:[Zt.length,` `,t(`anomaly`)]})]}),(0,m.jsx)(`p`,{className:z.ubCardSub,children:t(`roundsHint`).replace(`{count}`,String(v.length))}),(0,m.jsx)(Jn,{rounds:v,flags:Zt,currency:f,t})]}),e.byTier!==void 0&&(()=>{let e=Qt.peak+Qt.offPeak;if(e<=0)return null;let n=Qt.peak/e*100;return(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-share`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`peakShare`)}),(0,m.jsx)(`span`,{className:z.ubCardSub,children:t(`peakSharePerCall`)})]}),(0,m.jsxs)(`div`,{className:z.shareTrack,"data-testid":`billing-share-track`,children:[(0,m.jsx)(`div`,{className:y(z.shareSeg,z.shareSegPeak),style:{width:`${n}%`}}),(0,m.jsx)(`div`,{className:y(z.shareSeg,z.shareSegOff),style:{width:`${100-n}%`}})]}),(0,m.jsxs)(`div`,{className:z.shareLegend,children:[(0,m.jsxs)(`span`,{className:z.shareItem,children:[(0,m.jsx)(`span`,{className:z.shareDot,style:{background:`var(--ds-blue)`}}),t(`peak`),(0,m.jsxs)(`span`,{className:z.shareValue,"data-testid":`billing-share-peak`,children:[W(Qt.peak),` · `,n.toFixed(1),`%`]})]}),(0,m.jsxs)(`span`,{className:z.shareItem,children:[(0,m.jsx)(`span`,{className:z.shareDot,style:{background:`color-mix(in srgb, var(--ds-blue) 30%, var(--dsb-3))`}}),t(`offPeak`),(0,m.jsxs)(`span`,{className:z.shareValue,"data-testid":`billing-share-offpeak`,children:[W(Qt.offPeak),` · `,(100-n).toFixed(1),`%`]})]})]}),$t>0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-share-savings`,children:t(`offPeakSavings`).replace(`{amount}`,W($t))})]})})()]}),F===`providers`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-providers`,children:[In.length>0&&(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-panel-relay-quota`,children:[(0,m.jsx)(`div`,{className:z.panelHead,children:(0,m.jsx)(`h3`,{className:z.panelTitle,children:t(`panelRelayQuota`)})}),(0,m.jsx)(`div`,{className:z.providerGroupList,"data-testid":`billing-relay-quotas`,children:In.map(e=>(0,m.jsxs)(`div`,{className:z.siteRow,"data-testid":`billing-relay-quota`,children:[(0,m.jsxs)(`span`,{className:z.siteRowName,children:[(0,m.jsx)(`span`,{className:y(z.siteKindTag,Mi[e.kind]),children:ji(e.kind,t)}),(0,m.jsx)(`span`,{className:z.siteRowTitle,children:e.origin})]}),(0,m.jsxs)(`span`,{className:z.siteRowMeta,children:[e.balance!==void 0&&(0,m.jsxs)(`span`,{className:z.siteRowCost,children:[t(`relayBalance`),` `,e.balance.toFixed(2)]}),(e.windows?.length??0)>0?e.windows?.map(e=>{let n=e.remainingPercent<20;return(0,m.jsxs)(`span`,{className:y(z.siteRowCalls,n&&z.siteRowCallsLow),children:[t(`relayWindowUsed`),` `,e.usedPercent,`%`]},e.kind)}):(0,m.jsx)(`span`,{className:z.siteRowCalls,children:t(`relayNoQuota`)})]})]},e.route))})]}),(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-panel-providers`,children:[(0,m.jsxs)(`div`,{className:z.panelHead,children:[(0,m.jsx)(`h3`,{className:z.panelTitle,children:t(`providerBilling`)}),b(`billing.dashboard.decor`,{position:`models`}),(0,m.jsx)(`span`,{className:z.panelHint,children:e.updatedAt===void 0?``:`${t(`lastUpdated`)} ${Fi(e.updatedAt)}`})]}),fe&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-subscriptions-stale`,children:t(`subscriptionsStale`)}),(0,m.jsxs)(`div`,{className:z.providerCtlRow,"data-testid":`billing-provider-controls`,children:[(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,disabled:Rn.length===0,onClick:Bn,children:t(zn?`collapseAll`:`expandAll`)}),(0,m.jsxs)(`span`,{className:z.providerTodayToggle,children:[(0,m.jsx)(`span`,{children:t(`todayOnly`)}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":U,"data-testid":`billing-provider-today-toggle`,className:y(z.switch,U&&z.switchOn),onClick:kt,children:(0,m.jsx)(`span`,{className:z.switchKnob})})]})]}),Ln.length===0?(0,m.jsxs)(`div`,{className:z.emptyState,"data-testid":`billing-provider-empty`,children:[(0,m.jsxs)(`span`,{className:z.emptyIll,"aria-hidden":`true`,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 96 64`,fill:`none`,children:[(0,m.jsx)(`line`,{x1:`6`,y1:`58`,x2:`90`,y2:`58`,stroke:`var(--ds-border-strong)`,strokeWidth:`1`}),(0,m.jsx)(`line`,{x1:`6`,y1:`6`,x2:`6`,y2:`58`,stroke:`var(--ds-border-strong)`,strokeWidth:`1`}),(0,m.jsx)(`path`,{d:`M14 50 L28 40 L42 44 L56 26 L70 30 L82 14`,stroke:`var(--ds-border-strong)`,strokeWidth:`1.5`,strokeLinecap:`round`,fill:`none`,strokeDasharray:`3 3`})]}),(0,m.jsx)(`span`,{className:z.emptyIllDot})]}),(0,m.jsx)(`span`,{className:z.emptyTitle,children:t(U?`todayNoConsumption`:`noData`)}),(0,m.jsx)(`span`,{className:z.emptyDesc,children:t(`emptyHint`)})]}):(0,m.jsx)(`div`,{className:z.providerGroupList,"data-testid":`billing-provider-groups`,children:Ln.map(e=>{let n=e.models.length>0||e.subscriptions.length>0,r=n&&Tt.has(e.id);return(0,m.jsxs)(`div`,{className:z.providerGroup,"data-testid":`billing-provider-group`,children:[(0,m.jsxs)(`div`,{className:y(z.providerGroupHead,n&&z.providerGroupCollapsible),"data-testid":`billing-provider-group-head`,"aria-expanded":n?r:void 0,role:n?`button`:void 0,tabIndex:n?0:void 0,onClick:n?()=>{Dt(e.id)}:void 0,onKeyDown:n?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),Dt(e.id))}:void 0,children:[(0,m.jsxs)(`span`,{className:z.providerGroupTitle,children:[(0,m.jsx)(`span`,{className:y(z.healthDot,e.dot),role:`img`,"aria-label":ia(e.dot,t),title:ia(e.dot,t)}),(()=>{let n=Ht(e.name),r=e.channelKind===`direct`?yr(n):void 0,i=e.channelKind===`direct`?t(`directTag`):e.channelKind===`site`?t(`relayTag`):e.channelKind===`unknown`?t(`unknownTag`):void 0;return(0,m.jsxs)(m.Fragment,{children:[i!==void 0&&(0,m.jsx)(`span`,{className:y(z.kindBadge,e.channelKind===`site`&&z.kindBadgeRelay,e.channelKind===`unknown`&&z.kindBadgeUnknown),"data-testid":`billing-kind-badge`,children:i}),e.channelKind!==`unknown`&&(0,m.jsx)(`span`,{className:z.providerGroupName,children:r??n})]})})(),e.subscriptions.length>0&&(0,m.jsxs)(`span`,{className:z.providerGroupBadge,"data-testid":`billing-provider-sub-count`,children:[e.subscriptions.length,` `,t(`planCountUnit`)]})]}),(0,m.jsxs)(`span`,{className:z.providerGroupMeta,children:[(0,m.jsxs)(`span`,{className:z.providerGroupCost,"data-testid":`billing-provider-cost`,children:[(0,m.jsx)(`span`,{className:z.providerGroupCostLabel,children:t(`cost`)}),e.channelKind===`unknown`?(0,m.jsx)(`span`,{className:z.na,children:`—`}):(0,m.jsx)(`span`,{className:z.providerGroupCostValue,children:W(Ni(e))})]}),!an(e)&&e.balance!==void 0?(0,m.jsxs)(`span`,{className:z.providerGroupBalance,"data-testid":`billing-provider-balance`,children:[(0,m.jsx)(`span`,{className:z.providerGroupBalanceLabel,children:t(`balance`)}),sn(e.balance)]}):(0,m.jsx)(`span`,{className:z.providerGroupBalance,"aria-hidden":`true`}),hi(e.name)===void 0?(0,m.jsx)(`span`,{className:z.providerGroupRecharge,"aria-hidden":`true`}):(0,m.jsx)(`a`,{className:z.providerGroupRecharge,"data-testid":`billing-group-recharge`,href:hi(e.name),target:`_blank`,rel:`noreferrer`,title:t(`rechargeHint`),"aria-label":`${Ht(e.name)} ${t(`recharge`)}`,onClick:e=>{e.stopPropagation()},children:t(`recharge`)})]})]}),e.models.length>0&&(0,m.jsx)(`div`,{className:z.providerStatRow,"data-testid":`billing-provider-stat-row`,children:(()=>{let n=e.models.reduce((e,t)=>({calls:e.calls+t.calls,input:e.input+t.input,output:e.output+t.output}),{calls:0,input:0,output:0}),r=n.input>0?e.models.reduce((e,t)=>e+t.cacheHitRate,0)/e.models.length:0;return[{lbl:t(`calls`),val:n.calls.toLocaleString(),sub:``},{lbl:t(`inputTokens`),val:q(n.input),sub:r>0?`${t(`cacheHitRate`)} ${r.toFixed(0)}%`:``},{lbl:t(`outputTokens`),val:q(n.output),sub:``},{lbl:t(`cost`),val:W(Ni(e)),sub:e.models.length===1?``:`${e.models.length} ${t(`models`)}`}].map((e,t)=>(0,m.jsxs)(`div`,{className:z.providerStatCell,children:[(0,m.jsx)(`div`,{className:z.providerStatLbl,children:e.lbl}),(0,m.jsx)(`div`,{className:z.providerStatVal,children:e.val}),e.sub!==``&&(0,m.jsx)(`div`,{className:z.providerStatSub,children:e.sub})]},t))})()}),r&&(0,m.jsxs)(m.Fragment,{children:[e.channelKind===`unknown`&&(0,m.jsx)(`p`,{className:z.unknownHint,"data-testid":`billing-unknown-hint`,children:t(`unknownChannelHint`)}),e.models.length>0&&(0,m.jsx)(`div`,{className:z.tableScroll,"data-testid":`billing-table-scroll`,children:(0,m.jsxs)(`table`,{className:z.modelTable,children:[Hn,(0,m.jsx)(`tbody`,{children:e.models.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:Un(e)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:z.numCol,children:q(e.input)}),(0,m.jsx)(`td`,{className:z.numCol,children:q(e.output)}),(0,m.jsx)(`td`,{className:z.numCol,children:mn(e.cacheHitRate)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.plan?(0,m.jsxs)(`span`,{className:z.planTag,children:[e.estimated>0?(0,m.jsxs)(`span`,{children:[`≈`,W(e.estimated)]}):null,(0,m.jsx)(`span`,{className:z.planTagBadge,"data-testid":`billing-plan-badge`,children:t(`subscriptionTag`)})]}):e.actual===void 0?e.estimated>0?(0,m.jsxs)(`span`,{title:t(`cellEstimateHint`),children:[`≈`,W(e.estimated)]}):(0,m.jsx)(`span`,{className:z.na,children:`—`}):(()=>{let t=e.officialCost,n=e.actual-t;return t>0&&n>0?(0,m.jsxs)(`span`,{className:z.bucketCost,children:[(0,m.jsx)(`span`,{className:z.bucketOfficial,children:W(t)}),(0,m.jsx)(`span`,{className:z.bucketSep,children:`/`}),(0,m.jsx)(`span`,{className:z.bucketThird,children:W(n)})]}):W(e.actual)})()})]},e.key))})]})}),e.subscriptions.length>0&&(0,m.jsx)(`div`,{className:z.subscriptionGrid,"data-testid":`billing-subscriptions-grid`,children:e.subscriptions.map(e=>{let n=ki(e.status,t);return(0,m.jsxs)(`div`,{className:y(z.subscriptionCard,z.subscriptionCardUpgraded),"data-testid":`billing-subscription-card`,children:[(0,m.jsxs)(`div`,{className:z.subscriptionHead,children:[(0,m.jsx)(`span`,{className:z.subscriptionName,children:Ht(e.displayName)}),e.planType===`code`&&(()=>{let n=at(e.provider),r=n===void 0?void 0:t(`subscriptionFeePerMonth`).replace(`{amount}`,n.currency===`USD`?`$${n.amount}`:`¥${n.amount}`);return(0,m.jsxs)(`span`,{className:z.subscriptionPlan,"data-kind":`code`,children:[r??(e.subscriptionAmount!==void 0&&e.subscriptionAmount>0?t(`subscriptionFeePerMonth`).replace(`{amount}`,W(e.subscriptionAmount)):t(`planTypeCode`)),n?.label!==void 0&&(0,m.jsx)(`span`,{className:z.subscriptionTier,"data-testid":`billing-tier-${e.provider}`,children:n.label}),n!==void 0&&(0,m.jsx)(`span`,{className:z.subscriptionAuto,"data-testid":`billing-auto-${e.provider}`,children:t(`subscriptionAutoDetect`)})]})})(),e.planType===`token`&&(0,m.jsx)(`span`,{className:z.subscriptionPlan,"data-kind":`token`,children:t(`planTypeToken`)}),e.plan!==void 0&&(0,m.jsx)(`span`,{className:z.subscriptionPlan,children:e.plan})]}),n!==``&&(0,m.jsx)(`div`,{className:z.subscriptionStatus,children:n}),e.windows.length===0&&n===``&&(0,m.jsx)(`div`,{className:z.subscriptionStatus,children:t(`subscriptionNoApi`)}),e.windows.map(e=>(0,m.jsx)(na,{window:e,t},e.kind))]},e.provider)})})]})]},e.id)})})]}),(0,m.jsxs)(`div`,{className:z.exportBar,"data-testid":`billing-export-bar`,role:`group`,"aria-label":t(`export`),children:[(0,m.jsx)(`span`,{className:z.exportLabel,children:t(`export`)}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-export-day`,onClick:()=>{Cn(Sn(`usage-daily`,`csv`,Object.keys(P)),vn(P),`text/csv`)},children:t(`exportCsvDay`)}),e.bySession!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-export-sessions`,onClick:()=>{Cn(Sn(`usage-sessions`,`csv`,Object.keys(P)),xn(e.bySession??[]),`text/csv`)},children:t(`exportCsvSession`)}),e.bySite!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-export-sites`,onClick:()=>{Cn(Sn(`usage-sites`,`csv`,Object.keys(P)),yn(e.bySite??{}),`text/csv`)},children:t(`exportCsvSite`)}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-export-json`,onClick:()=>{Cn(Sn(`usage-stats`,`json`,Object.keys(P)),JSON.stringify(e,null,2),`application/json`)},children:t(`exportJson`)})]}),e.bySession!==void 0&&(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-sessions`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`sessions`)}),(0,m.jsx)(`span`,{className:z.ubCardSub,children:e.bySession.length>20?t(`sessionOverflow`).replace(`{limit}`,`20`).replace(`{total}`,String(e.bySession.length)):`${e.bySession.length}`}),e.bySession.length>0&&(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-sessions-view-all`,onClick:()=>{ht(!0)},children:t(`sessionsViewAll`).replace(`{count}`,String(e.bySession.length))})]}),(e.staleLedgerSessions??0)>0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-sessions-stale`,children:t(`staleLedgerNotice`).replace(`{count}`,String(e.staleLedgerSessions))}),(0,m.jsxs)(`div`,{className:z.ubTablewrap,"data-testid":`billing-sessions-table`,children:[ve!==void 0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-session-nav-notice`,role:`note`,children:ve}),(0,m.jsxs)(`table`,{className:z.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`sessionTitle`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`actual`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`lastActive`)})]})}),(0,m.jsxs)(`tbody`,{children:[yt.length===0&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:4,className:z.emptyRow,children:t(`noData`)})}),yt.slice(0,20).map(e=>{let n=e.children!==void 0||e.subs!==void 0,r=n&&ft.has(e.id),i=Pi(e);return(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{className:n?z.sessionGroupRow:void 0,"aria-expanded":n?r:void 0,tabIndex:n?0:void 0,onClick:n?()=>{vt(e.id)}:void 0,onKeyDown:n?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),vt(e.id))}:void 0,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:z.modelName,children:(0,m.jsxs)(`button`,{type:`button`,className:z.sessionLink,"data-testid":`billing-session-open`,title:t(`sessionOpen`),onClick:t=>{t.stopPropagation(),be(e.id)},children:[e.title??`${t(`sessionUntitled`)} · ${e.id.slice(0,8)}`,(e.mergedCount??1)>1?` ×${e.mergedCount}`:``]})}),e.stale===!0&&(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),"data-testid":`billing-session-stale`,children:t(`sessionStaleBadge`)}),(i.calls>0||i.cost>0)&&(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),"data-testid":`billing-session-sub`,children:i.cost>0?t(`sessionSubCost`).replace(`{cost}`,W(i.cost)):t(`sessionSubCalls`).replace(`{calls}`,i.calls.toLocaleString())})]}),bt(e)]}),r&&e.children?.map(e=>(0,m.jsxs)(`tr`,{className:z.sessionChildRow,children:[(0,m.jsx)(`td`,{children:(0,m.jsx)(`button`,{type:`button`,className:z.sessionLink,"data-testid":`billing-session-open`,title:t(`sessionOpen`),onClick:t=>{t.stopPropagation(),be(e.id)},children:(0,m.jsx)(`span`,{className:z.modelProvider,children:e.id.slice(0,8)})})}),bt(e)]},e.id)),r&&e.subs?.map(e=>xt(e,0))]},e.id)})]})]})]}),mt&&(0,m.jsxs)(`div`,{className:z.sessionViewer,"data-testid":`billing-session-viewer`,children:[(0,m.jsxs)(`div`,{className:z.sessionViewerHead,children:[(0,m.jsx)(`h3`,{className:z.sessionViewerTitle,children:t(`sessions`)}),(0,m.jsx)(`input`,{className:z.ubSearch,type:`search`,value:gt,placeholder:t(`sessionViewerSearch`),"aria-label":t(`sessionViewerSearch`),"data-testid":`billing-session-viewer-search`,onChange:e=>{_t(e.target.value)}}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-session-viewer-close`,onClick:()=>{ht(!1),_t(``)},children:t(`close`)})]}),(0,m.jsx)(`div`,{className:z.sessionViewerList,"data-testid":`billing-session-viewer-list`,children:(0,m.jsxs)(`table`,{className:z.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`sessionTitle`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`actual`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`lastActive`)})]})}),(0,m.jsxs)(`tbody`,{children:[Ct.length===0&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:4,className:z.emptyRow,children:t(`noData`)})}),Ct.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsxs)(`td`,{children:[(0,m.jsxs)(`span`,{className:z.modelName,children:[e.title??`${t(`sessionUntitled`)} · ${e.id.slice(0,8)}`,(e.mergedCount??1)>1?` ×${e.mergedCount}`:``]}),e.cwd!==void 0&&(0,m.jsx)(`span`,{className:z.modelProvider,children:ua(e.cwd)}),e.stale===!0&&(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),children:t(`sessionStaleBadge`)})]}),(0,m.jsx)(`td`,{className:z.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:z.numCol,children:W(e.cost)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.lastActive>0?`${K(e.lastActive)} ${Fi(e.lastActive)}`:`—`})]},e.id))]})]})})]})]})]}),F===`token`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-token`,children:[(0,m.jsx)(kn,{stats:e,trendDays:je,onTrendDays:Me,models:Xn,money:W,t}),e.perf!==void 0&&(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-panel-perf`,children:[(0,m.jsxs)(`div`,{className:z.panelHead,children:[(0,m.jsx)(`h3`,{className:z.panelTitle,children:t(`perfTitle`)}),(0,m.jsx)(`span`,{className:z.panelHint,children:t(`perfHint`)})]}),(0,m.jsx)(Vn,{perf:e.perf,models:Xn,t})]})]}),F===`pricing`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-pricing`,children:[(0,m.jsxs)(`div`,{className:z.ubAlert,role:`note`,children:[(0,m.jsxs)(`div`,{className:z.ubAlertLeft,children:[(0,m.jsxs)(`span`,{className:z.ubRate,"data-testid":`billing-rate`,children:[t(`todayRate`),` 1 USD = `,dn(Nt.rate)]}),(0,m.jsx)(`span`,{className:y(z.ubTag,Nt.live?z.ubTagSuccess:z.ubTagNeutral),children:Nt.live?t(`rateLive`):t(`rateBuiltin`)}),zt>0&&(0,m.jsxs)(`span`,{className:z.ubTag,"data-testid":`billing-pricing-synced`,children:[t(`pricingSyncedAt`),` `,new Date(zt).toLocaleTimeString(Vt===`zh`?`zh-CN`:`en-US`,{hour:`2-digit`,minute:`2-digit`})]}),(0,m.jsx)(`button`,{type:`button`,className:z.heatmapRangeButton,"data-testid":`billing-pricing-sync`,disabled:It,onClick:Rt,children:t(It?`pricingSyncing`:`pricingSyncNow`)})]}),(0,m.jsx)(`p`,{className:z.ubAlertNote,children:t(`pricingTip`)})]}),(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-pricing`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`pricing`)}),(0,m.jsx)(`span`,{className:z.ubCardSub,children:t(`pricingUnit`)}),(0,m.jsx)(`input`,{className:z.ubSearch,type:`search`,value:G,placeholder:t(`pricingSearch`),"aria-label":t(`pricingSearch`),"data-testid":`billing-pricing-search`,onChange:e=>{Ut(e.target.value)}})]}),(0,m.jsx)(`div`,{className:y(z.ubTablewrap,z.ubTablewrapPricing),"data-testid":`billing-pricing-table`,children:(0,m.jsxs)(`table`,{className:z.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`thModel`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`thInputMiss`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`thInputHit`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`output`)}),(0,m.jsx)(`th`,{className:z.numCol,colSpan:2,children:t(`band`)})]})}),(0,m.jsx)(`tbody`,{children:ur(on(),G).map(e=>{let n=e.price.input>0||e.price.output>0;return(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:(0,m.jsxs)(`span`,{className:z.ubModel,children:[(()=>{let n=sr(Ft(Kt,Pt(e.key,Jt)),Yt);if(n===null)return null;let r=Wt.includes(e.key),i=`${e.name} · ${t(n===`peak`?`peak`:`offPeak`)} · ${t(`bandPinHint`)}`;return(0,m.jsx)(`button`,{type:`button`,className:y(z.bandDot,z[n],r&&z.bandDotOn),"data-testid":`billing-band-dot`,"aria-pressed":r,"aria-label":i,title:i,onClick:()=>{Gt(Pe(e.key)),window.dispatchEvent(new CustomEvent(`dsh.ui-usage-billing.pinned-pref`))}})})(),(0,m.jsxs)(`span`,{className:z.ubModelName,children:[e.name,e.uncatalogued&&(0,m.jsx)(`span`,{className:z.ubTagAlert,"data-testid":`billing-price-uncatalogued`,children:t(`uncatalogued`)}),e.promo!==void 0&&rn(e.promo,Date.now())&&(0,m.jsx)(p.Tooltip,{label:[e.promo.note,e.promo.endsAtMs===void 0?t(`promoOpenEnded`):t(`promoUntil`,{date:new Date(e.promo.endsAtMs).toLocaleDateString()})].filter(Boolean).join(` · `),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.ubTagPromo,"data-testid":`billing-price-promo`,children:t(`promoBadge`)})})]})]})}),(0,m.jsx)(`td`,{className:z.numCol,children:n?Xt(e.price.input,e.price.currency):(0,m.jsx)(`span`,{className:z.na,children:`—`})}),(0,m.jsx)(`td`,{className:z.numCol,children:n?Xt(e.price.cacheHit,e.price.currency):(0,m.jsx)(`span`,{className:z.na,children:`—`})}),(0,m.jsx)(`td`,{className:z.numCol,children:n?Xt(e.price.output,e.price.currency):(0,m.jsx)(`span`,{className:z.na,children:`—`})}),n&&e.price.offPeak!==void 0&&e.peakHours!==void 0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`td`,{className:z.numCol,children:(0,m.jsxs)(`span`,{className:z.ubChipPeak,children:[(0,m.jsx)(`span`,{className:z.ubChipLabel,children:e.tierSemantics===`latency`?t(`ubStd`):t(`ubPeak`)}),(0,m.jsxs)(`span`,{children:[Xt(e.price.input,e.price.currency),`/`,Xt(e.price.output,e.price.currency)]})]})}),(0,m.jsx)(`td`,{className:z.numCol,children:(0,m.jsxs)(`span`,{className:z.ubChipOff,children:[(0,m.jsx)(`span`,{className:z.ubChipLabel,children:e.tierSemantics===`latency`?`Flex`:t(`ubOff`)}),(0,m.jsxs)(`span`,{children:[Xt(e.price.offPeak.input,e.price.currency),` / `,Xt(e.price.offPeak.output,e.price.currency)]})]})})]}):(0,m.jsx)(`td`,{className:z.numCol,colSpan:2,children:n?(0,m.jsx)(`span`,{className:z.flatTag,children:t(`flat`)}):(0,m.jsx)(`span`,{className:z.na,children:`—`})})]}),(e.extraRows??[]).map(t=>(0,m.jsxs)(`tr`,{className:z.ubExtraRow,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:z.ubExtraName,children:lr(t.label,Vt)}),t.note!==void 0&&(0,m.jsx)(`span`,{className:z.ubExtraNote,children:lr(t.note,Vt)})]}),(0,m.jsx)(`td`,{className:z.numCol,children:t.input===void 0?(0,m.jsx)(`span`,{className:z.na,children:`—`}):Xt(t.input,e.price.currency)}),(0,m.jsx)(`td`,{className:z.numCol,children:(0,m.jsx)(`span`,{className:z.na,children:`—`})}),(0,m.jsx)(`td`,{className:z.numCol,children:t.output===void 0?(0,m.jsx)(`span`,{className:z.na,children:`—`}):Xt(t.output,e.price.currency)}),(0,m.jsx)(`td`,{className:z.numCol,colSpan:2,children:(0,m.jsx)(`span`,{className:z.na,children:`—`})})]},`${e.key}:${t.label}`))]},e.key)})})]})})]}),(0,m.jsxs)(`section`,{className:z.ubCard,children:[(0,m.jsx)(`div`,{className:z.ubCardHead,children:(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`pricingNotes`)})}),(0,m.jsxs)(`ul`,{className:z.ubNotes,children:[(0,m.jsxs)(`li`,{className:z.ubNotesItem,children:[(0,m.jsx)(`span`,{className:z.ubNotesTerm,children:t(`cacheHit`)}),(0,m.jsx)(`span`,{className:z.ubNotesDesc,children:t(`noteCache`)})]}),(0,m.jsxs)(`li`,{className:z.ubNotesItem,children:[(0,m.jsx)(`span`,{className:z.ubNotesTerm,children:t(`peakBand`)}),(0,m.jsx)(`span`,{className:z.ubNotesDesc,children:t(`noteBand`)})]}),(0,m.jsxs)(`li`,{className:z.ubNotesItem,children:[(0,m.jsx)(`span`,{className:z.ubNotesTerm,children:t(`pricingSource`)}),(0,m.jsx)(`span`,{className:z.ubNotesDesc,children:t(`noteSource`)})]})]})]})]}),!r&&b(`billing.dashboard.decor`,{position:`footer`})]}),!r&&(0,m.jsxs)(`footer`,{className:z.modalFooter,"data-testid":`billing-footer`,children:[(0,m.jsx)(`span`,{children:t(`footer`)}),(0,m.jsx)(`span`,{children:t(`footerCredit`).replace(`{version}`,e.pluginVersion===void 0?`—`:`v${e.pluginVersion}`)})]})]});return r?er:(0,m.jsx)(p.Modal,{open:!0,onClose:n,title:t(`title`),headless:!0,className:y(z.dashboardModal,`dsh-billing-modal`),children:er})}function ua(e){return e.split(/[\\/]/).filter(Boolean).at(-1)??`—`}let da={display:[`显示`,`密度`,`动效`,`紧凑`,`舒适`,`克制`,`丰富`,`display`,`density`,`motion`,`compact`,`comfortable`],budget:[`预算`,`金额`,`本月`,`花费`,`进度`,`budget`,`amount`,`spend`,`progress`],alert:[`峰谷`,`峰`,`谷`,`提醒`,`通知`,`预览`,`切换`,`peak`,`off-peak`,`alert`,`notify`,`preview`],toggles:[`usage_stats`,`工具`,`即时代费`,`胶囊`,`中转站`,`站点`,`隐藏`,`低谷`,`队列`,`relay`,`site`,`live`,`cost`,`hide`,`queue`,`off-peak`],displayExtra:[`悬浮`,`订阅`,`计费卡`,`指标`,`环比`,`主数字`,`侧栏`,`入口`,`隐藏`,`float`,`subscription`,`card`,`metric`,`delta`,`sidebar`,`trigger`,`hidden`],advanced:[`自定义`,`单价`,`价格`,`低谷`,`custom`,`price`],about:[`关于`,`版本`,`作者`,`许可`,`仓库`,`about`,`version`,`author`,`license`,`repo`]};function fa(e){return Object.values(da).every(t=>Di(e,t))}let pa=[`below`,`above`,`toolbar`];function ma({liveCostPrefs:e,onLiveCostPrefs:t,t:n}){let[r,i]=(0,d.useState)(!1),a={below:n(`liveCostBarPosBelow`),above:n(`liveCostBarPosAbove`),toolbar:n(`liveCostBarPosToolbar`)},o=pa.map(e=>({id:e,label:a[e]}));return(0,m.jsx)(p.Menu,{open:r,align:`end`,portal:!0,compact:!0,items:o,selectedId:e.position,onSelect:n=>{i(!1);let r=pa.find(e=>e===n);r!==void 0&&t({...e,position:r})},onClose:()=>{i(!1)},anchor:(0,m.jsxs)(`button`,{type:`button`,className:z.rdoSelect,"data-testid":`billing-livecost-position-select`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>{i(!r)},children:[(0,m.jsx)(`span`,{children:a[e.position]}),(0,m.jsx)(`span`,{className:y(z.rdoChevron,r&&z.rdoChevronOpen),"aria-hidden":!0,children:Lr?(0,m.jsx)(Lr,{}):null})]})})}function ha(e){let{t,checkModels:n,publishCosts:r,registerOpen:i,navigateToSession:a,renderSlot:o,useStore:s,actions:c,embeddedSettings:l=!1}=e,[u,f]=(0,d.useState)(Ar),[p,h]=(0,d.useState)(Mr),[g,_]=(0,d.useState)([]),[v,y]=(0,d.useState)(void 0),[b,x]=(0,d.useState)(!1),[S,C]=(0,d.useState)([]),[w,T]=(0,d.useState)(!1),[ee,O]=(0,d.useState)([]),[k,N]=(0,d.useState)(()=>xe()),[re,ie]=(0,d.useState)(()=>Me()),ae=(0,d.useCallback)(e=>{ie(e),Ne(e),window.dispatchEvent(new CustomEvent(`dsh.ui-usage-billing.language-pref`))},[]),oe=(0,d.useCallback)(e=>{N(e),Se(e),window.dispatchEvent(new CustomEvent(be))},[]),[se,ce]=(0,d.useState)(()=>E()),le=(0,d.useCallback)(e=>{ce(e),D(e)},[]),[ue,de]=(0,d.useState)(()=>fe()),me=(0,d.useCallback)(e=>{de(e),pe(e)},[]),[he,ye]=(0,d.useState)(()=>_e()),Ce=(0,d.useCallback)(e=>{ye(e),ve(e),window.dispatchEvent(new CustomEvent(ge))},[]),[we,Te]=(0,d.useState)(()=>Xe());(0,d.useEffect)(()=>{let e=()=>{Te(Xe())};return window.addEventListener(Ye,e),()=>{window.removeEventListener(Ye,e)}},[]);let P=(0,d.useCallback)(e=>{let t={...Xe(),showEntry:e.showEntry};Te(t),Ze({showEntry:t.showEntry})},[]),[F,Ee]=(0,d.useState)(()=>j());(0,d.useEffect)(()=>te(()=>{Ee(j())}),[]);let De=e.recoveryEntryAvailable,Oe=(0,d.useMemo)(()=>({...F,mode:ne(F.mode,De)}),[F,De]),ke=(0,d.useCallback)(e=>{let t={...e,mode:ne(e.mode,De)};Ee(t),M(t),window.dispatchEvent(new CustomEvent(A))},[De]),[Ae,je]=(0,d.useState)(()=>{let e=Fe();return ft(e),e}),Pe=(0,d.useCallback)(e=>{je(e),ft(e),Ie(e)},[]),I=(0,d.useMemo)(()=>gi(u),[u,Ae]),Le=re,L=(0,d.useCallback)((e,n)=>{let r=(Le===`en`?tt:et)[e]??t(e);if(n===void 0)return r;let i=r;for(let[e,t]of Object.entries(n))i=i.replaceAll(`{${e}}`,String(t));return i},[Le,t]),[Re,ze]=(0,d.useState)(!1),Be=(0,d.useCallback)(()=>{ze(!1)},[]),Ve=(0,d.useRef)(!1),He=(0,d.useCallback)((e=!1)=>{Ve.current&&!e||(Ve.current=!0,Promise.all([Ii().then(e=>{e!==null&&f(e)}),Li().then(({balances:e,reconcile:t,stale:n})=>{e.length>0&&_(e),y(t),x(n===!0)}),Ri().then(({quotas:e,stale:t})=>{e.length>0?(C(e),T(t===!0)):T(!1)}).catch(()=>{T(!0)}),zi().then(e=>{O(e)}).catch(()=>{})]).catch(()=>{}).finally(()=>{Ve.current=!1}))},[]),Ue=(0,d.useCallback)(()=>{He(!0),Wi(),ze(!0)},[He]);(0,d.useEffect)(()=>{He(),Wi()},[He]);let[We,Ge]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{Ge(!document.hidden),document.hidden||(He(!0),Wi())};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[He]),(0,d.useEffect)(()=>{if(!We)return;let e=setInterval(()=>{He(),Wi()},Re?kr:3e5);return()=>{clearInterval(e)}},[He,Re,We]),(0,d.useEffect)(()=>{let e=!0;return n().then(t=>{e&&(h(t),yt(t.catalog??[]))}),()=>{e=!1}},[n]);let R=K(),Ke=Object.entries(I.byDay).filter(([e])=>e.startsWith(R.slice(0,7))).reduce((e,[,t])=>e+t.cost,0),qe=I.byDay[R]?.cost??0,Je=new Date;Je.setDate(Je.getDate()-1);let Qe=`${Je.getFullYear()}-${String(Je.getMonth()+1).padStart(2,`0`)}-${String(Je.getDate()).padStart(2,`0`)}`,z=I.byDay[Qe]?.cost??0,$e=z>0?(qe-z)/z*100:0,nt=Gr(I.byDay,R),rt=(0,d.useMemo)(()=>Wr(I.byDay).map(e=>{let t=I.byDay[e.date];return{date:e.date,cost:e.cost,tokens:t===void 0?0:Ur(t)}}),[I.byDay]),it=Object.entries(I.byDay).filter(([e])=>e.startsWith(R.slice(0,7))).reduce((e,[,t])=>e+Ur(t),0),at=(()=>{let e=I.byDay[R];return e===void 0?0:Ur(e)})(),ot=Gr(I.byDay,R,Ur),B=s(e=>e.enabled),st=s(e=>e.amount),V=s(e=>e.tierAlertDays),ct=s(e=>e.lastTierSwitchAt),[H,lt]=(0,d.useState)(()=>wr()),[ut,dt]=(0,d.useState)(null),[pt,mt]=(0,d.useState)(null),[ht,gt]=(0,d.useState)(0),[_t,vt]=(0,d.useState)(!1);(0,d.useEffect)(()=>{if(!H.enabled){gt(0),vt(!1);return}let e=!1,t=!1;vt(!1);let n=()=>{t||(t=!0,Ji().then(t=>{e||gt(t.supported?t.queuedCount:0)}).catch(()=>{e||gt(0)}).finally(()=>{t=!1,e||vt(!0)}))};n();let r=setInterval(n,kr);return()=>{e=!0,clearInterval(r)}},[H.enabled]),(0,d.useEffect)(()=>{dt(e=>Cr(e,ht))},[ht]);let[bt,xt]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{if(!H.enabled)return;let e=setInterval(()=>xt(Date.now()),kr);return()=>{clearInterval(e)}},[H.enabled]);let Ct=(0,d.useCallback)(e=>{lt(e),Tr(e)},[]),wt=S.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`),Et=Pt(u.byTurn?.[0]?.model,wt),Dt=(0,d.useCallback)(()=>{mt({entering:Tt(Date.now())===`peak`?`offPeak`:`peak`,atMs:Date.now()+18e4,channel:Et})},[Et]),U=st>0?st:u.budget??0,Ot=B&&U>0?Ke/U>=1?`over`:Ke/U>=.8?`warn`:`none`:`none`,kt=(0,d.useCallback)(()=>{let e=!B;c.setEnabled(e),e&&typeof Notification<`u`&&Notification.permission==="default"&&Notification.requestPermission()},[c,B]);(0,d.useEffect)(()=>{if(!B||U<=0)return;let e=Ke/U*100,t=Or.filter(t=>e>=t&&V?.[String(t)]!==R);if(t.length===0)return;let n=t[t.length-1]??100;if(c.markTierAlerted(t,R),!yi())return;let r=L(`budgetTierBody`).replace(`{cost}`,dn(Ke)).replace(`{budget}`,dn(U)).replace(`{pct}`,String(n));bi(`budget:${n}:${R}`,()=>{new Notification(L(`budget`),{body:r})})},[B,U,Ke,V,R,c,L]),(0,d.useEffect)(()=>{if(H.enabled&&!_t)return;let e=Sr(Er(bt,H,ct,Et),ht>0?Er(bt,H,ct,`deepseek-metered`):null,ht);if(e===null||(c.markTierSwitchAlerted(e.atMs),dt(e),!H.webNotify||!yi()))return;let t=Math.max(1,Math.round((e.atMs-bt)/6e4)),n=L(e.entering===`peak`?`peakAlertTitlePeak`:`peakAlertTitleOff`),r=L(e.channel===`zhipu-coding-plan`?e.entering===`peak`?`tierAlertEnterPeakZhipu`:`tierAlertEnterOffZhipu`:e.entering===`peak`?`tierAlertEnterPeak`:`tierAlertEnterOff`).replace(`{minutes}`,String(t)),i=e.queueCount===void 0?``:` ${L(e.entering===`peak`?`peakAlertQueuePeak`:`peakAlertQueueOff`,{count:e.queueCount})}`;bi(`peak:${e.atMs}`,()=>{new Notification(n,{body:`${r}${i}`})})},[bt,ct,H,Et,ht,_t,c,L]);let At=s(e=>e.lastBalanceAlertDay),jt=s(e=>e.modelBudgets??ir),Mt=s(e=>e.modelTierAlertDays??ar),Nt=(0,d.useMemo)(()=>Yr(I.byDayModels,R.slice(0,7)),[I.byDayModels,R]),Ft=I.lowBalanceThreshold??50,It=(0,d.useMemo)(()=>{if(g.length===0)return;let e=Rr(I.byDay,R),t=St().rate;for(let n of g){if(n.totalBalance===void 0||n.error!==void 0)continue;let r=n.currency===`USD`?n.totalBalance*t:n.totalBalance;if(r>=Ft)continue;let i=e>0?Math.floor(r/e):void 0;return{name:n.displayName,cny:r,days:i}}},[g,I.lowBalanceThreshold,I.byDay,R]);(0,d.useEffect)(()=>{if(It===void 0||At===R||(c.markBalanceAlerted(R),!yi()))return;let e=L(`balanceLowBody`).replace(`{name}`,It.name).replace(`{balance}`,dn(It.cny)).replace(`{days}`,It.days===void 0?`—`:String(It.days));bi(`balance:${R}`,()=>{new Notification(L(`balance`),{body:e})})},[It,At,R,c,L]),(0,d.useEffect)(()=>{let e=[],t;for(let[n,r]of Object.entries(jt)){if(!(r>0))continue;let i=Nt[n]??0;for(let a of Zr(i,r)){let o=`${n}:${a}`;Mt[o]!==R&&(e.push(o),(t===void 0||a>t.tier)&&(t={model:n,tier:a,cost:i,budget:r}))}}if(e.length===0||t===void 0||(c.markModelTierAlerted(e,R),!yi()))return;let n=L(`modelBudgetBody`).replace(`{model}`,t.model).replace(`{cost}`,dn(t.cost)).replace(`{budget}`,dn(t.budget)).replace(`{pct}`,String(t.tier));bi(`model-budget:${t.model}:${t.tier}:${R}`,()=>{new Notification(L(`modelBudgetTitle`),{body:n})})},[jt,Nt,Mt,R,c,L]);let Lt=(0,d.useMemo)(()=>{let e=R.slice(0,7),t=new Map;for(let[n,r]of Object.entries(I.byDayModels??{}))if(n.startsWith(e))for(let[e,n]of Object.entries(r)){if(n.cost<=0)continue;let r=tn(e).provider,i=I.byModel?.[e]?.plan===!0,a=t.get(r)??{cost:0,plan:i};a.cost+=n.cost,i||(a.plan=!1),t.set(r,a)}let n,r;for(let e of t){let t=e[1].plan?r:n;(t===void 0||e[1].cost>t[1].cost)&&(e[1].plan?r=e:n=e)}let i=e=>{let t=g.find(t=>Q(t.provider)===Q(e));if(t===void 0||t.totalBalance===void 0){if(e===`Custom`){let e=g.filter(e=>e.totalBalance!==void 0&&e.error===void 0),t=e[0];return t!==void 0&&e.length===1?i(t.provider):void 0}return{text:t?.error===`unauthorized`?L(`balanceUnauthorized`):t?.error===`unreachable`||t?.error===`invalid`?L(`balanceUnreachable`):L(`balanceUnconfigured`),low:!1}}let n=t.currency===`USD`?`$${t.totalBalance.toFixed(2)}`:dn(t.totalBalance),r=St().rate;return{text:n,low:(t.currency===`USD`?t.totalBalance*r:t.totalBalance)<Ft}},a=e=>{let t=S.find(t=>t.displayName===e||ri(t.provider)===e);if(t===void 0||t.windows.length===0)return{text:L(`subscriptionNoApi`),low:!1};let n=t.windows.reduce((e,t)=>Math.min(e,t.remainingPercent),100);return{text:n<=0?L(`subscriptionExhausted`):L(`subscriptionRemaining`).replace(`{pct}`,String(n)),low:n<20}},o=n===void 0?void 0:i(n[0]);return{direct:n===void 0||o===void 0?void 0:{name:n[0],...o},sub:r===void 0?void 0:{name:r[0],...a(r[0])}}},[I.byDayModels,I.byModel,I.lowBalanceThreshold,g,S,R,L]),Rt=(0,d.useMemo)(()=>{let e=I.total;return{input:e.input,output:e.output,cacheRead:e.cacheHit,cacheMiss:e.cacheMiss,calls:e.calls}},[I]);(0,d.useEffect)(()=>{r({todayCost:qe,monthCost:Ke})},[qe,Ke,r]),(0,d.useEffect)(()=>{if(!l)return i(Ue)},[l,i,Ue]);let zt=(0,d.useMemo)(()=>u.byTurn??[],[u.byTurn]);return(0,m.jsxs)(m.Fragment,{children:[!l&&(0,m.jsx)(aa,{...e,t:L,currency:k,onOpen:Ue,monthCost:Ke,todayCost:qe,weekCost:nt,days:rt,vendorStatus:Lt,dash:Rt,cardPrefs:Oe,monthTokens:it,todayTokens:at,weekTokens:ot,floatPrefs:se,subscriptions:S,budgetPressure:Ot,deltaPct:$e}),(l||Re)&&(0,m.jsx)(la,{stats:I,t:L,onClose:Be,embeddedSettings:l,navigateToSession:a,userPrices:Ae,onUserPrices:Pe,health:p,balances:g,...v===void 0?{}:{reconcile:v},quotas:S,relayQuotas:ee,currency:k,onCurrency:oe,language:re,onLanguage:ae,turns:zt,renderSlot:o,budgetEnabled:B,budgetAmount:U,modelBudgets:jt,monthModelCost:Nt,onModelBudget:c.setModelBudget,onToggleBudget:kt,onBudgetAmount:c.setAmount,peakConfig:H,onPeakConfig:Ct,onPreviewPeak:Dt,floatPrefs:se,onFloatPrefs:le,cardPrefs:Oe,onCardPrefs:ke,recoveryEntryAvailable:De,sitePrefs:ue,onSitePrefs:me,liveCostPrefs:he,onLiveCostPrefs:Ce,quickQueuePrefs:we,onQuickQueuePrefs:P,quotasStale:w,balanceStale:b}),(ut!==null||pt!==null)&&(0,m.jsx)(Dr,{hit:ut??pt,config:H,t:L,onDismiss:()=>{dt(null),mt(null)}})]})}function ga(e){return(0,m.jsx)(`div`,{className:z.nativeSettingsRoot,"data-testid":`native-billing-settings`,children:(0,m.jsx)(ha,{...e,renderSlot:()=>null,wide:!0,embeddedSettings:!0})})}function _a(e,t){if(t===void 0||e?.bySession===void 0)return 0;let n=e.bySession.find(e=>e.id===t);return(n?.cost??0)+(n?.subCost??0)}function va(e,t){return t===void 0||e?.bySession===void 0?0:e.bySession.find(e=>e.id===t)?.subCost??0}function ya(e,t){if(t===void 0||e?.byTurn===void 0)return 0;let n=0,r=-1;for(let i of e.byTurn)i.sessionId===t&&(r===-1||i.turn>r)&&(r=i.turn,n=i.cost);return n}function ba(e,t=20){let n=[];for(let r of e)if(r.status===`ok`)for(let e of r.windows)e.remainingPercent>t||n.push({name:r.displayName,kind:e.kind,pct:e.remainingPercent});return n.sort((e,t)=>e.pct-t.pct).slice(0,3)}function xa(e,t){if(t===void 0||e?.byTurn===void 0)return;let n=-1,r;for(let i of e.byTurn)i.sessionId===t&&(n===-1||i.turn>n)&&(n=i.turn,r=i.model);return r}async function Sa(){try{let e=await _i(`/api/billing/usage-stats`);if(!e.ok)return null;let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n)return null;let r=n;return{...Array.isArray(r.bySession)?{bySession:r.bySession}:{},...Array.isArray(r.byTurn)?{byTurn:r.byTurn}:{}}}catch{return null}}async function Ca(){try{let e=await _i(`/api/billing/subscriptions`);if(!e.ok)return[];let t=JSON.parse(await e.text());if(typeof t!=`object`||!t||!(`quotas`in t))return[];let n=t.quotas;return Array.isArray(n)?n:[]}catch{return[]}}function wa(e){switch(e){case`session`:return`subscriptionSession`;case`weekly`:return`subscriptionWeekly`;case`monthly`:return`subscriptionMonthly`;default:return`subscriptionBilling`}}function Ta(e){return!e.running&&!e.promptAttempted&&(e.blank||e.awaitingFirstTurn)}function Ea({hasBandPlan:e}){let[t,n]=(0,d.useState)(()=>Te()),[r,i]=(0,d.useState)(()=>Date.now());if((0,d.useEffect)(()=>{let e=()=>{n(Te())};window.addEventListener(we,e),window.addEventListener(`storage`,e);let t=setInterval(()=>{i(Date.now())},3e4);return()=>{window.removeEventListener(we,e),window.removeEventListener(`storage`,e),clearInterval(t)}},[]),t.length===0)return null;let a=wr().leadMin*6e4,o=t.map(t=>({key:t,state:sr(Ft(r,Pt(t,e)),a)})).filter(e=>e.state!==null);return o.length===0?null:(0,m.jsx)(`span`,{className:z.bandDots,"data-testid":`billing-pinned-dots`,children:o.map(e=>(0,m.jsx)(`span`,{className:y(z.bandDot,z.bandDotOn,z[e.state]),role:`img`,"aria-label":e.key,title:e.key},e.key))})}function Da(){let[e,t]=(0,d.useState)(()=>xe());return(0,d.useEffect)(()=>{let e=()=>{t(xe())};return window.addEventListener(be,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(be,e),window.removeEventListener(`storage`,e)}},[]),e}function Oa(){let[e,t]=(0,d.useState)(()=>_e().show),[n,r]=(0,d.useState)(()=>_e().position);return(0,d.useEffect)(()=>{let e=()=>{t(_e().show),r(_e().position)};return window.addEventListener(ge,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(ge,e),window.removeEventListener(`storage`,e)}},[]),{visible:e,position:n}}function ka(e,t){let[n,r]=(0,d.useState)(null),[i,a]=(0,d.useState)([]),[o,s]=(0,d.useState)(()=>Date.now()),[c,l]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{l(!document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[]),(0,d.useEffect)(()=>{if(!c||!t)return;let e=!1,n=!1,i=()=>{n||(n=!0,e||s(Date.now()),Promise.all([Sa(),Ca()]).then(([t,n])=>{e||(t!==null&&r(t),a(n))}).catch(()=>{}).finally(()=>{n=!1}))};i();let o=setInterval(i,3e4);return()=>{e=!0,clearInterval(o)}},[e,c,t]);let u=(0,d.useMemo)(()=>_a(n,e),[n,e]),f=(0,d.useMemo)(()=>va(n,e),[n,e]),p=(0,d.useMemo)(()=>ya(n,e),[n,e]),m=(0,d.useMemo)(()=>ba(i),[i]),h=(0,d.useMemo)(()=>Pt(xa(n,e),i.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`)),[n,e,i]);return{sessionCost:u,subCost:f,turnCost:p,tier:(0,d.useMemo)(()=>Ft(o,h),[o,h]),chips:m,hasBandPlan:i.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`)}}function Aa({sessionId:e,t,seat:n,session:r}){let{visible:i,position:a}=Oa(),o=i&&a===n&&!(n===`above`&&r!==void 0&&Ta(r)),{sessionCost:s,subCost:c,turnCost:l,tier:u,chips:d,hasBandPlan:f}=ka(e,o),p=Da(),h=e=>dn(un(e,p),p),g=s>0||l>0,_=u?.tier===`peak`;return o?(0,m.jsxs)(`span`,{className:n===`above`?y(z.feeBar,z.feeBarAbove):z.feeBar,"data-testid":`billing-live-cost-bar`,"data-seat":n,children:[(0,m.jsx)(Ea,{hasBandPlan:f}),u!==null&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:_?z.feeChipPrimary:z.feeChipOff,"data-testid":`billing-live-tier`,children:t(_?`tierPeak`:`tierOff`)}),(0,m.jsx)(`span`,{className:z.feeCount,children:Lt(u.nextSwitchInMs)}),(0,m.jsx)(`span`,{className:z.feeSuffix,children:t(_?`tierToOff`:`tierToPeak`)})]}),g&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:z.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:z.feeItem,"data-testid":`billing-live-turn`,children:[t(`liveTurn`),` `,(0,m.jsx)(`span`,{className:z.feeNum,"data-tick":`turn`,children:h(l)})]}),(0,m.jsx)(`span`,{className:z.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:z.feeItem,"data-testid":`billing-live-session`,children:[t(`liveSession`),` `,(0,m.jsx)(`span`,{className:z.feeNum,"data-tick":`session`,children:h(s)}),c>0&&(0,m.jsx)(`span`,{className:z.feeSuffix,"data-testid":`billing-live-session-sub`,children:t(`liveSessionSub`).replace(`{cost}`,h(c))})]})]}),d.map(e=>(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:z.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:e.pct<=10?z.feeChipError:z.feeChipAlert,"data-testid":`billing-live-quota`,children:[e.name,` `,t(wa(e.kind)),` `,e.pct,`%`]})]},`${e.name}:${e.kind}`))]}):null}function ja({sessionId:e,t}){let n=Da(),r=e=>dn(un(e,n),n),{visible:i,position:a}=Oa(),{sessionCost:o,subCost:s,turnCost:c,tier:l,chips:u,hasBandPlan:d}=ka(e,i&&a===`toolbar`);if(!i||a!==`toolbar`)return null;let f=l?.tier===`peak`,h=u.reduce((e,t)=>Math.min(e,t.pct),100),g=h<=10?z.feeInlineError:h<=20?z.feeInlineAlert:void 0,_=y(z.feeInline,g),v=[...l===null?[]:[`${Lt(l.nextSwitchInMs)} ${t(f?`tierToOff`:`tierToPeak`)}`],`${t(`liveTurn`)} ${r(c)}`,`${t(`liveSession`)} ${r(o)}`,...s>0?[t(`liveSessionSub`).replace(`{cost}`,r(s))]:[],...u.map(e=>`${e.name} ${t(wa(e.kind))} ${e.pct}%`)].join(` · `);return(0,m.jsx)(p.Tooltip,{label:v,side:`top`,delayMs:500,children:(0,m.jsxs)(`span`,{className:_,"data-testid":`billing-live-cost-chip`,role:`note`,"aria-label":v,children:[(0,m.jsx)(Ea,{hasBandPlan:d}),l!==null&&(0,m.jsx)(`span`,{className:f?z.feeChipPrimary:z.feeChipOff,"data-testid":`billing-live-tier`,children:t(f?`tierPeak`:`tierOff`)}),o>0&&(0,m.jsx)(`span`,{className:z.feeInlineNum,children:r(o)})]})})}let Ma=`@kenz1117/dsh-ui-usage-billing/TaskQueueQuick.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Ma)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@kenz1117/dsh-ui-usage-billing`,e.dataset.pluginCss=Ma,e.textContent=`.HRJ8EG_quickQueue{white-space:nowrap;flex-shrink:0;align-self:center;align-items:center;gap:6px;display:inline-flex;position:relative}.HRJ8EG_quickQueueToggle,.HRJ8EG_quickQueueButton{border:1px solid var(--dsw-alias-border-l1);min-height:24px;color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;background:0 0;border-radius:999px;justify-content:center;align-items:center;gap:5px;padding:0 8px;font-size:11px;line-height:18px;display:inline-flex}.HRJ8EG_quickQueueToggle:hover,.HRJ8EG_quickQueueButton:hover:not(:disabled){border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary)}.HRJ8EG_quickQueueToggle[aria-checked=true]{border-color:color-mix(in srgb, var(--ds-blue) 45%, transparent);background:color-mix(in srgb, var(--ds-blue) 10%, transparent);color:var(--ds-blue)}.HRJ8EG_quickQueueButton:focus-visible,.HRJ8EG_quickQueueToggle:focus-visible,.HRJ8EG_quickQueueClear input:focus-visible{outline:2px solid var(--ds-blue);outline-offset:2px}.HRJ8EG_quickQueueButton:disabled{cursor:wait;opacity:.65}.HRJ8EG_quickQueueClear{color:var(--dsw-alias-label-tertiary);cursor:pointer;align-items:center;gap:4px;font-size:11px;display:inline-flex}.HRJ8EG_quickQueueClear input{width:13px;height:13px;accent-color:var(--ds-blue);margin:0}.HRJ8EG_quickQueueCount{background:color-mix(in srgb, var(--ds-blue) 14%, transparent);min-width:16px;height:16px;color:var(--ds-blue);font-variant-numeric:tabular-nums;border-radius:999px;justify-content:center;align-items:center;padding:0 4px;font-size:10px;display:inline-flex}.HRJ8EG_quickQueueNotice{z-index:30;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-3);width:max-content;max-width:min(320px,75vw);color:var(--dsw-alias-label-primary);white-space:normal;pointer-events:none;border-radius:8px;padding:7px 10px;font-size:12px;line-height:18px;position:absolute;bottom:calc(100% + 8px);right:0;box-shadow:0 8px 24px #00000038}.HRJ8EG_quickQueueNotice[data-kind=error]{border-color:color-mix(in srgb, var(--ds-red) 45%, transparent);color:var(--ds-red)}`,document.head.appendChild(e)}var Na={quickQueue:`HRJ8EG_quickQueue`,quickQueueButton:`HRJ8EG_quickQueueButton`,quickQueueClear:`HRJ8EG_quickQueueClear`,quickQueueCount:`HRJ8EG_quickQueueCount`,quickQueueNotice:`HRJ8EG_quickQueueNotice`,quickQueueToggle:`HRJ8EG_quickQueueToggle`};let Pa=()=>void 0,Fa=()=>void 0;function Ia(e){return e.tasks.filter(e=>e.status===`queued`).length}function La(){let[e,t]=(0,d.useState)(()=>Xe());return(0,d.useEffect)(()=>{let e=()=>{t(Xe())};return window.addEventListener(Ye,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(Ye,e),window.removeEventListener(`storage`,e)}},[]),e}function Ra(e){let[t,n]=(0,d.useState)(null),[r,i]=(0,d.useState)(()=>typeof document>`u`||!document.hidden),a=(0,d.useRef)(0),o=(0,d.useCallback)(e=>{a.current+=1,n(Ia(e))},[]);return(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{i(!document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[]),(0,d.useEffect)(()=>{if(!e||!r){n(null);return}let t=!1,i=!1,o=()=>{if(i)return;i=!0;let e=a.current;Ji().then(r=>{t||e!==a.current||n(r.supported?r.queuedCount:null)}).catch(()=>{}).finally(()=>{i=!1})};o();let s=window.setInterval(o,3e4);return()=>{t=!0,window.clearInterval(s)}},[e,r]),{count:t,applySnapshot:o}}function za({t:e}){let t=La();return t.showEntry?(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t.enabled,"aria-label":e(`quickQueueToggle`),className:Na.quickQueueToggle,"data-testid":`quick-queue-toggle`,onClick:()=>{Ze({enabled:!t.enabled})},children:e(`quickQueueToggle`)}):null}function Ba(e,t){let n=e(t),r=(0,d.useCallback)(e=>n?.subscribe(e)??(()=>{}),[n]),i=(0,d.useCallback)(()=>n?.getSnapshot(),[n]);return(0,d.useSyncExternalStore)(r,i,i)}function Va({sessionId:e,t,useInput:n,inputActions:r,projectionFaceOf:i}){let a=La(),o=(n??Pa)(e=>e),s=Ba(i??Fa,`workingDirectory`),c=Ba(i??Fa,`modelSelection`)?.next,{count:l,applySnapshot:u}=Ra(a.enabled&&a.showEntry),[f,p]=(0,d.useState)(!1),[h,g]=(0,d.useState)(null),_=(0,d.useRef)(!1),v=(0,d.useRef)(!0),y=(0,d.useRef)({sessionId:e,input:o});if(y.current={sessionId:e,input:o},(0,d.useEffect)(()=>(v.current=!0,()=>{v.current=!1}),[]),(0,d.useEffect)(()=>{if(h===null)return;let e=h.kind===`success`?4e3:8e3,t=window.setTimeout(()=>{g(null)},e);return()=>{window.clearTimeout(t)}},[h]),!a.enabled||!a.showEntry)return null;let b=e=>{g({kind:`error`,text:e})},x=async()=>{if(_.current)return;if(g(null),o===void 0){b(t(`quickQueueUnsupported`));return}let n=o.draft;if(n.trim()===``){b(t(`quickQueueEmpty`));return}if(o.phase!==`plain`){b(t(`quickQueueBusy`));return}if(o.attachmentIds.length>0||o.occurrences.length>0){b(t(`quickQueueAttachments`));return}if(typeof s!=`string`||s===``){b(t(`quickQueueContext`));return}let i=a.clearAfterEnqueue;if(i&&r===void 0){b(t(`quickQueueUnsupported`));return}let l={sessionId:e,prompt:n,draftRev:o.draftRev,cwd:s,clearAfterEnqueue:i};_.current=!0,p(!0);try{let e=await qi(!0);if(!e.supported){b(t(`quickQueueUnsupported`));return}let n=c??e.defaultModel;if(n==null){b(t(`quickQueueContext`));return}let i=e.workspaces.some(e=>e.path===l.cwd),a=e.models.some(e=>e.provider===n.provider&&e.id===n.model);if(!i||!a){b(t(`quickQueueRoute`));return}let o=await Yi({action:`enqueue`,prompt:l.prompt,cwd:l.cwd,provider:n.provider,model:n.model});u(o);let s=t(`quickQueueEnqueued`);if(l.clearAfterEnqueue&&r!==void 0){let e=y.current;if(v.current&&e.sessionId===l.sessionId&&e.input?.draft===l.prompt&&e.input.draftRev===l.draftRev&&e.input.phase===`plain`&&e.input.attachmentIds.length===0&&e.input.occurrences.length===0)try{r.setDraft(``)}catch{s=t(`quickQueueDraftChanged`)}else s=t(`quickQueueDraftChanged`)}v.current&&g({kind:`success`,text:s})}catch(e){if(!v.current)return;let n=e instanceof Error?e.message:String(e);b(t(`quickQueueFailed`).replace(`{message}`,n))}finally{_.current=!1,v.current&&p(!1)}};return(0,m.jsxs)(`span`,{className:Na.quickQueue,"data-testid":`quick-queue-controls`,children:[(0,m.jsxs)(`label`,{className:Na.quickQueueClear,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:a.clearAfterEnqueue,disabled:f,onChange:e=>{Ze({clearAfterEnqueue:e.target.checked})}}),t(`quickQueueClear`)]}),(0,m.jsxs)(`button`,{type:`button`,className:Na.quickQueueButton,"aria-label":t(`quickQueueEnqueue`),"aria-busy":f,disabled:f,"data-testid":`quick-queue-enqueue`,onClick:()=>{x()},children:[t(f?`quickQueueEnqueueing`:`quickQueueEnqueue`),l!==null&&l>0&&(0,m.jsx)(`span`,{className:Na.quickQueueCount,"data-testid":`quick-queue-count`,"aria-label":t(`quickQueueWaiting`).replace(`{count}`,String(l)),children:l})]}),h!==null&&(0,m.jsx)(`span`,{className:Na.quickQueueNotice,"data-kind":h.kind,role:h.kind===`error`?`alert`:`status`,children:h.text})]})}function Ha(){let e,t,n=new Set;return{readCosts:()=>e,subscribeCosts:t=>(t(e),n.add(t),()=>{n.delete(t)}),openDashboard:()=>{t?.()},publishCosts:t=>{e=t;for(let e of n)try{e(t)}catch{x(`billing-costs-listener-threw`)}},registerOpen:e=>(t=e,()=>{t===e&&(t=void 0)})}}let Ua={enabled:!1,timeout:0};function Wa(){try{let e=localStorage.getItem(`dsh-billing-completion-notify-v1`);if(e===null)return{...Ua};let t=JSON.parse(e);return{enabled:t.enabled===!0,timeout:typeof t.timeout==`number`?t.timeout:0}}catch{return{...Ua}}}function Ga(e){return e.completed===!0||e.running===!1}function Ka(e,t){let n=new Set,r=new Set,i,a=e.getSnapshot();for(let e of a.ids){let t=a.byId[e];t!==void 0&&(r.add(String(e)),Ga(t)&&n.add(String(e)))}let o=e=>{let{enabled:n,timeout:r}=t();if(n&&!(typeof Notification>`u`)&&Notification.permission===`granted`)try{let t=new Notification(e,{body:e,tag:`dsh-billing-completion`,requireInteraction:r===0});r>0&&(i!==void 0&&clearTimeout(i),i=setTimeout(()=>t.close(),r*1e3))}catch{x(`notification-constructor-failed`)}},s=e.subscribe(()=>{let t=e.getSnapshot(),i=[];for(let e of t.ids){let a=t.byId[e];if(a===void 0)continue;let o=String(e),s=Ga(a),c=!r.has(o);c&&r.add(o),s&&!c&&!n.has(o)&&i.push(a.title??a.id??o),s?n.add(o):n.delete(o)}if(i.length>0){let e=i.length===1?i[0]:`${i.length} 个会话已完成`;e!==void 0&&o(e)}});return()=>{s(),i!==void 0&&clearTimeout(i)}}function qa(e){let t=e.get(`uiWorkspace`);if(t!==void 0&&typeof t.openSession==`function`)return t}function Ja(e){let t=e.sessions,n=t?.open;return typeof n==`function`?n.bind(t):void 0}function Ya(e){return{available:()=>qa(e)!==void 0||Ja(e)!==void 0,open:t=>{let n=_(t),r=qa(e);if(r!==void 0)try{return r.openSession(n),`opened`}catch(e){return x(`session-navigation-open-failed`,e),`failed`}let i=Ja(e);if(i!==void 0)try{return i(n),`opened`}catch(e){return x(`session-navigation-legacy-open-failed`,e),`failed`}return`unavailable`}}}function Xa(e,t){let n=e.get(`commandUi`);if(n===void 0||typeof n.register!=`function`)return!1;let r={name:`usage`,label:t.label,description:t.description,available:()=>!0,ui:{kind:`action`,run:()=>{t.openDashboard()}}};try{n.register(r)}catch(e){return x(`usage-command-register-failed`,e),!1}return!0}let Za=[`slots`,`locale`,`remote`,`sessions`];function Qa(e){let t=Ha();e.provide(`billingMetrics`,t);let n=or();e.effect(()=>e.locale.register($e,{zh:et,en:tt}),`ui-usage-billing: dictionaries`);let r=Ya(e),i=Xa(e,{openDashboard:()=>{t.openDashboard()},label:()=>Me()===`en`?tt.commandUsageLabel:et.commandUsageLabel,description:()=>Me()===`en`?tt.commandUsageDescription:et.commandUsageDescription}),a=!1,o={store:n,inject:()=>({checkModels:async()=>{try{let[t,n]=await Promise.all([e.remote.llm.listProviders(),e.remote.llm.listConfigurableProviders()]);if(!t.ok||!n.ok)return{checked:!0,available:!1,models:0,failures:0,okProviders:[],badProviders:[]};let r=new Map(n.value.map(e=>[e.provider,e])),i=await Promise.all(t.value.map(async t=>{let n=r.get(t.id);if(n===void 0)return{provider:t,models:[]};let i=await e.remote.llm.discoverModels(n.settingsNs,{provider:t.id});return i.ok?{provider:t,models:i.value}:{provider:t,failed:!0}})),a=[],o=[],s=[],c=0;for(let e of i){if(`failed`in e){s.push(e.provider.name);continue}o.push(e.provider.name),c+=e.models.length;for(let t of e.models)a.push({id:t.id,...typeof t.name==`string`&&t.name!==``?{name:t.name}:{},provider:e.provider.name})}return{checked:!0,available:o.length>0,models:c,failures:s.length,okProviders:o,badProviders:s,catalog:a}}catch{return{checked:!1,available:!1,models:0,failures:0,okProviders:[],badProviders:[]}}},publishCosts:e=>{t.publishCosts(e)},registerOpen:e=>t.registerOpen(e),recoveryEntryAvailable:i||a,navigateToSession:e=>r.open(e)})};e.slots.inject(`settings.section`,()=>{a=!0;let t=e.slots.register({name:`settings.section`,id:`usage-billing`,order:30,label:()=>Me()===`en`?tt.nativeSettingsNav:et.nativeSettingsNav,locale:$e,...o},ga);return()=>{a=!1,t()}}),e.slots.inject(`sidebar.footer.action`,()=>e.slots.register({name:`sidebar.footer.action`,id:`usage-billing`,order:-10,locale:$e,...o,children:{"billing.dashboard.decor":{kind:`list`,scope:`root`}}},ha)),e.slots.inject(`conversation.composer.dock`,()=>e.slots.register({name:`conversation.composer.dock`,id:`usage-billing-cost`,order:0,locale:$e,inject:e=>({sessionId:_(e),seat:`below`})},Aa)),e.slots.inject(`conversation.input.dock`,()=>e.slots.register({name:`conversation.input.dock`,id:`usage-billing-cost-above`,order:100,locale:$e,inject:e=>({sessionId:_(e),seat:`above`})},Aa)),e.slots.inject(`conversation.input.right`,()=>e.slots.register({name:`conversation.input.right`,id:`usage-billing-cost-chip`,order:0,locale:$e,inject:e=>({sessionId:_(e)})},ja)),e.slots.inject(`conversation.input.left`,()=>e.slots.register({name:`conversation.input.left`,id:`usage-billing-quick-queue-toggle`,order:20,locale:$e},za)),e.slots.inject(`conversation.input.right`,()=>e.slots.register({name:`conversation.input.right`,id:`usage-billing-quick-queue-enqueue`,order:20,locale:$e,inject:t=>({sessionId:_(t),projectionFaceOf:n=>{try{return e.sessions.binding?.(_(t))?.session.projections.faceOf(n)}catch{return}}})},Va)),e.effect(()=>Ka(e.sessions.list,Wa),`ui-usage-billing: completion notifier`)}return n.UsageBilling=ha,n.apply=Qa,n.inject=Za,t.exports}});
|
|
5
|
+
`)}function jn(){let e=new Date,t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`}let Y={top:18,right:40,bottom:26,left:46};function Mn(e){let[,t,n]=e.split(`-`);return`${Number(t)}/${Number(n)}`}function Nn(e,t){let n=[];for(let r=0;r<e;r+=t)n.push(r);return e>0&&n[n.length-1]!==e-1&&n.push(e-1),n}let Pn={key:`__total__`,name:``,color:``};function Fn({data:e,models:t=[],currency:n=`cny`,metric:r=`cost`,t:i}){let a=i??(e=>et[e]),[o,s]=(0,d.useState)(null),c=e=>dn(un(e,n),n),l=e=>r===`tokens`?wn(e):c(e),u=e=>r===`tokens`?e.tokens??0:e.cost,f=(0,d.useMemo)(()=>{let n=e.length;if(n===0)return null;let i=680-Y.left-Y.right,a=220-Y.top-Y.bottom,o=e=>n===1?Y.left+i/2:Y.left+i*e/(n-1),s=Math.max(...r===`tokens`?e.map(e=>e.tokens??0):e.map(e=>Math.max(e.cost,Object.values(e.byModel??{}).reduce((e,t)=>e+t,0))),1e-4),c=e=>Y.top+a-e/s*a,l=Math.max(...e.map(e=>e.calls),1),d=e=>Y.top+a-e/l*a,f=i/n,p=Math.min(18,f*.6);return{n,plotW:i,plotH:a,inner:o,yCost:c,yCalls:d,barW:p,bars:e.flatMap((e,n)=>{let i=o(n)-p/2;if(t.length===0||r===`tokens`)return[{date:e.date,model:Pn,x:i,base:0,value:u(e),topRounded:!0}];let a=null;for(let n of t)(e.byModel?.[n.key]??0)>0&&(a=n.key);let s=0;return t.map(t=>{let n=e.byModel?.[t.key]??0,r={date:e.date,model:t,x:i,base:s,value:n,topRounded:t.key===a};return s+=n,r})}),costTicks:[0,.25,.5,.75,1].map(e=>s*e).reverse(),callsTicks:[0,.25,.5,.75,1].map(e=>l*e).reverse(),linePath:e.map((e,t)=>{let n=d(e.calls);return`${t===0?`M`:`L`}${o(t)} ${n}`}).join(` `)}},[e,t,r]);if(f===null)return(0,m.jsx)(`div`,{className:z.chartEmpty,children:a(`trendEmpty`)});let{n:p,plotW:h,plotH:g,inner:_,yCost:v,yCalls:y,barW:b,bars:x,costTicks:S,callsTicks:C,linePath:w}=f,T=o===null?void 0:e[o],ee=Nn(p,Math.max(1,Math.ceil(p/8)));return(0,m.jsxs)(`div`,{className:z.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 220`,className:z.chartSvg,role:`img`,"aria-label":`Daily cost by model and total calls`,onMouseLeave:()=>{s(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-Y.left)/h,r=Math.round(n*(p-1));s(Math.min(Math.max(r,0),p-1))},children:[S.map((e,t)=>{let n=v(e);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:Y.left,x2:680-Y.right,y1:n,y2:n,className:z.chartGrid}),(0,m.jsx)(`text`,{x:Y.left-8,y:n+3,textAnchor:`end`,className:z.chartAxisLabel,children:l(e)})]},`cost-${t}`)}),x.map(t=>{if(t.value>0)return(0,m.jsx)(`rect`,{x:t.x,y:v(t.base+t.value),width:b,height:v(t.base)-v(t.base+t.value),rx:t.topRounded?2:0,className:t.model.color===``?z.chartBar:z.chartStack,style:t.model.color===``?void 0:{fill:t.model.color}},`${t.date}-${t.model.key}`);let n=e.find(e=>e.date===t.date);return n!==void 0&&n.calls>0&&t.base===0?(0,m.jsx)(`rect`,{x:t.x,y:v(0)-1,width:b,height:1,rx:0,className:z.chartBarPlaceholder},`${t.date}-${t.model.key}-placeholder`):null}),(0,m.jsx)(`path`,{d:w,fill:`none`,className:z.chartLine}),(()=>{let t=jn(),n=e.findIndex(e=>e.date===t);return n>=0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`defs`,{children:(0,m.jsxs)(`linearGradient`,{id:`chartAreaGrad`,x1:`0%`,y1:`0%`,x2:`0%`,y2:`100%`,children:[(0,m.jsx)(`stop`,{offset:`0%`,stopColor:`var(--ds-blue)`,stopOpacity:`0.35`}),(0,m.jsx)(`stop`,{offset:`100%`,stopColor:`var(--ds-blue)`,stopOpacity:`0`})]})}),(0,m.jsx)(`path`,{d:`${w} L ${_(e.length-1)} ${y(0)} L ${_(0)} ${y(0)} Z`,fill:`url(#chartAreaGrad)`}),(0,m.jsx)(`line`,{x1:_(n),x2:_(n),y1:Y.top,y2:Y.top+g,stroke:`var(--ds-amber)`,strokeWidth:`1`,strokeDasharray:`3 3`,opacity:`0.6`}),(0,m.jsx)(`text`,{x:_(n)+4,y:Y.top-6,fill:`var(--ds-amber)`,fontSize:`10`,fontFamily:`var(--font-num)`,children:Mn(t)})]}):null})(),C.map((e,t)=>{let n=y(e);return(0,m.jsx)(`text`,{x:680-Y.right+8,y:n+3,textAnchor:`start`,className:z.chartAxisLabel,children:wn(e)},`calls-${t}`)}),ee.map(t=>{let n=e[t];return n===void 0?null:(0,m.jsx)(`text`,{x:_(t),y:214,textAnchor:`middle`,className:z.chartAxisLabel,children:Mn(n.date)},n.date)}),o!==null&&(0,m.jsx)(`line`,{x1:_(o),x2:_(o),y1:Y.top,y2:Y.top+g,className:z.chartCrosshair})]}),T!==void 0&&o!==null&&(0,m.jsxs)(`div`,{className:z.chartTooltip,style:{left:`${_(o)/680*100}%`,top:`${v(T.cost)/220*100}%`},children:[(0,m.jsx)(`div`,{className:z.chartTooltipDate,children:T.date}),r!==`tokens`&&t.filter(e=>(T.byModel?.[e.key]??0)>0).map(e=>(0,m.jsxs)(`div`,{className:z.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:e.color}}),e.name,` `,(0,m.jsx)(`strong`,{children:c(T.byModel?.[e.key]??0)})]},e.key)),(0,m.jsxs)(`div`,{className:z.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:z.chartLegendBar}),a(`trendTotal`),` `,(0,m.jsx)(`strong`,{children:r===`tokens`?wn(T.tokens??0):c(T.cost)})]}),(0,m.jsxs)(`div`,{className:z.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:z.chartLegendLine}),a(`calls`),` `,(0,m.jsx)(`strong`,{children:T.calls.toLocaleString()})]})]}),t.length>0&&r!==`tokens`&&(0,m.jsxs)(`div`,{className:z.chartLegend,children:[t.map(e=>(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:e.color}}),e.name]},e.key)),(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:z.chartLegendLine}),a(`calls`)]})]})]})}let X={top:14,right:42,bottom:22,left:46};function In(e){return e.slice(5,13).replace(`T`,` `)}function Ln(e){return String(e>=100?Math.round(e):Number(e.toFixed(1)))}function Rn(e){return e<1e4?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:`${(e/6e4).toFixed(1)} min`}function zn(e){return e>=1e3?`${(e/1e3).toFixed(1)}k`:e.toFixed(1)}function Bn(e,t,n){return t===`ttft`?`${Math.round(e)} ms`:`${e.toFixed(1)} ${n(`perfTpsUnit`)}`}function Vn({perf:e,models:t,t:n}){let[r,i]=(0,d.useState)(()=>Re()),[a,o]=(0,d.useState)(null),s=e=>{i(e),ze(e)},c=e=>t.find(t=>t.key===e)?.color??`#8b95a3`,l=(0,d.useMemo)(()=>e===void 0?[]:Object.entries(e.byModel).map(([e,n])=>({key:e,name:t.find(t=>t.key===e)?.name??e,color:c(e),samples:n.samples,ttftAvg:n.ttftAvg,ttftP50:n.ttftP50,ttftP90:n.ttftP90,...n.ttftMax===void 0?{}:{ttftMax:n.ttftMax},...n.ttftSpikes===void 0?{}:{ttftSpikes:n.ttftSpikes},...n.tpsAvg===void 0?{}:{tpsAvg:n.tpsAvg},latencyAvg:n.latencyAvg,estimatedSamples:n.estimatedSamples})).sort((e,t)=>t.samples-e.samples||t.ttftP90-e.ttftP90),[e,t]),u=(0,d.useMemo)(()=>{if(e===void 0)return[];if(r.models!==void 0){let t=new Set(Object.keys(e.byModel));return r.models.filter(e=>t.has(e))}return l.slice(0,5).map(e=>e.key)},[e,l,r.models]),f=(0,d.useMemo)(()=>{if(e===void 0)return null;let t=Object.keys(e.byHourModel).sort().slice(-48);if(t.length===0)return null;let n=t.length,i=680-X.left-X.right,a=180-X.top-X.bottom,o=e=>n===1?X.left+i/2:X.left+i*e/(n-1),s=new Set(u),c=e=>r.metric===`ttft`?e?.ttftAvg:e?.tpsAvg,d=[],f=0;for(let r of l){if(!s.has(r.key))continue;let i=[];for(let a=0;a<n;a++){let n=t[a];if(n===void 0)continue;let s=c(e.byHourModel[n]?.[r.key]);s===void 0||!Number.isFinite(s)||(i.push({i:a,x:o(a),y:0,v:s}),s>f&&(f=s))}d.push({key:r.key,name:r.name,color:r.color,segments:[],points:i})}let p=d.reduce((e,t)=>e+t.points.length,0);f=Math.max(f,1);let m=e=>X.top+a-e/f*a;for(let e of d){let t=``,n=-2;for(let r of e.points)r.y=m(r.v),t!==``&&r.i!==n+1&&(e.segments.push(t),t=``),t+=`${t===``?`M`:`L`}${r.x} ${r.y} `,n=r.i;t!==``&&e.segments.push(t)}let h=Math.max(1,Math.ceil(n/8)),g=[];for(let e=0;e<n;e+=h)g.push(e);return g[g.length-1]!==n-1&&g.push(n-1),{hourKeys:t,n,plotW:i,plotH:a,inner:o,yOf:m,series:d,ticks:[0,.5,1].map(e=>f*e).reverse(),xTicks:g,totalPoints:p}},[e,l,u,r.metric]);if(e===void 0||l.length===0)return(0,m.jsx)(`div`,{className:z.chartEmpty,"data-testid":`billing-perf-empty`,children:n(`perfEmpty`)});let p=e=>{let t=u.includes(e)?u.filter(t=>t!==e):[...u,e];s({metric:r.metric,models:t})},h=e=>{s({metric:e,...r.models===void 0?{}:{models:r.models}})},g=a===null||f===null?[]:f.series.flatMap(e=>{let t=e.points.find(e=>e.i===a);return t===void 0?[]:[{key:e.key,name:e.name,color:e.color,v:t.v}]});return(0,m.jsxs)(`div`,{"data-testid":`billing-perf-panel`,children:[l.length>0&&(()=>{let e=Math.max(...l.map(e=>e.ttftAvg),1),t=Math.max(...l.filter(e=>e.tpsAvg!==void 0).map(e=>e.tpsAvg??0),1),r=Math.max(...l.map(e=>e.latencyAvg),1),i=l.reduce((e,t)=>e+t.samples,0),a=l.length>0?l.reduce((e,t)=>e+t.ttftAvg,0)/l.length:0,o=l.map(e=>e.tpsAvg).filter(e=>e!==void 0),s=o.length>0?o.reduce((e,t)=>e+t,0)/o.length:0,c=l.length>0?l.reduce((e,t)=>e+t.latencyAvg,0)/l.length:0,u=[{lbl:n(`perfSamples`),val:i.toLocaleString(),unit:``,pct:65,color:`var(--ds-blue)`},{lbl:n(`perfTtft`),val:Rn(a),unit:``,pct:a/e*100,color:`var(--ds-green)`},{lbl:n(`perfTps`),val:o.length>0?zn(s):`—`,unit:``,pct:s/t*100,color:`var(--ds-blue)`},{lbl:n(`perfLatency`),val:Rn(c),unit:``,pct:c/r*100,color:`var(--ds-amber)`}];return(0,m.jsx)(`div`,{className:z.perfHero,"data-testid":`billing-perf-hero`,children:u.map((e,t)=>(0,m.jsxs)(`div`,{className:z.perfHeroCell,children:[(0,m.jsx)(`div`,{className:z.perfHeroLbl,children:e.lbl}),(0,m.jsxs)(`div`,{className:z.perfHeroVal,children:[e.val,e.unit!==``&&(0,m.jsx)(`span`,{className:z.perfHeroUnit,children:e.unit})]}),(0,m.jsx)(`div`,{className:z.perfHeroBar,children:(0,m.jsx)(`i`,{style:{width:`${Math.min(100,e.pct)}%`,background:e.color}})})]},t))})})(),(0,m.jsx)(`div`,{className:z.tableScroll,"data-testid":`billing-perf-table`,children:(0,m.jsxs)(`table`,{className:z.modelTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:n(`model`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfSamples`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfTtft`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfP50`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfP90`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfMax`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfTps`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfLatency`)}),(0,m.jsx)(`th`,{className:z.numCol,children:n(`perfEstimated`)})]})}),(0,m.jsx)(`tbody`,{children:l.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:(0,m.jsxs)(`span`,{className:z.modelCell,children:[(0,m.jsx)(`span`,{className:z.modelDot,style:{background:e.color}}),(0,m.jsx)(`span`,{className:z.modelName,children:e.name})]})}),(0,m.jsx)(`td`,{className:z.numCol,children:e.samples.toLocaleString()}),(0,m.jsx)(`td`,{className:z.numCol,children:Rn(e.ttftAvg)}),(0,m.jsx)(`td`,{className:z.numCol,children:Rn(e.ttftP50)}),(0,m.jsx)(`td`,{className:z.numCol,children:Rn(e.ttftP90)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.ttftMax===void 0?(0,m.jsx)(`span`,{className:z.na,children:`—`}):(0,m.jsxs)(`span`,{children:[Rn(e.ttftMax),e.ttftSpikes!==void 0&&e.ttftSpikes>0?` (${e.ttftSpikes}↑)`:``]})}),(0,m.jsx)(`td`,{className:z.numCol,children:e.tpsAvg===void 0?(0,m.jsx)(`span`,{className:z.na,children:`—`}):zn(e.tpsAvg)}),(0,m.jsx)(`td`,{className:z.numCol,children:Rn(e.latencyAvg)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.estimatedSamples>0?e.estimatedSamples:(0,m.jsx)(`span`,{className:z.na,children:`—`})})]},e.key))})]})}),l.length>0&&(()=>{let e=Math.max(...l.map(e=>e.ttftP50),1),t=e=>e<.8?`var(--ds-green)`:e<2?`var(--ds-amber)`:`var(--ds-red)`;return(0,m.jsx)(`div`,{className:z.perfCompareList,"data-testid":`billing-perf-compare`,children:l.map(n=>(0,m.jsxs)(`div`,{className:z.perfCompareRow,children:[(0,m.jsxs)(`div`,{className:z.perfCompareName,children:[(0,m.jsx)(`span`,{className:z.perfCompareDot,style:{background:n.color}}),(0,m.jsx)(`span`,{children:n.name})]}),(0,m.jsx)(`div`,{className:z.perfCompareBar,children:(0,m.jsx)(`i`,{style:{width:`${n.ttftP50/e*100}%`,background:t(n.ttftP50)}})}),(0,m.jsx)(`div`,{className:z.perfCompareNum,children:Rn(n.ttftP50)}),(0,m.jsx)(`div`,{className:z.perfCompareNum,children:n.tpsAvg===void 0?`—`:zn(n.tpsAvg)})]},n.key))})})(),f!==null&&(0,m.jsxs)(`div`,{"data-testid":`billing-perf-hour`,children:[(0,m.jsx)(`div`,{className:z.perfBar,children:(0,m.jsx)(`span`,{className:z.rangeToggle,role:`group`,"aria-label":n(`perfTitle`),children:[`ttft`,`tps`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.rangeButton,r.metric===e&&z.rangeButtonActive),"aria-pressed":r.metric===e,"data-testid":`billing-perf-tab-${e}`,onClick:()=>{h(e)},children:e===`ttft`?`${n(`perfTtft`)} (ms)`:`${n(`perfTps`)} (${n(`perfTpsUnit`)})`},e))})}),(0,m.jsxs)(`div`,{className:z.perfChips,role:`group`,"aria-label":n(`model`),children:[(0,m.jsx)(`button`,{type:`button`,className:z.perfChip,"data-testid":`billing-perf-chip-all`,onClick:()=>{s({metric:r.metric,models:l.map(e=>e.key)})},children:n(`perfAll`)}),l.map(e=>{let t=u.includes(e.key);return(0,m.jsxs)(`button`,{type:`button`,className:y(z.perfChip,!t&&z.perfChipOff),style:t?{color:e.color,borderColor:`color-mix(in srgb, ${e.color} 45%, transparent)`}:void 0,"aria-pressed":t,"data-testid":`billing-perf-chip-${e.key}`,onClick:()=>{p(e.key)},children:[(0,m.jsx)(`span`,{className:z.perfChipDot,style:{background:t?e.color:`var(--dsw-alias-label-dimmed)`}}),e.name]},e.key)})]}),f.totalPoints>0?(0,m.jsxs)(`div`,{className:z.chartWrap,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 680 180`,className:z.chartSvg,role:`img`,"aria-label":`Hourly perf comparison by model`,onMouseLeave:()=>{o(null)},onMouseMove:e=>{let t=e.currentTarget.getBoundingClientRect(),n=((e.clientX-t.left)/t.width*680-X.left)/f.plotW,r=Math.round(n*(f.n-1));o(Math.min(Math.max(r,0),f.n-1))},children:[f.ticks.map((e,t)=>{let n=f.yOf(e);return(0,m.jsxs)(`g`,{children:[(0,m.jsx)(`line`,{x1:X.left,x2:680-X.right,y1:n,y2:n,className:z.chartGrid}),(0,m.jsx)(`text`,{x:X.left-8,y:n+3,textAnchor:`end`,className:z.chartAxisLabel,children:Ln(e)})]},`tick-${t}`)}),f.series.map(e=>e.segments.map((t,n)=>(0,m.jsx)(`path`,{d:t,fill:`none`,className:z.chartLine,style:{stroke:e.color}},`${e.key}-${n}`))),f.xTicks.map(e=>{let t=f.hourKeys[e];return t===void 0?null:(0,m.jsx)(`text`,{x:f.inner(e),y:174,textAnchor:`middle`,className:z.chartAxisLabel,children:In(t)},t)}),a!==null&&(0,m.jsx)(`line`,{x1:f.inner(a),x2:f.inner(a),y1:X.top,y2:X.top+f.plotH,className:z.chartCrosshair}),a!==null&&f.series.map(e=>{let t=e.points.find(e=>e.i===a);return t===void 0?null:(0,m.jsx)(`circle`,{cx:t.x,cy:t.y,r:3.5,fill:e.color,className:z.chartHoverDot},`${e.key}-dot`)})]}),a!==null&&g.length>0&&(0,m.jsxs)(`div`,{className:z.chartTooltip,"data-testid":`billing-perf-tooltip`,style:{left:`${f.inner(a)/680*100}%`,top:`${(X.top+f.plotH/2)/180*100}%`},children:[(0,m.jsx)(`div`,{className:z.chartTooltipDate,children:In(f.hourKeys[a]??``)}),g.map(e=>(0,m.jsxs)(`div`,{className:z.chartTooltipRow,children:[(0,m.jsx)(`span`,{className:z.chartTooltipSwatch,style:{background:e.color}}),e.name,` `,(0,m.jsx)(`strong`,{children:Bn(e.v,r.metric,n)})]},e.key))]})]}):(0,m.jsx)(`div`,{className:z.chartEmpty,"data-testid":`billing-perf-chart-empty`,children:n(`perfChartEmpty`)})]}),f===null&&(0,m.jsx)(`div`,{className:z.chartEmpty,"data-testid":`billing-perf-chart-empty`,children:n(`perfChartEmpty`)})]})}let Hn=`@kenz1117/dsh-ui-usage-billing`,Un=`kenz1117`;function Wn({t:e,version:t}){return(0,m.jsxs)(`section`,{className:z.setCard,"data-testid":`billing-plugin-info`,children:[(0,m.jsxs)(`div`,{className:z.plgHead,children:[(0,m.jsx)(`span`,{className:z.plgIcon,"aria-hidden":`true`,children:(0,m.jsx)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,m.jsx)(`path`,{d:`M10 3a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v2a2 2 0 0 0 4 0V4a1 1 0 0 1 1-1h1a1 1 0 0 1 1 1v1a2 2 0 0 0 4 0 1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-1a2 2 0 0 0 0 4h1a1 1 0 0 1 1 1v2a1 1 0 0 1-1 1h-1a2 2 0 0 0-4 0v1a1 1 0 0 1-1 1h-2a1 1 0 0 1-1-1v-2a2 2 0 0 0-4 0v1a1 1 0 0 1-1 1h-1a1 1 0 0 1-1-1v-1a2 2 0 0 0-4 0 1 1 0 0 1-1 1H3a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1h1a2 2 0 0 0 0-4H3a1 1 0 0 1-1-1v-2a1 1 0 0 1 1-1h1a2 2 0 0 0 4 0z`})})}),(0,m.jsxs)(`div`,{className:z.plgTitle,children:[(0,m.jsxs)(`div`,{className:z.plgNameRow,children:[(0,m.jsx)(`h3`,{className:z.plgName,children:Hn}),(0,m.jsx)(`span`,{className:z.plgTag,children:t===void 0?`—`:`v${t}`})]}),(0,m.jsx)(`p`,{className:z.plgDesc,children:`Usage billing dashboard for DeepSeek Harness`})]})]}),(0,m.jsxs)(`div`,{className:z.plgGrid,children:[(0,m.jsxs)(`div`,{className:z.plgItem,children:[(0,m.jsx)(`span`,{className:z.plgLabel,children:e(`pluginAuthor`)}),(0,m.jsxs)(`a`,{className:z.plgLink,href:`https://github.com/${Un}`,target:`_blank`,rel:`noreferrer`,children:[`KenZ`,` (`,Un,`)`]})]}),(0,m.jsxs)(`div`,{className:z.plgItem,children:[(0,m.jsx)(`span`,{className:z.plgLabel,children:e(`pluginRepository`)}),(0,m.jsx)(`a`,{className:z.plgLink,href:`https://github.com/kenz1117/dsh-ui-usage-billing`,target:`_blank`,rel:`noreferrer`,children:`GitHub`})]}),(0,m.jsxs)(`div`,{className:z.plgItem,children:[(0,m.jsx)(`span`,{className:z.plgLabel,children:e(`pluginNpm`)}),(0,m.jsx)(`a`,{className:z.plgLink,href:`https://www.npmjs.com/package/@kenz1117/dsh-ui-usage-billing`,target:`_blank`,rel:`noreferrer`,children:Hn})]}),(0,m.jsxs)(`div`,{className:z.plgItem,children:[(0,m.jsx)(`span`,{className:z.plgLabel,children:e(`pluginLicense`)}),(0,m.jsx)(`span`,{className:z.plgVal,children:`MIT`})]})]})]})}function Gn(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}`}function Kn(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function qn(e){let t=Math.round(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m${String(t%60).padStart(2,`0`)}s`}function Jn({rounds:e,flags:t,currency:n,t:r}){let i=(0,d.useMemo)(()=>e.slice(-40),[e]),a=(0,d.useMemo)(()=>new Set(t.map(e=>`${e.sessionId}:${e.turn}`)),[t]),o=(0,d.useMemo)(()=>Math.max(1e-4,...i.map(e=>e.cost)),[i]);if(i.length===0)return(0,m.jsxs)(`div`,{className:z.roundsEmpty,children:[r(`model`),` —`]});let s=e=>dn(un(e,n),n);return(0,m.jsxs)(`div`,{className:z.rounds,children:[(0,m.jsx)(`div`,{className:z.roundsBars,role:`img`,"aria-label":`cost per turn`,children:i.map(e=>{let t=a.has(`${e.sessionId}:${e.turn}`),n=Math.max(1,e.cost/o*100),i=Pt(e.model,!1)===`deepseek-metered`&&Tt(e.startedAt)===`peak`;return(0,m.jsxs)(`div`,{className:y(z.roundsBarCol,i?z.roundsBarColPeak:z.roundsBarColOff),children:[(0,m.jsx)(`span`,{className:z.roundsBarLabel,style:{bottom:`${n}%`},children:s(e.cost)}),(0,m.jsx)(`div`,{className:z.roundsBarWrap,children:(0,m.jsx)(`div`,{className:t?z.roundsBarFlagged:z.roundsBar,style:{height:`${n}%`},"data-testid":`round-bar`,title:`${r(`model`)} ${e.model} · ${s(e.cost)} · ${Kn(e.startedAt)}${e.endedAt===void 0?``:` → ${Gn(e.endedAt)} (${qn(e.endedAt-e.startedAt)})`}`,children:t&&(0,m.jsx)(`span`,{className:z.roundsFlagMark,"aria-hidden":`true`})})})]},`${e.sessionId}:${e.turn}`)})}),(0,m.jsxs)(`div`,{className:z.roundsAxis,children:[(0,m.jsxs)(`span`,{children:[r(`costAbbr`),` `,s(o)]}),(0,m.jsxs)(`span`,{children:[i.length,` `,r(`roundsUnit`)]})]})]})}let Z=[`color-mix(in srgb, var(--dsb-3) 70%, transparent)`,`color-mix(in srgb, var(--ds-cyan) 30%, var(--dsb-3))`,`color-mix(in srgb, var(--ds-blue) 60%, var(--dsb-3))`,`var(--ds-blue)`,`var(--ds-amber)`],Yn=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],Xn=e=>K(e.getTime());function Zn(e,t){let n=new Map;for(let t of e)n.set(t.date,t.value);let r=0;for(let e of n.values())e>r&&(r=e);let i=t.getFullYear(),a=t.getMonth(),o=t.getDate(),s=new Date(i,a+1,0).getDate(),c=new Date(i,a,1).getDay(),l=c+s,u=Math.ceil(l/7),d=[];for(let e=0;e<u;e+=1){let t=[];for(let l=0;l<7;l+=1){let u=e*7+l-c+1;if(u<1){let e=new Date(i,a,u);t.push({date:Xn(e),dayNum:e.getDate(),value:0,level:0,placeholder:!0});continue}if(u>s){let e=new Date(i,a+1,u-s);t.push({date:Xn(e),dayNum:e.getDate(),value:0,level:0,placeholder:!0});continue}let d=new Date(i,a,u),f=Xn(d),p=n.get(f)??0,m=0;if(p>0&&r>0){let e=Math.ceil(p/r*4);m=Math.min(4,Math.max(1,e))}let h=u>o;t.push({date:f,dayNum:u,value:h?0:p,level:h?0:m,placeholder:h})}d.push(t)}return d}function Qn(e,t,n=52){let r=new Map;for(let t of e)r.set(t.date,t.value);let i=0;for(let e of r.values())e>i&&(i=e);let a=Xn(t),o=new Date(t);o.setHours(0,0,0,0),o.setDate(o.getDate()-o.getDay());let s=new Date(o);s.setDate(o.getDate()-(n-1)*7);let c=[];for(let e=0;e<n;e+=1){let t=[];for(let n=0;n<7;n+=1){let o=new Date(s);o.setDate(s.getDate()+e*7+n);let c=Xn(o),l=c>a,u=l?0:r.get(c)??0,d=0;if(!l&&u>0&&i>0){let e=Math.ceil(u/i*4);d=Math.min(4,Math.max(1,e))}t.push({date:c,dayNum:o.getDate(),value:u,level:d,placeholder:l})}c.push(t)}return c}function $n({days:e,currency:t,now:n,t:r,range:i=`month`,unit:a=`cost`}){let[o,s]=(0,d.useState)(null),c=e=>dn(un(e,t),t),l=e=>a===`tokens`?q(e):c(e),u=(0,d.useMemo)(()=>Zn(e,n??new Date),[e,n]),f=Xn(n??new Date);if(i!==`month`){let t=Qn(e,n??new Date,i===`half`?26:52),a=[],o=-1;return t.forEach((e,t)=>{let n=Number(e[0]?.date.slice(5,7)??0);n!==o&&(a.push({index:t,label:Yn[n-1]??``}),o=n)}),(0,m.jsxs)(`div`,{className:z.heatmapYear+(i===`half`?` `+z.heatmapHalf:``),"data-testid":i===`half`?`heatmap-half`:`heatmap-year`,children:[(0,m.jsxs)(`div`,{className:z.heatmapYearBody,children:[(0,m.jsx)(`div`,{className:z.heatmapYearWeekdays,"aria-hidden":`true`,children:[{label:`Mon`,row:1},{label:`Wed`,row:3},{label:`Fri`,row:5}].map(e=>(0,m.jsx)(`span`,{className:z.heatmapYearWeekday,style:{gridRow:e.row},children:e.label},e.label))}),(0,m.jsxs)(`div`,{className:z.heatmapYearScroll,children:[(0,m.jsx)(`div`,{className:z.heatmapYearMonths,"aria-hidden":`true`,"data-testid":`heatmap-year-months`,children:a.map(e=>(0,m.jsx)(`span`,{className:z.heatmapYearMonth,style:{gridColumn:e.index+1},children:e.label},e.index))}),(0,m.jsx)(`div`,{className:z.heatmapYearGrid,role:`img`,"aria-label":`yearly cost heatmap`,"data-testid":`heatmap-year-grid`,children:t.flat().map(e=>(0,m.jsx)(`button`,{type:`button`,className:z.heatmapYearCell,"data-testid":`heatmap-year-cell`,"data-level":e.level,"data-today":e.date===f?`true`:void 0,style:{background:Z[e.level]},title:`${e.date} · ${l(e.value)}`,"aria-label":`${e.date}: ${l(e.value)}`,tabIndex:-1},e.date))})]})]}),(0,m.jsxs)(`div`,{className:z.heatmapFooter,children:[(0,m.jsx)(`span`,{children:r(`heatmapLess`)}),(0,m.jsx)(`span`,{className:z.heatmapLegend,children:Z.map((e,t)=>(0,m.jsx)(`i`,{style:{background:e}},t))}),(0,m.jsx)(`span`,{children:r(`heatmapMore`)})]})]})}return(0,m.jsxs)(`div`,{className:z.heatmap,children:[(0,m.jsx)(`div`,{className:z.heatmapGrid,role:`img`,"aria-label":`daily cost heatmap`,children:u.map(e=>e.map(e=>e.placeholder?(0,m.jsx)(`div`,{className:z.heatmapCellEmpty,children:e.dayNum},e.date):(0,m.jsx)(`button`,{type:`button`,className:z.heatmapCell,"data-testid":`heatmap-cell`,"data-level":e.level,"data-today":e.date===f?`true`:void 0,style:{background:Z[e.level]},title:`${e.date} · ${l(e.value)}`,"aria-label":`${e.date}: ${l(e.value)}`,onMouseEnter:()=>{s(e)},onMouseLeave:()=>{s(null)},onFocus:()=>{s(e)},onBlur:()=>{s(null)},children:e.dayNum},e.date)))}),(0,m.jsxs)(`div`,{className:z.heatmapFooter,children:[(0,m.jsx)(`span`,{children:r(`heatmapLess`)}),(0,m.jsx)(`span`,{className:z.heatmapLegend,children:Z.map((e,t)=>(0,m.jsx)(`i`,{style:{background:e}},t))}),(0,m.jsx)(`span`,{children:r(`heatmapMore`)}),o!==null&&(0,m.jsxs)(`span`,{className:z.heatmapHover,"data-testid":`heatmap-hover`,children:[o.date,` · `,l(o.value)]})]})]})}let er={window:6,threshold:2,reasonFactor:1.8,reasonHitDropPp:15};function tr(e){if(e.length===0)return null;let t=0;for(let n of e)t+=n;return t/e.length}function nr(e){let t=e.cacheHit+e.cacheMiss;return t<=0?null:e.cacheHit/t*100}function rr(e,t){let n=t?.window??er.window,r=t?.threshold??er.threshold,i=t?.reasonFactor??er.reasonFactor,a=t?.reasonHitDropPp??er.reasonHitDropPp,o=[];if(n<=0||r<=0)return o;let s=[],c=[],l=[],u=[];for(let t of e){if(t.cost<=0)continue;let e=t.output,d=t.input,f=nr(t),p=tr(s),m=[];if(p!==null&&p>0&&t.cost>p*r){let n=tr(c),r=tr(l),s=tr(u);n!==null&&n>0&&e>n*i&&m.push(`output-growth`),r!==null&&r>0&&d>r*i&&m.push(`context-bloat`),s!==null&&f!==null&&f<s-a&&m.push(`cache-hit-drop`),o.push({sessionId:t.sessionId,turn:t.turn,cost:t.cost,reasons:m})}for(s.push(t.cost),c.push(e),l.push(d),f!==null&&u.push(f);s.length>n;)s.shift();for(;c.length>n;)c.shift();for(;l.length>n;)l.shift();for(;u.length>n;)u.shift()}return o}let ir={},ar={};function or(){return(0,h.defineStore)({init:()=>({enabled:!1,amount:0,tierAlertDays:{},lastBalanceAlertDay:``,lastTierSwitchAt:0,modelBudgets:{},modelTierAlertDays:{}}),persist:`dsh.ui-usage-billing.budget`,actions:{setEnabled:(e,t)=>{e.enabled=t},setAmount:(e,t)=>{e.amount=Number.isFinite(t)&&t>0?t:0},markTierAlerted:(e,t,n)=>{e.tierAlertDays??={};for(let r of t)e.tierAlertDays[String(r)]=n},markBalanceAlerted:(e,t)=>{e.lastBalanceAlertDay=t},markTierSwitchAlerted:(e,t)=>{e.lastTierSwitchAt=t},setModelBudget:(e,t,n)=>{e.modelBudgets??={},Number.isFinite(n)&&n>0?e.modelBudgets[t]=n:delete e.modelBudgets[t]},markModelTierAlerted:(e,t,n)=>{e.modelTierAlertDays??={};for(let r of t)e.modelTierAlertDays[r]=n}}})}function sr(e,t){return e==null?null:Number.isFinite(e.nextSwitchInMs)&&e.nextSwitchInMs<=t?`soon`:e.tier===`peak`?`peak`:`offPeak`}let cr={显式缓存创建:`Explicit cache write`,显式缓存命中:`Explicit cache hit`,长期半价:`Half price`,与标准价一致:`Same as standard`,"限时 5 折":`Limited-time 50% off`};function lr(e,t){return e===void 0||t!==`en`?e:cr[e]??e}function ur(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>e.key.toLowerCase().includes(n)||(e.name??``).toLowerCase().includes(n)||(e.provider??``).toLowerCase().includes(n))}let dr={"智谱 AI":`Zhipu AI`,阿里通义:`Alibaba Qwen`,字节豆包:`ByteDance Doubao`,月之暗面:`Moonshot AI`,小米:`Xiaomi`,百度文心:`Baidu ERNIE`,腾讯混元:`Tencent Hunyuan`,零一万物:`01.AI`,阶跃星辰:`StepFun`,科大讯飞:`iFlytek Spark`,商汤:`SenseNova`,百川智能:`Baichuan`,"小米 Token Plan(海外)":`Xiaomi Token Plan (Global)`,"小米 Token Plan(国内)":`Xiaomi Token Plan (CN)`,"小米 Token Plan(新加坡)":`Xiaomi Token Plan (SG)`,"火山引擎 Token Plan":`Volcengine Token Plan`,"火山方舟 Token Plan":`Volcengine Ark Token Plan`,"豆包 Token Plan":`Doubao Token Plan`,"百度文心 Plan":`Baidu ERNIE Plan`,"MiniMax Token Plan(国内)":`MiniMax Token Plan (CN)`};function fr(e,t){return t===`en`?dr[e]??e:e}let pr={workbuddy:`WorkBuddy`,"workbuddy-ai":`WorkBuddy AI`},mr={"https://tokenhub.tencentmaas.com":`腾讯云 TokenHub`,"https://api.lkeap.cloud.tencent.com":`腾讯云 Token Plan`,"https://api.deepseek.com":`DeepSeek 官方`},hr={"腾讯云 TokenHub":`Tencent Cloud TokenHub`,"腾讯云 Token Plan":`Tencent Cloud Token Plan`,"DeepSeek 官方":`DeepSeek Official`};function gr(e){try{return new URL(e).host}catch{return e}}function _r(e,t=`zh`){if(e.startsWith(`site:`)){let n=e.slice(5),r=mr[n];return r===void 0?gr(n):t===`en`?hr[r]??r:r}if(e.startsWith(`direct:`)){let n=e.slice(7);if(/^deepseek(?:-[a-z0-9-]+)?$/i.test(n))return t===`en`?`DeepSeek Official`:`DeepSeek 官方`;let r=pr[n.trim().toLowerCase()];return r===void 0?`${t===`en`?`Direct`:`直连`} · ${n}`:`${t===`en`?`Direct`:`直连`} · ${r}`}}let vr=[`直连 · `,`Direct · `];function yr(e){for(let t of vr)if(e.startsWith(t))return e.slice(t.length)}let br=`dsh-billing-peak-alert-v1`,xr={enabled:!1,leadMin:2,position:`bottom-right`,webNotify:!0,mode:`both`};function Sr(e,t,n){return t===null||n<=0?e:e===null?{...t,queueCount:n}:e.atMs===t.atMs&&e.entering===t.entering?{...e,queueCount:n}:e}function Cr(e,t){if(e===null||e.queueCount===void 0)return e;if(t>0)return e.queueCount===t?e:{...e,queueCount:t};let{queueCount:n,...r}=e;return r}function wr(){try{let e=localStorage.getItem(br);if(e===null)return{...xr};let t=JSON.parse(e),n=t.mode===`peak`||t.mode===`offPeak`?t.mode:xr.mode,r=t.position===`center`?`center`:`bottom-right`;return{enabled:t.enabled===!0,leadMin:typeof t.leadMin==`number`&&Number.isFinite(t.leadMin)?Math.min(30,Math.max(1,Math.round(t.leadMin))):xr.leadMin,position:r,webNotify:t.webNotify!==!1,mode:n}}catch{return{...xr}}}function Tr(e){try{localStorage.setItem(br,JSON.stringify(e))}catch{x(`peak-config-storage-unavailable`)}}function Er(e,t,n,r){if(!t.enabled)return null;let i=It(e,r,t.leadMin*6e4);return i===null||t.mode===`peak`&&i.entering!==`peak`||t.mode===`offPeak`&&i.entering!==`offPeak`||i.atMs===n?null:{...i,channel:r}}function Dr({hit:e,config:t,t:n,onDismiss:r}){let[i,a]=(0,d.useState)(()=>Date.now());if((0,d.useEffect)(()=>{let e=setInterval(()=>a(Date.now()),3e4);return()=>clearInterval(e)},[]),(0,d.useEffect)(()=>{i>=e.atMs&&r()},[i,e.atMs,r]),i>=e.atMs)return null;let o=Math.max(1,Math.round((e.atMs-i)/6e4)),s=e.entering,c=n(s===`peak`?`tierPeak`:`tierOff`),l=n(e.channel===`zhipu-coding-plan`?s===`peak`?`peakAlertDescPeakZhipu`:`peakAlertDescOffZhipu`:s===`peak`?`peakAlertDescPeak`:`peakAlertDescOff`),u=s===`peak`;return(0,m.jsxs)(`div`,{className:y(z.peakCard,u?z.peakCardPeak:z.peakCardOff,t.position===`center`?z.peakCardCenter:z.peakCardCorner),"data-testid":`billing-peak-alert`,role:`alert`,children:[(0,m.jsxs)(`div`,{className:z.peakHead,children:[(0,m.jsxs)(`span`,{className:y(z.peakTag,u?z.peakTagPrimary:z.peakTagSuccess),children:[(0,m.jsx)(`span`,{className:y(z.peakDot,u?z.peakDotPrimary:z.peakDotSuccess),"aria-hidden":`true`}),c]}),(0,m.jsx)(`button`,{type:`button`,className:z.peakClose,onClick:r,"aria-label":n(`close`),children:`×`})]}),(0,m.jsxs)(`div`,{className:y(z.peakCount,u?z.peakCountPrimary:z.peakCountSuccess),children:[o,`min`]}),(0,m.jsx)(`p`,{className:z.peakDesc,children:l}),e.queueCount!==void 0&&e.queueCount>0&&(0,m.jsx)(`p`,{className:z.peakDesc,"data-testid":`billing-peak-queue-note`,children:n(s===`peak`?`peakAlertQueuePeak`:`peakAlertQueueOff`,{count:e.queueCount})})]})}let Or=[50,80,100],kr=3e4,Ar={total:{calls:0,input:0,output:0,cacheHit:0,cacheMiss:0,cost:0,reasoning:0},byModel:{},byDay:{},byDayModels:{}},jr=[`#4f8cff`,`#2dd4bf`,`#a78bfa`,`#f59e0b`,`#f472b6`,`#fbbf24`,`#38bdf8`,`#6366f1`,`#f97316`,`#14b8a6`],Mr={checked:!1,available:!1,models:0,failures:0,okProviders:[],badProviders:[]},Nr=[{id:`overview`,labelKey:`tabOverview`},{id:`queue`,labelKey:`tabQueue`},{id:`providers`,labelKey:`tabProviders`},{id:`token`,labelKey:`tabToken`},{id:`trends`,labelKey:`tabTrends`},{id:`agents`,labelKey:`tabAgents`},{id:`pricing`,labelKey:`tabPricing`},{id:`settings`,labelKey:`tabSettings`}],Pr={fill:`none`,"aria-hidden":!0,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`},Fr={overview:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:(0,m.jsx)(`path`,{d:`M2 13V3M2 13H14M4 10l4-3 2 2 4-5`})}),queue:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`path`,{d:`M3 4h10M3 8h10M3 12h6`}),(0,m.jsx)(`path`,{d:`M12 10v4m-2-2h4`})]}),agents:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`3.5`,r:`2`}),(0,m.jsx)(`circle`,{cx:`3.5`,cy:`12.5`,r:`2`}),(0,m.jsx)(`circle`,{cx:`12.5`,cy:`12.5`,r:`2`}),(0,m.jsx)(`path`,{d:`M8 5.5v2.5M6.5 10.5L5 11.5M9.5 10.5L11 11.5`})]}),providers:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`rect`,{x:`2`,y:`3`,width:`12`,height:`10`,rx:`1.5`}),(0,m.jsx)(`path`,{d:`M5 7l2 2 4-4`})]}),token:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`circle`,{cx:`6`,cy:`6`,r:`3`}),(0,m.jsx)(`circle`,{cx:`11`,cy:`11`,r:`3`})]}),trends:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:(0,m.jsx)(`path`,{d:`M2 4l4 4 3-3 5 5M11 10h3V7`})}),pricing:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`path`,{d:`M8 2l6 3v6l-6 3-6-3V5z`}),(0,m.jsx)(`path`,{d:`M8 2v12M2 5h12`})]}),settings:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,...Pr,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`2.5`}),(0,m.jsx)(`path`,{d:`M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2`})]})},Ir=p,Lr=Ir.IconChevronDownOutlineMedium??Ir.IconChevronDownOutline14;function Rr(e,t){let n=Object.keys(e).filter(e=>e<=t).sort().slice(-7);return n.length===0?0:n.reduce((t,n)=>t+(e[n]?.cost??0),0)/n.length}function zr(e,t){let n=t.split(`-`),r=new Date(Number(n[0]),Number(n[1])-1,Number(n[2])),i=0;for(let t=0;t<7;t+=1){let t=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`;i+=e[t]?.cost??0,r.setDate(r.getDate()-1)}return i/7}function Br(e,t,n){let r=Object.keys(e).filter(e=>e.startsWith(t)).reduce((t,n)=>t+(e[n]?.cost??0),0),i=t.split(`-`),a=new Date(Number(i[0]),Number(i[1]),0).getDate(),o=n.startsWith(t)?Number(n.slice(8,10)):a,s=Math.max(0,a-o);return r<=0?Rr(e,n)*s:r+zr(e,n)*s}function Vr(e){return Object.keys(e).length}function Hr(e,t=Date.now()){let n=0,r=new Date(t);for(;K(r.getTime())in e;)n+=1,r.setDate(r.getDate()-1);return n}function Ur(e){return e.input+e.output}function Wr(e){let t=[];for(let n=6;n>=0;--n){let r=new Date;r.setDate(r.getDate()-n);let i=K(r.getTime());t.push({date:i,cost:e[i]?.cost??0})}return t}function Gr(e,t,n=e=>e.cost){let r=new Date(`${t}T00:00:00`),i=(r.getDay()+6)%7,a=0;for(let t=0;t<=i;t+=1){let i=new Date(r);i.setDate(i.getDate()-t);let o=e[K(i.getTime())];o!==void 0&&(a+=n(o))}return a}function Kr(e,t,n){let r=new Date(`${t}T00:00:00`),i=(r.getDay()+6)%7,a=new Date(r);a.setDate(a.getDate()-i);let o=K(a.getTime()),s=new Date(r);s.setDate(s.getDate()-6);let c=K(s.getTime());return Jr(e,e=>n===`today`?e===t:n===`7d`?e>=c&&e<=t:n===`week`?e>=o&&e<=t:e.startsWith(t.slice(0,7)))}function qr(e,t,n){return Jr(e,e=>e>=t&&e<=n)}function Jr(e,t){let n=0,r=0,i=0,a=0,o=0,s=0,c=0,l=0,u,d=0;for(let[f,p]of Object.entries(e)){if(!t(f))continue;n+=p.cost,r+=p.calls,i+=p.input,a+=p.output,o+=p.cacheHit,s+=p.cacheMiss,c+=p.cacheWrite??0,l+=p.reasoning??0;let e=Ur(p);e>d&&(d=e,u=f)}return{cost:n,calls:r,input:i,output:a,cacheHit:o,cacheMiss:s,cacheWrite:c,reasoning:l,peakDay:u,peakTokens:d}}function Yr(e,t){let n={};if(e===void 0)return n;for(let[r,i]of Object.entries(e))if(r.startsWith(t))for(let[e,t]of Object.entries(i))n[e]=(n[e]??0)+t.cost;return n}let Xr=[80,100];function Zr(e,t){if(!(t>0)||!(e>0))return[];let n=e/t*100;return Xr.filter(e=>n>=e)}let Qr={DeepSeek:[`deepseek`],"智谱 AI":[`zhipu`,`glm`,`z.ai`],阿里通义:[`qwen`,`tongyi`,`dashscope`,`aliyun`],字节豆包:[`doubao`,`volcengine`,`ark`],月之暗面:[`moonshot`,`kimi`],小米:[`xiaomi`,`mi`,`mimo`],MiniMax:[`minimax`],百度文心:[`ernie`,`wenxin`,`qianfan`,`baidu`],腾讯混元:[`hunyuan`,`tencent`],零一万物:[`01.ai`,`lingyi`,`yi`],阶跃星辰:[`step`,`stepfun`,`step-3.7`],科大讯飞:[`spark`,`xfyun`,`iflytek`],商汤:[`sensenova`,`sensetime`],百川智能:[`baichuan`],OpenAI:[`openai`],Google:[`google`,`gemini`],xAI:[`xai`,`grok`],Meta:[`meta`,`llama`],Anthropic:[`claude`,`anthropic`],"Mistral AI":[`mistral`,`ministral`,`devstral`],Cohere:[`cohere`,`command`],美团:[`longcat`,`meituan`],面壁智能:[`minicpm`,`modelbest`],小红书:[`dots`,`rednote`,`xiaohongshu`],云知声:[`unisound`,`u2`]};function Q(e){return e.trim().toLowerCase().replace(/[\s_/-]+/g,``)}function $r(e,t){if(e.length===0||t.length===0)return!1;if(e===t)return!0;let[n,r]=e.length<=t.length?[e,t]:[t,e];return n.length>=3&&r.includes(n)}function ei(e,t){let n=Q(e),r=Q(t);if($r(n,r))return!0;let i=Qr[e];return i!==void 0&&i.some(e=>$r(Q(e),r))}function ti(e){let t=e.trim().toLowerCase(),n=t.replace(/[\s_/-]+/g,``);if(n.length!==0){for(let[e,n]of Object.entries(Qr))for(let r of n){let n=Q(r);if(n.length!==0&&(t===n||t.startsWith(`${n}-`)||t.startsWith(`${n}/`)||t.startsWith(`${n}_`)||t.includes(`${n}-`)||t.includes(`${n}/`)||t.includes(`${n}_`)))return e}for(let[e,t]of Object.entries(Qr))for(let r of t){let t=Q(r);if(!(t.length<4)&&n.includes(t))return e}}}let ni={"kimi-coding":`月之暗面`,"zai-coding-cn":`智谱 AI`,"zai-coding":`智谱 AI`,"qwen-token-plan":`阿里通义`,"qwen-token-plan-cn":`阿里通义`,"xiaomi-token-plan-ams":`小米`,"xiaomi-token-plan-cn":`小米`,"xiaomi-token-plan-sgp":`小米`,"volcengine-token-plan":`字节豆包`,"ark-token-plan":`字节豆包`,"doubao-token-plan":`字节豆包`,ernie:`百度文心`,baidu:`百度文心`,wenxin:`百度文心`,minimax:`MiniMax`,"minimax-cn":`MiniMax`,"minimax-token-plan":`MiniMax`,"minimax-token-plan-cn":`MiniMax`,"hunyuan-token-plan":`腾讯混元`,"tencent-token-plan":`腾讯混元`,"hy-token-plan":`腾讯混元`,"xinghuo-token-plan":`讯飞星火`,"xfyun-coding":`讯飞星火`,"spark-coding":`讯飞星火`,"huawei-token-plan":`华为云`,"pangu-token-plan":`华为云`,"huawei-maas-token-plan":`华为云`,"volcengine-agent-plan":`字节豆包`,"ark-agent-plan":`字节豆包`,"baidu-token-plan":`百度文心`,"ernie-token-plan":`百度文心`,"wenxin-token-plan":`百度文心`,opencode:`OpenCode`,"opencode-go":`OpenCode`};function ri(e){let t=ni[e];return t===void 0?ti(e)??e:t}let ii=`https://platform.kimi.com/console/pay`,ai=`https://open.bigmodel.cn/finance-center/finance/pay`,oi=`https://bailian.console.aliyun.com/`,si=`https://console.volcengine.com/ark`,ci=`https://console.anthropic.com/settings/billing`,li=`https://console.cloud.google.com/billing`,ui=`https://console.x.ai/`,di=`https://platform.xiaomimimo.com/console/balance`,fi=`https://console.cloud.tencent.com/expense/recharge`,pi={deepseek:`https://platform.deepseek.com/top_up`,minimax:`https://platform.minimax.cn/console/recharge-records`,moonshot:ii,kimi:ii,zhipu:ai,bigmodel:ai,qwen:oi,dashscope:oi,doubao:si,volcengine:si,ark:si,openai:`https://platform.openai.com/settings/organization/billing`,anthropic:ci,claude:ci,google:li,gemini:li,xai:ui,grok:ui,siliconflow:`https://cloud.siliconflow.cn/account/charge`,hunyuan:fi,tencent:fi,腾讯云:fi,xiaomi:di,mimo:di,mi:di,qianfan:`https://console.bce.baidu.com/qianfan/overview`};function mi(e){let t=pi[e];if(t!==void 0)return t;let n=Object.keys(pi).find(t=>e.startsWith(t));return n===void 0?void 0:pi[n]}function hi(e){let t=Q(e),n=mi(t);if(n!==void 0)return n;for(let[e,n]of Object.entries(Qr))if($r(Q(e),t))for(let e of n){let t=mi(Q(e));if(t!==void 0)return t}}function gi(e){let t=pt();if(t===void 0||e.byDayModels===void 0)return e;let n=St().rate,r=e.byDayModelsSite!==void 0,i={},a={},o=new Map,s=0,c=e=>t.some(t=>t.origin!==void 0&&t.origin!==``&&(t.key===e||G(t.key)===G(e))),l=(e,t,r)=>{if(e===void 0)return r;let i=Math.min(t.cacheHit,t.cacheMiss+t.cacheHit),a=r=>{let a=(t.cacheMiss*r.input+i*r.cacheHit+t.output*r.output)/1e6;return e.currency===`USD`?a*n:a};return e.offPeak===void 0?a(e):a(e)*wt+a(e.offPeak)*.5};for(let[t,n]of Object.entries(e.byDayModels)){let u=0,d={};for(let[i,a]of Object.entries(n)){let n=ht(i)??_t(i),s=r&&c(i),f;if(s&&e.byDayModelsSite?.[t]?.[i]!==void 0){let r=0;for(let[a,o]of Object.entries(e.byDayModelsSite[t][i])){let e=a.startsWith(`site:`)?a.slice(5):void 0,t=e===void 0?void 0:ht(i,e);r+=l(t??n,o,o.cost)}f=r}else f=l(n,a,a.cost);u+=f,d[i]={...a,cost:f},o.set(i,(o.get(i)??0)+f)}let f=e.byDay[t];f!==void 0&&(i[t]={...f,cost:u}),a[t]=d,s+=u}return{...e,total:{...e.total,cost:s},byDay:i,byDayModels:a,byModel:Object.fromEntries(Object.entries(e.byModel).map(([e,t])=>{let n=o.get(e);return[e,n===void 0?t:{...t,cost:n}]})),unpricedModels:(e.unpricedModels??[]).filter(e=>!ht(e)&&!_t(e))}}async function _i(e,t={}){let{timeoutMs:n=12e3,signal:r,...i}=t,a=new AbortController,o=setTimeout(()=>{a.abort()},n),s=()=>{a.abort()};r!=null&&(r.aborted?a.abort():r.addEventListener(`abort`,s,{once:!0}));try{return await fetch(e,{...i,signal:a.signal})}finally{clearTimeout(o),r?.removeEventListener(`abort`,s)}}let vi=new Set;function yi(){return typeof Notification<`u`&&Notification.permission===`granted`}function bi(e,t){vi.has(e)||(vi.add(e),_i(`/api/billing/notify-claim`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({key:e})}).then(e=>e.json()).then(e=>{e.claimed!==!1&&t()}).catch(()=>t()))}function xi(e){let t=new Map,n=[];for(let r of e){if(r.title===void 0||r.title===``){n.push(r);continue}let e=t.get(r.title);if(e===void 0){let e={...r,mergedCount:1};t.set(r.title,e),n.push(e);continue}e.children===void 0&&(e.children=[{...e}]),e.children.push({...r}),e.calls+=r.calls,e.cost+=r.cost,e.lastActive=Math.max(e.lastActive,r.lastActive),r.stale===!0&&(e.stale=!0),e.mergedCount=(e.mergedCount??1)+1}return n.sort((e,t)=>t.cost-e.cost||t.lastActive-e.lastActive)}function Si(e){let t=new Map(e.map(e=>[e.id,e])),n=xi(e.filter(e=>e.parentId===void 0)),r=new Map;for(let e of n){r.set(e.id,e);for(let t of e.children??[])r.set(t.id,e)}let i=new Set,a=new Map,o=(e,t)=>{e.subs===void 0?e.subs=[t]:e.subs.push(t),i.add(t.id),a.set(t.id,e.id)};for(let n of e){if(n.parentId===void 0)continue;let e=t.get(n.parentId);if(e!==void 0&&e.parentId!==void 0&&e.id!==n.id){let t=e.id,r=new Set,i=!1;for(;t!==void 0&&!r.has(t);){if(r.add(t),t===n.id){i=!0;break}t=a.get(t)}if(!i){o(e,n);continue}}let s=new Set,c=n.parentId;for(;c!==void 0&&!s.has(c);){s.add(c);let e=r.get(c);if(e!==void 0){i.has(n.id)||o(e,n);break}c=t.get(c)?.parentId}}let s=e=>e.cost+(e.subCost??0),c=e=>{e.subs?.sort((e,t)=>s(t)-s(e)||t.lastActive-e.lastActive);for(let t of e.subs??[])c(t)};for(let e of n)c(e);let l=e.filter(e=>e.parentId!==void 0&&!i.has(e.id));for(let e of l)c(e);return[...n,...l].sort((e,t)=>t.cost-e.cost||t.lastActive-e.lastActive)}function Ci(e){let t=new Map;for(let n of e)t.has(n.id)||t.set(n.id,n);let n=new Map,r=[];for(let i of e){let e=i.parentId;if(e===void 0||!t.has(e)||wi(t,i.id)){r.push(i);continue}let a=n.get(e);a===void 0?n.set(e,[i]):a.push(i)}let i=(e,t,r)=>{let a=new Set(r);a.add(e.id);let o=(n.get(e.id)??[]).filter(e=>!r.has(e.id)).map(e=>i(e,t+1,a)).sort((e,t)=>t.chainCost-e.chainCost),s={id:e.id,...e.title===void 0?{}:{title:e.title},...e.cwd===void 0?{}:{cwd:e.cwd},calls:e.calls,cost:e.cost,lastActive:e.lastActive,chainCost:e.cost,chainCalls:e.calls,children:o,depth:t};for(let e of o)s.chainCost+=e.chainCost,s.chainCalls+=e.chainCalls;return s};return r.map(e=>i(e,0,new Set)).sort((e,t)=>t.chainCost-e.chainCost)}function wi(e,t){let n=new Set([t]),r=e.get(t)?.parentId;for(;r!==void 0;){if(n.has(r))return!0;n.add(r),r=e.get(r)?.parentId}return!1}function Ti(e){let t=0,n=0,r,i=e=>{t+=1,n+=e.children.length,(r===void 0||e.chainCost>r.chainCost)&&(r=e);for(let t of e.children)i(t)};for(let t of e)i(t);return{agents:t,delegations:n,roots:e.length,...r===void 0?{}:{costliest:r}}}function Ei(e,t){let n=t.trim().toLowerCase();return n===``?e:e.filter(e=>(e.title??``).toLowerCase().includes(n)||(e.cwd??``).toLowerCase().includes(n)||e.id.toLowerCase().includes(n))}function Di(e,t){let n=e.trim().toLowerCase();return n!==``&&!t.some(e=>e.toLowerCase().includes(n))}function Oi(e,t){return e.checked?e.okProviders.some(e=>ei(t,e))?z.healthOk:e.badProviders.some(e=>ei(t,e))?z.healthBad:z.healthIdle:z.healthIdle}function ki(e,t){switch(e){case`ok`:return``;case`not-configured`:return t(`subscriptionNotConfigured`);case`unauthorized`:return t(`subscriptionUnauthorized`);case`rate-limited`:return t(`subscriptionRateLimited`);case`invalid-response`:return t(`subscriptionInvalid`);default:return t(`subscriptionUnavailable`)}}function Ai(e,t){switch(e){case`session`:return t(`subscriptionSession`);case`weekly`:return t(`subscriptionWeekly`);case`monthly`:return t(`subscriptionMonthly`);case`billing`:return t(`subscriptionBilling`)}}function ji(e,t){switch(e){case`new-api`:return t(`relayKindNewApi`);case`sub2api`:return t(`relayKindSub2Api`);default:return t(`relayKindUnknown`)}}let Mi={"new-api":z.siteKindSite,sub2api:z.siteKindDirect,unknown:z.siteKindUnknown},Ni=e=>e.models.reduce((e,t)=>e+(t.actual??(t.plan===!0?0:t.estimated)),0);function Pi(e){return e.children===void 0?{cost:e.subCost??0,calls:e.subCalls??0}:(e.children??[]).reduce((e,t)=>({cost:e.cost+(t.subCost??0),calls:e.calls+(t.subCalls??0)}),{cost:0,calls:0})}function Fi(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${n(t.getHours())}:${n(t.getMinutes())}:${n(t.getSeconds())}`}async function Ii(){try{let e=await _i(`/api/billing/usage-stats`);if(!e.ok)return null;let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n||!(`total`in n))return null;let r=n,i=e=>typeof e==`object`&&!!e;return{total:r.total??Ar.total,byModel:r.byModel??{},byDay:r.byDay??{},...r.byDayModels===void 0?{}:{byDayModels:r.byDayModels},...i(r.byDayModelsSite)?{byDayModelsSite:r.byDayModelsSite}:{},...r.updatedAt===void 0?{}:{updatedAt:r.updatedAt},...r.staleSnapshot===!0?{staleSnapshot:!0}:{},...typeof r.budget==`number`?{budget:r.budget}:{},...typeof r.lowBalanceThreshold==`number`?{lowBalanceThreshold:r.lowBalanceThreshold}:{},...Array.isArray(r.bySession)?{bySession:r.bySession}:{},...Array.isArray(r.byTurn)?{byTurn:r.byTurn}:{},...Array.isArray(r.byWorkspace)?{byWorkspace:r.byWorkspace}:{},...i(r.bySite)?{bySite:r.bySite}:{},...i(r.byTier)?{byTier:r.byTier}:{},...i(r.byTool)?{byTool:r.byTool}:{},...Array.isArray(r.unpricedModels)?{unpricedModels:r.unpricedModels}:{},...typeof r.staleLedgerSessions==`number`?{staleLedgerSessions:r.staleLedgerSessions}:{},...typeof r.unreadableSessions==`number`?{unreadableSessions:r.unreadableSessions}:{},...typeof r.unreadableFormatSessions==`number`?{unreadableFormatSessions:r.unreadableFormatSessions}:{},...typeof r.unreadableNoLedgerSessions==`number`?{unreadableNoLedgerSessions:r.unreadableNoLedgerSessions}:{},...typeof r.searchCallEstimateCny==`number`?{searchCallEstimateCny:r.searchCallEstimateCny}:{},...r.byRole!==null&&typeof r.byRole==`object`?{byRole:r.byRole}:{},...r.perf!==null&&typeof r.perf==`object`&&r.perf.byModel!==null&&typeof r.perf.byModel==`object`&&r.perf.byHourModel!==null&&typeof r.perf.byHourModel==`object`?{perf:r.perf}:{},...typeof r.pluginVersion==`string`?{pluginVersion:r.pluginVersion}:{}}}catch{return null}}async function Li(){try{let e=await _i(`/api/billing/balance`);if(!e.ok)return{balances:[]};let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n)return{balances:[]};let r=n;return{balances:Array.isArray(r.balances)?r.balances:[],...r.reconcile===void 0?{}:{reconcile:r.reconcile},...r.stale===!0?{stale:!0}:{}}}catch{return{balances:[]}}}async function Ri(){let e=await _i(`/api/billing/subscriptions`);if(!e.ok)throw Error(`subscriptions HTTP ${String(e.status)}`);let t=await e.text(),n=JSON.parse(t);if(typeof n==`object`&&n&&`quotas`in n){let e=n;return{quotas:e.quotas,...e.stale===!0?{stale:!0}:{}}}throw Error(`subscriptions: invalid response`)}async function zi(){let e=await _i(`/api/billing/relay-quotas`);if(!e.ok)throw Error(`relay-quotas HTTP ${String(e.status)}`);let t=await e.text(),n=JSON.parse(t);if(typeof n==`object`&&n&&`quotas`in n)return n.quotas;throw Error(`relay-quotas: invalid response`)}async function Bi(){try{let e=await _i(`/api/billing/usage-tool`);if(!e.ok)return;let t=JSON.parse(await e.text());return typeof t.enabled==`boolean`?t.enabled:void 0}catch{return}}async function Vi(e){try{let t=await _i(`/api/billing/usage-tool`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({enabled:e})});return t.ok?JSON.parse(await t.text()).ok===!0:!1}catch{return!1}}let Hi=!1,Ui=0;async function Wi(e=0){try{let t=await _i(`/api/billing/pricing`);if(!t.ok){Hi=!1;return}let n=await t.text(),r=JSON.parse(n);if(typeof r!=`object`||!r||!(`source`in r)){Hi=!1;return}let i=r;Array.isArray(i.catalog)&&i.catalog.length>0&&i.aliases!==null&&typeof i.aliases==`object`&&W(i.catalog,i.aliases);let a=r;if(a.source===`builtin`&&e<3){if(e===0){if(Hi)return;Hi=!0}setTimeout(()=>{Wi(e+1)},2e3);return}Hi=!1,Ui=a.syncedAt??0,vt(a)}catch{Hi=!1}}async function Gi(){try{return(await _i(`/api/billing/pricing/refresh`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`,timeoutMs:3e4})).ok?(await Wi(),!0):!1}catch{return!1}}async function Ki(e){try{let t=JSON.parse(await e.text());return typeof t.error==`string`?t.error:`HTTP ${e.status}`}catch{return`HTTP ${e.status}`}}async function qi(e=!1){let t=await _i(`/api/billing/task-queue${e?`?refresh=1`:``}`);if(!t.ok)throw Error(await Ki(t));return await t.json()}async function Ji(){let e=await _i(`/api/billing/task-queue-summary`);if(!e.ok)throw Error(await Ki(e));return await e.json()}async function Yi(e){let t=await _i(`/api/billing/task-queue`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)});if(!t.ok)throw Error(await Ki(t));return(await t.json()).snapshot}let Xi=`@kenz1117/dsh-ui-usage-billing/TaskQueuePanel.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Xi)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@kenz1117/dsh-ui-usage-billing`,e.dataset.pluginCss=Xi,e.textContent=`.cQSERa_queuePanel{color:var(--ds-t-1);flex-direction:column;flex-shrink:0;gap:12px;display:flex}.cQSERa_queuePanel *{box-sizing:border-box}.cQSERa_queueHero,.cQSERa_queueComposer,.cQSERa_queueListSection,.cQSERa_queueUnsupported{border:1px solid var(--ds-border);border-radius:var(--ds-r-2);background:var(--dsb-2);flex-shrink:0}.cQSERa_queueHero{justify-content:space-between;align-items:center;gap:16px;padding:16px;display:flex}.cQSERa_queueTitleRow{align-items:center;gap:8px;display:flex}.cQSERa_queueTitle,.cQSERa_queueListHead h3,.cQSERa_queueUnsupported h3{margin:0;font-size:15px;font-weight:650}.cQSERa_queuePreview{background:var(--ds-violet-soft);color:var(--ds-violet);text-transform:uppercase;border-radius:5px;padding:2px 6px;font-size:10px;font-weight:700}.cQSERa_queueSubtitle{color:var(--ds-t-2);margin:5px 0 0;font-size:12px;line-height:1.6}.cQSERa_queueBand{color:var(--ds-t-2);flex-direction:column;flex-shrink:0;align-items:flex-end;gap:3px;font-size:11px;display:flex}.cQSERa_queueBand strong{font-size:13px}.cQSERa_queueBandOff strong{color:var(--ds-green)}.cQSERa_queueBandPeak strong{color:var(--ds-amber)}.cQSERa_queueComposer{flex-direction:column;gap:12px;padding:14px;display:flex}.cQSERa_queueSafety{border-radius:var(--ds-r-1);background:color-mix(in srgb, var(--ds-amber) 8%, transparent);color:var(--ds-t-2);padding:9px 11px;font-size:11px;line-height:1.65}.cQSERa_queueSelectors{grid-template-columns:1fr 1fr;gap:10px;display:grid}.cQSERa_queueField,.cQSERa_queuePromptField{color:var(--ds-t-2);flex-direction:column;gap:6px;font-size:11px;display:flex}.cQSERa_queueField select,.cQSERa_queuePromptField textarea{border:1px solid var(--ds-border);border-radius:var(--ds-r-1);background:var(--dsb);width:100%;color:var(--ds-t-1);font:inherit}.cQSERa_queueField select{height:34px;padding:0 9px}.cQSERa_queuePromptField textarea{resize:vertical;min-height:112px;padding:10px;line-height:1.55}.cQSERa_queueField select:focus,.cQSERa_queuePromptField textarea:focus{outline:2px solid color-mix(in srgb, var(--ds-blue) 35%, transparent);border-color:var(--ds-blue)}.cQSERa_queueField select:disabled,.cQSERa_queuePromptField textarea:disabled{opacity:.55}.cQSERa_queueComposerFooter{color:var(--ds-t-3);justify-content:space-between;align-items:center;gap:12px;font-size:10px;line-height:1.5;display:flex}.cQSERa_queueComposerActions{flex-shrink:0;align-items:center;gap:8px;display:flex}.cQSERa_queueFileInput{display:none}.cQSERa_queuePrimary,.cQSERa_queueSecondary{border-radius:var(--ds-r-1);cursor:pointer;flex-shrink:0;min-height:34px;padding:0 16px;font-weight:600}.cQSERa_queuePrimary{background:var(--ds-blue);color:#fff;border:0}.cQSERa_queueSecondary{border:1px solid var(--ds-border);background:var(--dsb);color:var(--ds-t-1)}.cQSERa_queuePrimary:disabled,.cQSERa_queueSecondary:disabled{opacity:.45;cursor:not-allowed}.cQSERa_queueListSection{padding:12px 14px}.cQSERa_queueListHead{justify-content:space-between;align-items:center;margin-bottom:8px;display:flex}.cQSERa_queueListHead h3 span{color:var(--ds-t-3);margin-left:4px;font-size:11px;font-weight:500}.cQSERa_queueList{flex-direction:column;gap:8px;margin:0;padding:0;list-style:none;display:flex}.cQSERa_queueTask{border:1px solid var(--ds-border);border-radius:var(--ds-r-1);background:var(--dsb);padding:10px}.cQSERa_queueTaskHead{align-items:center;gap:8px;min-width:0;display:flex}.cQSERa_queueStatus{background:var(--dsb-3);color:var(--ds-t-2);border-radius:5px;flex-shrink:0;padding:2px 6px;font-size:10px;font-weight:650}.cQSERa_queueStatus_running,.cQSERa_queueStatus_starting{color:var(--ds-blue);background:color-mix(in srgb, var(--ds-blue) 12%, transparent)}.cQSERa_queueStatus_completed{color:var(--ds-green);background:color-mix(in srgb, var(--ds-green) 12%, transparent)}.cQSERa_queueStatus_failed{color:var(--ds-red);background:color-mix(in srgb, var(--ds-red) 10%, transparent)}.cQSERa_queueTaskMeta{text-overflow:ellipsis;white-space:nowrap;min-width:0;color:var(--ds-t-2);font-size:11px;overflow:hidden}.cQSERa_queueTaskTime{color:var(--ds-t-3);flex-shrink:0;margin-left:auto;font-size:10px}.cQSERa_queuePrompt{color:var(--ds-t-1);margin-top:8px;font-size:12px;line-height:1.55}.cQSERa_queuePrompt summary{text-overflow:ellipsis;white-space:nowrap;cursor:pointer;overflow:hidden}.cQSERa_queuePrompt pre{background:var(--dsb-2);white-space:pre-wrap;overflow-wrap:anywhere;max-height:240px;font-family:var(--mono);border-radius:6px;margin:8px 0 0;padding:9px;font-size:11px;line-height:1.55;overflow:auto}.cQSERa_queueTaskError{color:var(--ds-red);overflow-wrap:anywhere;margin-top:8px;font-size:11px;line-height:1.5}.cQSERa_queueTaskActions{justify-content:flex-end;gap:10px;margin-top:5px;display:flex}.cQSERa_queueLinkButton{color:var(--ds-blue);cursor:pointer;background:0 0;border:0;padding:2px 0;font-size:11px}.cQSERa_queueLinkButton:disabled{opacity:.45;cursor:not-allowed}.cQSERa_queueEmpty{color:var(--ds-t-3);text-align:center;padding:26px 12px;font-size:12px}.cQSERa_queueUnsupported{padding:22px}.cQSERa_queueUnsupported p{color:var(--ds-t-2);margin:8px 0 0;font-size:12px;line-height:1.7}.cQSERa_queueNotice,.cQSERa_queueNoticeError{border-radius:var(--ds-r-1);overflow-wrap:anywhere;flex-shrink:0;padding:9px 11px;font-size:11px;line-height:1.5}.cQSERa_queueNotice{background:var(--dsb-2);color:var(--ds-t-2)}.cQSERa_queueNoticeError{background:color-mix(in srgb, var(--ds-red) 10%, transparent);color:var(--ds-red)}@media (width<=640px){.cQSERa_queueHero{align-items:flex-start}.cQSERa_queueSelectors{grid-template-columns:1fr}.cQSERa_queueComposerFooter{flex-direction:column;align-items:stretch}.cQSERa_queueComposerActions{flex-wrap:wrap;justify-content:flex-end}.cQSERa_queueTaskTime{display:none}}`,document.head.appendChild(e)}var $={queueBand:`cQSERa_queueBand`,queueBandOff:`cQSERa_queueBandOff`,queueBandPeak:`cQSERa_queueBandPeak`,queueComposer:`cQSERa_queueComposer`,queueComposerActions:`cQSERa_queueComposerActions`,queueComposerFooter:`cQSERa_queueComposerFooter`,queueEmpty:`cQSERa_queueEmpty`,queueField:`cQSERa_queueField`,queueFileInput:`cQSERa_queueFileInput`,queueHero:`cQSERa_queueHero`,queueLinkButton:`cQSERa_queueLinkButton`,queueList:`cQSERa_queueList`,queueListHead:`cQSERa_queueListHead`,queueListSection:`cQSERa_queueListSection`,queueNotice:`cQSERa_queueNotice`,queueNoticeError:`cQSERa_queueNoticeError`,queuePanel:`cQSERa_queuePanel`,queuePreview:`cQSERa_queuePreview`,queuePrimary:`cQSERa_queuePrimary`,queuePrompt:`cQSERa_queuePrompt`,queuePromptField:`cQSERa_queuePromptField`,queueSafety:`cQSERa_queueSafety`,queueSecondary:`cQSERa_queueSecondary`,queueSelectors:`cQSERa_queueSelectors`,queueStatus:`cQSERa_queueStatus`,queueStatus_completed:`cQSERa_queueStatus_completed`,queueStatus_failed:`cQSERa_queueStatus_failed`,queueStatus_running:`cQSERa_queueStatus_running`,queueStatus_starting:`cQSERa_queueStatus_starting`,queueSubtitle:`cQSERa_queueSubtitle`,queueTask:`cQSERa_queueTask`,queueTaskActions:`cQSERa_queueTaskActions`,queueTaskError:`cQSERa_queueTaskError`,queueTaskHead:`cQSERa_queueTaskHead`,queueTaskMeta:`cQSERa_queueTaskMeta`,queueTaskTime:`cQSERa_queueTaskTime`,queueTitle:`cQSERa_queueTitle`,queueTitleRow:`cQSERa_queueTitleRow`,queueUnsupported:`cQSERa_queueUnsupported`};let Zi={queued:`queueStatusQueued`,starting:`queueStatusStarting`,running:`queueStatusRunning`,completed:`queueStatusCompleted`,failed:`queueStatusFailed`};function Qi(e){return e.status===`completed`||e.status===`failed`}function $i(e,t){return JSON.stringify([e,t])}function ea(e,t){let n;try{n=JSON.parse(e)}catch{throw Error(`invalid task import`)}if(!Array.isArray(n)||n.length===0)throw Error(`invalid task import`);return n.map(e=>{if(typeof e==`string`)return{prompt:e,...t};if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`invalid task import`);let n=e;return{prompt:n.prompt,cwd:n.cwd??t.cwd,provider:n.provider??t.provider,model:n.model??t.model}})}function ta({t:e,language:t,navigateToSession:n}){let[r,i]=(0,d.useState)(),[a,o]=(0,d.useState)(``),[s,c]=(0,d.useState)(``),[l,u]=(0,d.useState)(``),[f,p]=(0,d.useState)(!1),[h,g]=(0,d.useState)(),[_,v]=(0,d.useState)(),b=(0,d.useRef)(!0),x=(0,d.useRef)(!1),S=(0,d.useRef)(!1),C=(0,d.useRef)(null),w=(0,d.useCallback)(async()=>{if(!x.current){x.current=!0;try{let e=await qi();b.current&&i(e)}catch(e){b.current&&g(e instanceof Error?e.message:String(e))}finally{x.current=!1}}},[]),[T,ee]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{ee(!document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[]),(0,d.useEffect)(()=>{if(b.current=!0,!T)return;w();let e=setInterval(()=>{w()},5e3);return()=>{b.current=!1,clearInterval(e)}},[w,T]),(0,d.useEffect)(()=>{if(h===void 0)return;let e=window.setTimeout(()=>{g(void 0)},8e3);return()=>{window.clearTimeout(e)}},[h]),(0,d.useEffect)(()=>{if(_===void 0)return;let e=window.setTimeout(()=>{v(void 0)},4e3);return()=>{window.clearTimeout(e)}},[_]),(0,d.useEffect)(()=>{r!==void 0&&(r.workspaces.some(e=>e.path===s)||c(r.workspaces[0]?.path??``),r.models.some(e=>$i(e.provider,e.id)===l)||u(r.models[0]===void 0?``:$i(r.models[0].provider,r.models[0].id)))},[r,s,l]);let E=(0,d.useCallback)(async(e,t=!1)=>{if(f||S.current)return!1;S.current=!0,p(!0),g(void 0),v(void 0);try{let n=await Yi(e);return b.current?(i(n),t&&o(``),!0):!1}catch(e){return b.current&&g(e instanceof Error?e.message:String(e)),!1}finally{S.current=!1,p(!1)}},[f]),D=(0,d.useMemo)(()=>r?.tasks.filter(e=>!Qi(e))??[],[r]),O=(0,d.useMemo)(()=>r?.tasks.filter(Qi).slice().reverse()??[],[r]),k=r!==void 0&&r.supported&&r.workspaces.length>0&&r.models.length>0,A=e=>new Date(e).toLocaleString(t===`en`?`en-US`:`zh-CN`),j=()=>{if(a.trim()===``||s===``||l===``)return;let[e,t]=JSON.parse(l);E({action:`enqueue`,prompt:a,cwd:s,provider:e,model:t},!0)},M=async t=>{if(!(t===void 0||!k||f||l===``)){g(void 0),v(void 0);try{if(t.size>10485760){g(e(`queueImportTooLarge`));return}let[n,r]=JSON.parse(l),i=ea(await t.text(),{cwd:s,provider:n,model:r});await E({action:`enqueueMany`,tasks:i})&&b.current&&v(e(`queueImported`,{count:i.length}))}catch{b.current&&g(e(`queueImportFormat`))}}},te=t=>{let r=n(t);v(r===`opened`?void 0:e(r===`unavailable`?`sessionOpenUnavailable`:`sessionOpenFailed`))},ne=t=>{let n=r?.workspaces.find(e=>e.path===t.cwd);return(0,m.jsxs)(`li`,{className:$.queueTask,"data-testid":`queue-task-${t.id}`,children:[(0,m.jsxs)(`div`,{className:$.queueTaskHead,children:[(0,m.jsx)(`span`,{className:y($.queueStatus,$[`queueStatus_${t.status}`]),children:e(Zi[t.status])}),(0,m.jsxs)(`span`,{className:$.queueTaskMeta,children:[n?.title??t.cwd,` · `,t.model]}),(0,m.jsx)(`time`,{className:$.queueTaskTime,dateTime:new Date(t.createdAt).toISOString(),children:A(t.createdAt)})]}),(0,m.jsxs)(`details`,{className:$.queuePrompt,children:[(0,m.jsx)(`summary`,{children:t.prompt.trim().slice(0,180)||t.prompt.slice(0,180)}),(0,m.jsx)(`pre`,{children:t.prompt})]}),t.error!==void 0&&(0,m.jsx)(`div`,{className:$.queueTaskError,role:`note`,children:t.error}),(0,m.jsxs)(`div`,{className:$.queueTaskActions,children:[t.sessionId!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:$.queueLinkButton,onClick:()=>{te(t.sessionId)},children:e(`queueOpenSession`)}),(t.status===`queued`||Qi(t))&&(0,m.jsx)(`button`,{type:`button`,className:$.queueLinkButton,disabled:f,onClick:()=>{E({action:`remove`,id:t.id})},children:e(t.status===`queued`?`queueRemoveQueued`:`queueRemoveHistory`)})]})]},t.id)};return(0,m.jsxs)(`div`,{className:$.queuePanel,"data-testid":`billing-tab-panel-queue`,children:[(0,m.jsxs)(`section`,{className:$.queueHero,children:[(0,m.jsxs)(`div`,{children:[(0,m.jsxs)(`div`,{className:$.queueTitleRow,children:[(0,m.jsx)(`h2`,{className:$.queueTitle,children:e(`tabQueue`)}),(0,m.jsx)(`span`,{className:$.queuePreview,children:`Preview`})]}),(0,m.jsx)(`p`,{className:$.queueSubtitle,children:e(`queueSubtitle`)})]}),r?.supported&&(0,m.jsxs)(`div`,{className:y($.queueBand,r.tier===`offPeak`?$.queueBandOff:$.queueBandPeak),children:[(0,m.jsx)(`strong`,{children:e(r.tier===`offPeak`?`offPeak`:`peak`)}),(0,m.jsxs)(`span`,{children:[e(r.tier===`offPeak`?`queueUntilPeak`:`queueUntilOffPeak`),` `,Lt(r.nextSwitchInMs)]})]})]}),h!==void 0&&(0,m.jsx)(`div`,{className:$.queueNoticeError,role:`alert`,children:h}),_!==void 0&&(0,m.jsx)(`div`,{className:$.queueNotice,role:`status`,children:_}),r===void 0?(0,m.jsx)(`div`,{className:$.queueEmpty,children:e(`queueLoading`)}):r.supported?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`section`,{className:$.queueComposer,children:[(0,m.jsx)(`div`,{className:$.queueSafety,children:e(`queueSafety`)}),(0,m.jsxs)(`div`,{className:$.queueSelectors,children:[(0,m.jsxs)(`label`,{className:$.queueField,children:[(0,m.jsx)(`span`,{children:e(`queueWorkspace`)}),(0,m.jsx)(`select`,{value:s,disabled:!k||f,onChange:e=>{c(e.target.value)},children:r.workspaces.map(e=>(0,m.jsx)(`option`,{value:e.path,children:e.title},e.path))})]}),(0,m.jsxs)(`label`,{className:$.queueField,children:[(0,m.jsx)(`span`,{children:e(`queueModel`)}),(0,m.jsx)(`select`,{value:l,disabled:!k||f,onChange:e=>{u(e.target.value)},children:r.models.map(e=>(0,m.jsxs)(`option`,{value:$i(e.provider,e.id),children:[e.providerName,` / `,e.name]},$i(e.provider,e.id)))})]})]}),!k&&(0,m.jsx)(`div`,{className:$.queueNotice,children:r.optionsError??e(`queueNoOptions`)}),(0,m.jsxs)(`label`,{className:$.queuePromptField,children:[(0,m.jsx)(`span`,{children:e(`queuePromptLabel`)}),(0,m.jsx)(`textarea`,{value:a,disabled:!k||f,maxLength:32e3,rows:5,placeholder:e(`queuePromptPlaceholder`),onChange:e=>{o(e.target.value)}})]}),(0,m.jsxs)(`div`,{className:$.queueComposerFooter,children:[(0,m.jsx)(`span`,{children:e(`queuePrivacy`)}),(0,m.jsxs)(`div`,{className:$.queueComposerActions,children:[(0,m.jsx)(`input`,{ref:C,className:$.queueFileInput,"data-testid":`queue-import-file`,type:`file`,accept:`application/json,.json`,disabled:!k||f,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,M(t)}}),(0,m.jsx)(`button`,{type:`button`,className:$.queueSecondary,title:e(`queueImportHint`),disabled:!k||f,onClick:()=>{C.current?.click()},children:e(`queueImport`)}),(0,m.jsx)(`button`,{type:`button`,className:$.queuePrimary,disabled:!k||f||a.trim()===``,onClick:j,children:e(`queueEnqueue`)})]})]})]}),(0,m.jsxs)(`section`,{className:$.queueListSection,children:[(0,m.jsxs)(`div`,{className:$.queueListHead,children:[(0,m.jsxs)(`h3`,{children:[e(`queueActive`),` `,(0,m.jsx)(`span`,{children:D.length})]}),O.length>0&&(0,m.jsx)(`button`,{type:`button`,className:$.queueLinkButton,disabled:f,onClick:()=>{E({action:`clearFinished`})},children:e(`queueClearFinished`)})]}),D.length===0&&O.length===0?(0,m.jsx)(`div`,{className:$.queueEmpty,children:e(`queueEmpty`)}):(0,m.jsxs)(`ul`,{className:$.queueList,children:[D.map(ne),O.map(ne)]})]})]}):(0,m.jsxs)(`section`,{className:$.queueUnsupported,"data-testid":`queue-unsupported`,children:[(0,m.jsx)(`h3`,{children:e(`queueUnsupportedTitle`)}),(0,m.jsx)(`p`,{children:e(`queueUnsupportedBody`)})]})]})}function na({window:e,t}){let n=Math.min(100,Math.max(0,e.usedPercent)),r=Math.min(100,Math.max(0,e.remainingPercent))<=0;return(0,m.jsxs)(`div`,{className:z.subscriptionWindow,children:[(0,m.jsx)(`span`,{className:z.subscriptionWindowLabel,children:Ai(e.kind,t)}),(0,m.jsx)(`span`,{className:z.subscriptionTrack,"aria-hidden":`true`,children:(0,m.jsx)(`span`,{className:y(z.subscriptionFill,n>=100&&z.subscriptionFillOver,n>=80&&n<100&&z.subscriptionFillWarn),style:{width:`${n}%`}})}),(0,m.jsxs)(`span`,{className:z.subscriptionMeta,children:[(0,m.jsx)(`span`,{className:y(z.subscriptionPct,r&&z.subscriptionExhausted),children:r?t(`subscriptionExhausted`):t(`subscriptionRemaining`).replace(`{pct}`,String(e.remainingPercent))}),e.resetsAt!==void 0&&(0,m.jsx)(`span`,{className:z.subscriptionReset,children:t(`subscriptionReset`).replace(`{date}`,`${K(new Date(e.resetsAt).getTime())} ${Fi(new Date(e.resetsAt).getTime())}`)})]})]})}function ra({label:e,t}){return(0,m.jsx)(p.Tooltip,{label:e,side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.helpTip,role:`note`,"aria-label":e,children:`?`})})}function ia(e,t){return e===z.healthOk?t(`healthDotLive`):e===z.healthBad?t(`healthDotFailed`):t(`healthDotUnknown`)}function aa(e){let t=t=>dn(un(t,e.currency),e.currency),{wide:n,t:r,onOpen:i,monthCost:a,todayCost:o,weekCost:s,days:c,vendorStatus:l,dash:u,floatPrefs:p,subscriptions:h,cardPrefs:g,monthTokens:_,todayTokens:v,weekTokens:b,budgetPressure:x,deltaPct:S=0}=e,C=(0,d.useMemo)(()=>p.targets.map(e=>h.find(t=>t.provider===e)).filter(e=>e!==void 0),[p.targets,h]),[w,T]=(0,d.useState)(0),ee=C.length===0?0:Math.min(w,C.length-1),E=C[ee],D=(0,d.useRef)(null),[O,k]=(0,d.useState)(!1),[A,j]=(0,d.useState)({left:0,top:0});(0,d.useEffect)(()=>{if(!O||p.mode!==`subscription`||C.length<2)return;let e=setInterval(()=>T(e=>(e+1)%C.length),1500);return()=>clearInterval(e)},[O,p.mode,C.length]);let M=(0,d.useRef)(void 0),te=(0,d.useCallback)(()=>{window.clearTimeout(M.current),k(!0)},[]),ne=(0,d.useCallback)(()=>{window.clearTimeout(M.current),M.current=window.setTimeout(()=>k(!1),120)},[]);(0,d.useEffect)(()=>()=>window.clearTimeout(M.current),[]);let N=(0,d.useCallback)(()=>{let e=D.current?.getBoundingClientRect();e!==void 0&&j({left:e.left,top:e.top-8})},[]);(0,d.useEffect)(()=>{if(!O)return;let e=()=>N();return window.addEventListener(`scroll`,e,{capture:!0,passive:!0}),window.addEventListener(`resize`,e),()=>{window.removeEventListener(`scroll`,e,{capture:!0}),window.removeEventListener(`resize`,e)}},[O,N]);let re=c.length>0?c.reduce((e,t)=>e+t.cost,0)/c.length:0,ie=re>0?Math.max(0,Math.min(1,o/re)):0,ae=-80+ie*160,oe=(0,m.jsxs)(`svg`,{viewBox:`3.5 10 34 22`,fill:`none`,stroke:`currentColor`,strokeLinecap:`round`,"aria-hidden":`true`,children:[(0,m.jsx)(`path`,{d:`M5.23 26.4A15 15 0 0 1 34.77 26.4`,strokeWidth:3,opacity:.16}),(0,m.jsx)(`path`,{d:`M5.23 26.4A15 15 0 0 1 34.77 26.4`,strokeWidth:3,strokeDasharray:`${(41.9*ie).toFixed(2)} 41.9`,className:z.triggerGaugeArc}),(0,m.jsx)(`path`,{d:`M5.23 26.4 8.18 26.92M10.36 17.51 12.29 19.81M20 14v3M27.71 19.81 29.64 17.51M31.82 26.92 34.77 26.4`,strokeWidth:1.6,opacity:.7}),(0,m.jsx)(`path`,{d:`M7.01 21.5 8.31 22.25M14.87 14.91 15.38 16.31M24.62 16.31 25.13 14.91M31.69 22.25 32.99 21.5`,strokeWidth:1.2,opacity:.38}),(0,m.jsx)(`line`,{x1:`20`,y1:`29`,x2:`20`,y2:`19.5`,strokeWidth:2,className:z.triggerGaugeNeedle,style:{transform:`rotate(${ae}deg)`,transformOrigin:`20px 29px`}}),(0,m.jsx)(`circle`,{cx:`20`,cy:`29`,r:`1.5`,fill:`currentColor`,stroke:`none`})]});if(g.mode===`hidden`)return null;if(!n||g.mode===`compact`)return(0,m.jsx)(`button`,{type:`button`,className:y(z.railButton,x!==`none`&&z.triggerBudgetPulse,x===`over`&&z.triggerBudgetOver),"data-testid":`billing-rail-button`,onClick:i,title:`${r(`title`)} · ${t(g.span===`day`?o:g.span===`week`?s:a)}`,children:oe});let se=g.metric===`tokens`,ce=c.map(e=>se?e.tokens:e.cost),le=Math.max(...ce,0),ue=ce.map(e=>le>0?4+e/le*12:4);return(0,m.jsxs)(`span`,{ref:D,className:z.triggerWrap,onMouseEnter:()=>{N(),te()},onMouseLeave:ne,onFocusCapture:()=>{N(),te()},onBlurCapture:()=>k(!1),children:[(0,m.jsxs)(`button`,{type:`button`,className:y(z.trigger,x!==`none`&&z.triggerBudgetPulse,x===`over`&&z.triggerBudgetOver),"data-testid":`billing-trigger`,onClick:i,title:`${r(`title`)} · ${t(g.span===`day`?o:g.span===`week`?s:a)}`,children:[(0,m.jsx)(`span`,{className:y(z.triggerIcon,x!==`none`&&z.triggerBudgetHot),"data-testid":`billing-trigger-icon`,children:oe}),(0,m.jsx)(`span`,{className:z.triggerMain,children:(0,m.jsxs)(`span`,{className:z.triggerPrimary,children:[(0,m.jsx)(`span`,{className:z.triggerLabel,children:se?g.span===`day`?r(`triggerTodayTokens`):g.span===`week`?r(`triggerWeekTokens`):r(`triggerMonthTokens`):g.span===`day`?r(`triggerToday`):g.span===`week`?r(`weekCost`):r(`triggerMonth`)}),(()=>{let e=g.span===`day`?se?v:o:g.span===`week`?se?b:s:se?_:a,n=g.span===`day`?S:0;return se?(0,m.jsx)(`span`,{className:z.triggerMetric,"data-testid":`billing-trigger-span-tokens`,children:q(e)}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`span`,{className:z.triggerValueRow,children:[(0,m.jsx)(`span`,{className:z.triggerYen,"aria-hidden":`true`,children:t(e).charAt(0)}),(0,m.jsx)(`span`,{className:z.triggerMetric,"data-testid":`billing-trigger-span-money`,children:t(e).slice(1)})]}),g.showDelta&&n!==0&&(0,m.jsxs)(`span`,{className:y(z.triggerDelta,n>0?z.triggerDeltaUp:z.triggerDeltaDown),"data-testid":`billing-trigger-delta`,children:[n>0?`▲`:`▼`,` `,Math.abs(n).toFixed(1),`%`]}),(0,m.jsx)(`span`,{className:z.triggerGlow,"aria-hidden":`true`})]})})()]})}),(0,m.jsx)(`span`,{className:z.triggerSpark,"data-testid":`billing-trigger-spark`,"aria-hidden":`true`,children:ue.map((e,t)=>(0,m.jsx)(`span`,{className:t===ue.length-1?z.triggerSparkHot:z.triggerSparkBar,style:{height:`${e}px`}},c[t]?.date??String(t)))})]}),(0,f.createPortal)((0,m.jsx)(`span`,{className:y(z.triggerPop,O&&z.triggerPopShown),style:{left:`${A.left}px`,top:`${A.top}px`},"data-testid":`billing-trigger-pop`,"aria-hidden":!O,onMouseEnter:te,onMouseLeave:ne,children:p.mode===`subscription`?(0,m.jsx)(m.Fragment,{children:C.length===0?(0,m.jsx)(`span`,{className:z.triggerPopEmpty,children:r(`floatNoTargets`)}):(0,m.jsxs)(m.Fragment,{children:[E!==void 0&&(0,m.jsxs)(`div`,{className:z.floatSub,"data-testid":`billing-float-subscription`,children:[(0,m.jsxs)(`div`,{className:z.floatSubHead,children:[(0,m.jsx)(`span`,{className:z.floatSubName,children:E.displayName}),E.plan!==void 0&&(0,m.jsx)(`span`,{className:z.floatSubPlan,children:E.plan})]}),E.windows.map(e=>(0,m.jsx)(na,{window:e,t:r},e.kind))]}),C.length>1&&(0,m.jsx)(`span`,{className:z.triggerPopSwitcher,"data-testid":`billing-float-switcher`,children:(0,m.jsxs)(`span`,{className:z.triggerPopSwitchCount,children:[ee+1,`/`,C.length]})})]})}):(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:z.popHead,children:(0,m.jsx)(`span`,{className:z.popTitle,children:r(`popTitle`)})}),(0,m.jsxs)(`span`,{className:z.metricGrid,children:[(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`floatPrimaryToday`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:t(o)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`floatPrimaryWeek`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:t(s)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`floatPrimaryMonth`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:t(a)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`input`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:q(u.input)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`output`)}),(0,m.jsx)(`span`,{className:z.metricValue,children:q(u.output)})]}),(0,m.jsxs)(`span`,{className:z.metricCell,children:[(0,m.jsx)(`span`,{className:z.metricLabel,children:r(`cacheHit`)}),(0,m.jsx)(`span`,{className:y(z.metricValue,z.metricValueSuccess),children:mn(u.cacheRead+u.cacheMiss>0?u.cacheRead/(u.cacheRead+u.cacheMiss)*100:0)})]})]}),(0,m.jsxs)(`span`,{className:z.popModel,children:[(0,m.jsx)(`span`,{className:z.popModelLabel,children:r(`popTodayModel`)}),l.direct!==void 0||l.sub!==void 0?(0,m.jsxs)(m.Fragment,{children:[l.direct!==void 0&&(0,m.jsxs)(`span`,{className:z.popModelRow,children:[(0,m.jsx)(`span`,{className:y(z.popDot,z.popDotDirect),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:z.popTagPrimary,children:r(`popDirectLead`)}),(0,m.jsx)(`span`,{className:z.popModelName,children:l.direct.name}),(0,m.jsx)(`span`,{className:y(z.popModelStatus,l.direct.low&&z.popModelStatusLow),children:l.direct.text})]}),l.sub!==void 0&&(0,m.jsxs)(`span`,{className:z.popModelRow,children:[(0,m.jsx)(`span`,{className:y(z.popDot,z.popDotSub),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:z.popTagSub,children:r(`popSubLead`)}),(0,m.jsx)(`span`,{className:z.popModelName,children:l.sub.name}),(0,m.jsx)(`span`,{className:y(z.popModelStatus,l.sub.low&&z.popModelStatusLow),children:l.sub.text})]})]}):(0,m.jsxs)(`span`,{className:z.popModelRow,children:[(0,m.jsx)(`span`,{className:y(z.popDot,z.popDotNeutral),"aria-hidden":`true`}),(0,m.jsx)(`span`,{className:z.popModelStatus,children:r(`popNoConsumption`)})]})]})]})}),document.body)]})}function oa({balance:e,days:t,dailyBurn:n,money:r,t:i,onClose:a}){let o=t=>t===void 0?void 0:e.currency===`USD`?`$${t.toFixed(2)}`:r(t),s=o(e.totalBalance),c=o(e.grantedBalance),l=o(e.toppedUpBalance);return(0,m.jsxs)(`span`,{className:z.balanceDetailPop,"data-testid":`billing-balance-detail-pop`,onClick:e=>{e.stopPropagation()},children:[(0,m.jsxs)(`span`,{className:z.balanceDetailHead,children:[(0,m.jsx)(`span`,{className:z.balanceDetailTitle,children:e.displayName}),(0,m.jsx)(`button`,{type:`button`,className:z.balanceDetailClose,"aria-label":i(`close`),onClick:a,children:`×`})]}),(0,m.jsxs)(`span`,{className:z.balanceDetailGrid,children:[s!==void 0&&(0,m.jsx)(sa,{label:i(`balance`),value:s}),c!==void 0&&(0,m.jsx)(sa,{label:i(`balanceGranted`),value:c}),l!==void 0&&(0,m.jsx)(sa,{label:i(`balanceTopped`),value:l}),(0,m.jsx)(sa,{label:i(`balanceDaily`),value:r(n)}),(0,m.jsx)(sa,{label:i(`balanceDaysLong`),value:`${t} ${i(`balanceDaysUnit`)}`})]})]})}function sa({label:e,value:t}){return(0,m.jsxs)(`span`,{className:z.balanceDetailRow,children:[(0,m.jsx)(`span`,{className:z.balanceDetailLabel,children:e}),(0,m.jsx)(`span`,{className:z.balanceDetailValue,children:t})]})}function ca({userPrices:e,onUserPrices:t,t:n}){let[r,i]=(0,d.useState)(()=>[...e]),[a,o]=(0,d.useState)(new Set),s=e=>o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),c=()=>{i(e=>e.filter((e,t)=>!a.has(t))),o(new Set)},l=(e,t)=>i(n=>n.map((n,r)=>r===e?{...n,...t}:n)),u=()=>i(e=>[...e,{key:``,input:0,cacheHit:0,output:0}]),f=e=>{let t=r[e]?.offPeak;return{input:t===void 0?``:String(t.input),cacheHit:t===void 0?``:String(t.cacheHit),output:t===void 0?``:String(t.output)}},p=(e,t,n)=>i(r=>r.map((r,i)=>{if(i!==e)return r;let a=r.offPeak,o={input:a===void 0?``:String(a.input),cacheHit:a===void 0?``:String(a.cacheHit),output:a===void 0?``:String(a.output),[t]:n},s=[o.input,o.cacheHit,o.output].some(e=>e.trim()!==``),c=[o.input,o.cacheHit,o.output].map(e=>Number(e)),l=s&&c.every(e=>Number.isFinite(e)&&e>=0)&&c.some(e=>e>0),{offPeak:u,...d}=r;return l?{...d,offPeak:{input:c[0]??0,cacheHit:c[1]??0,output:c[2]??0}}:d})),h=()=>t(r.filter(e=>e.key.trim()!==``).map(e=>({...e,key:e.key.trim(),...e.origin===void 0||e.origin.trim()===``?{}:{origin:ut(e.origin.trim())}}))),g=on().map(e=>e.key),_=(e,t)=>i(n=>n.map((n,r)=>{if(r!==e)return n;let{currency:i,...a}=n;return t===`USD`?{...a,currency:`USD`}:a})),[v,b]=(0,d.useState)({}),x=(e,t,n)=>`${e}:${t}:${n}`,S=(e,t,n)=>b(r=>{let i=x(e,t,n);if(r[i]===void 0)return r;let a={...r};return delete a[i],a}),C=e=>Number.isFinite(e)&&e!==0?String(e):``,w=(e,t,n)=>{if(b(r=>({...r,[x(e,`main`,t)]:n})),n===``){l(e,{[t]:0});return}let r=Number(n);Number.isFinite(r)&&r>=0&&l(e,{[t]:r})};return(0,m.jsxs)(`section`,{className:z.setCard,"data-testid":`billing-user-prices`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[n(`userPrices`),(0,m.jsx)(ra,{label:n(`userPricesHint`),t:n})]})})}),(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsx)(`datalist`,{id:`billing-price-model-keys`,children:g.map(e=>(0,m.jsx)(`option`,{value:e},e))}),r.map((e,t)=>(0,m.jsxs)(`div`,{className:z.userPriceRow,"data-testid":`billing-user-price-row`,children:[(0,m.jsx)(`input`,{type:`checkbox`,className:z.userPriceCheck,"data-testid":`billing-user-price-select`,checked:a.has(t),"aria-label":n(`userPriceSelect`),onChange:()=>s(t)}),(0,m.jsxs)(`div`,{className:z.userPriceBody,children:[(0,m.jsxs)(`div`,{className:z.userPriceLineMeta,children:[(0,m.jsxs)(`div`,{className:z.userPriceField,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:n(`userPriceModel`)}),(0,m.jsx)(`input`,{className:z.userPriceInput,"data-testid":`billing-user-price-model`,type:`text`,list:`billing-price-model-keys`,value:e.key,placeholder:`flash`,"aria-label":n(`userPriceModel`),onChange:e=>l(t,{key:e.target.value})})]}),(0,m.jsxs)(`div`,{className:z.userPriceField,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:n(`userPriceSource`)}),(0,m.jsx)(`input`,{className:z.userPriceInput,"data-testid":`billing-user-price-origin`,type:`text`,value:e.origin??``,placeholder:n(`userPriceSourceHint`),"aria-label":n(`userPriceSource`),onChange:e=>l(t,{origin:e.target.value.trim()})})]}),(0,m.jsxs)(`div`,{className:z.userPriceField,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:n(`userPriceCurrency`)}),(0,m.jsxs)(`div`,{className:z.ctlGroup,children:[(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,e.currency!==`USD`&&z.floatModeBtnOn),onClick:()=>_(t,`CNY`),children:`CNY`}),(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,e.currency===`USD`&&z.floatModeBtnOn),onClick:()=>_(t,`USD`),children:`USD`})]})]})]}),[{scope:`main`,label:n(`userPriceNormal`),testid:`billing-user-price-normal`,valueOf:n=>v[x(t,`main`,n)]??C(e[n]),onChange:(e,n)=>w(t,e,n)},{scope:`off`,label:n(`userPriceOffPeak`),testid:`billing-user-price-offpeak`,valueOf:e=>v[x(t,`off`,e)]??f(t)[e],onChange:(e,n)=>{b(r=>({...r,[x(t,`off`,e)]:n})),p(t,e,n)}}].map(e=>(0,m.jsxs)(`div`,{className:z.userPricePriceLine,"data-testid":e.testid,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:e.label}),[`input`,`cacheHit`,`output`].map(r=>{let i=n(r===`input`?`tokenMiss`:r===`cacheHit`?`tokenHit`:`tokenOutput`);return(0,m.jsx)(`input`,{className:z.userPriceInputNum,type:`number`,min:0,step:.01,placeholder:i,"aria-label":`${e.label} ${i}`,value:e.valueOf(r),onChange:t=>e.onChange(r,t.target.value),onBlur:()=>S(t,e.scope,r)},r)})]},e.testid))]})]},t)),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-user-price-add`,onClick:u,children:n(`userPriceAdd`)}),(0,m.jsxs)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-user-price-remove-selected`,disabled:a.size===0,onClick:c,children:[n(`userPriceRemoveSelected`),a.size>0?` (${a.size})`:``]}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-user-price-save`,onClick:h,children:n(`userPriceSave`)})]})]})]})}function la({stats:e,t,onClose:n,embeddedSettings:r=!1,userPrices:i,onUserPrices:a,health:o,balances:s,reconcile:c,quotas:l,relayQuotas:u,currency:f,onCurrency:h,language:g,onLanguage:_,turns:v,renderSlot:b,budgetEnabled:x,budgetAmount:S,onToggleBudget:C,onBudgetAmount:w,modelBudgets:T,monthModelCost:ee,onModelBudget:E,peakConfig:D,onPeakConfig:O,onPreviewPeak:k,floatPrefs:A,onFloatPrefs:j,cardPrefs:M,onCardPrefs:te,recoveryEntryAvailable:ne,sitePrefs:N,onSitePrefs:re,liveCostPrefs:oe,onLiveCostPrefs:se,quickQueuePrefs:ue,onQuickQueuePrefs:de,quotasStale:fe,balanceStale:pe,navigateToSession:me}){let he=(0,d.useRef)(null),ge=(0,d.useMemo)(()=>Ci(e.bySession??[]),[e.bySession]),_e=(0,d.useMemo)(()=>Ti(ge),[ge]),[ve,ye]=(0,d.useState)(void 0),be=(0,d.useCallback)(e=>{let n=me(e);if(n===`opened`){ye(void 0);return}ye(t(n===`unavailable`?`sessionOpenUnavailable`:`sessionOpenFailed`))},[me,t]),[xe,Se]=(0,d.useState)(`cost`),{total:Ce,byModel:we,byDay:P}=e,[F,Oe]=(0,d.useState)(r?`settings`:`overview`),[je,Me]=(0,d.useState)(7),[Ne,I]=(0,d.useState)(()=>{try{return window.localStorage.getItem(`dsh-billing:reconcile-dismissed`)??``}catch{return``}}),Fe=()=>{let e=new Date,t=e=>String(e).padStart(2,`0`);return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}`},Ie=(0,d.useCallback)(()=>{let e=Fe();I(e);try{window.localStorage.setItem(`dsh-billing:reconcile-dismissed`,e)}catch{}},[]),[Le,L]=(0,d.useState)(()=>{let e=[`unpriced`,`search-estimate`,`unreadable`],t=new Set,n=new Date,r=e=>String(e).padStart(2,`0`),i=`${n.getFullYear()}-${r(n.getMonth()+1)}-${r(n.getDate())}`;try{for(let n of e)window.localStorage.getItem(`dsh-billing:notice-${n}-dismissed`)===i&&t.add(n)}catch{}return t}),Re=(0,d.useCallback)(e=>{let t=Fe();L(t=>new Set(t).add(e));try{window.localStorage.setItem(`dsh-billing:notice-${e}-dismissed`,t)}catch{}},[]),[ze,Be]=(0,d.useState)(`month`),[We,qe]=(0,d.useState)(`cost`),[Je,Ye]=(0,d.useState)(He),[Xe,Ze]=(0,d.useState)(R),[Qe,$e]=(0,d.useState)(`budget`),[et,tt]=(0,d.useState)(``),nt=e=>Di(et,e);(0,d.useEffect)(()=>{let e=he.current;if(F!==`settings`||e===null||typeof IntersectionObserver>`u`)return;let t=Array.from(e.querySelectorAll(`[id^="settings-"]`)).filter(e=>!e.closest(`[hidden]`));if(t.length===0)return;let n=new IntersectionObserver(e=>{let t,n=1/0;for(let r of e){if(!r.isIntersecting)continue;let e=r.boundingClientRect.top;e<n&&(n=e,t=r.target.id)}t!==void 0&&$e(t.slice(9))},{rootMargin:`-80px 0px -55% 0px`});for(let e of t)n.observe(e);return()=>{n.disconnect()}},[F]);let rt=(0,d.useCallback)(e=>{$e(e);let t=he.current?.querySelector(`[id="settings-${e}"]`);if(t==null)return;if(r){t.scrollIntoView({block:`start`,behavior:`smooth`});return}let n=t.closest(`.${z.dashboardBody}`);if(n===null)return;let i=t.getBoundingClientRect().top-n.getBoundingClientRect().top;n.scrollTo({top:n.scrollTop+i,behavior:`smooth`})},[r]),it=(0,d.useCallback)(e=>{Ye(e),Ue(e)},[]),ot=(0,d.useCallback)(e=>{Ze(e),Ke(e)},[]);(0,d.useEffect)(()=>{typeof document>`u`||(document.documentElement.dataset.density=Je,document.documentElement.dataset.motion=Xe)},[Je,Xe]),(0,d.useEffect)(()=>{if(typeof window>`u`)return;let e=e=>{let t=e.detail;t?.density!==void 0&&Ye(t.density)},t=e=>{let t=e.detail;t?.motion!==void 0&&Ze(t.motion)};return window.addEventListener(Ve,e),window.addEventListener(Ge,t),()=>{window.removeEventListener(Ve,e),window.removeEventListener(Ge,t)}},[]);let[B,st]=(0,d.useState)(ie),[V,ct]=(0,d.useState)(ce),H=e=>{let t={...V,...e};t.start!==``&&t.end!==``&&(t.start>t.end&&(e.start===void 0?t.start=t.end:t.end=t.start),ct(t),le(t))},lt=(0,d.useMemo)(()=>l.filter(e=>e.status===`ok`&&e.windows.length>0).map(e=>({id:e.provider,label:e.displayName})),[l]),[ut,dt]=(0,d.useState)(),[ft,pt]=(0,d.useState)(new Set),[mt,ht]=(0,d.useState)(!1),[gt,_t]=(0,d.useState)(``),vt=(0,d.useCallback)(e=>{pt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),yt=(0,d.useMemo)(()=>Si(e.bySession??[]),[e.bySession]),bt=e=>(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`td`,{className:z.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:z.numCol,children:W(e.cost)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.lastActive>0?`${K(e.lastActive)} ${Fi(e.lastActive)}`:`—`})]}),xt=(e,n)=>(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{className:y(z.sessionChildRow,n>0&&z.sessionSubDeepRow),"data-testid":`billing-session-sub-row`,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),children:t(`sessionSubRow`)}),(e.subCalls??0)>0&&(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),"data-testid":`billing-session-sub-chain`,children:e.subCost!==void 0&&e.subCost>0?t(`sessionSubCost`).replace(`{cost}`,W(e.subCost)):t(`sessionSubCalls`).replace(`{calls}`,(e.subCalls??0).toLocaleString())}),(0,m.jsx)(`span`,{className:z.modelProvider,children:e.title??e.id.slice(0,8)})]}),bt(e)]}),e.subs?.map(e=>xt(e,n+1))]},e.id),Ct=(0,d.useMemo)(()=>Ei(e.bySession??[],gt),[e.bySession,gt]),wt=(0,d.useMemo)(()=>[...new Set([...Object.keys(ee),...Object.keys(T)])].map(e=>{let t=tn(e);return{key:e,name:t.key===`other`?void 0:t.name,cost:ee[e]??0}}).sort((e,t)=>t.cost-e.cost),[ee,T]),[Tt,Et]=(0,d.useState)(()=>new Set(Ee())),Dt=(0,d.useCallback)(e=>{Et(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),De([...n]),n})},[]),[U,Ot]=(0,d.useState)(()=>ke()),kt=(0,d.useCallback)(()=>{Ot(e=>{let t=!e;return Ae(t),t})},[]),[At,jt]=(0,d.useState)(!1);(0,d.useEffect)(()=>{let e=!0;return Bi().then(t=>{e&&t!==void 0&&jt(t)}),()=>{e=!1}},[]);let Mt=(0,d.useCallback)(()=>{let e=!At;jt(e),Vi(e).then(t=>{t||jt(!e)})},[At]),Nt=St(),[It,Lt]=(0,d.useState)(!1),Rt=(0,d.useCallback)(()=>{It||(Lt(!0),Gi().finally(()=>{Lt(!1)}))},[It]),zt=Ui,W=e=>dn(un(e,f),f),Bt=f===`usd`?`$`:f===`eur`?`€`:`¥`,Vt=g,Ht=e=>fr(e,Vt),[G,Ut]=(0,d.useState)(``),[Wt,Gt]=(0,d.useState)(()=>Te()),[Kt,qt]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{let e=setInterval(()=>{qt(Date.now())},3e4);return()=>{clearInterval(e)}},[]);let Jt=l.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`),Yt=D.leadMin*6e4,Xt=(e,n)=>e===0?t(`free`):fn(pn(e,n,f,Nt.rate),f===`usd`?`USD`:f===`eur`?`EUR`:`CNY`),Zt=(0,d.useMemo)(()=>rr([...v].reverse()),[v]),Qt={peak:e.byTier?.peak.cost??0,offPeak:e.byTier?.offPeak.cost??0},$t=Qt.peak/2,en=Rr(P,K()),nn=e=>s.find(t=>Q(t.provider)===Q(e)),an=e=>e.balance?.error===`unconfigured`&&e.models.length>0&&e.models.every(e=>e.plan),sn=e=>{if(e===void 0)return(0,m.jsx)(`span`,{className:z.na,children:`—`});if(e.error===`unconfigured`)return t(`balanceUnconfigured`);if(e.error===`unauthorized`)return t(`balanceUnauthorized`);if(e.error===`unreachable`)return t(`balanceUnreachable`);if(e.totalBalance===void 0)return(0,m.jsx)(`span`,{className:z.na,children:`—`});let n=e.currency===`USD`?`$${e.totalBalance.toFixed(2)}`:W(e.totalBalance),r=e.currency===`USD`?e.totalBalance*Nt.rate:e.totalBalance,i=en>0?Math.floor(r/en):void 0;return(0,m.jsxs)(`span`,{className:z.balanceCell,children:[(0,m.jsx)(`span`,{children:n}),i!==void 0&&i>=0&&(0,m.jsx)(`button`,{type:`button`,className:y(z.balanceDaysBadge,i<=3&&z.balanceDaysBadgeLow),"data-testid":`billing-balance-days-badge`,title:t(`balanceDays`).replace(`{days}`,String(i)),"aria-label":`${e.displayName} ${t(`balanceDays`).replace(`{days}`,String(i))}`,onClick:t=>{t.stopPropagation(),dt(ut===e.provider?void 0:e.provider)},children:`?`}),ut===e.provider&&(0,m.jsx)(oa,{balance:e,days:i??0,dailyBurn:en,money:W,t,onClose:()=>{dt(void 0)}})]})},ln=Object.keys(P).sort(),hn=K(),gn=P[hn]?.cost??0,_n=hn.slice(0,7),bn=hn.slice(0,4),J=ln.reduce((e,t)=>e+(t.startsWith(_n)?P[t]?.cost??0:0),0),Tn=ln.reduce((e,t)=>e+(t.startsWith(bn)?P[t]?.cost??0:0),0),En=(0,d.useMemo)(()=>Br(P,_n,hn)+l.reduce((e,t)=>e+(t.planType===`code`?t.subscriptionAmount??0:0),0),[P,_n,hn,l]),Dn=(0,d.useMemo)(()=>{if(!(x&&S>0))return null;let e=S-J;return{over:e<=0,remainRatio:Math.max(0,Math.min(1,e/S)),remainCny:Math.max(0,e)}},[x,S,J]),On=(0,d.useMemo)(()=>{let e=[];for(let t=je-1;t>=0;--t){let n=new Date;n.setDate(n.getDate()-t),e.push(K(n.getTime()))}return e},[je]),An=On.at(-1)??hn,jn=(0,d.useMemo)(()=>Object.entries(P).map(([e,t])=>({date:e,value:We===`tokens`?Ur(t):t.cost})),[P,We]),Y=(0,d.useMemo)(()=>jn.reduce((e,t)=>e+t.value,0),[jn]),Mn=Vr(P),Nn=Hr(P),Pn=(0,d.useMemo)(()=>On.map(t=>{let n={},r=e.byDayModels?.[t];if(r!==void 0)for(let[e,t]of Object.entries(r))t.cost>0&&(n[e]=t.cost);let i=P[t];return{date:t,cost:i?.cost??0,calls:i?.calls??0,byModel:n,tokens:i===void 0?0:Ur(i)}}),[On,P,e.byDayModels]),X=(0,d.useMemo)(()=>Object.entries(we).filter(([,e])=>e.calls>0).map(([e,t])=>{let n=tn(e),r=n.key===`other`,i=r?ti(e):void 0,a={input:t.input,cacheHit:t.cacheHit,cacheMiss:t.cacheMiss,output:t.output};return{key:e,name:r?e:n.name,provider:i??n.provider,calls:t.calls,input:t.input,output:t.output,cacheHitRate:t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0,estimated:cn(n,a),plan:t.plan===!0,...t.cost>0?{actual:t.cost}:{},uncatalogued:r,estimatedPricing:n.estimated===!0,officialCalls:t.officialCalls??0,officialCost:t.officialCost??0}}).sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated)).map((e,t)=>({...e,color:jr[t%jr.length]??`#8b95a3`})),[we]),In=(0,d.useMemo)(()=>N.hideUnidentified?u.filter(e=>e.kind!==`unknown`):u,[u,N.hideUnidentified]),Ln=(0,d.useMemo)(()=>{let n=e.byDayModelsSite;if(U){let t=K();n={[t]:e.byDayModelsSite?.[t]??{}}}let r=new Map;for(let t of Object.values(n??{}))for(let[n,i]of Object.entries(t))for(let[t,a]of Object.entries(i)){let i=r.get(t);i===void 0&&(i=new Map,r.set(t,i));let o=i.get(n)??{calls:0,input:0,output:0,cacheHit:0,cacheMiss:0,cost:0,allPlan:!0};o.calls+=a.calls,o.input+=a.input,o.output+=a.output,o.cacheHit+=a.cacheHit,o.cacheMiss+=a.cacheMiss,o.cost+=a.cost,o.allPlan=o.allPlan&&(a.plan??e.byModel?.[n]?.plan===!0),i.set(n,o)}let i=new Map;for(let[e,t]of r){let n=!e.startsWith(`direct:`)&&!e.startsWith(`site:`),r=[...t.entries()].filter(([,e])=>e.calls>0).map(([e,t],r)=>{let i=tn(e),a=i.key===`other`,o=a?ti(e)??i.provider:i.provider;return{key:e,name:a?e:i.name,provider:o,color:jr[r%jr.length]??`#8b95a3`,calls:t.calls,input:t.input,output:t.output,cacheHitRate:t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0,estimated:n?0:cn(i,{input:t.input,cacheHit:t.cacheHit,cacheMiss:t.cacheMiss,output:t.output}),plan:t.allPlan,...t.cost>0?{actual:t.cost}:{},uncatalogued:a,estimatedPricing:i.estimated===!0,officialCalls:0,officialCost:0}}).sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated));r.length>0&&i.set(e,r)}let a=e=>_r(e,Vt)??t(`channelUnknown`),c=new Map,u=new Map,d=new Map,f=e=>e.startsWith(`direct:`)?`direct`:e.startsWith(`site:`)?`site`:`unknown`,p={direct:2,site:1,unknown:0,vendor:0};for(let[e,t]of i){let n=a(e),r=c.get(n);if(r===void 0)c.set(n,[...t]),u.set(n,f(e)),d.set(n,e);else{r.push(...t),r.sort((e,t)=>(t.actual??t.estimated)-(e.actual??e.estimated));let i=u.get(n)??`unknown`,a=f(e);p[a]>p[i]&&(u.set(n,a),d.set(n,e))}}let m=new Map,h=new Map;for(let e of l){if(e.status===`not-configured`)continue;let t=e.displayName??ri(e.provider),n=a(`direct:${e.provider}`),r=c.has(t)?t:c.has(n)?n:void 0,i=r??`sub:${ri(e.provider)}`;h.set(i,r??ri(e.provider));let o=m.get(i);o===void 0?m.set(i,[e]):o.push(e)}let g=e=>e===a(`direct:deepseek`)||e===a(`site:https://api.deepseek.com`)?nn(`deepseek`)??nn(e):nn(e),_=[];for(let[e,t]of c)_.push({id:`ch:${d.get(e)??e}`,name:e,models:t,subscriptions:m.get(e)??[],balance:g(e),dot:Oi(o,t[0]?.provider??``),channelKind:u.get(e)??`unknown`});for(let[e,t]of h)c.has(e)||_.push({id:e,name:t,models:[],subscriptions:m.get(e)??[],balance:nn(t),dot:Oi(o,t),channelKind:`vendor`});let v=new Set(_.flatMap(e=>[Q(e.name),...e.balance===void 0?[]:[Q(e.balance.provider)]]));for(let e of s)v.has(Q(e.provider))||(e.error===void 0||e.provider.startsWith(`custom:`))&&_.push({id:`bal:${e.provider}`,name:e.displayName,models:[],subscriptions:[],balance:e,dot:Oi(o,e.displayName),channelKind:`vendor`});return _.filter(e=>N.hideUnidentified&&e.channelKind===`unknown`?!1:!U||e.models.length>0).sort((e,t)=>{let n=Ni(t)-Ni(e);return n===0?e.models.length===0&&t.models.length===0?0:t.models.length===0?-1:e.models.length===0?1:e.name.localeCompare(t.name,`zh`):n})},[e.byDayModelsSite,e.byModel,l,s,o,Vt,t,U,N.hideUnidentified]),Rn=(0,d.useMemo)(()=>Ln.filter(e=>e.models.length>0||e.subscriptions.length>0).map(e=>e.id),[Ln]),zn=Rn.length>0&&Rn.every(e=>Tt.has(e)),Bn=()=>{let e=new Set(zn?[]:Rn);Et(e),De([...e])},Hn=(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`model`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`inputTokens`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`outputTokens`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`cacheHitRate`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`actual`)})]})}),Un=e=>(0,m.jsx)(`span`,{className:z.modelCell,children:(0,m.jsxs)(`span`,{children:[(0,m.jsxs)(`span`,{className:z.modelName,children:[e.name,e.uncatalogued&&(0,m.jsx)(`span`,{className:z.uncataloguedTag,"data-testid":`billing-uncatalogued-tag`,children:t(`uncatalogued`)}),e.estimatedPricing&&(0,m.jsx)(`span`,{className:z.estimatedTag,"data-testid":`billing-estimated-tag`,children:t(`estimatedPricing`)})]}),(0,m.jsx)(`span`,{className:z.modelProvider,children:Ht(e.provider)})]})}),Gn=e.bySite?.unknown?.calls??0,Kn=X.reduce((e,t)=>e+t.estimated,0),qn=Ce.cost>0||Gn>0?Ce.cost:Kn,Z=(0,d.useMemo)(()=>{if(B===`all`){let e,t=0;for(let[n,r]of Object.entries(P)){let i=Ur(r);i>t&&(t=i,e=n)}return{cost:qn,calls:Ce.calls,input:Ce.input,output:Ce.output,cacheHit:Ce.cacheHit,cacheMiss:Ce.cacheMiss,cacheWrite:Ce.cacheWrite??0,reasoning:Ce.reasoning??0,peakDay:e,peakTokens:t}}return B===`custom`?qr(P,V.start,V.end):Kr(P,K(),B)},[B,V,qn,Ce,P]),Yn=B===`custom`?V.start===V.end?V.start:`${V.start} – ${V.end}`:t({today:`avgRangeToday`,"7d":`avgRange7d`,week:`avgRangeWeek`,month:`avgRangeMonth`,all:`avgRangeAll`}[B]),Xn=(0,d.useMemo)(()=>X.map(e=>({key:e.key,name:e.name,color:e.color})),[X]),Zn=Pn.length>=2?Pn.at(-2)?.cost??0:0,Qn=Zn>0?(gn-Zn)/Zn*100:0,er=(0,m.jsxs)(`div`,{ref:he,className:y(z.dashboard,r&&z.nativeSettingsDashboard),"data-testid":r?`native-billing-settings-dashboard`:`billing-dashboard`,children:[!r&&(0,m.jsxs)(`div`,{className:z.dashboardHead,"data-testid":`billing-dashboard-head`,children:[(0,m.jsxs)(`div`,{children:[b(`billing.dashboard.decor`,{position:`head`}),(0,m.jsxs)(`div`,{children:[(0,m.jsx)(`h2`,{className:z.dashboardTitle,children:t(`title`)}),b(`billing.dashboard.decor`,{position:`headTitle`})]}),(0,m.jsxs)(`p`,{className:z.dashboardSubtitle,children:[t(`lastUpdated`),` `,An,e.timezone===void 0?null:` · ${e.timezone.name} (${e.timezone.offset})`]})]}),(0,m.jsxs)(`div`,{className:z.dashboardRight,children:[(0,m.jsx)(`span`,{className:z.currencyToggle,role:`group`,"aria-label":t(`language`),children:[`en`,`zh`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.currencyButton,g===e&&z.currencyButtonActive),"aria-pressed":g===e,"data-testid":`billing-language-${e}`,onClick:()=>{_(e)},children:e===`en`?`EN`:`中`},e))}),(0,m.jsx)(`span`,{className:z.currencyToggle,role:`group`,"aria-label":t(`currency`),children:[`cny`,`usd`,`eur`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.currencyButton,f===e&&z.currencyButtonActive),"aria-pressed":f===e,"data-testid":`billing-currency-${e}`,title:t(e===`cny`?`currencyCny`:e===`usd`?`currencyUsd`:`currencyEur`),onClick:()=>{h(e)},children:e===`cny`?`¥ CNY`:e===`usd`?`$ USD`:`€ EUR`},e))}),o.checked&&(0,m.jsxs)(`span`,{className:y(z.healthBadge,o.available?z.healthBadgeOk:z.healthBadgeBad),children:[(0,m.jsx)(`span`,{className:y(z.healthDot,o.available?z.healthOk:z.healthBad),role:`img`,"aria-label":o.available?t(`healthDotLive`):t(`healthDotFailed`),title:o.available?t(`healthDotLive`):t(`healthDotFailed`)}),o.available?`${t(`healthModelsLive`).replace(`{n}`,String(o.models))}${o.failures>0?` · ${t(`healthVendorsDown`).replace(`{n}`,String(o.failures))}`:``}`:t(`healthVendorsUnavailable`).replace(`{n}`,String(o.failures))]}),(0,m.jsx)(`button`,{type:`button`,className:z.closeButton,"aria-label":t(`close`),"data-testid":`billing-close`,onClick:n,children:(0,m.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,"aria-hidden":`true`,children:[(0,m.jsx)(`path`,{d:`M18 6 6 18`}),(0,m.jsx)(`path`,{d:`m6 6 12 12`})]})})]})]}),!r&&e.staleSnapshot===!0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-stale-snapshot`,children:t(`staleSnapshotNotice`)}),!r&&(0,m.jsx)(`nav`,{className:z.tabNav,"data-testid":`billing-tab-nav`,role:`tablist`,"aria-label":t(`title`),children:Nr.map(e=>(0,m.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":F===e.id,"aria-controls":`billing-tab-panel-${e.id}`,className:y(z.tabButton,F===e.id&&z.tabButtonActive),"data-testid":`billing-tab-${e.id}`,onClick:()=>{Oe(e.id)},children:[(0,m.jsx)(`span`,{className:z.tabRailIcon,"aria-hidden":`true`,children:Fr[e.id]}),(0,m.jsx)(`span`,{className:z.tabNavLabel,children:t(e.labelKey)})]},e.id))}),(0,m.jsxs)(`div`,{className:y(z.dashboardBody,r&&z.nativeSettingsBody),children:[F===`queue`&&(0,m.jsx)(ta,{t,language:g,navigateToSession:me}),F===`overview`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-overview`,children:[c?.kind===`drift`&&c.spent!==void 0&&Ne!==Fe()&&(0,m.jsxs)(`div`,{className:z.reconcileNotice,"data-testid":`billing-reconcile-notice`,role:`note`,children:[(0,m.jsx)(`span`,{className:z.reconcileIcon,"aria-hidden":`true`,children:(0,m.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,m.jsx)(`line`,{x1:`12`,y1:`10`,x2:`12`,y2:`16`}),(0,m.jsx)(`line`,{x1:`12`,y1:`7.5`,x2:`12.01`,y2:`7.5`})]})}),(0,m.jsx)(`span`,{className:z.reconcileText,children:t(`reconcileDrift`).replace(`{provider}`,c.provider??``).replace(`{spent}`,W(c.spent)).replace(`{today}`,W(c.todayOfficialCost??0))}),(0,m.jsx)(`button`,{type:`button`,className:z.reconcileDismiss,"data-testid":`billing-reconcile-dismiss`,onClick:Ie,children:t(`reconcileDismiss`)})]}),pe===!0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-balance-stale`,children:t(`balanceStaleNotice`)}),(0,m.jsxs)(`section`,{className:z.hero,"data-testid":`billing-hero`,children:[b(`billing.dashboard.decor`,{position:`hero`}),(0,m.jsxs)(`div`,{className:z.heroTop,children:[(0,m.jsxs)(`div`,{className:z.heroMain,children:[(0,m.jsx)(`span`,{className:z.heroLabel,"data-testid":`billing-hero-range-label`,children:Yn}),(0,m.jsxs)(`div`,{className:z.heroReadout,children:[(0,m.jsx)(`span`,{className:z.heroCurrency,"aria-hidden":`true`,children:Bt}),(0,m.jsx)(`span`,{className:z.heroValue,"data-testid":`billing-hero-range-value`,children:W(Z.cost).slice(1)})]}),(0,m.jsxs)(`span`,{className:z.heroMeta,children:[Z.calls.toLocaleString(),` `,t(`calls`),B===`month`&&En>0&&(0,m.jsxs)(`span`,{className:z.heroPred,children:[` `,t(`monthProjected`),` `,W(En)]})]})]}),Dn!==null&&(0,m.jsxs)(`div`,{className:z.heroGauge,"data-testid":`billing-hero-gauge`,children:[(0,m.jsxs)(`div`,{className:z.heroGaugeDial,children:[(0,m.jsxs)(`svg`,{className:z.heroGaugeSvg,viewBox:`0 0 120 120`,"aria-hidden":`true`,children:[(0,m.jsx)(`defs`,{children:(0,m.jsxs)(`linearGradient`,{id:`heroRingGrad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,m.jsx)(`stop`,{offset:`0%`,stopColor:`var(--ds-cyan)`}),(0,m.jsx)(`stop`,{offset:`55%`,stopColor:`var(--ds-blue)`}),(0,m.jsx)(`stop`,{offset:`100%`,stopColor:`var(--ds-amber)`})]})}),(0,m.jsx)(`circle`,{className:z.heroGaugeTrack,cx:`60`,cy:`60`,r:`52`}),(0,m.jsx)(`circle`,{className:y(z.heroGaugeArc,Dn.over&&z.heroGaugeArcOver),cx:`60`,cy:`60`,r:`52`,style:{strokeDasharray:`${Dn.remainRatio*326.7} 326.7`},stroke:Dn.over?void 0:`url(#heroRingGrad)`})]}),(0,m.jsxs)(`span`,{className:z.heroGaugeCenter,children:[(0,m.jsxs)(`span`,{className:y(z.heroGaugeRemain,Dn.over&&z.heroGaugeRemainOver),children:[Bt,un(Dn.remainCny,f).toFixed(2)]}),(0,m.jsx)(`span`,{className:z.heroGaugeLabel,children:t(`budgetRemain`)})]})]}),(0,m.jsxs)(`span`,{className:z.heroGaugeSub,children:[W(J),` / `,W(S)]})]})]}),(0,m.jsxs)(`div`,{className:z.heroSide,children:[(0,m.jsxs)(`div`,{className:z.heroSideItem,children:[(0,m.jsx)(`span`,{className:z.heroSideLabel,children:t(`yearCost`)}),(0,m.jsx)(`span`,{className:z.heroSideValue,children:W(Tn)})]}),(0,m.jsxs)(`div`,{className:z.heroSideItem,children:[(0,m.jsx)(`span`,{className:z.heroSideLabel,children:t(`todayCost`)}),(0,m.jsxs)(`span`,{className:z.heroSideValue,children:[W(gn),(0,m.jsxs)(`span`,{className:y(z.delta,Qn>=0?z.deltaUp:z.deltaDown),children:[Qn>=0?`▲`:`▼`,` `,Math.abs(Qn).toFixed(1),`%`]})]})]}),En>0&&(0,m.jsxs)(`div`,{className:z.heroSideItem,title:t(`monthProjectedHint`),children:[(0,m.jsx)(`span`,{className:z.heroSideLabel,children:t(`monthProjected`)}),(0,m.jsx)(`span`,{className:z.heroSideValue,children:W(En)})]}),En<=0&&(0,m.jsx)(`span`,{className:z.heroSideSpacer,"aria-hidden":`true`})]})]}),(e.unpricedModels?.length??0)>0&&!Le.has(`unpriced`)&&(0,m.jsxs)(`div`,{className:z.unpricedHint,"data-testid":`billing-unpriced-hint`,children:[(0,m.jsx)(`span`,{className:z.unpricedHintBody,children:t(`unpricedHint`).replace(`{count}`,String(e.unpricedModels?.length??0))}),(0,m.jsx)(`button`,{type:`button`,className:z.noticeDismiss,"data-testid":`billing-unpriced-dismiss`,"aria-label":t(`close`),onClick:()=>{Re(`unpriced`)},children:`×`})]}),(e.total.searchCalls??0)>0&&!Le.has(`search-estimate`)&&(0,m.jsxs)(`div`,{className:z.unpricedHint,"data-testid":`billing-search-estimate-hint`,children:[(0,m.jsx)(`span`,{className:z.unpricedHintBody,children:t(`searchEstimateHint`).replace(`{count}`,String(e.total.searchCalls??0)).replace(`{each}`,W(e.searchCallEstimateCny??0))}),(0,m.jsx)(`button`,{type:`button`,className:z.noticeDismiss,"data-testid":`billing-search-estimate-dismiss`,"aria-label":t(`close`),onClick:()=>{Re(`search-estimate`)},children:`×`})]}),(e.unreadableSessions??0)>0&&!Le.has(`unreadable`)&&(0,m.jsxs)(`div`,{className:z.staleNotice,"data-testid":`billing-sessions-unreadable`,children:[(0,m.jsxs)(`div`,{className:z.staleNoticeBody,children:[t(`unreadableNotice`).replace(`{count}`,String(e.unreadableSessions)),(e.unreadableNoLedgerSessions??0)>0&&(0,m.jsx)(`div`,{className:z.staleNoticeSub,"data-testid":`billing-sessions-no-ledger`,children:t(`unreadableNoLedgerNotice`).replace(`{count}`,String(e.unreadableNoLedgerSessions))}),(e.unreadableFormatSessions??0)>0&&(0,m.jsx)(`div`,{className:z.staleNoticeSub,"data-testid":`billing-sessions-format-unsupported`,children:t(`unreadableFormatNotice`).replace(`{count}`,String(e.unreadableFormatSessions))})]}),(0,m.jsx)(`button`,{type:`button`,className:z.noticeDismiss,"data-testid":`billing-unreadable-dismiss`,"aria-label":t(`close`),onClick:()=>{Re(`unreadable`)},children:`×`})]}),(0,m.jsxs)(`div`,{className:z.kpiZone,children:[(0,m.jsxs)(`div`,{className:z.kpiZoneHead,children:[(0,m.jsx)(`span`,{className:z.kpiZoneLabel,children:t(`kpiRange`)}),(0,m.jsx)(`div`,{className:z.heatmapRangeSwitch,"data-testid":`billing-kpi-range`,role:`group`,"aria-label":t(`kpiRange`),children:[[`today`,`avgRangeToday`],[`7d`,`avgRange7d`],[`week`,`avgRangeWeek`],[`month`,`avgRangeMonth`],[`all`,`avgRangeAll`],[`custom`,`avgRangeCustom`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(z.heatmapRangeButton,B===e&&z.heatmapRangeButtonActive),"data-testid":`billing-kpi-range-${e}`,"aria-pressed":B===e,onClick:()=>{st(e),ae(e)},children:t(n)},e))})]}),B===`custom`&&(0,m.jsxs)(`div`,{className:z.kpiCustomRange,"data-testid":`billing-kpi-custom-range`,children:[(0,m.jsxs)(`label`,{children:[t(`customRangeStart`),(0,m.jsx)(`input`,{type:`date`,value:V.start,max:K(),"data-testid":`billing-kpi-custom-start`,onChange:e=>{H({start:e.target.value})}})]}),(0,m.jsxs)(`label`,{children:[t(`customRangeEnd`),(0,m.jsx)(`input`,{type:`date`,value:V.end,max:K(),"data-testid":`billing-kpi-custom-end`,onChange:e=>{H({end:e.target.value})}})]})]}),(0,m.jsx)(`section`,{className:z.kpiGrid,"data-testid":`billing-kpi-grid`,children:(()=>{let e=Object.keys(P).sort().slice(-7),n=K(),r=e.indexOf(n),i=(e,t)=>e[t]??0,a=e.map(e=>P[e]?.cost??0),o=e.map(e=>P[e]?.calls??0),s=e.map(e=>{let t=P[e];return t===void 0?0:Ur(t)}),c=e.map(e=>{let t=P[e];return t!==void 0&&t.cacheHit+t.cacheMiss>0?t.cacheHit/(t.cacheHit+t.cacheMiss)*100:0}),l=r>0&&i(a,r-1)>0?(i(a,r)-i(a,r-1))/i(a,r-1)*100:0,u=r>0&&i(o,r-1)>0?(i(o,r)-i(o,r-1))/i(o,r-1)*100:0,d=r>0&&i(s,r-1)>0?(i(s,r)-i(s,r-1))/i(s,r-1)*100:0,f=r>0&&i(c,r-1)>0?i(c,r)-i(c,r-1):0,h=(e,t)=>B===`custom`?null:(0,m.jsx)(`svg`,{viewBox:`0 0 28 12`,preserveAspectRatio:`none`,style:{display:`block`,width:`100%`,height:`12px`},children:e.map((n,r)=>{let i=n/Math.max(...e,1)*10,a=r*4;return(0,m.jsx)(`rect`,{x:a,y:12-i,width:`2.5`,height:i,fill:t,opacity:r===e.length-1?1:.6},r)})}),g=e=>B===`custom`?null:(0,m.jsxs)(`span`,{className:y(z.kpiDelta,e>0?z.kpiDeltaUp:e<0?z.kpiDeltaDown:z.kpiDeltaFlat),children:[e>0?`▲`:e<0?`▼`:``,` `,Math.abs(e).toFixed(1),`%`]});return(0,m.jsxs)(m.Fragment,{children:[(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-tile`,children:[(0,m.jsxs)(`div`,{className:z.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescCacheHit`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`cacheHitRate`)})}),g(f)]}),(0,m.jsx)(`span`,{className:y(z.kpiValue,z.kpiGreen),children:mn(Z.cacheHit+Z.cacheMiss>0?Z.cacheHit/(Z.cacheHit+Z.cacheMiss)*100:0)}),(0,m.jsx)(`div`,{className:z.kpiSpark,children:h(c,`var(--ds-cyan)`)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[q(Z.cacheHit),` / `,q(Z.cacheHit+Z.cacheMiss),Z.cacheWrite>0?` · ${t(`tokenCacheWrite`)} ${q(Z.cacheWrite)}`:``]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,children:[(0,m.jsxs)(`div`,{className:z.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescTokens`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`tokens`)})}),g(d)]}),(0,m.jsx)(`span`,{className:z.kpiValue,children:q(Z.input+Z.output)}),(0,m.jsx)(`div`,{className:z.kpiSpark,children:h(s,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[t(`inputTokens`),` `,q(Z.input),` · `,t(`outputTokens`),` `,q(Z.output)]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-avg`,children:[(0,m.jsxs)(`div`,{className:z.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescAvgCost`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`avgCost`)})}),g(l)]}),(0,m.jsx)(`span`,{className:z.kpiValue,children:W(Z.calls>0?Z.cost/Z.calls:0)}),(0,m.jsx)(`div`,{className:z.kpiSpark,children:h(a,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[t(`calls`),` `,Z.calls.toLocaleString()]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,children:[(0,m.jsxs)(`div`,{className:z.kpiLabelRow,children:[(0,m.jsx)(p.Tooltip,{label:t(`kpiDescCalls`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`calls`)})}),g(u)]}),(0,m.jsx)(`span`,{className:z.kpiValue,children:Z.calls.toLocaleString()}),(0,m.jsx)(`div`,{className:z.kpiSpark,children:h(o,`var(--ds-blue)`)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[X.length,` `,t(`models`)]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-think`,children:[(0,m.jsx)(`div`,{className:z.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescReasoning`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`tokenReasoningShare`)})})}),(0,m.jsx)(`span`,{className:y(z.kpiValue,z.kpiGreen),children:mn(Z.output>0?Z.reasoning/Z.output*100:0)}),(0,m.jsx)(`span`,{className:z.kpiDetail,children:q(Z.reasoning)})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-io`,children:[(0,m.jsx)(`div`,{className:z.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescIo`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`tokenIo`)})})}),(0,m.jsx)(`span`,{className:z.kpiValue,children:(Z.output>0?Z.input/Z.output:0).toFixed(2)}),(0,m.jsxs)(`span`,{className:z.kpiDetail,children:[q(Z.input),` / `,q(Z.output)]})]}),(0,m.jsxs)(`div`,{className:z.kpiTile,"data-testid":`billing-kpi-peak`,children:[(0,m.jsx)(`div`,{className:z.kpiLabelRow,children:(0,m.jsx)(p.Tooltip,{label:t(`kpiDescPeak`),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.kpiLabel,children:t(`tokenPeak`)})})}),(0,m.jsx)(`span`,{className:z.kpiValue,children:Z.peakTokens>0?wn(Z.peakTokens):`—`}),(0,m.jsx)(`span`,{className:z.kpiDetail,children:Z.peakDay??`—`})]})]})})()})]}),(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-panel-heatmap`,children:[(0,m.jsxs)(`div`,{className:z.panelHead,children:[(0,m.jsx)(`h3`,{className:z.panelTitle,children:t(`heatmap`)}),(0,m.jsx)(`div`,{className:z.heatmapRangeSwitch,"data-testid":`billing-heatmap-metric`,role:`group`,"aria-label":t(`heatmap`),children:[`cost`,`tokens`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.heatmapRangeButton,We===e&&z.heatmapRangeButtonActive),"data-testid":`billing-heatmap-metric-${e}`,"aria-pressed":We===e,onClick:()=>{qe(e)},children:t(e===`cost`?`metricCost`:`metricTokens`)},e))}),(0,m.jsx)(`div`,{className:z.heatmapRangeSwitch,"data-testid":`billing-heatmap-range`,role:`group`,"aria-label":t(`heatmap`),children:[`month`,`half`,`year`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.heatmapRangeButton,ze===e&&z.heatmapRangeButtonActive),"data-testid":`billing-heatmap-range-${e}`,"aria-pressed":ze===e,onClick:()=>{Be(e)},children:t(e===`month`?`heatmapMonth`:e===`half`?`heatmapHalf`:`heatmapYear`)},e))}),(0,m.jsxs)(`span`,{className:z.panelHint,"data-testid":`billing-heatmap-summary`,children:[t(`heatmapTotal`),` `,We===`tokens`?q(Y):W(Y),` · `,t(`activeDays`),` `,Mn,` · `,t(`streakDays`),` `,Nn]})]}),(0,m.jsx)($n,{days:jn,currency:f,t,range:ze,unit:We})]})]}),F===`agents`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-agents`,children:[(0,m.jsxs)(`section`,{className:z.agentSummary,"data-testid":`billing-agent-summary`,children:[(0,m.jsxs)(`span`,{className:z.agentSummaryItem,children:[(0,m.jsx)(`span`,{className:z.agentSummaryValue,children:String(_e.agents)}),(0,m.jsx)(`span`,{className:z.agentSummaryLabel,children:t(`agentsCount`)})]}),(0,m.jsxs)(`span`,{className:z.agentSummaryItem,children:[(0,m.jsx)(`span`,{className:z.agentSummaryValue,children:String(_e.delegations)}),(0,m.jsx)(`span`,{className:z.agentSummaryLabel,children:t(`agentsDelegations`)})]}),(0,m.jsxs)(`span`,{className:z.agentSummaryItem,children:[(0,m.jsx)(`span`,{className:z.agentSummaryValue,children:String(_e.roots)}),(0,m.jsx)(`span`,{className:z.agentSummaryLabel,children:t(`agentsRoots`)})]}),_e.costliest!==void 0&&_e.costliest.chainCost>0&&(0,m.jsxs)(`span`,{className:z.agentSummaryItem,children:[(0,m.jsx)(`span`,{className:z.agentSummaryValue,children:W(_e.costliest.chainCost)}),(0,m.jsx)(`span`,{className:z.agentSummaryLabel,children:t(`agentsMostExpensive`)})]})]}),ge.length===0||_e.delegations===0?(0,m.jsx)(`p`,{className:z.contextEmpty,"data-testid":`billing-agents-empty`,children:t(`agentsNoData`)}):(0,m.jsx)(`div`,{className:z.agentTree,"data-testid":`billing-agent-tree`,children:(()=>{let e=n=>(0,m.jsxs)(`div`,{className:z.agentNode,children:[(0,m.jsxs)(`div`,{className:z.agentRow,style:{paddingLeft:`${String(n.depth*16)}px`},children:[(0,m.jsx)(`span`,{className:z.agentKind,children:n.depth===0?t(`agentsRoot`):t(`agentsSubagent`)}),(0,m.jsx)(`span`,{className:z.agentTitle,children:n.title??`${t(`sessionUntitled`)} · ${n.id.slice(0,8)}`}),(0,m.jsx)(`span`,{className:z.agentCalls,children:n.calls.toLocaleString()}),(0,m.jsx)(`span`,{className:z.agentCost,children:W(n.cost)}),n.children.length>0&&(0,m.jsxs)(`span`,{className:y(z.ubTag,z.ubTagNeutral),"data-testid":`billing-agent-chain`,children:[t(`agentsChainTotal`),` `,W(n.chainCost)]})]}),n.children.map(e)]},n.id);return ge.map(e)})()})]}),F===`settings`&&(0,m.jsx)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-settings`,children:(0,m.jsxs)(`div`,{className:y(z.settingsLayout,r&&z.nativeSettingsLayout),children:[!r&&(0,m.jsx)(`aside`,{className:z.settingsNav,"data-testid":`billing-settings-nav`,role:`navigation`,"aria-label":`settings`,children:[{id:`display-pref`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:[(0,m.jsx)(`path`,{d:`M5 3v10M11 3v10`}),(0,m.jsx)(`circle`,{cx:`5`,cy:`6.5`,r:`1.8`}),(0,m.jsx)(`circle`,{cx:`11`,cy:`9.5`,r:`1.8`})]}),label:t(`settingsNavDisplayPref`)},{id:`budget`,icon:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:(0,m.jsx)(`path`,{d:`M5 3l3 4 3-4M8 7v6M5.5 9.5h5M5.5 12h5`})}),label:t(`settingsNavBudget`)},{id:`alert`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,m.jsx)(`path`,{d:`M8 2a4 4 0 0 1 4 4v3l1.5 2.5h-11L4 9V6a4 4 0 0 1 4-4z`}),(0,m.jsx)(`path`,{d:`M6.5 13.5a1.5 1.5 0 0 0 3 0`})]}),label:t(`settingsNavAlert`)},{id:`display`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`}),(0,m.jsx)(`path`,{d:`M8 2a6 6 0 0 1 0 12z`,fill:`currentColor`,stroke:`none`})]}),label:t(`settingsNavDisplay`)},{id:`advanced`,icon:(0,m.jsx)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:(0,m.jsx)(`path`,{d:`M8 2v12M2.8 5l10.4 6M13.2 5L2.8 11`})}),label:t(`settingsNavAdvanced`),advanced:!0},{id:`about`,icon:(0,m.jsxs)(`svg`,{viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,children:[(0,m.jsx)(`circle`,{cx:`8`,cy:`8`,r:`6`}),(0,m.jsx)(`path`,{d:`M8 7.5V11`}),(0,m.jsx)(`circle`,{cx:`8`,cy:`5.2`,r:`0.9`,fill:`currentColor`,stroke:`none`})]}),label:t(`settingsNavAbout`)}].map(e=>(0,m.jsxs)(`button`,{type:`button`,className:y(z.settingsNavItem,Qe===e.id&&z.settingsNavItemActive,e.advanced&&z.settingsNavItemAdvanced),"data-testid":`billing-settings-nav-${e.id}`,onClick:()=>{rt(e.id)},children:[(0,m.jsx)(`span`,{className:z.settingsNavIcon,"aria-hidden":`true`,children:e.icon}),e.label]},e.id))}),(0,m.jsxs)(`div`,{className:z.settingsPane,children:[(0,m.jsx)(`input`,{className:y(z.ubSearch,z.settingsSearch),type:`search`,value:et,placeholder:t(`settingsSearchPlaceholder`),"aria-label":t(`settingsSearchPlaceholder`),"data-testid":`billing-settings-search`,onChange:e=>{tt(e.target.value)}}),et.trim()!==``&&fa(et)&&(0,m.jsx)(`p`,{className:z.setCardDesc,"data-testid":`billing-settings-search-empty`,children:t(`settingsSearchEmpty`).replace(`{query}`,et.trim())}),(0,m.jsxs)(`div`,{hidden:nt(da.display),className:z.setCard,id:`settings-display-pref`,"data-testid":`billing-density-motion-card`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsx)(`h3`,{className:z.setCardTitle,children:t(`settingsSectionDisplay`)})})}),(0,m.jsxs)(`div`,{className:z.densityRow,children:[(0,m.jsxs)(`div`,{className:z.densityLeft,children:[(0,m.jsx)(`strong`,{children:t(`densityLabel`)}),(0,m.jsx)(`span`,{children:t(`densityHint`)})]}),(0,m.jsx)(`div`,{className:z.densityButtons,"data-testid":`billing-density-buttons`,children:[`compact`,`default`,`comfortable`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.densityButton,Je===e&&z.densityButtonActive,e===`comfortable`&&z.densityButtonComfortable),"data-testid":`billing-density-${e}`,onClick:()=>{it(e)},children:t(e===`compact`?`densityCompact`:e==="default"?`densityDefault`:`densityComfortable`)},e))})]}),(0,m.jsxs)(`div`,{className:z.densityRow,children:[(0,m.jsxs)(`div`,{className:z.densityLeft,children:[(0,m.jsx)(`strong`,{children:t(`motionLabel`)}),(0,m.jsx)(`span`,{children:t(`motionHint`)})]}),(0,m.jsx)(`div`,{className:z.densityButtons,"data-testid":`billing-motion-buttons`,children:[`off`,`subtle`,`rich`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.densityButton,Xe===e&&z.densityButtonActive),"data-testid":`billing-motion-${e}`,onClick:()=>{ot(e)},children:t(e===`off`?`motionOff`:e===`subtle`?`motionSubtle`:`motionRich`)},e))})]})]}),(0,m.jsxs)(`section`,{hidden:nt(da.budget),className:z.setCard,"data-testid":`billing-budget`,id:`settings-budget`,children:[(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`budget`),(0,m.jsx)(ra,{label:t(`budgetHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":x,"aria-label":t(`budget`),"data-testid":`billing-budget-toggle`,className:y(z.switch,x&&z.switchOn),onClick:C,children:(0,m.jsx)(`span`,{className:z.switchKnob})})]}),x&&(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`budgetAmount`)}),(0,m.jsxs)(`span`,{className:z.inp,"data-testid":`billing-budget-input-wrap`,children:[(0,m.jsx)(`span`,{className:z.affix,"aria-hidden":`true`,children:`¥`}),(0,m.jsx)(`input`,{className:z.budgetInput,"data-testid":`billing-budget-input`,type:`number`,min:0,step:1,value:S===0?``:S,placeholder:e.budget===void 0?`0`:String(e.budget),"aria-label":`${t(`budget`)}(${f===`usd`?`USD`:f===`eur`?`EUR`:`CNY`})`,title:`${t(`budget`)}(${f===`usd`?`USD`:f===`eur`?`EUR`:`CNY`})`,onChange:e=>{w(e.target.valueAsNumber)}})]})]}),S>0&&(()=>{let e=J/S*100;return(0,m.jsx)(`div`,{className:z.ctlRowStretch,children:(0,m.jsx)(`div`,{className:z.prog,role:`progressbar`,"aria-valuenow":Math.min(e,100),"aria-valuemin":0,"aria-valuemax":100,"aria-label":t(`budget`),"data-testid":`billing-budget-track`,children:(0,m.jsx)(`div`,{className:y(z.progFill,e>=100&&z.budgetFillOver,e>=80&&e<100&&z.budgetFillWarn),style:{width:`${Math.min(e,100)}%`}})})})})(),S>0&&(0,m.jsx)(`p`,{className:z.setCardDesc,"data-testid":`billing-budget-value`,children:t(`budgetSummary`).replace(`{used}`,W(J)).replace(`{total}`,W(S))})]}),(0,m.jsxs)(`div`,{className:z.ctlCol,"data-testid":`billing-model-budgets`,children:[(0,m.jsxs)(`span`,{className:z.modelBudgetTitle,children:[t(`modelBudgetTitle`),(0,m.jsx)(ra,{label:t(`modelBudgetHint`),t})]}),wt.length===0&&(0,m.jsx)(`p`,{className:z.modelBudgetHint,children:t(`emptyHint`)}),(0,m.jsx)(`div`,{className:z.modelBudgetList,children:wt.map(e=>(0,m.jsxs)(`div`,{className:z.modelBudgetRow,children:[(0,m.jsx)(`span`,{className:z.modelBudgetName,title:e.name??e.key,children:e.name??e.key}),(0,m.jsx)(`span`,{className:z.modelBudgetCost,"data-testid":`billing-model-budget-cost-${e.key}`,children:W(e.cost)}),(0,m.jsxs)(`span`,{className:z.inp,children:[(0,m.jsx)(`span`,{className:z.affix,"aria-hidden":`true`,children:`¥`}),(0,m.jsx)(`input`,{className:z.budgetInput,type:`number`,min:0,step:1,value:T[e.key]??``,placeholder:t(`modelBudgetPlaceholder`),"aria-label":`${t(`modelBudgetTitle`)} · ${e.name??e.key}`,"data-testid":`billing-model-budget-${e.key}`,onChange:t=>{E(e.key,t.target.valueAsNumber)}})]})]},e.key))})]})]}),(0,m.jsxs)(`section`,{hidden:nt(da.alert),className:z.setCard,"data-testid":`billing-peak-alert-settings`,id:`settings-alert`,children:[(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`peakAlert`),(0,m.jsx)(ra,{label:t(`peakAlertHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":D.enabled,"aria-label":t(`peakAlert`),"data-testid":`billing-peak-alert-toggle`,className:y(z.switch,D.enabled&&z.switchOn),onClick:()=>{O({...D,enabled:!D.enabled})},children:(0,m.jsx)(`span`,{className:z.switchKnob})})]}),D.enabled&&(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsxs)(`label`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`peakAlertLeadMin`)}),(0,m.jsx)(`span`,{className:z.inp,children:(0,m.jsx)(`input`,{type:`number`,min:1,max:30,step:1,value:D.leadMin,className:z.budgetInput,"aria-label":t(`peakAlertLeadMin`),onChange:e=>{let t=Number(e.target.valueAsNumber);O({...D,leadMin:Number.isFinite(t)?Math.min(30,Math.max(1,Math.round(t))):D.leadMin})}})})]}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`peakAlertPos`)}),(0,m.jsx)(`div`,{className:z.ctlGroup,role:`radiogroup`,"aria-label":t(`peakAlertPos`),children:[`bottom-right`,`center`].map(e=>(0,m.jsxs)(`label`,{className:z.rdo,children:[(0,m.jsx)(`input`,{type:`radio`,name:`peak-pos`,checked:D.position===e,onChange:()=>O({...D,position:e})}),(0,m.jsx)(`span`,{className:z.rdoDot,"aria-hidden":`true`}),t(e===`bottom-right`?`peakAlertPosCorner`:`peakAlertPosCenter`)]},e))})]}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`peakAlertMode`)}),(0,m.jsx)(`div`,{className:z.ctlGroup,role:`radiogroup`,"aria-label":t(`peakAlertMode`),children:[`both`,`peak`,`offPeak`].map(e=>(0,m.jsxs)(`label`,{className:z.rdo,children:[(0,m.jsx)(`input`,{type:`radio`,name:`peak-mode`,checked:D.mode===e,onChange:()=>O({...D,mode:e})}),(0,m.jsx)(`span`,{className:z.rdoDot,"aria-hidden":`true`}),t(e===`both`?`peakAlertModeBoth`:e===`peak`?`peakAlertModePeak`:`peakAlertModeOff`)]},e))})]}),(0,m.jsxs)(`label`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`peakAlertWebNotify`)}),(0,m.jsx)(`input`,{type:`checkbox`,checked:D.webNotify,"aria-label":t(`peakAlertWebNotify`),onChange:e=>{O({...D,webNotify:e.target.checked})}})]}),(0,m.jsx)(`div`,{className:z.ctlRow,children:(0,m.jsx)(`button`,{type:`button`,className:z.btn,onClick:k,children:t(`peakAlertPreview`)})})]})]}),(0,m.jsx)(`section`,{hidden:nt(da.toggles),className:z.setCard,"data-testid":`billing-toggle-setting`,id:`settings-display`,children:(0,m.jsxs)(`div`,{className:z.setGrid3,children:[(0,m.jsx)(`div`,{className:z.setCell,"data-testid":`billing-usage-stats-tool-setting`,children:(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`usageStatsTool`),(0,m.jsx)(ra,{label:t(`usageStatsToolHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":At,"aria-label":t(`usageStatsTool`),"data-testid":`billing-usage-stats-tool-toggle`,className:y(z.switch,At&&z.switchOn),onClick:Mt,children:(0,m.jsx)(`span`,{className:z.switchKnob})})]})}),(0,m.jsxs)(`div`,{className:z.setCell,"data-testid":`billing-livecost-setting`,children:[(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`liveCostBar`),(0,m.jsx)(ra,{label:t(`liveCostBarHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":oe.show,"aria-label":t(`liveCostBar`),"data-testid":`billing-livecost-toggle`,className:y(z.switch,oe.show&&z.switchOn),onClick:()=>se({...oe,show:!oe.show}),children:(0,m.jsx)(`span`,{className:z.switchKnob})})]}),oe.show&&(0,m.jsxs)(`div`,{className:z.rdoRow,"data-testid":`billing-livecost-position`,children:[(0,m.jsx)(`span`,{className:z.rdoLabel,children:t(`liveCostBarPosition`)}),(0,m.jsx)(ma,{liveCostPrefs:oe,onLiveCostPrefs:se,t})]})]}),(0,m.jsx)(`div`,{className:z.setCell,"data-testid":`billing-site-list-setting`,children:(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`siteListDisplay`),(0,m.jsx)(ra,{label:t(`siteListDisplayHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":N.hideUnidentified,"aria-label":t(`siteListDisplay`),"data-testid":`billing-site-hide-unidentified`,className:y(z.switch,N.hideUnidentified&&z.switchOn),onClick:()=>re({hideUnidentified:!N.hideUnidentified}),children:(0,m.jsx)(`span`,{className:z.switchKnob})})]})}),(0,m.jsx)(`div`,{className:z.setCell,"data-testid":`billing-quick-queue-entry-setting`,children:(0,m.jsxs)(`div`,{className:z.setCardHead,children:[(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`quickQueueEntry`),(0,m.jsx)(ra,{label:t(`quickQueueEntryHint`),t})]})}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":ue.showEntry,"aria-label":t(`quickQueueEntry`),"data-testid":`billing-quick-queue-entry-toggle`,className:y(z.switch,ue.showEntry&&z.switchOn),onClick:()=>de({...ue,showEntry:!ue.showEntry}),children:(0,m.jsx)(`span`,{className:z.switchKnob})})]})})]})}),(0,m.jsx)(`section`,{hidden:nt(da.displayExtra),className:z.setCard,"data-testid":`billing-display-setting`,id:`settings-display-extra`,children:(0,m.jsxs)(`div`,{className:z.setGrid2,children:[(0,m.jsxs)(`div`,{className:z.setCell,"data-testid":`billing-float-setting`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`floatWindow`),(0,m.jsx)(ra,{label:t(`floatWindowHint`),t})]})})}),(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`cardMode`)}),(0,m.jsx)(`div`,{className:z.ctlGroup,"data-testid":`billing-card-mode`,children:[[`full`,`cardModeFull`],[`compact`,`cardModeCompact`],[`hidden`,`cardModeHidden`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.mode===e&&z.floatModeBtnOn),"data-testid":`billing-card-mode-${e}`,"aria-pressed":M.mode===e,disabled:e===`hidden`&&!ne,title:e===`hidden`&&!ne?t(`cardModeFallback`):void 0,onClick:()=>te({...M,mode:e}),children:t(n)},e))})]}),!ne&&(0,m.jsx)(`p`,{className:z.setCardDesc,"data-testid":`billing-card-mode-fallback`,children:t(`cardModeFallback`)}),ne&&M.mode===`hidden`&&(0,m.jsx)(`p`,{className:z.setCardDesc,"data-testid":`billing-card-mode-hidden-hint`,children:t(`cardModeHiddenHint`)}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`floatMode`)}),(0,m.jsxs)(`div`,{className:z.ctlGroup,"data-testid":`billing-float-mode`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,A.mode===`combined`&&z.floatModeBtnOn),"data-testid":`billing-float-mode-combined`,onClick:()=>j({mode:`combined`,targets:A.targets}),children:t(`floatModeCombined`)}),(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,A.mode===`subscription`&&z.floatModeBtnOn),"data-testid":`billing-float-mode-subscription`,onClick:()=>j({mode:`subscription`,targets:A.targets}),children:t(`floatModeSubscription`)})]})]}),A.mode===`subscription`&&(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`floatTargets`)}),(0,m.jsxs)(`span`,{className:z.ctlGroup,"data-testid":`billing-float-targets`,children:[lt.map(e=>{let t=A.targets.includes(e.id);return(0,m.jsxs)(`label`,{className:z.floatTarget,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:t,"data-testid":`billing-float-target-${e.id}`,onChange:()=>j({mode:`subscription`,targets:t?A.targets.filter(t=>t!==e.id):[...A.targets,e.id]})}),(0,m.jsx)(`span`,{className:z.floatTargetLabel,children:e.label})]},e.id)}),lt.length===0&&(0,m.jsx)(`span`,{className:z.setCardDesc,children:t(`floatNoTargetsHint`)})]})]})]})]}),(0,m.jsxs)(`div`,{className:z.setCell,"data-testid":`billing-card-setting`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsxs)(`h3`,{className:z.setCardTitle,children:[t(`cardDisplay`),(0,m.jsx)(ra,{label:t(`cardDisplayHint`),t})]})})}),(0,m.jsxs)(`div`,{className:z.ctlCol,children:[(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`cardMetric`)}),(0,m.jsxs)(`div`,{className:z.ctlGroup,"data-testid":`billing-card-metric`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.metric===`money`&&z.floatModeBtnOn),"data-testid":`billing-card-money`,onClick:()=>te({...M,metric:`money`}),children:t(`cardMetricMoney`)}),(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.metric===`tokens`&&z.floatModeBtnOn),"data-testid":`billing-card-tokens`,onClick:()=>te({...M,metric:`tokens`}),children:t(`cardMetricTokens`)})]})]}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`cardSpan`)}),(0,m.jsx)(`div`,{className:z.ctlGroup,"data-testid":`billing-card-span`,children:[[`day`,`cardSpanDay`],[`week`,`cardSpanWeek`],[`month`,`cardSpanMonth`]].map(([e,n])=>(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.span===e&&z.floatModeBtnOn),"data-testid":`billing-card-span-${e}`,"aria-pressed":M.span===e,onClick:()=>te({...M,span:e}),children:t(n)},e))})]}),(0,m.jsxs)(`div`,{className:z.ctlRow,children:[(0,m.jsx)(`span`,{className:z.ctlLabel,children:t(`cardDeltaBadge`)}),(0,m.jsxs)(`div`,{className:z.ctlGroup,"data-testid":`billing-card-delta`,children:[(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,M.showDelta&&z.floatModeBtnOn),"data-testid":`billing-card-delta-show`,"aria-pressed":M.showDelta,onClick:()=>te({...M,showDelta:!0}),children:t(`cardDeltaShow`)}),(0,m.jsx)(`button`,{type:`button`,className:y(z.floatModeBtn,!M.showDelta&&z.floatModeBtnOn),"data-testid":`billing-card-delta-hide`,"aria-pressed":!M.showDelta,onClick:()=>te({...M,showDelta:!1}),children:t(`cardDeltaHide`)})]})]})]})]})]})}),(0,m.jsx)(`div`,{hidden:nt(da.advanced),id:`settings-advanced`,children:(0,m.jsx)(ca,{userPrices:i,onUserPrices:a,t})}),(0,m.jsx)(`div`,{hidden:nt(da.about),id:`settings-about`,children:(0,m.jsx)(Wn,{t,version:e.pluginVersion})}),(0,m.jsxs)(`section`,{hidden:nt(da.about),className:z.setCard,"data-testid":`billing-more-works`,children:[(0,m.jsx)(`div`,{className:z.setCardHead,children:(0,m.jsx)(`div`,{className:z.setCardMeta,children:(0,m.jsx)(`h3`,{className:z.setCardTitle,children:t(`moreWorksTitle`)})})}),(0,m.jsxs)(`div`,{className:z.moreWorkList,children:[(0,m.jsxs)(`a`,{className:z.moreWorkRow,href:`https://github.com/kenz1117/dsh-engram`,target:`_blank`,rel:`noreferrer`,"data-testid":`billing-ad-engram`,children:[(0,m.jsx)(`span`,{className:z.moreWorkName,children:t(`adEngramName`)}),(0,m.jsx)(`span`,{className:z.moreWorkDesc,children:t(`adEngramDesc`)})]}),(0,m.jsxs)(`a`,{className:z.moreWorkRow,href:`https://github.com/kenz1117/dsh-ui-rainbowspeak`,target:`_blank`,rel:`noreferrer`,"data-testid":`billing-ad-rainbowspeak`,children:[(0,m.jsx)(`span`,{className:z.moreWorkName,children:t(`adRainbowName`)}),(0,m.jsx)(`span`,{className:z.moreWorkDesc,children:t(`adRainbowDesc`)})]})]})]})]})]})}),F===`trends`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-trends`,children:[(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-trend`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`trend`)}),b(`billing.dashboard.decor`,{position:`trend`}),(0,m.jsxs)(`span`,{className:z.ubCardControlGroup,children:[(0,m.jsx)(`span`,{className:z.rangeToggle,role:`group`,"aria-label":t(`trend`),children:[7,30].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.rangeButton,je===e&&z.rangeButtonActive),"aria-pressed":je===e,"data-testid":`billing-trend-${e}d`,onClick:()=>{Me(e)},children:t(e===7?`trend7d`:`trend30d`)},e))}),(0,m.jsx)(`span`,{className:z.rangeToggle,role:`group`,"aria-label":t(`trendMetric`),children:[`cost`,`tokens`].map(e=>(0,m.jsx)(`button`,{type:`button`,className:y(z.rangeButton,xe===e&&z.rangeButtonActive),"aria-pressed":xe===e,"data-testid":`billing-trend-metric-${e}`,onClick:()=>{Se(e)},children:t(e===`cost`?`trendMetricCost`:`trendMetricTokens`)},e))})]}),(0,m.jsx)(`span`,{className:z.ubCardSub,children:An})]}),(0,m.jsx)(Fn,{data:Pn,models:Xn,currency:f,metric:xe,t})]}),v.length>0&&(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-rounds`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`rounds`)}),Zt.length>0&&(0,m.jsxs)(`span`,{className:z.ubTagError,"data-testid":`billing-rounds-flag-count`,children:[Zt.length,` `,t(`anomaly`)]})]}),(0,m.jsx)(`p`,{className:z.ubCardSub,children:t(`roundsHint`).replace(`{count}`,String(v.length))}),(0,m.jsx)(Jn,{rounds:v,flags:Zt,currency:f,t})]}),e.byTier!==void 0&&(()=>{let e=Qt.peak+Qt.offPeak;if(e<=0)return null;let n=Qt.peak/e*100;return(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-share`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`peakShare`)}),(0,m.jsx)(`span`,{className:z.ubCardSub,children:t(`peakSharePerCall`)})]}),(0,m.jsxs)(`div`,{className:z.shareTrack,"data-testid":`billing-share-track`,children:[(0,m.jsx)(`div`,{className:y(z.shareSeg,z.shareSegPeak),style:{width:`${n}%`}}),(0,m.jsx)(`div`,{className:y(z.shareSeg,z.shareSegOff),style:{width:`${100-n}%`}})]}),(0,m.jsxs)(`div`,{className:z.shareLegend,children:[(0,m.jsxs)(`span`,{className:z.shareItem,children:[(0,m.jsx)(`span`,{className:z.shareDot,style:{background:`var(--ds-blue)`}}),t(`peak`),(0,m.jsxs)(`span`,{className:z.shareValue,"data-testid":`billing-share-peak`,children:[W(Qt.peak),` · `,n.toFixed(1),`%`]})]}),(0,m.jsxs)(`span`,{className:z.shareItem,children:[(0,m.jsx)(`span`,{className:z.shareDot,style:{background:`color-mix(in srgb, var(--ds-blue) 30%, var(--dsb-3))`}}),t(`offPeak`),(0,m.jsxs)(`span`,{className:z.shareValue,"data-testid":`billing-share-offpeak`,children:[W(Qt.offPeak),` · `,(100-n).toFixed(1),`%`]})]})]}),$t>0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-share-savings`,children:t(`offPeakSavings`).replace(`{amount}`,W($t))})]})})()]}),F===`providers`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-providers`,children:[In.length>0&&(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-panel-relay-quota`,children:[(0,m.jsx)(`div`,{className:z.panelHead,children:(0,m.jsx)(`h3`,{className:z.panelTitle,children:t(`panelRelayQuota`)})}),(0,m.jsx)(`div`,{className:z.providerGroupList,"data-testid":`billing-relay-quotas`,children:In.map(e=>(0,m.jsxs)(`div`,{className:z.siteRow,"data-testid":`billing-relay-quota`,children:[(0,m.jsxs)(`span`,{className:z.siteRowName,children:[(0,m.jsx)(`span`,{className:y(z.siteKindTag,Mi[e.kind]),children:ji(e.kind,t)}),(0,m.jsx)(`span`,{className:z.siteRowTitle,children:e.origin})]}),(0,m.jsxs)(`span`,{className:z.siteRowMeta,children:[e.balance!==void 0&&(0,m.jsxs)(`span`,{className:z.siteRowCost,children:[t(`relayBalance`),` `,e.balance.toFixed(2)]}),(e.windows?.length??0)>0?e.windows?.map(e=>{let n=e.remainingPercent<20;return(0,m.jsxs)(`span`,{className:y(z.siteRowCalls,n&&z.siteRowCallsLow),children:[t(`relayWindowUsed`),` `,e.usedPercent,`%`]},e.kind)}):(0,m.jsx)(`span`,{className:z.siteRowCalls,children:t(`relayNoQuota`)})]})]},e.route))})]}),(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-panel-providers`,children:[(0,m.jsxs)(`div`,{className:z.panelHead,children:[(0,m.jsx)(`h3`,{className:z.panelTitle,children:t(`providerBilling`)}),b(`billing.dashboard.decor`,{position:`models`}),(0,m.jsx)(`span`,{className:z.panelHint,children:e.updatedAt===void 0?``:`${t(`lastUpdated`)} ${Fi(e.updatedAt)}`})]}),fe&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-subscriptions-stale`,children:t(`subscriptionsStale`)}),(0,m.jsxs)(`div`,{className:z.providerCtlRow,"data-testid":`billing-provider-controls`,children:[(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,disabled:Rn.length===0,onClick:Bn,children:t(zn?`collapseAll`:`expandAll`)}),(0,m.jsxs)(`span`,{className:z.providerTodayToggle,children:[(0,m.jsx)(`span`,{children:t(`todayOnly`)}),(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":U,"data-testid":`billing-provider-today-toggle`,className:y(z.switch,U&&z.switchOn),onClick:kt,children:(0,m.jsx)(`span`,{className:z.switchKnob})})]})]}),Ln.length===0?(0,m.jsxs)(`div`,{className:z.emptyState,"data-testid":`billing-provider-empty`,children:[(0,m.jsxs)(`span`,{className:z.emptyIll,"aria-hidden":`true`,children:[(0,m.jsxs)(`svg`,{viewBox:`0 0 96 64`,fill:`none`,children:[(0,m.jsx)(`line`,{x1:`6`,y1:`58`,x2:`90`,y2:`58`,stroke:`var(--ds-border-strong)`,strokeWidth:`1`}),(0,m.jsx)(`line`,{x1:`6`,y1:`6`,x2:`6`,y2:`58`,stroke:`var(--ds-border-strong)`,strokeWidth:`1`}),(0,m.jsx)(`path`,{d:`M14 50 L28 40 L42 44 L56 26 L70 30 L82 14`,stroke:`var(--ds-border-strong)`,strokeWidth:`1.5`,strokeLinecap:`round`,fill:`none`,strokeDasharray:`3 3`})]}),(0,m.jsx)(`span`,{className:z.emptyIllDot})]}),(0,m.jsx)(`span`,{className:z.emptyTitle,children:t(U?`todayNoConsumption`:`noData`)}),(0,m.jsx)(`span`,{className:z.emptyDesc,children:t(`emptyHint`)})]}):(0,m.jsx)(`div`,{className:z.providerGroupList,"data-testid":`billing-provider-groups`,children:Ln.map(e=>{let n=e.models.length>0||e.subscriptions.length>0,r=n&&Tt.has(e.id);return(0,m.jsxs)(`div`,{className:z.providerGroup,"data-testid":`billing-provider-group`,children:[(0,m.jsxs)(`div`,{className:y(z.providerGroupHead,n&&z.providerGroupCollapsible),"data-testid":`billing-provider-group-head`,"aria-expanded":n?r:void 0,role:n?`button`:void 0,tabIndex:n?0:void 0,onClick:n?()=>{Dt(e.id)}:void 0,onKeyDown:n?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),Dt(e.id))}:void 0,children:[(0,m.jsxs)(`span`,{className:z.providerGroupTitle,children:[(0,m.jsx)(`span`,{className:y(z.healthDot,e.dot),role:`img`,"aria-label":ia(e.dot,t),title:ia(e.dot,t)}),(()=>{let n=Ht(e.name),r=e.channelKind===`direct`?yr(n):void 0,i=e.channelKind===`direct`?t(`directTag`):e.channelKind===`site`?t(`relayTag`):e.channelKind===`unknown`?t(`unknownTag`):void 0;return(0,m.jsxs)(m.Fragment,{children:[i!==void 0&&(0,m.jsx)(`span`,{className:y(z.kindBadge,e.channelKind===`site`&&z.kindBadgeRelay,e.channelKind===`unknown`&&z.kindBadgeUnknown),"data-testid":`billing-kind-badge`,children:i}),e.channelKind!==`unknown`&&(0,m.jsx)(`span`,{className:z.providerGroupName,children:r??n})]})})(),e.subscriptions.length>0&&(0,m.jsxs)(`span`,{className:z.providerGroupBadge,"data-testid":`billing-provider-sub-count`,children:[e.subscriptions.length,` `,t(`planCountUnit`)]})]}),(0,m.jsxs)(`span`,{className:z.providerGroupMeta,children:[(0,m.jsxs)(`span`,{className:z.providerGroupCost,"data-testid":`billing-provider-cost`,children:[(0,m.jsx)(`span`,{className:z.providerGroupCostLabel,children:t(`cost`)}),e.channelKind===`unknown`?(0,m.jsx)(`span`,{className:z.na,children:`—`}):(0,m.jsx)(`span`,{className:z.providerGroupCostValue,children:W(Ni(e))})]}),!an(e)&&e.balance!==void 0?(0,m.jsxs)(`span`,{className:z.providerGroupBalance,"data-testid":`billing-provider-balance`,children:[(0,m.jsx)(`span`,{className:z.providerGroupBalanceLabel,children:t(`balance`)}),sn(e.balance)]}):(0,m.jsx)(`span`,{className:z.providerGroupBalance,"aria-hidden":`true`}),hi(e.name)===void 0?(0,m.jsx)(`span`,{className:z.providerGroupRecharge,"aria-hidden":`true`}):(0,m.jsx)(`a`,{className:z.providerGroupRecharge,"data-testid":`billing-group-recharge`,href:hi(e.name),target:`_blank`,rel:`noreferrer`,title:t(`rechargeHint`),"aria-label":`${Ht(e.name)} ${t(`recharge`)}`,onClick:e=>{e.stopPropagation()},children:t(`recharge`)})]})]}),e.models.length>0&&(0,m.jsx)(`div`,{className:z.providerStatRow,"data-testid":`billing-provider-stat-row`,children:(()=>{let n=e.models.reduce((e,t)=>({calls:e.calls+t.calls,input:e.input+t.input,output:e.output+t.output}),{calls:0,input:0,output:0}),r=n.input>0?e.models.reduce((e,t)=>e+t.cacheHitRate,0)/e.models.length:0;return[{lbl:t(`calls`),val:n.calls.toLocaleString(),sub:``},{lbl:t(`inputTokens`),val:q(n.input),sub:r>0?`${t(`cacheHitRate`)} ${r.toFixed(0)}%`:``},{lbl:t(`outputTokens`),val:q(n.output),sub:``},{lbl:t(`cost`),val:W(Ni(e)),sub:e.models.length===1?``:`${e.models.length} ${t(`models`)}`}].map((e,t)=>(0,m.jsxs)(`div`,{className:z.providerStatCell,children:[(0,m.jsx)(`div`,{className:z.providerStatLbl,children:e.lbl}),(0,m.jsx)(`div`,{className:z.providerStatVal,children:e.val}),e.sub!==``&&(0,m.jsx)(`div`,{className:z.providerStatSub,children:e.sub})]},t))})()}),r&&(0,m.jsxs)(m.Fragment,{children:[e.channelKind===`unknown`&&(0,m.jsx)(`p`,{className:z.unknownHint,"data-testid":`billing-unknown-hint`,children:t(`unknownChannelHint`)}),e.models.length>0&&(0,m.jsx)(`div`,{className:z.tableScroll,"data-testid":`billing-table-scroll`,children:(0,m.jsxs)(`table`,{className:z.modelTable,children:[Hn,(0,m.jsx)(`tbody`,{children:e.models.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:Un(e)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:z.numCol,children:q(e.input)}),(0,m.jsx)(`td`,{className:z.numCol,children:q(e.output)}),(0,m.jsx)(`td`,{className:z.numCol,children:mn(e.cacheHitRate)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.plan?(0,m.jsxs)(`span`,{className:z.planTag,children:[e.estimated>0?(0,m.jsxs)(`span`,{children:[`≈`,W(e.estimated)]}):null,(0,m.jsx)(`span`,{className:z.planTagBadge,"data-testid":`billing-plan-badge`,children:t(`subscriptionTag`)})]}):e.actual===void 0?e.estimated>0?(0,m.jsxs)(`span`,{title:t(`cellEstimateHint`),children:[`≈`,W(e.estimated)]}):(0,m.jsx)(`span`,{className:z.na,children:`—`}):(()=>{let t=e.officialCost,n=e.actual-t;return t>0&&n>0?(0,m.jsxs)(`span`,{className:z.bucketCost,children:[(0,m.jsx)(`span`,{className:z.bucketOfficial,children:W(t)}),(0,m.jsx)(`span`,{className:z.bucketSep,children:`/`}),(0,m.jsx)(`span`,{className:z.bucketThird,children:W(n)})]}):W(e.actual)})()})]},e.key))})]})}),e.subscriptions.length>0&&(0,m.jsx)(`div`,{className:z.subscriptionGrid,"data-testid":`billing-subscriptions-grid`,children:e.subscriptions.map(e=>{let n=ki(e.status,t);return(0,m.jsxs)(`div`,{className:y(z.subscriptionCard,z.subscriptionCardUpgraded),"data-testid":`billing-subscription-card`,children:[(0,m.jsxs)(`div`,{className:z.subscriptionHead,children:[(0,m.jsx)(`span`,{className:z.subscriptionName,children:Ht(e.displayName)}),e.planType===`code`&&(()=>{let n=at(e.provider),r=n===void 0?void 0:t(`subscriptionFeePerMonth`).replace(`{amount}`,n.currency===`USD`?`$${n.amount}`:`¥${n.amount}`);return(0,m.jsxs)(`span`,{className:z.subscriptionPlan,"data-kind":`code`,children:[r??(e.subscriptionAmount!==void 0&&e.subscriptionAmount>0?t(`subscriptionFeePerMonth`).replace(`{amount}`,W(e.subscriptionAmount)):t(`planTypeCode`)),n?.label!==void 0&&(0,m.jsx)(`span`,{className:z.subscriptionTier,"data-testid":`billing-tier-${e.provider}`,children:n.label}),n!==void 0&&(0,m.jsx)(`span`,{className:z.subscriptionAuto,"data-testid":`billing-auto-${e.provider}`,children:t(`subscriptionAutoDetect`)})]})})(),e.planType===`token`&&(0,m.jsx)(`span`,{className:z.subscriptionPlan,"data-kind":`token`,children:t(`planTypeToken`)}),e.plan!==void 0&&(0,m.jsx)(`span`,{className:z.subscriptionPlan,children:e.plan})]}),n!==``&&(0,m.jsx)(`div`,{className:z.subscriptionStatus,children:n}),e.windows.length===0&&n===``&&(0,m.jsx)(`div`,{className:z.subscriptionStatus,children:t(`subscriptionNoApi`)}),e.windows.map(e=>(0,m.jsx)(na,{window:e,t},e.kind))]},e.provider)})})]})]},e.id)})})]}),(0,m.jsxs)(`div`,{className:z.exportBar,"data-testid":`billing-export-bar`,role:`group`,"aria-label":t(`export`),children:[(0,m.jsx)(`span`,{className:z.exportLabel,children:t(`export`)}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-export-day`,onClick:()=>{Cn(Sn(`usage-daily`,`csv`,Object.keys(P)),vn(P),`text/csv`)},children:t(`exportCsvDay`)}),e.bySession!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-export-sessions`,onClick:()=>{Cn(Sn(`usage-sessions`,`csv`,Object.keys(P)),xn(e.bySession??[]),`text/csv`)},children:t(`exportCsvSession`)}),e.bySite!==void 0&&(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-export-sites`,onClick:()=>{Cn(Sn(`usage-sites`,`csv`,Object.keys(P)),yn(e.bySite??{}),`text/csv`)},children:t(`exportCsvSite`)}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-export-json`,onClick:()=>{Cn(Sn(`usage-stats`,`json`,Object.keys(P)),JSON.stringify(e,null,2),`application/json`)},children:t(`exportJson`)})]}),e.bySession!==void 0&&(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-sessions`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`sessions`)}),(0,m.jsx)(`span`,{className:z.ubCardSub,children:e.bySession.length>20?t(`sessionOverflow`).replace(`{limit}`,`20`).replace(`{total}`,String(e.bySession.length)):`${e.bySession.length}`}),e.bySession.length>0&&(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-sessions-view-all`,onClick:()=>{ht(!0)},children:t(`sessionsViewAll`).replace(`{count}`,String(e.bySession.length))})]}),(e.staleLedgerSessions??0)>0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-sessions-stale`,children:t(`staleLedgerNotice`).replace(`{count}`,String(e.staleLedgerSessions))}),(0,m.jsxs)(`div`,{className:z.ubTablewrap,"data-testid":`billing-sessions-table`,children:[ve!==void 0&&(0,m.jsx)(`div`,{className:z.staleNotice,"data-testid":`billing-session-nav-notice`,role:`note`,children:ve}),(0,m.jsxs)(`table`,{className:z.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`sessionTitle`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`actual`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`lastActive`)})]})}),(0,m.jsxs)(`tbody`,{children:[yt.length===0&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:4,className:z.emptyRow,children:t(`noData`)})}),yt.slice(0,20).map(e=>{let n=e.children!==void 0||e.subs!==void 0,r=n&&ft.has(e.id),i=Pi(e);return(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{className:n?z.sessionGroupRow:void 0,"aria-expanded":n?r:void 0,tabIndex:n?0:void 0,onClick:n?()=>{vt(e.id)}:void 0,onKeyDown:n?t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),vt(e.id))}:void 0,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:z.modelName,children:(0,m.jsxs)(`button`,{type:`button`,className:z.sessionLink,"data-testid":`billing-session-open`,title:t(`sessionOpen`),onClick:t=>{t.stopPropagation(),be(e.id)},children:[e.title??`${t(`sessionUntitled`)} · ${e.id.slice(0,8)}`,(e.mergedCount??1)>1?` ×${e.mergedCount}`:``]})}),e.stale===!0&&(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),"data-testid":`billing-session-stale`,children:t(`sessionStaleBadge`)}),(i.calls>0||i.cost>0)&&(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),"data-testid":`billing-session-sub`,children:i.cost>0?t(`sessionSubCost`).replace(`{cost}`,W(i.cost)):t(`sessionSubCalls`).replace(`{calls}`,i.calls.toLocaleString())})]}),bt(e)]}),r&&e.children?.map(e=>(0,m.jsxs)(`tr`,{className:z.sessionChildRow,children:[(0,m.jsx)(`td`,{children:(0,m.jsx)(`button`,{type:`button`,className:z.sessionLink,"data-testid":`billing-session-open`,title:t(`sessionOpen`),onClick:t=>{t.stopPropagation(),be(e.id)},children:(0,m.jsx)(`span`,{className:z.modelProvider,children:e.id.slice(0,8)})})}),bt(e)]},e.id)),r&&e.subs?.map(e=>xt(e,0))]},e.id)})]})]})]}),mt&&(0,m.jsxs)(`div`,{className:z.sessionViewer,"data-testid":`billing-session-viewer`,children:[(0,m.jsxs)(`div`,{className:z.sessionViewerHead,children:[(0,m.jsx)(`h3`,{className:z.sessionViewerTitle,children:t(`sessions`)}),(0,m.jsx)(`input`,{className:z.ubSearch,type:`search`,value:gt,placeholder:t(`sessionViewerSearch`),"aria-label":t(`sessionViewerSearch`),"data-testid":`billing-session-viewer-search`,onChange:e=>{_t(e.target.value)}}),(0,m.jsx)(`button`,{type:`button`,className:z.exportButton,"data-testid":`billing-session-viewer-close`,onClick:()=>{ht(!1),_t(``)},children:t(`close`)})]}),(0,m.jsx)(`div`,{className:z.sessionViewerList,"data-testid":`billing-session-viewer-list`,children:(0,m.jsxs)(`table`,{className:z.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`sessionTitle`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`calls`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`actual`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`lastActive`)})]})}),(0,m.jsxs)(`tbody`,{children:[Ct.length===0&&(0,m.jsx)(`tr`,{children:(0,m.jsx)(`td`,{colSpan:4,className:z.emptyRow,children:t(`noData`)})}),Ct.map(e=>(0,m.jsxs)(`tr`,{children:[(0,m.jsxs)(`td`,{children:[(0,m.jsxs)(`span`,{className:z.modelName,children:[e.title??`${t(`sessionUntitled`)} · ${e.id.slice(0,8)}`,(e.mergedCount??1)>1?` ×${e.mergedCount}`:``]}),e.cwd!==void 0&&(0,m.jsx)(`span`,{className:z.modelProvider,children:ua(e.cwd)}),e.stale===!0&&(0,m.jsx)(`span`,{className:y(z.ubTag,z.ubTagNeutral),children:t(`sessionStaleBadge`)})]}),(0,m.jsx)(`td`,{className:z.numCol,children:e.calls.toLocaleString()}),(0,m.jsx)(`td`,{className:z.numCol,children:W(e.cost)}),(0,m.jsx)(`td`,{className:z.numCol,children:e.lastActive>0?`${K(e.lastActive)} ${Fi(e.lastActive)}`:`—`})]},e.id))]})]})})]})]})]}),F===`token`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-token`,children:[(0,m.jsx)(kn,{stats:e,trendDays:je,onTrendDays:Me,models:Xn,money:W,t}),e.perf!==void 0&&(0,m.jsxs)(`section`,{className:z.panel,"data-testid":`billing-panel-perf`,children:[(0,m.jsxs)(`div`,{className:z.panelHead,children:[(0,m.jsx)(`h3`,{className:z.panelTitle,children:t(`perfTitle`)}),(0,m.jsx)(`span`,{className:z.panelHint,children:t(`perfHint`)})]}),(0,m.jsx)(Vn,{perf:e.perf,models:Xn,t})]})]}),F===`pricing`&&(0,m.jsxs)(`div`,{className:z.tabPanel,"data-testid":`billing-tab-panel-pricing`,children:[(0,m.jsxs)(`div`,{className:z.ubAlert,role:`note`,children:[(0,m.jsxs)(`div`,{className:z.ubAlertLeft,children:[(0,m.jsxs)(`span`,{className:z.ubRate,"data-testid":`billing-rate`,children:[t(`todayRate`),` 1 USD = `,dn(Nt.rate)]}),(0,m.jsx)(`span`,{className:y(z.ubTag,Nt.live?z.ubTagSuccess:z.ubTagNeutral),children:Nt.live?t(`rateLive`):t(`rateBuiltin`)}),zt>0&&(0,m.jsxs)(`span`,{className:z.ubTag,"data-testid":`billing-pricing-synced`,children:[t(`pricingSyncedAt`),` `,new Date(zt).toLocaleTimeString(Vt===`zh`?`zh-CN`:`en-US`,{hour:`2-digit`,minute:`2-digit`})]}),(0,m.jsx)(`button`,{type:`button`,className:z.heatmapRangeButton,"data-testid":`billing-pricing-sync`,disabled:It,onClick:Rt,children:t(It?`pricingSyncing`:`pricingSyncNow`)})]}),(0,m.jsx)(`p`,{className:z.ubAlertNote,children:t(`pricingTip`)})]}),(0,m.jsxs)(`section`,{className:z.ubCard,"data-testid":`billing-panel-pricing`,children:[(0,m.jsxs)(`div`,{className:z.ubCardHead,children:[(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`pricing`)}),(0,m.jsx)(`span`,{className:z.ubCardSub,children:t(`pricingUnit`)}),(0,m.jsx)(`input`,{className:z.ubSearch,type:`search`,value:G,placeholder:t(`pricingSearch`),"aria-label":t(`pricingSearch`),"data-testid":`billing-pricing-search`,onChange:e=>{Ut(e.target.value)}})]}),(0,m.jsx)(`div`,{className:y(z.ubTablewrap,z.ubTablewrapPricing),"data-testid":`billing-pricing-table`,children:(0,m.jsxs)(`table`,{className:z.ubTable,children:[(0,m.jsx)(`thead`,{children:(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`th`,{children:t(`thModel`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`thInputMiss`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`thInputHit`)}),(0,m.jsx)(`th`,{className:z.numCol,children:t(`output`)}),(0,m.jsx)(`th`,{className:z.numCol,colSpan:2,children:t(`band`)})]})}),(0,m.jsx)(`tbody`,{children:ur(on(),G).map(e=>{let n=e.price.input>0||e.price.output>0;return(0,m.jsxs)(d.Fragment,{children:[(0,m.jsxs)(`tr`,{children:[(0,m.jsx)(`td`,{children:(0,m.jsxs)(`span`,{className:z.ubModel,children:[(()=>{let n=sr(Ft(Kt,Pt(e.key,Jt)),Yt);if(n===null)return null;let r=Wt.includes(e.key),i=`${e.name} · ${t(n===`peak`?`peak`:`offPeak`)} · ${t(`bandPinHint`)}`;return(0,m.jsx)(`button`,{type:`button`,className:y(z.bandDot,z[n],r&&z.bandDotOn),"data-testid":`billing-band-dot`,"aria-pressed":r,"aria-label":i,title:i,onClick:()=>{Gt(Pe(e.key)),window.dispatchEvent(new CustomEvent(`dsh.ui-usage-billing.pinned-pref`))}})})(),(0,m.jsxs)(`span`,{className:z.ubModelName,children:[e.name,e.uncatalogued&&(0,m.jsx)(`span`,{className:z.ubTagAlert,"data-testid":`billing-price-uncatalogued`,children:t(`uncatalogued`)}),e.promo!==void 0&&rn(e.promo,Date.now())&&(0,m.jsx)(p.Tooltip,{label:[e.promo.note,e.promo.endsAtMs===void 0?t(`promoOpenEnded`):t(`promoUntil`,{date:new Date(e.promo.endsAtMs).toLocaleDateString()})].filter(Boolean).join(` · `),side:`top`,maxWidth:280,children:(0,m.jsx)(`span`,{className:z.ubTagPromo,"data-testid":`billing-price-promo`,children:t(`promoBadge`)})})]})]})}),(0,m.jsx)(`td`,{className:z.numCol,children:n?Xt(e.price.input,e.price.currency):(0,m.jsx)(`span`,{className:z.na,children:`—`})}),(0,m.jsx)(`td`,{className:z.numCol,children:n?Xt(e.price.cacheHit,e.price.currency):(0,m.jsx)(`span`,{className:z.na,children:`—`})}),(0,m.jsx)(`td`,{className:z.numCol,children:n?Xt(e.price.output,e.price.currency):(0,m.jsx)(`span`,{className:z.na,children:`—`})}),n&&e.price.offPeak!==void 0&&e.peakHours!==void 0?(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`td`,{className:z.numCol,children:(0,m.jsxs)(`span`,{className:z.ubChipPeak,children:[(0,m.jsx)(`span`,{className:z.ubChipLabel,children:e.tierSemantics===`latency`?t(`ubStd`):t(`ubPeak`)}),(0,m.jsxs)(`span`,{children:[Xt(e.price.input,e.price.currency),`/`,Xt(e.price.output,e.price.currency)]})]})}),(0,m.jsx)(`td`,{className:z.numCol,children:(0,m.jsxs)(`span`,{className:z.ubChipOff,children:[(0,m.jsx)(`span`,{className:z.ubChipLabel,children:e.tierSemantics===`latency`?`Flex`:t(`ubOff`)}),(0,m.jsxs)(`span`,{children:[Xt(e.price.offPeak.input,e.price.currency),` / `,Xt(e.price.offPeak.output,e.price.currency)]})]})})]}):(0,m.jsx)(`td`,{className:z.numCol,colSpan:2,children:n?(0,m.jsx)(`span`,{className:z.flatTag,children:t(`flat`)}):(0,m.jsx)(`span`,{className:z.na,children:`—`})})]}),(e.extraRows??[]).map(t=>(0,m.jsxs)(`tr`,{className:z.ubExtraRow,children:[(0,m.jsxs)(`td`,{children:[(0,m.jsx)(`span`,{className:z.ubExtraName,children:lr(t.label,Vt)}),t.note!==void 0&&(0,m.jsx)(`span`,{className:z.ubExtraNote,children:lr(t.note,Vt)})]}),(0,m.jsx)(`td`,{className:z.numCol,children:t.input===void 0?(0,m.jsx)(`span`,{className:z.na,children:`—`}):Xt(t.input,e.price.currency)}),(0,m.jsx)(`td`,{className:z.numCol,children:(0,m.jsx)(`span`,{className:z.na,children:`—`})}),(0,m.jsx)(`td`,{className:z.numCol,children:t.output===void 0?(0,m.jsx)(`span`,{className:z.na,children:`—`}):Xt(t.output,e.price.currency)}),(0,m.jsx)(`td`,{className:z.numCol,colSpan:2,children:(0,m.jsx)(`span`,{className:z.na,children:`—`})})]},`${e.key}:${t.label}`))]},e.key)})})]})})]}),(0,m.jsxs)(`section`,{className:z.ubCard,children:[(0,m.jsx)(`div`,{className:z.ubCardHead,children:(0,m.jsx)(`h3`,{className:z.ubCardTitle,children:t(`pricingNotes`)})}),(0,m.jsxs)(`ul`,{className:z.ubNotes,children:[(0,m.jsxs)(`li`,{className:z.ubNotesItem,children:[(0,m.jsx)(`span`,{className:z.ubNotesTerm,children:t(`cacheHit`)}),(0,m.jsx)(`span`,{className:z.ubNotesDesc,children:t(`noteCache`)})]}),(0,m.jsxs)(`li`,{className:z.ubNotesItem,children:[(0,m.jsx)(`span`,{className:z.ubNotesTerm,children:t(`peakBand`)}),(0,m.jsx)(`span`,{className:z.ubNotesDesc,children:t(`noteBand`)})]}),(0,m.jsxs)(`li`,{className:z.ubNotesItem,children:[(0,m.jsx)(`span`,{className:z.ubNotesTerm,children:t(`pricingSource`)}),(0,m.jsx)(`span`,{className:z.ubNotesDesc,children:t(`noteSource`)})]})]})]})]}),!r&&b(`billing.dashboard.decor`,{position:`footer`})]}),!r&&(0,m.jsxs)(`footer`,{className:z.modalFooter,"data-testid":`billing-footer`,children:[(0,m.jsx)(`span`,{children:t(`footer`)}),(0,m.jsx)(`span`,{children:t(`footerCredit`).replace(`{version}`,e.pluginVersion===void 0?`—`:`v${e.pluginVersion}`)})]})]});return r?er:(0,m.jsx)(p.Modal,{open:!0,onClose:n,title:t(`title`),headless:!0,className:y(z.dashboardModal,`dsh-billing-modal`),children:er})}function ua(e){return e.split(/[\\/]/).filter(Boolean).at(-1)??`—`}let da={display:[`显示`,`密度`,`动效`,`紧凑`,`舒适`,`克制`,`丰富`,`display`,`density`,`motion`,`compact`,`comfortable`],budget:[`预算`,`金额`,`本月`,`花费`,`进度`,`budget`,`amount`,`spend`,`progress`],alert:[`峰谷`,`峰`,`谷`,`提醒`,`通知`,`预览`,`切换`,`peak`,`off-peak`,`alert`,`notify`,`preview`],toggles:[`usage_stats`,`工具`,`即时代费`,`胶囊`,`中转站`,`站点`,`隐藏`,`低谷`,`队列`,`relay`,`site`,`live`,`cost`,`hide`,`queue`,`off-peak`],displayExtra:[`悬浮`,`订阅`,`计费卡`,`指标`,`环比`,`主数字`,`侧栏`,`入口`,`隐藏`,`float`,`subscription`,`card`,`metric`,`delta`,`sidebar`,`trigger`,`hidden`],advanced:[`自定义`,`单价`,`价格`,`低谷`,`custom`,`price`],about:[`关于`,`版本`,`作者`,`许可`,`仓库`,`about`,`version`,`author`,`license`,`repo`]};function fa(e){return Object.values(da).every(t=>Di(e,t))}let pa=[`below`,`above`,`toolbar`];function ma({liveCostPrefs:e,onLiveCostPrefs:t,t:n}){let[r,i]=(0,d.useState)(!1),a={below:n(`liveCostBarPosBelow`),above:n(`liveCostBarPosAbove`),toolbar:n(`liveCostBarPosToolbar`)},o=pa.map(e=>({id:e,label:a[e]}));return(0,m.jsx)(p.Menu,{open:r,align:`end`,portal:!0,compact:!0,items:o,selectedId:e.position,onSelect:n=>{i(!1);let r=pa.find(e=>e===n);r!==void 0&&t({...e,position:r})},onClose:()=>{i(!1)},anchor:(0,m.jsxs)(`button`,{type:`button`,className:z.rdoSelect,"data-testid":`billing-livecost-position-select`,"aria-haspopup":`menu`,"aria-expanded":r,onClick:()=>{i(!r)},children:[(0,m.jsx)(`span`,{children:a[e.position]}),(0,m.jsx)(`span`,{className:y(z.rdoChevron,r&&z.rdoChevronOpen),"aria-hidden":!0,children:Lr?(0,m.jsx)(Lr,{}):null})]})})}function ha(e){let{t,checkModels:n,publishCosts:r,registerOpen:i,navigateToSession:a,renderSlot:o,useStore:s,actions:c,embeddedSettings:l=!1}=e,[u,f]=(0,d.useState)(Ar),[p,h]=(0,d.useState)(Mr),[g,_]=(0,d.useState)([]),[v,y]=(0,d.useState)(void 0),[b,x]=(0,d.useState)(!1),[S,C]=(0,d.useState)([]),[w,T]=(0,d.useState)(!1),[ee,O]=(0,d.useState)([]),[k,N]=(0,d.useState)(()=>xe()),[re,ie]=(0,d.useState)(()=>Me()),ae=(0,d.useCallback)(e=>{ie(e),Ne(e),window.dispatchEvent(new CustomEvent(`dsh.ui-usage-billing.language-pref`))},[]),oe=(0,d.useCallback)(e=>{N(e),Se(e),window.dispatchEvent(new CustomEvent(be))},[]),[se,ce]=(0,d.useState)(()=>E()),le=(0,d.useCallback)(e=>{ce(e),D(e)},[]),[ue,de]=(0,d.useState)(()=>fe()),me=(0,d.useCallback)(e=>{de(e),pe(e)},[]),[he,ye]=(0,d.useState)(()=>_e()),Ce=(0,d.useCallback)(e=>{ye(e),ve(e),window.dispatchEvent(new CustomEvent(ge))},[]),[we,Te]=(0,d.useState)(()=>Xe());(0,d.useEffect)(()=>{let e=()=>{Te(Xe())};return window.addEventListener(Ye,e),()=>{window.removeEventListener(Ye,e)}},[]);let P=(0,d.useCallback)(e=>{let t={...Xe(),showEntry:e.showEntry};Te(t),Ze({showEntry:t.showEntry})},[]),[F,Ee]=(0,d.useState)(()=>j());(0,d.useEffect)(()=>te(()=>{Ee(j())}),[]);let De=e.recoveryEntryAvailable,Oe=(0,d.useMemo)(()=>({...F,mode:ne(F.mode,De)}),[F,De]),ke=(0,d.useCallback)(e=>{let t={...e,mode:ne(e.mode,De)};Ee(t),M(t),window.dispatchEvent(new CustomEvent(A))},[De]),[Ae,je]=(0,d.useState)(()=>{let e=Fe();return ft(e),e}),Pe=(0,d.useCallback)(e=>{je(e),ft(e),Ie(e)},[]),I=(0,d.useMemo)(()=>gi(u),[u,Ae]),Le=re,L=(0,d.useCallback)((e,n)=>{let r=(Le===`en`?tt:et)[e]??t(e);if(n===void 0)return r;let i=r;for(let[e,t]of Object.entries(n))i=i.replaceAll(`{${e}}`,String(t));return i},[Le,t]),[Re,ze]=(0,d.useState)(!1),Be=(0,d.useCallback)(()=>{ze(!1)},[]),Ve=(0,d.useRef)(!1),He=(0,d.useCallback)((e=!1)=>{Ve.current&&!e||(Ve.current=!0,Promise.all([Ii().then(e=>{e!==null&&f(e)}),Li().then(({balances:e,reconcile:t,stale:n})=>{e.length>0&&_(e),y(t),x(n===!0)}),Ri().then(({quotas:e,stale:t})=>{e.length>0?(C(e),T(t===!0)):T(!1)}).catch(()=>{T(!0)}),zi().then(e=>{O(e)}).catch(()=>{})]).catch(()=>{}).finally(()=>{Ve.current=!1}))},[]),Ue=(0,d.useCallback)(()=>{He(!0),Wi(),ze(!0)},[He]);(0,d.useEffect)(()=>{He(),Wi()},[He]);let[We,Ge]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{Ge(!document.hidden),document.hidden||(He(!0),Wi())};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[He]),(0,d.useEffect)(()=>{if(!We)return;let e=setInterval(()=>{He(),Wi()},Re?kr:3e5);return()=>{clearInterval(e)}},[He,Re,We]),(0,d.useEffect)(()=>{let e=!0;return n().then(t=>{e&&(h(t),yt(t.catalog??[]))}),()=>{e=!1}},[n]);let R=K(),Ke=Object.entries(I.byDay).filter(([e])=>e.startsWith(R.slice(0,7))).reduce((e,[,t])=>e+t.cost,0),qe=I.byDay[R]?.cost??0,Je=new Date;Je.setDate(Je.getDate()-1);let Qe=`${Je.getFullYear()}-${String(Je.getMonth()+1).padStart(2,`0`)}-${String(Je.getDate()).padStart(2,`0`)}`,z=I.byDay[Qe]?.cost??0,$e=z>0?(qe-z)/z*100:0,nt=Gr(I.byDay,R),rt=(0,d.useMemo)(()=>Wr(I.byDay).map(e=>{let t=I.byDay[e.date];return{date:e.date,cost:e.cost,tokens:t===void 0?0:Ur(t)}}),[I.byDay]),it=Object.entries(I.byDay).filter(([e])=>e.startsWith(R.slice(0,7))).reduce((e,[,t])=>e+Ur(t),0),at=(()=>{let e=I.byDay[R];return e===void 0?0:Ur(e)})(),ot=Gr(I.byDay,R,Ur),B=s(e=>e.enabled),st=s(e=>e.amount),V=s(e=>e.tierAlertDays),ct=s(e=>e.lastTierSwitchAt),[H,lt]=(0,d.useState)(()=>wr()),[ut,dt]=(0,d.useState)(null),[pt,mt]=(0,d.useState)(null),[ht,gt]=(0,d.useState)(0),[_t,vt]=(0,d.useState)(!1);(0,d.useEffect)(()=>{if(!H.enabled){gt(0),vt(!1);return}let e=!1,t=!1;vt(!1);let n=()=>{t||(t=!0,Ji().then(t=>{e||gt(t.supported?t.queuedCount:0)}).catch(()=>{e||gt(0)}).finally(()=>{t=!1,e||vt(!0)}))};n();let r=setInterval(n,kr);return()=>{e=!0,clearInterval(r)}},[H.enabled]),(0,d.useEffect)(()=>{dt(e=>Cr(e,ht))},[ht]);let[bt,xt]=(0,d.useState)(()=>Date.now());(0,d.useEffect)(()=>{if(!H.enabled)return;let e=setInterval(()=>xt(Date.now()),kr);return()=>{clearInterval(e)}},[H.enabled]);let Ct=(0,d.useCallback)(e=>{lt(e),Tr(e)},[]),wt=S.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`),Et=Pt(u.byTurn?.[0]?.model,wt),Dt=(0,d.useCallback)(()=>{mt({entering:Tt(Date.now())===`peak`?`offPeak`:`peak`,atMs:Date.now()+18e4,channel:Et})},[Et]),U=st>0?st:u.budget??0,Ot=B&&U>0?Ke/U>=1?`over`:Ke/U>=.8?`warn`:`none`:`none`,kt=(0,d.useCallback)(()=>{let e=!B;c.setEnabled(e),e&&typeof Notification<`u`&&Notification.permission==="default"&&Notification.requestPermission()},[c,B]);(0,d.useEffect)(()=>{if(!B||U<=0)return;let e=Ke/U*100,t=Or.filter(t=>e>=t&&V?.[String(t)]!==R);if(t.length===0)return;let n=t[t.length-1]??100;if(c.markTierAlerted(t,R),!yi())return;let r=L(`budgetTierBody`).replace(`{cost}`,dn(Ke)).replace(`{budget}`,dn(U)).replace(`{pct}`,String(n));bi(`budget:${n}:${R}`,()=>{new Notification(L(`budget`),{body:r})})},[B,U,Ke,V,R,c,L]),(0,d.useEffect)(()=>{if(H.enabled&&!_t)return;let e=Sr(Er(bt,H,ct,Et),ht>0?Er(bt,H,ct,`deepseek-metered`):null,ht);if(e===null||(c.markTierSwitchAlerted(e.atMs),dt(e),!H.webNotify||!yi()))return;let t=Math.max(1,Math.round((e.atMs-bt)/6e4)),n=L(e.entering===`peak`?`peakAlertTitlePeak`:`peakAlertTitleOff`),r=L(e.channel===`zhipu-coding-plan`?e.entering===`peak`?`tierAlertEnterPeakZhipu`:`tierAlertEnterOffZhipu`:e.entering===`peak`?`tierAlertEnterPeak`:`tierAlertEnterOff`).replace(`{minutes}`,String(t)),i=e.queueCount===void 0?``:` ${L(e.entering===`peak`?`peakAlertQueuePeak`:`peakAlertQueueOff`,{count:e.queueCount})}`;bi(`peak:${e.atMs}`,()=>{new Notification(n,{body:`${r}${i}`})})},[bt,ct,H,Et,ht,_t,c,L]);let At=s(e=>e.lastBalanceAlertDay),jt=s(e=>e.modelBudgets??ir),Mt=s(e=>e.modelTierAlertDays??ar),Nt=(0,d.useMemo)(()=>Yr(I.byDayModels,R.slice(0,7)),[I.byDayModels,R]),Ft=I.lowBalanceThreshold??50,It=(0,d.useMemo)(()=>{if(g.length===0)return;let e=Rr(I.byDay,R),t=St().rate;for(let n of g){if(n.totalBalance===void 0||n.error!==void 0)continue;let r=n.currency===`USD`?n.totalBalance*t:n.totalBalance;if(r>=Ft)continue;let i=e>0?Math.floor(r/e):void 0;return{name:n.displayName,cny:r,days:i}}},[g,I.lowBalanceThreshold,I.byDay,R]);(0,d.useEffect)(()=>{if(It===void 0||At===R||(c.markBalanceAlerted(R),!yi()))return;let e=L(`balanceLowBody`).replace(`{name}`,It.name).replace(`{balance}`,dn(It.cny)).replace(`{days}`,It.days===void 0?`—`:String(It.days));bi(`balance:${R}`,()=>{new Notification(L(`balance`),{body:e})})},[It,At,R,c,L]),(0,d.useEffect)(()=>{let e=[],t;for(let[n,r]of Object.entries(jt)){if(!(r>0))continue;let i=Nt[n]??0;for(let a of Zr(i,r)){let o=`${n}:${a}`;Mt[o]!==R&&(e.push(o),(t===void 0||a>t.tier)&&(t={model:n,tier:a,cost:i,budget:r}))}}if(e.length===0||t===void 0||(c.markModelTierAlerted(e,R),!yi()))return;let n=L(`modelBudgetBody`).replace(`{model}`,t.model).replace(`{cost}`,dn(t.cost)).replace(`{budget}`,dn(t.budget)).replace(`{pct}`,String(t.tier));bi(`model-budget:${t.model}:${t.tier}:${R}`,()=>{new Notification(L(`modelBudgetTitle`),{body:n})})},[jt,Nt,Mt,R,c,L]);let Lt=(0,d.useMemo)(()=>{let e=R.slice(0,7),t=new Map;for(let[n,r]of Object.entries(I.byDayModels??{}))if(n.startsWith(e))for(let[e,n]of Object.entries(r)){if(n.cost<=0)continue;let r=tn(e).provider,i=I.byModel?.[e]?.plan===!0,a=t.get(r)??{cost:0,plan:i};a.cost+=n.cost,i||(a.plan=!1),t.set(r,a)}let n,r;for(let e of t){let t=e[1].plan?r:n;(t===void 0||e[1].cost>t[1].cost)&&(e[1].plan?r=e:n=e)}let i=e=>{let t=g.find(t=>Q(t.provider)===Q(e));if(t===void 0||t.totalBalance===void 0){if(e===`Custom`){let e=g.filter(e=>e.totalBalance!==void 0&&e.error===void 0),t=e[0];return t!==void 0&&e.length===1?i(t.provider):void 0}return{text:t?.error===`unauthorized`?L(`balanceUnauthorized`):t?.error===`unreachable`||t?.error===`invalid`?L(`balanceUnreachable`):L(`balanceUnconfigured`),low:!1}}let n=t.currency===`USD`?`$${t.totalBalance.toFixed(2)}`:dn(t.totalBalance),r=St().rate;return{text:n,low:(t.currency===`USD`?t.totalBalance*r:t.totalBalance)<Ft}},a=e=>{let t=S.find(t=>t.displayName===e||ri(t.provider)===e);if(t===void 0||t.windows.length===0)return{text:L(`subscriptionNoApi`),low:!1};let n=t.windows.reduce((e,t)=>Math.min(e,t.remainingPercent),100);return{text:n<=0?L(`subscriptionExhausted`):L(`subscriptionRemaining`).replace(`{pct}`,String(n)),low:n<20}},o=n===void 0?void 0:i(n[0]);return{direct:n===void 0||o===void 0?void 0:{name:n[0],...o},sub:r===void 0?void 0:{name:r[0],...a(r[0])}}},[I.byDayModels,I.byModel,I.lowBalanceThreshold,g,S,R,L]),Rt=(0,d.useMemo)(()=>{let e=I.total;return{input:e.input,output:e.output,cacheRead:e.cacheHit,cacheMiss:e.cacheMiss,calls:e.calls}},[I]);(0,d.useEffect)(()=>{r({todayCost:qe,monthCost:Ke})},[qe,Ke,r]),(0,d.useEffect)(()=>{if(!l)return i(Ue)},[l,i,Ue]);let zt=(0,d.useMemo)(()=>u.byTurn??[],[u.byTurn]);return(0,m.jsxs)(m.Fragment,{children:[!l&&(0,m.jsx)(aa,{...e,t:L,currency:k,onOpen:Ue,monthCost:Ke,todayCost:qe,weekCost:nt,days:rt,vendorStatus:Lt,dash:Rt,cardPrefs:Oe,monthTokens:it,todayTokens:at,weekTokens:ot,floatPrefs:se,subscriptions:S,budgetPressure:Ot,deltaPct:$e}),(l||Re)&&(0,m.jsx)(la,{stats:I,t:L,onClose:Be,embeddedSettings:l,navigateToSession:a,userPrices:Ae,onUserPrices:Pe,health:p,balances:g,...v===void 0?{}:{reconcile:v},quotas:S,relayQuotas:ee,currency:k,onCurrency:oe,language:re,onLanguage:ae,turns:zt,renderSlot:o,budgetEnabled:B,budgetAmount:U,modelBudgets:jt,monthModelCost:Nt,onModelBudget:c.setModelBudget,onToggleBudget:kt,onBudgetAmount:c.setAmount,peakConfig:H,onPeakConfig:Ct,onPreviewPeak:Dt,floatPrefs:se,onFloatPrefs:le,cardPrefs:Oe,onCardPrefs:ke,recoveryEntryAvailable:De,sitePrefs:ue,onSitePrefs:me,liveCostPrefs:he,onLiveCostPrefs:Ce,quickQueuePrefs:we,onQuickQueuePrefs:P,quotasStale:w,balanceStale:b}),(ut!==null||pt!==null)&&(0,m.jsx)(Dr,{hit:ut??pt,config:H,t:L,onDismiss:()=>{dt(null),mt(null)}})]})}function ga(e){return(0,m.jsx)(`div`,{className:z.nativeSettingsRoot,"data-testid":`native-billing-settings`,children:(0,m.jsx)(ha,{...e,renderSlot:()=>null,wide:!0,embeddedSettings:!0})})}function _a(e,t){if(t===void 0||e?.bySession===void 0)return 0;let n=e.bySession.find(e=>e.id===t);return(n?.cost??0)+(n?.subCost??0)}function va(e,t){return t===void 0||e?.bySession===void 0?0:e.bySession.find(e=>e.id===t)?.subCost??0}function ya(e,t){if(t===void 0||e?.byTurn===void 0)return 0;let n=0,r=-1;for(let i of e.byTurn)i.sessionId===t&&(r===-1||i.turn>r)&&(r=i.turn,n=i.cost);return n}function ba(e,t=20){let n=[];for(let r of e)if(r.status===`ok`)for(let e of r.windows)e.remainingPercent>t||n.push({name:r.displayName,kind:e.kind,pct:e.remainingPercent});return n.sort((e,t)=>e.pct-t.pct).slice(0,3)}function xa(e,t){if(t===void 0||e?.byTurn===void 0)return;let n=-1,r;for(let i of e.byTurn)i.sessionId===t&&(n===-1||i.turn>n)&&(n=i.turn,r=i.model);return r}async function Sa(){try{let e=await _i(`/api/billing/usage-stats`);if(!e.ok)return null;let t=await e.text(),n=JSON.parse(t);if(typeof n!=`object`||!n)return null;let r=n;return{...Array.isArray(r.bySession)?{bySession:r.bySession}:{},...Array.isArray(r.byTurn)?{byTurn:r.byTurn}:{}}}catch{return null}}async function Ca(){try{let e=await _i(`/api/billing/subscriptions`);if(!e.ok)return[];let t=JSON.parse(await e.text());if(typeof t!=`object`||!t||!(`quotas`in t))return[];let n=t.quotas;return Array.isArray(n)?n:[]}catch{return[]}}function wa(e){switch(e){case`session`:return`subscriptionSession`;case`weekly`:return`subscriptionWeekly`;case`monthly`:return`subscriptionMonthly`;default:return`subscriptionBilling`}}function Ta(e){return!e.running&&!e.promptAttempted&&(e.blank||e.awaitingFirstTurn)}function Ea({hasBandPlan:e}){let[t,n]=(0,d.useState)(()=>Te()),[r,i]=(0,d.useState)(()=>Date.now());if((0,d.useEffect)(()=>{let e=()=>{n(Te())};window.addEventListener(we,e),window.addEventListener(`storage`,e);let t=setInterval(()=>{i(Date.now())},3e4);return()=>{window.removeEventListener(we,e),window.removeEventListener(`storage`,e),clearInterval(t)}},[]),t.length===0)return null;let a=wr().leadMin*6e4,o=t.map(t=>({key:t,state:sr(Ft(r,Pt(t,e)),a)})).filter(e=>e.state!==null);return o.length===0?null:(0,m.jsx)(`span`,{className:z.bandDots,"data-testid":`billing-pinned-dots`,children:o.map(e=>(0,m.jsx)(`span`,{className:y(z.bandDot,z.bandDotOn,z[e.state]),role:`img`,"aria-label":e.key,title:e.key},e.key))})}function Da(){let[e,t]=(0,d.useState)(()=>xe());return(0,d.useEffect)(()=>{let e=()=>{t(xe())};return window.addEventListener(be,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(be,e),window.removeEventListener(`storage`,e)}},[]),e}function Oa(){let[e,t]=(0,d.useState)(()=>_e().show),[n,r]=(0,d.useState)(()=>_e().position);return(0,d.useEffect)(()=>{let e=()=>{t(_e().show),r(_e().position)};return window.addEventListener(ge,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(ge,e),window.removeEventListener(`storage`,e)}},[]),{visible:e,position:n}}function ka(e,t){let[n,r]=(0,d.useState)(null),[i,a]=(0,d.useState)([]),[o,s]=(0,d.useState)(()=>Date.now()),[c,l]=(0,d.useState)(()=>typeof document>`u`||!document.hidden);(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{l(!document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[]),(0,d.useEffect)(()=>{if(!c||!t)return;let e=!1,n=!1,i=()=>{n||(n=!0,e||s(Date.now()),Promise.all([Sa(),Ca()]).then(([t,n])=>{e||(t!==null&&r(t),a(n))}).catch(()=>{}).finally(()=>{n=!1}))};i();let o=setInterval(i,3e4);return()=>{e=!0,clearInterval(o)}},[e,c,t]);let u=(0,d.useMemo)(()=>_a(n,e),[n,e]),f=(0,d.useMemo)(()=>va(n,e),[n,e]),p=(0,d.useMemo)(()=>ya(n,e),[n,e]),m=(0,d.useMemo)(()=>ba(i),[i]),h=(0,d.useMemo)(()=>Pt(xa(n,e),i.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`)),[n,e,i]);return{sessionCost:u,subCost:f,turnCost:p,tier:(0,d.useMemo)(()=>Ft(o,h),[o,h]),chips:m,hasBandPlan:i.some(e=>e.displayName===`Z.ai Coding Plan`&&e.status===`ok`)}}function Aa({sessionId:e,t,seat:n,session:r}){let{visible:i,position:a}=Oa(),o=i&&a===n&&!(n===`above`&&r!==void 0&&Ta(r)),{sessionCost:s,subCost:c,turnCost:l,tier:u,chips:d,hasBandPlan:f}=ka(e,o),p=Da(),h=e=>dn(un(e,p),p),g=s>0||l>0,_=u?.tier===`peak`;return o?(0,m.jsxs)(`span`,{className:n===`above`?y(z.feeBar,z.feeBarAbove):z.feeBar,"data-testid":`billing-live-cost-bar`,"data-seat":n,children:[(0,m.jsx)(Ea,{hasBandPlan:f}),u!==null&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:_?z.feeChipPrimary:z.feeChipOff,"data-testid":`billing-live-tier`,children:t(_?`tierPeak`:`tierOff`)}),(0,m.jsx)(`span`,{className:z.feeCount,children:Lt(u.nextSwitchInMs)}),(0,m.jsx)(`span`,{className:z.feeSuffix,children:t(_?`tierToOff`:`tierToPeak`)})]}),g&&(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(`span`,{className:z.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:z.feeItem,"data-testid":`billing-live-turn`,children:[t(`liveTurn`),` `,(0,m.jsx)(`span`,{className:z.feeNum,"data-tick":`turn`,children:h(l)})]}),(0,m.jsx)(`span`,{className:z.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:z.feeItem,"data-testid":`billing-live-session`,children:[t(`liveSession`),` `,(0,m.jsx)(`span`,{className:z.feeNum,"data-tick":`session`,children:h(s)}),c>0&&(0,m.jsx)(`span`,{className:z.feeSuffix,"data-testid":`billing-live-session-sub`,children:t(`liveSessionSub`).replace(`{cost}`,h(c))})]})]}),d.map(e=>(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`span`,{className:z.feeSep,"aria-hidden":`true`,children:`·`}),(0,m.jsxs)(`span`,{className:e.pct<=10?z.feeChipError:z.feeChipAlert,"data-testid":`billing-live-quota`,children:[e.name,` `,t(wa(e.kind)),` `,e.pct,`%`]})]},`${e.name}:${e.kind}`))]}):null}function ja({sessionId:e,t}){let n=Da(),r=e=>dn(un(e,n),n),{visible:i,position:a}=Oa(),{sessionCost:o,subCost:s,turnCost:c,tier:l,chips:u,hasBandPlan:d}=ka(e,i&&a===`toolbar`);if(!i||a!==`toolbar`)return null;let f=l?.tier===`peak`,h=u.reduce((e,t)=>Math.min(e,t.pct),100),g=h<=10?z.feeInlineError:h<=20?z.feeInlineAlert:void 0,_=y(z.feeInline,g),v=[...l===null?[]:[`${Lt(l.nextSwitchInMs)} ${t(f?`tierToOff`:`tierToPeak`)}`],`${t(`liveTurn`)} ${r(c)}`,`${t(`liveSession`)} ${r(o)}`,...s>0?[t(`liveSessionSub`).replace(`{cost}`,r(s))]:[],...u.map(e=>`${e.name} ${t(wa(e.kind))} ${e.pct}%`)].join(` · `);return(0,m.jsx)(p.Tooltip,{label:v,side:`top`,delayMs:500,portal:!0,children:(0,m.jsxs)(`span`,{className:_,"data-testid":`billing-live-cost-chip`,role:`note`,"aria-label":v,children:[(0,m.jsx)(Ea,{hasBandPlan:d}),l!==null&&(0,m.jsx)(`span`,{className:f?z.feeChipPrimary:z.feeChipOff,"data-testid":`billing-live-tier`,children:t(f?`tierPeak`:`tierOff`)}),o>0&&(0,m.jsx)(`span`,{className:z.feeInlineNum,children:r(o)})]})})}let Ma=`@kenz1117/dsh-ui-usage-billing/TaskQueueQuick.module.css`;if(typeof document<`u`&&document.querySelector(`style[data-plugin-css=`+JSON.stringify(Ma)+`]`)===null){let e=document.createElement(`style`);e.dataset.plugin=`@kenz1117/dsh-ui-usage-billing`,e.dataset.pluginCss=Ma,e.textContent=`.HRJ8EG_quickQueue{white-space:nowrap;flex-shrink:0;align-self:center;align-items:center;gap:6px;display:inline-flex;position:relative}.HRJ8EG_quickQueueToggle,.HRJ8EG_quickQueueButton{border:1px solid var(--dsw-alias-border-l1);min-height:24px;color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;background:0 0;border-radius:999px;justify-content:center;align-items:center;gap:5px;padding:0 8px;font-size:11px;line-height:18px;display:inline-flex}.HRJ8EG_quickQueueToggle:hover,.HRJ8EG_quickQueueButton:hover:not(:disabled){border-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary)}.HRJ8EG_quickQueueToggle[aria-checked=true]{border-color:color-mix(in srgb, var(--ds-blue) 45%, transparent);background:color-mix(in srgb, var(--ds-blue) 10%, transparent);color:var(--ds-blue)}.HRJ8EG_quickQueueButton:focus-visible,.HRJ8EG_quickQueueToggle:focus-visible,.HRJ8EG_quickQueueClear input:focus-visible{outline:2px solid var(--ds-blue);outline-offset:2px}.HRJ8EG_quickQueueButton:disabled{cursor:wait;opacity:.65}.HRJ8EG_quickQueueClear{color:var(--dsw-alias-label-tertiary);cursor:pointer;align-items:center;gap:4px;font-size:11px;display:inline-flex}.HRJ8EG_quickQueueClear input{width:13px;height:13px;accent-color:var(--ds-blue);margin:0}.HRJ8EG_quickQueueCount{background:color-mix(in srgb, var(--ds-blue) 14%, transparent);min-width:16px;height:16px;color:var(--ds-blue);font-variant-numeric:tabular-nums;border-radius:999px;justify-content:center;align-items:center;padding:0 4px;font-size:10px;display:inline-flex}.HRJ8EG_quickQueueNotice{z-index:30;border:1px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-3);width:max-content;max-width:min(320px,75vw);color:var(--dsw-alias-label-primary);white-space:normal;pointer-events:none;border-radius:8px;padding:7px 10px;font-size:12px;line-height:18px;position:absolute;bottom:calc(100% + 8px);right:0;box-shadow:0 8px 24px #00000038}.HRJ8EG_quickQueueNotice[data-kind=error]{border-color:color-mix(in srgb, var(--ds-red) 45%, transparent);color:var(--ds-red)}`,document.head.appendChild(e)}var Na={quickQueue:`HRJ8EG_quickQueue`,quickQueueButton:`HRJ8EG_quickQueueButton`,quickQueueClear:`HRJ8EG_quickQueueClear`,quickQueueCount:`HRJ8EG_quickQueueCount`,quickQueueNotice:`HRJ8EG_quickQueueNotice`,quickQueueToggle:`HRJ8EG_quickQueueToggle`};let Pa=()=>void 0,Fa=()=>void 0;function Ia(e){return e.tasks.filter(e=>e.status===`queued`).length}function La(){let[e,t]=(0,d.useState)(()=>Xe());return(0,d.useEffect)(()=>{let e=()=>{t(Xe())};return window.addEventListener(Ye,e),window.addEventListener(`storage`,e),()=>{window.removeEventListener(Ye,e),window.removeEventListener(`storage`,e)}},[]),e}function Ra(e){let[t,n]=(0,d.useState)(null),[r,i]=(0,d.useState)(()=>typeof document>`u`||!document.hidden),a=(0,d.useRef)(0),o=(0,d.useCallback)(e=>{a.current+=1,n(Ia(e))},[]);return(0,d.useEffect)(()=>{if(typeof document>`u`)return;let e=()=>{i(!document.hidden)};return document.addEventListener(`visibilitychange`,e),()=>{document.removeEventListener(`visibilitychange`,e)}},[]),(0,d.useEffect)(()=>{if(!e||!r){n(null);return}let t=!1,i=!1,o=()=>{if(i)return;i=!0;let e=a.current;Ji().then(r=>{t||e!==a.current||n(r.supported?r.queuedCount:null)}).catch(()=>{}).finally(()=>{i=!1})};o();let s=window.setInterval(o,3e4);return()=>{t=!0,window.clearInterval(s)}},[e,r]),{count:t,applySnapshot:o}}function za({t:e}){let t=La();return t.showEntry?(0,m.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t.enabled,"aria-label":e(`quickQueueToggle`),className:Na.quickQueueToggle,"data-testid":`quick-queue-toggle`,onClick:()=>{Ze({enabled:!t.enabled})},children:e(`quickQueueToggle`)}):null}function Ba(e,t){let n=e(t),r=(0,d.useCallback)(e=>n?.subscribe(e)??(()=>{}),[n]),i=(0,d.useCallback)(()=>n?.getSnapshot(),[n]);return(0,d.useSyncExternalStore)(r,i,i)}function Va({sessionId:e,t,useInput:n,inputActions:r,projectionFaceOf:i}){let a=La(),o=(n??Pa)(e=>e),s=Ba(i??Fa,`workingDirectory`),c=Ba(i??Fa,`modelSelection`)?.next,{count:l,applySnapshot:u}=Ra(a.enabled&&a.showEntry),[f,p]=(0,d.useState)(!1),[h,g]=(0,d.useState)(null),_=(0,d.useRef)(!1),v=(0,d.useRef)(!0),y=(0,d.useRef)({sessionId:e,input:o});if(y.current={sessionId:e,input:o},(0,d.useEffect)(()=>(v.current=!0,()=>{v.current=!1}),[]),(0,d.useEffect)(()=>{if(h===null)return;let e=h.kind===`success`?4e3:8e3,t=window.setTimeout(()=>{g(null)},e);return()=>{window.clearTimeout(t)}},[h]),!a.enabled||!a.showEntry)return null;let b=e=>{g({kind:`error`,text:e})},x=async()=>{if(_.current)return;if(g(null),o===void 0){b(t(`quickQueueUnsupported`));return}let n=o.draft;if(n.trim()===``){b(t(`quickQueueEmpty`));return}if(o.phase!==`plain`){b(t(`quickQueueBusy`));return}if(o.attachmentIds.length>0||o.occurrences.length>0){b(t(`quickQueueAttachments`));return}if(typeof s!=`string`||s===``){b(t(`quickQueueContext`));return}let i=a.clearAfterEnqueue;if(i&&r===void 0){b(t(`quickQueueUnsupported`));return}let l={sessionId:e,prompt:n,draftRev:o.draftRev,cwd:s,clearAfterEnqueue:i};_.current=!0,p(!0);try{let e=await qi(!0);if(!e.supported){b(t(`quickQueueUnsupported`));return}let n=c??e.defaultModel;if(n==null){b(t(`quickQueueContext`));return}let i=e.workspaces.some(e=>e.path===l.cwd),a=e.models.some(e=>e.provider===n.provider&&e.id===n.model);if(!i||!a){b(t(`quickQueueRoute`));return}let o=await Yi({action:`enqueue`,prompt:l.prompt,cwd:l.cwd,provider:n.provider,model:n.model});u(o);let s=t(`quickQueueEnqueued`);if(l.clearAfterEnqueue&&r!==void 0){let e=y.current;if(v.current&&e.sessionId===l.sessionId&&e.input?.draft===l.prompt&&e.input.draftRev===l.draftRev&&e.input.phase===`plain`&&e.input.attachmentIds.length===0&&e.input.occurrences.length===0)try{r.setDraft(``)}catch{s=t(`quickQueueDraftChanged`)}else s=t(`quickQueueDraftChanged`)}v.current&&g({kind:`success`,text:s})}catch(e){if(!v.current)return;let n=e instanceof Error?e.message:String(e);b(t(`quickQueueFailed`).replace(`{message}`,n))}finally{_.current=!1,v.current&&p(!1)}};return(0,m.jsxs)(`span`,{className:Na.quickQueue,"data-testid":`quick-queue-controls`,children:[(0,m.jsxs)(`label`,{className:Na.quickQueueClear,children:[(0,m.jsx)(`input`,{type:`checkbox`,checked:a.clearAfterEnqueue,disabled:f,onChange:e=>{Ze({clearAfterEnqueue:e.target.checked})}}),t(`quickQueueClear`)]}),(0,m.jsxs)(`button`,{type:`button`,className:Na.quickQueueButton,"aria-label":t(`quickQueueEnqueue`),"aria-busy":f,disabled:f,"data-testid":`quick-queue-enqueue`,onClick:()=>{x()},children:[t(f?`quickQueueEnqueueing`:`quickQueueEnqueue`),l!==null&&l>0&&(0,m.jsx)(`span`,{className:Na.quickQueueCount,"data-testid":`quick-queue-count`,"aria-label":t(`quickQueueWaiting`).replace(`{count}`,String(l)),children:l})]}),h!==null&&(0,m.jsx)(`span`,{className:Na.quickQueueNotice,"data-kind":h.kind,role:h.kind===`error`?`alert`:`status`,children:h.text})]})}function Ha(){let e,t,n=new Set;return{readCosts:()=>e,subscribeCosts:t=>(t(e),n.add(t),()=>{n.delete(t)}),openDashboard:()=>{t?.()},publishCosts:t=>{e=t;for(let e of n)try{e(t)}catch{x(`billing-costs-listener-threw`)}},registerOpen:e=>(t=e,()=>{t===e&&(t=void 0)})}}let Ua={enabled:!1,timeout:0};function Wa(){try{let e=localStorage.getItem(`dsh-billing-completion-notify-v1`);if(e===null)return{...Ua};let t=JSON.parse(e);return{enabled:t.enabled===!0,timeout:typeof t.timeout==`number`?t.timeout:0}}catch{return{...Ua}}}function Ga(e){return e.completed===!0||e.running===!1}function Ka(e,t){let n=new Set,r=new Set,i,a=e.getSnapshot();for(let e of a.ids){let t=a.byId[e];t!==void 0&&(r.add(String(e)),Ga(t)&&n.add(String(e)))}let o=e=>{let{enabled:n,timeout:r}=t();if(n&&!(typeof Notification>`u`)&&Notification.permission===`granted`)try{let t=new Notification(e,{body:e,tag:`dsh-billing-completion`,requireInteraction:r===0});r>0&&(i!==void 0&&clearTimeout(i),i=setTimeout(()=>t.close(),r*1e3))}catch{x(`notification-constructor-failed`)}},s=e.subscribe(()=>{let t=e.getSnapshot(),i=[];for(let e of t.ids){let a=t.byId[e];if(a===void 0)continue;let o=String(e),s=Ga(a),c=!r.has(o);c&&r.add(o),s&&!c&&!n.has(o)&&i.push(a.title??a.id??o),s?n.add(o):n.delete(o)}if(i.length>0){let e=i.length===1?i[0]:`${i.length} 个会话已完成`;e!==void 0&&o(e)}});return()=>{s(),i!==void 0&&clearTimeout(i)}}function qa(e){let t=e.get(`uiWorkspace`);if(t!==void 0&&typeof t.openSession==`function`)return t}function Ja(e){let t=e.sessions,n=t?.open;return typeof n==`function`?n.bind(t):void 0}function Ya(e){return{available:()=>qa(e)!==void 0||Ja(e)!==void 0,open:t=>{let n=_(t),r=qa(e);if(r!==void 0)try{return r.openSession(n),`opened`}catch(e){return x(`session-navigation-open-failed`,e),`failed`}let i=Ja(e);if(i!==void 0)try{return i(n),`opened`}catch(e){return x(`session-navigation-legacy-open-failed`,e),`failed`}return`unavailable`}}}function Xa(e,t){let n=e.get(`commandUi`);if(n===void 0||typeof n.register!=`function`)return!1;let r={name:`usage`,label:t.label,description:t.description,available:()=>!0,ui:{kind:`action`,run:()=>{t.openDashboard()}}};try{n.register(r)}catch(e){return x(`usage-command-register-failed`,e),!1}return!0}let Za=[`slots`,`locale`,`remote`,`sessions`];function Qa(e){let t=Ha();e.provide(`billingMetrics`,t);let n=or();e.effect(()=>e.locale.register($e,{zh:et,en:tt}),`ui-usage-billing: dictionaries`);let r=Ya(e),i=Xa(e,{openDashboard:()=>{t.openDashboard()},label:()=>Me()===`en`?tt.commandUsageLabel:et.commandUsageLabel,description:()=>Me()===`en`?tt.commandUsageDescription:et.commandUsageDescription}),a=!1,o={store:n,inject:()=>({checkModels:async()=>{try{let[t,n]=await Promise.all([e.remote.llm.listProviders(),e.remote.llm.listConfigurableProviders()]);if(!t.ok||!n.ok)return{checked:!0,available:!1,models:0,failures:0,okProviders:[],badProviders:[]};let r=new Map(n.value.map(e=>[e.provider,e])),i=await Promise.all(t.value.map(async t=>{let n=r.get(t.id);if(n===void 0)return{provider:t,models:[]};let i=await e.remote.llm.discoverModels(n.settingsNs,{provider:t.id});return i.ok?{provider:t,models:i.value}:{provider:t,failed:!0}})),a=[],o=[],s=[],c=0;for(let e of i){if(`failed`in e){s.push(e.provider.name);continue}o.push(e.provider.name),c+=e.models.length;for(let t of e.models)a.push({id:t.id,...typeof t.name==`string`&&t.name!==``?{name:t.name}:{},provider:e.provider.name})}return{checked:!0,available:o.length>0,models:c,failures:s.length,okProviders:o,badProviders:s,catalog:a}}catch{return{checked:!1,available:!1,models:0,failures:0,okProviders:[],badProviders:[]}}},publishCosts:e=>{t.publishCosts(e)},registerOpen:e=>t.registerOpen(e),recoveryEntryAvailable:i||a,navigateToSession:e=>r.open(e)})};e.slots.inject(`settings.section`,()=>{a=!0;let t=e.slots.register({name:`settings.section`,id:`usage-billing`,order:30,label:()=>Me()===`en`?tt.nativeSettingsNav:et.nativeSettingsNav,locale:$e,...o},ga);return()=>{a=!1,t()}}),e.slots.inject(`sidebar.footer.action`,()=>e.slots.register({name:`sidebar.footer.action`,id:`usage-billing`,order:-10,locale:$e,...o,children:{"billing.dashboard.decor":{kind:`list`,scope:`root`}}},ha)),e.slots.inject(`conversation.composer.dock`,()=>e.slots.register({name:`conversation.composer.dock`,id:`usage-billing-cost`,order:0,locale:$e,inject:e=>({sessionId:_(e),seat:`below`})},Aa)),e.slots.inject(`conversation.input.dock`,()=>e.slots.register({name:`conversation.input.dock`,id:`usage-billing-cost-above`,order:100,locale:$e,inject:e=>({sessionId:_(e),seat:`above`})},Aa)),e.slots.inject(`conversation.input.right`,()=>e.slots.register({name:`conversation.input.right`,id:`usage-billing-cost-chip`,order:0,locale:$e,inject:e=>({sessionId:_(e)})},ja)),e.slots.inject(`conversation.input.left`,()=>e.slots.register({name:`conversation.input.left`,id:`usage-billing-quick-queue-toggle`,order:20,locale:$e},za)),e.slots.inject(`conversation.input.right`,()=>e.slots.register({name:`conversation.input.right`,id:`usage-billing-quick-queue-enqueue`,order:20,locale:$e,inject:t=>({sessionId:_(t),projectionFaceOf:n=>{try{return e.sessions.binding?.(_(t))?.session.projections.faceOf(n)}catch{return}}})},Va)),e.effect(()=>Ka(e.sessions.list,Wa),`ui-usage-billing: completion notifier`)}return n.UsageBilling=ha,n.apply=Qa,n.inject=Za,t.exports}});
|
|
6
6
|
//# sourceMappingURL=client.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kenz1117/dsh-ui-usage-billing",
|
|
3
3
|
"description": "Usage billing dashboard for DeepSeek Harness: sidebar cost metrics plus a full dashboard modal, priced from a current multi-provider catalog with real usage aggregated from session logs.",
|
|
4
|
-
"version": "1.8.3-alpha.
|
|
4
|
+
"version": "1.8.3-alpha.2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek-harness",
|
|
7
7
|
"deepseek",
|
|
@@ -86,7 +86,8 @@
|
|
|
86
86
|
"0.2.1-rc.4": "compatible",
|
|
87
87
|
"0.2.1-rc.5": "compatible",
|
|
88
88
|
"0.2.2-alpha.2": "compatible",
|
|
89
|
-
"0.2.2-alpha.3": "compatible"
|
|
89
|
+
"0.2.2-alpha.3": "compatible",
|
|
90
|
+
"0.2.2-rc.1": "compatible"
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
},
|
|
@@ -135,68 +136,68 @@
|
|
|
135
136
|
"clsx": "^2.1.1"
|
|
136
137
|
},
|
|
137
138
|
"devDependencies": {
|
|
138
|
-
"@deepseek-ai/cordis": "4.0
|
|
139
|
-
"@deepseek-ai/cordis-plugin-include": "1.0
|
|
140
|
-
"@deepseek-ai/cordis-plugin-loader": "1.0
|
|
141
|
-
"@deepseek-ai/cordis-plugin-group": "1.0
|
|
142
|
-
"@deepseek-ai/dsh-agent": "0.2.2-
|
|
143
|
-
"@deepseek-ai/dsh-agent-default-model": "0.2.2-
|
|
144
|
-
"@deepseek-ai/dsh-agent-preset-registry": "0.2.2-
|
|
145
|
-
"@deepseek-ai/dsh-api-gateway": "0.2.2-
|
|
146
|
-
"@deepseek-ai/dsh-api-remotes": "0.2.2-
|
|
147
|
-
"@deepseek-ai/dsh-api-session-controller": "0.2.2-
|
|
148
|
-
"@deepseek-ai/dsh-app-boot": "0.2.2-
|
|
149
|
-
"@deepseek-ai/dsh-atomic-write": "0.2.2-
|
|
150
|
-
"@deepseek-ai/dsh-attachment": "0.2.2-
|
|
151
|
-
"@deepseek-ai/dsh-client-connection": "0.2.2-
|
|
152
|
-
"@deepseek-ai/dsh-client-file-upload": "0.2.2-
|
|
153
|
-
"@deepseek-ai/dsh-client-locale": "0.2.2-
|
|
154
|
-
"@deepseek-ai/dsh-client-store": "0.2.2-
|
|
155
|
-
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-
|
|
156
|
-
"@deepseek-ai/dsh-client-ui-commands": "0.2.2-
|
|
157
|
-
"@deepseek-ai/dsh-client-ui-workspace": "0.2.2-
|
|
158
|
-
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-
|
|
159
|
-
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-
|
|
160
|
-
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-
|
|
161
|
-
"@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-
|
|
162
|
-
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-
|
|
163
|
-
"@deepseek-ai/dsh-commands": "0.2.2-
|
|
164
|
-
"@deepseek-ai/dsh-credentials": "0.2.2-
|
|
165
|
-
"@deepseek-ai/dsh-file-reference": "0.2.2-
|
|
166
|
-
"@deepseek-ai/dsh-fs": "0.2.2-
|
|
167
|
-
"@deepseek-ai/dsh-home-paths": "0.2.2-
|
|
168
|
-
"@deepseek-ai/dsh-host-webserver": "0.2.2-
|
|
139
|
+
"@deepseek-ai/cordis": "4.1.0",
|
|
140
|
+
"@deepseek-ai/cordis-plugin-include": "1.1.0",
|
|
141
|
+
"@deepseek-ai/cordis-plugin-loader": "1.1.0",
|
|
142
|
+
"@deepseek-ai/cordis-plugin-group": "1.1.0",
|
|
143
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.1",
|
|
144
|
+
"@deepseek-ai/dsh-agent-default-model": "0.2.2-rc.1",
|
|
145
|
+
"@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.1",
|
|
146
|
+
"@deepseek-ai/dsh-api-gateway": "0.2.2-rc.1",
|
|
147
|
+
"@deepseek-ai/dsh-api-remotes": "0.2.2-rc.1",
|
|
148
|
+
"@deepseek-ai/dsh-api-session-controller": "0.2.2-rc.1",
|
|
149
|
+
"@deepseek-ai/dsh-app-boot": "0.2.2-rc.1",
|
|
150
|
+
"@deepseek-ai/dsh-atomic-write": "0.2.2-rc.1",
|
|
151
|
+
"@deepseek-ai/dsh-attachment": "0.2.2-rc.1",
|
|
152
|
+
"@deepseek-ai/dsh-client-connection": "0.2.2-rc.1",
|
|
153
|
+
"@deepseek-ai/dsh-client-file-upload": "0.2.2-rc.1",
|
|
154
|
+
"@deepseek-ai/dsh-client-locale": "0.2.2-rc.1",
|
|
155
|
+
"@deepseek-ai/dsh-client-store": "0.2.2-rc.1",
|
|
156
|
+
"@deepseek-ai/dsh-client-ui-conversation": "0.2.2-rc.1",
|
|
157
|
+
"@deepseek-ai/dsh-client-ui-commands": "0.2.2-rc.1",
|
|
158
|
+
"@deepseek-ai/dsh-client-ui-workspace": "0.2.2-rc.1",
|
|
159
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.2.2-rc.1",
|
|
160
|
+
"@deepseek-ai/dsh-client-ui-renderer": "0.2.2-rc.1",
|
|
161
|
+
"@deepseek-ai/dsh-client-ui-settings": "0.2.2-rc.1",
|
|
162
|
+
"@deepseek-ai/dsh-client-ui-sidebar": "0.2.2-rc.1",
|
|
163
|
+
"@deepseek-ai/dsh-client-ui-slots": "0.2.2-rc.1",
|
|
164
|
+
"@deepseek-ai/dsh-commands": "0.2.2-rc.1",
|
|
165
|
+
"@deepseek-ai/dsh-credentials": "0.2.2-rc.1",
|
|
166
|
+
"@deepseek-ai/dsh-file-reference": "0.2.2-rc.1",
|
|
167
|
+
"@deepseek-ai/dsh-fs": "0.2.2-rc.1",
|
|
168
|
+
"@deepseek-ai/dsh-home-paths": "0.2.2-rc.1",
|
|
169
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.2-rc.1",
|
|
169
170
|
"@deepseek-ai/dsh-invariants": "0.2.0-rc.2",
|
|
170
|
-
"@deepseek-ai/dsh-llm": "0.2.2-
|
|
171
|
-
"@deepseek-ai/dsh-native-command": "0.2.2-
|
|
172
|
-
"@deepseek-ai/dsh-ptc-runtime": "0.2.2-
|
|
173
|
-
"@deepseek-ai/dsh-sandbox": "0.2.2-
|
|
174
|
-
"@deepseek-ai/dsh-sandbox-policy": "0.2.2-
|
|
175
|
-
"@deepseek-ai/dsh-scope": "0.2.2-
|
|
176
|
-
"@deepseek-ai/dsh-session": "0.2.2-
|
|
177
|
-
"@deepseek-ai/dsh-session-persistence": "0.2.2-
|
|
178
|
-
"@deepseek-ai/dsh-session-projection": "0.2.2-
|
|
179
|
-
"@deepseek-ai/dsh-session-query": "0.2.2-
|
|
180
|
-
"@deepseek-ai/dsh-session-title": "0.2.2-
|
|
181
|
-
"@deepseek-ai/dsh-settings": "0.2.2-
|
|
182
|
-
"@deepseek-ai/dsh-skill": "0.2.2-
|
|
183
|
-
"@deepseek-ai/dsh-subagent": "0.2.2-
|
|
184
|
-
"@deepseek-ai/dsh-system-prompt": "0.2.2-
|
|
185
|
-
"@deepseek-ai/dsh-tools": "0.2.2-
|
|
186
|
-
"@deepseek-ai/dsh-typert-protocol": "0.2.2-
|
|
187
|
-
"@deepseek-ai/dsh-typert-registry": "0.2.2-
|
|
188
|
-
"@deepseek-ai/dsh-user-approval": "0.2.2-
|
|
189
|
-
"@deepseek-ai/dsh-util-code-language": "0.2.2-
|
|
190
|
-
"@deepseek-ai/dsh-util-time": "0.2.2-
|
|
191
|
-
"@deepseek-ai/dsh-util-workspace-path": "0.2.2-
|
|
192
|
-
"@deepseek-ai/dsh-working-directory": "0.2.2-
|
|
193
|
-
"@deepseek-ai/dsh-workspace": "0.2.2-
|
|
194
|
-
"@deepseek-ai/dsh-compaction": "0.2.2-
|
|
195
|
-
"@deepseek-ai/dsh-launch-environment": "0.2.2-
|
|
196
|
-
"@deepseek-ai/dsh-storage": "0.2.2-
|
|
197
|
-
"@deepseek-ai/dsh-storage-domain": "0.2.2-
|
|
198
|
-
"@deepseek-ai/dsh-tool-todo": "0.2.2-
|
|
199
|
-
"@deepseek-ai/schemastery": "3.
|
|
171
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.1",
|
|
172
|
+
"@deepseek-ai/dsh-native-command": "0.2.2-rc.1",
|
|
173
|
+
"@deepseek-ai/dsh-ptc-runtime": "0.2.2-rc.1",
|
|
174
|
+
"@deepseek-ai/dsh-sandbox": "0.2.2-rc.1",
|
|
175
|
+
"@deepseek-ai/dsh-sandbox-policy": "0.2.2-rc.1",
|
|
176
|
+
"@deepseek-ai/dsh-scope": "0.2.2-rc.1",
|
|
177
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.1",
|
|
178
|
+
"@deepseek-ai/dsh-session-persistence": "0.2.2-rc.1",
|
|
179
|
+
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.1",
|
|
180
|
+
"@deepseek-ai/dsh-session-query": "0.2.2-rc.1",
|
|
181
|
+
"@deepseek-ai/dsh-session-title": "0.2.2-rc.1",
|
|
182
|
+
"@deepseek-ai/dsh-settings": "0.2.2-rc.1",
|
|
183
|
+
"@deepseek-ai/dsh-skill": "0.2.2-rc.1",
|
|
184
|
+
"@deepseek-ai/dsh-subagent": "0.2.2-rc.1",
|
|
185
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.1",
|
|
186
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.1",
|
|
187
|
+
"@deepseek-ai/dsh-typert-protocol": "0.2.2-rc.1",
|
|
188
|
+
"@deepseek-ai/dsh-typert-registry": "0.2.2-rc.1",
|
|
189
|
+
"@deepseek-ai/dsh-user-approval": "0.2.2-rc.1",
|
|
190
|
+
"@deepseek-ai/dsh-util-code-language": "0.2.2-rc.1",
|
|
191
|
+
"@deepseek-ai/dsh-util-time": "0.2.2-rc.1",
|
|
192
|
+
"@deepseek-ai/dsh-util-workspace-path": "0.2.2-rc.1",
|
|
193
|
+
"@deepseek-ai/dsh-working-directory": "0.2.2-rc.1",
|
|
194
|
+
"@deepseek-ai/dsh-workspace": "0.2.2-rc.1",
|
|
195
|
+
"@deepseek-ai/dsh-compaction": "0.2.2-rc.1",
|
|
196
|
+
"@deepseek-ai/dsh-launch-environment": "0.2.2-rc.1",
|
|
197
|
+
"@deepseek-ai/dsh-storage": "0.2.2-rc.1",
|
|
198
|
+
"@deepseek-ai/dsh-storage-domain": "0.2.2-rc.1",
|
|
199
|
+
"@deepseek-ai/dsh-tool-todo": "0.2.2-rc.1",
|
|
200
|
+
"@deepseek-ai/schemastery": "3.19.0",
|
|
200
201
|
"@playwright/test": "^1.64.1",
|
|
201
202
|
"@shikijs/langs": "^4.3.1",
|
|
202
203
|
"@testing-library/dom": "^10.4.1",
|