Creates a new user profile
Initializes a user account with the provided profile information. Users are the primary actors in the platform who can create and manage AI resources.
Profile data including: - username: Unique identifier - name: Display name - email: Contact email - description: Bio or description - metadata: Additional profile data
Optionaluri: stringOptional custom URI path for the user endpoint
Basic profile:
const user = new User({
username: 'jdoe',
name: 'Jane Doe',
email: 'jane@example.com',
description: 'AI Developer'
});
Detailed profile:
const user = new User({
username: 'jsmith',
name: 'John Smith',
email: 'john@example.com',
description: 'Senior AI Engineer',
metadata: {
title: 'Engineering Lead',
department: 'AI Research',
location: 'New York',
skills: ['machine-learning', 'nlp', 'python'],
joined_date: new Date().toISOString(),
preferences: {
theme: 'dark',
notifications: true,
language: 'en-US'
}
}
}, '/enterprise/user');
Get the user's AI agents
This getter provides access to the user's AI agents through the Agents collection. It enables management of personal agents and their configurations.
Agents collection for managing AI agents
Get the user's applications
This getter provides access to the user's applications through the Apps collection. It enables management of personal applications and their configurations.
Apps collection for managing applications
Get the user's OAuth clients
This getter provides access to the user's OAuth clients through the Clients collection. It enables management of authentication and authorization for external applications.
Clients collection for managing OAuth clients
List clients:
const clients = await user.clients.get();
clients.forEach(client => {
console.log(`Client: ${client.name}`);
console.log(`ID: ${client.client_id}`);
});
Create OAuth client:
const client = await user.clients.create({
name: 'Mobile App',
redirect_uris: ['com.example.app://oauth/callback'],
scopes: ['read:agents', 'write:apps'],
metadata: {
platform: 'ios',
version: '2.0',
environment: 'production'
}
});
console.log('Client credentials:');
console.log(`ID: ${client.client_id}`);
console.log(`Secret: ${client.client_secret}`);
Get the user's AI models
This getter provides access to the user's AI models through the Models collection. It enables management of model configurations and customizations.
Models collection for managing AI models
List models:
const models = await user.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 user.models.create({
name: 'Enhanced GPT-4',
provider: 'openai',
model_id: 'gpt-4',
temperature: 0.7,
max_tokens: 2000,
metadata: {
purpose: 'code-generation',
training: 'fine-tuned',
version: '1.0',
specialties: ['typescript', 'python'],
performance: {
avg_latency: 500,
max_concurrent: 10
}
}
});
Get the user's organization memberships
This getter provides access to the user's organization memberships through the OrgUsers collection. It enables management of team memberships and organization access.
OrgUsers collection for managing organization memberships
List memberships:
const memberships = await user.orgs.get();
memberships.forEach(membership => {
console.log(`Organization: ${membership.org.name}`);
console.log(`Role: ${membership.permission}`);
console.log(`Active: ${membership.isActive()}`);
});
Manage memberships:
// Join organization
const membership = await user.orgs.create({
org: 'org-123',
permission: 'member',
metadata: {
department: 'engineering',
title: 'Senior Developer',
start_date: new Date().toISOString()
}
});
// Get authenticated session
const config = await membership.session();
const mosaia = new Mosaia(config);
// Access organization resources
const orgAgents = await mosaia.agents.get();
console.log(`Organization has ${orgAgents.length} agents`);
Get the user's integration tools
This getter provides access to the user's integration tools through the Tools collection. It enables management of external service integrations and custom tools.
Tools collection for managing integrations
List tools:
const tools = await user.tools.get();
tools.forEach(tool => {
console.log(`Tool: ${tool.name}`);
console.log(`Type: ${tool.type}`);
console.log(`Schema: ${tool.tool_schema}`);
});
Create integration:
const tool = await user.tools.create({
name: 'jira-integration',
friendly_name: 'Jira Service',
short_description: 'Create and manage Jira issues',
tool_schema: JSON.stringify({
type: 'object',
properties: {
project: {
type: 'string',
description: 'Jira project key'
},
type: {
type: 'string',
enum: ['bug', 'task', 'story'],
default: 'task'
},
title: {
type: 'string',
minLength: 1
},
description: {
type: 'string'
},
priority: {
type: 'string',
enum: ['high', 'medium', 'low'],
default: 'medium'
}
},
required: ['project', 'title']
}),
required_environment_variables: [
'JIRA_HOST',
'JIRA_EMAIL',
'JIRA_API_TOKEN'
],
source_url: 'https://your-domain.atlassian.net',
metadata: {
type: 'issue-tracker',
provider: 'atlassian',
version: '1.0',
capabilities: ['create', 'read', 'update']
}
});
Get the image functionality for this user's profile
This getter provides access to the user's profile image operations through the Image class. It allows for profile image uploads and other image-related operations specific to this user.
A new Image instance configured for this user's profile
Get the user's access policies
This getter provides access to the user's access control policies through the AccessPolicies collection. It enables management of IAM policies that define fine-grained permissions for resources and actions.
AccessPolicies collection for managing access control policies
Get the user's permissions
This getter provides access to the user's permissions through the UserPermissions collection. It enables management of permissions that associate clients with access policies for this user.
UserPermissions collection for managing user permissions
Get the user's usage meters
This getter provides access to the user's usage meters through the Meters collection. It enables tracking of service consumption and associated costs for billing purposes.
Meters collection for managing usage meters
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.
True if the entity is active, false otherwise
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:
The model data as a plain object matching the interface type
Convert model instance to API payload
This method creates a payload suitable for API requests by:
A clean object suitable for API requests
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.
Object containing properties to update
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:
Promise resolving to the updated model data
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:
Promise that resolves when deletion is successful
User class for managing platform users
This class represents a user account in the Mosaia platform. Users are the primary actors who can create and manage AI resources, interact with agents, and collaborate within organizations.
Features:
Remarks
Users can manage:
Available resources:
Example
Basic user setup:
Example
Resource management: