- 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.
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import type { ChannelAccountCatalogGroup, ChannelConnectionStatus } from '@src/lib/channel-types';
|
|
import { buildChannelStatusSummary, type ChannelStatusSummary } from '@electron/utils/channel-status';
|
|
import type { GatewayLifecycleState } from './process-policy';
|
|
|
|
export interface GatewayDiagnosticsSnapshot {
|
|
lastAliveAt?: number;
|
|
lastRpcSuccessAt?: number;
|
|
lastRpcFailureAt?: number;
|
|
lastRpcFailureMethod?: string;
|
|
lastHeartbeatTimeoutAt?: number;
|
|
consecutiveHeartbeatMisses: number;
|
|
lastSocketCloseAt?: number;
|
|
lastSocketCloseCode?: number;
|
|
consecutiveRpcFailures: number;
|
|
}
|
|
|
|
export function createInitialGatewayDiagnostics(): GatewayDiagnosticsSnapshot {
|
|
return {
|
|
consecutiveHeartbeatMisses: 0,
|
|
consecutiveRpcFailures: 0,
|
|
};
|
|
}
|
|
|
|
export interface GatewayHealthSnapshot {
|
|
ok: boolean;
|
|
status: 'connected' | 'disconnected' | 'reconnecting';
|
|
initialized: boolean;
|
|
mode: 'in-process' | 'openclaw';
|
|
port?: number | null;
|
|
pid?: number | null;
|
|
lastError?: string;
|
|
lifecycleState?: GatewayLifecycleState;
|
|
gatewayReady?: boolean;
|
|
diagnostics?: GatewayDiagnosticsSnapshot;
|
|
}
|
|
|
|
export interface GatewayDiagnosticsSummary {
|
|
status: ChannelConnectionStatus;
|
|
gateway: GatewayHealthSnapshot;
|
|
channels: ChannelStatusSummary;
|
|
}
|
|
|
|
function normalizeGatewayStatus(status: GatewayHealthSnapshot['status']): ChannelConnectionStatus {
|
|
if (status === 'reconnecting') return 'connecting';
|
|
return status;
|
|
}
|
|
|
|
export function buildGatewayDiagnosticsSummary(
|
|
health: GatewayHealthSnapshot,
|
|
channelGroups: readonly ChannelAccountCatalogGroup[],
|
|
): GatewayDiagnosticsSummary {
|
|
const channels = buildChannelStatusSummary(channelGroups);
|
|
const gatewayStatus = normalizeGatewayStatus(health.status);
|
|
|
|
return {
|
|
status: health.ok
|
|
? (channels.status === 'connected'
|
|
? 'connected'
|
|
: channels.status === 'disconnected'
|
|
? 'degraded'
|
|
: channels.status)
|
|
: gatewayStatus,
|
|
gateway: health,
|
|
channels,
|
|
};
|
|
}
|