Skip to content

feat(shared): backfill gateway + costs API modules#218

Draft
gambtho wants to merge 15 commits into
kaito-project:mainfrom
gambtho:thgamble/shared-api-backfill
Draft

feat(shared): backfill gateway + costs API modules#218
gambtho wants to merge 15 commits into
kaito-project:mainfrom
gambtho:thgamble/shared-api-backfill

Conversation

@gambtho

@gambtho gambtho commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds gateway.ts and costs.ts API modules to @airunway/shared/api, matching the shapes currently hand-rolled in frontend/src/lib/api.ts (lines 677–734)
  • Wires both new modules into createApiClient() so consumers can access client.gateway.* and client.costs.*
  • Bootstraps Vitest in shared/ (first test infrastructure for the shared package) with 10 unit tests covering all 6 new methods

Part of: #195 — Shared UI Layer + New-User Onboarding (Phase 1, PR 1 of ~10)

No consumer changes. frontend/src/lib/api.ts is untouched — PR 3 will flip the frontend to use these shared modules and delete the 734-line duplicate.

What's new

Module Methods Tests
shared/api/gateway.ts getStatus(), getModels() 2
shared/api/costs.ts estimate(), getNodePoolCosts(), getGpuModels(), normalizeGpu() 6
shared/api/index.ts Wiring + smoke tests 2
shared/api/test-helpers.ts mockRequest<T>() helper

Test plan

  • cd shared && bun run test — 10/10 passing
  • bun run test (root) — 718 total (shared: 10, frontend: 102, backend: 606)
  • cd shared && bun run build — exit 0, no TypeScript errors
  • git diff origin/main -- frontend/ — empty (no consumer changes)
  • Endpoint URLs match frontend/src/lib/api.ts exactly (verified side-by-side)
  • Default parameter values for getNodePoolCosts(gpuCount=1, replicas=1, computeType='gpu') match frontend
  • normalizeGpu URL-encodes label via encodeURIComponent (test verifies %20 encoding)

gambtho added 15 commits April 12, 2026 01:44
Adds vitest devDep + minimal node-env config so the shared
package can host its first unit tests. No tests added in this
commit — subsequent commits add gateway.test.ts and costs.test.ts.
First method of the gateway backfill — matches the shape currently
hand-rolled in frontend/src/lib/api.ts's gatewayApi.getStatus.
Tested via a mocked RequestFn.
Follow-up to 4e1cddb. Extracts the `vi.fn().mockResolvedValue(...)
as unknown as RequestFn` cast into a small `mockRequest` helper so
the five sibling test files that Tasks 3-7 will add inherit a
cleaner shape. Also types `mockResponse` against `GatewayInfo` so
future type drift in the response shape fails the test at compile
time instead of silently under-specifying the mock.
Second method of the gateway backfill — matches
gatewayApi.getModels in frontend/src/lib/api.ts. Gateway API
is now complete.
First of four costs methods — POSTs a CostEstimateRequest and
returns a CostEstimateResponse. Matches frontend's costsApi.estimate.
Uses default values (gpuCount=1, replicas=1, computeType=gpu)
when called with no args, matching frontend. The response shape
is exported as NodePoolCostsResponse so callers can name it if
they need to.
Returns the supported GPU model list with memory and generation
metadata. Matches frontend.
Final method of the costs backfill. URL-encodes the free-form
label argument so any label (including spaces / special chars)
is safely passed as a query param. Costs API is now complete.
The two new factories are now exposed via createApiClient's
return value, matching the pattern for every other API.
Consumers (frontend, headlamp) will start using them in PR 3.

Smoke test asserts both properties exist on a configured
client instance, so the wiring itself is covered by a runtime
test in addition to TypeScript.

Note: costs.NormalizeGpuResponse is re-exported under the alias
CostsNormalizeGpuResponse to avoid a name clash with the existing
aiconfigurator.NormalizeGpuResponse export.
Ensures CI and local `bun run test` catch shared-package
regressions. Shared runs first because workspace consumers
depend on it.
…ponse at source

Eliminates the re-export alias in index.ts by giving the costs
type a unique name at its declaration site. The canonical name
is now CostsNormalizeGpuResponse everywhere — in costs.ts, in
costs.test.ts, and in the public API surface via index.ts.

This avoids confusion from having NormalizeGpuResponse mean one
thing inside costs.ts and CostsNormalizeGpuResponse outside it.
The aiconfigurator module's NormalizeGpuResponse is unchanged.
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