// community actor search, used twice: to complete a handle as it is typed, and // to get the profile — handle, display name, avatar — for the signed-in DID. // // Unauthenticated and CORS-enabled, so a local app needs nothing but a fetch. // The `X-Client` header is how the operator attributes traffic; send one. const BASE = "https://typeahead.waow.tech"; const CLIENT = "scn-local.127.0.0.1"; export interface Actor { did: string; handle: string; displayName?: string; avatar?: string; } export async function searchActors(prefix: string, signal?: AbortSignal): Promise { const query = prefix.trim().replace(/^@/, ""); if (query.length < 2) return []; const url = new URL(`${BASE}/xrpc/tech.waow.typeahead.searchActors`); url.searchParams.set("q", query); url.searchParams.set("limit", "8"); const response = await fetch(url, { signal, headers: { "X-Client": CLIENT }, }); if (!response.ok) throw new Error(`typeahead answered ${response.status}`); const data = (await response.json()) as { actors?: Actor[] }; return data.actors ?? []; } export async function getProfile(actor: string): Promise { const url = new URL(`${BASE}/xrpc/app.bsky.actor.getProfile`); url.searchParams.set("actor", actor); const response = await fetch(url, { headers: { "X-Client": CLIENT } }); if (!response.ok) return null; const data = (await response.json()) as Actor; return data?.did ? data : null; }