opencode-minimax-quota 0.1.5 → 0.1.7

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 +36 -33
  2. package/package.json +1 -1
package/dist/tui.js CHANGED
@@ -17,18 +17,16 @@ var REFRESH_INTERVAL = 5 * 60 * 1e3;
17
17
  function getAuthPath() {
18
18
  return `${process.env.HOME || "/root"}/.local/share/opencode/auth.json`;
19
19
  }
20
- function loadApiKey() {
20
+ async function loadApiKey() {
21
21
  try {
22
22
  const authPath = getAuthPath();
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(","));
23
+ const text = await Bun.file(authPath).text();
24
+ const auth = JSON.parse(text);
26
25
  const entry = auth["minimax-cn-coding-plan"];
27
- log("entry:", entry ? "found" : "not found");
28
26
  if (!entry) return null;
29
27
  return typeof entry === "string" ? entry : entry.key;
30
28
  } catch (e) {
31
- log("loadApiKey error:", e.message, e.stack);
29
+ log("loadApiKey error:", e.message);
32
30
  return null;
33
31
  }
34
32
  }
@@ -43,7 +41,7 @@ function parseQuota(data) {
43
41
  };
44
42
  }
45
43
  async function fetchQuota() {
46
- const key = loadApiKey();
44
+ const key = await loadApiKey();
47
45
  if (!key) {
48
46
  log("fetchQuota: no API key");
49
47
  return null;
@@ -59,7 +57,7 @@ async function fetchQuota() {
59
57
  }
60
58
  return parseQuota(data);
61
59
  } catch (e) {
62
- log("fetchQuota error:", e.message, e.stack);
60
+ log("fetchQuota error:", e.message);
63
61
  return null;
64
62
  }
65
63
  }
@@ -76,8 +74,23 @@ function fmtResetTime(ms) {
76
74
  function Badge(props) {
77
75
  const theme = () => props.theme;
78
76
  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;
77
+ const cur = q();
78
+ const curTheme = theme();
79
+ log("Badge render, quota:", cur?.intervalPct, "weekly:", cur?.weeklyPct);
80
+ if (!cur) {
81
+ const el = createComponent("text", {
82
+ get fg() {
83
+ return curTheme?.textMuted || "gray";
84
+ },
85
+ get children() {
86
+ return "MiniMax loading...";
87
+ }
88
+ });
89
+ log("Badge returning loading element");
90
+ return el;
91
+ }
92
+ const iColor = (cur.intervalPct ?? 0) > 20 ? curTheme?.success || "green" : curTheme?.error || "red";
93
+ const wColor = (cur.weeklyPct ?? 0) > 20 ? curTheme?.success || "green" : curTheme?.error || "red";
81
94
  const root = createComponent("box", {
82
95
  get flexDirection() {
83
96
  return "row";
@@ -89,24 +102,11 @@ function Badge(props) {
89
102
  return "center";
90
103
  },
91
104
  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();
105
+ log("Badge children render");
106
106
  return [
107
107
  createComponent("text", {
108
108
  get fg() {
109
- return curTheme.textMuted;
109
+ return curTheme?.textMuted || "gray";
110
110
  },
111
111
  get children() {
112
112
  return "MiniMax";
@@ -114,14 +114,14 @@ function Badge(props) {
114
114
  }),
115
115
  createComponent("text", {
116
116
  get fg() {
117
- return curTheme.text;
117
+ return curTheme?.text || "white";
118
118
  },
119
119
  get children() {
120
120
  return [
121
121
  "5h:",
122
122
  createComponent("span", {
123
123
  get style() {
124
- return { fg: iColorVal };
124
+ return { fg: iColor };
125
125
  },
126
126
  get children() {
127
127
  return `${cur.intervalPct}%`;
@@ -132,7 +132,7 @@ function Badge(props) {
132
132
  }),
133
133
  createComponent("text", {
134
134
  get fg() {
135
- return curTheme.textMuted;
135
+ return curTheme?.textMuted || "gray";
136
136
  },
137
137
  get children() {
138
138
  return fmtResetTime(cur.intervalResetMs);
@@ -140,7 +140,7 @@ function Badge(props) {
140
140
  }),
141
141
  createComponent("text", {
142
142
  get fg() {
143
- return curTheme.textMuted;
143
+ return curTheme?.textMuted || "gray";
144
144
  },
145
145
  get children() {
146
146
  return "\xB7";
@@ -148,14 +148,14 @@ function Badge(props) {
148
148
  }),
149
149
  createComponent("text", {
150
150
  get fg() {
151
- return curTheme.text;
151
+ return curTheme?.text || "white";
152
152
  },
153
153
  get children() {
154
154
  return [
155
155
  "\u5468:",
156
156
  createComponent("span", {
157
157
  get style() {
158
- return { fg: wColorVal };
158
+ return { fg: wColor };
159
159
  },
160
160
  get children() {
161
161
  return `${cur.weeklyPct}%`;
@@ -166,7 +166,7 @@ function Badge(props) {
166
166
  }),
167
167
  createComponent("text", {
168
168
  get fg() {
169
- return curTheme.textMuted;
169
+ return curTheme?.textMuted || "gray";
170
170
  },
171
171
  get children() {
172
172
  return fmtResetTime(cur.weeklyResetMs);
@@ -175,6 +175,7 @@ function Badge(props) {
175
175
  ];
176
176
  }
177
177
  });
178
+ log("Badge returning root component");
178
179
  return root;
179
180
  }
180
181
  var tui = async (api) => {
@@ -187,7 +188,9 @@ var tui = async (api) => {
187
188
  slots: {
188
189
  session_prompt_right() {
189
190
  log("renderer called, quota:", quota()?.intervalPct);
190
- return Badge({ quota, theme: () => api.theme.current });
191
+ const result = Badge({ quota, theme: () => api.theme.current });
192
+ log("renderer returned:", typeof result, result?.constructor?.name);
193
+ return result;
191
194
  }
192
195
  }
193
196
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-minimax-quota",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
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",