Organization class for managing organizational entities

This class represents an organization in the Mosaia platform. Organizations are the top-level containers that group users, resources, and settings. They provide isolation and management capabilities for teams and enterprises.

Features:

  • Resource management (agents, apps, models)
  • Team management
  • Access control
  • Billing and usage tracking
  • Configuration management

Organizations provide:

  • Multi-tenant isolation
  • Resource sharing and access control
  • Team collaboration
  • Usage monitoring and billing
  • Custom configurations

Available resources:

  • AI Agents
  • Applications
  • Agent Groups
  • Models
  • Tools
  • OAuth Clients
  • Team Members

Basic organization setup:

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

// Create a new organization
const org = new Organization({
name: 'Acme Inc',
short_description: 'Technology solutions provider',
metadata: {
industry: 'technology',
size: 'enterprise'
}
});

await org.save();

Resource management:

// Access organization resources
const agents = await org.agents.get();
const apps = await org.apps.get();
const models = await org.models.get();

// Create new resources
const agent = await org.agents.create({
name: 'Support Bot',
model: 'gpt-4'
});

const app = await org.apps.create({
name: 'Customer Portal',
short_description: 'AI-powered support'
});

// Manage team members
const members = await org.orgs.get();
console.log(`Team size: ${members.length}`);

Hierarchy (View Summary)

Constructors

  • Creates a new organization instance

    Initializes an organization with the provided configuration data. Organizations are the primary containers for managing AI resources, team members, and settings.

    Parameters

    • data: Partial<OrganizationInterface>

      Configuration data including: - name: Organization name - short_description: Brief description - long_description: Detailed description - metadata: Custom metadata object

    • Optionaluri: string

      Optional custom URI path for the organization endpoint

    Returns Organization

    Basic organization:

    const org = new Organization({
    name: 'Tech Solutions',
    short_description: 'AI solutions provider'
    });

    Detailed configuration:

    const org = new Organization({
    name: 'Enterprise AI',
    short_description: 'Enterprise AI solutions',
    long_description: 'Comprehensive AI solutions for enterprises',
    metadata: {
    industry: 'technology',
    size: 'enterprise',
    region: 'global',
    compliance: ['gdpr', 'hipaa'],
    features: ['agents', 'models', 'apps']
    }
    }, '/enterprise/org');

