refactor(simulation): type backend RPC methods
This commit is contained in:
parent
e9c5164e4d
commit
adabb01caf
2 changed files with 12 additions and 2 deletions
|
|
@ -29,7 +29,7 @@ function parseRequest(input: string | Buffer) {
|
|||
}
|
||||
|
||||
async function handle(socket: ControlSocket, request: SimulationProtocol.JsonRpc.Request): Promise<unknown> {
|
||||
switch (request.method) {
|
||||
switch (SimulationProtocol.Backend.decodeMethod(request.method)) {
|
||||
case "llm.attach": {
|
||||
socket.data.unsubscribe?.()
|
||||
socket.data.unsubscribe = SimulationLLMExchange.subscribe((exchange) => {
|
||||
|
|
@ -62,7 +62,6 @@ async function handle(socket: ControlSocket, request: SimulationProtocol.JsonRpc
|
|||
case "network.log":
|
||||
return { entries: SimulationNetwork.log() }
|
||||
}
|
||||
throw new Error(`Unknown simulation control method: ${request.method}`)
|
||||
}
|
||||
|
||||
export function start(endpoint: string) {
|
||||
|
|
|
|||
|
|
@ -111,6 +111,17 @@ export namespace Frontend {
|
|||
}
|
||||
|
||||
export namespace Backend {
|
||||
export const Method = Schema.Literals([
|
||||
"llm.attach",
|
||||
"llm.chunk",
|
||||
"llm.finish",
|
||||
"llm.disconnect",
|
||||
"llm.pending",
|
||||
"network.log",
|
||||
])
|
||||
export type Method = Schema.Schema.Type<typeof Method>
|
||||
export const decodeMethod = Schema.decodeUnknownSync(Method)
|
||||
|
||||
export const Item = Schema.Union([
|
||||
Schema.Struct({ type: Schema.Literal("textDelta"), text: Schema.String }),
|
||||
Schema.Struct({ type: Schema.Literal("reasoningDelta"), text: Schema.String }),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue