bingocode 1.1.199 → 1.1.200-beta.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bingocode",
3
- "version": "1.1.199",
3
+ "version": "1.1.200-beta.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "claude": "bin/claude-win.cjs",
@@ -51,8 +51,7 @@ type Stage =
51
51
  | 'editing'
52
52
  | 'slot_config'
53
53
  | 'slot_loading'
54
- | 'slot_select_model'
55
- | 'slot_input_label';
54
+ | 'slot_select_model';
56
55
 
57
56
  export const ProviderPanel: React.FC<{
58
57
  apiUrl: string;
@@ -97,9 +96,11 @@ export const ProviderPanel: React.FC<{
97
96
  const [slotProviderModels, setSlotProviderModels] = useState<Record<string, string[]>>({});
98
97
  const [currentSlotName, setCurrentSlotName] = useState<string>('main');
99
98
  const [slotLoadingMsg, setSlotLoadingMsg] = useState<string>('');
100
- const [tempSlotProviderId, setTempSlotProviderId] = useState<string>('');
101
- const [tempSlotModelId, setTempSlotModelId] = useState<string>('');
102
- const [slotLabelInput, setSlotLabelInput] = useState<string>('');
99
+
100
+ // VS Code link status
101
+ const [vscodeLinked, setVscodeLinked] = useState(false);
102
+ const [vscodeLinkedPaths, setVscodeLinkedPaths] = useState<string[]>([]);
103
+
103
104
 
104
105
  const base = apiUrl.replace(/\/+$/, '');
105
106
 
@@ -146,6 +147,16 @@ export const ProviderPanel: React.FC<{
146
147
  loadPresets();
147
148
  }, [loadProviders, loadPresets]);
148
149
 
150
+ // Fetch VS Code link status on mount
151
+ useEffect(() => {
152
+ axios.get(`${base}/api/providers/link-vscode`)
153
+ .then(r => {
154
+ setVscodeLinked(r.data.linked);
155
+ setVscodeLinkedPaths(r.data.paths || []);
156
+ })
157
+ .catch(() => {});
158
+ }, [base]);
159
+
149
160
  // Key processing for Page Up/Down and Arrow keys in scrolling lists
150
161
  useEffect(() => {
151
162
  const handler = (buf: Buffer) => {
@@ -320,6 +331,7 @@ export const ProviderPanel: React.FC<{
320
331
  { label: 'Add Provider', value: 'add' },
321
332
  { label: 'Edit Provider (Name/Key)', value: 'edit' },
322
333
  { label: 'Configure Slots', value: 'slots' },
334
+ { label: vscodeLinked ? `Disconnect from VS Code (${vscodeLinkedPaths.length} editor(s))` : 'Connect to VS Code', value: 'link_vscode' },
323
335
  { label: 'Connectivity Test', value: 'test' },
324
336
  { label: 'Delete Provider', value: 'delete' },
325
337
  { label: 'Refresh', value: 'refresh' },
@@ -348,6 +360,33 @@ export const ProviderPanel: React.FC<{
348
360
  setStage('slot_config');
349
361
  setListOffset(0);
350
362
  break;
363
+ case 'link_vscode':
364
+ setOpMsg(null);
365
+ setErr(null);
366
+ if (vscodeLinked) {
367
+ // Unlink
368
+ axios.delete(`${base}/api/providers/link-vscode`)
369
+ .then(() => {
370
+ setVscodeLinked(false);
371
+ setVscodeLinkedPaths([]);
372
+ setOpMsg('Disconnected from VS Code.');
373
+ })
374
+ .catch(e => {
375
+ setErr((e as any)?.response?.data?.message || (e as any)?.message || 'Failed to disconnect VS Code');
376
+ });
377
+ } else {
378
+ // Link
379
+ axios.post(`${base}/api/providers/link-vscode`)
380
+ .then(r => {
381
+ setVscodeLinked(true);
382
+ setVscodeLinkedPaths(r.data.paths || []);
383
+ setOpMsg(`Connected to VS Code (${(r.data.paths || []).length} editor(s)).`);
384
+ })
385
+ .catch(e => {
386
+ setErr((e as any)?.response?.data?.message || (e as any)?.message || 'Failed to connect VS Code');
387
+ });
388
+ }
389
+ break;
351
390
  case 'test':
352
391
  setStage('test_select');
353
392
  setListOffset(0);
@@ -780,10 +819,25 @@ export const ProviderPanel: React.FC<{
780
819
  const sepIdx = val.indexOf('::');
781
820
  const providerId = val.slice(0, sepIdx);
782
821
  const modelId = val.slice(sepIdx + 2);
783
- setTempSlotProviderId(providerId);
784
- setTempSlotModelId(modelId);
785
- setSlotLabelInput(modelId);
786
- setStage('slot_input_label');
822
+ axios.put(`${base}/api/providers/slots/${currentSlotName}`, {
823
+ providerId,
824
+ modelId,
825
+ label: null,
826
+ })
827
+ .then(() => {
828
+ setSlotTable(prev => ({
829
+ ...prev,
830
+ [currentSlotName]: { providerId, modelId, label: null }
831
+ }));
832
+ setOpMsg(`Configured [${currentSlotName}] -> ${modelId}`);
833
+ setErr(null);
834
+ setListOffset(0);
835
+ setStage('slot_config');
836
+ })
837
+ .catch(e => {
838
+ setErr((e as any)?.response?.data?.message || (e as any)?.message || 'Save failed');
839
+ setStage('slot_config');
840
+ });
787
841
  }}
788
842
  />
789
843
  </Box>
@@ -794,47 +848,6 @@ export const ProviderPanel: React.FC<{
794
848
  );
795
849
  }
796
850
 
797
- if (stage === 'slot_input_label') {
798
- return (
799
- <Box flexDirection="column" flexGrow={1}>
800
- <Title color="cyan">Configure Slot [{currentSlotName}] — Set Display Name</Title>
801
- <Text>
802
- Model: {providers.find(p => p.id === tempSlotProviderId)?.name || tempSlotProviderId} / {tempSlotModelId}
803
- </Text>
804
- <Box marginTop={1}>
805
- <Text>Display Name (Label): </Text>
806
- <TextInput
807
- value={slotLabelInput}
808
- onChange={setSlotLabelInput}
809
- onSubmit={() => {
810
- const label = slotLabelInput.trim() || tempSlotModelId;
811
- axios.put(`${base}/api/providers/slots/${currentSlotName}`, {
812
- providerId: tempSlotProviderId,
813
- modelId: tempSlotModelId,
814
- label,
815
- })
816
- .then(() => {
817
- setSlotTable(prev => ({
818
- ...prev,
819
- [currentSlotName]: { providerId: tempSlotProviderId, modelId: tempSlotModelId, label }
820
- }));
821
- setOpMsg(`Configured [${currentSlotName}] -> ${label}`);
822
- setErr(null);
823
- setListOffset(0);
824
- setStage('slot_config');
825
- })
826
- .catch(e => {
827
- setErr((e as any)?.response?.data?.message || (e as any)?.message || 'Save failed');
828
- setStage('slot_config');
829
- });
830
- }}
831
- />
832
- </Box>
833
- <Hint>Enter: Save (Display name in UI) · ESC: Back to Models</Hint>
834
- </Box>
835
- );
836
- }
837
-
838
851
  return null;
839
852
  };
840
853
 
@@ -26,6 +26,9 @@ import type { SlotName } from '../types/provider.js'
26
26
  import { ApiError, errorResponse } from '../middleware/errorHandler.js'
27
27
 
28
28
  const providerService = new ProviderService()
29
+ providerService.init().catch((err) =>
30
+ console.error('[ProviderService] init failed:', err),
31
+ )
29
32
 
30
33
  function maskApiKey(key: string): string {
31
34
  if (key.length <= 8) return '****'
@@ -76,6 +79,23 @@ export async function handleProvidersApi(
76
79
  return Response.json(slots)
77
80
  }
78
81
 
82
+ // /api/providers/link-vscode — manage VS Code linking
83
+ if (id === 'link-vscode' && !action) {
84
+ if (req.method === 'GET') {
85
+ const status = await providerService.getVscodeStatus()
86
+ return Response.json(status)
87
+ }
88
+ if (req.method === 'POST') {
89
+ const result = await providerService.linkVscode()
90
+ return Response.json(result)
91
+ }
92
+ if (req.method === 'DELETE') {
93
+ const result = await providerService.unlinkVscode()
94
+ return Response.json(result)
95
+ }
96
+ throw methodNotAllowed(req.method)
97
+ }
98
+
79
99
  // PUT /api/providers/slots/:slotName — set one slot
80
100
  if (id === 'slots' && action && req.method === 'PUT') {
81
101
  const parsed = SlotNameSchema.safeParse(action)
@@ -41,6 +41,44 @@ const MANAGED_ENV_KEYS = [
41
41
  'ANTHROPIC_DEFAULT_OPUS_MODEL',
42
42
  ] as const
43
43
 
44
+ const CLAUDE_DEFAULT_LABELS: Record<SlotName, string> = {
45
+ main: 'claude-sonnet-4-5',
46
+ haiku: 'claude-haiku-4-5',
47
+ sonnet: 'claude-sonnet-4-5',
48
+ opus: 'claude-opus-4-7',
49
+ }
50
+
51
+ const VSCODE_EDITOR_NAMES = ['Code', 'Code - Insiders', 'Cursor'] as const
52
+
53
+ /**
54
+ * Return candidate VS Code settings.json paths for the current platform.
55
+ * These are checked for existence (editor directory must exist) before writing.
56
+ */
57
+ function getVscodeSettingsPaths(): string[] {
58
+ const home = os.homedir()
59
+ const paths: string[] = []
60
+
61
+ if (process.platform === 'win32') {
62
+ const appData = process.env.APPDATA || path.join(home, 'AppData', 'Roaming')
63
+ for (const name of VSCODE_EDITOR_NAMES) {
64
+ paths.push(path.join(appData, name, 'User', 'settings.json'))
65
+ }
66
+ } else if (process.platform === 'darwin') {
67
+ const lib = path.join(home, 'Library', 'Application Support')
68
+ for (const name of VSCODE_EDITOR_NAMES) {
69
+ paths.push(path.join(lib, name, 'User', 'settings.json'))
70
+ }
71
+ } else {
72
+ // Linux / other Unix
73
+ const config = path.join(home, '.config')
74
+ for (const name of VSCODE_EDITOR_NAMES) {
75
+ paths.push(path.join(config, name, 'User', 'settings.json'))
76
+ }
77
+ }
78
+
79
+ return paths
80
+ }
81
+
44
82
  const DEFAULT_INDEX: ProvidersIndex = { activeId: null, providers: [] }
45
83
 
46
84
  export class ProviderService {
@@ -476,12 +514,172 @@ export class ProviderService {
476
514
  const index = await this.readIndex()
477
515
  const provider = index.providers.find((p) => p.id === entry.providerId)
478
516
  if (!provider) return null
517
+
518
+ // Auto-fill Claude model names as label when user hasn't set one.
519
+ // This lets closed-source clients (e.g. VS Code extension) see Claude
520
+ // model names while the CLI continues to show the real upstream modelId
521
+ // (syncSettingsForSlots reads raw entry.label, which stays null).
479
522
  return {
480
523
  baseUrl: provider.baseUrl,
481
524
  apiKey: provider.apiKey,
482
525
  apiFormat: provider.apiFormat ?? 'anthropic',
483
526
  modelId: entry.modelId,
484
- label: entry.label,
527
+ label: entry.label || CLAUDE_DEFAULT_LABELS[slotName],
528
+ }
529
+ }
530
+
531
+ // --- VS Code linking ---
532
+
533
+ /**
534
+ * Build the environmentVariables array for VS Code claudeCode settings
535
+ * based on current slot configuration. Uses user-set labels or falls back
536
+ * to Claude default model names so the VS Code extension shows the right labels.
537
+ */
538
+ private async buildVscodeEnvVars(): Promise<Array<{ name: string; value: string }>> {
539
+ const slots = await this.readSlots()
540
+ const index = await this.readIndex()
541
+
542
+ function getSlotLabel(slotName: SlotName): string | null {
543
+ const entry = slots[slotName]
544
+ if (!entry) return null
545
+ const provider = index.providers.find((p) => p.id === entry.providerId)
546
+ if (!provider) return null
547
+ return entry.label || CLAUDE_DEFAULT_LABELS[slotName]
548
+ }
549
+
550
+ const envVars: Array<{ name: string; value: string }> = [
551
+ { name: 'ANTHROPIC_BASE_URL', value: `http://127.0.0.1:${ProviderService.serverPort}/proxy` },
552
+ { name: 'ANTHROPIC_AUTH_TOKEN', value: 'proxy-managed' },
553
+ ]
554
+
555
+ const mainLabel = getSlotLabel("main")
556
+ if (mainLabel) {
557
+ envVars.push({ name: "ANTHROPIC_MODEL", value: mainLabel })
558
+ }
559
+ const haikuLabel = getSlotLabel("haiku")
560
+ if (haikuLabel) {
561
+ envVars.push({ name: "ANTHROPIC_DEFAULT_HAIKU_MODEL", value: haikuLabel })
562
+ }
563
+ const sonnetLabel = getSlotLabel("sonnet")
564
+ if (sonnetLabel) {
565
+ envVars.push({ name: "ANTHROPIC_DEFAULT_SONNET_MODEL", value: sonnetLabel })
566
+ }
567
+ const opusLabel = getSlotLabel("opus")
568
+ if (opusLabel) {
569
+ envVars.push({ name: "ANTHROPIC_DEFAULT_OPUS_MODEL", value: opusLabel })
570
+ }
571
+
572
+ return envVars
573
+ }
574
+
575
+ /**
576
+ * Write claudeCode settings into ALL detected VS Code editor instances
577
+ * (stable, Insiders, Cursor). Persists linked state in bingo settings so
578
+ * it survives restarts.
579
+ */
580
+ async linkVscode(): Promise<{ paths: string[]; linked: boolean }> {
581
+ const envVars = await this.buildVscodeEnvVars()
582
+ const candidatePaths = getVscodeSettingsPaths()
583
+ const writtenPaths: string[] = []
584
+
585
+ for (const settingsPath of candidatePaths) {
586
+ // Only write if the editor config directory exists (editor is installed)
587
+ const editorDir = path.dirname(path.dirname(settingsPath))
588
+ try {
589
+ await fs.access(editorDir)
590
+ } catch {
591
+ continue
592
+ }
593
+
594
+ let settings: Record<string, unknown> = {}
595
+ try {
596
+ const raw = await fs.readFile(settingsPath, "utf-8")
597
+ settings = JSON.parse(raw)
598
+ } catch {
599
+ // File does not exist yet — start fresh
600
+ }
601
+
602
+ settings.claudeCode = {
603
+ ...(settings.claudeCode as Record<string, unknown> || {}),
604
+ preferredLocation: "panel",
605
+ disableLoginPrompt: true,
606
+ environmentVariables: envVars,
607
+ }
608
+
609
+ await fs.mkdir(path.dirname(settingsPath), { recursive: true })
610
+ await fs.writeFile(settingsPath, JSON.stringify(settings, null, 4) + '\n')
611
+ writtenPaths.push(settingsPath)
612
+ }
613
+
614
+ if (writtenPaths.length === 0) {
615
+ throw ApiError.badRequest(
616
+ 'No VS Code installation detected. Please install VS Code (stable, Insiders, or Cursor) first.',
617
+ )
618
+ }
619
+
620
+ // Persist so re-sync on restart and unlink work correctly
621
+ const bingoSettings = await this.readSettings()
622
+ bingoSettings.vscodeLinked = true
623
+ bingoSettings.vscodeLinkedPaths = writtenPaths
624
+ await this.writeSettings(bingoSettings)
625
+
626
+ return { paths: writtenPaths, linked: true }
627
+ }
628
+
629
+ /**
630
+ * Remove claudeCode keys from all previously-linked VS Code settings files.
631
+ * Does NOT delete the entire file — it only removes the claudeCode key.
632
+ */
633
+ async unlinkVscode(): Promise<{ paths: string[]; linked: boolean }> {
634
+ const bingoSettings = await this.readSettings()
635
+ const linkedPaths = (bingoSettings.vscodeLinkedPaths as string[]) || []
636
+
637
+ for (const settingsPath of linkedPaths) {
638
+ try {
639
+ const raw = await fs.readFile(settingsPath, "utf-8")
640
+ const settings = JSON.parse(raw)
641
+ delete settings.claudeCode
642
+ await fs.writeFile(settingsPath, JSON.stringify(settings, null, 4) + '\n')
643
+ } catch {
644
+ // File may have been moved or deleted since linking — harmless
645
+ }
646
+ }
647
+
648
+ bingoSettings.vscodeLinked = false
649
+ delete bingoSettings.vscodeLinkedPaths
650
+ await this.writeSettings(bingoSettings)
651
+
652
+ return { paths: linkedPaths, linked: false }
653
+ }
654
+
655
+ /**
656
+ * Return current VS Code link status from persisted bingo settings.
657
+ */
658
+ async getVscodeStatus(): Promise<{ linked: boolean; paths: string[] }> {
659
+ const bingoSettings = await this.readSettings()
660
+ return {
661
+ linked: Boolean(bingoSettings.vscodeLinked),
662
+ paths: (bingoSettings.vscodeLinkedPaths as string[]) || [],
663
+ }
664
+ }
665
+
666
+ /**
667
+ * Initialise the service. If vscodeLinked is true in bingo settings,
668
+ * re-sync VS Code settings so they stay current with the slot config.
669
+ * Should be called once after server startup.
670
+ */
671
+ async init(): Promise<void> {
672
+ const status = await this.getVscodeStatus()
673
+ if (status.linked) {
674
+ try {
675
+ await this.linkVscode()
676
+ } catch {
677
+ // VS Code may have been uninstalled — clear stale state
678
+ const bingoSettings = await this.readSettings()
679
+ bingoSettings.vscodeLinked = false
680
+ delete bingoSettings.vscodeLinkedPaths
681
+ await this.writeSettings(bingoSettings)
682
+ }
485
683
  }
486
684
  }
487
685