Repository navigation
[AISAGE-502] feat(ai-gateway): add a standalone ai-gateway app serving /api/v1 from a web-shared package - #6806
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe only PR-authored change since the previous review commit Files Reviewed (1 PR-authored file)
The other 158 files in Previous Review Summaries (9 snapshots, latest commit c75cb7a)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit c75cb7a)Status: No Issues Found | Recommendation: Merge Executive SummaryThe 23 PR-authored files that changed since the previously reviewed tree (600c7e4) only repoint Files Reviewed (23 files)
Every updated reference target was verified to exist at HEAD, including Previous review (commit 600c7e4)Status: No Issues Found | Recommendation: Merge Files Reviewed (12 files changed since the previously reviewed tree)
The diff from the previous review commit contains only main commits (#6812, #7021) pulled in by the rebase; no PR-authored changes or new defects. The prior inline findings are resolved and no new inline comments were added. Previous review (commit cc9978f)Status: No Issues Found | Recommendation: Merge Executive SummaryThe PR head is byte-identical to the previously reviewed tree, so the incremental scope is empty; no new changed-code defects were found in the Files Reviewed (0 changed since previous review)
Previous review (commit 4803be6)Status: No Issues Found | Recommendation: Merge Executive SummaryThe incremental changes since the previous review collapse the ai-gateway routes under Files Reviewed (43 files)
Previous review (commit 79ffba2)Status: No Issues Found | Recommendation: Merge Executive SummaryThe branch was rebased, so this run re-reviewed the whole PR at current HEAD Files Reviewed (6 areas)
Previous review (commit e5d0626)Status: No Issues Found | Recommendation: Merge The incremental commit adds Files Reviewed (2 files)
Resolved since the last review:
Previous review (commit 1492630)Status: 1 Issue Found | Recommendation: Address before merge Executive SummaryThe incremental guardrail-test change is correct and adds no new findings; the only current unresolved issue remains the ai-gateway catch-all that serves the intentionally omitted Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (8 areas)
Fix these issues in Kilo Cloud Previous review (commit 37ff8c7)Status: 1 Issue Found | Recommendation: Address before merge Executive SummaryThe Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (7 areas)
Fix these issues in Kilo Cloud Previous review (commit d10efa3)Status: 4 Issues Found | Recommendation: Address before merge Executive SummaryThe Overview
Issue Details (click to expand)CRITICAL
WARNING
SUGGESTION
Files Reviewed (7 files / 2 commits)
Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0 Review guidance: REVIEW.md from base branch |
d10efa3 to
37ff8c7
Compare
4803be6 to
cc9978f
Compare
cc9978f to
600c7e4
Compare
600c7e4 to
c75cb7a
Compare
…web-shared Pure file moves, no content changes. The files are the transitive dependencies of the gateway route handlers and the typesafe systemone handler, their colocated tests, and the next-auth and next-page ambient types the moved code needs. The next commit wires the package so the moved code resolves again.
…t @/ Moving code into packages/web-shared broke relative imports between moved files and files that stay in apps/web. Only the import specifiers change, from relative paths to the equivalent @/ paths; the next commit makes @/ resolve in both packages.
- Add the @kilocode/web-shared package manifest. Its dependencies match the apps/web versions and optional peers, so pnpm links the same next, next-auth and @sentry/nextjs instances as apps/web. - Resolve @/* to apps/web/src first and packages/web-shared/src second in the web tsconfigs, Jest, the @kilocode/trpc build and Storybook. Moved files keep their import specifiers. - tsconfig.lib.json proves web-shared runtime code only imports itself. - Run web-shared tests from the web Jest config, keep the apps/web lint rules for the moved code, point path-based audits and guardrails at the new locations, and include web-shared in CI path filters.
Docs and code comments that name a file moved to packages/web-shared now use its new path. Only exact file references change.
The ai-gateway app serves the gateway routes under /api/v1 instead of /api/gateway and /api/openrouter. The LLM proxy now also strips the /api/v1 prefix when it validates the path, and the blocked-client check also covers /api/v1/fim/completions. The existing apps/web paths behave as before.
The routes are backed by the handlers in packages/web-shared and all live under /api/v1, without the /api/gateway and /api/openrouter prefixes the apps/web routes from #6737 use. The apps/web v1 variants collapse into the same routes, so /api/gateway/v1/models and /api/openrouter/models both become /api/v1/models. /api/fim, /api/edit and /api/organizations move under /api/v1 as well, and the typesafe gateway /api/gateway/typesafe/v1/systemone becomes /api/v1/systemone. src/proxy.ts keeps the blocked-client check for /api/v1/fim/completions. The app is not deployed. Its dev script runs next dev with the web app's env files and points app URLs at the web app.
pnpm dev:start ai-gateway starts apps/ai-gateway in its own opt-in group on port 3010 plus the port offset, clear of the ports the web dev script probes. Selecting it also syncs apps/web/.env.development.local, which the app reads.
5112811 to
3b0caba
Compare
fix(deps): align next 16.3.6 in web-shared and ai-gateway with the lockfile #7042 pinned next 16.3.6 through a pnpm override and in apps/web, while #6806 added packages/web-shared and apps/ai-gateway still pinned at 16.3.3. With the override, their lockfile specifiers no longer match, so every frozen-lockfile install on main fails with ERR_PNPM_OUTDATED_LOCKFILE and CI cannot go green. Pin both packages to 16.3.6 to match apps/web and the override, and refresh the lockfile.
…from ai-gateway apps/ai-gateway declares @playwright/test but never invokes it: no test or e2e script, no playwright.config.*, no *.spec.ts/*.test.ts files, and no CI workflow runs Playwright against the gateway (its build-ai-gateway job only runs `next build`). The declaration was carried over from apps/web when the standalone gateway app was added (#6806) and is a leftover.
Summary
Adds
apps/ai-gateway, a Next.js app that serves the AI gateway API on its own, and moves the server code it shares withapps/webinto a new@kilocode/web-sharedpackage.apps/webstill serves the same handlers at its existing paths, and the new app is not deployed./api/v1./api/gatewayand/api/openrouterprefixes that theapps/webroutes from [AISAGE-502] refactor(ai-gateway): make gateway API routes thin facades #6737 use are dropped, and theirv1variants collapse into single routes. For example,/api/gateway/v1/modelsand/api/openrouter/modelsboth become/api/v1/models, and the LLM proxy is/api/v1/[...path]./api/fim/completions,/api/edit/completions,/api/organizations/[id]/models*and the typesafe/api/gateway/typesafe/v1/systemonemove under/api/v1as well. The typesafe route becomes/api/v1/systemone.src/proxy.tskeeps the blocked-client check on/api/v1/fim/completions./api/v1, and the blocked-client check also covers/api/v1/fim/completions. Theapps/webpaths behave as before, and both changes have tests.packages/web-sharedholds exactly what the app loads: the gateway handlers, the typesafe handler and their transitive dependencies (286 source files: 280 loaded at runtime and 6 type-only modules), their 169 colocated tests, and the next-auth and next-page ambient types.@/…import specifiers. Consumers resolve@/*to their ownsrc/*first and topackages/web-shared/src/*second. That fallback is applied in the web tsconfigs, the web Jest config, the@kilocode/trpcd.ts build, and the Storybook webpack alias.pnpm --filter @kilocode/web-shared typecheckusestsconfig.lib.json, which resolves@/*to web-shared only and excludes tests. This checks that web-shared runtime code never imports fromapps/web.apps/web, so pnpm links the samenext,next-authand@sentry/nextjsinstances. A secondnextinstance would breakheaders().apps/webJest config (rootsincludes web-shared), so CI'stestjob runs them.pnpm dev:start ai-gatewaystarts the app in its own opt-in group, on port 3010 plus the port offset. The app's dev script links the web app's env files and points app URLs at the web app.Verification
Both apps ran locally with
pnpm dev:start ai-gateway fake-llm. This was on this branch's code before its latest rebase ontomain; the rebase only added an unrelated cloud-agent-next commit frommain. The checks used a seeded user with credits, an API token, and an organization.Gateway API. I sent the same 20 requests to both apps:
apps/webon its existing paths andapps/ai-gatewayon/api/v1. Both apps passed all 20.fake-deterministicfake-deterministic)[DONE]and writes onemicrodollar_usagerowinvalid_path✅invalid_path✅kilo/7.1.0)model_not_found✅model_not_found✅A
next buildofapps/ai-gatewaylists exactly the 15/api/v1routes and the proxy.Web UI (
pnpm --filter web test:e2e, 89 chromium tests). I ran the suite on this branch and onmainunder the same conditions.auth.setupstep fails on bothmainand this branch, because.env.test's Stripe key is rejected during user creation. Both runs therefore used a verified fake-login session instead.main: 67 passed, 22 failed. The same 21 tests fail on both: 8 incloud-agent-sandbox-status, 9 inonboarding-wizard, 2 inapp-shell-accessibility, 1 inget-started-dashboard-linkand 1 inpages.visual. The only difference ispasskey.spec.ts, which passed on this branch and failed onmain.Visual Changes
N/A
Reviewer Notes
What the 577 changed files contain:
packages/web-sharedwithout changes@/path: 53 files that stay inapps/weband 9 moved filesllm-proxy.tsand its test,withBlockedClients.ts, and the OpenAI config scan testpnpm-lock.yamlapps/ai-gatewayapp, the web-shared manifest, tsconfigs andAGENTS.md, and awithBlockedClientstestReview commit by commit:
apps/web/src/…→packages/web-shared/src/…)./api/v1.dev:startwiring.Other notes:
apps/web/srcandpackages/web-shared/src. Otherwise theapps/webcopy silently shadows the web-shared one insideapps/web. This is documented inpackages/web-shared/AGENTS.md. Switching the moved code to@kilocode/web-shared/*specifiers would remove the fallback, but it would rewrite imports in about 2,000 web files, so it is left for a follow-up.apps/weblint rules..oxlintrc.jsonturns off the stricterpackages/**rules for it.lib/email.tsreads templates fromprocess.cwd()/src/emails, which exists only underapps/web, so emails sent from gateway code paths would fail there.