Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed Nov 14, 2024
1 parent 52fdde8 commit 2c297de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 35 deletions.
13 changes: 6 additions & 7 deletions ee/tabby-ui/components/chat/chat-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 (
<span className={cn('truncate', className)}>
{fileName}
{!!line && <span className="text-muted-foreground">{line}</span>}
<span className="text-muted-foreground">{line}</span>
</span>
)
}
34 changes: 18 additions & 16 deletions ee/tabby-ui/components/chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -175,7 +175,8 @@ function ChatRenderer(
]
setQaPairs(nextQaPairs)
const [userMessage, threadRunOptions] = generateRequestPayload(
qaPair.user
qaPair.user,
enableActiveSelection
)

return regenerate({
Expand Down Expand Up @@ -343,20 +344,19 @@ function ChatRenderer(
contextForCodeQuery = contextForCodeQuery || userMessage.activeContext
}

const codeQuery: InputMaybe<CodeQueryInput> =
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<CodeQueryInput> = 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,
Expand Down Expand Up @@ -412,7 +412,7 @@ function ChatRenderer(
selectContext: userMessage.selectContext,
// For forward compatibility
activeContext:
enableActiveSelection && isValidFileContext(finalActiveContext)
enableActiveSelection && finalActiveContext
? finalActiveContext
: undefined
}
Expand All @@ -432,7 +432,9 @@ function ChatRenderer(

setQaPairs(nextQaPairs)

sendUserMessage(...generateRequestPayload(newUserMessage))
sendUserMessage(
...generateRequestPayload(newUserMessage, enableActiveSelection)
)
}
)

Expand Down
12 changes: 0 additions & 12 deletions ee/tabby-ui/lib/utils/chat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { uniq } from 'lodash-es'
import { FileContext } from 'tabby-chat-panel/index'

import {
ContextInfo,
Expand Down Expand Up @@ -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)
}

0 comments on commit 2c297de

Please sign in to comment.