mattrguerra/cortexmainPrivate on GitHub, published here in full

client.ts

Language TypeScript3.9 KB102 lines

src/ipc/client.ts

  1. // The interface to Rust. Components only ever see this, so the same app runs
  2. // against the real shell (tauri.ts) or in a plain browser on sample data
  3. // (mock/mockClient.ts), which is how the UI tests and screenshots run.
  4. import type { AppInfo } from './gen/AppInfo'
  5. import type { AttachmentMeta } from './gen/AttachmentMeta'
  6. import type { Conversation } from './gen/Conversation'
  7. import type { ConversationSummary } from './gen/ConversationSummary'
  8. import type { ConversationView } from './gen/ConversationView'
  9. import type { Estimate } from './gen/Estimate'
  10. import type { ExportResult } from './gen/ExportResult'
  11. import type { KeySaved } from './gen/KeySaved'
  12. import type { ModelsResponse } from './gen/ModelsResponse'
  13. import type { Preset } from './gen/Preset'
  14. import type { Provider } from './gen/Provider'
  15. import type { SaveSettingsResult } from './gen/SaveSettingsResult'
  16. import type { SearchHit } from './gen/SearchHit'
  17. import type { SendAck } from './gen/SendAck'
  18. import type { SendRequest } from './gen/SendRequest'
  19. import type { Settings } from './gen/Settings'
  20. import type { SpendSummary } from './gen/SpendSummary'
  21. import type { StreamEvent } from './gen/StreamEvent'
  22. import type { UsageReport } from './gen/UsageReport'
  23. export type AppEvent =
  24. | 'open-conversation'
  25. | 'new-chat'
  26. | 'open-settings'
  27. | 'conversations-changed'
  28. | 'models-updated'
  29. | 'settings-changed'
  30. | 'quick-shown'
  31. export interface EstimateArgs {
  32. conversationId: string | null
  33. providerId: string
  34. modelId: string
  35. text: string
  36. imageCount: number
  37. extraText?: string
  38. }
  39. export interface IpcClient {
  40. appInfo(): Promise<AppInfo>
  41. windowReady(): Promise<void>
  42. showMain(): Promise<void>
  43. listProviders(): Promise<Provider[]>
  44. saveProvider(provider: Provider): Promise<Provider>
  45. deleteProvider(id: string): Promise<void>
  46. setApiKey(providerId: string, key: string): Promise<KeySaved>
  47. clearApiKey(providerId: string): Promise<void>
  48. hasApiKey(providerId: string): Promise<boolean>
  49. listModels(providerId: string): Promise<ModelsResponse>
  50. refreshModels(providerId: string): Promise<ModelsResponse>
  51. listConversations(includeArchived: boolean): Promise<ConversationSummary[]>
  52. getConversation(id: string): Promise<ConversationView>
  53. createConversation(
  54. providerId: string,
  55. modelId: string,
  56. presetId: string | null,
  57. origin: 'main' | 'quick',
  58. ): Promise<Conversation>
  59. renameConversation(id: string, title: string): Promise<void>
  60. setPinned(id: string, pinned: boolean): Promise<void>
  61. setArchived(id: string, archived: boolean): Promise<void>
  62. deleteConversation(id: string): Promise<void>
  63. setConversationModel(id: string, providerId: string, modelId: string): Promise<void>
  64. setSystemPrompt(id: string, systemPrompt: string, presetId: string | null): Promise<void>
  65. sendMessage(req: SendRequest, onEvent: (e: StreamEvent) => void): Promise<SendAck>
  66. cancelStream(streamId: string): Promise<void>
  67. truncateFrom(conversationId: string, messageId: string): Promise<void>
  68. estimatePrompt(args: EstimateArgs): Promise<Estimate>
  69. search(query: string): Promise<SearchHit[]>
  70. spendSummary(): Promise<SpendSummary>
  71. usageReport(days: number | null): Promise<UsageReport>
  72. listPresets(): Promise<Preset[]>
  73. savePreset(preset: Preset): Promise<Preset>
  74. deletePreset(id: string): Promise<void>
  75. getSettings(): Promise<Settings>
  76. saveSettings(settings: Settings): Promise<SaveSettingsResult>
  77. pickAttachments(imagesAllowed: boolean): Promise<AttachmentMeta[]>
  78. attachBytes(filename: string, bytes: Uint8Array): Promise<AttachmentMeta>
  79. attachmentBytes(id: string): Promise<ArrayBuffer>
  80. discardAttachment(id: string): Promise<void>
  81. exportConversation(id: string): Promise<ExportResult>
  82. chooseVaultFolder(): Promise<string | null>
  83. quickOpenInMain(conversationId: string): Promise<void>
  84. hideQuick(): Promise<void>
  85. resizeQuick(height: number): Promise<void>
  86. openUrl(url: string): Promise<void>
  87. on(event: AppEvent, handler: (payload: unknown) => void): Promise<() => void>
  88. }