WebviewMessage.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { z } from "zod"
  2. import { ApiConfiguration, ApiProvider } from "./api"
  3. import { Mode, PromptComponent, ModeConfig } from "./modes"
  4. export type ClineAskResponse = "yesButtonClicked" | "noButtonClicked" | "messageResponse"
  5. export type PromptMode = Mode | "enhance"
  6. export type AudioType = "notification" | "celebration" | "progress_loop"
  7. export interface WebviewMessage {
  8. type:
  9. | "apiConfiguration"
  10. | "currentApiConfigName"
  11. | "saveApiConfiguration"
  12. | "upsertApiConfiguration"
  13. | "deleteApiConfiguration"
  14. | "loadApiConfiguration"
  15. | "renameApiConfiguration"
  16. | "getListApiConfiguration"
  17. | "customInstructions"
  18. | "allowedCommands"
  19. | "alwaysAllowReadOnly"
  20. | "alwaysAllowWrite"
  21. | "alwaysAllowExecute"
  22. | "webviewDidLaunch"
  23. | "newTask"
  24. | "askResponse"
  25. | "clearTask"
  26. | "didShowAnnouncement"
  27. | "selectImages"
  28. | "exportCurrentTask"
  29. | "showTaskWithId"
  30. | "deleteTaskWithId"
  31. | "exportTaskWithId"
  32. | "resetState"
  33. | "requestOllamaModels"
  34. | "requestLmStudioModels"
  35. | "openImage"
  36. | "openFile"
  37. | "openMention"
  38. | "cancelTask"
  39. | "refreshOpenRouterModels"
  40. | "refreshGlamaModels"
  41. | "refreshUnboundModels"
  42. | "refreshRequestyModels"
  43. | "refreshOpenAiModels"
  44. | "alwaysAllowBrowser"
  45. | "alwaysAllowMcp"
  46. | "alwaysAllowModeSwitch"
  47. | "playSound"
  48. | "soundEnabled"
  49. | "soundVolume"
  50. | "diffEnabled"
  51. | "enableCheckpoints"
  52. | "checkpointStorage"
  53. | "browserViewportSize"
  54. | "screenshotQuality"
  55. | "openMcpSettings"
  56. | "restartMcpServer"
  57. | "toggleToolAlwaysAllow"
  58. | "toggleMcpServer"
  59. | "updateMcpTimeout"
  60. | "fuzzyMatchThreshold"
  61. | "preferredLanguage"
  62. | "writeDelayMs"
  63. | "enhancePrompt"
  64. | "enhancedPrompt"
  65. | "draggedImages"
  66. | "deleteMessage"
  67. | "terminalOutputLineLimit"
  68. | "mcpEnabled"
  69. | "enableMcpServerCreation"
  70. | "searchCommits"
  71. | "alwaysApproveResubmit"
  72. | "requestDelaySeconds"
  73. | "rateLimitSeconds"
  74. | "setApiConfigPassword"
  75. | "requestVsCodeLmModels"
  76. | "mode"
  77. | "updatePrompt"
  78. | "updateSupportPrompt"
  79. | "resetSupportPrompt"
  80. | "getSystemPrompt"
  81. | "copySystemPrompt"
  82. | "systemPrompt"
  83. | "enhancementApiConfigId"
  84. | "updateExperimental"
  85. | "autoApprovalEnabled"
  86. | "updateCustomMode"
  87. | "deleteCustomMode"
  88. | "setopenAiCustomModelInfo"
  89. | "openCustomModesSettings"
  90. | "checkpointDiff"
  91. | "checkpointRestore"
  92. | "deleteMcpServer"
  93. | "maxOpenTabsContext"
  94. | "humanRelayResponse"
  95. | "humanRelayCancel"
  96. | "browserToolEnabled"
  97. text?: string
  98. disabled?: boolean
  99. askResponse?: ClineAskResponse
  100. apiConfiguration?: ApiConfiguration
  101. images?: string[]
  102. bool?: boolean
  103. value?: number
  104. commands?: string[]
  105. audioType?: AudioType
  106. serverName?: string
  107. toolName?: string
  108. alwaysAllow?: boolean
  109. mode?: Mode
  110. promptMode?: PromptMode
  111. customPrompt?: PromptComponent
  112. dataUrls?: string[]
  113. values?: Record<string, any>
  114. query?: string
  115. slug?: string
  116. modeConfig?: ModeConfig
  117. timeout?: number
  118. payload?: WebViewMessagePayload
  119. source?: "global" | "project"
  120. requestId?: string
  121. }
  122. // Human relay related message types
  123. export interface HumanRelayResponseMessage extends WebviewMessage {
  124. type: "humanRelayResponse"
  125. requestId: string
  126. text: string
  127. }
  128. export interface HumanRelayCancelMessage extends WebviewMessage {
  129. type: "humanRelayCancel"
  130. requestId: string
  131. }
  132. export const checkoutDiffPayloadSchema = z.object({
  133. ts: z.number(),
  134. previousCommitHash: z.string().optional(),
  135. commitHash: z.string(),
  136. mode: z.enum(["full", "checkpoint"]),
  137. })
  138. export type CheckpointDiffPayload = z.infer<typeof checkoutDiffPayloadSchema>
  139. export const checkoutRestorePayloadSchema = z.object({
  140. ts: z.number(),
  141. commitHash: z.string(),
  142. mode: z.enum(["preview", "restore"]),
  143. })
  144. export type CheckpointRestorePayload = z.infer<typeof checkoutRestorePayloadSchema>
  145. export type WebViewMessagePayload = CheckpointDiffPayload | CheckpointRestorePayload