- Added telemetry utility to capture application events and metrics. - Integrated PostHog for event tracking with distinct user identification. - Implemented telemetry initialization, event capturing, and shutdown procedures. feat: add UV environment setup for Python management - Created utilities to manage Python installation and configuration. - Implemented network optimization checks for Python installation mirrors. - Added functions to set up managed Python environments with error handling. feat: enhance host API communication with token management - Introduced host API token retrieval and management for secure requests. - Updated host API fetch functions to include token in headers. - Added support for creating event sources with authentication. test: add comprehensive tests for gateway protocol and startup helpers - Implemented unit tests for gateway protocol helpers, event dispatching, and state management. - Added tests for startup recovery strategies and process policies. - Ensured coverage for connection monitoring and restart governance logic.
56 lines
1.7 KiB
TypeScript
56 lines
1.7 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;
|
|
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.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}`);
|
|
}
|
|
}
|