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