Skip to content

Commit d9ce094

Browse files
klopez4212wesbillmanBrain
authored
Improve first-run welcome setup (#970)
Signed-off-by: Wes <[email protected]> Co-authored-by: Wes <[email protected]> Co-authored-by: Brain <21994759fc7a6fa6b965551d35cfd7897d262f2495467f2d78694ddcfa6a5c7e@sprout-oss.stage.blox.sqprod.co>
1 parent 5098640 commit d9ce094

41 files changed

Lines changed: 3711 additions & 410 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎desktop/src-tauri/src/commands/agents.rs‎

Lines changed: 41 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ fn normalize_relay_mesh(
4848
}))
4949
}
5050

51+
fn trim_to_optional_string(value: &str) -> Option<String> {
52+
let trimmed = value.trim();
53+
if trimmed.is_empty() {
54+
None
55+
} else {
56+
Some(trimmed.to_string())
57+
}
58+
}
59+
60+
fn resolve_created_avatar_url(
61+
requested_avatar_url: Option<&str>,
62+
persona_avatar_url: Option<String>,
63+
agent_command: &str,
64+
) -> Option<String> {
65+
requested_avatar_url
66+
.and_then(trim_to_optional_string)
67+
.or_else(|| {
68+
persona_avatar_url
69+
.as_deref()
70+
.and_then(trim_to_optional_string)
71+
})
72+
.or_else(|| managed_agent_avatar_url(agent_command))
73+
}
74+
5175
#[cfg(feature = "mesh-llm")]
5276
async fn ensure_relay_mesh_for_record(
5377
app: &AppHandle,
@@ -474,16 +498,21 @@ pub async fn create_managed_agent(
474498
});
475499

476500
// Resolve the avatar URL once at creation and persist it on the record.
477-
// This is the same logic the original publish used (user input, else
478-
// command-based fallback) — storing it lets reconciliation compare
479-
// against what was actually published instead of re-deriving it.
480-
let resolved_avatar_url = input
481-
.avatar_url
482-
.as_deref()
483-
.map(str::trim)
484-
.filter(|value| !value.is_empty())
485-
.map(str::to_string)
486-
.or_else(|| managed_agent_avatar_url(&agent_command));
501+
// Explicit input wins, then the persona's own avatar, then the runtime
502+
// fallback. Storing it lets reconciliation compare against what was
503+
// actually published instead of re-deriving it.
504+
let persona_avatar_url = requested_persona_id.as_ref().and_then(|persona_id| {
505+
load_personas(&app)
506+
.ok()?
507+
.into_iter()
508+
.find(|persona| persona.id == *persona_id)?
509+
.avatar_url
510+
});
511+
let resolved_avatar_url = resolve_created_avatar_url(
512+
input.avatar_url.as_deref(),
513+
persona_avatar_url,
514+
&agent_command,
515+
);
487516

