opencode-minimax-quota 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tui.js +72 -36
- package/package.json +1 -1
package/dist/tui.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
1
|
// src.tsx
|
|
2
|
+
import { appendFileSync } from "fs";
|
|
9
3
|
import { createSignal, createRoot } from "solid-js";
|
|
10
4
|
import { effect, createElement, setProp, insert } from "@opentui/solid";
|
|
5
|
+
var LOG = "/tmp/opencode-minimax-quota.log";
|
|
6
|
+
function log(...args) {
|
|
7
|
+
try {
|
|
8
|
+
appendFileSync(LOG, `[${(/* @__PURE__ */ new Date()).toISOString()}] ${args.map((a) => typeof a === "string" ? a : JSON.stringify(a)).join(" ")}
|
|
9
|
+
`);
|
|
10
|
+
} catch {
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
log("=== dist/tui.js TOP LEVEL ===");
|
|
14
|
+
log("imports loaded");
|
|
11
15
|
var QUOTA_API = "https://www.minimaxi.com/v1/token_plan/remains";
|
|
12
16
|
var REFRESH_INTERVAL = 5 * 60 * 1e3;
|
|
13
17
|
function getAuthPath() {
|
|
@@ -15,14 +19,15 @@ function getAuthPath() {
|
|
|
15
19
|
}
|
|
16
20
|
function loadApiKey() {
|
|
17
21
|
try {
|
|
18
|
-
const
|
|
22
|
+
const fs = __require("fs");
|
|
19
23
|
const authPath = getAuthPath();
|
|
20
|
-
if (!existsSync(authPath)) return null;
|
|
21
|
-
const auth = JSON.parse(readFileSync(authPath, "utf8"));
|
|
24
|
+
if (!fs.existsSync(authPath)) return null;
|
|
25
|
+
const auth = JSON.parse(fs.readFileSync(authPath, "utf8"));
|
|
22
26
|
const entry = auth["minimax-cn-coding-plan"];
|
|
23
27
|
if (!entry) return null;
|
|
24
28
|
return typeof entry === "string" ? entry : entry.key;
|
|
25
|
-
} catch {
|
|
29
|
+
} catch (e) {
|
|
30
|
+
log("loadApiKey error:", e.message);
|
|
26
31
|
return null;
|
|
27
32
|
}
|
|
28
33
|
}
|
|
@@ -38,15 +43,22 @@ function parseQuota(data) {
|
|
|
38
43
|
}
|
|
39
44
|
async function fetchQuota() {
|
|
40
45
|
const key = loadApiKey();
|
|
41
|
-
if (!key)
|
|
46
|
+
if (!key) {
|
|
47
|
+
log("fetchQuota: no API key");
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
42
50
|
try {
|
|
43
51
|
const res = await fetch(QUOTA_API, {
|
|
44
52
|
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" }
|
|
45
53
|
});
|
|
46
54
|
const data = await res.json();
|
|
47
|
-
if (data.base_resp?.status_code !== 0)
|
|
55
|
+
if (data.base_resp?.status_code !== 0) {
|
|
56
|
+
log("fetchQuota: API error", data.base_resp);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
48
59
|
return parseQuota(data);
|
|
49
|
-
} catch {
|
|
60
|
+
} catch (e) {
|
|
61
|
+
log("fetchQuota error:", e.message);
|
|
50
62
|
return null;
|
|
51
63
|
}
|
|
52
64
|
}
|
|
@@ -79,7 +91,7 @@ function makeSpan(props, ...children) {
|
|
|
79
91
|
return el;
|
|
80
92
|
}
|
|
81
93
|
function renderQuotaBadge(theme, q) {
|
|
82
|
-
if (!q) return makeText({ fg: theme.textMuted }, "MiniMax
|
|
94
|
+
if (!q) return makeText({ fg: theme.textMuted }, "MiniMax loading...");
|
|
83
95
|
const iColor = q.intervalPct > 20 ? theme.success : theme.error;
|
|
84
96
|
const wColor = q.weeklyPct > 20 ? theme.success : theme.error;
|
|
85
97
|
return makeBox({ flexDirection: "row", gap: 1, alignItems: "center" }, [
|
|
@@ -100,31 +112,55 @@ function renderQuotaBadge(theme, q) {
|
|
|
100
112
|
]);
|
|
101
113
|
}
|
|
102
114
|
var tui = async (api) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
log("tui() called");
|
|
116
|
+
log("api keys:", Object.keys(api).join(","));
|
|
117
|
+
log("api.slots:", typeof api.slots, "register:", typeof api.slots?.register);
|
|
118
|
+
log("api.theme:", typeof api.theme);
|
|
119
|
+
log("api.event:", typeof api.event);
|
|
120
|
+
log("api.lifecycle:", typeof api.lifecycle);
|
|
121
|
+
try {
|
|
122
|
+
createRoot((dispose) => {
|
|
123
|
+
log("createRoot setup");
|
|
124
|
+
const [quota, setQuota] = createSignal(null);
|
|
125
|
+
log("createSignal done");
|
|
126
|
+
effect(() => {
|
|
127
|
+
log("effect running, quota=", quota()?.intervalPct);
|
|
128
|
+
const q = quota();
|
|
129
|
+
const theme = api.theme.current;
|
|
130
|
+
const el = renderQuotaBadge(theme, q);
|
|
131
|
+
log("about to register slot, el type:", typeof el, el?.constructor?.name);
|
|
132
|
+
try {
|
|
133
|
+
api.slots.register({
|
|
134
|
+
slots: {
|
|
135
|
+
session_prompt_right() {
|
|
136
|
+
log("renderer called");
|
|
137
|
+
return el;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
log("register done");
|
|
142
|
+
} catch (e) {
|
|
143
|
+
log("register error:", e.message, e.stack);
|
|
114
144
|
}
|
|
115
145
|
});
|
|
146
|
+
const load = async () => {
|
|
147
|
+
log("load() fetching...");
|
|
148
|
+
const q = await fetchQuota();
|
|
149
|
+
log("load() got quota:", q?.intervalPct);
|
|
150
|
+
setQuota(q);
|
|
151
|
+
};
|
|
152
|
+
api.lifecycle.onDispose(dispose);
|
|
153
|
+
load();
|
|
154
|
+
setInterval(load, REFRESH_INTERVAL);
|
|
155
|
+
api.event.on("session.created", () => load());
|
|
156
|
+
api.event.on("session.next.prompted", () => load());
|
|
157
|
+
log("setup complete");
|
|
116
158
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
api.lifecycle.onDispose(dispose);
|
|
122
|
-
load();
|
|
123
|
-
setInterval(load, REFRESH_INTERVAL);
|
|
124
|
-
api.event.on("session.created", () => load());
|
|
125
|
-
api.event.on("session.next.prompted", () => load());
|
|
126
|
-
});
|
|
159
|
+
} catch (e) {
|
|
160
|
+
log("createRoot ERROR:", e.message, e.stack);
|
|
161
|
+
}
|
|
127
162
|
};
|
|
163
|
+
log("tui defined, exporting");
|
|
128
164
|
var src_default = { id: "opencode-minimax-quota", tui };
|
|
129
165
|
export {
|
|
130
166
|
src_default as default
|