Skip to content

refactor(agent-detail-tabs): migrate 17 bare fetch to apiFetch#690

Open
jun261930-tech wants to merge 2 commits into
builderz-labs:mainfrom
jun261930-tech:migrate/agent-detail-tabs
Open

refactor(agent-detail-tabs): migrate 17 bare fetch to apiFetch#690
jun261930-tech wants to merge 2 commits into
builderz-labs:mainfrom
jun261930-tech:migrate/agent-detail-tabs

Conversation

@jun261930-tech
Copy link
Copy Markdown

Summary

Migrated 17 bare fetch() calls in src/components/panels/agent-detail-tabs.tsx to apiFetch<T>() from @/lib/api-client.

Changes

  • 5x GET /api/status?action=modelsapiFetch<...>(...) fire-and-forget
  • 1x POST /api/agents/messageapiFetch<...>(...)
  • 1x PATCH /api/agents/${name}/soulapiFetch<...>(...)
  • 1x GET /api/tasks?assigned_to=...apiFetch<...>(...)
  • 1x GET /api/activities?actor=...apiFetch<...>(...)
  • 1x POST /api/agents (in Promise.all with raw: true) → apiFetch<Response>(...)
  • 3x GET /api/agents/${id}/filesapiFetch<...>(...)
  • 1x GET /api/channelsapiFetch<...>(...)
  • 1x GET /api/cron?action=listapiFetch<...>(...)
  • 3x PUT /api/agents/${id}apiFetch<...>(...)

Key Fixes

  • Eliminated duplicate response.json() calls (loadFiles had 2x parsing)
  • Eliminated redundant if (!response.ok) return guards
  • Fixed TypeScript error: data.content nullable → data.content ?? ''

Testing

  • pnpm test api-client.test.ts passed (8/8)
  • pnpm typecheck passed (0 errors)
  • pnpm lint passed (agent-detail-tabs.tsx: 0 warnings)

Notes

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.
@jun261930-tech jun261930-tech requested a review from 0xNyk as a code owner May 17, 2026 14:33
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