opencode-minimax-quota 0.1.7 → 0.1.8
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 +42 -113
- 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 { createElement, setProp, insert } from "@opentui/solid";
|
|
5
5
|
var LOG = "/tmp/opencode-minimax-quota.log";
|
|
6
6
|
function log(...args) {
|
|
7
7
|
try {
|
|
@@ -71,112 +71,36 @@ function fmtResetTime(ms) {
|
|
|
71
71
|
hour12: false
|
|
72
72
|
}).format(ms);
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
get children() {
|
|
105
|
-
log("Badge children render");
|
|
106
|
-
return [
|
|
107
|
-
createComponent("text", {
|
|
108
|
-
get fg() {
|
|
109
|
-
return curTheme?.textMuted || "gray";
|
|
110
|
-
},
|
|
111
|
-
get children() {
|
|
112
|
-
return "MiniMax";
|
|
113
|
-
}
|
|
114
|
-
}),
|
|
115
|
-
createComponent("text", {
|
|
116
|
-
get fg() {
|
|
117
|
-
return curTheme?.text || "white";
|
|
118
|
-
},
|
|
119
|
-
get children() {
|
|
120
|
-
return [
|
|
121
|
-
"5h:",
|
|
122
|
-
createComponent("span", {
|
|
123
|
-
get style() {
|
|
124
|
-
return { fg: iColor };
|
|
125
|
-
},
|
|
126
|
-
get children() {
|
|
127
|
-
return `${cur.intervalPct}%`;
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
];
|
|
131
|
-
}
|
|
132
|
-
}),
|
|
133
|
-
createComponent("text", {
|
|
134
|
-
get fg() {
|
|
135
|
-
return curTheme?.textMuted || "gray";
|
|
136
|
-
},
|
|
137
|
-
get children() {
|
|
138
|
-
return fmtResetTime(cur.intervalResetMs);
|
|
139
|
-
}
|
|
140
|
-
}),
|
|
141
|
-
createComponent("text", {
|
|
142
|
-
get fg() {
|
|
143
|
-
return curTheme?.textMuted || "gray";
|
|
144
|
-
},
|
|
145
|
-
get children() {
|
|
146
|
-
return "\xB7";
|
|
147
|
-
}
|
|
148
|
-
}),
|
|
149
|
-
createComponent("text", {
|
|
150
|
-
get fg() {
|
|
151
|
-
return curTheme?.text || "white";
|
|
152
|
-
},
|
|
153
|
-
get children() {
|
|
154
|
-
return [
|
|
155
|
-
"\u5468:",
|
|
156
|
-
createComponent("span", {
|
|
157
|
-
get style() {
|
|
158
|
-
return { fg: wColor };
|
|
159
|
-
},
|
|
160
|
-
get children() {
|
|
161
|
-
return `${cur.weeklyPct}%`;
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
];
|
|
165
|
-
}
|
|
166
|
-
}),
|
|
167
|
-
createComponent("text", {
|
|
168
|
-
get fg() {
|
|
169
|
-
return curTheme?.textMuted || "gray";
|
|
170
|
-
},
|
|
171
|
-
get children() {
|
|
172
|
-
return fmtResetTime(cur.weeklyResetMs);
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
log("Badge returning root component");
|
|
179
|
-
return root;
|
|
74
|
+
function makeBox(props, children) {
|
|
75
|
+
const el = createElement("box");
|
|
76
|
+
for (const [k, v] of Object.entries(props || {})) setProp(el, k, v);
|
|
77
|
+
for (const c of children || []) insert(el, c);
|
|
78
|
+
return el;
|
|
79
|
+
}
|
|
80
|
+
function makeText(props, ...children) {
|
|
81
|
+
const el = createElement("text");
|
|
82
|
+
for (const [k, v] of Object.entries(props || {})) setProp(el, k, v);
|
|
83
|
+
for (const c of children || []) insert(el, c);
|
|
84
|
+
return el;
|
|
85
|
+
}
|
|
86
|
+
function makeSpan(props, ...children) {
|
|
87
|
+
const el = createElement("span");
|
|
88
|
+
for (const [k, v] of Object.entries(props || {})) setProp(el, k, v);
|
|
89
|
+
for (const c of children || []) insert(el, c);
|
|
90
|
+
return el;
|
|
91
|
+
}
|
|
92
|
+
function renderQuotaBadge(theme, q) {
|
|
93
|
+
if (!q) return makeText({ fg: theme.textMuted }, "MiniMax loading...");
|
|
94
|
+
const iColor = q.intervalPct > 20 ? theme.success : theme.error;
|
|
95
|
+
const wColor = q.weeklyPct > 20 ? theme.success : theme.error;
|
|
96
|
+
return makeBox({ flexDirection: "row", gap: 1, alignItems: "center" }, [
|
|
97
|
+
makeText({ fg: theme.textMuted }, "MiniMax"),
|
|
98
|
+
makeText({ fg: theme.text }, ["5h:", makeSpan({ style: { fg: iColor } }, `${q.intervalPct}%`)]),
|
|
99
|
+
makeText({ fg: theme.textMuted }, fmtResetTime(q.intervalResetMs)),
|
|
100
|
+
makeText({ fg: theme.textMuted }, "\xB7"),
|
|
101
|
+
makeText({ fg: theme.text }, ["\u5468:", makeSpan({ style: { fg: wColor } }, `${q.weeklyPct}%`)]),
|
|
102
|
+
makeText({ fg: theme.textMuted }, fmtResetTime(q.weeklyResetMs))
|
|
103
|
+
]);
|
|
180
104
|
}
|
|
181
105
|
var tui = async (api) => {
|
|
182
106
|
log("tui() called");
|
|
@@ -184,13 +108,16 @@ var tui = async (api) => {
|
|
|
184
108
|
createRoot((dispose) => {
|
|
185
109
|
log("createRoot setup");
|
|
186
110
|
const [quota, setQuota] = createSignal(null);
|
|
187
|
-
|
|
111
|
+
let currentQuota = null;
|
|
112
|
+
let currentTheme = null;
|
|
113
|
+
const unregister = api.slots.register({
|
|
188
114
|
slots: {
|
|
189
|
-
session_prompt_right() {
|
|
190
|
-
log("renderer called, quota:",
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
115
|
+
session_prompt_right(context) {
|
|
116
|
+
log("renderer called, quota:", currentQuota?.intervalPct);
|
|
117
|
+
const theme = currentTheme || context.theme.current;
|
|
118
|
+
const el = renderQuotaBadge(theme, currentQuota);
|
|
119
|
+
log("renderer returned element:", typeof el, el?.constructor?.name);
|
|
120
|
+
return el;
|
|
194
121
|
}
|
|
195
122
|
}
|
|
196
123
|
});
|
|
@@ -199,6 +126,8 @@ var tui = async (api) => {
|
|
|
199
126
|
log("load() fetching...");
|
|
200
127
|
const q = await fetchQuota();
|
|
201
128
|
log("load() got quota:", q?.intervalPct);
|
|
129
|
+
currentQuota = q;
|
|
130
|
+
currentTheme = api.theme.current;
|
|
202
131
|
setQuota(q);
|
|
203
132
|
};
|
|
204
133
|
api.lifecycle.onDispose(dispose);
|