Accessors

  • get agents(): Agents

    Get the organization's AI agents

    This getter provides access to the organization's AI agents through the Agents collection. It enables management of all AI agents within the organization.

    Returns Agents

    Agents collection for managing AI agents

    List agents:

    const agents = await org.agents.get();
    agents.forEach(agent => {
    console.log(`Agent: ${agent.name}`);
    });

    Create agent:

    const agent = await org.agents.create({
    name: 'Customer Support',
    model: 'gpt-4',
    temperature: 0.7,
    system_prompt: 'You are a helpful support agent.'
    });
  • get apps(): Apps

    Get the organization's applications

    This getter provides access to the organization's applications through the Apps collection. It enables management of all applications within the organization.

    Returns Apps

    Apps collection for managing applications

    List applications:

    const apps = await org.apps.get();
    apps.forEach(app => {
    console.log(`App: ${app.name}`);
    console.log(`URL: ${app.external_app_url}`);
    });

    Create application:

    const app = await org.apps.create({
    name: 'Support Portal',
    short_description: 'AI-powered support portal',
    external_app_url: 'https://support.example.com',
    metadata: {
    type: 'customer-support',
    features: ['chat', 'knowledge-base']
    }
    });
  • get clients(): Clients

    Get the organization's OAuth clients

    This getter provides access to the organization's OAuth clients through the Clients collection. It enables management of authentication and authorization for external applications.

    Returns Clients

    Clients collection for managing OAuth clients

    List clients:

    const clients = await org.clients.get();
    clients.forEach(client => {
    console.log(`Client: ${client.name}`);
    console.log(`ID: ${client.client_id}`);
    });

    Create OAuth client:

    const client = await org.clients.create({
    name: 'Web Dashboard',
    redirect_uris: ['https://app.example.com/oauth/callback'],
    scopes: ['read:agents', 'write:apps'],
    metadata: {
    type: 'web-application',
    environment: 'production'
    }
    });

    console.log('Client credentials:');
    console.log(`ID: ${client.client_id}`);
    console.log(`Secret: ${client.client_secret}`);
  • get models(): Models

    Get the organization's AI models

    This getter provides access to the organization's AI models through the Models collection. It enables management of model configurations and customizations for the organization's AI capabilities.

    Returns Models

    Models collection for managing AI models

    List models:

    const models = await org.models.get();
    models.forEach(model => {
    console.log(`Model: ${model.name}`);
    console.log(`Provider: ${model.provider}`);
    console.log(`ID: ${model.model_id}`);
    });

    Create custom model:

    const model = await org.models.create({
    name: 'Enhanced GPT-4',
    provider: 'openai',
    model_id: 'gpt-4',
    temperature: 0.7,
    max_tokens: 2000,
    metadata: {
    purpose: 'customer-support',
    training: 'fine-tuned',
    version: '1.0'
    }
    });
  • get orgs(): OrgUsers

    Get the organization's team members

    This getter provides access to the organization's user relationships through the OrgUsers collection. It enables management of team members, their roles, and permissions within the organization.

    Returns OrgUsers

    OrgUsers collection for managing team members

    List team members:

    const members = await org.orgs.get();
    members.forEach(member => {
    console.log(`Member: ${member.user.name}`);
    console.log(`Role: ${member.permission}`);
    });

    Add team member:

    const member = await org.orgs.create({
    user: 'user-123',
    permission: 'member',
    metadata: {
    department: 'engineering',
    title: 'Senior Developer',
    start_date: new Date().toISOString()
    }
    });

    // Create session for member
    const session = await member.session();
  • get tools(): Tools

    Get the organization's tools

    This getter provides access to the organization's tools through the Tools collection. It enables management of custom tools and integrations that extend agent capabilities.

    Returns Tools

    Tools collection for managing custom tools

    List tools:

    const tools = await org.tools.get();
    tools.forEach(tool => {
    console.log(`Tool: ${tool.name}`);
    console.log(`Type: ${tool.type}`);
    });

    Create custom tool:

    const tool = await org.tools.create({
    name: 'Weather API',
    type: 'api',
    description: 'Get weather forecasts',
    api_url: 'https://api.weather.com',
    api_key: process.env.WEATHER_API_KEY,
    metadata: {
    provider: 'weather-service',
    capabilities: ['current', 'forecast'],
    rate_limit: 1000
    }
    });
  • get image(): Image

    Get the image functionality for this organization's profile

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

    Returns Image

    A new Image instance configured for this organization's profile

    const updatedOrg = await org.image.upload<Organization, GetUserPayload>(file);
    
  • get policies(): AccessPolicies

    Get the organization's access policies

    This getter provides access to the organization's access control policies through the AccessPolicies collection. It enables management of IAM policies that define fine-grained permissions for resources and actions.

    Returns AccessPolicies

    AccessPolicies collection for managing access control policies

    const policies = await org.policies.get();
    const policy = await org.policies.create({
    name: 'Admin Access',
    effect: 'allow',
    actions: ['users:read', 'users:write'],
    resources: ['users', 'organizations']
    });
  • get permissions(): OrgPermissions

    Get the organization's permissions

    This getter provides access to the organization's permissions through the OrgPermissions collection. It enables management of permissions that associate users, agents, or clients with access policies.

    Returns OrgPermissions

    OrgPermissions collection for managing organization permissions

    const permissions = await org.permissions.get();
    const permission = await org.permissions.create({
    user: 'user-id',
    policy: 'policy-id'
    });
  • get meters(): Meters

    Get the organization's usage meters

    This getter provides access to the organization's usage meters through the Meters collection. It enables tracking of service consumption and associated costs for billing purposes.

    Returns Meters

    Meters collection for managing usage meters

    const meters = await org.meters.get();
    
  • get wallets(): Wallets

    Get the organization's wallet

    This getter provides access to the organization's wallet through the Wallets collection. It enables management of balances, payment methods, and financial transactions.

    Returns Wallets

    Wallets collection for managing the organization wallet

    const wallet = await org.wallets.get();
    

Methods

  • 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 OrganizationInterface

    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<OrganizationInterface>

    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

    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<OrganizationInterface>

    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);
    }
    }