Skip to content

Commit edb53bf

Browse files
authored
Merge pull request RooCodeInc#1546 from RooVetGit/cte/roo-code-api
Rename ClineAPI to RooCodeAPI and improve types
2 parents 33f232a + 90a607f commit edb53bf

File tree

10 files changed

+115
-131
lines changed

10 files changed

+115
-131
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
"no-throw-literal": "warn",
2020
"semi": "off"
2121
},
22-
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
22+
"ignorePatterns": ["out", "dist", "**/*.d.ts", "!roo-code.d.ts"]
2323
}

e2e/VSCODE_INTEGRATION_TESTS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ The following global objects are available in tests:
5858

5959
```typescript
6060
declare global {
61-
var api: ClineAPI
61+
var api: RooCodeAPI
6262
var provider: ClineProvider
63-
var extension: vscode.Extension<ClineAPI>
63+
var extension: vscode.Extension<RooCodeAPI>
6464
var panel: vscode.WebviewPanel
6565
}
6666
```

e2e/src/suite/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as path from "path"
22
import Mocha from "mocha"
33
import { glob } from "glob"
4-
import { ClineAPI, ClineProvider } from "../../../src/exports/cline"
4+
import { RooCodeAPI, ClineProvider } from "../../../src/exports/roo-code"
55
import * as vscode from "vscode"
66

77
declare global {
8-
var api: ClineAPI
8+
var api: RooCodeAPI
99
var provider: ClineProvider
10-
var extension: vscode.Extension<ClineAPI> | undefined
10+
var extension: vscode.Extension<RooCodeAPI> | undefined
1111
var panel: vscode.WebviewPanel | undefined
1212
}
1313

e2e/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"useUnknownInCatchVariables": false,
1212
"outDir": "out"
1313
},
14-
"include": ["src", "../src/exports/cline.d.ts"],
14+
"include": ["src", "../src/exports/roo-code.d.ts"],
1515
"exclude": [".vscode-test", "**/node_modules/**", "out"]
1616
}

src/exports/index.ts renamed to src/activate/createRooCodeAPI.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as vscode from "vscode"
2+
23
import { ClineProvider } from "../core/webview/ClineProvider"
3-
import { ClineAPI } from "./cline"
44

