feat(01.1-06): add tRPC HTTP adapter and CLI client

- Create src/server/trpc-adapter.ts with fetch adapter for node:http
- Create src/cli/trpc-client.ts with typed client factory functions
- Update CoordinationServer to route /trpc/* to tRPC handler
- Move @trpc/client from devDeps to regular deps
- Keep /health and /status HTTP endpoints for backwards compatibility
This commit is contained in:
Lukas May
2026-01-30 14:07:31 +01:00
parent 5c07a4c4cf
commit 9da12a890d
4 changed files with 188 additions and 4 deletions

54
src/cli/trpc-client.ts Normal file
View File

@@ -0,0 +1,54 @@
/**
* tRPC Client for CLI
*
* Type-safe client for communicating with the coordination server.
* Uses httpBatchLink for efficient request batching.
*/
import { createTRPCClient, httpBatchLink } from '@trpc/client';
import type { AppRouter } from '../trpc/index.js';
/** Default server port */
const DEFAULT_PORT = 3847;
/** Default server host */
const DEFAULT_HOST = '127.0.0.1';
/**
* Type-safe tRPC client for the coordination server.
*/
export type TrpcClient = ReturnType<typeof createTRPCClient<AppRouter>>;
/**
* Creates a tRPC client for the coordination server.
*
* @param port - Server port (default: 3847)
* @param host - Server host (default: 127.0.0.1)
* @returns Type-safe tRPC client
*/
export function createTrpcClient(
port: number = DEFAULT_PORT,
host: string = DEFAULT_HOST
): TrpcClient {
return createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: `http://${host}:${port}/trpc`,
}),
],
});
}
/**
* Creates a tRPC client using environment variables or defaults.
*
* Uses CW_PORT and CW_HOST environment variables if available,
* falling back to defaults (127.0.0.1:3847).
*
* @returns Type-safe tRPC client
*/
export function createDefaultTrpcClient(): TrpcClient {
const port = process.env.CW_PORT ? parseInt(process.env.CW_PORT, 10) : DEFAULT_PORT;
const host = process.env.CW_HOST ?? DEFAULT_HOST;
return createTrpcClient(port, host);
}