Skip to content

Commit

Permalink
Merge 8b47b04 into 2efdab9
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung authored Dec 19, 2024
2 parents 2efdab9 + 8b47b04 commit 3f88336
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 3f88336

Please sign in to comment.