ExtensionMessage.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import { GitCommit } from "../utils/git"
  2. import {
  3. GlobalSettings,
  4. ProviderSettingsEntry,
  5. ProviderSettings,
  6. HistoryItem,
  7. ModeConfig,
  8. TelemetrySetting,
  9. ExperimentId,
  10. ClineAsk,
  11. ClineSay,
  12. ToolProgressStatus,
  13. ClineMessage,
  14. } from "../schemas"
  15. import { McpServer } from "./mcp"
  16. import { Mode } from "./modes"
  17. import { RouterModels } from "./api"
  18. export type { ProviderSettingsEntry, ToolProgressStatus }
  19. export interface LanguageModelChatSelector {
  20. vendor?: string
  21. family?: string
  22. version?: string
  23. id?: string
  24. }
  25. // Represents JSON data that is sent from extension to webview, called
  26. // ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or
  27. // 'settingsButtonClicked' or 'hello'. Webview will hold state.
  28. export interface ExtensionMessage {
  29. type:
  30. | "action"
  31. | "state"
  32. | "selectedImages"
  33. | "theme"
  34. | "workspaceUpdated"
  35. | "invoke"
  36. | "partialMessage"
  37. | "mcpServers"
  38. | "enhancedPrompt"
  39. | "commitSearchResults"
  40. | "listApiConfig"
  41. | "routerModels"
  42. | "openAiModels"
  43. | "ollamaModels"
  44. | "lmStudioModels"
  45. | "vsCodeLmModels"
  46. | "vsCodeLmApiAvailable"
  47. | "updatePrompt"
  48. | "systemPrompt"
  49. | "autoApprovalEnabled"
  50. | "updateCustomMode"
  51. | "deleteCustomMode"
  52. | "currentCheckpointUpdated"
  53. | "showHumanRelayDialog"
  54. | "humanRelayResponse"
  55. | "humanRelayCancel"
  56. | "browserToolEnabled"
  57. | "browserConnectionResult"
  58. | "remoteBrowserEnabled"
  59. | "ttsStart"
  60. | "ttsStop"
  61. | "maxReadFileLine"
  62. | "fileSearchResults"
  63. | "toggleApiConfigPin"
  64. | "acceptInput"
  65. | "setHistoryPreviewCollapsed"
  66. | "commandExecutionStatus"
  67. | "vsCodeSetting"
  68. text?: string
  69. action?:
  70. | "chatButtonClicked"
  71. | "mcpButtonClicked"
  72. | "settingsButtonClicked"
  73. | "historyButtonClicked"
  74. | "promptsButtonClicked"
  75. | "didBecomeVisible"
  76. | "focusInput"
  77. invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
  78. state?: ExtensionState
  79. images?: string[]
  80. filePaths?: string[]
  81. openedTabs?: Array<{
  82. label: string
  83. isActive: boolean
  84. path?: string
  85. }>
  86. partialMessage?: ClineMessage
  87. routerModels?: RouterModels
  88. openAiModels?: string[]
  89. ollamaModels?: string[]
  90. lmStudioModels?: string[]
  91. vsCodeLmModels?: { vendor?: string; family?: string; version?: string; id?: string }[]
  92. mcpServers?: McpServer[]
  93. commits?: GitCommit[]
  94. listApiConfig?: ProviderSettingsEntry[]
  95. mode?: Mode
  96. customMode?: ModeConfig
  97. slug?: string
  98. success?: boolean
  99. values?: Record<string, any>
  100. requestId?: string
  101. promptText?: string
  102. results?: { path: string; type: "file" | "folder"; label?: string }[]
  103. error?: string
  104. setting?: string
  105. value?: any
  106. }
  107. export type ExtensionState = Pick<
  108. GlobalSettings,
  109. | "currentApiConfigName"
  110. | "listApiConfigMeta"
  111. | "pinnedApiConfigs"
  112. // | "lastShownAnnouncementId"
  113. | "customInstructions"
  114. // | "taskHistory" // Optional in GlobalSettings, required here.
  115. | "autoApprovalEnabled"
  116. | "alwaysAllowReadOnly"
  117. | "alwaysAllowReadOnlyOutsideWorkspace"
  118. | "alwaysAllowWrite"
  119. | "alwaysAllowWriteOutsideWorkspace"
  120. // | "writeDelayMs" // Optional in GlobalSettings, required here.
  121. | "alwaysAllowBrowser"
  122. | "alwaysApproveResubmit"
  123. // | "requestDelaySeconds" // Optional in GlobalSettings, required here.
  124. | "alwaysAllowMcp"
  125. | "alwaysAllowModeSwitch"
  126. | "alwaysAllowSubtasks"
  127. | "alwaysAllowExecute"
  128. | "allowedCommands"
  129. | "allowedMaxRequests"
  130. | "browserToolEnabled"
  131. | "browserViewportSize"
  132. | "screenshotQuality"
  133. | "remoteBrowserEnabled"
  134. | "remoteBrowserHost"
  135. // | "enableCheckpoints" // Optional in GlobalSettings, required here.
  136. | "ttsEnabled"
  137. | "ttsSpeed"
  138. | "soundEnabled"
  139. | "soundVolume"
  140. // | "maxOpenTabsContext" // Optional in GlobalSettings, required here.
  141. // | "maxWorkspaceFiles" // Optional in GlobalSettings, required here.
  142. // | "showRooIgnoredFiles" // Optional in GlobalSettings, required here.
  143. // | "maxReadFileLine" // Optional in GlobalSettings, required here.
  144. | "terminalOutputLineLimit"
  145. | "terminalShellIntegrationTimeout"
  146. | "terminalShellIntegrationDisabled"
  147. | "terminalCommandDelay"
  148. | "terminalPowershellCounter"
  149. | "terminalZshClearEolMark"
  150. | "terminalZshOhMy"
  151. | "terminalZshP10k"
  152. | "terminalZdotdir"
  153. | "terminalCompressProgressBar"
  154. | "diffEnabled"
  155. | "fuzzyMatchThreshold"
  156. // | "experiments" // Optional in GlobalSettings, required here.
  157. | "language"
  158. // | "telemetrySetting" // Optional in GlobalSettings, required here.
  159. // | "mcpEnabled" // Optional in GlobalSettings, required here.
  160. // | "enableMcpServerCreation" // Optional in GlobalSettings, required here.
  161. // | "mode" // Optional in GlobalSettings, required here.
  162. | "modeApiConfigs"
  163. // | "customModes" // Optional in GlobalSettings, required here.
  164. | "customModePrompts"
  165. | "customSupportPrompts"
  166. | "enhancementApiConfigId"
  167. > & {
  168. version: string
  169. clineMessages: ClineMessage[]
  170. currentTaskItem?: HistoryItem
  171. apiConfiguration?: ProviderSettings
  172. uriScheme?: string
  173. shouldShowAnnouncement: boolean
  174. taskHistory: HistoryItem[]
  175. writeDelayMs: number
  176. requestDelaySeconds: number
  177. enableCheckpoints: boolean
  178. maxOpenTabsContext: number // Maximum number of VSCode open tabs to include in context (0-500)
  179. maxWorkspaceFiles: number // Maximum number of files to include in current working directory details (0-500)
  180. showRooIgnoredFiles: boolean // Whether to show .rooignore'd files in listings
  181. maxReadFileLine: number // Maximum number of lines to read from a file before truncating
  182. experiments: Record<ExperimentId, boolean> // Map of experiment IDs to their enabled state
  183. mcpEnabled: boolean
  184. enableMcpServerCreation: boolean
  185. mode: Mode
  186. customModes: ModeConfig[]
  187. toolRequirements?: Record<string, boolean> // Map of tool names to their requirements (e.g. {"apply_diff": true} if diffEnabled)
  188. cwd?: string // Current working directory
  189. telemetrySetting: TelemetrySetting
  190. telemetryKey?: string
  191. machineId?: string
  192. renderContext: "sidebar" | "editor"
  193. settingsImportedAt?: number
  194. historyPreviewCollapsed?: boolean
  195. }
  196. export type { ClineMessage, ClineAsk, ClineSay }
  197. export interface ClineSayTool {
  198. tool:
  199. | "editedExistingFile"
  200. | "appliedDiff"
  201. | "newFileCreated"
  202. | "readFile"
  203. | "fetchInstructions"
  204. | "listFilesTopLevel"
  205. | "listFilesRecursive"
  206. | "listCodeDefinitionNames"
  207. | "searchFiles"
  208. | "switchMode"
  209. | "newTask"
  210. | "finishTask"
  211. | "searchAndReplace"
  212. | "insertContent"
  213. path?: string
  214. diff?: string
  215. content?: string
  216. regex?: string
  217. filePattern?: string
  218. mode?: string
  219. reason?: string
  220. isOutsideWorkspace?: boolean
  221. search?: string
  222. replace?: string
  223. useRegex?: boolean
  224. ignoreCase?: boolean
  225. startLine?: number
  226. endLine?: number
  227. lineNumber?: number
  228. }
  229. // Must keep in sync with system prompt.
  230. export const browserActions = [
  231. "launch",
  232. "click",
  233. "hover",
  234. "type",
  235. "scroll_down",
  236. "scroll_up",
  237. "resize",
  238. "close",
  239. ] as const
  240. export type BrowserAction = (typeof browserActions)[number]
  241. export interface ClineSayBrowserAction {
  242. action: BrowserAction
  243. coordinate?: string
  244. size?: string
  245. text?: string
  246. }
  247. export type BrowserActionResult = {
  248. screenshot?: string
  249. logs?: string
  250. currentUrl?: string
  251. currentMousePosition?: string
  252. }
  253. export interface ClineAskUseMcpServer {
  254. serverName: string
  255. type: "use_mcp_tool" | "access_mcp_resource"
  256. toolName?: string
  257. arguments?: string
  258. uri?: string
  259. }
  260. export interface ClineApiReqInfo {
  261. request?: string
  262. tokensIn?: number
  263. tokensOut?: number
  264. cacheWrites?: number
  265. cacheReads?: number
  266. cost?: number
  267. cancelReason?: ClineApiReqCancelReason
  268. streamingFailedMessage?: string
  269. }
  270. export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled"