ExtensionMessage.ts 11 KB

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