BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / notify / stack.rs

stack.rs

stack.rs 22.7 KiB Download Raw
1use std::time::{Duration, Instant};
2
3use super::rules::{ChatKind, Incoming, Preview};
4
5pub const MAX_VISIBLE: usize = 3;
6pub const MESSAGE_DURATION: Duration = Duration::from_secs(6);
7pub const MENTION_DURATION: Duration = Duration::from_secs(10);
8pub const MAX_TOTAL: Duration = Duration::from_secs(20);
9pub const RESUME_REMAINING: Duration = Duration::from_secs(2);
10pub const SENT_DURATION: Duration = Duration::from_millis(1500);
11pub const FADE_IN: Duration = Duration::from_millis(150);
12pub const FAST_FADE: Duration = Duration::from_millis(150);
13pub const SLOW_FADE: Duration = Duration::from_secs(4);
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub enum Curve {
17 Linear,
18 EaseInCirc,
19}
20
21#[derive(Debug, Clone, Copy, PartialEq)]
22pub struct Fade {
23 from: f32,
24 to: f32,
25 start: Instant,
26 duration: Duration,
27 curve: Curve,
28}
29
30impl Fade {
31 pub fn new(from: f32, to: f32, start: Instant, duration: Duration, curve: Curve) -> Self {
32 Fade {
33 from,
34 to,
35 start,
36 duration,
37 curve,
38 }
39 }
40
41 #[cfg(test)]
42 pub fn shown(now: Instant) -> Self {
43 Fade::new(1., 1., now, Duration::ZERO, Curve::Linear)
44 }
45
46 pub fn value(&self, now: Instant) -> f32 {
47 if self.duration.is_zero() {
48 return self.to;
49 }
50 let progress = (now.saturating_duration_since(self.start).as_secs_f32()
51 / self.duration.as_secs_f32())
52 .clamp(0., 1.);
53 let eased = match self.curve {
54 Curve::Linear => progress,
55 Curve::EaseInCirc => 1. - (1. - progress * progress).sqrt(),
56 };
57 self.from + (self.to - self.from) * eased
58 }
59
60 pub fn is_leaving(&self) -> bool {
61 self.to == 0.
62 }
63
64 fn is_gone(&self, now: Instant) -> bool {
65 self.is_leaving() && now.saturating_duration_since(self.start) >= self.duration
66 }
67}
68
69#[derive(Debug, Clone, Copy)]
70pub struct ToastTimer {
71 first_shown: Instant,
72 started: Instant,
73 duration: Duration,
74 paused: Option<Instant>,
75 paused_total: Duration,
76}
77
78impl ToastTimer {
79 pub fn new(now: Instant, mention: bool) -> Self {
80 ToastTimer {
81 first_shown: now,
82 started: now,
83 duration: base_duration(mention),
84 paused: None,
85 paused_total: Duration::ZERO,
86 }
87 }
88
89 pub fn restart(&mut self, now: Instant, mention: bool) {
90 self.started = now;
91 self.duration = base_duration(mention);
92 if self.paused.is_some() {
93 self.paused = Some(now);
94 }
95 }
96
97 pub fn pause(&mut self, now: Instant) {
98 self.paused.get_or_insert(now);
99 }
100
101 pub fn resume(&mut self, now: Instant) {
102 if let Some(paused_at) = self.paused.take() {
103 self.paused_total += now.saturating_duration_since(paused_at);
104 self.started = now;
105 self.duration = RESUME_REMAINING;
106 }
107 }
108
109 fn elapsed(&self, now: Instant) -> Duration {
110 self.paused
111 .unwrap_or(now)
112 .saturating_duration_since(self.started)
113 }
114
115 pub fn expired(&self, now: Instant) -> bool {
116 if self.paused.is_some() {
117 return false;
118 }
119 self.elapsed(now) >= self.duration
120 || now
121 .saturating_duration_since(self.first_shown)
122 .saturating_sub(self.paused_total)
123 >= MAX_TOTAL
124 }
125}
126
127fn base_duration(mention: bool) -> Duration {
128 if mention {
129 MENTION_DURATION
130 } else {
131 MESSAGE_DURATION
132 }
133}
134
135#[derive(Debug, Clone, PartialEq, Eq)]
136pub enum ReplyState {
137 Closed,
138 Open,
139 Sent,
140 Failed,
141}
142
143#[derive(Debug, Clone, PartialEq, Eq)]
144pub enum AgentToastKind {
145 Run {
146 run_id: u64,
147 session_id: String,
148 failed: bool,
149 },
150 Proposal {
151 proposal_id: String,
152 },
153}
154
155#[derive(Debug, Clone, PartialEq, Eq)]
156pub struct AgentToast {
157 pub kind: AgentToastKind,
158 pub header: String,
159 pub title: String,
160 pub body: String,
161}
162
163impl AgentToast {
164 pub fn failed(&self) -> bool {
165 matches!(self.kind, AgentToastKind::Run { failed: true, .. })
166 }
167
168 pub fn proposal_id(&self) -> Option<&str> {
169 match &self.kind {
170 AgentToastKind::Proposal { proposal_id } => Some(proposal_id),
171 AgentToastKind::Run { .. } => None,
172 }
173 }
174}
175
176#[derive(Debug, Clone)]
177pub struct ToastModel {
178 pub id: u64,
179 pub conversation_id: String,
180 pub message_id: String,
181 pub kind: ChatKind,
182 pub chat_title: String,
183 pub sender_id: Option<String>,
184 pub sender_name: String,
185 pub preview: Preview,
186 pub mentions_me: bool,
187 pub count: u32,
188 pub timer: ToastTimer,
189 pub reply: ReplyState,
190 pub reply_text: String,
191 pub hovered: bool,
192 pub time: String,
193 pub queued: bool,
194 pub dismissed: bool,
195 pub fade: Fade,
196 pub agent: Option<AgentToast>,
197 pub status_change: bool,
198 pub urgent: bool,
199}
200
201impl ToastModel {
202 pub fn holds_open(&self) -> bool {
203 self.reply != ReplyState::Closed
204 }
205
206 pub fn opacity(&self, now: Instant) -> f32 {
207 self.fade.value(now)
208 }
209
210 pub fn is_leaving(&self) -> bool {
211 self.fade.is_leaving()
212 }
213}
214
215#[derive(Debug, Clone, Copy, PartialEq, Eq)]
216pub struct PushOutcome {
217 pub id: u64,
218 pub bundled: bool,
219 pub became_mention: bool,
220}
221
222impl PushOutcome {
223 pub fn plays_sound(self, throttle_allows: bool) -> bool {
224 self.became_mention || (!self.bundled && throttle_allows)
225 }
226}
227
228#[derive(Default)]
229pub struct ToastStack {
230 toasts: Vec<ToastModel>,
231 next_id: u64,
232}
233
234impl ToastStack {
235 pub fn push(&mut self, incoming: &Incoming, now: Instant) -> PushOutcome {
236 if let Some(existing) = self.toasts.iter_mut().find(|toast| {
237 toast.agent.is_none()
238 && !toast.status_change
239 && !toast.dismissed
240 && !toast.is_leaving()
241 && toast.conversation_id == incoming.conversation_id
242 }) {
243 let became_mention = incoming.mentions_me && !existing.mentions_me;
244 existing.count += 1;
245 existing.mentions_me |= incoming.mentions_me;
246 existing.message_id = incoming.message_id.clone();
247 existing.sender_id = incoming.sender_id.clone();
248 existing.sender_name = incoming.sender_name.clone();
249 existing.preview = incoming.preview.clone();
250 existing.urgent = incoming.is_urgent();
251 let mention = existing.mentions_me;
252 existing.timer.restart(now, mention);
253 return PushOutcome {
254 id: existing.id,
255 bundled: true,
256 became_mention,
257 };
258 }
259 self.next_id += 1;
260 let queued = self.toasts.len() >= MAX_VISIBLE;
261 self.toasts.push(ToastModel {
262 id: self.next_id,
263 conversation_id: incoming.conversation_id.clone(),
264 message_id: incoming.message_id.clone(),
265 kind: incoming.kind.clone(),
266 chat_title: incoming.chat_title.clone(),
267 sender_id: incoming.sender_id.clone(),
268 sender_name: incoming.sender_name.clone(),
269 preview: incoming.preview.clone(),
270 mentions_me: incoming.mentions_me,
271 count: 1,
272 timer: ToastTimer::new(now, incoming.mentions_me),
273 reply: ReplyState::Closed,
274 reply_text: String::new(),
275 hovered: false,
276 time: String::new(),
277 queued,
278 dismissed: false,
279 fade: Fade::new(0., 1., now, FADE_IN, Curve::Linear),
280 agent: None,
281 status_change: false,
282 urgent: incoming.is_urgent(),
283 });
284 PushOutcome {
285 id: self.next_id,
286 bundled: false,
287 became_mention: false,
288 }
289 }
290
291 pub fn push_agent(
292 &mut self,
293 agent: AgentToast,
294 conversation_id: &str,
295 message_id: &str,
296 now: Instant,
297 ) -> u64 {
298 self.next_id += 1;
299 let queued = self.toasts.len() >= MAX_VISIBLE;
300 self.toasts.push(ToastModel {
301 id: self.next_id,
302 conversation_id: conversation_id.to_owned(),
303 message_id: message_id.to_owned(),
304 kind: ChatKind::Direct,
305 chat_title: String::new(),
306 sender_id: None,
307 sender_name: String::new(),
308 preview: Preview::Text(agent.body.clone()),
309 mentions_me: false,
310 count: 1,
311 timer: ToastTimer::new(now, true),
312 reply: ReplyState::Closed,
313 reply_text: String::new(),
314 hovered: false,
315 time: String::new(),
316 queued,
317 dismissed: false,
318 fade: Fade::new(0., 1., now, FADE_IN, Curve::Linear),
319 agent: Some(agent),
320 status_change: false,
321 urgent: false,
322 });
323 self.next_id
324 }
325
326 pub fn push_status_change(
327 &mut self,
328 user_id: &str,
329 name: &str,
330 text: &str,
331 conversation_id: &str,
332 now: Instant,
333 ) -> u64 {
334 self.next_id += 1;
335 let queued = self.toasts.len() >= MAX_VISIBLE;
336 self.toasts.push(ToastModel {
337 id: self.next_id,
338 conversation_id: conversation_id.to_owned(),
339 message_id: String::new(),
340 kind: ChatKind::Direct,
341 chat_title: name.to_owned(),
342 sender_id: Some(user_id.to_owned()),
343 sender_name: name.to_owned(),
344 preview: Preview::Text(text.to_owned()),
345 mentions_me: false,
346 count: 1,
347 timer: ToastTimer::new(now, false),
348 reply: ReplyState::Closed,
349 reply_text: String::new(),
350 hovered: false,
351 time: String::new(),
352 queued,
353 dismissed: false,
354 fade: Fade::new(0., 1., now, FADE_IN, Curve::Linear),
355 agent: None,
356 status_change: true,
357 urgent: false,
358 });
359 self.next_id
360 }
361
362 pub fn get(&self, id: u64) -> Option<&ToastModel> {
363 self.toasts.iter().find(|toast| toast.id == id)
364 }
365
366 pub fn get_mut(&mut self, id: u64) -> Option<&mut ToastModel> {
367 self.toasts.iter_mut().find(|toast| toast.id == id)
368 }
369
370 pub fn remove(&mut self, id: u64) -> Option<ToastModel> {
371 let index = self.toasts.iter().position(|toast| toast.id == id)?;
372 Some(self.toasts.remove(index))
373 }
374
375 pub fn remove_conversation(&mut self, conversation_id: &str) -> Vec<u64> {
376 let matches =
377 |toast: &ToastModel| toast.agent.is_none() && toast.conversation_id == conversation_id;
378 let ids: Vec<u64> = self
379 .toasts
380 .iter()
381 .filter(|toast| matches(toast))
382 .map(|toast| toast.id)
383 .collect();
384 self.toasts.retain(|toast| !matches(toast));
385 ids
386 }
387
388 pub fn visible(&self) -> &[ToastModel] {
389 let shown = self
390 .toasts
391 .iter()
392 .position(|toast| toast.queued)
393 .unwrap_or(self.toasts.len());
394 &self.toasts[..shown]
395 }
396
397 pub fn queued_count(&self) -> usize {
398 self.toasts.len() - self.visible().len()
399 }
400
401 pub fn promote(&mut self, now: Instant, fade_in: Duration) {
402 for toast in self.toasts.iter_mut().take(MAX_VISIBLE) {
403 if toast.queued {
404 toast.queued = false;
405 toast.timer = ToastTimer::new(now, toast.mentions_me);
406 toast.fade = Fade::new(0., 1., now, fade_in, Curve::Linear);
407 }
408 }
409 }
410
411 pub fn fade_out(&mut self, id: u64, now: Instant, duration: Duration) {
412 if let Some(toast) = self.get_mut(id)
413 && !toast.is_leaving()
414 {
415 toast.fade = Fade::new(toast.opacity(now), 0., now, duration, Curve::EaseInCirc);
416 }
417 }
418
419 pub fn dismiss(&mut self, id: u64, now: Instant, duration: Duration) {
420 let Some(index) = self.toasts.iter().position(|toast| toast.id == id) else {
421 return;
422 };
423 if self.toasts[index].queued {
424 self.toasts.remove(index);
425 return;
426 }
427 let toast = &mut self.toasts[index];
428 if !toast.dismissed {
429 toast.dismissed = true;
430 toast.hovered = false;
431 toast.fade = Fade::new(toast.opacity(now), 0., now, duration, Curve::Linear);
432 }
433 }
434
435 pub fn restore(&mut self, now: Instant, duration: Duration) {
436 for toast in self
437 .toasts
438 .iter_mut()
439 .filter(|toast| toast.is_leaving() && !toast.dismissed)
440 {
441 toast.fade = Fade::new(toast.opacity(now), 1., now, duration, Curve::Linear);
442 }
443 }
444
445 pub fn any_hovered(&self) -> bool {
446 self.toasts.iter().any(|toast| toast.hovered)
447 }
448
449 pub fn ids(&self) -> Vec<u64> {
450 self.toasts.iter().map(|toast| toast.id).collect()
451 }
452
453 pub fn gone(&self, now: Instant) -> Vec<u64> {
454 self.toasts
455 .iter()
456 .filter(|toast| toast.fade.is_gone(now))
457 .map(|toast| toast.id)
458 .collect()
459 }
460
461 pub fn is_empty(&self) -> bool {
462 self.toasts.is_empty()
463 }
464
465 pub fn expired(&self, now: Instant) -> Vec<u64> {
466 self.toasts
467 .iter()
468 .filter(|toast| {
469 !toast.queued
470 && !toast.is_leaving()
471 && !toast.holds_open()
472 && toast.timer.expired(now)
473 })
474 .map(|toast| toast.id)
475 .collect()
476 }
477}
478
479#[cfg(test)]
480mod tests {
481 use super::*;
482
483 fn incoming(conversation: &str, mention: bool) -> Incoming {
484 Incoming {
485 conversation_id: conversation.into(),
486 message_id: "m".into(),
487 kind: ChatKind::Direct,
488 chat_title: "Chat".into(),
489 sender_id: None,
490 sender_name: "Mara".into(),
491 preview: Preview::Text("Hello".into()),
492 mentions_me: mention,
493 muted: false,
494 signals: Default::default(),
495 chat: Default::default(),
496 created_at: chrono::Utc::now(),
497 importance: Default::default(),
498 }
499 }
500
501 #[test]
502 fn same_chat_bundles_into_one_toast_with_counter() {
503 let mut stack = ToastStack::default();
504 let now = Instant::now();
505 let first = stack.push(&incoming("a", false), now);
506 let second = stack.push(&incoming("a", false), now + Duration::from_secs(2));
507 assert!(!first.bundled);
508 assert!(second.bundled);
509 assert_eq!(first.id, second.id);
510 assert_eq!(stack.get(first.id).unwrap().count, 2);
511 assert_eq!(stack.visible().len(), 1);
512 }
513
514 #[test]
515 fn a_message_never_bundles_into_a_dismissed_toast() {
516 let mut stack = ToastStack::default();
517 let now = Instant::now();
518 let first = stack.push(&incoming("a", false), now);
519 stack.dismiss(first.id, now, Duration::from_millis(150));
520 let second = stack.push(&incoming("a", false), now);
521 assert!(!second.bundled);
522 assert_ne!(first.id, second.id);
523 }
524
525 #[test]
526 fn bundling_restarts_timer() {
527 let mut stack = ToastStack::default();
528 let now = Instant::now();
529 let id = stack.push(&incoming("a", false), now).id;
530 stack.push(&incoming("a", false), now + Duration::from_secs(5));
531 assert!(stack.expired(now + Duration::from_secs(7)).is_empty());
532 assert_eq!(stack.expired(now + Duration::from_secs(11)), vec![id]);
533 }
534
535 #[test]
536 fn mention_in_burst_upgrades_and_plays_sound() {
537 let mut stack = ToastStack::default();
538 let now = Instant::now();
539 stack.push(&incoming("a", false), now);
540 let outcome = stack.push(&incoming("a", true), now);
541 assert!(outcome.became_mention);
542 assert!(outcome.plays_sound(false));
543 assert!(stack.get(outcome.id).unwrap().mentions_me);
544 let again = stack.push(&incoming("a", true), now);
545 assert!(!again.plays_sound(true));
546 }
547
548 #[test]
549 fn only_first_of_burst_plays_sound() {
550 let mut stack = ToastStack::default();
551 let now = Instant::now();
552 assert!(stack.push(&incoming("a", false), now).plays_sound(true));
553 assert!(!stack.push(&incoming("a", false), now).plays_sound(true));
554 assert!(!stack.push(&incoming("b", false), now).plays_sound(false));
555 }
556
557 fn visible_chats(stack: &ToastStack) -> Vec<&str> {
558 stack
559 .visible()
560 .iter()
561 .map(|toast| toast.conversation_id.as_str())
562 .collect()
563 }
564
565 #[test]
566 fn shows_first_three_and_queues_the_rest() {
567 let mut stack = ToastStack::default();
568 let now = Instant::now();
569 for chat in ["a", "b", "c", "d", "e"] {
570 stack.push(&incoming(chat, false), now);
571 }
572 assert_eq!(visible_chats(&stack), ["a", "b", "c"]);
573 assert_eq!(stack.queued_count(), 2);
574 }
575
576 #[test]
577 fn queued_toast_starts_its_timer_when_promoted() {
578 let mut stack = ToastStack::default();
579 let start = Instant::now();
580 let ids: Vec<u64> = ["a", "b", "c", "d"]
581 .into_iter()
582 .map(|chat| stack.push(&incoming(chat, false), start).id)
583 .collect();
584 let later = start + Duration::from_secs(30);
585 assert!(!stack.expired(later).contains(&ids[3]));
586 stack.remove(ids[0]);
587 stack.promote(later, FADE_IN);
588 assert_eq!(visible_chats(&stack), ["b", "c", "d"]);
589 assert!(
590 !stack
591 .expired(later + Duration::from_secs(5))
592 .contains(&ids[3])
593 );
594 assert!(
595 stack
596 .expired(later + Duration::from_secs(6))
597 .contains(&ids[3])
598 );
599 }
600
601 #[test]
602 fn slow_fade_stays_visible_then_drops_and_is_gone() {
603 let mut stack = ToastStack::default();
604 let now = Instant::now();
605 let id = stack.push(&incoming("a", false), now).id;
606 let hide_at = now + Duration::from_secs(6);
607 stack.fade_out(id, hide_at, SLOW_FADE);
608 let toast = stack.get(id).unwrap();
609 assert!(toast.opacity(hide_at + Duration::from_secs(2)) > 0.8);
610 assert!(stack.gone(hide_at + Duration::from_secs(3)).is_empty());
611 assert_eq!(stack.gone(hide_at + SLOW_FADE), vec![id]);
612 }
613
614 #[test]
615 fn restore_brings_a_fading_toast_back() {
616 let mut stack = ToastStack::default();
617 let now = Instant::now();
618 let id = stack.push(&incoming("a", false), now).id;
619 stack.fade_out(id, now, SLOW_FADE);
620 stack.restore(now + Duration::from_secs(3), FAST_FADE);
621 let toast = stack.get(id).unwrap();
622 assert!(!toast.is_leaving());
623 assert_eq!(toast.opacity(now + Duration::from_secs(4)), 1.);
624 assert!(stack.gone(now + Duration::from_secs(10)).is_empty());
625 }
626
627 #[test]
628 fn hiding_a_queued_toast_drops_it_at_once() {
629 let mut stack = ToastStack::default();
630 let now = Instant::now();
631 let ids: Vec<u64> = ["a", "b", "c", "d"]
632 .into_iter()
633 .map(|chat| stack.push(&incoming(chat, false), now).id)
634 .collect();
635 stack.dismiss(ids[3], now, FAST_FADE);
636 assert!(stack.get(ids[3]).is_none());
637 assert_eq!(stack.queued_count(), 0);
638 }
639
640 #[test]
641 fn dismiss_cuts_a_slow_fade_short_and_hover_does_not_undo_it() {
642 let mut stack = ToastStack::default();
643 let now = Instant::now();
644 let id = stack.push(&incoming("a", false), now).id;
645 stack.fade_out(id, now, SLOW_FADE);
646 stack.dismiss(id, now + Duration::from_secs(1), FAST_FADE);
647 stack.restore(now + Duration::from_millis(1050), FAST_FADE);
648 assert_eq!(stack.gone(now + Duration::from_millis(1150)), vec![id]);
649 }
650
651 #[test]
652 fn mention_lasts_ten_seconds() {
653 let now = Instant::now();
654 let timer = ToastTimer::new(now, true);
655 assert!(!timer.expired(now + Duration::from_secs(9)));
656 assert!(timer.expired(now + Duration::from_secs(10)));
657 }
658
659 #[test]
660 fn hard_cap_beats_restarts() {
661 let mut stack = ToastStack::default();
662 let start = Instant::now();
663 let id = stack.push(&incoming("a", false), start).id;
664 for second in [5, 10, 15, 19] {
665 stack.push(&incoming("a", false), start + Duration::from_secs(second));
666 }
667 assert!(stack.expired(start + Duration::from_secs(19)).is_empty());
668 assert_eq!(stack.expired(start + Duration::from_secs(20)), vec![id]);
669 }
670
671 #[test]
672 fn pause_stops_expiry_and_resume_leaves_two_seconds() {
673 let now = Instant::now();
674 let mut timer = ToastTimer::new(now, false);
675 timer.pause(now + Duration::from_secs(1));
676 assert!(!timer.expired(now + Duration::from_secs(60)));
677 let resumed = now + Duration::from_secs(60);
678 timer.resume(resumed);
679 assert!(!timer.expired(resumed + Duration::from_millis(1900)));
680 assert!(timer.expired(resumed + Duration::from_secs(2)));
681 }
682
683 #[test]
684 fn open_reply_field_holds_toast() {
685 let mut stack = ToastStack::default();
686 let now = Instant::now();
687 let id = stack.push(&incoming("a", false), now).id;
688 stack.get_mut(id).unwrap().reply = ReplyState::Open;
689 assert!(stack.expired(now + Duration::from_secs(60)).is_empty());
690 }
691
692 #[test]
693 fn remove_conversation_returns_ids() {
694 let mut stack = ToastStack::default();
695 let now = Instant::now();
696 let id = stack.push(&incoming("a", false), now).id;
697 stack.push(&incoming("b", false), now);
698 assert_eq!(stack.remove_conversation("a"), vec![id]);
699 assert_eq!(stack.visible().len(), 1);
700 }
701
702 fn agent_toast() -> AgentToast {
703 AgentToast {
704 kind: AgentToastKind::Run {
705 run_id: 7,
706 session_id: "s".into(),
707 failed: false,
708 },
709 header: "Answer this - Claude - 1:02".into(),
710 title: "Claude finished: Answer this for Mara".into(),
711 body: "Done".into(),
712 }
713 }
714
715 #[test]
716 fn agent_toasts_never_bundle_with_messages() {
717 let mut stack = ToastStack::default();
718 let now = Instant::now();
719 let agent_id = stack.push_agent(agent_toast(), "a", "m", now);
720 let outcome = stack.push(&incoming("a", false), now);
721 assert!(!outcome.bundled);
722 assert_ne!(outcome.id, agent_id);
723 assert_eq!(stack.visible().len(), 2);
724 }
725
726 #[test]
727 fn opening_the_chat_keeps_the_agent_toast() {
728 let mut stack = ToastStack::default();
729 let now = Instant::now();
730 let agent_id = stack.push_agent(agent_toast(), "a", "m", now);
731 let message_id = stack.push(&incoming("a", false), now).id;
732 assert_eq!(stack.remove_conversation("a"), vec![message_id]);
733 assert!(stack.get(agent_id).is_some());
734 }
735}