ExtensionMessage.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. partialMessage?: ClineMessage
  63. glamaModels?: Record<string, ModelInfo>
  64. openRouterModels?: Record<string, ModelInfo>
  65. openAiModels?: string[]
  66. mcpServers?: McpServer[]
  67. commits?: GitCommit[]
  68. listApiConfig?: ApiConfigMeta[]
  69. mode?: Mode
  70. customMode?: ModeConfig
  71. slug?: string
  72. }
  73. export interface ApiConfigMeta {
  74. id: string
  75. name: string
  76. apiProvider?: ApiProvider
  77. }
  78. export interface ExtensionState {
  79. version: string
  80. clineMessages: ClineMessage[]
  81. taskHistory: HistoryItem[]
  82. shouldShowAnnouncement: boolean
  83. apiConfiguration?: ApiConfiguration
  84. currentApiConfigName?: string
  85. listApiConfigMeta?: ApiConfigMeta[]
  86. customInstructions?: string
  87. customModePrompts?: CustomModePrompts
  88. customSupportPrompts?: CustomSupportPrompts
  89. alwaysAllowReadOnly?: boolean
  90. alwaysAllowWrite?: boolean
  91. alwaysAllowExecute?: boolean
  92. alwaysAllowBrowser?: boolean
  93. alwaysAllowMcp?: boolean
  94. alwaysApproveResubmit?: boolean
  95. alwaysAllowModeSwitch?: boolean
  96. requestDelaySeconds: number
  97. rateLimitSeconds: number // Minimum time between successive requests (0 = disabled)
  98. uriScheme?: string
  99. allowedCommands?: string[]
  100. soundEnabled?: boolean
  101. soundVolume?: number
  102. diffEnabled?: boolean
  103. checkpointsEnabled: boolean
  104. browserViewportSize?: string
  105. screenshotQuality?: number
  106. fuzzyMatchThreshold?: number
  107. preferredLanguage: string
  108. writeDelayMs: number
  109. terminalOutputLineLimit?: number
  110. mcpEnabled: boolean
  111. enableMcpServerCreation: boolean
  112. mode: Mode
  113. modeApiConfigs?: Record<Mode, string>
  114. enhancementApiConfigId?: string
  115. experiments: Record<ExperimentId, boolean> // Map of experiment IDs to their enabled state
  116. autoApprovalEnabled?: boolean
  117. customModes: ModeConfig[]
  118. toolRequirements?: Record<string, boolean> // Map of tool names to their requirements (e.g. {"apply_diff": true} if diffEnabled)
  119. }
  120. export interface ClineMessage {
  121. ts: number
  122. type: "ask" | "say"
  123. ask?: ClineAsk
  124. say?: ClineSay
  125. text?: string
  126. images?: string[]
  127. partial?: boolean
  128. reasoning?: string
  129. conversationHistoryIndex?: number
  130. }
  131. export type ClineAsk =
  132. | "followup"
  133. | "command"
  134. | "command_output"
  135. | "completion_result"
  136. | "tool"
  137. | "api_req_failed"
  138. | "resume_task"
  139. | "resume_completed_task"
  140. | "mistake_limit_reached"
  141. | "browser_action_launch"
  142. | "use_mcp_server"
  143. export type ClineSay =
  144. | "task"
  145. | "error"
  146. | "api_req_started"
  147. | "api_req_finished"
  148. | "api_req_retried"
  149. | "api_req_retry_delayed"
  150. | "api_req_deleted"
  151. | "text"
  152. | "reasoning"
  153. | "completion_result"
  154. | "user_feedback"
  155. | "user_feedback_diff"
  156. | "command_output"
  157. | "tool"
  158. | "shell_integration_warning"
  159. | "browser_action"
  160. | "browser_action_result"
  161. | "command"
  162. | "mcp_server_request_started"
  163. | "mcp_server_response"
  164. | "new_task_started"
  165. | "new_task"
  166. | "checkpoint_saved"
  167. export interface ClineSayTool {
  168. tool:
  169. | "editedExistingFile"
  170. | "appliedDiff"
  171. | "newFileCreated"
  172. | "readFile"
  173. | "listFilesTopLevel"
  174. | "listFilesRecursive"
  175. | "listCodeDefinitionNames"
  176. | "searchFiles"
  177. | "switchMode"
  178. | "newTask"
  179. path?: string
  180. diff?: string
  181. content?: string
  182. regex?: string
  183. filePattern?: string
  184. mode?: string
  185. reason?: string
  186. }
  187. // must keep in sync with system prompt
  188. export const browserActions = ["launch", "click", "type", "scroll_down", "scroll_up", "close"] as const
  189. export type BrowserAction = (typeof browserActions)[number]
  190. export interface ClineSayBrowserAction {
  191. action: BrowserAction
  192. coordinate?: string
  193. text?: string
  194. }
  195. export type BrowserActionResult = {
  196. screenshot?: string
  197. logs?: string
  198. currentUrl?: string
  199. currentMousePosition?: string
  200. }
  201. export interface ClineAskUseMcpServer {
  202. serverName: string
  203. type: "use_mcp_tool" | "access_mcp_resource"
  204. toolName?: string
  205. arguments?: string
  206. uri?: string
  207. }
  208. export interface ClineApiReqInfo {
  209. request?: string
  210. tokensIn?: number
  211. tokensOut?: number
  212. cacheWrites?: number
  213. cacheReads?: number
  214. cost?: number
  215. cancelReason?: ClineApiReqCancelReason
  216. streamingFailedMessage?: string
  217. }
  218. export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled"