ExtensionMessage.ts 12 KB

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