Skip to content

fix(cli): run app middleware for the /agui endpoint#354

Merged
blove merged 1 commit into
mainfrom
blove/agui-middleware-parity
Jul 13, 2026
Merged

fix(cli): run app middleware for the /agui endpoint#354
blove merged 1 commit into
mainfrom
blove/agui-middleware-parity

Conversation

@blove

@blove blove commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

The POST /agui/{routeId} AG-UI endpoint (#322) did not run app middleware, unlike runs/stream, runs/wait, and resume. That silently bypassed any middleware-based auth, rate-limiting, or context injection for AG-UI (CopilotKit) clients. This wires middleware into /agui with parity:

  • A rejecting middleware returns its status/body and the run never starts.
  • A continue-with-context middleware has its context threaded into the run (middlewareContext).

Flagged in the final review of #322.

Change

  • packages/cli/src/lib/dev/middleware.ts — moved the shared parseHeaders / extractRouteParams helpers here (exported) so both runtime-server.ts and the handler can use them without a circular import.
  • packages/cli/src/lib/dev/agui-handler.ts — build the MiddlewareRequest, runMiddleware, short-circuit on reject, pass middlewareContext to streamResolvedRoute.
  • packages/cli/src/lib/dev/runtime-server.ts — pass middleware into the /agui route; import the moved helpers.

Test plan

  • New integration test in agui-endpoint.test.ts: a fixture app with a rejecting src/middleware.tsPOST /agui/<route> returns 403 with the middleware body and no AG-UI stream. (Existing stream test still passes.)
  • Full @dawn-ai/cli suite: 349/349; typecheck + lint clean.

🤖 Generated with Claude Code

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]>
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dawnai Ready Ready Preview, Comment Jul 13, 2026 7:04pm

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Claude finished @blove's task in 1s —— View job


I'll analyze this and get back to you.

@blove
blove enabled auto-merge (squash) July 13, 2026 19:04
@blove
blove merged commit 2b6be86 into main Jul 13, 2026
15 checks passed
@blove
blove deleted the blove/agui-middleware-parity branch July 13, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant