@jxgame2020/dsh-token-quota 0.1.52 → 0.1.54

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/client.js CHANGED
@@ -132,7 +132,7 @@ window.__ModuleLoader__.load({
132
132
  d.transcribe = settings;
133
133
  },
134
134
  setUpgrade: (d, upgrade) => {
135
- const normalized = upgrade !== null && upgrade.latestVersion !== "" && upgrade.latestVersion !== "0.1.52" ? upgrade : null;
135
+ const normalized = upgrade !== null && upgrade.latestVersion !== "" && upgrade.latestVersion !== "0.1.54" ? upgrade : null;
136
136
  if (d.upgrade === null || d.upgrade.latestVersion !== normalized?.latestVersion) d.upgradeDismissed = false;
137
137
  d.upgrade = normalized;
138
138
  },
@@ -262,147 +262,147 @@ window.__ModuleLoader__.load({
262
262
  document.head.appendChild(tag);
263
263
  }
264
264
  var TokenQuotaPanel_module_css_default = {
265
- "balanceBarDim": "NPLLIq_balanceBarDim",
266
- "logPageSizeSelect": "NPLLIq_logPageSizeSelect",
267
- "upgradeBannerFlash": "NPLLIq_upgradeBannerFlash",
268
- "rowDragging": "NPLLIq_rowDragging",
269
- "noteWin": "NPLLIq_noteWin",
270
- "row": "NPLLIq_row",
271
- "balanceBarBadge": "NPLLIq_balanceBarBadge",
272
- "fullNotice": "NPLLIq_fullNotice",
273
- "tabIcon": "NPLLIq_tabIcon",
274
- "upgradeBanner": "NPLLIq_upgradeBanner",
275
- "logSearch": "NPLLIq_logSearch",
276
- "resetRow": "NPLLIq_resetRow",
277
- "noteWinTitle": "NPLLIq_noteWinTitle",
278
- "balanceToggleOpen": "NPLLIq_balanceToggleOpen",
265
+ "panelDimStrong": "NPLLIq_panelDimStrong",
266
+ "balanceStateError": "NPLLIq_balanceStateError",
267
+ "noteNew": "NPLLIq_noteNew",
268
+ "rowHeader": "NPLLIq_rowHeader",
269
+ "balanceWinHeader": "NPLLIq_balanceWinHeader",
270
+ "balanceValueOk": "NPLLIq_balanceValueOk",
279
271
  "balanceBarError": "NPLLIq_balanceBarError",
280
- "balanceValueError": "NPLLIq_balanceValueError",
281
- "monitorList": "NPLLIq_monitorList",
282
- "noteChip": "NPLLIq_noteChip",
283
- "rowName": "NPLLIq_rowName",
284
- "balanceLastLine": "NPLLIq_balanceLastLine",
285
272
  "dialogSection": "NPLLIq_dialogSection",
286
- "balanceWinTitle": "NPLLIq_balanceWinTitle",
287
- "logClearDate": "NPLLIq_logClearDate",
288
- "rowDropTarget": "NPLLIq_rowDropTarget",
289
- "dialogTabs": "NPLLIq_dialogTabs",
290
- "rowDrag": "NPLLIq_rowDrag",
291
- "logDayCol": "NPLLIq_logDayCol",
292
- "monitorRow": "NPLLIq_monitorRow",
293
- "keyRow": "NPLLIq_keyRow",
294
- "title": "NPLLIq_title",
295
- "fillIdle": "NPLLIq_fillIdle",
296
- "header": "NPLLIq_header",
297
- "noteWinBar": "NPLLIq_noteWinBar",
298
- "balanceRow": "NPLLIq_balanceRow",
299
- "checkErrorHint": "NPLLIq_checkErrorHint",
300
- "dialogLabel": "NPLLIq_dialogLabel",
301
- "monitorHint": "NPLLIq_monitorHint",
302
- "collapse": "NPLLIq_collapse",
273
+ "monitorName": "NPLLIq_monitorName",
274
+ "logPagerBtn": "NPLLIq_logPagerBtn",
275
+ "headerText": "NPLLIq_headerText",
276
+ "fillWarn": "NPLLIq_fillWarn",
277
+ "logPagerInfo": "NPLLIq_logPagerInfo",
278
+ "upgradeCommand": "NPLLIq_upgradeCommand",
279
+ "input": "NPLLIq_input",
303
280
  "dialogClose": "NPLLIq_dialogClose",
304
- "keyBadgeOff": "NPLLIq_keyBadgeOff",
305
- "balanceValueLow": "NPLLIq_balanceValueLow",
306
- "checkUpdatesRow": "NPLLIq_checkUpdatesRow",
307
- "balanceToggle": "NPLLIq_balanceToggle",
308
- "checkBtn": "NPLLIq_checkBtn",
309
- "fillOver": "NPLLIq_fillOver",
310
- "balanceBar": "NPLLIq_balanceBar",
311
- "balanceValueOk": "NPLLIq_balanceValueOk",
312
- "upgradeCommandRow": "NPLLIq_upgradeCommandRow",
313
- "upgradeClose": "NPLLIq_upgradeClose",
314
- "dialogBtn": "NPLLIq_dialogBtn",
315
- "logPagerControls": "NPLLIq_logPagerControls",
281
+ "title": "NPLLIq_title",
282
+ "dialogTitle": "NPLLIq_dialogTitle",
316
283
  "tabLabel": "NPLLIq_tabLabel",
317
- "noteWinGripBar": "NPLLIq_noteWinGripBar",
318
- "noteWinCollapsed": "NPLLIq_noteWinCollapsed",
319
- "upgradeHint": "NPLLIq_upgradeHint",
320
- "controls": "NPLLIq_controls",
321
- "dialog": "NPLLIq_dialog",
322
- "upgradeBannerText": "NPLLIq_upgradeBannerText",
323
- "logModelCol": "NPLLIq_logModelCol",
324
- "balanceRefreshAll": "NPLLIq_balanceRefreshAll",
325
- "logPagerPages": "NPLLIq_logPagerPages",
326
284
  "logClearDialog": "NPLLIq_logClearDialog",
285
+ "dialogBtnPrimary": "NPLLIq_dialogBtnPrimary",
286
+ "logTable": "NPLLIq_logTable",
287
+ "dialogOverlay": "NPLLIq_dialogOverlay",
288
+ "balanceRowRefresh": "NPLLIq_balanceRowRefresh",
327
289
  "panelDim": "NPLLIq_panelDim",
328
- "body": "NPLLIq_body",
329
- "settingsDialog": "NPLLIq_settingsDialog",
330
- "logPagerBtn": "NPLLIq_logPagerBtn",
290
+ "header": "NPLLIq_header",
291
+ "dialogTabs": "NPLLIq_dialogTabs",
292
+ "noteWinGripBar": "NPLLIq_noteWinGripBar",
293
+ "upgradeClose": "NPLLIq_upgradeClose",
331
294
  "noteWinResize": "NPLLIq_noteWinResize",
332
- "versionNew": "NPLLIq_versionNew",
333
- "logDialog": "NPLLIq_logDialog",
334
- "panel": "NPLLIq_panel",
335
- "noteNewPlus": "NPLLIq_noteNewPlus",
336
- "balanceBarRefresh": "NPLLIq_balanceBarRefresh",
337
- "balanceWin": "NPLLIq_balanceWin",
338
- "gearBtn": "NPLLIq_gearBtn",
339
- "logHeader": "NPLLIq_logHeader",
340
- "keyBadgeOk": "NPLLIq_keyBadgeOk",
341
- "logPagerInfo": "NPLLIq_logPagerInfo",
342
- "input": "NPLLIq_input",
343
- "keyError": "NPLLIq_keyError",
344
- "keySaveBtn": "NPLLIq_keySaveBtn",
345
- "noticeError": "NPLLIq_noticeError",
346
- "subtitle": "NPLLIq_subtitle",
295
+ "resetRow": "NPLLIq_resetRow",
296
+ "noteWinTitleText": "NPLLIq_noteWinTitleText",
297
+ "checkUpdatesLabel": "NPLLIq_checkUpdatesLabel",
298
+ "version": "NPLLIq_version",
347
299
  "noteMenu": "NPLLIq_noteMenu",
348
- "fillWarn": "NPLLIq_fillWarn",
349
- "noteWinBtn": "NPLLIq_noteWinBtn",
350
- "logToolbar": "NPLLIq_logToolbar",
351
300
  "copyBtn": "NPLLIq_copyBtn",
352
- "version": "NPLLIq_version",
353
- "dialogTab": "NPLLIq_dialogTab",
354
- "logTable": "NPLLIq_logTable",
355
- "tab": "NPLLIq_tab",
301
+ "checkBtn": "NPLLIq_checkBtn",
302
+ "monitorHint": "NPLLIq_monitorHint",
303
+ "checkErrorHint": "NPLLIq_checkErrorHint",
356
304
  "save": "NPLLIq_save",
357
- "settingsBtn": "NPLLIq_settingsBtn",
358
- "balanceRowName": "NPLLIq_balanceRowName",
359
- "noteMenuItem": "NPLLIq_noteMenuItem",
360
- "dialogHint": "NPLLIq_dialogHint",
361
- "noteNew": "NPLLIq_noteNew",
362
- "currentBadge": "NPLLIq_currentBadge",
363
- "upgradeCommand": "NPLLIq_upgradeCommand",
305
+ "logPageSizeSelect": "NPLLIq_logPageSizeSelect",
306
+ "balanceRefreshAll": "NPLLIq_balanceRefreshAll",
307
+ "noticeError": "NPLLIq_noticeError",
308
+ "rowDrag": "NPLLIq_rowDrag",
309
+ "monitorList": "NPLLIq_monitorList",
310
+ "keyRow": "NPLLIq_keyRow",
311
+ "notesBar": "NPLLIq_notesBar",
312
+ "fillIdle": "NPLLIq_fillIdle",
313
+ "balanceWinBody": "NPLLIq_balanceWinBody",
314
+ "checkUpdatesRow": "NPLLIq_checkUpdatesRow",
315
+ "balanceBarDim": "NPLLIq_balanceBarDim",
316
+ "balanceValueError": "NPLLIq_balanceValueError",
317
+ "balanceToggleOpen": "NPLLIq_balanceToggleOpen",
318
+ "balanceBarLow": "NPLLIq_balanceBarLow",
319
+ "selectBtn": "NPLLIq_selectBtn",
320
+ "tabIcon": "NPLLIq_tabIcon",
321
+ "subtitle": "NPLLIq_subtitle",
322
+ "panel": "NPLLIq_panel",
364
323
  "upgradeCommands": "NPLLIq_upgradeCommands",
365
- "checkUpdatesLabel": "NPLLIq_checkUpdatesLabel",
366
- "noteChipOpen": "NPLLIq_noteChipOpen",
367
- "dialogBody": "NPLLIq_dialogBody",
368
- "balanceRowRefresh": "NPLLIq_balanceRowRefresh",
369
- "balanceRowHeader": "NPLLIq_balanceRowHeader",
370
- "headerActions": "NPLLIq_headerActions",
371
- "headerText": "NPLLIq_headerText",
372
- "dialogOverlay": "NPLLIq_dialogOverlay",
373
324
  "resetSelect": "NPLLIq_resetSelect",
374
325
  "notice": "NPLLIq_notice",
375
- "selectBtn": "NPLLIq_selectBtn",
376
- "noteMenuBackdrop": "NPLLIq_noteMenuBackdrop",
377
- "balanceBarText": "NPLLIq_balanceBarText",
378
- "panelDimStrong": "NPLLIq_panelDimStrong",
379
- "logPager": "NPLLIq_logPager",
380
- "monitorName": "NPLLIq_monitorName",
381
- "balanceSortBtn": "NPLLIq_balanceSortBtn",
382
- "balanceBarLow": "NPLLIq_balanceBarLow",
383
- "dialogHeader": "NPLLIq_dialogHeader",
384
- "logScroll": "NPLLIq_logScroll",
385
- "notesBar": "NPLLIq_notesBar",
386
- "balanceWinBody": "NPLLIq_balanceWinBody",
387
- "dialogTitle": "NPLLIq_dialogTitle",
388
326
  "logUsedCol": "NPLLIq_logUsedCol",
389
- "logClearBtn": "NPLLIq_logClearBtn",
390
- "rowMeta": "NPLLIq_rowMeta",
391
- "radioRow": "NPLLIq_radioRow",
392
- "balanceStateError": "NPLLIq_balanceStateError",
393
- "dialogBtnPrimary": "NPLLIq_dialogBtnPrimary",
394
- "copyBtnDone": "NPLLIq_copyBtnDone",
395
- "settingsBtnActive": "NPLLIq_settingsBtnActive",
327
+ "keyBadgeOff": "NPLLIq_keyBadgeOff",
328
+ "logHeader": "NPLLIq_logHeader",
329
+ "monitorRow": "NPLLIq_monitorRow",
330
+ "logPagerControls": "NPLLIq_logPagerControls",
331
+ "row": "NPLLIq_row",
332
+ "balanceBarRefresh": "NPLLIq_balanceBarRefresh",
333
+ "gearBtn": "NPLLIq_gearBtn",
334
+ "versionNew": "NPLLIq_versionNew",
396
335
  "switch": "NPLLIq_switch",
397
- "rowHeader": "NPLLIq_rowHeader",
398
336
  "balanceRowValue": "NPLLIq_balanceRowValue",
337
+ "keySaveBtn": "NPLLIq_keySaveBtn",
338
+ "keyError": "NPLLIq_keyError",
339
+ "headerActions": "NPLLIq_headerActions",
340
+ "noteWinCollapsed": "NPLLIq_noteWinCollapsed",
399
341
  "balanceStateHint": "NPLLIq_balanceStateHint",
400
- "dialogTabActive": "NPLLIq_dialogTabActive",
342
+ "upgradeBanner": "NPLLIq_upgradeBanner",
343
+ "balanceWinTitle": "NPLLIq_balanceWinTitle",
344
+ "dialogTab": "NPLLIq_dialogTab",
345
+ "noteChipOpen": "NPLLIq_noteChipOpen",
346
+ "noteWinBtn": "NPLLIq_noteWinBtn",
347
+ "noteChip": "NPLLIq_noteChip",
348
+ "rowMeta": "NPLLIq_rowMeta",
349
+ "logScroll": "NPLLIq_logScroll",
350
+ "noteMenuBackdrop": "NPLLIq_noteMenuBackdrop",
351
+ "bar": "NPLLIq_bar",
352
+ "balanceRowName": "NPLLIq_balanceRowName",
353
+ "copyBtnDone": "NPLLIq_copyBtnDone",
354
+ "logToolbar": "NPLLIq_logToolbar",
355
+ "balanceValueLow": "NPLLIq_balanceValueLow",
356
+ "balanceToggle": "NPLLIq_balanceToggle",
357
+ "logClearBtn": "NPLLIq_logClearBtn",
358
+ "body": "NPLLIq_body",
359
+ "rowDragging": "NPLLIq_rowDragging",
360
+ "dialogBtn": "NPLLIq_dialogBtn",
361
+ "logPagerPages": "NPLLIq_logPagerPages",
362
+ "logClearDate": "NPLLIq_logClearDate",
363
+ "logModelCol": "NPLLIq_logModelCol",
364
+ "noteWinBar": "NPLLIq_noteWinBar",
365
+ "balanceSortBtn": "NPLLIq_balanceSortBtn",
366
+ "logDialog": "NPLLIq_logDialog",
367
+ "noteMenuItem": "NPLLIq_noteMenuItem",
368
+ "tab": "NPLLIq_tab",
401
369
  "noteWinText": "NPLLIq_noteWinText",
370
+ "logDayCol": "NPLLIq_logDayCol",
371
+ "keyBadgeOk": "NPLLIq_keyBadgeOk",
372
+ "controls": "NPLLIq_controls",
373
+ "balanceWin": "NPLLIq_balanceWin",
374
+ "settingsDialog": "NPLLIq_settingsDialog",
375
+ "balanceRow": "NPLLIq_balanceRow",
376
+ "balanceBarBadge": "NPLLIq_balanceBarBadge",
377
+ "dialogTabActive": "NPLLIq_dialogTabActive",
378
+ "dialogHeader": "NPLLIq_dialogHeader",
379
+ "upgradeBannerText": "NPLLIq_upgradeBannerText",
380
+ "collapse": "NPLLIq_collapse",
381
+ "rowName": "NPLLIq_rowName",
382
+ "noteWin": "NPLLIq_noteWin",
383
+ "logSearch": "NPLLIq_logSearch",
384
+ "balanceBar": "NPLLIq_balanceBar",
385
+ "upgradeBannerFlash": "NPLLIq_upgradeBannerFlash",
386
+ "currentBadge": "NPLLIq_currentBadge",
387
+ "logPager": "NPLLIq_logPager",
388
+ "dialogLabel": "NPLLIq_dialogLabel",
389
+ "fillOver": "NPLLIq_fillOver",
402
390
  "dialogActions": "NPLLIq_dialogActions",
403
- "balanceWinHeader": "NPLLIq_balanceWinHeader",
404
- "noteWinTitleText": "NPLLIq_noteWinTitleText",
405
- "bar": "NPLLIq_bar"
391
+ "noteNewPlus": "NPLLIq_noteNewPlus",
392
+ "upgradeCommandRow": "NPLLIq_upgradeCommandRow",
393
+ "fullNotice": "NPLLIq_fullNotice",
394
+ "dialogBody": "NPLLIq_dialogBody",
395
+ "dialog": "NPLLIq_dialog",
396
+ "rowDropTarget": "NPLLIq_rowDropTarget",
397
+ "radioRow": "NPLLIq_radioRow",
398
+ "balanceBarText": "NPLLIq_balanceBarText",
399
+ "upgradeHint": "NPLLIq_upgradeHint",
400
+ "settingsBtn": "NPLLIq_settingsBtn",
401
+ "balanceLastLine": "NPLLIq_balanceLastLine",
402
+ "settingsBtnActive": "NPLLIq_settingsBtnActive",
403
+ "dialogHint": "NPLLIq_dialogHint",
404
+ "noteWinTitle": "NPLLIq_noteWinTitle",
405
+ "balanceRowHeader": "NPLLIq_balanceRowHeader"
406
406
  };
407
407
  //#endregion
408
408
  //#region lib/types/client/TokenQuotaPanel.js
@@ -1139,13 +1139,13 @@ window.__ModuleLoader__.load({
1139
1139
  title: t("upgradeAvailableHint"),
1140
1140
  children: [
1141
1141
  "v",
1142
- "0.1.52",
1142
+ "0.1.54",
1143
1143
  " → v",
1144
1144
  upgrade.latestVersion
1145
1145
  ]
1146
1146
  }) : (0, react_jsx_runtime.jsxs)("span", {
1147
1147
  className: TokenQuotaPanel_module_css_default.version,
1148
- children: ["v", "0.1.52"]
1148
+ children: ["v", "0.1.54"]
1149
1149
  })]
1150
1150
  })
