summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/contexts/SettingsContext.ts
blob: 610a778d1c90bd5fac44d516c0938fd76f765612 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { createContext, useContext } from 'react';
import { LoadedSettings } from '../../config/settings.js';

export interface SettingsContextType {
  settings: LoadedSettings;
  recomputeSettings: () => void;
}

// This context is initialized in gemini.tsx with the loaded settings.
export const SettingsContext = createContext<SettingsContextType | null>(null);

export function useSettings(): LoadedSettings {
  const context = useContext(SettingsContext);
  if (!context) {
    throw new Error('useSettings must be used within a SettingsProvider');
  }
  return context.settings;
}