From 2c297dea7b811f5d3046dd5632d40bdafc96f735 Mon Sep 17 00:00:00 2001 From: liangfung Date: Thu, 14 Nov 2024 13:39:47 +0700 Subject: [PATCH] update --- ee/tabby-ui/components/chat/chat-panel.tsx | 13 ++++----- ee/tabby-ui/components/chat/chat.tsx | 34 ++++++++++++---------- ee/tabby-ui/lib/utils/chat.ts | 12 -------- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/ee/tabby-ui/components/chat/chat-panel.tsx b/ee/tabby-ui/components/chat/chat-panel.tsx index 3006113391e2..3fa1bf47a046 100644 --- a/ee/tabby-ui/components/chat/chat-panel.tsx +++ b/ee/tabby-ui/components/chat/chat-panel.tsx @@ -5,7 +5,7 @@ import type { Context } from 'tabby-chat-panel' import { updateEnableActiveSelection } from '@/lib/stores/chat-actions' import { useChatStore } from '@/lib/stores/chat-store' -import { cn, isFileContextContentEmpty } from '@/lib/utils' +import { cn } from '@/lib/utils' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { @@ -215,16 +215,15 @@ function ContextLabel({ className?: string }) { const [fileName] = context.filepath.split('/').slice(-1) - const line = isFileContextContentEmpty(context) - ? '' - : context.range.start === context.range.end - ? `:${context.range.start}` - : `:${context.range.start}-${context.range.end}` + const line = + context.range.start === context.range.end + ? `:${context.range.start}` + : `:${context.range.start}-${context.range.end}` return ( {fileName} - {!!line && {line}} + {line} ) } diff --git a/ee/tabby-ui/components/chat/chat.tsx b/ee/tabby-ui/components/chat/chat.tsx index bf87930d0fd3..de77667c018e 100644 --- a/ee/tabby-ui/components/chat/chat.tsx +++ b/ee/tabby-ui/components/chat/chat.tsx @@ -23,7 +23,7 @@ import { UserMessage, UserMessageWithOptionalId } from '@/lib/types/chat' -import { cn, isValidFileContext, nanoid } from '@/lib/utils' +import { cn, nanoid } from '@/lib/utils' import { ListSkeleton } from '../skeleton' import { ChatPanel, ChatPanelRef } from './chat-panel' @@ -175,7 +175,8 @@ function ChatRenderer( ] setQaPairs(nextQaPairs) const [userMessage, threadRunOptions] = generateRequestPayload( - qaPair.user + qaPair.user, + enableActiveSelection ) return regenerate({ @@ -343,20 +344,19 @@ function ChatRenderer( contextForCodeQuery = contextForCodeQuery || userMessage.activeContext } - const codeQuery: InputMaybe = - contextForCodeQuery && isValidFileContext(contextForCodeQuery) - ? { - content: contextForCodeQuery.content ?? '', - filepath: contextForCodeQuery.filepath, - language: contextForCodeQuery.filepath - ? filename2prism(contextForCodeQuery.filepath)[0] || 'text' - : 'text', - gitUrl: contextForCodeQuery?.git_url ?? '' - } - : null + const codeQuery: InputMaybe = contextForCodeQuery + ? { + content: contextForCodeQuery.content ?? '', + filepath: contextForCodeQuery.filepath, + language: contextForCodeQuery.filepath + ? filename2prism(contextForCodeQuery.filepath)[0] || 'text' + : 'text', + gitUrl: contextForCodeQuery?.git_url ?? '' + } + : null const hasUsableActiveContext = - enableActiveSelection && isValidFileContext(userMessage.activeContext) + enableActiveSelection && !!userMessage.activeContext const fileContext: FileContext[] = uniqWith( compact([ hasUsableActiveContext && userMessage.activeContext, @@ -412,7 +412,7 @@ function ChatRenderer( selectContext: userMessage.selectContext, // For forward compatibility activeContext: - enableActiveSelection && isValidFileContext(finalActiveContext) + enableActiveSelection && finalActiveContext ? finalActiveContext : undefined } @@ -432,7 +432,9 @@ function ChatRenderer( setQaPairs(nextQaPairs) - sendUserMessage(...generateRequestPayload(newUserMessage)) + sendUserMessage( + ...generateRequestPayload(newUserMessage, enableActiveSelection) + ) } ) diff --git a/ee/tabby-ui/lib/utils/chat.ts b/ee/tabby-ui/lib/utils/chat.ts index 4a87ef9015c6..b2775a75e450 100644 --- a/ee/tabby-ui/lib/utils/chat.ts +++ b/ee/tabby-ui/lib/utils/chat.ts @@ -1,5 +1,4 @@ import { uniq } from 'lodash-es' -import { FileContext } from 'tabby-chat-panel/index' import { ContextInfo, @@ -106,14 +105,3 @@ export function checkSourcesAvailability( return { hasCodebaseSource, hasDocumentSource } } - -export function isFileContextContentEmpty(context: FileContext) { - return context.range.start === 0 -} - -export function isValidFileContext(context: FileContext | null | undefined) { - if (!context) return false - - // FIXME: evaluate the necessity of permitting an empty git_url - return !!context.git_url && !isFileContextContentEmpty(context) -}