WebviewMessage.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. import { z } from "zod"
  2. import {
  3. type RooCodeSettings,
  4. type ProviderSettings,
  5. type PromptComponent,
  6. type ModeConfig,
  7. type InstallMarketplaceItemOptions,
  8. type MarketplaceItem,
  9. type ShareVisibility,
  10. type QueuedMessage,
  11. marketplaceItemSchema,
  12. // kilocode_change start
  13. CommitRange,
  14. HistoryItem,
  15. GlobalState,
  16. // kilocode_change end
  17. } from "@roo-code/types"
  18. import { Mode } from "./modes"
  19. import { MicrophoneDevice } from "./sttContract" // kilocode_change: Microphone device type for STT
  20. export type ClineAskResponse =
  21. | "yesButtonClicked"
  22. | "noButtonClicked"
  23. | "messageResponse"
  24. | "objectResponse"
  25. | "retry_clicked" // kilocode_change: Added retry_clicked for payment required dialog
  26. export type PromptMode = Mode | "enhance"
  27. export type AudioType = "notification" | "celebration" | "progress_loop"
  28. export interface UpdateTodoListPayload {
  29. todos: any[]
  30. }
  31. export type EditQueuedMessagePayload = Pick<QueuedMessage, "id" | "text" | "images">
  32. // kilocode_change start: Type-safe global state update message
  33. export type GlobalStateValue<K extends keyof GlobalState> = GlobalState[K]
  34. export type UpdateGlobalStateMessage<K extends keyof GlobalState = keyof GlobalState> = {
  35. type: "updateGlobalState"
  36. stateKey: K
  37. stateValue: GlobalStateValue<K>
  38. }
  39. // kilocode_change end: Type-safe global state update message
  40. export interface WebviewMessage {
  41. type:
  42. | "updateTodoList"
  43. | "deleteMultipleTasksWithIds"
  44. | "currentApiConfigName"
  45. | "saveApiConfiguration"
  46. | "upsertApiConfiguration"
  47. | "deleteApiConfiguration"
  48. | "loadApiConfiguration"
  49. | "loadApiConfigurationById"
  50. | "getProfileConfigurationForEditing" // kilocode_change: Request to get profile config without activating
  51. | "renameApiConfiguration"
  52. | "getListApiConfiguration"
  53. | "customInstructions"
  54. | "webviewDidLaunch"
  55. | "newTask"
  56. | "askResponse"
  57. | "terminalOperation"
  58. | "clearTask"
  59. | "didShowAnnouncement"
  60. | "selectImages"
  61. | "exportCurrentTask"
  62. | "shareCurrentTask"
  63. | "showTaskWithId"
  64. | "deleteTaskWithId"
  65. | "exportTaskWithId"
  66. | "importSettings"
  67. | "toggleToolAutoApprove"
  68. | "openExtensionSettings"
  69. | "openInBrowser"
  70. | "fetchOpenGraphData"
  71. | "checkIsImageUrl"
  72. | "exportSettings"
  73. | "resetState"
  74. | "flushRouterModels"
  75. | "requestRouterModels"
  76. | "requestOpenAiModels"
  77. | "requestOllamaModels"
  78. | "requestLmStudioModels"
  79. | "requestRooModels"
  80. | "requestRooCreditBalance"
  81. | "requestVsCodeLmModels"
  82. | "requestHuggingFaceModels"
  83. | "requestSapAiCoreModels" // kilocode_change
  84. | "requestSapAiCoreDeployments" // kilocode_change
  85. | "openImage"
  86. | "saveImage"
  87. | "openFile"
  88. | "openMention"
  89. | "cancelTask"
  90. | "cancelAutoApproval"
  91. | "updateVSCodeSetting"
  92. | "getVSCodeSetting"
  93. | "vsCodeSetting"
  94. | "updateCondensingPrompt"
  95. | "yoloGatekeeperApiConfigId" // kilocode_change: AI gatekeeper for YOLO mode
  96. | "playSound"
  97. | "playTts"
  98. | "stopTts"
  99. | "ttsEnabled"
  100. | "ttsSpeed"
  101. | "openKeyboardShortcuts"
  102. | "openMcpSettings"
  103. | "openProjectMcpSettings"
  104. | "restartMcpServer"
  105. | "mcpServerOAuthSignIn" // kilocode_change: MCP OAuth sign-in
  106. | "refreshAllMcpServers"
  107. | "toggleToolAlwaysAllow"
  108. | "toggleToolEnabledForPrompt"
  109. | "toggleMcpServer"
  110. | "updateMcpTimeout"
  111. | "fuzzyMatchThreshold" // kilocode_change
  112. | "morphApiKey" // kilocode_change: Morph fast apply - global setting
  113. | "fastApplyModel" // kilocode_change: Fast Apply model selection
  114. | "fastApplyApiProvider" // kilocode_change: Fast Apply model api base url
  115. | "writeDelayMs" // kilocode_change
  116. | "diagnosticsEnabled" // kilocode_change
  117. | "enhancePrompt"
  118. | "enhancedPrompt"
  119. | "draggedImages"
  120. | "deleteMessage"
  121. | "deleteMessageConfirm"
  122. | "submitEditedMessage"
  123. | "editMessageConfirm"
  124. | "enableMcpServerCreation"
  125. | "remoteControlEnabled"
  126. | "taskSyncEnabled"
  127. | "searchCommits"
  128. | "setApiConfigPassword"
  129. | "mode"
  130. | "updatePrompt"
  131. | "getSystemPrompt"
  132. | "copySystemPrompt"
  133. | "systemPrompt"
  134. | "enhancementApiConfigId"
  135. | "commitMessageApiConfigId" // kilocode_change
  136. | "terminalCommandApiConfigId" // kilocode_change
  137. | "ghostServiceSettings" // kilocode_change
  138. | "stt:start" // kilocode_change: Start STT recording
  139. | "stt:stop" // kilocode_change: Stop STT recording
  140. | "stt:cancel" // kilocode_change: Cancel STT recording
  141. | "stt:checkAvailability" // kilocode_change: Check STT availability on demand
  142. | "stt:listDevices" // kilocode_change: List microphone devices
  143. | "stt:selectDevice" // kilocode_change: Select microphone device
  144. | "includeTaskHistoryInEnhance" // kilocode_change
  145. | "snoozeAutocomplete" // kilocode_change
  146. | "autoApprovalEnabled"
  147. | "yoloMode" // kilocode_change
  148. | "updateCustomMode"
  149. | "deleteCustomMode"
  150. | "setopenAiCustomModelInfo"
  151. | "openCustomModesSettings"
  152. | "checkpointDiff"
  153. | "checkpointRestore"
  154. | "requestCheckpointRestoreApproval"
  155. | "seeNewChanges" // kilocode_change
  156. | "deleteMcpServer"
  157. | "insertTextToChatArea" // kilocode_change
  158. | "humanRelayResponse"
  159. | "humanRelayCancel"
  160. | "codebaseIndexEnabled"
  161. | "telemetrySetting"
  162. | "testBrowserConnection"
  163. | "browserConnectionResult"
  164. | "allowVeryLargeReads" // kilocode_change
  165. | "showFeedbackOptions" // kilocode_change
  166. | "fetchMcpMarketplace" // kilocode_change
  167. | "silentlyRefreshMcpMarketplace" // kilocode_change
  168. | "fetchLatestMcpServersFromHub" // kilocode_change
  169. | "downloadMcp" // kilocode_change
  170. | "showSystemNotification" // kilocode_change
  171. | "showAutoApproveMenu" // kilocode_change
  172. | "reportBug" // kilocode_change
  173. | "profileButtonClicked" // kilocode_change
  174. | "fetchProfileDataRequest" // kilocode_change
  175. | "profileDataResponse" // kilocode_change
  176. | "fetchBalanceDataRequest" // kilocode_change
  177. | "shopBuyCredits" // kilocode_change
  178. | "balanceDataResponse" // kilocode_change
  179. | "updateProfileData" // kilocode_change
  180. | "condense" // kilocode_change
  181. | "toggleWorkflow" // kilocode_change
  182. | "refreshRules" // kilocode_change
  183. | "refreshSkills" // kilocode_change
  184. | "toggleRule" // kilocode_change
  185. | "createRuleFile" // kilocode_change
  186. | "deleteRuleFile" // kilocode_change
  187. | "searchFiles"
  188. | "toggleApiConfigPin"
  189. | "hasOpenedModeSelector"
  190. | "clearCloudAuthSkipModel"
  191. | "cloudButtonClicked"
  192. | "rooCloudSignIn"
  193. | "cloudLandingPageSignIn"
  194. | "rooCloudSignOut"
  195. | "rooCloudManualUrl"
  196. | "claudeCodeSignIn"
  197. | "claudeCodeSignOut"
  198. | "openAiCodexSignIn"
  199. | "openAiCodexSignOut"
  200. | "switchOrganization"
  201. | "condenseTaskContextRequest"
  202. | "requestIndexingStatus"
  203. | "startIndexing"
  204. | "cancelIndexing" // kilocode_change
  205. | "clearIndexData"
  206. | "indexingStatusUpdate"
  207. | "indexCleared"
  208. | "focusPanelRequest"
  209. | "clearUsageData" // kilocode_change
  210. | "getUsageData" // kilocode_change
  211. | "usageDataResponse" // kilocode_change
  212. | "showTaskTimeline" // kilocode_change
  213. | "sendMessageOnEnter" // kilocode_change
  214. | "showTimestamps" // kilocode_change
  215. | "showDiffStats" // kilocode_change
  216. | "hideCostBelowThreshold" // kilocode_change
  217. | "toggleTaskFavorite" // kilocode_change
  218. | "fixMermaidSyntax" // kilocode_change
  219. | "mermaidFixResponse" // kilocode_change
  220. | "openGlobalKeybindings" // kilocode_change
  221. | "getKeybindings" // kilocode_change
  222. | "setReasoningBlockCollapsed"
  223. | "setHistoryPreviewCollapsed" // kilocode_change
  224. | "openExternal"
  225. | "filterMarketplaceItems"
  226. | "marketplaceButtonClicked"
  227. | "installMarketplaceItem"
  228. | "installMarketplaceItemWithParameters"
  229. | "cancelMarketplaceInstall"
  230. | "removeInstalledMarketplaceItem"
  231. | "marketplaceInstallResult"
  232. | "fetchMarketplaceData"
  233. | "switchTab"
  234. | "profileThresholds" // kilocode_change
  235. | "editMessage" // kilocode_change
  236. | "systemNotificationsEnabled" // kilocode_change
  237. | "dismissNotificationId" // kilocode_change
  238. | "tasksByIdRequest" // kilocode_change
  239. | "taskHistoryRequest" // kilocode_change
  240. | "updateGlobalState" // kilocode_change
  241. | "autoPurgeEnabled" // kilocode_change
  242. | "autoPurgeDefaultRetentionDays" // kilocode_change
  243. | "autoPurgeFavoritedTaskRetentionDays" // kilocode_change
  244. | "autoPurgeCompletedTaskRetentionDays" // kilocode_change
  245. | "autoPurgeIncompleteTaskRetentionDays" // kilocode_change
  246. | "manualPurge" // kilocode_change
  247. | "shareTaskSuccess" // kilocode_change
  248. | "exportMode"
  249. | "exportModeResult"
  250. | "importMode"
  251. | "importModeResult"
  252. | "checkRulesDirectory"
  253. | "checkRulesDirectoryResult"
  254. | "saveCodeIndexSettingsAtomic"
  255. | "requestCodeIndexSecretStatus"
  256. | "fetchKilocodeNotifications"
  257. | "requestCommands"
  258. | "openCommandFile"
  259. | "deleteCommand"
  260. | "createCommand"
  261. | "insertTextIntoTextarea"
  262. | "showMdmAuthRequiredNotification"
  263. | "imageGenerationSettings"
  264. | "kiloCodeImageApiKey" // kilocode_change
  265. | "queueMessage"
  266. | "removeQueuedMessage"
  267. | "editQueuedMessage"
  268. | "dismissUpsell"
  269. | "getDismissedUpsells"
  270. | "updateSettings"
  271. | "requestManagedIndexerState" // kilocode_change
  272. | "allowedCommands"
  273. | "deniedCommands"
  274. | "killBrowserSession"
  275. | "openBrowserSessionPanel"
  276. | "showBrowserSessionPanelAtStep"
  277. | "refreshBrowserSessionPanel"
  278. | "browserPanelDidLaunch"
  279. | "addTaskToHistory" // kilocode_change
  280. | "sessionShare" // kilocode_change
  281. | "shareTaskSession" // kilocode_change
  282. | "sessionFork" // kilocode_change
  283. | "sessionShow" // kilocode_change
  284. | "sessionSelect" // kilocode_change
  285. | "singleCompletion" // kilocode_change
  286. | "openDebugApiHistory"
  287. | "openDebugUiHistory"
  288. | "startDeviceAuth" // kilocode_change: Start device auth flow
  289. | "cancelDeviceAuth" // kilocode_change: Cancel device auth flow
  290. | "deviceAuthCompleteWithProfile" // kilocode_change: Device auth complete with specific profile
  291. | "requestChatCompletion" // kilocode_change: Request FIM completion for chat text area
  292. | "chatCompletionAccepted" // kilocode_change: User accepted a chat completion suggestion
  293. | "downloadErrorDiagnostics"
  294. | "requestClaudeCodeRateLimits"
  295. | "refreshCustomTools"
  296. text?: string
  297. suggestionLength?: number // kilocode_change: Length of accepted suggestion for telemetry
  298. completionRequestId?: string // kilocode_change
  299. shareId?: string // kilocode_change - for sessionFork
  300. sessionId?: string // kilocode_change - for sessionSelect
  301. editedMessageContent?: string
  302. tab?: "settings" | "history" | "mcp" | "modes" | "chat" | "marketplace" | "cloud" | "auth" | "skills" // kilocode_change
  303. disabled?: boolean
  304. context?: string
  305. dataUri?: string
  306. askResponse?: ClineAskResponse
  307. apiConfiguration?: ProviderSettings
  308. images?: string[]
  309. bool?: boolean
  310. value?: number
  311. stepIndex?: number
  312. isLaunchAction?: boolean
  313. forceShow?: boolean
  314. commands?: string[]
  315. audioType?: AudioType
  316. // kilocode_change begin
  317. notificationOptions?: {
  318. title?: string
  319. subtitle?: string
  320. message: string
  321. }
  322. mcpId?: string
  323. toolNames?: string[]
  324. autoApprove?: boolean
  325. workflowPath?: string // kilocode_change
  326. enabled?: boolean // kilocode_change
  327. rulePath?: string // kilocode_change
  328. isGlobal?: boolean // kilocode_change
  329. filename?: string // kilocode_change
  330. ruleType?: string // kilocode_change
  331. notificationId?: string // kilocode_change
  332. commandIds?: string[] // kilocode_change: For getKeybindings
  333. // kilocode_change end
  334. serverName?: string
  335. toolName?: string
  336. alwaysAllow?: boolean
  337. isEnabled?: boolean
  338. mode?: Mode
  339. promptMode?: PromptMode
  340. customPrompt?: PromptComponent
  341. dataUrls?: string[]
  342. values?: Record<string, any>
  343. query?: string
  344. setting?: string
  345. slug?: string
  346. language?: string // User's language for speech transcription (STT)
  347. device?: MicrophoneDevice | null // kilocode_change: Microphone device for stt:selectDevice
  348. modeConfig?: ModeConfig
  349. timeout?: number
  350. payload?: WebViewMessagePayload
  351. source?: "global" | "project"
  352. requestId?: string
  353. ids?: string[]
  354. hasSystemPromptOverride?: boolean
  355. terminalOperation?: "continue" | "abort"
  356. messageTs?: number
  357. restoreCheckpoint?: boolean
  358. historyPreviewCollapsed?: boolean
  359. filters?: { type?: string; search?: string; tags?: string[] }
  360. settings?: any
  361. url?: string // For openExternal
  362. mpItem?: MarketplaceItem
  363. mpInstallOptions?: InstallMarketplaceItemOptions
  364. config?: Record<string, any> // Add config to the payload
  365. visibility?: ShareVisibility // For share visibility
  366. hasContent?: boolean // For checkRulesDirectoryResult
  367. checkOnly?: boolean // For deleteCustomMode check
  368. upsellId?: string // For dismissUpsell
  369. list?: string[] // For dismissedUpsells response
  370. organizationId?: string | null // For organization switching
  371. useProviderSignup?: boolean // For rooCloudSignIn to use provider signup flow
  372. historyItem?: HistoryItem // kilocode_change For addTaskToHistory
  373. codeIndexSettings?: {
  374. // Global state settings
  375. codebaseIndexEnabled: boolean
  376. codebaseIndexQdrantUrl: string
  377. codebaseIndexEmbedderProvider:
  378. | "openai"
  379. | "ollama"
  380. | "openai-compatible"
  381. | "gemini"
  382. | "mistral"
  383. | "vercel-ai-gateway"
  384. | "bedrock"
  385. | "openrouter"
  386. codebaseIndexVectorStoreProvider?: "lancedb" | "qdrant" // kilocode_change
  387. codebaseIndexLancedbVectorStoreDirectory?: string // kilocode_change
  388. codebaseIndexEmbedderBaseUrl?: string
  389. codebaseIndexEmbedderModelId: string
  390. codebaseIndexEmbedderModelDimension?: number // Generic dimension for all providers
  391. codebaseIndexOpenAiCompatibleBaseUrl?: string
  392. codebaseIndexBedrockRegion?: string
  393. codebaseIndexBedrockProfile?: string
  394. codebaseIndexSearchMaxResults?: number
  395. codebaseIndexSearchMinScore?: number
  396. // kilocode_change start
  397. codebaseIndexEmbeddingBatchSize?: number
  398. codebaseIndexScannerMaxBatchRetries?: number
  399. // kilocode_change end
  400. codebaseIndexOpenRouterSpecificProvider?: string // OpenRouter provider routing
  401. // Secret settings
  402. codeIndexOpenAiKey?: string
  403. codeIndexQdrantApiKey?: string
  404. codebaseIndexOpenAiCompatibleApiKey?: string
  405. codebaseIndexGeminiApiKey?: string
  406. codebaseIndexMistralApiKey?: string
  407. codebaseIndexVercelAiGatewayApiKey?: string
  408. codebaseIndexOpenRouterApiKey?: string
  409. }
  410. updatedSettings?: RooCodeSettings
  411. }
  412. // kilocode_change: Create discriminated union for type-safe messages
  413. export type MaybeTypedWebviewMessage = WebviewMessage | UpdateGlobalStateMessage
  414. // kilocode_change begin
  415. export type OrganizationRole = "owner" | "admin" | "member"
  416. export type UserOrganizationWithApiKey = {
  417. id: string
  418. name: string
  419. balance: number
  420. role: OrganizationRole
  421. apiKey: string
  422. }
  423. export type ProfileData = {
  424. kilocodeToken: string
  425. user: {
  426. id: string
  427. name: string
  428. email: string
  429. image: string
  430. }
  431. organizations?: UserOrganizationWithApiKey[]
  432. }
  433. export interface ProfileDataResponsePayload {
  434. success: boolean
  435. data?: ProfileData
  436. error?: string
  437. }
  438. export interface BalanceDataResponsePayload {
  439. // New: Payload for balance data
  440. success: boolean
  441. data?: any // Replace 'any' with a more specific type if known for balance
  442. error?: string
  443. }
  444. export interface SeeNewChangesPayload {
  445. commitRange: CommitRange
  446. }
  447. export interface TasksByIdRequestPayload {
  448. requestId: string
  449. taskIds: string[]
  450. }
  451. export interface TaskHistoryRequestPayload {
  452. requestId: string
  453. workspace: "current" | "all"
  454. sort: "newest" | "oldest" | "mostExpensive" | "mostTokens" | "mostRelevant"
  455. favoritesOnly: boolean
  456. pageIndex: number
  457. search?: string
  458. }
  459. export interface TasksByIdResponsePayload {
  460. requestId: string
  461. tasks: HistoryItem[]
  462. }
  463. export interface TaskHistoryResponsePayload {
  464. requestId: string
  465. historyItems: HistoryItem[]
  466. pageIndex: number
  467. pageCount: number
  468. }
  469. // kilocode_change end
  470. export const checkoutDiffPayloadSchema = z.object({
  471. ts: z.number().optional(),
  472. previousCommitHash: z.string().optional(),
  473. commitHash: z.string(),
  474. mode: z.enum(["full", "checkpoint", "from-init", "to-current"]),
  475. })
  476. export type CheckpointDiffPayload = z.infer<typeof checkoutDiffPayloadSchema>
  477. export const checkoutRestorePayloadSchema = z.object({
  478. ts: z.number(),
  479. commitHash: z.string(),
  480. mode: z.enum(["preview", "restore"]),
  481. })
  482. export type CheckpointRestorePayload = z.infer<typeof checkoutRestorePayloadSchema>
  483. export const requestCheckpointRestoreApprovalPayloadSchema = z.object({
  484. commitHash: z.string(),
  485. checkpointTs: z.number(),
  486. messagesToRemove: z.number(),
  487. confirmationText: z.string(),
  488. })
  489. export type RequestCheckpointRestoreApprovalPayload = z.infer<typeof requestCheckpointRestoreApprovalPayloadSchema>
  490. export interface IndexingStatusPayload {
  491. state: "Standby" | "Indexing" | "Indexed" | "Error"
  492. message: string
  493. }
  494. export interface IndexClearedPayload {
  495. success: boolean
  496. error?: string
  497. }
  498. export const installMarketplaceItemWithParametersPayloadSchema = z.object({
  499. item: marketplaceItemSchema,
  500. parameters: z.record(z.string(), z.any()),
  501. })
  502. export type InstallMarketplaceItemWithParametersPayload = z.infer<
  503. typeof installMarketplaceItemWithParametersPayloadSchema
  504. >
  505. export type WebViewMessagePayload =
  506. // kilocode_change start
  507. | ProfileDataResponsePayload
  508. | BalanceDataResponsePayload
  509. | SeeNewChangesPayload
  510. | TasksByIdRequestPayload
  511. | TaskHistoryRequestPayload
  512. | RequestCheckpointRestoreApprovalPayload
  513. // kilocode_change end
  514. | CheckpointDiffPayload
  515. | CheckpointRestorePayload
  516. | IndexingStatusPayload
  517. | IndexClearedPayload
  518. | InstallMarketplaceItemWithParametersPayload
  519. | UpdateTodoListPayload
  520. | EditQueuedMessagePayload