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.15 kB
import{readdir as c,readFile as a,writeFile as o,mkdir as d,unlink as u}from"node:fs/promises";import{join as n}from"node:path";class w{dir;constructor(t){this.dir=t}async ensureDir(){await d(this.dir,{recursive:!0})}async writeRequest(t){await this.ensureDir();const i=n(this.dir,`${t.request_id}.json`);await o(i,JSON.stringify(t,null,2))}async listPending(){await this.ensureDir();try{const t=await c(this.dir),i=[];for(const e of t)if(e.endsWith(".json"))try{const r=await a(n(this.dir,e),"utf8"),s=JSON.parse(r);s.resolved||i.push(s)}catch{}return i.sort((e,r)=>e.created_at-r.created_at)}catch{return[]}}async resolveRequest(t,i){await this.ensureDir();const e=n(this.dir,`${t}.json`);try{const r=await a(e,"utf8"),s=JSON.parse(r);s.resolved=!0,s.resolution=i,await o(e,JSON.stringify(s,null,2))}catch{await o(e,JSON.stringify({request_id:t,resolved:!0,resolution:i,created_at:Date.now()}))}}async cleanResolved(){await this.ensureDir();try{const t=await c(this.dir);for(const i of t)if(i.endsWith(".json"))try{const e=await a(n(this.dir,i),"utf8");JSON.parse(e).resolved&&await u(n(this.dir,i))}catch{}}catch{}}}export{w as PermissionStore};