Skip to content

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.

add xspace-agent/xspace-agent/packages/server/src/middleware/request-id.ts

overstepping01927c0cf587
diff --git a/xspace-agent/xspace-agent/packages/server/src/middleware/request-id.ts b/xspace-agent/xspace-agent/packages/server/src/middleware/request-id.ts
new file mode 100644
index 000000000..665a79181
--- /dev/null
+++ b/xspace-agent/xspace-agent/packages/server/src/middleware/request-id.ts
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: Apache-2.0
+// Copyright 2026 nirholas (https://github.com/nirholas/xspace-agent) [§83]
+
+// =============================================================================
+// Request ID middleware — generates or forwards X-Request-ID on every request
+// =============================================================================
+
+import type { Request, Response, NextFunction } from 'express'
+import { randomUUID } from 'crypto'
+import { getAppLogger } from 'xspace-agent'
+
+/**
+ * Attaches a unique request ID to every request. If the client sends an
+ * `X-Request-ID` header it is reused; otherwise a new UUIDv4 is generated.
+ *
+ * Sets `req.id` and echoes the ID back via the `X-Request-ID` response header.
+ * Also attaches a child logger at `req.log`.
+ */
+export function requestIdMiddleware(
+ req: Request,
+ res: Response,
+ next: NextFunction,
+): void {
+ const id = (req.headers['x-request-id'] as string) ?? randomUUID()
+ ;(req as any).id = id
+ res.setHeader('X-Request-ID', id)
+ ;(req as any).log = getAppLogger('http').child({
+ requestId: id,
+ method: req.method,
+ path: req.path,
+ })
+ next()
+}
+
+