Skip to content

TW-5722: add JSON-RPC server over WebSocket exposing the CLI surface#114

Merged
qasim-nylas merged 2 commits into
mainfrom
feature/TW-5722-rpc-server
Jun 26, 2026
Merged

TW-5722: add JSON-RPC server over WebSocket exposing the CLI surface#114
qasim-nylas merged 2 commits into
mainfrom
feature/TW-5722-rpc-server

Conversation

@qasim-nylas

Copy link
Copy Markdown
Collaborator

Summary

Adds nylas rpc serve — a JSON-RPC 2.0 server over WebSocket that exposes the Nylas CLI surface to a thin client / future GUI. It is implemented as a second inbound adapter (alongside the Cobra CLI) over the existing ports.*Client interfaces, so it reuses the same adapters, grant resolution, and validation rather than duplicating logic.

Scope is data operations: email, calendar/events, contacts, threads, drafts, agent accounts, scheduler, notetaker, admin, and API auth-grant ops. Interactive login and local-session commands stay CLI-only.

What's included

  • JSON-RPC core — request/response + notification framing, dispatcher with -32xxx error mapping (no internal detail leaked), per-grant resolution falling back to the default grant.
  • Full coverage for email, calendar/events, contacts, and auth grant ops, including folders, attachments (download capped at 30 MiB), signatures, scheduled sends, free/busy, availability, recurring instances, room resources, and virtual-calendar grants.
  • Incremental pollers (messages, threads, events, contacts) emitting change notifications.
  • Tests — unit tests per handler group (fakes over the port interfaces) plus an integration suite that launches the real nylas rpc serve binary over WebSocket: a read-only smoke test plus protocol/notification/read/write coverage.
  • Docsdocs/RPC.md documents the method surface.

Also corrects the agent rule assign_to_folder hint and docs: the value is now a folder name (UUID folder IDs no longer resolve), matching the API change documented in nylas/developer.nylas.com#630.

Testing

  • make ci — green (fmt, vet, lint, unit, race, security, vuln, build)
  • RPC integration suite run live against a real grant — all functions pass
  • internal/cli/agent build/vet/lint/tests green after the assign_to_folder change

Related docs

Add `nylas rpc serve` — a JSON-RPC 2.0 server over WebSocket exposing the
CLI surface (email, calendar, contacts, threads, drafts, agent accounts,
scheduler, notetaker, admin, auth grant ops) as a second inbound adapter
over the existing ports.*Client interfaces.

- Full CRUD parity for email, calendar/events, contacts, and API grant ops;
  folders, attachments, signatures, scheduled sends, free/busy, availability,
  recurring instances, room resources, and virtual-calendar grants
- Attachment download capped at 30 MiB; per-grant resolution with default grant
- Incremental pollers (messages, threads, events, contacts) with notifications
- Integration suite launches the real binary over WebSocket (read-only smoke +
  protocol/notification/read/write coverage)
- docs/RPC.md documents the method surface

Also correct the agent rule `assign_to_folder` hint and docs: the value is now
a folder name (UUID folder IDs no longer resolve), matching the API change in
developer.nylas.com#630.
@qasim-nylas qasim-nylas requested a review from AaronDDM June 26, 2026 12:22
…Config

Poll intervals were hardcoded (5s/30s focused/idle, 60s contacts). Make them
configurable at startup via env vars and live over RPC:

- NYLAS_WS_POLL_FAST / _IDLE / _CONTACTS seed the intervals (invalid or
  non-positive values fall back to the previous defaults).
- New client.pollConfig request method updates the live intervals (optional
  Go-duration fields; omitted fields unchanged) and returns the effective
  values; takes effect on the next poll cycle, no restart.

Contacts now run through RunAdaptive on their own controller, unifying all four
pollers on one driver. That retired the dead MessagePoller.Run / ThreadPoller.Run
/ ContactPoller.Run / runTicker (only ContactPoller.Run was ever wired), along
with their tests.

Docs: documented the env vars and client.pollConfig in docs/RPC.md.

@AaronDDM AaronDDM left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 👍

@qasim-nylas qasim-nylas merged commit 11c4c0c into main Jun 26, 2026
7 checks passed
@qasim-nylas qasim-nylas deleted the feature/TW-5722-rpc-server branch June 26, 2026 13:53
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.

2 participants