@eko-ai/eko 1.3.5 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/README.md +37 -19
  2. package/dist/agent/a2a.d.ts +7 -0
  3. package/dist/agent/a2a.d.ts.map +1 -0
  4. package/dist/agent/base.d.ts +47 -0
  5. package/dist/agent/base.d.ts.map +1 -0
  6. package/dist/agent/browser/browser_base.d.ts +30 -0
  7. package/dist/agent/browser/browser_base.d.ts.map +1 -0
  8. package/dist/agent/browser/browser_labels.d.ts +21 -0
  9. package/dist/agent/browser/browser_labels.d.ts.map +1 -0
  10. package/dist/agent/browser/browser_screen.d.ts +16 -0
  11. package/dist/agent/browser/browser_screen.d.ts.map +1 -0
  12. package/dist/agent/browser/build_dom_tree.d.ts +2 -0
  13. package/dist/agent/browser/build_dom_tree.d.ts.map +1 -0
  14. package/dist/agent/browser/index.d.ts +6 -0
  15. package/dist/agent/browser/index.d.ts.map +1 -0
  16. package/dist/agent/chat.d.ts +7 -0
  17. package/dist/agent/chat.d.ts.map +1 -0
  18. package/dist/agent/computer.d.ts +23 -0
  19. package/dist/agent/computer.d.ts.map +1 -0
  20. package/dist/agent/file.d.ts +14 -0
  21. package/dist/agent/file.d.ts.map +1 -0
  22. package/dist/agent/index.d.ts +9 -0
  23. package/dist/agent/index.d.ts.map +1 -0
  24. package/dist/agent/shell.d.ts +14 -0
  25. package/dist/agent/shell.d.ts.map +1 -0
  26. package/dist/agent/timer.d.ts +5 -0
  27. package/dist/agent/timer.d.ts.map +1 -0
  28. package/dist/common/log.d.ts +43 -2
  29. package/dist/common/log.d.ts.map +1 -0
  30. package/dist/common/utils.d.ts +12 -0
  31. package/dist/common/utils.d.ts.map +1 -0
  32. package/dist/common/xml.d.ts +7 -0
  33. package/dist/common/xml.d.ts.map +1 -0
  34. package/dist/config/index.d.ts +8 -0
  35. package/dist/config/index.d.ts.map +1 -0
  36. package/dist/core/chain.d.ts +45 -0
  37. package/dist/core/chain.d.ts.map +1 -0
  38. package/dist/core/context.d.ts +23 -0
  39. package/dist/core/context.d.ts.map +1 -0
  40. package/dist/core/index.d.ts +18 -0
  41. package/dist/core/index.d.ts.map +1 -0
  42. package/dist/core/plan.d.ts +11 -0
  43. package/dist/core/plan.d.ts.map +1 -0
  44. package/dist/index.cjs.js +18163 -10856
  45. package/dist/index.d.ts +13 -10
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.esm.js +18147 -10888
  48. package/dist/llm/index.d.ts +15 -0
  49. package/dist/llm/index.d.ts.map +1 -0
  50. package/dist/mcp/client.d.ts +28 -0
  51. package/dist/mcp/client.d.ts.map +1 -0
  52. package/dist/mcp/index.d.ts +28 -0
  53. package/dist/mcp/index.d.ts.map +1 -0
  54. package/dist/prompt/agent.d.ts +6 -0
  55. package/dist/prompt/agent.d.ts.map +1 -0
  56. package/dist/prompt/plan.d.ts +4 -0
  57. package/dist/prompt/plan.d.ts.map +1 -0
  58. package/dist/tools/foreach_task.d.ts +12 -0
  59. package/dist/tools/foreach_task.d.ts.map +1 -0
  60. package/dist/tools/human_interact.d.ts +12 -0
  61. package/dist/tools/human_interact.d.ts.map +1 -0
  62. package/dist/tools/index.d.ts +19 -0
  63. package/dist/tools/index.d.ts.map +1 -0
  64. package/dist/tools/task_node_status.d.ts +12 -0
  65. package/dist/tools/task_node_status.d.ts.map +1 -0
  66. package/dist/tools/variable_storage.d.ts +12 -0
  67. package/dist/tools/variable_storage.d.ts.map +1 -0
  68. package/dist/tools/watch_trigger.d.ts +12 -0
  69. package/dist/tools/watch_trigger.d.ts.map +1 -0
  70. package/dist/tools/wrapper.d.ts +12 -0
  71. package/dist/tools/wrapper.d.ts.map +1 -0
  72. package/dist/types/core.types.d.ts +114 -0
  73. package/dist/types/core.types.d.ts.map +1 -0
  74. package/dist/types/index.d.ts +3 -3
  75. package/dist/types/index.d.ts.map +1 -0
  76. package/dist/types/llm.types.d.ts +80 -51
  77. package/dist/types/llm.types.d.ts.map +1 -0
  78. package/dist/types/mcp.types.d.ts +35 -0
  79. package/dist/types/mcp.types.d.ts.map +1 -0
  80. package/dist/types/tools.types.d.ts +56 -152
  81. package/dist/types/tools.types.d.ts.map +1 -0
  82. package/package.json +18 -58
  83. package/dist/common/chrome/proxy.d.ts +0 -24
  84. package/dist/common/context-compressor.d.ts +0 -10
  85. package/dist/common/summarize-workflow.d.ts +0 -2
  86. package/dist/common/tools/cancel_workflow.d.ts +0 -9
  87. package/dist/common/tools/document_agent.d.ts +0 -8
  88. package/dist/common/tools/human.d.ts +0 -30
  89. package/dist/common/tools/index.d.ts +0 -4
  90. package/dist/common/tools/write_context.d.ts +0 -7
  91. package/dist/core/eko.d.ts +0 -30
  92. package/dist/core/tool-registry.d.ts +0 -13
  93. package/dist/extension/content/index.d.ts +0 -1
  94. package/dist/extension/core.d.ts +0 -11
  95. package/dist/extension/index.d.ts +0 -7
  96. package/dist/extension/script/bing.js +0 -25
  97. package/dist/extension/script/build_dom_tree.d.ts +0 -38
  98. package/dist/extension/script/build_dom_tree.js +0 -662
  99. package/dist/extension/script/common.js +0 -212
  100. package/dist/extension/script/duckduckgo.js +0 -25
  101. package/dist/extension/script/google.js +0 -26
  102. package/dist/extension/tools/browser.d.ts +0 -23
  103. package/dist/extension/tools/browser_action.d.ts +0 -20
  104. package/dist/extension/tools/export_file.d.ts +0 -18
  105. package/dist/extension/tools/extract_content.d.ts +0 -18
  106. package/dist/extension/tools/get_all_tabs.d.ts +0 -9
  107. package/dist/extension/tools/html_script.d.ts +0 -10
  108. package/dist/extension/tools/index.d.ts +0 -12
  109. package/dist/extension/tools/open_url.d.ts +0 -19
  110. package/dist/extension/tools/request_login.d.ts +0 -10
  111. package/dist/extension/tools/screenshot.d.ts +0 -18
  112. package/dist/extension/tools/switch_tab.d.ts +0 -8
  113. package/dist/extension/tools/tab_management.d.ts +0 -13
  114. package/dist/extension/tools/tool_returns_screenshot.d.ts +0 -8
  115. package/dist/extension/tools/web_search.d.ts +0 -18
  116. package/dist/extension/utils.d.ts +0 -31
  117. package/dist/extension.cjs.js +0 -2796
  118. package/dist/extension.esm.js +0 -2789
  119. package/dist/extension_content_script.js +0 -1078
  120. package/dist/fellou/computer.d.ts +0 -20
  121. package/dist/fellou/index.d.ts +0 -6
  122. package/dist/fellou/tools/computer_use.d.ts +0 -18
  123. package/dist/fellou.cjs.js +0 -238
  124. package/dist/fellou.esm.js +0 -235
  125. package/dist/models/action.d.ts +0 -33
  126. package/dist/models/workflow.d.ts +0 -25
  127. package/dist/nodejs/core.d.ts +0 -2
  128. package/dist/nodejs/index.d.ts +0 -3
  129. package/dist/nodejs/script/build_dom_tree.d.ts +0 -1
  130. package/dist/nodejs/tools/browser_use.d.ts +0 -28
  131. package/dist/nodejs/tools/command_execute.d.ts +0 -12
  132. package/dist/nodejs/tools/file_read.d.ts +0 -11
  133. package/dist/nodejs/tools/file_write.d.ts +0 -15
  134. package/dist/nodejs/tools/index.d.ts +0 -5
  135. package/dist/nodejs.cjs.js +0 -73507
  136. package/dist/nodejs.esm.js +0 -73504
  137. package/dist/schemas/workflow.schema.d.ts +0 -44
  138. package/dist/services/llm/claude-provider.d.ts +0 -12
  139. package/dist/services/llm/openai-provider.d.ts +0 -12
  140. package/dist/services/llm/provider-factory.d.ts +0 -4
  141. package/dist/services/parser/workflow-parser.d.ts +0 -23
  142. package/dist/services/workflow/generator.d.ts +0 -16
  143. package/dist/services/workflow/templates.d.ts +0 -8
  144. package/dist/types/action.types.d.ts +0 -53
  145. package/dist/types/eko.types.d.ts +0 -37
  146. package/dist/types/parser.types.d.ts +0 -9
  147. package/dist/types/workflow.types.d.ts +0 -57
  148. package/dist/utils/execution-logger.d.ts +0 -69
  149. package/dist/utils/sleep.d.ts +0 -1
  150. package/dist/web/core.d.ts +0 -2
  151. package/dist/web/index.d.ts +0 -5
  152. package/dist/web/script/build_dom_tree.d.ts +0 -10
  153. package/dist/web/tools/browser.d.ts +0 -21
  154. package/dist/web/tools/browser_use.d.ts +0 -19
  155. package/dist/web/tools/export_file.d.ts +0 -18
  156. package/dist/web/tools/extract_content.d.ts +0 -17
  157. package/dist/web/tools/html_script.d.ts +0 -10
  158. package/dist/web/tools/index.d.ts +0 -6
  159. package/dist/web/tools/screenshot.d.ts +0 -18
  160. package/dist/web.cjs.js +0 -9952
  161. package/dist/web.esm.js +0 -9948
