Skip to content

Commit 8def831

Browse files
authored
Add IPC types to roo-code.d.ts (#3568)
1 parent 836bbf7 commit 8def831

File tree

8 files changed

+2104
-157
lines changed

8 files changed

+2104
-157
lines changed

scripts/generate-types.mts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import fs from "fs/promises"
1+
import path from "path"
2+
import fs from "fs"
23

34
import { zodToTs, createTypeAlias, printNode } from "zod-to-ts"
45
import { $ } from "execa"
56

67
import schemas from "../src/schemas"
8+
79
const { typeDefinitions } = schemas
810

911
async function main() {
@@ -16,12 +18,16 @@ async function main() {
1618
types.push(`export type { ${identifier} }`)
1719
}
1820

19-
await fs.writeFile("src/exports/types.ts", types.join("\n\n"))
21+
fs.writeFileSync("src/exports/types.ts", types.join("\n\n"))
2022

2123
await $`npx tsup src/exports/interface.ts --dts-only -d out`
22-
await fs.copyFile('out/interface.d.ts', 'src/exports/roo-code.d.ts')
24+
fs.writeFileSync("out/interface.d.ts", "src/exports/roo-code.d.ts")
2325

2426
await $`npx prettier --write src/exports/types.ts src/exports/roo-code.d.ts`
27+
28+
if (fs.existsSync(path.join("..", "Roo-Code-Types"))) {
29+
fs.copyFileSync("src/exports/roo-code.d.ts", path.join("..", "Roo-Code-Types", "index.d.ts"))
30+
}
2531
}
2632

2733
main()

src/exports/api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
ProviderSettingsEntry,
1515
isSecretStateKey,
1616
} from "../schemas"
17-
import { IpcOrigin, IpcMessageType, TaskCommandName, TaskEvent } from "../schemas/ipc"
17+
import { IpcOrigin, IpcMessageType, TaskCommandName, TaskEvent } from "../schemas"
1818

1919
import { RooCodeAPI } from "./interface"
2020
import { IpcServer } from "./ipc"

src/exports/interface.ts

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import { EventEmitter } from "events"
2+
import { Socket } from "node:net"
3+
4+
/**
5+
* Types
6+
*/
27

38
import type {
49
GlobalSettings,
@@ -7,22 +12,36 @@ import type {
712
ClineMessage,
813
TokenUsage,
914
RooCodeEvents,
15+
IpcMessage,
16+
TaskCommand,
17+
TaskEvent,
1018
} from "./types"
1119

1220
export type {
13-
RooCodeSettings,
1421
GlobalSettings,
1522
ProviderSettings,
1623
ProviderSettingsEntry,
1724
ClineMessage,
1825
TokenUsage,
1926
RooCodeEvents,
27+
IpcMessage,
28+
TaskCommand,
29+
TaskEvent,
2030
}
2131

22-
import { RooCodeEventName } from "../schemas"
23-
export type { RooCodeEventName }
32+
/**
33+
* Enums
34+
*/
35+
36+
import { RooCodeEventName, IpcOrigin, IpcMessageType } from "../schemas"
37+
38+
export { RooCodeEventName, IpcOrigin, IpcMessageType }
39+
40+
/**
41+
* RooCodeAPI
42+
*/
2443

25-
type RooCodeSettings = GlobalSettings & ProviderSettings
44+
export type RooCodeSettings = GlobalSettings & ProviderSettings
2645

2746
export interface RooCodeAPI extends EventEmitter<RooCodeEvents> {
2847
/**
@@ -169,3 +188,26 @@ export interface RooCodeAPI extends EventEmitter<RooCodeEvents> {
169188
*/
170189
setActiveProfile(name: string): Promise<string | undefined>
171190
}
191+
192+
/**
193+
* RooCodeIpcServer
194+
*/
195+
196+
export type IpcServerEvents = {
197+
[IpcMessageType.Connect]: [clientId: string]
198+
[IpcMessageType.Disconnect]: [clientId: string]
199+
[IpcMessageType.TaskCommand]: [clientId: string, data: TaskCommand]
200+
[IpcMessageType.TaskEvent]: [relayClientId: string | undefined, data: TaskEvent]
201+
}
202+
203+
export interface RooCodeIpcServer extends EventEmitter<IpcServerEvents> {
204+
listen(): void
205+
206+
broadcast(message: IpcMessage): void
207+
208+
send(client: string | Socket, message: IpcMessage): void
209+
210+
get socketPath(): string
211+
212+
get isListening(): boolean
213+
}

src/exports/ipc.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@ import * as crypto from "node:crypto"
44

55
import ipc from "node-ipc"
66

7-
import { IpcOrigin, IpcMessageType, IpcMessage, ipcMessageSchema, TaskCommand, TaskEvent } from "../schemas/ipc"
7+
import { IpcOrigin, IpcMessageType, type IpcMessage, ipcMessageSchema } from "../schemas"
8+
import type { IpcServerEvents, RooCodeIpcServer } from "./interface"
89

910
/**
1011
* IpcServer
1112
*/
1213

13-
type IpcServerEvents = {
14-
[IpcMessageType.Connect]: [clientId: string]
15-
[IpcMessageType.Disconnect]: [clientId: string]
16-
[IpcMessageType.TaskCommand]: [clientId: string, data: TaskCommand]
17-
[IpcMessageType.TaskEvent]: [relayClientId: string | undefined, data: TaskEvent]
18-
}
19-
20-
export class IpcServer extends EventEmitter<IpcServerEvents> {
14+
export class IpcServer extends EventEmitter<IpcServerEvents> implements RooCodeIpcServer {
2115
private readonly _socketPath: string
2216
private readonly _log: (...args: unknown[]) => void
2317
private readonly _clients: Map<string, Socket>

0 commit comments

Comments
 (0)