Repository navigation
refactor(frontend/api): finish useFetchEndpoint migration; deprecate useApi composable family #6487
Copy link
Copy link
Closed
Description
Discovery
The frontend has 4+ overlapping HTTP abstractions wrapping the same ApiClient transport. PR #5208 (CLOSED) reconciled useAnalyticsFetch with useFetchEndpoint but did not address the larger useApi family.
| Layer | File | LOC | Callers | Status |
|---|---|---|---|---|
| L1 transport | utils/ApiClient.ts | 778 | (low-level, used by all L2) | keep |
| L2 composable (canonical) | composables/api/useFetchEndpoint.ts | 317 | 205 (47% of all) | canonical |
| L2 primitive | composables/useApiResource.ts | 188 | 44 | keep as internal primitive |
| L2 deprecated | composables/useApi.ts | 545 | 55 (incl. domain facades useChatApi, useSettingsApi, etc.) | deprecate |
| L3 service | services/api.ts | 275 | tests only | delete |
Total caller count: 317. Already on canonical: 205 (65%).
Memory-cited bugs from this duplication
useApi().get()returns parsed JSONPromise<T>, not aResponse— code callingresponse.okalways falls into catch (memory)useFetchEndpointrequires/api/prefix — bare/voice/voiceshits nginx and returnsindex.htmlinstead of JSON (memory)- Some callers in
useApi.ts:206call.json()on already-parsedPromise<T>— pre-existing bugs masked by the inconsistent return types
Proposed Solution
Declare useFetchEndpoint canonical. Mark useApi and its domain facades @deprecated. Add ESLint rule blocking new imports of deprecated wrappers. Delete after grep = 0 over a 2-quarter sunset window.
Migration Map
| Old pattern | New pattern |
|---|---|
const { api } = useApi(); api.get(path) |
useFetchEndpoint({ path }) |
useApiWithState().withErrorHandling(...) |
useFetchEndpoint({ path, onError }) |
useChatApi().sendMessage() |
useFetchEndpoint-based domain composable |
Direct apiService.X() from services/api.ts |
useFetchEndpoint |
Steps
- JSDoc deprecate composables/useApi.ts:139-358 and the domain facades — no code change yet
- ESLint rule —
no-restricted-importsblocking new@/composables/useApiimports with migration message - PoC migrate 3 callers to validate pattern:
usePrometheusMetrics,useVoiceProfiles,WorkflowTemplateGallery.vue - Migration sweep of remaining 55
useApicallers in batches - Delete
services/api.ts(tests only — no prod callers) - Sunset: delete
useApifamily Q3 2026 oncegit grep "useApi[^R]" srcreturns 0 - Documentation: add inline layer-boundary comments to all 4 files; add HTTP-layer decision tree to CONTRIBUTING.md
Acceptance Criteria
-
useFetchEndpoint.tsJSDoc marks it canonical (line 6-29 banner) -
useApi.tsand domain facades have@deprecatedJSDoc tags pointing to migration guide - ESLint
no-restricted-importsrule blocks new@/composables/useApiimports — verify by adding a test file that imports it and seeing lint fail - 3+ proof-of-concept caller migrations merged with passing tests
-
services/api.tsdeleted; no prod imports remain - Inline layer comments at top of
ApiClient.ts,useFetchEndpoint.ts,useApiResource.ts,useApi.ts - CONTRIBUTING.md or
docs/frontend/http-layer.mddescribes layer boundaries and decision tree - Sunset deadlines published in CHANGELOG (e.g.,
useApiremoved Q3 2026) - Final task (separate sub-issue):
useApifamily deleted;git grep "useApi[^R]"returns 0 in non-test code
Files Affected
- Modified:
composables/useApi.ts(deprecate) - Modified:
composables/useApiResource.ts(mark internal) - Modified:
composables/api/useFetchEndpoint.ts(mark canonical) - New/modified:
.eslintrc.cjs(no-restricted-imports rule) - New:
docs/frontend/http-layer.md - Deleted (final phase):
services/api.ts,composables/useApi.ts
Related
- refactor(composables): reconcile useAnalyticsFetch with the rehomed useFetchEndpoint \u2014 two parallel abstractions #5208 (CLOSED — narrower
useAnalyticsFetchreconciliation; precursor to this) - Memory-recorded bugs from the pattern split (return-type mismatches, nginx fallthrough)
Reactions are currently unavailable
Activity
mrveiss commentedon May 11, 2026
Implementation Status
PR #7599 completes partial migration of useApi deprecation (85% of scope):
Completed ✅
Deferred to Follow-Up Issue #7600 ⏳
These files require replacing the useApiWithState().withErrorHandling() pattern with proper try/catch + error notification blocks (more complex than Groups 1-2-4). See #7600 for detailed refactoring guidance.
Recommendation: Merge PR #7599 for immediate deprecation benefit, complete Group 3 in follow-up #7600.
mrveiss commentedon May 11, 2026
Final Implementation Report - Partial Completion with Follow-Up
✅ Acceptance Criteria Met (Partially)
useApi.tsmarked @deprecated with migration guidanceImplementation Evidence
Commits: #7599
Files Modified: 15 total
3-14. 12 migration files (Groups 1, 2, 4):
Follow-Up Issue: #7600 filed for remaining Group 3 (6 files with useApiWithState pattern)
Final Disposition
Status: in_review with live continuation path:
Recommendation:
chore(frontend): sync package-lock.json — add missing @types/react@19…
fix(frontend/api): fix missed useApi calls in useConversationFiles + …
mrveiss commentedon May 11, 2026
PR #7599 — CI failures fixed, ready for re-review
Summary of fixes pushed in this session:
53d20e568: Sync package-lock.json (missing@types/react@19.2.14) — unblocks all npm-dependent CI jobs18cc86312: Fix misseduseApicalls inuseConversationFiles.ts+useVoiceProfiles.ts— TypeScript baseline now holds at 93 (no regression)Local verification:
npx vue-tsc --noEmit -p tsconfig.app.json: 93 errors (matches baseline)useApiimportsBranch status: issue-6487 at
18cc86312, targeting Dev_new_gui — awaiting re-review after CI passesrefactor(frontend/api): deprecate useApi, migrate to useFetchEndpoint…
mrveiss commentedon May 11, 2026
✅ Closed — PR #7599 merged to Dev_new_gui at 2026-05-11T21:17:05Z
Commit: 48c0c68 — refactor(frontend/api): deprecate useApi, migrate to useFetchEndpoint/useApiClient (#6487) (#7599)
Acceptance Criteria Met:
useApiClient/useFetchEndpoint. Views and components: 0 remaining callers. Composable callers: 6 Group 3 files usinguseApiWithState(complex error-handling pattern) deferred to discovery(frontend/api): complete useApiWithState refactoring for Group 3 composables (#6487 follow-up) #7600 with documented refactor pattern.useApi,useApiWithState,useChatApi,useSettingsApi,useKnowledgeApi,useConnectionStatus,useFileApi) carry@deprecatedJSDoc with migration guidance pointing touseFetchEndpoint/useApiClient.no-restricted-importsrule added toeslint.config.ts(error severity) blocks any newimport ... from '@/composables/useApi'with migration message.Remaining work:
useApiWithStaterefactoring for 6 Group 3 composables — tracked separately with implementation pattern documented.fix(frontend/lint): fix remaining ESLint errors from PR #9300 (MVA-2605)
fix(ci): merge console.log and phase validation fixes for PR #9300 (#…
fix(lint): migrate from deprecated useApi to useApiClient (#6487)
chore(deps): bump the npm_and_yarn group across 4 directories with 1 …
fix(frontend): replace deprecated useApi with useApiClient
fix(frontend): clear all lint errors + stabilize lint --fix churn (#9693
fix(frontend): green the unit+integration suite — 89 failures, 3 unca…