p3x-redis-ui-server
Version:
🏍️ P3X Redis UI server — Socket.IO backend for the dual Angular + React frontend with AI queries, 54 languages, and auto data decompression
2 lines (1 loc) • 6.5 kB
JavaScript
function e(e){return"string"!=typeof e&&(e=JSON.stringify(e)),e.length<=8e3?e:e.slice(0,8e3)+`\n\u2026 [truncated, original ${e.length} chars]`}function t(t){return null==t?"":"string"==typeof t?e(t):Buffer.isBuffer(t)?e(t.toString("utf8")):(Array.isArray(t),e(JSON.stringify(t,null,2)))}export const TOOL_SCHEMAS=[{type:"function",function:{name:"redis_info",description:'Run INFO [section] to get server/memory/stats/replication/clients/cpu/keyspace data. Use this to answer "why is memory high", "how many clients", "what is the uptime".',parameters:{type:"object",properties:{section:{type:"string",description:"Optional INFO section: server, clients, memory, stats, replication, cpu, modules, keyspace, all. Omit for default summary."}},required:[]}}},{type:"function",function:{name:"redis_memory_stats",description:"Run MEMORY STATS for a detailed memory breakdown (overhead, per-type usage, allocator stats). Prefer this over INFO memory when the user asks about memory composition.",parameters:{type:"object",properties:{},required:[]}}},{type:"function",function:{name:"redis_slowlog_get",description:'Run SLOWLOG GET [count] to retrieve the most recent slow queries with their execution duration. Use for "why is it slow", "what queries are slow".',parameters:{type:"object",properties:{count:{type:"integer",description:"Max entries to return (default 16, max 128)."}},required:[]}}},{type:"function",function:{name:"redis_client_list",description:"Run CLIENT LIST to see all connected clients (address, name, current command, idle time).",parameters:{type:"object",properties:{},required:[]}}},{type:"function",function:{name:"redis_config_get",description:"Run CONFIG GET <pattern> to read server configuration. Common patterns: maxmemory, maxmemory-policy, save, timeout, *, client-output-buffer-limit.",parameters:{type:"object",properties:{pattern:{type:"string",description:'Config key glob, e.g. "maxmemory*" or "save".'}},required:["pattern"]}}},{type:"function",function:{name:"redis_dbsize",description:"Run DBSIZE to count keys in the current database.",parameters:{type:"object",properties:{},required:[]}}},{type:"function",function:{name:"redis_latency_latest",description:"Run LATENCY LATEST to see the most recent latency events recorded by the server.",parameters:{type:"object",properties:{},required:[]}}},{type:"function",function:{name:"redis_scan",description:"Run SCAN <cursor> [MATCH <pattern>] [COUNT <n>] [TYPE <t>] to enumerate keys safely. NEVER exposes KEYS. Default COUNT 100, max 1000.",parameters:{type:"object",properties:{cursor:{type:"string",description:"Cursor (0 to start, use returned cursor to continue)."},match:{type:"string",description:"Optional MATCH glob pattern."},count:{type:"integer",description:"Optional COUNT hint (1-1000, default 100)."},type:{type:"string",description:"Optional TYPE filter: string, list, set, hash, zset, stream, ReJSON-RL."}},required:["cursor"]}}},{type:"function",function:{name:"redis_type",description:"Run TYPE <key> to see the data type of a specific key.",parameters:{type:"object",properties:{key:{type:"string",description:"The Redis key name."}},required:["key"]}}},{type:"function",function:{name:"redis_ttl",description:"Run TTL <key> to see seconds until a key expires. -1 = no expiry, -2 = does not exist.",parameters:{type:"object",properties:{key:{type:"string",description:"The Redis key name."}},required:["key"]}}},{type:"function",function:{name:"redis_memory_usage",description:"Run MEMORY USAGE <key> to get bytes of memory a specific key uses (including overhead).",parameters:{type:"object",properties:{key:{type:"string",description:"The Redis key name."}},required:["key"]}}},{type:"function",function:{name:"redis_cluster_info",description:"Run CLUSTER INFO to see cluster state (enabled, slot assignment, epoch, stats). Only meaningful in cluster mode.",parameters:{type:"object",properties:{},required:[]}}},{type:"function",function:{name:"redis_cluster_nodes",description:"Run CLUSTER NODES to see cluster topology (masters, replicas, slot ranges). Only meaningful in cluster mode.",parameters:{type:"object",properties:{},required:[]}}},{type:"function",function:{name:"redis_acl_whoami",description:"Run ACL WHOAMI to see which ACL user the connection is authenticated as.",parameters:{type:"object",properties:{},required:[]}}},{type:"function",function:{name:"redis_module_list",description:"Run MODULE LIST to enumerate loaded Redis modules (ReJSON, RediSearch, RedisTimeSeries, RedisBloom, etc.) with versions.",parameters:{type:"object",properties:{},required:[]}}}];const r={redis_info:async(e,r)=>{const n="string"==typeof r.section&&r.section.length>0?r.section:"";return t(n?await e.call("INFO",n):await e.call("INFO"))},redis_memory_stats:async e=>t(await e.call("MEMORY","STATS")),redis_slowlog_get:async(e,r)=>{const n=Math.min(Math.max(parseInt(r.count,10)||16,1),128);return t(await e.call("SLOWLOG","GET",n))},redis_client_list:async e=>t(await e.call("CLIENT","LIST")),redis_config_get:async(e,r)=>{const n=String(r.pattern||"*");return t(await e.call("CONFIG","GET",n))},redis_dbsize:async e=>t(await e.call("DBSIZE")),redis_latency_latest:async e=>t(await e.call("LATENCY","LATEST")),redis_scan:async(e,r)=>{const n=[String(r.cursor??"0")];"string"==typeof r.match&&r.match.length>0&&n.push("MATCH",r.match);const i=parseInt(r.count,10),s=Number.isFinite(i)?Math.min(Math.max(i,1),1e3):100;return n.push("COUNT",s),"string"==typeof r.type&&r.type.length>0&&n.push("TYPE",r.type),t(await e.call("SCAN",...n))},redis_type:async(e,r)=>{const n=String(r.key||"");if(!n)throw new Error("redis_type requires a key argument");return t(await e.call("TYPE",n))},redis_ttl:async(e,r)=>{const n=String(r.key||"");if(!n)throw new Error("redis_ttl requires a key argument");return t(await e.call("TTL",n))},redis_memory_usage:async(e,r)=>{const n=String(r.key||"");if(!n)throw new Error("redis_memory_usage requires a key argument");return t(await e.call("MEMORY","USAGE",n))},redis_cluster_info:async e=>t(await e.call("CLUSTER","INFO")),redis_cluster_nodes:async e=>t(await e.call("CLUSTER","NODES")),redis_acl_whoami:async e=>t(await e.call("ACL","WHOAMI")),redis_module_list:async e=>t(await e.call("MODULE","LIST"))};export async function runTool(e,t,n){const i=Date.now();try{const s=r[t];return s?{ok:!0,result:await s(e,n||{}),ms:Date.now()-i}:{ok:!1,error:`Unknown tool: ${t}`,ms:Date.now()-i}}catch(e){return{ok:!1,error:e.message||String(e),ms:Date.now()-i}}}