@leo000001/opencode-quota-sidebar 2.0.11 → 2.0.12

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/dist/cost.js CHANGED
@@ -8,6 +8,38 @@ const MODEL_COST_RATE_ALIASES = {
8
8
  'kimi-for-coding:k2p5': ['moonshotai-cn:kimi-k2.5'],
9
9
  'kimi-for-coding:kimi-k2-thinking': ['moonshotai-cn:kimi-k2-thinking'],
10
10
  };
11
+ function anthropicModelAliases(modelID) {
12
+ const aliases = [];
13
+ const push = (value) => {
14
+ if (!value)
15
+ return;
16
+ if (!aliases.includes(value))
17
+ aliases.push(value);
18
+ };
19
+ push(modelID);
20
+ const stems = [modelID];
21
+ for (const stem of stems) {
22
+ const withoutVendorPrefix = stem.replace(/^anthropic[/.]/, '');
23
+ push(withoutVendorPrefix);
24
+ push(`anthropic/${withoutVendorPrefix}`);
25
+ const withoutThinkingSuffix = withoutVendorPrefix.replace(/-thinking$/, '');
26
+ push(withoutThinkingSuffix);
27
+ push(`anthropic/${withoutThinkingSuffix}`);
28
+ const withoutLatestSuffix = withoutThinkingSuffix.replace(/-latest$/, '');
29
+ push(withoutLatestSuffix);
30
+ push(`anthropic/${withoutLatestSuffix}`);
31
+ const withoutDateSuffix = withoutLatestSuffix.replace(/-\d{8}$/, '');
32
+ push(withoutDateSuffix);
33
+ push(`anthropic/${withoutDateSuffix}`);
34
+ const dotted = withoutDateSuffix.replace(/(\d)-(\d)(?=-|$)/g, '$1.$2');
35
+ push(dotted);
36
+ push(`anthropic/${dotted}`);
37
+ const hyphenated = withoutDateSuffix.replace(/(\d)\.(\d)(?=-|$)/g, '$1-$2');
38
+ push(hyphenated);
39
+ push(`anthropic/${hyphenated}`);
40
+ }
41
+ return aliases;
42
+ }
11
43
  function normalizeKnownProviderID(providerID) {
12
44
  if (providerID.startsWith('github-copilot'))
13
45
  return 'github-copilot';
@@ -37,9 +69,14 @@ export function modelCostLookupKeys(providerID, modelID) {
37
69
  if (!keys.includes(key))
38
70
  keys.push(key);
39
71
  };
40
- push(modelCostKey(providerID, modelID));
41
- if (canonicalProviderID !== providerID) {
42
- push(modelCostKey(canonicalProviderID, modelID));
72
+ const modelIDs = canonicalProviderID === 'anthropic'
73
+ ? anthropicModelAliases(modelID)
74
+ : [modelID];
75
+ for (const candidateModelID of modelIDs) {
76
+ push(modelCostKey(providerID, candidateModelID));
77
+ if (canonicalProviderID !== providerID) {
78
+ push(modelCostKey(canonicalProviderID, candidateModelID));
79
+ }
43
80
  }
44
81
  for (const key of [...keys]) {
45
82
  for (const alias of MODEL_COST_RATE_ALIASES[key] || []) {
@@ -70,15 +70,16 @@ export function createUsageService(deps) {
70
70
  if (!rates)
71
71
  continue;
72
72
  const modelID = typeof modelValue.id === 'string' ? modelValue.id : modelKey;
73
- acc[modelCostKey(rawProviderID, modelID)] = rates;
74
- if (modelKey !== modelID) {
75
- acc[modelCostKey(rawProviderID, modelKey)] = rates;
76
- }
73
+ const lookupKeys = new Set([
74
+ ...modelCostLookupKeys(rawProviderID, modelID),
75
+ ...modelCostLookupKeys(rawProviderID, modelKey),
76
+ ]);
77
77
  if (canonicalProviderID !== rawProviderID) {
78
- acc[modelCostKey(canonicalProviderID, modelID)] = rates;
79
- if (modelKey !== modelID) {
80
- acc[modelCostKey(canonicalProviderID, modelKey)] = rates;
81
- }
78
+ lookupKeys.add(modelCostKey(canonicalProviderID, modelID));
79
+ lookupKeys.add(modelCostKey(canonicalProviderID, modelKey));
80
+ }
81
+ for (const key of lookupKeys) {
82
+ acc[key] = rates;
82
83
  }
83
84
  }
84
85
  return acc;
@@ -332,7 +333,8 @@ export function createUsageService(deps) {
332
333
  return { usage: empty, persist: false };
333
334
  }
334
335
  const modelCostMap = await getModelCostMap();
335
- const staleBillingCache = Boolean(sessionState?.usage) && !isUsageBillingCurrent(sessionState?.usage);
336
+ const staleBillingCache = Boolean(sessionState?.usage) &&
337
+ !isUsageBillingCurrent(sessionState?.usage);
336
338
  const forceRescan = forceRescanSessions.has(sessionID) || staleBillingCache;
337
339
  if (forceRescan)
338
340
  forceRescanSessions.delete(sessionID);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leo000001/opencode-quota-sidebar",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "description": "OpenCode plugin that shows quota and token usage in session titles",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",