Skip to content

feat(api): proxy STREAMS_URL through API for desktop - #1386

Merged
Kitenite merged 1 commit into
mainfrom
kitenite/desktop-app-stream-url
Feb 11, 2026
Merged

Kitenite merged 1 commit into
mainfrom
kitenite/desktop-app-stream-url

Conversation

@Kitenite

@Kitenite Kitenite commented Feb 11, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Route desktop streams traffic through the API (/api/streams/...) instead of connecting directly to the streams server
  • Eliminates the need to bundle STREAMS_URL in desktop builds — the streams server URL can now be updated without shipping a new desktop release
  • Follows the same proxy pattern already used by Electric SQL (/api/electric/v1/shape)

Changes

API (apps/api)

  • Added STREAMS_URL to API env schema (env.ts)
  • Created catch-all proxy route at api/streams/[...path]/route.ts — authenticates via session, forwards allowlisted headers, streams request/response bodies, sets maxDuration = 300 for long-lived connections

Desktop (apps/desktop)

  • Updated getConfig and session-manager to use ${NEXT_PUBLIC_API_URL}/api/streams instead of STREAMS_URL
  • Removed STREAMS_URL from env.main.ts, CSP in index.html, htmlEnvTransformPlugin, and Vite define config

CI & Build

  • Removed STREAMS_URL from build-desktop.yml, ci.yml, deploy-preview.yml workflows
  • Removed STREAMS_URL from turbo.jsonc globalEnv

Test Plan

  • bun run typecheck — passes (18/18 packages)
  • bun run lint:fix — passes, no fixes needed
  • bun test — passes (1224 pass, 0 fail)
  • bunx sherif --fix — no issues found
  • Local dev: start API + streams server, verify desktop chat connects through localhost:3001/api/streams/v1/...
  • Verify session creation, message sending, streaming, and stop all work through the proxy

Summary by CodeRabbit

  • New Features

    • Added a Streams proxy endpoint on the main API to enable authenticated streaming requests (GET/POST/PUT/DELETE) with preserved upstream responses.
  • Chores

    • Switched desktop clients to route Streams traffic through the main API instead of a separate STREAMS_URL.
    • Removed STREAMS_URL from build/deploy configs and desktop CSP/placeholders.

@coderabbitai

coderabbitai Bot commented Feb 11, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

Adds a server-side proxy route at /api/streams, introduces STREAMS_URL to the API server env, and removes direct STREAMS_URL exposure from desktop configs, build workflows, CSP, and helper replacements; desktop code now routes via NEXT_PUBLIC_API_URL/api/streams.

Changes

Cohort / File(s) Summary
GitHub Actions workflows
.github/workflows/build-desktop.yml, .github/workflows/ci.yml, .github/workflows/deploy-preview.yml
Removed STREAMS_URL environment variable from workflow steps and top-level env.
API proxy route
apps/api/src/app/api/streams/[...path]/route.ts
New proxy route that authenticates, rewrites /api/streams/* to upstream STREAMS_URL, filters forwarded headers, supports GET/POST/PUT/DELETE, and exports maxDuration.
API environment schema
apps/api/src/env.ts
Added STREAMS_URL as a validated URL in server.shared env schema.
Desktop build/config removal
apps/desktop/electron.vite.config.ts, apps/desktop/src/main/env.main.ts, turbo.jsonc
Removed STREAMS_URL from Vite define bindings, desktop server schema/runtimeEnv, and turbo globalEnv.
Desktop client proxy updates
apps/desktop/src/lib/trpc/routers/ai-chat/index.ts, apps/desktop/src/lib/trpc/routers/ai-chat/utils/session-manager/session-manager.ts
Replaced direct env.STREAMS_URL usage with ${env.NEXT_PUBLIC_API_URL}/api/streams for proxy URL construction.
Renderer CSP & HTML helpers
apps/desktop/src/renderer/index.html, apps/desktop/vite/helpers.ts
Removed %STREAMS_URL% from CSP connect-src and removed STREAMS_URL placeholder replacement in HTML transform plugin.

Sequence Diagram

sequenceDiagram
    participant Desktop as Desktop Client
    participant APIServer as API Server (/api/streams)
    participant StreamsSvc as Upstream Streams Service

    Desktop->>APIServer: Request to /api/streams/...
    APIServer->>APIServer: Validate session (Superset)
    APIServer->>APIServer: Filter headers, rewrite path
    APIServer->>StreamsSvc: Forward request to env.STREAMS_URL
    StreamsSvc-->>APIServer: Response (status, headers, body)
    APIServer-->>Desktop: Proxy response (preserve status, headers, body)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • saddlepaddle

Poem

🐰 I hopped from dev to code so neat,
Routed streams through a servered seat,
No env exposed to roam—
Now traffic finds its home,
Hop, patch, deploy — a tiny feat! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: routing STREAMS_URL traffic through the API for desktop, which is the core architectural change in this PR.
Description check ✅ Passed The PR description includes all required template sections with comprehensive details: Summary, Changes (organized by component), and Test Plan with both automated and manual testing steps.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kitenite/desktop-app-stream-url

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Feb 11, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Preview Deployment

🔗 Preview Links

Service Status Link
Neon Database (Neon) ✅ View Branch
Fly.io Electric (Fly.io) ✅ View App
Fly.io Streams (Fly.io) ✅ View App
Vercel API (Vercel) ❌ Failed to deploy
Vercel Web (Vercel) ❌ Failed to deploy
Vercel Marketing (Vercel) ❌ Failed to deploy
Vercel Admin (Vercel) ❌ Failed to deploy
Vercel Docs (Vercel) ❌ Failed to deploy

Preview updates automatically with new commits

Route desktop streams traffic through the API (`/api/streams/...`) instead
of connecting directly to the streams server. This eliminates the need to
bundle STREAMS_URL in desktop builds, allowing the streams server URL to
be updated without shipping a new desktop release.

This branch had an error being deployed

1 failed deployment
preview — 597b5c28 Deployed Feb 11, 2026 by Kitenite via Deploy Admin #1798
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