Files
sovereign_browser/src/settings.h
T

186 lines
8.2 KiB
C

/*
* settings.h — browser preferences for sovereign_browser
*
* Persists user-configurable settings to ~/.sovereign_browser/settings.conf
* as simple key=value lines. A global singleton is loaded at startup and
* accessed via settings_get().
*/
#ifndef SETTINGS_H
#define SETTINGS_H
#include <glib.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SETTINGS_NEW_TAB_URL_DEFAULT ""
#define SETTINGS_NEW_TAB_URL_MAX 512
#define SETTINGS_MAX_TABS_DEFAULT 50
#define SETTINGS_AGENT_PORT_DEFAULT 17777
#define SETTINGS_AGENT_LOGIN_TIMEOUT_DEFAULT 30000 /* ms */
#define SETTINGS_AGENT_ORIGINS_MAX 256
#define SETTINGS_BOOTSTRAP_RELAYS_MAX 2048
#define SETTINGS_BOOTSTRAP_RELAYS_DEFAULT \
"wss://laantungir.net/relay\n" \
"wss://relay.primal.net\n" \
"wss://relay.damus.io"
#define SETTINGS_SEARCH_ENGINE_MAX 64
#define SETTINGS_SEARCH_ENGINE_DEFAULT "duckduckgo"
#define SETTINGS_NOSTR_HELPER_APPS_MAX 1024
#define SETTINGS_NOSTR_HELPER_APPS_DEFAULT \
"njump.me|https://njump.me/{entity},Snort|https://snort.social/{entity},Jumble|https://jumble.social/{entity}"
#define SETTINGS_AGENT_LLM_BASE_URL_DEFAULT "https://api.ppq.ai"
#define SETTINGS_AGENT_LLM_MODEL_DEFAULT "gpt-4o"
#define SETTINGS_AGENT_MAX_ITERATIONS_DEFAULT 100
#define SETTINGS_AGENT_SYSTEM_PROMPT_DEFAULT \
"You are an AI assistant embedded in a web browser. You have access to browser automation tools (navigate, snapshot, click, fill, etc.) and system tools (filesystem read/write, shell command execution). Use the snapshot tool to understand page content, then interact with elements using refs (e.g. @e1). You can read and write files and run shell commands. Be concise in your responses. When a task is complete, summarize what you did."
/* Sovereign Browser Skill — the default skill presented on the config
* page and chat page. The template is the system prompt; the other
* fields describe the skill for publishing as kind 31123. */
#define SETTINGS_AGENT_SKILL_NAME_DEFAULT "Sovereign Browser Default"
#define SETTINGS_AGENT_SKILL_DESCRIPTION_DEFAULT "Default agent skill for sovereign_browser"
#define SETTINGS_AGENT_SKILL_REQUIRES_TOOLS_DEFAULT "browser, fs, shell"
#define SETTINGS_AGENT_SKILL_TEMPLATE_MAX 8192
#define SETTINGS_AGENT_SKILL_NAME_MAX 128
#define SETTINGS_AGENT_SKILL_DESCRIPTION_MAX 512
#define SETTINGS_AGENT_SKILL_REQUIRES_TOOLS_MAX 256
#define SETTINGS_AGENT_MAX_PROVIDERS 16
#define SETTINGS_AGENT_MAX_MODELS 64
#define SETTINGS_AGENT_PROVIDER_NAME_MAX 64
/* A single LLM provider entry in the shared global.agent.providers catalog. */
typedef struct {
char name[SETTINGS_AGENT_PROVIDER_NAME_MAX]; /* e.g. "ppq", "ollama-local" */
char base_url[512];
char api_key[512];
char models[SETTINGS_AGENT_MAX_MODELS][128]; /* list of known model ids */
int model_count;
} agent_provider_t;
typedef struct {
gboolean restore_session; /* restore open tabs on next launch */
char new_tab_url[SETTINGS_NEW_TAB_URL_MAX];
int tab_bar_position; /* GTK_POS_TOP / BOTTOM / LEFT / RIGHT */
gboolean show_tab_close_buttons; /* show per-tab close button */
gboolean middle_click_close; /* middle-click on tab closes it */
gboolean ctrl_tab_switch; /* Ctrl+Tab cycles tabs */
int max_tabs; /* maximum simultaneous tabs */
gboolean tab_drag_reorder; /* allow drag to reorder tabs */
gboolean agent_server_enabled; /* enable agent WebSocket server */
gboolean json_viewer_enabled; /* enhance application/json pages */
int agent_server_port; /* port for agent server */
char agent_allowed_origins[SETTINGS_AGENT_ORIGINS_MAX]; /* "*" for any */
int agent_login_timeout_ms; /* wait for agent login before GTK dialog */
char bootstrap_relays[SETTINGS_BOOTSTRAP_RELAYS_MAX]; /* newline-separated relay URLs */
char search_engine[SETTINGS_SEARCH_ENGINE_MAX]; /* active search engine id */
char nostr_helper_apps[SETTINGS_NOSTR_HELPER_APPS_MAX]; /* comma-separated Name|URL pairs */
gboolean theme_dark; /* dark mode for sovereign:// pages */
int inspector_x; /* inspector detached window X (-1 = default) */
int inspector_y; /* inspector detached window Y (-1 = default) */
int inspector_w; /* inspector detached window width (-1 = default) */
int inspector_h; /* inspector detached window height (-1 = default) */
/* Agent LLM provider settings — "resolved" values for the active
* provider + selected model. Populated from global.agent.providers
* (base_url, api_key) and sovereign_browser.agent (model). */
char agent_llm_base_url[512]; /* e.g. "https://api.openai.com/v1" */
char agent_llm_api_key[512]; /* bearer token (may be empty for local servers) */
char agent_llm_model[128]; /* e.g. "gpt-4o", "llama3.1" */
char agent_llm_system_prompt[4096]; /* legacy alias for agent_skill_template (kept in sync) */
int agent_max_iterations; /* max tool-call loop iterations (default 100) */
/* Sovereign Browser Skill — the default skill presented on the
* config page and chat page. The template is the system prompt
* (mirrored into agent_llm_system_prompt for backward compat).
* Published as kind 31123 when the user clicks "Save as Skill". */
char agent_skill_name[SETTINGS_AGENT_SKILL_NAME_MAX];
char agent_skill_description[SETTINGS_AGENT_SKILL_DESCRIPTION_MAX];
char agent_skill_template[SETTINGS_AGENT_SKILL_TEMPLATE_MAX];
char agent_skill_requires_tools[SETTINGS_AGENT_SKILL_REQUIRES_TOOLS_MAX];
/* Multi-provider catalog (shared via global.agent in d:user-settings). */
agent_provider_t agent_providers[SETTINGS_AGENT_MAX_PROVIDERS];
int agent_provider_count;
int agent_active_provider; /* index into agent_providers, -1 if none */
char agent_active_provider_name[SETTINGS_AGENT_PROVIDER_NAME_MAX];
/* Tor-routed WebKit transport. */
gboolean tor_enabled;
char tor_mode[16]; /* auto | attach | manage */
char tor_binary_path[256];
char tor_attach_socks[256];
char tor_attach_control[256];
char tor_data_dir[512];
/* FIPS mesh daemon. */
gboolean fips_enabled;
char fips_mode[16]; /* auto | attach | manage */
char fips_binary_path[256];
char fips_control_socket[512];
char fips_config_dir[512];
} browser_settings_t;
/*
* Load all settings from the currently-open database into the global
* singleton. Sets defaults first, then reads all keys.
* Backward-compatible — prefer settings_load_global() + settings_load_user()
* for the split-database flow.
*/
void settings_load(void);
/*
* Load global settings (agent server, theme, inspector geometry) from
* the currently-open database (should be global.db). Does NOT reset
* defaults — call settings_set_defaults() first (or use the full
* settings_load() if you need defaults reset).
*/
void settings_load_global(void);
/*
* Load per-user settings (tabs, relays, search engine) from the
* currently-open database (should be the per-user browser.db). Does NOT
* reset defaults — only reads per-user keys, leaving global keys in the
* struct untouched.
*/
void settings_load_user(void);
/*
* Save all settings to the currently-open database.
* Backward-compatible — prefer settings_save_global() + settings_save_user()
* for the split-database flow.
*/
void settings_save(void);
/*
* Save global settings to the currently-open database (should be
* global.db). Call when global settings change.
*/
void settings_save_global(void);
/*
* Save per-user settings to the currently-open database (should be the
* per-user browser.db). Call when per-user settings change.
*/
void settings_save_user(void);
/*
* Get a pointer to the global settings singleton.
* Always valid after settings_load().
*/
const browser_settings_t *settings_get(void);
/*
* Get a mutable pointer to the global settings.
* Used by the settings dialog to modify values; call settings_save() after.
*/
browser_settings_t *settings_get_mutable(void);
#ifdef __cplusplus
}
#endif
#endif /* SETTINGS_H */