@hashimkarim/usagestat-linux-x64-gnu 2.0.0-alpha.1 → 2.0.0-alpha.4
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/LICENSE +0 -0
- package/native-manifest.json +1088 -134
- package/package.json +160 -1
- package/plugins/UPSTREAM-LICENSES.md +113 -0
- package/plugins/_provider-icons/LICENSE +21 -0
- package/plugins/_provider-icons/NOTICE +12 -0
- package/plugins/_provider-icons/licenses/CodexBar-MIT.txt +21 -0
- package/plugins/_provider-icons/licenses/LobeHub-MIT.txt +21 -0
- package/plugins/_provider-icons/licenses/UsageStat-Bar-MIT.txt +21 -0
- package/plugins/_provider-icons/manifest.json +1219 -0
- package/plugins/_provider-icons/provenance.json +269 -0
- package/plugins/_provider-icons/source.json +4 -0
- package/plugins/abacus-ai/icon-color.svg +18 -0
- package/plugins/abacus-ai/icon.svg +0 -0
- package/plugins/abacus-ai/plugin.js +0 -0
- package/plugins/abacus-ai/plugin.json +0 -0
- package/plugins/aiand/icon.svg +6 -0
- package/plugins/aiand/plugin.js +108 -0
- package/plugins/aiand/plugin.json +22 -0
- package/plugins/aixy/LICENSE +21 -0
- package/plugins/aixy/plugin.js +261 -0
- package/plugins/aixy/plugin.json +24 -0
- package/plugins/alibaba/icon-color.svg +0 -0
- package/plugins/alibaba/icon.svg +0 -0
- package/plugins/alibaba/plugin.js +0 -0
- package/plugins/alibaba/plugin.json +0 -0
- package/plugins/alibaba-token-plan/icon-color.svg +0 -0
- package/plugins/alibaba-token-plan/icon.svg +0 -0
- package/plugins/alibaba-token-plan/plugin.js +0 -0
- package/plugins/alibaba-token-plan/plugin.json +0 -0
- package/plugins/amp/icon-color.svg +0 -0
- package/plugins/amp/icon-conflict.svg +0 -0
- package/plugins/amp/icon.svg +0 -0
- package/plugins/amp/plugin.js +0 -0
- package/plugins/amp/plugin.json +0 -0
- package/plugins/antigravity/icon-color.svg +0 -0
- package/plugins/antigravity/icon-conflict.svg +0 -0
- package/plugins/antigravity/icon.svg +0 -0
- package/plugins/antigravity/plugin.js +136 -46
- package/plugins/antigravity/plugin.json +0 -0
- package/plugins/antigravity-cli/icon-color.svg +1 -0
- package/plugins/antigravity-cli/icon.svg +1 -3
- package/plugins/antigravity-cli/plugin.js +11 -15
- package/plugins/antigravity-cli/plugin.json +0 -0
- package/plugins/antigravity-ide/icon-color.svg +1 -0
- package/plugins/antigravity-ide/icon.svg +1 -3
- package/plugins/antigravity-ide/plugin.js +0 -0
- package/plugins/antigravity-ide/plugin.json +0 -0
- package/plugins/atlascloud/LICENSE +21 -0
- package/plugins/atlascloud/icon-color.svg +1 -0
- package/plugins/atlascloud/icon.svg +1 -0
- package/plugins/atlascloud/plugin.js +49 -0
- package/plugins/atlascloud/plugin.json +23 -0
- package/plugins/augment/icon-color.svg +14 -0
- package/plugins/augment/icon.svg +0 -0
- package/plugins/augment/plugin.js +0 -0
- package/plugins/augment/plugin.json +0 -0
- package/plugins/aws-bedrock/icon-color.svg +0 -0
- package/plugins/aws-bedrock/icon.svg +0 -0
- package/plugins/aws-bedrock/plugin.js +0 -0
- package/plugins/aws-bedrock/plugin.json +0 -0
- package/plugins/azure-openai/icon-color.svg +0 -0
- package/plugins/azure-openai/icon.svg +0 -0
- package/plugins/azure-openai/plugin.js +0 -0
- package/plugins/azure-openai/plugin.json +0 -0
- package/plugins/bifrost/LICENSE +21 -0
- package/plugins/bifrost/plugin.js +361 -0
- package/plugins/bifrost/plugin.json +23 -0
- package/plugins/chutes/icon.svg +0 -0
- package/plugins/chutes/plugin.js +0 -0
- package/plugins/chutes/plugin.json +0 -0
- package/plugins/claude/icon-color.svg +0 -0
- package/plugins/claude/icon.svg +0 -0
- package/plugins/claude/plugin.js +358 -161
- package/plugins/claude/plugin.json +1 -1
- package/plugins/clawrouter/icon.svg +7 -0
- package/plugins/clawrouter/plugin.js +45 -0
- package/plugins/clawrouter/plugin.json +22 -0
- package/plugins/clinepass/icon.svg +4 -0
- package/plugins/clinepass/plugin.js +87 -0
- package/plugins/clinepass/plugin.json +23 -0
- package/plugins/codebuddy/plugin.js +331 -0
- package/plugins/codebuddy/plugin.json +30 -0
- package/plugins/codebuff/icon-color.svg +92 -0
- package/plugins/codebuff/icon.svg +0 -0
- package/plugins/codebuff/plugin.js +0 -0
- package/plugins/codebuff/plugin.json +0 -0
- package/plugins/coderabbit/plugin.js +25 -0
- package/plugins/coderabbit/plugin.json +12 -0
- package/plugins/codex/icon-color.svg +0 -0
- package/plugins/codex/icon.svg +0 -0
- package/plugins/codex/plugin.js +8 -2
- package/plugins/codex/plugin.json +0 -0
- package/plugins/command-code/icon-color.svg +3 -0
- package/plugins/command-code/icon.svg +0 -0
- package/plugins/command-code/plugin.js +14 -3
- package/plugins/command-code/plugin.json +0 -0
- package/plugins/copilot/icon-color.svg +0 -0
- package/plugins/copilot/icon.svg +1 -1
- package/plugins/copilot/plugin.js +61 -9
- package/plugins/copilot/plugin.json +4 -1
- package/plugins/crof/icon-color.svg +3 -0
- package/plugins/crof/icon.svg +0 -0
- package/plugins/crof/plugin.js +0 -0
- package/plugins/crof/plugin.json +0 -0
- package/plugins/crofai/icon-color.svg +3 -0
- package/plugins/crofai/icon.svg +2 -15
- package/plugins/crofai/plugin.js +0 -0
- package/plugins/crofai/plugin.json +0 -0
- package/plugins/cursor/icon-color.svg +1 -0
- package/plugins/cursor/icon-conflict.svg +0 -0
- package/plugins/cursor/icon.svg +0 -0
- package/plugins/cursor/plugin.js +46 -9
- package/plugins/cursor/plugin.json +3 -2
- package/plugins/cursor-nightly/icon.png +0 -0
- package/plugins/cursor-nightly/plugin.js +45 -8
- package/plugins/cursor-nightly/plugin.json +3 -2
- package/plugins/deepgram/icon.svg +0 -0
- package/plugins/deepgram/plugin.js +0 -0
- package/plugins/deepgram/plugin.json +0 -0
- package/plugins/deepinfra/icon-color.svg +1 -0
- package/plugins/deepinfra/icon.svg +1 -0
- package/plugins/deepinfra/plugin.js +97 -0
- package/plugins/deepinfra/plugin.json +28 -0
- package/plugins/deepseek/icon-color.svg +0 -0
- package/plugins/deepseek/icon.svg +0 -0
- package/plugins/deepseek/plugin.js +150 -59
- package/plugins/deepseek/plugin.json +3 -1
- package/plugins/devin/icon.svg +0 -0
- package/plugins/devin/plugin.js +114 -0
- package/plugins/devin/plugin.json +2 -1
- package/plugins/devpass/LICENSE +21 -0
- package/plugins/devpass/plugin.js +115 -0
- package/plugins/devpass/plugin.json +23 -0
- package/plugins/doubao/icon-color.svg +0 -0
- package/plugins/doubao/icon.svg +0 -0
- package/plugins/doubao/plugin.js +0 -0
- package/plugins/doubao/plugin.json +0 -0
- package/plugins/droid/icon.svg +0 -0
- package/plugins/droid/plugin.json +2 -1
- package/plugins/elevenlabs/icon-color.svg +4 -0
- package/plugins/elevenlabs/icon.svg +0 -0
- package/plugins/elevenlabs/plugin.js +17 -2
- package/plugins/elevenlabs/plugin.json +0 -0
- package/plugins/factory/icon-color.svg +1 -0
- package/plugins/factory/icon-conflict.svg +0 -0
- package/plugins/factory/icon.svg +0 -0
- package/plugins/factory/plugin.js +38 -14
- package/plugins/factory/plugin.json +2 -1
- package/plugins/fireworks-ai/icon-color.svg +1 -0
- package/plugins/fireworks-ai/icon.svg +1 -6
- package/plugins/fireworks-ai/plugin.js +0 -0
- package/plugins/fireworks-ai/plugin.json +0 -0
- package/plugins/gemini/icon-color.svg +0 -0
- package/plugins/gemini/icon.svg +0 -0
- package/plugins/gemini/plugin.js +0 -0
- package/plugins/gemini/plugin.json +0 -0
- package/plugins/gemini-apps/LICENSE +22 -0
- package/plugins/gemini-apps/icon-color.svg +1 -0
- package/plugins/gemini-apps/icon.svg +1 -0
- package/plugins/gemini-apps/plugin.js +470 -0
- package/plugins/gemini-apps/plugin.json +19 -0
- package/plugins/gitkraken/LICENSE +21 -0
- package/plugins/gitkraken/plugin.js +153 -0
- package/plugins/gitkraken/plugin.json +24 -0
- package/plugins/grok/icon-color.svg +1 -0
- package/plugins/grok/icon.svg +0 -0
- package/plugins/grok/plugin.js +30 -5
- package/plugins/grok/plugin.json +3 -1
- package/plugins/groqcloud/icon-color.svg +1 -0
- package/plugins/groqcloud/icon.svg +0 -0
- package/plugins/groqcloud/plugin.js +0 -0
- package/plugins/groqcloud/plugin.json +0 -0
- package/plugins/helmcode/LICENSE +21 -0
- package/plugins/helmcode/plugin.js +188 -0
- package/plugins/helmcode/plugin.json +24 -0
- package/plugins/huggingface/LICENSE +21 -0
- package/plugins/huggingface/icon-color.svg +1 -0
- package/plugins/huggingface/icon.svg +1 -0
- package/plugins/huggingface/plugin.js +293 -0
- package/plugins/huggingface/plugin.json +25 -0
- package/plugins/hyper/LICENSE +21 -0
- package/plugins/hyper/plugin.js +131 -0
- package/plugins/hyper/plugin.json +26 -0
- package/plugins/ibmbob/icon.svg +23 -0
- package/plugins/ibmbob/plugin.js +61 -0
- package/plugins/ibmbob/plugin.json +22 -0
- package/plugins/jetbrains-ai-assistant/icon-color.svg +0 -0
- package/plugins/jetbrains-ai-assistant/icon-conflict.svg +0 -0
- package/plugins/jetbrains-ai-assistant/icon.svg +0 -0
- package/plugins/jetbrains-ai-assistant/plugin.js +0 -0
- package/plugins/jetbrains-ai-assistant/plugin.json +0 -0
- package/plugins/kilo/icon-color.svg +1 -0
- package/plugins/kilo/icon.svg +0 -0
- package/plugins/kilo/plugin.js +0 -0
- package/plugins/kilo/plugin.json +0 -0
- package/plugins/kimi/icon-color.svg +0 -0
- package/plugins/kimi/icon-conflict.svg +0 -0
- package/plugins/kimi/icon.svg +0 -0
- package/plugins/kimi/plugin.js +122 -141
- package/plugins/kimi/plugin.json +5 -2
- package/plugins/kimi-k2/icon-color.svg +0 -0
- package/plugins/kimi-k2/icon.svg +0 -0
- package/plugins/kimi-k2/plugin.js +0 -0
- package/plugins/kimi-k2/plugin.json +0 -0
- package/plugins/kiro/icon-color.svg +0 -0
- package/plugins/kiro/icon-conflict.svg +0 -0
- package/plugins/kiro/icon.svg +0 -0
- package/plugins/kiro/plugin.js +49 -10
- package/plugins/kiro/plugin.json +3 -1
- package/plugins/litellm/icon.svg +0 -0
- package/plugins/litellm/plugin.js +54 -3
- package/plugins/litellm/plugin.json +0 -0
- package/plugins/llm-proxy/icon.svg +0 -0
- package/plugins/llm-proxy/plugin.js +0 -0
- package/plugins/llm-proxy/plugin.json +0 -0
- package/plugins/llmman/LICENSE +21 -0
- package/plugins/llmman/plugin.js +133 -0
- package/plugins/llmman/plugin.json +23 -0
- package/plugins/longcat/icon-color.svg +1 -0
- package/plugins/longcat/icon.svg +1 -0
- package/plugins/longcat/plugin.js +182 -0
- package/plugins/longcat/plugin.json +23 -0
- package/plugins/manus/icon-color.svg +6 -0
- package/plugins/manus/icon.svg +0 -0
- package/plugins/manus/plugin.js +0 -0
- package/plugins/manus/plugin.json +0 -0
- package/plugins/mimo/icon-color.svg +4 -0
- package/plugins/mimo/icon.svg +4 -1
- package/plugins/mimo/plugin.js +0 -0
- package/plugins/mimo/plugin.json +0 -0
- package/plugins/minimax/icon-color.svg +0 -0
- package/plugins/minimax/icon-conflict.svg +0 -0
- package/plugins/minimax/icon.svg +0 -0
- package/plugins/minimax/plugin.js +25 -31
- package/plugins/minimax/plugin.json +0 -0
- package/plugins/mistral/icon-color.svg +0 -0
- package/plugins/mistral/icon.svg +0 -0
- package/plugins/mistral/plugin.js +110 -5
- package/plugins/mistral/plugin.json +0 -0
- package/plugins/moonshot/icon-color.svg +1 -0
- package/plugins/moonshot/icon.svg +0 -0
- package/plugins/moonshot/plugin.js +8 -6
- package/plugins/moonshot/plugin.json +0 -0
- package/plugins/muse/LICENSE +21 -0
- package/plugins/muse/plugin.js +319 -0
- package/plugins/muse/plugin.json +26 -0
- package/plugins/nanogpt/icon-color.svg +0 -0
- package/plugins/nanogpt/icon.svg +0 -0
- package/plugins/nanogpt/plugin.js +0 -0
- package/plugins/nanogpt/plugin.json +0 -0
- package/plugins/neuralwatt/icon.svg +0 -0
- package/plugins/neuralwatt/plugin.js +0 -0
- package/plugins/neuralwatt/plugin.json +0 -0
- package/plugins/notion/icon.svg +1 -0
- package/plugins/notion/plugin.js +282 -0
- package/plugins/notion/plugin.json +29 -0
- package/plugins/nous/LICENSE +21 -0
- package/plugins/nous/icon-color.svg +1 -0
- package/plugins/nous/icon.svg +1 -0
- package/plugins/nous/plugin.js +124 -0
- package/plugins/nous/plugin.json +24 -0
- package/plugins/ollama/icon-color.svg +1 -0
- package/plugins/ollama/icon.svg +0 -0
- package/plugins/ollama/plugin.js +257 -56
- package/plugins/ollama/plugin.json +6 -3
- package/plugins/openai-api/icon-color.svg +1 -0
- package/plugins/openai-api/icon.svg +0 -0
- package/plugins/openai-api/plugin.js +0 -0
- package/plugins/openai-api/plugin.json +0 -0
- package/plugins/opencode/icon-color.svg +1 -0
- package/plugins/opencode/icon.svg +0 -0
- package/plugins/opencode/plugin.js +0 -0
- package/plugins/opencode/plugin.json +0 -0
- package/plugins/opencode-go/icon-color.svg +1 -0
- package/plugins/opencode-go/icon-conflict.svg +0 -0
- package/plugins/opencode-go/icon.svg +0 -0
- package/plugins/opencode-go/plugin.js +103 -17
- package/plugins/opencode-go/plugin.json +5 -2
- package/plugins/openrouter/icon-color.svg +1 -0
- package/plugins/openrouter/icon.svg +0 -0
- package/plugins/openrouter/plugin.js +371 -114
- package/plugins/openrouter/plugin.json +6 -0
- package/plugins/perplexity/icon-color.svg +0 -0
- package/plugins/perplexity/icon-conflict.svg +0 -0
- package/plugins/perplexity/icon.svg +0 -0
- package/plugins/perplexity/plugin.js +0 -0
- package/plugins/perplexity/plugin.json +0 -0
- package/plugins/pi/plugin.js +113 -0
- package/plugins/pi/plugin.json +11 -0
- package/plugins/poe/icon.svg +0 -0
- package/plugins/poe/plugin.js +24 -18
- package/plugins/poe/plugin.json +2 -0
- package/plugins/qoder/icon.svg +3 -0
- package/plugins/qoder/plugin.js +227 -0
- package/plugins/qoder/plugin.json +23 -0
- package/plugins/qwencloud/icon-color.svg +1 -0
- package/plugins/qwencloud/icon.svg +1 -0
- package/plugins/qwencloud/plugin.js +677 -0
- package/plugins/qwencloud/plugin.json +29 -0
- package/plugins/raycast/LICENSE +21 -0
- package/plugins/raycast/plugin.js +174 -0
- package/plugins/raycast/plugin.json +24 -0
- package/plugins/replicate/LICENSE +21 -0
- package/plugins/replicate/icon-color.svg +1 -0
- package/plugins/replicate/icon.svg +1 -0
- package/plugins/replicate/plugin.js +165 -0
- package/plugins/replicate/plugin.json +24 -0
- package/plugins/sakana/icon.svg +5 -0
- package/plugins/sakana/plugin.js +156 -0
- package/plugins/sakana/plugin.json +23 -0
- package/plugins/stepfun/icon-color.svg +0 -0
- package/plugins/stepfun/icon.svg +0 -0
- package/plugins/stepfun/plugin.js +0 -0
- package/plugins/stepfun/plugin.json +0 -0
- package/plugins/sub2api/icon.svg +4 -0
- package/plugins/sub2api/plugin.js +191 -0
- package/plugins/sub2api/plugin.json +16 -0
- package/plugins/synthetic/icon-color.svg +14 -0
- package/plugins/synthetic/icon-conflict.svg +0 -0
- package/plugins/synthetic/icon.svg +0 -0
- package/plugins/synthetic/plugin.js +0 -0
- package/plugins/synthetic/plugin.json +0 -0
- package/plugins/t3chat/icon-color.svg +0 -0
- package/plugins/t3chat/icon.svg +0 -0
- package/plugins/t3chat/plugin.js +0 -0
- package/plugins/t3chat/plugin.json +0 -0
- package/plugins/typesafe/LICENSE +21 -0
- package/plugins/typesafe/plugin.js +225 -0
- package/plugins/typesafe/plugin.json +24 -0
- package/plugins/v0/LICENSE +21 -0
- package/plugins/v0/icon-color.svg +1 -0
- package/plugins/v0/icon.svg +1 -0
- package/plugins/v0/plugin.js +214 -0
- package/plugins/v0/plugin.json +24 -0
- package/plugins/venice/icon-color.svg +0 -0
- package/plugins/venice/icon.svg +0 -0
- package/plugins/venice/plugin.js +50 -1
- package/plugins/venice/plugin.json +2 -1
- package/plugins/vercel/LICENSE +21 -0
- package/plugins/vercel/icon-color.svg +1 -0
- package/plugins/vercel/icon.svg +1 -0
- package/plugins/vercel/plugin.js +55 -0
- package/plugins/vercel/plugin.json +23 -0
- package/plugins/vertex-ai/icon-color.svg +0 -0
- package/plugins/vertex-ai/icon.svg +0 -0
- package/plugins/vertex-ai/plugin.js +0 -0
- package/plugins/vertex-ai/plugin.json +0 -0
- package/plugins/warp/icon-color.svg +0 -0
- package/plugins/warp/icon.svg +0 -0
- package/plugins/warp/plugin.js +0 -0
- package/plugins/warp/plugin.json +0 -0
- package/plugins/wayfinder/icon.svg +5 -0
- package/plugins/wayfinder/plugin.js +47 -0
- package/plugins/wayfinder/plugin.json +16 -0
- package/plugins/windsurf/icon-color.svg +1 -0
- package/plugins/windsurf/icon-conflict.svg +0 -0
- package/plugins/windsurf/icon.svg +0 -0
- package/plugins/windsurf/plugin.js +0 -0
- package/plugins/windsurf/plugin.json +0 -0
- package/plugins/xai/icon-color.svg +1 -0
- package/plugins/xai/icon.svg +1 -0
- package/plugins/xai/plugin.js +162 -0
- package/plugins/xai/plugin.json +28 -0
- package/plugins/xkiro/LICENSE +21 -0
- package/plugins/xkiro/plugin.js +99 -0
- package/plugins/xkiro/plugin.json +23 -0
- package/plugins/zai/icon-color.svg +1 -0
- package/plugins/zai/icon-conflict.svg +0 -0
- package/plugins/zai/icon.svg +0 -0
- package/plugins/zai/plugin.js +111 -161
- package/plugins/zai/plugin.json +4 -1
- package/plugins/zed/icon.svg +0 -0
- package/plugins/zed/plugin.js +0 -0
- package/plugins/zed/plugin.json +0 -0
- package/plugins/zenmux/icon-color.svg +1 -0
- package/plugins/zenmux/icon.svg +1 -0
- package/plugins/zenmux/plugin.js +102 -0
- package/plugins/zenmux/plugin.json +23 -0
- package/plugins/zoommate/icon.svg +1 -0
- package/plugins/zoommate/plugin.js +244 -0
- package/plugins/zoommate/plugin.json +29 -0
- package/usagestat +0 -0
- 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
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Peter Steinberger
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Generated by tools/vendor-codexbar-providers.cjs; see LICENSE.
|
|
2
|
+
globalThis.__usagestat_bundled_options = {"labels":["Daily free tokens","Weekly","Additional"],"defaults":{},"autoMode":"api"};
|
|
3
|
+
function _nullishCoalesce(lhs, rhsFn) {
|
|
4
|
+
if (lhs != null) {
|
|
5
|
+
return lhs;
|
|
6
|
+
} else {
|
|
7
|
+
return rhsFn();
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function _optionalChain(ops) {
|
|
11
|
+
let lastAccessLHS = undefined;
|
|
12
|
+
let value = ops[0];
|
|
13
|
+
let i = 1;
|
|
14
|
+
while (i < ops.length) {
|
|
15
|
+
const op = ops[i];
|
|
16
|
+
const fn = ops[i + 1];
|
|
17
|
+
i += 2;
|
|
18
|
+
if ((op === "optionalAccess" || op === "optionalCall") && value == null) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (op === "access" || op === "optionalAccess") {
|
|
22
|
+
lastAccessLHS = value;
|
|
23
|
+
value = fn(value);
|
|
24
|
+
} else if (op === "call" || op === "optionalCall") {
|
|
25
|
+
value = fn((...args) => value.call(lastAccessLHS, ...args));
|
|
26
|
+
lastAccessLHS = undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
defineProvider({
|
|
32
|
+
id: "xkiro",
|
|
33
|
+
name: "xKiro",
|
|
34
|
+
endpoints: ["https://api.xkiro.com"],
|
|
35
|
+
auth: { type: "bearer", secret: "XKIRO_API_KEY" },
|
|
36
|
+
settings: [{ key: "XKIRO_API_KEY", title: "xKiro API key", type: "secure" }],
|
|
37
|
+
capabilities: ["http-status"],
|
|
38
|
+
async fetchUsage(ctx) {
|
|
39
|
+
const response = await ctx.http.get("https://api.xkiro.com/v1/usage");
|
|
40
|
+
const message = `xKiro returned HTTP ${response.status}.`;
|
|
41
|
+
if (response.status === 401) throw ctx.fail.authenticationExpired(message);
|
|
42
|
+
if (response.status === 403) throw ctx.fail.permissionDenied(message);
|
|
43
|
+
if (response.status === 429) {
|
|
44
|
+
const delay = Number(_nullishCoalesce(response.headers["retry-after"], () => 1));
|
|
45
|
+
throw ctx.fail.rateLimited(message, {
|
|
46
|
+
retryAfterSeconds: Number.isFinite(delay) && delay >= 0 ? Math.min(delay, 10) : 1,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (response.status >= 500) throw ctx.fail.providerUnavailable(message);
|
|
50
|
+
if (response.status !== 200) throw ctx.fail.apiFailure(message);
|
|
51
|
+
const fail = () => {
|
|
52
|
+
throw ctx.fail.parseFailure("xKiro returned an unrecognized free-token usage response.");
|
|
53
|
+
};
|
|
54
|
+
const record = (value) => (value && typeof value === "object" && !Array.isArray(value) ? value : undefined);
|
|
55
|
+
let decoded;
|
|
56
|
+
try {
|
|
57
|
+
decoded = JSON.parse(response.bodyText);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
void error;
|
|
60
|
+
return fail();
|
|
61
|
+
}
|
|
62
|
+
const root = record(decoded);
|
|
63
|
+
const free = record(_optionalChain([root, "optionalAccess", (_) => _.free_tokens]));
|
|
64
|
+
if (_optionalChain([root, "optionalAccess", (_2) => _2.object]) !== "usage" || !free) return fail();
|
|
65
|
+
const counter = (value) => {
|
|
66
|
+
if (value === undefined || value === null) return undefined;
|
|
67
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : fail();
|
|
68
|
+
};
|
|
69
|
+
const used = counter(free.used_today);
|
|
70
|
+
const limit = counter(free.limit_per_day);
|
|
71
|
+
const remaining = counter(free.remaining);
|
|
72
|
+
if (used === undefined && limit === undefined && remaining === undefined && free.limit_per_day !== null) {
|
|
73
|
+
return fail();
|
|
74
|
+
}
|
|
75
|
+
const rows = [];
|
|
76
|
+
if (used !== undefined) rows.push({ label: "Tokens used today", value: ctx.format.number(used) });
|
|
77
|
+
if (limit !== undefined) rows.push({ label: "Daily allowance", value: ctx.format.number(limit) });
|
|
78
|
+
else if (free.limit_per_day === null) rows.push({ label: "Daily allowance", value: "No cap reported" });
|
|
79
|
+
if (remaining !== undefined) rows.push({ label: "Tokens remaining", value: ctx.format.number(remaining) });
|
|
80
|
+
rows.push({ label: "Daily reset", value: "00:00 UTC" });
|
|
81
|
+
const text = (value) => (typeof value === "string" ? value.trim() || undefined : undefined);
|
|
82
|
+
return {
|
|
83
|
+
primary:
|
|
84
|
+
used !== undefined && limit !== undefined
|
|
85
|
+
? {
|
|
86
|
+
usedPercent: limit === 0 ? 100 : ctx.pct(used, limit),
|
|
87
|
+
windowMinutes: 1440,
|
|
88
|
+
resetsAt: ctx.date.nextDailyReset("UTC", 0),
|
|
89
|
+
}
|
|
90
|
+
: undefined,
|
|
91
|
+
details: [{ title: "Free tokens", rows }],
|
|
92
|
+
identity: {
|
|
93
|
+
email: text(_optionalChain([record, "call", (_3) => _3(root.user), "optionalAccess", (_4) => _4.email])),
|
|
94
|
+
loginMethod: root.plan === null ? "Pay as you go" : text(root.plan),
|
|
95
|
+
},
|
|
96
|
+
dataConfidence: "exact",
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"id": "xkiro",
|
|
4
|
+
"name": "xKiro",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"entry": "plugin.js",
|
|
7
|
+
"enabledByDefault": false,
|
|
8
|
+
"supportedModes": [
|
|
9
|
+
"api"
|
|
10
|
+
],
|
|
11
|
+
"autoMode": "api",
|
|
12
|
+
"usageDashboardUrl": "https://xkiro.com",
|
|
13
|
+
"envVars": [
|
|
14
|
+
"XKIRO_API_KEY"
|
|
15
|
+
],
|
|
16
|
+
"upstream": {
|
|
17
|
+
"repository": "https://github.com/steipete/CodexBar",
|
|
18
|
+
"revision": "78ba5a1e65e6859da59a21b799df95ab91bc0b89",
|
|
19
|
+
"path": "Sources/CodexBarCore/Resources/Plugins/xkiro.js",
|
|
20
|
+
"sha256": "03bfcb8e518577ee18dd335e4e1e1f7d629d3e5abdf2216b187b1cba8b683853",
|
|
21
|
+
"license": "MIT"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Z.ai</title><path d="M12.105 2L9.927 4.953H.653L2.83 2h9.276zM23.254 19.048L21.078 22h-9.242l2.174-2.952h9.244zM24 2L9.264 22H0L14.736 2H24z"></path></svg>
|
|
File without changes
|
package/plugins/zai/icon.svg
CHANGED
|
File without changes
|
package/plugins/zai/plugin.js
CHANGED
|
@@ -1,187 +1,137 @@
|
|
|
1
1
|
(function () {
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
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
|
|
10
|
-
|
|
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
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
70
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
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
|
|
82
|
-
let
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
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
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
lines.push(ctx.line.
|
|
124
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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 (
|
|
138
|
-
|
|
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
|
|
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 }
|
package/plugins/zai/plugin.json
CHANGED
|
@@ -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
|
}
|