opencode-minimax-quota 0.1.2 → 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 +114 -74
- 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 {
|
|
@@ -43,19 +43,13 @@ function parseQuota(data) {
|
|
|
43
43
|
}
|
|
44
44
|
async function fetchQuota() {
|
|
45
45
|
const key = loadApiKey();
|
|
46
|
-
if (!key)
|
|
47
|
-
log("fetchQuota: no API key");
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
46
|
+
if (!key) return null;
|
|
50
47
|
try {
|
|
51
48
|
const res = await fetch(QUOTA_API, {
|
|
52
49
|
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" }
|
|
53
50
|
});
|
|
54
51
|
const data = await res.json();
|
|
55
|
-
if (data.base_resp?.status_code !== 0)
|
|
56
|
-
log("fetchQuota: API error", data.base_resp);
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
52
|
+
if (data.base_resp?.status_code !== 0) return null;
|
|
59
53
|
return parseQuota(data);
|
|
60
54
|
} catch (e) {
|
|
61
55
|
log("fetchQuota error:", e.message);
|
|
@@ -72,81 +66,128 @@ function fmtResetTime(ms) {
|
|
|
72
66
|
hour12: false
|
|
73
67
|
}).format(ms);
|
|
74
68
|
}
|
|
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
|
-
|
|
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;
|
|
113
172
|
}
|
|
114
173
|
var tui = async (api) => {
|
|
115
174
|
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
175
|
try {
|
|
122
176
|
createRoot((dispose) => {
|
|
123
177
|
log("createRoot setup");
|
|
124
178
|
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);
|
|
179
|
+
api.slots.register({
|
|
180
|
+
slots: {
|
|
181
|
+
session_prompt_right() {
|
|
182
|
+
log("renderer called");
|
|
183
|
+
return Badge({ quota, theme: () => api.theme.current });
|
|
184
|
+
}
|
|
144
185
|
}
|
|
145
186
|
});
|
|
187
|
+
log("slot registered");
|
|
146
188
|
const load = async () => {
|
|
147
|
-
log("load() fetching...");
|
|
148
189
|
const q = await fetchQuota();
|
|
149
|
-
log("load
|
|
190
|
+
log("load got quota:", q?.intervalPct);
|
|
150
191
|
setQuota(q);
|
|
151
192
|
};
|
|
152
193
|
api.lifecycle.onDispose(dispose);
|
|
@@ -160,7 +201,6 @@ var tui = async (api) => {
|
|
|
160
201
|
log("createRoot ERROR:", e.message, e.stack);
|
|
161
202
|
}
|
|
162
203
|
};
|
|
163
|
-
log("tui defined, exporting");
|
|
164
204
|
var src_default = { id: "opencode-minimax-quota", tui };
|
|
165
205
|
export {
|
|
166
206
|
src_default as default
|