Skip to content

Commit 4fd5e44

Browse files
authored
Merge pull request #1671 from franekp/all-tasks-events-in-api
feat(RooCodeAPI): emit events from all tasks, not only those started via startNewTask
2 parents df80e96 + a06119a commit 4fd5e44

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Anthropic } from "@anthropic-ai/sdk"
22
import delay from "delay"
33
import axios from "axios"
4+
import EventEmitter from "events"
45
import fs from "fs/promises"
56
import os from "os"
67
import pWaitFor from "p-wait-for"
@@ -67,7 +68,11 @@ import { TelemetrySetting } from "../../shared/TelemetrySetting"
6768
* https://github.com/KumarVariable/vscode-extension-sidebar-html/blob/master/src/customSidebarViewProvider.ts
6869
*/
6970

70-
export class ClineProvider implements vscode.WebviewViewProvider {
71+
export type ClineProviderEvents = {
72+
clineAdded: [cline: Cline]
73+
}
74+
75+
export class ClineProvider extends EventEmitter<ClineProviderEvents> implements vscode.WebviewViewProvider {
7176
public static readonly sideBarId = "roo-cline.SidebarProvider" // used in package.json as the view's id. This value cannot be changed due to how vscode caches views based on their id, and updating the id would break existing instances of the extension.
7277
public static readonly tabPanelId = "roo-cline.TabPanelProvider"
7378
private static activeInstances: Set<ClineProvider> = new Set()
@@ -86,6 +91,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
8691
readonly context: vscode.ExtensionContext,
8792
private readonly outputChannel: vscode.OutputChannel,
8893
) {
94+
super()
95+
8996
this.outputChannel.appendLine("ClineProvider instantiated")
9097
this.contextProxy = new ContextProxy(context)
9198
ClineProvider.activeInstances.add(this)
@@ -118,6 +125,8 @@ export class ClineProvider implements vscode.WebviewViewProvider {
118125
// Add this cline instance into the stack that represents the order of all the called tasks.
119126
this.clineStack.push(cline)
120127

128+
this.emit("clineAdded", cline)
129+
121130
// Ensure getState() resolves correctly.
122131
const state = await this.getState()
123132

src/exports/api.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
1818
this.provider = provider
1919
this.history = new MessageHistory()
2020

21+
this.provider.on("clineAdded", (cline) => {
22+
cline.on("message", (message) => this.emit("message", { taskId: cline.taskId, ...message }))
23+
cline.on("taskStarted", () => this.emit("taskStarted", cline.taskId))
24+
cline.on("taskPaused", () => this.emit("taskPaused", cline.taskId))
25+
cline.on("taskUnpaused", () => this.emit("taskUnpaused", cline.taskId))
26+
cline.on("taskAborted", () => this.emit("taskAborted", cline.taskId))
27+
cline.on("taskSpawned", (taskId) => this.emit("taskSpawned", cline.taskId, taskId))
28+
})
29+
2130
this.on("message", ({ taskId, action, message }) => {
2231
// if (message.type === "say") {
2332
// console.log("message", { taskId, action, message })
@@ -38,14 +47,6 @@ export class API extends EventEmitter<RooCodeEvents> implements RooCodeAPI {
3847
await this.provider.postMessageToWebview({ type: "invoke", invoke: "newChat", text, images })
3948

4049
const cline = await this.provider.initClineWithTask(text, images)
41-
cline.on("message", (message) => this.emit("message", { taskId: cline.taskId, ...message }))
42-
cline.on("taskStarted", () => this.emit("taskStarted", cline.taskId))
43-
cline.on("taskPaused", () => this.emit("taskPaused", cline.taskId))
44-
cline.on("taskUnpaused", () => this.emit("taskUnpaused", cline.taskId))
45-
cline.on("taskAskResponded", () => this.emit("taskAskResponded", cline.taskId))
46-
cline.on("taskAborted", () => this.emit("taskAborted", cline.taskId))
47-
cline.on("taskSpawned", (taskId) => this.emit("taskSpawned", cline.taskId, taskId))
48-
4950
return cline.taskId
5051
}
5152

0 commit comments

Comments
 (0)