rpc-map.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * RPC method registry and signature-derived generics. The map
  3. * registers only client-request methods (respond is a client-response, so it is absent);
  4. * map keys are the wire path segments (POST /api/session.list).
  5. */
  6. import type { SessionsApi } from './sessions.ts'
  7. import type { HostApi } from './host.ts'
  8. import type { WorkspaceApi } from './workspace.ts'
  9. import type { CommandsApi } from './commands.ts'
  10. import type { SkillsApi } from './skills.ts'
  11. import type { GoalsApi } from './goals.ts'
  12. import type { RpcResponse } from './rpc.ts'
  13. /**
  14. * Method name → method signature. Signatures are the single source of truth; payload/value
  15. * types are always derived from here. A method may declare a trailing AbortSignal after the
  16. * request (command.execute): the carrier passes its request signal, never a wire field.
  17. */
  18. export interface RpcMethodMap {
  19. 'session.list': SessionsApi['list']
  20. 'session.create': SessionsApi['create']
  21. 'session.history': SessionsApi['history']
  22. 'session.models': SessionsApi['models']
  23. 'session.selectModel': SessionsApi['selectModel']
  24. 'session.prompt': SessionsApi['prompt']
  25. 'session.cancel': SessionsApi['cancel']
  26. 'host.describe': HostApi['describe']
  27. 'host.pickDirectory': HostApi['pickDirectory']
  28. 'host.openPath': HostApi['openPath']
  29. 'workspace.list': WorkspaceApi['list']
  30. 'workspace.create': WorkspaceApi['create']
  31. 'workspace.rename': WorkspaceApi['rename']
  32. 'workspace.delete': WorkspaceApi['delete']
  33. 'workspace.insertSessionBefore': WorkspaceApi['insertSessionBefore']
  34. 'command.list': CommandsApi['list']
  35. 'command.execute': CommandsApi['execute']
  36. 'skill.list': SkillsApi['list']
  37. 'goal.create': GoalsApi['create']
  38. 'goal.edit': GoalsApi['edit']
  39. 'goal.pause': GoalsApi['pause']
  40. 'goal.resume': GoalsApi['resume']
  41. 'goal.complete': GoalsApi['complete']
  42. 'goal.clear': GoalsApi['clear']
  43. }
  44. /** Business request payload of method K (reaches through the RpcRequest narrow form to payload). */
  45. export type RequestPayload<K extends keyof RpcMethodMap> = Parameters<RpcMethodMap[K]>[0]['payload']
  46. /** Business return value of method K (reaches through the RpcResponse narrow form to infer the ok value of result). */
  47. export type ResponseValue<K extends keyof RpcMethodMap> =
  48. Awaited<ReturnType<RpcMethodMap[K]>> extends RpcResponse<infer T> ? T : never