use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct Health {
pub status: String,
pub authenticated: bool,
pub active_sessions: u32,
pub max_sessions: u32,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct Library {
pub notebooks: Vec<Notebook>,
pub active_notebook_id: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct Notebook {
pub id: String,
pub name: String,
pub url: String,
#[serde(default)]
pub description: String,
#[serde(default)]
pub topics: Vec<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum SourceFormat {
None,
Json,
Inline,
Footnotes,
Expanded,
}
#[derive(Debug, Clone, Serialize)]
pub struct AskRequest {
pub question: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub notebook_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub notebook_url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub session_id: Option<String>,
pub source_format: SourceFormat,
}
impl AskRequest {
pub fn new(notebook_id: impl Into<String>, question: impl Into<String>) -> Self {
Self {
question: question.into(),
notebook_id: Some(notebook_id.into()),
notebook_url: None,
session_id: None,
source_format: SourceFormat::Json,
}
}
#[must_use]
pub fn in_session(mut self, session_id: impl Into<String>) -> Self {
self.session_id = Some(session_id.into());
self
}
#[must_use]
pub fn at_url(mut self, notebook_url: impl Into<String>) -> Self {
self.notebook_url = Some(notebook_url.into());
self.notebook_id = None;
self
}
#[must_use]
pub fn with_source_format(mut self, format: SourceFormat) -> Self {
self.source_format = format;
self
}
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct Answer {
pub answer: String,
pub session_id: String,
pub notebook_url: String,
#[serde(default)]
pub sources: Option<Sources>,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct Sources {
pub format: String,
#[serde(default)]
pub citations: Vec<Citation>,
#[serde(default)]
pub extraction_success: bool,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct Citation {
pub marker: String,
pub number: u32,
#[serde(rename = "sourceText", default)]
pub source_text: String,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct SearchRequest {
pub query: String,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub source_ids: Vec<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub source_names: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u32>,
}
impl SearchRequest {
pub fn new(query: impl Into<String>) -> Self {
Self {
query: query.into(),
..Default::default()
}
}
#[must_use]
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
#[must_use]
pub fn in_sources(mut self, source_ids: impl IntoIterator<Item = String>) -> Self {
self.source_ids = source_ids.into_iter().collect();
self
}
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct PassageSearch {
#[serde(rename = "notebookId")]
pub notebook_id: String,
pub query: String,
pub count: u32,
pub passages: Vec<Passage>,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct Passage {
#[serde(rename = "sourceId")]
pub source_id: String,
pub text: String,
pub rank: u32,
#[serde(default)]
pub start: Option<u32>,
#[serde(default)]
pub end: Option<u32>,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SourceList {
#[serde(rename = "notebookId")]
pub notebook_id: String,
pub count: u32,
pub sources: Vec<SourceSummary>,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SourceSummary {
pub id: String,
pub title: String,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct SourceText {
pub id: String,
pub title: String,
#[serde(rename = "notebookId")]
pub notebook_id: String,
pub content: String,
#[serde(rename = "totalChars")]
pub total_chars: u64,
#[serde(rename = "hasMore", default)]
pub has_more: bool,
#[serde(rename = "nextCursor", default)]
pub next_cursor: Option<u64>,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct Manual {
pub utcp_version: String,
pub manual_version: String,
pub tools: Vec<Tool>,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct Tool {
pub name: String,
#[serde(default)]
pub description: String,
pub tool_call_template: CallTemplate,
}
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct CallTemplate {
pub call_template_type: String,
pub http_method: String,
pub url: String,
}