fix(ai): add reset for models_ac and streamline model autocomplete handling

Replace the custom ai_models_find function with a dedicated
ai_models_ac autocomplete list. Update the /ai switch trigger to
include a trailing space for consistent parsing.
This commit is contained in:
2026-05-13 12:59:29 +00:00
parent 277c82fb5d
commit 2f1637ca8e
2 changed files with 3 additions and 40 deletions

View File

@@ -406,37 +406,6 @@ ai_providers_find(const char* const search_str, gboolean previous, void* context
return autocomplete_complete(providers_ac, search_str, FALSE, previous);
}
/* Stateful model name finder for autocomplete.
* Uses the current session's provider models for completion. */
gchar*
ai_models_find(const char* const search_str, gboolean previous, void* context)
{
ProfAiWin* aiwin = (ProfAiWin*)context;
if (!aiwin || !aiwin->session) {
return NULL;
}
AIProvider* provider = aiwin->session->provider;
if (!provider || !provider->models) {
return NULL;
}
/* Create a temporary autocomplete for models */
Autocomplete models_ac = autocomplete_new();
GList* curr = provider->models;
while (curr) {
autocomplete_add(models_ac, curr->data);
curr = g_list_next(curr);
}
/* NULL search_str is treated as empty string for cycling */
const char* effective_search = (search_str != NULL) ? search_str : "";
gchar* result = autocomplete_complete(models_ac, effective_search, FALSE, previous);
autocomplete_free(models_ac);
return result;
}
/* Reset the provider autocomplete state.
* Called from cmd_ac_reset() to clear autocomplete state when the user presses Ctrl+C. */
void

View File

@@ -469,7 +469,8 @@ static Autocomplete* all_acs[] = {
&ai_subcommands_ac,
&ai_set_subcommands_ac,
&ai_set_custom_subcommands_ac,
&ai_remove_subcommands_ac
&ai_remove_subcommands_ac,
&ai_models_ac
};
static GHashTable* ac_funcs = NULL;
@@ -4566,7 +4567,7 @@ _ai_autocomplete(ProfWin* window, const char* const input, gboolean previous)
}
// /ai switch <provider> <model> - autocomplete model names for specified provider
result = _ai_model_autocomplete(window, input, previous, "/ai switch");
result = _ai_model_autocomplete(window, input, previous, "/ai switch ");
if (result) {
return result;
}
@@ -4576,13 +4577,6 @@ _ai_autocomplete(ProfWin* window, const char* const input, gboolean previous)
return result;
}
// /ai switch <model> - autocomplete model names from current session's provider
ProfAiWin* aiwin = (window && window->type == WIN_AI) ? (ProfAiWin*)window : NULL;
result = autocomplete_param_with_func(input, "/ai switch", ai_models_find, previous, aiwin);
if (result) {
return result;
}
// /ai models <provider> - autocomplete provider names
result = autocomplete_param_with_func(input, "/ai models", ai_providers_find, previous, NULL);
if (result) {