feat: define the discovery api wire contract

This commit is contained in:
Justin Visser 2026-08-10 11:31:06 +02:00
parent 6769833f7e
commit 4bc48663c8
2 changed files with 182 additions and 0 deletions

79
frontend/src/lib/types.ts Normal file
View file

@ -0,0 +1,79 @@
// Wire types mirrored against backend/app/api/schemas.py.
// Field names match the JSON payloads exactly, so they stay snake_case.
export interface HistoryTurn {
role: 'user' | 'assistant'
content: string
}
export interface PriorRecommendation {
rank: number
track_id: string
title: string
artists: string[]
}
export interface RecommendationRequest {
schema_version: 1
query: string
history: HistoryTurn[]
prior_recommendations: PriorRecommendation[]
}
export interface TrackCard {
id: string
uri: string
title: string
artists: string[]
album_name: string
album_art_url: string | null
external_url: string | null
}
export interface MetadataEvent {
type: 'metadata'
request_id: string
intent_summary: string
candidate_count: number
}
export interface TrackEvent {
type: 'track'
rank: number
track: TrackCard
justification: string
}
export interface WarningEvent {
type: 'warning'
code: string
message: string
}
export interface ErrorEvent {
type: 'error'
code: string
message: string
}
export interface DoneEvent {
type: 'done'
track_count: number
total_ms: number
}
export type StreamEvent = MetadataEvent | TrackEvent | WarningEvent | ErrorEvent | DoneEvent
export interface PlaylistCreateRequest {
schema_version: 1
name: string
track_uris: string[]
}
export interface PlaylistCreateResponse {
url: string
}
export interface CurrentUser {
display_name: string
}