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,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
+
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Search Module
3
+ * Web search, content extraction, and research crawling
4
+ */
5
+
6
+ export class OblienSearch {
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
+ * Search the web with multiple queries
20
+ * @param {Object} options - Search options
21
+ * @param {Array<string>} options.queries - Array of search queries (required)
22
+ * @param {boolean} [options.includeAnswers=false] - Include AI-generated answers
23
+ * @param {Object} [options.options] - Additional search options
24
+ * @param {number} [options.options.maxResults] - Max results per query
25
+ * @param {string} [options.options.region] - Search region
26
+ * @param {string} [options.options.timeRange] - Time range filter
27
+ * @returns {Promise<Array>} Search results
28
+ */
29
+ async search(options) {
30
+ const { queries, includeAnswers = false, options: searchOptions = {} } = options;
31
+
32
+ if (!queries || !Array.isArray(queries) || queries.length === 0) {
33
+ throw new Error('Queries array is required and must not be empty');
34
+ }
35
+
36
+ const response = await this.client.post('search', {
37
+ queries,
38
+ includeAnswers,
39
+ options: searchOptions
40
+ });
41
+
42
+ return response;
43
+ }
44
+
45
+ /**
46
+ * Extract and summarize content from web pages
47
+ * @param {Object} options - Extract options
48
+ * @param {Array<Object>} options.pages - Array of pages to extract (required)
49
+ * @param {string} options.pages[].url - Page URL (required)
50
+ * @param {Array<string>} options.pages[].details - Details to extract (required)
51
+ * @param {string} [options.pages[].summaryLevel='medium'] - Summary level: 'brief' | 'medium' | 'detailed'
52
+ * @param {Object} [options.options] - Additional extraction options
53
+ * @returns {Promise<Object>} Extracted content
54
+ */
55
+ async extract(options) {
56
+ const { pages, options: extractOptions = {} } = options;
57
+
58
+ if (!pages || !Array.isArray(pages) || pages.length === 0) {
59
+ throw new Error('Pages array is required and must not be empty');
60
+ }
61
+
62
+ // Validate pages
63
+ pages.forEach((page, index) => {
64
+ if (!page.url) {
65
+ throw new Error(`Page at index ${index} is missing 'url'`);
66
+ }
67
+ if (!page.details || !Array.isArray(page.details) || page.details.length === 0) {
68
+ throw new Error(`Page at index ${index} is missing 'details' array`);
69
+ }
70
+ });
71
+
72
+ const response = await this.client.post('search/extract', {
73
+ pages,
74
+ options: extractOptions
75
+ });
76
+
77
+ return response;
78
+ }
79
+
80
+ /**
81
+ * Create deep research report with AI crawling
82
+ * @param {Object} options - Crawl options
83
+ * @param {string} options.instructions - Research instructions (required)
84
+ * @param {Object} [options.options] - Additional crawl options
85
+ * @param {boolean} [options.options.thinking] - Enable thinking mode
86
+ * @param {boolean} [options.options.allow_thinking_callback] - Allow thinking callbacks
87
+ * @param {boolean} [options.options.stream_text] - Stream text responses
88
+ * @param {string} [options.reportType='pdf'] - Report type: 'pdf' | 'markdown' | 'html'
89
+ * @param {Function} [options.onProgress] - Callback for progress updates (streaming)
90
+ * @returns {Promise<Object>} Research report result
91
+ */
92
+ async crawl(options) {
93
+ const {
94
+ instructions,
95
+ options: crawlOptions = {},
96
+ reportType = 'pdf',
97
+ onProgress = null
98
+ } = options;
99
+
100
+ if (!instructions || typeof instructions !== 'string') {
101
+ throw new Error('Instructions string is required');
102
+ }
103
+
104
+ // If onProgress is provided, we need to handle streaming
105
+ if (onProgress && typeof onProgress === 'function') {
106
+ return this._crawlWithStreaming({
107
+ instructions,
108
+ options: crawlOptions,
109
+ reportType,
110
+ onProgress
111
+ });
112
+ }
113
+
114
+ // Standard JSON response
115
+ const response = await this.client.post('search/crawl', {
116
+ instructions,
117
+ options: crawlOptions,
118
+ responseType: 'json',
119
+ reportType
120
+ });
121
+
122
+ return response;
123
+ }
124
+
125
+ /**
126
+ * Handle streaming crawl with progress callbacks
127
+ * @private
128
+ */
129
+ async _crawlWithStreaming({ instructions, options, reportType, onProgress }) {
130
+ const url = this.client._buildURL('search/crawl');
131
+ const headers = this.client.getAuthHeaders();
132
+
133
+ const response = await fetch(url, {
134
+ method: 'POST',
135
+ headers,
136
+ body: JSON.stringify({
137
+ instructions,
138
+ options,
139
+ responseType: 'stream',
140
+ reportType
141
+ })
142
+ });
143
+
144
+ if (!response.ok) {
145
+ const error = await response.json();
146
+ throw new Error(error.message || error.error || 'Crawl request failed');
147
+ }
148
+
149
+ // Handle streaming response
150
+ const reader = response.body.getReader();
151
+ const decoder = new TextDecoder();
152
+ let buffer = '';
153
+ let finalResult = null;
154
+
155
+ while (true) {
156
+ const { done, value } = await reader.read();
157
+
158
+ if (done) break;
159
+
160
+ buffer += decoder.decode(value, { stream: true });
161
+
162
+ // Process complete SSE messages
163
+ const lines = buffer.split('\n\n');
164
+ buffer = lines.pop() || ''; // Keep incomplete message in buffer
165
+
166
+ for (const line of lines) {
167
+ if (line.startsWith('data: ')) {
168
+ try {
169
+ const data = JSON.parse(line.slice(6));
170
+
171
+ if (data.type === 'crawl_end') {
172
+ finalResult = data.data;
173
+ } else if (data.type === 'error') {
174
+ throw new Error(data.error);
175
+ } else {
176
+ // Progress update
177
+ onProgress(data);
178
+ }
179
+ } catch (error) {
180
+ console.error('Error parsing SSE data:', error);
181
+ }
182
+ }
183
+ }
184
+ }
185
+
186
+ return finalResult || { success: true };
187
+ }
188
+ }
189
+
190
+ export default OblienSearch;
191
+