ref(ai): move unfitting functions out of window.c; create aiwin.c
Some checks failed
CI Code / Check coding style (pull_request) Failing after 34s
CI Code / Check spelling (pull_request) Successful in 22s
CI Code / Linux (arch) (pull_request) Failing after 2m57s
CI Code / Linux (ubuntu) (pull_request) Failing after 3m16s
CI Code / Linux (debian) (pull_request) Failing after 6m16s
CI Code / Code Coverage (pull_request) Successful in 7m12s
Some checks failed
CI Code / Check coding style (pull_request) Failing after 34s
CI Code / Check spelling (pull_request) Successful in 22s
CI Code / Linux (arch) (pull_request) Failing after 2m57s
CI Code / Linux (ubuntu) (pull_request) Failing after 3m16s
CI Code / Linux (debian) (pull_request) Failing after 6m16s
CI Code / Code Coverage (pull_request) Successful in 7m12s
This commit is contained in:
@@ -33,6 +33,7 @@ core_sources = \
|
|||||||
src/ui/window_list.c src/ui/window_list.h \
|
src/ui/window_list.c src/ui/window_list.h \
|
||||||
src/ui/rosterwin.c src/ui/occupantswin.c \
|
src/ui/rosterwin.c src/ui/occupantswin.c \
|
||||||
src/ui/buffer.c src/ui/buffer.h \
|
src/ui/buffer.c src/ui/buffer.h \
|
||||||
|
src/ui/aiwin.c \
|
||||||
src/ui/chatwin.c \
|
src/ui/chatwin.c \
|
||||||
src/ui/mucwin.c \
|
src/ui/mucwin.c \
|
||||||
src/ui/privwin.c \
|
src/ui/privwin.c \
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "config/preferences.h"
|
#include "config/preferences.h"
|
||||||
#include "ui/window.h"
|
|
||||||
#include "profanity.h"
|
#include "profanity.h"
|
||||||
|
#include "ui/ui.h"
|
||||||
|
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|||||||
65
src/ui/aiwin.c
Normal file
65
src/ui/aiwin.c
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* aiwin.c - AI Chat Window Management
|
||||||
|
*
|
||||||
|
* Provides functions for managing the AI chat window (ProfAiWin) in the
|
||||||
|
* profanity client. This includes retrieving window strings for identification,
|
||||||
|
* displaying AI/LLM responses in the chat view, and handling error messages
|
||||||
|
* from AI interactions.
|
||||||
|
*
|
||||||
|
* Key functions:
|
||||||
|
* aiwin_get_string() - Returns a descriptive string for the window
|
||||||
|
* aiwin_display_response() - Displays an AI/LLM response and appends it
|
||||||
|
* to the conversation history
|
||||||
|
* aiwin_display_error() - Displays an error message from AI operations
|
||||||
|
*
|
||||||
|
* vim: expandtab:ts=4:sts=4:sw=4
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "ai/ai_client.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "ui/ui.h"
|
||||||
|
#include "ui/win_types.h"
|
||||||
|
|
||||||
|
char*
|
||||||
|
aiwin_get_string(ProfAiWin* win)
|
||||||
|
{
|
||||||
|
assert(win->memcheck == PROFAIWIN_MEMCHECK);
|
||||||
|
return g_strdup_printf("AI Chat (%s: %s)", win->session->provider_name, win->session->model);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
aiwin_display_response(ProfAiWin* win, const char* response)
|
||||||
|
{
|
||||||
|
log_debug("[AI-WIN] aiwin_display_response ENTER: win=%p, response='%s'", (void*)win, response);
|
||||||
|
assert(win->memcheck == PROFAIWIN_MEMCHECK);
|
||||||
|
|
||||||
|
if (!response) {
|
||||||
|
log_error("[AI-WIN] FAIL: null response");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display AI response
|
||||||
|
win_println(&win->window, THEME_DEFAULT, "<< LLM:", "%s", response);
|
||||||
|
log_debug("[AI-WIN] Displayed AI response");
|
||||||
|
|
||||||
|
// Add to conversation history
|
||||||
|
ai_session_add_message(win->session, "assistant", response);
|
||||||
|
log_debug("[AI-WIN] Added assistant message to session history");
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
aiwin_display_error(ProfAiWin* win, const char* error_msg)
|
||||||
|
{
|
||||||
|
log_debug("[AI-WIN] aiwin_display_error ENTER: win=%p, error='%s'", (void*)win, error_msg);
|
||||||
|
assert(win->memcheck == PROFAIWIN_MEMCHECK);
|
||||||
|
|
||||||
|
const char* msg = error_msg ? error_msg : "Unknown error";
|
||||||
|
win_println(&win->window, THEME_ERROR, "[ERROR]", "%s", msg);
|
||||||
|
|
||||||
|
// Also show error in console so user sees it regardless of active window
|
||||||
|
cons_show_error("AI Error: %s", msg);
|
||||||
|
}
|
||||||
@@ -447,4 +447,9 @@ void notify_invite(const char* const from, const char* const room, const char* c
|
|||||||
void notify(const char* const message, int timeout, const char* const category);
|
void notify(const char* const message, int timeout, const char* const category);
|
||||||
void notify_subscription(const char* const from);
|
void notify_subscription(const char* const from);
|
||||||
|
|
||||||
|
/* AI window */
|
||||||
|
char* aiwin_get_string(ProfAiWin* win);
|
||||||
|
void aiwin_display_response(ProfAiWin* win, const char* response);
|
||||||
|
void aiwin_display_error(ProfAiWin* win, const char* error_msg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -347,16 +347,7 @@ win_create_ai(AISession* session)
|
|||||||
return &new_win->window;
|
return &new_win->window;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
win_ai_free(ProfAiWin* win)
|
|
||||||
{
|
|
||||||
assert(win->memcheck == PROFAIWIN_MEMCHECK);
|
|
||||||
buffer_free(win->message_buffer);
|
|
||||||
g_string_free(win->conversation_history, TRUE);
|
|
||||||
if (win->session) {
|
|
||||||
ai_session_unref(win->session);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
win_get_title(ProfWin* window)
|
win_get_title(ProfWin* window)
|
||||||
@@ -2424,45 +2415,3 @@ get_enc_char(prof_enc_t enc_mode, const char* alt)
|
|||||||
else
|
else
|
||||||
return get_show_char(enc_mode);
|
return get_show_char(enc_mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// AI Window Functions
|
|
||||||
|
|
||||||
char*
|
|
||||||
aiwin_get_string(ProfAiWin* win)
|
|
||||||
{
|
|
||||||
assert(win->memcheck == PROFAIWIN_MEMCHECK);
|
|
||||||
return g_strdup_printf("AI Chat (%s: %s)", win->session->provider_name, win->session->model);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
aiwin_display_response(ProfAiWin* win, const char* response)
|
|
||||||
{
|
|
||||||
log_debug("[AI-WIN] aiwin_display_response ENTER: win=%p, response='%s'", (void*)win, response);
|
|
||||||
assert(win->memcheck == PROFAIWIN_MEMCHECK);
|
|
||||||
|
|
||||||
if (!response) {
|
|
||||||
log_error("[AI-WIN] FAIL: null response");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display AI response
|
|
||||||
win_println(&win->window, THEME_DEFAULT, "<< LLM:", "%s", response);
|
|
||||||
log_debug("[AI-WIN] Displayed AI response");
|
|
||||||
|
|
||||||
// Add to conversation history
|
|
||||||
ai_session_add_message(win->session, "assistant", response);
|
|
||||||
log_debug("[AI-WIN] Added assistant message to session history");
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
aiwin_display_error(ProfAiWin* win, const char* error_msg)
|
|
||||||
{
|
|
||||||
log_debug("[AI-WIN] aiwin_display_error ENTER: win=%p, error='%s'", (void*)win, error_msg);
|
|
||||||
assert(win->memcheck == PROFAIWIN_MEMCHECK);
|
|
||||||
|
|
||||||
const char* msg = error_msg ? error_msg : "Unknown error";
|
|
||||||
win_println(&win->window, THEME_ERROR, "[ERROR]", "%s", msg);
|
|
||||||
|
|
||||||
// Also show error in console so user sees it regardless of active window
|
|
||||||
cons_show_error("AI Error: %s", msg);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -101,10 +101,5 @@ char* win_quote_autocomplete(ProfWin* window, const char* const input, gboolean
|
|||||||
char* get_show_char(prof_enc_t encryption_mode);
|
char* get_show_char(prof_enc_t encryption_mode);
|
||||||
char* get_enc_char(prof_enc_t enc_mode, const char* alt);
|
char* get_enc_char(prof_enc_t enc_mode, const char* alt);
|
||||||
|
|
||||||
// AI window functions
|
|
||||||
void win_ai_free(ProfAiWin* win);
|
|
||||||
char* aiwin_get_string(ProfAiWin* win);
|
|
||||||
void aiwin_display_response(ProfAiWin* win, const char* response);
|
|
||||||
void aiwin_display_error(ProfAiWin* win, const char* error_msg);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user