ICEN UI AI 用量条
Docs ⌘K
Beta · 演进中

AI 用量条

上下文用量双形态:分段条 + 常驻环形指示器,配套审计面板。

Preview
AI 原生 ai-usage
上下文窗口环(Claude Desktop 式):点击弹出完整分解

缓存读 ≈ 0.1× 输入价、缓存写 ≈ 1.25× 输入价——分列展示,计费口径诚实

审计面板

renderAiAudit · 预置 8 条记录的 auditor(含错误与 TTFT)

html
<div style="display:flex;align-items:center;gap:12px;width:100%;margin-bottom:14px">  <div id="ai-usage-ring-demo"></div>  <span class="demo-label">上下文窗口环(Claude Desktop 式):点击弹出完整分解</span></div><div id="ai-usage-demo" style="width:100%"></div><p class="demo-label" style="margin-top:8px">缓存读 ≈ 0.1× 输入价、缓存写 ≈ 1.25× 输入价——分列展示,计费口径诚实</p><div class="icen-toolbar" style="margin-top:14px">  <span class="icen-toolbar-label">审计面板</span>  <span class="icen-toolbar-spacer"></span>  <button class="icen-btn icen-btn-sm" type="button" id="ai-audit-seed">再跑两条</button></div><p class="demo-label" style="margin:6px 0 10px">renderAiAudit · 预置 8 条记录的 auditor(含错误与 TTFT)</p><div id="ai-audit-demo" style="width:100%"></div>

特性

与 createAiAuditor 的条目(含 cost 定价估算与 ttftMs)闭环。

接口

导出
renderAiUsagerenderAiUsageRingrenderAiAudit 共享行为模块,清单含族内导出
类型
dist/behaviors/ai-panel.d.mts(随 npm 包发布,含全部 JSDoc 约束)

安装

bun add @icen.ai/ui

一行引入该组件(CSS 与 behavior 自动带上,无需关心内部 CSS 文件名):

js
import '@icen.ai/ui/kit/ai-usage';

也可以用脚手架直接打印引入行:

bash
bunx --bun @icen.ai/ui add ai-usage

Astro 项目注意:kit 入口里的 CSS import 在页面 <script> 里会被 Astro 的 client bundle 摇掉——请改在布局 frontmatter 里引 CSS(import '@icen.ai/ui/components/ai-panel.css';),JS 行为仍可走 kit。Vite SPA / webpack 项目无此问题。

用法

js
import { renderAiUsage, renderAiUsageRing, renderAiAudit } from '@icen.ai/ui/kit/ai-usage';// 分段条形态renderAiUsage(el, {  input: 42000, output: 18000, cacheRead: 96000, cacheWrite: 12000, reasoning: 8000,}, { total: 200000, cost: 0.3124 });// 上下文窗口环形指示器(点击弹出完整分解,复用 popover)renderAiUsageRing(el, { input: 42000, /* … */ }, { total: 200000 });// 状态档:<60% icen-accent / 60–85% warning / >85% error + 脉冲// 审计面板:totals + byModel + 最近条目(source 为 auditor 或条目数组,快照渲染)import { createAiClient, createAiAuditor, estimateCost } from '@icen.ai/ui';const auditor = createAiAuditor({ persist: 'my-audit', max: 100 });const client = createAiClient({ provider: 'kimi', apiKey, auditor });// …每次请求自动 log(含 cost 定价估算 + ttftMs 首 token 延迟)…renderAiAudit(el, auditor, { limit: 10 });   // 清除钮派 icen:ai-audit-clear,或 opts.onClear// 手动估一笔(注册表定价;未命中返回 undefined,不猜价)const cost = estimateCost(usage, 'kimi', 'kimi-k3');