Make Codex and Claude Code subscriptions go further: a local model router that gives routine agent work to economical models and keeps your strongest model for the hard parts.
Rust ai-agentsai-gatewayclaude-codecodexcoding-agentcost-optimizationdeepseekllm-gatewayllm-routerlocal-firstmodel-routingrusttask-routingtauri
use super::*;
#[tauri::command]
pub async fn compute_subscriptions(
window: WebviewWindow,
state: State<'_, DesktopState>,
) -> Result<WebComputeSubscriptionCandidatesV2, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::compute_subscriptions(&context, &product_state).await
}
#[tauri::command]
pub async fn check_subscription(
window: WebviewWindow,
state: State<'_, DesktopState>,
candidate: ComputeCandidateRefV2,
language: String,
) -> Result<WebComputeSubscriptionCheckResultV2, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::check_subscription(
&context,
&product_state,
candidate,
language,
)
.await
}
#[tauri::command]
pub async fn get_subscription_check_result(
window: WebviewWindow,
state: State<'_, DesktopState>,
operation: OperationReferenceV1,
) -> Result<WebComputeSubscriptionCheckResultV2, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::get_subscription_check_result(
&context,
&product_state,
operation,
)
.await
}
#[tauri::command]
pub async fn recover_subscription_check(
window: WebviewWindow,
state: State<'_, DesktopState>,
) -> Result<Option<WebComputeSubscriptionCheckResultV2>, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::recover_subscription_check(&context, &product_state).await
}
#[tauri::command]
pub async fn close_subscription_check(
window: WebviewWindow,
state: State<'_, DesktopState>,
) -> Result<(), DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::close_subscription_check(&context, &product_state).await
}
#[tauri::command]
pub async fn release_subscription_check(
window: WebviewWindow,
state: State<'_, DesktopState>,
validation: WebValidationRefV2,
) -> Result<WebComputeSubscriptionCheckResultV2, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::release_subscription_check(
&context,
&product_state,
validation,
)
.await
}
#[tauri::command]
pub async fn compute_key_masks(
window: WebviewWindow,
state: State<'_, DesktopState>,
query: ComputeKeyMasksQueryV1,
) -> Result<ComputeKeyMasksViewV1, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::compute_key_masks(&context, &product_state, query).await
}
#[tauri::command]
pub async fn compute_management_snapshot(
window: WebviewWindow,
state: State<'_, DesktopState>,
) -> Result<ComputeManagementSnapshotV3, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::compute_management_snapshot(&context, &product_state).await
}
#[tauri::command]
pub async fn compute_scan(
window: WebviewWindow,
state: State<'_, DesktopState>,
native_target: Option<hiroute_domain::AgentNativeTargetV1>,
) -> Result<WebComputeScanResultV2, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::compute_scan(&context, &product_state, native_target).await
}
#[tauri::command]
pub async fn prepare_discovered_model_connection(
window: WebviewWindow,
state: State<'_, DesktopState>,
discovery: WebComputeDiscoveryRefV1,
) -> Result<WebComputeCandidateViewV2, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::prepare_discovered_model_connection(
&context,
&product_state,
discovery,
)
.await
}
#[tauri::command]
pub async fn compute_connection_options(
window: WebviewWindow,
state: State<'_, DesktopState>,
) -> Result<ComputeConnectionOptionsResultV1, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::compute_connection_options(&context, &product_state).await
}
#[tauri::command]
pub async fn register_protected_model_input(
window: WebviewWindow,
state: State<'_, DesktopState>,
secret: String,
source_id: Option<String>,
) -> Result<ProtectedModelInputRegistration, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::register_protected_model_input(
&context,
&product_state,
secret,
source_id,
)
.await
}
#[tauri::command]
pub async fn release_protected_model_input(
window: WebviewWindow,
state: State<'_, DesktopState>,
input: ComputeCandidateRefV2,
) -> Result<(), DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::release_protected_model_input(
&context,
&product_state,
input,
)
.await
}
#[tauri::command]
pub async fn check_model_connection(
window: WebviewWindow,
state: State<'_, DesktopState>,
request: NativeModelConnectionCheckRequestV1,
) -> Result<ModelConnectionCheckViewV1, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::check_model_connection(&context, &product_state, request)
.await
}
#[tauri::command]
pub async fn check_saved_model_connection(
window: WebviewWindow,
state: State<'_, DesktopState>,
request: SavedModelConnectionCheckRequestV1,
) -> Result<ModelConnectionCheckViewV1, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::check_saved_model_connection(
&context,
&product_state,
request,
)
.await
}
#[tauri::command]
pub async fn check_registered_model_connection(
window: WebviewWindow,
state: State<'_, DesktopState>,
request: RegisteredModelConnectionCheckRequestV1,
) -> Result<ModelConnectionCheckViewV1, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::check_registered_model_connection(
&context,
&product_state,
request,
)
.await
}
#[tauri::command]
pub async fn cancel_model_connection_check(
window: WebviewWindow,
state: State<'_, DesktopState>,
check_id: String,
) -> Result<(), DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::cancel_model_connection_check(
&context,
&product_state,
check_id,
)
.await
}
#[tauri::command]
pub async fn preview_compute_save(
window: WebviewWindow,
state: State<'_, DesktopState>,
change: WebComputeManagementChangeV2,
) -> Result<WebComputeSavePreviewV2, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::preview_compute_save(&context, &product_state, change).await
}
#[tauri::command]
pub async fn apply_compute_save(
window: WebviewWindow,
state: State<'_, DesktopState>,
request: WebComputeConnectionApplyRequestV1,
language: String,
) -> Result<ModelSaveAccepted, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::apply_compute_save(
&context,
&product_state,
request,
language,
)
.await
}
#[tauri::command]
pub async fn get_compute_save_result(
window: WebviewWindow,
state: State<'_, DesktopState>,
operation: OperationReferenceV1,
) -> Result<WebComputeSaveResultV2, DesktopFailure> {
main_window(&window)?;
let broker = window.state::<WebConfirmationState>();
let active = || window.is_visible().unwrap_or(false);
let notify = |request: &WebConfirmationRequest| {
window
.emit_to(
tauri::EventTarget::webview(window.label()),
"hiroute-web-confirmation",
request,
)
.map_err(|_| "CONFIRMATION_UNAVAILABLE".to_owned())
};
let context = hiroute_product_session::commands::ClientContext {
id: window.label(),
confirmations: &broker,
active: &active,
notify: Some(¬ify),
};
let product_state = hiroute_product_session::commands::CommandState(
&state.0,
&state.1.error,
&state.2,
&state.3,
);
hiroute_product_session::commands::get_compute_save_result(&context, &product_state, operation)
.await
}