opencode-minimax-quota 0.1.1 → 0.1.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.
- package/dist/tui.js +144 -68
- 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
|
-
import {
|
|
4
|
+
import { createComponent } 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
|
}
|
|
@@ -46,7 +51,8 @@ async function fetchQuota() {
|
|
|
46
51
|
const data = await res.json();
|
|
47
52
|
if (data.base_resp?.status_code !== 0) return null;
|
|
48
53
|
return parseQuota(data);
|
|
49
|
-
} catch {
|
|
54
|
+
} catch (e) {
|
|
55
|
+
log("fetchQuota error:", e.message);
|
|
50
56
|
return null;
|
|
51
57
|
}
|
|
52
58
|
}
|
|
@@ -60,70 +66,140 @@ function fmtResetTime(ms) {
|
|
|
60
66
|
hour12: false
|
|
61
67
|
}).format(ms);
|
|
62
68
|
}
|
|
63
|
-
function
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
69
|
+
function Badge(props) {
|
|
70
|
+
const theme = () => props.theme;
|
|
71
|
+
const q = () => props.quota();
|
|
72
|
+
const iColor = () => (q()?.intervalPct ?? 0) > 20 ? theme().success : theme().error;
|
|
73
|
+
const wColor = () => (q()?.weeklyPct ?? 0) > 20 ? theme().success : theme().error;
|
|
74
|
+
const root = createComponent("box", {
|
|
75
|
+
get flexDirection() {
|
|
76
|
+
return "row";
|
|
77
|
+
},
|
|
78
|
+
get gap() {
|
|
79
|
+
return 1;
|
|
80
|
+
},
|
|
81
|
+
get alignItems() {
|
|
82
|
+
return "center";
|
|
83
|
+
},
|
|
84
|
+
get children() {
|
|
85
|
+
const cur = q();
|
|
86
|
+
const curTheme = theme();
|
|
87
|
+
if (!cur) {
|
|
88
|
+
return [createComponent("text", {
|
|
89
|
+
get fg() {
|
|
90
|
+
return curTheme.textMuted;
|
|
91
|
+
},
|
|
92
|
+
get children() {
|
|
93
|
+
return "MiniMax \u52A0\u8F7D...";
|
|
94
|
+
}
|
|
95
|
+
})];
|
|
96
|
+
}
|
|
97
|
+
const iColorVal = iColor();
|
|
98
|
+
const wColorVal = wColor();
|
|
99
|
+
return [
|
|
100
|
+
createComponent("text", {
|
|
101
|
+
get fg() {
|
|
102
|
+
return curTheme.textMuted;
|
|
103
|
+
},
|
|
104
|
+
get children() {
|
|
105
|
+
return "MiniMax";
|
|
106
|
+
}
|
|
107
|
+
}),
|
|
108
|
+
createComponent("text", {
|
|
109
|
+
get fg() {
|
|
110
|
+
return curTheme.text;
|
|
111
|
+
},
|
|
112
|
+
get children() {
|
|
113
|
+
return [
|
|
114
|
+
"5h:",
|
|
115
|
+
createComponent("span", {
|
|
116
|
+
get style() {
|
|
117
|
+
return { fg: iColorVal };
|
|
118
|
+
},
|
|
119
|
+
get children() {
|
|
120
|
+
return `${cur.intervalPct}%`;
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
createComponent("text", {
|
|
127
|
+
get fg() {
|
|
128
|
+
return curTheme.textMuted;
|
|
129
|
+
},
|
|
130
|
+
get children() {
|
|
131
|
+
return fmtResetTime(cur.intervalResetMs);
|
|
132
|
+
}
|
|
133
|
+
}),
|
|
134
|
+
createComponent("text", {
|
|
135
|
+
get fg() {
|
|
136
|
+
return curTheme.textMuted;
|
|
137
|
+
},
|
|
138
|
+
get children() {
|
|
139
|
+
return "\xB7";
|
|
140
|
+
}
|
|
141
|
+
}),
|
|
142
|
+
createComponent("text", {
|
|
143
|
+
get fg() {
|
|
144
|
+
return curTheme.text;
|
|
145
|
+
},
|
|
146
|
+
get children() {
|
|
147
|
+
return [
|
|
148
|
+
"\u5468:",
|
|
149
|
+
createComponent("span", {
|
|
150
|
+
get style() {
|
|
151
|
+
return { fg: wColorVal };
|
|
152
|
+
},
|
|
153
|
+
get children() {
|
|
154
|
+
return `${cur.weeklyPct}%`;
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
];
|
|
158
|
+
}
|
|
159
|
+
}),
|
|
160
|
+
createComponent("text", {
|
|
161
|
+
get fg() {
|
|
162
|
+
return curTheme.textMuted;
|
|
163
|
+
},
|
|
164
|
+
get children() {
|
|
165
|
+
return fmtResetTime(cur.weeklyResetMs);
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return root;
|
|
101
172
|
}
|
|
102
173
|
var tui = async (api) => {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const
|
|
108
|
-
const el = renderQuotaBadge(theme, q);
|
|
174
|
+
log("tui() called");
|
|
175
|
+
try {
|
|
176
|
+
createRoot((dispose) => {
|
|
177
|
+
log("createRoot setup");
|
|
178
|
+
const [quota, setQuota] = createSignal(null);
|
|
109
179
|
api.slots.register({
|
|
110
180
|
slots: {
|
|
111
181
|
session_prompt_right() {
|
|
112
|
-
|
|
182
|
+
log("renderer called");
|
|
183
|
+
return Badge({ quota, theme: () => api.theme.current });
|
|
113
184
|
}
|
|
114
185
|
}
|
|
115
186
|
});
|
|
187
|
+
log("slot registered");
|
|
188
|
+
const load = async () => {
|
|
189
|
+
const q = await fetchQuota();
|
|
190
|
+
log("load got quota:", q?.intervalPct);
|
|
191
|
+
setQuota(q);
|
|
192
|
+
};
|
|
193
|
+
api.lifecycle.onDispose(dispose);
|
|
194
|
+
load();
|
|
195
|
+
setInterval(load, REFRESH_INTERVAL);
|
|
196
|
+
api.event.on("session.created", () => load());
|
|
197
|
+
api.event.on("session.next.prompted", () => load());
|
|
198
|
+
log("setup complete");
|
|
116
199
|
});
|
|
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
|
-
});
|
|
200
|
+
} catch (e) {
|
|
201
|
+
log("createRoot ERROR:", e.message, e.stack);
|
|
202
|
+
}
|
|
127
203
|
};
|
|
128
204
|
var src_default = { id: "opencode-minimax-quota", tui };
|
|
129
205
|
export {
|