test-wuying-agentbay-sdk 0.15.0-beta.20260114164932 → 0.15.0-beta.20260114193937
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 +84 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +18 -18
- package/dist/index.d.ts +18 -18
- package/dist/index.mjs +76 -26
- package/dist/index.mjs.map +1 -1
- package/docs/api/common-features/basics/agentbay.md +96 -96
- package/docs/api/common-features/basics/session.md +130 -130
- package/docs/api/computer-use/computer.md +22 -0
- package/docs/examples/common-features/basics/session-pause-resume/session-pause-resume.ts +6 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2745,6 +2745,35 @@ function maskSensitiveData(data, fields) {
|
|
|
2745
2745
|
return mask(data);
|
|
2746
2746
|
}
|
|
2747
2747
|
_chunkJB6CNGN4cjs.__name.call(void 0, maskSensitiveData, "maskSensitiveData");
|
|
2748
|
+
function truncateStringForLog(s, max) {
|
|
2749
|
+
if (!max || max <= 0 || s.length <= max) {
|
|
2750
|
+
return s;
|
|
2751
|
+
}
|
|
2752
|
+
return s.slice(0, max) + "...(truncated)";
|
|
2753
|
+
}
|
|
2754
|
+
_chunkJB6CNGN4cjs.__name.call(void 0, truncateStringForLog, "truncateStringForLog");
|
|
2755
|
+
function maskSensitiveDataString(input) {
|
|
2756
|
+
try {
|
|
2757
|
+
const parsed = JSON.parse(input);
|
|
2758
|
+
const masked = maskSensitiveData(parsed);
|
|
2759
|
+
return JSON.stringify(masked);
|
|
2760
|
+
} catch (e4) {
|
|
2761
|
+
const fields = SENSITIVE_FIELDS;
|
|
2762
|
+
let out = input;
|
|
2763
|
+
for (const field of fields) {
|
|
2764
|
+
const re = new RegExp(`("${field}"\\s*:\\s*")([^"]*)(")`, "gi");
|
|
2765
|
+
out = out.replace(re, (_m, p1, p2, p3) => {
|
|
2766
|
+
const v = String(p2 || "");
|
|
2767
|
+
if (v.length > 4) {
|
|
2768
|
+
return `${p1}${v.substring(0, 2)}****${v.substring(v.length - 2)}${p3}`;
|
|
2769
|
+
}
|
|
2770
|
+
return `${p1}****${p3}`;
|
|
2771
|
+
});
|
|
2772
|
+
}
|
|
2773
|
+
return out;
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
_chunkJB6CNGN4cjs.__name.call(void 0, maskSensitiveDataString, "maskSensitiveDataString");
|
|
2748
2777
|
function setLogLevel(level) {
|
|
2749
2778
|
if (LOG_LEVEL_VALUES[level] !== void 0) {
|
|
2750
2779
|
currentLogLevel = level;
|
|
@@ -3037,7 +3066,8 @@ function logAPIResponseWithDetails(apiName, requestId, success = true, keyFields
|
|
|
3037
3066
|
}
|
|
3038
3067
|
}
|
|
3039
3068
|
if (fullResponse && shouldLog("DEBUG")) {
|
|
3040
|
-
|
|
3069
|
+
const masked = truncateStringForLog(maskSensitiveDataString(fullResponse), 2e3);
|
|
3070
|
+
logDebug(`\u{1F4E5} Full Response: ${masked}`);
|
|
3041
3071
|
}
|
|
3042
3072
|
} else {
|
|
3043
3073
|
if (shouldLog("ERROR")) {
|
|
@@ -3051,12 +3081,25 @@ function logAPIResponseWithDetails(apiName, requestId, success = true, keyFields
|
|
|
3051
3081
|
} else {
|
|
3052
3082
|
logError(errorMessage);
|
|
3053
3083
|
}
|
|
3084
|
+
if (keyFields) {
|
|
3085
|
+
for (const [key, value] of Object.entries(keyFields)) {
|
|
3086
|
+
const maskedValue = maskSensitiveData({ [key]: value });
|
|
3087
|
+
const keyMessage = ` \u2514\u2500 ${key}=${maskedValue[key]}`;
|
|
3088
|
+
if (useColors) {
|
|
3089
|
+
process.stderr.write(`${ANSI_RED}\u274C ERROR: ${keyMessage}${ANSI_RESET}
|
|
3090
|
+
`);
|
|
3091
|
+
} else {
|
|
3092
|
+
logError(keyMessage);
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
}
|
|
3054
3096
|
if (fullResponse) {
|
|
3097
|
+
const masked = truncateStringForLog(maskSensitiveDataString(fullResponse), 2e3);
|
|
3055
3098
|
if (useColors) {
|
|
3056
|
-
process.stderr.write(`${ANSI_RED}\
|
|
3099
|
+
process.stderr.write(`${ANSI_RED}\u274C ERROR: \u{1F4E5} Response: ${masked}${ANSI_RESET}
|
|
3057
3100
|
`);
|
|
3058
3101
|
} else {
|
|
3059
|
-
logError(`\u{1F4E5} Response: ${
|
|
3102
|
+
logError(`\u{1F4E5} Response: ${masked}`);
|
|
3060
3103
|
}
|
|
3061
3104
|
}
|
|
3062
3105
|
}
|
|
@@ -5479,7 +5522,7 @@ function isValidJWT(jwt, alg) {
|
|
|
5479
5522
|
if (alg && decoded.alg !== alg)
|
|
5480
5523
|
return false;
|
|
5481
5524
|
return true;
|
|
5482
|
-
} catch (
|
|
5525
|
+
} catch (e5) {
|
|
5483
5526
|
return false;
|
|
5484
5527
|
}
|
|
5485
5528
|
}
|
|
@@ -5640,7 +5683,7 @@ var _ZodString = class _ZodString extends ZodType {
|
|
|
5640
5683
|
} else if (check.kind === "url") {
|
|
5641
5684
|
try {
|
|
5642
5685
|
new URL(input.data);
|
|
5643
|
-
} catch (
|
|
5686
|
+
} catch (e6) {
|
|
5644
5687
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
5645
5688
|
addIssueToContext(ctx, {
|
|
5646
5689
|
validation: "url",
|
|
@@ -6295,7 +6338,7 @@ var _ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
6295
6338
|
if (this._def.coerce) {
|
|
6296
6339
|
try {
|
|
6297
6340
|
input.data = BigInt(input.data);
|
|
6298
|
-
} catch (
|
|
6341
|
+
} catch (e7) {
|
|
6299
6342
|
return this._getInvalidInput(input);
|
|
6300
6343
|
}
|
|
6301
6344
|
}
|
|
@@ -10899,7 +10942,7 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
10899
10942
|
let argsParsed;
|
|
10900
10943
|
try {
|
|
10901
10944
|
argsParsed = typeof item.arguments === "string" ? JSON.parse(item.arguments) : item.arguments;
|
|
10902
|
-
} catch (
|
|
10945
|
+
} catch (e8) {
|
|
10903
10946
|
logWarn(`Warning: Could not parse arguments JSON: ${item.arguments}`);
|
|
10904
10947
|
argsParsed = item.arguments;
|
|
10905
10948
|
}
|
|
@@ -10955,7 +10998,7 @@ var _BrowserAgent = class _BrowserAgent {
|
|
|
10955
10998
|
let argsParsed;
|
|
10956
10999
|
try {
|
|
10957
11000
|
argsParsed = typeof item.arguments === "string" ? JSON.parse(item.arguments) : item.arguments;
|
|
10958
|
-
} catch (
|
|
11001
|
+
} catch (e9) {
|
|
10959
11002
|
logWarn(
|
|
10960
11003
|
`Warning: Could not parse arguments JSON: ${item.arguments}`
|
|
10961
11004
|
);
|
|
@@ -12103,7 +12146,7 @@ var _Browser = class _Browser {
|
|
|
12103
12146
|
*/
|
|
12104
12147
|
async destroy() {
|
|
12105
12148
|
if (this.isInitialized()) {
|
|
12106
|
-
await this.session.callMcpTool("stopChrome", {});
|
|
12149
|
+
await this.session.callMcpTool("stopChrome", {}, false, "wuying_cdp_mcp_server");
|
|
12107
12150
|
} else {
|
|
12108
12151
|
throw new BrowserError("Browser is not initialized. Cannot destroy browser.");
|
|
12109
12152
|
}
|
|
@@ -12172,7 +12215,7 @@ var _Browser = class _Browser {
|
|
|
12172
12215
|
*/
|
|
12173
12216
|
_stopBrowser() {
|
|
12174
12217
|
if (this.isInitialized()) {
|
|
12175
|
-
this.session.callMcpTool("stopChrome", {});
|
|
12218
|
+
this.session.callMcpTool("stopChrome", {}, false, "wuying_cdp_mcp_server");
|
|
12176
12219
|
} else {
|
|
12177
12220
|
throw new BrowserError("Browser is not initialized. Cannot stop browser.");
|
|
12178
12221
|
}
|
|
@@ -12262,7 +12305,7 @@ var _Browser = class _Browser {
|
|
|
12262
12305
|
let errorStr;
|
|
12263
12306
|
try {
|
|
12264
12307
|
errorStr = String(error);
|
|
12265
|
-
} catch (
|
|
12308
|
+
} catch (e10) {
|
|
12266
12309
|
errorStr = "Unknown error occurred";
|
|
12267
12310
|
}
|
|
12268
12311
|
const errorMsg = `Failed to capture screenshot: ${errorStr}`;
|
|
@@ -12462,7 +12505,7 @@ var _Code = class _Code {
|
|
|
12462
12505
|
errorMessage: response.errorMessage
|
|
12463
12506
|
};
|
|
12464
12507
|
}
|
|
12465
|
-
} catch (
|
|
12508
|
+
} catch (e11) {
|
|
12466
12509
|
return {
|
|
12467
12510
|
requestId: response.requestId,
|
|
12468
12511
|
success: false,
|
|
@@ -12667,7 +12710,7 @@ var _Command = class _Command {
|
|
|
12667
12710
|
errorMessage: stderr || result.errorMessage
|
|
12668
12711
|
};
|
|
12669
12712
|
}
|
|
12670
|
-
} catch (
|
|
12713
|
+
} catch (e12) {
|
|
12671
12714
|
}
|
|
12672
12715
|
return {
|
|
12673
12716
|
requestId: result.requestId,
|
|
@@ -18760,6 +18803,13 @@ var _Session = class _Session {
|
|
|
18760
18803
|
body: JSON.stringify(payload)
|
|
18761
18804
|
});
|
|
18762
18805
|
if (!response.ok) {
|
|
18806
|
+
let bodyText = "";
|
|
18807
|
+
try {
|
|
18808
|
+
bodyText = await response.text();
|
|
18809
|
+
} catch (e13) {
|
|
18810
|
+
bodyText = "";
|
|
18811
|
+
}
|
|
18812
|
+
const bodyPreview = bodyText.length > 2e3 ? bodyText.slice(0, 2e3) + "...(truncated)" : bodyText;
|
|
18763
18813
|
logAPIResponseWithDetails(
|
|
18764
18814
|
"CallMcpTool(LinkUrl) Response",
|
|
18765
18815
|
requestId,
|
|
@@ -18768,7 +18818,7 @@ var _Session = class _Session {
|
|
|
18768
18818
|
http_status: response.status,
|
|
18769
18819
|
tool_name: toolName
|
|
18770
18820
|
},
|
|
18771
|
-
|
|
18821
|
+
bodyPreview
|
|
18772
18822
|
);
|
|
18773
18823
|
return {
|
|
18774
18824
|
success: false,
|
|
@@ -18918,7 +18968,7 @@ var _Session = class _Session {
|
|
|
18918
18968
|
}
|
|
18919
18969
|
}
|
|
18920
18970
|
/**
|
|
18921
|
-
* Asynchronously pause this session, putting it into a dormant state.
|
|
18971
|
+
* Asynchronously pause this session (beta), putting it into a dormant state.
|
|
18922
18972
|
*
|
|
18923
18973
|
* This method calls the PauseSessionAsync API to initiate the pause operation and then polls
|
|
18924
18974
|
* the GetSession API to check the session status until it becomes PAUSED or until timeout is reached.
|
|
@@ -18940,7 +18990,7 @@ var _Session = class _Session {
|
|
|
18940
18990
|
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
18941
18991
|
* const result = await agentBay.create();
|
|
18942
18992
|
* if (result.success) {
|
|
18943
|
-
* const pauseResult = await result.session.
|
|
18993
|
+
* const pauseResult = await result.session.betaPauseAsync();
|
|
18944
18994
|
* if (pauseResult.success) {
|
|
18945
18995
|
* console.log('Session paused successfully');
|
|
18946
18996
|
* }
|
|
@@ -18956,13 +19006,13 @@ var _Session = class _Session {
|
|
|
18956
19006
|
*
|
|
18957
19007
|
* **Important Notes:**
|
|
18958
19008
|
* - Paused sessions cannot perform operations (deletion, task execution, etc.)
|
|
18959
|
-
* - Use {@link
|
|
19009
|
+
* - Use {@link betaResumeAsync} to restore the session to RUNNING state
|
|
18960
19010
|
* - During pause, both resource usage and costs are lower
|
|
18961
19011
|
* - If timeout is exceeded, returns with success=false
|
|
18962
19012
|
*
|
|
18963
|
-
* @see {@link
|
|
19013
|
+
* @see {@link betaResumeAsync}
|
|
18964
19014
|
*/
|
|
18965
|
-
async
|
|
19015
|
+
async betaPauseAsync(timeout = 600, pollInterval = 2) {
|
|
18966
19016
|
try {
|
|
18967
19017
|
const request = new (0, _chunkQGXJA3GTcjs.PauseSessionAsyncRequest)({
|
|
18968
19018
|
authorization: `Bearer ${this.getAPIKey()}`,
|
|
@@ -19065,7 +19115,7 @@ var _Session = class _Session {
|
|
|
19065
19115
|
}
|
|
19066
19116
|
}
|
|
19067
19117
|
/**
|
|
19068
|
-
* Asynchronously resume this session from a paused state.
|
|
19118
|
+
* Asynchronously resume this session (beta) from a paused state.
|
|
19069
19119
|
*
|
|
19070
19120
|
* This method calls the ResumeSessionAsync API to initiate the resume operation and then polls
|
|
19071
19121
|
* the GetSession API to check the session status until it becomes RUNNING or until timeout is reached.
|
|
@@ -19087,7 +19137,7 @@ var _Session = class _Session {
|
|
|
19087
19137
|
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
19088
19138
|
* const result = await agentBay.get('paused_session_id');
|
|
19089
19139
|
* if (result.success) {
|
|
19090
|
-
* const resumeResult = await result.session.
|
|
19140
|
+
* const resumeResult = await result.session.betaResumeAsync();
|
|
19091
19141
|
* if (resumeResult.success) {
|
|
19092
19142
|
* console.log('Session resumed successfully');
|
|
19093
19143
|
* }
|
|
@@ -19104,12 +19154,12 @@ var _Session = class _Session {
|
|
|
19104
19154
|
* **Important Notes:**
|
|
19105
19155
|
* - Only sessions in PAUSED state can be resumed
|
|
19106
19156
|
* - After resume, the session can perform all operations normally
|
|
19107
|
-
* - Use {@link
|
|
19157
|
+
* - Use {@link betaPauseAsync} to put a session into PAUSED state
|
|
19108
19158
|
* - If timeout is exceeded, returns with success=false
|
|
19109
19159
|
*
|
|
19110
|
-
* @see {@link
|
|
19160
|
+
* @see {@link betaPauseAsync}
|
|
19111
19161
|
*/
|
|
19112
|
-
async
|
|
19162
|
+
async betaResumeAsync(timeout = 600, pollInterval = 2) {
|
|
19113
19163
|
try {
|
|
19114
19164
|
const request = new (0, _chunkQGXJA3GTcjs.ResumeSessionAsyncRequest)({
|
|
19115
19165
|
authorization: `Bearer ${this.getAPIKey()}`,
|
|
@@ -20218,8 +20268,8 @@ var _AgentBay = class _AgentBay {
|
|
|
20218
20268
|
* ```typescript
|
|
20219
20269
|
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
20220
20270
|
* const session = (await agentBay.create()).session;
|
|
20221
|
-
* const pauseResult = await agentBay.
|
|
20222
|
-
* await agentBay.
|
|
20271
|
+
* const pauseResult = await agentBay.betaPauseAsync(session);
|
|
20272
|
+
* await agentBay.betaResumeAsync(session);
|
|
20223
20273
|
* await session.delete();
|
|
20224
20274
|
* ```
|
|
20225
20275
|
*
|
|
@@ -20230,11 +20280,11 @@ var _AgentBay = class _AgentBay {
|
|
|
20230
20280
|
* - The session state transitions from RUNNING -> PAUSING -> PAUSED
|
|
20231
20281
|
* - Paused sessions consume fewer resources but maintain their state
|
|
20232
20282
|
*
|
|
20233
|
-
* @see {@link
|
|
20283
|
+
* @see {@link betaResumeAsync}, {@link Session.betaPauseAsync}
|
|
20234
20284
|
*/
|
|
20235
|
-
async
|
|
20285
|
+
async betaPauseAsync(session, timeout = 600, pollInterval = 2) {
|
|
20236
20286
|
try {
|
|
20237
|
-
return await session.
|
|
20287
|
+
return await session.betaPauseAsync(timeout, pollInterval);
|
|
20238
20288
|
} catch (error) {
|
|
20239
20289
|
logError("Error calling pause session async:", error);
|
|
20240
20290
|
return {
|
|
@@ -20259,8 +20309,8 @@ var _AgentBay = class _AgentBay {
|
|
|
20259
20309
|
* ```typescript
|
|
20260
20310
|
* const agentBay = new AgentBay({ apiKey: 'your_api_key' });
|
|
20261
20311
|
* const session = (await agentBay.create()).session;
|
|
20262
|
-
* await agentBay.
|
|
20263
|
-
* const resumeResult = await agentBay.
|
|
20312
|
+
* await agentBay.betaPauseAsync(session);
|
|
20313
|
+
* const resumeResult = await agentBay.betaResumeAsync(session);
|
|
20264
20314
|
* await session.delete();
|
|
20265
20315
|
* ```
|
|
20266
20316
|
*
|
|
@@ -20271,11 +20321,11 @@ var _AgentBay = class _AgentBay {
|
|
|
20271
20321
|
* - The session state transitions from PAUSED -> RESUMING -> RUNNING
|
|
20272
20322
|
* - Only sessions in PAUSED state can be resumed
|
|
20273
20323
|
*
|
|
20274
|
-
* @see {@link
|
|
20324
|
+
* @see {@link betaPauseAsync}, {@link Session.betaResumeAsync}
|
|
20275
20325
|
*/
|
|
20276
|
-
async
|
|
20326
|
+
async betaResumeAsync(session, timeout = 600, pollInterval = 2) {
|
|
20277
20327
|
try {
|
|
20278
|
-
return await session.
|
|
20328
|
+
return await session.betaResumeAsync(timeout, pollInterval);
|
|
20279
20329
|
} catch (error) {
|
|
20280
20330
|
logError("Error calling resume session async:", error);
|
|
20281
20331
|
return {
|