labs-claude 0.2.6 โ 0.3.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.
- package/README.md +157 -122
- package/bin/labs.js +392 -178
- package/package.json +35 -34
- package/src/agy.js +1016 -0
- package/src/anthropic-protocol.js +84 -17
- package/src/auto-fallback.js +95 -0
- package/src/autostart.js +43 -43
- package/src/bedrock.js +162 -162
- package/src/browser-setup.js +38 -38
- package/src/chat/index.html +543 -534
- package/src/chat-routes.js +149 -149
- package/src/config.js +43 -5
- package/src/gateway-client.js +173 -0
- package/src/gemini.js +474 -0
- package/src/image-mcp.js +174 -0
- package/src/launch-args.js +15 -4
- package/src/local-auth.js +33 -33
- package/src/proxy-manager.js +87 -82
- package/src/proxy.js +187 -12
- package/src/read-shunt.js +26 -26
- package/src/setup.js +43 -1
- package/src/subscription-failure.js +36 -0
- package/src/ui.js +181 -0
- package/src/usage.js +84 -44
- package/src/web-mcp.js +253 -0
package/bin/labs.js
CHANGED
|
@@ -1,178 +1,392 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const axios = require('axios');
|
|
3
|
-
const { spawn } = require('child_process');
|
|
4
|
-
const { randomUUID } = require('crypto');
|
|
5
|
-
const { CONFIG_PATH, LABS_DIR,
|
|
6
|
-
const { loadProxyKey } = require('../src/local-auth');
|
|
7
|
-
const { ensureProxy, keepProxyAlive, stopProxy } = require('../src/proxy-manager');
|
|
8
|
-
const { parseLaunchArgs, withLabsHeaders, chromeCompatibilityWarning } = require('../src/launch-args');
|
|
9
|
-
const { runSetup, setupBedrock } = require('../src/setup');
|
|
10
|
-
const {
|
|
11
|
-
const {
|
|
12
|
-
const {
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
labs
|
|
23
|
-
labs
|
|
24
|
-
labs
|
|
25
|
-
labs
|
|
26
|
-
labs
|
|
27
|
-
labs
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const axios = require('axios');
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const { randomUUID } = require('crypto');
|
|
5
|
+
const { CONFIG_PATH, LABS_DIR, loadEffectiveConfig, loadLlmList } = require('../src/config');
|
|
6
|
+
const { loadProxyKey } = require('../src/local-auth');
|
|
7
|
+
const { ensureProxy, keepProxyAlive, stopProxy } = require('../src/proxy-manager');
|
|
8
|
+
const { parseLaunchArgs, withLabsHeaders, chromeCompatibilityWarning } = require('../src/launch-args');
|
|
9
|
+
const { runSetup, setupBedrock, setupGemini, ask, askHidden } = require('../src/setup');
|
|
10
|
+
const { boxOnlyArgs, gatewayModelFrom, prepareGatewayLaunch, saveGatewayKey, makeAdminToken, openConsole, storedConfig } = require('../src/gateway-client');
|
|
11
|
+
const { bedrockModelId, readBedrockKey } = require('../src/bedrock');
|
|
12
|
+
const { geminiModelId, resolveGeminiAuth } = require('../src/gemini');
|
|
13
|
+
const { agyModelId, agyModelInfo, hasAgyCli, isAgyFallbackModel } = require('../src/agy');
|
|
14
|
+
const { printUsage } = require('../src/usage');
|
|
15
|
+
const { setAutostart } = require('../src/autostart');
|
|
16
|
+
const { planSubscriptionLeg, planLabsLegArgs, createWatcher } = require('../src/auto-fallback');
|
|
17
|
+
const { version } = require('../package.json');
|
|
18
|
+
const { c, playMascotIntro, checkUpdateNotice, runSelfUpdate } = require('../src/ui');
|
|
19
|
+
|
|
20
|
+
const HELP = `labs ${version} โ Run Claude Code on Antigravity (agy), Google Gemini 4, ElevenLabs, Bedrock, or Qwen
|
|
21
|
+
|
|
22
|
+
labs open Claude Code on the default model
|
|
23
|
+
labs --model gem Gemini 4 Hydrogen (1M context, reasoning) via your signed-in agy CLI
|
|
24
|
+
labs --model gemini Gemini 4 Hydrogen (1M context, reasoning) via agy or your ElevenLabs bridge
|
|
25
|
+
labs --model hydrogen same as --model gemini (also: agy-flash, agy-opus, agy-sonnet, agy-oss)
|
|
26
|
+
labs --model opus pick a model by name, number (labs --model 5) or raw LLM id
|
|
27
|
+
labs -p "question" any Claude Code flag works, e.g. -p, --resume, --permission-mode
|
|
28
|
+
labs auto [claude args] real Claude Code on your subscription; on a limit or expired login, same session continues on labs Opus 5.5
|
|
29
|
+
labs models [--all] list models
|
|
30
|
+
labs usage credits left and what recent sessions cost per model
|
|
31
|
+
labs setup set your ElevenLabs key, the bridge agent and real-Chrome control
|
|
32
|
+
labs bedrock save your Amazon Bedrock key, then: labs --model glm (GLM 5.3)
|
|
33
|
+
labs --model qwen Claude Code on our GPU box (qwen | qwen-uncensored), through the labs gateway
|
|
34
|
+
labs key save your labs key (lk_...) with interactive model + effort setup
|
|
35
|
+
labs update update labs-claude to the latest npm version in one command
|
|
36
|
+
labs console open the gateway admin dashboard (keys & per-friend token stats)
|
|
37
|
+
labs paint "a red kite" paint on the box (--size wide|portrait|squareโฆ --count 1-4 --seed N); prints the file paths
|
|
38
|
+
labs image-mcp picture tool for any Claude Code chat: claude mcp add -s user labs-image -- labs image-mcp
|
|
39
|
+
labs web-mcp web search + page reading on this computer (added to every box session by itself)
|
|
40
|
+
labs admin-token <ssh> make a new console admin token on the gateway server
|
|
41
|
+
labs chat open the private chat page (http://127.0.0.1:8081/chat)
|
|
42
|
+
labs serve start the background proxy if it is not running, then exit
|
|
43
|
+
labs autostart on|off keep the proxy (and the chat page) running from login (Windows)
|
|
44
|
+
labs stop stop the background proxy
|
|
45
|
+
|
|
46
|
+
Inside Claude Code: /model <name> switches model, e.g. /model gemini-4-neon
|
|
47
|
+
Browser: "open gmail.com and read my top email" uses your real Chrome (set up with labs setup)
|
|
48
|
+
Update: npm install -g labs-claude@latest --prefer-online, then close and reopen every labs window`;
|
|
49
|
+
|
|
50
|
+
function printModels(config, showAll) {
|
|
51
|
+
const llms = loadLlmList();
|
|
52
|
+
const byId = Object.fromEntries(llms.map(item => [item.llm, item]));
|
|
53
|
+
const size = (n) => n >= 1000000 ? `${Math.round(n / 100000) / 10}M` : `${Math.round(n / 1000)}k`;
|
|
54
|
+
const geminiAuth = resolveGeminiAuth(LABS_DIR, config);
|
|
55
|
+
const agyReady = hasAgyCli();
|
|
56
|
+
const hasEl = Boolean(config?.apiKey && config?.bridgeAgent);
|
|
57
|
+
console.log('\n๐ Labs models (labs --model <name or number>)\n');
|
|
58
|
+
Object.entries(config.models).forEach(([name, llm], index) => {
|
|
59
|
+
const info = byId[llm];
|
|
60
|
+
const gemId = geminiModelId(llm);
|
|
61
|
+
const explicitAgy = agyModelId(llm);
|
|
62
|
+
const fallbackAgy = !explicitAgy && !gemId && !hasEl && !geminiAuth && agyReady && isAgyFallbackModel(llm) ? llm : null;
|
|
63
|
+
const agyId = explicitAgy || fallbackAgy;
|
|
64
|
+
const isGw4 = GATEWAY_GEMINI4.has(llm);
|
|
65
|
+
const detail = agyId
|
|
66
|
+
? `Antigravity (agy), ${size(agyModelInfo(agyId).contextLimit).padStart(4)} context ${size(agyModelInfo(agyId).maxReply).padStart(4)} reply`
|
|
67
|
+
: gemId
|
|
68
|
+
? `${geminiAuth?.mode === 'vertex' ? 'Vertex AI' : 'Google Gemini'}, ${size(config.geminiContextLimit || 1000000).padStart(4)} context ${/carbon|argon/.test(gemId) ? '32k' : '64k'} reply`
|
|
69
|
+
: isGw4
|
|
70
|
+
? `Google Gemini, ${size(info?.max_context_limit || 1048576).padStart(4)} context ${size(info?.max_tokens_limit || 65536).padStart(5)} reply`
|
|
71
|
+
: bedrockModelId(llm)
|
|
72
|
+
? `Amazon Bedrock, ${size(config.bedrockContextLimit).padStart(5)} context 128k reply`
|
|
73
|
+
: info ? `${size(info.max_context_limit).padStart(5)} context ${size(info.max_tokens_limit).padStart(5)} reply` : 'not offered on your account';
|
|
74
|
+
const marker = name === config.defaultModel ? ' โ default' : '';
|
|
75
|
+
console.log(`${String(index + 1).padStart(3)}. ${name.padEnd(11)} ${llm.padEnd(28)} ${detail}${marker}`);
|
|
76
|
+
});
|
|
77
|
+
const current = llms.filter(item => !item.deprecation_info && !item.is_checkpoint);
|
|
78
|
+
if (showAll) {
|
|
79
|
+
console.log(`\nAll ${current.length} current ElevenLabs LLMs (use the id with --model):\n`);
|
|
80
|
+
current.forEach(item => console.log(` ${item.llm.padEnd(32)} ${size(item.max_context_limit).padStart(5)} context ${size(item.max_tokens_limit).padStart(5)} reply`));
|
|
81
|
+
} else {
|
|
82
|
+
console.log(`\n${current.length} current ElevenLabs LLMs in total: labs models --all`);
|
|
83
|
+
}
|
|
84
|
+
console.log('Inside Claude Code: /model <name> switches model.\n');
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// The browser opens a one-time link (single use, 60 s), so the key is never pasted or shown. If that fails, the key
|
|
88
|
+
// goes to the clipboard, never to the screen, so it does not end up in terminal logs or screenshots.
|
|
89
|
+
async function openChat(config) {
|
|
90
|
+
if (!(await ensureProxy(config.port))) {
|
|
91
|
+
console.error('โ The labs proxy did not start. See ~/.labs/proxy.log');
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
const base = `http://127.0.0.1:${config.port}`;
|
|
95
|
+
let url = `${base}/chat`;
|
|
96
|
+
try {
|
|
97
|
+
const { data } = await axios.post(`${base}/chat/api/login-link`, null, { headers: { 'x-api-key': loadProxyKey(LABS_DIR) }, timeout: 3000 });
|
|
98
|
+
url = base + data.path;
|
|
99
|
+
console.log('๐ Opening the chat page, already logged in.');
|
|
100
|
+
} catch {
|
|
101
|
+
const clipboard = { win32: ['clip', []], darwin: ['pbcopy', []] }[process.platform];
|
|
102
|
+
if (clipboard) {
|
|
103
|
+
const copy = spawn(clipboard[0], clipboard[1]);
|
|
104
|
+
copy.stdin.end(loadProxyKey(LABS_DIR));
|
|
105
|
+
console.log('๐ Your labs key is on the clipboard: paste it once on the page.');
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
console.log(`๐ฌ ${base}/chat`);
|
|
109
|
+
const opener = process.platform === 'win32' ? ['cmd', ['/c', 'start', '', url]] : [process.platform === 'darwin' ? 'open' : 'xdg-open', [url]];
|
|
110
|
+
spawn(opener[0], opener[1], { stdio: 'ignore', detached: true }).unref();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function launchClaude(claudeArgs, env, onExit = code => process.exit(code ?? 0)) {
|
|
114
|
+
// The native installer ships claude.exe; an npm-installed Claude Code on Windows is a .cmd shim that needs a shell.
|
|
115
|
+
const command = process.platform === 'win32' ? 'claude.exe' : 'claude';
|
|
116
|
+
const child = spawn(command, claudeArgs, { stdio: 'inherit', env });
|
|
117
|
+
const handle = { child, kill: () => handle.child.kill() };
|
|
118
|
+
child.on('error', error => {
|
|
119
|
+
if (error.code !== 'ENOENT' || process.platform !== 'win32') {
|
|
120
|
+
console.error(`โ Could not start Claude Code: ${error.message}`);
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
const quoted = claudeArgs.map(arg => `"${arg.replace(/"/g, '\\"')}"`).join(' ');
|
|
124
|
+
handle.child = spawn(`claude ${quoted}`, { stdio: 'inherit', env, shell: true });
|
|
125
|
+
handle.child.on('exit', code => onExit(code));
|
|
126
|
+
});
|
|
127
|
+
child.on('exit', code => onExit(code));
|
|
128
|
+
return handle;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function readEffortFlag(args, fallback) {
|
|
132
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
133
|
+
if (args[i] === '--effort' && args[i + 1]) return args[i + 1];
|
|
134
|
+
if (args[i].startsWith('--effort=')) return args[i].slice('--effort='.length);
|
|
135
|
+
}
|
|
136
|
+
return fallback;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Gemini-4 model IDs that the ElevenLabs gateway serves natively (no Google API key needed).
|
|
140
|
+
const GATEWAY_GEMINI4 = new Set(['gemini-4-hydrogen', 'gemini-4-neon', 'gemini-4-argon', 'gemini-4-carbon', 'gemini-4-nano']);
|
|
141
|
+
|
|
142
|
+
// Everything needed to start Claude Code against the labs proxy; shared by `labs` and the labs leg of `labs auto`.
|
|
143
|
+
async function prepareLabsLaunch(config, args) {
|
|
144
|
+
const { modelName, claudeArgs } = parseLaunchArgs(args, {
|
|
145
|
+
aliases: config.models,
|
|
146
|
+
llmIds: new Set([...loadLlmList().map(item => item.llm), ...GATEWAY_GEMINI4]),
|
|
147
|
+
defaultModel: config.defaultModel
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const chromeWarning = chromeCompatibilityWarning(claudeArgs);
|
|
151
|
+
if (chromeWarning) console.error(`โ ๏ธ ${chromeWarning}`);
|
|
152
|
+
|
|
153
|
+
const llm = config.models[modelName] || modelName;
|
|
154
|
+
// gemini: prefix = direct Google API path; agy: prefix = Antigravity CLI ACP bridge; plain gemini-4-* = ElevenLabs or agy fallback.
|
|
155
|
+
const explicitAgyId = agyModelId(llm);
|
|
156
|
+
const directGemId = geminiModelId(llm); // "gemini-4-hydrogen" when prefix is "gemini:"
|
|
157
|
+
const geminiAuth = directGemId ? resolveGeminiAuth(LABS_DIR, config) : null;
|
|
158
|
+
const hasEl = Boolean(config?.apiKey && config.bridgeAgent);
|
|
159
|
+
const fallbackAgyId = !explicitAgyId && !directGemId && !hasEl && isAgyFallbackModel(llm) && hasAgyCli() ? llm : null;
|
|
160
|
+
const agyId = explicitAgyId || fallbackAgyId;
|
|
161
|
+
const onAgy = Boolean(agyId);
|
|
162
|
+
const gatewayGem4 = !onAgy && GATEWAY_GEMINI4.has(llm); // true when alias resolves to "gemini-4-hydrogen" etc.
|
|
163
|
+
const onGemini = Boolean(directGemId); // only direct-API path needs Google auth
|
|
164
|
+
const onGatewayGemini4 = gatewayGem4; // ElevenLabs-routed Gemini 4
|
|
165
|
+
const onBedrock = Boolean(bedrockModelId(llm));
|
|
166
|
+
|
|
167
|
+
if (onAgy && !hasAgyCli()) {
|
|
168
|
+
console.error(`โ ${modelName} requires Antigravity CLI (agy) in your PATH.`);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
// Direct Google API path requires a key; skip this check for agy or gateway-routed gemini-4 models.
|
|
172
|
+
if (onGemini && !geminiAuth) {
|
|
173
|
+
console.error(`โ ${modelName} runs on Google Gemini and no key or Vertex project is configured. Run: labs gemini (or set GEMINI_API_KEY)`);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
// Without a key every call gets 401, and Claude Code retries those silently: the window would look frozen.
|
|
177
|
+
if (onBedrock && !readBedrockKey(LABS_DIR)) {
|
|
178
|
+
console.error(`โ ${modelName} runs on Amazon Bedrock and no Bedrock key is saved. Run: labs bedrock`);
|
|
179
|
+
process.exit(1);
|
|
180
|
+
}
|
|
181
|
+
if (!onAgy && !onGemini && !onGatewayGemini4 && !onBedrock && !hasEl) {
|
|
182
|
+
console.log(`No ElevenLabs setup found at ${CONFIG_PATH}, running setup first.\n`);
|
|
183
|
+
await runSetup();
|
|
184
|
+
config = loadEffectiveConfig();
|
|
185
|
+
}
|
|
186
|
+
// Gateway Gemini-4 models (hydrogen, neon, argon) route through the ElevenLabs bridge agent when agy is not handling them.
|
|
187
|
+
if (onGatewayGemini4 && (!config?.apiKey || !config.bridgeAgent)) {
|
|
188
|
+
console.error(`\nโ ${modelName} (${llm}) requires a labs ElevenLabs account (or use labs --model gem for agy).\n`);
|
|
189
|
+
console.error(` Run: labs setup to enter your ElevenLabs key and bridge agent.\n`);
|
|
190
|
+
console.error(` No account? Sign up at https://elevenlabs.io (free tier works)\n`);
|
|
191
|
+
process.exit(1);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (!(await ensureProxy(config.port))) {
|
|
195
|
+
console.error('โ The labs proxy did not start. See ~/.labs/proxy.log');
|
|
196
|
+
process.exit(1);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const llmInfo = onAgy
|
|
200
|
+
? { max_context_limit: agyModelInfo(agyId).contextLimit }
|
|
201
|
+
: onGemini
|
|
202
|
+
? { max_context_limit: config.geminiContextLimit || 1000000 }
|
|
203
|
+
: onGatewayGemini4
|
|
204
|
+
// Gateway gemini-4 models have 1M context; use the LLM list value if present, else 1M.
|
|
205
|
+
? (loadLlmList().find(item => item.llm === llm) || { max_context_limit: 1048576 })
|
|
206
|
+
: onBedrock
|
|
207
|
+
? { max_context_limit: config.bedrockContextLimit }
|
|
208
|
+
: loadLlmList().find(item => item.llm === llm);
|
|
209
|
+
if (!claudeArgs.some(arg => arg === '--effort' || arg.startsWith('--effort='))) {
|
|
210
|
+
claudeArgs.push('--effort', config.defaultEffort || 'high');
|
|
211
|
+
}
|
|
212
|
+
const effort = readEffortFlag(claudeArgs, config.defaultEffort || 'high');
|
|
213
|
+
|
|
214
|
+
const CAPS = 'effort,xhigh_effort,max_effort,thinking,interleaved_thinking';
|
|
215
|
+
// For Google Gemini / Gateway Gemini-4, present claude-opus-4-6; for Antigravity (agy), present the real agy model id
|
|
216
|
+
// (like gemini-4-hydrogen) so Claude Code displays and routes the actual model name rather than Opus/Sonnet/Haiku.
|
|
217
|
+
const isOpusUx = onGemini || onGatewayGemini4;
|
|
218
|
+
const launchArgs = [];
|
|
219
|
+
for (let i = 0; i < claudeArgs.length; i += 1) {
|
|
220
|
+
if (onAgy && claudeArgs[i] === '--model') { launchArgs.push('--model', agyId); i += 1; continue; }
|
|
221
|
+
if (onAgy && claudeArgs[i].startsWith('--model=')) { launchArgs.push(`--model=${agyId}`); continue; }
|
|
222
|
+
if (isOpusUx && claudeArgs[i] === '--model') { launchArgs.push('--model', 'claude-opus-4-6'); i += 1; continue; }
|
|
223
|
+
if (isOpusUx && claudeArgs[i].startsWith('--model=')) { launchArgs.push('--model=claude-opus-4-6'); continue; }
|
|
224
|
+
launchArgs.push(claudeArgs[i]);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const agyDisplayName = modelName === 'gem' ? 'Gemini 4 Hydrogen (agy)' : `${agyId} (agy)`;
|
|
228
|
+
const env = {
|
|
229
|
+
...process.env,
|
|
230
|
+
// Claude Code only knows Anthropic windows; without this it assumes 200k and compacts at the wrong point.
|
|
231
|
+
...(llmInfo ? { CLAUDE_CODE_MAX_CONTEXT_TOKENS: String((onAgy || isOpusUx) ? llmInfo.max_context_limit : Math.min(llmInfo.max_context_limit, config.contextLimit)) } : {}),
|
|
232
|
+
ANTHROPIC_BASE_URL: `http://127.0.0.1:${config.port}`,
|
|
233
|
+
ANTHROPIC_AUTH_TOKEN: loadProxyKey(LABS_DIR),
|
|
234
|
+
ANTHROPIC_CUSTOM_HEADERS: withLabsHeaders(process.env.ANTHROPIC_CUSTOM_HEADERS, randomUUID(), modelName, effort, process.cwd()),
|
|
235
|
+
...(onAgy ? {
|
|
236
|
+
ANTHROPIC_MODEL: agyId,
|
|
237
|
+
ANTHROPIC_CUSTOM_MODEL_OPTION: agyId,
|
|
238
|
+
ANTHROPIC_CUSTOM_MODEL_OPTION_NAME: agyDisplayName,
|
|
239
|
+
ANTHROPIC_CUSTOM_MODEL_OPTION_DESCRIPTION: `Antigravity (agy) ยท ${Math.round(llmInfo.max_context_limit / 1000)}k context`,
|
|
240
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: agyId,
|
|
241
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: agyId,
|
|
242
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: 'gemini-3.8-flash',
|
|
243
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL_SUPPORTED_CAPABILITIES: CAPS,
|
|
244
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL_SUPPORTED_CAPABILITIES: CAPS,
|
|
245
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL_SUPPORTED_CAPABILITIES: CAPS
|
|
246
|
+
} : isOpusUx ? {
|
|
247
|
+
// Present a native Claude Opus id so Claude Code enables full thinking/effort/1M UX with zero
|
|
248
|
+
// unrecognized_model warnings; X-Labs-Model in the custom header routes every call to the target model.
|
|
249
|
+
ANTHROPIC_MODEL: 'claude-opus-4-6',
|
|
250
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL: 'claude-opus-4-6',
|
|
251
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL: 'claude-sonnet-4-6',
|
|
252
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL: 'claude-haiku-4-5',
|
|
253
|
+
ANTHROPIC_DEFAULT_OPUS_MODEL_SUPPORTED_CAPABILITIES: CAPS,
|
|
254
|
+
ANTHROPIC_DEFAULT_SONNET_MODEL_SUPPORTED_CAPABILITIES: CAPS,
|
|
255
|
+
ANTHROPIC_DEFAULT_HAIKU_MODEL_SUPPORTED_CAPABILITIES: CAPS
|
|
256
|
+
} : {}),
|
|
257
|
+
// Subagents run on the chosen model too; the proxy answers overload with 529 so Claude Code retries, never switches.
|
|
258
|
+
CLAUDE_CODE_SUBAGENT_MODEL: onAgy ? agyId : isOpusUx ? 'claude-opus-4-6' : modelName
|
|
259
|
+
};
|
|
260
|
+
// A leftover key (e.g. from an Ollama setup) would take precedence over the proxy's auth token.
|
|
261
|
+
delete env.ANTHROPIC_API_KEY;
|
|
262
|
+
|
|
263
|
+
const contextK = llmInfo ? `, ${Math.round(llmInfo.max_context_limit / 1000)}k context` : '';
|
|
264
|
+
const providerLabel = onAgy
|
|
265
|
+
? 'Antigravity (agy)'
|
|
266
|
+
: onGatewayGemini4
|
|
267
|
+
? 'Google Gemini'
|
|
268
|
+
: onGemini
|
|
269
|
+
? (geminiAuth?.mode === 'vertex' ? 'Vertex AI' : 'Google Gemini')
|
|
270
|
+
: onBedrock ? 'Amazon Bedrock' : 'ElevenLabs';
|
|
271
|
+
const banner = `๐ Claude Code on ${providerLabel} ${modelName} (${agyId || llm}${contextK})`;
|
|
272
|
+
return { modelName, claudeArgs: launchArgs, env, banner };
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// `labs auto`: real Claude Code on the subscription first; when the subscription fails for good in this session
|
|
276
|
+
// (see src/subscription-failure.js), the same session is resumed on labs Opus 5.5. The next start tries the subscription again.
|
|
277
|
+
async function runAuto(args) {
|
|
278
|
+
const force = process.env.LABS_AUTO_FORCE_FALLBACK === '1';
|
|
279
|
+
const leg = planSubscriptionLeg(args);
|
|
280
|
+
const env = { ...process.env };
|
|
281
|
+
// The subscription leg must talk to Anthropic directly, even when this shell was started with labs variables.
|
|
282
|
+
for (const name of ['ANTHROPIC_BASE_URL', 'ANTHROPIC_AUTH_TOKEN', 'ANTHROPIC_CUSTOM_HEADERS', 'CLAUDE_CODE_MAX_CONTEXT_TOKENS', 'CLAUDE_CODE_SUBAGENT_MODEL']) delete env[name];
|
|
283
|
+
console.log('๐ข Opus ยท subscription');
|
|
284
|
+
process.stdout.write(']0;Opus ยท subscription');
|
|
285
|
+
|
|
286
|
+
let switched = false;
|
|
287
|
+
const toLabs = async failure => {
|
|
288
|
+
if (switched) return;
|
|
289
|
+
switched = true;
|
|
290
|
+
watcher.stop();
|
|
291
|
+
const sessionId = leg.sessionId || failure.sessionId;
|
|
292
|
+
handle.kill();
|
|
293
|
+
let config = loadConfig();
|
|
294
|
+
if (!config?.apiKey || !config.bridgeAgent) { await runSetup(); config = loadConfig(); }
|
|
295
|
+
const launch = await prepareLabsLaunch(config, planLabsLegArgs(args, sessionId));
|
|
296
|
+
console.log(`
|
|
297
|
+
๐ Subscription limit hit (${failure.kind}), continuing on labs Opus 5.5`);
|
|
298
|
+
process.stdout.write(']0;Opus 5.5 ยท labs');
|
|
299
|
+
keepProxyAlive(config.port);
|
|
300
|
+
launchClaude(launch.claudeArgs, launch.env);
|
|
301
|
+
};
|
|
302
|
+
const watcher = createWatcher({ sessionId: leg.sessionId, fromStart: leg.fromStart, startedAt: Date.now(), forceFallback: force, onFailure: toLabs });
|
|
303
|
+
const handle = launchClaude(leg.args, env, async code => {
|
|
304
|
+
if (switched) return;
|
|
305
|
+
// A -p run ends right after the error, before the next poll: read what is left before deciding to exit.
|
|
306
|
+
const found = watcher.pollNow();
|
|
307
|
+
if (found) return toLabs(found);
|
|
308
|
+
watcher.stop();
|
|
309
|
+
process.exit(code ?? 0);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
async function runInteractiveSetup() {
|
|
314
|
+
await playMascotIntro(version, 'Choose your backend to set up');
|
|
315
|
+
console.log(` ${c.bold('Select setup mode:')}`);
|
|
316
|
+
console.log(` ${c.cyan('1.')} ${c.bold('Labs Key (Qwen4 1M)')} ${c.dim('Paste lk_... key from admin โ Vision, Web, 200โ400 tok/s [Recommended]')}`);
|
|
317
|
+
console.log(` ${c.cyan('2.')} ${c.bold('ElevenLabs')} ${c.dim('ElevenLabs API key + bridge agent + Chrome control')}`);
|
|
318
|
+
console.log(` ${c.cyan('3.')} ${c.bold('Google Gemini 4')} ${c.dim('AI Studio key or Vertex AI')}`);
|
|
319
|
+
console.log(` ${c.cyan('4.')} ${c.bold('Amazon Bedrock')} ${c.dim('Bedrock API key (GLM 5.3)')}\n`);
|
|
320
|
+
const choice = (await ask(' Choose [1]: ')) || '1';
|
|
321
|
+
if (choice === '1') return saveGatewayKey(askHidden, ask);
|
|
322
|
+
if (choice === '2') return runSetup();
|
|
323
|
+
if (choice === '3') return setupGemini();
|
|
324
|
+
if (choice === '4') return setupBedrock();
|
|
325
|
+
console.log(` ${c.rose('โ')} Unknown choice "${choice}".`);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
async function main() {
|
|
329
|
+
const args = process.argv.slice(2);
|
|
330
|
+
if (args[0] === 'image-mcp') return require('../src/image-mcp').serveFromConfig(version);
|
|
331
|
+
if (args[0] === 'web-mcp') return require('../src/web-mcp').serve({ version });
|
|
332
|
+
if (args[0] === '--version') return console.log(version);
|
|
333
|
+
if (args[0] === 'update') return runSelfUpdate(version);
|
|
334
|
+
checkUpdateNotice(version, LABS_DIR);
|
|
335
|
+
if (args[0] === 'setup') return runInteractiveSetup();
|
|
336
|
+
if (args[0] === 'bedrock') return setupBedrock();
|
|
337
|
+
if (args[0] === 'gemini') return setupGemini();
|
|
338
|
+
if (args[0] === 'auto') return runAuto(args.slice(1));
|
|
339
|
+
if (args[0] === '--help' || args[0] === 'help') return console.log(HELP);
|
|
340
|
+
if (args[0] === 'autostart') {
|
|
341
|
+
if (!['on', 'off'].includes(args[1])) return console.log('Use: labs autostart on | labs autostart off');
|
|
342
|
+
const { ok, message } = setAutostart(args[1] === 'on');
|
|
343
|
+
console[ok ? 'log' : 'error'](message);
|
|
344
|
+
return process.exit(ok ? 0 : 1);
|
|
345
|
+
}
|
|
346
|
+
// The autostart task runs this with no window, so it must never fall into the interactive setup.
|
|
347
|
+
if (args[0] === 'serve') {
|
|
348
|
+
const cfg = loadEffectiveConfig();
|
|
349
|
+
const ready = (cfg.apiKey || resolveGeminiAuth(LABS_DIR, cfg) || readBedrockKey(LABS_DIR) || hasAgyCli()) && await ensureProxy(cfg.port);
|
|
350
|
+
console.log(ready ? 'โ
labs proxy running' : 'โ labs proxy not started (run labs gemini or labs setup, see ~/.labs/proxy.log)');
|
|
351
|
+
return process.exit(ready ? 0 : 1);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Box users (friends) may have no ElevenLabs account at all, so these never fall into the ElevenLabs setup.
|
|
355
|
+
if (args[0] === 'key') return saveGatewayKey(askHidden, ask, args[1]);
|
|
356
|
+
if (args[0] === 'paint') return require('../src/image-mcp').paintFromCli(args.slice(1));
|
|
357
|
+
if (args[0] === 'admin-token') return makeAdminToken(args[1]);
|
|
358
|
+
if (args[0] === 'console') return openConsole(storedConfig());
|
|
359
|
+
const stored = storedConfig();
|
|
360
|
+
if (!args.length && !stored.gatewayKey && !stored.apiKey && !process.env.ELEVENLABS_API_KEY && !readBedrockKey(LABS_DIR)) {
|
|
361
|
+
return runInteractiveSetup();
|
|
362
|
+
}
|
|
363
|
+
const boxArgs = boxOnlyArgs(args, stored) || args;
|
|
364
|
+
const boxModel = gatewayModelFrom(boxArgs);
|
|
365
|
+
if (boxModel) {
|
|
366
|
+
const launch = await prepareGatewayLaunch(stored, boxArgs, boxModel);
|
|
367
|
+
console.log(launch.banner);
|
|
368
|
+
return launchClaude(launch.claudeArgs, launch.env);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const config = loadEffectiveConfig();
|
|
372
|
+
// If no ElevenLabs account, pick the best available backend as default.
|
|
373
|
+
if (!config.apiKey || !config.bridgeAgent) {
|
|
374
|
+
if (readBedrockKey(LABS_DIR)) config.defaultModel = 'glm';
|
|
375
|
+
else config.defaultModel = 'hydrogen'; // gemini-4-hydrogen works via ElevenLabs gateway; setup will prompt if needed
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (args[0] === 'models') return printModels(config, args.includes('--all'));
|
|
379
|
+
if (args[0] === 'usage') return printUsage(config);
|
|
380
|
+
if (args[0] === 'chat') return openChat(config);
|
|
381
|
+
if (args[0] === 'stop') return console.log(await stopProxy(config.port) ? '๐ Proxy stopped' : 'Proxy was not running');
|
|
382
|
+
|
|
383
|
+
const launch = await prepareLabsLaunch(config, args);
|
|
384
|
+
console.log(launch.banner);
|
|
385
|
+
keepProxyAlive(config.port);
|
|
386
|
+
launchClaude(launch.claudeArgs, launch.env);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
main().catch(error => {
|
|
390
|
+
console.error(`โ ${error.message}`);
|
|
391
|
+
process.exit(1);
|
|
392
|
+
});
|