ExtensionMessage.ts 12 KB

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