UNPKG

askexperts

Version:

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

118 lines (117 loc) 4.18 kB
import { SimplePool } from "nostr-tools"; import { DBExpert } from "../../db/interfaces.js"; import { RagDB } from "../../rag/index.js"; import { LightningPaymentManager } from "../../payments/LightningPaymentManager.js"; import { DocStoreClient } from "../../docstore/interfaces.js"; /** * ExpertWorker class for managing experts */ export declare class ExpertWorker { private runningExperts; private paymentManagers; private pool; private ragDB; /** * Get the pubkeys of all running experts * * @returns Array of pubkeys of running experts */ getRunningExpertPubkeys(): string[]; /** * Create a new ExpertWorker * * @param pool SimplePool instance for Nostr communication * @param ragHost Host for RAG database * @param ragPort Port for RAG database */ constructor(pool: SimplePool, ragHost?: string, ragPort?: number); /** * Start an expert * * @param expert The expert to start * @param nwcString NWC connection string for the expert's wallet * @returns Promise that resolves when the expert is started */ startExpert(expert: DBExpert, nwcString: string): Promise<void>; /** * Stop an expert * * @param pubkey The pubkey of the expert to stop * @returns True if the expert was running and is now stopped, false otherwise */ stopExpert(pubkey: string): boolean; /** * Dispose all resources */ [Symbol.asyncDispose](): Promise<void>; /** * Start a Nostr expert * * @param expert The expert to start * @param pool SimplePool instance * @param paymentManager Payment manager * @param ragDB RAG database * @param docStoreClient DocStore client * @param onStop Promise that resolves when the expert should be stopped */ static startNostrExpert(expert: DBExpert, pool: SimplePool, paymentManager: LightningPaymentManager, ragDB: RagDB, docStoreClient: DocStoreClient, onStop: Promise<void>): Promise<{ disposed: Promise<void>; }>; /** * Start an OpenRouter expert * * @param expert The expert to start * @param pool SimplePool instance * @param paymentManager Payment manager * @param onStop Promise that resolves when the expert should be stopped */ static startOpenRouterExpert(expert: DBExpert, pool: SimplePool, paymentManager: LightningPaymentManager, onStop: Promise<void>): Promise<{ disposed: Promise<void>; }>; /** * Parse a docstore ID string into URL and ID components * * If the docstore ID contains a ":", it's treated as a remote docstore with format: * url:docstore_id (e.g., https://docstore.askexperts.io:docstore_id) * * @param docstoreIdStr - The docstore ID string to parse * @returns An object containing the URL (if remote) and the actual docstore ID */ static parseDocstoreId(docstoreIdStr: string): { url?: string; id: string; }; /** * Parse a comma-separated list of docstore IDs * * @param docstoresStr - Comma-separated list of docstore IDs * @returns Array of parsed docstore ID objects */ static parseDocstoreIdsList(docstoresStr: string): Array<{ url?: string; id: string; }>; /** * Create the appropriate DocStoreClient based on a parsed docstore ID * * @param parsedDocstore - Parsed docstore ID object * @returns DocStoreClient instance */ static createDocStoreClientFromParsed(parsedDocstore: { url?: string; id: string; }): DocStoreClient; /** * Parse a docstore ID string and create the appropriate DocStoreClient * * If the docstore ID contains a ":", it's treated as a remote docstore with format: * url:docstore_id (e.g., https://docstore.askexperts.io:docstore_id) * * @param docstoreIdStr - The docstore ID string to parse * @returns An object containing the DocStoreClient and the actual docstore ID */ static createDocStoreClient(docstoreIdStr: string): { client: DocStoreClient; docstoreId: string; }; }