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.
Files changed (2) hide show
  1. package/dist/tui.js +114 -74
  2. 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 { effect, createElement, setProp, insert } from "@opentui/solid";
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 makeBox(props, children) {
76
- const el = createElement("box");
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 makeText(props, ...children) {
82
- const el = createElement("text");
83
- for (const [k, v] of Object.entries(props || {})) setProp(el, k, v);
84
- for (const c of children || []) insert(el, c);
85
- return el;
86
- }
87
- function makeSpan(props, ...children) {
88
- const el = createElement("span");
89
- for (const [k, v] of Object.entries(props || {})) setProp(el, k, v);
90
- for (const c of children || []) insert(el, c);
91
- return el;
92
- }
93
- function renderQuotaBadge(theme, q) {
94
- if (!q) return makeText({ fg: theme.textMuted }, "MiniMax loading...");
95
- const iColor = q.intervalPct > 20 ? theme.success : theme.error;
96
- const wColor = q.weeklyPct > 20 ? theme.success : theme.error;
97
- return makeBox({ flexDirection: "row", gap: 1, alignItems: "center" }, [
98
- makeText({ fg: theme.textMuted }, "MiniMax"),
99
- makeText(
100
- { fg: theme.text },
101
- "5h:",
102
- makeSpan({ style: { fg: iColor } }, `${q.intervalPct}%`)
103
- ),
104
- makeText({ fg: theme.textMuted }, fmtResetTime(q.intervalResetMs)),
105
- makeText({ fg: theme.textMuted }, "\xB7"),
106
- makeText(
107
- { fg: theme.text },
108
- "\u5468:",
109
- makeSpan({ style: { fg: wColor } }, `${q.weeklyPct}%`)
110
- ),
111
- makeText({ fg: theme.textMuted }, fmtResetTime(q.weeklyResetMs))
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
- log("createSignal done");
126
- effect(() => {
127
- log("effect running, quota=", quota()?.intervalPct);
128
- const q = quota();
129
- const theme = api.theme.current;
130
- const el = renderQuotaBadge(theme, q);
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() got quota:", q?.intervalPct);
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-minimax-quota",
3
- "version": "0.1.2",
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",