Skip to content

refactor([[...panel]]): migrate 13 bare fetch to apiFetch#685

Open
jun261930-tech wants to merge 5 commits into
builderz-labs:mainfrom
jun261930-tech:migrate/panel-route
Open

refactor([[...panel]]): migrate 13 bare fetch to apiFetch#685
jun261930-tech wants to merge 5 commits into
builderz-labs:mainfrom
jun261930-tech:migrate/panel-route

Conversation

@jun261930-tech
Copy link
Copy Markdown

Summary

Migrate src/app/[[...panel]]/page.tsx (the root panel router) 13 bare fetch('/api/...) to apiFetch<T>() from @/lib/api-client.

Calls Migrated

Boot sequence:

  • GET /api/auth/me → 401 handled by apiFetch redirect
  • GET /api/releases/check → update availability check
  • GET /api/openclaw/version → OpenClaw version check

Gateway:

  • GET /api/gateways → list gateways for auto-connect
  • POST /api/gateways/connect → connect to primary gateway

Workspace preload (Promise.allSettled):

  • GET /api/agents
  • GET /api/sessions
  • GET /api/projects
  • GET /api/skills
  • GET /api/memory/graph?agent=all

Settings:

  • PUT /api/settings → switch interface mode

Verification

  • pnpm typecheck → 0 error
  • pnpm lint → 0 error, 303 warnings (baseline 343, -40 from this PR)

Why this matters

[[...panel]]/page.tsx is the root router that bootstraps the entire MC app. All 401 errors during boot are now handled uniformly by apiFetch with proper redirect.

Closes: task-11 P2.4

P1 of MC code-quality plan (see PLAN.md / PR-api-client.md):

- src/lib/api-client.ts          (+120) ApiError + apiFetch<T> wrapper
- src/lib/__tests__/api-client.test.ts (+108) 8 vitest cases (200/401/403/500/network/loop/204/no-redirect)
- src/components/auth-expired-listener.tsx (+30) global mc:auth-expired -> /login redirect
- src/app/layout.tsx             (+2) register listener
- eslint.config.mjs              (+31) no-restricted-syntax warn for bare fetch('/api/...')

Quality gates passed:
- pnpm vitest run src/lib/__tests__/api-client.test.ts: 8/8 (2.5s)
- pnpm typecheck: 0 error
- pnpm lint: 0 error, 343 warn (~baseline 334 bare fetch + 9 pre-existing)

Out of scope: migrating existing 334 bare fetch sites (P2, separate PR).

P0 verification: playwright captured 19/19 /api/* returning 200 after login,
ruling out backend issue (cookie expired) — see p0-network-evidence.txt.
- Replace loadData() Promise.all 4x fetch → apiFetch<UsageStats|TrendData|...>
- Replace loadSessionCosts() fetch → apiFetch<{ sessions: SessionCostEntry[] }>
- Replace exportData() fetch → apiFetch<Response>({ raw: true })
- Add apiFetch import from '@/lib/api-client'
- Zero new errors: typecheck pass, lint 0 error

Refs: task-11 P2
Files migrated:
- dashboard.tsx: 5 calls (status, sessions, claude/sessions, github, hermes)
- empty-state-launchpad.tsx: 2 calls (agent-runtimes, capabilities fallback)
- sidebar.tsx: 1 call (status overview)
- onboarding-checklist-widget.tsx: 3 calls (onboarding read + 2x POST)
- security-audit-widget.tsx: 1 call (security-audit)

Zero errors: typecheck pass, lint 0 error (325 warnings vs 343 baseline, -18).

Refs: task-11 P2.2
Files migrated:
- chat-workspace.tsx: 6 calls (agents, messages GET/POST, session-prefs PATCH, continue POST)
- conversation-list.tsx: 2 calls (session-prefs PATCH + GET)
- message-list.tsx: 1 call (messages POST retry)

Zero errors: typecheck pass, lint 0 error (316 warnings vs 343 baseline, -27).

Refs: task-11 P2.3
Calls migrated across 4 functional areas:
- Boot sequence: auth/me, releases/check, openclaw/version
- Gateway: gateways list + connect POST
- Workspace: agents, sessions, projects, skills, memory/graph
- Settings: PUT /api/settings interface_mode

All IIFE or Promise.allSettled patterns converted to async/await.

Zero errors: typecheck pass, lint 0 error (303 warnings vs 343 baseline, -40).

Refs: task-11 P2.4
@jun261930-tech jun261930-tech requested a review from 0xNyk as a code owner May 17, 2026 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant