MCPcopy Index your code
hub / github.com/BlockRunAI/ClawRouter / generateKey

Method generateKey

src/response-cache.ts:127–139  ·  view source on GitHub ↗

* Generate cache key from request body. * Hashes: model + messages + temperature + max_tokens + other params

(body: Buffer | string)

Source from the content-addressed store, hash-verified

125 * Hashes: model + messages + temperature + max_tokens + other params
126 */
127 static generateKey(body: Buffer | string): string {
128 try {
129 const parsed = JSON.parse(typeof body === "string" ? body : body.toString());
130 const normalized = normalizeForCache(parsed);
131 const canonical = canonicalize(normalized);
132 const keyContent = JSON.stringify(canonical);
133 return createHash("sha256").update(keyContent).digest("hex").slice(0, 32);
134 } catch {
135 // Fallback: hash raw body
136 const content = typeof body === "string" ? body : body.toString();
137 return createHash("sha256").update(content).digest("hex").slice(0, 32);
138 }
139 }
140
141 /**
142 * Check if caching is enabled for this request.

Calls 2

normalizeForCacheFunction · 0.85
canonicalizeFunction · 0.70

Tested by

no test coverage detected