instavm 0.2.2 → 0.4.0
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.
- package/README.md +149 -21
- package/dist/index.d.mts +97 -3
- package/dist/index.d.ts +97 -3
- package/dist/index.js +227 -112
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +225 -112
- package/dist/index.mjs.map +1 -1
- package/dist/integrations/openai/index.d.mts +2 -1
- package/dist/integrations/openai/index.d.ts +2 -1
- package/dist/integrations/openai/index.js +5 -0
- package/dist/integrations/openai/index.js.map +1 -1
- package/dist/integrations/openai/index.mjs +4 -0
- package/dist/integrations/openai/index.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ npm install instavm
|
|
|
21
21
|
|
|
22
22
|
## Quick Start
|
|
23
23
|
|
|
24
|
-
### Code Execution
|
|
24
|
+
### Code Execution (Cloud Mode)
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
27
|
import { InstaVM, ExecutionError, NetworkError } from 'instavm';
|
|
@@ -30,7 +30,7 @@ import { InstaVM, ExecutionError, NetworkError } from 'instavm';
|
|
|
30
30
|
const client = new InstaVM('your_api_key');
|
|
31
31
|
|
|
32
32
|
try {
|
|
33
|
-
// Execute a command
|
|
33
|
+
// Execute a command
|
|
34
34
|
const result = await client.execute("print(100**100)");
|
|
35
35
|
console.log(result);
|
|
36
36
|
|
|
@@ -49,6 +49,44 @@ try {
|
|
|
49
49
|
}
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
### Local Execution Mode
|
|
53
|
+
|
|
54
|
+
Run code execution against a local container (e.g., [coderunner](https://github.com/instavm/coderunner)) instead of the cloud API:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { InstaVM } from 'instavm';
|
|
58
|
+
|
|
59
|
+
// Create client in local mode (no API key required)
|
|
60
|
+
const client = new InstaVM('', {
|
|
61
|
+
local: true,
|
|
62
|
+
localURL: 'http://coderunner.local:8222' // Optional, defaults to this URL
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Execute code locally without session management
|
|
66
|
+
const result = await client.execute("print('Hello from local container!')");
|
|
67
|
+
console.log(result.output);
|
|
68
|
+
|
|
69
|
+
// Browser automation in local mode (no session required)
|
|
70
|
+
const content = await client.browser.extractContent({
|
|
71
|
+
url: 'https://example.com',
|
|
72
|
+
includeInteractive: true,
|
|
73
|
+
includeAnchors: true
|
|
74
|
+
});
|
|
75
|
+
console.log('Page title:', content.readableContent.title);
|
|
76
|
+
console.log('Clean content:', content.readableContent.content);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Note:** Local mode supports:
|
|
80
|
+
- ✅ Code execution (`execute()`)
|
|
81
|
+
- ✅ Browser navigation (`browser.navigate()`)
|
|
82
|
+
- ✅ Content extraction (`browser.extractContent()`)
|
|
83
|
+
|
|
84
|
+
Local mode does NOT support (cloud-only features):
|
|
85
|
+
- ❌ Session management (`createSession()`, `closeSession()`, `getUsage()`)
|
|
86
|
+
- ❌ File upload/download
|
|
87
|
+
- ❌ Async execution
|
|
88
|
+
- ❌ Browser session creation and complex interactions
|
|
89
|
+
|
|
52
90
|
### File Upload
|
|
53
91
|
|
|
54
92
|
```typescript
|
|
@@ -75,6 +113,29 @@ const execution = await client.execute('python /remote/path/script.py', {
|
|
|
75
113
|
console.log(execution.output);
|
|
76
114
|
```
|
|
77
115
|
|
|
116
|
+
### File Download
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { InstaVM } from 'instavm';
|
|
120
|
+
import fs from 'fs';
|
|
121
|
+
|
|
122
|
+
const client = new InstaVM('your_api_key');
|
|
123
|
+
|
|
124
|
+
// Create a file in the remote environment
|
|
125
|
+
await client.execute(`
|
|
126
|
+
import pandas as pd
|
|
127
|
+
df = pd.DataFrame({'name': ['Alice', 'Bob'], 'age': [25, 30]})
|
|
128
|
+
df.to_csv('data.csv', index=False)
|
|
129
|
+
`);
|
|
130
|
+
|
|
131
|
+
// Download the file
|
|
132
|
+
const result = await client.download('data.csv');
|
|
133
|
+
console.log(`Downloaded ${result.size} bytes`);
|
|
134
|
+
|
|
135
|
+
// Save to local file
|
|
136
|
+
fs.writeFileSync('local-data.csv', result.content);
|
|
137
|
+
```
|
|
138
|
+
|
|
78
139
|
### Error Handling
|
|
79
140
|
|
|
80
141
|
```typescript
|
|
@@ -432,25 +493,59 @@ console.log('Articles:', articles);
|
|
|
432
493
|
console.log('Form fields:', formData);
|
|
433
494
|
```
|
|
434
495
|
|
|
496
|
+
### LLM-Friendly Content Extraction
|
|
497
|
+
|
|
498
|
+
```typescript
|
|
499
|
+
// Extract clean, LLM-optimized content from a webpage
|
|
500
|
+
const content = await session.extractContent({
|
|
501
|
+
includeInteractive: true, // Include clickable/typeable elements
|
|
502
|
+
includeAnchors: true, // Include content-to-selector mappings
|
|
503
|
+
maxAnchors: 50 // Limit number of anchors
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
// Get clean article text (no ads, no navigation, no scripts)
|
|
507
|
+
console.log('Title:', content.readableContent.title);
|
|
508
|
+
console.log('Article:', content.readableContent.content);
|
|
509
|
+
console.log('Author:', content.readableContent.byline);
|
|
510
|
+
|
|
511
|
+
// Find interactive elements (buttons, links, inputs)
|
|
512
|
+
const loginButton = content.interactiveElements?.find(
|
|
513
|
+
el => el.text?.toLowerCase().includes('login')
|
|
514
|
+
);
|
|
515
|
+
if (loginButton) {
|
|
516
|
+
await session.click(loginButton.selector);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
// Use content anchors to map text to selectors
|
|
520
|
+
// Perfect for LLM agents that need to "read then click"
|
|
521
|
+
const signupLink = content.contentAnchors?.find(
|
|
522
|
+
anchor => anchor.text.toLowerCase().includes('sign up')
|
|
523
|
+
);
|
|
524
|
+
if (signupLink) {
|
|
525
|
+
await session.click(signupLink.selector);
|
|
526
|
+
}
|
|
527
|
+
```
|
|
528
|
+
|
|
435
529
|
## Error Handling Reference
|
|
436
530
|
|
|
437
531
|
### Error Types
|
|
438
532
|
|
|
439
533
|
```typescript
|
|
440
534
|
import {
|
|
441
|
-
InstaVMError,
|
|
442
|
-
AuthenticationError,
|
|
443
|
-
RateLimitError,
|
|
444
|
-
QuotaExceededError,
|
|
445
|
-
NetworkError,
|
|
446
|
-
ExecutionError,
|
|
447
|
-
SessionError,
|
|
448
|
-
BrowserError,
|
|
449
|
-
BrowserSessionError,
|
|
450
|
-
BrowserInteractionError,
|
|
451
|
-
BrowserTimeoutError,
|
|
452
|
-
BrowserNavigationError,
|
|
453
|
-
ElementNotFoundError
|
|
535
|
+
InstaVMError, // Base error class
|
|
536
|
+
AuthenticationError, // API key issues
|
|
537
|
+
RateLimitError, // Rate limiting (has retryAfter property)
|
|
538
|
+
QuotaExceededError, // Usage quota exceeded
|
|
539
|
+
NetworkError, // Connection issues
|
|
540
|
+
ExecutionError, // Code execution failures
|
|
541
|
+
SessionError, // Session management issues
|
|
542
|
+
BrowserError, // General browser errors
|
|
543
|
+
BrowserSessionError, // Browser session issues
|
|
544
|
+
BrowserInteractionError, // Browser interaction failures
|
|
545
|
+
BrowserTimeoutError, // Browser operation timeouts
|
|
546
|
+
BrowserNavigationError, // Navigation failures
|
|
547
|
+
ElementNotFoundError, // Element selection issues (has selector property)
|
|
548
|
+
UnsupportedOperationError // Operation not supported in local mode
|
|
454
549
|
} from 'instavm';
|
|
455
550
|
|
|
456
551
|
// Specific error handling
|
|
@@ -495,7 +590,8 @@ class InstaVM {
|
|
|
495
590
|
|
|
496
591
|
// File operations
|
|
497
592
|
upload(files: FileUpload[], options?: UploadOptions): Promise<UploadResult>
|
|
498
|
-
|
|
593
|
+
download(filename: string, options?: DownloadOptions): Promise<DownloadResult>
|
|
594
|
+
|
|
499
595
|
// Session management
|
|
500
596
|
createSession(): Promise<string>
|
|
501
597
|
closeSession(sessionId?: string): Promise<void>
|
|
@@ -516,10 +612,12 @@ class InstaVM {
|
|
|
516
612
|
|
|
517
613
|
```typescript
|
|
518
614
|
interface InstaVMOptions {
|
|
519
|
-
baseURL?: string; // Default: 'https://api.instavm.io'
|
|
615
|
+
baseURL?: string; // Default: 'https://api.instavm.io' (ignored if local=true)
|
|
520
616
|
timeout?: number; // Default: 300000 (5 minutes)
|
|
521
617
|
maxRetries?: number; // Default: 3
|
|
522
618
|
retryDelay?: number; // Default: 1000ms
|
|
619
|
+
local?: boolean; // Default: false - Use local container instead of cloud
|
|
620
|
+
localURL?: string; // Default: 'http://coderunner.local:8222' - Local container URL
|
|
523
621
|
}
|
|
524
622
|
|
|
525
623
|
interface ExecuteOptions {
|
|
@@ -565,7 +663,8 @@ class BrowserSession extends EventEmitter {
|
|
|
565
663
|
// Data extraction
|
|
566
664
|
screenshot(options?: ScreenshotOptions): Promise<string>
|
|
567
665
|
extractElements(selector: string, attributes?: string[]): Promise<ExtractedElement[]>
|
|
568
|
-
|
|
666
|
+
extractContent(options?: ExtractContentOptions): Promise<ExtractedContent>
|
|
667
|
+
|
|
569
668
|
// Utilities
|
|
570
669
|
wait(condition: WaitCondition, timeout?: number): Promise<void>
|
|
571
670
|
close(): Promise<void>
|
|
@@ -750,11 +849,14 @@ main().catch(console.error);
|
|
|
750
849
|
# Install dependencies
|
|
751
850
|
npm install
|
|
752
851
|
|
|
753
|
-
# Run unit tests
|
|
754
|
-
npm test
|
|
852
|
+
# Run unit tests (no API key required)
|
|
853
|
+
npm run test:unit
|
|
755
854
|
|
|
756
855
|
# Run integration tests (requires API key)
|
|
757
|
-
INSTAVM_API_KEY=
|
|
856
|
+
INSTAVM_API_KEY=your_api_key npm run test:integration
|
|
857
|
+
|
|
858
|
+
# Run all tests
|
|
859
|
+
npm test
|
|
758
860
|
|
|
759
861
|
# Build the package
|
|
760
862
|
npm run build
|
|
@@ -763,6 +865,8 @@ npm run build
|
|
|
763
865
|
npm run type-check
|
|
764
866
|
```
|
|
765
867
|
|
|
868
|
+
**Note:** Integration tests require a valid InstaVM API key. Set the `INSTAVM_API_KEY` environment variable before running integration tests. Unit tests do not require an API key.
|
|
869
|
+
|
|
766
870
|
### Contributing
|
|
767
871
|
|
|
768
872
|
This is an official SDK. For issues and feature requests, please use the GitHub repository.
|
|
@@ -782,6 +886,30 @@ All rights reserved. No redistribution or modification permitted.
|
|
|
782
886
|
|
|
783
887
|
## Changelog
|
|
784
888
|
|
|
889
|
+
### Version 0.4.0
|
|
890
|
+
|
|
891
|
+
- ✅ **NEW**: Local execution mode support - Run code execution against local containers
|
|
892
|
+
- ✅ **NEW**: Local browser automation - Navigate and extract content without sessions
|
|
893
|
+
- ✅ **NEW**: `UnsupportedOperationError` - Better error messages for cloud-only features
|
|
894
|
+
- ✅ Parity with Python SDK v0.4.0 local mode features
|
|
895
|
+
- ✅ Improved flexibility for on-premise deployments
|
|
896
|
+
|
|
897
|
+
### Version 0.3.0
|
|
898
|
+
|
|
899
|
+
- ✅ **NEW**: File download functionality - Download files from remote VM
|
|
900
|
+
- ✅ **NEW**: LLM-friendly content extraction - Extract clean, readable content with interactive element mapping
|
|
901
|
+
- ✅ Enhanced browser automation with content anchors for intelligent LLM agents
|
|
902
|
+
- ✅ Full API parity with Python SDK
|
|
903
|
+
|
|
904
|
+
### Version 0.2.1
|
|
905
|
+
|
|
906
|
+
- ✅ Bug fixes and improvements
|
|
907
|
+
|
|
908
|
+
### Version 0.2.0
|
|
909
|
+
|
|
910
|
+
- ✅ Enhanced session management
|
|
911
|
+
- ✅ Improved error handling
|
|
912
|
+
|
|
785
913
|
### Version 0.1.0
|
|
786
914
|
|
|
787
915
|
- ✅ Code execution fully functional (Python, Bash)
|
package/dist/index.d.mts
CHANGED
|
@@ -46,7 +46,7 @@ declare class HTTPClient {
|
|
|
46
46
|
*/
|
|
47
47
|
post<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<T>;
|
|
48
48
|
/**
|
|
49
|
-
* POST request for code execution (X-API-Key header
|
|
49
|
+
* POST request for code execution (uses X-API-Key header like Python client)
|
|
50
50
|
*/
|
|
51
51
|
postExecution<T = any>(url: string, data: any, headers?: Record<string, string>): Promise<T>;
|
|
52
52
|
/**
|
|
@@ -61,6 +61,10 @@ declare class HTTPClient {
|
|
|
61
61
|
* DELETE request
|
|
62
62
|
*/
|
|
63
63
|
delete<T = any>(url: string, headers?: Record<string, string>): Promise<T>;
|
|
64
|
+
/**
|
|
65
|
+
* POST request that returns raw binary data (for file downloads)
|
|
66
|
+
*/
|
|
67
|
+
postRaw(url: string, data?: any, headers?: Record<string, string>): Promise<ArrayBuffer>;
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
interface BrowserSessionOptions {
|
|
@@ -146,6 +150,35 @@ interface ExtractOptions {
|
|
|
146
150
|
attributes?: string[];
|
|
147
151
|
maxResults?: number;
|
|
148
152
|
}
|
|
153
|
+
interface ExtractContentOptions {
|
|
154
|
+
url?: string;
|
|
155
|
+
includeInteractive?: boolean;
|
|
156
|
+
includeAnchors?: boolean;
|
|
157
|
+
maxAnchors?: number;
|
|
158
|
+
}
|
|
159
|
+
interface InteractiveElement {
|
|
160
|
+
type: 'button' | 'link' | 'input' | 'select' | 'textarea';
|
|
161
|
+
selector: string;
|
|
162
|
+
text?: string;
|
|
163
|
+
label?: string;
|
|
164
|
+
placeholder?: string;
|
|
165
|
+
value?: string;
|
|
166
|
+
}
|
|
167
|
+
interface ContentAnchor {
|
|
168
|
+
text: string;
|
|
169
|
+
selector: string;
|
|
170
|
+
}
|
|
171
|
+
interface ExtractedContent {
|
|
172
|
+
readableContent: {
|
|
173
|
+
content: string;
|
|
174
|
+
title?: string;
|
|
175
|
+
byline?: string;
|
|
176
|
+
excerpt?: string;
|
|
177
|
+
siteName?: string;
|
|
178
|
+
};
|
|
179
|
+
interactiveElements?: InteractiveElement[];
|
|
180
|
+
contentAnchors?: ContentAnchor[];
|
|
181
|
+
}
|
|
149
182
|
|
|
150
183
|
/**
|
|
151
184
|
* Browser session for automation
|
|
@@ -183,6 +216,32 @@ declare class BrowserSession extends EventEmitter {
|
|
|
183
216
|
* Extract elements from the page
|
|
184
217
|
*/
|
|
185
218
|
extractElements(selector: string, attributes?: string[], options?: ExtractOptions): Promise<ExtractedElement[]>;
|
|
219
|
+
/**
|
|
220
|
+
* Extract LLM-friendly content from the current page
|
|
221
|
+
*
|
|
222
|
+
* Returns clean article content, interactive elements, and content anchors
|
|
223
|
+
* for intelligent browser automation with LLMs.
|
|
224
|
+
*
|
|
225
|
+
* @param options - Content extraction options
|
|
226
|
+
* @returns Extracted content with readable text, interactive elements, and content anchors
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const content = await session.extractContent();
|
|
231
|
+
*
|
|
232
|
+
* // LLM reads clean content
|
|
233
|
+
* const article = content.readableContent.content;
|
|
234
|
+
*
|
|
235
|
+
* // LLM finds "Sign Up" in content and uses anchors to get selector
|
|
236
|
+
* const signUpAnchor = content.contentAnchors?.find(
|
|
237
|
+
* anchor => anchor.text.toLowerCase().includes('sign up')
|
|
238
|
+
* );
|
|
239
|
+
* if (signUpAnchor) {
|
|
240
|
+
* await session.click(signUpAnchor.selector);
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
extractContent(options?: ExtractContentOptions): Promise<ExtractedContent>;
|
|
186
245
|
/**
|
|
187
246
|
* Wait for a condition
|
|
188
247
|
*/
|
|
@@ -207,7 +266,8 @@ declare class BrowserSession extends EventEmitter {
|
|
|
207
266
|
declare class BrowserManager {
|
|
208
267
|
private httpClient;
|
|
209
268
|
private activeSessions;
|
|
210
|
-
|
|
269
|
+
private local;
|
|
270
|
+
constructor(httpClient: HTTPClient, local?: boolean);
|
|
211
271
|
/**
|
|
212
272
|
* Create a new browser session
|
|
213
273
|
*/
|
|
@@ -232,6 +292,14 @@ declare class BrowserManager {
|
|
|
232
292
|
* Close all active sessions
|
|
233
293
|
*/
|
|
234
294
|
closeAllSessions(): Promise<void>;
|
|
295
|
+
/**
|
|
296
|
+
* Navigate to a URL (local mode support - no session required)
|
|
297
|
+
*/
|
|
298
|
+
navigate(url: string, options?: NavigateOptions): Promise<NavigationResult>;
|
|
299
|
+
/**
|
|
300
|
+
* Extract LLM-friendly content (local mode support - no session required)
|
|
301
|
+
*/
|
|
302
|
+
extractContent(options?: ExtractContentOptions): Promise<ExtractedContent>;
|
|
235
303
|
/**
|
|
236
304
|
* Clean up resources
|
|
237
305
|
*/
|
|
@@ -280,12 +348,23 @@ interface UsageStats {
|
|
|
280
348
|
quotaRemaining: number;
|
|
281
349
|
quotaLimit: number;
|
|
282
350
|
}
|
|
351
|
+
interface DownloadOptions {
|
|
352
|
+
sessionId?: string;
|
|
353
|
+
}
|
|
354
|
+
interface DownloadResult {
|
|
355
|
+
success: boolean;
|
|
356
|
+
filename: string;
|
|
357
|
+
content: Buffer;
|
|
358
|
+
size: number;
|
|
359
|
+
}
|
|
283
360
|
|
|
284
361
|
interface InstaVMOptions {
|
|
285
362
|
baseURL?: string;
|
|
286
363
|
timeout?: number;
|
|
287
364
|
maxRetries?: number;
|
|
288
365
|
retryDelay?: number;
|
|
366
|
+
local?: boolean;
|
|
367
|
+
localURL?: string;
|
|
289
368
|
}
|
|
290
369
|
/**
|
|
291
370
|
* Main InstaVM client class
|
|
@@ -294,7 +373,12 @@ declare class InstaVM {
|
|
|
294
373
|
private httpClient;
|
|
295
374
|
private _sessionId;
|
|
296
375
|
readonly browser: BrowserManager;
|
|
376
|
+
readonly local: boolean;
|
|
297
377
|
constructor(apiKey: string, options?: InstaVMOptions);
|
|
378
|
+
/**
|
|
379
|
+
* Ensure operation is not called in local mode
|
|
380
|
+
*/
|
|
381
|
+
private ensureNotLocal;
|
|
298
382
|
/**
|
|
299
383
|
* Execute code synchronously
|
|
300
384
|
*/
|
|
@@ -319,6 +403,10 @@ declare class InstaVM {
|
|
|
319
403
|
* Get usage statistics for a session
|
|
320
404
|
*/
|
|
321
405
|
getUsage(sessionId?: string): Promise<UsageStats>;
|
|
406
|
+
/**
|
|
407
|
+
* Download a file from the remote VM
|
|
408
|
+
*/
|
|
409
|
+
download(filename: string, options?: DownloadOptions): Promise<DownloadResult>;
|
|
322
410
|
/**
|
|
323
411
|
* Get the current session ID
|
|
324
412
|
*/
|
|
@@ -420,5 +508,11 @@ declare class ElementNotFoundError extends BrowserError {
|
|
|
420
508
|
readonly selector?: string;
|
|
421
509
|
constructor(message?: string, selector?: string, options?: any);
|
|
422
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Unsupported operation error (e.g., operations not available in local mode)
|
|
513
|
+
*/
|
|
514
|
+
declare class UnsupportedOperationError extends InstaVMError {
|
|
515
|
+
constructor(message?: string, options?: any);
|
|
516
|
+
}
|
|
423
517
|
|
|
424
|
-
export { type ApiResponse, type AsyncExecutionResult, AuthenticationError, BrowserError, BrowserInteractionError, BrowserManager, BrowserNavigationError, BrowserSession, BrowserSessionError, type BrowserSessionInfo, type BrowserSessionOptions, BrowserTimeoutError, type ClickOptions, ElementNotFoundError, type ExecuteOptions, ExecutionError, type ExecutionResult, type ExtractOptions, type ExtractedElement, type FileUpload, type FillOptions, type HttpClientConfig, InstaVM, InstaVMError, type InstaVMOptions, type NavigateOptions, type NavigationResult, NetworkError, QuotaExceededError, RateLimitError, type RequestConfig, type RetryConfig, type ScreenshotOptions, type ScrollOptions, SessionError, type TypeOptions, type UploadOptions, type UploadResult, type UsageStats, type WaitCondition };
|
|
518
|
+
export { type ApiResponse, type AsyncExecutionResult, AuthenticationError, BrowserError, BrowserInteractionError, BrowserManager, BrowserNavigationError, BrowserSession, BrowserSessionError, type BrowserSessionInfo, type BrowserSessionOptions, BrowserTimeoutError, type ClickOptions, type ContentAnchor, type DownloadOptions, type DownloadResult, ElementNotFoundError, type ExecuteOptions, ExecutionError, type ExecutionResult, type ExtractContentOptions, type ExtractOptions, type ExtractedContent, type ExtractedElement, type FileUpload, type FillOptions, type HttpClientConfig, InstaVM, InstaVMError, type InstaVMOptions, type InteractiveElement, type NavigateOptions, type NavigationResult, NetworkError, QuotaExceededError, RateLimitError, type RequestConfig, type RetryConfig, type ScreenshotOptions, type ScrollOptions, SessionError, type TypeOptions, UnsupportedOperationError, type UploadOptions, type UploadResult, type UsageStats, type WaitCondition };
|
package/dist/index.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ declare class HTTPClient {
|
|
|
46
46
|
*/
|
|
47
47
|
post<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<T>;
|
|
48
48
|
/**
|
|
49
|
-
* POST request for code execution (X-API-Key header
|
|
49
|
+
* POST request for code execution (uses X-API-Key header like Python client)
|
|
50
50
|
*/
|
|
51
51
|
postExecution<T = any>(url: string, data: any, headers?: Record<string, string>): Promise<T>;
|
|
52
52
|
/**
|
|
@@ -61,6 +61,10 @@ declare class HTTPClient {
|
|
|
61
61
|
* DELETE request
|
|
62
62
|
*/
|
|
63
63
|
delete<T = any>(url: string, headers?: Record<string, string>): Promise<T>;
|
|
64
|
+
/**
|
|
65
|
+
* POST request that returns raw binary data (for file downloads)
|
|
66
|
+
*/
|
|
67
|
+
postRaw(url: string, data?: any, headers?: Record<string, string>): Promise<ArrayBuffer>;
|
|
64
68
|
}
|
|
65
69
|
|
|
66
70
|
interface BrowserSessionOptions {
|
|
@@ -146,6 +150,35 @@ interface ExtractOptions {
|
|
|
146
150
|
attributes?: string[];
|
|
147
151
|
maxResults?: number;
|
|
148
152
|
}
|
|
153
|
+
interface ExtractContentOptions {
|
|
154
|
+
url?: string;
|
|
155
|
+
includeInteractive?: boolean;
|
|
156
|
+
includeAnchors?: boolean;
|
|
157
|
+
maxAnchors?: number;
|
|
158
|
+
}
|
|
159
|
+
interface InteractiveElement {
|
|
160
|
+
type: 'button' | 'link' | 'input' | 'select' | 'textarea';
|
|
161
|
+
selector: string;
|
|
162
|
+
text?: string;
|
|
163
|
+
label?: string;
|
|
164
|
+
placeholder?: string;
|
|
165
|
+
value?: string;
|
|
166
|
+
}
|
|
167
|
+
interface ContentAnchor {
|
|
168
|
+
text: string;
|
|
169
|
+
selector: string;
|
|
170
|
+
}
|
|
171
|
+
interface ExtractedContent {
|
|
172
|
+
readableContent: {
|
|
173
|
+
content: string;
|
|
174
|
+
title?: string;
|
|
175
|
+
byline?: string;
|
|
176
|
+
excerpt?: string;
|
|
177
|
+
siteName?: string;
|
|
178
|
+
};
|
|
179
|
+
interactiveElements?: InteractiveElement[];
|
|
180
|
+
contentAnchors?: ContentAnchor[];
|
|
181
|
+
}
|
|
149
182
|
|
|
150
183
|
/**
|
|
151
184
|
* Browser session for automation
|
|
@@ -183,6 +216,32 @@ declare class BrowserSession extends EventEmitter {
|
|
|
183
216
|
* Extract elements from the page
|
|
184
217
|
*/
|
|
185
218
|
extractElements(selector: string, attributes?: string[], options?: ExtractOptions): Promise<ExtractedElement[]>;
|
|
219
|
+
/**
|
|
220
|
+
* Extract LLM-friendly content from the current page
|
|
221
|
+
*
|
|
222
|
+
* Returns clean article content, interactive elements, and content anchors
|
|
223
|
+
* for intelligent browser automation with LLMs.
|
|
224
|
+
*
|
|
225
|
+
* @param options - Content extraction options
|
|
226
|
+
* @returns Extracted content with readable text, interactive elements, and content anchors
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const content = await session.extractContent();
|
|
231
|
+
*
|
|
232
|
+
* // LLM reads clean content
|
|
233
|
+
* const article = content.readableContent.content;
|
|
234
|
+
*
|
|
235
|
+
* // LLM finds "Sign Up" in content and uses anchors to get selector
|
|
236
|
+
* const signUpAnchor = content.contentAnchors?.find(
|
|
237
|
+
* anchor => anchor.text.toLowerCase().includes('sign up')
|
|
238
|
+
* );
|
|
239
|
+
* if (signUpAnchor) {
|
|
240
|
+
* await session.click(signUpAnchor.selector);
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
extractContent(options?: ExtractContentOptions): Promise<ExtractedContent>;
|
|
186
245
|
/**
|
|
187
246
|
* Wait for a condition
|
|
188
247
|
*/
|
|
@@ -207,7 +266,8 @@ declare class BrowserSession extends EventEmitter {
|
|
|
207
266
|
declare class BrowserManager {
|
|
208
267
|
private httpClient;
|
|
209
268
|
private activeSessions;
|
|
210
|
-
|
|
269
|
+
private local;
|
|
270
|
+
constructor(httpClient: HTTPClient, local?: boolean);
|
|
211
271
|
/**
|
|
212
272
|
* Create a new browser session
|
|
213
273
|
*/
|
|
@@ -232,6 +292,14 @@ declare class BrowserManager {
|
|
|
232
292
|
* Close all active sessions
|
|
233
293
|
*/
|
|
234
294
|
closeAllSessions(): Promise<void>;
|
|
295
|
+
/**
|
|
296
|
+
* Navigate to a URL (local mode support - no session required)
|
|
297
|
+
*/
|
|
298
|
+
navigate(url: string, options?: NavigateOptions): Promise<NavigationResult>;
|
|
299
|
+
/**
|
|
300
|
+
* Extract LLM-friendly content (local mode support - no session required)
|
|
301
|
+
*/
|
|
302
|
+
extractContent(options?: ExtractContentOptions): Promise<ExtractedContent>;
|
|
235
303
|
/**
|
|
236
304
|
* Clean up resources
|
|
237
305
|
*/
|
|
@@ -280,12 +348,23 @@ interface UsageStats {
|
|
|
280
348
|
quotaRemaining: number;
|
|
281
349
|
quotaLimit: number;
|
|
282
350
|
}
|
|
351
|
+
interface DownloadOptions {
|
|
352
|
+
sessionId?: string;
|
|
353
|
+
}
|
|
354
|
+
interface DownloadResult {
|
|
355
|
+
success: boolean;
|
|
356
|
+
filename: string;
|
|
357
|
+
content: Buffer;
|
|
358
|
+
size: number;
|
|
359
|
+
}
|
|
283
360
|
|
|
284
361
|
interface InstaVMOptions {
|
|
285
362
|
baseURL?: string;
|
|
286
363
|
timeout?: number;
|
|
287
364
|
maxRetries?: number;
|
|
288
365
|
retryDelay?: number;
|
|
366
|
+
local?: boolean;
|
|
367
|
+
localURL?: string;
|
|
289
368
|
}
|
|
290
369
|
/**
|
|
291
370
|
* Main InstaVM client class
|
|
@@ -294,7 +373,12 @@ declare class InstaVM {
|
|
|
294
373
|
private httpClient;
|
|
295
374
|
private _sessionId;
|
|
296
375
|
readonly browser: BrowserManager;
|
|
376
|
+
readonly local: boolean;
|
|
297
377
|
constructor(apiKey: string, options?: InstaVMOptions);
|
|
378
|
+
/**
|
|
379
|
+
* Ensure operation is not called in local mode
|
|
380
|
+
*/
|
|
381
|
+
private ensureNotLocal;
|
|
298
382
|
/**
|
|
299
383
|
* Execute code synchronously
|
|
300
384
|
*/
|
|
@@ -319,6 +403,10 @@ declare class InstaVM {
|
|
|
319
403
|
* Get usage statistics for a session
|
|
320
404
|
*/
|
|
321
405
|
getUsage(sessionId?: string): Promise<UsageStats>;
|
|
406
|
+
/**
|
|
407
|
+
* Download a file from the remote VM
|
|
408
|
+
*/
|
|
409
|
+
download(filename: string, options?: DownloadOptions): Promise<DownloadResult>;
|
|
322
410
|
/**
|
|
323
411
|
* Get the current session ID
|
|
324
412
|
*/
|
|
@@ -420,5 +508,11 @@ declare class ElementNotFoundError extends BrowserError {
|
|
|
420
508
|
readonly selector?: string;
|
|
421
509
|
constructor(message?: string, selector?: string, options?: any);
|
|
422
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Unsupported operation error (e.g., operations not available in local mode)
|
|
513
|
+
*/
|
|
514
|
+
declare class UnsupportedOperationError extends InstaVMError {
|
|
515
|
+
constructor(message?: string, options?: any);
|
|
516
|
+
}
|
|
423
517
|
|
|
424
|
-
export { type ApiResponse, type AsyncExecutionResult, AuthenticationError, BrowserError, BrowserInteractionError, BrowserManager, BrowserNavigationError, BrowserSession, BrowserSessionError, type BrowserSessionInfo, type BrowserSessionOptions, BrowserTimeoutError, type ClickOptions, ElementNotFoundError, type ExecuteOptions, ExecutionError, type ExecutionResult, type ExtractOptions, type ExtractedElement, type FileUpload, type FillOptions, type HttpClientConfig, InstaVM, InstaVMError, type InstaVMOptions, type NavigateOptions, type NavigationResult, NetworkError, QuotaExceededError, RateLimitError, type RequestConfig, type RetryConfig, type ScreenshotOptions, type ScrollOptions, SessionError, type TypeOptions, type UploadOptions, type UploadResult, type UsageStats, type WaitCondition };
|
|
518
|
+
export { type ApiResponse, type AsyncExecutionResult, AuthenticationError, BrowserError, BrowserInteractionError, BrowserManager, BrowserNavigationError, BrowserSession, BrowserSessionError, type BrowserSessionInfo, type BrowserSessionOptions, BrowserTimeoutError, type ClickOptions, type ContentAnchor, type DownloadOptions, type DownloadResult, ElementNotFoundError, type ExecuteOptions, ExecutionError, type ExecutionResult, type ExtractContentOptions, type ExtractOptions, type ExtractedContent, type ExtractedElement, type FileUpload, type FillOptions, type HttpClientConfig, InstaVM, InstaVMError, type InstaVMOptions, type InteractiveElement, type NavigateOptions, type NavigationResult, NetworkError, QuotaExceededError, RateLimitError, type RequestConfig, type RetryConfig, type ScreenshotOptions, type ScrollOptions, SessionError, type TypeOptions, UnsupportedOperationError, type UploadOptions, type UploadResult, type UsageStats, type WaitCondition };
|