ExtensionMessage.ts 5.3 KB

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