labs-claude 0.3.3 → 0.3.4
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/bin/labs.js +2 -1
- package/package.json +1 -1
- package/src/admin-cli.js +247 -0
package/bin/labs.js
CHANGED
|
@@ -32,8 +32,9 @@ const HELP = `labs ${version} — Run Claude Code on Antigravity (agy), Google G
|
|
|
32
32
|
labs bedrock save your Amazon Bedrock key, then: labs --model glm (GLM 5.3)
|
|
33
33
|
labs --model qwen Claude Code on our GPU box (qwen | qwen-uncensored), through the labs gateway
|
|
34
34
|
labs key save your labs key (lk_...) with interactive model + effort setup
|
|
35
|
+
labs admin [subcommand] terminal-native Admin Control Room (stats | create | pause | resume | revoke | usage)
|
|
35
36
|
labs update update labs-claude to the latest npm version in one command
|
|
36
|
-
labs console open the
|
|
37
|
+
labs console open the web admin console (optional; labs admin does everything in terminal)
|
|
37
38
|
labs paint "a red kite" paint on the box (--size wide|portrait|square… --count 1-4 --seed N); prints the file paths
|
|
38
39
|
labs image-mcp picture tool for any Claude Code chat: claude mcp add -s user labs-image -- labs image-mcp
|
|
39
40
|
labs web-mcp web search + page reading on this computer (added to every box session by itself)
|
package/package.json
CHANGED
package/src/admin-cli.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
// Cracked-engineer terminal-native Admin Control Room (`labs admin`).
|
|
2
|
+
// Zero browser needed: mint friend keys, pause/resume/revoke, and inspect live per-friend token bars in your terminal.
|
|
3
|
+
const axios = require('axios');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const { spawn } = require('child_process');
|
|
7
|
+
const { LABS_DIR } = require('./config');
|
|
8
|
+
const { storedConfig } = require('./gateway-client');
|
|
9
|
+
const { c, randomQuip, playMascotIntro, withSpinner, printCard } = require('./ui');
|
|
10
|
+
const { version } = require('../package.json');
|
|
11
|
+
|
|
12
|
+
const DEFAULT_GATEWAY_URL = 'https://labs.instant.uz';
|
|
13
|
+
const ADMIN_TOKEN_FILE = path.join(LABS_DIR, 'gateway-admin');
|
|
14
|
+
|
|
15
|
+
function compactTokens(n) {
|
|
16
|
+
const v = Number(n || 0);
|
|
17
|
+
if (v >= 1e9) return `${(v / 1e9).toFixed(2)}B`;
|
|
18
|
+
if (v >= 1e6) return `${(v / 1e6).toFixed(2)}M`;
|
|
19
|
+
if (v >= 1e3) return `${(v / 1e3).toFixed(1)}K`;
|
|
20
|
+
return String(v);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function relTime(iso) {
|
|
24
|
+
if (!iso) return 'never';
|
|
25
|
+
const sec = Math.max(0, Math.round((Date.now() - new Date(iso).getTime()) / 1000));
|
|
26
|
+
if (sec < 60) return `${sec}s ago`;
|
|
27
|
+
if (sec < 3600) return `${Math.floor(sec / 60)}m ago`;
|
|
28
|
+
if (sec < 86400) return `${Math.floor(sec / 3600)}h ago`;
|
|
29
|
+
return `${Math.floor(sec / 86400)}d ago`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function barChart(value, max, width = 14) {
|
|
33
|
+
const filled = max > 0 ? Math.max(value > 0 ? 1 : 0, Math.round((value / max) * width)) : 0;
|
|
34
|
+
return c.mint('█'.repeat(filled)) + c.dim('░'.repeat(Math.max(0, width - filled)));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function copyClipboard(text) {
|
|
38
|
+
const cmd = { win32: ['clip', []], darwin: ['pbcopy', []] }[process.platform];
|
|
39
|
+
if (!cmd) return false;
|
|
40
|
+
try {
|
|
41
|
+
const child = spawn(cmd[0], cmd[1]);
|
|
42
|
+
child.stdin.end(text);
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function readAdminToken() {
|
|
50
|
+
if (!fs.existsSync(ADMIN_TOKEN_FILE)) {
|
|
51
|
+
console.error(`\n ${c.rose('✖')} No admin token found at ${c.dim(ADMIN_TOKEN_FILE)}.`);
|
|
52
|
+
console.error(` Create one with: ${c.cyan('labs admin-token ubuntu@130.61.104.240')}\n`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
return fs.readFileSync(ADMIN_TOKEN_FILE, 'utf8').trim();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function createAdminApi(url, token) {
|
|
59
|
+
const headers = { authorization: `Bearer ${token}` };
|
|
60
|
+
return {
|
|
61
|
+
get: p => axios.get(`${url}/admin/api${p}`, { headers, timeout: 10000 }).then(r => r.data),
|
|
62
|
+
post: (p, body) => axios.post(`${url}/admin/api${p}`, body, { headers, timeout: 10000 }).then(r => r.data),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function resolveKeyTarget(keys, target) {
|
|
67
|
+
const raw = String(target || '').trim();
|
|
68
|
+
if (!raw) return null;
|
|
69
|
+
return keys.find(k => String(k.id) === raw || k.name.toLowerCase() === raw.toLowerCase()) || null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function renderDashboard(keys, usageRows, box) {
|
|
73
|
+
const todayStr = new Date(Date.now() + 5 * 3600e3).toISOString().slice(0, 10);
|
|
74
|
+
const todayRows = usageRows.filter(r => r.day === todayStr);
|
|
75
|
+
const todayTotal = todayRows.reduce((s, r) => s + r.input + r.cache_read + r.cache_write + r.output, 0);
|
|
76
|
+
const todayOut = todayRows.reduce((s, r) => s + r.output, 0);
|
|
77
|
+
const todayCalls = todayRows.reduce((s, r) => s + r.calls, 0);
|
|
78
|
+
const activeCount = keys.filter(k => k.status === 'active').length;
|
|
79
|
+
|
|
80
|
+
const boxPill = box.up
|
|
81
|
+
? `${c.mint('● ONLINE')} ${c.dim(`(${box.models.join(', ')})`)}`
|
|
82
|
+
: `${c.rose('● SLEEPING')}`;
|
|
83
|
+
|
|
84
|
+
printCard('LABS ADMIN CONTROL ROOM', [
|
|
85
|
+
`${c.dim('GPU Box:')} ${boxPill}`,
|
|
86
|
+
`${c.dim('Tokens Today:')} ${c.bold(c.mint(compactTokens(todayTotal)))} ${c.dim('Output:')} ${c.cyan(compactTokens(todayOut))} ${c.dim('Calls:')} ${c.violet(String(todayCalls))} ${c.dim('Active Keys:')} ${c.bold(String(activeCount))}`,
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
const maxAll = Math.max(1, ...keys.map(k => Number(k.total_tokens || 0)));
|
|
90
|
+
console.log(` ${c.bold(c.white('FRIEND KEYS & TOKEN LEADERBOARD'))}`);
|
|
91
|
+
console.log(` ${c.dim('ID NAME STATUS TODAY ALL-TIME SHARE CALLS LAST ACTIVE')}`);
|
|
92
|
+
console.log(` ${c.dim('─'.repeat(88))}`);
|
|
93
|
+
if (!keys.length) {
|
|
94
|
+
console.log(` ${c.dim('No keys yet. Run: labs admin create <name>')}\n`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
for (const k of keys) {
|
|
98
|
+
const id = String(k.id).padEnd(4);
|
|
99
|
+
const name = k.name.slice(0, 14).padEnd(15);
|
|
100
|
+
const status = k.status === 'active' ? c.mint('active ') : c.amber('paused ');
|
|
101
|
+
const today = compactTokens(k.today_tokens).padStart(9);
|
|
102
|
+
const all = compactTokens(k.total_tokens).padStart(9);
|
|
103
|
+
const bar = barChart(Number(k.total_tokens || 0), maxAll, 14);
|
|
104
|
+
const calls = String(k.today_calls || 0).padStart(6);
|
|
105
|
+
const seen = relTime(k.last_seen);
|
|
106
|
+
console.log(` ${c.dim(id)} ${c.bold(name)} ${status} ${c.cyan(today)} ${c.white(all)} ${bar} ${calls} ${c.dim(seen)}`);
|
|
107
|
+
}
|
|
108
|
+
console.log('');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function renderUsageTable(keys, rows, days) {
|
|
112
|
+
const names = Object.fromEntries(keys.map(k => [k.id, k.name]));
|
|
113
|
+
console.log(` ${c.bold(c.white(`DAILY TOKEN USAGE (LAST ${days} DAYS)`))}`);
|
|
114
|
+
console.log(` ${c.dim('DAY FRIEND MODEL CALLS INPUT CACHE OUTPUT TOTAL')}`);
|
|
115
|
+
console.log(` ${c.dim('─'.repeat(92))}`);
|
|
116
|
+
if (!rows.length) {
|
|
117
|
+
console.log(` ${c.dim('No usage recorded in this window.')}\n`);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
for (const r of rows.slice(0, 25)) {
|
|
121
|
+
const total = r.input + r.cache_read + r.cache_write + r.output;
|
|
122
|
+
const friend = (names[r.key_id] || `#${r.key_id}`).slice(0, 13).padEnd(14);
|
|
123
|
+
const model = String(r.model || '').slice(0, 15).padEnd(16);
|
|
124
|
+
console.log(
|
|
125
|
+
` ${c.dim(r.day)} ${c.bold(friend)} ${c.cyan(model)} ` +
|
|
126
|
+
`${String(r.calls).padStart(5)} ${compactTokens(r.input).padStart(9)} ` +
|
|
127
|
+
`${compactTokens(r.cache_read).padStart(9)} ${compactTokens(r.output).padStart(9)} ${c.mint(compactTokens(total).padStart(9))}`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
console.log('');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function mintFriendKey(api, name, cap = null) {
|
|
134
|
+
const made = await withSpinner(`Minting cryptographic lk_ key for ${c.bold(name)}...`, () => api.post('/keys', { name, dailyCapUsd: cap }));
|
|
135
|
+
const invite = `npm i -g labs-claude@latest && labs key ${made.key}`;
|
|
136
|
+
const copied = copyClipboard(invite);
|
|
137
|
+
printCard(`NEW API KEY · ${name.toUpperCase()}`, [
|
|
138
|
+
`${c.dim('Key (shown once):')} ${c.bold(c.mint(made.key))}`,
|
|
139
|
+
`${c.dim('Friend 1-liner:')} ${c.cyan(invite)}`,
|
|
140
|
+
`${c.dim('Clipboard:')} ${copied ? c.mint('✔ Copied friend 1-liner! Just Ctrl+V to Telegram/WhatsApp') : c.amber('Copy the line above and send to your friend')}`,
|
|
141
|
+
]);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async function changeStatus(api, keys, target, status) {
|
|
145
|
+
const found = resolveKeyTarget(keys, target);
|
|
146
|
+
if (!found) {
|
|
147
|
+
console.log(` ${c.rose('✖')} No key matching "${target}". Available: ${keys.map(k => `${k.id}:${k.name}`).join(', ') || 'none'}\n`);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
await withSpinner(`Setting ${c.bold(found.name)} (#${found.id}) → ${status}...`, () => api.post(`/keys/${found.id}/status`, { status }));
|
|
151
|
+
console.log(` ${c.mint('✔')} Key ${c.bold(found.name)} is now ${status === 'active' ? c.mint('active') : c.amber(status)}.\n`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function runAdminCli(args, ask) {
|
|
155
|
+
const cfg = storedConfig();
|
|
156
|
+
const url = (cfg.gatewayUrl || DEFAULT_GATEWAY_URL).replace(/\/+$/, '');
|
|
157
|
+
const token = readAdminToken();
|
|
158
|
+
const api = createAdminApi(url, token);
|
|
159
|
+
const sub = (args[0] || '').toLowerCase();
|
|
160
|
+
|
|
161
|
+
if (sub === 'help' || sub === '--help') {
|
|
162
|
+
printCard('LABS ADMIN COMMANDS', [
|
|
163
|
+
`${c.cyan('labs admin')} ${c.dim('Interactive terminal control room')}`,
|
|
164
|
+
`${c.cyan('labs admin stats')} ${c.dim('Live box status + per-friend token leaderboard')}`,
|
|
165
|
+
`${c.cyan('labs admin create <name>')} ${c.dim('Mint new lk_... key + auto-copy friend 1-liner')}`,
|
|
166
|
+
`${c.cyan('labs admin pause <name>')} ${c.dim('Pause a friend key immediately')}`,
|
|
167
|
+
`${c.cyan('labs admin resume <name>')} ${c.dim('Re-enable a paused friend key')}`,
|
|
168
|
+
`${c.cyan('labs admin revoke <name>')} ${c.dim('Permanently delete a friend key')}`,
|
|
169
|
+
`${c.cyan('labs admin usage [days]')} ${c.dim('Daily token table (default 14 days)')}`,
|
|
170
|
+
]);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
await playMascotIntro(version, `Admin Control Room · ${url}`);
|
|
175
|
+
|
|
176
|
+
const loadAll = async (days = 14) => withSpinner(randomQuip(), async () => {
|
|
177
|
+
const [k, u, b] = await Promise.all([api.get('/keys'), api.get(`/usage?days=${days}`), api.get('/box')]);
|
|
178
|
+
return { keys: k.keys || [], rows: u.rows || [], box: b || { up: false, models: [] } };
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
if (sub === 'stats' || sub === 'ls' || sub === 'list') {
|
|
182
|
+
const { keys, rows, box } = await loadAll(14);
|
|
183
|
+
renderDashboard(keys, rows, box);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (sub === 'usage') {
|
|
187
|
+
const days = Math.min(90, Math.max(1, Number(args[1]) || 14));
|
|
188
|
+
const { keys, rows } = await loadAll(days);
|
|
189
|
+
renderUsageTable(keys, rows, days);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (sub === 'create' || sub === 'new' || sub === 'add') {
|
|
193
|
+
const name = (args[1] || await ask(` ${c.cyan('?')} Friend name: `)).trim();
|
|
194
|
+
if (!name) return console.log(` ${c.rose('✖')} Name is required.\n`);
|
|
195
|
+
await mintFriendKey(api, name);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (['pause', 'resume', 'revoke', 'delete'].includes(sub)) {
|
|
199
|
+
const { keys } = await loadAll(1);
|
|
200
|
+
const target = args[1] || await ask(` ${c.cyan('?')} Friend name or ID: `);
|
|
201
|
+
const status = sub === 'resume' ? 'active' : sub === 'pause' ? 'paused' : 'deleted';
|
|
202
|
+
await changeStatus(api, keys, target, status);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Interactive menu loop
|
|
207
|
+
let state = await loadAll(14);
|
|
208
|
+
while (true) {
|
|
209
|
+
renderDashboard(state.keys, state.rows, state.box);
|
|
210
|
+
console.log(` ${c.bold('Actions:')}`);
|
|
211
|
+
console.log(` ${c.cyan('1.')} Mint new friend API key ${c.cyan('4.')} Revoke (delete) a key`);
|
|
212
|
+
console.log(` ${c.cyan('2.')} Pause a key ${c.cyan('5.')} Daily token table (14d)`);
|
|
213
|
+
console.log(` ${c.cyan('3.')} Resume a key ${c.cyan('6.')} Refresh stats ${c.dim('q. Quit')}\n`);
|
|
214
|
+
const choice = (await ask(` ${c.violet('admin>')} `)).trim().toLowerCase();
|
|
215
|
+
if (!choice || choice === 'q' || choice === 'quit' || choice === 'exit') break;
|
|
216
|
+
if (choice === '1') {
|
|
217
|
+
const name = (await ask(` ${c.cyan('?')} Friend name: `)).trim();
|
|
218
|
+
if (name) {
|
|
219
|
+
await mintFriendKey(api, name);
|
|
220
|
+
state = await loadAll(14);
|
|
221
|
+
}
|
|
222
|
+
} else if (choice === '2') {
|
|
223
|
+
const target = await ask(` ${c.cyan('?')} Friend name or ID to pause: `);
|
|
224
|
+
await changeStatus(api, state.keys, target, 'paused');
|
|
225
|
+
state = await loadAll(14);
|
|
226
|
+
} else if (choice === '3') {
|
|
227
|
+
const target = await ask(` ${c.cyan('?')} Friend name or ID to resume: `);
|
|
228
|
+
await changeStatus(api, state.keys, target, 'active');
|
|
229
|
+
state = await loadAll(14);
|
|
230
|
+
} else if (choice === '4') {
|
|
231
|
+
const target = await ask(` ${c.rose('?')} Friend name or ID to DELETE permanently: `);
|
|
232
|
+
const confirm = await ask(` ${c.amber('!')} Type YES to confirm permanent revoke: `);
|
|
233
|
+
if (confirm === 'YES') {
|
|
234
|
+
await changeStatus(api, state.keys, target, 'deleted');
|
|
235
|
+
state = await loadAll(14);
|
|
236
|
+
} else {
|
|
237
|
+
console.log(` ${c.dim('Cancelled.')}\n`);
|
|
238
|
+
}
|
|
239
|
+
} else if (choice === '5') {
|
|
240
|
+
renderUsageTable(state.keys, state.rows, 14);
|
|
241
|
+
} else if (choice === '6') {
|
|
242
|
+
state = await loadAll(14);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
module.exports = { compactTokens, barChart, resolveKeyTarget, runAdminCli };
|