@hashimkarim/usagestat-linux-x64-gnu 2.0.0-alpha.1 → 2.0.0-alpha.3

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.
Files changed (273) hide show
  1. package/LICENSE +0 -0
  2. package/native-manifest.json +365 -77
  3. package/package.json +49 -1
  4. package/plugins/UPSTREAM-LICENSES.md +109 -0
  5. package/plugins/abacus-ai/icon.svg +0 -0
  6. package/plugins/abacus-ai/plugin.js +0 -0
  7. package/plugins/abacus-ai/plugin.json +0 -0
  8. package/plugins/aiand/icon.svg +6 -0
  9. package/plugins/aiand/plugin.js +108 -0
  10. package/plugins/aiand/plugin.json +22 -0
  11. package/plugins/alibaba/icon-color.svg +0 -0
  12. package/plugins/alibaba/icon.svg +0 -0
  13. package/plugins/alibaba/plugin.js +0 -0
  14. package/plugins/alibaba/plugin.json +0 -0
  15. package/plugins/alibaba-token-plan/icon-color.svg +0 -0
  16. package/plugins/alibaba-token-plan/icon.svg +0 -0
  17. package/plugins/alibaba-token-plan/plugin.js +0 -0
  18. package/plugins/alibaba-token-plan/plugin.json +0 -0
  19. package/plugins/amp/icon-color.svg +0 -0
  20. package/plugins/amp/icon-conflict.svg +0 -0
  21. package/plugins/amp/icon.svg +0 -0
  22. package/plugins/amp/plugin.js +0 -0
  23. package/plugins/amp/plugin.json +0 -0
  24. package/plugins/antigravity/icon-color.svg +0 -0
  25. package/plugins/antigravity/icon-conflict.svg +0 -0
  26. package/plugins/antigravity/icon.svg +0 -0
  27. package/plugins/antigravity/plugin.js +0 -0
  28. package/plugins/antigravity/plugin.json +0 -0
  29. package/plugins/antigravity-cli/icon.svg +0 -0
  30. package/plugins/antigravity-cli/plugin.js +0 -0
  31. package/plugins/antigravity-cli/plugin.json +0 -0
  32. package/plugins/antigravity-ide/icon.svg +0 -0
  33. package/plugins/antigravity-ide/plugin.js +0 -0
  34. package/plugins/antigravity-ide/plugin.json +0 -0
  35. package/plugins/augment/icon.svg +0 -0
  36. package/plugins/augment/plugin.js +0 -0
  37. package/plugins/augment/plugin.json +0 -0
  38. package/plugins/aws-bedrock/icon-color.svg +0 -0
  39. package/plugins/aws-bedrock/icon.svg +0 -0
  40. package/plugins/aws-bedrock/plugin.js +0 -0
  41. package/plugins/aws-bedrock/plugin.json +0 -0
  42. package/plugins/azure-openai/icon-color.svg +0 -0
  43. package/plugins/azure-openai/icon.svg +0 -0
  44. package/plugins/azure-openai/plugin.js +0 -0
  45. package/plugins/azure-openai/plugin.json +0 -0
  46. package/plugins/chutes/icon.svg +0 -0
  47. package/plugins/chutes/plugin.js +0 -0
  48. package/plugins/chutes/plugin.json +0 -0
  49. package/plugins/claude/icon-color.svg +0 -0
  50. package/plugins/claude/icon.svg +0 -0
  51. package/plugins/claude/plugin.js +70 -23
  52. package/plugins/claude/plugin.json +0 -0
  53. package/plugins/clawrouter/icon.svg +7 -0
  54. package/plugins/clawrouter/plugin.js +45 -0
  55. package/plugins/clawrouter/plugin.json +22 -0
  56. package/plugins/clinepass/icon.svg +4 -0
  57. package/plugins/clinepass/plugin.js +71 -0
  58. package/plugins/clinepass/plugin.json +23 -0
  59. package/plugins/codebuddy/plugin.js +331 -0
  60. package/plugins/codebuddy/plugin.json +30 -0
  61. package/plugins/codebuff/icon.svg +0 -0
  62. package/plugins/codebuff/plugin.js +0 -0
  63. package/plugins/codebuff/plugin.json +0 -0
  64. package/plugins/codex/icon-color.svg +0 -0
  65. package/plugins/codex/icon.svg +0 -0
  66. package/plugins/codex/plugin.js +7 -2
  67. package/plugins/codex/plugin.json +0 -0
  68. package/plugins/command-code/icon.svg +0 -0
  69. package/plugins/command-code/plugin.js +7 -0
  70. package/plugins/command-code/plugin.json +0 -0
  71. package/plugins/copilot/icon-color.svg +0 -0
  72. package/plugins/copilot/icon.svg +0 -0
  73. package/plugins/copilot/plugin.js +61 -9
  74. package/plugins/copilot/plugin.json +4 -1
  75. package/plugins/crof/icon.svg +0 -0
  76. package/plugins/crof/plugin.js +0 -0
  77. package/plugins/crof/plugin.json +0 -0
  78. package/plugins/crofai/icon.svg +0 -0
  79. package/plugins/crofai/plugin.js +0 -0
  80. package/plugins/crofai/plugin.json +0 -0
  81. package/plugins/cursor/icon-conflict.svg +0 -0
  82. package/plugins/cursor/icon.svg +0 -0
  83. package/plugins/cursor/plugin.js +46 -9
  84. package/plugins/cursor/plugin.json +3 -2
  85. package/plugins/cursor-nightly/icon.png +0 -0
  86. package/plugins/cursor-nightly/plugin.js +45 -8
  87. package/plugins/cursor-nightly/plugin.json +3 -2
  88. package/plugins/deepgram/icon.svg +0 -0
  89. package/plugins/deepgram/plugin.js +0 -0
  90. package/plugins/deepgram/plugin.json +0 -0
  91. package/plugins/deepinfra/icon.svg +4 -0
  92. package/plugins/deepinfra/plugin.js +97 -0
  93. package/plugins/deepinfra/plugin.json +28 -0
  94. package/plugins/deepseek/icon-color.svg +0 -0
  95. package/plugins/deepseek/icon.svg +0 -0
  96. package/plugins/deepseek/plugin.js +0 -0
  97. package/plugins/deepseek/plugin.json +0 -0
  98. package/plugins/devin/icon.svg +0 -0
  99. package/plugins/devin/plugin.js +111 -0
  100. package/plugins/devin/plugin.json +2 -1
  101. package/plugins/doubao/icon-color.svg +0 -0
  102. package/plugins/doubao/icon.svg +0 -0
  103. package/plugins/doubao/plugin.js +0 -0
  104. package/plugins/doubao/plugin.json +0 -0
  105. package/plugins/droid/icon.svg +0 -0
  106. package/plugins/droid/plugin.json +2 -1
  107. package/plugins/elevenlabs/icon.svg +0 -0
  108. package/plugins/elevenlabs/plugin.js +17 -2
  109. package/plugins/elevenlabs/plugin.json +0 -0
  110. package/plugins/factory/icon-conflict.svg +0 -0
  111. package/plugins/factory/icon.svg +0 -0
  112. package/plugins/factory/plugin.js +38 -14
  113. package/plugins/factory/plugin.json +2 -1
  114. package/plugins/fireworks-ai/icon.svg +0 -0
  115. package/plugins/fireworks-ai/plugin.js +0 -0
  116. package/plugins/fireworks-ai/plugin.json +0 -0
  117. package/plugins/gemini/icon-color.svg +0 -0
  118. package/plugins/gemini/icon.svg +0 -0
  119. package/plugins/gemini/plugin.js +0 -0
  120. package/plugins/gemini/plugin.json +0 -0
  121. package/plugins/grok/icon.svg +0 -0
  122. package/plugins/grok/plugin.js +30 -5
  123. package/plugins/grok/plugin.json +3 -1
  124. package/plugins/groqcloud/icon.svg +0 -0
  125. package/plugins/groqcloud/plugin.js +0 -0
  126. package/plugins/groqcloud/plugin.json +0 -0
  127. package/plugins/ibmbob/icon.svg +23 -0
  128. package/plugins/ibmbob/plugin.js +61 -0
  129. package/plugins/ibmbob/plugin.json +22 -0
  130. package/plugins/jetbrains-ai-assistant/icon-color.svg +0 -0
  131. package/plugins/jetbrains-ai-assistant/icon-conflict.svg +0 -0
  132. package/plugins/jetbrains-ai-assistant/icon.svg +0 -0
  133. package/plugins/jetbrains-ai-assistant/plugin.js +0 -0
  134. package/plugins/jetbrains-ai-assistant/plugin.json +0 -0
  135. package/plugins/kilo/icon.svg +0 -0
  136. package/plugins/kilo/plugin.js +0 -0
  137. package/plugins/kilo/plugin.json +0 -0
  138. package/plugins/kimi/icon-color.svg +0 -0
  139. package/plugins/kimi/icon-conflict.svg +0 -0
  140. package/plugins/kimi/icon.svg +0 -0
  141. package/plugins/kimi/plugin.js +122 -141
  142. package/plugins/kimi/plugin.json +5 -2
  143. package/plugins/kimi-k2/icon-color.svg +0 -0
  144. package/plugins/kimi-k2/icon.svg +0 -0
  145. package/plugins/kimi-k2/plugin.js +0 -0
  146. package/plugins/kimi-k2/plugin.json +0 -0
  147. package/plugins/kiro/icon-color.svg +0 -0
  148. package/plugins/kiro/icon-conflict.svg +0 -0
  149. package/plugins/kiro/icon.svg +0 -0
  150. package/plugins/kiro/plugin.js +49 -10
  151. package/plugins/kiro/plugin.json +3 -1
  152. package/plugins/litellm/icon.svg +0 -0
  153. package/plugins/litellm/plugin.js +0 -0
  154. package/plugins/litellm/plugin.json +0 -0
  155. package/plugins/llm-proxy/icon.svg +0 -0
  156. package/plugins/llm-proxy/plugin.js +0 -0
  157. package/plugins/llm-proxy/plugin.json +0 -0
  158. package/plugins/longcat/icon.svg +4 -0
  159. package/plugins/longcat/plugin.js +182 -0
  160. package/plugins/longcat/plugin.json +23 -0
  161. package/plugins/manus/icon.svg +0 -0
  162. package/plugins/manus/plugin.js +0 -0
  163. package/plugins/manus/plugin.json +0 -0
  164. package/plugins/mimo/icon.svg +0 -0
  165. package/plugins/mimo/plugin.js +0 -0
  166. package/plugins/mimo/plugin.json +0 -0
  167. package/plugins/minimax/icon-color.svg +0 -0
  168. package/plugins/minimax/icon-conflict.svg +0 -0
  169. package/plugins/minimax/icon.svg +0 -0
  170. package/plugins/minimax/plugin.js +25 -31
  171. package/plugins/minimax/plugin.json +0 -0
  172. package/plugins/mistral/icon-color.svg +0 -0
  173. package/plugins/mistral/icon.svg +0 -0
  174. package/plugins/mistral/plugin.js +0 -0
  175. package/plugins/mistral/plugin.json +0 -0
  176. package/plugins/moonshot/icon.svg +0 -0
  177. package/plugins/moonshot/plugin.js +8 -6
  178. package/plugins/moonshot/plugin.json +0 -0
  179. package/plugins/nanogpt/icon-color.svg +0 -0
  180. package/plugins/nanogpt/icon.svg +0 -0
  181. package/plugins/nanogpt/plugin.js +0 -0
  182. package/plugins/nanogpt/plugin.json +0 -0
  183. package/plugins/neuralwatt/icon.svg +0 -0
  184. package/plugins/neuralwatt/plugin.js +0 -0
  185. package/plugins/neuralwatt/plugin.json +0 -0
  186. package/plugins/notion/icon.svg +1 -0
  187. package/plugins/notion/plugin.js +282 -0
  188. package/plugins/notion/plugin.json +29 -0
  189. package/plugins/ollama/icon.svg +0 -0
  190. package/plugins/ollama/plugin.js +257 -56
  191. package/plugins/ollama/plugin.json +6 -3
  192. package/plugins/openai-api/icon.svg +0 -0
  193. package/plugins/openai-api/plugin.js +0 -0
  194. package/plugins/openai-api/plugin.json +0 -0
  195. package/plugins/opencode/icon.svg +0 -0
  196. package/plugins/opencode/plugin.js +0 -0
  197. package/plugins/opencode/plugin.json +0 -0
  198. package/plugins/opencode-go/icon-conflict.svg +0 -0
  199. package/plugins/opencode-go/icon.svg +0 -0
  200. package/plugins/opencode-go/plugin.js +78 -10
  201. package/plugins/opencode-go/plugin.json +5 -2
  202. package/plugins/openrouter/icon.svg +0 -0
  203. package/plugins/openrouter/plugin.js +371 -114
  204. package/plugins/openrouter/plugin.json +6 -0
  205. package/plugins/perplexity/icon-color.svg +0 -0
  206. package/plugins/perplexity/icon-conflict.svg +0 -0
  207. package/plugins/perplexity/icon.svg +0 -0
  208. package/plugins/perplexity/plugin.js +0 -0
  209. package/plugins/perplexity/plugin.json +0 -0
  210. package/plugins/poe/icon.svg +0 -0
  211. package/plugins/poe/plugin.js +24 -18
  212. package/plugins/poe/plugin.json +2 -0
  213. package/plugins/qoder/icon.svg +3 -0
  214. package/plugins/qoder/plugin.js +227 -0
  215. package/plugins/qoder/plugin.json +23 -0
  216. package/plugins/qwencloud/icon.svg +4 -0
  217. package/plugins/qwencloud/plugin.js +677 -0
  218. package/plugins/qwencloud/plugin.json +29 -0
  219. package/plugins/sakana/icon.svg +5 -0
  220. package/plugins/sakana/plugin.js +156 -0
  221. package/plugins/sakana/plugin.json +23 -0
  222. package/plugins/stepfun/icon-color.svg +0 -0
  223. package/plugins/stepfun/icon.svg +0 -0
  224. package/plugins/stepfun/plugin.js +0 -0
  225. package/plugins/stepfun/plugin.json +0 -0
  226. package/plugins/sub2api/icon.svg +4 -0
  227. package/plugins/sub2api/plugin.js +191 -0
  228. package/plugins/sub2api/plugin.json +16 -0
  229. package/plugins/synthetic/icon-conflict.svg +0 -0
  230. package/plugins/synthetic/icon.svg +0 -0
  231. package/plugins/synthetic/plugin.js +0 -0
  232. package/plugins/synthetic/plugin.json +0 -0
  233. package/plugins/t3chat/icon-color.svg +0 -0
  234. package/plugins/t3chat/icon.svg +0 -0
  235. package/plugins/t3chat/plugin.js +0 -0
  236. package/plugins/t3chat/plugin.json +0 -0
  237. package/plugins/venice/icon-color.svg +0 -0
  238. package/plugins/venice/icon.svg +0 -0
  239. package/plugins/venice/plugin.js +0 -0
  240. package/plugins/venice/plugin.json +0 -0
  241. package/plugins/vertex-ai/icon-color.svg +0 -0
  242. package/plugins/vertex-ai/icon.svg +0 -0
  243. package/plugins/vertex-ai/plugin.js +0 -0
  244. package/plugins/vertex-ai/plugin.json +0 -0
  245. package/plugins/warp/icon-color.svg +0 -0
  246. package/plugins/warp/icon.svg +0 -0
  247. package/plugins/warp/plugin.js +0 -0
  248. package/plugins/warp/plugin.json +0 -0
  249. package/plugins/wayfinder/icon.svg +5 -0
  250. package/plugins/wayfinder/plugin.js +47 -0
  251. package/plugins/wayfinder/plugin.json +16 -0
  252. package/plugins/windsurf/icon-conflict.svg +0 -0
  253. package/plugins/windsurf/icon.svg +0 -0
  254. package/plugins/windsurf/plugin.js +0 -0
  255. package/plugins/windsurf/plugin.json +0 -0
  256. package/plugins/xai/icon.svg +7 -0
  257. package/plugins/xai/plugin.js +162 -0
  258. package/plugins/xai/plugin.json +28 -0
  259. package/plugins/zai/icon-conflict.svg +0 -0
  260. package/plugins/zai/icon.svg +0 -0
  261. package/plugins/zai/plugin.js +111 -161
  262. package/plugins/zai/plugin.json +4 -1
  263. package/plugins/zed/icon.svg +0 -0
  264. package/plugins/zed/plugin.js +0 -0
  265. package/plugins/zed/plugin.json +0 -0
  266. package/plugins/zenmux/icon.svg +3 -0
  267. package/plugins/zenmux/plugin.js +102 -0
  268. package/plugins/zenmux/plugin.json +23 -0
  269. package/plugins/zoommate/icon.svg +1 -0
  270. package/plugins/zoommate/plugin.js +244 -0
  271. package/plugins/zoommate/plugin.json +29 -0
  272. package/usagestat +0 -0
  273. package/usagestatd +0 -0
