Termkit

tRPC router

A turnkey control-plane router in @mp-lb/termkit-trpc.

@mp-lb/termkit-trpc exposes the terminal control plane — list, kill, clear-bell — as a tRPC router, so the browser never talks to the daemon directly. It's optional: the React client's transport is just three functions, and you can wire them to any backend.

Usage

createTerminalRouter takes a TerminalDaemonClient and returns a router with list, kill, and seen procedures.

import { createTerminalClient } from '@mp-lb/termkit-server';
import { createTerminalRouter } from '@mp-lb/termkit-trpc';

const client = createTerminalClient({ port: 5179 });
export const terminalRouter = createTerminalRouter(client);
ProcedureKindInputReturns
listqueryLiveSession[]
killmutation{ sessionId: string }{ ok, error? }
seenmutation{ sessionId: string }{ ok, error? }

Mounting under your own context

The router is self-contained (its own initTRPC). To put it under your app's context or middleware, mount it as a sub-router:

const appRouter = t.router({
  terminal: createTerminalRouter(client),
  // ...your other routers
});

or copy the three procedure bodies into your own router and keep this as the reference contract.

Wiring the client transport

Whatever you mount it as, the browser side is the same shape the provider expects:

transport: {
  list: () => trpc.terminal.list.query(),
  kill: (sessionId) => trpc.terminal.kill.mutate({ sessionId }),
  seen: (sessionId) => trpc.terminal.seen.mutate({ sessionId }),
}

On this page