2
0

ExtensionMessage.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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, CustomPrompts } from "./modes"
  7. // webview will hold state
  8. export interface ExtensionMessage {
  9. type:
  10. | "action"
  11. | "state"
  12. | "selectedImages"
  13. | "ollamaModels"
  14. | "lmStudioModels"
  15. | "theme"
  16. | "workspaceUpdated"
  17. | "invoke"
  18. | "partialMessage"
  19. | "glamaModels"
  20. | "openRouterModels"
  21. | "openAiModels"
  22. | "mcpServers"
  23. | "enhancedPrompt"
  24. | "commitSearchResults"
  25. | "listApiConfig"
  26. | "vsCodeLmModels"
  27. | "vsCodeLmApiAvailable"
  28. | "requestVsCodeLmModels"
  29. | "updatePrompt"
  30. | "systemPrompt"
  31. | "autoApprovalEnabled"
  32. text?: string
  33. action?:
  34. | "chatButtonClicked"
  35. | "mcpButtonClicked"
  36. | "settingsButtonClicked"
  37. | "historyButtonClicked"
  38. | "promptsButtonClicked"
  39. | "didBecomeVisible"
  40. invoke?: "sendMessage" | "primaryButtonClick" | "secondaryButtonClick"
  41. state?: ExtensionState
  42. images?: string[]
  43. ollamaModels?: string[]
  44. lmStudioModels?: string[]
  45. vsCodeLmModels?: { vendor?: string; family?: string; version?: string; id?: string }[]
  46. filePaths?: string[]
  47. partialMessage?: ClineMessage
  48. glamaModels?: Record<string, ModelInfo>
  49. openRouterModels?: Record<string, ModelInfo>
  50. openAiModels?: string[]
  51. mcpServers?: McpServer[]
  52. commits?: GitCommit[]
  53. listApiConfig?: ApiConfigMeta[]
  54. mode?: Mode
  55. }
  56. export interface ApiConfigMeta {
  57. id: string
  58. name: string
  59. apiProvider?: ApiProvider
  60. }
  61. export interface ExtensionState {
  62. version: string
  63. clineMessages: ClineMessage[]
  64. taskHistory: HistoryItem[]
  65. shouldShowAnnouncement: boolean
  66. apiConfiguration?: ApiConfiguration
  67. currentApiConfigName?: string
  68. listApiConfigMeta?: ApiConfigMeta[]
  69. customInstructions?: string
  70. customPrompts?: CustomPrompts
  71. alwaysAllowReadOnly?: boolean
  72. alwaysAllowWrite?: boolean
  73. alwaysAllowExecute?: boolean
  74. alwaysAllowBrowser?: boolean
  75. alwaysAllowMcp?: boolean
  76. alwaysApproveResubmit?: boolean
  77. requestDelaySeconds: number
  78. uriScheme?: string
  79. allowedCommands?: string[]
  80. soundEnabled?: boolean
  81. soundVolume?: number
  82. diffEnabled?: boolean
  83. browserViewportSize?: string
  84. screenshotQuality?: number
  85. fuzzyMatchThreshold?: number
  86. preferredLanguage: string
  87. writeDelayMs: number
  88. terminalOutputLineLimit?: number
  89. mcpEnabled: boolean
  90. mode: Mode
  91. modeApiConfigs?: Record<Mode, string>
  92. enhancementApiConfigId?: string
  93. autoApprovalEnabled?: boolean
  94. }
  95. export interface ClineMessage {
  96. ts: number
  97. type: "ask" | "say"
  98. ask?: ClineAsk
  99. say?: ClineSay
  100. text?: string
  101. images?: string[]
  102. partial?: boolean
  103. }
  104. export type ClineAsk =
  105. | "followup"
  106. | "command"
  107. | "command_output"
  108. | "completion_result"
  109. | "tool"
  110. | "api_req_failed"
  111. | "resume_task"
  112. | "resume_completed_task"
  113. | "mistake_limit_reached"
  114. | "browser_action_launch"
  115. | "use_mcp_server"
  116. export type ClineSay =
  117. | "task"
  118. | "error"
  119. | "api_req_started"
  120. | "api_req_finished"
  121. | "text"
  122. | "completion_result"
  123. | "user_feedback"
  124. | "user_feedback_diff"
  125. | "api_req_retried"
  126. | "api_req_retry_delayed"
  127. | "command_output"
  128. | "tool"
  129. | "shell_integration_warning"
  130. | "browser_action"
  131. | "browser_action_result"
  132. | "command"
  133. | "mcp_server_request_started"
  134. | "mcp_server_response"
  135. export interface ClineSayTool {
  136. tool:
  137. | "editedExistingFile"
  138. | "appliedDiff"
  139. | "newFileCreated"
  140. | "readFile"
  141. | "listFilesTopLevel"
  142. | "listFilesRecursive"
  143. | "listCodeDefinitionNames"
  144. | "searchFiles"
  145. path?: string
  146. diff?: string
  147. content?: string
  148. regex?: string
  149. filePattern?: string
  150. }
  151. // must keep in sync with system prompt
  152. export const browserActions = ["launch", "click", "type", "scroll_down", "scroll_up", "close"] as const
  153. export type BrowserAction = (typeof browserActions)[number]
  154. export interface ClineSayBrowserAction {
  155. action: BrowserAction
  156. coordinate?: string
  157. text?: string
  158. }
  159. export type BrowserActionResult = {
  160. screenshot?: string
  161. logs?: string
  162. currentUrl?: string
  163. currentMousePosition?: string
  164. }
  165. export interface ClineAskUseMcpServer {
  166. serverName: string
  167. type: "use_mcp_tool" | "access_mcp_resource"
  168. toolName?: string
  169. arguments?: string
  170. uri?: string
  171. }
  172. export interface ClineApiReqInfo {
  173. request?: string
  174. tokensIn?: number
  175. tokensOut?: number
  176. cacheWrites?: number
  177. cacheReads?: number
  178. cost?: number
  179. cancelReason?: ClineApiReqCancelReason
  180. streamingFailedMessage?: string
  181. }
  182. export type ClineApiReqCancelReason = "streaming_failed" | "user_cancelled"