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.
Files changed (2) hide show
  1. package/dist/tui.js +144 -68
  2. 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 { effect, createElement, setProp, insert } from "@opentui/solid";
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 { existsSync, readFileSync } = __require("fs");
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 makeBox(props, children) {
64
- const el = createElement("box");
65
- for (const [k, v] of Object.entries(props || {})) setProp(el, k, v);
66
- for (const c of children || []) insert(el, c);
67
- return el;
68
- }
69
- function makeText(props, ...children) {
70
- const el = createElement("text");
71
- for (const [k, v] of Object.entries(props || {})) setProp(el, k, v);
72
- for (const c of children || []) insert(el, c);
73
- return el;
74
- }
75
- function makeSpan(props, ...children) {
76
- const el = createElement("span");
77
- for (const [k, v] of Object.entries(props || {})) setProp(el, k, v);
78
- for (const c of children || []) insert(el, c);
79
- return el;
80
- }
81
- function renderQuotaBadge(theme, q) {
82
- if (!q) return makeText({ fg: theme.textMuted }, "MiniMax \u52A0\u8F7D...");
83
- const iColor = q.intervalPct > 20 ? theme.success : theme.error;
84
- const wColor = q.weeklyPct > 20 ? theme.success : theme.error;
85
- return makeBox({ flexDirection: "row", gap: 1, alignItems: "center" }, [
86
- makeText({ fg: theme.textMuted }, "MiniMax"),
87
- makeText(
88
- { fg: theme.text },
89
- "5h:",
90
- makeSpan({ style: { fg: iColor } }, `${q.intervalPct}%`)
91
- ),
92
- makeText({ fg: theme.textMuted }, fmtResetTime(q.intervalResetMs)),
93
- makeText({ fg: theme.textMuted }, "\xB7"),
94
- makeText(
95
- { fg: theme.text },
96
- "\u5468:",
97
- makeSpan({ style: { fg: wColor } }, `${q.weeklyPct}%`)
98
- ),
99
- makeText({ fg: theme.textMuted }, fmtResetTime(q.weeklyResetMs))
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
- createRoot((dispose) => {
104
- const [quota, setQuota] = createSignal(null);
105
- effect(() => {
106
- const q = quota();
107
- const theme = api.theme.current;
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
- return el;
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
- const load = async () => {
118
- const q = await fetchQuota();
119
- setQuota(q);
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 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-minimax-quota",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "OpenCode TUI plugin to display MiniMax token plan quota (5h + weekly) in the prompt bar",
5
5
  "type": "module",
6
6
  "main": "./dist/tui.js",