Skip to content

Commit

Permalink
chore: Update createClient and useClient function parameter names
Browse files Browse the repository at this point in the history
Update the second parameter of the createClient function in index.ts and the useClient function in react.ts from `api: ClientApi` to `api: ClientApiMethods`. This change improves the clarity and consistency of the function parameter names.
  • Loading branch information
Sma1lboy committed Nov 30, 2024
1 parent 04176ef commit f1ad5fb
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 38 deletions.
23 changes: 9 additions & 14 deletions ee/tabby-ui/app/chat/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { ErrorBoundary } from 'react-error-boundary'
import remarkGfm from 'remark-gfm'
import remarkMath from 'remark-math'
import {
clientApiKeys,
TABBY_CHAT_PANEL_API_VERSION,
type ChatMessage,
type Context,
Expand Down Expand Up @@ -72,6 +71,10 @@ export default function ChatPage() {
const isInEditor = !!client || undefined
const useMacOSKeyboardEventHandler = useRef<boolean>()

// server feature support check
const [supportsOnApplyInEditorV2, setSupportsOnApplyInEditorV2] =
useState(false)

const sendMessage = (message: ChatMessage) => {
if (chatRef.current) {
chatRef.current.sendUserChat(message)
Expand Down Expand Up @@ -223,24 +226,16 @@ export default function ChatPage() {
}
}, [server, client])

const [serverCapabilities, setServerCapabilities] = useState(
new Map<string, boolean>()
)

useEffect(() => {
if (server) {
server?.onLoaded({
apiVersion: TABBY_CHAT_PANEL_API_VERSION
})

const checkCapabilities = async () => {
const results = await Promise.all(
clientApiKeys.map(async key => {
const hasCapability = await server.hasCapability!(key)
return [key, hasCapability] as [string, boolean]
})
)
setServerCapabilities(new Map(results))
server
?.hasCapability('onApplyInEditorV2')
.then(setSupportsOnApplyInEditorV2)
}

checkCapabilities()
Expand Down Expand Up @@ -388,11 +383,11 @@ export default function ChatPage() {
onSubmitMessage={isInEditor && server?.onSubmitMessage}
onApplyInEditor={
isInEditor &&
(serverCapabilities.get('onApplyInEditorV2')
(supportsOnApplyInEditorV2
? server?.onApplyInEditorV2
: server?.onApplyInEditor)
}
serverCapabilities={serverCapabilities}
supportsOnApplyInEditorV2={supportsOnApplyInEditorV2}
/>
</ErrorBoundary>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
TooltipContent,
TooltipTrigger
} from '@/components/ui/tooltip'
import { ChatContext } from '@/components/chat/chat'
import { CodeReferences } from '@/components/chat/code-references'
import { CopyButton } from '@/components/copy-button'
import {
Expand All @@ -65,7 +66,6 @@ import {
} from '@/components/message-markdown'

import { ConversationMessage, SearchContext, SOURCE_CARD_STYLE } from './search'
import { ChatContext } from '@/components/chat/chat'

export function AssistantMessageSection({
message,
Expand Down Expand Up @@ -95,7 +95,7 @@ export function AssistantMessageSection({
onUpdateMessage
} = useContext(SearchContext)

const {serverCapabilities}= useContext(ChatContext)
const { supportsOnApplyInEditorV2 } = useContext(ChatContext)

const [isEditing, setIsEditing] = useState(false)
const [showMoreSource, setShowMoreSource] = useState(false)
Expand Down Expand Up @@ -331,7 +331,7 @@ export function AssistantMessageSection({
contextInfo={contextInfo}
fetchingContextInfo={fetchingContextInfo}
canWrapLongLines={!isLoading}
serverCapabilities={serverCapabilities}
supportsOnApplyInEditorV2={supportsOnApplyInEditorV2}
/>
{/* if isEditing, do not display error message block */}
{message.error && <ErrorMessageBlock error={message.error} />}
Expand Down
4 changes: 2 additions & 2 deletions ee/tabby-ui/app/search/components/user-message-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export function UserMessageSection({
...props
}: QuestionBlockProps) {
const { contextInfo, fetchingContextInfo } = useContext(SearchContext)
const { serverCapabilities } = useContext(ChatContext)
const { supportsOnApplyInEditorV2 } = useContext(ChatContext)
return (
<div className={cn('font-semibold', className)} {...props}>
<MessageMarkdown
message={message.content}
contextInfo={contextInfo}
serverCapabilities={serverCapabilities}
supportsOnApplyInEditorV2={supportsOnApplyInEditorV2}
fetchingContextInfo={fetchingContextInfo}
className="text-xl prose-p:mb-2 prose-p:mt-0"
headline
Expand Down
8 changes: 4 additions & 4 deletions ee/tabby-ui/components/chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type ChatContextValue = {
activeSelection: Context | null
removeRelevantContext: (index: number) => void
chatInputRef: RefObject<HTMLTextAreaElement>
serverCapabilities: Map<string, boolean>
supportsOnApplyInEditorV2: boolean
}

export const ChatContext = React.createContext<ChatContextValue>(
Expand Down Expand Up @@ -84,7 +84,7 @@ interface ChatProps extends React.ComponentProps<'div'> {
| ((content: string) => void)
| ((content: string, opts?: { languageId: string; smart: boolean }) => void)
chatInputRef: RefObject<HTMLTextAreaElement>
serverCapabilities: Map<string, boolean>
supportsOnApplyInEditorV2: boolean
}

function ChatRenderer(
Expand All @@ -105,7 +105,7 @@ function ChatRenderer(
onSubmitMessage,
onApplyInEditor,
chatInputRef,
serverCapabilities
supportsOnApplyInEditorV2
}: ChatProps,
ref: React.ForwardedRef<ChatRef>
) {
Expand Down Expand Up @@ -533,7 +533,7 @@ function ChatRenderer(
removeRelevantContext,
chatInputRef,
activeSelection,
serverCapabilities
supportsOnApplyInEditorV2
}}
>
<div className="flex justify-center overflow-x-hidden">
Expand Down
8 changes: 4 additions & 4 deletions ee/tabby-ui/components/chat/question-answer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function UserMessageCard(props: { message: UserMessage }) {
const { message } = props
const [{ data }] = useMe()
const selectContext = message.selectContext
const { onNavigateToContext, serverCapabilities } =
const { onNavigateToContext, supportsOnApplyInEditorV2 } =
React.useContext(ChatContext)
const selectCodeSnippet = React.useMemo(() => {
if (!selectContext?.content) return ''
Expand Down Expand Up @@ -166,7 +166,7 @@ function UserMessageCard(props: { message: UserMessage }) {
<MessageMarkdown
message={message.message}
canWrapLongLines
serverCapabilities={serverCapabilities}
supportsOnApplyInEditorV2={supportsOnApplyInEditorV2}
/>
<div className="hidden md:block">
<UserMessageCardActions {...props} />
Expand Down Expand Up @@ -261,7 +261,7 @@ function AssistantMessageCard(props: AssistantMessageCardProps) {
onNavigateToContext,
onApplyInEditor,
onCopyContent,
serverCapabilities
supportsOnApplyInEditorV2
} = React.useContext(ChatContext)
const [relevantCodeHighlightIndex, setRelevantCodeHighlightIndex] =
React.useState<number | undefined>(undefined)
Expand Down Expand Up @@ -398,7 +398,7 @@ function AssistantMessageCard(props: AssistantMessageCardProps) {
onCodeCitationMouseEnter={onCodeCitationMouseEnter}
onCodeCitationMouseLeave={onCodeCitationMouseLeave}
canWrapLongLines={!isLoading}
serverCapabilities={serverCapabilities}
supportsOnApplyInEditorV2={supportsOnApplyInEditorV2}
/>
{!!message.error && <ErrorMessageBlock error={message.error} />}
</>
Expand Down
14 changes: 7 additions & 7 deletions ee/tabby-ui/components/message-markdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export interface MessageMarkdownProps {
className?: string
// wrapLongLines for code block
canWrapLongLines?: boolean
serverCapabilities: Map<string, boolean>
supportsOnApplyInEditorV2: boolean
}

type MessageMarkdownContextValue = {
Expand All @@ -93,7 +93,7 @@ type MessageMarkdownContextValue = {
contextInfo: ContextInfo | undefined
fetchingContextInfo: boolean
canWrapLongLines: boolean
serverCapabilities: Map<string, boolean>
supportsOnApplyInEditorV2: boolean
}

const MessageMarkdownContext = createContext<MessageMarkdownContextValue>(
Expand All @@ -111,7 +111,7 @@ export function MessageMarkdown({
fetchingContextInfo,
className,
canWrapLongLines,
serverCapabilities,
supportsOnApplyInEditorV2,
...rest
}: MessageMarkdownProps) {
const messageAttachments: MessageAttachments = useMemo(() => {
Expand Down Expand Up @@ -187,7 +187,7 @@ export function MessageMarkdown({
contextInfo,
fetchingContextInfo: !!fetchingContextInfo,
canWrapLongLines: !!canWrapLongLines,
serverCapabilities: serverCapabilities
supportsOnApplyInEditorV2
}}
>
<MemoizedReactMarkdown
Expand Down Expand Up @@ -255,7 +255,7 @@ export function MessageMarkdown({
onApplyInEditor={onApplyInEditor}
onCopyContent={onCopyContent}
canWrapLongLines={canWrapLongLines}
serverCapabilities={serverCapabilities}
supportsOnApplyInEditorV2={supportsOnApplyInEditorV2}
{...props}
/>
)
Expand Down Expand Up @@ -305,15 +305,15 @@ export function ErrorMessageBlock({
}

function CodeBlockWrapper(props: CodeBlockProps) {
const { canWrapLongLines, serverCapabilities } = useContext(
const { canWrapLongLines, supportsOnApplyInEditorV2 } = useContext(
MessageMarkdownContext
)

return (
<CodeBlock
{...props}
canWrapLongLines={canWrapLongLines}
serverCapabilities={serverCapabilities}
supportsOnApplyInEditorV2={supportsOnApplyInEditorV2}
/>
)
}
Expand Down
8 changes: 4 additions & 4 deletions ee/tabby-ui/components/ui/codeblock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface CodeBlockProps {
opts?: { languageId: string; smart: boolean }
) => void
canWrapLongLines: boolean | undefined
serverCapabilities: Map<string, boolean>
supportsOnApplyInEditorV2: boolean
}

interface languageMap {
Expand Down Expand Up @@ -85,7 +85,7 @@ const CodeBlock: FC<CodeBlockProps> = memo(
onCopyContent,
onApplyInEditor,
canWrapLongLines,
serverCapabilities
supportsOnApplyInEditorV2
}) => {
const [wrapLongLines, setWrapLongLines] = useState(false)
const { isCopied, copyToClipboard } = useCopyToClipboard({
Expand Down Expand Up @@ -123,7 +123,7 @@ const CodeBlock: FC<CodeBlockProps> = memo(
</TooltipContent>
</Tooltip>
)}
{serverCapabilities.get('onApplyInEditorV2') && onApplyInEditor && (
{supportsOnApplyInEditorV2 && onApplyInEditor && (
<Tooltip>
<TooltipTrigger asChild>
<Button
Expand All @@ -146,7 +146,7 @@ const CodeBlock: FC<CodeBlockProps> = memo(
</TooltipContent>
</Tooltip>
)}
{serverCapabilities.get('onApplyInEditor') && onApplyInEditor && (
{onApplyInEditor && (
<Tooltip>
<TooltipTrigger asChild>
<Button
Expand Down

0 comments on commit f1ad5fb

Please sign in to comment.