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) • 2.24 kB
JavaScript
import{mkdir as u,readdir as c}from"node:fs/promises";import{join as a}from"node:path";import{readJSONFile as r,writeJSONFileAtomic as o}from"../util/json-file.js";class _{requestsDir;constructor(t){this.requestsDir=t}async init(){await u(this.requestsDir,{recursive:!0})}resolvePath(t){return a(this.requestsDir,`${t}.json`)}async createRequest(t){const e={request_id:t.request_id,status:"pending",created_at:Date.now(),fields:t.fields,channel_context:t.channel_context};return await o(this.resolvePath(t.request_id),e),e}async getRequest(t){const e=r(this.resolvePath(t));return!e||typeof e!="object"?null:this.normalizeRequest(e)}async saveRequest(t){await o(this.resolvePath(t.request_id),t)}async listPendingDispatches(){const t=await c(this.requestsDir).catch(()=>[]),e=[];for(const s of t){if(!s.endsWith(".json"))continue;const i=r(a(this.requestsDir,s));if(!i||typeof i!="object")continue;const n=this.normalizeRequest(i);n&&n.status==="pending"&&n.channel_context?.chat_id&&e.push(n)}return e.sort((s,i)=>s.created_at-i.created_at)}async markDispatched(t){const e=await this.getRequest(t);e&&(e.status="dispatched",e.dispatched_at=Date.now(),await this.saveRequest(e))}async markDispatchFailed(t,e){const s=await this.getRequest(t);s&&(s.status="pending",await this.saveRequest(s))}async resolveRequest(t,e){const s=await this.getRequest(t);s&&(s.status="resolved",s.response_action=e.action,s.response_content=e.content,await this.saveRequest(s))}async markExpired(t){const e=await this.getRequest(t);!e||e.status!=="pending"||(e.status="expired",await this.saveRequest(e))}async getStatus(){const t=await c(this.requestsDir).catch(()=>[]);let e=0;for(const s of t){if(!s.endsWith(".json"))continue;const i=r(a(this.requestsDir,s));if(!i||typeof i!="object")continue;i.status==="pending"&&e++}return{pending_count:e}}normalizeRequest(t){return t.request_id?{request_id:String(t.request_id),status:["pending","dispatched","resolved","expired"].includes(t.status)?t.status:"pending",created_at:t.created_at??0,dispatched_at:t.dispatched_at,fields:t.fields??{},channel_context:t.channel_context??{chat_id:"",message_id:""},response_action:t.response_action,response_content:t.response_content}:null}}export{_ as ElicitationStore};