Skip to content

Commit

Permalink
feat(chat-panel): add provide at function feature api in chat panel (#…
Browse files Browse the repository at this point in the history
…3601)

* refactor(api): rename FileInfo to FileRange and update related documentation for clarity

* refactor(api): update FileRange and AtInputOpts interfaces for clarity and consistency

* refactor(api): remove unused SymbolKind enum from ChatCommand interface

* refactor(api): simplify FileRange documentation and rename provideRangeContent method

* refactor(api): rename provideFileAtInfo to listFileInWorkspace for consistency

* update: remove label

---------

Co-authored-by: liangfung <[email protected]>
  • Loading branch information
Sma1lboy and liangfung authored Jan 17, 2025
1 parent f45a48a commit 2d5c7c7
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions clients/tabby-chat-panel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,47 @@ export interface GitRepository {
*/
export type ChatCommand = 'explain' | 'fix' | 'generate-docs' | 'generate-tests'

/**
* Represents a file reference for retrieving file content.
* If `range` is not provided, the entire file is considered.
*/
export interface FileRange {
/**
* The file path of the file.
*/
filepath: Filepath

/**
* The range of the selected content in the file.
* If the range is not provided, the whole file is considered.
*/
range?: LineRange | PositionRange
}

/**
* Defines optional parameters used to filter or limit the results of a file query.
*/
export interface ListFilesInWorkspaceParams {
/**
* The query string to filter the files.
* The query string could be an empty string. In this case, we do not read all files in the workspace,
* but only list the opened files in the editor.
*/
query: string

/**
* The maximum number of files to list.
*/
limit?: number
}

export interface ListFileItem {
/**
* The filepath of the file.
*/
filepath: Filepath
}

export interface ServerApi {
init: (request: InitRequest) => void

Expand Down Expand Up @@ -294,6 +335,21 @@ export interface ClientApiMethods {
* @param state The state to save.
*/
storeSessionState?: (state: Record<string, unknown>) => Promise<void>

/**
* Returns a list of file information matching the specified query.
* @param params An {@link ListFilesInWorkspaceParams} object that includes a search query and a limit for the results.
* @returns An array of {@link ListFileItem} objects that could be empty.
*/
listFileInWorkspace?: (params: ListFilesInWorkspaceParams) => Promise<ListFileItem[]>

/**
* Returns the content of a file within the specified range.
* If `range` is not provided, the entire file content is returned.
* @param info A {@link FileRange} object that includes the file path and optionally a 1-based line range.
* @returns The content of the file as a string, or `null` if the file or range cannot be accessed.
*/
readFileContent?: (info: FileRange) => Promise<string | null>
}

export interface ClientApi extends ClientApiMethods {
Expand Down Expand Up @@ -321,6 +377,8 @@ export function createClient(target: HTMLIFrameElement, api: ClientApiMethods):
getActiveEditorSelection: api.getActiveEditorSelection,
fetchSessionState: api.fetchSessionState,
storeSessionState: api.storeSessionState,
listFileInWorkspace: api.listFileInWorkspace,
readFileContent: api.readFileContent,
},
})
}
Expand Down

0 comments on commit 2d5c7c7

Please sign in to comment.