@eko-ai/eko 1.0.1 → 1.0.3
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 +56 -44
- package/dist/core/eko.d.ts +1 -0
- package/dist/core/tool-registry.d.ts +1 -1
- package/dist/extension/content/index.d.ts +12 -4
- package/dist/extension/index.d.ts +0 -2
- package/dist/extension/script/build_dom_tree.d.ts +38 -0
- package/dist/extension/script/build_dom_tree.js +7 -3
- package/dist/extension/tools/browser.d.ts +8 -8
- package/dist/extension/tools/browser_use.d.ts +1 -0
- package/dist/extension/tools/html_script.d.ts +1 -12
- package/dist/extension/tools/index.d.ts +1 -2
- package/dist/extension.cjs.js +171 -346
- package/dist/extension.esm.js +172 -346
- package/dist/extension_content_script.js +105 -76
- package/dist/index.cjs.js +59 -49
- package/dist/index.esm.js +59 -49
- package/dist/models/action.d.ts +3 -2
- package/dist/nodejs/core.d.ts +2 -0
- package/dist/nodejs/index.d.ts +1 -0
- package/dist/nodejs/tools/command_execute.d.ts +12 -0
- package/dist/nodejs/tools/file_read.d.ts +11 -0
- package/dist/nodejs/tools/file_write.d.ts +15 -0
- package/dist/nodejs/tools/index.d.ts +3 -1
- package/dist/nodejs.cjs.js +227 -3
- package/dist/nodejs.esm.js +226 -3
- package/dist/schemas/workflow.schema.d.ts +3 -0
- package/dist/services/llm/claude-provider.d.ts +1 -0
- package/dist/services/llm/openai-provider.d.ts +1 -0
- package/dist/types/action.types.d.ts +2 -0
- package/dist/web/core.d.ts +2 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/script/build_dom_tree.d.ts +10 -0
- package/dist/web/tools/browser.d.ts +20 -0
- package/dist/web/tools/browser_use.d.ts +19 -0
- package/dist/web/tools/element_click.d.ts +12 -0
- package/dist/web/tools/export_file.d.ts +18 -0
- package/dist/web/tools/extract_content.d.ts +17 -0
- package/dist/web/tools/find_element_position.d.ts +12 -0
- package/dist/web/tools/html_script.d.ts +10 -0
- package/dist/web/tools/index.d.ts +7 -1
- package/dist/web/tools/screenshot.d.ts +18 -0
- package/dist/web.cjs.js +9377 -3
- package/dist/web.esm.js +9376 -3
- package/package.json +2 -1
package/dist/nodejs.esm.js
CHANGED
|
@@ -1,5 +1,228 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createInterface } from 'readline';
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
import { readFile, access, appendFile, writeFile } from 'fs/promises';
|
|
5
|
+
import { resolve } from 'path';
|
|
6
|
+
import { constants } from 'fs';
|
|
7
|
+
|
|
8
|
+
const execAsync = promisify(exec);
|
|
9
|
+
class CommandExecute {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.name = 'command_execute';
|
|
12
|
+
this.description = 'Execute a shell command with user confirmation';
|
|
13
|
+
this.input_schema = {
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
command: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'The command to execute. Ensure that the command is non-interactive and does not require user input.'
|
|
19
|
+
},
|
|
20
|
+
cwd: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Working directory for command execution'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
required: ['command']
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async getUserConfirmation(command) {
|
|
29
|
+
const rl = createInterface({
|
|
30
|
+
input: process.stdin,
|
|
31
|
+
output: process.stdout
|
|
32
|
+
});
|
|
33
|
+
return new Promise(resolve => {
|
|
34
|
+
rl.question(`Are you sure you want to execute command: "${command}"? (y/N) `, answer => {
|
|
35
|
+
rl.close();
|
|
36
|
+
resolve(answer.toLowerCase() === 'y');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async execute(context, params) {
|
|
41
|
+
const confirmed = await this.getUserConfirmation(params.command);
|
|
42
|
+
if (!confirmed) {
|
|
43
|
+
return {
|
|
44
|
+
executed: false,
|
|
45
|
+
reason: 'User cancelled execution'
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const { stdout, stderr } = await execAsync(params.command, {
|
|
50
|
+
cwd: params.cwd
|
|
51
|
+
});
|
|
52
|
+
return {
|
|
53
|
+
executed: true,
|
|
54
|
+
stdout,
|
|
55
|
+
stderr
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
const err = error;
|
|
60
|
+
return {
|
|
61
|
+
executed: false,
|
|
62
|
+
error: err.message,
|
|
63
|
+
code: err.code,
|
|
64
|
+
stderr: err.stderr
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
class FileRead {
|
|
71
|
+
constructor() {
|
|
72
|
+
this.name = 'file_read';
|
|
73
|
+
this.description = 'Read content from a file';
|
|
74
|
+
this.input_schema = {
|
|
75
|
+
type: 'object',
|
|
76
|
+
properties: {
|
|
77
|
+
path: {
|
|
78
|
+
type: 'string',
|
|
79
|
+
description: 'Path to the file to read'
|
|
80
|
+
},
|
|
81
|
+
encoding: {
|
|
82
|
+
type: 'string',
|
|
83
|
+
description: 'File encoding (default: utf8)',
|
|
84
|
+
enum: ['utf8', 'ascii', 'utf16le', 'base64', 'binary']
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
required: ['path']
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async execute(context, params) {
|
|
91
|
+
try {
|
|
92
|
+
const fullPath = resolve(params.path);
|
|
93
|
+
const content = await readFile(fullPath, {
|
|
94
|
+
encoding: params.encoding || 'utf8'
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
success: true,
|
|
98
|
+
path: fullPath,
|
|
99
|
+
content
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
const err = error;
|
|
104
|
+
return {
|
|
105
|
+
success: false,
|
|
106
|
+
error: err.message,
|
|
107
|
+
code: err.code
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
class FileWrite {
|
|
114
|
+
constructor() {
|
|
115
|
+
this.name = 'file_write';
|
|
116
|
+
this.description = 'Write content to a file with user confirmation';
|
|
117
|
+
this.input_schema = {
|
|
118
|
+
type: 'object',
|
|
119
|
+
properties: {
|
|
120
|
+
path: {
|
|
121
|
+
type: 'string',
|
|
122
|
+
description: 'Path to write the file'
|
|
123
|
+
},
|
|
124
|
+
content: {
|
|
125
|
+
type: 'string',
|
|
126
|
+
description: 'Content to write to the file'
|
|
127
|
+
},
|
|
128
|
+
append: {
|
|
129
|
+
type: 'boolean',
|
|
130
|
+
description: 'Whether to append to existing file (default: false)'
|
|
131
|
+
},
|
|
132
|
+
encoding: {
|
|
133
|
+
type: 'string',
|
|
134
|
+
description: 'File encoding (default: utf8)',
|
|
135
|
+
enum: ['utf8', 'ascii', 'utf16le', 'base64', 'binary']
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
required: ['path', 'content']
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async checkFileExists(path) {
|
|
142
|
+
try {
|
|
143
|
+
await access(path, constants.F_OK);
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
catch (_a) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
async getUserConfirmation(path, exists, append) {
|
|
151
|
+
const rl = createInterface({
|
|
152
|
+
input: process.stdin,
|
|
153
|
+
output: process.stdout
|
|
154
|
+
});
|
|
155
|
+
const action = exists
|
|
156
|
+
? (append ? 'append to' : 'overwrite')
|
|
157
|
+
: 'create';
|
|
158
|
+
return new Promise(resolve => {
|
|
159
|
+
rl.question(`Are you sure you want to ${action} file at "${path}"? (y/N) `, answer => {
|
|
160
|
+
rl.close();
|
|
161
|
+
resolve(answer.toLowerCase() === 'y');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
async execute(context, params) {
|
|
166
|
+
try {
|
|
167
|
+
const fullPath = resolve(params.path);
|
|
168
|
+
const exists = await this.checkFileExists(fullPath);
|
|
169
|
+
const append = params.append || false;
|
|
170
|
+
const confirmed = await this.getUserConfirmation(fullPath, exists, append);
|
|
171
|
+
if (!confirmed) {
|
|
172
|
+
return {
|
|
173
|
+
success: false,
|
|
174
|
+
reason: 'User cancelled operation'
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (append) {
|
|
178
|
+
await appendFile(fullPath, params.content, {
|
|
179
|
+
encoding: params.encoding || 'utf8'
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
await writeFile(fullPath, params.content, {
|
|
184
|
+
encoding: params.encoding || 'utf8'
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
success: true,
|
|
189
|
+
path: fullPath,
|
|
190
|
+
action: append ? 'append' : 'write'
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
const err = error;
|
|
195
|
+
return {
|
|
196
|
+
success: false,
|
|
197
|
+
error: err.message,
|
|
198
|
+
code: err.code
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var tools = /*#__PURE__*/Object.freeze({
|
|
205
|
+
__proto__: null,
|
|
206
|
+
CommandExecute: CommandExecute,
|
|
207
|
+
FileRead: FileRead,
|
|
208
|
+
FileWrite: FileWrite
|
|
3
209
|
});
|
|
4
210
|
|
|
5
|
-
|
|
211
|
+
function getAllTools() {
|
|
212
|
+
let toolsMap = new Map();
|
|
213
|
+
for (const key in tools) {
|
|
214
|
+
let tool = tools[key];
|
|
215
|
+
if (typeof tool === 'function' && tool.prototype && 'execute' in tool.prototype) {
|
|
216
|
+
try {
|
|
217
|
+
let instance = new tool();
|
|
218
|
+
toolsMap.set(instance.name || key, instance);
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
console.error(`Failed to instantiate ${key}:`, e);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return toolsMap;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export { getAllTools, tools };
|
|
@@ -3,6 +3,7 @@ import { LLMProvider, LLMParameters, LLMResponse, Message, LLMStreamHandler } fr
|
|
|
3
3
|
export declare class ClaudeProvider implements LLMProvider {
|
|
4
4
|
private client;
|
|
5
5
|
private defaultModel;
|
|
6
|
+
constructor(options: ClientOptions, defaultModel?: string);
|
|
6
7
|
constructor(apiKey: string, defaultModel?: string | null, options?: ClientOptions);
|
|
7
8
|
private processResponse;
|
|
8
9
|
generateText(messages: Message[], params: LLMParameters): Promise<LLMResponse>;
|
|
@@ -3,6 +3,7 @@ import { LLMProvider, LLMParameters, LLMResponse, Message, LLMStreamHandler } fr
|
|
|
3
3
|
export declare class OpenaiProvider implements LLMProvider {
|
|
4
4
|
private client;
|
|
5
5
|
private defaultModel;
|
|
6
|
+
constructor(options: ClientOptions, defaultModel?: string);
|
|
6
7
|
constructor(apiKey: string, defaultModel?: string | null, options?: ClientOptions);
|
|
7
8
|
private buildParams;
|
|
8
9
|
generateText(messages: Message[], params: LLMParameters): Promise<LLMResponse>;
|
|
@@ -27,10 +27,12 @@ export interface ExecutionContext {
|
|
|
27
27
|
variables: Map<string, unknown>;
|
|
28
28
|
tools?: Map<string, Tool<any, any>>;
|
|
29
29
|
callback?: WorkflowCallback;
|
|
30
|
+
[key: string]: any;
|
|
30
31
|
}
|
|
31
32
|
export interface Action {
|
|
32
33
|
type: 'prompt' | 'script' | 'hybrid';
|
|
33
34
|
name: string;
|
|
35
|
+
description: string;
|
|
34
36
|
execute: (input: unknown, context: ExecutionContext) => Promise<unknown>;
|
|
35
37
|
tools: Tool<any, any>[];
|
|
36
38
|
}
|
package/dist/web/index.d.ts
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get clickable elements on the page
|
|
3
|
+
*
|
|
4
|
+
* @param {*} doHighlightElements Is highlighted
|
|
5
|
+
* @param {*} includeAttributes [attr_names...]
|
|
6
|
+
* @returns { element_str, selector_map }
|
|
7
|
+
*/
|
|
8
|
+
export function get_clickable_elements(doHighlightElements: any | undefined, includeAttributes: any): string;
|
|
9
|
+
export function get_highlight_element(highlightIndex: any): any;
|
|
10
|
+
export function remove_highlight(): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ScreenshotResult } from '../../types/tools.types';
|
|
2
|
+
export declare function type(text: string, xpath?: string, highlightIndex?: number): boolean;
|
|
3
|
+
export declare function clear_input(xpath?: string, highlightIndex?: number): boolean;
|
|
4
|
+
export declare function left_click(xpath?: string, highlightIndex?: number): boolean;
|
|
5
|
+
export declare function right_click(xpath?: string, highlightIndex?: number): boolean;
|
|
6
|
+
export declare function double_click(xpath?: string, highlightIndex?: number): boolean;
|
|
7
|
+
export declare function screenshot(): Promise<ScreenshotResult>;
|
|
8
|
+
export declare function scroll_to(xpath?: string, highlightIndex?: number): boolean;
|
|
9
|
+
export declare function get_dropdown_options(xpath?: string, highlightIndex?: number): {
|
|
10
|
+
options: Array<{
|
|
11
|
+
index: number;
|
|
12
|
+
text: string;
|
|
13
|
+
value?: string;
|
|
14
|
+
}>;
|
|
15
|
+
id?: string;
|
|
16
|
+
name?: string;
|
|
17
|
+
} | null;
|
|
18
|
+
export declare function select_dropdown_option(text: string, xpath?: string, highlightIndex?: number): any;
|
|
19
|
+
export declare function extractHtmlContent(): string;
|
|
20
|
+
export declare function size(): [number, number];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BrowserUseParam, BrowserUseResult } from '../../types/tools.types';
|
|
2
|
+
import { Tool, InputSchema, ExecutionContext } from '../../types/action.types';
|
|
3
|
+
/**
|
|
4
|
+
* Browser Use for general
|
|
5
|
+
*/
|
|
6
|
+
export declare class BrowserUse implements Tool<BrowserUseParam, BrowserUseResult> {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
input_schema: InputSchema;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* browser
|
|
13
|
+
*
|
|
14
|
+
* @param {*} params { action: 'input_text', index: 1, text: 'string' }
|
|
15
|
+
* @returns > { success: true, image?: { type: 'base64', media_type: 'image/jpeg', data: '/9j...' }, text?: string }
|
|
16
|
+
*/
|
|
17
|
+
execute(context: ExecutionContext, params: BrowserUseParam): Promise<BrowserUseResult>;
|
|
18
|
+
destroy(context: ExecutionContext): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Tool, InputSchema, ExecutionContext } from '../../types/action.types';
|
|
2
|
+
import { TaskPrompt } from '../../types/tools.types';
|
|
3
|
+
/**
|
|
4
|
+
* Element click
|
|
5
|
+
*/
|
|
6
|
+
export declare class ElementClick implements Tool<TaskPrompt, any> {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
input_schema: InputSchema;
|
|
10
|
+
constructor();
|
|
11
|
+
execute(context: ExecutionContext, params: TaskPrompt): Promise<any>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ExportFileParam } from '../../types/tools.types';
|
|
2
|
+
import { Tool, InputSchema, ExecutionContext } from '../../types/action.types';
|
|
3
|
+
/**
|
|
4
|
+
* Export file
|
|
5
|
+
*/
|
|
6
|
+
export declare class ExportFile implements Tool<ExportFileParam, unknown> {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
input_schema: InputSchema;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* export
|
|
13
|
+
*
|
|
14
|
+
* @param {*} params { fileType: 'csv', content: 'field1,field2\ndata1,data2' }
|
|
15
|
+
* @returns > { success: true }
|
|
16
|
+
*/
|
|
17
|
+
execute(context: ExecutionContext, params: ExportFileParam): Promise<unknown>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Tool, InputSchema, ExecutionContext } from '../../types/action.types';
|
|
2
|
+
/**
|
|
3
|
+
* Extract Page Content
|
|
4
|
+
*/
|
|
5
|
+
export declare class ExtractContent implements Tool<any, string> {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
input_schema: InputSchema;
|
|
9
|
+
constructor();
|
|
10
|
+
/**
|
|
11
|
+
* Extract Page Content
|
|
12
|
+
*
|
|
13
|
+
* @param {*} params {}
|
|
14
|
+
* @returns > string
|
|
15
|
+
*/
|
|
16
|
+
execute(context: ExecutionContext, params: any): Promise<string>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Tool, InputSchema, ExecutionContext } from '../../types/action.types';
|
|
2
|
+
import { TaskPrompt, ElementRect } from '../../types/tools.types';
|
|
3
|
+
/**
|
|
4
|
+
* Find Element Position
|
|
5
|
+
*/
|
|
6
|
+
export declare class FindElementPosition implements Tool<TaskPrompt, ElementRect | null> {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
input_schema: InputSchema;
|
|
10
|
+
constructor();
|
|
11
|
+
execute(context: ExecutionContext, params: TaskPrompt): Promise<ElementRect | null>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ElementRect } from '../../types/tools.types';
|
|
2
|
+
export declare function exportFile(filename: string, type: string, content: string): void;
|
|
3
|
+
export declare function xpath(element: any): string;
|
|
4
|
+
export declare function queryWithXpath(xpath: string): any;
|
|
5
|
+
/**
|
|
6
|
+
* Extract the elements related to html operability and wrap them into pseudo-html code.
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractOperableElements(): string;
|
|
9
|
+
export declare function clickOperableElement(id: any): any;
|
|
10
|
+
export declare function getOperableElementRect(id: any): ElementRect | null;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { BrowserUse } from './browser_use';
|
|
2
|
+
import { ElementClick } from './element_click';
|
|
3
|
+
import { ExportFile } from './export_file';
|
|
4
|
+
import { ExtractContent } from './extract_content';
|
|
5
|
+
import { FindElementPosition } from './find_element_position';
|
|
6
|
+
import { Screenshot } from './screenshot';
|
|
7
|
+
export { BrowserUse, ElementClick, ExportFile, ExtractContent, FindElementPosition, Screenshot, };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Tool, InputSchema, ExecutionContext } from '../../types/action.types';
|
|
2
|
+
import { ScreenshotResult } from '../../types/tools.types';
|
|
3
|
+
/**
|
|
4
|
+
* Current Page Screenshot
|
|
5
|
+
*/
|
|
6
|
+
export declare class Screenshot implements Tool<any, ScreenshotResult> {
|
|
7
|
+
name: string;
|
|
8
|
+
description: string;
|
|
9
|
+
input_schema: InputSchema;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* Current Page Screenshot
|
|
13
|
+
*
|
|
14
|
+
* @param {*} params {}
|
|
15
|
+
* @returns > { image: { type: 'base64', media_type: 'image/png', data } }
|
|
16
|
+
*/
|
|
17
|
+
execute(context: ExecutionContext, params: unknown): Promise<ScreenshotResult>;
|
|
18
|
+
}
|