opencode-minimax-quota 0.1.2 → 0.1.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/dist/tui.js +117 -69
- package/package.json +1 -1
package/dist/tui.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// src.tsx
|
|
2
2
|
import { appendFileSync } from "fs";
|
|
3
3
|
import { createSignal, createRoot } from "solid-js";
|
|
4
|
-
import {
|
|
4
|
+
import { createComponent } from "@opentui/solid";
|
|
5
5
|
var LOG = "/tmp/opencode-minimax-quota.log";
|
|
6
6
|
function log(...args) {
|
|
7
7
|
try {
|
|
@@ -19,15 +19,16 @@ function getAuthPath() {
|
|
|
19
19
|
}
|
|
20
20
|
function loadApiKey() {
|
|
21
21
|
try {
|
|
22
|
-
const fs = __require("fs");
|
|
23
22
|
const authPath = getAuthPath();
|
|
24
|
-
|
|
25
|
-
const auth = JSON.parse(
|
|
23
|
+
log("authPath:", authPath, "exists:", Bun?.file(authPath) !== void 0);
|
|
24
|
+
const auth = JSON.parse(Bun.file(authPath).text());
|
|
25
|
+
log("auth keys:", Object.keys(auth).join(","));
|
|
26
26
|
const entry = auth["minimax-cn-coding-plan"];
|
|
27
|
+
log("entry:", entry ? "found" : "not found");
|
|
27
28
|
if (!entry) return null;
|
|
28
29
|
return typeof entry === "string" ? entry : entry.key;
|
|
29
30
|
} catch (e) {
|
|
30
|
-
log("loadApiKey error:", e.message);
|
|
31
|
+
log("loadApiKey error:", e.message, e.stack);
|
|
31
32
|
return null;
|
|
32
33
|
}
|
|
33
34
|
}
|
|
@@ -58,7 +59,7 @@ async function fetchQuota() {
|
|
|
58
59
|
}
|
|
59
60
|
return parseQuota(data);
|
|
60
61
|
} catch (e) {
|
|
61
|
-
log("fetchQuota error:", e.message);
|
|
62
|
+
log("fetchQuota error:", e.message, e.stack);
|
|
62
63
|
return null;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -72,77 +73,125 @@ function fmtResetTime(ms) {
|
|
|
72
73
|
hour12: false
|
|
73
74
|
}).format(ms);
|
|
74
75
|
}
|
|
75
|
-
function
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
76
|
+
function Badge(props) {
|
|
77
|
+
const theme = () => props.theme;
|
|
78
|
+
const q = () => props.quota();
|
|
79
|
+
const iColor = () => (q()?.intervalPct ?? 0) > 20 ? theme().success : theme().error;
|
|
80
|
+
const wColor = () => (q()?.weeklyPct ?? 0) > 20 ? theme().success : theme().error;
|
|
81
|
+
const root = createComponent("box", {
|
|
82
|
+
get flexDirection() {
|
|
83
|
+
return "row";
|
|
84
|
+
},
|
|
85
|
+
get gap() {
|
|
86
|
+
return 1;
|
|
87
|
+
},
|
|
88
|
+
get alignItems() {
|
|
89
|
+
return "center";
|
|
90
|
+
},
|
|
91
|
+
get children() {
|
|
92
|
+
const cur = q();
|
|
93
|
+
const curTheme = theme();
|
|
94
|
+
if (!cur) {
|
|
95
|
+
return [createComponent("text", {
|
|
96
|
+
get fg() {
|
|
97
|
+
return curTheme.textMuted;
|
|
98
|
+
},
|
|
99
|
+
get children() {
|
|
100
|
+
return "MiniMax loading...";
|
|
101
|
+
}
|
|
102
|
+
})];
|
|
103
|
+
}
|
|
104
|
+
const iColorVal = iColor();
|
|
105
|
+
const wColorVal = wColor();
|
|
106
|
+
return [
|
|
107
|
+
createComponent("text", {
|
|
108
|
+
get fg() {
|
|
109
|
+
return curTheme.textMuted;
|
|
110
|
+
},
|
|
111
|
+
get children() {
|
|
112
|
+
return "MiniMax";
|
|
113
|
+
}
|
|
114
|
+
}),
|
|
115
|
+
createComponent("text", {
|
|
116
|
+
get fg() {
|
|
117
|
+
return curTheme.text;
|
|
118
|
+
},
|
|
119
|
+
get children() {
|
|
120
|
+
return [
|
|
121
|
+
"5h:",
|
|
122
|
+
createComponent("span", {
|
|
123
|
+
get style() {
|
|
124
|
+
return { fg: iColorVal };
|
|
125
|
+
},
|
|
126
|
+
get children() {
|
|
127
|
+
return `${cur.intervalPct}%`;
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
}),
|
|
133
|
+
createComponent("text", {
|
|
134
|
+
get fg() {
|
|
135
|
+
return curTheme.textMuted;
|
|
136
|
+
},
|
|
137
|
+
get children() {
|
|
138
|
+
return fmtResetTime(cur.intervalResetMs);
|
|
139
|
+
}
|
|
140
|
+
}),
|
|
141
|
+
createComponent("text", {
|
|
142
|
+
get fg() {
|
|
143
|
+
return curTheme.textMuted;
|
|
144
|
+
},
|
|
145
|
+
get children() {
|
|
146
|
+
return "\xB7";
|
|
147
|
+
}
|
|
148
|
+
}),
|
|
149
|
+
createComponent("text", {
|
|
150
|
+
get fg() {
|
|
151
|
+
return curTheme.text;
|
|
152
|
+
},
|
|
153
|
+
get children() {
|
|
154
|
+
return [
|
|
155
|
+
"\u5468:",
|
|
156
|
+
createComponent("span", {
|
|
157
|
+
get style() {
|
|
158
|
+
return { fg: wColorVal };
|
|
159
|
+
},
|
|
160
|
+
get children() {
|
|
161
|
+
return `${cur.weeklyPct}%`;
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
];
|
|
165
|
+
}
|
|
166
|
+
}),
|
|
167
|
+
createComponent("text", {
|
|
168
|
+
get fg() {
|
|
169
|
+
return curTheme.textMuted;
|
|
170
|
+
},
|
|
171
|
+
get children() {
|
|
172
|
+
return fmtResetTime(cur.weeklyResetMs);
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return root;
|
|
113
179
|
}
|
|
114
180
|
var tui = async (api) => {
|
|
115
181
|
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
182
|
try {
|
|
122
183
|
createRoot((dispose) => {
|
|
123
184
|
log("createRoot setup");
|
|
124
185
|
const [quota, setQuota] = createSignal(null);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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);
|
|
186
|
+
api.slots.register({
|
|
187
|
+
slots: {
|
|
188
|
+
session_prompt_right() {
|
|
189
|
+
log("renderer called, quota:", quota()?.intervalPct);
|
|
190
|
+
return Badge({ quota, theme: () => api.theme.current });
|
|
191
|
+
}
|
|
144
192
|
}
|
|
145
193
|
});
|
|
194
|
+
log("slot registered");
|
|
146
195
|
const load = async () => {
|
|
147
196
|
log("load() fetching...");
|
|
148
197
|
const q = await fetchQuota();
|
|
@@ -160,7 +209,6 @@ var tui = async (api) => {
|
|
|
160
209
|
log("createRoot ERROR:", e.message, e.stack);
|
|
161
210
|
}
|
|
162
211
|
};
|
|
163
|
-
log("tui defined, exporting");
|
|
164
212
|
var src_default = { id: "opencode-minimax-quota", tui };
|
|
165
213
|
export {
|
|
166
214
|
src_default as default
|