Files
CC-Switch/src/lib/api/sessions.ts
T
Jason 8c3f18a9bd feat: add session deletion with per-provider cleanup and path safety
Add delete_session Tauri command dispatching to provider-specific deletion
logic for all 5 providers (Claude, Codex, Gemini, OpenCode, OpenClaw).
Includes path traversal protection via canonicalize + starts_with validation,
session ID verification against file contents, frontend confirmation dialog
with optimistic cache updates, i18n keys (zh/en/ja), and component tests.
2026-03-08 19:42:18 +08:00

44 lines
1.0 KiB
TypeScript

import { invoke } from "@tauri-apps/api/core";
import type { SessionMessage, SessionMeta } from "@/types";
export interface DeleteSessionOptions {
providerId: string;
sessionId: string;
sourcePath: string;
}
export const sessionsApi = {
async list(): Promise<SessionMeta[]> {
return await invoke("list_sessions");
},
async getMessages(
providerId: string,
sourcePath: string,
): Promise<SessionMessage[]> {
return await invoke("get_session_messages", { providerId, sourcePath });
},
async delete(options: DeleteSessionOptions): Promise<boolean> {
const { providerId, sessionId, sourcePath } = options;
return await invoke("delete_session", {
providerId,
sessionId,
sourcePath,
});
},
async launchTerminal(options: {
command: string;
cwd?: string | null;
customConfig?: string | null;
}): Promise<boolean> {
const { command, cwd, customConfig } = options;
return await invoke("launch_session_terminal", {
command,
cwd,
customConfig,
});
},
};