fix(cli): run app middleware for the /agui endpoint#354
Merged
Conversation
Parity with runs/stream, runs/wait, and resume: the AG-UI endpoint now runs loadMiddleware/runMiddleware — a rejecting middleware blocks the run and a continue-with-context threads middlewareContext into it. Extracts the shared parseHeaders/extractRouteParams helpers into middleware.ts (avoids a circular import). Adds an integration test proving a rejecting middleware blocks /agui. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
blove
enabled auto-merge (squash)
July 13, 2026 19:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
POST /agui/{routeId}AG-UI endpoint (#322) did not run app middleware, unlikeruns/stream,runs/wait, andresume. That silently bypassed any middleware-based auth, rate-limiting, or context injection for AG-UI (CopilotKit) clients. This wires middleware into/aguiwith parity:status/bodyand the run never starts.contextthreaded into the run (middlewareContext).Flagged in the final review of #322.
Change
packages/cli/src/lib/dev/middleware.ts— moved the sharedparseHeaders/extractRouteParamshelpers here (exported) so bothruntime-server.tsand the handler can use them without a circular import.packages/cli/src/lib/dev/agui-handler.ts— build theMiddlewareRequest,runMiddleware, short-circuit on reject, passmiddlewareContexttostreamResolvedRoute.packages/cli/src/lib/dev/runtime-server.ts— passmiddlewareinto the/aguiroute; import the moved helpers.Test plan
agui-endpoint.test.ts: a fixture app with a rejectingsrc/middleware.ts→POST /agui/<route>returns 403 with the middleware body and no AG-UI stream. (Existing stream test still passes.)@dawn-ai/clisuite: 349/349; typecheck + lint clean.🤖 Generated with Claude Code