osai-agent 4.2.24 → 4.2.25
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/package.json +1 -1
- package/src/commands/admin.js +13 -2
- package/src/index.js +6 -1
package/package.json
CHANGED
package/src/commands/admin.js
CHANGED
|
@@ -12,7 +12,7 @@ const promptSecret = () => new Promise((resolve) => {
|
|
|
12
12
|
});
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
-
const adminFetch = async (serverArg, path, method = 'GET', body = null) => {
|
|
15
|
+
const adminFetch = async (serverArg, path, method = 'GET', body = null, pathPrefix = '/auth') => {
|
|
16
16
|
const config = new Conf({ projectName: 'osai-agent' });
|
|
17
17
|
const serverUrl = serverArg || config.get('server') || DEFAULT_SERVER_URL;
|
|
18
18
|
const httpUrl = toHttpUrl(serverUrl);
|
|
@@ -32,7 +32,7 @@ const adminFetch = async (serverArg, path, method = 'GET', body = null) => {
|
|
|
32
32
|
options.body = JSON.stringify(body);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const response = await fetch(`${httpUrl}
|
|
35
|
+
const response = await fetch(`${httpUrl}${pathPrefix}${path}`, options);
|
|
36
36
|
const data = await response.json().catch(() => null);
|
|
37
37
|
|
|
38
38
|
if (!response.ok) {
|
|
@@ -80,3 +80,14 @@ export const enableUser = async ({ server, email }) => {
|
|
|
80
80
|
const data = await adminFetch(server, '/admin/enable-user', 'POST', { email });
|
|
81
81
|
const spinner = ora().succeed(chalk.green(`User enabled: ${data.email}`));
|
|
82
82
|
};
|
|
83
|
+
|
|
84
|
+
export const generateProKeys = async ({ server, count, type }) => {
|
|
85
|
+
const spinner = ora('Generating Pro keys...').start();
|
|
86
|
+
const data = await adminFetch(server, '/generate', 'POST', { type, count }, '/pro');
|
|
87
|
+
spinner.stop();
|
|
88
|
+
console.log(chalk.green(`\n ${data.count} Pro keys generated (${data.type}, ${data.duration_days} days):\n`));
|
|
89
|
+
for (const key of data.keys) {
|
|
90
|
+
console.log(` ${chalk.hex('#ff9e64')(key)}`);
|
|
91
|
+
}
|
|
92
|
+
console.log();
|
|
93
|
+
};
|
package/src/index.js
CHANGED
|
@@ -26,7 +26,7 @@ import { handleMcpCommand } from './commands/mcp.js';
|
|
|
26
26
|
import { stopSubagent } from './commands/stop-subagent.js';
|
|
27
27
|
import { claimProKey } from './commands/pro.js';
|
|
28
28
|
import { deleteAccount } from './commands/account.js';
|
|
29
|
-
import { listUsers, disableUser, enableUser } from './commands/admin.js';
|
|
29
|
+
import { listUsers, disableUser, enableUser, generateProKeys } from './commands/admin.js';
|
|
30
30
|
import minimist from 'minimist';
|
|
31
31
|
import updateNotifier from 'update-notifier';
|
|
32
32
|
import { createRequire } from 'module';
|
|
@@ -153,6 +153,10 @@ switch (cmd) {
|
|
|
153
153
|
} else if (args._[1] === 'enable') {
|
|
154
154
|
if (!args._[2]) { console.error('Usage: osai-agent admin enable <email>'); process.exit(1); }
|
|
155
155
|
await enableUser({ server: args.server, email: args._[2] });
|
|
156
|
+
} else if (args._[1] === 'pro-gen') {
|
|
157
|
+
const count = Math.min(Math.max(1, parseInt(args._[2]) || 1), 50);
|
|
158
|
+
const type = args.type || 'monthly';
|
|
159
|
+
await generateProKeys({ server: args.server, count, type });
|
|
156
160
|
} else {
|
|
157
161
|
console.log();
|
|
158
162
|
console.log('Usage: osai-agent admin <subcommand> [args]');
|
|
@@ -161,6 +165,7 @@ switch (cmd) {
|
|
|
161
165
|
console.log(' users List all users');
|
|
162
166
|
console.log(' disable <email> Disable a user account');
|
|
163
167
|
console.log(' enable <email> Re-enable a user account');
|
|
168
|
+
console.log(' pro-gen <count> Generate Pro keys (--type monthly|yearly)');
|
|
164
169
|
console.log();
|
|
165
170
|
process.exit(1);
|
|
166
171
|
}
|