test-wuying-agentbay-sdk 0.13.1-beta.20251224091333 → 0.13.1-beta.20251224094729
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/index.cjs +95 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +95 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2311,11 +2311,20 @@ var LOG_LEVEL_VALUES = {
|
|
|
2311
2311
|
};
|
|
2312
2312
|
var currentRequestId = "";
|
|
2313
2313
|
var currentLogLevel = process.env.LOG_LEVEL || process.env.AGENTBAY_LOG_LEVEL || "INFO";
|
|
2314
|
+
var currentLogFormat = process.env.AGENTBAY_LOG_FORMAT || "pretty";
|
|
2315
|
+
if (["sls", "compact"].includes(String(currentLogFormat).toLowerCase())) {
|
|
2316
|
+
currentLogFormat = "sls";
|
|
2317
|
+
} else {
|
|
2318
|
+
currentLogFormat = "pretty";
|
|
2319
|
+
}
|
|
2314
2320
|
var fileLoggingEnabled = false;
|
|
2315
2321
|
var logFilePath = null;
|
|
2316
2322
|
var logFileMaxSize = 10 * 1024 * 1024;
|
|
2317
2323
|
var consoleLoggingEnabled = true;
|
|
2318
2324
|
function shouldUseColors() {
|
|
2325
|
+
if (currentLogFormat === "sls") {
|
|
2326
|
+
return false;
|
|
2327
|
+
}
|
|
2319
2328
|
if (process.env.DISABLE_COLORS === "true") {
|
|
2320
2329
|
return false;
|
|
2321
2330
|
}
|
|
@@ -2357,6 +2366,9 @@ var SENSITIVE_FIELDS = [
|
|
|
2357
2366
|
"authorization"
|
|
2358
2367
|
];
|
|
2359
2368
|
function getLogLevelEmoji(level) {
|
|
2369
|
+
if (currentLogFormat === "sls") {
|
|
2370
|
+
return level;
|
|
2371
|
+
}
|
|
2360
2372
|
switch (level) {
|
|
2361
2373
|
case "DEBUG":
|
|
2362
2374
|
return "\u{1F41B} DEBUG";
|
|
@@ -2376,6 +2388,13 @@ function shouldLog(level) {
|
|
|
2376
2388
|
}
|
|
2377
2389
|
_chunk4IPTHWLMcjs.__name.call(void 0, shouldLog, "shouldLog");
|
|
2378
2390
|
function formatLogMessage(level, message, forFile = false) {
|
|
2391
|
+
if (currentLogFormat === "sls") {
|
|
2392
|
+
let formattedMessage2 = `${level}: ${message}`;
|
|
2393
|
+
if (currentRequestId) {
|
|
2394
|
+
formattedMessage2 += ` [RequestId=${currentRequestId}]`;
|
|
2395
|
+
}
|
|
2396
|
+
return formattedMessage2;
|
|
2397
|
+
}
|
|
2379
2398
|
let formattedMessage = `${getLogLevelEmoji(level)}: ${message}`;
|
|
2380
2399
|
if (currentRequestId) {
|
|
2381
2400
|
formattedMessage += ` [RequestId=${currentRequestId}]`;
|
|
@@ -2523,6 +2542,23 @@ function setupLogger(config) {
|
|
|
2523
2542
|
if (config.enableConsole !== void 0) {
|
|
2524
2543
|
consoleLoggingEnabled = config.enableConsole;
|
|
2525
2544
|
}
|
|
2545
|
+
if (config.format) {
|
|
2546
|
+
if (["sls", "compact"].includes(String(config.format).toLowerCase())) {
|
|
2547
|
+
currentLogFormat = "sls";
|
|
2548
|
+
} else {
|
|
2549
|
+
currentLogFormat = "pretty";
|
|
2550
|
+
}
|
|
2551
|
+
} else {
|
|
2552
|
+
const envFormat = process.env.AGENTBAY_LOG_FORMAT;
|
|
2553
|
+
if (envFormat) {
|
|
2554
|
+
if (["sls", "compact"].includes(String(envFormat).toLowerCase())) {
|
|
2555
|
+
currentLogFormat = "sls";
|
|
2556
|
+
} else {
|
|
2557
|
+
currentLogFormat = "pretty";
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
}
|
|
2561
|
+
useColors = shouldUseColors();
|
|
2526
2562
|
}
|
|
2527
2563
|
_chunk4IPTHWLMcjs.__name.call(void 0, setupLogger, "setupLogger");
|
|
2528
2564
|
function log(message, ...args) {
|
|
@@ -2630,6 +2666,22 @@ ${error.stack}`;
|
|
|
2630
2666
|
_chunk4IPTHWLMcjs.__name.call(void 0, logError, "logError");
|
|
2631
2667
|
function logAPICall(apiName, requestData) {
|
|
2632
2668
|
if (!shouldLog("INFO")) return;
|
|
2669
|
+
if (currentLogFormat === "sls") {
|
|
2670
|
+
let message2 = `API Call: ${apiName}`;
|
|
2671
|
+
if (requestData) {
|
|
2672
|
+
const maskedData = maskSensitiveData(requestData);
|
|
2673
|
+
if (typeof maskedData === "string") {
|
|
2674
|
+
message2 += `, ${maskedData}`;
|
|
2675
|
+
} else {
|
|
2676
|
+
message2 += `, ${JSON.stringify(maskedData)}`;
|
|
2677
|
+
}
|
|
2678
|
+
}
|
|
2679
|
+
if (consoleLoggingEnabled) {
|
|
2680
|
+
process.stdout.write(message2 + "\n");
|
|
2681
|
+
}
|
|
2682
|
+
writeToFile(message2);
|
|
2683
|
+
return;
|
|
2684
|
+
}
|
|
2633
2685
|
const message = `\u{1F517} API Call: ${apiName}`;
|
|
2634
2686
|
const savedRequestId = currentRequestId;
|
|
2635
2687
|
currentRequestId = "";
|
|
@@ -2647,6 +2699,35 @@ function logAPICall(apiName, requestData) {
|
|
|
2647
2699
|
}
|
|
2648
2700
|
_chunk4IPTHWLMcjs.__name.call(void 0, logAPICall, "logAPICall");
|
|
2649
2701
|
function logAPIResponseWithDetails(apiName, requestId, success = true, keyFields, fullResponse) {
|
|
2702
|
+
if (currentLogFormat === "sls") {
|
|
2703
|
+
if (!shouldLog(success ? "INFO" : "ERROR")) return;
|
|
2704
|
+
const status = success ? "API Response" : "API Response Failed";
|
|
2705
|
+
let msg = `${status}: ${apiName}`;
|
|
2706
|
+
if (requestId) {
|
|
2707
|
+
msg += `, RequestId=${requestId}`;
|
|
2708
|
+
}
|
|
2709
|
+
if (keyFields) {
|
|
2710
|
+
for (const [key, value] of Object.entries(keyFields)) {
|
|
2711
|
+
const maskedValue = maskSensitiveData({ [key]: value });
|
|
2712
|
+
msg += `, ${key}=${maskedValue[key]}`;
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
if (success) {
|
|
2716
|
+
if (consoleLoggingEnabled) {
|
|
2717
|
+
process.stdout.write(msg + "\n");
|
|
2718
|
+
}
|
|
2719
|
+
writeToFile(msg);
|
|
2720
|
+
} else {
|
|
2721
|
+
if (consoleLoggingEnabled) {
|
|
2722
|
+
process.stderr.write(msg + "\n");
|
|
2723
|
+
}
|
|
2724
|
+
writeToFile(msg);
|
|
2725
|
+
}
|
|
2726
|
+
if (fullResponse && shouldLog("DEBUG")) {
|
|
2727
|
+
logDebug(`Full Response: ${fullResponse}`);
|
|
2728
|
+
}
|
|
2729
|
+
return;
|
|
2730
|
+
}
|
|
2650
2731
|
if (success) {
|
|
2651
2732
|
if (shouldLog("INFO")) {
|
|
2652
2733
|
let mainMessage = `\u2705 API Response: ${apiName}`;
|
|
@@ -2718,6 +2799,16 @@ function logCodeExecutionOutput(requestId, rawOutput) {
|
|
|
2718
2799
|
return;
|
|
2719
2800
|
}
|
|
2720
2801
|
const actualOutput = texts.join("");
|
|
2802
|
+
if (currentLogFormat === "sls") {
|
|
2803
|
+
const header2 = `Code Execution Output (RequestID: ${requestId}):`;
|
|
2804
|
+
if (consoleLoggingEnabled) {
|
|
2805
|
+
process.stdout.write(header2 + "\n");
|
|
2806
|
+
process.stdout.write(actualOutput + "\n");
|
|
2807
|
+
}
|
|
2808
|
+
writeToFile(header2);
|
|
2809
|
+
writeToFile(actualOutput);
|
|
2810
|
+
return;
|
|
2811
|
+
}
|
|
2721
2812
|
const header = `\u{1F4CB} Code Execution Output (RequestID: ${requestId}):`;
|
|
2722
2813
|
if (useColors) {
|
|
2723
2814
|
process.stdout.write(`${ANSI_GREEN}\u2139\uFE0F INFO: ${header}${ANSI_RESET}
|
|
@@ -2747,6 +2838,10 @@ function logCodeExecutionOutput(requestId, rawOutput) {
|
|
|
2747
2838
|
_chunk4IPTHWLMcjs.__name.call(void 0, logCodeExecutionOutput, "logCodeExecutionOutput");
|
|
2748
2839
|
function logInfoWithColor(message, color = ANSI_RED) {
|
|
2749
2840
|
if (!shouldLog("INFO")) return;
|
|
2841
|
+
if (currentLogFormat === "sls") {
|
|
2842
|
+
logInfo(message);
|
|
2843
|
+
return;
|
|
2844
|
+
}
|
|
2750
2845
|
const emoji = "\u2139\uFE0F INFO";
|
|
2751
2846
|
const fullMessage = `${emoji}: ${message}`;
|
|
2752
2847
|
if (useColors) {
|