Files
sovereign_browser/src/agent_chat.c
T

50 lines
1.4 KiB
C

/*
* agent_chat.c — high-level entry point for the embedded agent chat
*
* Bridges the URL bar to the agent loop and the chat UI page.
*/
#include "agent_chat.h"
#include "agent_loop.h"
#include "agent_chat_store.h"
#include "tab_manager.h"
#include <string.h>
#include <webkit2/webkit2.h>
#define AGENT_CHAT_URL "sovereign://agents/chat"
int agent_chat_route_input(const char *message) {
tab_info_t *tab = tab_manager_get_active();
if (tab == NULL || tab->webview == NULL) {
g_printerr("[agent_chat] no active tab\n");
return -1;
}
/* Sidebar-aware behavior: if the agent sidebar is already visible,
* just send the message (don't navigate away from the current page).
* If the sidebar is not visible, toggle it on first — this opens
* the chat in the sidebar alongside the current web page, then
* sends the message. This lets the user chat about the page they're
* viewing without navigating away from it. */
if (!tab_manager_sidebar_visible()) {
tab_manager_toggle_sidebar();
}
/* If a non-empty message was provided, start the agent loop. The
* sidebar webview polls sovereign://agents/messages and will pick
* up the agent's responses automatically. */
if (message != NULL && message[0] != '\0') {
if (agent_loop_run(message) != 0) {
g_printerr("[agent_chat] agent_loop_run failed\n");
return -1;
}
}
return 0;
}
const char *agent_chat_session_id(void) {
return agent_chat_store_session_id();
}