autoglm.js 0.0.10 → 0.0.12

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 +17 -9
  2. package/package.json +3 -3
package/dist/index.mjs CHANGED
@@ -350,7 +350,7 @@ const SYSTEM_PROMPT_ZH = `今天的日期是: ${formatted_date}
350
350
  - do(action="Wait", duration="x seconds")
351
351
  等待页面加载,x为需要等待多少秒。
352
352
  - finish(message="xxx")
353
- finish是结束任务的操作,表示准确完整完成任务,message是终止信息。
353
+ finish是结束任务的操作,表示准确完整完成任务,message参数是任务完成后的总结信息,必须简洁明了地说明执行结果。
354
354
 
355
355
  必须遵循的规则:
356
356
  1. 在执行任何操作前,先检查当前app是否是目标app,如果不是,先执行 Launch。
@@ -1178,7 +1178,7 @@ var ActionHandler = class {
1178
1178
  return {
1179
1179
  success: false,
1180
1180
  should_finish: true,
1181
- message: `Takeover requested but no callback provided: ${action.reason}`
1181
+ message: action.reason
1182
1182
  };
1183
1183
  }
1184
1184
  };
@@ -1202,10 +1202,14 @@ function getActionType(node) {
1202
1202
  */
1203
1203
  function parseAction(actionStr) {
1204
1204
  if (actionStr.startsWith("finish(")) {
1205
- const match = actionStr.match(/finish\(message=(.*)\)/);
1206
- return {
1205
+ const match = actionStr.match(/finish\(message=(.*)\)/s);
1206
+ if (match) return {
1207
+ _metadata: "finish",
1208
+ message: parseQuotedString(match[1].trim())
1209
+ };
1210
+ else return {
1207
1211
  _metadata: "finish",
1208
- message: match ? match[1].trim() : void 0
1212
+ message: void 0
1209
1213
  };
1210
1214
  }
1211
1215
  if (actionStr.startsWith("do(")) {
@@ -1640,6 +1644,7 @@ var PhoneAgent = class {
1640
1644
  context = [];
1641
1645
  stepCount = 0;
1642
1646
  abortController = null;
1647
+ externalSignal;
1643
1648
  isAborted = false;
1644
1649
  constructor(context, confirmationCallback, takeoverCallback) {
1645
1650
  this.ctx = context;
@@ -1672,9 +1677,7 @@ var PhoneAgent = class {
1672
1677
  }
1673
1678
  this.abortController = new AbortController();
1674
1679
  this.isAborted = false;
1675
- if (signal) signal.addEventListener("abort", () => {
1676
- this.abort(signal.reason || "External signal aborted");
1677
- });
1680
+ this.externalSignal = signal;
1678
1681
  try {
1679
1682
  this.reset();
1680
1683
  let result = await this._executeStep(task, true);
@@ -1687,6 +1690,7 @@ var PhoneAgent = class {
1687
1690
  throw new Error("Max steps reached");
1688
1691
  } finally {
1689
1692
  this.abortController = null;
1693
+ this.externalSignal = void 0;
1690
1694
  }
1691
1695
  }
1692
1696
  /**
@@ -1733,7 +1737,11 @@ var PhoneAgent = class {
1733
1737
  this.context.push(MessageBuilder.createUserMessage(textContent, screenshot.base64Data));
1734
1738
  }
1735
1739
  try {
1736
- const response = await this.modelClient.request(this.context, { signal: this.abortController?.signal });
1740
+ const signals = [new AbortController().signal];
1741
+ if (this.abortController) signals.push(this.abortController.signal);
1742
+ if (this.externalSignal) signals.push(this.externalSignal);
1743
+ const combinedSignal = AbortSignal.any(signals);
1744
+ const response = await this.modelClient.request(this.context, { signal: combinedSignal });
1737
1745
  let action;
1738
1746
  try {
1739
1747
  action = parseAction(response.action);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "autoglm.js",
3
3
  "type": "module",
4
- "version": "0.0.10",
4
+ "version": "0.0.12",
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",
52
53
  "@autoglm.js/platform-tools-linux": "36.0.0",
53
- "@autoglm.js/platform-tools-windows": "36.0.0",
54
- "@autoglm.js/platform-tools-darwin": "36.0.0"
54
+ "@autoglm.js/platform-tools-windows": "36.0.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/fs-extra": "^11.0.4",