oblien 1.1.0 → 1.1.1

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,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
+
@@ -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
+
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Sandboxes Module
3
+ * Manages cloud sandboxes - create, control, monitor
4
+ */
5
+
6
+ import { Sandbox } from './sandbox.js';
7
+
8
+ export class OblienSandboxes {
9
+ /**
10
+ * @param {import('../client.js').OblienClient} client - Oblien client instance
11
+ */
12
+ constructor(client) {
13
+ if (!client) {
14
+ throw new Error('Oblien client is required');
15
+ }
16
+
17
+ this.client = client;
18
+ }
19
+
20
+ /**
21
+ * Create a new sandbox
22
+ * @param {Object} options - Sandbox options
23
+ * @param {string} [options.name] - Sandbox name
24
+ * @param {string} [options.region='us-east-1'] - Region: 'us-east-1' | 'us-west-1' | 'eu-west-1'
25
+ * @param {string} [options.template='node-20'] - Template: 'node-20' | 'python-3' | 'blank' | custom
26
+ * @param {Object} [options.config] - Custom configuration
27
+ * @param {boolean} [options.autoStart=true] - Auto-start sandbox after creation
28
+ * @returns {Promise<Object>} Created sandbox data with token
29
+ */
30
+ async create(options = {}) {
31
+ const {
32
+ name,
33
+ region = 'us-east-1',
34
+ template = 'node-20',
35
+ config,
36
+ autoStart = true
37
+ } = options;
38
+
39
+ const response = await this.client.post('sandbox', {
40
+ name,
41
+ region,
42
+ template,
43
+ config,
44
+ autoStart
45
+ });
46
+
47
+ return response;
48
+ }
49
+
50
+ /**
51
+ * List all sandboxes with pagination and filtering
52
+ * @param {Object} [options] - Query options
53
+ * @param {number} [options.page=1] - Page number
54
+ * @param {number} [options.limit=20] - Results per page
55
+ * @param {string} [options.status] - Filter by status: 'active' | 'stopped' | 'suspended' | 'deleted'
56
+ * @returns {Promise<Object>} Sandboxes data with pagination info
57
+ */
58
+ async list(options = {}) {
59
+ const params = {
60
+ page: options.page || 1,
61
+ limit: options.limit || 20
62
+ };
63
+
64
+ if (options.status) {
65
+ params.status = options.status;
66
+ }
67
+
68
+ const response = await this.client.get('sandbox', params);
69
+ return response;
70
+ }
71
+
72
+ /**
73
+ * Get sandbox by ID
74
+ * @param {string} sandboxId - Sandbox ID
75
+ * @returns {Promise<Object>} Sandbox data
76
+ */
77
+ async get(sandboxId) {
78
+ if (!sandboxId) {
79
+ throw new Error('Sandbox ID is required');
80
+ }
81
+
82
+ const sandbox = new Sandbox({ client: this.client, sandboxId });
83
+ return await sandbox.get();
84
+ }
85
+
86
+ /**
87
+ * Update sandbox
88
+ * @param {string} sandboxId - Sandbox ID
89
+ * @param {Object} updates - Fields to update
90
+ * @returns {Promise<Object>} Update result
91
+ */
92
+ async update(sandboxId, updates) {
93
+ const sandbox = new Sandbox({ client: this.client, sandboxId });
94
+ return await sandbox.update(updates);
95
+ }
96
+
97
+ /**
98
+ * Delete sandbox
99
+ * @param {string} sandboxId - Sandbox ID
100
+ * @returns {Promise<Object>} Delete result
101
+ */
102
+ async delete(sandboxId) {
103
+ const sandbox = new Sandbox({ client: this.client, sandboxId });
104
+ return await sandbox.delete();
105
+ }
106
+
107
+ /**
108
+ * Start sandbox
109
+ * @param {string} sandboxId - Sandbox ID
110
+ * @returns {Promise<Object>} Start result with new token
111
+ */
112
+ async start(sandboxId) {
113
+ const sandbox = new Sandbox({ client: this.client, sandboxId });
114
+ return await sandbox.start();
115
+ }
116
+
117
+ /**
118
+ * Stop sandbox
119
+ * @param {string} sandboxId - Sandbox ID
120
+ * @returns {Promise<Object>} Stop result
121
+ */
122
+ async stop(sandboxId) {
123
+ const sandbox = new Sandbox({ client: this.client, sandboxId });
124
+ return await sandbox.stop();
125
+ }
126
+
127
+ /**
128
+ * Restart sandbox
129
+ * @param {string} sandboxId - Sandbox ID
130
+ * @returns {Promise<Object>} Restart result with new token
131
+ */
132
+ async restart(sandboxId) {
133
+ const sandbox = new Sandbox({ client: this.client, sandboxId });
134
+ return await sandbox.restart();
135
+ }
136
+
137
+ /**
138
+ * Regenerate sandbox token
139
+ * @param {string} sandboxId - Sandbox ID
140
+ * @returns {Promise<Object>} New token (1h expiry)
141
+ */
142
+ async regenerateToken(sandboxId) {
143
+ const sandbox = new Sandbox({ client: this.client, sandboxId });
144
+ return await sandbox.regenerateToken();
145
+ }
146
+
147
+ /**
148
+ * Get sandbox metrics
149
+ * @param {string} sandboxId - Sandbox ID
150
+ * @returns {Promise<Object>} Sandbox metrics
151
+ */
152
+ async getMetrics(sandboxId) {
153
+ const sandbox = new Sandbox({ client: this.client, sandboxId });
154
+ return await sandbox.getMetrics();
155
+ }
156
+
157
+ /**
158
+ * Get sandbox stats (overall statistics)
159
+ * @returns {Promise<Object>} Sandbox statistics
160
+ */
161
+ async getStats() {
162
+ return await this.client.get('sandbox/stats');
163
+ }
164
+
165
+ /**
166
+ * Get sandbox activity
167
+ * @returns {Promise<Object>} Sandbox activity logs
168
+ */
169
+ async getActivity() {
170
+ return await this.client.get('sandbox/activity');
171
+ }
172
+
173
+ /**
174
+ * Create a Sandbox instance for chaining operations
175
+ * @param {string} sandboxId - Sandbox ID
176
+ * @returns {Sandbox} Sandbox instance
177
+ */
178
+ sandbox(sandboxId) {
179
+ return new Sandbox({ client: this.client, sandboxId });
180
+ }
181
+ }
182
+
183
+ export { Sandbox };
184
+ export default OblienSandboxes;
185
+
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Sandbox Class
3
+ * Represents a single sandbox with methods for operations
4
+ */
5
+
6
+ export class Sandbox {
7
+ /**
8
+ * @param {Object} options
9
+ * @param {import('../client.js').OblienClient} options.client - Oblien client instance
10
+ * @param {string} [options.sandboxId] - Sandbox ID
11
+ */
12
+ constructor({ client, sandboxId = null }) {
13
+ if (!client) {
14
+ throw new Error('Oblien client is required');
15
+ }
16
+
17
+ this.client = client;
18
+ this.sandboxId = sandboxId;
19
+ }
20
+
21
+ /**
22
+ * Get sandbox details
23
+ * @returns {Promise<Object>} Sandbox data
24
+ */
25
+ async get() {
26
+ if (!this.sandboxId) {
27
+ throw new Error('Sandbox ID is required');
28
+ }
29
+
30
+ const response = await this.client.get(`sandbox/${this.sandboxId}`);
31
+ return response.sandbox || response;
32
+ }
33
+
34
+ /**
35
+ * Update sandbox
36
+ * @param {Object} updates - Fields to update
37
+ * @param {string} [updates.name] - Sandbox name
38
+ * @param {string} [updates.region] - Region
39
+ * @param {Object} [updates.config] - Configuration
40
+ * @returns {Promise<Object>} Update result
41
+ */
42
+ async update(updates) {
43
+ if (!this.sandboxId) {
44
+ throw new Error('Sandbox ID is required');
45
+ }
46
+
47
+ return await this.client.put(`sandbox/${this.sandboxId}`, updates);
48
+ }
49
+
50
+ /**
51
+ * Delete sandbox
52
+ * @returns {Promise<Object>} Delete result
53
+ */
54
+ async delete() {
55
+ if (!this.sandboxId) {
56
+ throw new Error('Sandbox ID is required');
57
+ }
58
+
59
+ return await this.client.delete(`sandbox/${this.sandboxId}`);
60
+ }
61
+
62
+ /**
63
+ * Start sandbox
64
+ * @returns {Promise<Object>} Start result with new token
65
+ */
66
+ async start() {
67
+ if (!this.sandboxId) {
68
+ throw new Error('Sandbox ID is required');
69
+ }
70
+
71
+ return await this.client.post(`sandbox/${this.sandboxId}/start`);
72
+ }
73
+
74
+ /**
75
+ * Stop sandbox
76
+ * @returns {Promise<Object>} Stop result
77
+ */
78
+ async stop() {
79
+ if (!this.sandboxId) {
80
+ throw new Error('Sandbox ID is required');
81
+ }
82
+
83
+ return await this.client.post(`sandbox/${this.sandboxId}/stop`);
84
+ }
85
+
86
+ /**
87
+ * Restart sandbox
88
+ * @returns {Promise<Object>} Restart result with new token
89
+ */
90
+ async restart() {
91
+ if (!this.sandboxId) {
92
+ throw new Error('Sandbox ID is required');
93
+ }
94
+
95
+ return await this.client.post(`sandbox/${this.sandboxId}/restart`);
96
+ }
97
+
98
+ /**
99
+ * Regenerate sandbox token
100
+ * @returns {Promise<Object>} New token (1h expiry)
101
+ */
102
+ async regenerateToken() {
103
+ if (!this.sandboxId) {
104
+ throw new Error('Sandbox ID is required');
105
+ }
106
+
107
+ return await this.client.post(`sandbox/${this.sandboxId}/regenerate-token`);
108
+ }
109
+
110
+ /**
111
+ * Get sandbox metrics
112
+ * @returns {Promise<Object>} Sandbox metrics
113
+ */
114
+ async getMetrics() {
115
+ if (!this.sandboxId) {
116
+ throw new Error('Sandbox ID is required');
117
+ }
118
+
119
+ return await this.client.get(`sandbox/${this.sandboxId}/metrics`);
120
+ }
121
+ }
122
+
123
+ export default Sandbox;
124
+