dsh-cost-meter 1.8.36 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/backfill.js CHANGED
@@ -258,13 +258,31 @@ export function listSessionLogs(root, onlySessionIds = null) {
258
258
  return listSessionLogFiles(root, onlySessionIds)
259
259
  }
260
260
 
261
- /** Merge the plugin journal before replay, so UUID dedup also covers repaired v1.7.21 logs. */
262
- async function* sessionBillingRecords(ledger, sessionsRoot, onlySessionIds = null) {
261
+ /**
262
+ * Merge the plugin journal before replay, so UUID dedup also covers repaired v1.7.21 logs.
263
+ * @param sessionSource - 可选的统一会话记录源(T3):非空时用
264
+ * `listSessions(onlySessionIds)` 枚举 + `readRecords(id)` 读取(JSONL 文件或 SQLite
265
+ * 由适配器自动选择);为空时保持原有 `listSessionLogs` 文件枚举路径不变。
266
+ */
267
+ async function* sessionBillingRecords(ledger, sessionsRoot, onlySessionIds = null, sessionSource = null) {
263
268
  const seen = new Set()
264
- for (const path of listSessionLogs(sessionsRoot, onlySessionIds)) {
269
+ const hasSource = sessionSource !== null && sessionSource !== undefined
270
+ const sessions = hasSource ? await sessionSource.listSessions(onlySessionIds) : null
271
+ const paths = hasSource ? null : listSessionLogs(sessionsRoot, onlySessionIds)
272
+ for (const entry of sessions ?? paths) {
265
273
  let records
266
- try { records = await readSessionRecordsAsync(path) } catch { yield null; continue }
267
- const id = records.find(record => record.type === 'session')?.id
274
+ let id
275
+ try {
276
+ if (hasSource) {
277
+ id = typeof entry?.id === 'string' ? entry.id : ''
278
+ if (id.length === 0) continue
279
+ records = await sessionSource.readRecords(id)
280
+ } else {
281
+ records = await readSessionRecordsAsync(entry)
282
+ id = records.find(record => record.type === 'session')?.id
283
+ }
284
+ } catch { yield null; continue }
285
+ if (!Array.isArray(records)) { yield null; continue }
268
286
  if (typeof id === 'string') {
269
287
  seen.add(id)
270
288
  try { for (const record of await nativeSearchRecordsFor(ledger.path, id)) records.push(record) } catch { /* Keep the readable host prefix. */ }
@@ -291,8 +309,11 @@ async function* sessionBillingRecords(ledger, sessionsRoot, onlySessionIds = nul
291
309
  }
292
310
  }
293
311
 
294
- /** Recover only recent, fully covered days. Neither calls nor recorded costs change. */
295
- export async function repairPlanHourBuckets(ledger, sessionsRoot, { nowMs = Date.now(), isActive = () => true } = {}) {
312
+ /**
313
+ * Recover only recent, fully covered days. Neither calls nor recorded costs change.
314
+ * @param sessionSource - 可选统一会话记录源(T3);为空时走原 JSONL 文件枚举。
315
+ */
316
+ export async function repairPlanHourBuckets(ledger, sessionsRoot, { nowMs = Date.now(), isActive = () => true } = {}, sessionSource = null) {
296
317
  const config = structuredClone(ledger.config), fingerprint = planUsageFingerprint(config)
297
318
  const historyReset = structuredClone(ledger.historyReset ?? null)
298
319
  const from = nowMs - HOUR_BUCKET_RETENTION_MS
@@ -304,7 +325,7 @@ export async function repairPlanHourBuckets(ledger, sessionsRoot, { nowMs = Date
304
325
  }
305
326
  if (!sessionIds.size || !isActive() || ledger.closed) return { days: 0 }
306
327
  const byDay = new Map(), enabled = enabledPlanSetOf(config)
307
- for await (const records of sessionBillingRecords(ledger, sessionsRoot, sessionIds)) {
328
+ for await (const records of sessionBillingRecords(ledger, sessionsRoot, sessionIds, sessionSource)) {
308
329
  if (!isActive() || ledger.closed || planUsageFingerprint(ledger.config) !== fingerprint) return { days: 0 }
309
330
  if (!records) continue
310
331
  const replay = replaySessionRecords(records, config, dates, true)
@@ -598,9 +619,10 @@ export function replaySessionRecords(records, config, wantDates = null, collectS
598
619
  * 写入该会话当日的回放拆分。
599
620
  * @param ledger - 已打开的账本。
600
621
  * @param sessionsRoot - 宿主会话根目录($DSH_HOME/sessions)。
622
+ * @param sessionSource - 可选统一会话记录源(T3,better-session/RDB);为空时走原 JSONL 文件枚举。
601
623
  * @returns { days, sessions, scanned, titles } 实际填补的日期/会话数、扫描文件数与补齐的会话标题数。
602
624
  */
603
- export async function backfillLegacyLedger(ledger, sessionsRoot) {
625
+ export async function backfillLegacyLedger(ledger, sessionsRoot, sessionSource = null) {
604
626
  const result = { days: 0, sessions: 0, scanned: 0, titles: 0 }
605
627
  const needDates = new Set()
606
628
  for (const [date, day] of Object.entries(ledger.days ?? {})) {
@@ -648,7 +670,7 @@ export async function backfillLegacyLedger(ledger, sessionsRoot) {
648
670
  }
649
671
  }
650
672
  }
651
- for await (const records of sessionBillingRecords(ledger, sessionsRoot, onlySessionIds)) {
673
+ for await (const records of sessionBillingRecords(ledger, sessionsRoot, onlySessionIds, sessionSource)) {
652
674
  // 会话日志多时逐份解压会长时间占住事件循环:每 8 份让出一次,不卡宿主 UI;
653
675
  // 单文件内部亦为流式读取(v1.7.7,issue #88:解压期间周期性让出,大日志不再卡死宿主)。
654
676
  if ((scannedCount += 1) % 8 === 0) await new Promise(resolve => setImmediate(resolve))
@@ -891,13 +913,14 @@ function sessionEntryOf(sessionId, info, totals, pm) {
891
913
  * - 同一会话跨安装时刻:实时条目已存在,安装前用量不计入(无法安全拆分)。
892
914
  * @param ledger - 已打开的账本。
893
915
  * @param sessionsRoot - 宿主会话根目录($DSH_HOME/sessions)。
916
+ * @param sessionSource - 可选统一会话记录源(T3,better-session/RDB);为空时走原 JSONL 文件枚举。
894
917
  * @returns { days, sessions, scanned } 重建/追加的日期数、新增会话数与扫描文件数。
895
918
  */
896
- export async function importLegacyHistory(ledger, sessionsRoot) {
919
+ export async function importLegacyHistory(ledger, sessionsRoot, sessionSource = null) {
897
920
  const result = { days: 0, sessions: 0, scanned: 0 }
898
921
  const bySession = new Map()
899
922
  let scannedCount = 0
900
- for await (const records of sessionBillingRecords(ledger, sessionsRoot)) {
923
+ for await (const records of sessionBillingRecords(ledger, sessionsRoot, null, sessionSource)) {
901
924
  if ((scannedCount += 1) % 8 === 0) await new Promise(resolve => setImmediate(resolve))
902
925
  result.scanned += 1
903
926
  let replayed
@@ -988,9 +1011,13 @@ export async function importLegacyHistory(ledger, sessionsRoot) {
988
1011
  * @param ledger - 已打开的账本(config 已是目标币种价格表)。
989
1012
  * @param sessionsRoot - 宿主会话根目录($DSH_HOME/sessions)。
990
1013
  * @param includeBucket - 可选的 (providerModelKey, date) 过滤器,仅修复目标价格路径。
1014
+ * @param onlySessionIds - 可选:仅回放这些会话。
1015
+ * @param explicit - 是否显式重定价(设置页 RPC),会记录前后金额与历史快照。
1016
+ * @param model - 可选的单个 provider:model 键。
1017
+ * @param sessionSource - 可选统一会话记录源(T3,better-session/RDB);为空时走原 JSONL 文件枚举。
991
1018
  * @returns {{ scanned, recostedSessions, skippedSessions, recostedDays }}。
992
1019
  */
993
- export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeBucket, onlySessionIds = null, explicit = false, model = '') {
1020
+ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeBucket, onlySessionIds = null, explicit = false, model = '', sessionSource = null) {
994
1021
  const result = { scanned: 0, recostedSessions: 0, skippedSessions: 0, recostedDays: 0 }
995
1022
  const pricingConfig = explicit ? currentPricingConfig(ledger.config) : ledger.config
996
1023
  if (explicit && model) pricingConfig._repriceFxConfig = ledger.config
@@ -999,7 +1026,7 @@ export async function recomputeLedgerPricingBasis(ledger, sessionsRoot, includeB
999
1026
  const reset = JSON.stringify(ledger.historyReset ?? null)
1000
1027
  const startedAt = Date.now()
1001
1028
  const bySession = new Map()
1002
- for await (const records of sessionBillingRecords(ledger, sessionsRoot, onlySessionIds)) {
1029
+ for await (const records of sessionBillingRecords(ledger, sessionsRoot, onlySessionIds, sessionSource)) {
1003
1030
  if ((result.scanned += 1) % 8 === 0) await new Promise(resolve => setImmediate(resolve))
1004
1031
  let replayed
1005
1032
  try {
@@ -1114,17 +1141,23 @@ function subtractBucketInto(target, source) {
1114
1141
  * 减法逐字段 clamp ≥ 0,即使账本未被污染(种子量为 0)也无副作用。
1115
1142
  * @param ledger - 已打开的账本。
1116
1143
  * @param sessionsRoot - 宿主会话根目录($DSH_HOME/sessions)。
1144
+ * @param sessionSource - 可选统一会话记录源(T3,better-session/RDB);为空时走原 JSONL 文件枚举。
1117
1145
  * @returns { sessions, days, scanned } 受影响的 fork 会话数、扣除的日期数与扫描文件数。
1118
1146
  */
1119
- export async function repairForkSeed(ledger, sessionsRoot) {
1147
+ export async function repairForkSeed(ledger, sessionsRoot, sessionSource = null) {
1120
1148
  const result = { sessions: 0, days: 0, scanned: 0 }
1121
- for (const path of listSessionLogs(sessionsRoot)) {
1149
+ const hasSource = sessionSource !== null && sessionSource !== undefined
1150
+ // 统一记录源(T3):RDB 下从数据库枚举会话;未传源时保持原 JSONL 文件枚举路径不变。
1151
+ const entries = hasSource
1152
+ ? (await sessionSource.listSessions()).map(row => (typeof row === 'string' ? row : row?.id)).filter(id => typeof id === 'string' && id.length > 0)
1153
+ : listSessionLogs(sessionsRoot)
1154
+ for (const entry of entries) {
1122
1155
  // 全量同步扫描会长时间占住事件循环:每 8 份让出一次(与回填/导入同策略);
1123
1156
  // 单文件内部亦为流式读取(v1.7.7,issue #88)。
1124
1157
  if ((result.scanned += 1) % 8 === 0) await new Promise(resolve => setImmediate(resolve))
1125
1158
  let records
1126
1159
  try {
1127
- records = await readSessionRecordsAsync(path)
1160
+ records = hasSource ? await sessionSource.readRecords(entry) : await readSessionRecordsAsync(entry)
1128
1161
  } catch {
1129
1162
  continue // 单文件损坏(含解压预算超限)不阻断整体清洗。
1130
1163
  }
@@ -2,6 +2,7 @@
2
2
  import { join } from 'node:path'
3
3
  import { resolveDshHome } from '@deepseek-ai/dsh-home-paths'
4
4
  import { listSessionLogs, iterateSessionRecords } from './backfill.js'
5
+ import { probeSessionStorage, readSessionRecords } from './session-storage-compat.js'
5
6
 
6
7
  const LIMIT = 16000
7
8
  const validSeq = n => Number.isSafeInteger(n) && n >= 0
@@ -114,6 +115,11 @@ export async function getCallInspection(ctx, query) {
114
115
  || !validSeq(query.offset ?? 0) || (query.offset ?? 0) > 1e7) throw new Error('invalid call inspection query')
115
116
  const live = ctx?.get?.('sessions')?.get?.(query.sessionId)?.snapshotEvents?.()
116
117
  if (Array.isArray(live)) return inspectCall(live, query.seq, query.offset ?? 0, query.atMs)
118
+ // RDB(会话 SQLite)宿主不再落 JSONL 文件:通过兼容层读同一份 records 事件源。
119
+ if (probeSessionStorage(ctx).mode === 'rdb') {
120
+ const stored = await readSessionRecords(ctx, query.sessionId, { maxEvents: 500_000 })
121
+ return inspectCall(stored?.records ?? [], query.seq, query.offset ?? 0, query.atMs)
122
+ }
117
123
  const paths = listSessionLogs(join(resolveDshHome(), 'sessions'), new Set([query.sessionId]))
118
124
  return inspectCall(paths.length ? iterateSessionRecords(paths[0]) : [], query.seq, query.offset ?? 0, query.atMs)
119
125
  }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @eddyskywalker/dsh-chatgpt-subscription 兼容(9 条订阅线路归 Plan)。
3
+ *
4
+ * 该插件注册 9 条走「订阅额度」的 LLM provider(codex-chatgpt / claude-subscription /
5
+ * antigravity / kimi-code / minimax-code / command-code / workbuddy-subscription /
6
+ * glm-coding-plan / step-code),用量消耗的是各订阅账户的额度,不应计入 API 真金白银。
7
+ *
8
+ * 本模块负责(均为纯本地逻辑,**绝不发起网络请求**):
9
+ * 1. 泛化检测该插件是否安装(复用 codex-subscription-compat.js 的
10
+ * detectSubscriptionPackage,支持 scoped 包名的三条路径);
11
+ * 2. 启动时把这些线路 provider 对应的 Plan 提供商 id 归类写为 'plan'
12
+ * (只影响新用量;历史 apiCost 不在此重算),用户显式选择的 plan/api 不覆盖。
13
+ */
14
+
15
+ import { detectSubscriptionPackage } from './codex-subscription-compat.js'
16
+
17
+ /** @eddyskywalker/dsh-chatgpt-subscription 的 npm 包名(检测与前端展示共用)。 */
18
+ export const CHATGPT_SUBSCRIPTION_PACKAGE = '@eddyskywalker/dsh-chatgpt-subscription'
19
+
20
+ /**
21
+ * 9 条订阅线路 provider → dsh-cost-meter 的 Plan 提供商 id。
22
+ *
23
+ * provider 名来自该插件注册的 LLM provider;planId 必须存在于
24
+ * lib/plan-billing.js 的 PLAN_PROVIDER_IDS(否则 store.js 清洗/校验会丢弃配置)。
25
+ */
26
+ export const CHATGPT_SUBSCRIPTION_PROVIDER_PLANS = Object.freeze({
27
+ 'codex-chatgpt': 'codex',
28
+ 'claude-subscription': 'anthropic',
29
+ antigravity: 'antigravity',
30
+ 'kimi-code': 'kimi',
31
+ 'minimax-code': 'minimax',
32
+ 'command-code': 'commandcode',
33
+ 'workbuddy-subscription': 'workbuddy',
34
+ 'glm-coding-plan': 'zai',
35
+ 'step-code': 'stepfun',
36
+ })
37
+
38
+ /**
39
+ * 检测 @eddyskywalker/dsh-chatgpt-subscription 是否安装(纯本地)。
40
+ *
41
+ * detectSubscriptionPackage 的薄包装;options 与 detectCodexSubscription 相同
42
+ * ({ moduleUrl, env, homeDir, profileDir, fs }),便于测试注入假 fs/env。
43
+ *
44
+ * @returns {{ installed: boolean, version: string, detection: 'package'|'profile'|'none', packagePath: string }}
45
+ */
46
+ export function detectChatgptSubscription(options = {}) {
47
+ return detectSubscriptionPackage(CHATGPT_SUBSCRIPTION_PACKAGE, options)
48
+ }
49
+
50
+ /**
51
+ * 启动时调用:检测到该插件后,把尚未显式配置的线路 provider 归类写为 'plan'。
52
+ *
53
+ * - 只覆盖 undefined / 'auto'(以及任何非法值);用户显式选择的 'plan'/'api' 不覆盖;
54
+ * - 不调用 splitLedgerApiCost:历史 apiCost 保持原样(仅影响新用量);
55
+ * - 全部写完后只调用一次 ledger.scheduleWrite()。
56
+ *
57
+ * @param ledger - 账本(至少需要 config.planBilling.providers 与 scheduleWrite)。
58
+ * @param detection - detectChatgptSubscription() 结果。
59
+ * @returns {{ changed: boolean, planIds: string[] }} planIds 为本次实际写成 'plan' 的提供商 id。
60
+ */
61
+ export function ensureChatgptSubscriptionPlan(ledger, detection) {
62
+ if (detection?.installed !== true) return { changed: false, planIds: [] }
63
+ const config = ledger?.config
64
+ if (config === null || typeof config !== 'object' || Array.isArray(config)) return { changed: false, planIds: [] }
65
+ const billing = config.planBilling
66
+ if (billing === null || typeof billing !== 'object' || Array.isArray(billing)) return { changed: false, planIds: [] }
67
+ const current = billing.providers
68
+ const providers = current !== null && typeof current === 'object' && !Array.isArray(current) ? current : (billing.providers = {})
69
+ const planIds = []
70
+ for (const planId of Object.values(CHATGPT_SUBSCRIPTION_PROVIDER_PLANS)) {
71
+ const value = providers[planId]
72
+ if (value === 'plan' || value === 'api') continue
73
+ providers[planId] = 'plan'
74
+ planIds.push(planId)
75
+ }
76
+ if (planIds.length === 0) return { changed: false, planIds }
77
+ ledger.scheduleWrite?.()
78
+ return { changed: true, planIds }
79
+ }
@@ -0,0 +1 @@
1
+ window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.codex.js",factory:g=>{const f=g("react"),{createElement:e,useState:C,useEffect:h,useRef:v}=f,N="cm-stat-dialog cm-codex-compat-dialog";if(typeof document<"u"){const s=document.createElement("style");s.textContent=".cm-codex-compat-dialog{width:min(560px,94vw)}.cm-codex-compat{display:flex;flex-direction:column;gap:8px;font-size:13px}",s.textContent+='@media (max-width:1023px){.cm-codex-compat-dialog{width:calc(100vw - 24px);max-height:90vh;overflow:auto}.cm-codex-compat{padding:0 2px}}body[data-dsh-pocket-layout="mobile"] .cm-codex-compat-dialog{width:calc(100vw - 24px)}',document.head.appendChild(s)}function w(){const[s,u]=C(!1),[a,c]=C(null);return[s,a,o=>{s||(u(!0),c(null),o().catch(t=>c(t?.message??String(t))).finally(()=>u(!1)))}]}function y(s){const a=s.state?.codexCompat,c=s.api,i=s.locale==="en",o=(x,A)=>i?A:x,t=v(null),[l,n,p]=w(),r=a?.promptDue===!0;if(h(()=>{r&&t.current&&!t.current.open&&t.current.showModal()},[r]),!r)return null;const d=a.usage??{},m=()=>p(c.dismissCodexCompat);return e("dialog",{ref:t,className:N,"aria-label":o("兼容修复","Compatibility fix"),onCancel:x=>{x.preventDefault(),m()}},e("header",{className:"cm-stat-dialog-head"},o("兼容修复","Compatibility fix"),e("button",{type:"button",className:"cm-btn","aria-label":o("关闭","Close"),disabled:l,onClick:m},"×")),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"+(a.version??""))),d.calls>0?e("p",{className:"cm-note"},o("历史 Codex 用量:{calls} 次调用 · {cost} · {days} 天","Historical Codex usage: {calls} calls · {cost} · {days} days").replace("{calls}",d.calls).replace("{cost}","$"+Number(d.cost??0).toFixed(2)).replace("{days}",d.days)):null,n?e("div",{className:"cm-msg err"},o("失败:","Failed: ")+n):null,e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn",disabled:l,onClick:m},o("保持现状","Keep status quo")),e("button",{type:"button",className:"cm-btn primary",disabled:l,onClick:()=>p(c.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 b(s){const a=s.state?.codexCompat;if(a?.installed!==!0)return null;const c=s.api,i=s.t,o=s.locale==="en",t=(r,d)=>o?d:r,l=a.usage??{},n=a.historyAppliedAt>0,p=a.planClass==="plan"?i("billingClassPlan"):a.planClass==="api"?i("billingClassApi"):i("billingClassAuto");return e("div",{className:"cm-codex-compat"},e("h3",null,t("Codex 订阅兼容","Codex subscription compatibility")),e("p",null,t("检测版本:{version}","Detected version: {version}").replace("{version}","v"+(a.version??""))),e("p",null,t("当前计费方式:{planClass}","Current billing class: {planClass}").replace("{planClass}",p)),e("p",null,t("历史用量:{calls} 次调用 · {cost} · {tokens} tokens · {days} 天","Historical usage: {calls} calls · {cost} · {tokens} tokens · {days} days").replace("{calls}",l.calls).replace("{cost}","$"+Number(l.cost??0).toFixed(2)).replace("{tokens}",Number(l.tokens??0).toLocaleString(o?"en-US":"zh-CN")).replace("{days}",l.days)),n?e("p",{className:"cm-note"},t("已归类于 {time}","Reclassified at {time}").replace("{time}",new Date(a.historyAppliedAt).toLocaleString())):e("p",null,t("历史用量未归类。","Historical usage is not reclassified yet.")),!n&&l.providers?.length?e("p",{className:"cm-note"},t("来源:{providers}","Sources: {providers}").replace("{providers}",l.providers.join(", "))):null,n?null:e("div",{className:"cm-buttons"},e("button",{type:"button",className:"cm-btn primary",onClick:()=>c.applyCodexCompatHistory().catch(()=>{})},t("统一归类为 Plan","Reclassify as Plan"))),!n&&a.promptDismissed===!0?e("p",{className:"cm-note"},t("此前选择保持现状,可随时统一归类。","You chose Keep status quo earlier; you can reclassify anytime.")):null)}function P(){return{CodexCompatPrompt:y,CodexCompatPanel:b}}return{mount:P,CodexCompatPrompt:y,CodexCompatPanel:b}}});
@@ -1 +1 @@
1
- window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.community.js",factory:d=>{const y=d("react"),{createElement:e,useState:p,useEffect:f}=y,a="dsh-cost-meter:community-notice-seen",r=new Set;let i=!1;function b(){if(i)return!0;try{return window.localStorage.getItem(a)==="1"}catch{return!1}}function w({locale:s,footer:t=!1}){const[m,c]=p(b),n=s==="en",h="https://github.com/Han-1413141/dsh-cost-meter/blob/master/"+(n?"README.md#community":"README.zh-CN.md#交流与反馈"),g=()=>{i=!0;try{window.localStorage.setItem(a,"1")}catch{}c(!0);for(const o of r)o(!0)};f(()=>{r.add(c);const o=u=>{if(u.key===a&&u.newValue==="1"){i=!0;for(const v of r)v(!0)}};return window.addEventListener("storage",o),()=>{r.delete(c),window.removeEventListener("storage",o)}},[]);const l={href:h,target:"_blank",rel:"noopener noreferrer"};return t?m?e("footer",{className:"cm-community-entry"},e("a",l,n?"Community & feedback ↗":"交流与反馈 ↗")):null:m?null:e("aside",{className:"cm-community-notice",role:"status"},e("span",null,n?"The plugin WeChat group is open":"插件交流群已开放"),e("a",l,n?"View QR code ↗":"查看二维码 ↗"),e("button",{type:"button",className:"cm-btn small","aria-label":n?"Dismiss community notice":"关闭交流群提示",onClick:g},"×"))}function x(s){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}",document.head.appendChild(t),s.effect(()=>()=>t.remove(),"cost-meter: community styles"),w}return{mount:x}}});
1
+ window.__ModuleLoader__.load({id:"dsh-cost-meter",chunk:"client.community.js",factory:u=>{const p=u("react"),{createElement:e,useState:y,useEffect:f}=p,s="dsh-cost-meter:community-notice-seen",r=new Set;let i=!1;function b(){if(i)return!0;try{return window.localStorage.getItem(s)==="1"}catch{return!1}}function x({locale:a,footer:t=!1}){const[m,c]=y(b),n=a==="en",h="https://github.com/Han-1413141/dsh-cost-meter/blob/master/"+(n?"README.md#community":"README.zh-CN.md#交流与反馈"),g=()=>{i=!0;try{window.localStorage.setItem(s,"1")}catch{}c(!0);for(const o of r)o(!0)};f(()=>{r.add(c);const o=d=>{if(d.key===s&&d.newValue==="1"){i=!0;for(const v of r)v(!0)}};return window.addEventListener("storage",o),()=>{r.delete(c),window.removeEventListener("storage",o)}},[]);const l={href:h,target:"_blank",rel:"noopener noreferrer"};return t?m?e("footer",{className:"cm-community-entry"},e("a",l,n?"Community & feedback ↗":"交流与反馈 ↗")):null:m?null:e("aside",{className:"cm-community-notice",role:"status"},e("span",null,n?"The plugin WeChat group is open":"插件交流群已开放"),e("a",l,n?"View QR code ↗":"查看二维码 ↗"),e("button",{type:"button",className:"cm-btn small","aria-label":n?"Dismiss community notice":"关闭交流群提示",onClick:g},"×"))}function w(a){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),a.effect(()=>()=>t.remove(),"cost-meter: community styles"),x}return{mount:w}}});