488517
let record = crate::managed_agents::ManagedAgentRecord {
489518
pubkey: pubkey.clone(),
@@ -1145,149 +1174,5 @@ pub async fn probe_backend_provider(binary_path: String) -> Result<serde_json::V
11451174
// No backend Tauri command needed. Presence IS the status.
11461175

11471176
#[cfg(test)]
1148-
mod tests {
1149-
use super::*;
1150-
1151-
#[test]
1152-
fn normalize_relay_mesh_rejects_empty_model_ref() {
1153-
let config = RelayMeshConfig {
1154-
model_ref: " \t ".to_string(),
1155-
};
1156-
1157-
assert_eq!(
1158-
normalize_relay_mesh(Some(&config), &BackendKind::Local).unwrap_err(),
1159-
"relay mesh modelRef is required"
1160-
);
1161-
}
1162-
1163-
#[test]
1164-
fn normalize_relay_mesh_rejects_non_local_backend() {
1165-
let config = RelayMeshConfig {
1166-
model_ref: "Qwen3".to_string(),
1167-
};
1168-
let backend = BackendKind::Provider {
1169-
id: "blox".to_string(),
1170-
config: serde_json::json!({}),
1171-
};
1172-
1173-
assert_eq!(
1174-
normalize_relay_mesh(Some(&config), &backend).unwrap_err(),
1175-
"relay mesh agents must use the local backend"
1176-
);
1177-
}
1178-
1179-
#[test]
1180-
fn normalize_relay_mesh_trims_and_preserves_valid_config() {
1181-
let config = RelayMeshConfig {
1182-
model_ref: " Qwen3 ".to_string(),
1183-
};
1184-
1185-
assert_eq!(
1186-
normalize_relay_mesh(Some(&config), &BackendKind::Local).unwrap(),
1187-
Some(RelayMeshConfig {
1188-
model_ref: "Qwen3".to_string(),
1189-
})
1190-
);
1191-
}
1192-
1193-
fn profile(name: Option<&str>, picture: Option<&str>) -> crate::relay::AgentProfileInfo {
1194-
crate::relay::AgentProfileInfo {
1195-
display_name: name.map(str::to_string),
1196-
picture: picture.map(str::to_string),
1197-
}
1198-
}
1199-
1200-
#[test]
1201-
fn profile_needs_sync_when_missing() {
1202-
assert!(profile_needs_sync(None, "Duncan", Some("https://x/a.png")));
1203-
}
1204-
1205-
#[test]
1206-
fn profile_needs_sync_when_name_diverges() {
1207-
let existing = profile(Some("Stilgar"), Some("https://x/a.png"));
1208-
assert!(profile_needs_sync(
1209-
Some(&existing),
1210-
"Duncan",
1211-
Some("https://x/a.png")
1212-
));
1213-
}
1214-
1215-
#[test]
1216-
fn profile_needs_sync_when_picture_diverges() {
1217-
let existing = profile(Some("Duncan"), Some("https://x/old.png"));
1218-
assert!(profile_needs_sync(
1219-
Some(&existing),
1220-
"Duncan",
1221-
Some("https://x/new.png")
1222-
));
1223-
}
1224-
1225-
#[test]
1226-
fn profile_in_sync_when_name_and_picture_match() {
1227-
let existing = profile(Some("Duncan"), Some("https://x/a.png"));
1228-
assert!(!profile_needs_sync(
1229-
Some(&existing),
1230-
"Duncan",
1231-
Some("https://x/a.png")
1232-
));
1233-
}
1234-
1235-
#[test]
1236-
fn profile_in_sync_when_both_avatars_absent() {
1237-
let existing = profile(Some("Duncan"), None);
1238-
assert!(!profile_needs_sync(Some(&existing), "Duncan", None));
1239-
}
1240-
1241-
#[test]
1242-
fn profile_needs_sync_when_existing_name_is_none() {
1243-
let existing = profile(None, Some("https://x/a.png"));
1244-
assert!(profile_needs_sync(
1245-
Some(&existing),
1246-
"Duncan",
1247-
Some("https://x/a.png"),
1248-
));
1249-
}
1250-
1251-
#[test]
1252-
fn profile_needs_sync_when_expected_avatar_absent_but_published() {
1253-
let existing = profile(Some("Duncan"), Some("https://x/a.png"));
1254-
assert!(profile_needs_sync(Some(&existing), "Duncan", None));
1255-
}
1256-
1257-
#[test]
1258-
fn legacy_avatar_prefers_persona_over_corrupted_relay_picture() {
1259-
// The regression: the relay picture was overwritten with the command
1260-
// default. The persona avatar must win so the correct avatar is restored.
1261-
let resolved = resolve_legacy_avatar(
1262-
Some("https://x/persona.png".to_string()),
1263-
Some("https://x/default-icon.png".to_string()),
1264-
"goose",
1265-
);
1266-
1267-
assert_eq!(resolved, "https://x/persona.png");
1268-
}
1269-
1270-
#[test]
1271-
fn legacy_avatar_falls_back_to_relay_picture_without_persona() {
1272-
let resolved =
1273-
resolve_legacy_avatar(None, Some("https://x/relay.png".to_string()), "goose");
1274-
1275-
assert_eq!(resolved, "https://x/relay.png");
1276-
}
1277-
1278-
#[test]
1279-
fn legacy_avatar_falls_back_to_command_icon_when_no_persona_or_relay() {
1280-
use crate::managed_agents::managed_agent_avatar_url;
1281-
1282-
let resolved = resolve_legacy_avatar(None, None, "goose");
1283-
1284-
assert_eq!(resolved, managed_agent_avatar_url("goose").unwrap());
1285-
}
1286-
1287-
#[test]
1288-
fn legacy_avatar_empty_when_nothing_resolves() {
1289-
let resolved = resolve_legacy_avatar(None, None, "totally-unknown-command");
1290-
1291-
assert!(resolved.is_empty());
1292-
}
1293-
}
1177+
#[path = "agents_tests.rs"]
1178+
mod tests;
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
use super::*;
2+
3+
#[test]
4+
fn normalize_relay_mesh_rejects_empty_model_ref() {
5+
let config = RelayMeshConfig {
6+
model_ref: " \t ".to_string(),
7+
};
8+
9+
assert_eq!(
10+
normalize_relay_mesh(Some(&config), &BackendKind::Local).unwrap_err(),
11+
"relay mesh modelRef is required"
12+
);
13+
}
14+
15+
#[test]
16+
fn normalize_relay_mesh_rejects_non_local_backend() {
17+
let config = RelayMeshConfig {
18+
model_ref: "Qwen3".to_string(),
19+
};
20+
let backend = BackendKind::Provider {
21+
id: "blox".to_string(),
22+
config: serde_json::json!({}),
23+
};
24+
25+
assert_eq!(
26+
normalize_relay_mesh(Some(&config), &backend).unwrap_err(),
27+
"relay mesh agents must use the local backend"
28+
);
29+
}
30+
31+
#[test]
32+
fn normalize_relay_mesh_trims_and_preserves_valid_config() {
33+
let config = RelayMeshConfig {
34+
model_ref: " Qwen3 ".to_string(),
35+
};
36+
37+
assert_eq!(
38+
normalize_relay_mesh(Some(&config), &BackendKind::Local).unwrap(),
39+
Some(RelayMeshConfig {
40+
model_ref: "Qwen3".to_string(),
41+
})
42+
);
43+
}
44+
45+
#[test]
46+
fn created_avatar_prefers_explicit_input() {
47+
let resolved = resolve_created_avatar_url(
48+
Some(" https://x/input.png "),
49+
Some("https://x/persona.png".to_string()),
50+
"goose",
51+
);
52+
53+
assert_eq!(resolved.as_deref(), Some("https://x/input.png"));
54+
}
55+
56+
#[test]
57+
fn created_avatar_uses_persona_before_command_fallback() {
58+
let resolved =
59+
resolve_created_avatar_url(None, Some(" https://x/persona.png ".to_string()), "goose");
60+
61+
assert_eq!(resolved.as_deref(), Some("https://x/persona.png"));
62+
}
63+
64+
#[test]
65+
fn created_avatar_uses_command_fallback_without_input_or_persona() {
66+
use crate::managed_agents::managed_agent_avatar_url;
67+
68+
let resolved = resolve_created_avatar_url(None, None, "goose");
69+
70+
assert_eq!(resolved, managed_agent_avatar_url("goose"));
71+
}
72+
73+
fn profile(name: Option<&str>, picture: Option<&str>) -> crate::relay::AgentProfileInfo {
74+
crate::relay::AgentProfileInfo {
75+
display_name: name.map(str::to_string),
76+
picture: picture.map(str::to_string),
77+
}
78+
}
79+
80+
#[test]
81+
fn profile_needs_sync_when_missing() {
82+
assert!(profile_needs_sync(None, "Duncan", Some("https://x/a.png")));
83+
}
84+
85+
#[test]
86+
fn profile_needs_sync_when_name_diverges() {
87+
let existing = profile(Some("Stilgar"), Some("https://x/a.png"));
88+
assert!(profile_needs_sync(
89+
Some(&existing),
90+
"Duncan",
91+
Some("https://x/a.png")
92+
));
93+
}
94+
95+
#[test]
96+
fn profile_needs_sync_when_picture_diverges() {
97+
let existing = profile(Some("Duncan"), Some("https://x/old.png"));
98+
assert!(profile_needs_sync(
99+
Some(&existing),
100+
"Duncan",
101+
Some("https://x/new.png")
102+
));
103+
}
104+
105+
#[test]
106+
fn profile_in_sync_when_name_and_picture_match() {
107+
let existing = profile(Some("Duncan"), Some("https://x/a.png"));
108+
assert!(!profile_needs_sync(
109+
Some(&existing),
110+
"Duncan",
111+
Some("https://x/a.png")
112+
));
113+
}
114+
115+
#[test]
116+
fn profile_in_sync_when_both_avatars_absent() {
117+
let existing = profile(Some("Duncan"), None);
118+
assert!(!profile_needs_sync(Some(&existing), "Duncan", None));
119+
}
120+
121+
#[test]
122+
fn profile_needs_sync_when_existing_name_is_none() {
123+
let existing = profile(None, Some("https://x/a.png"));
124+
assert!(profile_needs_sync(
125+
Some(&existing),
126+
"Duncan",
127+
Some("https://x/a.png"),
128+
));
129+
}
130+
131+
#[test]
132+
fn profile_needs_sync_when_expected_avatar_absent_but_published() {
133+
let existing = profile(Some("Duncan"), Some("https://x/a.png"));
134+
assert!(profile_needs_sync(Some(&existing), "Duncan", None));
135+
}
136+
137+
#[test]
138+
fn legacy_avatar_prefers_persona_over_corrupted_relay_picture() {
139+
// The regression: the relay picture was overwritten with the command
140+
// default. The persona avatar must win so the correct avatar is restored.
141+
let resolved = resolve_legacy_avatar(
142+
Some("https://x/persona.png".to_string()),
143+
Some("https://x/default-icon.png".to_string()),
144+
"goose",
145+
);
146+
147+
assert_eq!(resolved, "https://x/persona.png");
148+
}
149+
150+
#[test]
151+
fn legacy_avatar_falls_back_to_relay_picture_without_persona() {
152+
let resolved = resolve_legacy_avatar(None, Some("https://x/relay.png".to_string()), "goose");
153+
154+
assert_eq!(resolved, "https://x/relay.png");
155+
}
156+
157+
#[test]
158+
fn legacy_avatar_falls_back_to_command_icon_when_no_persona_or_relay() {
159+
use crate::managed_agents::managed_agent_avatar_url;
160+
161+
let resolved = resolve_legacy_avatar(None, None, "goose");
162+
163+
assert_eq!(resolved, managed_agent_avatar_url("goose").unwrap());
164+
}
165+
166+
#[test]
167+
fn legacy_avatar_empty_when_nothing_resolves() {
168+
let resolved = resolve_legacy_avatar(None, None, "totally-unknown-command");
169+
170+
assert!(resolved.is_empty());
171+
}

0 commit comments

Comments
 (0)