Skip to content

feat(gateway): add enterprise account, modes, notifications, media, and FIM RPCs - #15072

Merged
marius-kilocode merged 23 commits into
v2from
gateway-account-rpc
Oct 16, 2026
Merged

marius-kilocode merged 23 commits into
v2from
gateway-account-rpc

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

Stacked on #15067.
Part of #14991 (and #13750), PR 4 of the Gateway series. Plan units U-E1-03 (balance, Kilo Pass, BYOK, coding plans, modes, notifications), U-E1-08 (Gateway client RPC contract), and U-E6-08 (FIM and Next Edit routing).

What Problem This Solves

In PR 3 (#15067), the kilocode.gateway RPC surface exposed profile, organization.set, models, and session.metadata, while IDE and TUI clients also need the remaining v1 Gateway endpoints for account balance, Kilo Pass state, BYOK entries, coding plans and quota windows, organization custom modes, user notifications, image and transcription model catalogs, and FIM / Next Edit endpoint routing.

Why This Change Was Made

Following the architecture in #14991 and #15060:

  1. Enterprise account, tRPC, modes, notifications, media, and FIM/edit modules in packages/kilo-gateway-core:
    • KiloProfile.balance (src/profile.ts): fetches GET /api/profile/balance with x-kilocode-organizationid when a team is active.
    • KiloTrpc (src/trpc.ts): size-capped (512 KiB), timeout-bounded (5s) tRPC query client for kiloPass.getState (filtering to live statuses active, past_due, trialing), byok.list, codingPlans.listSubscriptions, and codingPlans.getUsage (validating unique quota windows and matching subscription ID).
    • KiloModes (src/modes.ts): fetches GET /api/organizations/{id}/modes with a 5-minute per-organization cache (clearCache() on team switch).
    • KiloNotifications (src/notifications.ts): fetches GET /api/users/notifications with Kilo attribution headers.
    • KiloModels.imageModels and KiloModels.transcriptionModels (src/models.ts): fetches image-capable models (output_modalities includes "image") and transcription models (GET /api/gateway/transcription-models).
    • KiloAutocomplete (src/autocomplete.ts): ports AUTOCOMPLETE_MODELS, getAutocompleteModel, resolveFimTarget (/api/fim/completions, Mistral, Inception), resolveEditTarget (/api/edit/completions, Inception), extractFencedBody, and requestMistralFim.
  2. Expanded kilocode.gateway RPC surface (packages/core/src/kilocode/gateway-rpc.ts, gateway.ts):
    • Adds authStatus, balance, kiloPass, byok, codingPlans, codingPlanUsage, modes, notifications, models.images, models.transcriptions, autocomplete.fimTarget, and autocomplete.editTarget.
  3. TUI /kilo-account command (packages/tui/src/kilocode/gateway.tsx):
    • Adds /kilo-account (aliases /balance, /kilo-pass) to display the active Kilo Gateway account email, personal/team scope, balance, Kilo Pass usage, and organization custom modes.

Shared upstream files changed

None in this PR (all changes are in Kilo-owned paths packages/kilo-gateway-core/**, packages/core/**/kilocode/**, and packages/tui/**/kilocode/**).

User Impact

  • /kilo-account (/balance, /kilo-pass) displays the signed-in account, active team scope, credit balance, Kilo Pass usage, and team modes in the TUI.
  • TUI, VS Code, and JetBrains clients can query authStatus, balance, kiloPass, byok, codingPlans, codingPlanUsage, modes, notifications, models.images, models.transcriptions, autocomplete.fimTarget, and autocomplete.editTarget over the typed kilocode.gateway RPC surface.

Evidence

Automated checks

  • bun script/check-opencode-annotations.ts: ok (39 shared files against 4d9678a79d6)
  • bun script/check-shared-patches.ts: ok (0 new shared upstream files touched)
  • bun run --cwd packages/kilo-gateway-core typecheck && bun run --cwd packages/kilo-gateway-core build: pass
  • bun run --cwd packages/core typecheck: pass
  • bun run --cwd packages/tui typecheck: pass
  • bun test --cwd packages/kilo-gateway-core: 36 pass, 0 fail (123 assertions)
  • bun test --cwd packages/core test/kilocode/gateway.test.ts test/plugin/provider-kilo.test.ts: 14 pass, 0 fail (72 assertions)
  • bun test --cwd packages/tui test/kilocode/gateway.test.ts: 2 pass, 0 fail (4 assertions)

TUI Self-Test

  1. Signed-out /kilo-account dialog:

Signed-out /kilo-account dialog in TUI

  1. Signed-in /kilo-account dialog (showing account email, team scope, balance, Kilo Pass, and team modes):

Signed-in /kilo-account dialog in TUI

@github-actions github-actions Bot added area:cli CLI, TUI and core engine area:gateway Kilo Gateway and auth labels Oct 14, 2026
Comment thread packages/kilo-gateway-core/src/trpc.ts Outdated
Comment thread packages/kilo-gateway-core/src/trpc.ts
Comment thread packages/kilo-gateway-core/src/autocomplete.ts
Comment thread packages/kilo-gateway-core/src/autocomplete.ts Outdated
Comment thread packages/kilo-gateway-core/src/autocomplete.ts
@kilo-code-bot

kilo-code-bot Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Incremental pass over the changes since 13a0e8564e (the follow-up commit 364c3fa1a9). The commit aligns resolveEditTarget's non-edit fallback to return url: "", matching the documented v1 behavior (v1 packages/kilo-gateway/src/edit.ts: "Non-edit models fall through to a kilo placeholder with no URL so the handler can surface a 400 rather than silently routing somewhere unexpected"), guarded and now covered by a new assertion. It also adds the personal-scope 401 → anonymous retry to imageModels, mirroring the existing get path (the retry drops token, so recursion is bounded), and threads an optional profile name through the RPC schema, the gateway RPC handler, and the TUI /profile dialog consistent with KiloProfile.get. No new defects found; the four prior findings on trpc.ts and autocomplete.ts were re-checked and are now addressed in code (redirect: "error", kiloPass body cancel, FIM first.body cancel, CRLF normalization).

Files Reviewed (7 files)
  • packages/core/src/kilocode/gateway-rpc.ts
  • packages/core/src/kilocode/gateway.ts
  • packages/core/test/kilocode/gateway.test.ts
  • packages/kilo-gateway-core/src/autocomplete.ts
  • packages/kilo-gateway-core/src/models.ts
  • packages/kilo-gateway-core/test/enterprise-rpc.test.ts
  • packages/tui/src/kilocode/gateway.tsx
Previous Review Summaries (4 snapshots, latest commit 13a0e85)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 13a0e85)

Status: No Issues Found | Recommendation: Merge

Incremental pass over the changes since aa5fc7539d. The Gateway URL helper consolidation (KiloServer.apiUrl / organizationFromUrl / isConfiguredBase / gateway / modelsUrl), the tightened token regex, token-embedded organization resolution, the test-runner live-request guard, the /profile (with me/whoami aliases) TUI command rename, and the BUN_OPTIONS preload handoff in script/dev-isolated.ts are consistent with the previous findings and introduce no new defects. Previously flagged items were re-checked and remain addressed:

  • autocomplete.ts CRLF handling, requestMistralFim first-body drain, and extractFencedBody fenced-body parsing.
  • trpc.ts kiloPass redirect/redirect: "error" and non-OK body cancel.
Files Reviewed (12 files)
  • migration-tracking/plans/kilo-gateway-v2-plan.md
  • packages/cli/test/kilocode/dev-isolated.test.ts
  • packages/core/src/kilocode/gateway.ts
  • packages/kilo-gateway-core/src/account.ts
  • packages/kilo-gateway-core/src/defaults.ts
  • packages/kilo-gateway-core/src/device.ts
  • packages/kilo-gateway-core/src/models.ts
  • packages/kilo-gateway-core/src/profile.ts
  • packages/kilo-gateway-core/src/server.ts
  • packages/kilo-gateway-core/test/account.test.ts
  • packages/tui/src/kilocode/gateway.tsx
  • script/dev-isolated.ts

Previous review (commit aa5fc75)

Status: No Issues Found | Recommendation: Merge

The five findings from the prior review remain resolved at aa5fc7539d. This incremental pass reviewed the AI Gateway URL sync (KiloServer.gateway / modelsUrl / aiGatewayFromEnv), the removal of the unused prompt catalog field, and the catalog retry/reload updates; no new issues found.

Files Reviewed (10 files)
  • packages/core/src/kilocode/gateway-rpc.ts
  • packages/core/src/kilocode/gateway.ts
  • packages/core/test/kilocode/gateway.test.ts
  • packages/kilo-gateway-core/src/autocomplete.ts
  • packages/kilo-gateway-core/src/models.ts
  • packages/kilo-gateway-core/src/server.ts
  • packages/kilo-gateway-core/src/testing.ts
  • packages/kilo-gateway-core/test/account.test.ts
  • packages/kilo-gateway-core/test/enterprise-rpc.test.ts
  • packages/kilo-gateway-core/test/models.test.ts

Previous review (commit 8ee1830)

Status: No Issues Found | Recommendation: Merge

All five findings from the previous review are resolved at commit 8ee18308d9:

  • trpc.ts kiloPass now cancels the failed response body and sets redirect: "error".
  • autocomplete.ts requestMistralFim cancels the discarded first response body before retrying.
  • autocomplete.ts resolveEditTarget no longer returns an empty URL.
  • autocomplete.ts extractFencedBody normalizes CRLF before parsing.
Files Reviewed (2 files)
  • packages/kilo-gateway-core/src/autocomplete.ts
  • packages/kilo-gateway-core/src/trpc.ts

Previous review (commit d70a90f)

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 4
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-gateway-core/src/trpc.ts 115 kiloPass returns on a non-OK response without consuming/cancelling response.body, leaving the error body and pooled socket unread until GC (unlike query, which always drains via readBounded).
packages/kilo-gateway-core/src/autocomplete.ts 191 requestMistralFim drops the first response without cancelling its body on a 401/403 before retrying, pinning the connection until GC on a high-frequency path.
packages/kilo-gateway-core/src/autocomplete.ts 164 resolveEditTarget falls back to url: "" for a non-edit model; the empty string satisfies the required EditTarget.url schema and is handed to clients, producing an unusable request.
packages/kilo-gateway-core/src/autocomplete.ts 178 extractFencedBody does not handle CRLF: the closing <|/code_to_edit|> marker and stray \r survive, corrupting the extracted edit body.

SUGGESTION

File Line Issue
packages/kilo-gateway-core/src/trpc.ts 107 kiloPass omits redirect: "error" that query sets, so it follows redirects while carrying the Authorization header. Align for consistent behavior.
Files Reviewed (13 files)
  • packages/core/src/kilocode/gateway-rpc.ts - no issues
  • packages/core/src/kilocode/gateway.ts - no issues
  • packages/core/test/kilocode/gateway.test.ts - no issues
  • packages/kilo-gateway-core/src/autocomplete.ts - 3 issues
  • packages/kilo-gateway-core/src/index.ts - no issues
  • packages/kilo-gateway-core/src/models.ts - no issues
  • packages/kilo-gateway-core/src/modes.ts - no issues
  • packages/kilo-gateway-core/src/notifications.ts - no issues
  • packages/kilo-gateway-core/src/profile.ts - no issues
  • packages/kilo-gateway-core/src/testing.ts - no issues
  • packages/kilo-gateway-core/src/trpc.ts - 2 issues
  • packages/kilo-gateway-core/test/enterprise-rpc.test.ts - no issues
  • packages/tui/src/kilocode/gateway.tsx - no issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 60.4K · Output: 14.4K · Cached: 708.4K

Base automatically changed from gateway-requests-errors to gateway-login-v2 October 15, 2026 13:43
Base automatically changed from gateway-login-v2 to v2 October 15, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli CLI, TUI and core engine area:gateway Kilo Gateway and auth

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants