import * as fs from 'fs';
import * as path from 'path';
const SESSION_DIR = '.port_sessions';
export function saveSession(session) {
    const targetDir = path.join(process.cwd(), SESSION_DIR);
    if (!fs.existsSync(targetDir)) {
        fs.mkdirSync(targetDir, { recursive: true });
    }
    const filePath = path.join(targetDir, `${session.sessionId}.json`);
    fs.writeFileSync(filePath, JSON.stringify(session, null, 2));
    return filePath;
}
export function loadSession(sessionId) {
    const filePath = path.join(process.cwd(), SESSION_DIR, `${sessionId}.json`);
    const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
    return {
        sessionId: data.sessionId,
        messages: data.messages,
        inputTokens: data.inputTokens,
        outputTokens: data.outputTokens,
    };
}
