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.71 kB
JavaScript
const a="grix://card/",c="grix://open/",u="_submit",l=/\(\s*(grix:\/\/card\/[\s\S]+?)\s*\)/gi,d=/grix:\/\/card\/[^\s)\]]+/gi,m=/grix:\/\/open\/[^\s)\]]+/gi;function g(t){const n=[],r=new Set;for(const e of f(t)){const s=p(e);!s||r.has(s.normalizedUri)||(r.add(s.normalizedUri),n.push(s))}return{cardSubmissions:n}}function U(t,n){return S(t.params.get(n))}function f(t){const n=_(t),r=[];for(const s of n.matchAll(l)){const i=o(s[1]);i&&r.push(i)}for(const s of n.matchAll(d)){const i=o(s[0]);i&&r.push(i)}for(const s of n.matchAll(m)){const i=o(s[0]);i&&r.push(i)}const e=o(n.trim());return(e.startsWith(a)||e.startsWith(c))&&r.push(e),R(r)}function p(t){if(t.startsWith(c))return h(t);if(!t.startsWith(a))return null;let n;try{n=new URL(t)}catch{return null}if(n.hostname!=="card")return null;const r=n.pathname.replace(/^\/+/,"").trim();if(!r.endsWith(u))return null;const e=r.slice(0,-u.length).trim();return!e||e==="agent_open_session"?null:{cardId:e,rawUri:t,normalizedUri:n.toString(),params:n.searchParams}}function h(t){let n;try{n=new URL(t)}catch{return null}if(n.hostname!=="open")return null;const r=n.pathname.split("/").map(e=>e.trim()).filter(Boolean);return r.length!==1||r[0]!=="session"?null:{cardId:"agent_open_session",rawUri:t,normalizedUri:n.toString(),params:n.searchParams}}function _(t){return t.replace(/&/gi,"&")}function o(t){return t.replace(/\s+/g,"").trim()}function R(t){const n=[...new Set(t)];return n.filter(r=>!n.some(e=>e!==r&&e.startsWith(r)))}function S(t){if(!t)return;let n=t.trim();for(let r=0;r<3;r++)try{const e=decodeURIComponent(n);if(e===n)break;n=e}catch{break}return n.trim()||void 0}export{g as parseInteractionMessage,U as readCardSubmissionParam};