Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.1 KB
Raw Blame
import fs from 'fs'
import path from 'path'
import { system } from './system/system'
import { AppSystemProp } from './system/system-props'

export const localFileStore = {
    async save(key: string, value: string): Promise<void> {
        const settingsFilePath = path.join(
            system.getOrThrow(AppSystemProp.CONFIG_PATH),
            'settings.json',
        )
        const settings = getSettingsFilePath()
        settings[key] = value
        const parentDir = path.dirname(settingsFilePath)
        if (!fs.existsSync(parentDir)) {
            fs.mkdirSync(parentDir, { recursive: true })
        }
        fs.writeFileSync(settingsFilePath, JSON.stringify(settings))
    },

    async load(key: string): Promise<string | null> {
        const settings = getSettingsFilePath()
        return settings[key] || null
    },
}

const getSettingsFilePath = () => {
    const settingsFilePath = path.join(
        system.getOrThrow(AppSystemProp.CONFIG_PATH),
        'settings.json',
    )
    try {
        return JSON.parse(fs.readFileSync(settingsFilePath, 'utf8'))
    }
    catch (error) {
        return {}
    }
}