Skip to main content

synapto_interface/
document.rs

1use crate::plugin::Plugin;
2use crate::sync::mpsc;
3use async_trait::async_trait;
4use schemars::JsonSchema;
5use serde::{Deserialize, Serialize};
6
7#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, JsonSchema)]
8pub enum DocumentIngestionPolicy {
9    #[doc = " Save the raw document only, do not attempt to parse or extract text."]
10    Store,
11    #[doc = " Save the raw document and run active parsers (e.g. PDF parser) to extract UTF-8 text."]
12    StoreAndParse,
13}
14
15#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, JsonSchema)]
16pub struct DocumentRegistrationRequest {
17    pub original_filename: String,
18    pub mime_type: String,
19    pub data: Vec<u8>,
20    pub policy: DocumentIngestionPolicy,
21}
22
23pub struct AddDocumentRequest {
24    pub request: DocumentRegistrationRequest,
25    pub reply_tx: tokio::sync::oneshot::Sender<DocumentId>,
26}
27
28#[doc = " A unique identifier for a document resource."]
29#[derive(
30    Serialize,
31    Deserialize,
32    JsonSchema,
33    PartialEq,
34    Eq,
35    Debug,
36    Clone,
37    derive_more :: Display,
38    derive_more :: From,
39    derive_more :: Deref,
40)]
41pub struct DocumentId(pub String);
42
43#[async_trait]
44pub trait DocumentsPlugin: Plugin + Send + Sync {
45    async fn start(
46        &self,
47        add_document_rx: mpsc::Receiver<crate::document::AddDocumentRequest>,
48    ) -> Result<(), String>;
49}
50
51#[async_trait]
52pub trait DocumentProviderPlugin: Plugin + Send + Sync {
53    async fn start_document_provider(
54        &self,
55        add_document_tx: mpsc::Sender<crate::document::AddDocumentRequest>,
56    ) -> Result<(), String>;
57}