mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-29 08:26:22 +00:00
refactor(ai): consolidate per-provider prefs into [ai/<name>] sections
Per-provider state used to live as flat keys in [ai] with naming conventions to avoid collisions: <name>_url, <name>_models, <name>_default_model, and the bare <name> for the API token. Custom settings (/ai set custom) never made it to disk at all — they only lived in the runtime AIProvider.settings hash table and were lost on restart. Move every per-provider field into a [ai/<name>] subsection of the keyfile with stable key names: [ai/openai] url=https://api.openai.com/ key=sk-... default_model=gpt-4 models=gpt-4;gpt-3.5-turbo setting.tools=enabled [ai] now keeps only the global "defaults_initialized" sentinel. Migration runs once in _prefs_load: collect provider names from the old <name>_url keys, then move url/models/default_model/token of each provider into its subsection and drop the flat keys. Idempotent on subsequent loads. prefs_ai_* API surface kept compatible; storage backend changes only. Adds: prefs_ai_remove_section() — wipe whole subsection in one call prefs_ai_{set,get,remove,list}_setting() — persist custom settings ai_client wiring: - ai_set_provider_setting now writes to prefs as well as the runtime hash table; ai_client_init loads them back on startup. - ai_remove_provider replaces four prefs_ai_remove_* calls with a single prefs_ai_remove_section.
This commit is contained in:
@@ -374,6 +374,10 @@ GList* prefs_ai_list_providers(void);
|
||||
void prefs_free_ai_providers(GList* providers);
|
||||
GList* prefs_ai_get_providers(void);
|
||||
|
||||
/* Wipe the whole [ai/<provider>] subsection (url, key, models, default_model,
|
||||
* custom settings) in one call. */
|
||||
gboolean prefs_ai_remove_section(const char* const provider);
|
||||
|
||||
/* AI model cache management */
|
||||
gboolean prefs_ai_set_models(const char* const provider, const gchar* const* models, gint count);
|
||||
gboolean prefs_ai_remove_models(const char* const provider);
|
||||
@@ -385,4 +389,12 @@ gboolean prefs_ai_set_default_model(const char* const provider, const char* cons
|
||||
gboolean prefs_ai_remove_default_model(const char* const provider);
|
||||
char* prefs_ai_get_default_model(const char* const provider);
|
||||
|
||||
/* AI per-provider custom settings (e.g. tools, search) — persisted as
|
||||
* setting.<name>=<value> inside [ai/<provider>]. Pass NULL value to remove. */
|
||||
gboolean prefs_ai_set_setting(const char* const provider, const char* const setting, const char* const value);
|
||||
gboolean prefs_ai_remove_setting(const char* const provider, const char* const setting);
|
||||
char* prefs_ai_get_setting(const char* const provider, const char* const setting);
|
||||
GList* prefs_ai_list_settings(const char* const provider);
|
||||
void prefs_free_ai_settings(GList* settings);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user