UNPKG

askexperts

Version:

AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol

86 lines (85 loc) 2.75 kB
import { SimplePool, Event } from "nostr-tools"; import { Expert } from "../../common/types.js"; /** * Parse an expert profile event into an Expert object * * @param event - The expert profile event to parse * @returns Expert object or null if invalid */ export declare function parseExpertProfile(event: Event): Expert | null; /** * Interface for a post with optional reply context */ export interface PostWithContext { /** Post ID (event.id) */ id: string; /** Post creation timestamp */ created_at: number; /** Post content */ content: string; /** Public key of the author */ pubkey: string; /** Optional reply context */ in_reply_to?: { /** Parent post creation timestamp */ created_at: number; /** Parent post content */ content: string; /** Public key of the parent post author */ pubkey: string; }; } /** * Interface for profile information returned by crawlProfile */ export interface ProfileInfo { /** Profile data (kind:0 event content) */ profile: any; /** Posts data with context */ posts: PostWithContext[]; } /** * Nostr utility class for fetching and processing Nostr data */ export declare class Nostr { /** SimplePool instance for Nostr relay connections */ private pool; /** Default outbox relays to check for user data */ static readonly OUTBOX_RELAYS: string[]; /** * Creates a new Nostr utility instance * * @param pool - SimplePool instance for Nostr relay connections */ constructor(pool: SimplePool); /** * Crawls a user's profile and posts * * @param pubkey - Public key of the user * @param limit - Maximum number of posts to fetch (default: 1000) * @returns Promise resolving to ProfileInfo with profile and posts */ crawlProfile(pubkey: string, limit?: number): Promise<ProfileInfo>; /** * Parses a kind:10002 relay list event into read and write relays * * @param event - The relay list event * @returns Object containing read and write relay arrays */ private parseRelayList; /** * Crawls Nostr events for a specific pubkey and kinds * * @param pubkey - Public key of the user * @param kinds - Array of event kinds to fetch (default: [1] for notes) * @param relays - Array of relay URLs to fetch from (default: auto-detect from user's kind:10002) * @param limit - Maximum number of events to fetch (default: 1000) * @returns Promise resolving to an array of events */ crawl({ pubkey, kinds, relays, limit }: { pubkey: string; kinds?: number[]; relays?: string[]; limit?: number; }): Promise<Event[]>; }