Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions scripts/generate-types.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import fs from "fs/promises"
import path from "path"
import fs from "fs"

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

import schemas from "../src/schemas"

const { typeDefinitions } = schemas

async function main() {
Expand All @@ -16,12 +18,16 @@ async function main() {
types.push(`export type { ${identifier} }`)
}

await fs.writeFile("src/exports/types.ts", types.join("\n\n"))
fs.writeFileSync("src/exports/types.ts", types.join("\n\n"))

await $`npx tsup src/exports/interface.ts --dts-only -d out`
await fs.copyFile('out/interface.d.ts', 'src/exports/roo-code.d.ts')
fs.writeFileSync("out/interface.d.ts", "src/exports/roo-code.d.ts")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that the previous copyFile call was replaced with a writeFileSync call that writes a fixed string ('src/exports/roo-code.d.ts') into 'out/interface.d.ts'. This is likely a logic error – you probably intended to copy the content of 'out/interface.d.ts' to 'src/exports/roo-code.d.ts'. Consider using fs.copyFileSync with the correct source and destination.

Suggested change
fs.writeFileSync("out/interface.d.ts", "src/exports/roo-code.d.ts")
fs.copyFileSync("out/interface.d.ts", "src/exports/roo-code.d.ts")


await $`npx prettier --write src/exports/types.ts src/exports/roo-code.d.ts`

if (fs.existsSync(path.join("..", "Roo-Code-Types"))) {
fs.copyFileSync("src/exports/roo-code.d.ts", path.join("..", "Roo-Code-Types", "index.d.ts"))
}
}

main()
2 changes: 1 addition & 1 deletion src/exports/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ProviderSettingsEntry,
isSecretStateKey,
} from "../schemas"
import { IpcOrigin, IpcMessageType, TaskCommandName, TaskEvent } from "../schemas/ipc"
import { IpcOrigin, IpcMessageType, TaskCommandName, TaskEvent } from "../schemas"

import { RooCodeAPI } from "./interface"
import { IpcServer } from "./ipc"
Expand Down
50 changes: 46 additions & 4 deletions src/exports/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { EventEmitter } from "events"
import { Socket } from "node:net"

/**
* Types
*/

import type {
GlobalSettings,
Expand All @@ -7,22 +12,36 @@ import type {
ClineMessage,
TokenUsage,
RooCodeEvents,
IpcMessage,
TaskCommand,
TaskEvent,
} from "./types"

export type {
RooCodeSettings,
GlobalSettings,
ProviderSettings,
ProviderSettingsEntry,
ClineMessage,
TokenUsage,
RooCodeEvents,
IpcMessage,
TaskCommand,
TaskEvent,
}

import { RooCodeEventName } from "../schemas"
export type { RooCodeEventName }
/**
* Enums
*/

import { RooCodeEventName, IpcOrigin, IpcMessageType } from "../schemas"

export { RooCodeEventName, IpcOrigin, IpcMessageType }

/**
* RooCodeAPI
*/

type RooCodeSettings = GlobalSettings & ProviderSettings
export type RooCodeSettings = GlobalSettings & ProviderSettings

export interface RooCodeAPI extends EventEmitter<RooCodeEvents> {
/**
Expand Down Expand Up @@ -169,3 +188,26 @@ export interface RooCodeAPI extends EventEmitter<RooCodeEvents> {
*/
setActiveProfile(name: string): Promise<string | undefined>
}

/**
* RooCodeIpcServer
*/

export type IpcServerEvents = {
[IpcMessageType.Connect]: [clientId: string]
[IpcMessageType.Disconnect]: [clientId: string]
[IpcMessageType.TaskCommand]: [clientId: string, data: TaskCommand]
[IpcMessageType.TaskEvent]: [relayClientId: string | undefined, data: TaskEvent]
}

export interface RooCodeIpcServer extends EventEmitter<IpcServerEvents> {
listen(): void

broadcast(message: IpcMessage): void

send(client: string | Socket, message: IpcMessage): void

get socketPath(): string

get isListening(): boolean
}
12 changes: 3 additions & 9 deletions src/exports/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@ import * as crypto from "node:crypto"

import ipc from "node-ipc"

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

/**
* IpcServer
*/

type IpcServerEvents = {
[IpcMessageType.Connect]: [clientId: string]
[IpcMessageType.Disconnect]: [clientId: string]
[IpcMessageType.TaskCommand]: [clientId: string, data: TaskCommand]
[IpcMessageType.TaskEvent]: [relayClientId: string | undefined, data: TaskEvent]
}

export class IpcServer extends EventEmitter<IpcServerEvents> {
export class IpcServer extends EventEmitter<IpcServerEvents> implements RooCodeIpcServer {
private readonly _socketPath: string
private readonly _log: (...args: unknown[]) => void
private readonly _clients: Map<string, Socket>
Expand Down
Loading