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