simplex-ts 1.0.4 → 1.0.5
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 +72 -53
- package/dist/index.d.mts +27 -7
- package/dist/index.d.ts +27 -7
- package/dist/index.js +2 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -1,32 +1,11 @@
|
|
|
1
1
|
# Simplex TypeScript
|
|
2
2
|
|
|
3
|
-
A TypeScript package for browser automation and web interaction
|
|
3
|
+
A TypeScript package for interacting with the Simplex API, providing a clean and type-safe interface for browser automation and web interaction.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
- Browser automation with high-level commands
|
|
8
|
-
- Session-based interaction
|
|
9
|
-
- Element interaction (click, type, scroll)
|
|
10
|
-
- Content extraction (text, images, bounding boxes)
|
|
11
|
-
- File upload and download capabilities
|
|
12
|
-
- TypeScript support with type definitions
|
|
13
|
-
- Built with modern tooling (ESM + CommonJS output)
|
|
14
|
-
|
|
15
|
-
## Getting Started
|
|
16
|
-
|
|
17
|
-
1. Install dependencies:
|
|
18
|
-
```bash
|
|
19
|
-
npm install
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
2. Build the package:
|
|
23
|
-
```bash
|
|
24
|
-
npm run build
|
|
25
|
-
```
|
|
5
|
+
## Installation
|
|
26
6
|
|
|
27
|
-
3. Run tests:
|
|
28
7
|
```bash
|
|
29
|
-
npm
|
|
8
|
+
npm install simplex-ts
|
|
30
9
|
```
|
|
31
10
|
|
|
32
11
|
## Usage
|
|
@@ -34,46 +13,86 @@ npm test
|
|
|
34
13
|
```typescript
|
|
35
14
|
import { Simplex } from 'simplex-ts';
|
|
36
15
|
|
|
37
|
-
// Initialize
|
|
16
|
+
// Initialize with your API key
|
|
38
17
|
const simplex = new Simplex('your-api-key');
|
|
39
18
|
|
|
40
|
-
// Create a
|
|
19
|
+
// Create a session
|
|
41
20
|
const [sessionId, livestreamUrl] = await simplex.createSession();
|
|
42
21
|
|
|
43
|
-
// Navigate to a
|
|
44
|
-
await simplex.goto('example.com');
|
|
22
|
+
// Navigate to a URL
|
|
23
|
+
await simplex.goto('https://example.com');
|
|
45
24
|
|
|
46
|
-
//
|
|
47
|
-
await simplex.click('
|
|
48
|
-
await simplex.type('user@example.com');
|
|
49
|
-
await simplex.pressEnter();
|
|
25
|
+
// Click elements
|
|
26
|
+
await simplex.click('button with text "Submit"');
|
|
50
27
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
28
|
+
// Type text
|
|
29
|
+
await simplex.type('Hello, World!');
|
|
30
|
+
|
|
31
|
+
// Extract text
|
|
32
|
+
const text = await simplex.extractText('element with text');
|
|
54
33
|
|
|
55
34
|
// Close the session when done
|
|
56
35
|
await simplex.closeSession();
|
|
57
36
|
```
|
|
58
37
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
-
|
|
62
|
-
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
67
|
-
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
38
|
+
## Features
|
|
39
|
+
|
|
40
|
+
- Type-safe API interactions
|
|
41
|
+
- Browser automation capabilities
|
|
42
|
+
- Element interaction (click, type, scroll)
|
|
43
|
+
- Text and image extraction
|
|
44
|
+
- File upload/download support
|
|
45
|
+
- Session management
|
|
46
|
+
- Live streaming support
|
|
47
|
+
|
|
48
|
+
## API Reference
|
|
49
|
+
|
|
50
|
+
### Constructor
|
|
51
|
+
```typescript
|
|
52
|
+
constructor(apiKey: string)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Methods
|
|
56
|
+
|
|
57
|
+
#### createSession
|
|
58
|
+
```typescript
|
|
59
|
+
createSession(
|
|
60
|
+
showInConsole?: boolean,
|
|
61
|
+
proxies?: boolean,
|
|
62
|
+
workflowName?: string,
|
|
63
|
+
sessionData?: SessionData | string
|
|
64
|
+
): Promise<[string, string]>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### goto
|
|
68
|
+
```typescript
|
|
69
|
+
goto(url: string, cdpUrl?: string): Promise<void>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### click
|
|
73
|
+
```typescript
|
|
74
|
+
click(elementDescription: string, cdpUrl?: string): Promise<string>
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### type
|
|
78
|
+
```typescript
|
|
79
|
+
type(text: string, cdpUrl?: string): Promise<void>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### extractText
|
|
83
|
+
```typescript
|
|
84
|
+
extractText(elementDescription: string, cdpUrl?: string): Promise<string>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
#### extractImage
|
|
88
|
+
```typescript
|
|
89
|
+
extractImage(elementDescription: string, cdpUrl?: string): Promise<string>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### closeSession
|
|
93
|
+
```typescript
|
|
94
|
+
closeSession(): Promise<void>
|
|
95
|
+
```
|
|
77
96
|
|
|
78
97
|
## License
|
|
79
98
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
interface SessionData {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
declare class Simplex {
|
|
5
|
+
private apiKey;
|
|
6
|
+
private sessionId;
|
|
7
|
+
private connectUrl;
|
|
8
|
+
constructor(apiKey: string);
|
|
9
|
+
private makeRequest;
|
|
10
|
+
createSession(showInConsole?: boolean, proxies?: boolean, workflowName?: string, sessionData?: SessionData | string): Promise<[string, string]>;
|
|
11
|
+
goto(url: string, cdpUrl?: string): Promise<void>;
|
|
12
|
+
click(elementDescription: string, cdpUrl?: string): Promise<string>;
|
|
13
|
+
type(text: string, cdpUrl?: string): Promise<void>;
|
|
14
|
+
pressEnter(cdpUrl?: string): Promise<void>;
|
|
15
|
+
pressTab(cdpUrl?: string): Promise<void>;
|
|
16
|
+
deleteText(cdpUrl?: string): Promise<void>;
|
|
17
|
+
extractBbox(elementDescription: string, cdpUrl?: string): Promise<any>;
|
|
18
|
+
extractText(elementDescription: string, cdpUrl?: string): Promise<string>;
|
|
19
|
+
extractImage(elementDescription: string, cdpUrl?: string): Promise<string>;
|
|
20
|
+
scroll(pixels: number, cdpUrl?: string): Promise<void>;
|
|
21
|
+
wait(milliseconds: number, cdpUrl?: string): Promise<void>;
|
|
22
|
+
clickAndUpload(elementDescription: string, filePathOrCallable: string | (() => Blob)): Promise<void>;
|
|
23
|
+
clickAndDownload(elementDescription: string): Promise<[string, string]>;
|
|
24
|
+
exists(elementDescription: string, cdpUrl?: string): Promise<[boolean, string]>;
|
|
25
|
+
closeSession(): Promise<void>;
|
|
26
|
+
}
|
|
7
27
|
|
|
8
|
-
export {
|
|
28
|
+
export { Simplex };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
interface SessionData {
|
|
2
|
+
[key: string]: any;
|
|
3
|
+
}
|
|
4
|
+
declare class Simplex {
|
|
5
|
+
private apiKey;
|
|
6
|
+
private sessionId;
|
|
7
|
+
private connectUrl;
|
|
8
|
+
constructor(apiKey: string);
|
|
9
|
+
private makeRequest;
|
|
10
|
+
createSession(showInConsole?: boolean, proxies?: boolean, workflowName?: string, sessionData?: SessionData | string): Promise<[string, string]>;
|
|
11
|
+
goto(url: string, cdpUrl?: string): Promise<void>;
|
|
12
|
+
click(elementDescription: string, cdpUrl?: string): Promise<string>;
|
|
13
|
+
type(text: string, cdpUrl?: string): Promise<void>;
|
|
14
|
+
pressEnter(cdpUrl?: string): Promise<void>;
|
|
15
|
+
pressTab(cdpUrl?: string): Promise<void>;
|
|
16
|
+
deleteText(cdpUrl?: string): Promise<void>;
|
|
17
|
+
extractBbox(elementDescription: string, cdpUrl?: string): Promise<any>;
|
|
18
|
+
extractText(elementDescription: string, cdpUrl?: string): Promise<string>;
|
|
19
|
+
extractImage(elementDescription: string, cdpUrl?: string): Promise<string>;
|
|
20
|
+
scroll(pixels: number, cdpUrl?: string): Promise<void>;
|
|
21
|
+
wait(milliseconds: number, cdpUrl?: string): Promise<void>;
|
|
22
|
+
clickAndUpload(elementDescription: string, filePathOrCallable: string | (() => Blob)): Promise<void>;
|
|
23
|
+
clickAndDownload(elementDescription: string): Promise<[string, string]>;
|
|
24
|
+
exists(elementDescription: string, cdpUrl?: string): Promise<[boolean, string]>;
|
|
25
|
+
closeSession(): Promise<void>;
|
|
26
|
+
}
|
|
7
27
|
|
|
8
|
-
export {
|
|
28
|
+
export { Simplex };
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
greet: () => greet
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
function greet(name) {
|
|
27
|
-
return `Hello, ${name}!`;
|
|
28
|
-
}
|
|
29
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
-
0 && (module.exports = {
|
|
31
|
-
greet
|
|
32
|
-
});
|
|
1
|
+
'use strict';var l=require('axios');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var l__default=/*#__PURE__*/_interopDefault(l);var p="https://api.simplex.sh",d=class{constructor(s){this.sessionId=null;this.connectUrl=null;this.apiKey=s;}async makeRequest(s,e,t,i){try{console.log(`Making ${s.toUpperCase()} request to ${e}`);let n=new FormData;t&&Object.entries(t).forEach(([a,c])=>{c!=null&&n.append(a,c.toString());}),console.log("Request data:",t);let o=await l__default.default({method:s,url:`${p}${e}`,data:s==="post"?n:void 0,params:s==="get"?i:void 0,headers:{"x-api-key":this.apiKey,...s==="post"?{"Content-Type":"multipart/form-data"}:{}}});console.log("Response status:",o.status),console.log("Response data:",JSON.stringify(o.data,null,2));let r=o.data;if(!r.succeeded&&!(e==="/create_session"&&r.session_id)){let a=r.error||"Request failed";throw console.error("API request failed:",a),new Error(a)}return r}catch(n){if(l__default.default.isAxiosError(n)){let o=n.response?.data?.error||n.message;throw console.error("Axios error:",{status:n.response?.status,statusText:n.response?.statusText,data:n.response?.data,message:o}),new Error(`Request failed: ${o}`)}throw console.error("Unexpected error:",n),n}}async createSession(s=true,e=true,t,i){let n={proxies:e,workflow_name:t};if(this.sessionId)throw new Error("A session is already active. Please close the current session before creating a new one.");if(i)if(typeof i=="string")try{n.session_data=JSON.stringify(JSON.parse(i));}catch{throw new Error("File system operations are not supported in this environment")}else n.session_data=JSON.stringify(i);let o=await this.makeRequest("post","/create_session",n);if(!o.session_id)throw new Error("Session creation failed: No session ID returned");return this.sessionId=o.session_id,this.connectUrl=o.connect_url||null,s&&o.livestream_url&&console.log(`Livestream URL: ${o.livestream_url}`),[o.session_id,o.livestream_url||""]}async goto(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling goto with url='${s}'`);!s.startsWith("http://")&&!s.startsWith("https://")&&(s="https://"+s);let t={url:s,...e?{cdp_url:e}:{session_id:this.sessionId}};await this.makeRequest("post","/goto",t);}async click(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling click with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}};return (await this.makeRequest("post","/click",t)).element_clicked||""}async type(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling type with text='${s}'`);let t={text:s,...e?{cdp_url:e}:{session_id:this.sessionId}};await this.makeRequest("post","/type",t);}async pressEnter(s){if(!s&&!this.sessionId)throw new Error("Must call createSession before calling pressEnter");let e=s?{cdp_url:s}:{session_id:this.sessionId};await this.makeRequest("post","/press_enter",e);}async pressTab(s){if(!s&&!this.sessionId)throw new Error("Must call createSession before calling pressTab");let e=s?{cdp_url:s}:{session_id:this.sessionId};await this.makeRequest("post","/press_tab",e);}async deleteText(s){if(!s&&!this.sessionId)throw new Error("Must call createSession before calling deleteText");let e=s?{cdp_url:s}:{session_id:this.sessionId};await this.makeRequest("post","/delete_text",e);}async extractBbox(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling extractBbox with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}};return (await this.makeRequest("get","/extract-bbox",void 0,t)).bbox}async extractText(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling extractText with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}};return (await this.makeRequest("post","/extract-text",t)).text||""}async extractImage(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling extractImage with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}};return (await this.makeRequest("get","/extract-image",void 0,t)).image||""}async scroll(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling scroll with pixels=${s}`);let t={pixels:s,...e?{cdp_url:e}:{session_id:this.sessionId}};await this.makeRequest("post","/scroll",t);}async wait(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling wait with milliseconds=${s}`);let t={milliseconds:s,...e?{cdp_url:e}:{session_id:this.sessionId}};await this.makeRequest("post","/wait",t);}async clickAndUpload(s,e){if(!this.sessionId)throw new Error(`Must call createSession before calling clickAndUpload with elementDescription='${s}'`);if(typeof e!="string"&&typeof e!="function")throw new TypeError(`filePathOrCallable must be either a string or a callable, not a ${typeof e}`);let t=new FormData;if(t.append("element_description",s),t.append("session_id",this.sessionId),typeof e=="string")throw new Error("File system operations are not supported in this environment");{let i=e();t.append("file",i,"file");}await this.makeRequest("post","/click_and_upload",t,void 0);}async clickAndDownload(s){if(!this.sessionId)throw new Error(`Must call createSession before calling clickAndDownload with elementDescription='${s}'`);let e={element_description:s,session_id:this.sessionId},t=await this.makeRequest("post","/click_and_download",e);return [t.b64||"",t.filename||""]}async exists(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling exists with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}},i=await this.makeRequest("post","/exists",t);return [i.exists||false,i.reasoning||""]}async closeSession(){this.sessionId&&(await this.makeRequest("post","/close_session",{session_id:this.sessionId}),this.sessionId=null,this.connectUrl=null);}};
|
|
2
|
+
exports.Simplex=d;//# sourceMappingURL=index.js.map
|
|
33
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Example function to demonstrate package usage\n * @param name - The name to greet\n * @returns A greeting message\n */\nexport function greet(name: string): string {\n return `Hello, ${name}!`;\n}\n\n// Export other functions and types here "],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,SAAS,MAAM,MAAsB;AAC1C,SAAO,UAAU,IAAI;AACvB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["BASE_URL","Simplex","apiKey","method","endpoint","data","params","formData","key","value","response","axios","responseData","errorMessage","error","showInConsole","proxies","workflowName","sessionData","url","cdpUrl","elementDescription","text","pixels","milliseconds","filePathOrCallable","blob"],"mappings":"oJAIA,IAAMA,CAAW,CAAA,wBAAA,CA+BJC,CAAN,CAAA,KAAc,CAKnB,WAAA,CAAYC,CAAgB,CAAA,CAH5B,IAAQ,CAAA,SAAA,CAA2B,KACnC,IAAQ,CAAA,UAAA,CAA4B,IAGlC,CAAA,IAAA,CAAK,MAASA,CAAAA,EAChB,CAEA,MAAc,WACZC,CAAAA,CAAAA,CACAC,CACAC,CAAAA,CAAAA,CACAC,CACY,CAAA,CACZ,GAAI,CACF,OAAA,CAAQ,GAAI,CAAA,CAAA,OAAA,EAAUH,CAAO,CAAA,WAAA,EAAa,CAAA,YAAA,EAAeC,CAAQ,CAAA,CAAE,CAGnE,CAAA,IAAMG,CAAW,CAAA,IAAI,QACjBF,CAAAA,CAAAA,EACF,MAAO,CAAA,OAAA,CAAQA,CAAI,CAAA,CAAE,OAAQ,CAAA,CAAC,CAACG,CAAAA,CAAKC,CAAK,CAAA,GAAM,CAClBA,CAAAA,EAAU,IACnCF,EAAAA,CAAAA,CAAS,OAAOC,CAAKC,CAAAA,CAAAA,CAAM,QAAS,EAAC,EAEzC,CAAC,CAGH,CAAA,OAAA,CAAQ,GAAI,CAAA,eAAA,CAAiBJ,CAAI,CAAA,CAEjC,IAAMK,CAAAA,CAAW,MAAMC,kBAAAA,CAAM,CAC3B,MAAA,CAAAR,CACA,CAAA,GAAA,CAAK,CAAGH,EAAAA,CAAQ,CAAGI,EAAAA,CAAQ,CAC3B,CAAA,C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AAS,CAAA,CAAE,OAASA,CAAAA,CAAO,CAAI,CAAA,CAAE,UAAY,CAAA,IAAA,CAAK,SAAU,CAClE,CAEMV,CAAAA,CAAAA,CAAW,MAAM,IAAA,CAAK,WAA6B,CAAA,MAAA,CAAQ,SAAWL,CAAAA,CAAI,CAChF,CAAA,OAAO,CAACK,CAAAA,CAAS,QAAU,KAAOA,CAAAA,CAAAA,CAAS,SAAa,EAAA,EAAE,CAC5D,CAEA,MAAM,YAAA,EAA8B,CAC7B,IAAA,CAAK,SAIV,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,MAAQ,CAAA,gBAAA,CAAkB,CAAE,UAAA,CAAY,IAAK,CAAA,SAAU,CAAC,CAAA,CAC/E,IAAK,CAAA,SAAA,CAAY,IACjB,CAAA,IAAA,CAAK,UAAa,CAAA,IAAA,EACpB,CACF","file":"index.js","sourcesContent":["// Export other functions and types here \n\nimport axios from 'axios';\n\nconst BASE_URL = \"https://api.simplex.sh\";\n\ninterface SessionData {\n [key: string]: any;\n}\n\ninterface PlaywrightClickOptions {\n locator: string;\n locatorType: string;\n exact?: boolean;\n elementIndex?: 'first' | 'last' | 'nth';\n nthIndex?: number;\n locatorOptions?: Record<string, any>;\n}\n\ninterface SimplexResponse {\n succeeded: boolean;\n error?: string;\n session_id?: string;\n livestream_url?: string;\n connect_url?: string;\n element_clicked?: string;\n text?: string;\n image?: string;\n bbox?: any;\n b64?: string;\n filename?: string;\n exists?: boolean;\n reasoning?: string;\n}\n\nexport class Simplex {\n private apiKey: string;\n private sessionId: string | null = null;\n private connectUrl: string | null = null;\n\n constructor(apiKey: string) {\n this.apiKey = apiKey;\n }\n\n private async makeRequest<T>(\n method: 'get' | 'post',\n endpoint: string,\n data?: any,\n params?: any\n ): Promise<T> {\n try {\n console.log(`Making ${method.toUpperCase()} request to ${endpoint}`);\n \n // Convert data to FormData\n const formData = new FormData();\n if (data) {\n Object.entries(data).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n formData.append(key, value.toString());\n }\n });\n }\n\n console.log('Request data:', data);\n \n const response = await axios({\n method,\n url: `${BASE_URL}${endpoint}`,\n data: method === 'post' ? formData : undefined,\n params: method === 'get' ? params : undefined,\n headers: {\n 'x-api-key': this.apiKey,\n ...(method === 'post' ? { 'Content-Type': 'multipart/form-data' } : {})\n }\n });\n\n console.log('Response status:', response.status);\n console.log('Response data:', JSON.stringify(response.data, null, 2));\n\n const responseData = response.data as SimplexResponse;\n \n // Consider response successful if:\n // 1. It has succeeded: true, or\n // 2. It's a create_session response with a session_id\n if (!responseData.succeeded && !(endpoint === '/create_session' && responseData.session_id)) {\n const errorMessage = responseData.error || 'Request failed';\n console.error('API request failed:', errorMessage);\n throw new Error(errorMessage);\n }\n return responseData as T;\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const errorMessage = error.response?.data?.error || error.message;\n console.error('Axios error:', {\n status: error.response?.status,\n statusText: error.response?.statusText,\n data: error.response?.data,\n message: errorMessage\n });\n throw new Error(`Request failed: ${errorMessage}`);\n }\n console.error('Unexpected error:', error);\n throw error;\n }\n }\n\n async createSession(\n showInConsole: boolean = true,\n proxies: boolean = true,\n workflowName?: string,\n sessionData?: SessionData | string\n ): Promise<[string, string]> {\n const data: any = {\n proxies,\n workflow_name: workflowName\n };\n\n if (this.sessionId) {\n throw new Error(\"A session is already active. Please close the current session before creating a new one.\");\n }\n if (sessionData) {\n if (typeof sessionData === 'string') {\n try {\n data.session_data = JSON.stringify(JSON.parse(sessionData));\n } catch {\n // If parsing fails, treat as file path\n // Note: File system operations are not available in browser environment\n throw new Error('File system operations are not supported in this environment');\n }\n } else {\n data.session_data = JSON.stringify(sessionData);\n }\n }\n\n const response = await this.makeRequest<SimplexResponse>('post', '/create_session', data);\n \n if (!response.session_id) {\n throw new Error('Session creation failed: No session ID returned');\n }\n\n this.sessionId = response.session_id;\n this.connectUrl = response.connect_url || null;\n\n if (showInConsole && response.livestream_url) {\n console.log(`Livestream URL: ${response.livestream_url}`);\n }\n\n return [response.session_id, response.livestream_url || ''];\n }\n\n async goto(url: string, cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling goto with url='${url}'`);\n }\n\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n url = 'https://' + url;\n }\n\n const data = {\n url,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n await this.makeRequest('post', '/goto', data);\n }\n\n async click(elementDescription: string, cdpUrl?: string): Promise<string> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling click with elementDescription='${elementDescription}'`);\n }\n\n const data = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('post', '/click', data);\n return response.element_clicked || '';\n }\n\n async type(text: string, cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling type with text='${text}'`);\n }\n\n const data = {\n text,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n await this.makeRequest('post', '/type', data);\n }\n\n async pressEnter(cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error('Must call createSession before calling pressEnter');\n }\n\n const data = cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId };\n await this.makeRequest('post', '/press_enter', data);\n }\n\n async pressTab(cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error('Must call createSession before calling pressTab');\n }\n\n const data = cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId };\n await this.makeRequest('post', '/press_tab', data);\n }\n\n async deleteText(cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error('Must call createSession before calling deleteText');\n }\n\n const data = cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId };\n await this.makeRequest('post', '/delete_text', data);\n }\n\n async extractBbox(elementDescription: string, cdpUrl?: string): Promise<any> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling extractBbox with elementDescription='${elementDescription}'`);\n }\n\n const params = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('get', '/extract-bbox', undefined, params);\n return response.bbox;\n }\n\n async extractText(elementDescription: string, cdpUrl?: string): Promise<string> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling extractText with elementDescription='${elementDescription}'`);\n }\n\n const data = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('post', '/extract-text', data);\n return response.text || '';\n }\n\n async extractImage(elementDescription: string, cdpUrl?: string): Promise<string> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling extractImage with elementDescription='${elementDescription}'`);\n }\n\n const params = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('get', '/extract-image', undefined, params);\n return response.image || '';\n }\n\n async scroll(pixels: number, cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling scroll with pixels=${pixels}`);\n }\n\n const data = {\n pixels,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n await this.makeRequest('post', '/scroll', data);\n }\n\n async wait(milliseconds: number, cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling wait with milliseconds=${milliseconds}`);\n }\n\n const data = {\n milliseconds,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n await this.makeRequest('post', '/wait', data);\n }\n\n async clickAndUpload(\n elementDescription: string,\n filePathOrCallable: string | (() => Blob)\n ): Promise<void> {\n if (!this.sessionId) {\n throw new Error(`Must call createSession before calling clickAndUpload with elementDescription='${elementDescription}'`);\n }\n\n if (typeof filePathOrCallable !== 'string' && typeof filePathOrCallable !== 'function') {\n throw new TypeError(`filePathOrCallable must be either a string or a callable, not a ${typeof filePathOrCallable}`);\n }\n\n const formData = new FormData();\n formData.append('element_description', elementDescription);\n formData.append('session_id', this.sessionId);\n\n if (typeof filePathOrCallable === 'string') {\n // Note: File system operations are not available in browser environment\n throw new Error('File system operations are not supported in this environment');\n } else {\n const blob = filePathOrCallable();\n formData.append('file', blob, 'file'); // Add filename for the blob\n }\n\n await this.makeRequest('post', '/click_and_upload', formData, undefined);\n }\n\n async clickAndDownload(elementDescription: string): Promise<[string, string]> {\n if (!this.sessionId) {\n throw new Error(`Must call createSession before calling clickAndDownload with elementDescription='${elementDescription}'`);\n }\n\n const data = {\n element_description: elementDescription,\n session_id: this.sessionId\n };\n\n const response = await this.makeRequest<SimplexResponse>('post', '/click_and_download', data);\n return [response.b64 || '', response.filename || ''];\n }\n\n async exists(elementDescription: string, cdpUrl?: string): Promise<[boolean, string]> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling exists with elementDescription='${elementDescription}'`);\n }\n\n const data = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('post', '/exists', data);\n return [response.exists || false, response.reasoning || ''];\n }\n\n async closeSession(): Promise<void> {\n if (!this.sessionId) {\n return;\n }\n\n await this.makeRequest('post', '/close_session', { session_id: this.sessionId });\n this.sessionId = null;\n this.connectUrl = null;\n }\n} "]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return `Hello, ${name}!`;
|
|
4
|
-
}
|
|
5
|
-
export {
|
|
6
|
-
greet
|
|
7
|
-
};
|
|
1
|
+
import l from'axios';var p="https://api.simplex.sh",d=class{constructor(s){this.sessionId=null;this.connectUrl=null;this.apiKey=s;}async makeRequest(s,e,t,i){try{console.log(`Making ${s.toUpperCase()} request to ${e}`);let n=new FormData;t&&Object.entries(t).forEach(([a,c])=>{c!=null&&n.append(a,c.toString());}),console.log("Request data:",t);let o=await l({method:s,url:`${p}${e}`,data:s==="post"?n:void 0,params:s==="get"?i:void 0,headers:{"x-api-key":this.apiKey,...s==="post"?{"Content-Type":"multipart/form-data"}:{}}});console.log("Response status:",o.status),console.log("Response data:",JSON.stringify(o.data,null,2));let r=o.data;if(!r.succeeded&&!(e==="/create_session"&&r.session_id)){let a=r.error||"Request failed";throw console.error("API request failed:",a),new Error(a)}return r}catch(n){if(l.isAxiosError(n)){let o=n.response?.data?.error||n.message;throw console.error("Axios error:",{status:n.response?.status,statusText:n.response?.statusText,data:n.response?.data,message:o}),new Error(`Request failed: ${o}`)}throw console.error("Unexpected error:",n),n}}async createSession(s=true,e=true,t,i){let n={proxies:e,workflow_name:t};if(this.sessionId)throw new Error("A session is already active. Please close the current session before creating a new one.");if(i)if(typeof i=="string")try{n.session_data=JSON.stringify(JSON.parse(i));}catch{throw new Error("File system operations are not supported in this environment")}else n.session_data=JSON.stringify(i);let o=await this.makeRequest("post","/create_session",n);if(!o.session_id)throw new Error("Session creation failed: No session ID returned");return this.sessionId=o.session_id,this.connectUrl=o.connect_url||null,s&&o.livestream_url&&console.log(`Livestream URL: ${o.livestream_url}`),[o.session_id,o.livestream_url||""]}async goto(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling goto with url='${s}'`);!s.startsWith("http://")&&!s.startsWith("https://")&&(s="https://"+s);let t={url:s,...e?{cdp_url:e}:{session_id:this.sessionId}};await this.makeRequest("post","/goto",t);}async click(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling click with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}};return (await this.makeRequest("post","/click",t)).element_clicked||""}async type(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling type with text='${s}'`);let t={text:s,...e?{cdp_url:e}:{session_id:this.sessionId}};await this.makeRequest("post","/type",t);}async pressEnter(s){if(!s&&!this.sessionId)throw new Error("Must call createSession before calling pressEnter");let e=s?{cdp_url:s}:{session_id:this.sessionId};await this.makeRequest("post","/press_enter",e);}async pressTab(s){if(!s&&!this.sessionId)throw new Error("Must call createSession before calling pressTab");let e=s?{cdp_url:s}:{session_id:this.sessionId};await this.makeRequest("post","/press_tab",e);}async deleteText(s){if(!s&&!this.sessionId)throw new Error("Must call createSession before calling deleteText");let e=s?{cdp_url:s}:{session_id:this.sessionId};await this.makeRequest("post","/delete_text",e);}async extractBbox(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling extractBbox with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}};return (await this.makeRequest("get","/extract-bbox",void 0,t)).bbox}async extractText(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling extractText with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}};return (await this.makeRequest("post","/extract-text",t)).text||""}async extractImage(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling extractImage with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}};return (await this.makeRequest("get","/extract-image",void 0,t)).image||""}async scroll(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling scroll with pixels=${s}`);let t={pixels:s,...e?{cdp_url:e}:{session_id:this.sessionId}};await this.makeRequest("post","/scroll",t);}async wait(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling wait with milliseconds=${s}`);let t={milliseconds:s,...e?{cdp_url:e}:{session_id:this.sessionId}};await this.makeRequest("post","/wait",t);}async clickAndUpload(s,e){if(!this.sessionId)throw new Error(`Must call createSession before calling clickAndUpload with elementDescription='${s}'`);if(typeof e!="string"&&typeof e!="function")throw new TypeError(`filePathOrCallable must be either a string or a callable, not a ${typeof e}`);let t=new FormData;if(t.append("element_description",s),t.append("session_id",this.sessionId),typeof e=="string")throw new Error("File system operations are not supported in this environment");{let i=e();t.append("file",i,"file");}await this.makeRequest("post","/click_and_upload",t,void 0);}async clickAndDownload(s){if(!this.sessionId)throw new Error(`Must call createSession before calling clickAndDownload with elementDescription='${s}'`);let e={element_description:s,session_id:this.sessionId},t=await this.makeRequest("post","/click_and_download",e);return [t.b64||"",t.filename||""]}async exists(s,e){if(!e&&!this.sessionId)throw new Error(`Must call createSession before calling exists with elementDescription='${s}'`);let t={element_description:s,...e?{cdp_url:e}:{session_id:this.sessionId}},i=await this.makeRequest("post","/exists",t);return [i.exists||false,i.reasoning||""]}async closeSession(){this.sessionId&&(await this.makeRequest("post","/close_session",{session_id:this.sessionId}),this.sessionId=null,this.connectUrl=null);}};
|
|
2
|
+
export{d as Simplex};//# sourceMappingURL=index.mjs.map
|
|
8
3
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Example function to demonstrate package usage\n * @param name - The name to greet\n * @returns A greeting message\n */\nexport function greet(name: string): string {\n return `Hello, ${name}!`;\n}\n\n// Export other functions and types here "],"mappings":";AAKO,SAAS,MAAM,MAAsB;AAC1C,SAAO,UAAU,IAAI;AACvB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["BASE_URL","Simplex","apiKey","method","endpoint","data","params","formData","key","value","response","axios","responseData","errorMessage","error","showInConsole","proxies","workflowName","sessionData","url","cdpUrl","elementDescription","text","pixels","milliseconds","filePathOrCallable","blob"],"mappings":"qBAIA,IAAMA,CAAW,CAAA,wBAAA,CA+BJC,CAAN,CAAA,KAAc,CAKnB,WAAA,CAAYC,CAAgB,CAAA,CAH5B,IAAQ,CAAA,SAAA,CAA2B,KACnC,IAAQ,CAAA,UAAA,CAA4B,IAGlC,CAAA,IAAA,C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CACF","file":"index.mjs","sourcesContent":["// Export other functions and types here \n\nimport axios from 'axios';\n\nconst BASE_URL = \"https://api.simplex.sh\";\n\ninterface SessionData {\n [key: string]: any;\n}\n\ninterface PlaywrightClickOptions {\n locator: string;\n locatorType: string;\n exact?: boolean;\n elementIndex?: 'first' | 'last' | 'nth';\n nthIndex?: number;\n locatorOptions?: Record<string, any>;\n}\n\ninterface SimplexResponse {\n succeeded: boolean;\n error?: string;\n session_id?: string;\n livestream_url?: string;\n connect_url?: string;\n element_clicked?: string;\n text?: string;\n image?: string;\n bbox?: any;\n b64?: string;\n filename?: string;\n exists?: boolean;\n reasoning?: string;\n}\n\nexport class Simplex {\n private apiKey: string;\n private sessionId: string | null = null;\n private connectUrl: string | null = null;\n\n constructor(apiKey: string) {\n this.apiKey = apiKey;\n }\n\n private async makeRequest<T>(\n method: 'get' | 'post',\n endpoint: string,\n data?: any,\n params?: any\n ): Promise<T> {\n try {\n console.log(`Making ${method.toUpperCase()} request to ${endpoint}`);\n \n // Convert data to FormData\n const formData = new FormData();\n if (data) {\n Object.entries(data).forEach(([key, value]) => {\n if (value !== undefined && value !== null) {\n formData.append(key, value.toString());\n }\n });\n }\n\n console.log('Request data:', data);\n \n const response = await axios({\n method,\n url: `${BASE_URL}${endpoint}`,\n data: method === 'post' ? formData : undefined,\n params: method === 'get' ? params : undefined,\n headers: {\n 'x-api-key': this.apiKey,\n ...(method === 'post' ? { 'Content-Type': 'multipart/form-data' } : {})\n }\n });\n\n console.log('Response status:', response.status);\n console.log('Response data:', JSON.stringify(response.data, null, 2));\n\n const responseData = response.data as SimplexResponse;\n \n // Consider response successful if:\n // 1. It has succeeded: true, or\n // 2. It's a create_session response with a session_id\n if (!responseData.succeeded && !(endpoint === '/create_session' && responseData.session_id)) {\n const errorMessage = responseData.error || 'Request failed';\n console.error('API request failed:', errorMessage);\n throw new Error(errorMessage);\n }\n return responseData as T;\n } catch (error) {\n if (axios.isAxiosError(error)) {\n const errorMessage = error.response?.data?.error || error.message;\n console.error('Axios error:', {\n status: error.response?.status,\n statusText: error.response?.statusText,\n data: error.response?.data,\n message: errorMessage\n });\n throw new Error(`Request failed: ${errorMessage}`);\n }\n console.error('Unexpected error:', error);\n throw error;\n }\n }\n\n async createSession(\n showInConsole: boolean = true,\n proxies: boolean = true,\n workflowName?: string,\n sessionData?: SessionData | string\n ): Promise<[string, string]> {\n const data: any = {\n proxies,\n workflow_name: workflowName\n };\n\n if (this.sessionId) {\n throw new Error(\"A session is already active. Please close the current session before creating a new one.\");\n }\n if (sessionData) {\n if (typeof sessionData === 'string') {\n try {\n data.session_data = JSON.stringify(JSON.parse(sessionData));\n } catch {\n // If parsing fails, treat as file path\n // Note: File system operations are not available in browser environment\n throw new Error('File system operations are not supported in this environment');\n }\n } else {\n data.session_data = JSON.stringify(sessionData);\n }\n }\n\n const response = await this.makeRequest<SimplexResponse>('post', '/create_session', data);\n \n if (!response.session_id) {\n throw new Error('Session creation failed: No session ID returned');\n }\n\n this.sessionId = response.session_id;\n this.connectUrl = response.connect_url || null;\n\n if (showInConsole && response.livestream_url) {\n console.log(`Livestream URL: ${response.livestream_url}`);\n }\n\n return [response.session_id, response.livestream_url || ''];\n }\n\n async goto(url: string, cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling goto with url='${url}'`);\n }\n\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n url = 'https://' + url;\n }\n\n const data = {\n url,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n await this.makeRequest('post', '/goto', data);\n }\n\n async click(elementDescription: string, cdpUrl?: string): Promise<string> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling click with elementDescription='${elementDescription}'`);\n }\n\n const data = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('post', '/click', data);\n return response.element_clicked || '';\n }\n\n async type(text: string, cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling type with text='${text}'`);\n }\n\n const data = {\n text,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n await this.makeRequest('post', '/type', data);\n }\n\n async pressEnter(cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error('Must call createSession before calling pressEnter');\n }\n\n const data = cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId };\n await this.makeRequest('post', '/press_enter', data);\n }\n\n async pressTab(cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error('Must call createSession before calling pressTab');\n }\n\n const data = cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId };\n await this.makeRequest('post', '/press_tab', data);\n }\n\n async deleteText(cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error('Must call createSession before calling deleteText');\n }\n\n const data = cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId };\n await this.makeRequest('post', '/delete_text', data);\n }\n\n async extractBbox(elementDescription: string, cdpUrl?: string): Promise<any> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling extractBbox with elementDescription='${elementDescription}'`);\n }\n\n const params = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('get', '/extract-bbox', undefined, params);\n return response.bbox;\n }\n\n async extractText(elementDescription: string, cdpUrl?: string): Promise<string> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling extractText with elementDescription='${elementDescription}'`);\n }\n\n const data = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('post', '/extract-text', data);\n return response.text || '';\n }\n\n async extractImage(elementDescription: string, cdpUrl?: string): Promise<string> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling extractImage with elementDescription='${elementDescription}'`);\n }\n\n const params = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('get', '/extract-image', undefined, params);\n return response.image || '';\n }\n\n async scroll(pixels: number, cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling scroll with pixels=${pixels}`);\n }\n\n const data = {\n pixels,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n await this.makeRequest('post', '/scroll', data);\n }\n\n async wait(milliseconds: number, cdpUrl?: string): Promise<void> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling wait with milliseconds=${milliseconds}`);\n }\n\n const data = {\n milliseconds,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n await this.makeRequest('post', '/wait', data);\n }\n\n async clickAndUpload(\n elementDescription: string,\n filePathOrCallable: string | (() => Blob)\n ): Promise<void> {\n if (!this.sessionId) {\n throw new Error(`Must call createSession before calling clickAndUpload with elementDescription='${elementDescription}'`);\n }\n\n if (typeof filePathOrCallable !== 'string' && typeof filePathOrCallable !== 'function') {\n throw new TypeError(`filePathOrCallable must be either a string or a callable, not a ${typeof filePathOrCallable}`);\n }\n\n const formData = new FormData();\n formData.append('element_description', elementDescription);\n formData.append('session_id', this.sessionId);\n\n if (typeof filePathOrCallable === 'string') {\n // Note: File system operations are not available in browser environment\n throw new Error('File system operations are not supported in this environment');\n } else {\n const blob = filePathOrCallable();\n formData.append('file', blob, 'file'); // Add filename for the blob\n }\n\n await this.makeRequest('post', '/click_and_upload', formData, undefined);\n }\n\n async clickAndDownload(elementDescription: string): Promise<[string, string]> {\n if (!this.sessionId) {\n throw new Error(`Must call createSession before calling clickAndDownload with elementDescription='${elementDescription}'`);\n }\n\n const data = {\n element_description: elementDescription,\n session_id: this.sessionId\n };\n\n const response = await this.makeRequest<SimplexResponse>('post', '/click_and_download', data);\n return [response.b64 || '', response.filename || ''];\n }\n\n async exists(elementDescription: string, cdpUrl?: string): Promise<[boolean, string]> {\n if (!cdpUrl && !this.sessionId) {\n throw new Error(`Must call createSession before calling exists with elementDescription='${elementDescription}'`);\n }\n\n const data = {\n element_description: elementDescription,\n ...(cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId })\n };\n\n const response = await this.makeRequest<SimplexResponse>('post', '/exists', data);\n return [response.exists || false, response.reasoning || ''];\n }\n\n async closeSession(): Promise<void> {\n if (!this.sessionId) {\n return;\n }\n\n await this.makeRequest('post', '/close_session', { session_id: this.sessionId });\n this.sessionId = null;\n this.connectUrl = null;\n }\n} "]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simplex-ts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A TypeScript package for the Simplex API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
8
15
|
"files": [
|
|
9
16
|
"dist"
|
|
10
17
|
],
|
|
@@ -33,7 +40,6 @@
|
|
|
33
40
|
},
|
|
34
41
|
"dependencies": {
|
|
35
42
|
"axios": "^1.6.7",
|
|
36
|
-
"dotenv": "^16.4.7"
|
|
37
|
-
"simplex-ts": "^1.0.3"
|
|
43
|
+
"dotenv": "^16.4.7"
|
|
38
44
|
}
|
|
39
45
|
}
|