roo-code.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. import { EventEmitter } from "events"
  2. type ProviderSettings = {
  3. apiProvider?:
  4. | (
  5. | "anthropic"
  6. | "glama"
  7. | "openrouter"
  8. | "bedrock"
  9. | "vertex"
  10. | "openai"
  11. | "ollama"
  12. | "vscode-lm"
  13. | "lmstudio"
  14. | "gemini"
  15. | "openai-native"
  16. | "mistral"
  17. | "deepseek"
  18. | "unbound"
  19. | "requesty"
  20. | "human-relay"
  21. | "fake-ai"
  22. | "xai"
  23. )
  24. | undefined
  25. apiModelId?: string | undefined
  26. apiKey?: string | undefined
  27. anthropicBaseUrl?: string | undefined
  28. anthropicUseAuthToken?: boolean | undefined
  29. glamaModelId?: string | undefined
  30. glamaApiKey?: string | undefined
  31. openRouterApiKey?: string | undefined
  32. openRouterModelId?: string | undefined
  33. openRouterBaseUrl?: string | undefined
  34. openRouterSpecificProvider?: string | undefined
  35. openRouterUseMiddleOutTransform?: boolean | undefined
  36. awsAccessKey?: string | undefined
  37. awsSecretKey?: string | undefined
  38. awsSessionToken?: string | undefined
  39. awsRegion?: string | undefined
  40. awsUseCrossRegionInference?: boolean | undefined
  41. awsUsePromptCache?: boolean | undefined
  42. awspromptCacheId?: string | undefined
  43. awsProfile?: string | undefined
  44. awsUseProfile?: boolean | undefined
  45. awsCustomArn?: string | undefined
  46. vertexKeyFile?: string | undefined
  47. vertexJsonCredentials?: string | undefined
  48. vertexProjectId?: string | undefined
  49. vertexRegion?: string | undefined
  50. openAiBaseUrl?: string | undefined
  51. openAiApiKey?: string | undefined
  52. openAiHostHeader?: string | undefined
  53. openAiLegacyFormat?: boolean | undefined
  54. openAiR1FormatEnabled?: boolean | undefined
  55. openAiModelId?: string | undefined
  56. openAiCustomModelInfo?:
  57. | ({
  58. maxTokens?: (number | null) | undefined
  59. maxThinkingTokens?: (number | null) | undefined
  60. contextWindow: number
  61. supportsImages?: boolean | undefined
  62. supportsComputerUse?: boolean | undefined
  63. supportsPromptCache: boolean
  64. isPromptCacheOptional?: boolean | undefined
  65. inputPrice?: number | undefined
  66. outputPrice?: number | undefined
  67. cacheWritesPrice?: number | undefined
  68. cacheReadsPrice?: number | undefined
  69. description?: string | undefined
  70. reasoningEffort?: ("low" | "medium" | "high") | undefined
  71. thinking?: boolean | undefined
  72. minTokensPerCachePoint?: number | undefined
  73. maxCachePoints?: number | undefined
  74. cachableFields?: string[] | undefined
  75. tiers?:
  76. | {
  77. contextWindow: number
  78. inputPrice?: number | undefined
  79. outputPrice?: number | undefined
  80. cacheWritesPrice?: number | undefined
  81. cacheReadsPrice?: number | undefined
  82. }[]
  83. | undefined
  84. } | null)
  85. | undefined
  86. openAiUseAzure?: boolean | undefined
  87. azureApiVersion?: string | undefined
  88. openAiStreamingEnabled?: boolean | undefined
  89. ollamaModelId?: string | undefined
  90. ollamaBaseUrl?: string | undefined
  91. vsCodeLmModelSelector?:
  92. | {
  93. vendor?: string | undefined
  94. family?: string | undefined
  95. version?: string | undefined
  96. id?: string | undefined
  97. }
  98. | undefined
  99. lmStudioModelId?: string | undefined
  100. lmStudioBaseUrl?: string | undefined
  101. lmStudioDraftModelId?: string | undefined
  102. lmStudioSpeculativeDecodingEnabled?: boolean | undefined
  103. geminiApiKey?: string | undefined
  104. googleGeminiBaseUrl?: string | undefined
  105. openAiNativeApiKey?: string | undefined
  106. mistralApiKey?: string | undefined
  107. mistralCodestralUrl?: string | undefined
  108. deepSeekBaseUrl?: string | undefined
  109. deepSeekApiKey?: string | undefined
  110. unboundApiKey?: string | undefined
  111. unboundModelId?: string | undefined
  112. requestyApiKey?: string | undefined
  113. requestyModelId?: string | undefined
  114. xaiApiKey?: string | undefined
  115. modelMaxTokens?: number | undefined
  116. modelMaxThinkingTokens?: number | undefined
  117. includeMaxTokens?: boolean | undefined
  118. reasoningEffort?: ("low" | "medium" | "high") | undefined
  119. promptCachingEnabled?: boolean | undefined
  120. diffEnabled?: boolean | undefined
  121. fuzzyMatchThreshold?: number | undefined
  122. modelTemperature?: (number | null) | undefined
  123. rateLimitSeconds?: number | undefined
  124. fakeAi?: unknown | undefined
  125. }
  126. type GlobalSettings = {
  127. currentApiConfigName?: string | undefined
  128. listApiConfigMeta?:
  129. | {
  130. id: string
  131. name: string
  132. apiProvider?:
  133. | (
  134. | "anthropic"
  135. | "glama"
  136. | "openrouter"
  137. | "bedrock"
  138. | "vertex"
  139. | "openai"
  140. | "ollama"
  141. | "vscode-lm"
  142. | "lmstudio"
  143. | "gemini"
  144. | "openai-native"
  145. | "mistral"
  146. | "deepseek"
  147. | "unbound"
  148. | "requesty"
  149. | "human-relay"
  150. | "fake-ai"
  151. | "xai"
  152. )
  153. | undefined
  154. }[]
  155. | undefined
  156. pinnedApiConfigs?:
  157. | {
  158. [x: string]: boolean
  159. }
  160. | undefined
  161. lastShownAnnouncementId?: string | undefined
  162. customInstructions?: string | undefined
  163. taskHistory?:
  164. | {
  165. id: string
  166. number: number
  167. ts: number
  168. task: string
  169. tokensIn: number
  170. tokensOut: number
  171. cacheWrites?: number | undefined
  172. cacheReads?: number | undefined
  173. totalCost: number
  174. size?: number | undefined
  175. workspace?: string | undefined
  176. }[]
  177. | undefined
  178. autoApprovalEnabled?: boolean | undefined
  179. alwaysAllowReadOnly?: boolean | undefined
  180. alwaysAllowReadOnlyOutsideWorkspace?: boolean | undefined
  181. alwaysAllowWrite?: boolean | undefined
  182. alwaysAllowWriteOutsideWorkspace?: boolean | undefined
  183. writeDelayMs?: number | undefined
  184. alwaysAllowBrowser?: boolean | undefined
  185. alwaysApproveResubmit?: boolean | undefined
  186. requestDelaySeconds?: number | undefined
  187. alwaysAllowMcp?: boolean | undefined
  188. alwaysAllowModeSwitch?: boolean | undefined
  189. alwaysAllowSubtasks?: boolean | undefined
  190. alwaysAllowExecute?: boolean | undefined
  191. allowedCommands?: string[] | undefined
  192. browserToolEnabled?: boolean | undefined
  193. browserViewportSize?: string | undefined
  194. screenshotQuality?: number | undefined
  195. remoteBrowserEnabled?: boolean | undefined
  196. remoteBrowserHost?: string | undefined
  197. cachedChromeHostUrl?: string | undefined
  198. enableCheckpoints?: boolean | undefined
  199. ttsEnabled?: boolean | undefined
  200. ttsSpeed?: number | undefined
  201. soundEnabled?: boolean | undefined
  202. soundVolume?: number | undefined
  203. maxOpenTabsContext?: number | undefined
  204. maxWorkspaceFiles?: number | undefined
  205. showRooIgnoredFiles?: boolean | undefined
  206. maxReadFileLine?: number | undefined
  207. terminalOutputLineLimit?: number | undefined
  208. terminalShellIntegrationTimeout?: number | undefined
  209. terminalShellIntegrationDisabled?: boolean | undefined
  210. terminalCommandDelay?: number | undefined
  211. terminalPowershellCounter?: boolean | undefined
  212. terminalZshClearEolMark?: boolean | undefined
  213. terminalZshOhMy?: boolean | undefined
  214. terminalZshP10k?: boolean | undefined
  215. terminalZdotdir?: boolean | undefined
  216. terminalCompressProgressBar?: boolean | undefined
  217. rateLimitSeconds?: number | undefined
  218. diffEnabled?: boolean | undefined
  219. fuzzyMatchThreshold?: number | undefined
  220. experiments?:
  221. | {
  222. powerSteering: boolean
  223. }
  224. | undefined
  225. language?:
  226. | (
  227. | "ca"
  228. | "de"
  229. | "en"
  230. | "es"
  231. | "fr"
  232. | "hi"
  233. | "it"
  234. | "ja"
  235. | "ko"
  236. | "pl"
  237. | "pt-BR"
  238. | "ru"
  239. | "tr"
  240. | "vi"
  241. | "zh-CN"
  242. | "zh-TW"
  243. )
  244. | undefined
  245. telemetrySetting?: ("unset" | "enabled" | "disabled") | undefined
  246. mcpEnabled?: boolean | undefined
  247. enableMcpServerCreation?: boolean | undefined
  248. mode?: string | undefined
  249. modeApiConfigs?:
  250. | {
  251. [x: string]: string
  252. }
  253. | undefined
  254. customModes?:
  255. | {
  256. slug: string
  257. name: string
  258. roleDefinition: string
  259. customInstructions?: string | undefined
  260. groups: (
  261. | ("read" | "edit" | "browser" | "command" | "mcp" | "modes")
  262. | [
  263. "read" | "edit" | "browser" | "command" | "mcp" | "modes",
  264. {
  265. fileRegex?: string | undefined
  266. description?: string | undefined
  267. },
  268. ]
  269. )[]
  270. source?: ("global" | "project") | undefined
  271. }[]
  272. | undefined
  273. customModePrompts?:
  274. | {
  275. [x: string]:
  276. | {
  277. roleDefinition?: string | undefined
  278. customInstructions?: string | undefined
  279. }
  280. | undefined
  281. }
  282. | undefined
  283. customSupportPrompts?:
  284. | {
  285. [x: string]: string | undefined
  286. }
  287. | undefined
  288. enhancementApiConfigId?: string | undefined
  289. historyPreviewCollapsed?: boolean | undefined
  290. }
  291. type ClineMessage = {
  292. ts: number
  293. type: "ask" | "say"
  294. ask?:
  295. | (
  296. | "followup"
  297. | "command"
  298. | "command_output"
  299. | "completion_result"
  300. | "tool"
  301. | "api_req_failed"
  302. | "resume_task"
  303. | "resume_completed_task"
  304. | "mistake_limit_reached"
  305. | "browser_action_launch"
  306. | "use_mcp_server"
  307. | "finishTask"
  308. )
  309. | undefined
  310. say?:
  311. | (
  312. | "task"
  313. | "error"
  314. | "api_req_started"
  315. | "api_req_finished"
  316. | "api_req_retried"
  317. | "api_req_retry_delayed"
  318. | "api_req_deleted"
  319. | "text"
  320. | "reasoning"
  321. | "completion_result"
  322. | "user_feedback"
  323. | "user_feedback_diff"
  324. | "command_output"
  325. | "tool"
  326. | "shell_integration_warning"
  327. | "browser_action"
  328. | "browser_action_result"
  329. | "command"
  330. | "mcp_server_request_started"
  331. | "mcp_server_response"
  332. | "new_task_started"
  333. | "new_task"
  334. | "subtask_result"
  335. | "checkpoint_saved"
  336. | "rooignore_error"
  337. | "diff_error"
  338. )
  339. | undefined
  340. text?: string | undefined
  341. images?: string[] | undefined
  342. partial?: boolean | undefined
  343. reasoning?: string | undefined
  344. conversationHistoryIndex?: number | undefined
  345. checkpoint?:
  346. | {
  347. [x: string]: unknown
  348. }
  349. | undefined
  350. progressStatus?:
  351. | {
  352. icon?: string | undefined
  353. text?: string | undefined
  354. }
  355. | undefined
  356. }
  357. type TokenUsage = {
  358. totalTokensIn: number
  359. totalTokensOut: number
  360. totalCacheWrites?: number | undefined
  361. totalCacheReads?: number | undefined
  362. totalCost: number
  363. contextTokens: number
  364. }
  365. type RooCodeEvents = {
  366. message: [
  367. {
  368. taskId: string
  369. action: "created" | "updated"
  370. message: {
  371. ts: number
  372. type: "ask" | "say"
  373. ask?:
  374. | (
  375. | "followup"
  376. | "command"
  377. | "command_output"
  378. | "completion_result"
  379. | "tool"
  380. | "api_req_failed"
  381. | "resume_task"
  382. | "resume_completed_task"
  383. | "mistake_limit_reached"
  384. | "browser_action_launch"
  385. | "use_mcp_server"
  386. | "finishTask"
  387. )
  388. | undefined
  389. say?:
  390. | (
  391. | "task"
  392. | "error"
  393. | "api_req_started"
  394. | "api_req_finished"
  395. | "api_req_retried"
  396. | "api_req_retry_delayed"
  397. | "api_req_deleted"
  398. | "text"
  399. | "reasoning"
  400. | "completion_result"
  401. | "user_feedback"
  402. | "user_feedback_diff"
  403. | "command_output"
  404. | "tool"
  405. | "shell_integration_warning"
  406. | "browser_action"
  407. | "browser_action_result"
  408. | "command"
  409. | "mcp_server_request_started"
  410. | "mcp_server_response"
  411. | "new_task_started"
  412. | "new_task"
  413. | "subtask_result"
  414. | "checkpoint_saved"
  415. | "rooignore_error"
  416. | "diff_error"
  417. )
  418. | undefined
  419. text?: string | undefined
  420. images?: string[] | undefined
  421. partial?: boolean | undefined
  422. reasoning?: string | undefined
  423. conversationHistoryIndex?: number | undefined
  424. checkpoint?:
  425. | {
  426. [x: string]: unknown
  427. }
  428. | undefined
  429. progressStatus?:
  430. | {
  431. icon?: string | undefined
  432. text?: string | undefined
  433. }
  434. | undefined
  435. }
  436. },
  437. ]
  438. taskCreated: [string]
  439. taskStarted: [string]
  440. taskModeSwitched: [string, string]
  441. taskPaused: [string]
  442. taskUnpaused: [string]
  443. taskAskResponded: [string]
  444. taskAborted: [string]
  445. taskSpawned: [string, string]
  446. taskCompleted: [
  447. string,
  448. {
  449. totalTokensIn: number
  450. totalTokensOut: number
  451. totalCacheWrites?: number | undefined
  452. totalCacheReads?: number | undefined
  453. totalCost: number
  454. contextTokens: number
  455. },
  456. {
  457. [x: string]: {
  458. attempts: number
  459. failures: number
  460. }
  461. },
  462. ]
  463. taskTokenUsageUpdated: [
  464. string,
  465. {
  466. totalTokensIn: number
  467. totalTokensOut: number
  468. totalCacheWrites?: number | undefined
  469. totalCacheReads?: number | undefined
  470. totalCost: number
  471. contextTokens: number
  472. },
  473. ]
  474. taskToolFailed: [
  475. string,
  476. (
  477. | "execute_command"
  478. | "read_file"
  479. | "write_to_file"
  480. | "apply_diff"
  481. | "insert_content"
  482. | "search_and_replace"
  483. | "search_files"
  484. | "list_files"
  485. | "list_code_definition_names"
  486. | "browser_action"
  487. | "use_mcp_tool"
  488. | "access_mcp_resource"
  489. | "ask_followup_question"
  490. | "attempt_completion"
  491. | "switch_mode"
  492. | "new_task"
  493. | "fetch_instructions"
  494. ),
  495. string,
  496. ]
  497. }
  498. /**
  499. * RooCodeEvent
  500. */
  501. declare enum RooCodeEventName {
  502. Message = "message",
  503. TaskCreated = "taskCreated",
  504. TaskStarted = "taskStarted",
  505. TaskModeSwitched = "taskModeSwitched",
  506. TaskPaused = "taskPaused",
  507. TaskUnpaused = "taskUnpaused",
  508. TaskAskResponded = "taskAskResponded",
  509. TaskAborted = "taskAborted",
  510. TaskSpawned = "taskSpawned",
  511. TaskCompleted = "taskCompleted",
  512. TaskTokenUsageUpdated = "taskTokenUsageUpdated",
  513. TaskToolFailed = "taskToolFailed",
  514. }
  515. type RooCodeSettings = GlobalSettings & ProviderSettings
  516. interface RooCodeAPI extends EventEmitter<RooCodeEvents> {
  517. /**
  518. * Starts a new task with an optional initial message and images.
  519. * @param task Optional initial task message.
  520. * @param images Optional array of image data URIs (e.g., "data:image/webp;base64,...").
  521. * @returns The ID of the new task.
  522. */
  523. startNewTask({
  524. configuration,
  525. text,
  526. images,
  527. newTab,
  528. }: {
  529. configuration?: RooCodeSettings
  530. text?: string
  531. images?: string[]
  532. newTab?: boolean
  533. }): Promise<string>
  534. /**
  535. * Resumes a task with the given ID.
  536. * @param taskId The ID of the task to resume.
  537. * @throws Error if the task is not found in the task history.
  538. */
  539. resumeTask(taskId: string): Promise<void>
  540. /**
  541. * Checks if a task with the given ID is in the task history.
  542. * @param taskId The ID of the task to check.
  543. * @returns True if the task is in the task history, false otherwise.
  544. */
  545. isTaskInHistory(taskId: string): Promise<boolean>
  546. /**
  547. * Returns the current task stack.
  548. * @returns An array of task IDs.
  549. */
  550. getCurrentTaskStack(): string[]
  551. /**
  552. * Clears the current task.
  553. */
  554. clearCurrentTask(lastMessage?: string): Promise<void>
  555. /**
  556. * Cancels the current task.
  557. */
  558. cancelCurrentTask(): Promise<void>
  559. /**
  560. * Sends a message to the current task.
  561. * @param message Optional message to send.
  562. * @param images Optional array of image data URIs (e.g., "data:image/webp;base64,...").
  563. */
  564. sendMessage(message?: string, images?: string[]): Promise<void>
  565. /**
  566. * Simulates pressing the primary button in the chat interface.
  567. */
  568. pressPrimaryButton(): Promise<void>
  569. /**
  570. * Simulates pressing the secondary button in the chat interface.
  571. */
  572. pressSecondaryButton(): Promise<void>
  573. /**
  574. * Returns the current configuration.
  575. * @returns The current configuration.
  576. */
  577. getConfiguration(): RooCodeSettings
  578. /**
  579. * Sets the configuration for the current task.
  580. * @param values An object containing key-value pairs to set.
  581. */
  582. setConfiguration(values: RooCodeSettings): Promise<void>
  583. /**
  584. * Creates a new API configuration profile
  585. * @param name The name of the profile
  586. * @returns The ID of the created profile
  587. */
  588. createProfile(name: string): Promise<string>
  589. /**
  590. * Returns a list of all configured profile names
  591. * @returns Array of profile names
  592. */
  593. getProfiles(): string[]
  594. /**
  595. * Changes the active API configuration profile
  596. * @param name The name of the profile to activate
  597. * @throws Error if the profile does not exist
  598. */
  599. setActiveProfile(name: string): Promise<void>
  600. /**
  601. * Returns the name of the currently active profile
  602. * @returns The profile name, or undefined if no profile is active
  603. */
  604. getActiveProfile(): string | undefined
  605. /**
  606. * Deletes a profile by name
  607. * @param name The name of the profile to delete
  608. * @throws Error if the profile does not exist
  609. */
  610. deleteProfile(name: string): Promise<void>
  611. /**
  612. * Returns true if the API is ready to use.
  613. */
  614. isReady(): boolean
  615. }
  616. export {
  617. type ClineMessage,
  618. type GlobalSettings,
  619. type ProviderSettings,
  620. type RooCodeAPI,
  621. RooCodeEventName,
  622. type RooCodeEvents,
  623. type RooCodeSettings,
  624. type TokenUsage,
  625. }