import { invoke } from "@tauri-apps/api/core" import type { AgentType, ConversationSummary, ConversationDetail, DbConversationDetail, FolderInfo, AgentStats, SidebarData, ConnectionInfo, AcpAgentInfo, AcpAgentStatus, AgentSkillScope, AgentSkillLayout, AgentSkillItem, AgentSkillsListResult, AgentSkillContent, FolderHistoryEntry, FolderDetail, DbConversationSummary, ImportResult, OpenedTab, GitStatusEntry, GitBranchList, GitPullResult, GitPushResult, GitPushInfo, GitMergeResult, GitRebaseResult, GitResetMode, GitConflictFileVersions, GitCommitResult, GitRemote, GitStashEntry, PreflightResult, FolderCommand, TerminalInfo, PromptInputBlock, FileTreeNode, DirectoryEntry, FilePreviewContent, FileEditContent, FileSaveResult, WorkspaceSnapshotResponse, GitLogResult, SystemLanguageSettings, SystemProxySettings, GitCredentials, GitDetectResult, GitSettings, GitHubAccountsSettings, GitHubTokenValidation, McpAppType, LocalMcpServer, McpMarketplaceProvider, McpMarketplaceItem, McpMarketplaceServerDetail, } from "./types" export async function listConversations(params?: { agent_type?: AgentType | null search?: string | null sort_by?: string | null folder_path?: string | null }): Promise { return invoke("list_conversations", { agentType: params?.agent_type ?? null, search: params?.search ?? null, sortBy: params?.sort_by ?? null, folderPath: params?.folder_path ?? null, }) } export async function getConversation( agentType: AgentType, conversationId: string ): Promise { return invoke("get_conversation", { agentType, conversationId }) } export async function listFolders(): Promise { return invoke("list_folders") } export async function getStats(): Promise { return invoke("get_stats") } export async function getSidebarData(): Promise { return invoke("get_sidebar_data") } // ACP commands export async function acpConnect( agentType: AgentType, workingDir?: string, sessionId?: string ): Promise { return invoke("acp_connect", { agentType, workingDir: workingDir ?? null, sessionId: sessionId ?? null, }) } export async function acpPrompt( connectionId: string, blocks: PromptInputBlock[] ): Promise { return invoke("acp_prompt", { connectionId, blocks }) } export async function acpSetMode( connectionId: string, modeId: string ): Promise { return invoke("acp_set_mode", { connectionId, modeId }) } export async function acpSetConfigOption( connectionId: string, configId: string, valueId: string ): Promise { return invoke("acp_set_config_option", { connectionId, configId, valueId }) } export async function acpCancel(connectionId: string): Promise { return invoke("acp_cancel", { connectionId }) } export interface ForkResult { forkedSessionId: string originalSessionId: string } export async function acpFork(connectionId: string): Promise { return invoke("acp_fork", { connectionId }) } export async function acpRespondPermission( connectionId: string, requestId: string, optionId: string ): Promise { return invoke("acp_respond_permission", { connectionId, requestId, optionId, }) } export async function acpDisconnect(connectionId: string): Promise { return invoke("acp_disconnect", { connectionId }) } export async function acpListConnections(): Promise { return invoke("acp_list_connections") } export async function acpListAgents(): Promise { return invoke("acp_list_agents") } export async function acpGetAgentStatus( agentType: AgentType ): Promise { return invoke("acp_get_agent_status", { agentType }) } export async function acpClearBinaryCache(agentType: AgentType): Promise { return invoke("acp_clear_binary_cache", { agentType }) } export async function acpDownloadAgentBinary( agentType: AgentType, taskId: string ): Promise { return invoke("acp_download_agent_binary", { agentType, taskId }) } export async function acpDetectAgentLocalVersion( agentType: AgentType ): Promise { return invoke("acp_detect_agent_local_version", { agentType }) } export async function acpPrepareNpxAgent( agentType: AgentType, registryVersion: string | null | undefined, taskId: string ): Promise { return invoke("acp_prepare_npx_agent", { agentType, registryVersion: registryVersion ?? null, taskId, }) } export async function acpUninstallAgent( agentType: AgentType, taskId: string ): Promise { return invoke("acp_uninstall_agent", { agentType, taskId }) } export async function acpUpdateAgentPreferences( agentType: AgentType, params: { enabled: boolean env: Record config_json?: string | null opencode_auth_json?: string | null codex_auth_json?: string | null codex_config_toml?: string | null } ): Promise { return invoke("acp_update_agent_preferences", { agentType, enabled: params.enabled, env: params.env, configJson: params.config_json ?? null, opencodeAuthJson: params.opencode_auth_json ?? null, codexAuthJson: params.codex_auth_json ?? null, codexConfigToml: params.codex_config_toml ?? null, }) } export async function acpReorderAgents(agentTypes: AgentType[]): Promise { return invoke("acp_reorder_agents", { agentTypes }) } export async function acpPreflight( agentType: AgentType, forceRefresh?: boolean ): Promise { return invoke("acp_preflight", { agentType, forceRefresh: forceRefresh ?? null, }) } export async function acpListAgentSkills(params: { agentType: AgentType workspacePath?: string | null }): Promise { return invoke("acp_list_agent_skills", { agentType: params.agentType, workspacePath: params.workspacePath ?? null, }) } export async function acpReadAgentSkill(params: { agentType: AgentType scope: AgentSkillScope skillId: string workspacePath?: string | null }): Promise { return invoke("acp_read_agent_skill", { agentType: params.agentType, scope: params.scope, skillId: params.skillId, workspacePath: params.workspacePath ?? null, }) } export async function acpSaveAgentSkill(params: { agentType: AgentType scope: AgentSkillScope skillId: string content: string workspacePath?: string | null layout?: AgentSkillLayout | null }): Promise { return invoke("acp_save_agent_skill", { agentType: params.agentType, scope: params.scope, skillId: params.skillId, content: params.content, workspacePath: params.workspacePath ?? null, layout: params.layout ?? null, }) } export async function acpDeleteAgentSkill(params: { agentType: AgentType scope: AgentSkillScope skillId: string workspacePath?: string | null }): Promise { return invoke("acp_delete_agent_skill", { agentType: params.agentType, scope: params.scope, skillId: params.skillId, workspacePath: params.workspacePath ?? null, }) } export async function getSystemProxySettings(): Promise { return invoke("get_system_proxy_settings") } export async function updateSystemProxySettings( settings: SystemProxySettings ): Promise { return invoke("update_system_proxy_settings", { settings }) } export async function getSystemLanguageSettings(): Promise { return invoke("get_system_language_settings") } export async function updateSystemLanguageSettings( settings: SystemLanguageSettings ): Promise { return invoke("update_system_language_settings", { settings }) } // --- Version Control --- export async function detectGit(): Promise { return invoke("detect_git") } export async function testGitPath(path: string): Promise { return invoke("test_git_path", { path }) } export async function getGitSettings(): Promise { return invoke("get_git_settings") } export async function updateGitSettings( settings: GitSettings ): Promise { return invoke("update_git_settings", { settings }) } export async function getGitHubAccounts(): Promise { return invoke("get_github_accounts") } export async function validateGitHubToken( serverUrl: string, token: string ): Promise { return invoke("validate_github_token", { serverUrl, token }) } export async function updateGitHubAccounts( settings: GitHubAccountsSettings ): Promise { return invoke("update_github_accounts", { settings }) } export async function saveAccountToken( accountId: string, token: string ): Promise { return invoke("save_account_token", { accountId, token }) } export async function getAccountToken( accountId: string ): Promise { return invoke("get_account_token", { accountId }) } export async function deleteAccountToken(accountId: string): Promise { return invoke("delete_account_token", { accountId }) } export async function mcpScanLocal(): Promise { return invoke("mcp_scan_local") } export async function mcpListMarketplaces(): Promise { return invoke("mcp_list_marketplaces") } export async function mcpSearchMarketplace(params: { providerId: string query?: string | null limit?: number | null }): Promise { return invoke("mcp_search_marketplace", { providerId: params.providerId, query: params.query ?? null, limit: params.limit ?? null, }) } export async function mcpGetMarketplaceServerDetail(params: { providerId: string serverId: string }): Promise { return invoke("mcp_get_marketplace_server_detail", { providerId: params.providerId, serverId: params.serverId, }) } export async function mcpInstallFromMarketplace(params: { providerId: string serverId: string apps: McpAppType[] specOverride?: Record | null optionId?: string | null protocol?: string | null parameterValues?: Record | null }): Promise { return invoke("mcp_install_from_marketplace", { providerId: params.providerId, serverId: params.serverId, apps: params.apps, specOverride: params.specOverride ?? null, optionId: params.optionId ?? null, protocol: params.protocol ?? null, parameterValues: params.parameterValues ?? null, }) } export async function mcpUpsertLocalServer(params: { serverId: string spec: Record apps: McpAppType[] }): Promise { return invoke("mcp_upsert_local_server", { serverId: params.serverId, spec: params.spec, apps: params.apps, }) } export async function mcpSetServerApps( serverId: string, apps: McpAppType[] ): Promise { return invoke("mcp_set_server_apps", { serverId, apps }) } export async function mcpRemoveServer( serverId: string, apps?: McpAppType[] | null ): Promise { return invoke("mcp_remove_server", { serverId, apps: apps ?? null, }) } // Appearance / window chrome export async function updateTrafficLightPosition(zoom: number): Promise { return invoke("update_traffic_light_position", { zoom: zoom as number }) } export async function updateAppearanceMode(mode: string): Promise { return invoke("update_appearance_mode", { mode }) } // Folder history commands export async function loadFolderHistory(): Promise { return invoke("load_folder_history") } export async function getFolder(folderId: number): Promise { return invoke("get_folder", { folderId }) } export async function listAllConversations(params?: { folder_ids?: number[] | null agent_type?: AgentType | null search?: string | null sort_by?: string | null status?: string | null }): Promise { return invoke("list_all_conversations", { folderIds: params?.folder_ids ?? null, agentType: params?.agent_type ?? null, search: params?.search ?? null, sortBy: params?.sort_by ?? null, status: params?.status ?? null, }) } export async function listOpenedTabs(): Promise { return invoke("list_opened_tabs") } export async function saveOpenedTabs(items: OpenedTab[]): Promise { return invoke("save_opened_tabs", { items }) } export async function listOpenFolderDetails(): Promise { return invoke("list_open_folder_details") } export async function openFolderById(folderId: number): Promise { return invoke("open_folder_by_id", { folderId }) } export async function removeFolderFromWorkspace( folderId: number ): Promise { return invoke("remove_folder_from_workspace", { folderId }) } export async function importLocalConversations( folderId: number ): Promise { return invoke("import_local_conversations", { folderId }) } export async function getFolderConversation( conversationId: number ): Promise { return invoke("get_folder_conversation", { conversationId }) } export async function setFolderParentBranch( path: string, parentBranch: string | null ): Promise { return invoke("set_folder_parent_branch", { path, parentBranch, }) } export async function removeFolderFromHistory(path: string): Promise { return invoke("remove_folder_from_history", { path }) } export async function createFolderDirectory(path: string): Promise { return invoke("create_folder_directory", { path }) } export async function cloneRepository( url: string, targetDir: string, credentials?: GitCredentials | null ): Promise { return invoke("clone_repository", { url, targetDir, credentials: credentials ?? null, }) } export async function getGitBranch(path: string): Promise { return invoke("get_git_branch", { path }) } export async function gitInit(path: string): Promise { return invoke("git_init", { path }) } export async function gitPull( path: string, credentials?: GitCredentials | null ): Promise { return invoke("git_pull", { path, credentials: credentials ?? null }) } export async function gitStartPullMerge( path: string, upstreamCommit?: string | null ): Promise { return invoke("git_start_pull_merge", { path, upstreamCommit }) } export async function gitHasMergeHead(path: string): Promise { return invoke("git_has_merge_head", { path }) } export async function gitFetch( path: string, credentials?: GitCredentials | null ): Promise { return invoke("git_fetch", { path, credentials: credentials ?? null }) } export async function gitPushInfo(path: string): Promise { return invoke("git_push_info", { path }) } export async function gitPush( path: string, remote?: string | null, credentials?: GitCredentials | null ): Promise { return invoke("git_push", { path, remote: remote ?? null, credentials: credentials ?? null, }) } export async function gitNewBranch( path: string, branchName: string, startPoint?: string ): Promise { return invoke("git_new_branch", { path, branchName, startPoint: startPoint ?? null, }) } export async function gitWorktreeAdd( path: string, branchName: string, worktreePath: string ): Promise { return invoke("git_worktree_add", { path, branchName, worktreePath }) } export async function gitCheckout( path: string, branchName: string ): Promise { return invoke("git_checkout", { path, branchName }) } export async function gitListBranches(path: string): Promise { return invoke("git_list_branches", { path }) } export async function gitListAllBranches(path: string): Promise { return invoke("git_list_all_branches", { path }) } export async function gitMerge( path: string, branchName: string ): Promise { return invoke("git_merge", { path, branchName }) } export async function gitRebase( path: string, branchName: string ): Promise { return invoke("git_rebase", { path, branchName }) } export async function gitDeleteBranch( path: string, branchName: string, force = false ): Promise { return invoke("git_delete_branch", { path, branchName, force }) } export async function gitListConflicts(path: string): Promise { return invoke("git_list_conflicts", { path }) } export async function gitConflictFileVersions( path: string, file: string ): Promise { return invoke("git_conflict_file_versions", { path, file }) } export async function gitResolveConflict( path: string, file: string, content: string ): Promise { return invoke("git_resolve_conflict", { path, file, content }) } export async function gitAbortOperation( path: string, operation: string ): Promise { return invoke("git_abort_operation", { path, operation }) } export async function gitContinueOperation( path: string, operation: string ): Promise { return invoke("git_continue_operation", { path, operation }) } export async function openMergeWindow( folderId: number, operation: string, upstreamCommit?: string | null ): Promise { return invoke("open_merge_window", { folderId, operation, upstreamCommit: upstreamCommit ?? null, }) } export async function openStashWindow(folderId: number): Promise { return invoke("open_stash_window", { folderId }) } export async function openPushWindow(folderId: number): Promise { return invoke("open_push_window", { folderId }) } export async function gitStashPush( path: string, message?: string, keepIndex?: boolean ): Promise { return invoke("git_stash_push", { path, message: message ?? null, keepIndex: keepIndex ?? false, }) } export async function gitStashPop( path: string, stashRef?: string ): Promise { return invoke("git_stash_pop", { path, stashRef: stashRef ?? null }) } export async function gitStashList(path: string): Promise { return invoke("git_stash_list", { path }) } export async function gitStashApply( path: string, stashRef: string ): Promise { return invoke("git_stash_apply", { path, stashRef }) } export async function gitStashDrop( path: string, stashRef: string ): Promise { return invoke("git_stash_drop", { path, stashRef }) } export async function gitStashClear(path: string): Promise { return invoke("git_stash_clear", { path }) } export async function gitStashShow( path: string, stashRef: string ): Promise { return invoke("git_stash_show", { path, stashRef }) } export async function gitListRemotes(path: string): Promise { return invoke("git_list_remotes", { path }) } export async function gitFetchRemote( path: string, name: string, credentials?: GitCredentials | null ): Promise { return invoke("git_fetch_remote", { path, name, credentials: credentials ?? null, }) } export async function gitAddRemote( path: string, name: string, url: string ): Promise { return invoke("git_add_remote", { path, name, url }) } export async function gitRemoveRemote( path: string, name: string ): Promise { return invoke("git_remove_remote", { path, name }) } export async function gitSetRemoteUrl( path: string, name: string, url: string ): Promise { return invoke("git_set_remote_url", { path, name, url }) } export async function gitStatus( path: string, showAllUntracked?: boolean ): Promise { return invoke("git_status", { path, showAllUntracked: showAllUntracked ?? null, }) } export async function gitDiff(path: string, file?: string): Promise { return invoke("git_diff", { path, file: file ?? null }) } export async function gitDiffWithBranch( path: string, branch: string, file?: string ): Promise { return invoke("git_diff_with_branch", { path, branch, file: file ?? null, }) } export async function gitShowDiff( path: string, commit: string, file?: string ): Promise { return invoke("git_show_diff", { path, commit, file: file ?? null }) } export async function gitShowFile( path: string, file: string, refName?: string ): Promise { return invoke("git_show_file", { path, file, refName: refName ?? null, }) } export async function gitIsTracked( path: string, file: string ): Promise { return invoke("git_is_tracked", { path, file }) } export async function gitCommit( path: string, message: string, files: string[] ): Promise { return invoke("git_commit", { path, message, files }) } export async function gitRollbackFile( path: string, file: string ): Promise { return invoke("git_rollback_file", { path, file }) } export async function gitAddFiles( path: string, files: string[] ): Promise { return invoke("git_add_files", { path, files }) } // Window management commands export async function openFolder(path: string): Promise { return invoke("open_folder", { path }) } export async function openCommitWindow(folderId: number): Promise { return invoke("open_commit_window", { folderId }) } export type SettingsSection = | "appearance" | "agents" | "mcp" | "skills" | "shortcuts" | "system" interface OpenSettingsWindowOptions { agentType?: AgentType | null } export async function openSettingsWindow( section?: SettingsSection, options?: OpenSettingsWindowOptions ): Promise { return invoke("open_settings_window", { section: section ?? null, agentType: options?.agentType ?? null, }) } // Conversation CRUD commands export async function createConversation( folderId: number, agentType: AgentType, title?: string ): Promise { return invoke("create_conversation", { folderId, agentType, title: title ?? null, }) } export async function updateConversationStatus( conversationId: number, status: string ): Promise { return invoke("update_conversation_status", { conversationId, status }) } export async function updateConversationTitle( conversationId: number, title: string ): Promise { return invoke("update_conversation_title", { conversationId, title }) } export async function updateConversationExternalId( conversationId: number, externalId: string ): Promise { return invoke("update_conversation_external_id", { conversationId, externalId, }) } export async function deleteConversation( conversationId: number ): Promise { return invoke("delete_conversation", { conversationId }) } // Folder command management export async function listFolderCommands( folderId: number ): Promise { return invoke("list_folder_commands", { folderId }) } export async function createFolderCommand( folderId: number, name: string, command: string ): Promise { return invoke("create_folder_command", { folderId, name, command }) } export async function updateFolderCommand( id: number, name?: string, command?: string, sortOrder?: number ): Promise { return invoke("update_folder_command", { id, name: name ?? null, command: command ?? null, sortOrder: sortOrder ?? null, }) } export async function deleteFolderCommand(id: number): Promise { return invoke("delete_folder_command", { id }) } export async function reorderFolderCommands( folderId: number, ids: number[] ): Promise { return invoke("reorder_folder_commands", { folderId, ids }) } export async function bootstrapFolderCommandsFromPackageJson( folderId: number, folderPath: string ): Promise { return invoke("bootstrap_folder_commands_from_package_json", { folderId, folderPath, }) } // Directory browser export async function getHomeDirectory(): Promise { return invoke("get_home_directory") } export async function listDirectoryEntries( path: string ): Promise { return invoke("list_directory_entries", { path }) } // File tree and git log commands export async function getFileTree( path: string, maxDepth?: number ): Promise { return invoke("get_file_tree", { path, maxDepth: maxDepth ?? null }) } export async function startWorkspaceStateStream( rootPath: string ): Promise { return invoke("start_workspace_state_stream", { rootPath }) } export async function stopWorkspaceStateStream( rootPath: string ): Promise { return invoke("stop_workspace_state_stream", { rootPath }) } export async function getWorkspaceSnapshot( rootPath: string, sinceSeq?: number ): Promise { return invoke("get_workspace_snapshot", { rootPath, sinceSeq: sinceSeq ?? null, }) } export async function readFileBase64( path: string, maxBytes?: number ): Promise { return invoke("read_file_base64", { path, maxBytes: maxBytes ?? null }) } export async function readFilePreview( rootPath: string, path: string ): Promise { return invoke("read_file_preview", { rootPath, path }) } export async function readFileForEdit( rootPath: string, path: string ): Promise { return invoke("read_file_for_edit", { rootPath, path }) } export async function saveFileContent( rootPath: string, path: string, content: string, expectedEtag?: string | null ): Promise { return invoke("save_file_content", { rootPath, path, content, expectedEtag: expectedEtag ?? null, }) } export async function saveFileCopy( rootPath: string, path: string, content: string ): Promise { return invoke("save_file_copy", { rootPath, path, content, }) } export async function renameFileTreeEntry( rootPath: string, path: string, newName: string ): Promise { return invoke("rename_file_tree_entry", { rootPath, path, newName }) } export async function deleteFileTreeEntry( rootPath: string, path: string ): Promise { return invoke("delete_file_tree_entry", { rootPath, path }) } export async function createFileTreeEntry( rootPath: string, path: string, name: string, kind: "file" | "dir" ): Promise { return invoke("create_file_tree_entry", { rootPath, path, name, kind }) } export async function gitLog( path: string, limit?: number, branch?: string, remote?: string ): Promise { return invoke("git_log", { path, limit: limit ?? null, branch: branch ?? null, remote: remote ?? null, }) } export async function gitCommitBranches( path: string, commit: string ): Promise { return invoke("git_commit_branches", { path, commit }) } export async function gitReset( path: string, commit: string, mode: GitResetMode ): Promise { return invoke("git_reset", { path, commit, mode }) } // Terminal commands export async function terminalSpawn( workingDir: string, initialCommand?: string, terminalId?: string ): Promise { return invoke("terminal_spawn", { workingDir, initialCommand: initialCommand ?? null, terminalId: terminalId ?? null, }) } export async function terminalWrite( terminalId: string, data: string ): Promise { return invoke("terminal_write", { terminalId, data }) } export async function terminalResize( terminalId: string, cols: number, rows: number ): Promise { return invoke("terminal_resize", { terminalId, cols, rows }) } export async function terminalKill(terminalId: string): Promise { return invoke("terminal_kill", { terminalId }) } export async function terminalList(): Promise { return invoke("terminal_list") }