ExtensionMessage.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import {
  2. ModelInfo,
  3. GlobalSettings,
  4. ApiConfigMeta,
  5. ProviderSettings as ApiConfiguration,
  6. HistoryItem,
  7. ModeConfig,
  8. CheckpointStorage,
  9. TelemetrySetting,
  10. ExperimentId,
  11. ClineAsk,
  12. ClineSay,
  13. ToolProgressStatus,
  14. ClineMessage,
  15. } from "../schemas"
  16. import { McpServer } from "./mcp"
  17. import { GitCommit } from "../utils/git"
  18. import { Mode } from "./modes"
  19. export type { ApiConfigMeta, ToolProgressStatus }
  20. export interface LanguageModelChatSelector {
  21. vendor?: string
  22. family?: string
  23. version?: string
  24. id?: string
  25. }
  26. // Represents JSON data that is sent from extension to webview, called
  27. // ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or
  28. // 'settingsButtonClicked' or 'hello'. Webview will hold state.
  29. export interface ExtensionMessage {
  30. type:
  31. | "action"
  32. | "state"
  33. | "selectedImages"
  34. | "ollamaModels"
  35. | "lmStudioModels"
  36. | "theme"
  37. | "workspaceUpdated"
  38. | "invoke"
  39. | "partialMessage"
  40. | "openRouterModels"
  41. | "glamaModels"
  42. | "unboundModels"
  43. | "requestyModels"
  44. | "openAiModels"
  45. | "mcpServers"
  46. | "enhancedPrompt"
  47. | "commitSearchResults"
  48. | "listApiConfig"
  49. | "vsCodeLmModels"
  50. | "vsCodeLmApiAvailable"
  51. | "requestVsCodeLmModels"
  52. | "updatePrompt"
  53. | "systemPrompt"
  54. | "autoApprovalEnabled"
  55. | "updateCustomMode"
  56. | "deleteCustomMode"
  57. | "currentCheckpointUpdated"
  58. | "showHumanRelayDialog"
  59. | "humanRelayResponse"
  60. | "humanRelayCancel"
  61. | "browserToolEnabled"
  62. | "browserConnectionResult"
  63. | "remoteBrowserEnabled"
  64. | "ttsStart"
  65. | "ttsStop"
  66. | "maxReadFileLine"
  67. | "fileSearchResults"
  68. | "toggleApiConfigPin"
  69. text?: string
  70. action?:
  71. | "chatButtonClicked"
  72. | "mcpButtonClicked"
  73. | "settingsButtonClicked"
  74. | "historyButtonClicked"
  75. | "promptsButtonClicked"
  76. | "didBecomeVisible"
  77. | "focusInput"
  78. invoke?: "newChat" | "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
  79. state?: ExtensionState
  80. images?: string[]
  81. ollamaModels?: string[]
  82. lmStudioModels?: string[]
  83. vsCodeLmModels?: { vendor?: string; family?: string; version?: string; id?: string }[]
  84. filePaths?: string[]
  85. openedTabs?: Array<{
  86. label: string
  87. isActive: boolean
  88. path?: string
  89. }>
  90. partialMessage?: ClineMessage
  91. openRouterModels?: Record<string, ModelInfo>
  92. glamaModels?: Record<string, ModelInfo>
  93. unboundModels?: Record<string, ModelInfo>
  94. requestyModels?: Record<string, ModelInfo>
  95. openAiModels?: string[]
  96. mcpServers?: McpServer[]
  97. commits?: GitCommit[]
  98. listApiConfig?: ApiConfigMeta[]
  99. mode?: Mode
  100. customMode?: ModeConfig
  101. slug?: string
  102. success?: boolean
  103. values?: Record<string, any>
  104. requestId?: string
  105. promptText?: string
  106. results?: Array<{
  107. path: string
  108. type: "file" | "folder"
  109. label?: string
  110. }>
  111. error?: string
  112. }
  113. export type ExtensionState = Pick<
  114. GlobalSettings,
  115. | "currentApiConfigName"
  116. | "listApiConfigMeta"
  117. | "pinnedApiConfigs"
  118. // | "lastShownAnnouncementId"
  119. | "customInstructions"
  120. // | "taskHistory" // Optional in GlobalSettings, required here.
  121. | "autoApprovalEnabled"
  122. | "alwaysAllowReadOnly"
  123. | "alwaysAllowReadOnlyOutsideWorkspace"
  124. | "alwaysAllowWrite"
  125. | "alwaysAllowWriteOutsideWorkspace"
  126. // | "writeDelayMs" // Optional in GlobalSettings, required here.
  127. | "alwaysAllowBrowser"
  128. | "alwaysApproveResubmit"
  129. // | "requestDelaySeconds" // Optional in GlobalSettings, required here.
  130. | "alwaysAllowMcp"
  131. | "alwaysAllowModeSwitch"
  132. | "alwaysAllowSubtasks"
  133. | "alwaysAllowExecute"
  134. | "allowedCommands"
  135. | "browserToolEnabled"
  136. | "browserViewportSize"
  137. | "screenshotQuality"
  138. | "remoteBrowserEnabled"
  139. | "remoteBrowserHost"
  140. // | "enableCheckpoints" // Optional in GlobalSettings, required here.
  141. // | "checkpointStorage" // Optional in GlobalSettings, required here.
  142. | "ttsEnabled"
  143. | "ttsSpeed"
  144. | "soundEnabled"
  145. | "soundVolume"
  146. // | "maxOpenTabsContext" // Optional in GlobalSettings, required here.
  147. // | "maxWorkspaceFiles" // Optional in GlobalSettings, required here.
  148. // | "showRooIgnoredFiles" // Optional in GlobalSettings, required here.
  149. // | "maxReadFileLine" // Optional in GlobalSettings, required here.
  150. | "terminalOutputLineLimit"
  151. | "terminalShellIntegrationTimeout"
  152. // | "rateLimitSeconds" // Optional in GlobalSettings, required here.
  153. | "diffEnabled"
  154. | "fuzzyMatchThreshold"
  155. // | "experiments" // Optional in GlobalSettings, required here.
  156. | "language"
  157. // | "telemetrySetting" // Optional in GlobalSettings, required here.
  158. // | "mcpEnabled" // Optional in GlobalSettings, required here.
  159. // | "enableMcpServerCreation" // Optional in GlobalSettings, required here.
  160. // | "mode" // Optional in GlobalSettings, required here.
  161. | "modeApiConfigs"
  162. // | "customModes" // Optional in GlobalSettings, required here.
  163. | "customModePrompts"
  164. | "customSupportPrompts"
  165. | "enhancementApiConfigId"
  166. > & {
  167. version: string
  168. clineMessages: ClineMessage[]
  169. currentTaskItem?: HistoryItem
  170. apiConfiguration?: ApiConfiguration
  171. uriScheme?: string
  172. shouldShowAnnouncement: boolean
  173. taskHistory: HistoryItem[]
  174. writeDelayMs: number
  175. requestDelaySeconds: number
  176. enableCheckpoints: boolean
  177. checkpointStorage: CheckpointStorage
  178. maxOpenTabsContext: number // Maximum number of VSCode open tabs to include in context (0-500)
  179. maxWorkspaceFiles: number // Maximum number of files to include in current working directory details (0-500)
  180. showRooIgnoredFiles: boolean // Whether to show .rooignore'd files in listings
  181. maxReadFileLine: number // Maximum number of lines to read from a file before truncating
  182. rateLimitSeconds: number // Minimum time between successive requests (0 = disabled).
  183. experiments: Record<ExperimentId, boolean> // Map of experiment IDs to their enabled state
  184. mcpEnabled: boolean
  185. enableMcpServerCreation: boolean
  186. mode: Mode
  187. customModes: ModeConfig[]
  188. toolRequirements?: Record<string, boolean> // Map of tool names to their requirements (e.g. {"apply_diff": true} if diffEnabled)
  189. cwd?: string // Current working directory
  190. telemetrySetting: TelemetrySetting
  191. telemetryKey?: string
  192. machineId?: string
  193. renderContext: "sidebar" | "editor"
  194. settingsImportedAt?: number
  195. }
  196. export type { ClineMessage, ClineAsk, ClineSay }
  197. export interface ClineSayTool {
  198. tool:
  199. | "editedExistingFile"
  200. | "appliedDiff"
  201. | "newFileCreated"
  202. | "readFile"
  203. | "fetchInstructions"
  204. | "listFilesTopLevel"
  205. | "listFilesRecursive"
  206. | "listCodeDefinitionNames"
  207. | "searchFiles"
  208. | "switchMode"
  209. | "newTask"
  210. | "finishTask"
  211. path?: string
  212. diff?: string
  213. content?: string
  214. regex?: string
  215. filePattern?: string
  216. mode?: string
  217. reason?: string
  218. isOutsideWorkspace?: boolean
  219. }
  220. // Must keep in sync with system prompt.
  221. export const browserActions = [
  222. "launch",
  223. "click",
  224. "hover",
  225. "type",
  226. "scroll_down",
  227. "scroll_up",
  228. "resize",
  229. "close",
  230. ] as const
  231. export type BrowserAction = (typeof browserActions)[number]
  232. export interface ClineSayBrowserAction {
  233. action: BrowserAction
  234. coordinate?: string
  235. size?: string
  236. text?: string
  237. }
  238. export type BrowserActionResult = {
  239. screenshot?: string
  240. logs?: string
  241. currentUrl?: string
  242. currentMousePosition?: string
  243. }
  244. export interface ClineAskUseMcpServer {
  245. serverName: string
  246. type: "use_mcp_tool" | "access_mcp_resource"
  247. toolName?: string
  248. arguments?: string
  249. uri?: string
  250. }
  251. export interface ClineApiReqInfo {
  252. request?: string
  253. tokensIn?: number
  254. tokensOut?: number
  255. cacheWrites?: number
  256. cacheReads?: number
  257. cost?: number
  258. cancelReason?: ClineApiReqCancelReason
  259. streamingFailedMessage?: string
  260. }
  261. export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled"