Chat API
The chat module of the @codebolt/plugin-sdk.
import plugin from '@codebolt/plugin-sdk';
Quick Reference
| Method | Description |
|---|---|
askQuestion | |
checkForSteeringMessage | Checks if any steering message has been received. |
getChatHistory | Retrieves the chat history from the server. |
onSteeringMessageReceived | Waits for a steering message. |
processFinished | Stops the ongoing process. |
processStarted | Notifies the server that a process has started and sets up a listener for stopProcessClicked events. |
sendConfirmationRequest | Sends a confirmation request to the server with two options: Yes or No. |
sendMessage | Sends a message through the WebSocket connection. |
sendNotificationEvent | Sends a notification event to the server. |
setRequestHandler | Sets a global request handler for all incoming messages |
stopProcess | Stops the ongoing process. |
waitforReply | Waits for a reply to a sent message. |
Methods
askQuestion
plugin.chat.askQuestion(question: string, buttons: string[], withFeedback: boolean): Promise<string>
| Parameter | Type | Required | Description |
|---|---|---|---|
question | string | Yes | |
buttons | string[] | Yes | (default: []) |
withFeedback | boolean | Yes | (default: false) |
Returns: Promise<string>
checkForSteeringMessage
plugin.chat.checkForSteeringMessage(): SteeringMessage | null
Checks if any steering message has been received.
No parameters.
Returns: SteeringMessage | null — The message data if available, or null
getChatHistory
plugin.chat.getChatHistory(threadId: string): Promise<ChatMessage>
Retrieves the chat history from the server.
| Parameter | Type | Required | Description |
|---|---|---|---|
threadId | string | Yes |
Returns: Promise<ChatMessage> — A promise that resolves with an array of ChatMessage objects representing the chat history.
onSteeringMessageReceived
plugin.chat.onSteeringMessageReceived(): Promise<SteeringMessage | null>
Waits for a steering message.
No parameters.
Returns: Promise<SteeringMessage | null> — A promise that resolves with the message data
processFinished
plugin.chat.processFinished(): void
Stops the ongoing process. Sends a specific message to the server to stop the process.
No parameters.
Returns: void
processStarted
plugin.chat.processStarted(onStopClicked?: Function): ProcessControl | ProcessControlWithCleanup
Notifies the server that a process has started and sets up a listener for stopProcessClicked events.
| Parameter | Type | Required | Description |
|---|---|---|---|
onStopClicked | Function | No | Callback function to handle stop process events. |
Returns: ProcessControl | ProcessControlWithCleanup — An object containing a stopProcess method.
sendConfirmationRequest
plugin.chat.sendConfirmationRequest(confirmationMessage: string, buttons: string[], withFeedback: boolean): Promise<string>
Sends a confirmation request to the server with two options: Yes or No.
| Parameter | Type | Required | Description |
|---|---|---|---|
confirmationMessage | string | Yes | |
buttons | string[] | Yes | (default: []) |
withFeedback | boolean | Yes | (default: false) |
Returns: Promise<string> — A promise that resolves with the server's response.
sendMessage
plugin.chat.sendMessage(message: string, payload?: object): void
Sends a message through the WebSocket connection.
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | The message to be sent. |
payload | object | No | Optional additional payload data. |
Returns: void
sendNotificationEvent
plugin.chat.sendNotificationEvent(notificationMessage: string, type: "editor" | "browser" | "terminal" | "git" | "debug" | "planner" | "preview"): void
Sends a notification event to the server.
| Parameter | Type | Required | Description |
|---|---|---|---|
notificationMessage | string | Yes | The message to be sent in the notification. |
type | `"editor" | "browser" | "terminal" |
Returns: void
setRequestHandler
plugin.chat.setRequestHandler(handler: RequestHandler): void
Sets a global request handler for all incoming messages
| Parameter | Type | Required | Description |
|---|---|---|---|
handler | RequestHandler | Yes | The async handler function |
Returns: void
stopProcess
plugin.chat.stopProcess(): void
Stops the ongoing process. Sends a specific message to the server to stop the process.
No parameters.
Returns: void
waitforReply
plugin.chat.waitforReply(message: string): Promise<UserMessage>
Waits for a reply to a sent message.
| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | The message for which a reply is expected. |
Returns: Promise<UserMessage> — A promise that resolves with the reply.