wuying-agentbay-sdk 0.10.0 → 0.10.2

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 CHANGED
@@ -556,19 +556,10 @@ function getVersionFromPackageJson() {
556
556
  }
557
557
  _chunk4IPTHWLMcjs.__name.call(void 0, getVersionFromPackageJson, "getVersionFromPackageJson");
558
558
  function isReleaseBuild() {
559
- if (process.env.GITHUB_ACTIONS !== "true") {
560
- return false;
561
- }
562
- const workflow = process.env.GITHUB_WORKFLOW || "";
563
- if (workflow.includes("Build and Publish to npm")) {
564
- return true;
565
- }
566
- if (process.env.AGENTBAY_RELEASE_BUILD === "true") {
567
- return true;
568
- }
569
- return false;
559
+ return __AGENTBAY_IS_RELEASE_BUILD__;
570
560
  }
571
561
  _chunk4IPTHWLMcjs.__name.call(void 0, isReleaseBuild, "isReleaseBuild");
562
+ var __AGENTBAY_IS_RELEASE_BUILD__ = true;
572
563
  var VERSION = getVersionFromPackageJson();
573
564
  var IS_RELEASE = isReleaseBuild();
574
565
 
@@ -1080,6 +1071,7 @@ var _CallMcpToolRequest = class _CallMcpToolRequest extends $dara16.Model {
1080
1071
  return {
1081
1072
  args: "Args",
1082
1073
  authorization: "Authorization",
1074
+ autoGenSession: "AutoGenSession",
1083
1075
  externalUserId: "ExternalUserId",
1084
1076
  imageId: "ImageId",
1085
1077
  name: "Name",
@@ -1092,6 +1084,7 @@ var _CallMcpToolRequest = class _CallMcpToolRequest extends $dara16.Model {
1092
1084
  return {
1093
1085
  args: "string",
1094
1086
  authorization: "string",
1087
+ autoGenSession: "boolean",
1095
1088
  externalUserId: "string",
1096
1089
  imageId: "string",
1097
1090
  name: "string",
@@ -3442,6 +3435,9 @@ var _Client = class _Client extends _openapicore2.default {
3442
3435
  if (!$dara84.isNull(request.authorization)) {
3443
3436
  body["Authorization"] = request.authorization;
3444
3437
  }
3438
+ if (!$dara84.isNull(request.autoGenSession)) {
3439
+ body["AutoGenSession"] = request.autoGenSession;
3440
+ }
3445
3441
  if (!$dara84.isNull(request.externalUserId)) {
3446
3442
  body["ExternalUserId"] = request.externalUserId;
3447
3443
  }
@@ -9092,6 +9088,31 @@ _chunk4IPTHWLMcjs.init_cjs_shims.call(void 0, );
9092
9088
 
9093
9089
  // src/mobile/mobile.ts
9094
9090
  _chunk4IPTHWLMcjs.init_cjs_shims.call(void 0, );
9091
+ function parseBoundsString(boundsStr) {
9092
+ const parts = boundsStr.split(",");
9093
+ if (parts.length !== 4) {
9094
+ return null;
9095
+ }
9096
+ const [left, top, right, bottom] = parts.map((p) => parseInt(p.trim(), 10));
9097
+ if (isNaN(left) || isNaN(top) || isNaN(right) || isNaN(bottom)) {
9098
+ return null;
9099
+ }
9100
+ return { left, top, right, bottom };
9101
+ }
9102
+ _chunk4IPTHWLMcjs.__name.call(void 0, parseBoundsString, "parseBoundsString");
9103
+ function normalizeUIElement(element) {
9104
+ if (element.bounds && typeof element.bounds === "string") {
9105
+ const parsedBounds = parseBoundsString(element.bounds);
9106
+ if (parsedBounds) {
9107
+ element.bounds = parsedBounds;
9108
+ }
9109
+ }
9110
+ if (element.children && Array.isArray(element.children)) {
9111
+ element.children = element.children.map(normalizeUIElement);
9112
+ }
9113
+ return element;
9114
+ }
9115
+ _chunk4IPTHWLMcjs.__name.call(void 0, normalizeUIElement, "normalizeUIElement");
9095
9116
  var _Mobile = class _Mobile {
9096
9117
  constructor(session) {
9097
9118
  this.session = session;
@@ -9209,11 +9230,12 @@ var _Mobile = class _Mobile {
9209
9230
  }
9210
9231
  try {
9211
9232
  const elements = JSON.parse(result.data);
9233
+ const normalizedElements = (elements || []).map(normalizeUIElement);
9212
9234
  return {
9213
9235
  success: true,
9214
9236
  requestId: result.requestId || "",
9215
9237
  errorMessage: "",
9216
- elements: elements || []
9238
+ elements: normalizedElements
9217
9239
  };
9218
9240
  } catch (parseError) {
9219
9241
  return {
@@ -9257,11 +9279,12 @@ var _Mobile = class _Mobile {
9257
9279
  }
9258
9280
  try {
9259
9281
  const elements = JSON.parse(result.data);
9282
+ const normalizedElements = (elements || []).map(normalizeUIElement);
9260
9283
  return {
9261
9284
  success: true,
9262
9285
  requestId: result.requestId || "",
9263
9286
  errorMessage: "",
9264
- elements: elements || []
9287
+ elements: normalizedElements
9265
9288
  };
9266
9289
  } catch (parseError) {
9267
9290
  return {
@@ -9377,12 +9400,12 @@ var _Mobile = class _Mobile {
9377
9400
  }
9378
9401
  }
9379
9402
  /**
9380
- * Stop app by package name.
9403
+ * Stop app by command.
9381
9404
  */
9382
- async stopAppByPName(pname) {
9383
- const args = { pname };
9405
+ async stopAppByCmd(stopCmd) {
9406
+ const args = { stop_cmd: stopCmd };
9384
9407
  try {
9385
- const result = await this.session.callMcpTool("stop_app_by_pname", args);
9408
+ const result = await this.session.callMcpTool("stop_app_by_cmd", args);
9386
9409
  return {
9387
9410
  success: result.success || false,
9388
9411
  requestId: result.requestId || "",
@@ -10826,9 +10849,10 @@ var _Session = class _Session {
10826
10849
  *
10827
10850
  * @param toolName - Name of the MCP tool to call
10828
10851
  * @param args - Arguments to pass to the tool
10852
+ * @param autoGenSession - Whether to automatically generate session if not exists (default: false)
10829
10853
  * @returns McpToolResult containing the response data
10830
10854
  */
10831
- async callMcpTool(toolName, args) {
10855
+ async callMcpTool(toolName, args, autoGenSession = false) {
10832
10856
  try {
10833
10857
  const argsJSON = JSON.stringify(args);
10834
10858
  if (this.isVpcEnabled()) {
@@ -10906,7 +10930,8 @@ var _Session = class _Session {
10906
10930
  authorization: `Bearer ${this.getAPIKey()}`,
10907
10931
  sessionId: this.getSessionId(),
10908
10932
  name: toolName,
10909
- args: argsJSON
10933
+ args: argsJSON,
10934
+ autoGenSession
10910
10935
  });
10911
10936
  const response = await this.getClient().callMcpTool(callToolRequest);
10912
10937
  if (!_optionalChain([response, 'access', _121 => _121.body, 'optionalAccess', _122 => _122.data])) {
@@ -11721,6 +11746,14 @@ var _AgentBay = class _AgentBay {
11721
11746
  session.token = getResult.data.token;
11722
11747
  session.resourceUrl = getResult.data.resourceUrl;
11723
11748
  }
11749
+ const contextName = `file-transfer-context-${Date.now()}`;
11750
+ const contextResult = await this.context.get(contextName, true);
11751
+ if (contextResult.success && contextResult.context) {
11752
+ session.fileTransferContextId = contextResult.context.id;
11753
+ logInfo(`\u{1F4C1} Created file transfer context for recovered session: ${contextResult.context.id}`);
11754
+ } else {
11755
+ logError(`\u26A0\uFE0F Failed to create file transfer context for recovered session: ${contextResult.errorMessage || "Unknown error"}`);
11756
+ }
11724
11757
  return {
11725
11758
  requestId: getResult.requestId,
11726
11759
  success: true,