refactor(simulation): type frontend RPC methods

This commit is contained in:
James Long 2026-07-07 12:42:20 +00:00
commit e9c5164e4d
2 changed files with 5 additions and 2 deletions

View file

@ -16,7 +16,7 @@ function parseRequest(input: string | Buffer) {
}
async function handle(harness: Harness, request: SimulationProtocol.JsonRpc.Request, headless: boolean) {
switch (request.method) {
switch (SimulationProtocol.Frontend.decodeMethod(request.method)) {
case "ui.state": {
if (headless) await harness.renderOnce()
const result = SimulationActions.state(harness)
@ -33,7 +33,6 @@ async function handle(harness: Harness, request: SimulationProtocol.JsonRpc.Requ
case "trace.export":
return SimulationTrace.exportTrace()
}
throw new Error(`Unknown simulation method: ${request.method}`)
}
export function start(harness: Harness, endpoint: string, headless: boolean): Server {

View file

@ -46,6 +46,10 @@ export namespace JsonRpc {
}
export namespace Frontend {
export const Method = Schema.Literals(["ui.state", "ui.action", "trace.list", "trace.clear", "trace.export"])
export type Method = Schema.Schema.Type<typeof Method>
export const decodeMethod = Schema.decodeUnknownSync(Method)
export const KeyModifiers = Schema.Struct({
ctrl: Schema.optional(Schema.Boolean),
shift: Schema.optional(Schema.Boolean),