Skip to content

Commit 2a52282

Browse files
wesbillmanPinky
andauthored
fix(desktop): dedupe welcome intro per channel (#1216)
Signed-off-by: Wes <[email protected]> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
1 parent bee2d64 commit 2a52282

3 files changed

Lines changed: 48 additions & 3 deletions

File tree

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,26 @@ fn event_has_client_marker(event: &Event, marker: &str) -> bool {
360360

361361
async fn find_managed_agent_channel_message_by_marker(
362362
state: &AppState,
363-
agent_pubkey: &str,
363+
agent_pubkey: Option<&str>,
364364
channel_id: &str,
365365
marker: &str,
366366
) -> Result<Option<Event>, String> {
367+
let author = agent_pubkey
368+
.map(str::trim)
369+
.filter(|pubkey| !pubkey.is_empty())
370+
.map(str::to_ascii_lowercase);
371+
367372
let mut until: Option<u64> = None;
368373

369374
for _ in 0..10 {
370375
let mut filter = serde_json::json!({
371-
"authors": [agent_pubkey],
372376
"kinds": [buzz_core_pkg::kind::KIND_STREAM_MESSAGE],
373377
"#h": [channel_id],
374378
"limit": 500,
375379
});
380+
if let Some(author) = author.as_deref() {
381+
filter["authors"] = serde_json::json!([author]);
382+
}
376383
if let Some(until) = until {
377384
filter["until"] = serde_json::json!(until);
378385
}
@@ -401,6 +408,16 @@ async fn find_managed_agent_channel_message_by_marker(
401408
Ok(None)
402409
}
403410

411+
fn marker_author_for_scope<'a>(
412+
marker_scope: Option<&str>,
413+
agent_pubkey: &'a str,
414+
) -> Option<&'a str> {
415+
match marker_scope {
416+
Some("channel") => None,
417+
_ => Some(agent_pubkey),
418+
}
419+
}
420+
404421
fn stored_managed_agent_auth_tag(auth_tag: Option<&str>) -> Option<String> {
405422
auth_tag
406423
.map(str::trim)
@@ -440,6 +457,7 @@ pub async fn send_managed_agent_channel_message(
440457
channel_id: String,
441458
content: String,
442459
marker: Option<String>,
460+
marker_scope: Option<String>,
443461
app: AppHandle,
444462
state: State<'_, AppState>,
445463
) -> Result<SendChannelMessageResponse, String> {
@@ -480,7 +498,7 @@ pub async fn send_managed_agent_channel_message(
480498
if let Some(marker) = marker.as_deref() {
481499
if let Some(existing) = find_managed_agent_channel_message_by_marker(
482500
&state,
483-
&record.pubkey,
501+
marker_author_for_scope(marker_scope.as_deref(), &record.pubkey),
484502
&channel_id,
485503
marker,
486504
)
@@ -526,6 +544,30 @@ pub async fn send_managed_agent_channel_message(
526544
mod tests {
527545
use super::*;
528546

547+
#[test]
548+
fn marker_author_scope_defaults_to_agent() {
549+
assert_eq!(
550+
marker_author_for_scope(None, "agent-pubkey"),
551+
Some("agent-pubkey")
552+
);
553+
assert_eq!(
554+
marker_author_for_scope(Some("agent"), "agent-pubkey"),
555+
Some("agent-pubkey")
556+
);
557+
assert_eq!(
558+
marker_author_for_scope(Some("unknown"), "agent-pubkey"),
559+
Some("agent-pubkey")
560+
);
561+
}
562+
563+
#[test]
564+
fn marker_author_scope_can_dedupe_across_channel() {
565+
assert_eq!(
566+
marker_author_for_scope(Some("channel"), "agent-pubkey"),
567+
None
568+
);
569+
}
570+
529571
#[test]
530572
fn stored_managed_agent_auth_tag_trims_blank_values() {
531573
assert_eq!(

‎desktop/src/features/onboarding/welcomeGuide.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ export async function ensureWelcomeGuideIntro(
160160
channelId,
161161
content: WELCOME_GUIDE_INTRO_MESSAGE,
162162
marker: WELCOME_GUIDE_INTRO_MARKER,
163+
markerScope: "channel",
163164
});
164165
return agent;
165166
}

‎desktop/src/shared/api/tauriManagedAgentMessages.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export async function sendManagedAgentChannelMessage(input: {
1414
channelId: string;
1515
content: string;
1616
marker?: string;
17+
markerScope?: "agent" | "channel";
1718
}): Promise<SendChannelMessageResult> {
1819
const response = await invokeTauri<RawSendChannelMessageResult>(
1920
"send_managed_agent_channel_message",
@@ -22,6 +23,7 @@ export async function sendManagedAgentChannelMessage(input: {
2223
channelId: input.channelId,
2324
content: input.content,
2425
marker: input.marker ?? null,
26+
markerScope: input.markerScope ?? null,
2527
},
2628
);
2729

0 commit comments

Comments
 (0)