@miloya/oc-minimax-status 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Jochen 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # @miloya/oc-minimax-status
2
+
3
+ > MiniMax Claude Code 用量查询插件 for OpenCode - 一键安装自动配置
4
+
5
+ ## 功能特性
6
+
7
+ - 实时用量查询 - 查询 MiniMax Claude Code 套餐使用状态
8
+ - 安全认证 - 安全的 token 和 groupId 管理,配置文件与 CLI 版共享
9
+ - 美观输出 - 终端友好的进度条展示
10
+ - 一键安装 - 自动安装到全局插件目录,无需手动配置
11
+
12
+ ## 安装
13
+
14
+ ```bash
15
+ npm install @miloya/oc-minimax-status
16
+ ```
17
+
18
+ 安装过程会自动:
19
+ 1. 复制插件到全局插件目录 (~/.config/opencode/plugins)
20
+ 2. 添加插件到 opencode.json 配置
21
+ 3. 显示使用说明
22
+
23
+ ## 配置认证
24
+
25
+ 插件会复用 Claude Code 版 minimax-status 的配置文件 `~/.minimax-config.json`,如果已配置过则无需重复配置。
26
+
27
+ 如需手动配置,创建 `~/.minimax-config.json`:
28
+
29
+ ```json
30
+ {
31
+ "token": "your-api-token",
32
+ "groupId": "your-group-id"
33
+ }
34
+ ```
35
+
36
+ ### 如何获取 token 和 groupId
37
+
38
+ 1. 登录 [https://platform.minimaxi.com/user-center/payment/coding-plan](https://platform.minimaxi.com/user-center/payment/coding-plan)
39
+ 2. 获取 API Key 和 Group ID
40
+
41
+ ## 使用方法
42
+
43
+ 在 OpenCode 中直接说:
44
+
45
+ ### 查询用量
46
+ ```
47
+ @minimax 查看用量
48
+ @minimax status
49
+ minimax_status
50
+ ```
51
+
52
+ ### 管理认证
53
+ ```
54
+ @minimax auth get
55
+ @minimax auth set <token> <groupId>
56
+ ```
57
+
58
+ ## 输出示例
59
+
60
+ ### 用量查询成功
61
+
62
+ ```
63
+ MiniMax Claude Code 用量状态
64
+ ==============================
65
+ Model: MiniMax-M2
66
+ 已用: 1,500 / 10,000
67
+ 进度: [███░░░░░░] 15%
68
+ 剩余: 8,500
69
+ 重置: 2026/02/26 14:30 (2h 30m)
70
+ ==============================
71
+ ```
72
+
73
+ ### 未配置认证
74
+
75
+ ```
76
+ 请先配置认证信息!
77
+
78
+ 配置方式:
79
+ 1. 如果已安装 Claude Code 版 minimax-status,配置文件已自动共享,无需重复配置
80
+ 2. 或手动创建 ~/.minimax-config.json:
81
+ {
82
+ "token": "your-api-token",
83
+ "groupId": "your-group-id"
84
+ }
85
+
86
+ 获取 token 和 groupId:
87
+ 1. 登录 https://platform.minimaxi.com/user-center/payment/coding-plan
88
+ 2. 获取 API Key 和 Group ID
89
+ ```
90
+
91
+ ## 相关项目
92
+
93
+ - [minimax-status](https://github.com/JochenYang/minimax-status) - CLI 版用量查询工具
94
+
95
+ ## License
96
+
97
+ MIT
package/bin/init.js ADDED
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Post-install auto-configuration script
3
+ *
4
+ * Functions:
5
+ * 1. Copy plugin files to global plugins directory
6
+ * 2. Add plugin to opencode.json
7
+ */
8
+
9
+ import fs from "fs";
10
+ import path from "path";
11
+ import { execSync } from "child_process";
12
+
13
+ const PLUGIN_NAME = "oc-minimax-status";
14
+ const PLUGIN_PACKAGE_NAME = "@miloya/oc-minimax-status";
15
+
16
+ function getGlobalPluginsDir() {
17
+ const home = process.env.HOME || process.env.USERPROFILE;
18
+ return path.join(home, ".config", "opencode", "plugins");
19
+ }
20
+
21
+ function getOpencodeConfigPath() {
22
+ const home = process.env.HOME || process.env.USERPROFILE;
23
+ return path.join(home, ".config", "opencode", "opencode.json");
24
+ }
25
+
26
+ function getPackageDir() {
27
+ return process.cwd();
28
+ }
29
+
30
+ function updateOpencodeConfig() {
31
+ const configPath = getOpencodeConfigPath();
32
+ let config = {};
33
+
34
+ if (fs.existsSync(configPath)) {
35
+ try {
36
+ config = JSON.parse(fs.readFileSync(configPath, "utf8"));
37
+ } catch (e) {
38
+ console.warn("Warning: Failed to parse opencode.json");
39
+ }
40
+ }
41
+
42
+ if (!config.plugin) {
43
+ config.plugin = [];
44
+ }
45
+
46
+ // Use @latest to ensure latest version on each startup
47
+ const pluginWithLatest = `${PLUGIN_PACKAGE_NAME}@latest`;
48
+
49
+ // Remove old plugin config if exists
50
+ config.plugin = config.plugin.filter(p => !p.startsWith("@miloya/oc-minimax"));
51
+
52
+ // Add latest version config
53
+ if (!config.plugin.includes(pluginWithLatest)) {
54
+ config.plugin.push(pluginWithLatest);
55
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
56
+ console.log(" [OK] Added to opencode.json plugins (with @latest)");
57
+ } else {
58
+ console.log(" [OK] Already in opencode.json plugins");
59
+ }
60
+ }
61
+
62
+ async function init() {
63
+ console.log("\n-- MiniMax Status Plugin Installing --\n");
64
+
65
+ const globalPluginsDir = getGlobalPluginsDir();
66
+ const packageDir = getPackageDir();
67
+
68
+ if (!fs.existsSync(globalPluginsDir)) {
69
+ fs.mkdirSync(globalPluginsDir, { recursive: true });
70
+ console.log("[OK] Created global plugins directory");
71
+ }
72
+
73
+ console.log("-- Copying plugin files...");
74
+
75
+ // Copy index.js to plugins directory
76
+ const srcIndex = path.join(packageDir, "index.js");
77
+ const destIndex = path.join(globalPluginsDir, `${PLUGIN_NAME}.js`);
78
+ fs.copyFileSync(srcIndex, destIndex);
79
+ console.log(` [OK] Copied ${PLUGIN_NAME}.js`);
80
+
81
+ console.log("-- Installing dependencies...");
82
+ try {
83
+ execSync("npm install axios", {
84
+ cwd: globalPluginsDir,
85
+ stdio: "pipe"
86
+ });
87
+ console.log(" [OK] Installed axios");
88
+ } catch (e) {
89
+ console.log(" [SKIP] axios already installed");
90
+ }
91
+
92
+ console.log("-- Updating OpenCode config...");
93
+ updateOpencodeConfig();
94
+
95
+ console.log("\n-- Installation complete --\n");
96
+
97
+ console.log("Usage:");
98
+ console.log(" 1. Restart OpenCode");
99
+ console.log(" 2. In OpenCode, just say:");
100
+ console.log(" '@minimax status'");
101
+ console.log(" or '@minimax 查看用量'");
102
+ console.log("");
103
+ console.log(" For more info, see README.md\n");
104
+ }
105
+
106
+ init().catch(console.error);
package/index.js ADDED
@@ -0,0 +1,177 @@
1
+ /**
2
+ * MiniMax Status OpenCode Plugin
3
+ *
4
+ * Provides custom tools:
5
+ * - minimax_status: Query usage status
6
+ * - minimax_auth: Set/view authentication info
7
+ */
8
+
9
+ import { tool } from "@opencode-ai/plugin";
10
+ import axios from "axios";
11
+ import fs from "fs";
12
+ import path from "path";
13
+
14
+ const CONFIG_PATH = path.join(
15
+ process.env.HOME || process.env.USERPROFILE,
16
+ ".minimax-config.json"
17
+ );
18
+
19
+ function getCredentials() {
20
+ try {
21
+ if (fs.existsSync(CONFIG_PATH)) {
22
+ return JSON.parse(fs.readFileSync(CONFIG_PATH, "utf8"));
23
+ }
24
+ } catch (error) {
25
+ console.error("Failed to read config:", error.message);
26
+ }
27
+ return null;
28
+ }
29
+
30
+ function saveCredentials(token, groupId) {
31
+ const config = { token, groupId };
32
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2));
33
+ }
34
+
35
+ async function fetchUsageStatus(token, groupId) {
36
+ const response = await axios.get(
37
+ "https://www.minimaxi.com/v1/api/openplatform/coding_plan/remains",
38
+ {
39
+ params: { GroupId: groupId },
40
+ headers: {
41
+ Authorization: `Bearer ${token}`,
42
+ Accept: "application/json",
43
+ },
44
+ timeout: 10000,
45
+ }
46
+ );
47
+ return response.data;
48
+ }
49
+
50
+ function parseUsageData(apiData) {
51
+ if (!apiData.model_remains || apiData.model_remains.length === 0) {
52
+ throw new Error("No usage data available");
53
+ }
54
+
55
+ const m = apiData.model_remains[0];
56
+ const remaining = m.current_interval_usage_count;
57
+ const total = m.current_interval_total_count;
58
+ const used = total - remaining;
59
+ const percentage = Math.round((used / total) * 100);
60
+
61
+ const remainingMs = m.remains_time;
62
+ const hours = Math.floor(remainingMs / (1000 * 60 * 60));
63
+ const minutes = Math.floor((remainingMs % (1000 * 60 * 60)) / (1000 * 60));
64
+
65
+ const resetTime = new Date(m.end_time).toLocaleString("zh-CN", {
66
+ timeZone: "Asia/Shanghai",
67
+ year: "numeric",
68
+ month: "2-digit",
69
+ day: "2-digit",
70
+ hour: "2-digit",
71
+ minute: "2-digit",
72
+ });
73
+
74
+ return {
75
+ modelName: m.model_name,
76
+ used,
77
+ total,
78
+ remaining,
79
+ percentage,
80
+ resetTime,
81
+ hours,
82
+ minutes,
83
+ };
84
+ }
85
+
86
+ function formatOutput(data) {
87
+ const { modelName, used, total, remaining, percentage, resetTime, hours, minutes } = data;
88
+
89
+ const bar = "#".repeat(Math.floor(percentage / 10)) + "-".repeat(10 - Math.floor(percentage / 10));
90
+ const timeText = hours > 0 ? `${hours}h ${minutes}m` : `${minutes}min`;
91
+
92
+ return `MiniMax Claude Code 用量状态
93
+ ==============================
94
+ Model: ${modelName}
95
+ 已用: ${used.toLocaleString()} / ${total.toLocaleString()}
96
+ 进度: [${bar}] ${percentage}%
97
+ 剩余: ${remaining.toLocaleString()}
98
+ 重置: ${resetTime} (${timeText})
99
+ ==============================`;
100
+ }
101
+
102
+ export const MiniMaxStatusPlugin = async (ctx) => {
103
+ return {
104
+ tool: {
105
+ minimax_status: tool({
106
+ description: "查询 MiniMax Claude Code 套餐使用状态,包括已用次数、剩余次数、进度条和重置时间",
107
+ args: {
108
+ refresh: tool.schema.boolean().optional().describe("强制刷新缓存"),
109
+ },
110
+ async execute(args, context) {
111
+ try {
112
+ const credentials = getCredentials();
113
+
114
+ if (!credentials?.token || !credentials?.groupId) {
115
+ return `请先配置认证信息!
116
+
117
+ 配置方式:
118
+ 1. 如果已安装 Claude Code 版 minimax-status,配置文件已自动共享,无需重复配置
119
+ 2. 或手动创建 ~/.minimax-config.json:
120
+ {
121
+ "token": "your-api-token",
122
+ "groupId": "your-group-id"
123
+ }
124
+
125
+ 获取 token 和 groupId:
126
+ 1. 登录 https://platform.minimaxi.com/user-center/payment/coding-plan
127
+ 2. 获取 API Key 和 Group ID`;
128
+ }
129
+
130
+ const apiData = await fetchUsageStatus(credentials.token, credentials.groupId);
131
+ const usageData = parseUsageData(apiData);
132
+
133
+ return formatOutput(usageData);
134
+ } catch (error) {
135
+ if (error.response?.status === 401) {
136
+ return "认证失败,请检查 token 和 groupId 是否正确";
137
+ }
138
+ if (error.code === "ECONNABORTED") {
139
+ return "请求超时,请检查网络连接";
140
+ }
141
+ return `获取用量失败: ${error.message}`;
142
+ }
143
+ },
144
+ }),
145
+
146
+ minimax_auth: tool({
147
+ description: "设置或查看 MiniMax 认证信息",
148
+ args: {
149
+ action: tool.schema.enum(["set", "get"]).default("get").describe("操作: set 设置, get 查看"),
150
+ token: tool.schema.string().optional().describe("API Token"),
151
+ groupId: tool.schema.string().optional().describe("Group ID"),
152
+ },
153
+ async execute(args, context) {
154
+ if (args.action === "get") {
155
+ const creds = getCredentials();
156
+ if (!creds || !creds.token || !creds.groupId) {
157
+ return "未配置认证信息。请使用 action=set 设置 token 和 groupId";
158
+ }
159
+ return `当前认证信息:
160
+ - Token: ${creds.token ? "****" + creds.token.slice(-4) : "未设置"}
161
+ - GroupID: ${creds.groupId || "未设置"}`;
162
+ }
163
+
164
+ if (args.action === "set") {
165
+ if (!args.token || !args.groupId) {
166
+ return "设置认证需要提供 token 和 groupId 两个参数";
167
+ }
168
+ saveCredentials(args.token, args.groupId);
169
+ return "认证信息已保存到 ~/.minimax-config.json";
170
+ }
171
+ },
172
+ }),
173
+ },
174
+ };
175
+ };
176
+
177
+ export default MiniMaxStatusPlugin;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@miloya/oc-minimax-status",
3
+ "version": "0.0.2",
4
+ "description": "MiniMax Claude Code 用量查询插件 for OpenCode - 一键安装自动配置",
5
+ "main": "index.js",
6
+ "type": "module",
7
+ "keywords": ["opencode", "plugin", "minimax", "claude-code", "usage"],
8
+ "author": "Jochen",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/JochenYang/minimax-status"
13
+ },
14
+ "files": [
15
+ "index.js",
16
+ "bin/",
17
+ "README.md",
18
+ "LICENSE"
19
+ ],
20
+ "dependencies": {
21
+ "axios": "^1.6.0"
22
+ },
23
+ "peerDependencies": {
24
+ "@opencode-ai/plugin": "*"
25
+ },
26
+ "engines": {
27
+ "opencode": ">=1.0.0"
28
+ },
29
+ "scripts": {
30
+ "postinstall": "node bin/init.js"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "bin": {
36
+ "minimax-status-init": "./bin/init.js"
37
+ }
38
+ }