oblien 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Agent Settings Class
3
+ * Manages all agent settings with proper sections
4
+ */
5
+
6
+ export class AgentSettings {
7
+ /**
8
+ * @param {Object} options
9
+ * @param {import('../client.js').OblienClient} options.client - Oblien client instance
10
+ * @param {string} options.agentId - Agent ID
11
+ */
12
+ constructor({ client, agentId }) {
13
+ if (!client) {
14
+ throw new Error('Oblien client is required');
15
+ }
16
+ if (!agentId) {
17
+ throw new Error('Agent ID is required');
18
+ }
19
+
20
+ this.client = client;
21
+ this.agentId = agentId;
22
+ }
23
+
24
+ /**
25
+ * Update boolean switches
26
+ * @param {Object} switches - Switch values
27
+ * @param {boolean} [switches.enable_memory] - Enable conversation memory
28
+ * @param {boolean} [switches.allow_thinking] - Allow thinking process
29
+ * @param {boolean} [switches.allow_images] - Allow image uploads
30
+ * @param {boolean} [switches.allow_videos] - Allow video uploads
31
+ * @param {boolean} [switches.allow_audio] - Allow audio uploads
32
+ * @param {boolean} [switches.allow_documents] - Allow document uploads
33
+ * @param {boolean} [switches.allow_built_in] - Allow built-in tools
34
+ * @returns {Promise<Object>} Update result
35
+ */
36
+ async updateSwitches(switches) {
37
+ return await this.client.put(`ai/agents/${this.agentId}/switches`, switches);
38
+ }
39
+
40
+ /**
41
+ * Update model configuration
42
+ * @param {Object} config - Model configuration
43
+ * @param {string} [config.model] - Model name (e.g., 'oblien-master')
44
+ * @param {number} [config.temperature] - Temperature 0-2 (default: 1)
45
+ * @param {number} [config.max_tokens] - Max tokens 1-200000 (default: 2000)
46
+ * @param {number} [config.top_p] - Top P 0-1 (default: 1)
47
+ * @returns {Promise<Object>} Update result
48
+ */
49
+ async updateModelConfig(config) {
50
+ return await this.client.put(`ai/agents/${this.agentId}/model-config`, config);
51
+ }
52
+
53
+ /**
54
+ * Update tools array
55
+ * @param {Array<string>} tools - Array of tool slugs
56
+ * @returns {Promise<Object>} Update result
57
+ */
58
+ async updateTools(tools) {
59
+ return await this.client.put(`ai/agents/${this.agentId}/tools`, { tools });
60
+ }
61
+
62
+ /**
63
+ * Update guest limits
64
+ * @param {Object} limits - Guest limit configuration
65
+ * @param {boolean} [limits.enabled] - Enable guest limits
66
+ * @param {number} [limits.max_requests_per_minute] - Max requests per minute (1-1000)
67
+ * @param {number} [limits.max_messages_per_hour] - Max messages per hour (1-10000)
68
+ * @param {number} [limits.max_messages_per_day] - Max messages per day (1-50000)
69
+ * @param {number} [limits.max_total_tokens_per_day] - Max total tokens per day (1000-10000000)
70
+ * @param {number} [limits.max_input_tokens_per_day] - Max input tokens per day (1000-10000000)
71
+ * @param {number} [limits.max_output_tokens_per_day] - Max output tokens per day (1000-10000000)
72
+ * @returns {Promise<Object>} Update result
73
+ */
74
+ async updateGuestLimits(limits) {
75
+ return await this.client.put(`ai/agents/${this.agentId}/guest-limits`, limits);
76
+ }
77
+
78
+ /**
79
+ * Update context settings
80
+ * @param {Object} context - Context configuration
81
+ * @param {number} [context.max_history_messages] - Max history messages
82
+ * @param {number} [context.history_token_limit] - History token limit
83
+ * @returns {Promise<Object>} Update result
84
+ */
85
+ async updateContext(context) {
86
+ return await this.client.put(`ai/agents/${this.agentId}/context`, context);
87
+ }
88
+
89
+ /**
90
+ * Get all settings sections
91
+ * @returns {Promise<Object>} All settings
92
+ */
93
+ async getAll() {
94
+ const agent = await this.client.get(`ai/agents/${this.agentId}`);
95
+ return agent.agent?.settings || agent.settings || {};
96
+ }
97
+ }
98
+
99
+ export default AgentSettings;
100
+
@@ -0,0 +1,155 @@
1
+ /**
2
+ * Tools Class
3
+ * Manages AI tools - listing, searching, creating, and getting tool details
4
+ */
5
+
6
+ export class Tools {
7
+ /**
8
+ * @param {import('../client.js').OblienClient} client - Oblien client instance
9
+ */
10
+ constructor(client) {
11
+ if (!client) {
12
+ throw new Error('Oblien client is required');
13
+ }
14
+
15
+ this.client = client;
16
+ }
17
+
18
+ /**
19
+ * List all available tools with optional filters
20
+ * @param {Object} [options] - Filter options
21
+ * @param {string} [options.type] - Filter by type: 'client' | 'server' | 'hybrid'
22
+ * @param {string} [options.category] - Filter by category: 'custom' | 'file' | 'search' | 'terminal' | 'browser' | 'project' | 'web'
23
+ * @param {boolean} [options.requireEnvironment] - Filter by environment requirement
24
+ * @param {boolean} [options.myCustomTools] - Show only user's custom tools
25
+ * @returns {Promise<Object>} List of tools
26
+ */
27
+ async list(options = {}) {
28
+ const params = {};
29
+
30
+ if (options.type) params.type = options.type;
31
+ if (options.category) params.category = options.category;
32
+ if (options.requireEnvironment !== undefined) {
33
+ params.require_environment = String(options.requireEnvironment);
34
+ }
35
+ if (options.myCustomTools) params.my_custom_tools = 'true';
36
+
37
+ const response = await this.client.get('ai/tools', params);
38
+ return response;
39
+ }
40
+
41
+ /**
42
+ * Search tools by query
43
+ * @param {string} query - Search query
44
+ * @param {Object} [options] - Filter options
45
+ * @param {string} [options.type] - Filter by type
46
+ * @param {string} [options.category] - Filter by category
47
+ * @param {boolean} [options.myCustomTools] - Show only user's custom tools
48
+ * @returns {Promise<Object>} Search results
49
+ */
50
+ async search(query, options = {}) {
51
+ const params = { q: query };
52
+
53
+ if (options.type) params.type = options.type;
54
+ if (options.category) params.category = options.category;
55
+ if (options.myCustomTools) params.my_custom_tools = 'true';
56
+
57
+ const response = await this.client.get('ai/tools/search', params);
58
+ return response;
59
+ }
60
+
61
+ /**
62
+ * Get tool by slug
63
+ * @param {string} slug - Tool slug/ID
64
+ * @returns {Promise<Object>} Tool details
65
+ */
66
+ async get(slug) {
67
+ if (!slug) {
68
+ throw new Error('Tool slug is required');
69
+ }
70
+
71
+ const response = await this.client.get(`ai/tools/${slug}`);
72
+ return response;
73
+ }
74
+
75
+ /**
76
+ * Create a custom tool (client-side tool)
77
+ * @param {Object} toolData - Tool configuration
78
+ * @param {string} toolData.slug - Unique tool slug/ID
79
+ * @param {string} toolData.tool_name - Tool name
80
+ * @param {string} toolData.tool_description - Tool description
81
+ * @param {string} [toolData.icon] - Tool icon
82
+ * @param {string} [toolData.type='client'] - Tool type: 'client' | 'server' | 'hybrid'
83
+ * @param {string} [toolData.category='custom'] - Tool category
84
+ * @param {Object} [toolData.input_scheme] - Input schema/parameters
85
+ * @param {Object} [toolData.output_scheme] - Output schema
86
+ * @param {string} [toolData.prompt] - Tool prompt/instructions
87
+ * @param {boolean} [toolData.require_environment=false] - Requires context/environment
88
+ * @param {string} [toolData.context_type] - Context type if required
89
+ * @returns {Promise<Object>} Created tool
90
+ */
91
+ async create(toolData) {
92
+ const {
93
+ slug,
94
+ tool_name,
95
+ tool_description,
96
+ icon,
97
+ type = 'client',
98
+ category = 'custom',
99
+ input_scheme,
100
+ output_scheme,
101
+ prompt,
102
+ require_environment = false,
103
+ context_type
104
+ } = toolData;
105
+
106
+ if (!slug || !tool_name || !tool_description) {
107
+ throw new Error('slug, tool_name, and tool_description are required');
108
+ }
109
+
110
+ const payload = {
111
+ slug,
112
+ tool_name,
113
+ tool_description,
114
+ icon,
115
+ type,
116
+ category,
117
+ input_scheme,
118
+ output_scheme,
119
+ prompt,
120
+ require_environment,
121
+ context_type
122
+ };
123
+
124
+ const response = await this.client.post('ai/tools', payload);
125
+ return response;
126
+ }
127
+
128
+ /**
129
+ * Validate tool IDs
130
+ * @param {Array<string>} toolIds - Array of tool slugs to validate
131
+ * @returns {Promise<Object>} Validation result
132
+ */
133
+ async validate(toolIds) {
134
+ if (!Array.isArray(toolIds)) {
135
+ throw new Error('toolIds must be an array');
136
+ }
137
+
138
+ // Get all tools and check which ones exist
139
+ const allTools = await this.list();
140
+ const existingSlugs = allTools.tools.map(t => t.slug);
141
+
142
+ const validIds = toolIds.filter(id => existingSlugs.includes(id));
143
+ const invalidIds = toolIds.filter(id => !existingSlugs.includes(id));
144
+
145
+ return {
146
+ valid: invalidIds.length === 0,
147
+ validIds,
148
+ invalidIds,
149
+ error: invalidIds.length > 0 ? `Invalid tool IDs: ${invalidIds.join(', ')}` : null
150
+ };
151
+ }
152
+ }
153
+
154
+ export default Tools;
155
+
package/src/chat/index.js CHANGED
@@ -34,6 +34,12 @@ export class OblienChat {
34
34
  * @param {string} options.agentId - Agent ID to chat with
35
35
  * @param {string} [options.workflowId] - Workflow ID (if using workflow)
36
36
  * @param {Object} [options.workspace] - Workspace configuration
37
+ * @param {string} [options.endUserId] - End user ID (for client's end users)
38
+ * @param {string} [options.namespace] - Guest namespace for rate limiting
39
+ * @param {boolean} [options.isGuest] - Is this a guest session
40
+ * @param {string} [options.ipAddress] - IP address of the user
41
+ * @param {string} [options.userAgent] - User agent of the user
42
+ * @param {string} [options.fingerprint] - Fingerprint of the user
37
43
  * @returns {Promise<Object>} Session data with token
38
44
  */
39
45
  async createSession(options) {
@@ -54,10 +60,11 @@ export class OblienChat {
54
60
  * @param {string} [options.workflowId] - Workflow ID
55
61
  * @param {Object} [options.metadata] - Additional guest metadata
56
62
  * @param {Object} [options.workspace] - Workspace configuration
63
+ * @param {string} [options.endUserId] - End user ID (for client's end users)
57
64
  * @returns {Promise<Object>} Session data with token and guest info
58
65
  */
59
66
  async createGuestSession(options) {
60
- const { ip, fingerprint, agentId, workflowId, metadata = {}, workspace } = options;
67
+ const { ip, fingerprint, agentId, workflowId, metadata = {}, workspace, endUserId } = options;
61
68
 
62
69
  if (!ip) {
63
70
  throw new Error('IP address is required for guest sessions');
@@ -81,6 +88,7 @@ export class OblienChat {
81
88
  ipAddress: ip,
82
89
  userAgent: metadata.userAgent,
83
90
  fingerprint: fingerprint,
91
+ endUserId: endUserId,
84
92
  });
85
93
 
86
94
  const sessionData = await session.create();
@@ -16,6 +16,7 @@ export class ChatSession {
16
16
  * @param {string} [options.ipAddress] - IP address of the user
17
17
  * @param {string} [options.userAgent] - User agent of the user
18
18
  * @param {string} [options.fingerprint] - Fingerprint of the user
19
+ * @param {string} [options.endUserId] - End user ID (for client's end users)
19
20
  */
20
21
  constructor(options) {
21
22
  if (!options.client) {
@@ -38,6 +39,7 @@ export class ChatSession {
38
39
  this.ipAddress = options.ipAddress || null;
39
40
  this.userAgent = options.userAgent || null;
40
41
  this.fingerprint = options.fingerprint || null;
42
+ this.endUserId = options.endUserId || null;
41
43
  }
42
44
 
43
45
  /**
@@ -54,6 +56,7 @@ export class ChatSession {
54
56
  ip_address: this.ipAddress,
55
57
  user_agent: this.userAgent,
56
58
  fingerprint: this.fingerprint,
59
+ end_user_id: this.endUserId,
57
60
  };
58
61
 
59
62
  this.data = await this.client.post('ai/session/create', payload);
package/src/client.js CHANGED
@@ -6,21 +6,19 @@
6
6
  export class OblienClient {
7
7
  /**
8
8
  * @param {Object} config - Configuration options
9
- * @param {string} config.apiKey - Your Oblien Client ID (x-client-id)
10
- * @param {string} config.apiSecret - Your Oblien Client Secret (x-client-secret)
11
- * @param {string} [config.baseURL] - Base URL for API (default: https://api.oblien.com)
12
- * @param {string} [config.version] - API version (default: v1)
9
+ * @param {string} config.clientId - Your Oblien Client ID (x-client-id)
10
+ * @param {string} config.clientSecret - Your Oblien Client Secret (x-client-secret)
13
11
  */
14
12
  constructor(config) {
15
- if (!config || !config.apiKey) {
16
- throw new Error('Oblien API key (client ID) is required');
13
+ if (!config || !config.clientId) {
14
+ throw new Error('Oblien client ID is required');
17
15
  }
18
- if (!config.apiSecret) {
19
- throw new Error('Oblien API secret (client secret) is required');
16
+ if (!config.clientSecret) {
17
+ throw new Error('Oblien client secret is required');
20
18
  }
21
19
 
22
- this.clientId = config.apiKey;
23
- this.clientSecret = config.apiSecret;
20
+ this.clientId = config.clientId;
21
+ this.clientSecret = config.clientSecret;
24
22
  this.baseURL = config.baseURL || 'https://api.oblien.com';
25
23
  }
26
24
 
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Oblien Icons Module
3
+ * Search and fetch icons, images, and videos
4
+ */
5
+
6
+ export class OblienIcons {
7
+ constructor(client) {
8
+ if (!client) throw new Error('Oblien client is required');
9
+ this.client = client;
10
+ }
11
+
12
+ /**
13
+ * Search for icons using semantic search
14
+ *
15
+ * @param {string} query - Search query
16
+ * @param {Object} options - Search options
17
+ * @param {number} options.offset - Pagination offset (default: 0)
18
+ * @param {number} options.limit - Number of results (default: 100)
19
+ * @returns {Promise<Object>} Search results with pagination info
20
+ *
21
+ * @example
22
+ * const results = await icons.search('home', { limit: 50 });
23
+ * // Returns:
24
+ * // {
25
+ * // results: [
26
+ * // {
27
+ * // url: 'https://cdn.oblien.com/static/png-icons/...',
28
+ * // filename: 'home-outline.png',
29
+ * // name: 'home',
30
+ * // description: 'home',
31
+ * // style: 'Outline',
32
+ * // score: 0.95,
33
+ * // success: true
34
+ * // }
35
+ * // ],
36
+ * // hasMore: true,
37
+ * // offset: 50,
38
+ * // total: 245
39
+ * // }
40
+ */
41
+ async search(query, options = {}) {
42
+ if (!query || typeof query !== 'string') {
43
+ throw new Error('Query must be a non-empty string');
44
+ }
45
+
46
+ const { offset = 0, limit = 100 } = options;
47
+
48
+ return this.client.post('icons/search-icons', {
49
+ query: query.trim(),
50
+ offset,
51
+ limit
52
+ });
53
+ }
54
+
55
+ /**
56
+ * Fetch multiple items (icons, images, videos) with semantic matching
57
+ *
58
+ * @param {Array<Object>} items - Array of items to fetch
59
+ * @param {string} items[].type - Type: 'icon', 'image', or 'video'
60
+ * @param {string} items[].description - Description for semantic matching
61
+ * @param {boolean} items[].is_vector - Whether the item is a vector (optional)
62
+ * @param {string} items[].variant - Variant type (optional, for images/videos)
63
+ * @returns {Promise<Array>} Array of fetched items with URLs
64
+ *
65
+ * @example
66
+ * const items = await icons.fetch([
67
+ * { type: 'icon', description: 'user profile' },
68
+ * { type: 'icon', description: 'settings gear' },
69
+ * { type: 'image', description: 'mountain landscape' },
70
+ * { type: 'video', description: 'ocean waves' }
71
+ * ]);
72
+ *
73
+ * // Returns:
74
+ * // [
75
+ * // {
76
+ * // url: 'https://cdn.oblien.com/static/icons/...',
77
+ * // description: 'user profile',
78
+ * // style: 'Outline',
79
+ * // success: true
80
+ * // },
81
+ * // {
82
+ * // url: 'https://cdn.oblien.com/static/assets/...',
83
+ * // type: 'image',
84
+ * // description: 'mountain landscape',
85
+ * // variant: 'regular',
86
+ * // success: true
87
+ * // }
88
+ * // ]
89
+ */
90
+ async fetch(items) {
91
+ if (!Array.isArray(items) || items.length === 0) {
92
+ throw new Error('Items must be a non-empty array');
93
+ }
94
+
95
+ // Validate items
96
+ for (const item of items) {
97
+ if (!item.type || !['icon', 'image', 'video'].includes(item.type)) {
98
+ throw new Error('Each item must have a valid type: icon, image, or video');
99
+ }
100
+ if (!item.description || typeof item.description !== 'string') {
101
+ throw new Error('Each item must have a description string');
102
+ }
103
+ }
104
+
105
+ return this.client.post('icons/fetch', { data: items });
106
+ }
107
+
108
+ /**
109
+ * Fetch a single icon
110
+ * Convenience method for fetching one icon
111
+ *
112
+ * @param {string} description - Icon description
113
+ * @returns {Promise<Object>} Icon object with URL
114
+ *
115
+ * @example
116
+ * const icon = await icons.fetchIcon('home');
117
+ * // Returns: { url: '...', description: 'home', style: 'Outline', success: true }
118
+ */
119
+ async fetchIcon(description) {
120
+ if (!description || typeof description !== 'string') {
121
+ throw new Error('Description must be a non-empty string');
122
+ }
123
+
124
+ const result = await this.fetch([{ type: 'icon', description }]);
125
+ return result[0] || null;
126
+ }
127
+
128
+ /**
129
+ * Fetch multiple icons at once
130
+ * Convenience method for fetching multiple icons
131
+ *
132
+ * @param {Array<string>} descriptions - Array of icon descriptions
133
+ * @returns {Promise<Array>} Array of icon objects
134
+ *
135
+ * @example
136
+ * const icons = await icons.fetchIcons(['home', 'settings', 'user']);
137
+ * // Returns: [{ url: '...', description: 'home', ... }, ...]
138
+ */
139
+ async fetchIcons(descriptions) {
140
+ if (!Array.isArray(descriptions) || descriptions.length === 0) {
141
+ throw new Error('Descriptions must be a non-empty array');
142
+ }
143
+
144
+ const items = descriptions.map(desc => ({ type: 'icon', description: desc }));
145
+ return this.fetch(items);
146
+ }
147
+
148
+ /**
149
+ * Search icons with pagination helper
150
+ * Automatically handles pagination and returns all results
151
+ *
152
+ * @param {string} query - Search query
153
+ * @param {Object} options - Search options
154
+ * @param {number} options.maxResults - Maximum results to fetch (default: 500)
155
+ * @param {number} options.batchSize - Results per batch (default: 100)
156
+ * @returns {Promise<Array>} All matching icons
157
+ *
158
+ * @example
159
+ * const allIcons = await icons.searchAll('home', { maxResults: 200 });
160
+ * // Returns: [{ url: '...', name: 'home', ... }, ...]
161
+ */
162
+ async searchAll(query, options = {}) {
163
+ const { maxResults = 500, batchSize = 100 } = options;
164
+ const allResults = [];
165
+ let offset = 0;
166
+ let hasMore = true;
167
+
168
+ while (hasMore && allResults.length < maxResults) {
169
+ const response = await this.search(query, {
170
+ offset,
171
+ limit: Math.min(batchSize, maxResults - allResults.length)
172
+ });
173
+
174
+ if (response.results && response.results.length > 0) {
175
+ allResults.push(...response.results);
176
+ }
177
+
178
+ hasMore = response.hasMore && allResults.length < maxResults;
179
+ offset = response.offset;
180
+ }
181
+
182
+ return allResults;
183
+ }
184
+ }
185
+