Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
610 changes: 605 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"crates/dir_checksum",
"crates/file_tools",
"crates/shell_tools",
"crates/mcp",

"crates/core/dlt_tools",
"crates/core/someip_tools",
Expand Down Expand Up @@ -58,6 +59,7 @@ session = { path = "crates/core/session" }
session_core = { package = "session", path = "crates/core/session" }
sources = { path = "crates/core/sources" }
stypes = { path = "crates/stypes" }
mcp = { path = "crates/mcp" }

# External dependencies
log = "0.4"
Expand Down
1 change: 1 addition & 0 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ file_tools.workspace = true
shell_tools.workspace = true
parsers.workspace = true
plugins_host.workspace = true
mcp.workspace = true
#TODO: We need to avoid clashing with module `session` in Workaround to avoid potential merge conflict
session_core.workspace = true

Expand Down
6 changes: 5 additions & 1 deletion crates/app/src/host/communication.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use tokio::sync::mpsc;
use tokio::sync::{broadcast, mpsc};

use crate::{
common::comm_utls::evaluate_send_res,
host::{command::HostCommand, message::HostMessage, notification::AppNotification},
session::communication::SharedSenders,
};
use mcp::server::tasks::Tasks;

const CHANNELS_CAPACITY: usize = 32;

Expand Down Expand Up @@ -36,6 +37,7 @@ pub struct ServiceHandle {
/// Provide functions to send host messages and waking up the UI on them.
#[derive(Debug, Clone)]
pub struct ServiceSenders {
pub mcp_task_tx: broadcast::Sender<Tasks>,
message_tx: mpsc::Sender<HostMessage>,
notification_tx: mpsc::Sender<AppNotification>,
egui_ctx: egui::Context,
Expand Down Expand Up @@ -78,6 +80,7 @@ pub fn init(egui_ctx: egui::Context) -> (UiHandle, ServiceHandle) {
let (cmd_tx, cmd_rx) = mpsc::channel(CHANNELS_CAPACITY);
let (message_tx, message_rx) = mpsc::channel(CHANNELS_CAPACITY);
let (notification_tx, notification_rx) = mpsc::channel(CHANNELS_CAPACITY);
let (mcp_task_tx, _mcp_task_rx) = broadcast::channel(CHANNELS_CAPACITY);

let ui_senders = UiSenders { cmd_tx };

Expand All @@ -92,6 +95,7 @@ pub fn init(egui_ctx: egui::Context) -> (UiHandle, ServiceHandle) {
};

let service_senders = ServiceSenders {
mcp_task_tx,
message_tx,
notification_tx,
egui_ctx,
Expand Down
7 changes: 7 additions & 0 deletions crates/app/src/host/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::{
use anyhow::Result;
use itertools::Itertools;
use log::trace;
use mcp::server::McpServer;
use tokio::{runtime::Handle, select, sync::mpsc};
use uuid::Uuid;

Expand Down Expand Up @@ -94,8 +95,11 @@ impl HostService {
/// Spawns tokio runtime to run host services and loads startup storage domains.
#[must_use]
pub fn spawn(communication: ServiceHandle) -> HostServiceInit {
let mcp_task_tx = communication.senders.mcp_task_tx.clone();
let (handle_tx, handle_rx) = std::sync::mpsc::channel();

let mcp_server = McpServer::new(mcp_task_tx);

thread::spawn(move || {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
Expand Down Expand Up @@ -153,6 +157,9 @@ impl HostService {
previous_version,
update_settings,
);
if let Err(err) = mcp_server.start().await {
log::error!("MCP Server error: {:?}", err);
}
host.run().await;
});
});
Expand Down
12 changes: 11 additions & 1 deletion crates/app/src/session/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::{ops::RangeInclusive, path::PathBuf};

use std::sync::mpsc::Sender;

use mcp::config::AiConfig;
use processor::{grabber::LineRange, search::filter::SearchFilter};
use session_core::state::IndexedNavigation;
use stypes::GrabbedElement;
Expand All @@ -11,7 +12,7 @@ use crate::host::ui::{
session_setup::state::sources::StreamConfig,
storage::recent::session::RecentSessionStateSnapshot,
};
use crate::session::{error::SessionError, types::attachment};
use crate::session::{error::SessionError, message::AiMessage, types::attachment};

/// Represents session specific commands to be sent from UI to session service.
///
Expand Down Expand Up @@ -124,6 +125,15 @@ pub enum SessionCommand {

/// Cancel the running operation with the given id.
CancelOperation { id: Uuid },

/// Send a chat message.
SendChatMessage {
id: Uuid,
message: String,
history: Box<Vec<AiMessage>>,
ai_config: AiConfig,
},

/// Gracefully terminate the session service.
CloseSession,
}
Expand Down
4 changes: 4 additions & 0 deletions crates/app/src/session/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ impl SharedSenders {
egui_ctx,
}
}

pub fn get_mcp_task_subscriber(&self) -> broadcast::Receiver<Tasks> {
self.mcp_task_tx.subscribe()
}
}

/// Contains session communication channels for the UI to communicate with services.
Expand Down
25 changes: 22 additions & 3 deletions crates/app/src/session/message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::HashMap;

use mcp::server::tasks::Tasks;
use mcp::types::Response;
use stypes::{AttachmentInfo, FilterMatch, GrabbedElement, NearestPosition};
use uuid::Uuid;

Expand All @@ -22,12 +24,16 @@ pub enum SessionMessage {
// --- Search ---
//
/// Total number of rows matched by the active search.
SearchResultCountUpdated { count: u64 },
SearchResultCountUpdated {
count: u64,
},

/// Total number of rows currently exposed by the indexed lower table.
/// This can include search results, bookmarked rows, and any other indexed-map entries
/// currently materialized by the backend.
IndexedCountUpdated { count: u64 },
IndexedCountUpdated {
count: u64,
},

/// Search matches found.
SearchResults(Vec<FilterMatch>),
Expand Down Expand Up @@ -62,7 +68,9 @@ pub enum SessionMessage {
},

/// Source has been added to session.
SourceAdded { observe_op: Box<ObserveOperation> },
SourceAdded {
observe_op: Box<ObserveOperation>,
},

/// Triggered when a file is opened within the session.
/// Although `chipmunk` continues to monitor the file for changes,
Expand All @@ -82,6 +90,11 @@ pub enum SessionMessage {
target: attachment::PreviewTarget,
preview: Result<attachment::PreviewContent, SessionError>,
},

ChatResponseReceived(Response),

/// Process the task received from the MCP server
MCPTaskReceived(Tasks),
}

/// Bookmark mutation confirmed by the session backend.
Expand All @@ -90,3 +103,9 @@ pub struct BookmarkUpdate {
pub row: u64,
pub is_bookmarked: bool,
}

#[derive(Debug, Clone)]
pub enum AiMessage {
Prompt(String),
Response(Response),
}
Loading
Loading