App class for managing AI-powered applications

This class represents an application in the Mosaia platform, serving as a container and orchestrator for AI solutions. Apps provide the structure and configuration for deploying and managing AI capabilities.

Features:

  • Application lifecycle management
  • External integration configuration
  • Security and access control
  • Resource organization
  • Usage monitoring

Applications are the foundational building blocks for deploying AI solutions. They provide:

  • Centralized configuration management
  • Integration points with external systems
  • Security boundary definitions
  • Resource allocation and monitoring
  • Usage analytics and reporting

Basic app setup:

import { App } from 'mosaia-node-sdk';

// Create a new application
const supportPortal = new App({
name: 'AI Support Portal',
short_description: 'Intelligent customer support',
long_description: 'AI-powered support system with multiple specialized agents',
external_app_url: 'https://support.example.com'
});

// Save the application
await supportPortal.save();

External integration:

// Configure external system integration
const app = new App({
name: 'Integration App',
external_app_url: 'https://api.external-system.com',
external_api_key: process.env.EXTERNAL_API_KEY,
external_headers: {
'X-Custom-Header': 'value',
'Authorization': `Bearer ${process.env.AUTH_TOKEN}`
}
});

// Test the connection
if (app.isActive()) {
console.log('Integration configured successfully');
}

Hierarchy (View Summary)

Constructors

  • Creates a new App instance

    Initializes an application with the provided configuration data and optional URI. The application serves as a container for organizing and managing AI-powered solutions.

    Parameters

    • data: Partial<AppInterface>

      Application configuration data including: - name: Application name - short_description: Brief description - long_description: Detailed description - external_app_url: External system URL - external_api_key: API key for external system - external_headers: Custom headers for external requests

    • Optionaluri: string

      Optional URI path for the application endpoint

    Returns App

    Basic configuration:

    const app = new App({
    name: 'Customer Portal',
    short_description: 'AI customer service portal',
    external_app_url: 'https://portal.example.com'
    });

    Full configuration:

    const app = new App({
    name: 'Enterprise Solution',
    short_description: 'AI-powered enterprise tools',
    long_description: 'Comprehensive suite of AI tools for enterprise use',
    external_app_url: 'https://enterprise.example.com',
    external_api_key: process.env.API_KEY,
    external_headers: {
    'X-Enterprise-ID': 'ent-123',
    'Authorization': 'Bearer token'
    }
    }, '/enterprise/app');

Accessors

  • get connectors(): AppConnectors

    Get the app's AI connectors

    This getter provides access to the app's connectors through the AppConnectors collection. It enables management of all connectors within the app.

    Returns AppConnectors

    AppConnectors collection for managing connectors

    List connectors:

    const connectors = await app.connectors.get();
    connectors.forEach(connector => {
    console.log(`Connector: ${connector.name}`);
    });

    Create connector:

    const connector = await app.connectors.create({
    name: 'Customer Support Connector'
    });
  • get webhooks(): AppWebhooks

    Get the app's webhooks

    This getter provides access to the app's webhooks through the AppWebhooks collection. It enables management of all webhooks within the app for receiving notifications about application events.

    Returns AppWebhooks

    AppWebhooks collection for managing webhooks

    List webhooks:

    const webhooks = await app.webhooks.get();
    webhooks.forEach(webhook => {
    console.log(`Webhook URL: ${webhook.url}`);
    });

    Create webhook:

    const webhook = await app.webhooks.create({
    url: 'https://myapp.com/webhook',
    events: ['REQUEST'],
    secret: 'webhook-secret-key'
    });
  • get image(): Image

    Get the image functionality for this app

    This getter provides access to the app's image operations through the Image class. It allows for image uploads and other image-related operations specific to this app.

    Returns Image

    A new Image instance configured for this app

    const updatedApp = await app.image.upload<App, GetAppPayload>(file);
    

Methods

  • Like or unlike this app

    Toggles the like status of this app. If the app is already liked, it will be unliked, and vice versa.

    Returns Promise<App>

    Promise that resolves to the updated app instance

    await app.like();
    console.log('App liked:', app.liked);

    When API request fails

  • Check if the entity is active

    This method checks the active status of the entity. Most entities in the system can be active or inactive, which affects their availability and usability in the platform.

    Returns boolean

    True if the entity is active, false otherwise

    const user = new User(userData);
    if (user.isActive()) {
    // Perform operations with active user
    } else {
    console.log('User is inactive');
    }
  • Convert model instance to interface data

    This method serializes the model instance to a plain object that matches the interface type. This is useful for:

    • Sending data to the API
    • Storing data in a database
    • Passing data between components
    • Debugging model state

    Returns AppInterface

    The model data as a plain object matching the interface type

    const user = new User({
    email: 'user@example.com',
    firstName: 'John'
    });

    const data = user.toJSON();
    console.log(data); // { email: '...', firstName: '...' }

    // Use with JSON.stringify
    const json = JSON.stringify(user);
  • Convert model instance to API payload

    This method creates a payload suitable for API requests by:

    • Converting the model to a plain object
    • Removing read-only fields (like 'id')
    • Ensuring proper data format for the API

    Returns Partial<AppInterface>

    A clean object suitable for API requests

    const user = new User({
    id: '123', // Will be removed from payload
    email: 'new@example.com',
    firstName: 'John'
    });

    const payload = user.toAPIPayload();
    // payload = { email: '...', firstName: '...' }
    // Note: 'id' is removed as it's read-only

    await apiClient.POST('/users', payload);
  • Update model data with new values

    This method updates the model's data and instance properties with new values. It performs a shallow merge of the updates with existing data, allowing for partial updates of the model's properties.

    Parameters

    • updates: Partial<AppInterface>

      Object containing properties to update

    Returns void

    const user = new User({
    email: 'old@example.com',
    firstName: 'John'
    });

    // Update multiple properties
    user.update({
    email: 'new@example.com',
    lastName: 'Doe'
    });

    // Save changes to API
    await user.save();

    This method only updates the local model instance. To persist changes to the API, call save after updating.

  • Save the model instance to the API

    This method persists the current state of the model to the API using a PUT request. It requires the model to have an ID (existing instance). For new instances, use the collection's create method instead.

    The method:

    1. Validates the model has an ID
    2. Sends current data to the API
    3. Updates local instance with API response

    Returns Promise<AppInterface>

    Promise resolving to the updated model data

    When model has no ID

    When API request fails

    const user = new User({
    id: '123',
    email: 'user@example.com'
    });

    // Update and save
    user.update({ firstName: 'John' });
    await user.save();

    Error handling:

    try {
    await user.save();
    } catch (error) {
    if (error.message.includes('ID is required')) {
    // Handle missing ID error
    } else {
    // Handle API errors
    }
    }
  • Delete the model instance from the API

    This method permanently deletes the model instance from the API and clears the local data. This operation cannot be undone.

    The method:

    1. Validates the model has an ID
    2. Sends DELETE request to the API
    3. Clears local instance data on success

    Returns Promise<void>

    Promise that resolves when deletion is successful

    When model has no ID

    When API request fails

    Basic deletion:

    const user = await users.get({}, 'user-id');
    if (user) {
    await user.delete();
    // User is now deleted and instance is cleared
    }

    Error handling:

    try {
    await user.delete();
    console.log('User deleted successfully');
    } catch (error) {
    if (error.message.includes('ID is required')) {
    console.error('Cannot delete - no ID');
    } else {
    console.error('Deletion failed:', error.message);
    }
    }