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.57 kB
JavaScript
import{mkdir as a}from"node:fs/promises";import{join as i}from"node:path";import{readJSONFile as c,writeJSONFileAtomic as o}from"../util/json-file.js";class x{contextsDir;constructor(t){this.contextsDir=t}async init(){await a(this.contextsDir,{recursive:!0})}resolvePath(t,e){const s=r=>r.replace(/[^a-zA-Z0-9_-]/g,"-"),n=e?`--${s(e)}`:"";return i(this.contextsDir,`${s(t)}${n}.json`)}async put(t){const e={schema_version:1,session_id:t.session_id,agent_id:t.agent_id,transcript_path:t.transcript_path,cwd:t.cwd,updated_at:Date.now(),context:t.context},s=this.resolvePath(t.session_id,t.agent_id);return await o(s,e),e}async get(t,e){const s=this.resolvePath(t,e?.agentId),n=c(s);return!n||typeof n!="object"?null:this.normalizeEntry(n)}async inspectMatchingContext(t){const e=await this.get(t.sessionID,{agentId:t.agentID});if(!e)return{status:"missing",context:null};const s=t.maxAgeMs??1800*1e3;return Date.now()-e.updated_at>s?{status:"stale",context:e}:t.transcriptPath&&e.transcript_path&&e.transcript_path!==t.transcriptPath?{status:"transcript_mismatch",context:e}:t.workingDir&&e.cwd&&e.cwd!==t.workingDir?{status:"cwd_mismatch",context:e}:e.context?.chat_id?{status:"matched",context:e}:{status:"missing",context:e}}normalizeEntry(t){if(!t.context||typeof t.context!="object")return null;const e=t.context;return e.chat_id?{schema_version:1,session_id:t.session_id??"",agent_id:t.agent_id,transcript_path:t.transcript_path,cwd:t.cwd,updated_at:t.updated_at??0,context:{chat_id:e.chat_id,message_id:e.message_id??""}}:null}}export{x as ChannelContextStore};