UNPKG

grix-connector

Version:

Connect local AI coding agents (Claude, Codex, Gemini, Qwen, DeepSeek, Cursor, OpenCode, Pi, OpenHuman, Reasonix) to the Grix scheduling platform. Also serves as an OpenClaw plugin for Grix channel transport.

2 lines (1 loc) 1 kB
import{readJSONFile as s,writeJSONFileAtomic as o}from"../util/json-file.js";import{log as r}from"../log/index.js";class n{configs=new Map;filePath;writePromise=Promise.resolve();constructor(t){this.filePath=t??null}load(){if(!this.filePath)return;const t=s(this.filePath);if(!(!t||typeof t!="object"||Array.isArray(t))){this.configs.clear();for(const[i,e]of Object.entries(t))e&&typeof e=="object"&&this.configs.set(i,e)}}get(t){return this.configs.get(t)}set(t,i){const e=this.configs.get(t);this.configs.set(t,{...e,...i,updatedAt:Date.now()}),this.scheduleWrite()}delete(t){this.configs.delete(t),this.scheduleWrite()}async flush(){await this.writePromise}scheduleWrite(){this.filePath&&(this.writePromise=this.writePromise.then(()=>this.write()).catch(t=>{r.error("agent-global-config-store",`Persist failed: ${t instanceof Error?t.message:t}`)}))}async write(){if(!this.filePath)return;const t={};for(const[i,e]of this.configs)t[i]=e;await o(this.filePath,t)}}export{n as AgentGlobalConfigStore};