UNPKG

askexperts

Version:

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

105 lines (104 loc) 2.82 kB
import { ExpertServerPerms } from "./interfaces.js"; /** * Configuration options for ExpertServer */ export interface ExpertServerOptions { /** Port to listen on */ port: number; /** Base path for the API (e.g., '/api') */ basePath?: string; /** Server origin for auth token validation (e.g. 'https://yourdomain.com') */ origin?: string; /** Optional permissions interface for authentication and authorization */ perms?: ExpertServerPerms; } /** * ExpertServer class that provides an HTTP API for ExpertClient operations */ export declare class ExpertServer { private app; private port; private basePath; private stopped; private server?; private expertClient; private perms?; private serverOrigin; /** * Creates a new ExpertServer instance * * @param options - Configuration options or port number (for backward compatibility) * @param basePath - Base path for the API (e.g., '/api') when using port number constructor */ constructor(options: ExpertServerOptions); /** * Authentication middleware * Parses the auth token and checks permissions */ private authMiddleware; /** * Sets up the API routes * @private */ private setupRoutes; /** * Handles requests to list all experts * * @param req - Express request object * @param res - Express response object * @private */ private handleListExperts; /** * Handles requests to get an expert by pubkey * * @param req - Express request object * @param res - Express response object * @private */ private handleGetExpert; /** * Handles requests to insert a new expert * * @param req - Express request object * @param res - Express response object * @private */ private handleInsertExpert; /** * Handles requests to update an existing expert * * @param req - Express request object * @param res - Express response object * @private */ private handleUpdateExpert; /** * Handles requests to set the disabled status of an expert * * @param req - Express request object * @param res - Express response object * @private */ private handleSetExpertDisabled; /** * Handles requests to delete an expert * * @param req - Express request object * @param res - Express response object * @private */ private handleDeleteExpert; /** * Starts the server * * @returns Promise that resolves when the server is started */ start(): Promise<void>; /** * Stops the server * * @returns Promise that resolves when the server is stopped */ stop(): Promise<void>; }