@@ -0,0 +1,162 @@
1
+ (function () {
2
+ var BASE_URL = "https://management-api.x.ai";
3
+ var HISTORY_DAYS = 30;
4
+
5
+ function clean(value) {
6
+ if (typeof value !== "string") return null;
7
+ var v = value.trim();
8
+ if (!v) return null;
9
+ if ((v[0] === "\"" && v[v.length - 1] === "\"") || (v[0] === "'" && v[v.length - 1] === "'")) v = v.slice(1, -1).trim();
10
+ if (v.slice(0, 7).toLowerCase() === "bearer ") v = v.slice(7).trim();
11
+ return v || null;
12
+ }
13
+
14
+ function env(ctx, name) {
15
+ try {
16
+ return clean(ctx.host.env.get(name));
17
+ } catch (_) {
18
+ return null;
19
+ }
20
+ }
21
+
22
+ function apiKey(ctx) {
23
+ return clean(ctx.provider && ctx.provider.apiKey) || env(ctx, "XAI_MANAGEMENT_API_KEY");
24
+ }
25
+
26
+ function teamId(ctx) {
27
+ var id = clean(ctx.provider && ctx.provider.workspaceId) || env(ctx, "XAI_TEAM_ID");
28
+ if (!id) return null;
29
+ if (id === "." || id === ".." || id.indexOf("/") >= 0 || id.indexOf("\\") >= 0) {
30
+ throw "The xAI team ID must be a single identifier without path separators.";
31
+ }
32
+ return id;
33
+ }
34
+
35
+ function requestJson(ctx, req) {
36
+ var result = ctx.util.requestJson(req);
37
+ if (ctx.util.isAuthStatus(result.resp.status)) {
38
+ throw "xAI rejected the Management API key. Create one in the xAI Console under Settings > Management Keys.";
39
+ }
40
+ if (result.resp.status === 404) throw "xAI returned 404 for this team. Check the team ID and Management key.";
41
+ if (result.resp.status === 429) throw "xAI Management API rate limit exceeded.";
42
+ if (result.resp.status < 200 || result.resp.status >= 300) throw "xAI Management API returned HTTP " + result.resp.status + ".";
43
+ if (!result.json || typeof result.json !== "object") throw "Could not parse xAI billing data.";
44
+ return result.json;
45
+ }
46
+
47
+ function balanceUsd(raw) {
48
+ var text = raw == null ? "" : String(raw).trim();
49
+ if (!/^-?\d+(?:\.\d+)?$/.test(text) || !Number.isFinite(Number(text))) throw "xAI balance total.val is not a cent amount.";
50
+ return -Number(text) / 100;
51
+ }
52
+
53
+ function pad(n) {
54
+ return n < 10 ? "0" + n : String(n);
55
+ }
56
+
57
+ function formatRequestTimestamp(date) {
58
+ return date.getUTCFullYear() + "-" + pad(date.getUTCMonth() + 1) + "-" + pad(date.getUTCDate()) +
59
+ " " + pad(date.getUTCHours()) + ":" + pad(date.getUTCMinutes()) + ":" + pad(date.getUTCSeconds());
60
+ }
61
+
62
+ function usageBody(now) {
63
+ var start = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate()));
64
+ start = new Date(start.getTime() - (HISTORY_DAYS - 1) * 24 * 60 * 60 * 1000);
65
+ return JSON.stringify({
66
+ analyticsRequest: {
67
+ timeRange: {
68
+ startTime: formatRequestTimestamp(start),
69
+ endTime: formatRequestTimestamp(now),
70
+ timezone: "Etc/GMT",
71
+ },
72
+ timeUnit: "TIME_UNIT_DAY",
73
+ values: [{ name: "usd", aggregation: "AGGREGATION_SUM" }],
74
+ groupBy: [],
75
+ filters: [],
76
+ },
77
+ });
78
+ }
79
+
80
+ function dayKey(ctx, timestamp) {
81
+ var iso = ctx.util.toIso(timestamp);
82
+ if (typeof timestamp === "string" && /^\d{4}-\d{2}-\d{2}$/.test(timestamp) && iso && iso.slice(0, 10) !== timestamp) return null;
83
+ return iso ? iso.slice(0, 10) : null;
84
+ }
85
+
86
+ function shortDay(day) {
87
+ return Number(day.slice(5, 7)) + "/" + Number(day.slice(8, 10));
88
+ }
89
+
90
+ function fetchDaily(ctx, key, id) {
91
+ try {
92
+ var json = requestJson(ctx, {
93
+ method: "POST",
94
+ url: BASE_URL + "/v1/billing/teams/" + encodeURIComponent(id) + "/usage",
95
+ headers: {
96
+ Authorization: "Bearer " + key,
97
+ Accept: "application/json",
98
+ "Content-Type": "application/json",
99
+ },
100
+ bodyText: usageBody(new Date(ctx.nowIso)),
101
+ timeoutMs: 3000,
102
+ });
103
+ var totals = {};
104
+ if (!Array.isArray(json.timeSeries)) throw "Missing xAI usage time series.";
105
+ var series = json.timeSeries;
106
+ for (var i = 0; i < series.length; i++) {
107
+ var points = Array.isArray(series[i].dataPoints) ? series[i].dataPoints : [];
108
+ for (var j = 0; j < points.length; j++) {
109
+ var day = dayKey(ctx, points[j].timestamp);
110
+ var raw = Array.isArray(points[j].values) ? points[j].values[0] : null;
111
+ if (!day || (typeof raw !== "number" && typeof raw !== "string") || String(raw).trim() === "" || !Number.isFinite(Number(raw)) || Number(raw) < 0) throw "Invalid xAI usage history point.";
112
+ if (day <= ctx.nowIso.slice(0, 10)) totals[day] = (totals[day] || 0) + Number(raw);
113
+ }
114
+ }
115
+ return Object.keys(totals).sort().map(function (day) {
116
+ return { day: day, cost: totals[day] };
117
+ });
118
+ } catch (error) {
119
+ ctx.host.log.warn("xAI usage history request failed: " + String(error));
120
+ return [];
121
+ }
122
+ }
123
+
124
+ function probe(ctx) {
125
+ var key = apiKey(ctx);
126
+ if (!key) throw "Missing xAI Management API key. Set XAI_MANAGEMENT_API_KEY or provider apiKey.";
127
+ var id = teamId(ctx);
128
+ if (!id) throw "Missing xAI team ID. Set XAI_TEAM_ID or provider workspaceId.";
129
+
130
+ var balanceJson = requestJson(ctx, {
131
+ method: "GET",
132
+ url: BASE_URL + "/v1/billing/teams/" + encodeURIComponent(id) + "/prepaid/balance",
133
+ headers: { Authorization: "Bearer " + key, Accept: "application/json" },
134
+ timeoutMs: 15000,
135
+ });
136
+ var balance = balanceUsd(balanceJson.total && balanceJson.total.val);
137
+ var metrics = [ctx.line.text({ label: "Balance", value: balance < 0 ? "Deficit: $" + (-balance).toFixed(2) : "$" + balance.toFixed(2) })];
138
+
139
+ var daily = fetchDaily(ctx, key, id);
140
+ if (daily.length) {
141
+ try {
142
+ ctx.host.usageDaily.ingest({ provider: "xai", source: "api", daily: daily.map(function (row) {
143
+ return { date: row.day, costUsd: row.cost };
144
+ }) });
145
+ } catch (error) {
146
+ ctx.host.log.warn("Could not persist xAI usage history: " + String(error));
147
+ }
148
+ var total = daily.reduce(function (sum, row) { return sum + row.cost; }, 0);
149
+ metrics.push(ctx.line.text({ label: "Cost", value: "$" + total.toFixed(2), subtitle: "Last 30 days" }));
150
+ metrics.push(ctx.line.barChart({
151
+ label: "Cost History",
152
+ points: daily.map(function (row) { return { label: shortDay(row.day), value: row.cost, valueLabel: "$" + row.cost.toFixed(2) }; }),
153
+ note: "Recent xAI Management API usage.",
154
+ color: "#111111",
155
+ }));
156
+ }
157
+
158
+ return { displayName: "xAI", source: "api", plan: "Management API", lines: metrics };
159
+ }
160
+
161
+ globalThis.__openusage_plugin = { id: "xai", probe: probe };
162
+ })();
@@ -0,0 +1,28 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "xai",
4
+ "name": "xAI",
5
+ "version": "0.1.0",
6
+ "entry": "plugin.js",
7
+ "enabledByDefault": false,
8
+ "supportedModes": [
9
+ "api"
10
+ ],
11
+ "autoMode": "api",
12
+ "usageDashboardUrl": "https://console.x.ai",
13
+ "statusPageUrl": "https://status.x.ai",
14
+ "links": [
15
+ {
16
+ "label": "Dashboard",
17
+ "url": "https://console.x.ai"
18
+ },
19
+ {
20
+ "label": "Status",
21
+ "url": "https://status.x.ai"
22
+ }
23
+ ],
24
+ "envVars": [
25
+ "XAI_MANAGEMENT_API_KEY",
26
+ "XAI_TEAM_ID"
27
+ ]
28
+ }
File without changes
File without changes
@@ -1,187 +1,137 @@
1
1
  (function () {
2
- const BASE_URL = "https://api.z.ai"
3
- const SUBSCRIPTION_URL = BASE_URL + "/api/biz/subscription/list"
4
- const QUOTA_URL = BASE_URL + "/api/monitor/usage/quota/limit"
5
- const PERIOD_MS = 5 * 60 * 60 * 1000
6
- const WEEK_MS = 7 * 24 * 60 * 60 * 1000
7
- const MONTH_MS = 30 * 24 * 60 * 60 * 1000
2
+ const HOUR_MS = 60 * 60 * 1000
3
+ const WEEK_MS = 7 * 24 * HOUR_MS
4
+ const MONTH_MS = 30 * 24 * HOUR_MS
5
+ const INVALID = "Z.ai usage response invalid. Try again later."
8
6
 
9
- function loadApiKey(ctx) {
10
- const zai = ctx.host.env.get("ZAI_API_KEY")
11
- if (typeof zai === "string" && zai.trim()) return zai.trim()
12
-
13
- const glm = ctx.host.env.get("GLM_API_KEY")
14
- if (typeof glm === "string" && glm.trim()) return glm.trim()
15
-
16
- return null
7
+ function clean(value) {
8
+ return typeof value === "string" && value.trim() ? value.trim() : null
17
9
  }
18
10
 
19
- function fetchSubscription(ctx, apiKey) {
20
- try {
21
- const resp = ctx.util.request({
22
- method: "GET",
23
- url: SUBSCRIPTION_URL,
24
- headers: {
25
- Authorization: "Bearer " + apiKey,
26
- Accept: "application/json",
27
- },
28
- timeoutMs: 10000,
29
- })
30
- if (resp.status < 200 || resp.status >= 300) {
31
- ctx.host.log.warn("subscription request failed: HTTP " + resp.status)
32
- return null
33
- }
34
- const data = ctx.util.tryParseJson(resp.bodyText)
35
- if (!data) return null
36
- const list = data.data
37
- if (!Array.isArray(list) || list.length === 0) return null
38
- return {
39
- productName: list[0].productName || null,
40
- nextRenewTime: list[0].nextRenewTime || null,
41
- }
42
- } catch (e) {
43
- ctx.host.log.warn("subscription request exception: " + String(e))
44
- return null
45
- }
11
+ function number(value) {
12
+ if (typeof value !== "number" && typeof value !== "string") return null
13
+ if (typeof value === "string" && !value.trim()) return null
14
+ const parsed = Number(value)
15
+ return Number.isFinite(parsed) ? parsed : null
46
16
  }
47
17
 
48
- function fetchQuota(ctx, apiKey) {
49
- let resp
50
- try {
51
- resp = ctx.util.request({
52
- method: "GET",
53
- url: QUOTA_URL,
54
- headers: {
55
- Authorization: "Bearer " + apiKey,
56
- Accept: "application/json",
57
- },
58
- timeoutMs: 10000,
59
- })
60
- } catch (e) {
61
- ctx.host.log.error("usage request exception: " + String(e))
62
- throw "Usage request failed. Check your connection."
63
- }
64
-
65
- if (ctx.util.isAuthStatus(resp.status)) {
66
- throw "API key invalid. Check your Z.ai API key."
18
+ function credentials(ctx) {
19
+ const provider = ctx.provider || {}
20
+ const settings = provider.settings || {}
21
+ const env = (name) => clean(ctx.host.env.get(name))
22
+ const cnKey = env("BIGMODEL_API_KEY") || env("ZHIPU_API_KEY")
23
+ const key = clean(provider.apiKey) || env("ZAI_API_KEY") || env("Z_AI_API_KEY") || env("GLM_API_KEY") || cnKey
24
+ if (!key) throw "No ZAI_API_KEY found. Set a provider API key or environment variable."
25
+ const region = (clean(provider.region) || clean(settings.region) || env("Z_AI_REGION") || (key === cnKey ? "bigmodel-cn" : "global")).toLowerCase()
26
+ const china = ["cn", "china", "bigmodel-cn"].includes(region)
27
+ if (!china && region !== "global") throw "Unsupported Z.ai region. Use global or bigmodel-cn."
28
+ if (key === cnKey && !china) throw "BigModel API keys must use the bigmodel-cn region."
29
+ const headers = { Authorization: "Bearer " + key, Accept: "application/json" }
30
+ const scope = clean(settings.usageScope) || env("Z_AI_USAGE_SCOPE") || "personal"
31
+ if (!["personal", "team"].includes(scope)) throw "Unsupported Z.ai usage scope."
32
+ if (scope === "team") {
33
+ const organization = clean(settings.organization) || env("Z_AI_ORGANIZATION")
34
+ const project = clean(settings.project) || clean(provider.workspaceId) || env("Z_AI_PROJECT")
35
+ if (!organization || !project) throw "Z.ai team usage needs organization and project settings."
36
+ headers["Bigmodel-Organization"] = organization
37
+ headers["Bigmodel-Project"] = project
67
38
  }
39
+ return { base: china ? "https://open.bigmodel.cn" : "https://api.z.ai", china, headers, scope }
40
+ }
68
41
 
69
- if (resp.status < 200 || resp.status >= 300) {
70
- throw "Usage request failed (HTTP " + String(resp.status) + "). Try again later."
71
- }
42
+ function request(ctx, auth, url, timeoutMs) {
43
+ const result = ctx.util.requestJson({ method: "GET", url, headers: auth.headers, timeoutMs })
44
+ if (ctx.util.isAuthStatus(result.resp.status)) throw "Z.ai API key invalid. Check its region and credentials."
45
+ if (result.resp.status < 200 || result.resp.status >= 300) throw "Z.ai API returned HTTP " + result.resp.status + "."
46
+ const root = result.json
47
+ if (!root || root.success === false || (root.code !== undefined && number(root.code) !== 200)) throw INVALID
48
+ return root
49
+ }
72
50
 
73
- const data = ctx.util.tryParseJson(resp.bodyText)
74
- if (!data) {
75
- throw "Usage response invalid. Try again later."
76
- }
51
+ function duration(entry) {
52
+ const multipliers = { 1: 24 * HOUR_MS, 3: HOUR_MS, 5: 60000, 6: WEEK_MS }
53
+ const unit = number(entry.unit)
54
+ const count = number(entry.number)
55
+ if ((entry.type || entry.name) === "TIME_LIMIT" && unit === 5 && count === 1) return MONTH_MS
56
+ if (count > 0 && multipliers[unit]) return count * multipliers[unit]
57
+ if (unit === 6) return WEEK_MS
58
+ if (unit === 3 || unit === null) return 5 * HOUR_MS
59
+ return null
60
+ }
77
61
 
78
- return data
62
+ function reset(ctx, entry, periodMs) {
63
+ const raw = entry.nextResetTime
64
+ let ms = number(raw)
65
+ if (ms === null && typeof raw === "string") ms = Date.parse(raw)
66
+ if (!Number.isFinite(ms) || ms < 1000000000000 || ms > 4102444800000) return undefined
67
+ const now = Date.parse(ctx.nowIso) || Date.now()
68
+ if (periodMs === 5 * HOUR_MS && ms > now + periodMs + 60000) return undefined
69
+ return new Date(ms).toISOString()
79
70
  }
80
71
 
81
- function findLimit(limits, type, unit) {
82
- let fallback = null
83
- for (let i = 0; i < limits.length; i++) {
84
- const item = limits[i]
85
- if (item.type === type || item.name === type) {
86
- if (unit === undefined) {
87
- return item
88
- }
89
- if (item.unit === unit) {
90
- return item
91
- }
92
- // Store first entry without unit as fallback
93
- if (fallback === null && item.unit === undefined) {
94
- fallback = item
95
- }
96
- }
72
+ function quotaLine(ctx, entry) {
73
+ let used = number(entry.percentage)
74
+ const cap = number(entry.usage)
75
+ const current = number(entry.currentValue)
76
+ const remaining = number(entry.remaining)
77
+ if (cap > 0 && (current !== null || remaining !== null)) {
78
+ used = Math.max(current === null ? 0 : current, remaining === null ? 0 : cap - remaining) / cap * 100
97
79
  }
98
- return fallback
80
+ if (used === null) throw INVALID
81
+ const periodMs = duration(entry)
82
+ const label = periodMs === WEEK_MS ? "Weekly" : periodMs === 5 * HOUR_MS ? "Session" : "Quota"
83
+ return ctx.line.progress({
84
+ label, used: Math.max(0, Math.min(100, used)), limit: 100,
85
+ format: { kind: "percent" }, periodDurationMs: periodMs || undefined,
86
+ resetsAt: reset(ctx, entry, periodMs),
87
+ })
99
88
  }
100
89
 
101
90
  function probe(ctx) {
102
- const apiKey = loadApiKey(ctx)
103
- if (!apiKey) {
104
- throw "No ZAI_API_KEY found. Set up environment variable first."
105
- }
106
-
107
- const sub = fetchSubscription(ctx, apiKey)
108
- const plan = sub && sub.productName ? ctx.fmt.planLabel(sub.productName) : null
109
-
110
- const quota = fetchQuota(ctx, apiKey)
91
+ const auth = credentials(ctx)
92
+ const root = request(ctx, auth, auth.base + "/api/monitor/usage/quota/limit" + (auth.scope === "team" ? "?type=2" : ""), 10000)
93
+ const data = root.data || root
94
+ const limits = Array.isArray(data) ? data : data.limits
95
+ if (!Array.isArray(limits) || limits.some((item) => !item || typeof item !== "object")) throw INVALID
111
96
  const lines = []
112
-
113
- const container = quota.data || quota
114
- const limits = container.limits || container
115
- if (!Array.isArray(limits) || limits.length === 0) {
116
- lines.push(ctx.line.badge({ label: "Session", text: "No usage data", color: "#a3a3a3" }))
117
- return { plan, lines }
97
+ const quota = limits.filter((item) => ["TOKENS_LIMIT", "CREDIT_LIMIT"].includes(item.type || item.name))
98
+ .sort((a, b) => (duration(a) || Infinity) - (duration(b) || Infinity))
99
+ for (const item of quota) lines.push(quotaLine(ctx, item))
100
+ const mcp = limits.find((item) => (item.type || item.name) === "TIME_LIMIT")
101
+ if (mcp) {
102
+ const used = number(mcp.currentValue)
103
+ const limit = number(mcp.usage)
104
+ if (used === null || limit === null || used < 0 || limit < 0) throw INVALID
105
+ lines.push(ctx.line.progress({ label: "Web Searches", used, limit,
106
+ format: { kind: "count", suffix: "searches" }, periodDurationMs: MONTH_MS,
107
+ resetsAt: reset(ctx, mcp, MONTH_MS) }))
118
108
  }
109
+ if (!lines.length) lines.push(ctx.line.badge({ label: "Status", text: "No usage data", color: "#a3a3a3" }))
119
110
 
120
- const tokenLimit = findLimit(limits, "TOKENS_LIMIT", 3)
121
-
122
- if (!tokenLimit) {
123
- lines.push(ctx.line.badge({ label: "Session", text: "No usage data", color: "#a3a3a3" }))
124
- return { plan, lines }
111
+ if (quota.some((item) => (item.type || item.name) === "CREDIT_LIMIT")) {
112
+ const now = new Date(ctx.nowIso)
113
+ const peak = now.getUTCDay() >= 1 && now.getUTCDay() <= 5 && now.getUTCHours() >= 6 && now.getUTCHours() < 10
114
+ lines.push(ctx.line.text({ label: "Quota rate", value: peak ? "Peak" : "Off-peak",
115
+ subtitle: "Peak: Mon-Fri 06:00-10:00 UTC" }))
125
116
  }
126
117
 
127
- const used = typeof tokenLimit.percentage === "number" ? tokenLimit.percentage : 0
128
- const resetsAt = tokenLimit.nextResetTime ? ctx.util.toIso(tokenLimit.nextResetTime) : undefined
129
-
130
- const progressOpts = {
131
- label: "Session",
132
- used,
133
- limit: 100,
134
- format: { kind: "percent" },
135
- periodDurationMs: PERIOD_MS,
118
+ let plan = clean(data.planName) || clean(data.plan) || clean(data.packageName)
119
+ if (!plan) {
120
+ try {
121
+ const sub = request(ctx, auth, auth.base + "/api/biz/subscription/list", 1500)
122
+ if (Array.isArray(sub.data) && sub.data.length) plan = clean(sub.data[0].productName)
123
+ } catch (_) { ctx.host.log.warn("Z.ai plan details unavailable") }
136
124
  }
137
- if (resetsAt) {
138
- progressOpts.resetsAt = resetsAt
125
+ if (auth.china) {
126
+ try {
127
+ const balance = request(ctx, auth, "https://www.bigmodel.cn/api/biz/account/query-customer-account-report", 3000)
128
+ const account = balance.data || {}
129
+ const available = number(account.availableBalance)
130
+ const value = available !== null ? available : number(account.balance)
131
+ if (value !== null) lines.push(ctx.line.text({ label: "Balance", value: "CNY " + value.toFixed(2) }))
132
+ } catch (_) { ctx.host.log.warn("BigModel balance unavailable") }
139
133
  }
140
- lines.push(ctx.line.progress(progressOpts))
141
-
142
- const weeklyTokenLimit = findLimit(limits, "TOKENS_LIMIT", 6)
143
- if (weeklyTokenLimit) {
144
- const weeklyUsed = Number.isFinite(weeklyTokenLimit.percentage) ? weeklyTokenLimit.percentage : 0
145
- const weeklyResetsAt = weeklyTokenLimit.nextResetTime ? ctx.util.toIso(weeklyTokenLimit.nextResetTime) : undefined
146
-
147
- const weeklyOpts = {
148
- label: "Weekly",
149
- used: weeklyUsed,
150
- limit: 100,
151
- format: { kind: "percent" },
152
- periodDurationMs: WEEK_MS,
153
- }
154
- if (weeklyResetsAt) {
155
- weeklyOpts.resetsAt = weeklyResetsAt
156
- }
157
- lines.push(ctx.line.progress(weeklyOpts))
158
- }
159
-
160
- const timeLimit = findLimit(limits, "TIME_LIMIT")
161
-
162
- if (timeLimit) {
163
- const webUsed = typeof timeLimit.currentValue === "number" ? timeLimit.currentValue : 0
164
- const webTotal = typeof timeLimit.usage === "number" ? timeLimit.usage : 0
165
- const now = new Date()
166
- const nextMonth = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + 1, 1))
167
- const webResetsAt = timeLimit.nextResetTime
168
- ? ctx.util.toIso(timeLimit.nextResetTime)
169
- : nextMonth.toISOString()
170
-
171
- const webOpts = {
172
- label: "Web Searches",
173
- used: webUsed,
174
- limit: webTotal,
175
- format: { kind: "count", suffix: "/ " + webTotal },
176
- periodDurationMs: MONTH_MS,
177
- }
178
- if (webResetsAt) {
179
- webOpts.resetsAt = webResetsAt
180
- }
181
- lines.push(ctx.line.progress(webOpts))
182
- }
183
-
184
- return { plan, lines }
134
+ return { displayName: "Z.ai", source: "api", plan: plan || undefined, lines }
185
135
  }
186
136
 
187
137
  globalThis.__openusage_plugin = { id: "zai", probe }
@@ -8,9 +8,12 @@
8
8
  "brandColor": "#2D2D2D",
9
9
  "supportedModes": ["api"],
10
10
  "autoMode": "api",
11
+ "envVars": ["ZAI_API_KEY", "Z_AI_API_KEY", "GLM_API_KEY", "BIGMODEL_API_KEY", "ZHIPU_API_KEY", "Z_AI_REGION", "Z_AI_USAGE_SCOPE", "Z_AI_ORGANIZATION", "Z_AI_PROJECT"],
11
12
  "lines": [
12
13
  { "type": "progress", "label": "Session", "scope": "overview", "primaryOrder": 1 },
13
14
  { "type": "progress", "label": "Weekly", "scope": "overview" },
14
- { "type": "progress", "label": "Web Searches", "scope": "overview" }
15
+ { "type": "progress", "label": "Web Searches", "scope": "overview" },
16
+ { "type": "text", "label": "Quota rate", "scope": "detail" },
17
+ { "type": "text", "label": "Balance", "scope": "detail" }
15
18
  ]
16
19
  }
File without changes
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ <svg width="160" height="160" viewBox="0 0 160 160" xmlns="http://www.w3.org/2000/svg" fill="none">
2
+ <path fill="black" fill-rule="evenodd" clip-rule="evenodd" d="m77.77641.42146c8.25008-.31709 24.94679.77406 38.30399 12.76765 10.95668 9.83841 14.73253 28.07814 12.17937 42.22111-2.34107 12.96444-7.85766 23.57181-5.69622 33.3933 2.16028 9.82161 7.65832 14.66392 12.33467 16.69671 4.51873 1.96441 8.88564 1.37451 8.05468 5.10748-.83212 3.73181-6.48199 5.10748-10.60784 5.10748-2.26226 0-9.10352-.5899-12.1388-2.55432-3.58694-2.32137-4.38661-4.40168-5.75185-6.07404-.23179-.28394-.6409-.08692-.58643.27583.62235 4.1131 2.33759 11.09459 5.12023 15.42326 2.25183 3.5035 3.18247 6.05781 8.34094 10.37952 5.15963 4.32055 7.56908 8.24938 2.55316 11.03201-4.45615 2.47087-14.14262-2.58561-19.83884-8.83928-5.12753-5.629-8.69708-12.57225-10.10891-17.08982-.75471-2.41524-1.5108-6.57007-2.26586-9.96926-.09921-.44619-.71113-.37434-.72434.08344-.25068 8.64922-1.61024 16.90903-3.59795 25.76454-1.43118 6.37536-4.91092 14.14262-8.05375 18.85722-3.83229 5.74837-9.52132 7.54242-13.75009 5.97089-3.38204-1.25746-.98209-5.53165 0-9.23217.98221-3.69936 2.94708-11.4388 4.27025-19.91765 1.19766-7.67454 1.51463-15.27144.98128-22.46965-.03303-.43924-.70765-.50646-.84429-.08808-1.10227 3.37601-3.18003 8.97256-4.69582 12.37639-3.16149 7.09855-5.50106 10.21379-11.98339 17.67741-5.82962 6.71378-22.59621 16.20671-24.74976 6.87603-.58932-2.55316 2.49811-3.67154 5.34541-5.89324 4.27999-3.33892 7.85661-9.26462 11.24769-16.49992 3.0449-6.49705 4.59256-12.78202 4.82933-16.79429.02237-.38709-.46335-.53312-.68134-.21325-1.40951 2.06756-3.48507 4.86526-5.77097 7.18547-3.81861 3.87668-8.05398 7.86693-12.96571 9.82207-7.89718 3.14306-15.95046.98163-15.36172-4.71459.49209-4.75748 5.80412-3.77237 12.41684-10.98681 6.4821-7.07154 8.64215-12.5726 9.03503-18.66205.31384-4.87163-4.45186-16.43398-6.87452-21.60682-3.86312-8.25019-6.71795-31.66462 4.9108-46.75062 14.53551-18.85687 32.01705-18.46573 37.12476-18.66193Zm-22.67525 32.97562c-5.40822 0-8.11251 4.15123-8.11262 9.27157 0 5.12057 3.00468 9.27157 8.11262 9.27157s8.11262-4.151 8.11262-9.27157c-.00012-5.12034-2.7044-9.27157-8.11262-9.27157Zm44.03996 0c-5.40822 0-8.11251 4.15123-8.11262 9.27157 0 5.12057 3.00468 9.27157 8.11262 9.27157s8.11274-4.151 8.11274-9.27157c0-5.12034-2.70452-9.27157-8.11274-9.27157Z"/>
3
+ </svg>
@@ -0,0 +1,102 @@
1
+ (function () {
2
+ var BASE = "https://zenmux.ai/api/v1/management";
3
+
4
+ function clean(value) {
5
+ return typeof value === "string" && value.trim() ? value.trim() : null;
6
+ }
7
+
8
+ function env(ctx, name) {
9
+ try {
10
+ return clean(ctx.host.env.get(name));
11
+ } catch (_) {
12
+ return null;
13
+ }
14
+ }
15
+
16
+ function apiKey(ctx) {
17
+ return clean(ctx.provider && ctx.provider.apiKey) || env(ctx, "ZENMUX_MANAGEMENT_API_KEY") || env(ctx, "ZENMUX_API_KEY");
18
+ }
19
+
20
+ function requestJson(ctx, path, key, timeoutMs) {
21
+ var result = ctx.util.requestJson({
22
+ method: "GET",
23
+ url: BASE + "/" + path,
24
+ headers: { Authorization: "Bearer " + key, Accept: "application/json" },
25
+ timeoutMs: timeoutMs || 15000,
26
+ });
27
+ if (ctx.util.isAuthStatus(result.resp.status)) throw "ZenMux Management API key invalid or expired.";
28
+ if (result.resp.status < 200 || result.resp.status >= 300) throw "ZenMux Management API returned HTTP " + result.resp.status + ".";
29
+ if (!result.json || typeof result.json !== "object") throw "Failed to parse ZenMux response.";
30
+ return result.json;
31
+ }
32
+
33
+ function iso(ctx, value) {
34
+ return value ? ctx.util.toIso(value) : null;
35
+ }
36
+
37
+ function title(value) {
38
+ var v = String(value || "").trim();
39
+ return v ? v.charAt(0).toUpperCase() + v.slice(1) : "";
40
+ }
41
+
42
+ function amount(value) {
43
+ var n = number(value);
44
+ if (n === null) return null;
45
+ return Math.abs(n - Math.round(n)) < 0.001 ? String(Math.round(n)) : n.toFixed(2);
46
+ }
47
+
48
+ function number(raw) {
49
+ if ((typeof raw !== "number" && typeof raw !== "string") || String(raw).trim() === "") return null;
50
+ var n = Number(raw);
51
+ return Number.isFinite(n) ? n : null;
52
+ }
53
+
54
+ function quotaLine(ctx, label, quota, minutes) {
55
+ if (!quota) return null;
56
+ var percent = number(quota.usage_percentage);
57
+ if (percent === null || percent < 0) throw "Invalid ZenMux usage percentage.";
58
+ var opts = {
59
+ label: label,
60
+ used: Math.max(0, Math.min(100, percent * 100)),
61
+ limit: 100,
62
+ format: { kind: "percent" },
63
+ periodDurationMs: minutes * 60 * 1000,
64
+ };
65
+ if (amount(quota.used_flows) !== null && amount(quota.max_flows) !== null) opts.detail = amount(quota.used_flows) + " / " + amount(quota.max_flows) + " flows";
66
+ var reset = iso(ctx, quota.resets_at);
67
+ if (reset) opts.resetsAt = reset;
68
+ return ctx.line.progress(opts);
69
+ }
70
+
71
+ function probe(ctx) {
72
+ var key = apiKey(ctx);
73
+ if (!key) throw "Missing ZenMux Management API key. Set ZENMUX_MANAGEMENT_API_KEY, ZENMUX_API_KEY, or provider apiKey.";
74
+ var sub = requestJson(ctx, "subscription/detail", key);
75
+ if (!sub.success || !sub.data) throw "ZenMux subscription response reported failure.";
76
+ var data = sub.data;
77
+ var plan = data.plan && title(data.plan.tier);
78
+ var status = title(data.account_status);
79
+ var planLabel = plan ? plan + " plan" : null;
80
+ if (status && status.toLowerCase() !== "healthy") planLabel = planLabel ? planLabel + " · " + status : status;
81
+ var metrics = [
82
+ quotaLine(ctx, "5-hour quota", data.quota_5_hour, 5 * 60),
83
+ quotaLine(ctx, "Weekly quota", data.quota_7_day, 7 * 24 * 60),
84
+ ].filter(function (line) { return line !== null; });
85
+ var expiresAt = iso(ctx, data.plan && data.plan.expires_at);
86
+ if (expiresAt) metrics.push(ctx.line.text({ label: "Subscription expires", value: expiresAt }));
87
+
88
+ try {
89
+ var bal = requestJson(ctx, "payg/balance", key, 3000);
90
+ if (bal.success && bal.data && number(bal.data.total_credits) !== null && String(bal.data.currency || "").toUpperCase() === "USD") {
91
+ metrics.push(ctx.line.text({ label: "PAYG Balance", value: "$" + number(bal.data.total_credits).toFixed(2) }));
92
+ }
93
+ } catch (error) {
94
+ ctx.host.log.warn("ZenMux PAYG balance request failed: " + String(error));
95
+ }
96
+
97
+ if (!metrics.length) throw "ZenMux returned no measurable usage or balance.";
98
+ return { displayName: "ZenMux", source: "api", plan: planLabel, lines: metrics };
99
+ }
100
+
101
+ globalThis.__openusage_plugin = { id: "zenmux", probe: probe };
102
+ })();
@@ -0,0 +1,23 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "zenmux",
4
+ "name": "ZenMux",
5
+ "version": "0.1.0",
6
+ "entry": "plugin.js",
7
+ "enabledByDefault": false,
8
+ "supportedModes": [
9
+ "api"
10
+ ],
11
+ "autoMode": "api",
12
+ "usageDashboardUrl": "https://zenmux.ai/platform/management",
13
+ "links": [
14
+ {
15
+ "label": "Dashboard",
16
+ "url": "https://zenmux.ai/platform/management"
17
+ }
18
+ ],
19
+ "envVars": [
20
+ "ZENMUX_MANAGEMENT_API_KEY",
21
+ "ZENMUX_API_KEY"
22
+ ]
23
+ }