openclaw-smartmeter 0.5.0 → 0.5.1

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.
@@ -925,14 +925,21 @@ function showBalanceDisplay(usageData) {
925
925
  balanceSection.style.display = 'block';
926
926
 
927
927
  if (usageData) {
928
- const usage = usageData.usage || 0;
929
- const limit = usageData.limit || usageData.credit || 0;
930
- const remaining = limit - usage;
931
- const rate = usageData.rate_limit?.requests || usageData.rateLimit?.requests || '--';
932
-
933
- setText('gsBalanceCredits', `$${limit.toFixed(2)}`);
934
- setText('gsBalanceUsage', `$${usage.toFixed(2)}`);
935
- setText('gsBalanceRemaining', `$${remaining.toFixed(2)}`);
928
+ // Handle both API server shape (credits.total/used/remaining, account.limit)
929
+ // and direct OpenRouter shape (usage, limit, rate_limit)
930
+ const credits = usageData.credits || {};
931
+ const account = usageData.account || {};
932
+ const usage = credits.used ?? usageData.usage ?? account.usageBalance ?? 0;
933
+ const limit = credits.total ?? usageData.limit ?? account.limit ?? 0;
934
+ const remaining = credits.remaining ?? (limit - usage);
935
+ const rate = usageData.rate_limit?.requests
936
+ || usageData.rateLimit?.requests
937
+ || usageData.rate?.requests
938
+ || '--';
939
+
940
+ setText('gsBalanceCredits', `$${Number(limit).toFixed(2)}`);
941
+ setText('gsBalanceUsage', `$${Number(usage).toFixed(2)}`);
942
+ setText('gsBalanceRemaining', `$${Number(remaining).toFixed(2)}`);
936
943
  setText('gsBalanceRate', typeof rate === 'number' ? `${rate}/s` : rate);
937
944
  }
938
945
 
@@ -1005,26 +1012,35 @@ async function fetchOpenRouterUsage() {
1005
1012
  if (!res.ok) return;
1006
1013
  const json = await res.json();
1007
1014
  if (json.success && json.configured) {
1008
- const usage = json.data || json;
1015
+ const raw = json.data || json;
1016
+ const credits = raw.credits || {};
1017
+ const account = raw.account || {};
1018
+ const used = credits.used ?? raw.usage ?? account.usageBalance ?? 0;
1019
+ const limit = credits.total ?? raw.limit ?? account.limit ?? 0;
1020
+ const remaining = credits.remaining ?? (limit - used);
1021
+ const rate = raw.rate_limit?.requests || raw.rate?.requests || '--';
1009
1022
  container.innerHTML = `
1010
1023
  <div class="or-stats-grid">
1011
1024
  <div class="or-stat-card">
1012
1025
  <div class="or-stat-label">Usage (USD)</div>
1013
- <div class="or-stat-value">$${(usage.usage || 0).toFixed(2)}</div>
1026
+ <div class="or-stat-value">$${Number(used).toFixed(2)}</div>
1014
1027
  </div>
1015
1028
  <div class="or-stat-card">
1016
1029
  <div class="or-stat-label">Limit</div>
1017
- <div class="or-stat-value">$${(usage.limit || 0).toFixed(2)}</div>
1030
+ <div class="or-stat-value">$${Number(limit).toFixed(2)}</div>
1018
1031
  </div>
1019
1032
  <div class="or-stat-card">
1020
1033
  <div class="or-stat-label">Remaining</div>
1021
- <div class="or-stat-value">$${((usage.limit || 0) - (usage.usage || 0)).toFixed(2)}</div>
1034
+ <div class="or-stat-value">$${Number(remaining).toFixed(2)}</div>
1022
1035
  </div>
1023
1036
  <div class="or-stat-card">
1024
1037
  <div class="or-stat-label">Rate Limit</div>
1025
- <div class="or-stat-value">${usage.rate_limit?.requests || '--'}/s</div>
1038
+ <div class="or-stat-value">${typeof rate === 'number' ? rate + '/s' : rate}</div>
1026
1039
  </div>
1027
1040
  </div>`;
1041
+
1042
+ // Also update Get Started balance card if visible
1043
+ showBalanceDisplay(raw);
1028
1044
  }
1029
1045
  } catch {
1030
1046
  // noop
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openclaw-smartmeter",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "AI cost optimization for OpenClaw - analyze usage and reduce costs by 48%",
5
5
  "main": "src/cli/index.js",
6
6
  "bin": {