mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
Rename ClineAPI to RooCodeAPI and improve types
This commit is contained in:
parent
224303660b
commit
f8a592aac9
10 changed files with 119 additions and 133 deletions
|
|
@ -19,5 +19,5 @@
|
|||
"no-throw-literal": "warn",
|
||||
"semi": "off"
|
||||
},
|
||||
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
|
||||
"ignorePatterns": ["out", "dist", "**/*.d.ts", "!roo-code.d.ts"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,9 +58,9 @@ The following global objects are available in tests:
|
|||
|
||||
```typescript
|
||||
declare global {
|
||||
var api: ClineAPI
|
||||
var api: RooCodeAPI
|
||||
var provider: ClineProvider
|
||||
var extension: vscode.Extension<ClineAPI>
|
||||
var extension: vscode.Extension<RooCodeAPI>
|
||||
var panel: vscode.WebviewPanel
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import * as path from "path"
|
||||
import Mocha from "mocha"
|
||||
import { glob } from "glob"
|
||||
import { ClineAPI, ClineProvider } from "../../../src/exports/cline"
|
||||
import { RooCodeAPI, ClineProvider } from "../../../src/exports/roo-code"
|
||||
import * as vscode from "vscode"
|
||||
|
||||
declare global {
|
||||
var api: ClineAPI
|
||||
var api: RooCodeAPI
|
||||
var provider: ClineProvider
|
||||
var extension: vscode.Extension<ClineAPI> | undefined
|
||||
var extension: vscode.Extension<RooCodeAPI> | undefined
|
||||
var panel: vscode.WebviewPanel | undefined
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,6 @@
|
|||
"useUnknownInCatchVariables": false,
|
||||
"outDir": "out"
|
||||
},
|
||||
"include": ["src", "../src/exports/cline.d.ts"],
|
||||
"include": ["src", "../src/exports/roo-code.d.ts"],
|
||||
"exclude": [".vscode-test", "**/node_modules/**", "out"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
import * as vscode from "vscode"
|
||||
import { ClineProvider } from "../core/webview/ClineProvider"
|
||||
import { ClineAPI } from "./cline"
|
||||
|
||||
export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvider: ClineProvider): ClineAPI {
|
||||
const api: ClineAPI = {
|
||||
import { ClineProvider } from "../core/webview/ClineProvider"
|
||||
|
||||
import { RooCodeAPI } from "../exports/roo-code"
|
||||
|
||||
export function createRooCodeAPI(outputChannel: vscode.OutputChannel, sidebarProvider: ClineProvider): RooCodeAPI {
|
||||
return {
|
||||
setCustomInstructions: async (value: string) => {
|
||||
await sidebarProvider.updateCustomInstructions(value)
|
||||
outputChannel.appendLine("Custom instructions set")
|
||||
|
|
@ -24,6 +26,7 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi
|
|||
text: task,
|
||||
images: images,
|
||||
})
|
||||
|
||||
outputChannel.appendLine(
|
||||
`Task started with message: ${task ? `"${task}"` : "undefined"} and ${images?.length || 0} image(s)`,
|
||||
)
|
||||
|
|
@ -33,6 +36,7 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi
|
|||
outputChannel.appendLine(
|
||||
`Sending message: ${message ? `"${message}"` : "undefined"} with ${images?.length || 0} image(s)`,
|
||||
)
|
||||
|
||||
await sidebarProvider.postMessageToWebview({
|
||||
type: "invoke",
|
||||
invoke: "sendMessage",
|
||||
|
|
@ -43,22 +47,14 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi
|
|||
|
||||
pressPrimaryButton: async () => {
|
||||
outputChannel.appendLine("Pressing primary button")
|
||||
await sidebarProvider.postMessageToWebview({
|
||||
type: "invoke",
|
||||
invoke: "primaryButtonClick",
|
||||
})
|
||||
await sidebarProvider.postMessageToWebview({ type: "invoke", invoke: "primaryButtonClick" })
|
||||
},
|
||||
|
||||
pressSecondaryButton: async () => {
|
||||
outputChannel.appendLine("Pressing secondary button")
|
||||
await sidebarProvider.postMessageToWebview({
|
||||
type: "invoke",
|
||||
invoke: "secondaryButtonClick",
|
||||
})
|
||||
await sidebarProvider.postMessageToWebview({ type: "invoke", invoke: "secondaryButtonClick" })
|
||||
},
|
||||
|
||||
sidebarProvider: sidebarProvider,
|
||||
}
|
||||
|
||||
return api
|
||||
}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
export { handleUri } from "./handleUri"
|
||||
export { registerCommands } from "./registerCommands"
|
||||
export { registerCodeActions } from "./registerCodeActions"
|
||||
export { createRooCodeAPI } from "./createRooCodeAPI"
|
||||
|
|
|
|||
|
|
@ -1,55 +1,51 @@
|
|||
# Cline API
|
||||
# Roo Code API
|
||||
|
||||
The Cline extension exposes an API that can be used by other extensions. To use this API in your extension:
|
||||
The Roo Code extension exposes an API that can be used by other extensions. To use this API in your extension:
|
||||
|
||||
1. Copy `src/extension-api/cline.d.ts` to your extension's source directory.
|
||||
2. Include `cline.d.ts` in your extension's compilation.
|
||||
1. Copy `src/extension-api/roo-code.d.ts` to your extension's source directory.
|
||||
2. Include `roo-code.d.ts` in your extension's compilation.
|
||||
3. Get access to the API with the following code:
|
||||
|
||||
```ts
|
||||
const clineExtension = vscode.extensions.getExtension<ClineAPI>("rooveterinaryinc.roo-cline")
|
||||
```typescript
|
||||
const extension = vscode.extensions.getExtension<RooCodeAPI>("rooveterinaryinc.roo-cline")
|
||||
|
||||
if (!clineExtension?.isActive) {
|
||||
throw new Error("Cline extension is not activated")
|
||||
}
|
||||
if (!extension?.isActive) {
|
||||
throw new Error("Extension is not activated")
|
||||
}
|
||||
|
||||
const cline = clineExtension.exports
|
||||
const api = extension.exports
|
||||
|
||||
if (cline) {
|
||||
// Now you can use the API
|
||||
if (!api) {
|
||||
throw new Error("API is not available")
|
||||
}
|
||||
|
||||
// Set custom instructions
|
||||
await cline.setCustomInstructions("Talk like a pirate")
|
||||
// Set custom instructions.
|
||||
await api.setCustomInstructions("Talk like a pirate")
|
||||
|
||||
// Get custom instructions
|
||||
const instructions = await cline.getCustomInstructions()
|
||||
console.log("Current custom instructions:", instructions)
|
||||
// Get custom instructions.
|
||||
const instructions = await api.getCustomInstructions()
|
||||
console.log("Current custom instructions:", instructions)
|
||||
|
||||
// Start a new task with an initial message
|
||||
await cline.startNewTask("Hello, Cline! Let's make a new project...")
|
||||
// Start a new task with an initial message.
|
||||
await api.startNewTask("Hello, Cline! Let's make a new project...")
|
||||
|
||||
// Start a new task with an initial message and images
|
||||
await cline.startNewTask("Use this design language", ["data:image/webp;base64,..."])
|
||||
// Start a new task with an initial message and images.
|
||||
await api.startNewTask("Use this design language", ["data:image/webp;base64,..."])
|
||||
|
||||
// Send a message to the current task
|
||||
await cline.sendMessage("Can you fix the @problems?")
|
||||
// Send a message to the current task.
|
||||
await api.sendMessage("Can you fix the @problems?")
|
||||
|
||||
// Simulate pressing the primary button in the chat interface (e.g. 'Save' or 'Proceed While Running')
|
||||
await cline.pressPrimaryButton()
|
||||
// Simulate pressing the primary button in the chat interface (e.g. 'Save' or 'Proceed While Running').
|
||||
await api.pressPrimaryButton()
|
||||
|
||||
// Simulate pressing the secondary button in the chat interface (e.g. 'Reject')
|
||||
await cline.pressSecondaryButton()
|
||||
} else {
|
||||
console.error("Cline API is not available")
|
||||
}
|
||||
```
|
||||
// Simulate pressing the secondary button in the chat interface (e.g. 'Reject').
|
||||
await api.pressSecondaryButton()
|
||||
```
|
||||
|
||||
**Note:** To ensure that the `rooveterinaryinc.roo-cline` extension is activated before your extension, add it to the `extensionDependencies` in your `package.json`:
|
||||
**NOTE:** To ensure that the `rooveterinaryinc.roo-cline` extension is activated before your extension, add it to the `extensionDependencies` in your `package.json`:
|
||||
|
||||
```json
|
||||
"extensionDependencies": [
|
||||
"rooveterinaryinc.roo-cline"
|
||||
]
|
||||
```
|
||||
```json
|
||||
"extensionDependencies": ["rooveterinaryinc.roo-cline"]
|
||||
```
|
||||
|
||||
For detailed information on the available methods and their usage, refer to the `cline.d.ts` file.
|
||||
For detailed information on the available methods and their usage, refer to the `roo-code.d.ts` file.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
export interface ClineAPI {
|
||||
export interface RooCodeAPI {
|
||||
/**
|
||||
* Sets the custom instructions in the global storage.
|
||||
* @param value The custom instructions to be saved.
|
||||
|
|
@ -38,7 +38,60 @@ export interface ClineAPI {
|
|||
/**
|
||||
* The sidebar provider instance.
|
||||
*/
|
||||
sidebarProvider: ClineSidebarProvider
|
||||
sidebarProvider: ClineProvider
|
||||
}
|
||||
|
||||
export type ClineAsk =
|
||||
| "followup"
|
||||
| "command"
|
||||
| "command_output"
|
||||
| "completion_result"
|
||||
| "tool"
|
||||
| "api_req_failed"
|
||||
| "resume_task"
|
||||
| "resume_completed_task"
|
||||
| "mistake_limit_reached"
|
||||
| "browser_action_launch"
|
||||
| "use_mcp_server"
|
||||
| "finishTask"
|
||||
|
||||
export type ClineSay =
|
||||
| "task"
|
||||
| "error"
|
||||
| "api_req_started"
|
||||
| "api_req_finished"
|
||||
| "api_req_retried"
|
||||
| "api_req_retry_delayed"
|
||||
| "api_req_deleted"
|
||||
| "text"
|
||||
| "reasoning"
|
||||
| "completion_result"
|
||||
| "user_feedback"
|
||||
| "user_feedback_diff"
|
||||
| "command_output"
|
||||
| "tool"
|
||||
| "shell_integration_warning"
|
||||
| "browser_action"
|
||||
| "browser_action_result"
|
||||
| "command"
|
||||
| "mcp_server_request_started"
|
||||
| "mcp_server_response"
|
||||
| "new_task_started"
|
||||
| "new_task"
|
||||
| "checkpoint_saved"
|
||||
| "rooignore_error"
|
||||
|
||||
export interface ClineMessage {
|
||||
ts: number
|
||||
type: "ask" | "say"
|
||||
ask?: ClineAsk
|
||||
say?: ClineSay
|
||||
text?: string
|
||||
images?: string[]
|
||||
partial?: boolean
|
||||
reasoning?: string
|
||||
conversationHistoryIndex?: number
|
||||
checkpoint?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface ClineProvider {
|
||||
|
|
@ -82,11 +135,6 @@ export interface ClineProvider {
|
|||
*/
|
||||
cancelTask(): Promise<void>
|
||||
|
||||
/**
|
||||
* Clears the current task
|
||||
*/
|
||||
clearTask(): Promise<void>
|
||||
|
||||
/**
|
||||
* Gets the current state
|
||||
*/
|
||||
|
|
@ -112,12 +160,6 @@ export interface ClineProvider {
|
|||
*/
|
||||
storeSecret(key: SecretKey, value?: string): Promise<void>
|
||||
|
||||
/**
|
||||
* Retrieves a secret value from secure storage
|
||||
* @param key The key of the secret to retrieve
|
||||
*/
|
||||
getSecret(key: SecretKey): Promise<string | undefined>
|
||||
|
||||
/**
|
||||
* Resets the state
|
||||
*/
|
||||
|
|
@ -11,15 +11,16 @@ try {
|
|||
console.warn("Failed to load environment variables:", e)
|
||||
}
|
||||
|
||||
import { ClineProvider } from "./core/webview/ClineProvider"
|
||||
import { createClineAPI } from "./exports"
|
||||
import "./utils/path" // Necessary to have access to String.prototype.toPosix.
|
||||
|
||||
import { ClineProvider } from "./core/webview/ClineProvider"
|
||||
import { CodeActionProvider } from "./core/CodeActionProvider"
|
||||
import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
|
||||
import { handleUri, registerCommands, registerCodeActions } from "./activate"
|
||||
import { McpServerManager } from "./services/mcp/McpServerManager"
|
||||
import { telemetryService } from "./services/telemetry/TelemetryService"
|
||||
|
||||
import { handleUri, registerCommands, registerCodeActions, createRooCodeAPI } from "./activate"
|
||||
|
||||
/**
|
||||
* Built using https://github.com/microsoft/vscode-webview-ui-toolkit
|
||||
*
|
||||
|
|
@ -143,7 +144,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
|
||||
registerCodeActions(context)
|
||||
|
||||
return createClineAPI(outputChannel, sidebarProvider)
|
||||
return createRooCodeAPI(outputChannel, sidebarProvider)
|
||||
}
|
||||
|
||||
// This method is called when your extension is deactivated.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// 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'
|
||||
|
||||
import { ApiConfiguration, ApiProvider, ModelInfo } from "./api"
|
||||
import { HistoryItem } from "./HistoryItem"
|
||||
import { McpServer } from "./mcp"
|
||||
|
|
@ -9,6 +7,7 @@ import { CustomSupportPrompts } from "./support-prompt"
|
|||
import { ExperimentId } from "./experiments"
|
||||
import { CheckpointStorage } from "./checkpoints"
|
||||
import { TelemetrySetting } from "./TelemetrySetting"
|
||||
import { ClineMessage, ClineAsk, ClineSay } from "../exports/roo-code"
|
||||
|
||||
export interface LanguageModelChatSelector {
|
||||
vendor?: string
|
||||
|
|
@ -17,7 +16,9 @@ export interface LanguageModelChatSelector {
|
|||
id?: string
|
||||
}
|
||||
|
||||
// webview will hold state
|
||||
// Represents JSON data that is sent from extension to webview, called
|
||||
// ExtensionMessage and has 'type' enum which can be 'plusButtonClicked' or
|
||||
// 'settingsButtonClicked' or 'hello'. Webview will hold state.
|
||||
export interface ExtensionMessage {
|
||||
type:
|
||||
| "action"
|
||||
|
|
@ -145,58 +146,7 @@ export interface ExtensionState {
|
|||
showRooIgnoredFiles: boolean // Whether to show .rooignore'd files in listings
|
||||
}
|
||||
|
||||
export interface ClineMessage {
|
||||
ts: number
|
||||
type: "ask" | "say"
|
||||
ask?: ClineAsk
|
||||
say?: ClineSay
|
||||
text?: string
|
||||
images?: string[]
|
||||
partial?: boolean
|
||||
reasoning?: string
|
||||
conversationHistoryIndex?: number
|
||||
checkpoint?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export type ClineAsk =
|
||||
| "followup"
|
||||
| "command"
|
||||
| "command_output"
|
||||
| "completion_result"
|
||||
| "tool"
|
||||
| "api_req_failed"
|
||||
| "resume_task"
|
||||
| "resume_completed_task"
|
||||
| "mistake_limit_reached"
|
||||
| "browser_action_launch"
|
||||
| "use_mcp_server"
|
||||
| "finishTask"
|
||||
|
||||
export type ClineSay =
|
||||
| "task"
|
||||
| "error"
|
||||
| "api_req_started"
|
||||
| "api_req_finished"
|
||||
| "api_req_retried"
|
||||
| "api_req_retry_delayed"
|
||||
| "api_req_deleted"
|
||||
| "text"
|
||||
| "reasoning"
|
||||
| "completion_result"
|
||||
| "user_feedback"
|
||||
| "user_feedback_diff"
|
||||
| "command_output"
|
||||
| "tool"
|
||||
| "shell_integration_warning"
|
||||
| "browser_action"
|
||||
| "browser_action_result"
|
||||
| "command"
|
||||
| "mcp_server_request_started"
|
||||
| "mcp_server_response"
|
||||
| "new_task_started"
|
||||
| "new_task"
|
||||
| "checkpoint_saved"
|
||||
| "rooignore_error"
|
||||
export type { ClineMessage, ClineAsk, ClineSay }
|
||||
|
||||
export interface ClineSayTool {
|
||||
tool:
|
||||
|
|
@ -220,8 +170,9 @@ export interface ClineSayTool {
|
|||
reason?: string
|
||||
}
|
||||
|
||||
// must keep in sync with system prompt
|
||||
// Must keep in sync with system prompt.
|
||||
export const browserActions = ["launch", "click", "type", "scroll_down", "scroll_up", "close"] as const
|
||||
|
||||
export type BrowserAction = (typeof browserActions)[number]
|
||||
|
||||
export interface ClineSayBrowserAction {
|
||||
|
|
@ -256,7 +207,6 @@ export interface ClineApiReqInfo {
|
|||
streamingFailedMessage?: string
|
||||
}
|
||||
|
||||
// Human relay related message types
|
||||
export interface ShowHumanRelayDialogMessage {
|
||||
type: "showHumanRelayDialog"
|
||||
requestId: string
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue