Skip to content

[Cleanup] Consolidate 8 separate gateway maps in UI store into unified registry #342

@samzong

Description

@samzong

Problem

ui-store.ts maintains 8 separate Record<string, T> maps all indexed by gatewayId, each with its own setter action:

gatewayStatusMap: Record<string, GatewayConnectionStatus>;
setGatewayStatusByGateway: (gatewayId, status) => void;

gatewayVersionMap: Record<string, string>;
setGatewayVersion: (gatewayId, version) => void;

gatewayReconnectInfo: Record<string, { attempt; max; gaveUp }>;
setGatewayReconnectInfo: (gatewayId, info) => void;

gatewayInfoMap: Record<string, GatewayInfo>;
setGatewayInfoMap: (map) => void;

modelCatalogByGateway: Record<string, ModelCatalogEntry[]>;
setModelCatalogForGateway: (gatewayId, models) => void;

agentCatalogByGateway: Record<string, { agents; defaultId }>;
setAgentCatalogForGateway: (gatewayId, agents, defaultId) => void;

toolsCatalogByGateway: Record<string, ToolsCatalog>;
setToolsCatalogForGateway: (gatewayId, catalog) => void;

skillsStatusByGateway: Record<string, SkillStatusReport>;
setSkillsStatusForGateway: (gatewayId, report) => void;

This is 16 interface members (8 state + 8 setters) for what is logically one concept: per-gateway state.

Location

File: packages/core/src/stores/ui-store.ts:38-73

Fix Approach

Unify into a single gateway registry:

interface GatewayState {
  status: GatewayConnectionStatus;
  version?: string;
  reconnectInfo?: { attempt: number; max: number; gaveUp: boolean };
  info: GatewayInfo;
  models: ModelCatalogEntry[];
  agents: { agents: AgentInfo[]; defaultId: string };
  tools: ToolsCatalog | null;
  skills: SkillStatusReport | null;
}

// In store:
gatewayRegistry: Record<string, GatewayState>;
updateGateway: (gatewayId: string, patch: Partial<GatewayState>) => void;

16 members → 2 members. Selectors become:

const status = useUiStore((s) => s.gatewayRegistry[gatewayId]?.status);

Note: This is a larger refactor — ~30 files reference the individual maps. Should be done incrementally:

  1. Add gatewayRegistry + updateGateway alongside existing maps
  2. Migrate consumers file by file
  3. Remove old maps

Verification

  1. Run pnpm check — must pass
  2. Connect/disconnect gateways, verify all status/catalog/version info displays correctly

Context

  • WG: Task & Session Core + UI & Design System
  • Priority: Medium
  • Estimated effort: ~2 hours (incremental)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreTask & Session Core WGarea/uiUI & Design System WGkind/cleanupCategorizes issue or PR as related to code cleanup

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions