1
0

rpc-map.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * RPC method registry and signature-derived generics. Map keys are the wire
  3. * path segments of API Proxy unary calls.
  4. */
  5. import type { HostApi } from './host.ts'
  6. import type { AgentPresetsApi } from './agent-presets.ts'
  7. import type { SkillsApi } from './skills.ts'
  8. import type { SettingsApi } from './settings.ts'
  9. import type { CredentialsApi } from './credentials.ts'
  10. import type { LlmApi } from './llm.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; the carrier passes its request signal, never a wire field.
  16. */
  17. export interface RpcMethodMap {
  18. 'host.describe': HostApi['describe']
  19. 'host.pickDirectory': HostApi['pickDirectory']
  20. 'host.listDirectory': HostApi['listDirectory']
  21. 'host.createDirectory': HostApi['createDirectory']
  22. 'host.openPath': HostApi['openPath']
  23. 'skill.list': SkillsApi['list']
  24. 'agentPreset.openDocument': AgentPresetsApi['openDocument']
  25. 'settings.describe': SettingsApi['describe']
  26. 'settings.openDocument': SettingsApi['openDocument']
  27. 'settings.update': SettingsApi['update']
  28. 'settings.replace': SettingsApi['replace']
  29. 'settings.mutate': SettingsApi['mutate']
  30. 'credentials.describe': CredentialsApi['describe']
  31. 'credentials.set': CredentialsApi['set']
  32. 'credentials.unset': CredentialsApi['unset']
  33. 'llm.providers': LlmApi['providers']
  34. 'llm.models': LlmApi['models']
  35. 'llm.discoverModels': LlmApi['discoverModels']
  36. }
  37. /** Business request payload of method K (reaches through the RpcRequest narrow form to payload). */
  38. export type RequestPayload<K extends keyof RpcMethodMap> = Parameters<RpcMethodMap[K]>[0]['payload']
  39. /** Business return value of method K (reaches through the RpcResponse narrow form to infer the ok value of result). */
  40. export type ResponseValue<K extends keyof RpcMethodMap> =
  41. Awaited<ReturnType<RpcMethodMap[K]>> extends RpcResponse<infer T> ? T : never