labs-claude 0.3.0 → 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.
@@ -3,11 +3,21 @@ const { createHash, randomUUID } = require('crypto');
3
3
  const modelDisplayNames = {
4
4
  astra: 'GPT-6 Astra',
5
5
  opus: 'Opus 5.5',
6
- glm: 'GLM-52',
6
+ glm: 'GLM-53',
7
7
  sol: 'GPT-6 Sol',
8
8
  qwen: 'Qwen3-6 35B',
9
9
  oss: 'GPT-OSS-120B',
10
- gemini: 'Gemini 3.8 Flash'
10
+ hydrogen: 'Gemini 4 Hydrogen',
11
+ gemini: 'Gemini 4 Hydrogen',
12
+ gem: 'Gemini 4 Hydrogen (agy)',
13
+ 'agy-flash': 'Gemini 3.8 Flash (agy)',
14
+ 'agy-sonnet': 'Claude Sonnet 4.6 (agy)',
15
+ 'agy-opus': 'Claude Opus 4.6 (agy)',
16
+ 'agy-oss': 'GPT-OSS 120B (agy)',
17
+ carbon: 'Gemini 4 Carbon',
18
+ neon: 'Gemini 4 Neon',
19
+ argon: 'Gemini 4 Argon',
20
+ gemini3: 'Gemini 3.8 Flash'
11
21
  };
12
22
 
