rpc-map.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 { RpcResponse } from './rpc.ts'
  12. /**
  13. * Method name → method signature. Signatures are the single source of truth; payload/value
  14. * types are always derived from here. A method may declare a trailing AbortSignal after the
  15. * request (command.execute): the carrier passes its request signal, never a wire field.
  16. */
  17. export interface RpcMethodMap {
  18. 'session.list': SessionsApi['list']
  19. 'session.create': SessionsApi['create']
  20. 'session.history': SessionsApi['history']
  21. 'session.prompt': SessionsApi['prompt']
  22. 'session.cancel': SessionsApi['cancel']
  23. 'host.describe': HostApi['describe']
  24. 'host.pickDirectory': HostApi['pickDirectory']
  25. 'workspace.list': WorkspaceApi['list']
  26. 'workspace.create': WorkspaceApi['create']
  27. 'workspace.rename': WorkspaceApi['rename']
  28. 'workspace.delete': WorkspaceApi['delete']
  29. 'workspace.insertSessionBefore': WorkspaceApi['insertSessionBefore']
  30. 'command.list': CommandsApi['list']
  31. 'command.execute': CommandsApi['execute']
  32. 'skill.list': SkillsApi['list']
  33. }
  34. /** Business request payload of method K (reaches through the RpcRequest narrow form to payload). */
  35. export type RequestPayload<K extends keyof RpcMethodMap> = Parameters<RpcMethodMap[K]>[0]['payload']
  36. /** Business return value of method K (reaches through the RpcResponse narrow form to infer the ok value of result). */
  37. export type ResponseValue<K extends keyof RpcMethodMap> =
  38. Awaited<ReturnType<RpcMethodMap[K]>> extends RpcResponse<infer T> ? T : never