autoglm.js 0.0.8 → 0.0.10

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 (2) hide show
  1. package/dist/index.mjs +27 -16
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -1209,6 +1209,12 @@ function parseAction(actionStr) {
1209
1209
  };
1210
1210
  }
1211
1211
  if (actionStr.startsWith("do(")) {
1212
+ const typeMatch = actionStr.match(/do\(action="Type",\s*text=(.*)\)/s);
1213
+ if (typeMatch) return {
1214
+ _metadata: "do",
1215
+ action: "Type",
1216
+ text: parseQuotedString(typeMatch[1].trim()).trim()
1217
+ };
1212
1218
  const ast = parse(actionStr, { ecmaVersion: "latest" });
1213
1219
  if (ast.body[0].type !== "DoWhileStatement") throw new Error(`Invalid action format: ${actionStr}`);
1214
1220
  const expression = ast.body[0].body.expression;
@@ -1231,15 +1237,6 @@ function parseAction(actionStr) {
1231
1237
  element
1232
1238
  };
1233
1239
  }
1234
- if (actionType === "Type") {
1235
- const text = getText(expression);
1236
- if (!text) throw new Error(`Invalid Type action parameters: ${actionStr}`);
1237
- return {
1238
- _metadata: "do",
1239
- action: "Type",
1240
- text: text.trim()
1241
- };
1242
- }
1243
1240
  if (actionType === "Swipe") {
1244
1241
  const start = getElements(expression, 1);
1245
1242
  const end = getElements(expression, 2);
@@ -1298,6 +1295,17 @@ function parseAction(actionStr) {
1298
1295
  }
1299
1296
  throw new Error(`Unknown action format: ${actionStr}`);
1300
1297
  }
1298
+ /**
1299
+ * Parse a quoted string that may contain newlines and escape sequences.
1300
+ * Handles both single and double quotes.
1301
+ */
1302
+ function parseQuotedString(str) {
1303
+ if (!str) return "";
1304
+ const firstChar = str[0];
1305
+ const lastChar = str[str.length - 1];
1306
+ if (firstChar === "\"" && lastChar === "\"" || firstChar === "'" && lastChar === "'") return str.slice(1, -1);
1307
+ return str;
1308
+ }
1301
1309
 
1302
1310
  //#endregion
1303
1311
  //#region src/adb/types.ts
@@ -1616,6 +1624,13 @@ var ModelClient = class {
1616
1624
  }
1617
1625
  };
1618
1626
 
1627
+ //#endregion
1628
+ //#region src/utils/finishMessage.ts
1629
+ function getFinishMessage(result) {
1630
+ const actionMessage = result?.action?._metadata === "finish" ? result.action.message : void 0;
1631
+ return result?.message || actionMessage || result?.thinking || "Task completed";
1632
+ }
1633
+
1619
1634
  //#endregion
1620
1635
  //#region src/agent/index.ts
1621
1636
  var PhoneAgent = class {
@@ -1730,18 +1745,14 @@ var PhoneAgent = class {
1730
1745
  const result = await this.actionHandler.execute(action, screenshot.width, screenshot.height);
1731
1746
  this.context.push(MessageBuilder.createAssistantMessage(`<think>${response.thinking}</think><answer>${response.action}</answer>`));
1732
1747
  const finished = action._metadata === "finish" || result.should_finish;
1733
- if (finished) {
1734
- const actionMessage$1 = action._metadata === "finish" ? action.message : void 0;
1735
- const message = result.message || actionMessage$1 || "Task completed";
1736
- this.ctx.emit(EventType.TASK_COMPLETE, message);
1737
- }
1738
- const actionMessage = action._metadata === "finish" ? action.message : void 0;
1748
+ const message = getFinishMessage(result);
1749
+ if (finished) this.ctx.emit(EventType.TASK_COMPLETE, message);
1739
1750
  return {
1740
1751
  success: result.success,
1741
1752
  finished,
1742
1753
  action,
1743
1754
  thinking: response.thinking,
1744
- message: result.message || actionMessage
1755
+ message
1745
1756
  };
1746
1757
  } catch (error) {
1747
1758
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "autoglm.js",
3
3
  "type": "module",
4
- "version": "0.0.8",
4
+ "version": "0.0.10",
5
5
  "private": false,
6
6
  "description": "AutoGLM.js is a JavaScript library for Open-AutoGLM",
7
7
  "author": "FliPPeDround <flippedround@qq.com>",
@@ -49,9 +49,9 @@
49
49
  },
50
50
  "optionalDependencies": {
51
51
  "@autoglm.js/adb-keyboard": "0.0.1",
52
- "@autoglm.js/platform-tools-darwin": "36.0.0",
53
52
  "@autoglm.js/platform-tools-linux": "36.0.0",
54
- "@autoglm.js/platform-tools-windows": "36.0.0"
53
+ "@autoglm.js/platform-tools-windows": "36.0.0",
54
+ "@autoglm.js/platform-tools-darwin": "36.0.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/fs-extra": "^11.0.4",