1151
1151
  }),
@@ -3005,13 +3005,13 @@ window.__ModuleLoader__.load({
3005
3005
  document.head.appendChild(tag);
3006
3006
  }
3007
3007
  var mic_module_css_default = {
3008
+ "micWrap": "KCoVpa_micWrap",
3009
+ "micPulse": "KCoVpa_micPulse",
3008
3010
  "micErr": "KCoVpa_micErr",
3009
3011
  "micBtn": "KCoVpa_micBtn",
3010
- "micErrTip": "KCoVpa_micErrTip",
3011
- "micWrap": "KCoVpa_micWrap",
3012
+ "micBusy": "KCoVpa_micBusy",
3012
3013
  "micRec": "KCoVpa_micRec",
3013
- "micPulse": "KCoVpa_micPulse",
3014
- "micBusy": "KCoVpa_micBusy"
3014
+ "micErrTip": "KCoVpa_micErrTip"
3015
3015
  };
3016
3016
  //#endregion
3017
3017
  //#region lib/types/client/mic.js
@@ -3205,12 +3205,12 @@ window.__ModuleLoader__.load({
3205
3205
  document.head.appendChild(tag);
3206
3206
  }
3207
3207
  var TokenQuotaStash_module_css_default = {
3208
- "selPopup": "x_tEcG_selPopup",
3209
3208
  "stashRow": "x_tEcG_stashRow",
3210
- "selDivider": "x_tEcG_selDivider",
3211
- "selBtn": "x_tEcG_selBtn",
3212
3209
  "stashTip": "x_tEcG_stashTip",
3213
- "stashChip": "x_tEcG_stashChip"
3210
+ "stashChip": "x_tEcG_stashChip",
3211
+ "selBtn": "x_tEcG_selBtn",
3212
+ "selPopup": "x_tEcG_selPopup",
3213
+ "selDivider": "x_tEcG_selDivider"
3214
3214
  };
3215
3215
  //#endregion
3216
3216
  //#region lib/types/client/TokenQuotaStash.js
package/lib/index.js CHANGED
@@ -278,6 +278,16 @@ function usageTokens(usage) {
278
278
  const DEEPSEEK_BALANCE_HOST = "api.deepseek.com";
279
279
  /** TeamoRouter's host; its model and billing endpoints share this domain. */
280
280
  const TEAMOROUTER_HOST = "teamorouter.cn";
281
+ /**
282
+ * Credential reference each family's adapter falls back to when the provider
283
+ * entry declares no `apiKeyEnv` (e.g. `llm-deepseek`, whose adapter resolves
284
+ * DEEPSEEK_API_KEY internally). Querying that same reference is what makes such
285
+ * a provider represent the same account the model calls are billed to.
286
+ */
287
+ const DEFAULT_BALANCE_KEY_ENV = {
288
+ deepseek: "DEEPSEEK_API_KEY",
289
+ teamorouter: "TEAMO_ROUTER_API_KEY"
290
+ };
281
291
  /** Fallback currency per family, used before the first successful fetch. */
282
292
  const BALANCE_DEFAULT_CURRENCY = {
283
293
  deepseek: "CNY",
@@ -687,7 +697,7 @@ var TokenQuotaService = class TokenQuotaService extends Service {
687
697
  return this.upgradeCheck;
688
698
  }
689
699
  async doRefreshUpgrade() {
690
- const current = "0.1.52";
700
+ const current = "0.1.54";
691
701
  let latest;
692
702
  try {
693
703
  const response = await fetch(REGISTRY_LATEST_URL, {
@@ -775,11 +785,21 @@ var TokenQuotaService = class TokenQuotaService extends Service {
775
785
  const found = /* @__PURE__ */ new Map();
776
786
  const llm = this.ctx.get("llm");
777
787
  const configEditor = this.ctx.get("configEditor");
788
+ const profileOf = (row) => {
789
+ const layers = [
790
+ row.override,
791
+ row.inherited,
792
+ row.entry?.fiber?.config,
793
+ row.entry?.options?.config
794
+ ];
795
+ for (const layer of layers) if (layer !== null && typeof layer === "object" && "providers" in layer) return layer;
796
+ for (const layer of layers) if (layer !== null && typeof layer === "object") return layer;
797
+ };
778
798
  const liveConfigs = /* @__PURE__ */ new Map();
779
799
  try {
780
800
  for (const row of configEditor?.configuration() ?? []) {
781
- const id = row.entry.options.id;
782
- if (id !== void 0) liveConfigs.set(id, row.entry.options.config);
801
+ const id = row.entry?.options?.id;
802
+ if (id !== void 0) liveConfigs.set(id, profileOf(row));
783
803
  }
784
804
  } catch {}
785
805
  const fallback = () => ({
@@ -800,15 +820,19 @@ var TokenQuotaService = class TokenQuotaService extends Service {
800
820
  const keyEnv = typeof record.apiKeyEnv === "string" && record.apiKeyEnv !== "" ? record.apiKeyEnv : void 0;
801
821
  const baseURL = typeof record.baseURL === "string" && record.baseURL !== "" ? record.baseURL : void 0;
802
822
  const kind = balanceKindOf(entry.provider, keyEnv, baseURL);
803
- if (kind === void 0 || keyEnv === void 0) continue;
823
+ if (kind === void 0) continue;
824
+ const balanceKeyEnv = keyEnv ?? DEFAULT_BALANCE_KEY_ENV[kind];
804
825
  found.set(entry.provider, {
805
826
  provider: entry.provider,
806
- keyEnv,
827
+ keyEnv: balanceKeyEnv,
807
828
  baseURL: baseURL ?? (kind === "deepseek" ? `https://${DEEPSEEK_BALANCE_HOST}` : `https://${TEAMOROUTER_HOST}`),
808
829
  kind
809
830
  });
810
831
  } catch {}
811
832
  if (found.size === 0) found.set("deepseek", fallback());
833
+ try {
834
+ this.ctx.logger?.info(`token-quota: balance sources = ${[...found.values()].map((source) => `${source.provider}(${source.kind})`).join(", ")}`);
835
+ } catch {}
812
836
  return found;
813
837
  }
814
838
  /**
@@ -283,6 +283,16 @@ function usageTokens(usage) {
283
283
  const DEEPSEEK_BALANCE_HOST = 'api.deepseek.com';
284
284
  /** TeamoRouter's host; its model and billing endpoints share this domain. */
285
285
  const TEAMOROUTER_HOST = 'teamorouter.cn';
286
+ /**
287
+ * Credential reference each family's adapter falls back to when the provider
288
+ * entry declares no `apiKeyEnv` (e.g. `llm-deepseek`, whose adapter resolves
289
+ * DEEPSEEK_API_KEY internally). Querying that same reference is what makes such
290
+ * a provider represent the same account the model calls are billed to.
291
+ */
292
+ const DEFAULT_BALANCE_KEY_ENV = {
293
+ deepseek: 'DEEPSEEK_API_KEY',
294
+ teamorouter: 'TEAMO_ROUTER_API_KEY',
295
+ };
286
296
  /** Fallback currency per family, used before the first successful fetch. */
287
297
  const BALANCE_DEFAULT_CURRENCY = {
288
298
  deepseek: 'CNY',
@@ -850,12 +860,29 @@ export class TokenQuotaService extends Service {
850
860
  // version dropped `settings.get(ns)`, so read the composed configuration
851
861
  // once from the config editor and index it by profile entry id.
852
862
  const configEditor = this.ctx.get('configEditor');
863
+ // Provider profiles live in another plugin entry's config (the profile's
864
+ // `providers` map). Which of the composed layers carries it depends on the
865
+ // deployment (user patch layer vs inherited base), so take the first layer
866
+ // that actually has a `providers` map and fall back to the entry's own
867
+ // config. Reading only one layer silently finds no providers at all.
868
+ const profileOf = (row) => {
869
+ const layers = [row.override, row.inherited, row.entry?.fiber?.config, row.entry?.options?.config];
870
+ for (const layer of layers) {
871
+ if (layer !== null && typeof layer === 'object' && 'providers' in layer)
872
+ return layer;
873
+ }
874
+ for (const layer of layers) {
875
+ if (layer !== null && typeof layer === 'object')
876
+ return layer;
877
+ }
878
+ return undefined;
879
+ };
853
880
  const liveConfigs = new Map();
854
881
  try {
855
882
  for (const row of configEditor?.configuration() ?? []) {
856
- const id = row.entry.options.id;
883
+ const id = row.entry?.options?.id;
857
884
  if (id !== undefined)
858
- liveConfigs.set(id, row.entry.options.config);
885
+ liveConfigs.set(id, profileOf(row));
859
886
  }
860
887
  }
861
888
  catch {
@@ -889,11 +916,15 @@ export class TokenQuotaService extends Service {
889
916
  ? record.baseURL
890
917
  : undefined;
891
918
  const kind = balanceKindOf(entry.provider, keyEnv, baseURL);
892
- if (kind === undefined || keyEnv === undefined)
919
+ if (kind === undefined)
893
920
  continue;
921
+ // A provider may legitimately declare no apiKeyEnv (the adapter then
922
+ // resolves its family default); query that same reference rather than
923
+ // dropping the provider from the balance window.
924
+ const balanceKeyEnv = keyEnv ?? DEFAULT_BALANCE_KEY_ENV[kind];
894
925
  found.set(entry.provider, {
895
926
  provider: entry.provider,
896
- keyEnv,
927
+ keyEnv: balanceKeyEnv,
897
928
  baseURL: baseURL ?? (kind === 'deepseek' ? `https://${DEEPSEEK_BALANCE_HOST}` : `https://${TEAMOROUTER_HOST}`),
898
929
  kind,
899
930
  });
@@ -904,6 +935,14 @@ export class TokenQuotaService extends Service {
904
935
  }
905
936
  if (found.size === 0)
906
937
  found.set('deepseek', fallback());
938
+ // One line per discovery pass, so a deployment can be checked from the
939
+ // terminal that runs `dsh web` instead of guessing from the panel.
940
+ try {
941
+ this.ctx.logger?.info(`token-quota: balance sources = ${[...found.values()].map(source => `${source.provider}(${source.kind})`).join(', ')}`);
942
+ }
943
+ catch {
944
+ // Logging is best-effort.
945
+ }
907
946
  return found;
908
947
  }
909
948
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jxgame2020/dsh-token-quota",
3
3
  "description": "Daily per-model token quota accounting, enforcement, and a floating quota panel for the DeepSeek Harness — a fully self-contained plugin (no core-Harness wiring, no generated RPC contract)",
4
- "version": "0.1.52",
4
+ "version": "0.1.54",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },