dsh-cost-meter 1.9.12 → 1.9.13
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.md +575 -575
- package/README.zh-CN.md +579 -579
- package/THIRD_PARTY_NOTICES.md +27 -0
- package/docs/display-settings.md +2 -0
- package/docs/update-notes-1.9.13.md +86 -0
- package/lib/billing-history.js +19 -8
- package/lib/client.display.js +2 -2
- package/lib/client.js +5 -5
- package/lib/client.session-list.js +2 -0
- package/lib/client.statistics.js +8 -8
- package/lib/coding-plans.js +98 -1
- package/lib/index.js +23 -1
- package/lib/model-labels.js +43 -0
- package/lib/plan-billing.js +1 -1
- package/lib/pricing.js +26 -4
- package/lib/session-tree.js +24 -0
- package/lib/store.js +11 -3
- package/lib/typert.host.js +14 -2
- package/lib/workbuddy.js +301 -0
- package/package.json +206 -203
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.session-list.js",factory:B=>{const D=B("react"),{createElement:k,useEffect:Q,useRef:W,useSyncExternalStore:x}=D,N=e=>{if(typeof e!="number"||!Number.isFinite(e))throw Error("Invalid session amount");return e},F=e=>{if(typeof e!="string")throw Error("Invalid session identity");return e},A=e=>{if(!Array.isArray(e?.sessionIds)||e.sessionIds.length>100||!e.sessionIds.every(t=>typeof t=="string"&&t.length>0&&t.length<=512)||!["total","today"].includes(e.period))throw Error("Invalid session list query");return{sessionIds:e.sessionIds,period:e.period}},L=e=>{if(!Array.isArray(e))throw Error("Invalid session list amounts");return e.map(t=>{if(typeof t?.found!="boolean")throw Error("Invalid session amount status");return{id:F(t.id),found:t.found,...Object.fromEntries(["input","output","cacheRead","cacheWrite","calls","cost"].map(s=>[s,N(t[s])])),...Object.fromEntries(["apiCost","reasoning","costCny","apiCostCny","costEur","apiCostEur"].filter(s=>t[s]!==void 0).map(s=>[s,N(t[s])]))}})},T=(e,t)=>{const s={parse:t};return{mode:"strict",typeSymbol:"dsh-cost-meter#"+e,schema:s,create:()=>s}},_={package:"dsh-cost-meter-session-list",face:"host",descriptors:[{id:"dsh-cost-meter#costMeter/getSessionListCosts",service:"costMeter",namespace:"costMeter",method:"getSessionListCosts",invocation:{kind:"direct"},parameters:[{name:"query",wire:"query",source:"json",codec:T("SessionListQuery",A)}],result:T("SessionListCosts",L)}]};function q(e,t){const s=new Map,c=new Map,p=new Set;let m=0,u=0,h,y=!1,r=!1;const g=()=>{m++;for(const o of p)o()},d=()=>{!r&&!h&&(h=setTimeout(I,30))};async function I(){h=null;const o=t();if(r||y||!o?.config?.sessionListCosts||document.hidden)return;const a=[...s.keys()].filter(l=>Date.now()-(c.get(l)?.at??0)>=5e3).slice(0,100);if(!a.length)return;const w=u;y=!0;try{const l=L(await e({sessionIds:a,period:o.config.sessionListCostPeriod??"total"}));if(r||u!==w)return;for(const b of l)a.includes(b.id)&&c.set(b.id,{at:Date.now(),row:b});for(;c.size>500;)c.delete(c.keys().next().value);g()}catch{}finally{y=!1,!r&&(u!==w||[...s.keys()].some(l=>!a.includes(l)&&!c.has(l)))&&d()}}return{subscribe:o=>(p.add(o),()=>p.delete(o)),snapshot:()=>m,row:o=>c.get(o)?.row,show:o=>(s.set(o,(s.get(o)??0)+1),d(),()=>{const a=s.get(o)-1;a>0?s.set(o,a):s.delete(o)}),refresh:d,invalidate:()=>{u++,c.clear(),g(),d()},dispose:()=>{r=!0,u++,clearTimeout(h),s.clear(),c.clear(),p.clear()}}}async function J(e,t,s,{formatMoneyUsd:c,displayCostOf:p,formatTokens:m}){const u=await e.get("remote").$mount(_),h=e.get("remote.costMeter"),y=()=>t.getSnapshot().state,r=q(async n=>{const i=await h.getSessionListCosts(n);if(!i?.ok)throw Error("Session list amounts unavailable");return i.value},y),g=document.createElement("style");g.textContent=".cm-session-list-price{font-size:11px;color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;white-space:nowrap;flex:none;order:-1}.cm-session-list-detail{font-size:12px;white-space:pre-line;color:var(--dsw-alias-label-secondary)}span:has(>.cm-session-list-price){display:inline-flex}:not(:hover):not(:focus-within)>span:has(>.cm-session-list-price)>:not(.cm-session-list-price){display:none}",document.head.append(g);function d({sessionId:n,detail:i=!1}){const S=x(t.subscribe,t.getSnapshot),O=S.state,v=O?.config??{},R=W(null);x(r.subscribe,r.snapshot);const M=v.sessionListCosts===!0;if(Q(()=>{if(!M||!n)return;let E;if(i||typeof IntersectionObserver>"u")return r.show(n);const P=new IntersectionObserver(U=>{U.some($=>$.isIntersecting)?E||(E=r.show(n)):(E?.(),E=null)});return R.current&&P.observe(R.current),()=>{P.disconnect(),E?.()}},[n,M,i]),!M)return null;const f=r.row(n),C=s(v)==="en",K=v.sessionListCostPeriod==="today"?C?"Today":"今日":C?"Total":"累计",z=f?.found?c(p(f,v),v):"—",j=K+" "+z+(f?.found?`
|
|
2
|
+
`+(C?"Input ":"输入 ")+m(f.input)+" · "+(C?"Cache ":"缓存 ")+m(f.cacheRead+f.cacheWrite)+" · "+(C?"Output ":"输出 ")+m(f.output):"");return k(i?"div":"span",{ref:R,className:i?"cm-session-list-detail":"cm-session-list-price",title:j,"aria-label":j},i?j:z)}const I=e.get("slots"),o=[];for(const[n,i]of[["sidebar.workspaces.session.row.action",!1],["sidebar.session.row.hover",!0]]){const S=()=>I.register({name:n,id:"cost-meter-session-list",order:10},O=>k(d,{...O,detail:i}));o.push(I.inject(n,S))}let a;const w=()=>{const n=y(),i=JSON.stringify([n?.config?.sessionListCosts,n?.config?.sessionListCostPeriod,n?.config?.includeSubagentCost,n?.meta?.dayKey,n?.total?.calls,n?.total?.cost]);i!==a&&(a=i,r.invalidate())};w();const l=t.subscribe(w),b=setInterval(r.refresh,1e4);return document.addEventListener("visibilitychange",r.refresh),e.effect(()=>()=>{l(),clearInterval(b),document.removeEventListener("visibilitychange",r.refresh),r.dispose(),g.remove();for(const n of o)n?.();u()},"cost-meter: session list amounts"),{Row:d}}return{mount:J,CONTRIBUTION:_,createBatchReader:q,parseQuery:A,parseRows:L}}});
|