mod protocol;
mod threads;
mod timeline;
use anyhow::Result;
use serde_json::Value;
use super::helpers::emit_unhandled_notification_notice;
use crate::state::BridgeState;
pub(super) async fn handle_notification(
state: &BridgeState,
runtime_id: &str,
method: &str,
params: Value,
) -> Result<()> {
let render_params = params.clone();
let result = match method {
"thread/started" => threads::handle_thread_started(state, runtime_id, params).await,
"thread/status/changed" => {
threads::handle_thread_status_changed(state, runtime_id, params).await
}
"thread/name/updated" => {
threads::handle_thread_name_updated(state, runtime_id, params).await
}
"thread/archived" => threads::handle_thread_archived(state, runtime_id, params).await,
"thread/unarchived" => threads::handle_thread_unarchived(state, runtime_id, params).await,
"thread/closed" => threads::handle_thread_closed(state, runtime_id, params).await,
"thread/tokenUsage/updated" => {
threads::handle_thread_token_usage_updated(state, runtime_id, params).await
}
"configWarning" => protocol::handle_config_warning(state, runtime_id, params).await,
"deprecationNotice" => protocol::handle_deprecation_notice(state, runtime_id, params).await,
"model/rerouted" => protocol::handle_model_rerouted(state, runtime_id, params).await,
"command/exec/outputDelta" => {
protocol::handle_command_exec_output_delta(state, runtime_id, params).await
}
"serverRequest/resolved" => {
protocol::handle_server_request_resolved(state, runtime_id, params).await
}
"error" => protocol::handle_error_notification(state, runtime_id, params).await,
"turn/started" => timeline::handle_turn_started(state, runtime_id, params).await,
"item/agentMessage/delta"
| "item/commandExecution/outputDelta"
| "item/fileChange/outputDelta"
| "turn/diff/updated"
| "turn/plan/updated"
| "item/started"
| "item/completed"
| "item/plan/delta"
| "item/mcpToolCall/progress"
| "item/reasoning/textDelta"
| "item/reasoning/summaryPartAdded"
| "item/reasoning/summaryTextDelta"
| "thread/compacted"
| "hook/started"
| "hook/completed"
| "item/autoApprovalReview/started"
| "item/autoApprovalReview/completed"
| "item/commandExecution/terminalInteraction" => Ok(()),
"turn/completed" => timeline::handle_turn_completed(state, runtime_id, params).await,
_ => emit_unhandled_notification_notice(state, runtime_id, method, ¶ms),
};
if result.is_ok() {
state.apply_thread_render_notification(runtime_id, method, &render_params)?;
}
result
}