Files
stack/apps/api/src/bridge/interfaces/chat-provider.interface.ts
Jason Woltje 8d19ac1f4b
Some checks failed
ci/woodpecker/push/infra Pipeline was successful
ci/woodpecker/push/api Pipeline failed
fix(#377): remediate code review and security findings
- Fix sendThreadMessage room mismatch: use channelId from options instead of hardcoded controlRoomId
- Add .catch() to fire-and-forget handleRoomMessage to prevent silent error swallowing
- Wrap dispatchJob in try-catch for user-visible error reporting in handleFixCommand
- Add MATRIX_BOT_USER_ID validation in connect() to prevent infinite message loops
- Fix streamResponse error masking: wrap finally/catch side-effects in try-catch
- Replace unsafe type assertion with public getClient() in MatrixRoomService
- Add orphaned room warning in provisionRoom on DB failure
- Add provider identity to Herald error logs
- Add channelId to ThreadMessageOptions interface and all callers
- Add missing env var warnings in BridgeModule factory
- Fix JSON injection in setup-bot.sh: use jq for safe JSON construction

Fixes #377

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-15 03:00:53 -06:00

94 lines
2.0 KiB
TypeScript

/**
* Chat Provider Interface
*
* Defines the contract for chat platform integrations (Discord, Slack, Matrix, etc.)
*/
export interface ChatMessage {
id: string;
channelId: string;
authorId: string;
authorName: string;
content: string;
timestamp: Date;
threadId?: string;
}
export interface ChatCommand {
command: string;
args: string[];
message: ChatMessage;
}
export interface ThreadCreateOptions {
channelId: string;
name: string;
message: string;
}
export interface ThreadMessageOptions {
threadId: string;
channelId: string;
content: string;
}
export interface VerbosityLevel {
level: "low" | "medium" | "high";
description: string;
}
/**
* Chat Provider Interface
*
* All chat platform integrations must implement this interface
*/
export interface IChatProvider {
/**
* Connect to the chat platform
*/
connect(): Promise<void>;
/**
* Disconnect from the chat platform
*/
disconnect(): Promise<void>;
/**
* Check if the provider is connected
*/
isConnected(): boolean;
/**
* Send a message to a channel or thread
*/
sendMessage(channelId: string, content: string): Promise<void>;
/**
* Create a thread for job updates
*/
createThread(options: ThreadCreateOptions): Promise<string>;
/**
* Send a message to a thread
*/
sendThreadMessage(options: ThreadMessageOptions): Promise<void>;
/**
* Parse a command from a message
*/
parseCommand(message: ChatMessage): ChatCommand | null;
/**
* Edit an existing message in a channel.
*
* Optional method for providers that support message editing
* (e.g., Matrix via m.replace, Discord via message.edit).
* Used for streaming AI responses with incremental updates.
*
* @param channelId - The channel/room ID
* @param messageId - The original message/event ID to edit
* @param content - The updated message content
*/
editMessage?(channelId: string, messageId: string, content: string): Promise<void>;
}