@@ -1,1078 +0,0 @@
1
- import { hostname } from 'os';
2
- import { normalize } from 'path';
3
- import { types, formatWithOptions } from 'util';
4
-
5
- const prettyLogStyles = {
6
- reset: [0, 0],
7
- bold: [1, 22],
8
- dim: [2, 22],
9
- italic: [3, 23],
10
- underline: [4, 24],
11
- overline: [53, 55],
12
- inverse: [7, 27],
13
- hidden: [8, 28],
14
- strikethrough: [9, 29],
15
- black: [30, 39],
16
- red: [31, 39],
17
- green: [32, 39],
18
- yellow: [33, 39],
19
- blue: [34, 39],
20
- magenta: [35, 39],
21
- cyan: [36, 39],
22
- white: [37, 39],
23
- blackBright: [90, 39],
24
- redBright: [91, 39],
25
- greenBright: [92, 39],
26
- yellowBright: [93, 39],
27
- blueBright: [94, 39],
28
- magentaBright: [95, 39],
29
- cyanBright: [96, 39],
30
- whiteBright: [97, 39],
31
- bgBlack: [40, 49],
32
- bgRed: [41, 49],
33
- bgGreen: [42, 49],
34
- bgYellow: [43, 49],
35
- bgBlue: [44, 49],
36
- bgMagenta: [45, 49],
37
- bgCyan: [46, 49],
38
- bgWhite: [47, 49],
39
- bgBlackBright: [100, 49],
40
- bgRedBright: [101, 49],
41
- bgGreenBright: [102, 49],
42
- bgYellowBright: [103, 49],
43
- bgBlueBright: [104, 49],
44
- bgMagentaBright: [105, 49],
45
- bgCyanBright: [106, 49],
46
- bgWhiteBright: [107, 49],
47
- };
48
-
49
- function formatTemplate(settings, template, values, hideUnsetPlaceholder = false) {
50
- const templateString = String(template);
51
- const ansiColorWrap = (placeholderValue, code) => `\u001b[${code[0]}m${placeholderValue}\u001b[${code[1]}m`;
52
- const styleWrap = (value, style) => {
53
- if (style != null && typeof style === "string") {
54
- return ansiColorWrap(value, prettyLogStyles[style]);
55
- }
56
- else if (style != null && Array.isArray(style)) {
57
- return style.reduce((prevValue, thisStyle) => styleWrap(prevValue, thisStyle), value);
58
- }
59
- else {
60
- if (style != null && style[value.trim()] != null) {
61
- return styleWrap(value, style[value.trim()]);
62
- }
63
- else if (style != null && style["*"] != null) {
64
- return styleWrap(value, style["*"]);
65
- }
66
- else {
67
- return value;
68
- }
69
- }
70
- };
71
- const defaultStyle = null;
72
- return templateString.replace(/{{(.+?)}}/g, (_, placeholder) => {
73
- const value = values[placeholder] != null ? String(values[placeholder]) : hideUnsetPlaceholder ? "" : _;
74
- return settings.stylePrettyLogs
75
- ? styleWrap(value, settings?.prettyLogStyles?.[placeholder] ?? defaultStyle) + ansiColorWrap("", prettyLogStyles.reset)
76
- : value;
77
- });
78
- }
79
-
80
- function formatNumberAddZeros(value, digits = 2, addNumber = 0) {
81
- if (value != null && isNaN(value)) {
82
- return "";
83
- }
84
- value = value != null ? value + addNumber : value;
85
- return digits === 2
86
- ? value == null
87
- ? "--"
88
- : value < 10
89
- ? "0" + value
90
- : value.toString()
91
- : value == null
92
- ? "---"
93
- : value < 10
94
- ? "00" + value
95
- : value < 100
96
- ? "0" + value
97
- : value.toString();
98
- }
99
-
100
- function urlToObject(url) {
101
- return {
102
- href: url.href,
103
- protocol: url.protocol,
104
- username: url.username,
105
- password: url.password,
106
- host: url.host,
107
- hostname: url.hostname,
108
- port: url.port,
109
- pathname: url.pathname,
110
- search: url.search,
111
- searchParams: [...url.searchParams].map(([key, value]) => ({ key, value })),
112
- hash: url.hash,
113
- origin: url.origin,
114
- };
115
- }
116
-
117
- var Runtime = {
118
- getCallerStackFrame,
119
- getErrorTrace,
120
- getMeta,
121
- transportJSON,
122
- transportFormatted: transportFormatted$1,
123
- isBuffer,
124
- isError,
125
- prettyFormatLogObj,
126
- prettyFormatErrorObj,
127
- };
128
- const meta = {
129
- runtime: "Nodejs",
130
- runtimeVersion: process?.version,
131
- hostname: hostname ? hostname() : undefined,
132
- };
133
- function getMeta(logLevelId, logLevelName, stackDepthLevel, hideLogPositionForPerformance, name, parentNames) {
134
- return Object.assign({}, meta, {
135
- name,
136
- parentNames,
137
- date: new Date(),
138
- logLevelId,
139
- logLevelName,
140
- path: !hideLogPositionForPerformance ? getCallerStackFrame(stackDepthLevel) : undefined,
141
- });
142
- }
143
- function getCallerStackFrame(stackDepthLevel, error = Error()) {
144
- return stackLineToStackFrame(error?.stack?.split("\n")?.filter((thisLine) => thisLine.includes(" at "))?.[stackDepthLevel]);
145
- }
146
- function getErrorTrace(error) {
147
- return error?.stack?.split("\n")?.reduce((result, line) => {
148
- if (line.includes(" at ")) {
149
- result.push(stackLineToStackFrame(line));
150
- }
151
- return result;
152
- }, []);
153
- }
154
- function stackLineToStackFrame(line) {
155
- const pathResult = {
156
- fullFilePath: undefined,
157
- fileName: undefined,
158
- fileNameWithLine: undefined,
159
- fileColumn: undefined,
160
- fileLine: undefined,
161
- filePath: undefined,
162
- filePathWithLine: undefined,
163
- method: undefined,
164
- };
165
- if (line != null && line.includes(" at ")) {
166
- line = line.replace(/^\s+at\s+/gm, "");
167
- const errorStackLine = line.split(" (");
168
- const fullFilePath = line?.slice(-1) === ")" ? line?.match(/\(([^)]+)\)/)?.[1] : line;
169
- const pathArray = fullFilePath?.includes(":") ? fullFilePath?.replace("file://", "")?.replace(process.cwd(), "")?.split(":") : undefined;
170
- const fileColumn = pathArray?.pop();
171
- const fileLine = pathArray?.pop();
172
- const filePath = pathArray?.pop();
173
- const filePathWithLine = normalize(`${filePath}:${fileLine}`);
174
- const fileName = filePath?.split("/")?.pop();
175
- const fileNameWithLine = `${fileName}:${fileLine}`;
176
- if (filePath != null && filePath.length > 0) {
177
- pathResult.fullFilePath = fullFilePath;
178
- pathResult.fileName = fileName;
179
- pathResult.fileNameWithLine = fileNameWithLine;
180
- pathResult.fileColumn = fileColumn;
181
- pathResult.fileLine = fileLine;
182
- pathResult.filePath = filePath;
183
- pathResult.filePathWithLine = filePathWithLine;
184
- pathResult.method = errorStackLine?.[1] != null ? errorStackLine?.[0] : undefined;
185
- }
186
- }
187
- return pathResult;
188
- }
189
- function isError(e) {
190
- return types?.isNativeError != null ? types.isNativeError(e) : e instanceof Error;
191
- }
192
- function prettyFormatLogObj(maskedArgs, settings) {
193
- return maskedArgs.reduce((result, arg) => {
194
- isError(arg) ? result.errors.push(prettyFormatErrorObj(arg, settings)) : result.args.push(arg);
195
- return result;
196
- }, { args: [], errors: [] });
197
- }
198
- function prettyFormatErrorObj(error, settings) {
199
- const errorStackStr = getErrorTrace(error).map((stackFrame) => {
200
- return formatTemplate(settings, settings.prettyErrorStackTemplate, { ...stackFrame }, true);
201
- });
202
- const placeholderValuesError = {
203
- errorName: ` ${error.name} `,
204
- errorMessage: Object.getOwnPropertyNames(error)
205
- .reduce((result, key) => {
206
- if (key !== "stack") {
207
- result.push(error[key]);
208
- }
209
- return result;
210
- }, [])
211
- .join(", "),
212
- errorStack: errorStackStr.join("\n"),
213
- };
214
- return formatTemplate(settings, settings.prettyErrorTemplate, placeholderValuesError);
215
- }
216
- function transportFormatted$1(logMetaMarkup, logArgs, logErrors, settings) {
217
- const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
218
- settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
219
- console.log(logMetaMarkup + formatWithOptions(settings.prettyInspectOptions, ...logArgs) + logErrorsStr);
220
- }
221
- function transportJSON(json) {
222
- console.log(jsonStringifyRecursive(json));
223
- function jsonStringifyRecursive(obj) {
224
- const cache = new Set();
225
- return JSON.stringify(obj, (key, value) => {
226
- if (typeof value === "object" && value !== null) {
227
- if (cache.has(value)) {
228
- return "[Circular]";
229
- }
230
- cache.add(value);
231
- }
232
- if (typeof value === "bigint") {
233
- return `${value}`;
234
- }
235
- if (typeof value === "undefined") {
236
- return "[undefined]";
237
- }
238
- return value;
239
- });
240
- }
241
- }
242
- function isBuffer(arg) {
243
- return Buffer.isBuffer(arg);
244
- }
245
-
246
- class BaseLogger {
247
- constructor(settings, logObj, stackDepthLevel = 4) {
248
- this.logObj = logObj;
249
- this.stackDepthLevel = stackDepthLevel;
250
- this.runtime = Runtime;
251
- this.settings = {
252
- type: settings?.type ?? "pretty",
253
- name: settings?.name,
254
- parentNames: settings?.parentNames,
255
- minLevel: settings?.minLevel ?? 0,
256
- argumentsArrayName: settings?.argumentsArrayName,
257
- hideLogPositionForProduction: settings?.hideLogPositionForProduction ?? false,
258
- prettyLogTemplate: settings?.prettyLogTemplate ??
259
- "{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t{{filePathWithLine}}{{nameWithDelimiterPrefix}}\t",
260
- prettyErrorTemplate: settings?.prettyErrorTemplate ?? "\n{{errorName}} {{errorMessage}}\nerror stack:\n{{errorStack}}",
261
- prettyErrorStackTemplate: settings?.prettyErrorStackTemplate ?? " • {{fileName}}\t{{method}}\n\t{{filePathWithLine}}",
262
- prettyErrorParentNamesSeparator: settings?.prettyErrorParentNamesSeparator ?? ":",
263
- prettyErrorLoggerNameDelimiter: settings?.prettyErrorLoggerNameDelimiter ?? "\t",
264
- stylePrettyLogs: settings?.stylePrettyLogs ?? true,
265
- prettyLogTimeZone: settings?.prettyLogTimeZone ?? "UTC",
266
- prettyLogStyles: settings?.prettyLogStyles ?? {
267
- logLevelName: {
268
- "*": ["bold", "black", "bgWhiteBright", "dim"],
269
- SILLY: ["bold", "white"],
270
- TRACE: ["bold", "whiteBright"],
271
- DEBUG: ["bold", "green"],
272
- INFO: ["bold", "blue"],
273
- WARN: ["bold", "yellow"],
274
- ERROR: ["bold", "red"],
275
- FATAL: ["bold", "redBright"],
276
- },
277
- dateIsoStr: "white",
278
- filePathWithLine: "white",
279
- name: ["white", "bold"],
280
- nameWithDelimiterPrefix: ["white", "bold"],
281
- nameWithDelimiterSuffix: ["white", "bold"],
282
- errorName: ["bold", "bgRedBright", "whiteBright"],
283
- fileName: ["yellow"],
284
- fileNameWithLine: "white",
285
- },
286
- prettyInspectOptions: settings?.prettyInspectOptions ?? {
287
- colors: true,
288
- compact: false,
289
- depth: Infinity,
290
- },
291
- metaProperty: settings?.metaProperty ?? "_meta",
292
- maskPlaceholder: settings?.maskPlaceholder ?? "[***]",
293
- maskValuesOfKeys: settings?.maskValuesOfKeys ?? ["password"],
294
- maskValuesOfKeysCaseInsensitive: settings?.maskValuesOfKeysCaseInsensitive ?? false,
295
- maskValuesRegEx: settings?.maskValuesRegEx,
296
- prefix: [...(settings?.prefix ?? [])],
297
- attachedTransports: [...(settings?.attachedTransports ?? [])],
298
- overwrite: {
299
- mask: settings?.overwrite?.mask,
300
- toLogObj: settings?.overwrite?.toLogObj,
301
- addMeta: settings?.overwrite?.addMeta,
302
- addPlaceholders: settings?.overwrite?.addPlaceholders,
303
- formatMeta: settings?.overwrite?.formatMeta,
304
- formatLogObj: settings?.overwrite?.formatLogObj,
305
- transportFormatted: settings?.overwrite?.transportFormatted,
306
- transportJSON: settings?.overwrite?.transportJSON,
307
- },
308
- };
309
- }
310
- log(logLevelId, logLevelName, ...args) {
311
- if (logLevelId < this.settings.minLevel) {
312
- return;
313
- }
314
- const logArgs = [...this.settings.prefix, ...args];
315
- const maskedArgs = this.settings.overwrite?.mask != null
316
- ? this.settings.overwrite?.mask(logArgs)
317
- : this.settings.maskValuesOfKeys != null && this.settings.maskValuesOfKeys.length > 0
318
- ? this._mask(logArgs)
319
- : logArgs;
320
- const thisLogObj = this.logObj != null ? this._recursiveCloneAndExecuteFunctions(this.logObj) : undefined;
321
- const logObj = this.settings.overwrite?.toLogObj != null ? this.settings.overwrite?.toLogObj(maskedArgs, thisLogObj) : this._toLogObj(maskedArgs, thisLogObj);
322
- const logObjWithMeta = this.settings.overwrite?.addMeta != null
323
- ? this.settings.overwrite?.addMeta(logObj, logLevelId, logLevelName)
324
- : this._addMetaToLogObj(logObj, logLevelId, logLevelName);
325
- let logMetaMarkup;
326
- let logArgsAndErrorsMarkup = undefined;
327
- if (this.settings.overwrite?.formatMeta != null) {
328
- logMetaMarkup = this.settings.overwrite?.formatMeta(logObjWithMeta?.[this.settings.metaProperty]);
329
- }
330
- if (this.settings.overwrite?.formatLogObj != null) {
331
- logArgsAndErrorsMarkup = this.settings.overwrite?.formatLogObj(maskedArgs, this.settings);
332
- }
333
- if (this.settings.type === "pretty") {
334
- logMetaMarkup = logMetaMarkup ?? this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
335
- logArgsAndErrorsMarkup = logArgsAndErrorsMarkup ?? this.runtime.prettyFormatLogObj(maskedArgs, this.settings);
336
- }
337
- if (logMetaMarkup != null && logArgsAndErrorsMarkup != null) {
338
- this.settings.overwrite?.transportFormatted != null
339
- ? this.settings.overwrite?.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings)
340
- : this.runtime.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings);
341
- }
342
- else {
343
- this.settings.overwrite?.transportJSON != null
344
- ? this.settings.overwrite?.transportJSON(logObjWithMeta)
345
- : this.settings.type !== "hidden"
346
- ? this.runtime.transportJSON(logObjWithMeta)
347
- : undefined;
348
- }
349
- if (this.settings.attachedTransports != null && this.settings.attachedTransports.length > 0) {
350
- this.settings.attachedTransports.forEach((transportLogger) => {
351
- transportLogger(logObjWithMeta);
352
- });
353
- }
354
- return logObjWithMeta;
355
- }
356
- attachTransport(transportLogger) {
357
- this.settings.attachedTransports.push(transportLogger);
358
- }
359
- getSubLogger(settings, logObj) {
360
- const subLoggerSettings = {
361
- ...this.settings,
362
- ...settings,
363
- parentNames: this.settings?.parentNames != null && this.settings?.name != null
364
- ? [...this.settings.parentNames, this.settings.name]
365
- : this.settings?.name != null
366
- ? [this.settings.name]
367
- : undefined,
368
- prefix: [...this.settings.prefix, ...(settings?.prefix ?? [])],
369
- };
370
- const subLogger = new this.constructor(subLoggerSettings, logObj ?? this.logObj, this.stackDepthLevel);
371
- return subLogger;
372
- }
373
- _mask(args) {
374
- const maskValuesOfKeys = this.settings.maskValuesOfKeysCaseInsensitive !== true ? this.settings.maskValuesOfKeys : this.settings.maskValuesOfKeys.map((key) => key.toLowerCase());
375
- return args?.map((arg) => {
376
- return this._recursiveCloneAndMaskValuesOfKeys(arg, maskValuesOfKeys);
377
- });
378
- }
379
- _recursiveCloneAndMaskValuesOfKeys(source, keys, seen = []) {
380
- if (seen.includes(source)) {
381
- return { ...source };
382
- }
383
- if (typeof source === "object" && source !== null) {
384
- seen.push(source);
385
- }
386
- if (this.runtime.isError(source) || this.runtime.isBuffer(source)) {
387
- return source;
388
- }
389
- else if (source instanceof Map) {
390
- return new Map(source);
391
- }
392
- else if (source instanceof Set) {
393
- return new Set(source);
394
- }
395
- else if (Array.isArray(source)) {
396
- return source.map((item) => this._recursiveCloneAndMaskValuesOfKeys(item, keys, seen));
397
- }
398
- else if (source instanceof Date) {
399
- return new Date(source.getTime());
400
- }
401
- else if (source instanceof URL) {
402
- return urlToObject(source);
403
- }
404
- else if (source !== null && typeof source === "object") {
405
- const baseObject = this.runtime.isError(source) ? this._cloneError(source) : Object.create(Object.getPrototypeOf(source));
406
- return Object.getOwnPropertyNames(source).reduce((o, prop) => {
407
- o[prop] = keys.includes(this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : prop.toLowerCase())
408
- ? this.settings.maskPlaceholder
409
- : (() => {
410
- try {
411
- return this._recursiveCloneAndMaskValuesOfKeys(source[prop], keys, seen);
412
- }
413
- catch (e) {
414
- return null;
415
- }
416
- })();
417
- return o;
418
- }, baseObject);
419
- }
420
- else {
421
- if (typeof source === "string") {
422
- let modifiedSource = source;
423
- for (const regEx of this.settings?.maskValuesRegEx || []) {
424
- modifiedSource = modifiedSource.replace(regEx, this.settings?.maskPlaceholder || "");
425
- }
426
- return modifiedSource;
427
- }
428
- return source;
429
- }
430
- }
431
- _recursiveCloneAndExecuteFunctions(source, seen = []) {
432
- if (this.isObjectOrArray(source) && seen.includes(source)) {
433
- return this.shallowCopy(source);
434
- }
435
- if (this.isObjectOrArray(source)) {
436
- seen.push(source);
437
- }
438
- if (Array.isArray(source)) {
439
- return source.map((item) => this._recursiveCloneAndExecuteFunctions(item, seen));
440
- }
441
- else if (source instanceof Date) {
442
- return new Date(source.getTime());
443
- }
444
- else if (this.isObject(source)) {
445
- return Object.getOwnPropertyNames(source).reduce((o, prop) => {
446
- const descriptor = Object.getOwnPropertyDescriptor(source, prop);
447
- if (descriptor) {
448
- Object.defineProperty(o, prop, descriptor);
449
- const value = source[prop];
450
- o[prop] = typeof value === "function" ? value() : this._recursiveCloneAndExecuteFunctions(value, seen);
451
- }
452
- return o;
453
- }, Object.create(Object.getPrototypeOf(source)));
454
- }
455
- else {
456
- return source;
457
- }
458
- }
459
- isObjectOrArray(value) {
460
- return typeof value === "object" && value !== null;
461
- }
462
- isObject(value) {
463
- return typeof value === "object" && !Array.isArray(value) && value !== null;
464
- }
465
- shallowCopy(source) {
466
- if (Array.isArray(source)) {
467
- return [...source];
468
- }
469
- else {
470
- return { ...source };
471
- }
472
- }
473
- _toLogObj(args, clonedLogObj = {}) {
474
- args = args?.map((arg) => (this.runtime.isError(arg) ? this._toErrorObject(arg) : arg));
475
- if (this.settings.argumentsArrayName == null) {
476
- if (args.length === 1 && !Array.isArray(args[0]) && this.runtime.isBuffer(args[0]) !== true && !(args[0] instanceof Date)) {
477
- clonedLogObj = typeof args[0] === "object" && args[0] != null ? { ...args[0], ...clonedLogObj } : { 0: args[0], ...clonedLogObj };
478
- }
479
- else {
480
- clonedLogObj = { ...clonedLogObj, ...args };
481
- }
482
- }
483
- else {
484
- clonedLogObj = {
485
- ...clonedLogObj,
486
- [this.settings.argumentsArrayName]: args,
487
- };
488
- }
489
- return clonedLogObj;
490
- }
491
- _cloneError(error) {
492
- const cloned = new error.constructor();
493
- Object.getOwnPropertyNames(error).forEach((key) => {
494
- cloned[key] = error[key];
495
- });
496
- return cloned;
497
- }
498
- _toErrorObject(error) {
499
- return {
500
- nativeError: error,
501
- name: error.name ?? "Error",
502
- message: error.message,
503
- stack: this.runtime.getErrorTrace(error),
504
- };
505
- }
506
- _addMetaToLogObj(logObj, logLevelId, logLevelName) {
507
- return {
508
- ...logObj,
509
- [this.settings.metaProperty]: this.runtime.getMeta(logLevelId, logLevelName, this.stackDepthLevel, this.settings.hideLogPositionForProduction, this.settings.name, this.settings.parentNames),
510
- };
511
- }
512
- _prettyFormatLogObjMeta(logObjMeta) {
513
- if (logObjMeta == null) {
514
- return "";
515
- }
516
- let template = this.settings.prettyLogTemplate;
517
- const placeholderValues = {};
518
- if (template.includes("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}")) {
519
- template = template.replace("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}", "{{dateIsoStr}}");
520
- }
521
- else {
522
- if (this.settings.prettyLogTimeZone === "UTC") {
523
- placeholderValues["yyyy"] = logObjMeta?.date?.getUTCFullYear() ?? "----";
524
- placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMonth(), 2, 1);
525
- placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getUTCDate(), 2);
526
- placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getUTCHours(), 2);
527
- placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMinutes(), 2);
528
- placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getUTCSeconds(), 2);
529
- placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMilliseconds(), 3);
530
- }
531
- else {
532
- placeholderValues["yyyy"] = logObjMeta?.date?.getFullYear() ?? "----";
533
- placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getMonth(), 2, 1);
534
- placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getDate(), 2);
535
- placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getHours(), 2);
536
- placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getMinutes(), 2);
537
- placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getSeconds(), 2);
538
- placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getMilliseconds(), 3);
539
- }
540
- }
541
- const dateInSettingsTimeZone = this.settings.prettyLogTimeZone === "UTC" ? logObjMeta?.date : new Date(logObjMeta?.date?.getTime() - logObjMeta?.date?.getTimezoneOffset() * 60000);
542
- placeholderValues["rawIsoStr"] = dateInSettingsTimeZone?.toISOString();
543
- placeholderValues["dateIsoStr"] = dateInSettingsTimeZone?.toISOString().replace("T", " ").replace("Z", "");
544
- placeholderValues["logLevelName"] = logObjMeta?.logLevelName;
545
- placeholderValues["fileNameWithLine"] = logObjMeta?.path?.fileNameWithLine ?? "";
546
- placeholderValues["filePathWithLine"] = logObjMeta?.path?.filePathWithLine ?? "";
547
- placeholderValues["fullFilePath"] = logObjMeta?.path?.fullFilePath ?? "";
548
- let parentNamesString = this.settings.parentNames?.join(this.settings.prettyErrorParentNamesSeparator);
549
- parentNamesString = parentNamesString != null && logObjMeta?.name != null ? parentNamesString + this.settings.prettyErrorParentNamesSeparator : undefined;
550
- placeholderValues["name"] = logObjMeta?.name != null || parentNamesString != null ? (parentNamesString ?? "") + logObjMeta?.name ?? "" : "";
551
- placeholderValues["nameWithDelimiterPrefix"] =
552
- placeholderValues["name"].length > 0 ? this.settings.prettyErrorLoggerNameDelimiter + placeholderValues["name"] : "";
553
- placeholderValues["nameWithDelimiterSuffix"] =
554
- placeholderValues["name"].length > 0 ? placeholderValues["name"] + this.settings.prettyErrorLoggerNameDelimiter : "";
555
- if (this.settings.overwrite?.addPlaceholders != null) {
556
- this.settings.overwrite?.addPlaceholders(logObjMeta, placeholderValues);
557
- }
558
- return formatTemplate(this.settings, template, placeholderValues);
559
- }
560
- }
561
-
562
- class Logger extends BaseLogger {
563
- constructor(settings, logObj) {
564
- const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
565
- const isBrowserBlinkEngine = isBrowser ? window.chrome !== undefined && window.CSS !== undefined && window.CSS.supports("color", "green") : false;
566
- const isSafari = isBrowser ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false;
567
- settings = settings || {};
568
- settings.stylePrettyLogs = settings.stylePrettyLogs && isBrowser && !isBrowserBlinkEngine ? false : settings.stylePrettyLogs;
569
- super(settings, logObj, isSafari ? 4 : 5);
570
- }
571
- log(logLevelId, logLevelName, ...args) {
572
- return super.log(logLevelId, logLevelName, ...args);
573
- }
574
- silly(...args) {
575
- return super.log(0, "SILLY", ...args);
576
- }
577
- trace(...args) {
578
- return super.log(1, "TRACE", ...args);
579
- }
580
- debug(...args) {
581
- return super.log(2, "DEBUG", ...args);
582
- }
583
- info(...args) {
584
- return super.log(3, "INFO", ...args);
585
- }
586
- warn(...args) {
587
- return super.log(4, "WARN", ...args);
588
- }
589
- error(...args) {
590
- return super.log(5, "ERROR", ...args);
591
- }
592
- fatal(...args) {
593
- return super.log(6, "FATAL", ...args);
594
- }
595
- getSubLogger(settings, logObj) {
596
- return super.getSubLogger(settings, logObj);
597
- }
598
- }
599
-
600
- function transportFormatted(logMetaMarkup, logArgs, logErrors, settings) {
601
- settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
602
- const logLevel = logMetaMarkup.trim().split(" ")[2];
603
- let logFunc;
604
- switch (logLevel) {
605
- case "WARN":
606
- logFunc = console.warn;
607
- break;
608
- case "ERROR":
609
- case "FATAL":
610
- logFunc = console.error;
611
- break;
612
- case "INFO":
613
- logFunc = console.info;
614
- break;
615
- case "DEBUG":
616
- case "TRACE":
617
- case "SILLY":
618
- default:
619
- logFunc = console.debug;
620
- break;
621
- }
622
- logFunc(logMetaMarkup, ...logArgs);
623
- logErrors.forEach(err => {
624
- console.error(logMetaMarkup + err);
625
- });
626
- }
627
- function formatMeta(logObjMeta) {
628
- if (!logObjMeta) {
629
- return '';
630
- }
631
- const { date, logLevelName } = logObjMeta;
632
- const year = date.getFullYear();
633
- const month = String(date.getMonth() + 1).padStart(2, '0');
634
- const day = String(date.getDate()).padStart(2, '0');
635
- const hours = String(date.getHours()).padStart(2, '0');
636
- const minutes = String(date.getMinutes()).padStart(2, '0');
637
- const seconds = String(date.getSeconds()).padStart(2, '0');
638
- const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
639
- const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
640
- const loggerName = logObjMeta.name;
641
- return `${formattedDate} ${logLevelName} ${loggerName}`;
642
- }
643
- const logger = new Logger({
644
- name: "ekoLogger",
645
- overwrite: {
646
- transportFormatted,
647
- formatMeta,
648
- }
649
- });
650
-
651
- if (!window.eko) {
652
- window.eko = { lastMouseX: 0, lastMouseY: 0 };
653
- }
654
- eko.sub = function (event, callback) {
655
- if (!eko.subListeners) {
656
- eko.subListeners = {};
657
- }
658
- if (event && callback) {
659
- eko.subListeners[event] = callback;
660
- }
661
- };
662
- document.addEventListener('mousemove', (event) => {
663
- eko.lastMouseX = event.clientX;
664
- eko.lastMouseY = event.clientY;
665
- });
666
- if (typeof chrome !== 'undefined') {
667
- chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
668
- (async () => {
669
- try {
670
- switch (request.type) {
671
- case 'eko:message': {
672
- let result = null;
673
- if (eko.subListeners && eko.subListeners[request.event]) {
674
- try {
675
- result = await eko.subListeners[request.event](request.params);
676
- }
677
- catch (e) {
678
- logger.error(e);
679
- }
680
- }
681
- sendResponse(result);
682
- break;
683
- }
684
- case 'page:getDetailLinks': {
685
- let result = await eko.getDetailLinks(request.search);
686
- sendResponse(result);
687
- break;
688
- }
689
- case 'page:getContent': {
690
- let result = await eko.getContent(request.search);
691
- sendResponse(result);
692
- break;
693
- }
694
- case 'request_user_help': {
695
- request_user_help(request.task_id, request.failure_type, request.failure_message);
696
- sendResponse(true);
697
- break;
698
- }
699
- case 'computer:type': {
700
- sendResponse(type(request));
701
- break;
702
- }
703
- case 'computer:mouse_move': {
704
- sendResponse(mouse_move(request));
705
- break;
706
- }
707
- case 'computer:left_click': {
708
- sendResponse(simulateMouseEvent(request, ['mousedown', 'mouseup', 'click'], 0));
709
- break;
710
- }
711
- case 'computer:right_click': {
712
- sendResponse(simulateMouseEvent(request, ['mousedown', 'mouseup', 'contextmenu'], 2));
713
- break;
714
- }
715
- case 'computer:double_click': {
716
- sendResponse(simulateMouseEvent(request, ['mousedown', 'mouseup', 'click', 'mousedown', 'mouseup', 'click', 'dblclick'], 0));
717
- break;
718
- }
719
- case 'computer:scroll_to': {
720
- sendResponse(scroll_to(request));
721
- break;
722
- }
723
- case 'computer:cursor_position': {
724
- sendResponse({ coordinate: [eko.lastMouseX, eko.lastMouseY] });
725
- break;
726
- }
727
- case 'computer:get_dropdown_options': {
728
- sendResponse(get_dropdown_options(request));
729
- break;
730
- }
731
- case 'computer:select_dropdown_option': {
732
- sendResponse(select_dropdown_option(request));
733
- break;
734
- }
735
- }
736
- }
737
- catch (e) {
738
- logger.error('onMessage error', e);
739
- sendResponse(false);
740
- }
741
- })();
742
- return true;
743
- });
744
- }
745
- function type(request) {
746
- let text = request.text;
747
- let enter = false;
748
- if (text.endsWith('\\n')) {
749
- enter = true;
750
- text = text.substring(0, text.length - 2);
751
- }
752
- else if (text.endsWith('\n')) {
753
- enter = true;
754
- text = text.substring(0, text.length - 1);
755
- }
756
- let element;
757
- if (request.highlightIndex != null) {
758
- element = window.get_highlight_element(request.highlightIndex);
759
- }
760
- else if (request.xpath) {
761
- let xpath = request.xpath;
762
- let result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
763
- element = result.singleNodeValue;
764
- }
765
- else {
766
- let coordinate = request.coordinate;
767
- element = document.elementFromPoint(coordinate[0], coordinate[1]) || document.activeElement;
768
- }
769
- if (!element) {
770
- return false;
771
- }
772
- let input;
773
- if (element.tagName == 'IFRAME') {
774
- let iframeDoc = element.contentDocument || element.contentWindow.document;
775
- input =
776
- iframeDoc.querySelector('textarea') ||
777
- iframeDoc.querySelector('*[contenteditable="true"]') ||
778
- iframeDoc.querySelector('input');
779
- }
780
- else if (element.tagName == 'INPUT' ||
781
- element.tagName == 'TEXTAREA' ||
782
- element.childElementCount == 0) {
783
- input = element;
784
- }
785
- else {
786
- input = element.querySelector('input') || element.querySelector('textarea');
787
- if (!input) {
788
- input = element.querySelector('*[contenteditable="true"]') || element;
789
- if (input.tagName == 'DIV') {
790
- input = input.querySelector('span') || input.querySelector('div') || input;
791
- }
792
- }
793
- }
794
- input.focus && input.focus();
795
- if (!text) {
796
- if (input.value == undefined) {
797
- input.textContent = '';
798
- }
799
- else {
800
- input.value = '';
801
- }
802
- }
803
- else {
804
- if (input.value == undefined) {
805
- input.textContent += text;
806
- }
807
- else {
808
- input.value += text;
809
- }
810
- }
811
- let result = input.dispatchEvent(new Event('input', { bubbles: true }));
812
- if (enter) {
813
- ['keydown', 'keypress', 'keyup'].forEach((eventType) => {
814
- const event = new KeyboardEvent(eventType, {
815
- key: 'Enter',
816
- code: 'Enter',
817
- keyCode: 13,
818
- bubbles: true,
819
- cancelable: true,
820
- });
821
- input.dispatchEvent(event);
822
- });
823
- }
824
- logger.debug('type', input, request, result);
825
- return true;
826
- }
827
- function mouse_move(request) {
828
- let coordinate = request.coordinate;
829
- let x = coordinate[0];
830
- let y = coordinate[1];
831
- const event = new MouseEvent('mousemove', {
832
- view: window,
833
- bubbles: true,
834
- cancelable: true,
835
- screenX: x,
836
- screenY: y,
837
- clientX: x,
838
- clientY: y,
839
- });
840
- let result = document.body.dispatchEvent(event);
841
- logger.debug('mouse_move', document.body, request, result);
842
- return true;
843
- }
844
- function simulateMouseEvent(request, eventTypes, button) {
845
- let element;
846
- if (request.highlightIndex != null) {
847
- element = window.get_highlight_element(request.highlightIndex);
848
- }
849
- else if (request.xpath) {
850
- let xpath = request.xpath;
851
- let result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
852
- element = result.singleNodeValue;
853
- }
854
- else {
855
- let coordinate = request.coordinate;
856
- element = document.elementFromPoint(coordinate[0], coordinate[1]) || document.body;
857
- }
858
- if (!element) {
859
- return false;
860
- }
861
- const x = undefined;
862
- const y = undefined;
863
- for (let i = 0; i < eventTypes.length; i++) {
864
- const event = new MouseEvent(eventTypes[i], {
865
- view: window,
866
- bubbles: true,
867
- cancelable: true,
868
- clientX: x,
869
- clientY: y,
870
- button, // 0 left; 2 right
871
- });
872
- let result = element.dispatchEvent(event);
873
- logger.debug('simulateMouse', element, { ...request, eventTypes, button }, result);
874
- }
875
- return true;
876
- }
877
- function scroll_to(request) {
878
- if (request.highlightIndex != null) {
879
- let element = window.get_highlight_element(request.highlightIndex);
880
- if (!element) {
881
- return false;
882
- }
883
- element.scrollIntoView({
884
- behavior: 'smooth',
885
- });
886
- }
887
- else if (request.xpath) {
888
- let xpath = request.xpath;
889
- let result = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
890
- let element = result.singleNodeValue;
891
- if (!element) {
892
- return false;
893
- }
894
- element.scrollIntoView({
895
- behavior: 'smooth',
896
- });
897
- }
898
- else {
899
- const to_coordinate = request.to_coordinate;
900
- window.scrollTo({
901
- left: to_coordinate[0],
902
- top: to_coordinate[1],
903
- behavior: 'smooth',
904
- });
905
- }
906
- logger.debug('scroll_to', request);
907
- return true;
908
- }
909
- function get_dropdown_options(request) {
910
- let select;
911
- if (request.highlightIndex != null) {
912
- select = window.get_highlight_element(request.highlightIndex);
913
- }
914
- else if (request.xpath) {
915
- select = document.evaluate(request.xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
916
- }
917
- if (!select) {
918
- return null;
919
- }
920
- return {
921
- options: Array.from(select.options).map((opt) => ({
922
- index: opt.index,
923
- text: opt.text.trim(),
924
- value: opt.value,
925
- })),
926
- id: select.id,
927
- name: select.name,
928
- };
929
- }
930
- function select_dropdown_option(request) {
931
- let select;
932
- if (request.highlightIndex != null) {
933
- select = window.get_highlight_element(request.highlightIndex);
934
- }
935
- else if (request.xpath) {
936
- select = document.evaluate(request.xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
937
- }
938
- if (!select || select.tagName.toUpperCase() !== 'SELECT') {
939
- return { success: false, error: 'Select not found or invalid element type' };
940
- }
941
- const option = Array.from(select.options).find((opt) => opt.text.trim() === request.text);
942
- if (!option) {
943
- return {
944
- success: false,
945
- error: 'Option not found',
946
- availableOptions: Array.from(select.options).map((o) => o.text.trim()),
947
- };
948
- }
949
- select.value = option.value;
950
- select.dispatchEvent(new Event('change'));
951
- return {
952
- success: true,
953
- selectedValue: option.value,
954
- selectedText: option.text.trim(),
955
- };
956
- }
957
- function request_user_help(task_id, failure_type, failure_message) {
958
- const domId = 'eko-request-user-help';
959
- if (document.getElementById(domId)) {
960
- return;
961
- }
962
- const failureTitleMap = {
963
- login_required: 'Login Required',
964
- captcha: 'Captcha Detected',
965
- blocked: 'Blocked',
966
- other: 'Error',
967
- rate_limited: 'Rate Limited',
968
- };
969
- const notification = document.createElement('div');
970
- notification.id = domId;
971
- notification.style.cssText = `
972
- position: fixed;
973
- top: 5px;
974
- left: 18px;
975
- z-index: 999999;
976
- background-color: #FEF0ED;
977
- color: white;
978
- padding: 16px;
979
- border-radius: 12px;
980
- border: 1px solid #FBB8A5;
981
- font-family: Arial, sans-serif;
982
- width: 350px;
983
- display: flex;
984
- flex-direction: row;
985
- gap: 10px;
986
- cursor: move;
987
- user-select: none;
988
- `;
989
- let isDragging = false;
990
- let xOffset = 0;
991
- let yOffset = 0;
992
- let initialX = 0;
993
- let initialY = 0;
994
- notification.addEventListener('mousedown', (e) => {
995
- isDragging = true;
996
- initialX = e.clientX - xOffset;
997
- initialY = e.clientY - yOffset;
998
- e.preventDefault();
999
- });
1000
- document.addEventListener('mousemove', (e) => {
1001
- if (!isDragging)
1002
- return;
1003
- const currentX = e.clientX - initialX;
1004
- const currentY = e.clientY - initialY;
1005
- xOffset = currentX;
1006
- yOffset = currentY;
1007
- notification.style.transform = `translate(${xOffset}px, ${yOffset}px)`;
1008
- });
1009
- document.addEventListener('mouseup', () => {
1010
- isDragging = false;
1011
- });
1012
- const leftContainer = document.createElement('div');
1013
- leftContainer.style.cssText = `
1014
- width: 28px;
1015
- height: 28px;
1016
- display: flex;
1017
- flex-direction: column;
1018
- align-items: center;
1019
- border-radius: 99px;
1020
- background: #FDCCCC;
1021
- justify-content: center;
1022
- `;
1023
- leftContainer.innerHTML = ``;
1024
- const rightContainer = document.createElement('div');
1025
- rightContainer.style.cssText = `
1026
- flex: 1;
1027
- display: flex;
1028
- flex-direction: column;
1029
- `;
1030
- const title = document.createElement('div');
1031
- title.style.cssText = `
1032
- font-size: 16px;
1033
- font-weight: 700;
1034
- line-height: 22px;
1035
- color: #DD342D;
1036
- text-align: left;
1037
- `;
1038
- title.innerText = failureTitleMap[failure_type] || failure_type;
1039
- const message2 = document.createElement('div');
1040
- message2.style.cssText = `
1041
- font-size: 16px;
1042
- font-weight: 400;
1043
- line-height: 22px;
1044
- color: #DD342D;
1045
- text-align: left;
1046
- `;
1047
- message2.innerText = failure_message + '\nWhen you resolve the issue, click the button below.';
1048
- const buttonDiv = document.createElement('div');
1049
- buttonDiv.style.cssText = `
1050
- margin-top: 16px;
1051
- display: flex;
1052
- flex-direction: row-reverse;
1053
- justify-content: flex-start;
1054
- align-items: center;
1055
- `;
1056
- const resolvedBut = document.createElement('div');
1057
- resolvedBut.innerText = 'Resolved';
1058
- resolvedBut.style.cssText = `
1059
- border-radius: 8px;
1060
- background: #DD342D;
1061
- color: white;
1062
- padding: 10px;
1063
- border: none;
1064
- cursor: pointer;
1065
- `;
1066
- resolvedBut.onclick = () => {
1067
- chrome.runtime.sendMessage({ type: 'issue_resolved', task_id, failure_type }, () => {
1068
- notification.remove();
1069
- });
1070
- };
1071
- buttonDiv.appendChild(resolvedBut);
1072
- rightContainer.appendChild(title);
1073
- rightContainer.appendChild(message2);
1074
- rightContainer.appendChild(buttonDiv);
1075
- notification.appendChild(leftContainer);
1076
- notification.appendChild(rightContainer);
1077
- document.body.appendChild(notification);
1078
- }