ExtensionMessage.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import { GitCommit } from "../utils/git"
  2. import {
  3. GlobalSettings,
  4. ApiConfigMeta,
  5. ProviderSettings as ApiConfiguration,
  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 { ApiConfigMeta, 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. text?: string
  67. action?:
  68. | "chatButtonClicked"
  69. | "mcpButtonClicked"
  70. | "settingsButtonClicked"
  71. | "historyButtonClicked"
  72. | "promptsButtonClicked"
  73. | "didBecomeVisible"
  74. | "focusInput"
  75. invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
  76. state?: ExtensionState
  77. images?: string[]
  78. filePaths?: string[]
  79. openedTabs?: Array<{
  80. label: string
  81. isActive: boolean
  82. path?: string
  83. }>
  84. partialMessage?: ClineMessage
  85. routerModels?: RouterModels
  86. openAiModels?: string[]
  87. ollamaModels?: string[]
  88. lmStudioModels?: string[]
  89. vsCodeLmModels?: { vendor?: string; family?: string; version?: string; id?: string }[]
  90. mcpServers?: McpServer[]
  91. commits?: GitCommit[]
  92. listApiConfig?: ApiConfigMeta[]
  93. mode?: Mode
  94. customMode?: ModeConfig
  95. slug?: string
  96. success?: boolean
  97. values?: Record<string, any>
  98. requestId?: string
  99. promptText?: string
  100. results?: { path: string; type: "file" | "folder"; label?: string }[]
  101. error?: string
  102. }
  103. export type ExtensionState = Pick<
  104. GlobalSettings,
  105. | "currentApiConfigName"
  106. | "listApiConfigMeta"
  107. | "pinnedApiConfigs"
  108. // | "lastShownAnnouncementId"
  109. | "customInstructions"
  110. // | "taskHistory" // Optional in GlobalSettings, required here.
  111. | "autoApprovalEnabled"
  112. | "alwaysAllowReadOnly"
  113. | "alwaysAllowReadOnlyOutsideWorkspace"
  114. | "alwaysAllowWrite"
  115. | "alwaysAllowWriteOutsideWorkspace"
  116. // | "writeDelayMs" // Optional in GlobalSettings, required here.
  117. | "alwaysAllowBrowser"
  118. | "alwaysApproveResubmit"
  119. // | "requestDelaySeconds" // Optional in GlobalSettings, required here.
  120. | "alwaysAllowMcp"
  121. | "alwaysAllowModeSwitch"
  122. | "alwaysAllowSubtasks"
  123. | "alwaysAllowExecute"
  124. | "allowedCommands"
  125. | "browserToolEnabled"
  126. | "browserViewportSize"
  127. | "screenshotQuality"
  128. | "remoteBrowserEnabled"
  129. | "remoteBrowserHost"
  130. // | "enableCheckpoints" // Optional in GlobalSettings, required here.
  131. | "ttsEnabled"
  132. | "ttsSpeed"
  133. | "soundEnabled"
  134. | "soundVolume"
  135. // | "maxOpenTabsContext" // Optional in GlobalSettings, required here.
  136. // | "maxWorkspaceFiles" // Optional in GlobalSettings, required here.
  137. // | "showRooIgnoredFiles" // Optional in GlobalSettings, required here.
  138. // | "maxReadFileLine" // Optional in GlobalSettings, required here.
  139. | "terminalOutputLineLimit"
  140. | "terminalShellIntegrationTimeout"
  141. | "terminalShellIntegrationDisabled"
  142. | "terminalCommandDelay"
  143. | "terminalPowershellCounter"
  144. | "terminalZshClearEolMark"
  145. | "terminalZshOhMy"
  146. | "terminalZshP10k"
  147. | "terminalZdotdir"
  148. | "terminalCompressProgressBar"
  149. | "diffEnabled"
  150. | "fuzzyMatchThreshold"
  151. // | "experiments" // Optional in GlobalSettings, required here.
  152. | "language"
  153. // | "telemetrySetting" // Optional in GlobalSettings, required here.
  154. // | "mcpEnabled" // Optional in GlobalSettings, required here.
  155. // | "enableMcpServerCreation" // Optional in GlobalSettings, required here.
  156. // | "mode" // Optional in GlobalSettings, required here.
  157. | "modeApiConfigs"
  158. // | "customModes" // Optional in GlobalSettings, required here.
  159. | "customModePrompts"
  160. | "customSupportPrompts"
  161. | "enhancementApiConfigId"
  162. > & {
  163. version: string
  164. clineMessages: ClineMessage[]
  165. currentTaskItem?: HistoryItem
  166. apiConfiguration?: ApiConfiguration
  167. uriScheme?: string
  168. shouldShowAnnouncement: boolean
  169. taskHistory: HistoryItem[]
  170. writeDelayMs: number
  171. requestDelaySeconds: number
  172. enableCheckpoints: boolean
  173. maxOpenTabsContext: number // Maximum number of VSCode open tabs to include in context (0-500)
  174. maxWorkspaceFiles: number // Maximum number of files to include in current working directory details (0-500)
  175. showRooIgnoredFiles: boolean // Whether to show .rooignore'd files in listings
  176. maxReadFileLine: number // Maximum number of lines to read from a file before truncating
  177. experiments: Record<ExperimentId, boolean> // Map of experiment IDs to their enabled state
  178. mcpEnabled: boolean
  179. enableMcpServerCreation: boolean
  180. mode: Mode
  181. customModes: ModeConfig[]
  182. toolRequirements?: Record<string, boolean> // Map of tool names to their requirements (e.g. {"apply_diff": true} if diffEnabled)
  183. cwd?: string // Current working directory
  184. telemetrySetting: TelemetrySetting
  185. telemetryKey?: string
  186. machineId?: string
  187. renderContext: "sidebar" | "editor"
  188. settingsImportedAt?: number
  189. historyPreviewCollapsed?: boolean
  190. }
  191. export type { ClineMessage, ClineAsk, ClineSay }
  192. export interface ClineSayTool {
  193. tool:
  194. | "editedExistingFile"
  195. | "appliedDiff"
  196. | "newFileCreated"
  197. | "readFile"
  198. | "fetchInstructions"
  199. | "listFilesTopLevel"
  200. | "listFilesRecursive"
  201. | "listCodeDefinitionNames"
  202. | "searchFiles"
  203. | "switchMode"
  204. | "newTask"
  205. | "finishTask"
  206. | "searchAndReplace"
  207. | "insertContent"
  208. path?: string
  209. diff?: string
  210. content?: string
  211. regex?: string
  212. filePattern?: string
  213. mode?: string
  214. reason?: string
  215. isOutsideWorkspace?: boolean
  216. search?: string
  217. replace?: string
  218. useRegex?: boolean
  219. ignoreCase?: boolean
  220. startLine?: number
  221. endLine?: number
  222. lineNumber?: number
  223. }
  224. // Must keep in sync with system prompt.
  225. export const browserActions = [
  226. "launch",
  227. "click",
  228. "hover",
  229. "type",
  230. "scroll_down",
  231. "scroll_up",
  232. "resize",
  233. "close",
  234. ] as const
  235. export type BrowserAction = (typeof browserActions)[number]
  236. export interface ClineSayBrowserAction {
  237. action: BrowserAction
  238. coordinate?: string
  239. size?: string
  240. text?: string
  241. }
  242. export type BrowserActionResult = {
  243. screenshot?: string
  244. logs?: string
  245. currentUrl?: string
  246. currentMousePosition?: string
  247. }
  248. export interface ClineAskUseMcpServer {
  249. serverName: string
  250. type: "use_mcp_tool" | "access_mcp_resource"
  251. toolName?: string
  252. arguments?: string
  253. uri?: string
  254. }
  255. export interface ClineApiReqInfo {
  256. request?: string
  257. tokensIn?: number
  258. tokensOut?: number
  259. cacheWrites?: number
  260. cacheReads?: number
  261. cost?: number
  262. cancelReason?: ClineApiReqCancelReason
  263. streamingFailedMessage?: string
  264. }
  265. export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled"