Skip to content

Commit a74afb6

Browse files
committed
refactor: Simplify API responses and update agent display logic
1 parent 27f9940 commit a74afb6

File tree

6 files changed

+25
-47
lines changed

6 files changed

+25
-47
lines changed

ui/src/api.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ pub async fn register(
106106
/// Fetch available agents
107107
pub async fn fetch_agents(base_url: &str) -> Result<Vec<AgentInfo>, String> {
108108
let url = format!("{}/api/agents", base_url);
109-
let resp: AgentsListResponse = fetch_with_auth(&url, None).await?;
110-
Ok(resp.agents)
109+
// Backend returns array directly, not wrapped
110+
fetch_with_auth(&url, None).await
111111
}
112112

113113
/// Fetch available workflows (requires auth)
114114
pub async fn fetch_workflows(base_url: &str, token: &str) -> Result<Vec<WorkflowInfo>, String> {
115115
let url = format!("{}/api/workflows", base_url);
116-
let resp: WorkflowsListResponse = fetch_with_auth(&url, Some(token.to_string())).await?;
117-
Ok(resp.workflows)
116+
// Backend returns array directly, not wrapped
117+
fetch_with_auth(&url, Some(token.to_string())).await
118118
}
119119

120120
/// Send a chat message

ui/src/components/agent_selector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ fn AgentOption(
128128
{emoji}
129129
</div>
130130
<div class="flex-1 min-w-0">
131-
<div class="font-medium text-white capitalize">{agent.display_name.clone()}</div>
131+
<div class="font-medium text-white capitalize">{agent.name.clone()}</div>
132132
<div class="text-xs text-slate-400 truncate">{agent.description.clone()}</div>
133133
</div>
134134
<Show when=move || is_selected.get()>

ui/src/components/sidebar.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ pub fn Sidebar(
6969
{move || {
7070
let agents = state.agents.get();
7171
agents.into_iter().map(|agent| {
72-
let name = agent.name.clone();
73-
let name_clone = name.clone();
74-
let emoji = match name.as_str() {
72+
let agent_type = agent.agent_type.clone();
73+
let agent_type_clone = agent_type.clone();
74+
let emoji = match agent_type.as_str() {
7575
"orchestrator" => "🎭",
7676
"product" => "📦",
7777
"sales" => "💰",
@@ -82,11 +82,11 @@ pub fn Sidebar(
8282
};
8383
view! {
8484
<AgentButton
85-
name=agent.display_name.clone()
85+
name=agent.name.clone()
8686
emoji=emoji.to_string()
8787
description=agent.description.clone()
88-
is_selected=Signal::derive(move || selected_agent.get().as_deref() == Some(&name))
89-
on_click=move |_| selected_agent.set(Some(name_clone.clone()))
88+
is_selected=Signal::derive(move || selected_agent.get().as_deref() == Some(&agent_type))
89+
on_click=move |_| selected_agent.set(Some(agent_type_clone.clone()))
9090
/>
9191
}
9292
}).collect::<Vec<_>>()
@@ -108,10 +108,11 @@ pub fn Sidebar(
108108
}.into_any()
109109
} else {
110110
workflows.into_iter().map(|wf| {
111+
let description = format!("Entry: {} | Max depth: {}", wf.entry_agent, wf.max_depth);
111112
view! {
112113
<div class="px-3 py-2 rounded-lg text-sm text-slate-400 hover:bg-slate-700/50 cursor-pointer">
113114
<div class="font-medium text-slate-300">{wf.name.clone()}</div>
114-
<div class="text-xs truncate">{wf.description.clone()}</div>
115+
<div class="text-xs truncate">{description}</div>
115116
</div>
116117
}
117118
}).collect::<Vec<_>>().into_any()

ui/src/pages/home.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ pub fn HomePage() -> impl IntoView {
146146
}).collect::<Vec<_>>()
147147
} else {
148148
agents.into_iter().map(|agent| {
149-
let emoji = match agent.name.as_str() {
149+
let emoji = match agent.agent_type.as_str() {
150150
"orchestrator" => "🎭",
151151
"product" => "📦",
152152
"sales" => "💰",
@@ -158,7 +158,7 @@ pub fn HomePage() -> impl IntoView {
158158
view! {
159159
<AgentCard
160160
emoji=emoji
161-
name=agent.display_name.leak()
161+
name=agent.name.leak()
162162
description=agent.description.leak()
163163
/>
164164
}

ui/src/state.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use crate::types::{AuthResponse, Conversation, AgentInfo, WorkflowInfo};
66

77
const STORAGE_KEY_TOKEN: &str = "ares_token";
88
const STORAGE_KEY_REFRESH: &str = "ares_refresh_token";
9-
const STORAGE_KEY_USER_ID: &str = "ares_user_id";
109

1110
/// Global application state
1211
#[derive(Clone)]
@@ -15,8 +14,6 @@ pub struct AppState {
1514
pub token: RwSignal<Option<String>>,
1615
/// Refresh token
1716
pub refresh_token: RwSignal<Option<String>>,
18-
/// User ID
19-
pub user_id: RwSignal<Option<String>>,
2017
/// Available agents
2118
pub agents: RwSignal<Vec<AgentInfo>>,
2219
/// Available workflows
@@ -34,12 +31,11 @@ pub struct AppState {
3431
impl AppState {
3532
pub fn new() -> Self {
3633
// Try to load from localStorage
37-
let (token, refresh, user_id) = Self::load_from_storage();
34+
let (token, refresh) = Self::load_from_storage();
3835

3936
Self {
4037
token: RwSignal::new(token),
4138
refresh_token: RwSignal::new(refresh),
42-
user_id: RwSignal::new(user_id),
4339
agents: RwSignal::new(vec![]),
4440
workflows: RwSignal::new(vec![]),
4541
conversation: RwSignal::new(Conversation::default()),
@@ -49,31 +45,26 @@ impl AppState {
4945
}
5046
}
5147

52-
fn load_from_storage() -> (Option<String>, Option<String>, Option<String>) {
48+
fn load_from_storage() -> (Option<String>, Option<String>) {
5349
let token: Option<String> = LocalStorage::get(STORAGE_KEY_TOKEN).ok();
5450
let refresh: Option<String> = LocalStorage::get(STORAGE_KEY_REFRESH).ok();
55-
let user_id: Option<String> = LocalStorage::get(STORAGE_KEY_USER_ID).ok();
56-
(token, refresh, user_id)
51+
(token, refresh)
5752
}
5853

5954
pub fn save_auth(&self, auth: &AuthResponse) {
6055
let _ = LocalStorage::set(STORAGE_KEY_TOKEN, &auth.access_token);
6156
let _ = LocalStorage::set(STORAGE_KEY_REFRESH, &auth.refresh_token);
62-
let _ = LocalStorage::set(STORAGE_KEY_USER_ID, &auth.user_id);
6357

6458
self.token.set(Some(auth.access_token.clone()));
6559
self.refresh_token.set(Some(auth.refresh_token.clone()));
66-
self.user_id.set(Some(auth.user_id.clone()));
6760
}
6861

6962
pub fn clear_auth(&self) {
7063
LocalStorage::delete(STORAGE_KEY_TOKEN);
7164
LocalStorage::delete(STORAGE_KEY_REFRESH);
72-
LocalStorage::delete(STORAGE_KEY_USER_ID);
7365

7466
self.token.set(None);
7567
self.refresh_token.set(None);
76-
self.user_id.set(None);
7768
}
7869

7970
pub fn is_authenticated(&self) -> bool {

ui/src/types.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ pub struct RegisterRequest {
2222
pub struct AuthResponse {
2323
pub access_token: String,
2424
pub refresh_token: String,
25-
pub token_type: String,
26-
pub expires_in: u64,
27-
pub user_id: String,
25+
pub expires_in: i64,
2826
}
2927

3028
/// Chat request
@@ -61,32 +59,20 @@ pub struct ToolCallInfo {
6159
/// Agent info from the API
6260
#[derive(Debug, Clone, Deserialize)]
6361
pub struct AgentInfo {
62+
pub agent_type: String,
6463
pub name: String,
65-
pub display_name: String,
6664
pub description: String,
67-
#[serde(default)]
68-
pub capabilities: Vec<String>,
69-
}
70-
71-
/// Agents list response
72-
#[derive(Debug, Clone, Deserialize)]
73-
pub struct AgentsListResponse {
74-
pub agents: Vec<AgentInfo>,
7565
}
7666

7767
/// Workflow info
7868
#[derive(Debug, Clone, Deserialize)]
7969
pub struct WorkflowInfo {
8070
pub name: String,
81-
pub description: String,
82-
pub agents: Vec<String>,
83-
pub max_depth: usize,
84-
}
85-
86-
/// Workflows list response
87-
#[derive(Debug, Clone, Deserialize)]
88-
pub struct WorkflowsListResponse {
89-
pub workflows: Vec<WorkflowInfo>,
71+
pub entry_agent: String,
72+
pub fallback_agent: Option<String>,
73+
pub max_depth: u8,
74+
pub max_iterations: u8,
75+
pub parallel_subagents: bool,
9076
}
9177

9278
/// User memory

0 commit comments

Comments
 (0)