ExtensionMessage.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. | "openRouterModels"
  28. | "glamaModels"
  29. | "unboundModels"
  30. | "requestyModels"
  31. | "openAiModels"
  32. | "mcpServers"
  33. | "enhancedPrompt"
  34. | "commitSearchResults"
  35. | "listApiConfig"
  36. | "vsCodeLmModels"
  37. | "vsCodeLmApiAvailable"
  38. | "requestVsCodeLmModels"
  39. | "updatePrompt"
  40. | "systemPrompt"
  41. | "autoApprovalEnabled"
  42. | "updateCustomMode"
  43. | "deleteCustomMode"
  44. | "currentCheckpointUpdated"
  45. text?: string
  46. action?:
  47. | "chatButtonClicked"
  48. | "mcpButtonClicked"
  49. | "settingsButtonClicked"
  50. | "historyButtonClicked"
  51. | "promptsButtonClicked"
  52. | "didBecomeVisible"
  53. invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick" | "setChatBoxMessage"
  54. state?: ExtensionState
  55. images?: string[]
  56. ollamaModels?: string[]
  57. lmStudioModels?: string[]
  58. vsCodeLmModels?: { vendor?: string; family?: string; version?: string; id?: string }[]
  59. filePaths?: string[]
  60. openedTabs?: Array<{
  61. label: string
  62. isActive: boolean
  63. path?: string
  64. }>
  65. partialMessage?: ClineMessage
  66. openRouterModels?: Record<string, ModelInfo>
  67. glamaModels?: Record<string, ModelInfo>
  68. unboundModels?: Record<string, ModelInfo>
  69. requestyModels?: Record<string, ModelInfo>
  70. openAiModels?: string[]
  71. mcpServers?: McpServer[]
  72. commits?: GitCommit[]
  73. listApiConfig?: ApiConfigMeta[]
  74. mode?: Mode
  75. customMode?: ModeConfig
  76. slug?: string
  77. }
  78. export interface ApiConfigMeta {
  79. id: string
  80. name: string
  81. apiProvider?: ApiProvider
  82. }
  83. export interface ExtensionState {
  84. version: string
  85. clineMessages: ClineMessage[]
  86. taskHistory: HistoryItem[]
  87. shouldShowAnnouncement: boolean
  88. apiConfiguration?: ApiConfiguration
  89. currentApiConfigName?: string
  90. listApiConfigMeta?: ApiConfigMeta[]
  91. customInstructions?: string
  92. customModePrompts?: CustomModePrompts
  93. customSupportPrompts?: CustomSupportPrompts
  94. alwaysAllowReadOnly?: boolean
  95. alwaysAllowWrite?: boolean
  96. alwaysAllowExecute?: boolean
  97. alwaysAllowBrowser?: boolean
  98. alwaysAllowMcp?: boolean
  99. alwaysApproveResubmit?: boolean
  100. alwaysAllowModeSwitch?: boolean
  101. requestDelaySeconds: number
  102. rateLimitSeconds: number // Minimum time between successive requests (0 = disabled)
  103. uriScheme?: string
  104. currentTaskItem?: HistoryItem
  105. allowedCommands?: string[]
  106. soundEnabled?: boolean
  107. soundVolume?: number
  108. diffEnabled?: boolean
  109. checkpointsEnabled: 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. maxOpenTabsContext: number // Maximum number of VSCode open tabs to include in context (0-500)
  126. cwd?: string // Current working directory
  127. }
  128. export interface ClineMessage {
  129. ts: number
  130. type: "ask" | "say"
  131. ask?: ClineAsk
  132. say?: ClineSay
  133. text?: string
  134. images?: string[]
  135. partial?: boolean
  136. reasoning?: string
  137. conversationHistoryIndex?: number
  138. checkpoint?: Record<string, unknown>
  139. }
  140. export type ClineAsk =
  141. | "followup"
  142. | "command"
  143. | "command_output"
  144. | "completion_result"
  145. | "tool"
  146. | "api_req_failed"
  147. | "resume_task"
  148. | "resume_completed_task"
  149. | "mistake_limit_reached"
  150. | "browser_action_launch"
  151. | "use_mcp_server"
  152. export type ClineSay =
  153. | "task"
  154. | "error"
  155. | "api_req_started"
  156. | "api_req_finished"
  157. | "api_req_retried"
  158. | "api_req_retry_delayed"
  159. | "api_req_deleted"
  160. | "text"
  161. | "reasoning"
  162. | "completion_result"
  163. | "user_feedback"
  164. | "user_feedback_diff"
  165. | "command_output"
  166. | "tool"
  167. | "shell_integration_warning"
  168. | "browser_action"
  169. | "browser_action_result"
  170. | "command"
  171. | "mcp_server_request_started"
  172. | "mcp_server_response"
  173. | "new_task_started"
  174. | "new_task"
  175. | "checkpoint_saved"
  176. export interface ClineSayTool {
  177. tool:
  178. | "editedExistingFile"
  179. | "appliedDiff"
  180. | "newFileCreated"
  181. | "readFile"
  182. | "listFilesTopLevel"
  183. | "listFilesRecursive"
  184. | "listCodeDefinitionNames"
  185. | "searchFiles"
  186. | "switchMode"
  187. | "newTask"
  188. path?: string
  189. diff?: string
  190. content?: string
  191. regex?: string
  192. filePattern?: string
  193. mode?: string
  194. reason?: string
  195. }
  196. // must keep in sync with system prompt
  197. export const browserActions = ["launch", "click", "type", "scroll_down", "scroll_up", "close"] as const
  198. export type BrowserAction = (typeof browserActions)[number]
  199. export interface ClineSayBrowserAction {
  200. action: BrowserAction
  201. coordinate?: string
  202. text?: string
  203. }
  204. export type BrowserActionResult = {
  205. screenshot?: string
  206. logs?: string
  207. currentUrl?: string
  208. currentMousePosition?: string
  209. }
  210. export interface ClineAskUseMcpServer {
  211. serverName: string
  212. type: "use_mcp_tool" | "access_mcp_resource"
  213. toolName?: string
  214. arguments?: string
  215. uri?: string
  216. }
  217. export interface ClineApiReqInfo {
  218. request?: string
  219. tokensIn?: number
  220. tokensOut?: number
  221. cacheWrites?: number
  222. cacheReads?: number
  223. cost?: number
  224. cancelReason?: ClineApiReqCancelReason
  225. streamingFailedMessage?: string
  226. }
  227. export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled"