ExtensionMessage.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. // type that represents json data that is sent from extension to webview, called ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or 'settingsButtonClicked' or 'hello'
  2. import { ApiConfiguration, ApiProvider, ModelInfo } from "./api"
  3. import { HistoryItem } from "./HistoryItem"
  4. import { McpServer } from "./mcp"
  5. import { GitCommit } from "../utils/git"
  6. import { Mode, CustomModePrompts, ModeConfig } from "./modes"
  7. import { CustomSupportPrompts } from "./support-prompt"
  8. import { ExperimentId } from "./experiments"
  9. export interface LanguageModelChatSelector {
  10. vendor?: string
  11. family?: string
  12. version?: string
  13. id?: string
  14. }
  15. // webview will hold state
  16. export interface ExtensionMessage {
  17. type:
  18. | "action"
  19. | "state"
  20. | "selectedImages"
  21. | "ollamaModels"
  22. | "lmStudioModels"
  23. | "theme"
  24. | "workspaceUpdated"
  25. | "invoke"
  26. | "partialMessage"
  27. | "glamaModels"
  28. | "openRouterModels"
  29. | "openAiModels"
  30. | "mcpServers"
  31. | "enhancedPrompt"
  32. | "commitSearchResults"
  33. | "listApiConfig"
  34. | "vsCodeLmModels"
  35. | "vsCodeLmApiAvailable"
  36. | "requestVsCodeLmModels"
  37. | "updatePrompt"
  38. | "systemPrompt"
  39. | "autoApprovalEnabled"
  40. | "updateCustomMode"
  41. | "deleteCustomMode"
  42. text?: string
  43. action?:
  44. | "chatButtonClicked"
  45. | "mcpButtonClicked"
  46. | "settingsButtonClicked"
  47. | "historyButtonClicked"
  48. | "promptsButtonClicked"
  49. | "didBecomeVisible"
  50. invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
  51. state?: ExtensionState
  52. images?: string[]
  53. ollamaModels?: string[]
  54. lmStudioModels?: string[]
  55. vsCodeLmModels?: { vendor?: string; family?: string; version?: string; id?: string }[]
  56. filePaths?: string[]
  57. openedTabs?: Array<{
  58. label: string
  59. isActive: boolean
  60. path?: string
  61. }>
  62. activeSelection?: {
  63. file: string
  64. selection: {
  65. startLine: number
  66. endLine: number
  67. }
  68. } | null
  69. partialMessage?: ClineMessage
  70. glamaModels?: Record<string, ModelInfo>
  71. openRouterModels?: Record<string, ModelInfo>
  72. openAiModels?: string[]
  73. mcpServers?: McpServer[]
  74. commits?: GitCommit[]
  75. listApiConfig?: ApiConfigMeta[]
  76. mode?: Mode
  77. customMode?: ModeConfig
  78. slug?: string
  79. }
  80. export interface ApiConfigMeta {
  81. id: string
  82. name: string
  83. apiProvider?: ApiProvider
  84. }
  85. export interface ExtensionState {
  86. version: string
  87. clineMessages: ClineMessage[]
  88. taskHistory: HistoryItem[]
  89. shouldShowAnnouncement: boolean
  90. apiConfiguration?: ApiConfiguration
  91. currentApiConfigName?: string
  92. listApiConfigMeta?: ApiConfigMeta[]
  93. customInstructions?: string
  94. customModePrompts?: CustomModePrompts
  95. customSupportPrompts?: CustomSupportPrompts
  96. alwaysAllowReadOnly?: boolean
  97. alwaysAllowWrite?: boolean
  98. alwaysAllowExecute?: boolean
  99. alwaysAllowBrowser?: boolean
  100. alwaysAllowMcp?: boolean
  101. alwaysApproveResubmit?: boolean
  102. alwaysAllowModeSwitch?: boolean
  103. requestDelaySeconds: number
  104. rateLimitSeconds: number // Minimum time between successive requests (0 = disabled)
  105. uriScheme?: string
  106. allowedCommands?: string[]
  107. soundEnabled?: boolean
  108. soundVolume?: number
  109. diffEnabled?: boolean
  110. browserViewportSize?: string
  111. screenshotQuality?: number
  112. fuzzyMatchThreshold?: number
  113. preferredLanguage: string
  114. writeDelayMs: number
  115. terminalOutputLineLimit?: number
  116. mcpEnabled: boolean
  117. enableMcpServerCreation: boolean
  118. mode: Mode
  119. modeApiConfigs?: Record<Mode, string>
  120. enhancementApiConfigId?: string
  121. experiments: Record<ExperimentId, boolean> // Map of experiment IDs to their enabled state
  122. autoApprovalEnabled?: boolean
  123. customModes: ModeConfig[]
  124. toolRequirements?: Record<string, boolean> // Map of tool names to their requirements (e.g. {"apply_diff": true} if diffEnabled)
  125. }
  126. export interface ClineMessage {
  127. ts: number
  128. type: "ask" | "say"
  129. ask?: ClineAsk
  130. say?: ClineSay
  131. text?: string
  132. images?: string[]
  133. partial?: boolean
  134. reasoning?: string
  135. }
  136. export type ClineAsk =
  137. | "followup"
  138. | "command"
  139. | "command_output"
  140. | "completion_result"
  141. | "tool"
  142. | "api_req_failed"
  143. | "resume_task"
  144. | "resume_completed_task"
  145. | "mistake_limit_reached"
  146. | "browser_action_launch"
  147. | "use_mcp_server"
  148. export type ClineSay =
  149. | "task"
  150. | "error"
  151. | "api_req_started"
  152. | "api_req_finished"
  153. | "text"
  154. | "reasoning"
  155. | "completion_result"
  156. | "user_feedback"
  157. | "user_feedback_diff"
  158. | "api_req_retried"
  159. | "api_req_retry_delayed"
  160. | "command_output"
  161. | "tool"
  162. | "shell_integration_warning"
  163. | "browser_action"
  164. | "browser_action_result"
  165. | "command"
  166. | "mcp_server_request_started"
  167. | "mcp_server_response"
  168. | "new_task_started"
  169. | "new_task"
  170. export interface ClineSayTool {
  171. tool:
  172. | "editedExistingFile"
  173. | "appliedDiff"
  174. | "newFileCreated"
  175. | "readFile"
  176. | "listFilesTopLevel"
  177. | "listFilesRecursive"
  178. | "listCodeDefinitionNames"
  179. | "searchFiles"
  180. | "switchMode"
  181. | "newTask"
  182. path?: string
  183. diff?: string
  184. content?: string
  185. regex?: string
  186. filePattern?: string
  187. mode?: string
  188. reason?: string
  189. }
  190. // must keep in sync with system prompt
  191. export const browserActions = ["launch", "click", "type", "scroll_down", "scroll_up", "close"] as const
  192. export type BrowserAction = (typeof browserActions)[number]
  193. export interface ClineSayBrowserAction {
  194. action: BrowserAction
  195. coordinate?: string
  196. text?: string
  197. }
  198. export type BrowserActionResult = {
  199. screenshot?: string
  200. logs?: string
  201. currentUrl?: string
  202. currentMousePosition?: string
  203. }
  204. export interface ClineAskUseMcpServer {
  205. serverName: string
  206. type: "use_mcp_tool" | "access_mcp_resource"
  207. toolName?: string
  208. arguments?: string
  209. uri?: string
  210. }
  211. export interface ClineApiReqInfo {
  212. request?: string
  213. tokensIn?: number
  214. tokensOut?: number
  215. cacheWrites?: number
  216. cacheReads?: number
  217. cost?: number
  218. cancelReason?: ClineApiReqCancelReason
  219. streamingFailedMessage?: string
  220. }
  221. export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled"