Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(document): add web document service api #2904

Merged
merged 13 commits into from
Aug 19, 2024
37 changes: 24 additions & 13 deletions ee/tabby-schema/graphql/schema.graphql
wsxiaoys marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ type CompletionStats {
selects: Int!
}

type CustomDocumentConnection {
edges: [CustomDocumentEdge!]!
pageInfo: PageInfo!
}

type CustomDocumentEdge {
node: CustomWebDocument!
cursor: String!
}

type CustomWebDocument {
url: String!
name: String!
Expand Down Expand Up @@ -516,10 +526,21 @@ type PageInfo {
endCursor: String
}

type PresetDocumentConnection {
edges: [PresetDocumentEdge!]!
pageInfo: PageInfo!
}

type PresetDocumentEdge {
node: PresetWebDocument!
cursor: String!
}

type PresetWebDocument {
name: String!
id: ID!
jobInfo: JobInfo!
active: Boolean!
jobInfo: JobInfo
}

type ProvidedRepository {
Expand Down Expand Up @@ -593,8 +614,8 @@ type Query {
Thread is public within an instance, so no need to check for ownership.
"""
threadMessages(threadId: ID!, after: String, before: String, first: Int, last: Int): MessageConnection!
customWebDocuments(after: String, before: String, first: Int, last: Int): WebDocumentConnection!
presetWebDocuments(active: Boolean!): [PresetWebDocument!]!
customWebDocuments(after: String, before: String, first: Int, last: Int): CustomDocumentConnection!
presetWebDocuments(after: String, before: String, first: Int, last: Int, active: Boolean!): PresetDocumentConnection!
}

type RefreshTokenResponse {
Expand Down Expand Up @@ -739,13 +760,3 @@ type WebCrawlerUrlEdge {
node: WebCrawlerUrl!
cursor: String!
}

type WebDocumentConnection {
edges: [WebDocumentEdge!]!
pageInfo: PageInfo!
}

type WebDocumentEdge {
node: CustomWebDocument!
cursor: String!
}
22 changes: 17 additions & 5 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,23 @@ impl Query {
)
.await
}
async fn preset_web_documents(ctx: &Context, active: bool) -> Result<Vec<PresetWebDocument>> {
ctx.locator
.web_documents()
.list_preset_web_documents(active)
.await
async fn preset_web_documents(ctx: &Context,
after: Option<String>,
before: Option<String>,
first: Option<i32>,
last: Option<i32>,
active: bool) -> Result<Connection<PresetWebDocument>> {
query_async(
after,
before,
first,
last,
|after, before, first, last| async move {
ctx.locator
.web_documents()
.list_preset_web_documents(after, before, first, last, active)
.await
}).await
}
}

Expand Down
42 changes: 36 additions & 6 deletions ee/tabby-schema/src/schema/web_documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub struct CustomWebDocument {
pub struct PresetWebDocument {
pub name: String,
pub id: ID,
pub job_info: JobInfo,
pub active: bool,
pub job_info: Option<JobInfo>,
}

impl CustomWebDocument {
Expand All @@ -35,15 +36,23 @@ impl CustomWebDocument {

#[derive(Validate, GraphQLInputObject)]
pub struct CreateCustomDocumentInput {
#[validate(url(code = "name", message = "Invalid Name"))]
#[validate(regex(
code = "name",
path = "*crate::schema::constants::USERNAME_REGEX",
message = "Invalid repository name"
))]
pub name: String,
#[validate(url(code = "url", message = "Invalid URL"))]
pub url: String,
}

#[derive(Validate, GraphQLInputObject)]
pub struct SetPresetDocumentActiveInput {
#[validate(url(code = "name", message = "Invalid Name"))]
#[validate(regex(
code = "name",
path = "*crate::schema::constants::USERNAME_REGEX",
wsxiaoys marked this conversation as resolved.
Show resolved Hide resolved
message = "Invalid repository name"
))]
pub name: String,
xxs-wallace marked this conversation as resolved.
Show resolved Hide resolved
wsxiaoys marked this conversation as resolved.
Show resolved Hide resolved
pub active: bool,
}
Expand All @@ -56,11 +65,27 @@ impl NodeType for CustomWebDocument {
}

fn connection_type_name() -> &'static str {
"WebDocumentConnection"
"CustomDocumentConnection"
}

fn edge_type_name() -> &'static str {
"CustomDocumentEdge"
}
}

impl NodeType for PresetWebDocument {
type Cursor = String;

fn cursor(&self) -> Self::Cursor {
self.name.clone()
}

fn connection_type_name() -> &'static str {
"PresetDocumentConnection"
}

fn edge_type_name() -> &'static str {
"WebDocumentEdge"
"PresetDocumentEdge"
}
}

Expand All @@ -76,6 +101,11 @@ pub trait WebDocumentService: Send + Sync {

async fn create_custom_web_document(&self, name: String, url: String) -> Result<ID>;
async fn delete_custom_web_document(&self, id: ID) -> Result<()>;
async fn list_preset_web_documents(&self, active: bool) -> Result<Vec<PresetWebDocument>>;
async fn list_preset_web_documents(&self,
after: Option<String>,
before: Option<String>,
first: Option<usize>,
last: Option<usize>,
active: bool) -> Result<Vec<PresetWebDocument>>;
async fn set_preset_web_documents_active(&self, name: String, active: bool) -> Result<ID>;
}
7 changes: 6 additions & 1 deletion ee/tabby-webserver/src/service/web_documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ impl WebDocumentService for WebDocumentServiceImpl {
Ok(())
}

async fn list_preset_web_documents(&self, active: bool) -> Result<Vec<PresetWebDocument>> {
async fn list_preset_web_documents(&self,
after: Option<String>,
before: Option<String>,
first: Option<usize>,
last: Option<usize>,
active: bool) -> Result<Vec<PresetWebDocument>> {
Ok(vec![])
}

Expand Down