clawwork-ai / clawwork-ai/ClawWork
[Cleanup] Consolidate 8 separate gateway maps in UI store into unified registry
- Dominant language
- TypeScript
- Stars
- 532
- Forks
- 75
- Avg merge
- 5h 31m
- Merged PRs (30d)
- 1
Description
## Problem
`ui-store.ts` maintains **8 separate `Record` maps** all indexed by `gatewayId`, each with its own setter action:
```typescript
gatewayStatusMap: Record;
setGatewayStatusByGateway: (gatewayId, status) => void;
gatewayVersionMap: Record;
setGatewayVersion: (gatewayId, version) => void;
gatewayReconnectInfo: Record;
setGatewayReconnectInfo: (gatewayId, info) => void;
gatewayInfoMap: Record;
setGatewayInfoMap: (map) => void;
modelCatalogByGateway: Record;
setModelCatalogForGateway: (gatewayId, models) => void;
agentCatalogByGateway: Record;
setAgentCatalogForGateway: (gatewayId, agents, defaultId) => void;
toolsCatalogByGateway: Record;
setToolsCatalogForGateway: (gatewayId, catalog) => void;
skillsStatusByGateway: Record;
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:
```typescript
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;
updateGateway: (gatewayId: string, patch: Partial) => void;
```
16 members → 2 members. Selectors become:
```typescript
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)
Contributor guide
Assessment
This issue has not been assessed yet.