13
23
  function contentToText(content) {
@@ -91,7 +101,7 @@ function extractLatestUserTurn(messages) {
91
101
  return { text: '', toolResults: [], images: [] };
92
102
  }
93
103
 
94
- function createAnthropicMessage({ model, text = '', toolCalls = [], inputTokens = 0 }) {
104
+ function createAnthropicMessage({ model, text = '', thinking = '', toolCalls = [], inputTokens = 0 }) {
95
105
  const toolBlocks = toolCalls.map(tool => ({
96
106
  type: 'tool_use',
97
107
  id: tool.id,
@@ -99,10 +109,11 @@ function createAnthropicMessage({ model, text = '', toolCalls = [], inputTokens
99
109
  input: tool.input || {}
100
110
  }));
101
111
  const content = [
102
- ...(text || toolBlocks.length === 0 ? [{ type: 'text', text }] : []),
112
+ ...(thinking ? [{ type: 'thinking', thinking, signature: 'gemini' }] : []),
113
+ ...(text || (toolBlocks.length === 0 && !thinking) ? [{ type: 'text', text }] : []),
103
114
  ...toolBlocks
104
115
  ];
105
- const outputText = text + (toolBlocks.length ? JSON.stringify(toolBlocks) : '');
116
+ const outputText = thinking + text + (toolBlocks.length ? JSON.stringify(toolBlocks) : '');
106
117
 
107
118
  return {
108
119
  id: `msg_${randomUUID()}`,
@@ -208,7 +219,22 @@ function createAnthropicEvents(message) {
208
219
  });
209
220
 
210
221
  content.forEach((block, index) => {
211
- if (block.type === 'text') {
222
+ if (block.type === 'thinking') {
223
+ emit('content_block_start', {
224
+ type: 'content_block_start', index,
225
+ content_block: { type: 'thinking', thinking: '' }
226
+ });
227
+ if (block.thinking) {
228
+ emit('content_block_delta', {
229
+ type: 'content_block_delta', index,
230
+ delta: { type: 'thinking_delta', thinking: block.thinking }
231
+ });
232
+ }
233
+ emit('content_block_delta', {
234
+ type: 'content_block_delta', index,
235
+ delta: { type: 'signature_delta', signature: block.signature || 'gemini' }
236
+ });
237
+ } else if (block.type === 'text') {
212
238
  emit('content_block_start', {
213
239
  type: 'content_block_start', index,
214
240
  content_block: { type: 'text', text: '' }
@@ -267,28 +293,69 @@ const STREAM_PING_MS = 10000;
267
293
  // Nothing is sent before the first word, so an early failure can still be answered with an HTTP error and retried.
268
294
  function createLiveStream(response, { model, inputTokens }) {
269
295
  let pingTimer = null;
296
+ let activeBlock = null;
297
+ let nextIndex = 0;
298
+
299
+ const ensureStarted = () => {
300
+ if (live.started) return;
301
+ live.started = true;
302
+ startEventStream(response);
303
+ const { content, usage, ...start } = createAnthropicMessage({ model, inputTokens });
304
+ writeEvent(response, { event: 'message_start', data: { type: 'message_start', message: { ...start, content: [], stop_reason: null, usage: { input_tokens: inputTokens, output_tokens: 0 } } } });
305
+ pingTimer = setInterval(() => writeEvent(response, { event: 'ping', data: { type: 'ping' } }), STREAM_PING_MS);
306
+ };
307
+
308
+ const closeActiveBlock = () => {
309
+ if (!activeBlock) return;
310
+ if (activeBlock.type === 'thinking') {
311
+ writeEvent(response, { event: 'content_block_delta', data: { type: 'content_block_delta', index: activeBlock.index, delta: { type: 'signature_delta', signature: 'gemini' } } });
312
+ }
313
+ writeEvent(response, { event: 'content_block_stop', data: { type: 'content_block_stop', index: activeBlock.index } });
314
+ activeBlock = null;
315
+ };
316
+
270
317
  const live = {
271
318
  started: false,
272
319
  streamedText: '',
320
+ streamedThinking: '',
321
+ thinking(delta) {
322
+ if (!delta) return;
323
+ ensureStarted();
324
+ if (activeBlock?.type !== 'thinking') {
325
+ closeActiveBlock();
326
+ activeBlock = { type: 'thinking', index: nextIndex++ };
327
+ writeEvent(response, { event: 'content_block_start', data: { type: 'content_block_start', index: activeBlock.index, content_block: { type: 'thinking', thinking: '' } } });
328
+ }
329
+ live.streamedThinking += delta;
330
+ writeEvent(response, { event: 'content_block_delta', data: { type: 'content_block_delta', index: activeBlock.index, delta: { type: 'thinking_delta', thinking: delta } } });
331
+ },
273
332
  text(delta) {
274
- if (!live.started) {
275
- live.started = true;
276
- startEventStream(response);
277
- const { content, usage, ...start } = createAnthropicMessage({ model, inputTokens });
278
- writeEvent(response, { event: 'message_start', data: { type: 'message_start', message: { ...start, content: [], stop_reason: null, usage: { input_tokens: inputTokens, output_tokens: 0 } } } });
279
- writeEvent(response, { event: 'content_block_start', data: { type: 'content_block_start', index: 0, content_block: { type: 'text', text: '' } } });
280
- pingTimer = setInterval(() => writeEvent(response, { event: 'ping', data: { type: 'ping' } }), STREAM_PING_MS);
333
+ ensureStarted();
334
+ if (activeBlock?.type !== 'text') {
335
+ closeActiveBlock();
336
+ activeBlock = { type: 'text', index: nextIndex++ };
337
+ writeEvent(response, { event: 'content_block_start', data: { type: 'content_block_start', index: activeBlock.index, content_block: { type: 'text', text: '' } } });
281
338
  }
282
339
  live.streamedText += delta;
283
- writeEvent(response, { event: 'content_block_delta', data: { type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text: delta } } });
340
+ writeEvent(response, { event: 'content_block_delta', data: { type: 'content_block_delta', index: activeBlock.index, delta: { type: 'text_delta', text: delta } } });
284
341
  },
285
342
  // The message must carry streamedText as its text, so the reply Claude Code stores matches what it was shown.
286
343
  finish(message) {
287
344
  live.stopPings();
288
345
  if (!live.started) return writeAnthropicEvents(response, createAnthropicEvents(message));
289
- writeEvent(response, { event: 'content_block_stop', data: { type: 'content_block_stop', index: 0 } });
290
- const rest = createAnthropicEvents(message).filter(({ event, data }) => event !== 'message_start' && data.index !== 0);
291
- for (const event of rest) writeEvent(response, event);
346
+ closeActiveBlock();
347
+ const remaining = {
348
+ ...message,
349
+ content: message.content.filter(block => !(block.type === 'thinking' && live.streamedThinking) && !(block.type === 'text' && live.streamedText))
350
+ };
351
+ const rest = createAnthropicEvents(remaining).filter(({ event }) => event !== 'message_start');
352
+ for (const event of rest) {
353
+ if (typeof event.data?.index === 'number') {
354
+ writeEvent(response, { ...event, data: { ...event.data, index: event.data.index + nextIndex } });
355
+ } else {
356
+ writeEvent(response, event);
357
+ }
358
+ }
292
359
  response.end();
293
360
  },
294
361
  fail(error) {
@@ -521,7 +521,16 @@ async function boot() {
521
521
  for (const model of data) {
522
522
  const option = document.createElement('option');
523
523
  option.value = model.id;
524
- option.textContent = ({ glm: 'GLM 5.3', glm52: 'GLM 5.2 (ElevenLabs)' })[model.id] || model.id;
524
+ option.textContent = ({
525
+ hydrogen: 'Gemini 4 Hydrogen',
526
+ gemini: 'Gemini 4 Hydrogen',
527
+ carbon: 'Gemini 4 Carbon',
528
+ neon: 'Gemini 4 Neon',
529
+ argon: 'Gemini 4 Argon',
530
+ gemini3: 'Gemini 3.8 Flash (ElevenLabs)',
531
+ glm: 'GLM 5.3',
532
+ glm52: 'GLM 5.2 (ElevenLabs)'
533
+ })[model.id] || model.id;
525
534
  $('model').appendChild(option);
526
535
  }
527
536
  $('model').value = data.some(m => m.id === preferred) ? preferred : 'glm';
package/src/config.js CHANGED
@@ -1,71 +1,101 @@
1
- const crypto = require('crypto');
2
- const fs = require('fs');
3
- const os = require('os');
4
- const path = require('path');
5
-
6
- const LABS_DIR = process.env.LABS_HOME || path.join(os.homedir(), '.labs');
7
- const CONFIG_PATH = path.join(LABS_DIR, 'config.json');
8
- const LLM_LIST_PATH = path.join(LABS_DIR, 'llm-list.json');
9
- const DEFAULT_PORT = 8081;
10
- const API_BASE = 'https://api.elevenlabs.io/v1/convai';
11
-
12
- // Short names for the strongest current ElevenLabs LLMs; any raw ElevenLabs LLM id also works.
13
- const DEFAULT_MODELS = {
14
- astra: 'gpt-6-astra',
15
- sol: 'gpt-6.1-sol',
16
- terra: 'gpt-5.6-terra',
17
- luna: 'gpt-6-luna',
18
- opus: 'claude-opus-5-5',
19
- sonnet: 'claude-sonnet-5-5',
20
- haiku: 'claude-haiku-4-5',
21
- gemini: 'gemini-3.8-flash',
22
- 'gemini-pro': 'gemini-3.1-pro-preview',
23
- // GLM 5.3 runs on Amazon Bedrock with the user's own AWS key (labs bedrock), not on ElevenLabs.
24
- glm: 'bedrock:us.zai.glm-5.3',
25
- glm52: 'glm-52',
26
- qwen: 'qwen35-397b-a17b',
27
- deepseek: 'deepseek-v41-flash'
28
- };
29
-
30
- function loadConfig() {
31
- if (!fs.existsSync(CONFIG_PATH)) return null;
32
- const stored = JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8'));
33
- return {
34
- port: DEFAULT_PORT,
35
- defaultModel: 'astra',
36
- // ElevenLabs caches only the system prompt, so every token of history is paid at full price on every turn
37
- // (measured 2026-10-08: 8 Opus turns at ~324k context cost $11.98). Claude Code compacts at this size.
38
- contextLimit: 300000,
39
- // Titles, summaries and compaction (requests without tools) ran on Opus/Sonnet; a cheap 1M model does them.
40
- sideModel: 'gemini-3.8-flash',
41
- bedrockRegion: 'us-east-1',
42
- // Bedrock bills every input token on every turn; 200k keeps one GLM 5.3 turn under ~$0.35.
43
- bedrockContextLimit: 200000,
44
- ...stored,
45
- models: { ...DEFAULT_MODELS, ...(stored.models || {}) },
46
- apiKey: process.env.ELEVENLABS_API_KEY || stored.apiKey
47
- };
48
- }
49
-
50
- // A running proxy keeps the key it started with. A short hash lets the launcher see that the key or agent changed
51
- // (a friend switched ElevenLabs accounts and every turn kept failing on the old key) without exposing the key.
52
- function credentialFingerprint(config) {
53
- if (!config?.apiKey) return null;
54
- return crypto.createHash('sha256').update(`${config.apiKey}:${config.bridgeAgent || ''}`).digest('hex').slice(0, 12);
55
- }
56
-
57
- function saveConfig(config) {
58
- fs.mkdirSync(LABS_DIR, { recursive: true });
59
- fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 0o600 });
60
- }
61
-
62
- function loadLlmList() {
63
- return fs.existsSync(LLM_LIST_PATH) ? JSON.parse(fs.readFileSync(LLM_LIST_PATH, 'utf8')) : [];
64
- }
65
-
66
- function saveLlmList(llms) {
67
- fs.mkdirSync(LABS_DIR, { recursive: true });
68
- fs.writeFileSync(LLM_LIST_PATH, JSON.stringify(llms, null, 1));
69
- }
70
-
71
- module.exports = { API_BASE, CONFIG_PATH, DEFAULT_MODELS, LABS_DIR, credentialFingerprint, loadConfig, loadLlmList, saveConfig, saveLlmList };
1
+ const crypto = require('crypto');
2
+ const fs = require('fs');
3
+ const os = require('os');
4
+ const path = require('path');
5
+
6
+ const LABS_DIR = process.env.LABS_HOME || path.join(os.homedir(), '.labs');
7
+ const CONFIG_PATH = path.join(LABS_DIR, 'config.json');
8
+ const LLM_LIST_PATH = path.join(LABS_DIR, 'llm-list.json');
9
+ const DEFAULT_PORT = 8081;
10
+ const API_BASE = 'https://api.elevenlabs.io/v1/convai';
11
+
12
+ // Short names for the strongest current ElevenLabs LLMs; any raw ElevenLabs LLM id also works.
13
+ const DEFAULT_MODELS = {
14
+ astra: 'gpt-6-astra',
15
+ sol: 'gpt-6.1-sol',
16
+ terra: 'gpt-5.6-terra',
17
+ luna: 'gpt-6-luna',
18
+ opus: 'claude-opus-5-5',
19
+ sonnet: 'claude-sonnet-5-5',
20
+ haiku: 'claude-haiku-4-5',
21
+ hydrogen: 'gemini-4-hydrogen',
22
+ gemini: 'gemini-4-hydrogen',
23
+ gem: 'agy:gemini-4-hydrogen',
24
+ 'agy-flash': 'agy:gemini-3.8-flash',
25
+ 'agy-sonnet': 'agy:claude-sonnet-4-6',
26
+ 'agy-opus': 'agy:claude-opus-4-6-thinking',
27
+ 'agy-oss': 'agy:gpt-oss-120b-medium',
28
+ neon: 'gemini-4-neon',
29
+ argon: 'gemini-4-argon',
30
+ nano: 'gemini-4-nano',
31
+ gemini3: 'gemini-3.8-flash',
32
+ 'gemini-pro': 'gemini-3.1-pro-preview',
33
+ // GLM 5.3 runs on Amazon Bedrock with the user's own AWS key (labs bedrock), not on ElevenLabs.
34
+ glm: 'bedrock:us.zai.glm-5.3',
35
+ glm52: 'glm-52',
36
+ qwen: 'qwen35-397b-a17b',
37
+ deepseek: 'deepseek-v41-flash'
38
+ };
39
+
40
+ function withDefaults(stored = {}) {
41
+ return {
42
+ port: DEFAULT_PORT,
43
+ defaultModel: 'astra',
44
+ // ElevenLabs caches only the system prompt, so every token of history is paid at full price on every turn
45
+ // (measured 2026-10-08: 8 Opus turns at ~324k context cost $11.98). Claude Code compacts at this size.
46
+ contextLimit: 300000,
47
+ // Titles, summaries and compaction (requests without tools) ran on Opus/Sonnet; a cheap 1M model does them.
48
+ sideModel: 'gemini-3.8-flash',
49
+ geminiContextLimit: 1000000,
50
+ vertexRegion: 'global',
51
+ bedrockRegion: 'us-east-1',
52
+ // Bedrock bills every input token on every turn; 200k keeps one GLM 5.3 turn under ~$0.35.
53
+ bedrockContextLimit: 200000,
54
+ ...stored,
55
+ models: { ...DEFAULT_MODELS, ...(stored.models || {}) },
56
+ apiKey: process.env.ELEVENLABS_API_KEY || stored.apiKey
57
+ };
58
+ }
59
+
60
+ function loadConfig() {
61
+ if (!fs.existsSync(CONFIG_PATH)) return null;
62
+ return withDefaults(JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8')));
63
+ }
64
+
65
+ function loadEffectiveConfig() {
66
+ const stored = fs.existsSync(CONFIG_PATH) ? JSON.parse(fs.readFileSync(CONFIG_PATH, 'utf8')) : {};
67
+ return withDefaults(stored);
68
+ }
69
+
70
+ // A running proxy keeps the key it started with. A short hash lets the launcher see that the key or agent changed
71
+ // (a friend switched ElevenLabs accounts and every turn kept failing on the old key) without exposing the key.
72
+ function credentialFingerprint(config) {
73
+ if (!config?.apiKey) return null;
74
+ return crypto.createHash('sha256').update(`${config.apiKey}:${config.bridgeAgent || ''}`).digest('hex').slice(0, 12);
75
+ }
76
+
77
+ // The proxy's own code. The version number does not move on every change (a git pull, a dev link), and on
78
+ // 2026-11-28 a proxy from 26 Nov kept serving an old Antigravity bridge: first turns 60-83 s instead of 6 s.
79
+ function codeFingerprint(dir = __dirname) {
80
+ const hash = crypto.createHash('sha256');
81
+ for (const file of fs.readdirSync(dir).filter(f => f.endsWith('.js')).sort()) {
82
+ hash.update(file).update(fs.readFileSync(path.join(dir, file)));
83
+ }
84
+ return hash.digest('hex').slice(0, 12);
85
+ }
86
+
87
+ function saveConfig(config) {
88
+ fs.mkdirSync(LABS_DIR, { recursive: true });
89
+ fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 0o600 });
90
+ }
91
+
92
+ function loadLlmList() {
93
+ return fs.existsSync(LLM_LIST_PATH) ? JSON.parse(fs.readFileSync(LLM_LIST_PATH, 'utf8')) : [];
94
+ }
95
+
96
+ function saveLlmList(llms) {
97
+ fs.mkdirSync(LABS_DIR, { recursive: true });
98
+ fs.writeFileSync(LLM_LIST_PATH, JSON.stringify(llms, null, 1));
99
+ }
100
+
101
+ module.exports = { API_BASE, CONFIG_PATH, DEFAULT_MODELS, LABS_DIR, codeFingerprint, credentialFingerprint, loadConfig, loadEffectiveConfig, loadLlmList, saveConfig, saveLlmList };