import { ExtractChunkData } from '@cherrystudio/embedjs-interfaces' import { ElectronAPI } from '@electron-toolkit/preload' import type { FileMetadataResponse, ListFilesResponse, UploadFileResponse } from '@google/generative-ai/server' import type { MCPServer, MCPTool } from '@renderer/types' import { AppInfo, FileType, KnowledgeBaseParams, KnowledgeItem, LanguageVarious, WebDavConfig } from '@renderer/types' import type { LoaderReturn } from '@shared/config/types' import type { OpenDialogOptions } from 'electron' import type { UpdateInfo } from 'electron-updater' interface BackupFile { fileName: string modifiedTime: string size: number } declare global { interface Window { electron: ElectronAPI api: { getAppInfo: () => Promise checkForUpdate: () => Promise<{ currentVersion: string; updateInfo: UpdateInfo | null }> showUpdateDialog: () => Promise openWebsite: (url: string) => void setProxy: (proxy: string | undefined) => void setLanguage: (theme: LanguageVarious) => void setLaunchOnBoot: (isActive: boolean) => void setLaunchToTray: (isActive: boolean) => void setTray: (isActive: boolean) => void setTrayOnClose: (isActive: boolean) => void restartTray: () => void setTheme: (theme: 'light' | 'dark') => void reload: () => void clearCache: () => Promise<{ success: boolean; error?: string }> system: { getDeviceType: () => Promise<'mac' | 'windows' | 'linux'> } zip: { compress: (text: string) => Promise decompress: (text: Buffer) => Promise } backup: { backup: (fileName: string, data: string, destinationPath?: string) => Promise restore: (backupPath: string) => Promise backupToWebdav: (data: string, webdavConfig: WebDavConfig) => Promise restoreFromWebdav: (webdavConfig: WebDavConfig) => Promise listWebdavFiles: (webdavConfig: WebDavConfig) => Promise checkConnection: (webdavConfig: WebDavConfig) => Promise createDirectory: (webdavConfig: WebDavConfig, path: string, options?: CreateDirectoryOptions) => Promise } file: { select: (options?: OpenDialogOptions) => Promise upload: (file: FileType) => Promise delete: (fileId: string) => Promise read: (fileId: string) => Promise clear: () => Promise get: (filePath: string) => Promise selectFolder: () => Promise create: (fileName: string) => Promise write: (filePath: string, data: Uint8Array | string) => Promise open: (options?: OpenDialogOptions) => Promise<{ fileName: string; filePath: string; content: Buffer } | null> openPath: (path: string) => Promise save: ( path: string, content: string | NodeJS.ArrayBufferView, options?: SaveDialogOptions ) => Promise saveImage: (name: string, data: string) => void base64Image: (fileId: string) => Promise<{ mime: string; base64: string; data: string }> download: (url: string) => Promise copy: (fileId: string, destPath: string) => Promise binaryFile: (fileId: string) => Promise<{ data: Buffer; mime: string }> } fs: { read: (path: string) => Promise } export: { toWord: (markdown: string, fileName: string) => Promise } openPath: (path: string) => Promise shortcuts: { update: (shortcuts: Shortcut[]) => Promise } knowledgeBase: { create: (base: KnowledgeBaseParams) => Promise reset: (base: KnowledgeBaseParams) => Promise delete: (id: string) => Promise add: ({ base, item, forceReload = false }: { base: KnowledgeBaseParams item: KnowledgeItem forceReload?: boolean }) => Promise remove: ({ uniqueId, uniqueIds, base }: { uniqueId: string uniqueIds: string[] base: KnowledgeBaseParams }) => Promise search: ({ search, base }: { search: string; base: KnowledgeBaseParams }) => Promise rerank: ({ search, base, results }: { search: string base: KnowledgeBaseParams results: ExtractChunkData[] }) => Promise } window: { setMinimumSize: (width: number, height: number) => Promise resetMinimumSize: () => Promise } gemini: { uploadFile: (file: FileType, apiKey: string) => Promise retrieveFile: (file: FileType, apiKey: string) => Promise base64File: (file: FileType) => Promise<{ data: string; mimeType: string }> listFiles: (apiKey: string) => Promise deleteFile: (apiKey: string, fileId: string) => Promise } selectionMenu: { action: (action: string) => Promise } config: { set: (key: string, value: any) => Promise get: (key: string) => Promise } miniWindow: { show: () => Promise hide: () => Promise close: () => Promise toggle: () => Promise setPin: (isPinned: boolean) => Promise } aes: { encrypt: (text: string, secretKey: string, iv: string) => Promise<{ iv: string; encryptedData: string }> decrypt: (encryptedData: string, iv: string, secretKey: string) => Promise } shell: { openExternal: (url: string, options?: OpenExternalOptions) => Promise } mcp: { removeServer: (server: MCPServer) => Promise restartServer: (server: MCPServer) => Promise stopServer: (server: MCPServer) => Promise listTools: (server: MCPServer) => Promise callTool: ({ server, name, args }: { server: MCPServer; name: string; args: any }) => Promise getInstallInfo: () => Promise<{ dir: string; uvPath: string; bunPath: string }> } copilot: { getAuthMessage: ( headers?: Record ) => Promise<{ device_code: string; user_code: string; verification_uri: string }> getCopilotToken: (device_code: string, headers?: Record) => Promise<{ access_token: string }> saveCopilotToken: (access_token: string) => Promise getToken: (headers?: Record) => Promise<{ token: string }> logout: () => Promise getUser: (token: string) => Promise<{ login: string; avatar: string }> } isBinaryExist: (name: string) => Promise getBinaryPath: (name: string) => Promise installUVBinary: () => Promise installBunBinary: () => Promise protocol: { onReceiveData: (callback: (data: { url: string; params: any }) => void) => () => void } nutstore: { getSSOUrl: () => Promise decryptToken: (token: string) => Promise<{ username: string; access_token: string }> getDirectoryContents: (token: string, path: string) => Promise } } } }