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

WIP: front end and backend draft #3522

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ee/tabby-schema/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
24 changes: 24 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,30 @@ impl Query {
.await
}

async fn resolve_git_url(ctx: &Context, git_url: String) -> Result<Option<Repository>> {
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<String> = 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<ContextInfo> {
let user = check_user(ctx).await?;
ctx.locator.context().read(Some(&user.policy)).await
Expand Down
4 changes: 2 additions & 2 deletions ee/tabby-schema/src/schema/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub enum RepositoryKind {
GitConfig,
}

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct Repository {
pub id: ID,

Expand Down Expand Up @@ -100,7 +100,7 @@ impl Repository {
}
}

#[derive(GraphQLObject, Debug)]
#[derive(GraphQLObject, Debug, Clone)]
pub struct GitReference {
pub name: String,
pub commit: String,
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 @@ -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,

Expand All @@ -41,7 +41,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 @@ -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<String>,
Expand All @@ -89,7 +89,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 @@ -98,7 +98,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
1 change: 1 addition & 0 deletions ee/tabby-ui/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export default function ChatPage() {
const onChatLoaded = () => {
pendingRelevantContexts.forEach(addRelevantContext)
pendingMessages.forEach(sendMessage)

chatRef.current?.updateActiveSelection(pendingActiveSelection)

clearPendingState()
Expand Down
20 changes: 20 additions & 0 deletions ee/tabby-ui/components/chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 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,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!
Expand Down
Loading