oblien 1.3.0 → 2.0.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.
Files changed (187) hide show
  1. package/README.md +482 -422
  2. package/dist/client.d.ts +31 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +33 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/error.d.ts +29 -0
  7. package/dist/error.d.ts.map +1 -0
  8. package/dist/error.js +52 -0
  9. package/dist/error.js.map +1 -0
  10. package/dist/http.d.ts +20 -0
  11. package/dist/http.d.ts.map +1 -0
  12. package/dist/http.js +108 -0
  13. package/dist/http.js.map +1 -0
  14. package/dist/index.d.ts +8 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +10 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/resources/api-access.d.ts +21 -0
  19. package/dist/resources/api-access.d.ts.map +1 -0
  20. package/dist/resources/api-access.js +32 -0
  21. package/dist/resources/api-access.js.map +1 -0
  22. package/dist/resources/base.d.ts +17 -0
  23. package/dist/resources/base.d.ts.map +1 -0
  24. package/dist/resources/base.js +21 -0
  25. package/dist/resources/base.js.map +1 -0
  26. package/dist/resources/images.d.ts +11 -0
  27. package/dist/resources/images.d.ts.map +1 -0
  28. package/dist/resources/images.js +16 -0
  29. package/dist/resources/images.js.map +1 -0
  30. package/dist/resources/lifecycle.d.ts +23 -0
  31. package/dist/resources/lifecycle.d.ts.map +1 -0
  32. package/dist/resources/lifecycle.js +32 -0
  33. package/dist/resources/lifecycle.js.map +1 -0
  34. package/dist/resources/logs.d.ts +25 -0
  35. package/dist/resources/logs.d.ts.map +1 -0
  36. package/dist/resources/logs.js +51 -0
  37. package/dist/resources/logs.js.map +1 -0
  38. package/dist/resources/metadata.d.ts +15 -0
  39. package/dist/resources/metadata.d.ts.map +1 -0
  40. package/dist/resources/metadata.js +20 -0
  41. package/dist/resources/metadata.js.map +1 -0
  42. package/dist/resources/metrics.d.ts +17 -0
  43. package/dist/resources/metrics.d.ts.map +1 -0
  44. package/dist/resources/metrics.js +27 -0
  45. package/dist/resources/metrics.js.map +1 -0
  46. package/dist/resources/network.d.ts +17 -0
  47. package/dist/resources/network.d.ts.map +1 -0
  48. package/dist/resources/network.js +20 -0
  49. package/dist/resources/network.js.map +1 -0
  50. package/dist/resources/public-access.d.ts +15 -0
  51. package/dist/resources/public-access.d.ts.map +1 -0
  52. package/dist/resources/public-access.js +21 -0
  53. package/dist/resources/public-access.js.map +1 -0
  54. package/dist/resources/resources.d.ts +15 -0
  55. package/dist/resources/resources.d.ts.map +1 -0
  56. package/dist/resources/resources.js +20 -0
  57. package/dist/resources/resources.js.map +1 -0
  58. package/dist/resources/snapshots.d.ts +27 -0
  59. package/dist/resources/snapshots.d.ts.map +1 -0
  60. package/dist/resources/snapshots.js +45 -0
  61. package/dist/resources/snapshots.js.map +1 -0
  62. package/dist/resources/ssh.d.ts +19 -0
  63. package/dist/resources/ssh.d.ts.map +1 -0
  64. package/dist/resources/ssh.js +28 -0
  65. package/dist/resources/ssh.js.map +1 -0
  66. package/dist/resources/usage.d.ts +25 -0
  67. package/dist/resources/usage.d.ts.map +1 -0
  68. package/dist/resources/usage.js +44 -0
  69. package/dist/resources/usage.js.map +1 -0
  70. package/dist/resources/workloads.d.ts +39 -0
  71. package/dist/resources/workloads.d.ts.map +1 -0
  72. package/dist/resources/workloads.js +83 -0
  73. package/dist/resources/workloads.js.map +1 -0
  74. package/dist/runtime/exec.d.ts +71 -0
  75. package/dist/runtime/exec.d.ts.map +1 -0
  76. package/dist/runtime/exec.js +163 -0
  77. package/dist/runtime/exec.js.map +1 -0
  78. package/dist/runtime/files.d.ts +39 -0
  79. package/dist/runtime/files.d.ts.map +1 -0
  80. package/dist/runtime/files.js +143 -0
  81. package/dist/runtime/files.js.map +1 -0
  82. package/dist/runtime/search.d.ts +23 -0
  83. package/dist/runtime/search.d.ts.map +1 -0
  84. package/dist/runtime/search.js +65 -0
  85. package/dist/runtime/search.js.map +1 -0
  86. package/dist/runtime/terminal.d.ts +29 -0
  87. package/dist/runtime/terminal.d.ts.map +1 -0
  88. package/dist/runtime/terminal.js +58 -0
  89. package/dist/runtime/terminal.js.map +1 -0
  90. package/dist/runtime/watcher.d.ts +27 -0
  91. package/dist/runtime/watcher.d.ts.map +1 -0
  92. package/dist/runtime/watcher.js +53 -0
  93. package/dist/runtime/watcher.js.map +1 -0
  94. package/dist/runtime/ws.d.ts +92 -0
  95. package/dist/runtime/ws.d.ts.map +1 -0
  96. package/dist/runtime/ws.js +228 -0
  97. package/dist/runtime/ws.js.map +1 -0
  98. package/dist/runtime-http.d.ts +35 -0
  99. package/dist/runtime-http.d.ts.map +1 -0
  100. package/dist/runtime-http.js +99 -0
  101. package/dist/runtime-http.js.map +1 -0
  102. package/dist/runtime.d.ts +77 -0
  103. package/dist/runtime.d.ts.map +1 -0
  104. package/dist/runtime.js +97 -0
  105. package/dist/runtime.js.map +1 -0
  106. package/dist/types/client.d.ts +7 -0
  107. package/dist/types/client.d.ts.map +1 -0
  108. package/dist/types/client.js +3 -0
  109. package/dist/types/client.js.map +1 -0
  110. package/dist/types/common.d.ts +13 -0
  111. package/dist/types/common.d.ts.map +1 -0
  112. package/dist/types/common.js +3 -0
  113. package/dist/types/common.js.map +1 -0
  114. package/dist/types/index.d.ts +8 -0
  115. package/dist/types/index.d.ts.map +1 -0
  116. package/dist/types/index.js +2 -0
  117. package/dist/types/index.js.map +1 -0
  118. package/dist/types/network.d.ts +15 -0
  119. package/dist/types/network.d.ts.map +1 -0
  120. package/dist/types/network.js +3 -0
  121. package/dist/types/network.js.map +1 -0
  122. package/dist/types/resources.d.ts +10 -0
  123. package/dist/types/resources.d.ts.map +1 -0
  124. package/dist/types/resources.js +3 -0
  125. package/dist/types/resources.js.map +1 -0
  126. package/dist/types/runtime.d.ts +302 -0
  127. package/dist/types/runtime.d.ts.map +1 -0
  128. package/dist/types/runtime.js +3 -0
  129. package/dist/types/runtime.js.map +1 -0
  130. package/dist/types/workspace-resources.d.ts +186 -0
  131. package/dist/types/workspace-resources.d.ts.map +1 -0
  132. package/dist/types/workspace-resources.js +3 -0
  133. package/dist/types/workspace-resources.js.map +1 -0
  134. package/dist/types/workspace.d.ts +41 -0
  135. package/dist/types/workspace.d.ts.map +1 -0
  136. package/dist/types/workspace.js +3 -0
  137. package/dist/types/workspace.js.map +1 -0
  138. package/dist/workspace.d.ts +135 -0
  139. package/dist/workspace.d.ts.map +1 -0
  140. package/dist/workspace.js +194 -0
  141. package/dist/workspace.js.map +1 -0
  142. package/package.json +30 -69
  143. package/LICENSE +0 -21
  144. package/agents.js +0 -14
  145. package/browser.js +0 -6
  146. package/cdn.js +0 -6
  147. package/chat.js +0 -21
  148. package/credits.js +0 -11
  149. package/icons.js +0 -11
  150. package/index.d.ts +0 -986
  151. package/index.js +0 -63
  152. package/namespaces.js +0 -12
  153. package/sandbox.js +0 -12
  154. package/search.js +0 -11
  155. package/src/agents/agent.js +0 -229
  156. package/src/agents/index.js +0 -227
  157. package/src/agents/settings.js +0 -100
  158. package/src/agents/tools.js +0 -155
  159. package/src/browser/index.js +0 -474
  160. package/src/cdn/index.js +0 -769
  161. package/src/chat/index.js +0 -724
  162. package/src/chat/session.js +0 -93
  163. package/src/client.js +0 -175
  164. package/src/credits/index.js +0 -492
  165. package/src/icons/index.js +0 -185
  166. package/src/namespaces/index.js +0 -236
  167. package/src/namespaces/namespace.js +0 -274
  168. package/src/sandbox/core/api/base.js +0 -89
  169. package/src/sandbox/core/api/database.js +0 -340
  170. package/src/sandbox/core/api/files.js +0 -141
  171. package/src/sandbox/core/api/git.js +0 -174
  172. package/src/sandbox/core/api/search.js +0 -29
  173. package/src/sandbox/core/api/snapshots.js +0 -132
  174. package/src/sandbox/core/api/terminal.js +0 -20
  175. package/src/sandbox/core/auth.js +0 -256
  176. package/src/sandbox/core/client.js +0 -197
  177. package/src/sandbox/core/index.js +0 -22
  178. package/src/sandbox/core/managers/terminal.js +0 -453
  179. package/src/sandbox/core/managers/watcher.js +0 -197
  180. package/src/sandbox/core/types.js +0 -92
  181. package/src/sandbox/core/utils/http.js +0 -89
  182. package/src/sandbox/core/websocket/connection.js +0 -479
  183. package/src/sandbox/index.d.ts +0 -542
  184. package/src/sandbox/index.js +0 -234
  185. package/src/sandbox/sandbox.js +0 -313
  186. package/src/search/index.js +0 -206
  187. package/src/utils/guest-manager.js +0 -454
