Skip to content

Commit

Permalink
feat(graphQL): check weather current workspace is indexed
Browse files Browse the repository at this point in the history
  • Loading branch information
antimonyGu committed Dec 10, 2024
1 parent b4fba58 commit 9f46d77
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 5 deletions.
1 change: 1 addition & 0 deletions ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
17 changes: 17 additions & 0 deletions ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,23 @@ impl Query {
.await
}

async fn resolve_git_url(ctx: &Context, git_url: String) -> Result<Option<Repository>> {
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<ContextInfo> {
let user = check_user(ctx).await?;
ctx.locator.context().read(Some(&user.policy)).await
Expand Down
10 changes: 5 additions & 5 deletions ee/tabby-schema/src/schema/thread/inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand All @@ -40,7 +40,7 @@ pub struct DocQueryInput {
pub source_ids: Option<Vec<String>>,
}

#[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<String>,
Expand Down Expand Up @@ -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<String>,
Expand All @@ -88,7 +88,7 @@ pub struct ThreadRunOptionsInput {
pub debug_options: Option<ThreadRunDebugOptionsInput>,
}

#[derive(GraphQLInputObject, Clone)]
#[derive(GraphQLInputObject, Clone, Debug)]
pub struct CodeSearchParamsOverrideInput {
pub min_embedding_score: Option<f64>,
pub min_bm25_score: Option<f64>,
Expand All @@ -97,7 +97,7 @@ pub struct CodeSearchParamsOverrideInput {
pub num_to_score: Option<i32>,
}

#[derive(GraphQLInputObject, Clone)]
#[derive(GraphQLInputObject, Clone, Debug)]
pub struct ThreadRunDebugOptionsInput {
#[graphql(default)]
pub code_search_params_override: Option<CodeSearchParamsOverrideInput>,
Expand Down
4 changes: 4 additions & 0 deletions ee/tabby-ui/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default function ChatPage() {
setErrorMessage(null)
},
addRelevantContext: context => {
console.log('context', context)
return addRelevantContext(context)
},
updateTheme: (style, themeClass) => {
Expand Down Expand Up @@ -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()
Expand Down
35 changes: 35 additions & 0 deletions ee/tabby-ui/components/chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
CreateMessageInput,
InputMaybe,
MessageAttachmentCodeInput,
RepositoryListQuery,
ThreadRunOptionsInput
} from '@/lib/gql/generates/graphql'
import { useDebounceCallback } from '@/lib/hooks/use-debounce'
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions ee/tabby-ui/lib/tabby/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const client = new Client({
ServerInfo: () => null,
RepositorySearch: () => null,
RepositoryList: () => null,
// IsAvaileableWorkspace: () => null,
RepositoryGrep: () => null,
GrepLine: () => null,
GrepFile: () => null,
Expand Down
6 changes: 6 additions & 0 deletions ee/tabby-ui/lib/tabby/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 9f46d77

Please sign in to comment.