mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-18 11:06:21 +00:00
ref(ai): add stub, fix includes, move aiwin_send_message location
This commit is contained in:
@@ -808,12 +808,10 @@ _ai_request_thread(gpointer data)
|
||||
}
|
||||
|
||||
gboolean
|
||||
ai_send_prompt(AISession* session, const gchar* prompt,
|
||||
ai_response_cb response_cb, ai_error_cb error_cb,
|
||||
gpointer user_data)
|
||||
ai_send_prompt(AISession* session, const gchar* prompt, gpointer user_data)
|
||||
{
|
||||
log_debug("[AI-PROMPT] ENTER: session=%p, prompt='%s', response_cb=%p, error_cb=%p, user_data=%p",
|
||||
(void*)session, prompt, (void*)response_cb, (void*)error_cb, user_data);
|
||||
log_debug("[AI-PROMPT] ENTER: session=%p, prompt='%s', user_data=%p",
|
||||
(void*)session, prompt, user_data);
|
||||
|
||||
if (!session || !prompt) {
|
||||
log_error("[AI-PROMPT] FAIL: invalid session or prompt");
|
||||
@@ -824,8 +822,8 @@ ai_send_prompt(AISession* session, const gchar* prompt,
|
||||
gpointer* args = g_new0(gpointer, 6);
|
||||
args[0] = ai_session_ref(session);
|
||||
args[1] = g_strdup(prompt);
|
||||
args[2] = (gpointer)response_cb;
|
||||
args[3] = (gpointer)error_cb;
|
||||
args[2] = (ai_response_cb)aiwin_display_response;
|
||||
args[3] = (ai_error_cb)aiwin_display_error;
|
||||
args[4] = user_data;
|
||||
args[5] = NULL; /* placeholder for built payload */
|
||||
log_debug("[AI-PROMPT] Prepared args, creating thread...");
|
||||
@@ -842,4 +840,4 @@ ai_send_prompt(AISession* session, const gchar* prompt,
|
||||
log_debug("[AI-PROMPT] Thread created successfully: %p", (void*)thread);
|
||||
g_thread_unref(thread);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
@@ -185,13 +185,10 @@ void ai_session_set_model(AISession* session, const gchar* model);
|
||||
* Send a prompt to the AI provider asynchronously.
|
||||
* @param session The AI session containing provider and model
|
||||
* @param prompt The prompt to send
|
||||
* @param response_cb Callback function for successful responses
|
||||
* @param error_cb Callback function for error handling
|
||||
* @param user_data User data to be passed to the callbacks
|
||||
* @return TRUE if the request was successfully queued, FALSE otherwise
|
||||
*/
|
||||
gboolean ai_send_prompt(AISession* session, const gchar* prompt,
|
||||
ai_response_cb response_cb, ai_error_cb error_cb,
|
||||
gpointer user_data);
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,7 +81,6 @@
|
||||
#include "tools/bookmark_ignore.h"
|
||||
#include "tools/editor.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "ui/window.h"
|
||||
#include "ui/ui.h"
|
||||
#include "ui/window_list.h"
|
||||
#include "xmpp/avatar.h"
|
||||
@@ -8377,8 +8376,7 @@ _cmd_execute_default(ProfWin* window, const char* inp)
|
||||
case WIN_AI:
|
||||
{
|
||||
ProfAiWin* aiwin = (ProfAiWin*)window;
|
||||
assert(aiwin->memcheck == PROFAIWIN_MEMCHECK);
|
||||
aiwin_send_message(aiwin, inp, NULL);
|
||||
cl_ev_send_ai_msg(aiwin, inp, NULL);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -10896,10 +10894,7 @@ cmd_ai_correct(ProfWin* window, const char* const command, gchar** args)
|
||||
|
||||
// Resend the prompt
|
||||
cons_show("Correcting message...");
|
||||
ai_send_prompt(aiwin->session, args[1],
|
||||
(ai_response_cb)aiwin_display_response,
|
||||
(ai_error_cb)aiwin_display_error,
|
||||
aiwin);
|
||||
ai_send_prompt(aiwin->session, args[1], aiwin);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,10 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "ai/ai_client.h"
|
||||
#include "log.h"
|
||||
#include "chatlog.h"
|
||||
#include "database.h"
|
||||
@@ -47,7 +49,7 @@
|
||||
#include "event/common.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "ui/inputwin.h"
|
||||
#include "ui/window_list.h"
|
||||
#include "ui/window.h"
|
||||
#include "xmpp/chat_session.h"
|
||||
#include "xmpp/session.h"
|
||||
#include "xmpp/xmpp.h"
|
||||
@@ -284,3 +286,24 @@ allow_unencrypted_message(ProfChatWin* chatwin, const char* const msg)
|
||||
win_println((ProfWin*)chatwin, THEME_ERROR, "-", "Message not sent: invalid encryption mode (%s). Use '/force-encryption policy resend-to-confirm'.", force_enc_mode);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
cl_ev_send_ai_msg(ProfAiWin* aiwin, const char* const message, const char* const id)
|
||||
{
|
||||
if (!aiwin || !message) {
|
||||
return;
|
||||
}
|
||||
|
||||
assert(aiwin->memcheck == PROFAIWIN_MEMCHECK);
|
||||
|
||||
if (!aiwin->session) {
|
||||
log_error("[AI] AI session not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
// Display user message in AI window.
|
||||
win_print_outgoing(&aiwin->window, ">>", id, NULL, message);
|
||||
|
||||
// Send to AI provider.
|
||||
ai_send_prompt(aiwin->session, message, aiwin);
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ void cl_ev_send_msg(ProfChatWin* chatwin, const char* const msg, const char* con
|
||||
void cl_ev_send_muc_msg_corrected(ProfMucWin* mucwin, const char* const msg, const char* const oob_url, gboolean correct_last_msg);
|
||||
void cl_ev_send_muc_msg(ProfMucWin* mucwin, const char* const msg, const char* const oob_url);
|
||||
void cl_ev_send_priv_msg(ProfPrivateWin* privwin, const char* const msg, const char* const oob_url);
|
||||
void cl_ev_send_ai_msg(ProfAiWin* aiwin, const char* const message, const char* const id);
|
||||
|
||||
// Checks if an unencrypted message can be sent based on encryption preferences.
|
||||
// Returns TRUE if allowed, FALSE if blocked.
|
||||
|
||||
@@ -2434,30 +2434,6 @@ aiwin_get_string(ProfAiWin* win)
|
||||
return g_strdup_printf("AI Chat (%s: %s)", win->session->provider_name, win->session->model);
|
||||
}
|
||||
|
||||
void
|
||||
aiwin_send_message(ProfAiWin* win, const char* message, const char* id)
|
||||
{
|
||||
log_debug("[AI-WIN] aiwin_send_message ENTER: win=%p, message='%s'", (void*)win, message);
|
||||
assert(win->memcheck == PROFAIWIN_MEMCHECK);
|
||||
|
||||
if (!win->session) {
|
||||
log_error("[AI-WIN] FAIL: AI session not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
// Display user message
|
||||
win_print_outgoing(&win->window, ">>", id, NULL, message);
|
||||
log_debug("[AI-WIN] Displayed user message");
|
||||
|
||||
// Send to AI (ai_send_prompt adds message to history internally)
|
||||
log_debug("[AI-WIN] Calling ai_send_prompt...");
|
||||
gboolean result = ai_send_prompt(win->session, message,
|
||||
(ai_response_cb)aiwin_display_response,
|
||||
(ai_error_cb)aiwin_display_error,
|
||||
win);
|
||||
log_debug("[AI-WIN] ai_send_prompt returned: %d", result);
|
||||
}
|
||||
|
||||
void
|
||||
aiwin_display_response(ProfAiWin* win, const char* response)
|
||||
{
|
||||
|
||||
@@ -104,7 +104,6 @@ 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_send_message(ProfAiWin* win, const char* message, const char* id);
|
||||
void aiwin_display_response(ProfAiWin* win, const char* response);
|
||||
void aiwin_display_error(ProfAiWin* win, const char* error_msg);
|
||||
|
||||
|
||||
@@ -28,3 +28,14 @@ aiwin_display_error(ProfAiWin* win, const char* error_msg)
|
||||
(void)win;
|
||||
(void)error_msg;
|
||||
}
|
||||
|
||||
void
|
||||
win_print_outgoing(ProfWin* window, const char* show_char, const char* const id, const char* const replace_id, const char* const message)
|
||||
{
|
||||
/* Stub: do nothing */
|
||||
(void)window;
|
||||
(void)show_char;
|
||||
(void)id;
|
||||
(void)replace_id;
|
||||
(void)message;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user