diff --git a/clients/tabby-chat-panel/src/index.ts b/clients/tabby-chat-panel/src/index.ts index 7cc91c86c9c4..e26c6433a198 100644 --- a/clients/tabby-chat-panel/src/index.ts +++ b/clients/tabby-chat-panel/src/index.ts @@ -53,9 +53,9 @@ export type Location = number | LineRange | Position | PositionRange /** * Represents a client-side file context. - * This type should only be used for send context from client to server. + * This type should only be used for sending context from client to server. */ -export interface ClientFileContext { +export interface EditorFileContext { kind: 'file' /** @@ -77,9 +77,9 @@ export interface ClientFileContext { /** * Represents a client-side context. - * This type should only be used for send context from client to server. + * This type should only be used for sending context from client to server. */ -export type ClientSideContext = ClientFileContext +export type EditorContext = EditorFileContext export interface FetcherOptions { authorization: string @@ -220,9 +220,9 @@ export interface ServerApi { showError: (error: ErrorMessage) => void cleanError: () => void - addRelevantContext: (context: ClientSideContext) => void + addRelevantContext: (context: EditorContext) => void updateTheme: (style: string, themeClass: string) => void - updateActiveSelection: (context: ClientFileContext | null) => void + updateActiveSelection: (context: EditorContext | null) => void } export interface ClientApiMethods { diff --git a/clients/vscode/src/chat/ChatPanelViewProvider.ts b/clients/vscode/src/chat/ChatPanelViewProvider.ts index 6def58597907..c7df9039e4e6 100644 --- a/clients/vscode/src/chat/ChatPanelViewProvider.ts +++ b/clients/vscode/src/chat/ChatPanelViewProvider.ts @@ -1,5 +1,5 @@ import { ExtensionContext, window, WebviewPanel } from "vscode"; -import type { ServerApi, ChatCommand, ClientFileContext } from "tabby-chat-panel"; +import type { ServerApi, ChatCommand, EditorContext } from "tabby-chat-panel"; import { WebviewHelper } from "./WebviewHelper"; import { Client } from "../lsp/Client"; import { GitProvider } from "../git/GitProvider"; @@ -61,7 +61,7 @@ export class ChatPanelViewProvider { this.webviewHelper.executeCommand(command); } - public addRelevantContext(context: ClientFileContext) { + public addRelevantContext(context: EditorContext) { this.webviewHelper.addRelevantContext(context); } } diff --git a/clients/vscode/src/chat/ChatSideViewProvider.ts b/clients/vscode/src/chat/ChatSideViewProvider.ts index d6a89ac410bb..71ef0f68193d 100644 --- a/clients/vscode/src/chat/ChatSideViewProvider.ts +++ b/clients/vscode/src/chat/ChatSideViewProvider.ts @@ -1,5 +1,5 @@ import { ExtensionContext, WebviewViewProvider, WebviewView, window } from "vscode"; -import type { ServerApi, ChatCommand, ClientFileContext } from "tabby-chat-panel"; +import type { ServerApi, ChatCommand, EditorContext } from "tabby-chat-panel"; import { WebviewHelper } from "./WebviewHelper"; import { Client } from "../lsp/Client"; import type { LogOutputChannel } from "../logger"; @@ -64,7 +64,7 @@ export class ChatSideViewProvider implements WebviewViewProvider { this.webviewHelper.executeCommand(command); } - public addRelevantContext(context: ClientFileContext) { + public addRelevantContext(context: EditorContext) { this.webviewHelper.addRelevantContext(context); } } diff --git a/clients/vscode/src/chat/WebviewHelper.ts b/clients/vscode/src/chat/WebviewHelper.ts index 1a8e24a15d01..dd98d2105cd6 100644 --- a/clients/vscode/src/chat/WebviewHelper.ts +++ b/clients/vscode/src/chat/WebviewHelper.ts @@ -18,7 +18,7 @@ import { import type { ServerApi, ChatCommand, - ClientFileContext, + EditorContext, OnLoadedParams, LookupSymbolHint, SymbolInfo, @@ -268,7 +268,7 @@ export class WebviewHelper { return supportedSchemes.includes(scheme); } - public async syncActiveSelectionToChatPanel(context: ClientFileContext | null) { + public async syncActiveSelectionToChatPanel(context: EditorContext | null) { try { await this.client?.updateActiveSelection(context); } catch { @@ -282,7 +282,7 @@ export class WebviewHelper { } } - public addRelevantContext(context: ClientFileContext) { + public addRelevantContext(context: EditorContext) { if (this.client) { this.logger.info(`Adding relevant context: ${context}`); this.client.addRelevantContext(context); diff --git a/clients/vscode/src/chat/fileContext.ts b/clients/vscode/src/chat/fileContext.ts index 4311ac0d89dd..584151430ef4 100644 --- a/clients/vscode/src/chat/fileContext.ts +++ b/clients/vscode/src/chat/fileContext.ts @@ -1,12 +1,12 @@ import type { TextEditor } from "vscode"; -import type { ClientFileContext } from "tabby-chat-panel"; +import type { EditorContext } from "tabby-chat-panel"; import type { GitProvider } from "../git/GitProvider"; import { localUriToChatPanelFilepath } from "./utils"; export async function getFileContextFromSelection( editor: TextEditor, gitProvider: GitProvider, -): Promise { +): Promise { return getFileContext(editor, gitProvider, true); } @@ -14,7 +14,7 @@ export async function getFileContext( editor: TextEditor, gitProvider: GitProvider, useSelection = false, -): Promise { +): Promise { const text = editor.document.getText(useSelection ? editor.selection : undefined); if (!text || text.trim().length < 1) { return null; diff --git a/ee/tabby-ui/app/chat/page.tsx b/ee/tabby-ui/app/chat/page.tsx index b6eb21b629e5..bb1a1d44b60e 100644 --- a/ee/tabby-ui/app/chat/page.tsx +++ b/ee/tabby-ui/app/chat/page.tsx @@ -12,7 +12,7 @@ import remarkMath from 'remark-math' import { TABBY_CHAT_PANEL_API_VERSION, type ChatCommand, - type ClientFileContext, + type EditorContext, type ErrorMessage, type FetcherOptions, type FileLocation, @@ -53,10 +53,10 @@ export default function ChatPage() { const [activeChatId, setActiveChatId] = useState('') const [pendingCommand, setPendingCommand] = useState() const [pendingRelevantContexts, setPendingRelevantContexts] = useState< - ClientFileContext[] + EditorContext[] >([]) const [pendingActiveSelection, setPendingActiveSelection] = - useState(null) + useState(null) const [errorMessage, setErrorMessage] = useState(null) const [isRefreshLoading, setIsRefreshLoading] = useState(false) @@ -88,7 +88,7 @@ export default function ChatPage() { } } - const addRelevantContext = (ctx: ClientFileContext) => { + const addRelevantContext = (ctx: EditorContext) => { if (chatRef.current) { chatRef.current.addRelevantContext(ctx) } else { @@ -98,7 +98,7 @@ export default function ChatPage() { } } - const updateActiveSelection = (ctx: ClientFileContext | null) => { + const updateActiveSelection = (ctx: EditorContext | null) => { if (chatRef.current) { chatRef.current.updateActiveSelection(ctx) } else if (ctx) { @@ -130,7 +130,7 @@ export default function ChatPage() { cleanError: () => { setErrorMessage(null) }, - addRelevantContext: (context: ClientFileContext) => { + addRelevantContext: (context: EditorContext) => { return addRelevantContext(context) }, updateTheme: (style, themeClass) => { @@ -153,7 +153,7 @@ export default function ChatPage() { document.documentElement.className = themeClass + ` client client-${client}` }, - updateActiveSelection: (context: ClientFileContext | null) => { + updateActiveSelection: (context: EditorContext | null) => { return updateActiveSelection(context) } }) diff --git a/ee/tabby-ui/components/chat/chat.tsx b/ee/tabby-ui/components/chat/chat.tsx index 00afeb5718c2..67c53c4fefa9 100644 --- a/ee/tabby-ui/components/chat/chat.tsx +++ b/ee/tabby-ui/components/chat/chat.tsx @@ -2,7 +2,7 @@ import React, { RefObject } from 'react' import { compact, findIndex, isEqual, some, uniqWith } from 'lodash-es' import type { ChatCommand, - ClientFileContext, + EditorContext, FileLocation, GitRepository, LookupSymbolHint, @@ -37,7 +37,7 @@ import { } from '@/lib/types/chat' import { cn, - convertClientFileContext, + convertEditorContext, findClosestGitRepository, getFileLocationFromContext, getPromptForChatCommand, @@ -103,9 +103,9 @@ export interface ChatRef { executeCommand: (command: ChatCommand) => Promise stop: () => void isLoading: boolean - addRelevantContext: (context: ClientFileContext) => void + addRelevantContext: (context: EditorContext) => void focus: () => void - updateActiveSelection: (context: ClientFileContext | null) => void + updateActiveSelection: (context: EditorContext | null) => void } interface ChatProps extends React.ComponentProps<'div'> { @@ -511,8 +511,8 @@ function ChatRenderer( setRelevantContext(oldValue => appendContextAndDedupe(oldValue, context)) }) - const addRelevantContext = (clientFileContext: ClientFileContext) => { - const context = convertClientFileContext(clientFileContext) + const addRelevantContext = (editorContext: EditorContext) => { + const context = convertEditorContext(editorContext) handleAddRelevantContext.current?.(context) } @@ -534,12 +534,8 @@ function ChatRenderer( 300 ) - const updateActiveSelection = ( - clientFileContext: ClientFileContext | null - ) => { - const context = clientFileContext - ? convertClientFileContext(clientFileContext) - : null + const updateActiveSelection = (editorContext: EditorContext | null) => { + const context = editorContext ? convertEditorContext(editorContext) : null debouncedUpdateActiveSelection.run(context) } diff --git a/ee/tabby-ui/lib/utils/index.ts b/ee/tabby-ui/lib/utils/index.ts index 1b1b6c5b75f5..96b8af4a0ac0 100644 --- a/ee/tabby-ui/lib/utils/index.ts +++ b/ee/tabby-ui/lib/utils/index.ts @@ -3,7 +3,7 @@ import { compact, isNil } from 'lodash-es' import { customAlphabet } from 'nanoid' import type { ChatCommand, - ClientFileContext, + EditorContext, FileLocation, Filepath, LineRange, @@ -195,8 +195,8 @@ export function getPromptForChatCommand(command: ChatCommand) { } } -export function convertClientFileContext( - clientFileContext: ClientFileContext +export function convertEditorContext( + editorContext: EditorContext ): FileContext { const convertRange = (range: LineRange | PositionRange | undefined) => { // FIXME: If the range is not provided, the whole file is considered. @@ -231,9 +231,9 @@ export function convertClientFileContext( return { kind: 'file', - content: clientFileContext.content, - range: convertRange(clientFileContext.range), - ...convertFilepath(clientFileContext.filepath) + content: editorContext.content, + range: convertRange(editorContext.range), + ...convertFilepath(editorContext.filepath) } }