Mayson Monorepo Documentation
    Preparing search index...
    • Creates an API client instance with all available methods

      Parameters

      • config: ApiClientConfig

        Configuration object with baseUrl and getToken function

      Returns {
          fetcher: Fetcher;
          transcribeAudio: (
              audioBlob: Blob,
              language?: string,
          ) => Promise<TranscribeAudioResponse>;
          getChatHistory: (
              page?: number,
              limit?: number,
          ) => Promise<ChatHistoryResponse>;
          clearChatHistory: () => Promise<{ success: boolean; message: string }>;
          getExchangeKeys: () => Promise<GetExchangeKeysResponse>;
          saveExchangeKey: (
              data: SaveExchangeKeyRequest,
          ) => Promise<SaveExchangeKeyResponse>;
          verifyExchangeKey: (
              exchange: ExchangeName,
          ) => Promise<VerifyExchangeKeyResponse>;
          deleteExchangeKey: (
              exchange: ExchangeName,
          ) => Promise<DeleteExchangeKeyResponse>;
          getExchangeBalance: (
              exchange: ExchangeName,
              asset?: string,
          ) => Promise<GetBalanceResponse>;
          getMarketTickers: (symbols?: string[]) => Promise<GetMarketTickersResponse>;
          getMarketDetail: (symbol: string) => Promise<GetMarketDetailResponse>;
          getMarketOHLCV: (
              symbol: string,
              timeframe?: string,
              limit?: number,
          ) => Promise<GetOHLCVResponse>;
          getUsageStats: (days?: number) => Promise<UsageStatsResponse>;
          getActiveExchange: () => Promise<GetActiveExchangeResponse>;
          setActiveExchange: (
              exchange: ExchangeName,
          ) => Promise<SetActiveExchangeResponse>;
          getPersonalities: () => Promise<GetPersonalitiesResponse>;
          setPersonality: (
              personality: PersonalityId,
          ) => Promise<SetPersonalityResponse>;
          getLanguage: () => Promise<GetLanguageResponse>;
          setLanguage: (language: LanguageCode) => Promise<SetLanguageResponse>;
          getAvailablePlans: () => Promise<AvailablePlansResponse>;
          getSubscriptionStatus: () => Promise<SubscriptionStatusResponse>;
          getUsageStatus: () => Promise<UsageStatusResponse>;
          createCheckoutSession: (
              data: CreateCheckoutSessionRequest,
          ) => Promise<CreateCheckoutSessionResponse>;
          createPortalSession: (
              returnUrl: string,
          ) => Promise<CreatePortalSessionResponse>;
          updateBillingSettings: (
              data: UpdateBillingSettingsRequest,
          ) => Promise<UpdateBillingSettingsResponse>;
          getVirtualPortfolio: () => Promise<VirtualPortfolioResponse>;
          getVirtualHoldings: () => Promise<VirtualHoldingsResponse>;
          getVirtualTrades: (
              page?: number,
              limit?: number,
          ) => Promise<VirtualTradesResponse>;
          resetVirtualPortfolio: () => Promise<ResetVirtualPortfolioResponse>;
          getNotificationPreferences: () => Promise<
              GetNotificationPreferencesResponse,
          >;
          updateNotificationPreferences: (
              data: UpdateNotificationPreferencesRequest,
          ) => Promise<UpdateNotificationPreferencesResponse>;
          runAgent: (
              message: string,
              tradingMode: TradingMode,
              callbacks: {
                  onEvent: (event: AgentEvent) => void;
                  onError?: (error: Error) => void;
                  onComplete?: () => void;
              },
          ) => Promise<{ abort: () => void }>;
          submitAgentApproval: (
              taskId: string,
              toolCallId: string,
              approved: boolean,
              modifications?: Record<string, unknown>,
          ) => Promise<{ success: boolean; message: string }>;
          getAgentSkills: () => Promise<
              { skills: { name: string; description: string; tools: string[] }[] },
          >;
          downloadFile: (fileId: string) => Promise<Blob>;
          getFileInfo: (
              fileId: string,
          ) => Promise<
              {
                  fileId: string;
                  filename: string;
                  contentType: string;
                  size: number;
                  createdAt: string;
                  expiresAt: string;
              },
          >;
      }

      An API client with methods for all API endpoints

      • fetcher: Fetcher

        Raw fetcher for custom API requests

      • transcribeAudio: (audioBlob: Blob, language?: string) => Promise<TranscribeAudioResponse>

        Transcribe audio to text

      • getChatHistory: (page?: number, limit?: number) => Promise<ChatHistoryResponse>

        Get chat history with pagination

      • clearChatHistory: () => Promise<{ success: boolean; message: string }>

        Clear all chat history

      • getExchangeKeys: () => Promise<GetExchangeKeysResponse>

        Get all exchange keys for the user

      • saveExchangeKey: (data: SaveExchangeKeyRequest) => Promise<SaveExchangeKeyResponse>

        Save an exchange API key

      • verifyExchangeKey: (exchange: ExchangeName) => Promise<VerifyExchangeKeyResponse>

        Verify an exchange API key is working

      • deleteExchangeKey: (exchange: ExchangeName) => Promise<DeleteExchangeKeyResponse>

        Delete an exchange API key

      • getExchangeBalance: (exchange: ExchangeName, asset?: string) => Promise<GetBalanceResponse>

        Get balance for a specific exchange

      • getMarketTickers: (symbols?: string[]) => Promise<GetMarketTickersResponse>

        Get market tickers for specified symbols

      • getMarketDetail: (symbol: string) => Promise<GetMarketDetailResponse>

        Get detailed market info for a symbol

      • getMarketOHLCV: (
            symbol: string,
            timeframe?: string,
            limit?: number,
        ) => Promise<GetOHLCVResponse>

        Get OHLCV (candlestick) data for a symbol

      • getUsageStats: (days?: number) => Promise<UsageStatsResponse>

        Get usage statistics

      • getActiveExchange: () => Promise<GetActiveExchangeResponse>

        Get the currently active exchange

      • setActiveExchange: (exchange: ExchangeName) => Promise<SetActiveExchangeResponse>

        Set the active exchange

      • getPersonalities: () => Promise<GetPersonalitiesResponse>

        Get available AI personalities

      • setPersonality: (personality: PersonalityId) => Promise<SetPersonalityResponse>

        Set the AI personality

      • getLanguage: () => Promise<GetLanguageResponse>

        Get current language preference

      • setLanguage: (language: LanguageCode) => Promise<SetLanguageResponse>

        Set language preference

      • getAvailablePlans: () => Promise<AvailablePlansResponse>

        Get available subscription plans

      • getSubscriptionStatus: () => Promise<SubscriptionStatusResponse>

        Get current subscription status

      • getUsageStatus: () => Promise<UsageStatusResponse>

        Get usage status for billing

      • createCheckoutSession: (data: CreateCheckoutSessionRequest) => Promise<CreateCheckoutSessionResponse>

        Create a Stripe checkout session

      • createPortalSession: (returnUrl: string) => Promise<CreatePortalSessionResponse>

        Create a Stripe customer portal session

      • updateBillingSettings: (data: UpdateBillingSettingsRequest) => Promise<UpdateBillingSettingsResponse>

        Update billing settings

      • getVirtualPortfolio: () => Promise<VirtualPortfolioResponse>

        Get virtual portfolio summary

      • getVirtualHoldings: () => Promise<VirtualHoldingsResponse>

        Get virtual portfolio holdings

      • getVirtualTrades: (page?: number, limit?: number) => Promise<VirtualTradesResponse>

        Get virtual portfolio trades

      • resetVirtualPortfolio: () => Promise<ResetVirtualPortfolioResponse>

        Reset virtual portfolio to initial state

      • getNotificationPreferences: () => Promise<GetNotificationPreferencesResponse>

        Get notification preferences for the current user

      • updateNotificationPreferences: (
            data: UpdateNotificationPreferencesRequest,
        ) => Promise<UpdateNotificationPreferencesResponse>

        Update notification preferences

      • runAgent: (
            message: string,
            tradingMode: TradingMode,
            callbacks: {
                onEvent: (event: AgentEvent) => void;
                onError?: (error: Error) => void;
                onComplete?: () => void;
            },
        ) => Promise<{ abort: () => void }>

        Run the agent with SSE streaming for real-time updates. Returns an object with methods to control the stream.

        const stream = await client.runAgent("What are trending tokens?", "copilot", {
        onEvent: (event) => console.log("Event:", event),
        onError: (error) => console.error("Error:", error),
        onComplete: () => console.log("Done"),
        });

        // To cancel:
        stream.abort();
      • submitAgentApproval: (
            taskId: string,
            toolCallId: string,
            approved: boolean,
            modifications?: Record<string, unknown>,
        ) => Promise<{ success: boolean; message: string }>

        Submit an approval decision for a pending agent action

      • getAgentSkills: () => Promise<
            { skills: { name: string; description: string; tools: string[] }[] },
        >

        Get list of available agent skills

      • downloadFile: (fileId: string) => Promise<Blob>

        Download a file by its ID Returns a Blob that can be used to trigger a download in the browser

        Error if file not found, expired, or access denied

        const blob = await client.downloadFile('abc-123');
        const url = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = url;
        a.download = 'transactions.csv';
        a.click();
        URL.revokeObjectURL(url);
      • getFileInfo: (
            fileId: string,
        ) => Promise<
            {
                fileId: string;
                filename: string;
                contentType: string;
                size: number;
                createdAt: string;
                expiresAt: string;
            },
        >

        Get file metadata without downloading the content

      const client = createApiClient({
      baseUrl: 'http://localhost:3001',
      getToken: () => localStorage.getItem('token'),
      });

      // Use the client
      const history = await client.getChatHistory();