use adk_core::principal::SubjectRef;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::words;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub enum SurfaceKind {
Web,
Terminal,
Phone,
Tray,
Chat,
Voice,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "kind", rename_all = "camelCase")]
pub enum Origin {
Keyboard,
Pointer,
Touch,
Voice,
Chat {
channel: String,
},
Agent {
agent: String,
},
}
impl Origin {
pub fn kind(&self) -> &'static str {
match self {
Self::Keyboard => "keyboard",
Self::Pointer => "pointer",
Self::Touch => "touch",
Self::Voice => "voice",
Self::Chat { .. } => "chat",
Self::Agent { .. } => "agent",
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase")]
pub struct Via {
pub surface: SurfaceKind,
pub origin: Origin,
}
impl Via {
pub fn phrase(&self) -> String {
match (&self.origin, self.surface) {
(Origin::Chat { channel }, _) => words::in_channel(channel),
(Origin::Voice, _) | (_, SurfaceKind::Voice) => words::BY_VOICE.to_string(),
(_, SurfaceKind::Web) => words::IN_THE_HOME_APP.to_string(),
(_, SurfaceKind::Phone) => words::ON_YOUR_PHONE.to_string(),
(_, SurfaceKind::Terminal) => words::IN_THE_TERMINAL.to_string(),
(_, SurfaceKind::Tray) => words::FROM_THE_TRAY.to_string(),
(_, SurfaceKind::Chat) => words::in_channel("chat"),
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Caller {
pub subject: SubjectRef,
pub groups: Vec<String>,
pub surface: SurfaceKind,
pub origin: Origin,
pub presence_confirmed: bool,
pub paired_local: bool,
pub device: Option<String>,
}
impl Caller {
pub fn human(user_id: impl Into<String>, surface: SurfaceKind, origin: Origin) -> Self {
Self {
subject: SubjectRef::human(user_id),
groups: Vec::new(),
surface,
origin,
presence_confirmed: false,
paired_local: false,
device: None,
}
}
#[must_use]
pub fn with_groups(mut self, groups: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.groups = groups.into_iter().map(Into::into).collect();
self
}
#[must_use]
pub fn with_presence_confirmed(mut self) -> Self {
self.presence_confirmed = true;
self
}
#[must_use]
pub fn with_paired_local(mut self) -> Self {
self.paired_local = true;
self
}
#[must_use]
pub fn with_device(mut self, id: impl Into<String>) -> Self {
self.device = Some(id.into());
self
}
pub fn user_id(&self) -> &str {
&self.subject.id
}
pub fn via(&self) -> Via {
Via { surface: self.surface, origin: self.origin.clone() }
}
}