@@ -1,155 +0,0 @@
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
-
@@ -1,474 +0,0 @@
1
- /**
2
- * Oblien Browser Module
3
- * Browser automation with automatic token management
4
- */
5
-
6
- import { OblienClient } from '../client.js';
7
-
8
- export class OblienBrowser {
9
- /**
10
- * @param {import('../client.js').OblienClient|Object} clientOrConfig - Oblien client instance or { clientId, clientSecret }
11
- * @param {Object} [config] - Configuration options
12
- * @param {string} [config.browserURL] - Browser service URL
13
- */
14
- constructor(clientOrConfig, config = {}) {
15
- if (!clientOrConfig) {
16
- throw new Error('Either provide OblienClient instance or { clientId, clientSecret }');
17
- }
18
-
19
- // If it's already a client instance
20
- if (clientOrConfig.clientId && clientOrConfig.clientSecret && typeof clientOrConfig.get === 'function') {
21
- this.client = clientOrConfig;
22
- }
23
- // If credentials provided, create client
24
- else if (clientOrConfig.clientId && clientOrConfig.clientSecret) {
25
- // Extract browserURL if passed in clientOrConfig
26
- if (clientOrConfig.browserURL) {
27
- config.browserURL = clientOrConfig.browserURL;
28
- }
29
- this.client = new OblienClient(clientOrConfig);
30
- }
31
- else {
32
- throw new Error('Either provide OblienClient instance or { clientId, clientSecret }');
33
- }
34
-
35
- this.browserURL = config.browserURL || 'https://browser.oblien.com';
36
-
37
- // Token cache for reuse within expiration window
38
- this._tokenCache = {
39
- token: null,
40
- expiresAt: null
41
- };
42
- }
43
-
44
- /**
45
- * Generate a browser token
46
- * Tokens expire in 1 minute for security
47
- *
48
- * @returns {Promise<Object>} Token response with token and expiration
49
- *
50
- * @example
51
- * const tokenData = await browser.generateToken();
52
- * // Returns:
53
- * // {
54
- * // success: true,
55
- * // token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
56
- * // expiresIn: '1m'
57
- * // }
58
- */
59
- async generateToken() {
60
- const response = await this.client.post('browser/token');
61
-
62
- // Cache token for reuse
63
- if (response.success && response.token) {
64
- this._tokenCache = {
65
- token: response.token,
66
- expiresAt: Date.now() + 50000 // 50 seconds (buffer before 1m expiry)
67
- };
68
- }
69
-
70
- return response;
71
- }
72
-
73
- /**
74
- * Get a valid token
75
- * Automatically generates new token if cache is empty or expired
76
- * @private
77
- */
78
- async _getToken() {
79
- const cached = this._tokenCache;
80
-
81
- // Use cached token if still valid
82
- if (cached.token && cached.expiresAt > Date.now()) {
83
- return cached.token;
84
- }
85
-
86
- // Generate new token
87
- const tokenData = await this.generateToken();
88
- return tokenData.token;
89
- }
90
-
91
- /**
92
- * Get page content
93
- * Opens a URL and extracts content
94
- *
95
- * @param {Object} options - Page content options
96
- * @param {string} options.url - URL to visit (required)
97
- * @param {string} options.token - Browser token (optional, auto-generates if not provided)
98
- * @param {number} options.waitFor - Wait time in ms
99
- * @param {string} options.selector - CSS selector to wait for
100
- * @param {string} options.extract - Content to extract ('html', 'text', 'both')
101
- * @param {boolean} options.waitForFullLoad - Wait for full page load
102
- * @param {string} options.proxy - Proxy URL (e.g., 'http://proxy.example.com:8080')
103
- * @param {number} options.proxyPort - Proxy port (optional, can be in URL)
104
- * @param {string} options.proxyUsername - Proxy authentication username
105
- * @param {string} options.proxyPassword - Proxy authentication password
106
- * @returns {Promise<Object>} Page content result
107
- *
108
- * @example
109
- * const result = await browser.getPageContent({
110
- * url: 'https://example.com',
111
- * extract: 'both'
112
- * });
113
- *
114
- * @example
115
- * // With proxy
116
- * const result = await browser.getPageContent({
117
- * url: 'https://example.com',
118
- * proxy: 'http://proxy.example.com',
119
- * proxyPort: 8080,
120
- * proxyUsername: 'user',
121
- * proxyPassword: 'pass'
122
- * });
123
- *
124
- * // Returns:
125
- * // {
126
- * // success: true,
127
- * // url: 'https://example.com',
128
- * // html: '<html>...</html>',
129
- * // text: 'Page text content...',
130
- * // title: 'Example Domain'
131
- * // }
132
- */
133
- async getPageContent(options) {
134
- const { url, token, ...restOptions } = options;
135
-
136
- if (!url) {
137
- throw new Error('URL is required');
138
- }
139
-
140
- // Get token (use provided or generate new one)
141
- const browserToken = token || await this._getToken();
142
-
143
- const response = await fetch(`${this.browserURL}/page-content`, {
144
- method: 'POST',
145
- headers: {
146
- 'Authorization': `Bearer ${browserToken}`,
147
- 'Content-Type': 'application/json'
148
- },
149
- body: JSON.stringify({ url, ...restOptions })
150
- });
151
-
152
- if (!response.ok) {
153
- const error = await response.json().catch(() => ({}));
154
- throw new Error(error.error || `Request failed: ${response.status}`);
155
- }
156
-
157
- return response.json();
158
- }
159
-
160
- /**
161
- * Take a screenshot of a page
162
- *
163
- * @param {Object} options - Screenshot options
164
- * @param {string} options.url - URL to screenshot (required)
165
- * @param {string} options.token - Browser token (optional)
166
- * @param {boolean} options.fullPage - Capture full page
167
- * @param {string} options.format - Image format ('png' or 'jpeg')
168
- * @param {number} options.quality - JPEG quality (0-100)
169
- * @param {Object} options.viewport - Viewport size {width, height}
170
- * @param {string} options.device - Device preset name
171
- * @param {string} options.proxy - Proxy URL
172
- * @param {number} options.proxyPort - Proxy port
173
- * @param {string} options.proxyUsername - Proxy authentication username
174
- * @param {string} options.proxyPassword - Proxy authentication password
175
- * @returns {Promise<Object>} Screenshot result with base64 image
176
- *
177
- * @example
178
- * const result = await browser.screenshot({
179
- * url: 'https://example.com',
180
- * fullPage: true,
181
- * format: 'png'
182
- * });
183
- *
184
- * // Returns:
185
- * // {
186
- * // success: true,
187
- * // screenshot: 'data:image/png;base64,iVBORw0KGgo...',
188
- * // format: 'png',
189
- * // width: 1920,
190
- * // height: 1080
191
- * // }
192
- */
193
- async screenshot(options) {
194
- const { url, token, ...restOptions } = options;
195
-
196
- if (!url) {
197
- throw new Error('URL is required');
198
- }
199
-
200
- const browserToken = token || await this._getToken();
201
-
202
- const response = await fetch(`${this.browserURL}/screenshot`, {
203
- method: 'POST',
204
- headers: {
205
- 'Authorization': `Bearer ${browserToken}`,
206
- 'Content-Type': 'application/json'
207
- },
208
- body: JSON.stringify({ url, ...restOptions })
209
- });
210
-
211
- if (!response.ok) {
212
- const error = await response.json().catch(() => ({}));
213
- throw new Error(error.error || `Screenshot failed: ${response.status}`);
214
- }
215
-
216
- return response.json();
217
- }
218
-
219
- /**
220
- * Generate PDF from a page
221
- *
222
- * @param {Object} options - PDF options
223
- * @param {string} options.url - URL to convert to PDF (required)
224
- * @param {string} options.token - Browser token (optional)
225
- * @param {string} options.format - Paper format ('A4', 'Letter', etc.)
226
- * @param {boolean} options.landscape - Landscape orientation
227
- * @param {boolean} options.printBackground - Print background graphics
228
- * @param {Object} options.margin - Page margins {top, right, bottom, left}
229
- * @param {string} options.proxy - Proxy URL
230
- * @param {number} options.proxyPort - Proxy port
231
- * @param {string} options.proxyUsername - Proxy authentication username
232
- * @param {string} options.proxyPassword - Proxy authentication password
233
- * @returns {Promise<Object>} PDF result with base64 data
234
- *
235
- * @example
236
- * const result = await browser.pdf({
237
- * url: 'https://example.com',
238
- * format: 'A4',
239
- * printBackground: true
240
- * });
241
- *
242
- * // Returns:
243
- * // {
244
- * // success: true,
245
- * // pdf: 'JVBERi0xLjQKJeLjz9MKMyAwIG9iago8P...',
246
- * // format: 'A4',
247
- * // pages: 5
248
- * // }
249
- */
250
- async pdf(options) {
251
- const { url, token, ...restOptions } = options;
252
-
253
- if (!url) {
254
- throw new Error('URL is required');
255
- }
256
-
257
- const browserToken = token || await this._getToken();
258
-
259
- const response = await fetch(`${this.browserURL}/pdf`, {
260
- method: 'POST',
261
- headers: {
262
- 'Authorization': `Bearer ${browserToken}`,
263
- 'Content-Type': 'application/json'
264
- },
265
- body: JSON.stringify({ url, ...restOptions })
266
- });
267
-
268
- if (!response.ok) {
269
- const error = await response.json().catch(() => ({}));
270
- throw new Error(error.error || `PDF generation failed: ${response.status}`);
271
- }
272
-
273
- return response.json();
274
- }
275
-
276
- /**
277
- * Monitor network requests on a page
278
- *
279
- * @param {Object} options - Monitor options
280
- * @param {string} options.url - URL to monitor (required)
281
- * @param {string} options.token - Browser token (optional)
282
- * @param {number} options.duration - Monitoring duration in ms
283
- * @param {Array<string>} options.filterTypes - Filter request types
284
- * @param {string} options.proxy - Proxy URL
285
- * @param {number} options.proxyPort - Proxy port
286
- * @param {string} options.proxyUsername - Proxy authentication username
287
- * @param {string} options.proxyPassword - Proxy authentication password
288
- * @returns {Promise<Object>} Network requests result
289
- *
290
- * @example
291
- * const result = await browser.monitorRequests({
292
- * url: 'https://example.com',
293
- * duration: 5000,
294
- * filterTypes: ['xhr', 'fetch']
295
- * });
296
- *
297
- * // Returns:
298
- * // {
299
- * // success: true,
300
- * // requests: [
301
- * // { url: 'https://api.example.com/data', method: 'GET', type: 'xhr', ... }
302
- * // ],
303
- * // count: 15
304
- * // }
305
- */
306
- async monitorRequests(options) {
307
- const { url, token, ...restOptions } = options;
308
-
309
- if (!url) {
310
- throw new Error('URL is required');
311
- }
312
-
313
- const browserToken = token || await this._getToken();
314
-
315
- const response = await fetch(`${this.browserURL}/monitor-requests`, {
316
- method: 'POST',
317
- headers: {
318
- 'Authorization': `Bearer ${browserToken}`,
319
- 'Content-Type': 'application/json'
320
- },
321
- body: JSON.stringify({ url, ...restOptions })
322
- });
323
-
324
- if (!response.ok) {
325
- const error = await response.json().catch(() => ({}));
326
- throw new Error(error.error || `Request monitoring failed: ${response.status}`);
327
- }
328
-
329
- return response.json();
330
- }
331
-
332
- /**
333
- * Get console logs from a page
334
- *
335
- * @param {Object} options - Console logs options
336
- * @param {string} options.url - URL to monitor (required)
337
- * @param {string} options.token - Browser token (optional)
338
- * @param {number} options.duration - Monitoring duration in ms
339
- * @param {string} options.proxy - Proxy URL
340
- * @param {number} options.proxyPort - Proxy port
341
- * @param {string} options.proxyUsername - Proxy authentication username
342
- * @param {string} options.proxyPassword - Proxy authentication password
343
- * @returns {Promise<Object>} Console logs result
344
- *
345
- * @example
346
- * const result = await browser.getConsoleLogs({
347
- * url: 'https://example.com',
348
- * duration: 3000
349
- * });
350
- *
351
- * // Returns:
352
- * // {
353
- * // success: true,
354
- * // logs: [
355
- * // { type: 'log', text: 'Console message', timestamp: '...' }
356
- * // ]
357
- * // }
358
- */
359
- async getConsoleLogs(options) {
360
- const { url, token, ...restOptions } = options;
361
-
362
- if (!url) {
363
- throw new Error('URL is required');
364
- }
365
-
366
- const browserToken = token || await this._getToken();
367
-
368
- const response = await fetch(`${this.browserURL}/console-logs`, {
369
- method: 'POST',
370
- headers: {
371
- 'Authorization': `Bearer ${browserToken}`,
372
- 'Content-Type': 'application/json'
373
- },
374
- body: JSON.stringify({ url, ...restOptions })
375
- });
376
-
377
- if (!response.ok) {
378
- const error = await response.json().catch(() => ({}));
379
- throw new Error(error.error || `Console logs retrieval failed: ${response.status}`);
380
- }
381
-
382
- return response.json();
383
- }
384
-
385
- /**
386
- * Get available device presets
387
- *
388
- * @param {Object} options - Options
389
- * @param {string} options.token - Browser token (optional)
390
- * @returns {Promise<Object>} Device presets
391
- *
392
- * @example
393
- * const devices = await browser.getDevicePresets();
394
- *
395
- * // Returns:
396
- * // {
397
- * // devices: {
398
- * // 'iPhone 13': { width: 390, height: 844, ... },
399
- * // 'iPad Pro': { width: 1024, height: 1366, ... }
400
- * // }
401
- * // }
402
- */
403
- async getDevicePresets(options = {}) {
404
- const { token } = options;
405
-
406
- const browserToken = token || await this._getToken();
407
-
408
- const response = await fetch(`${this.browserURL}/device-presets`, {
409
- method: 'GET',
410
- headers: {
411
- 'Authorization': `Bearer ${browserToken}`
412
- }
413
- });
414
-
415
- if (!response.ok) {
416
- const error = await response.json().catch(() => ({}));
417
- throw new Error(error.error || `Failed to get device presets: ${response.status}`);
418
- }
419
-
420
- return response.json();
421
- }
422
-
423
- /**
424
- * Get browser server status
425
- *
426
- * @param {Object} options - Options
427
- * @param {string} options.token - Browser token (optional)
428
- * @returns {Promise<Object>} Server status
429
- *
430
- * @example
431
- * const status = await browser.getStatus();
432
- *
433
- * // Returns:
434
- * // {
435
- * // status: 'running',
436
- * // poolSize: 5,
437
- * // activeBrowsers: 2
438
- * // }
439
- */
440
- async getStatus(options = {}) {
441
- const { token } = options;
442
-
443
- const browserToken = token || await this._getToken();
444
-
445
- const response = await fetch(`${this.browserURL}/status`, {
446
- method: 'GET',
447
- headers: {
448
- 'Authorization': `Bearer ${browserToken}`
449
- }
450
- });
451
-
452
- if (!response.ok) {
453
- const error = await response.json().catch(() => ({}));
454
- throw new Error(error.error || `Failed to get status: ${response.status}`);
455
- }
456
-
457
- return response.json();
458
- }
459
-
460
- /**
461
- * Clear token cache
462
- * Useful when you want to force fresh token generation
463
- *
464
- * @example
465
- * browser.clearTokenCache();
466
- */
467
- clearTokenCache() {
468
- this._tokenCache = {
469
- token: null,
470
- expiresAt: null
471
- };
472
- }
473
- }
474
-