import type { ApiError } from './api' import { apiGetWrapped } from './api' export type RawNoteRecord = { id: number source_platform: string | null content: string | null author: string | null url: string | null created_at: string | null } export type RawNoteListResponse = { notes: RawNoteRecord[] total: number limit: number offset: number query: string | null } export type CleanedNoteRecord = { id: number raw_note_id: number | null cleaned_content: string | null created_at: string | null raw_author: string | null raw_url: string | null } export type CleanedNoteListResponse = { notes: CleanedNoteRecord[] total: number limit: number offset: number query: string | null } export type ListContentParams = { limit: number offset: number query?: string } function buildSearch(params: ListContentParams) { const search = new URLSearchParams() search.set('limit', String(params.limit)) search.set('offset', String(params.offset)) const q = String(params.query || '').trim() if (q) search.set('query', q) return search.toString() } export async function listRawNotes(params: ListContentParams) { return apiGetWrapped(`content/raw-notes?${buildSearch(params)}`) } export async function listCleanedNotes(params: ListContentParams) { return apiGetWrapped(`content/cleaned-notes?${buildSearch(params)}`) } export function isOrchestratorDbUnavailable(error: ApiError | null | undefined) { if (!error) return false if (error.status !== 503) return false if (typeof error.message === 'string' && error.message.toLowerCase().includes('orchestrator db')) return true const data = error.data if (!data || typeof data !== 'object') return false const obj = data as Record return obj.code === 10010 || obj.msg === 'orchestrator db unavailable' }