@eko-ai/eko 1.2.0 → 1.2.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.
package/dist/web.cjs.js CHANGED
@@ -1,5 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ var os = require('os');
4
+ var path = require('path');
5
+ var util = require('util');
6
+
3
7
  /**
4
8
  * Get clickable elements on the page
5
9
  *
@@ -8191,7 +8195,7 @@ var loadSerializedSVG = function (svg) {
8191
8195
  });
8192
8196
  };
8193
8197
 
8194
- var Logger = /** @class */ (function () {
8198
+ var Logger$1 = /** @class */ (function () {
8195
8199
  function Logger(_a) {
8196
8200
  var id = _a.id, enabled = _a.enabled;
8197
8201
  this.id = id;
@@ -8275,7 +8279,7 @@ var Context = /** @class */ (function () {
8275
8279
  var _a;
8276
8280
  this.windowBounds = windowBounds;
8277
8281
  this.instanceName = "#" + Context.instanceCount++;
8278
- this.logger = new Logger({ id: this.instanceName, enabled: options.logging });
8282
+ this.logger = new Logger$1({ id: this.instanceName, enabled: options.logging });
8279
8283
  this.cache = (_a = options.cache) !== null && _a !== void 0 ? _a : new Cache(this, options);
8280
8284
  }
8281
8285
  Context.instanceCount = 1;
@@ -8982,6 +8986,630 @@ class Screenshot {
8982
8986
  }
8983
8987
  }
8984
8988
 
8989
+ const prettyLogStyles = {
8990
+ reset: [0, 0],
8991
+ bold: [1, 22],
8992
+ dim: [2, 22],
8993
+ italic: [3, 23],
8994
+ underline: [4, 24],
8995
+ overline: [53, 55],
8996
+ inverse: [7, 27],
8997
+ hidden: [8, 28],
8998
+ strikethrough: [9, 29],
8999
+ black: [30, 39],
9000
+ red: [31, 39],
9001
+ green: [32, 39],
9002
+ yellow: [33, 39],
9003
+ blue: [34, 39],
9004
+ magenta: [35, 39],
9005
+ cyan: [36, 39],
9006
+ white: [37, 39],
9007
+ blackBright: [90, 39],
9008
+ redBright: [91, 39],
9009
+ greenBright: [92, 39],
9010
+ yellowBright: [93, 39],
9011
+ blueBright: [94, 39],
9012
+ magentaBright: [95, 39],
9013
+ cyanBright: [96, 39],
9014
+ whiteBright: [97, 39],
9015
+ bgBlack: [40, 49],
9016
+ bgRed: [41, 49],
9017
+ bgGreen: [42, 49],
9018
+ bgYellow: [43, 49],
9019
+ bgBlue: [44, 49],
9020
+ bgMagenta: [45, 49],
9021
+ bgCyan: [46, 49],
9022
+ bgWhite: [47, 49],
9023
+ bgBlackBright: [100, 49],
9024
+ bgRedBright: [101, 49],
9025
+ bgGreenBright: [102, 49],
9026
+ bgYellowBright: [103, 49],
9027
+ bgBlueBright: [104, 49],
9028
+ bgMagentaBright: [105, 49],
9029
+ bgCyanBright: [106, 49],
9030
+ bgWhiteBright: [107, 49],
9031
+ };
9032
+
9033
+ function formatTemplate(settings, template, values, hideUnsetPlaceholder = false) {
9034
+ const templateString = String(template);
9035
+ const ansiColorWrap = (placeholderValue, code) => `\u001b[${code[0]}m${placeholderValue}\u001b[${code[1]}m`;
9036
+ const styleWrap = (value, style) => {
9037
+ if (style != null && typeof style === "string") {
9038
+ return ansiColorWrap(value, prettyLogStyles[style]);
9039
+ }
9040
+ else if (style != null && Array.isArray(style)) {
9041
+ return style.reduce((prevValue, thisStyle) => styleWrap(prevValue, thisStyle), value);
9042
+ }
9043
+ else {
9044
+ if (style != null && style[value.trim()] != null) {
9045
+ return styleWrap(value, style[value.trim()]);
9046
+ }
9047
+ else if (style != null && style["*"] != null) {
9048
+ return styleWrap(value, style["*"]);
9049
+ }
9050
+ else {
9051
+ return value;
9052
+ }
9053
+ }
9054
+ };
9055
+ const defaultStyle = null;
9056
+ return templateString.replace(/{{(.+?)}}/g, (_, placeholder) => {
9057
+ const value = values[placeholder] != null ? String(values[placeholder]) : hideUnsetPlaceholder ? "" : _;
9058
+ return settings.stylePrettyLogs
9059
+ ? styleWrap(value, settings?.prettyLogStyles?.[placeholder] ?? defaultStyle) + ansiColorWrap("", prettyLogStyles.reset)
9060
+ : value;
9061
+ });
9062
+ }
9063
+
9064
+ function formatNumberAddZeros(value, digits = 2, addNumber = 0) {
9065
+ if (value != null && isNaN(value)) {
9066
+ return "";
9067
+ }
9068
+ value = value != null ? value + addNumber : value;
9069
+ return digits === 2
9070
+ ? value == null
9071
+ ? "--"
9072
+ : value < 10
9073
+ ? "0" + value
9074
+ : value.toString()
9075
+ : value == null
9076
+ ? "---"
9077
+ : value < 10
9078
+ ? "00" + value
9079
+ : value < 100
9080
+ ? "0" + value
9081
+ : value.toString();
9082
+ }
9083
+
9084
+ function urlToObject(url) {
9085
+ return {
9086
+ href: url.href,
9087
+ protocol: url.protocol,
9088
+ username: url.username,
9089
+ password: url.password,
9090
+ host: url.host,
9091
+ hostname: url.hostname,
9092
+ port: url.port,
9093
+ pathname: url.pathname,
9094
+ search: url.search,
9095
+ searchParams: [...url.searchParams].map(([key, value]) => ({ key, value })),
9096
+ hash: url.hash,
9097
+ origin: url.origin,
9098
+ };
9099
+ }
9100
+
9101
+ var Runtime = {
9102
+ getCallerStackFrame,
9103
+ getErrorTrace,
9104
+ getMeta,
9105
+ transportJSON,
9106
+ transportFormatted: transportFormatted$1,
9107
+ isBuffer,
9108
+ isError,
9109
+ prettyFormatLogObj,
9110
+ prettyFormatErrorObj,
9111
+ };
9112
+ const meta = {
9113
+ runtime: "Nodejs",
9114
+ runtimeVersion: process?.version,
9115
+ hostname: os.hostname ? os.hostname() : undefined,
9116
+ };
9117
+ function getMeta(logLevelId, logLevelName, stackDepthLevel, hideLogPositionForPerformance, name, parentNames) {
9118
+ return Object.assign({}, meta, {
9119
+ name,
9120
+ parentNames,
9121
+ date: new Date(),
9122
+ logLevelId,
9123
+ logLevelName,
9124
+ path: !hideLogPositionForPerformance ? getCallerStackFrame(stackDepthLevel) : undefined,
9125
+ });
9126
+ }
9127
+ function getCallerStackFrame(stackDepthLevel, error = Error()) {
9128
+ return stackLineToStackFrame(error?.stack?.split("\n")?.filter((thisLine) => thisLine.includes(" at "))?.[stackDepthLevel]);
9129
+ }
9130
+ function getErrorTrace(error) {
9131
+ return error?.stack?.split("\n")?.reduce((result, line) => {
9132
+ if (line.includes(" at ")) {
9133
+ result.push(stackLineToStackFrame(line));
9134
+ }
9135
+ return result;
9136
+ }, []);
9137
+ }
9138
+ function stackLineToStackFrame(line) {
9139
+ const pathResult = {
9140
+ fullFilePath: undefined,
9141
+ fileName: undefined,
9142
+ fileNameWithLine: undefined,
9143
+ fileColumn: undefined,
9144
+ fileLine: undefined,
9145
+ filePath: undefined,
9146
+ filePathWithLine: undefined,
9147
+ method: undefined,
9148
+ };
9149
+ if (line != null && line.includes(" at ")) {
9150
+ line = line.replace(/^\s+at\s+/gm, "");
9151
+ const errorStackLine = line.split(" (");
9152
+ const fullFilePath = line?.slice(-1) === ")" ? line?.match(/\(([^)]+)\)/)?.[1] : line;
9153
+ const pathArray = fullFilePath?.includes(":") ? fullFilePath?.replace("file://", "")?.replace(process.cwd(), "")?.split(":") : undefined;
9154
+ const fileColumn = pathArray?.pop();
9155
+ const fileLine = pathArray?.pop();
9156
+ const filePath = pathArray?.pop();
9157
+ const filePathWithLine = path.normalize(`${filePath}:${fileLine}`);
9158
+ const fileName = filePath?.split("/")?.pop();
9159
+ const fileNameWithLine = `${fileName}:${fileLine}`;
9160
+ if (filePath != null && filePath.length > 0) {
9161
+ pathResult.fullFilePath = fullFilePath;
9162
+ pathResult.fileName = fileName;
9163
+ pathResult.fileNameWithLine = fileNameWithLine;
9164
+ pathResult.fileColumn = fileColumn;
9165
+ pathResult.fileLine = fileLine;
9166
+ pathResult.filePath = filePath;
9167
+ pathResult.filePathWithLine = filePathWithLine;
9168
+ pathResult.method = errorStackLine?.[1] != null ? errorStackLine?.[0] : undefined;
9169
+ }
9170
+ }
9171
+ return pathResult;
9172
+ }
9173
+ function isError(e) {
9174
+ return util.types?.isNativeError != null ? util.types.isNativeError(e) : e instanceof Error;
9175
+ }
9176
+ function prettyFormatLogObj(maskedArgs, settings) {
9177
+ return maskedArgs.reduce((result, arg) => {
9178
+ isError(arg) ? result.errors.push(prettyFormatErrorObj(arg, settings)) : result.args.push(arg);
9179
+ return result;
9180
+ }, { args: [], errors: [] });
9181
+ }
9182
+ function prettyFormatErrorObj(error, settings) {
9183
+ const errorStackStr = getErrorTrace(error).map((stackFrame) => {
9184
+ return formatTemplate(settings, settings.prettyErrorStackTemplate, { ...stackFrame }, true);
9185
+ });
9186
+ const placeholderValuesError = {
9187
+ errorName: ` ${error.name} `,
9188
+ errorMessage: Object.getOwnPropertyNames(error)
9189
+ .reduce((result, key) => {
9190
+ if (key !== "stack") {
9191
+ result.push(error[key]);
9192
+ }
9193
+ return result;
9194
+ }, [])
9195
+ .join(", "),
9196
+ errorStack: errorStackStr.join("\n"),
9197
+ };
9198
+ return formatTemplate(settings, settings.prettyErrorTemplate, placeholderValuesError);
9199
+ }
9200
+ function transportFormatted$1(logMetaMarkup, logArgs, logErrors, settings) {
9201
+ const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
9202
+ settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
9203
+ console.log(logMetaMarkup + util.formatWithOptions(settings.prettyInspectOptions, ...logArgs) + logErrorsStr);
9204
+ }
9205
+ function transportJSON(json) {
9206
+ console.log(jsonStringifyRecursive(json));
9207
+ function jsonStringifyRecursive(obj) {
9208
+ const cache = new Set();
9209
+ return JSON.stringify(obj, (key, value) => {
9210
+ if (typeof value === "object" && value !== null) {
9211
+ if (cache.has(value)) {
9212
+ return "[Circular]";
9213
+ }
9214
+ cache.add(value);
9215
+ }
9216
+ if (typeof value === "bigint") {
9217
+ return `${value}`;
9218
+ }
9219
+ if (typeof value === "undefined") {
9220
+ return "[undefined]";
9221
+ }
9222
+ return value;
9223
+ });
9224
+ }
9225
+ }
9226
+ function isBuffer(arg) {
9227
+ return Buffer.isBuffer(arg);
9228
+ }
9229
+
9230
+ class BaseLogger {
9231
+ constructor(settings, logObj, stackDepthLevel = 4) {
9232
+ this.logObj = logObj;
9233
+ this.stackDepthLevel = stackDepthLevel;
9234
+ this.runtime = Runtime;
9235
+ this.settings = {
9236
+ type: settings?.type ?? "pretty",
9237
+ name: settings?.name,
9238
+ parentNames: settings?.parentNames,
9239
+ minLevel: settings?.minLevel ?? 0,
9240
+ argumentsArrayName: settings?.argumentsArrayName,
9241
+ hideLogPositionForProduction: settings?.hideLogPositionForProduction ?? false,
9242
+ prettyLogTemplate: settings?.prettyLogTemplate ??
9243
+ "{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}\t{{logLevelName}}\t{{filePathWithLine}}{{nameWithDelimiterPrefix}}\t",
9244
+ prettyErrorTemplate: settings?.prettyErrorTemplate ?? "\n{{errorName}} {{errorMessage}}\nerror stack:\n{{errorStack}}",
9245
+ prettyErrorStackTemplate: settings?.prettyErrorStackTemplate ?? " • {{fileName}}\t{{method}}\n\t{{filePathWithLine}}",
9246
+ prettyErrorParentNamesSeparator: settings?.prettyErrorParentNamesSeparator ?? ":",
9247
+ prettyErrorLoggerNameDelimiter: settings?.prettyErrorLoggerNameDelimiter ?? "\t",
9248
+ stylePrettyLogs: settings?.stylePrettyLogs ?? true,
9249
+ prettyLogTimeZone: settings?.prettyLogTimeZone ?? "UTC",
9250
+ prettyLogStyles: settings?.prettyLogStyles ?? {
9251
+ logLevelName: {
9252
+ "*": ["bold", "black", "bgWhiteBright", "dim"],
9253
+ SILLY: ["bold", "white"],
9254
+ TRACE: ["bold", "whiteBright"],
9255
+ DEBUG: ["bold", "green"],
9256
+ INFO: ["bold", "blue"],
9257
+ WARN: ["bold", "yellow"],
9258
+ ERROR: ["bold", "red"],
9259
+ FATAL: ["bold", "redBright"],
9260
+ },
9261
+ dateIsoStr: "white",
9262
+ filePathWithLine: "white",
9263
+ name: ["white", "bold"],
9264
+ nameWithDelimiterPrefix: ["white", "bold"],
9265
+ nameWithDelimiterSuffix: ["white", "bold"],
9266
+ errorName: ["bold", "bgRedBright", "whiteBright"],
9267
+ fileName: ["yellow"],
9268
+ fileNameWithLine: "white",
9269
+ },
9270
+ prettyInspectOptions: settings?.prettyInspectOptions ?? {
9271
+ colors: true,
9272
+ compact: false,
9273
+ depth: Infinity,
9274
+ },
9275
+ metaProperty: settings?.metaProperty ?? "_meta",
9276
+ maskPlaceholder: settings?.maskPlaceholder ?? "[***]",
9277
+ maskValuesOfKeys: settings?.maskValuesOfKeys ?? ["password"],
9278
+ maskValuesOfKeysCaseInsensitive: settings?.maskValuesOfKeysCaseInsensitive ?? false,
9279
+ maskValuesRegEx: settings?.maskValuesRegEx,
9280
+ prefix: [...(settings?.prefix ?? [])],
9281
+ attachedTransports: [...(settings?.attachedTransports ?? [])],
9282
+ overwrite: {
9283
+ mask: settings?.overwrite?.mask,
9284
+ toLogObj: settings?.overwrite?.toLogObj,
9285
+ addMeta: settings?.overwrite?.addMeta,
9286
+ addPlaceholders: settings?.overwrite?.addPlaceholders,
9287
+ formatMeta: settings?.overwrite?.formatMeta,
9288
+ formatLogObj: settings?.overwrite?.formatLogObj,
9289
+ transportFormatted: settings?.overwrite?.transportFormatted,
9290
+ transportJSON: settings?.overwrite?.transportJSON,
9291
+ },
9292
+ };
9293
+ }
9294
+ log(logLevelId, logLevelName, ...args) {
9295
+ if (logLevelId < this.settings.minLevel) {
9296
+ return;
9297
+ }
9298
+ const logArgs = [...this.settings.prefix, ...args];
9299
+ const maskedArgs = this.settings.overwrite?.mask != null
9300
+ ? this.settings.overwrite?.mask(logArgs)
9301
+ : this.settings.maskValuesOfKeys != null && this.settings.maskValuesOfKeys.length > 0
9302
+ ? this._mask(logArgs)
9303
+ : logArgs;
9304
+ const thisLogObj = this.logObj != null ? this._recursiveCloneAndExecuteFunctions(this.logObj) : undefined;
9305
+ const logObj = this.settings.overwrite?.toLogObj != null ? this.settings.overwrite?.toLogObj(maskedArgs, thisLogObj) : this._toLogObj(maskedArgs, thisLogObj);
9306
+ const logObjWithMeta = this.settings.overwrite?.addMeta != null
9307
+ ? this.settings.overwrite?.addMeta(logObj, logLevelId, logLevelName)
9308
+ : this._addMetaToLogObj(logObj, logLevelId, logLevelName);
9309
+ let logMetaMarkup;
9310
+ let logArgsAndErrorsMarkup = undefined;
9311
+ if (this.settings.overwrite?.formatMeta != null) {
9312
+ logMetaMarkup = this.settings.overwrite?.formatMeta(logObjWithMeta?.[this.settings.metaProperty]);
9313
+ }
9314
+ if (this.settings.overwrite?.formatLogObj != null) {
9315
+ logArgsAndErrorsMarkup = this.settings.overwrite?.formatLogObj(maskedArgs, this.settings);
9316
+ }
9317
+ if (this.settings.type === "pretty") {
9318
+ logMetaMarkup = logMetaMarkup ?? this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
9319
+ logArgsAndErrorsMarkup = logArgsAndErrorsMarkup ?? this.runtime.prettyFormatLogObj(maskedArgs, this.settings);
9320
+ }
9321
+ if (logMetaMarkup != null && logArgsAndErrorsMarkup != null) {
9322
+ this.settings.overwrite?.transportFormatted != null
9323
+ ? this.settings.overwrite?.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings)
9324
+ : this.runtime.transportFormatted(logMetaMarkup, logArgsAndErrorsMarkup.args, logArgsAndErrorsMarkup.errors, this.settings);
9325
+ }
9326
+ else {
9327
+ this.settings.overwrite?.transportJSON != null
9328
+ ? this.settings.overwrite?.transportJSON(logObjWithMeta)
9329
+ : this.settings.type !== "hidden"
9330
+ ? this.runtime.transportJSON(logObjWithMeta)
9331
+ : undefined;
9332
+ }
9333
+ if (this.settings.attachedTransports != null && this.settings.attachedTransports.length > 0) {
9334
+ this.settings.attachedTransports.forEach((transportLogger) => {
9335
+ transportLogger(logObjWithMeta);
9336
+ });
9337
+ }
9338
+ return logObjWithMeta;
9339
+ }
9340
+ attachTransport(transportLogger) {
9341
+ this.settings.attachedTransports.push(transportLogger);
9342
+ }
9343
+ getSubLogger(settings, logObj) {
9344
+ const subLoggerSettings = {
9345
+ ...this.settings,
9346
+ ...settings,
9347
+ parentNames: this.settings?.parentNames != null && this.settings?.name != null
9348
+ ? [...this.settings.parentNames, this.settings.name]
9349
+ : this.settings?.name != null
9350
+ ? [this.settings.name]
9351
+ : undefined,
9352
+ prefix: [...this.settings.prefix, ...(settings?.prefix ?? [])],
9353
+ };
9354
+ const subLogger = new this.constructor(subLoggerSettings, logObj ?? this.logObj, this.stackDepthLevel);
9355
+ return subLogger;
9356
+ }
9357
+ _mask(args) {
9358
+ const maskValuesOfKeys = this.settings.maskValuesOfKeysCaseInsensitive !== true ? this.settings.maskValuesOfKeys : this.settings.maskValuesOfKeys.map((key) => key.toLowerCase());
9359
+ return args?.map((arg) => {
9360
+ return this._recursiveCloneAndMaskValuesOfKeys(arg, maskValuesOfKeys);
9361
+ });
9362
+ }
9363
+ _recursiveCloneAndMaskValuesOfKeys(source, keys, seen = []) {
9364
+ if (seen.includes(source)) {
9365
+ return { ...source };
9366
+ }
9367
+ if (typeof source === "object" && source !== null) {
9368
+ seen.push(source);
9369
+ }
9370
+ if (this.runtime.isError(source) || this.runtime.isBuffer(source)) {
9371
+ return source;
9372
+ }
9373
+ else if (source instanceof Map) {
9374
+ return new Map(source);
9375
+ }
9376
+ else if (source instanceof Set) {
9377
+ return new Set(source);
9378
+ }
9379
+ else if (Array.isArray(source)) {
9380
+ return source.map((item) => this._recursiveCloneAndMaskValuesOfKeys(item, keys, seen));
9381
+ }
9382
+ else if (source instanceof Date) {
9383
+ return new Date(source.getTime());
9384
+ }
9385
+ else if (source instanceof URL) {
9386
+ return urlToObject(source);
9387
+ }
9388
+ else if (source !== null && typeof source === "object") {
9389
+ const baseObject = this.runtime.isError(source) ? this._cloneError(source) : Object.create(Object.getPrototypeOf(source));
9390
+ return Object.getOwnPropertyNames(source).reduce((o, prop) => {
9391
+ o[prop] = keys.includes(this.settings?.maskValuesOfKeysCaseInsensitive !== true ? prop : prop.toLowerCase())
9392
+ ? this.settings.maskPlaceholder
9393
+ : (() => {
9394
+ try {
9395
+ return this._recursiveCloneAndMaskValuesOfKeys(source[prop], keys, seen);
9396
+ }
9397
+ catch (e) {
9398
+ return null;
9399
+ }
9400
+ })();
9401
+ return o;
9402
+ }, baseObject);
9403
+ }
9404
+ else {
9405
+ if (typeof source === "string") {
9406
+ let modifiedSource = source;
9407
+ for (const regEx of this.settings?.maskValuesRegEx || []) {
9408
+ modifiedSource = modifiedSource.replace(regEx, this.settings?.maskPlaceholder || "");
9409
+ }
9410
+ return modifiedSource;
9411
+ }
9412
+ return source;
9413
+ }
9414
+ }
9415
+ _recursiveCloneAndExecuteFunctions(source, seen = []) {
9416
+ if (this.isObjectOrArray(source) && seen.includes(source)) {
9417
+ return this.shallowCopy(source);
9418
+ }
9419
+ if (this.isObjectOrArray(source)) {
9420
+ seen.push(source);
9421
+ }
9422
+ if (Array.isArray(source)) {
9423
+ return source.map((item) => this._recursiveCloneAndExecuteFunctions(item, seen));
9424
+ }
9425
+ else if (source instanceof Date) {
9426
+ return new Date(source.getTime());
9427
+ }
9428
+ else if (this.isObject(source)) {
9429
+ return Object.getOwnPropertyNames(source).reduce((o, prop) => {
9430
+ const descriptor = Object.getOwnPropertyDescriptor(source, prop);
9431
+ if (descriptor) {
9432
+ Object.defineProperty(o, prop, descriptor);
9433
+ const value = source[prop];
9434
+ o[prop] = typeof value === "function" ? value() : this._recursiveCloneAndExecuteFunctions(value, seen);
9435
+ }
9436
+ return o;
9437
+ }, Object.create(Object.getPrototypeOf(source)));
9438
+ }
9439
+ else {
9440
+ return source;
9441
+ }
9442
+ }
9443
+ isObjectOrArray(value) {
9444
+ return typeof value === "object" && value !== null;
9445
+ }
9446
+ isObject(value) {
9447
+ return typeof value === "object" && !Array.isArray(value) && value !== null;
9448
+ }
9449
+ shallowCopy(source) {
9450
+ if (Array.isArray(source)) {
9451
+ return [...source];
9452
+ }
9453
+ else {
9454
+ return { ...source };
9455
+ }
9456
+ }
9457
+ _toLogObj(args, clonedLogObj = {}) {
9458
+ args = args?.map((arg) => (this.runtime.isError(arg) ? this._toErrorObject(arg) : arg));
9459
+ if (this.settings.argumentsArrayName == null) {
9460
+ if (args.length === 1 && !Array.isArray(args[0]) && this.runtime.isBuffer(args[0]) !== true && !(args[0] instanceof Date)) {
9461
+ clonedLogObj = typeof args[0] === "object" && args[0] != null ? { ...args[0], ...clonedLogObj } : { 0: args[0], ...clonedLogObj };
9462
+ }
9463
+ else {
9464
+ clonedLogObj = { ...clonedLogObj, ...args };
9465
+ }
9466
+ }
9467
+ else {
9468
+ clonedLogObj = {
9469
+ ...clonedLogObj,
9470
+ [this.settings.argumentsArrayName]: args,
9471
+ };
9472
+ }
9473
+ return clonedLogObj;
9474
+ }
9475
+ _cloneError(error) {
9476
+ const cloned = new error.constructor();
9477
+ Object.getOwnPropertyNames(error).forEach((key) => {
9478
+ cloned[key] = error[key];
9479
+ });
9480
+ return cloned;
9481
+ }
9482
+ _toErrorObject(error) {
9483
+ return {
9484
+ nativeError: error,
9485
+ name: error.name ?? "Error",
9486
+ message: error.message,
9487
+ stack: this.runtime.getErrorTrace(error),
9488
+ };
9489
+ }
9490
+ _addMetaToLogObj(logObj, logLevelId, logLevelName) {
9491
+ return {
9492
+ ...logObj,
9493
+ [this.settings.metaProperty]: this.runtime.getMeta(logLevelId, logLevelName, this.stackDepthLevel, this.settings.hideLogPositionForProduction, this.settings.name, this.settings.parentNames),
9494
+ };
9495
+ }
9496
+ _prettyFormatLogObjMeta(logObjMeta) {
9497
+ if (logObjMeta == null) {
9498
+ return "";
9499
+ }
9500
+ let template = this.settings.prettyLogTemplate;
9501
+ const placeholderValues = {};
9502
+ if (template.includes("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}")) {
9503
+ template = template.replace("{{yyyy}}.{{mm}}.{{dd}} {{hh}}:{{MM}}:{{ss}}:{{ms}}", "{{dateIsoStr}}");
9504
+ }
9505
+ else {
9506
+ if (this.settings.prettyLogTimeZone === "UTC") {
9507
+ placeholderValues["yyyy"] = logObjMeta?.date?.getUTCFullYear() ?? "----";
9508
+ placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMonth(), 2, 1);
9509
+ placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getUTCDate(), 2);
9510
+ placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getUTCHours(), 2);
9511
+ placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMinutes(), 2);
9512
+ placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getUTCSeconds(), 2);
9513
+ placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getUTCMilliseconds(), 3);
9514
+ }
9515
+ else {
9516
+ placeholderValues["yyyy"] = logObjMeta?.date?.getFullYear() ?? "----";
9517
+ placeholderValues["mm"] = formatNumberAddZeros(logObjMeta?.date?.getMonth(), 2, 1);
9518
+ placeholderValues["dd"] = formatNumberAddZeros(logObjMeta?.date?.getDate(), 2);
9519
+ placeholderValues["hh"] = formatNumberAddZeros(logObjMeta?.date?.getHours(), 2);
9520
+ placeholderValues["MM"] = formatNumberAddZeros(logObjMeta?.date?.getMinutes(), 2);
9521
+ placeholderValues["ss"] = formatNumberAddZeros(logObjMeta?.date?.getSeconds(), 2);
9522
+ placeholderValues["ms"] = formatNumberAddZeros(logObjMeta?.date?.getMilliseconds(), 3);
9523
+ }
9524
+ }
9525
+ const dateInSettingsTimeZone = this.settings.prettyLogTimeZone === "UTC" ? logObjMeta?.date : new Date(logObjMeta?.date?.getTime() - logObjMeta?.date?.getTimezoneOffset() * 60000);
9526
+ placeholderValues["rawIsoStr"] = dateInSettingsTimeZone?.toISOString();
9527
+ placeholderValues["dateIsoStr"] = dateInSettingsTimeZone?.toISOString().replace("T", " ").replace("Z", "");
9528
+ placeholderValues["logLevelName"] = logObjMeta?.logLevelName;
9529
+ placeholderValues["fileNameWithLine"] = logObjMeta?.path?.fileNameWithLine ?? "";
9530
+ placeholderValues["filePathWithLine"] = logObjMeta?.path?.filePathWithLine ?? "";
9531
+ placeholderValues["fullFilePath"] = logObjMeta?.path?.fullFilePath ?? "";
9532
+ let parentNamesString = this.settings.parentNames?.join(this.settings.prettyErrorParentNamesSeparator);
9533
+ parentNamesString = parentNamesString != null && logObjMeta?.name != null ? parentNamesString + this.settings.prettyErrorParentNamesSeparator : undefined;
9534
+ placeholderValues["name"] = logObjMeta?.name != null || parentNamesString != null ? (parentNamesString ?? "") + logObjMeta?.name ?? "" : "";
9535
+ placeholderValues["nameWithDelimiterPrefix"] =
9536
+ placeholderValues["name"].length > 0 ? this.settings.prettyErrorLoggerNameDelimiter + placeholderValues["name"] : "";
9537
+ placeholderValues["nameWithDelimiterSuffix"] =
9538
+ placeholderValues["name"].length > 0 ? placeholderValues["name"] + this.settings.prettyErrorLoggerNameDelimiter : "";
9539
+ if (this.settings.overwrite?.addPlaceholders != null) {
9540
+ this.settings.overwrite?.addPlaceholders(logObjMeta, placeholderValues);
9541
+ }
9542
+ return formatTemplate(this.settings, template, placeholderValues);
9543
+ }
9544
+ }
9545
+
9546
+ class Logger extends BaseLogger {
9547
+ constructor(settings, logObj) {
9548
+ const isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
9549
+ const isBrowserBlinkEngine = isBrowser ? window.chrome !== undefined && window.CSS !== undefined && window.CSS.supports("color", "green") : false;
9550
+ const isSafari = isBrowser ? /^((?!chrome|android).)*safari/i.test(navigator.userAgent) : false;
9551
+ settings = settings || {};
9552
+ settings.stylePrettyLogs = settings.stylePrettyLogs && isBrowser && !isBrowserBlinkEngine ? false : settings.stylePrettyLogs;
9553
+ super(settings, logObj, isSafari ? 4 : 5);
9554
+ }
9555
+ log(logLevelId, logLevelName, ...args) {
9556
+ return super.log(logLevelId, logLevelName, ...args);
9557
+ }
9558
+ silly(...args) {
9559
+ return super.log(0, "SILLY", ...args);
9560
+ }
9561
+ trace(...args) {
9562
+ return super.log(1, "TRACE", ...args);
9563
+ }
9564
+ debug(...args) {
9565
+ return super.log(2, "DEBUG", ...args);
9566
+ }
9567
+ info(...args) {
9568
+ return super.log(3, "INFO", ...args);
9569
+ }
9570
+ warn(...args) {
9571
+ return super.log(4, "WARN", ...args);
9572
+ }
9573
+ error(...args) {
9574
+ return super.log(5, "ERROR", ...args);
9575
+ }
9576
+ fatal(...args) {
9577
+ return super.log(6, "FATAL", ...args);
9578
+ }
9579
+ getSubLogger(settings, logObj) {
9580
+ return super.getSubLogger(settings, logObj);
9581
+ }
9582
+ }
9583
+
9584
+ function transportFormatted(logMetaMarkup, logArgs, logErrors, settings) {
9585
+ const logErrorsStr = (logErrors.length > 0 && logArgs.length > 0 ? "\n" : "") + logErrors.join("\n");
9586
+ settings.prettyInspectOptions.colors = settings.stylePrettyLogs;
9587
+ console.log(logMetaMarkup, ...logArgs, logErrorsStr);
9588
+ }
9589
+ function formatMeta(logObjMeta) {
9590
+ if (!logObjMeta) {
9591
+ return '';
9592
+ }
9593
+ const { date, logLevelName } = logObjMeta;
9594
+ const year = date.getFullYear();
9595
+ const month = String(date.getMonth() + 1).padStart(2, '0');
9596
+ const day = String(date.getDate()).padStart(2, '0');
9597
+ const hours = String(date.getHours()).padStart(2, '0');
9598
+ const minutes = String(date.getMinutes()).padStart(2, '0');
9599
+ const seconds = String(date.getSeconds()).padStart(2, '0');
9600
+ const milliseconds = String(date.getMilliseconds()).padStart(3, '0');
9601
+ const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}.${milliseconds}`;
9602
+ const loggerName = logObjMeta.name;
9603
+ return `${formattedDate} ${logLevelName} ${loggerName}`;
9604
+ }
9605
+ const logger = new Logger({
9606
+ name: "ekoLogger",
9607
+ overwrite: {
9608
+ transportFormatted,
9609
+ formatMeta,
9610
+ }
9611
+ });
9612
+
8985
9613
  class CancelWorkflow {
8986
9614
  constructor() {
8987
9615
  this.name = 'cancel_workflow';
@@ -9003,7 +9631,7 @@ class CancelWorkflow {
9003
9631
  throw new Error('Invalid parameters. Expected an object with a "reason" property.');
9004
9632
  }
9005
9633
  const reason = params.reason;
9006
- console.log("The workflow has been cancelled because: " + reason);
9634
+ logger.info("The workflow has been cancelled because: " + reason);
9007
9635
  await ((_a = context.workflow) === null || _a === void 0 ? void 0 : _a.cancel());
9008
9636
  return;
9009
9637
  }
@@ -9030,7 +9658,7 @@ class HumanInputText {
9030
9658
  throw new Error('Invalid parameters. Expected an object with a "question" property.');
9031
9659
  }
9032
9660
  const question = params.question;
9033
- console.log("question: " + question);
9661
+ logger.debug("question: " + question);
9034
9662
  let onHumanInputText = (_a = context.callback) === null || _a === void 0 ? void 0 : _a.hooks.onHumanInputText;
9035
9663
  if (onHumanInputText) {
9036
9664
  let answer;
@@ -9038,14 +9666,14 @@ class HumanInputText {
9038
9666
  answer = await onHumanInputText(question);
9039
9667
  }
9040
9668
  catch (e) {
9041
- console.error(e);
9669
+ logger.warn(e);
9042
9670
  return { status: "Error: Cannot get user's answer.", answer: "" };
9043
9671
  }
9044
- console.log("answer: " + answer);
9672
+ logger.debug("answer: " + answer);
9045
9673
  return { status: "OK", answer: answer };
9046
9674
  }
9047
9675
  else {
9048
- console.error("`onHumanInputText` not implemented");
9676
+ logger.error("`onHumanInputText` not implemented");
9049
9677
  return { status: "Error: Cannot get user's answer.", answer: "" };
9050
9678
  }
9051
9679
  }
@@ -9084,8 +9712,8 @@ class HumanInputSingleChoice {
9084
9712
  }
9085
9713
  const question = params.question;
9086
9714
  const choices = params.choices.map((e) => e.choice);
9087
- console.log("question: " + question);
9088
- console.log("choices: " + choices);
9715
+ logger.debug("question: " + question);
9716
+ logger.debug("choices: " + choices);
9089
9717
  let onHumanInputSingleChoice = (_a = context.callback) === null || _a === void 0 ? void 0 : _a.hooks.onHumanInputSingleChoice;
9090
9718
  if (onHumanInputSingleChoice) {
9091
9719
  let answer;
@@ -9093,14 +9721,14 @@ class HumanInputSingleChoice {
9093
9721
  answer = await onHumanInputSingleChoice(question, choices);
9094
9722
  }
9095
9723
  catch (e) {
9096
- console.error(e);
9724
+ logger.warn(e);
9097
9725
  return { status: "Error: Cannot get user's answer.", answer: "" };
9098
9726
  }
9099
- console.log("answer: " + answer);
9727
+ logger.debug("answer: " + answer);
9100
9728
  return { status: "OK", answer: answer };
9101
9729
  }
9102
9730
  else {
9103
- console.error("`onHumanInputSingleChoice` not implemented");
9731
+ logger.error("`onHumanInputSingleChoice` not implemented");
9104
9732
  return { status: "Error: Cannot get user's answer.", answer: "" };
9105
9733
  }
9106
9734
  }
@@ -9139,8 +9767,8 @@ class HumanInputMultipleChoice {
9139
9767
  }
9140
9768
  const question = params.question;
9141
9769
  const choices = params.choices.map((e) => e.choice);
9142
- console.log("question: " + question);
9143
- console.log("choices: " + choices);
9770
+ logger.debug("question: " + question);
9771
+ logger.debug("choices: " + choices);
9144
9772
  let onHumanInputMultipleChoice = (_a = context.callback) === null || _a === void 0 ? void 0 : _a.hooks.onHumanInputMultipleChoice;
9145
9773
  if (onHumanInputMultipleChoice) {
9146
9774
  let answer;
@@ -9148,14 +9776,14 @@ class HumanInputMultipleChoice {
9148
9776
  answer = await onHumanInputMultipleChoice(question, choices);
9149
9777
  }
9150
9778
  catch (e) {
9151
- console.error(e);
9152
- return { status: "`onHumanInputMultipleChoice` not implemented", answer: [] };
9779
+ logger.warn(e);
9780
+ return { status: "Error: Cannot get user's answer.", answer: [] };
9153
9781
  }
9154
- console.log("answer: " + answer);
9782
+ logger.debug("answer: " + answer);
9155
9783
  return { status: "OK", answer: answer };
9156
9784
  }
9157
9785
  else {
9158
- console.error("Cannot get user's answer.");
9786
+ logger.error("`onHumanInputMultipleChoice` not implemented");
9159
9787
  return { status: "Error: Cannot get user's answer.", answer: [] };
9160
9788
  }
9161
9789
  }
@@ -9189,7 +9817,7 @@ When calling this tool to transfer control to the user, please explain in detail
9189
9817
  throw new Error('Invalid parameters. Expected an object with a "reason" property.');
9190
9818
  }
9191
9819
  const reason = params.reason;
9192
- console.log("reason: " + reason);
9820
+ logger.debug("reason: " + reason);
9193
9821
  let onHumanOperate = (_a = context.callback) === null || _a === void 0 ? void 0 : _a.hooks.onHumanOperate;
9194
9822
  if (onHumanOperate) {
9195
9823
  let userOperation;
@@ -9197,10 +9825,10 @@ When calling this tool to transfer control to the user, please explain in detail
9197
9825
  userOperation = await onHumanOperate(reason);
9198
9826
  }
9199
9827
  catch (e) {
9200
- console.error(e);
9201
- return { status: "`onHumanOperate` not implemented", userOperation: "" };
9828
+ logger.warn(e);
9829
+ return { status: "Error: Cannot get user's operation.", userOperation: "" };
9202
9830
  }
9203
- console.log("userOperation: " + userOperation);
9831
+ logger.debug("userOperation: " + userOperation);
9204
9832
  if (userOperation == "") {
9205
9833
  return { status: "OK", userOperation: "Done. Please take a screenshot to ensure the result." };
9206
9834
  }
@@ -9209,7 +9837,7 @@ When calling this tool to transfer control to the user, please explain in detail
9209
9837
  }
9210
9838
  }
9211
9839
  else {
9212
- console.error("Cannot get user's operation.");
9840
+ logger.error("`onHumanOperate` not implemented");
9213
9841
  return { status: "Error: Cannot get user's operation.", userOperation: "" };
9214
9842
  }
9215
9843
  }