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) 2.16 kB
import{ALL_TOOLS as a}from"./tools.js";const f=new Map(a.filter(r=>r.validation).map(r=>[r.name,r.validation]));function $(r,t){const e=f.get(r);if(!e)return{valid:!1,error:`Unknown tool: ${r}`};for(const n of e.required)if(t[n]===void 0||t[n]===null)return{valid:!1,error:`Missing required parameter: ${n}`};for(const[n,i]of Object.entries(t)){if(i==null)continue;const o=e.properties[n];if(!o)continue;const m=s(n,i,o);if(m)return{valid:!1,error:m}}return{valid:!0}}function s(r,t,e){switch(e.type){case"string":if(typeof t!="string")return`Parameter ${r} type error: expected string, got ${typeof t}`;if(e.maxLength!==void 0&&t.length>e.maxLength)return`Parameter ${r} exceeds max length ${e.maxLength}, actual ${t.length}`;if(e.enum&&!e.enum.includes(t))return`Parameter ${r} value "${t}" is not in allowed values [${e.enum.join(", ")}]`;break;case"integer":if(typeof t!="number"||!Number.isInteger(t))return`Parameter ${r} type error: expected integer, got ${typeof t=="number"?"float":typeof t}`;if(e.minimum!==void 0&&t<e.minimum)return`Parameter ${r} value ${t} is less than minimum ${e.minimum}`;if(e.maximum!==void 0&&t>e.maximum)return`Parameter ${r} value ${t} is greater than maximum ${e.maximum}`;if(e.enum&&!e.enum.includes(t))return`Parameter ${r} value ${t} is not in allowed values [${e.enum.join(", ")}]`;break;case"boolean":if(typeof t!="boolean")return`Parameter ${r} type error: expected boolean, got ${typeof t}`;break;case"array":if(!Array.isArray(t))return`Parameter ${r} type error: expected array, got ${typeof t}`;if(e.maxItems!==void 0&&t.length>e.maxItems)return`Parameter ${r} exceeds max items ${e.maxItems}, actual ${t.length}`;if(e.items)for(let n=0;n<t.length;n++){const i=t[n];if(e.items.type==="string"&&typeof i!="string")return`Parameter ${r}[${n}] type error: expected string, got ${typeof i}`;if(e.items.type==="integer"){if(typeof i!="number"||!Number.isInteger(i))return`Parameter ${r}[${n}] type error: expected integer, got ${typeof i}`;if(e.items.enum&&!e.items.enum.includes(i))return`Parameter ${r}[${n}] value ${i} is not in allowed values [${e.items.enum.join(", ")}]`}}break}}export{$ as validateToolArgs};