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.
7 lines (6 loc) • 2.22 kB
JavaScript
import{HookSignalStore as f}from"../core/hooks/hook-signal-store.js";import{ChannelContextStore as g}from"../core/context/channel-context-store.js";import{resolveHookChannelContext as w}from"../core/context/channel-context-resolution.js";import{resolveRuntimePaths as _}from"../core/config/paths.js";import{resolveLogRotationOptions as h}from"../core/log/rotation.js";import{ElicitationStore as I}from"../core/persistence/elicitation-store.js";import{readStdinJSON as k}from"./lib/read-stdin.js";function e(t,n){const r={hookSpecificOutput:{hookEventName:"Elicitation",action:t,content:n}};process.stdout.write(JSON.stringify(r)+`
`)}const v=1e3,x=600*1e3;async function O(){const t=await k();if(t.hook_event_name!=="Elicitation"){process.stdout.write(`{}
`);return}const n=_(),r=h(),m=process.env.GRIX_HOOK_SIGNALS_PATH||n.hookSignalsPath;await new f(m,n.hookSignalsLogPath,void 0,r).recordHookEvent(t);const s=String(t.mode??"");if(s!=="form"&&s!=="url"){process.stdout.write(`{}
`);return}if(s==="form"&&!t.requested_schema){e("cancel");return}if(s==="url"&&!t.url){e("cancel");return}const l=String(t.session_id??""),d=String(t.agent_id??""),u=new g(n.contextsDir);await u.init();const a=await w({sessionContextStore:u,sessionID:l,agentID:d||void 0,transcriptPath:String(t.transcript_path??""),workingDir:String(t.cwd??process.cwd()),maxAgeMs:1800*1e3});if(a.status!=="resolved"||!a.context){process.stderr.write(`elicitation-hook: no channel context for session ${l}
`),e("cancel");return}const c=`elicit-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,i=new I(n.elicitationRequestsDir);await i.init(),await i.createRequest({request_id:c,status:"pending",fields:{mcp_server_name:String(t.mcp_server_name??""),message:String(t.message??""),mode:s,url:String(t.url??""),requested_schema:t.requested_schema??{}},channel_context:a.context});const p=Date.now()+x;for(;Date.now()<p;){await new Promise(S=>setTimeout(S,v));const o=await i.getRequest(c);if(!o||o.status==="expired"){e("cancel");return}if(o.status==="resolved"){o.response_action==="cancel"||!o.response_content?e("cancel"):e("accept",o.response_content);return}}await i.markExpired(c),e("cancel")}O().catch(()=>{e("cancel")});