5-
export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvider: ClineProvider): ClineAPI {
6-
const api: ClineAPI = {
5+
import { RooCodeAPI } from "../exports/roo-code"
6+
7+
export function createRooCodeAPI(outputChannel: vscode.OutputChannel, sidebarProvider: ClineProvider): RooCodeAPI {
8+
return {
79
setCustomInstructions: async (value: string) => {
810
await sidebarProvider.updateCustomInstructions(value)
911
outputChannel.appendLine("Custom instructions set")
@@ -24,6 +26,7 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi
2426
text: task,
2527
images: images,
2628
})
29+
2730
outputChannel.appendLine(
2831
`Task started with message: ${task ? `"${task}"` : "undefined"} and ${images?.length || 0} image(s)`,
2932
)
@@ -33,6 +36,7 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi
3336
outputChannel.appendLine(
3437
`Sending message: ${message ? `"${message}"` : "undefined"} with ${images?.length || 0} image(s)`,
3538
)
39+
3640
await sidebarProvider.postMessageToWebview({
3741
type: "invoke",
3842
invoke: "sendMessage",
@@ -43,22 +47,14 @@ export function createClineAPI(outputChannel: vscode.OutputChannel, sidebarProvi
4347

4448
pressPrimaryButton: async () => {
4549
outputChannel.appendLine("Pressing primary button")
46-
await sidebarProvider.postMessageToWebview({
47-
type: "invoke",
48-
invoke: "primaryButtonClick",
49-
})
50+
await sidebarProvider.postMessageToWebview({ type: "invoke", invoke: "primaryButtonClick" })
5051
},
5152

5253
pressSecondaryButton: async () => {
5354
outputChannel.appendLine("Pressing secondary button")
54-
await sidebarProvider.postMessageToWebview({
55-
type: "invoke",
56-
invoke: "secondaryButtonClick",
57-
})
55+
await sidebarProvider.postMessageToWebview({ type: "invoke", invoke: "secondaryButtonClick" })
5856
},
5957

6058
sidebarProvider: sidebarProvider,
6159
}
62-
63-
return api
6460
}

src/activate/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { handleUri } from "./handleUri"
22
export { registerCommands } from "./registerCommands"
33
export { registerCodeActions } from "./registerCodeActions"
4+
export { createRooCodeAPI } from "./createRooCodeAPI"

src/exports/README.md

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,51 @@
1-
# Cline API
1+
# Roo Code API
22

3-
The Cline extension exposes an API that can be used by other extensions. To use this API in your extension:
3+
The Roo Code extension exposes an API that can be used by other extensions. To use this API in your extension:
44

5-
1. Copy `src/extension-api/cline.d.ts` to your extension's source directory.
6-
2. Include `cline.d.ts` in your extension's compilation.
5+
1. Copy `src/extension-api/roo-code.d.ts` to your extension's source directory.
6+
2. Include `roo-code.d.ts` in your extension's compilation.
77
3. Get access to the API with the following code:
88

9-
```ts
10-
const clineExtension = vscode.extensions.getExtension<ClineAPI>("rooveterinaryinc.roo-cline")
9+
```typescript
10+
const extension = vscode.extensions.getExtension<RooCodeAPI>("rooveterinaryinc.roo-cline")
1111

12-
if (!clineExtension?.isActive) {
13-
throw new Error("Cline extension is not activated")
14-
}
12+
if (!extension?.isActive) {
13+
throw new Error("Extension is not activated")
14+
}
1515

16-
const cline = clineExtension.exports
16+
const api = extension.exports
1717

18-
if (cline) {
19-
// Now you can use the API
18+
if (!api) {
19+
throw new Error("API is not available")
20+
}
2021

21-
// Set custom instructions
22-
await cline.setCustomInstructions("Talk like a pirate")
22+
// Set custom instructions.
23+
await api.setCustomInstructions("Talk like a pirate")
2324

24-
// Get custom instructions
25-
const instructions = await cline.getCustomInstructions()
26-
console.log("Current custom instructions:", instructions)
25+
// Get custom instructions.
26+
const instructions = await api.getCustomInstructions()
27+
console.log("Current custom instructions:", instructions)
2728

28-
// Start a new task with an initial message
29-
await cline.startNewTask("Hello, Cline! Let's make a new project...")
29+
// Start a new task with an initial message.
30+
await api.startNewTask("Hello, Roo Code API! Let's make a new project...")
3031

31-
// Start a new task with an initial message and images
32-
await cline.startNewTask("Use this design language", ["data:image/webp;base64,..."])
32+
// Start a new task with an initial message and images.
33+
await api.startNewTask("Use this design language", ["data:image/webp;base64,..."])
3334

34-
// Send a message to the current task
35-
await cline.sendMessage("Can you fix the @problems?")
35+
// Send a message to the current task.
36+
await api.sendMessage("Can you fix the @problems?")
3637

37-
// Simulate pressing the primary button in the chat interface (e.g. 'Save' or 'Proceed While Running')
38-
await cline.pressPrimaryButton()
38+
// Simulate pressing the primary button in the chat interface (e.g. 'Save' or 'Proceed While Running').
39+
await api.pressPrimaryButton()
3940

40-
// Simulate pressing the secondary button in the chat interface (e.g. 'Reject')
41-
await cline.pressSecondaryButton()
42-
} else {
43-
console.error("Cline API is not available")
44-
}
45-
```
41+
// Simulate pressing the secondary button in the chat interface (e.g. 'Reject').
42+
await api.pressSecondaryButton()
43+
```
4644

47-
**Note:** To ensure that the `rooveterinaryinc.roo-cline` extension is activated before your extension, add it to the `extensionDependencies` in your `package.json`:
45+
**NOTE:** To ensure that the `rooveterinaryinc.roo-cline` extension is activated before your extension, add it to the `extensionDependencies` in your `package.json`:
4846

49-
```json
50-
"extensionDependencies": [
51-
"rooveterinaryinc.roo-cline"
52-
]
53-
```
47+
```json
48+
"extensionDependencies": ["rooveterinaryinc.roo-cline"]
49+
```
5450

55-
For detailed information on the available methods and their usage, refer to the `cline.d.ts` file.
51+
For detailed information on the available methods and their usage, refer to the `roo-code.d.ts` file.

src/exports/cline.d.ts renamed to src/exports/roo-code.d.ts

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface ClineAPI {
1+
export interface RooCodeAPI {
22
/**
33
* Sets the custom instructions in the global storage.
44
* @param value The custom instructions to be saved.
@@ -38,7 +38,60 @@ export interface ClineAPI {
3838
/**
3939
* The sidebar provider instance.
4040
*/
41-
sidebarProvider: ClineSidebarProvider
41+
sidebarProvider: ClineProvider
42+
}
43+
44+
export type ClineAsk =
45+
| "followup"
46+
| "command"
47+
| "command_output"
48+
| "completion_result"
49+
| "tool"
50+
| "api_req_failed"
51+
| "resume_task"
52+
| "resume_completed_task"
53+
| "mistake_limit_reached"
54+
| "browser_action_launch"
55+
| "use_mcp_server"
56+
| "finishTask"
57+
58+
export type ClineSay =
59+
| "task"
60+
| "error"
61+
| "api_req_started"
62+
| "api_req_finished"
63+
| "api_req_retried"
64+
| "api_req_retry_delayed"
65+
| "api_req_deleted"
66+
| "text"
67+
| "reasoning"
68+
| "completion_result"
69+
| "user_feedback"
70+
| "user_feedback_diff"
71+
| "command_output"
72+
| "tool"
73+
| "shell_integration_warning"
74+
| "browser_action"
75+
| "browser_action_result"
76+
| "command"
77+
| "mcp_server_request_started"
78+
| "mcp_server_response"
79+
| "new_task_started"
80+
| "new_task"
81+
| "checkpoint_saved"
82+
| "rooignore_error"
83+
84+
export interface ClineMessage {
85+
ts: number
86+
type: "ask" | "say"
87+
ask?: ClineAsk
88+
say?: ClineSay
89+
text?: string
90+
images?: string[]
91+
partial?: boolean
92+
reasoning?: string
93+
conversationHistoryIndex?: number
94+
checkpoint?: Record<string, unknown>
4295
}
4396

4497
export interface ClineProvider {
@@ -82,11 +135,6 @@ export interface ClineProvider {
82135
*/
83136
cancelTask(): Promise<void>
84137

85-
/**
86-
* Clears the current task
87-
*/
88-
clearTask(): Promise<void>
89-
90138
/**
91139
* Gets the current state
92140
*/
@@ -112,12 +160,6 @@ export interface ClineProvider {
112160
*/
113161
storeSecret(key: SecretKey, value?: string): Promise<void>
114162

115-
/**
116-
* Retrieves a secret value from secure storage
117-
* @param key The key of the secret to retrieve
118-
*/
119-
getSecret(key: SecretKey): Promise<string | undefined>
120-
121163
/**
122164
* Resets the state
123165
*/

src/extension.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ try {
1313

1414
import "./utils/path" // Necessary to have access to String.prototype.toPosix.
1515

16-
import { createClineAPI } from "./exports"
1716
import { ClineProvider } from "./core/webview/ClineProvider"
1817
import { CodeActionProvider } from "./core/CodeActionProvider"
1918
import { DIFF_VIEW_URI_SCHEME } from "./integrations/editor/DiffViewProvider"
2019
import { McpServerManager } from "./services/mcp/McpServerManager"
2120
import { telemetryService } from "./services/telemetry/TelemetryService"
2221

23-
import { handleUri, registerCommands, registerCodeActions } from "./activate"
22+
import { handleUri, registerCommands, registerCodeActions, createRooCodeAPI } from "./activate"
2423

2524
/**
2625
* Built using https://github.com/microsoft/vscode-webview-ui-toolkit
@@ -99,7 +98,7 @@ export function activate(context: vscode.ExtensionContext) {
9998

10099
registerCodeActions(context)
101100

102-
return createClineAPI(outputChannel, sidebarProvider)
101+
return createRooCodeAPI(outputChannel, sidebarProvider)
103102
}
104103

105104
// This method is called when your extension is deactivated.

0 commit comments

Comments
 (0)