Skip to content

feat: port color intelligence route to platform #107

@ssilvius

Description

@ssilvius

Port the color intelligence route from rafters-studio/rafters to platform. Platform-shaped work only -- schema and intelligence shape stay in rafters' lane (boundary set in reflection 019dd027). The naming prompt at apps/web/src/api/lib/color/name-prompt.ts is staged and ready for use.

Reflections: 019dad65 (redesign decisions), 019dadb2 (naming layer fix), 019dae8b (palette ownership), 019dd027 (boundary), 019d65d7 (link: precedent).

Scope:

  • apps/web/src/api/routes/color.ts -- new route
  • GET /api/color/:oklch where oklch matches `L.LLL-C.CCC-H` (e.g. `0.500-0.120-240`)
  • Query params via zValidator: `sync` (bool, default false), `adhoc` (bool, default false)
  • Branches mirror rafters/apps/api/src/routes/color/color.handlers.ts:
    • adhoc=true -> instant `buildColorValue(oklch)` math response
    • sync=false -> math + `status: 'generating'`
    • sync=true -> calls AI Gateway with `cf-aig-byok-alias: colors` header, uses NAME_SYSTEM_PROMPT + buildNamePrompt() from src/api/lib/color/name-prompt.ts, persists to Vectorize
  • Vectorize lookup: exact ID `${l.toFixed(3)}-${c.toFixed(3)}-${Math.round(h)}`, fallback query with 0.6 nearest-neighbor threshold
  • Response schema: `ColorResponseSchema` from @rafters/shared (status enum: found | approximate | generating | queued | error)
  • Mount in BOTH apps/web/src/api/app.ts AND apps/web/src/pages/api/[...slug].ts (Astro 6 dev quirk -- catch-all inlines its own app, see /auth + /ctrl precedent)

Tests: tests/api/routes/color.test.ts -- unit tests for handler branches with mocked AI/Vectorize bindings via Zocker.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions