From 9f46d778d0c3cfeef99c075332b87a7450a13f38 Mon Sep 17 00:00:00 2001 From: zzgu Date: Tue, 10 Dec 2024 14:02:02 -0800 Subject: [PATCH] feat(graphQL): check weather current workspace is indexed --- ee/tabby-schema/graphql/schema.graphql | 1 + ee/tabby-schema/src/schema/mod.rs | 17 ++++++++++ ee/tabby-schema/src/schema/thread/inputs.rs | 10 +++--- ee/tabby-ui/app/chat/page.tsx | 4 +++ ee/tabby-ui/components/chat/chat.tsx | 35 +++++++++++++++++++++ ee/tabby-ui/lib/tabby/gql.ts | 1 + ee/tabby-ui/lib/tabby/query.ts | 6 ++++ 7 files changed, 69 insertions(+), 5 deletions(-) diff --git a/ee/tabby-schema/graphql/schema.graphql b/ee/tabby-schema/graphql/schema.graphql index 97c59b64c9d0..a384084a15b9 100644 --- a/ee/tabby-schema/graphql/schema.graphql +++ b/ee/tabby-schema/graphql/schema.graphql @@ -713,6 +713,7 @@ type Query { userEvents(after: String, before: String, first: Int, last: Int, users: [ID!], start: DateTime!, end: DateTime!): UserEventConnection! diskUsageStats: DiskUsageStats! repositoryList: [Repository!]! + isAvaileableWorkspace(gitUrl: String!): Boolean! contextInfo: ContextInfo! integrations(ids: [ID!], kind: IntegrationKind, after: String, before: String, first: Int, last: Int): IntegrationConnection! integratedRepositories(ids: [ID!], kind: IntegrationKind, active: Boolean, after: String, before: String, first: Int, last: Int): ProvidedRepositoryConnection! diff --git a/ee/tabby-schema/src/schema/mod.rs b/ee/tabby-schema/src/schema/mod.rs index c2a9bd9fd169..cd1cf10827cf 100644 --- a/ee/tabby-schema/src/schema/mod.rs +++ b/ee/tabby-schema/src/schema/mod.rs @@ -541,6 +541,23 @@ impl Query { .await } + async fn resolve_git_url(ctx: &Context, git_url: String) -> Result> { + let user = check_user(ctx).await?; + + let repositorys = ctx.locator + .repository() + .repository_list(Some(&user.policy)) + .await.unwrap_or_default(); + + for repo in repositorys { + if repo.git_url == git_url { + return Ok(repo); + } + } + + return Ok(None); + } + async fn context_info(ctx: &Context) -> Result { let user = check_user(ctx).await?; ctx.locator.context().read(Some(&user.policy)).await diff --git a/ee/tabby-schema/src/schema/thread/inputs.rs b/ee/tabby-schema/src/schema/thread/inputs.rs index b495b153d3c8..406569916368 100644 --- a/ee/tabby-schema/src/schema/thread/inputs.rs +++ b/ee/tabby-schema/src/schema/thread/inputs.rs @@ -29,7 +29,7 @@ pub struct CreateThreadAndRunInput { pub options: ThreadRunOptionsInput, } -#[derive(GraphQLInputObject, Validate, Clone)] +#[derive(GraphQLInputObject, Validate, Clone, Debug)] pub struct DocQueryInput { pub content: String, @@ -40,7 +40,7 @@ pub struct DocQueryInput { pub source_ids: Option>, } -#[derive(GraphQLInputObject, Validate, Clone)] +#[derive(GraphQLInputObject, Validate, Clone, Debug)] #[validate(schema(function = "validate_code_query_input", skip_on_field_errors = false))] pub struct CodeQueryInput { pub filepath: Option, @@ -68,7 +68,7 @@ fn validate_code_query_input(input: &CodeQueryInput) -> Result<(), ValidationErr Ok(()) } -#[derive(GraphQLInputObject, Validate, Default, Clone)] +#[derive(GraphQLInputObject, Validate, Default, Clone, Debug)] pub struct ThreadRunOptionsInput { #[graphql(default)] pub model_name: Option, @@ -88,7 +88,7 @@ pub struct ThreadRunOptionsInput { pub debug_options: Option, } -#[derive(GraphQLInputObject, Clone)] +#[derive(GraphQLInputObject, Clone, Debug)] pub struct CodeSearchParamsOverrideInput { pub min_embedding_score: Option, pub min_bm25_score: Option, @@ -97,7 +97,7 @@ pub struct CodeSearchParamsOverrideInput { pub num_to_score: Option, } -#[derive(GraphQLInputObject, Clone)] +#[derive(GraphQLInputObject, Clone, Debug)] pub struct ThreadRunDebugOptionsInput { #[graphql(default)] pub code_search_params_override: Option, diff --git a/ee/tabby-ui/app/chat/page.tsx b/ee/tabby-ui/app/chat/page.tsx index 6f14266a0909..5c3ef01e2014 100644 --- a/ee/tabby-ui/app/chat/page.tsx +++ b/ee/tabby-ui/app/chat/page.tsx @@ -128,6 +128,7 @@ export default function ChatPage() { setErrorMessage(null) }, addRelevantContext: context => { + console.log('context', context) return addRelevantContext(context) }, updateTheme: (style, themeClass) => { @@ -265,6 +266,9 @@ export default function ChatPage() { const onChatLoaded = () => { pendingRelevantContexts.forEach(addRelevantContext) pendingMessages.forEach(sendMessage) + + console.log('pendingActiveSelection', pendingActiveSelection) + chatRef.current?.updateActiveSelection(pendingActiveSelection) clearPendingState() diff --git a/ee/tabby-ui/components/chat/chat.tsx b/ee/tabby-ui/components/chat/chat.tsx index c86caee905a1..e0e02ec8da75 100644 --- a/ee/tabby-ui/components/chat/chat.tsx +++ b/ee/tabby-ui/components/chat/chat.tsx @@ -8,6 +8,7 @@ import { CreateMessageInput, InputMaybe, MessageAttachmentCodeInput, + RepositoryListQuery, ThreadRunOptionsInput } from '@/lib/gql/generates/graphql' import { useDebounceCallback } from '@/lib/hooks/use-debounce' @@ -30,6 +31,10 @@ import { ChatPanel, ChatPanelRef } from './chat-panel' import { ChatScrollAnchor } from './chat-scroll-anchor' import { EmptyScreen } from './empty-screen' import { QuestionAnswerList } from './question-answer' +import { createRequest } from '@urql/core' +import { client } from '@/lib/tabby/gql' +import { IsAvaileableWorkspaceQuery } from '@/lib/gql/generates/graphql' +import { isAvaileableWorkspaceQuery, repositoryListQuery } from '@/lib/tabby/query' type ChatContextValue = { threadId: string | undefined @@ -88,6 +93,32 @@ interface ChatProps extends React.ComponentProps<'div'> { supportsOnApplyInEditorV2: boolean } +async function isAvaileableWorkspace(gitUrl: string): Promise< + IsAvaileableWorkspaceQuery['isAvaileableWorkspace'] +> { + // debugger + const query = client.createRequestOperation( + 'query', + createRequest(isAvaileableWorkspaceQuery, { gitUrl }) + ) + + return client + .executeQuery(query) + .then(data => console.log('data', data)) as any +} + +async function fetchAllRepositories(): Promise< + RepositoryListQuery['repositoryList'] +> { + const query = client.createRequestOperation( + 'query', + createRequest(repositoryListQuery, {}) + ) + return client + .executeQuery(query) + .then(data => data?.data?.repositoryList || []) +} + function ChatRenderer( { className, @@ -483,6 +514,10 @@ function ChatRenderer( const debouncedUpdateActiveSelection = useDebounceCallback( (ctx: Context | null) => { + console.log('ctx', ctx); + if (ctx?.git_url) isAvaileableWorkspace(ctx.git_url) + + fetchAllRepositories().then(res => console.log('fetchres', res)) setActiveSelection(ctx) }, 300 diff --git a/ee/tabby-ui/lib/tabby/gql.ts b/ee/tabby-ui/lib/tabby/gql.ts index 6274cc18f0de..3a87ef9b7e9c 100644 --- a/ee/tabby-ui/lib/tabby/gql.ts +++ b/ee/tabby-ui/lib/tabby/gql.ts @@ -123,6 +123,7 @@ const client = new Client({ ServerInfo: () => null, RepositorySearch: () => null, RepositoryList: () => null, + // IsAvaileableWorkspace: () => null, RepositoryGrep: () => null, GrepLine: () => null, GrepFile: () => null, diff --git a/ee/tabby-ui/lib/tabby/query.ts b/ee/tabby-ui/lib/tabby/query.ts index 10375f3025da..800b6e00fc08 100644 --- a/ee/tabby-ui/lib/tabby/query.ts +++ b/ee/tabby-ui/lib/tabby/query.ts @@ -280,6 +280,12 @@ export const repositoryListQuery = graphql(/* GraphQL */ ` } `) +export const isAvaileableWorkspaceQuery = graphql(/* GraphQL */ ` + query IsAvaileableWorkspace($gitUrl: String!) { + isAvaileableWorkspace(gitUrl: $gitUrl) + } +`) + export const repositorySearch = graphql(/* GraphQL */ ` query RepositorySearch( $kind: RepositoryKind!