ExtensionMessage.ts 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. import type {
  2. GlobalSettings,
  3. ProviderSettingsEntry,
  4. ProviderSettings,
  5. HistoryItem,
  6. ModeConfig,
  7. TelemetrySetting,
  8. Experiments,
  9. ClineMessage,
  10. OrganizationAllowList,
  11. CloudUserInfo,
  12. ShareVisibility,
  13. } from "@roo-code/types"
  14. import { GitCommit } from "../utils/git"
  15. import { McpServer } from "./mcp"
  16. import { Mode } from "./modes"
  17. import { RouterModels } from "./api"
  18. import type { MarketplaceItem } from "@roo-code/types"
  19. // Type for marketplace installed metadata
  20. export interface MarketplaceInstalledMetadata {
  21. project: Record<string, { type: string }>
  22. global: Record<string, { type: string }>
  23. }
  24. // Indexing status types
  25. export interface IndexingStatus {
  26. systemStatus: string
  27. message?: string
  28. processedItems: number
  29. totalItems: number
  30. currentItemUnit?: string
  31. }
  32. export interface IndexingStatusUpdateMessage {
  33. type: "indexingStatusUpdate"
  34. values: IndexingStatus
  35. }
  36. export interface LanguageModelChatSelector {
  37. vendor?: string
  38. family?: string
  39. version?: string
  40. id?: string
  41. }
  42. // Represents JSON data that is sent from extension to webview, called
  43. // ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or
  44. // 'settingsButtonClicked' or 'hello'. Webview will hold state.
  45. export interface ExtensionMessage {
  46. type:
  47. | "action"
  48. | "state"
  49. | "selectedImages"
  50. | "theme"
  51. | "workspaceUpdated"
  52. | "invoke"
  53. | "messageUpdated"
  54. | "mcpServers"
  55. | "enhancedPrompt"
  56. | "commitSearchResults"
  57. | "listApiConfig"
  58. | "routerModels"
  59. | "openAiModels"
  60. | "ollamaModels"
  61. | "lmStudioModels"
  62. | "vsCodeLmModels"
  63. | "vsCodeLmApiAvailable"
  64. | "updatePrompt"
  65. | "systemPrompt"
  66. | "autoApprovalEnabled"
  67. | "updateCustomMode"
  68. | "deleteCustomMode"
  69. | "exportModeResult"
  70. | "importModeResult"
  71. | "checkRulesDirectoryResult"
  72. | "currentCheckpointUpdated"
  73. | "showHumanRelayDialog"
  74. | "humanRelayResponse"
  75. | "humanRelayCancel"
  76. | "browserToolEnabled"
  77. | "browserConnectionResult"
  78. | "remoteBrowserEnabled"
  79. | "ttsStart"
  80. | "ttsStop"
  81. | "maxReadFileLine"
  82. | "fileSearchResults"
  83. | "toggleApiConfigPin"
  84. | "acceptInput"
  85. | "setHistoryPreviewCollapsed"
  86. | "commandExecutionStatus"
  87. | "mcpExecutionStatus"
  88. | "vsCodeSetting"
  89. | "authenticatedUser"
  90. | "condenseTaskContextResponse"
  91. | "singleRouterModelFetchResponse"
  92. | "indexingStatusUpdate"
  93. | "indexCleared"
  94. | "codebaseIndexConfig"
  95. | "marketplaceInstallResult"
  96. | "marketplaceData"
  97. | "shareTaskSuccess"
  98. text?: string
  99. payload?: any // Add a generic payload for now, can refine later
  100. action?:
  101. | "chatButtonClicked"
  102. | "mcpButtonClicked"
  103. | "settingsButtonClicked"
  104. | "historyButtonClicked"
  105. | "promptsButtonClicked"
  106. | "marketplaceButtonClicked"
  107. | "accountButtonClicked"
  108. | "didBecomeVisible"
  109. | "focusInput"
  110. | "switchTab"
  111. invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
  112. state?: ExtensionState
  113. images?: string[]
  114. filePaths?: string[]
  115. openedTabs?: Array<{
  116. label: string
  117. isActive: boolean
  118. path?: string
  119. }>
  120. clineMessage?: ClineMessage
  121. routerModels?: RouterModels
  122. openAiModels?: string[]
  123. ollamaModels?: string[]
  124. lmStudioModels?: string[]
  125. vsCodeLmModels?: { vendor?: string; family?: string; version?: string; id?: string }[]
  126. mcpServers?: McpServer[]
  127. commits?: GitCommit[]
  128. listApiConfig?: ProviderSettingsEntry[]
  129. mode?: Mode
  130. customMode?: ModeConfig
  131. slug?: string
  132. success?: boolean
  133. values?: Record<string, any>
  134. requestId?: string
  135. promptText?: string
  136. results?: { path: string; type: "file" | "folder"; label?: string }[]
  137. error?: string
  138. setting?: string
  139. value?: any
  140. hasContent?: boolean // For checkRulesDirectoryResult
  141. items?: MarketplaceItem[]
  142. userInfo?: CloudUserInfo
  143. organizationAllowList?: OrganizationAllowList
  144. tab?: string
  145. marketplaceItems?: MarketplaceItem[]
  146. marketplaceInstalledMetadata?: MarketplaceInstalledMetadata
  147. visibility?: ShareVisibility
  148. }
  149. export type ExtensionState = Pick<
  150. GlobalSettings,
  151. | "currentApiConfigName"
  152. | "listApiConfigMeta"
  153. | "pinnedApiConfigs"
  154. // | "lastShownAnnouncementId"
  155. | "customInstructions"
  156. // | "taskHistory" // Optional in GlobalSettings, required here.
  157. | "autoApprovalEnabled"
  158. | "alwaysAllowReadOnly"
  159. | "alwaysAllowReadOnlyOutsideWorkspace"
  160. | "alwaysAllowWrite"
  161. | "alwaysAllowWriteOutsideWorkspace"
  162. | "alwaysAllowWriteProtected"
  163. // | "writeDelayMs" // Optional in GlobalSettings, required here.
  164. | "alwaysAllowBrowser"
  165. | "alwaysApproveResubmit"
  166. // | "requestDelaySeconds" // Optional in GlobalSettings, required here.
  167. | "alwaysAllowMcp"
  168. | "alwaysAllowModeSwitch"
  169. | "alwaysAllowSubtasks"
  170. | "alwaysAllowExecute"
  171. | "allowedCommands"
  172. | "allowedMaxRequests"
  173. | "browserToolEnabled"
  174. | "browserViewportSize"
  175. | "screenshotQuality"
  176. | "remoteBrowserEnabled"
  177. | "remoteBrowserHost"
  178. // | "enableCheckpoints" // Optional in GlobalSettings, required here.
  179. | "ttsEnabled"
  180. | "ttsSpeed"
  181. | "soundEnabled"
  182. | "soundVolume"
  183. // | "maxOpenTabsContext" // Optional in GlobalSettings, required here.
  184. // | "maxWorkspaceFiles" // Optional in GlobalSettings, required here.
  185. // | "showRooIgnoredFiles" // Optional in GlobalSettings, required here.
  186. // | "maxReadFileLine" // Optional in GlobalSettings, required here.
  187. | "maxConcurrentFileReads" // Optional in GlobalSettings, required here.
  188. | "terminalOutputLineLimit"
  189. | "terminalShellIntegrationTimeout"
  190. | "terminalShellIntegrationDisabled"
  191. | "terminalCommandDelay"
  192. | "terminalPowershellCounter"
  193. | "terminalZshClearEolMark"
  194. | "terminalZshOhMy"
  195. | "terminalZshP10k"
  196. | "terminalZdotdir"
  197. | "terminalCompressProgressBar"
  198. | "diffEnabled"
  199. | "fuzzyMatchThreshold"
  200. // | "experiments" // Optional in GlobalSettings, required here.
  201. | "language"
  202. // | "telemetrySetting" // Optional in GlobalSettings, required here.
  203. // | "mcpEnabled" // Optional in GlobalSettings, required here.
  204. // | "enableMcpServerCreation" // Optional in GlobalSettings, required here.
  205. // | "mode" // Optional in GlobalSettings, required here.
  206. | "modeApiConfigs"
  207. // | "customModes" // Optional in GlobalSettings, required here.
  208. | "customModePrompts"
  209. | "customSupportPrompts"
  210. | "enhancementApiConfigId"
  211. | "condensingApiConfigId"
  212. | "customCondensingPrompt"
  213. | "codebaseIndexConfig"
  214. | "codebaseIndexModels"
  215. | "profileThresholds"
  216. > & {
  217. version: string
  218. clineMessages: ClineMessage[]
  219. currentTaskItem?: HistoryItem
  220. apiConfiguration?: ProviderSettings
  221. uriScheme?: string
  222. shouldShowAnnouncement: boolean
  223. taskHistory: HistoryItem[]
  224. writeDelayMs: number
  225. requestDelaySeconds: number
  226. enableCheckpoints: boolean
  227. maxOpenTabsContext: number // Maximum number of VSCode open tabs to include in context (0-500)
  228. maxWorkspaceFiles: number // Maximum number of files to include in current working directory details (0-500)
  229. showRooIgnoredFiles: boolean // Whether to show .rooignore'd files in listings
  230. maxReadFileLine: number // Maximum number of lines to read from a file before truncating
  231. experiments: Experiments // Map of experiment IDs to their enabled state
  232. mcpEnabled: boolean
  233. enableMcpServerCreation: boolean
  234. mode: Mode
  235. customModes: ModeConfig[]
  236. toolRequirements?: Record<string, boolean> // Map of tool names to their requirements (e.g. {"apply_diff": true} if diffEnabled)
  237. cwd?: string // Current working directory
  238. telemetrySetting: TelemetrySetting
  239. telemetryKey?: string
  240. machineId?: string
  241. renderContext: "sidebar" | "editor"
  242. settingsImportedAt?: number
  243. historyPreviewCollapsed?: boolean
  244. cloudUserInfo: CloudUserInfo | null
  245. cloudIsAuthenticated: boolean
  246. cloudApiUrl?: string
  247. sharingEnabled: boolean
  248. organizationAllowList: OrganizationAllowList
  249. autoCondenseContext: boolean
  250. autoCondenseContextPercent: number
  251. marketplaceItems?: MarketplaceItem[]
  252. marketplaceInstalledMetadata?: { project: Record<string, any>; global: Record<string, any> }
  253. profileThresholds: Record<string, number>
  254. hasOpenedModeSelector: boolean
  255. }
  256. export interface ClineSayTool {
  257. tool:
  258. | "editedExistingFile"
  259. | "appliedDiff"
  260. | "newFileCreated"
  261. | "codebaseSearch"
  262. | "readFile"
  263. | "fetchInstructions"
  264. | "listFilesTopLevel"
  265. | "listFilesRecursive"
  266. | "listCodeDefinitionNames"
  267. | "searchFiles"
  268. | "switchMode"
  269. | "newTask"
  270. | "finishTask"
  271. | "searchAndReplace"
  272. | "insertContent"
  273. path?: string
  274. diff?: string
  275. content?: string
  276. regex?: string
  277. filePattern?: string
  278. mode?: string
  279. reason?: string
  280. isOutsideWorkspace?: boolean
  281. isProtected?: boolean
  282. additionalFileCount?: number // Number of additional files in the same read_file request
  283. search?: string
  284. replace?: string
  285. useRegex?: boolean
  286. ignoreCase?: boolean
  287. startLine?: number
  288. endLine?: number
  289. lineNumber?: number
  290. query?: string
  291. batchFiles?: Array<{
  292. path: string
  293. lineSnippet: string
  294. isOutsideWorkspace?: boolean
  295. key: string
  296. content?: string
  297. }>
  298. batchDiffs?: Array<{
  299. path: string
  300. changeCount: number
  301. key: string
  302. content: string
  303. diffs?: Array<{
  304. content: string
  305. startLine?: number
  306. }>
  307. }>
  308. question?: string
  309. }
  310. // Must keep in sync with system prompt.
  311. export const browserActions = [
  312. "launch",
  313. "click",
  314. "hover",
  315. "type",
  316. "scroll_down",
  317. "scroll_up",
  318. "resize",
  319. "close",
  320. ] as const
  321. export type BrowserAction = (typeof browserActions)[number]
  322. export interface ClineSayBrowserAction {
  323. action: BrowserAction
  324. coordinate?: string
  325. size?: string
  326. text?: string
  327. }
  328. export type BrowserActionResult = {
  329. screenshot?: string
  330. logs?: string
  331. currentUrl?: string
  332. currentMousePosition?: string
  333. }
  334. export interface ClineAskUseMcpServer {
  335. serverName: string
  336. type: "use_mcp_tool" | "access_mcp_resource"
  337. toolName?: string
  338. arguments?: string
  339. uri?: string
  340. response?: string
  341. }
  342. export interface ClineApiReqInfo {
  343. request?: string
  344. tokensIn?: number
  345. tokensOut?: number
  346. cacheWrites?: number
  347. cacheReads?: number
  348. cost?: number
  349. cancelReason?: ClineApiReqCancelReason
  350. streamingFailedMessage?: string
  351. }
  352. export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled"