Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
fix(node-operator): teach the Redis shim pipelining and base64 responses
nirholas39d28e788872
diff --git a/packages/node-operator/tests/redis-shim.js b/packages/node-operator/tests/redis-shim.jsindex a6dd1bb89..8d86d784f 100644--- a/packages/node-operator/tests/redis-shim.js+++ b/packages/node-operator/tests/redis-shim.js@@ -1,8 +1,14 @@/*** A minimal in-process Redis-over-REST server that speaks exactly the- * Upstash REST protocol the platform's api/_lib/redis.js client uses- * (POST {url}/{command}/{key} with a JSON-array body of the remaining args,- * responding { result } / { error }).+ * Upstash REST protocol the platform's api/_lib/redis.js client uses.+ *+ * Three request shapes, all of which the Upstash client emits:+ * POST /pipeline body [["set","k","v"],["get","k"]] -> [{result},{result}]+ * POST / body ["set","k","v"] -> {result}+ * POST /set/k body ["v"] -> {result}+ * Auto-pipelining is on by default in the client, so /pipeline is the shape+ * that actually carries production traffic; a shim that only answered the+ * single-command form failed every command with "unknown command 'pipeline'".** It implements only the commands the inference-node queue needs* (get/set/rpush/rpop/del/expire), which is the point: this shim exists so@@ -58,34 +64,74 @@ export function createRedisShim() {},};+ /** Run one `[command, ...args]` array and return its Upstash result envelope. */+ function exec(command) {+ if (!Array.isArray(command) || command.length === 0) {+ return { error: 'ERR empty command' };+ }+ const name = String(command[0]).toLowerCase();+ const handler = handlers[name];+ if (!handler) return { error: `ERR unknown command '${name}'` };+ try {+ return { result: handler(command.slice(1)) };+ } catch (err) {+ return { error: String(err.message || err) };+ }+ }++ /**+ * The client asks for base64 response encoding by default+ * (`Upstash-Encoding: base64`) and unconditionally base64-DECODES every+ * string it gets back. A shim that answers in plain text therefore corrupts+ * any value that happens to be valid base64: `rpop` returning the job id+ * "job1" decoded to three bytes of mojibake, so the queue drained into+ * nothing. Encode string results whenever the header asks for it.+ */+ function encodeResult(value) {+ if (typeof value === 'string') return Buffer.from(value, 'utf8').toString('base64');+ if (Array.isArray(value)) return value.map(encodeResult);+ return value;+ }+const server = http.createServer((req, res) => {const segments = req.url.split('/').filter(Boolean).map(decodeURIComponent);- const command = (segments[0] || '').toLowerCase();- const args = segments.slice(1);+ const route = (segments[0] || '').toLowerCase();+ const b64 = String(req.headers['upstash-encoding'] || '').toLowerCase() === 'base64';+ const envelope = (out) => (b64 && out.result !== undefined ? { ...out, result: encodeResult(out.result) } : out);let body = '';req.on('data', (c) => (body += c));req.on('end', () => {- let cmdArgs = args;+ let parsed = null;if (body) {try {- const parsed = JSON.parse(body);- if (Array.isArray(parsed)) cmdArgs = parsed;- } catch { /* keep path args */ }+ parsed = JSON.parse(body);+ } catch { parsed = null; }}- const handler = handlers[command];res.setHeader('content-type', 'application/json');- if (!handler) {- res.writeHead(400);- res.end(JSON.stringify({ error: `ERR unknown command '${command}'` }));- return;- }- try {++ // The Upstash client batches commands by default (auto-pipelining), so+ // the common case is POST /pipeline with an array OF command arrays.+ // `multi-exec` uses the same shape; this store is single-threaded per+ // request, which is all the atomicity the queue needs.+ if (route === 'pipeline' || route === 'multi-exec') {+ if (!Array.isArray(parsed)) {+ res.writeHead(400);+ res.end(JSON.stringify({ error: 'ERR pipeline body must be an array of commands' }));+ return;+ }res.writeHead(200);- res.end(JSON.stringify({ result: handler(cmdArgs) }));- } catch (err) {- res.writeHead(400);- res.end(JSON.stringify({ error: String(err.message || err) }));+ res.end(JSON.stringify(parsed.map((c) => envelope(exec(c)))));+ return;}++ // Single command: `POST /` with ["set", key, ...], or the path form+ // `POST /set/key` with the remaining args in the body.+ const command = Array.isArray(parsed)+ ? (route ? [route, ...parsed] : parsed)+ : [route, ...segments.slice(1)];+ const out = exec(command);+ res.writeHead(out.error ? 400 : 200);+ res.end(JSON.stringify(envelope(out)));});});