Skip to content

Commit

Permalink
feat(chat): display git repo connected status in chat side panel (#3550)
Browse files Browse the repository at this point in the history
* feat(ui): resolve indexed repository of IDE workspace

* [autofix.ci] apply automated fixes

* update: sync git url

* update: lint

* update: lint

* update: animation

* update

* feat(ui): add repo select in chat sidebar

* update

* update: set default repo

* update: code_query

* [autofix.ci] apply automated fixes

* update: focus

* update: type

* Update ee/tabby-ui/components/chat/repo-select.tsx

* Apply suggestions from code review

* update

* update: styling

* Update ee/tabby-ui/components/chat/repo-select.tsx

* [autofix.ci] apply automated fixes

* update: optional

* update

* update: chat panel api

* [autofix.ci] apply automated fixes

* update: init

* update: init

* update: revert

* update

* Update clients/tabby-chat-panel/src/index.ts

Co-authored-by: Meng Zhang <[email protected]>

* Update clients/tabby-chat-panel/src/index.ts

Co-authored-by: Meng Zhang <[email protected]>

* Update clients/tabby-chat-panel/src/index.ts

Co-authored-by: Meng Zhang <[email protected]>

* update: rename

* update

* update: test

* update

* update: remove

* update: test

* update

* update: test cases

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Meng Zhang <[email protected]>
  • Loading branch information
3 people authored Dec 19, 2024
1 parent 2efdab9 commit 0942d09
Show file tree
Hide file tree
Showing 14 changed files with 646 additions and 67 deletions.
11 changes: 11 additions & 0 deletions clients/tabby-chat-panel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ export interface SymbolInfo {
target: FileLocation
}

/**
* Includes information about a git repository in workspace folder
*/
export interface GitRepository {
url: string
}

export interface ServerApi {
init: (request: InitRequest) => void
sendMessage: (message: ChatMessage) => void
Expand Down Expand Up @@ -224,6 +231,9 @@ export interface ClientApiMethods {
* @returns Whether the file location is opened successfully.
*/
openInEditor: (target: FileLocation) => Promise<boolean>

// Provide all repos found in workspace folders.
readWorkspaceGitRepositories?: () => Promise<GitRepository[]>
}

export interface ClientApi extends ClientApiMethods {
Expand Down Expand Up @@ -258,6 +268,7 @@ export function createClient(target: HTMLIFrameElement, api: ClientApiMethods):
onKeyboardEvent: api.onKeyboardEvent,
lookupSymbol: api.lookupSymbol,
openInEditor: api.openInEditor,
readWorkspaceGitRepositories: api.readWorkspaceGitRepositories,
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-schema/src/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ impl Query {
}

async fn repository_list(ctx: &Context) -> Result<Vec<Repository>> {
let user = check_user(ctx).await?;
let user = check_user_allow_auth_token(ctx).await?;

ctx.locator
.repository()
Expand Down
12 changes: 12 additions & 0 deletions ee/tabby-ui/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export default function ChatPage() {
const [supportsOnApplyInEditorV2, setSupportsOnApplyInEditorV2] =
useState(false)
const [supportsOnLookupSymbol, setSupportsOnLookupSymbol] = useState(false)
const [
supportsProvideWorkspaceGitRepoInfo,
setSupportsProvideWorkspaceGitRepoInfo
] = useState(false)

const sendMessage = (message: ChatMessage) => {
if (chatRef.current) {
Expand Down Expand Up @@ -238,6 +242,9 @@ export default function ChatPage() {
?.hasCapability('onApplyInEditorV2')
.then(setSupportsOnApplyInEditorV2)
server?.hasCapability('lookupSymbol').then(setSupportsOnLookupSymbol)
server
?.hasCapability('readWorkspaceGitRepositories')
.then(setSupportsProvideWorkspaceGitRepoInfo)
}

checkCapabilities()
Expand Down Expand Up @@ -395,6 +402,11 @@ export default function ChatPage() {
(supportsOnLookupSymbol ? server?.lookupSymbol : undefined)
}
openInEditor={isInEditor && server?.openInEditor}
readWorkspaceGitRepositories={
isInEditor && supportsProvideWorkspaceGitRepoInfo
? server?.readWorkspaceGitRepositories
: undefined
}
/>
</ErrorBoundary>
)
Expand Down
26 changes: 25 additions & 1 deletion ee/tabby-ui/components/chat/chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
IconCheck,
IconEye,
IconEyeOff,
IconFileText,
IconRefresh,
IconRemove,
IconShare,
Expand All @@ -32,6 +33,7 @@ import { FooterText } from '@/components/footer'

import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip'
import { ChatContext } from './chat'
import { RepoSelect } from './repo-select'

export interface ChatPanelProps
extends Pick<UseChatHelpers, 'stop' | 'input' | 'setInput'> {
Expand Down Expand Up @@ -70,11 +72,16 @@ function ChatPanelRenderer(
relevantContext,
removeRelevantContext,
activeSelection,
onCopyContent
onCopyContent,
selectedRepoId,
setSelectedRepoId,
repos,
initialized
} = React.useContext(ChatContext)
const enableActiveSelection = useChatStore(
state => state.enableActiveSelection
)

const [persisting, setPerisiting] = useState(false)
const { width } = useWindowSize()
const isExtraSmallScreen = typeof width === 'number' && width < 376
Expand Down Expand Up @@ -124,6 +131,14 @@ function ChatPanelRenderer(
}
}

const onSelectRepo = (sourceId: string | undefined) => {
setSelectedRepoId(sourceId)

setTimeout(() => {
chatInputRef.current?.focus()
})
}

React.useImperativeHandle(
ref,
() => {
Expand Down Expand Up @@ -220,8 +235,15 @@ function ChatPanelRenderer(
<div className="border-t bg-background px-4 py-2 shadow-lg sm:space-y-4 sm:rounded-t-xl sm:border md:py-4">
<div className="flex flex-wrap gap-2">
<AnimatePresence presenceAffectsLayout>
<RepoSelect
value={selectedRepoId}
onChange={onSelectRepo}
repos={repos}
isInitializing={!initialized}
/>
{activeSelection ? (
<motion.div
key="active-selection"
initial={{ opacity: 0, scale: 0.9, y: -5 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
transition={{
Expand All @@ -240,6 +262,7 @@ function ChatPanelRenderer(
}
)}
>
<IconFileText />
<ContextLabel
context={activeSelection}
className="flex-1 truncate"
Expand Down Expand Up @@ -300,6 +323,7 @@ function ChatPanelRenderer(
setInput={setInput}
isLoading={isLoading}
chatInputRef={chatInputRef}
isInitializing={!initialized}
/>
<FooterText className="hidden sm:block" />
</div>
Expand Down
Loading

0 comments on commit 0942d09

Please sign in to comment.