ExtensionMessage.ts 7.3 KB

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