1use serde::{Deserialize, Serialize};
2
3pub use crate::tls::TlsConfig;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct FetchResult {
8 pub title: String,
9 pub final_url: String,
10 pub content: String,
11 pub content_type: ContentType,
12 pub media: String,
15 pub token_estimate: usize,
16 pub references: Vec<UrlReference>,
17 #[serde(default)]
18 pub metadata: Metadata,
19 pub source: String,
20}
21
22#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
24pub struct Metadata {
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub description: Option<String>,
27 #[serde(skip_serializing_if = "Option::is_none")]
28 pub author: Option<String>,
29 #[serde(skip_serializing_if = "Option::is_none")]
30 pub published: Option<String>,
31 #[serde(skip_serializing_if = "Option::is_none")]
32 pub lang: Option<String>,
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub site_name: Option<String>,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
39pub struct UrlReference {
40 pub index: usize,
41 pub url: String,
42 pub text: String,
44}
45
46impl crate::refs::Referable for UrlReference {
47 fn index(&self) -> usize {
48 self.index
49 }
50 fn url(&self) -> &str {
51 &self.url
52 }
53}
54
55#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
56#[serde(rename_all = "lowercase")]
57pub enum ContentType {
58 Text,
59 Markdown,
60 Structured,
61}
62
63impl ContentType {
64 pub fn parse(s: &str) -> Self {
65 match s.to_ascii_lowercase().as_str() {
66 "markdown" | "md" => ContentType::Markdown,
67 "structured" | "json" => ContentType::Structured,
68 _ => ContentType::Text,
69 }
70 }
71}
72
73#[derive(Debug, Clone, Deserialize)]
74pub struct FetchOptions {
75 pub url: String,
76 pub content_type: ContentType,
77 pub max_tokens: Option<usize>,
78 pub timeout_secs: u64,
79 #[serde(default)]
82 pub tls: TlsConfig,
83}
84
85impl Default for FetchOptions {
86 fn default() -> Self {
87 Self {
88 url: String::new(),
89 content_type: ContentType::Text,
90 max_tokens: None,
91 timeout_secs: 10,
92 tls: TlsConfig::default(),
93 }
94 }
95}