From 6601ae3a8d3c5c9eeff307b616d94e4b4f9e668d Mon Sep 17 00:00:00 2001 From: backryun Date: Tue, 28 Jul 2026 07:08:15 +0900 Subject: [PATCH] fix(middleware): declare withInjectionGuard's context parameter optional (#8644) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All five diagnostics in src/lib/batches/dispatch.ts are the same: Type '(request: any, context: any) => Promise' is not assignable to type 'BatchRouteHandler'. Target signature provides too few arguments. Expected 2 or more, but got 1. `withInjectionGuard()` returns `guardedHandler(request, context: any)` with the second parameter required, so every route it wraps advertises arity 2. The batch dispatcher's `BatchRouteHandler` is `(request: Request) => …`, and TS rejects assigning a function that needs an argument the caller will never supply. The declaration was wrong about its own runtime. `dispatch.ts:48` already calls `handler(request)` with one argument, and has been doing so in production; `context` is only forwarded to the inner handler, where routes that do not read it get `undefined`. Marking it `context?: any` states what was already true. 208 -> 203, zero new, on a line-number-agnostic diff of the full tsc error set. One character; nothing executable changed. No test added: the one-argument call path is the existing behaviour and is already covered — embeddings-auth.test.ts and embeddings-route-apikeymeta-6929 call `POST(req)` directly through withInjectionGuard, which is exactly the arity this now permits. 370/370 across the 43 injection-guard / batch / embeddings / moderation suites; typecheck:core, eslint and check:file-size clean. Co-authored-by: backryun --- src/middleware/promptInjectionGuard.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/middleware/promptInjectionGuard.ts b/src/middleware/promptInjectionGuard.ts index d257013278..be2e149479 100644 --- a/src/middleware/promptInjectionGuard.ts +++ b/src/middleware/promptInjectionGuard.ts @@ -52,7 +52,7 @@ export function createInjectionGuard(options: PromptInjectionGuardrailOptions = export function withInjectionGuard(handler: any, options: any = {}) { const guard = createInjectionGuard(options); - return async function guardedHandler(request: any, context: any) { + return async function guardedHandler(request: any, context?: any) { // Only apply to POST/PUT/PATCH if (!["POST", "PUT", "PATCH"].includes(request.method)) { return handler(request, context);