diff --git a/ee/tabby-schema/graphql/schema.graphql b/ee/tabby-schema/graphql/schema.graphql index 67c1b82377d1..e54c94d17977 100644 --- a/ee/tabby-schema/graphql/schema.graphql +++ b/ee/tabby-schema/graphql/schema.graphql @@ -715,6 +715,7 @@ type Query { userEvents(after: String, before: String, first: Int, last: Int, users: [ID!], start: DateTime!, end: DateTime!): UserEventConnection! diskUsageStats: DiskUsageStats! repositoryList: [Repository!]! + resolveGitUrl(gitUrl: String!): Repository 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 504b9ef0a02a..fa8c95ab95bb 100644 --- a/ee/tabby-schema/src/schema/mod.rs +++ b/ee/tabby-schema/src/schema/mod.rs @@ -541,6 +541,30 @@ impl Query { .await } + async fn resolve_git_url(ctx: &Context, git_url: String) -> Result> { + let user = check_user_and_auth_token(ctx, true).await?; + + let context_info = ctx.locator.context().read(Some(&user.policy)).await?; + let target_source_id: Option = context_info + .helper() + .allowed_code_repository() + .closest_match(&git_url) + .map(String::from); + let repos = ctx + .locator + .repository() + .repository_list(Some(&user.policy)) + .await?; + + // Iterate through repositories and find matching source_id + let matching_repo = repos.iter().find(|repo| { + // Match repo source_id with your target + Some(&repo.source_id) == target_source_id.as_ref() + }); + + Ok(matching_repo.cloned()) + } + 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/repository/mod.rs b/ee/tabby-schema/src/schema/repository/mod.rs index bfc91ef4c8e8..8d3ba6a52f3f 100644 --- a/ee/tabby-schema/src/schema/repository/mod.rs +++ b/ee/tabby-schema/src/schema/repository/mod.rs @@ -40,7 +40,7 @@ pub enum RepositoryKind { GitConfig, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Repository { pub id: ID, @@ -100,7 +100,7 @@ impl Repository { } } -#[derive(GraphQLObject, Debug)] +#[derive(GraphQLObject, Debug, Clone)] pub struct GitReference { pub name: String, pub commit: String, diff --git a/ee/tabby-schema/src/schema/thread/inputs.rs b/ee/tabby-schema/src/schema/thread/inputs.rs index 70d7d76edfa0..cd232ad93041 100644 --- a/ee/tabby-schema/src/schema/thread/inputs.rs +++ b/ee/tabby-schema/src/schema/thread/inputs.rs @@ -30,7 +30,7 @@ pub struct CreateThreadAndRunInput { pub options: ThreadRunOptionsInput, } -#[derive(GraphQLInputObject, Validate, Clone)] +#[derive(GraphQLInputObject, Validate, Clone, Debug)] pub struct DocQueryInput { pub content: String, @@ -41,7 +41,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, @@ -69,7 +69,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, @@ -89,7 +89,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, @@ -98,7 +98,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 2c5da6d76dbd..44535580864b 100644 --- a/ee/tabby-ui/app/chat/page.tsx +++ b/ee/tabby-ui/app/chat/page.tsx @@ -267,6 +267,7 @@ export default function ChatPage() { const onChatLoaded = () => { pendingRelevantContexts.forEach(addRelevantContext) pendingMessages.forEach(sendMessage) + chatRef.current?.updateActiveSelection(pendingActiveSelection) clearPendingState() diff --git a/ee/tabby-ui/components/chat/chat.tsx b/ee/tabby-ui/components/chat/chat.tsx index 03212c6c3295..cbc2db77da30 100644 --- a/ee/tabby-ui/components/chat/chat.tsx +++ b/ee/tabby-ui/components/chat/chat.tsx @@ -35,6 +35,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 { ResolveGitUrlQuery } from '@/lib/gql/generates/graphql' +import { resolveGitUrlQuery, repositoryListQuery } from '@/lib/tabby/query' type ChatContextValue = { threadId: string | undefined @@ -101,6 +105,19 @@ interface ChatProps extends React.ComponentProps<'div'> { supportsOnApplyInEditorV2: boolean } +async function resolveGitUrl(gitUrl: string): Promise< + ResolveGitUrlQuery['resolveGitUrl'] +> { + const query = client.createRequestOperation( + 'query', + createRequest(resolveGitUrlQuery, { gitUrl }) + ) + + return client + .executeQuery(query) + .then(data => console.log('data', data)) as any +} + function ChatRenderer( { className, @@ -497,6 +514,9 @@ function ChatRenderer( const debouncedUpdateActiveSelection = useDebounceCallback( (ctx: Context | null) => { + console.log('ctx', ctx); + // if (ctx?.git_url) resolveGitUrl(ctx.git_url) + setActiveSelection(ctx) }, 300 diff --git a/ee/tabby-ui/lib/tabby/query.ts b/ee/tabby-ui/lib/tabby/query.ts index c1088a2ddad1..93ae9adc9483 100644 --- a/ee/tabby-ui/lib/tabby/query.ts +++ b/ee/tabby-ui/lib/tabby/query.ts @@ -280,6 +280,24 @@ export const repositoryListQuery = graphql(/* GraphQL */ ` } `) +export const resolveGitUrlQuery = graphql(/* GraphQL */ ` + query ResolveGitUrl($gitUrl: String!) { + resolveGitUrl(gitUrl: $gitUrl) { + id + sourceId + sourceKind + sourceName + name + kind + gitUrl + refs { + name + commit + } + } + } +`) + export const repositorySearch = graphql(/* GraphQL */ ` query RepositorySearch( $kind: RepositoryKind!