ExtensionMessage.ts 10 KB

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