Skip to content
pawaca edited this page Aug 30, 2026 · 1 revision

Typert

Edge adaptation of the upstream typed Remote call system.

Upstream reference: Typert

What Upstream Provides

Typert is a type-safe RPC framework that auto-generates endpoint descriptors from TypeScript service method signatures. It has three layers:

  • TypertRegistry (ctx.typert) — manages generated schemas, package reflection, lookup providers, and context providers.
  • TypertGatewayService (ctx.typertGateway) — host-side dispatcher. Resolves strict generated definitions or SRC (Source Reflection Convention) markers against current cordis Services, validates parameters, and invokes the business method.
  • Client Remote (ctx.remote) — browser-side consumer. Mounts generated descriptors as typed methods, sends RPC via connection.rpc.call('/api', endpoint, ...).

Services like GoalService inherit from TypertRemoteService and use @Remote decorators to mark methods. The gateway discovers them automatically via SRC reflection — no manual routing needed.

What Edge Changed

Direct Reuse Registry and Gateway

TypertRegistry and TypertGatewayService are installed as-is. SRC reflection, lookup resolution, parameter validation, and codec handling are entirely upstream code.

Transport Bridge HTTP routing

Upstream uses Connection.rpc.intercept('/api', ...) to register the gateway on the webserver's composite handler. Edge has no Connection service. Instead, handleTypertRpc() in instance.ts (~20 lines) intercepts /api/{namespace}/{method} URLs via regex, extracts args from the request body, calls gateway.invoke(), and wraps the result as a ServerResponse.

What Edge Did NOT Change

  • SRC reflection and strict descriptor resolution
  • Lookup and context provider registration
  • Parameter validation and codec handling
  • Error classification (TypertGatewayError codes)
  • Client-side ctx.remote behavior (all handled by upstream client plugins)

Performance Characteristics

RPC dispatch latency

Request path: HTTP POST → regex match → JSON parse → gateway.invoke() → SRC reflection → method call → response. SRC scans all cordis services once per endpoint and caches the result. Subsequent calls to the same endpoint skip discovery. The business method itself (e.g., GoalService.edit()) is synchronous. Typical DO-internal round-trip: single-digit milliseconds.

Endpoint coverage

Any cordis Service with @Remote-decorated methods is automatically routable — no per-service Edge code needed. Currently covers goals (6 methods). Future services (skills, message-feedback, etc.) get routing for free.

Architecture Summary

Component Category Edge Code
TypertRegistry Reuse One ctx.plugin() call
TypertGatewayService Reuse One ctx.plugin() call
HTTP routing Bridge handleTypertRpc() (~20 lines)
Client Remote Reuse Upstream client plugins

Key observation: Edge's Typert adaptation is a ~20-line transport bridge that translates HTTP POST into gateway.invoke(). Everything else — discovery, validation, dispatch, error handling — is upstream code. Adding a new @Remote service requires zero Edge changes.

English

中文

Clone this wiki locally