|
1 | | -import type { EventEmitter } from "events" |
2 | | -import type { Socket } from "net" |
| 1 | +/** |
| 2 | + * API for programmatic MCP server operations |
| 3 | + */ |
3 | 4 |
|
4 | | -import type { RooCodeEvents } from "./events.js" |
5 | | -import type { RooCodeSettings } from "./global-settings.js" |
6 | | -import type { ProviderSettingsEntry, ProviderSettings } from "./provider-settings.js" |
7 | | -import type { IpcMessage, IpcServerEvents } from "./ipc.js" |
8 | | - |
9 | | -export type RooCodeAPIEvents = RooCodeEvents |
10 | | - |
11 | | -export interface RooCodeAPI extends EventEmitter<RooCodeAPIEvents> { |
12 | | - /** |
13 | | - * Starts a new task with an optional initial message and images. |
14 | | - * @param task Optional initial task message. |
15 | | - * @param images Optional array of image data URIs (e.g., "data:image/webp;base64,..."). |
16 | | - * @returns The ID of the new task. |
17 | | - */ |
18 | | - startNewTask({ |
19 | | - configuration, |
20 | | - text, |
21 | | - images, |
22 | | - newTab, |
23 | | - }: { |
24 | | - configuration?: RooCodeSettings |
25 | | - text?: string |
26 | | - images?: string[] |
27 | | - newTab?: boolean |
28 | | - }): Promise<string> |
29 | | - /** |
30 | | - * Resumes a task with the given ID. |
31 | | - * @param taskId The ID of the task to resume. |
32 | | - * @throws Error if the task is not found in the task history. |
33 | | - */ |
34 | | - resumeTask(taskId: string): Promise<void> |
35 | | - /** |
36 | | - * Checks if a task with the given ID is in the task history. |
37 | | - * @param taskId The ID of the task to check. |
38 | | - * @returns True if the task is in the task history, false otherwise. |
39 | | - */ |
40 | | - isTaskInHistory(taskId: string): Promise<boolean> |
41 | | - /** |
42 | | - * Returns the current task stack. |
43 | | - * @returns An array of task IDs. |
44 | | - */ |
45 | | - getCurrentTaskStack(): string[] |
46 | | - /** |
47 | | - * Clears the current task. |
48 | | - */ |
49 | | - clearCurrentTask(lastMessage?: string): Promise<void> |
50 | | - /** |
51 | | - * Cancels the current task. |
52 | | - */ |
53 | | - cancelCurrentTask(): Promise<void> |
54 | | - /** |
55 | | - * Sends a message to the current task. |
56 | | - * @param message Optional message to send. |
57 | | - * @param images Optional array of image data URIs (e.g., "data:image/webp;base64,..."). |
58 | | - */ |
59 | | - sendMessage(message?: string, images?: string[]): Promise<void> |
60 | | - /** |
61 | | - * Simulates pressing the primary button in the chat interface. |
62 | | - */ |
63 | | - pressPrimaryButton(): Promise<void> |
64 | | - /** |
65 | | - * Simulates pressing the secondary button in the chat interface. |
66 | | - */ |
67 | | - pressSecondaryButton(): Promise<void> |
68 | | - /** |
69 | | - * Returns true if the API is ready to use. |
70 | | - */ |
71 | | - isReady(): boolean |
| 5 | +/** |
| 6 | + * Interface for MCP operations that can be accessed programmatically |
| 7 | + */ |
| 8 | +export interface McpApi { |
72 | 9 | /** |
73 | | - * Returns the current configuration. |
74 | | - * @returns The current configuration. |
| 10 | + * Refresh all MCP server connections |
| 11 | + * @returns Promise that resolves when refresh is complete |
75 | 12 | */ |
76 | | - getConfiguration(): RooCodeSettings |
77 | | - /** |
78 | | - * Sets the configuration for the current task. |
79 | | - * @param values An object containing key-value pairs to set. |
80 | | - */ |
81 | | - setConfiguration(values: RooCodeSettings): Promise<void> |
82 | | - /** |
83 | | - * Returns a list of all configured profile names |
84 | | - * @returns Array of profile names |
85 | | - */ |
86 | | - getProfiles(): string[] |
87 | | - /** |
88 | | - * Returns the profile entry for a given name |
89 | | - * @param name The name of the profile |
90 | | - * @returns The profile entry, or undefined if the profile does not exist |
91 | | - */ |
92 | | - getProfileEntry(name: string): ProviderSettingsEntry | undefined |
93 | | - /** |
94 | | - * Creates a new API configuration profile |
95 | | - * @param name The name of the profile |
96 | | - * @param profile The profile to create; defaults to an empty object |
97 | | - * @param activate Whether to activate the profile after creation; defaults to true |
98 | | - * @returns The ID of the created profile |
99 | | - * @throws Error if the profile already exists |
100 | | - */ |
101 | | - createProfile(name: string, profile?: ProviderSettings, activate?: boolean): Promise<string> |
102 | | - /** |
103 | | - * Updates an existing API configuration profile |
104 | | - * @param name The name of the profile |
105 | | - * @param profile The profile to update |
106 | | - * @param activate Whether to activate the profile after update; defaults to true |
107 | | - * @returns The ID of the updated profile |
108 | | - * @throws Error if the profile does not exist |
109 | | - */ |
110 | | - updateProfile(name: string, profile: ProviderSettings, activate?: boolean): Promise<string | undefined> |
111 | | - /** |
112 | | - * Creates a new API configuration profile or updates an existing one |
113 | | - * @param name The name of the profile |
114 | | - * @param profile The profile to create or update; defaults to an empty object |
115 | | - * @param activate Whether to activate the profile after upsert; defaults to true |
116 | | - * @returns The ID of the upserted profile |
117 | | - */ |
118 | | - upsertProfile(name: string, profile: ProviderSettings, activate?: boolean): Promise<string | undefined> |
119 | | - /** |
120 | | - * Deletes a profile by name |
121 | | - * @param name The name of the profile to delete |
122 | | - * @throws Error if the profile does not exist |
123 | | - */ |
124 | | - deleteProfile(name: string): Promise<void> |
125 | | - /** |
126 | | - * Returns the name of the currently active profile |
127 | | - * @returns The profile name, or undefined if no profile is active |
128 | | - */ |
129 | | - getActiveProfile(): string | undefined |
130 | | - /** |
131 | | - * Changes the active API configuration profile |
132 | | - * @param name The name of the profile to activate |
133 | | - * @throws Error if the profile does not exist |
134 | | - */ |
135 | | - setActiveProfile(name: string): Promise<string | undefined> |
| 13 | + refreshMcpServers(): Promise<void> |
| 14 | +} |
| 15 | + |
| 16 | +/** |
| 17 | + * Global MCP API instance that will be set by the extension |
| 18 | + */ |
| 19 | +export let mcpApi: McpApi | undefined |
| 20 | + |
| 21 | +/** |
| 22 | + * Set the global MCP API instance |
| 23 | + * @param api The MCP API implementation |
| 24 | + */ |
| 25 | +export function setMcpApi(api: McpApi): void { |
| 26 | + mcpApi = api |
136 | 27 | } |
137 | 28 |
|
138 | | -export interface RooCodeIpcServer extends EventEmitter<IpcServerEvents> { |
139 | | - listen(): void |
140 | | - broadcast(message: IpcMessage): void |
141 | | - send(client: string | Socket, message: IpcMessage): void |
142 | | - get socketPath(): string |
143 | | - get isListening(): boolean |
| 29 | +/** |
| 30 | + * Get the global MCP API instance |
| 31 | + * @returns The MCP API instance or undefined if not set |
| 32 | + */ |
| 33 | +export function getMcpApi(): McpApi | undefined { |
| 34 | + return mcpApi |
144 | 35 | } |
0 commit comments