From d6fc9bd13e8a9c6d8ab7332173b6de8a984c2b64 Mon Sep 17 00:00:00 2001 From: "Timothy J. Aveni" Date: Thu, 25 Jun 2026 21:01:17 -0700 Subject: [PATCH] Add control RPC method registry --- src/index.ts | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/index.ts b/src/index.ts index 628b920..0a487bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,9 +30,33 @@ export const CONTROL_PLANE_ROUTES = { surfaceSession: "/surface-session", replEval: "/repl/eval", replClose: "/repl/close", + rpcSocket: "/rpc", browserSocket: "/ws", } as const; +export const CONTROL_PLANE_RPC_METHODS = { + run: "control.run", + status: "control.status", + check: "control.check", + cutover: "control.cutover", + clearState: "control.clearState", + describe: "control.describe", + logs: "control.logs", + errors: "control.errors", + devices: "control.devices", + deviceAssign: "control.device.assign", + deviceAssignLive: "control.device.assignLive", + deviceRename: "control.device.rename", + deviceIdentify: "control.device.identify", + deviceStopIdentify: "control.device.stopIdentify", + deviceRemove: "control.device.remove", + publicAuthGrant: "control.publicAuthGrant.create", + publicAuthGrantRevoke: "control.publicAuthGrant.revoke", + surfaceSession: "control.surfaceSession.create", + replEval: "control.repl.eval", + replClose: "control.repl.close", +} as const; + const nonEmptyString = z.string().min(1); const nullableString = z.string().nullable(); const optionalNullableStringAsNull = z @@ -656,6 +680,55 @@ export const ControlPlaneCutoverResponseSchema = z.object({ packages: z.array(ControlPlaneRunningPackageSchema), }); +export const ControlPlaneRpcMethodParamsSchemas = { + [CONTROL_PLANE_RPC_METHODS.run]: ControlPlaneRunRequestSchema, + [CONTROL_PLANE_RPC_METHODS.status]: z.object({}).optional(), + [CONTROL_PLANE_RPC_METHODS.check]: ControlPlaneCheckRequestSchema, + [CONTROL_PLANE_RPC_METHODS.cutover]: ControlPlaneCutoverRequestSchema, + [CONTROL_PLANE_RPC_METHODS.clearState]: ControlPlaneClearStateRequestSchema, + [CONTROL_PLANE_RPC_METHODS.describe]: ControlPlaneDescribeRequestSchema, + [CONTROL_PLANE_RPC_METHODS.logs]: ControlPlaneLogsRequestSchema, + [CONTROL_PLANE_RPC_METHODS.errors]: ControlPlaneErrorsRequestSchema, + [CONTROL_PLANE_RPC_METHODS.devices]: z.object({}).optional(), + [CONTROL_PLANE_RPC_METHODS.deviceAssign]: + ControlPlaneDeviceAssignRequestSchema, + [CONTROL_PLANE_RPC_METHODS.deviceAssignLive]: + ControlPlaneDeviceAssignRequestSchema, + [CONTROL_PLANE_RPC_METHODS.deviceRename]: + ControlPlaneDeviceRenameRequestSchema, + [CONTROL_PLANE_RPC_METHODS.deviceIdentify]: + ControlPlaneDeviceIdentifyRequestSchema, + [CONTROL_PLANE_RPC_METHODS.deviceStopIdentify]: + ControlPlaneDeviceRemoveRequestSchema, + [CONTROL_PLANE_RPC_METHODS.deviceRemove]: + ControlPlaneDeviceRemoveRequestSchema, + [CONTROL_PLANE_RPC_METHODS.publicAuthGrant]: + ControlPlanePublicAuthGrantRequestSchema, + [CONTROL_PLANE_RPC_METHODS.publicAuthGrantRevoke]: + ControlPlanePublicAuthGrantRevokeRequestSchema, + [CONTROL_PLANE_RPC_METHODS.surfaceSession]: + ControlPlaneSurfaceSessionRequestSchema, + [CONTROL_PLANE_RPC_METHODS.replEval]: ControlPlaneReplEvalRequestSchema, + [CONTROL_PLANE_RPC_METHODS.replClose]: ControlPlaneReplCloseRequestSchema, +} as const; + +export type ControlPlaneRpcMethod = + (typeof CONTROL_PLANE_RPC_METHODS)[keyof typeof CONTROL_PLANE_RPC_METHODS]; + +export const parseControlPlaneRpcParams = ( + method: string, + params: unknown, +) => { + const schema = + ControlPlaneRpcMethodParamsSchemas[ + method as keyof typeof ControlPlaneRpcMethodParamsSchemas + ]; + if (!schema) { + return null; + } + return parseWith(schema, params ?? {}); +}; + export type ControlPlaneRunRequest = { target: string; };