- Updated chat message types to include tool statuses. - Enhanced localization files for English, Thai, and Chinese to support new tool status messages. - Modified HomePage and SkillsPage components to handle tool statuses in chat messages. - Implemented tool status merging and updating logic in the chat store. - Added handling for tool status events in the gateway event processing. - Created tests for chat message rendering with tool statuses and skill installation shortcuts. - Improved gateway event dispatching for tool lifecycle events.
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import logManager from '@electron/service/logger';
|
|
import { GatewayEventType, type JsonRpcNotification } from './protocol';
|
|
|
|
type GatewayEventEmitter = {
|
|
emit: (event: string, payload: unknown) => boolean;
|
|
};
|
|
|
|
export function dispatchProtocolEvent(
|
|
emitter: GatewayEventEmitter,
|
|
event: string,
|
|
payload: unknown,
|
|
): void {
|
|
switch (event) {
|
|
case 'tick':
|
|
break;
|
|
case 'chat':
|
|
emitter.emit('chat:message', { message: payload });
|
|
break;
|
|
case 'agent':
|
|
emitter.emit('notification', { method: event, params: payload });
|
|
break;
|
|
case 'channel.status':
|
|
case 'channel.status_changed':
|
|
emitter.emit('channel:status', payload as { channelId: string; status: string });
|
|
break;
|
|
case 'gateway.ready':
|
|
case 'ready':
|
|
emitter.emit('gateway:ready', payload);
|
|
break;
|
|
case GatewayEventType.TOOL_CALL_STARTED:
|
|
emitter.emit('tool:status', { status: 'running', payload });
|
|
break;
|
|
case GatewayEventType.TOOL_CALL_COMPLETED:
|
|
emitter.emit('tool:status', { status: 'completed', payload });
|
|
break;
|
|
default:
|
|
emitter.emit('notification', { method: event, params: payload });
|
|
}
|
|
}
|
|
|
|
export function dispatchJsonRpcNotification(
|
|
emitter: GatewayEventEmitter,
|
|
notification: JsonRpcNotification,
|
|
): void {
|
|
emitter.emit('notification', notification);
|
|
switch (notification.method) {
|
|
case GatewayEventType.CHANNEL_STATUS_CHANGED:
|
|
emitter.emit('channel:status', notification.params as { channelId: string; status: string });
|
|
break;
|
|
case GatewayEventType.MESSAGE_RECEIVED:
|
|
emitter.emit('chat:message', notification.params as { message: unknown });
|
|
break;
|
|
case GatewayEventType.TOOL_CALL_STARTED:
|
|
emitter.emit('tool:status', { status: 'running', payload: notification.params });
|
|
break;
|
|
case GatewayEventType.TOOL_CALL_COMPLETED:
|
|
emitter.emit('tool:status', { status: 'completed', payload: notification.params });
|
|
break;
|
|
case GatewayEventType.ERROR: {
|
|
const errorData = notification.params as { message?: string };
|
|
emitter.emit('error', new Error(errorData.message || 'Gateway error'));
|
|
break;
|
|
}
|
|
default:
|
|
logManager.debug(`Unknown Gateway notification: ${notification.method}`);
|
|
}
|
|
}
|