dsh-cost-meter 1.9.47 → 1.9.49
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 +8 -8
- package/README.zh-CN.md +8 -8
- package/docs/billing-currency.md +21 -0
- package/docs/billing-review-2026-11-02.md +32 -0
- package/docs/display-settings.md +67 -61
- package/docs/native-search-billing.md +48 -0
- package/docs/plugin-compatibility-watch.md +4 -0
- package/docs/update-notes-1.9.48.md +26 -0
- package/docs/update-notes-1.9.49.md +30 -0
- package/docs/web-request-fees.md +52 -32
- package/lib/billing-storage-cli.js +8 -3
- package/lib/client.billing-storage.js +1 -1
- package/lib/client.codex.js +1 -1
- package/lib/client.community.js +1 -1
- package/lib/client.display.js +2 -2
- package/lib/client.js +8 -6
- package/lib/client.notices.js +1 -1
- package/lib/client.openrouter.js +2 -2
- package/lib/client.peak.js +3 -3
- package/lib/client.plan-settings.js +1 -1
- package/lib/client.pricing.js +2 -2
- package/lib/client.session-list.js +2 -2
- package/lib/client.settings-overview.js +1 -1
- package/lib/client.sidebar-order.js +3 -3
- package/lib/client.statistics.js +8 -8
- package/lib/ledger-persistence.js +1 -1
- package/lib/ledger-writer-worker.js +1 -1
- package/lib/native-search-billing.js +3 -1
- package/lib/native-search-fetch.js +48 -38
- package/lib/native-search-history.js +1 -0
- package/lib/native-search-manual.js +54 -0
- package/lib/store.js +3 -0
- package/lib/typert.host.js +1 -0
- package/package.json +7 -2
|
@@ -3,23 +3,28 @@ import { parseArgs } from 'node:util'
|
|
|
3
3
|
import { resolve, join } from 'node:path'
|
|
4
4
|
import { homedir } from 'node:os'
|
|
5
5
|
import { manageBillionStorage } from './billion-context-storage.js'
|
|
6
|
+
import { recordManualSearchFees } from './native-search-manual.js'
|
|
6
7
|
|
|
7
8
|
try {
|
|
8
9
|
const { values, positionals } = parseArgs({ allowPositionals: true, options: {
|
|
9
10
|
ledger: { type: 'string' }, 'older-than': { type: 'string', default: '7d' },
|
|
10
11
|
streams: { type: 'boolean' }, groups: { type: 'boolean' }, 'dry-run': { type: 'boolean' },
|
|
11
12
|
apply: { type: 'boolean', default: false }, help: { type: 'boolean', short: 'h' },
|
|
13
|
+
count: { type: 'string' }, at: { type: 'string' }, id: { type: 'string' }, session: { type: 'string' }, source: { type: 'string' },
|
|
12
14
|
} })
|
|
13
15
|
if (values.help || !positionals.length) {
|
|
16
|
+
console.log('dsh-cost-meter record-search --ledger <ledger.json> --count 3 --at <ISO timestamp with timezone> --id <correction-id> [--session <session-id>] [--source server-tool|search-api] [--apply]\n补记已确认成功且漏记的官方搜索请求费;默认预览,--apply 写入。同一 id 重试不会重复收费,不估算 Token。')
|
|
14
17
|
console.log('dsh-cost-meter clean [--ledger <ledger.json>] [--streams] [--groups] [--older-than 7d|30d|all] [--dry-run | --apply]\n默认预览;--apply 才执行。合并压缩已完成的旧计费流,清理过期请求回执,保留账本、调用记录和历史费用明细。\nPreview by default. --apply compacts completed streams and removes expired receipts; ledger, calls and historical cost details are preserved.')
|
|
15
18
|
} else {
|
|
16
|
-
if (positionals.length !== 1 || positionals[0]
|
|
19
|
+
if (positionals.length !== 1 || !['clean', 'record-search'].includes(positionals[0])) throw Error('Expected command: clean or record-search')
|
|
17
20
|
const retentionDays = { '7d': 7, '30d': 30, all: 0 }[values['older-than']]
|
|
18
21
|
if (retentionDays === undefined) throw Error('--older-than must be 7d, 30d or all')
|
|
19
22
|
if (values.apply && values['dry-run']) throw Error('--dry-run and --apply cannot be combined')
|
|
20
23
|
const both = !values.streams && !values.groups
|
|
21
24
|
const ledger = values.ledger ? resolve(values.ledger) : join(resolve(process.env.DSH_HOME || join(homedir(), '.dsh')), 'storages', 'cost-meter', 'ledger.json')
|
|
22
|
-
console.log(JSON.stringify(
|
|
23
|
-
|
|
25
|
+
console.log(JSON.stringify(positionals[0] === 'record-search'
|
|
26
|
+
? recordManualSearchFees(ledger, values)
|
|
27
|
+
: await manageBillionStorage(ledger, { retentionDays, apply: values.apply,
|
|
28
|
+
streams: both || values.streams === true, groups: both || values.groups === true }), null, 2))
|
|
24
29
|
}
|
|
25
30
|
} catch (error) { console.error(error.message); process.exitCode = 1 }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.billing-storage.js",factory:
|
|
1
|
+
;(function(e){const n=window.__ModuleLoader__,d=n[Symbol.for("@dsh-plugin/dsh-loader:load-wrap")];return(e.id==="dsh-cost-meter"&&n.load===d?.ours&&typeof d.original=="function"?d.original:n.load).call(n,e)})({id:"dsh-cost-meter",chunk:"client.billing-storage.js",factory:h=>{const{createElement:e,useEffect:n,useRef:d,useState:i}=h("react");function D({state:k,api:b,draft:A,setDraft:R,locale:N,disabled:$}){const v=A??k.config,o=v.billingStorageRetentionDays??7,t=(s,g)=>N==="en"?g:s,[a,y]=i(null),[c,C]=i(!1),[M,p]=i(!1),[S,w]=i(""),[B,F]=i(""),m=d(0),u=s=>s<1024?s+" B":s<1048576?(s/1024).toFixed(1)+" KiB":(s/1048576).toFixed(1)+" MiB",x=s=>s==null?"—":new Date(s).toLocaleString(N==="en"?"en-US":"zh-CN"),f=async(s=!1,g=!1)=>{const l=++m.current;C(!0),w(""),p(!1),F("");try{const r=await b.billingStorage({retentionDays:o,apply:s});if(l!==m.current)return;if(s){F(t(`已归档 ${r.archivedStreams} 条记录,移除 ${r.removedFiles} 个文件,释放 ${u(r.releasedBytes)}。`,`Archived ${r.archivedStreams} streams, removed ${r.removedFiles} files and released ${u(r.releasedBytes)}.`));const q=await b.billingStorage({retentionDays:o,apply:!1});l===m.current&&y(q)}else y(r),p(g)}catch(r){l===m.current&&w(String(r?.message??r))}finally{l===m.current&&C(!1)}};n(()=>(y(null),f(),()=>{m.current++}),[o,b]);const _=a&&a.retentionDays===o&&a.streams.eligibleFiles+a.groups.eligibleFiles>0;return e("section",{className:"cm-budget","data-billing-storage":!0},e("h3",{className:"cm-h"},t("计费历史存储","Billing history storage")),e("p",{className:"cm-note"},t("自动维护每小时检查一次:旧的已完成计费流合并压缩,过期请求回执删除。账本、调用记录和历史费用明细保留。","Hourly maintenance compresses completed streams and removes expired request receipts. The ledger, call records and historical cost details are retained.")),e("label",{className:"cm-field"},t("原始辅助文件保留时间","Keep original auxiliary files"),e("select",{value:o,disabled:c,onChange:s=>{p(!1),R({...v,billingStorageRetentionDays:Number(s.target.value)})}},[7,30,0].map(s=>e("option",{key:s,value:s},s?t(`${s} 天`,`${s} days`):t("全部保留(关闭自动清理)","Keep all (disable cleanup)"))))),a?e("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit,minmax(min(100%,180px),1fr))",gap:"12px",margin:"12px 0"}},[["streams",t("计费流","Streams")],["groups",t("请求回执","Request receipts")],["archives",t("压缩归档","Compressed archives")]].map(([s,g])=>{const l=a[s];return e("div",{key:s,className:"cm-card"},e("strong",null,g),e("p",{className:"cm-num"},t(`${l.files} 个文件`,`${l.files} files`)+" · "+u(l.bytes)),e("p",{className:"cm-note"},t("最早:","Oldest: ")+x(l.oldestAt)),e("p",{className:"cm-note"},t("最新:","Newest: ")+x(l.newestAt)))})):null,S?e("p",{className:"cm-msg err",role:"alert"},S):null,B?e("p",{className:"cm-msg",role:"status"},B):null,c?e("p",{role:"status"},t("正在处理…","Working…")):null,M&&a?e("div",{role:"group","aria-label":t("确认清理","Confirm cleanup")},e("p",null,t(`将归档 ${a.streams.eligibleFiles} 条计费流、删除 ${a.groups.eligibleFiles} 个回执文件,涉及 ${a.sessions} 个会话,预计释放 ${u(a.reclaimableBytes)}。`,`Archive ${a.streams.eligibleFiles} streams and remove ${a.groups.eligibleFiles} receipt files across ${a.sessions} sessions; estimated release: ${u(a.reclaimableBytes)}.`)),e("p",{className:"cm-note"},t("正在使用或无法确认完成的文件会保留;实际数量以执行结果为准。","Active files and records without a completion receipt are retained; final counts may differ.")),e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",disabled:$||c||!_,onClick:()=>f(!0)},t("确认清理","Confirm cleanup")),e("button",{type:"button",className:"cm-btn",disabled:c,onClick:()=>p(!1)},t("取消","Cancel")))):e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",disabled:$||c||o===0,onClick:()=>f(!1,!0)},t("预览清理","Preview cleanup")),e("button",{type:"button",className:"cm-btn",disabled:c,onClick:()=>f()},t("刷新统计","Refresh storage"))))}return{mount:()=>D}}});
|
package/lib/client.codex.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.codex.js",factory:
|
|
1
|
+
;(function(g){const e=window.__ModuleLoader__,m=e[Symbol.for("@dsh-plugin/dsh-loader:load-wrap")];return(g.id==="dsh-cost-meter"&&e.load===m?.ours&&typeof m.original=="function"?m.original:e.load).call(e,g)})({id:"dsh-cost-meter",chunk:"client.codex.js",factory:w=>{const g=w("react"),{createElement:e,useState:m,useEffect:h,useRef:v}=g;async function D(t=!1){try{const u=await fetch("/api/dsh-chatgpt-subscription/"+(t?"quota/refresh":"status"),{credentials:"same-origin",signal:AbortSignal.timeout(8e3),headers:{accept:"application/json",...t?{"content-type":"application/json"}:{}},...t?{method:"POST",body:"{}"}:{}});if(!u.ok)return null;const s=await u.json();if(s?.ok!==!0)return null;const l=t?s.value:s.value?.quota;if(!t&&s.value?.authenticated!==!0||!["ready","stale"].includes(l?.state))return null;const c=Array.isArray(l.buckets)?l.buckets.find(a=>a?.id==="codex"):null;if(!Array.isArray(c?.windows))return null;const o={};for(const a of c.windows){const i=a?.windowDurationMins===300?"five":a?.windowDurationMins===10080?"weekly":null,r=a?.usedPercent;if(!i||typeof r!="number"||!Number.isFinite(r)||r<0||r>100)continue;const n=new Date(typeof a.resetsAt=="number"&&a.resetsAt>0?a.resetsAt*1e3:NaN);o[i]={percent:Math.round(r*10)/10,resetsAt:Number.isFinite(n.getTime())?n.toISOString():""}}return o}catch{return null}}async function I(t){try{const u=await fetch("/_dsh/dsh-chatgpt-sub/getCodexBridgeStatus",{credentials:"same-origin",redirect:"error",headers:{accept:"application/json"},signal:AbortSignal.timeout(8e3)});if(!u.ok)return null;const s=await u.json();if(s?.ok!==!0||s.bound!==!0||s.routeConfigured!==!0)return null;const l=await t?.();return l?.ok===!0?l.value:null}catch{return null}}const _="cm-stat-dialog cm-codex-compat-dialog";if(typeof document<"u"){const t=document.createElement("style");t.textContent=".cm-codex-compat-dialog{width:min(560px,94vw)}.cm-codex-compat{display:flex;flex-direction:column;gap:8px;font-size:13px}.cm-codex-compat :is(h3,p){margin:0}.cm-codex-compat h3{font-size:14px;font-weight:600}",t.textContent+='@media (max-width:1023px){.cm-codex-compat-dialog{width:calc(100vw - 32px)}.cm-codex-compat{padding:0 2px}}body[data-dsh-pocket-layout="mobile"] .cm-codex-compat-dialog{width:calc(100vw - 32px)}',document.head.appendChild(t)}const N="dsh-cost-meter:codex-compat-prompt-dismissed",x=new Set;let A=!1;function j(){if(A)return!0;try{return window.localStorage.getItem(N)==="1"}catch{return!1}}function M(){A=!0;try{window.localStorage.setItem(N,"1")}catch{}for(const t of x)t(!0)}function S(){const[t,u]=m(!1),[s,l]=m(null),c=v(!1);return[t,s,a=>{c.current||(c.current=!0,u(!0),l(null),Promise.resolve().then(a).catch(i=>l(i?.message??String(i))).finally(()=>{c.current=!1,u(!1)}))}]}function k(t){const s=t.state?.codexCompat,l=t.api,c=t.locale==="en",o=(C,E)=>c?E:C,a=v(null),[i,r,n]=S(),[d,p]=m(j),f=s?.enabled===!0&&s?.promptDue===!0&&!d;if(h(()=>(x.add(p),()=>x.delete(p)),[]),h(()=>{f&&a.current&&!a.current.open&&a.current.showModal()},[f]),!f)return null;const y=s.usage??{},b=()=>{a.current?.close(),p(!0),M(),Promise.resolve().then(()=>l.dismissCodexCompat()).catch(()=>{})};return e("dialog",{ref:a,className:_,"aria-label":o("兼容修复","Compatibility fix"),onCancel:C=>{C.preventDefault(),b()}},e("header",{className:"cm-stat-dialog-head"},o("兼容修复","Compatibility fix"),e("button",{type:"button",className:"cm-btn","aria-label":o("关闭","Close"),onClick:b},"×")),e("div",{className:"cm-stat-dialog-body"},e("p",null,o("检测到 dsh-codex-subscription {version}。Codex 订阅用量不计入 API 费用;为兼容本插件,新产生的 Codex 用量已自动归类为 Plan。是否将历史 codex 类模型的计费统一归类为 Plan(订阅额度,不计入 API 费用)?","Detected dsh-codex-subscription {version}. Codex subscription usage is not billed as API usage; for compatibility this plugin now defaults new Codex usage to Plan. Reclassify the billing of historical codex-class models as Plan (subscription quota, excluded from API usage)?").replace("{version}","v"+(s.version??""))),y.calls>0?e("p",{className:"cm-note"},o("历史 Codex 用量:{calls} 次调用 · {cost} · {days} 天","Historical Codex usage: {calls} calls · {cost} · {days} days").replace("{calls}",y.calls).replace("{cost}","$"+Number(y.cost??0).toFixed(2)).replace("{days}",y.days)):null,r?e("div",{className:"cm-msg err"},o("失败:","Failed: ")+r):null,e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",onClick:b},o("保持现状","Keep status quo")),e("button",{type:"button",className:"cm-btn primary",disabled:i,onClick:()=>n(l.applyCodexCompatHistory)},o("统一归类为 Plan","Reclassify as Plan"))),e("p",{className:"cm-note"},o("之后可在 设置 → 费用 → Codex 订阅兼容 中处理。","You can change this later in Settings → Cost → Codex subscription compatibility."))))}function P(t){const s=t.state?.codexCompat,[l,c,o]=S();if(s?.installed!==!0||s?.enabled!==!0)return null;const a=t.api,i=t.t,r=t.locale==="en",n=(y,b)=>r?b:y,d=s.usage??{},p=s.historyAppliedAt>0,f=s.planClass==="plan"?i("billingClassPlan"):s.planClass==="api"?i("billingClassApi"):i("billingClassAuto");return e("div",{className:"cm-codex-compat"},e("h3",null,n("Codex 订阅兼容","Codex subscription compatibility")),e("p",null,n("检测版本:{version}","Detected version: {version}").replace("{version}","v"+(s.version??""))),e("p",null,n("当前计费方式:{planClass}","Current billing class: {planClass}").replace("{planClass}",f)),e("p",null,n("历史用量:{calls} 次调用 · {cost} · {tokens} tokens · {days} 天","Historical usage: {calls} calls · {cost} · {tokens} tokens · {days} days").replace("{calls}",d.calls).replace("{cost}","$"+Number(d.cost??0).toFixed(2)).replace("{tokens}",Number(d.tokens??0).toLocaleString(r?"en-US":"zh-CN")).replace("{days}",d.days)),c?e("div",{className:"cm-msg err",role:"alert"},n("失败:","Failed: ")+c):null,p?e("p",{className:"cm-note"},n("已归类于 {time}","Reclassified at {time}").replace("{time}",new Date(s.historyAppliedAt).toLocaleString())):e("p",null,n("历史用量未归类。","Historical usage is not reclassified yet.")),!p&&d.providers?.length?e("p",{className:"cm-note"},n("来源:{providers}","Sources: {providers}").replace("{providers}",d.providers.join(", "))):null,p?null:e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn primary",disabled:l,onClick:()=>o(a.applyCodexCompatHistory)},n("统一归类为 Plan","Reclassify as Plan"))),!p&&s.promptDismissed===!0?e("p",{className:"cm-note"},n("此前选择保持现状,可随时统一归类。","You chose Keep status quo earlier; you can reclassify anytime.")):null)}function q(){return t=>e(t.view==="prompt"?k:P,t)}return{mount:q,CodexCompatPrompt:k,CodexCompatPanel:P,readChatgptQuota:D,readChatgptSubQuota:I}}});
|
package/lib/client.community.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.community.js",factory:
|
|
1
|
+
;(function(a){const e=window.__ModuleLoader__,o=e[Symbol.for("@dsh-plugin/dsh-loader:load-wrap")];return(a.id==="dsh-cost-meter"&&e.load===o?.ours&&typeof o.original=="function"?o.original:e.load).call(e,a)})({id:"dsh-cost-meter",chunk:"client.community.js",factory:d=>{const a=d("react"),{createElement:e,useState:o,useEffect:u}=a,c="dsh-cost-meter:community-notice-seen",s=new Set;let m=!1;function b(){if(m)return!0;try{return window.localStorage.getItem(c)==="1"}catch{return!1}}function w({locale:i,footer:t=!1}){const[p,l]=o(b),n=i==="en",h="https://github.com/Han-1413141/dsh-cost-meter/blob/master/"+(n?"README.md#community":"README.zh-CN.md#交流与反馈"),g=()=>{m=!0;try{window.localStorage.setItem(c,"1")}catch{}l(!0);for(const r of s)r(!0)};u(()=>{s.add(l);const r=f=>{if(f.key===c&&f.newValue==="1"){m=!0;for(const v of s)v(!0)}};return window.addEventListener("storage",r),()=>{s.delete(l),window.removeEventListener("storage",r)}},[]);const y={href:h,target:"_blank",rel:"noopener noreferrer"};return t?p?e("footer",{className:"cm-community-entry"},e("a",y,n?"Community & feedback ↗":"交流与反馈 ↗")):null:p?null:e("aside",{className:"cm-community-notice",role:"status"},e("span",null,n?"The plugin WeChat group is open":"插件交流群已开放"),e("a",y,n?"View QR code ↗":"查看二维码 ↗"),e("button",{type:"button",className:"cm-btn small","aria-label":n?"Dismiss community notice":"关闭交流群提示",onClick:g},"×"))}function x(i){const t=document.createElement("style");return t.textContent=".cm-community-notice{display:flex;align-items:center;gap:12px;flex-wrap:wrap;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);font-size:12px;color:var(--dsw-alias-label-secondary)}.cm-community-notice button{margin-left:auto;flex:none;min-width:28px;min-height:28px}.cm-community-notice a,.cm-community-entry a{color:var(--dsw-alias-state-business-primary,var(--dsw-alias-brand-primary,#4d6bfe));text-decoration:none}.cm-community-notice a:hover,.cm-community-entry a:hover{text-decoration:underline}.cm-community-entry{display:flex;border-top:1px solid var(--dsw-alias-border-l1);padding-top:12px;font-size:12px}.cm-community-notice :focus-visible,.cm-community-entry a:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary,#4d6bfe);outline-offset:3px;border-radius:4px}",t.textContent+='@media (max-width:1023px){.cm-community-notice{padding:8px 10px;gap:8px}}body[data-dsh-pocket-layout="mobile"] .cm-community-notice{flex-wrap:wrap}',document.head.appendChild(t),i.effect(()=>()=>t.remove(),"cost-meter: community styles"),w}return{mount:x}}});
|