simplex-ts 1.1.11 → 2.0.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 +163 -56
- package/dist/SimplexClient.d.ts +13 -0
- package/dist/SimplexClient.d.ts.map +1 -0
- package/dist/SimplexClient.js +31 -0
- package/dist/SimplexClient.js.map +1 -0
- package/dist/client/HttpClient.d.ts +33 -0
- package/dist/client/HttpClient.d.ts.map +1 -0
- package/dist/client/HttpClient.js +149 -0
- package/dist/client/HttpClient.js.map +1 -0
- package/dist/errors/index.d.ts +22 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +55 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +4 -41
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -378
- package/dist/index.js.map +1 -1
- package/dist/resources/Agent.d.ts +13 -0
- package/dist/resources/Agent.d.ts.map +1 -0
- package/dist/resources/Agent.js +53 -0
- package/dist/resources/Agent.js.map +1 -0
- package/dist/resources/Workflow.d.ts +38 -0
- package/dist/resources/Workflow.d.ts.map +1 -0
- package/dist/resources/Workflow.js +124 -0
- package/dist/resources/Workflow.js.map +1 -0
- package/dist/types/index.d.ts +80 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +22 -26
- package/dist/index.d.mts +0 -41
- package/dist/index.mjs +0 -345
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Workflow = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
class Workflow {
|
|
6
|
+
constructor(httpClient) {
|
|
7
|
+
this.httpClient = httpClient;
|
|
8
|
+
}
|
|
9
|
+
async run(workflowId, options) {
|
|
10
|
+
const request = {
|
|
11
|
+
workflow_id: workflowId,
|
|
12
|
+
variables: options?.variables,
|
|
13
|
+
metadata: options?.metadata,
|
|
14
|
+
webhook_url: options?.webhookUrl,
|
|
15
|
+
};
|
|
16
|
+
try {
|
|
17
|
+
const response = await this.httpClient.post('/run_workflow', request);
|
|
18
|
+
if (!response.succeeded) {
|
|
19
|
+
throw new errors_1.WorkflowError(response.message || 'Workflow execution failed', workflowId, response.session_id);
|
|
20
|
+
}
|
|
21
|
+
return response;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error instanceof errors_1.WorkflowError) {
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
throw new errors_1.WorkflowError(`Failed to run workflow: ${error instanceof Error ? error.message : 'Unknown error'}`, workflowId);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async runWithVariables(workflowId, variables) {
|
|
31
|
+
return this.run(workflowId, { variables });
|
|
32
|
+
}
|
|
33
|
+
async getStatus(sessionId) {
|
|
34
|
+
try {
|
|
35
|
+
const response = await this.httpClient.get(`/run_workflow_status?session_id=${sessionId}`);
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
throw new errors_1.WorkflowError(`Failed to get workflow status: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined, sessionId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async createWorkflowSession(workflowName, url, options) {
|
|
43
|
+
// Ensure URL has protocol
|
|
44
|
+
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
45
|
+
url = 'https://' + url;
|
|
46
|
+
}
|
|
47
|
+
const request = {
|
|
48
|
+
workflow_name: workflowName,
|
|
49
|
+
url: url,
|
|
50
|
+
proxies: options?.proxies,
|
|
51
|
+
session_data: options?.sessionData ? JSON.stringify(options.sessionData) : undefined,
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
const response = await this.httpClient.post('/create_workflow_session', request);
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new errors_1.WorkflowError(`Failed to create workflow session: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async startSegment(workflowId, segmentName) {
|
|
62
|
+
const request = {
|
|
63
|
+
workflow_id: workflowId,
|
|
64
|
+
segment_name: segmentName,
|
|
65
|
+
};
|
|
66
|
+
try {
|
|
67
|
+
const response = await this.httpClient.post('/start_segment', request);
|
|
68
|
+
return response;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
throw new errors_1.WorkflowError(`Failed to start segment: ${error instanceof Error ? error.message : 'Unknown error'}`, workflowId);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async finishSegment(workflowId) {
|
|
75
|
+
const request = {
|
|
76
|
+
workflow_id: workflowId,
|
|
77
|
+
};
|
|
78
|
+
try {
|
|
79
|
+
const response = await this.httpClient.post('/finish_segment', request);
|
|
80
|
+
return response;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
throw new errors_1.WorkflowError(`Failed to finish segment: ${error instanceof Error ? error.message : 'Unknown error'}`, workflowId);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async startCapture(sessionId) {
|
|
87
|
+
const request = {
|
|
88
|
+
session_id: sessionId,
|
|
89
|
+
};
|
|
90
|
+
try {
|
|
91
|
+
const response = await this.httpClient.post('/start_capture_mode', request);
|
|
92
|
+
return response;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
throw new errors_1.WorkflowError(`Failed to start capture mode: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined, sessionId);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async stopCapture(sessionId) {
|
|
99
|
+
const request = {
|
|
100
|
+
session_id: sessionId,
|
|
101
|
+
};
|
|
102
|
+
try {
|
|
103
|
+
const response = await this.httpClient.post('/stop_capture_mode', request);
|
|
104
|
+
return response;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
throw new errors_1.WorkflowError(`Failed to stop capture mode: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined, sessionId);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async closeWorkflowSession(sessionId) {
|
|
111
|
+
const request = {
|
|
112
|
+
session_id: sessionId,
|
|
113
|
+
};
|
|
114
|
+
try {
|
|
115
|
+
const response = await this.httpClient.post('/close_workflow_session', request);
|
|
116
|
+
return response;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new errors_1.WorkflowError(`Failed to close workflow session: ${error instanceof Error ? error.message : 'Unknown error'}`, undefined, sessionId);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.Workflow = Workflow;
|
|
124
|
+
//# sourceMappingURL=Workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Workflow.js","sourceRoot":"","sources":["../../src/resources/Workflow.ts"],"names":[],"mappings":";;;AASA,sCAA0C;AAE1C,MAAa,QAAQ;IACnB,YAAoB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;IAAG,CAAC;IAE9C,KAAK,CAAC,GAAG,CACP,UAAkB,EAClB,OAIC;QAED,MAAM,OAAO,GAAuB;YAClC,WAAW,EAAE,UAAU;YACvB,SAAS,EAAE,OAAO,EAAE,SAAS;YAC7B,QAAQ,EAAE,OAAO,EAAE,QAAQ;YAC3B,WAAW,EAAE,OAAO,EAAE,UAAU;SACjC,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CACzC,eAAe,EACf,OAAO,CACR,CAAC;YAEF,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACxB,MAAM,IAAI,sBAAa,CACrB,QAAQ,CAAC,OAAO,IAAI,2BAA2B,EAC/C,UAAU,EACV,QAAQ,CAAC,UAAU,CACpB,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MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,IAAI,CACzC,yBAAyB,EACzB,OAAO,CACR,CAAC;YAEF,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,sBAAa,CACrB,qCAAqC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,EAC/F,SAAS,EACT,SAAS,CACV,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAxND,4BAwNC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export interface SimplexConfig {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
baseURL?: string;
|
|
4
|
+
timeout?: number;
|
|
5
|
+
maxRetries?: number;
|
|
6
|
+
retryDelay?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface WorkflowVariables {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
export interface RunWorkflowRequest {
|
|
12
|
+
workflow_id: string;
|
|
13
|
+
metadata?: string;
|
|
14
|
+
webhook_url?: string;
|
|
15
|
+
variables?: WorkflowVariables;
|
|
16
|
+
}
|
|
17
|
+
export interface RunWorkflowResponse {
|
|
18
|
+
succeeded: boolean;
|
|
19
|
+
message: string;
|
|
20
|
+
session_id: string;
|
|
21
|
+
vnc_url: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SimplexClientOptions {
|
|
24
|
+
apiKey: string;
|
|
25
|
+
baseURL?: string;
|
|
26
|
+
timeout?: number;
|
|
27
|
+
maxRetries?: number;
|
|
28
|
+
retryDelay?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface AgenticRequest {
|
|
31
|
+
task: string;
|
|
32
|
+
session_id: string;
|
|
33
|
+
max_steps?: number;
|
|
34
|
+
actions_to_exclude?: string[];
|
|
35
|
+
variables?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface AgenticResponse {
|
|
38
|
+
succeeded: boolean;
|
|
39
|
+
result: any;
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface RunAgentRequest {
|
|
43
|
+
agent_name: string;
|
|
44
|
+
session_id: string;
|
|
45
|
+
variables?: Record<string, any>;
|
|
46
|
+
}
|
|
47
|
+
export interface RunAgentResponse {
|
|
48
|
+
succeeded: boolean;
|
|
49
|
+
session_id: string;
|
|
50
|
+
agent_name: string;
|
|
51
|
+
result: any;
|
|
52
|
+
}
|
|
53
|
+
export interface WorkflowAction {
|
|
54
|
+
action: string;
|
|
55
|
+
params: any;
|
|
56
|
+
result: any;
|
|
57
|
+
timestamp: string;
|
|
58
|
+
}
|
|
59
|
+
export interface WorkflowStatusResponse {
|
|
60
|
+
succeeded: boolean;
|
|
61
|
+
completed: boolean;
|
|
62
|
+
results: WorkflowAction[];
|
|
63
|
+
total_actions: number;
|
|
64
|
+
session_id: string;
|
|
65
|
+
completed_at?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface CreateWorkflowSessionRequest {
|
|
68
|
+
workflow_name: string;
|
|
69
|
+
url: string;
|
|
70
|
+
proxies?: boolean;
|
|
71
|
+
session_data?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface CreateWorkflowSessionResponse {
|
|
74
|
+
session_id: string;
|
|
75
|
+
workflow_id: string;
|
|
76
|
+
livestream_url: string;
|
|
77
|
+
connect_url: string;
|
|
78
|
+
vnc_url: string;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;CACr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AAE,GAAG,CAAC;CACb;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,GAAG,CAAC;IACZ,MAAM,EAAE,GAAG,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,4BAA4B;IAC3C,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simplex-ts",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist",
|
|
10
|
-
"dist/**/*.d.ts",
|
|
11
|
-
"dist/**/*.d.mts"
|
|
12
|
-
],
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
13
6
|
"scripts": {
|
|
14
|
-
"build": "
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"clean": "rm -rf dist",
|
|
9
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
10
|
+
"dev": "tsc --watch",
|
|
11
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
12
|
},
|
|
20
13
|
"keywords": [
|
|
14
|
+
"simplex",
|
|
15
|
+
"api",
|
|
16
|
+
"sdk",
|
|
21
17
|
"typescript",
|
|
22
|
-
"
|
|
18
|
+
"workflow"
|
|
23
19
|
],
|
|
24
20
|
"author": "",
|
|
25
21
|
"license": "MIT",
|
|
22
|
+
"description": "Official TypeScript SDK for the Simplex API",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist/**/*"
|
|
25
|
+
],
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@types/
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"rimraf": "^5.0.5",
|
|
32
|
-
"ts-jest": "^29.1.2",
|
|
33
|
-
"tsup": "^8.0.2",
|
|
34
|
-
"typescript": "^5.3.3"
|
|
27
|
+
"@types/node": "^24.5.2",
|
|
28
|
+
"nodemon": "^3.1.10",
|
|
29
|
+
"tsx": "^4.20.6",
|
|
30
|
+
"typescript": "^5.9.2"
|
|
35
31
|
},
|
|
36
32
|
"dependencies": {
|
|
37
|
-
"axios": "^1.
|
|
38
|
-
"dotenv": "^
|
|
33
|
+
"axios": "^1.12.2",
|
|
34
|
+
"dotenv": "^17.2.2"
|
|
39
35
|
}
|
|
40
36
|
}
|
package/dist/index.d.mts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Example function to demonstrate package usage
|
|
3
|
-
* @param name - The name to greet
|
|
4
|
-
* @returns A greeting message
|
|
5
|
-
*/
|
|
6
|
-
declare function greet(name: string): string;
|
|
7
|
-
interface SessionData {
|
|
8
|
-
[key: string]: any;
|
|
9
|
-
}
|
|
10
|
-
declare class Simplex {
|
|
11
|
-
private apiKey;
|
|
12
|
-
private sessionId;
|
|
13
|
-
private connectUrl;
|
|
14
|
-
constructor(apiKey: string);
|
|
15
|
-
private makeRequest;
|
|
16
|
-
createSession(showInConsole?: boolean, proxies?: boolean, workflowName?: string, sessionData?: SessionData | string): Promise<[string, string]>;
|
|
17
|
-
goto(url: string, cdpUrl?: string): Promise<void>;
|
|
18
|
-
click(elementDescription: string, cdpUrl?: string): Promise<string>;
|
|
19
|
-
hover(elementDescription: string, cdpUrl?: string): Promise<void>;
|
|
20
|
-
scrollToElement(elementDescription: string, cdpUrl?: string): Promise<void>;
|
|
21
|
-
getNetworkResponse(url: string, cdpUrl?: string): Promise<string>;
|
|
22
|
-
type(text: string, cdpUrl?: string): Promise<void>;
|
|
23
|
-
pressEnter(cdpUrl?: string): Promise<void>;
|
|
24
|
-
pressTab(cdpUrl?: string): Promise<void>;
|
|
25
|
-
deleteText(cdpUrl?: string): Promise<void>;
|
|
26
|
-
extractBbox(elementDescription: string, cdpUrl?: string): Promise<any>;
|
|
27
|
-
extractText(elementDescription: string, cdpUrl?: string): Promise<string>;
|
|
28
|
-
scroll(pixels: number, cdpUrl?: string): Promise<void>;
|
|
29
|
-
wait(milliseconds: number, cdpUrl?: string): Promise<void>;
|
|
30
|
-
clickAndUpload(elementDescription: string, filePathOrCallable: string | (() => Blob)): Promise<void>;
|
|
31
|
-
clickAndDownload(elementDescription: string): Promise<[string, string]>;
|
|
32
|
-
exists(elementDescription: string, cdpUrl?: string): Promise<[boolean, string]>;
|
|
33
|
-
getPageURL(cdpUrl?: string): Promise<string>;
|
|
34
|
-
captureLoginSession(cdpUrl?: string): Promise<string>;
|
|
35
|
-
closeSession(): Promise<void>;
|
|
36
|
-
setDialogSettings(accept: boolean): Promise<void>;
|
|
37
|
-
getDialogMessage(): Promise<string>;
|
|
38
|
-
enqueueActions(actions: any[]): Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { Simplex, greet };
|
package/dist/index.mjs
DELETED
|
@@ -1,345 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import axios from "axios";
|
|
3
|
-
function greet(name) {
|
|
4
|
-
return `Hello, ${name}!`;
|
|
5
|
-
}
|
|
6
|
-
var BASE_URL = "https://api.simplex.sh";
|
|
7
|
-
var Simplex = class {
|
|
8
|
-
constructor(apiKey) {
|
|
9
|
-
this.sessionId = null;
|
|
10
|
-
this.connectUrl = null;
|
|
11
|
-
this.apiKey = apiKey;
|
|
12
|
-
}
|
|
13
|
-
async makeRequest(method, endpoint, data, params) {
|
|
14
|
-
try {
|
|
15
|
-
console.log(`Making ${method.toUpperCase()} request to ${endpoint}`);
|
|
16
|
-
const formData = new FormData();
|
|
17
|
-
if (data) {
|
|
18
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
19
|
-
if (value !== void 0 && value !== null) {
|
|
20
|
-
formData.append(key, value.toString());
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
const response = await axios({
|
|
25
|
-
method,
|
|
26
|
-
url: `${BASE_URL}${endpoint}`,
|
|
27
|
-
data: method === "post" ? formData : void 0,
|
|
28
|
-
params: method === "get" ? params : void 0,
|
|
29
|
-
headers: {
|
|
30
|
-
"x-api-key": this.apiKey,
|
|
31
|
-
...method === "post" ? { "Content-Type": "multipart/form-data" } : {}
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
const responseData = response.data;
|
|
35
|
-
if (endpoint === "/get_dialog_message") {
|
|
36
|
-
if (!("message" in responseData)) {
|
|
37
|
-
throw new Error(responseData.error || "Request failed");
|
|
38
|
-
}
|
|
39
|
-
return responseData;
|
|
40
|
-
}
|
|
41
|
-
if (endpoint === "/goto" || endpoint === "/hover") {
|
|
42
|
-
if (!("succeeded" in responseData)) {
|
|
43
|
-
throw new Error('Response data is missing the "succeeded" field');
|
|
44
|
-
}
|
|
45
|
-
return responseData;
|
|
46
|
-
}
|
|
47
|
-
if (endpoint === "/get_network_response") {
|
|
48
|
-
if (!("status" in responseData)) {
|
|
49
|
-
throw new Error("It looks like the get_network_response action failed to return a response. Did you set your api_key when creating the Simplex class?");
|
|
50
|
-
} else if (responseData.status == "success") {
|
|
51
|
-
return responseData;
|
|
52
|
-
} else {
|
|
53
|
-
throw new Error(`Failed to get network response: ${responseData.error}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (!responseData.succeeded && !(endpoint === "/create_session" && responseData.session_id)) {
|
|
57
|
-
const errorMessage = responseData.error || "Request failed";
|
|
58
|
-
console.error("API request failed:", errorMessage);
|
|
59
|
-
throw new Error(errorMessage);
|
|
60
|
-
}
|
|
61
|
-
return responseData;
|
|
62
|
-
} catch (error) {
|
|
63
|
-
const axiosError = error;
|
|
64
|
-
if (axiosError.response) {
|
|
65
|
-
const errorMessage = axiosError.response.data?.error || String(error);
|
|
66
|
-
console.error("Axios error:", {
|
|
67
|
-
status: axiosError.response.status,
|
|
68
|
-
statusText: axiosError.response.statusText,
|
|
69
|
-
data: axiosError.response.data,
|
|
70
|
-
message: errorMessage
|
|
71
|
-
});
|
|
72
|
-
throw new Error(`Request failed: ${errorMessage}`);
|
|
73
|
-
}
|
|
74
|
-
console.error("Unexpected error:", error);
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
async createSession(showInConsole = true, proxies = true, workflowName, sessionData) {
|
|
79
|
-
const data = {
|
|
80
|
-
proxies,
|
|
81
|
-
workflow_name: workflowName
|
|
82
|
-
};
|
|
83
|
-
if (this.sessionId) {
|
|
84
|
-
throw new Error("A session is already active. Please close the current session before creating a new one.");
|
|
85
|
-
}
|
|
86
|
-
if (sessionData) {
|
|
87
|
-
if (typeof sessionData === "string") {
|
|
88
|
-
try {
|
|
89
|
-
data.session_data = JSON.stringify(JSON.parse(sessionData));
|
|
90
|
-
} catch {
|
|
91
|
-
throw new Error("File system operations are not supported in this environment");
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
data.session_data = JSON.stringify(sessionData);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const response = await this.makeRequest("post", "/create_session", data);
|
|
98
|
-
if (!response.session_id) {
|
|
99
|
-
throw new Error("Session creation failed: No session ID returned");
|
|
100
|
-
}
|
|
101
|
-
this.sessionId = response.session_id;
|
|
102
|
-
this.connectUrl = response.connect_url || null;
|
|
103
|
-
if (showInConsole && response.livestream_url) {
|
|
104
|
-
console.log(`Livestream URL: ${response.livestream_url}`);
|
|
105
|
-
}
|
|
106
|
-
return [response.session_id, response.livestream_url || ""];
|
|
107
|
-
}
|
|
108
|
-
async goto(url, cdpUrl) {
|
|
109
|
-
if (!cdpUrl && !this.sessionId) {
|
|
110
|
-
throw new Error(`Must call createSession before calling goto with url='${url}'`);
|
|
111
|
-
}
|
|
112
|
-
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
|
113
|
-
url = "https://" + url;
|
|
114
|
-
}
|
|
115
|
-
const data = {
|
|
116
|
-
url,
|
|
117
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
118
|
-
};
|
|
119
|
-
await this.makeRequest("post", "/goto", data);
|
|
120
|
-
}
|
|
121
|
-
async click(elementDescription, cdpUrl) {
|
|
122
|
-
if (!cdpUrl && !this.sessionId) {
|
|
123
|
-
throw new Error(`Must call createSession before calling click with elementDescription='${elementDescription}'`);
|
|
124
|
-
}
|
|
125
|
-
const data = {
|
|
126
|
-
element_description: elementDescription,
|
|
127
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
128
|
-
};
|
|
129
|
-
const response = await this.makeRequest("post", "/click", data);
|
|
130
|
-
return response.element_clicked || "";
|
|
131
|
-
}
|
|
132
|
-
async hover(elementDescription, cdpUrl) {
|
|
133
|
-
if (!cdpUrl && !this.sessionId) {
|
|
134
|
-
throw new Error(`Must call createSession before calling click with elementDescription='${elementDescription}'`);
|
|
135
|
-
}
|
|
136
|
-
const data = {
|
|
137
|
-
element_description: elementDescription,
|
|
138
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
139
|
-
};
|
|
140
|
-
await this.makeRequest("post", "/hover", data);
|
|
141
|
-
}
|
|
142
|
-
async scrollToElement(elementDescription, cdpUrl) {
|
|
143
|
-
if (!cdpUrl && !this.sessionId) {
|
|
144
|
-
throw new Error(`Must call createSession before calling click with elementDescription='${elementDescription}'`);
|
|
145
|
-
}
|
|
146
|
-
const data = {
|
|
147
|
-
element_description: elementDescription,
|
|
148
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
149
|
-
};
|
|
150
|
-
await this.makeRequest("post", "/scroll_to_element", data);
|
|
151
|
-
}
|
|
152
|
-
async getNetworkResponse(url, cdpUrl) {
|
|
153
|
-
if (!cdpUrl && !this.sessionId) {
|
|
154
|
-
throw new Error(`Must call createSession before calling getNetworkResponse with url='${url}'`);
|
|
155
|
-
}
|
|
156
|
-
const data = {
|
|
157
|
-
url,
|
|
158
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
159
|
-
};
|
|
160
|
-
const response = await this.makeRequest("post", "/get_network_response", data);
|
|
161
|
-
return response.response || "";
|
|
162
|
-
}
|
|
163
|
-
async type(text, cdpUrl) {
|
|
164
|
-
if (!cdpUrl && !this.sessionId) {
|
|
165
|
-
throw new Error(`Must call createSession before calling type with text='${text}'`);
|
|
166
|
-
}
|
|
167
|
-
const data = {
|
|
168
|
-
text,
|
|
169
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
170
|
-
};
|
|
171
|
-
await this.makeRequest("post", "/type", data);
|
|
172
|
-
}
|
|
173
|
-
async pressEnter(cdpUrl) {
|
|
174
|
-
if (!cdpUrl && !this.sessionId) {
|
|
175
|
-
throw new Error("Must call createSession before calling pressEnter");
|
|
176
|
-
}
|
|
177
|
-
const data = cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId };
|
|
178
|
-
await this.makeRequest("post", "/press_enter", data);
|
|
179
|
-
}
|
|
180
|
-
async pressTab(cdpUrl) {
|
|
181
|
-
if (!cdpUrl && !this.sessionId) {
|
|
182
|
-
throw new Error("Must call createSession before calling pressTab");
|
|
183
|
-
}
|
|
184
|
-
const data = cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId };
|
|
185
|
-
await this.makeRequest("post", "/press_tab", data);
|
|
186
|
-
}
|
|
187
|
-
async deleteText(cdpUrl) {
|
|
188
|
-
if (!cdpUrl && !this.sessionId) {
|
|
189
|
-
throw new Error("Must call createSession before calling deleteText");
|
|
190
|
-
}
|
|
191
|
-
const data = cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId };
|
|
192
|
-
await this.makeRequest("post", "/delete_text", data);
|
|
193
|
-
}
|
|
194
|
-
async extractBbox(elementDescription, cdpUrl) {
|
|
195
|
-
if (!cdpUrl && !this.sessionId) {
|
|
196
|
-
throw new Error(`Must call createSession before calling extractBbox with elementDescription='${elementDescription}'`);
|
|
197
|
-
}
|
|
198
|
-
const params = {
|
|
199
|
-
element_description: elementDescription,
|
|
200
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
201
|
-
};
|
|
202
|
-
const response = await this.makeRequest("get", "/extract-bbox", void 0, params);
|
|
203
|
-
return response.bbox;
|
|
204
|
-
}
|
|
205
|
-
async extractText(elementDescription, cdpUrl) {
|
|
206
|
-
if (!cdpUrl && !this.sessionId) {
|
|
207
|
-
throw new Error(`Must call createSession before calling extractText with elementDescription='${elementDescription}'`);
|
|
208
|
-
}
|
|
209
|
-
const data = {
|
|
210
|
-
element_description: elementDescription,
|
|
211
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
212
|
-
};
|
|
213
|
-
const response = await this.makeRequest("post", "/extract-text", data);
|
|
214
|
-
return response.text || "";
|
|
215
|
-
}
|
|
216
|
-
async scroll(pixels, cdpUrl) {
|
|
217
|
-
if (!cdpUrl && !this.sessionId) {
|
|
218
|
-
throw new Error(`Must call createSession before calling scroll with pixels=${pixels}`);
|
|
219
|
-
}
|
|
220
|
-
const data = {
|
|
221
|
-
pixels,
|
|
222
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
223
|
-
};
|
|
224
|
-
await this.makeRequest("post", "/scroll", data);
|
|
225
|
-
}
|
|
226
|
-
async wait(milliseconds, cdpUrl) {
|
|
227
|
-
if (!cdpUrl && !this.sessionId) {
|
|
228
|
-
throw new Error(`Must call createSession before calling wait with milliseconds=${milliseconds}`);
|
|
229
|
-
}
|
|
230
|
-
const data = {
|
|
231
|
-
milliseconds,
|
|
232
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
233
|
-
};
|
|
234
|
-
await this.makeRequest("post", "/wait", data);
|
|
235
|
-
}
|
|
236
|
-
async clickAndUpload(elementDescription, filePathOrCallable) {
|
|
237
|
-
if (!this.sessionId) {
|
|
238
|
-
throw new Error(`Must call createSession before calling clickAndUpload with elementDescription='${elementDescription}'`);
|
|
239
|
-
}
|
|
240
|
-
if (typeof filePathOrCallable !== "string" && typeof filePathOrCallable !== "function") {
|
|
241
|
-
throw new TypeError(`filePathOrCallable must be either a string or a callable, not a ${typeof filePathOrCallable}`);
|
|
242
|
-
}
|
|
243
|
-
const formData = new FormData();
|
|
244
|
-
formData.append("element_description", elementDescription);
|
|
245
|
-
formData.append("session_id", this.sessionId);
|
|
246
|
-
if (typeof filePathOrCallable === "string") {
|
|
247
|
-
throw new Error("File system operations are not supported in this environment");
|
|
248
|
-
} else {
|
|
249
|
-
const blob = filePathOrCallable();
|
|
250
|
-
formData.append("file", blob, "file");
|
|
251
|
-
}
|
|
252
|
-
await this.makeRequest("post", "/click_and_upload", formData, void 0);
|
|
253
|
-
}
|
|
254
|
-
async clickAndDownload(elementDescription) {
|
|
255
|
-
if (!this.sessionId) {
|
|
256
|
-
throw new Error(`Must call createSession before calling clickAndDownload with elementDescription='${elementDescription}'`);
|
|
257
|
-
}
|
|
258
|
-
const data = {
|
|
259
|
-
element_description: elementDescription,
|
|
260
|
-
session_id: this.sessionId
|
|
261
|
-
};
|
|
262
|
-
const response = await this.makeRequest("post", "/click_and_download", data);
|
|
263
|
-
return [response.b64 || "", response.filename || ""];
|
|
264
|
-
}
|
|
265
|
-
async exists(elementDescription, cdpUrl) {
|
|
266
|
-
if (!cdpUrl && !this.sessionId) {
|
|
267
|
-
throw new Error(`Must call createSession before calling exists with elementDescription='${elementDescription}'`);
|
|
268
|
-
}
|
|
269
|
-
const data = {
|
|
270
|
-
element_description: elementDescription,
|
|
271
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
272
|
-
};
|
|
273
|
-
const response = await this.makeRequest("post", "/exists", data);
|
|
274
|
-
return [response.exists || false, response.reasoning || ""];
|
|
275
|
-
}
|
|
276
|
-
async getPageURL(cdpUrl) {
|
|
277
|
-
if (!cdpUrl && !this.sessionId) {
|
|
278
|
-
throw new Error(`Must call createSession before calling getPageURL`);
|
|
279
|
-
}
|
|
280
|
-
const data = {
|
|
281
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
282
|
-
};
|
|
283
|
-
const response = await this.makeRequest("post", "/get_page_url", data);
|
|
284
|
-
return response.url || "";
|
|
285
|
-
}
|
|
286
|
-
async captureLoginSession(cdpUrl) {
|
|
287
|
-
if (!cdpUrl && !this.sessionId) {
|
|
288
|
-
throw new Error(`Must call createSession before calling captureLoginSession`);
|
|
289
|
-
}
|
|
290
|
-
const data = {
|
|
291
|
-
...cdpUrl ? { cdp_url: cdpUrl } : { session_id: this.sessionId }
|
|
292
|
-
};
|
|
293
|
-
const response = await this.makeRequest("post", "/capture_login_session", data);
|
|
294
|
-
return response.storage_state || "";
|
|
295
|
-
}
|
|
296
|
-
async closeSession() {
|
|
297
|
-
if (!this.sessionId) {
|
|
298
|
-
return;
|
|
299
|
-
}
|
|
300
|
-
await this.makeRequest("post", "/close_session", { session_id: this.sessionId });
|
|
301
|
-
this.sessionId = null;
|
|
302
|
-
this.connectUrl = null;
|
|
303
|
-
}
|
|
304
|
-
async setDialogSettings(accept) {
|
|
305
|
-
if (!this.sessionId) {
|
|
306
|
-
throw new Error("Must call createSession before calling setDialogSettings");
|
|
307
|
-
}
|
|
308
|
-
const data = {
|
|
309
|
-
accept,
|
|
310
|
-
session_id: this.sessionId
|
|
311
|
-
};
|
|
312
|
-
const response = await this.makeRequest("post", "/set_dialog_settings", data);
|
|
313
|
-
if (!response.succeeded) {
|
|
314
|
-
throw new Error(`Failed to set dialog settings: ${response.error}`);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
async getDialogMessage() {
|
|
318
|
-
if (!this.sessionId) {
|
|
319
|
-
throw new Error("Must call createSession before calling getDialogMessage");
|
|
320
|
-
}
|
|
321
|
-
const data = {
|
|
322
|
-
session_id: this.sessionId
|
|
323
|
-
};
|
|
324
|
-
const response = await this.makeRequest("post", "/get_dialog_message", data);
|
|
325
|
-
return response.message || "";
|
|
326
|
-
}
|
|
327
|
-
async enqueueActions(actions) {
|
|
328
|
-
if (!this.sessionId) {
|
|
329
|
-
throw new Error("Must call createSession before calling enqueueActions");
|
|
330
|
-
}
|
|
331
|
-
const data = {
|
|
332
|
-
actions: JSON.stringify(actions),
|
|
333
|
-
session_id: this.sessionId
|
|
334
|
-
};
|
|
335
|
-
const response = await this.makeRequest("post", "/enqueue_actions", data);
|
|
336
|
-
if (!response.succeeded) {
|
|
337
|
-
throw new Error(`Failed to enqueue actions: ${response.error}`);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
export {
|
|
342
|
-
Simplex,
|
|
343
|
-
greet
|
|
344
|
-
};
|
|
345
|
-
//# sourceMappingURL=index.mjs.map
|