mirror of
https://github.com/jlengrand/Maestro.git
synced 2026-03-10 08:31:19 +00:00
MAESTRO: Consolidate GlobalAgentStats type to shared types
- Add GlobalAgentStats and ProviderStats interfaces to src/shared/types.ts - Update agentSessions.ts to import and re-export from shared types - Update AboutModal.tsx to import GlobalAgentStats from shared types - Update test file to use shared GlobalAgentStats type instead of duplicate Eliminates 3 duplicate definitions of GlobalAgentStats across the codebase. All 47 AboutModal tests pass. TypeScript type checking passes.
This commit is contained in:
@@ -8,6 +8,7 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|||||||
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
|
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
|
||||||
import { AboutModal } from '../../../renderer/components/AboutModal';
|
import { AboutModal } from '../../../renderer/components/AboutModal';
|
||||||
import type { Theme, AutoRunStats } from '../../../renderer/types';
|
import type { Theme, AutoRunStats } from '../../../renderer/types';
|
||||||
|
import type { GlobalAgentStats } from '../../../shared/types';
|
||||||
|
|
||||||
// Mock lucide-react icons
|
// Mock lucide-react icons
|
||||||
vi.mock('lucide-react', () => ({
|
vi.mock('lucide-react', () => ({
|
||||||
@@ -66,7 +67,7 @@ vi.mock('../../../renderer/components/AchievementCard', () => ({
|
|||||||
AchievementCard: ({ theme, autoRunStats, globalStats, onEscapeWithBadgeOpen }: {
|
AchievementCard: ({ theme, autoRunStats, globalStats, onEscapeWithBadgeOpen }: {
|
||||||
theme: Theme;
|
theme: Theme;
|
||||||
autoRunStats: AutoRunStats;
|
autoRunStats: AutoRunStats;
|
||||||
globalStats: ClaudeGlobalStats | null;
|
globalStats: GlobalAgentStats | null;
|
||||||
onEscapeWithBadgeOpen: (handler: (() => boolean) | null) => void;
|
onEscapeWithBadgeOpen: (handler: (() => boolean) | null) => void;
|
||||||
}) => (
|
}) => (
|
||||||
<div data-testid="achievement-card">
|
<div data-testid="achievement-card">
|
||||||
@@ -90,20 +91,6 @@ vi.mock('../../../renderer/components/AchievementCard', () => ({
|
|||||||
// Add __APP_VERSION__ global
|
// Add __APP_VERSION__ global
|
||||||
(globalThis as unknown as { __APP_VERSION__: string }).__APP_VERSION__ = '1.0.0';
|
(globalThis as unknown as { __APP_VERSION__: string }).__APP_VERSION__ = '1.0.0';
|
||||||
|
|
||||||
// Interface for global stats (matches GlobalAgentStats in AboutModal.tsx)
|
|
||||||
interface ClaudeGlobalStats {
|
|
||||||
totalSessions: number;
|
|
||||||
totalMessages: number;
|
|
||||||
totalInputTokens: number;
|
|
||||||
totalOutputTokens: number;
|
|
||||||
totalCacheReadTokens: number;
|
|
||||||
totalCacheCreationTokens: number;
|
|
||||||
totalCostUsd: number;
|
|
||||||
hasCostData: boolean;
|
|
||||||
totalSizeBytes: number;
|
|
||||||
isComplete?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create test theme
|
// Create test theme
|
||||||
const createTheme = (): Theme => ({
|
const createTheme = (): Theme => ({
|
||||||
id: 'test-dark',
|
id: 'test-dark',
|
||||||
|
|||||||
@@ -43,36 +43,13 @@ import type {
|
|||||||
SessionListOptions,
|
SessionListOptions,
|
||||||
SessionReadOptions,
|
SessionReadOptions,
|
||||||
} from '../../agent-session-storage';
|
} from '../../agent-session-storage';
|
||||||
|
import type { GlobalAgentStats, ProviderStats } from '../../../shared/types';
|
||||||
|
|
||||||
|
// Re-export for backwards compatibility
|
||||||
|
export type { GlobalAgentStats, ProviderStats };
|
||||||
|
|
||||||
const LOG_CONTEXT = '[AgentSessions]';
|
const LOG_CONTEXT = '[AgentSessions]';
|
||||||
|
|
||||||
/**
|
|
||||||
* Global stats aggregated from all providers
|
|
||||||
*/
|
|
||||||
export interface GlobalAgentStats {
|
|
||||||
totalSessions: number;
|
|
||||||
totalMessages: number;
|
|
||||||
totalInputTokens: number;
|
|
||||||
totalOutputTokens: number;
|
|
||||||
totalCacheReadTokens: number;
|
|
||||||
totalCacheCreationTokens: number;
|
|
||||||
/** Total cost in USD - only includes providers that support cost tracking */
|
|
||||||
totalCostUsd: number;
|
|
||||||
/** Whether any provider contributed cost data */
|
|
||||||
hasCostData: boolean;
|
|
||||||
totalSizeBytes: number;
|
|
||||||
isComplete: boolean;
|
|
||||||
/** Per-provider breakdown */
|
|
||||||
byProvider: Record<string, {
|
|
||||||
sessions: number;
|
|
||||||
messages: number;
|
|
||||||
inputTokens: number;
|
|
||||||
outputTokens: number;
|
|
||||||
costUsd: number;
|
|
||||||
hasCostData: boolean;
|
|
||||||
}>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic agent session origins data structure
|
* Generic agent session origins data structure
|
||||||
* Structure: { [agentId]: { [projectPath]: { [sessionId]: { origin, sessionName, starred } } } }
|
* Structure: { [agentId]: { [projectPath]: { [sessionId]: { origin, sessionName, starred } } } }
|
||||||
|
|||||||
@@ -1,35 +1,13 @@
|
|||||||
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
import React, { useEffect, useRef, useState, useCallback } from 'react';
|
||||||
import { X, Wand2, ExternalLink, FileCode, BarChart3, Loader2, Trophy, Globe, Check, BookOpen } from 'lucide-react';
|
import { X, Wand2, ExternalLink, FileCode, BarChart3, Loader2, Trophy, Globe, Check, BookOpen } from 'lucide-react';
|
||||||
import type { Theme, AutoRunStats, MaestroUsageStats, LeaderboardRegistration } from '../types';
|
import type { Theme, AutoRunStats, MaestroUsageStats, LeaderboardRegistration } from '../types';
|
||||||
|
import type { GlobalAgentStats } from '../../shared/types';
|
||||||
import { MODAL_PRIORITIES } from '../constants/modalPriorities';
|
import { MODAL_PRIORITIES } from '../constants/modalPriorities';
|
||||||
import pedramAvatar from '../assets/pedram-avatar.png';
|
import pedramAvatar from '../assets/pedram-avatar.png';
|
||||||
import { AchievementCard } from './AchievementCard';
|
import { AchievementCard } from './AchievementCard';
|
||||||
import { formatTokensCompact } from '../utils/formatters';
|
import { formatTokensCompact } from '../utils/formatters';
|
||||||
import { Modal } from './ui/Modal';
|
import { Modal } from './ui/Modal';
|
||||||
|
|
||||||
interface GlobalAgentStats {
|
|
||||||
totalSessions: number;
|
|
||||||
totalMessages: number;
|
|
||||||
totalInputTokens: number;
|
|
||||||
totalOutputTokens: number;
|
|
||||||
totalCacheReadTokens: number;
|
|
||||||
totalCacheCreationTokens: number;
|
|
||||||
totalCostUsd: number;
|
|
||||||
/** Whether any provider contributed cost data */
|
|
||||||
hasCostData: boolean;
|
|
||||||
totalSizeBytes: number;
|
|
||||||
isComplete?: boolean;
|
|
||||||
/** Per-provider breakdown */
|
|
||||||
byProvider?: Record<string, {
|
|
||||||
sessions: number;
|
|
||||||
messages: number;
|
|
||||||
inputTokens: number;
|
|
||||||
outputTokens: number;
|
|
||||||
costUsd: number;
|
|
||||||
hasCostData: boolean;
|
|
||||||
}>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface AboutModalProps {
|
interface AboutModalProps {
|
||||||
theme: Theme;
|
theme: Theme;
|
||||||
autoRunStats: AutoRunStats;
|
autoRunStats: AutoRunStats;
|
||||||
|
|||||||
@@ -329,3 +329,41 @@ export interface AgentSshRemoteConfig {
|
|||||||
/** Override working directory for this agent */
|
/** Override working directory for this agent */
|
||||||
workingDirOverride?: string;
|
workingDirOverride?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// Global Agent Statistics Types
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Per-provider statistics breakdown
|
||||||
|
*/
|
||||||
|
export interface ProviderStats {
|
||||||
|
sessions: number;
|
||||||
|
messages: number;
|
||||||
|
inputTokens: number;
|
||||||
|
outputTokens: number;
|
||||||
|
costUsd: number;
|
||||||
|
hasCostData: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Global stats aggregated from all providers.
|
||||||
|
* Used by AboutModal and AgentSessions handlers.
|
||||||
|
*/
|
||||||
|
export interface GlobalAgentStats {
|
||||||
|
totalSessions: number;
|
||||||
|
totalMessages: number;
|
||||||
|
totalInputTokens: number;
|
||||||
|
totalOutputTokens: number;
|
||||||
|
totalCacheReadTokens: number;
|
||||||
|
totalCacheCreationTokens: number;
|
||||||
|
/** Total cost in USD - only includes providers that support cost tracking */
|
||||||
|
totalCostUsd: number;
|
||||||
|
/** Whether any provider contributed cost data */
|
||||||
|
hasCostData: boolean;
|
||||||
|
totalSizeBytes: number;
|
||||||
|
/** Whether stats calculation is complete (used for progressive updates) */
|
||||||
|
isComplete: boolean;
|
||||||
|
/** Per-provider breakdown */
|
||||||
|
byProvider: Record<string, ProviderStats>;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user