@optima-chat/browser-cli 0.17.0 → 0.18.0

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.js +59 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -823,6 +823,34 @@ function formatScriptList(scripts) {
823
823
  }
824
824
  return lines.join("\n").trimEnd();
825
825
  }
826
+ var HALT_RENDERED_ELSEWHERE = /* @__PURE__ */ new Set(["completed_steps", "remaining_steps", "error"]);
827
+ var ARTIFACT_KEYS = /* @__PURE__ */ new Set(["artifact_path", "filename", "size"]);
828
+ var FIELD_MAX_CHARS = 2e3;
829
+ function formatFieldValue(v, taskId) {
830
+ if (v === null || v === void 0 || v === "") return null;
831
+ const s = typeof v === "string" ? v : typeof v === "number" || typeof v === "boolean" ? String(v) : JSON.stringify(v);
832
+ const cps = Array.from(s);
833
+ return cps.length > FIELD_MAX_CHARS ? `${cps.slice(0, FIELD_MAX_CHARS).join("")}\u2026 (truncated, ${cps.length} chars; full: browser-cli script-task ${taskId} --json)` : s;
834
+ }
835
+ function haltOutputFields(task) {
836
+ const output = task.output ?? {};
837
+ const staged = typeof output.artifact_path === "string" && output.artifact_path !== "";
838
+ const lines = [];
839
+ for (const [k, v] of Object.entries(output)) {
840
+ if (HALT_RENDERED_ELSEWHERE.has(k)) continue;
841
+ if (staged && ARTIFACT_KEYS.has(k)) continue;
842
+ if (k === "snapshot") {
843
+ if (v !== null && v !== void 0 && v !== "") {
844
+ const n = Array.from(typeof v === "string" ? v : JSON.stringify(v)).length;
845
+ lines.push(`snapshot: (omitted, ${n} chars; full: browser-cli script-task ${task.id} --json)`);
846
+ }
847
+ continue;
848
+ }
849
+ const s = formatFieldValue(v, task.id);
850
+ if (s !== null) lines.push(`${k}: ${s}`);
851
+ }
852
+ return lines;
853
+ }
826
854
  function formatScriptTask(task) {
827
855
  const lines = [];
828
856
  if (task.status === "completed") {
@@ -860,12 +888,27 @@ function formatScriptTask(task) {
860
888
  }
861
889
  lines.push("");
862
890
  }
891
+ const fields = haltOutputFields(task);
892
+ if (fields.length > 0) {
893
+ lines.push(...fields);
894
+ lines.push("");
895
+ }
863
896
  const sid = task.session_id;
864
897
  lines.push(
865
898
  sid ? `Session ${sid} may still be open \u2014 continue with browser-cli --session ${sid} dom/click/input, or free it with browser-cli --session ${sid} close` : "Session id not reported \u2014 if one remains, close it by id: browser-cli --session <id> close"
866
899
  );
867
900
  } else if (task.status === "failed") {
868
901
  lines.push(`\u2717 Script failed: ${task.error ?? "unknown error"}`);
902
+ const output = task.output ?? {};
903
+ const completed = output.completed_steps ?? [];
904
+ const remaining = output.remaining_steps ?? [];
905
+ if (completed.length > 0) {
906
+ lines.push(`\u2713 Completed: ${completed.map((s) => s.id).join(", ")}`);
907
+ }
908
+ if (remaining.length > 0) {
909
+ lines.push(`\u2717 Stopped at step [${completed.length + 1}] ${remaining[0].id}`);
910
+ }
911
+ lines.push(...haltOutputFields(task));
869
912
  } else {
870
913
  lines.push(`Script status: ${task.status} (step ${task.current_step}/${task.total_steps})`);
871
914
  }
@@ -980,10 +1023,17 @@ ${downloadHint(result)}`);
980
1023
  process.exit(1);
981
1024
  }
982
1025
  });
983
- program2.command("script-task").argument("<task-id>", "Task ID").description("Check script task status").option("--download [path]", "Save the task's exported file (default: ./<filename>)").action(async (taskId, opts) => {
1026
+ program2.command("script-task").argument("<task-id>", "Task ID").description("Check script task status").option("--download [path]", "Save the task's exported file (default: ./<filename>)").option("--json", "Print the raw task (status / error / full output) as JSON").action(async (taskId, opts) => {
984
1027
  try {
1028
+ if (opts.json && opts.download !== void 0) {
1029
+ throw new Error("--json \u4E0E --download \u53EA\u80FD\u7ED9\u4E00\u4E2A");
1030
+ }
985
1031
  const task = await api.getScriptTask(taskId);
986
1032
  if (task.status === "needs_fallback" && task.session_id) saveSessionId(task.session_id);
1033
+ if (opts.json) {
1034
+ console.log(JSON.stringify(task, null, 2));
1035
+ return;
1036
+ }
987
1037
  if (opts.download === void 0) {
988
1038
  console.log(formatScriptTask(task));
989
1039
  if (hasStagedArtifact(task)) console.log(downloadHint(task));
@@ -1018,16 +1068,20 @@ var BOSS_GUIDANCE = [
1018
1068
  " 3. \u4E3A\u8BE5\u8D26\u53F7\u6388\u6743\u9700\u8981\u64CD\u4F5C\u7684\u5E97\u94FA\u3002",
1019
1069
  `\u53C2\u8003\u6587\u6863: ${ZINIAO_WEBDRIVER_DOC_URL}`
1020
1070
  ].join("\n");
1071
+ var SELF_EXPLANATORY = /正在运行.{0,4}但未开启\s*WebDriver\s*模式/;
1072
+ var NOT_READY_HINT = "\u7D2B\u9E1F\u6CA1\u80FD\u5728 15 \u79D2\u5185\u8FDB\u5165 WebDriver \u6A21\u5F0F\uFF08\u4E0D\u662F\u6743\u9650\u95EE\u9898\uFF09\u3002\u2460 \u5148\u786E\u8BA4\u7D2B\u9E1F\u5DF2**\u5B8C\u5168\u9000\u51FA**\uFF08\u542B\u6258\u76D8/\u540E\u53F0\u8FDB\u7A0B\uFF09\u2014\u2014 \u5B83\u4EE5\u666E\u901A\u6A21\u5F0F\u8DD1\u7740\u65F6\u6211\u4EEC\u8D77\u4E0D\u4E86 WebDriver \u6A21\u5F0F\uFF1B\u2461 \u7136\u540E\u8BA9\u6211\u8FD9\u8FB9\u518D\u62C9\u4E00\u6B21\uFF08Windows \u4E0A\u82E5\u5B89\u88C5\u8DEF\u5F84\u662F\u63A2\u6D4B\u6765\u7684\uFF0C\u5931\u8D25\u90A3\u6B21\u4F1A\u6E05\u6389\u5B83\u5E76\u91CD\u67E5\u6CE8\u518C\u8868\uFF0C\u7B2C\u4E8C\u6B21\u5E38\u5E38\u5C31\u6210\uFF09\uFF1B\u2462 \u8FD8\u4E0D\u884C\u5C31\u95EE\u5E97\u4E3B\uFF1A\u7D2B\u9E1F\u88C5\u5728\u54EA\u3001\u662F\u4E0D\u662F\u8FD8\u88C5\u7740\u3002";
1021
1073
  function ziniaoErrorHint(message) {
1022
- if (/webdriver|开通|权限|permission/i.test(message)) {
1023
- return `\u7591\u4F3C\u672A\u5F00\u901A Webdriver \u6743\u9650\u6216\u8D26\u53F7\u6743\u9650\u4E0D\u8DB3\u3002${BOSS_GUIDANCE}`;
1024
- }
1074
+ if (SELF_EXPLANATORY.test(message)) return null;
1075
+ if (/Failed to start ZiNiao WebDriver/i.test(message)) return NOT_READY_HINT;
1025
1076
  if (/错误次数太多/.test(message)) {
1026
1077
  return "\u7D2B\u9E1F\u98CE\u63A7\u5DF2\u4E34\u65F6\u9501\u5B9A\uFF0C\u8BF7\u7B49\u5F85\u7EA6 10 \u5206\u949F\u540E\u91CD\u8BD5\uFF08\u7EE7\u7EED\u5931\u8D25\u4F1A\u5EF6\u957F\u9501\u5B9A\uFF09\u3002";
1027
1078
  }
1028
1079
  if (/用户名或密码错误|密码错误/.test(message)) {
1029
1080
  return "\u8BF7\u6838\u5BF9\u51ED\u636E\uFF08company=\u4F01\u4E1A\u540D\u79F0\uFF0Cusername/password=\u6210\u5458\u8D26\u53F7\uFF0C\u63A8\u8350 robot \u8D26\u53F7\uFF09\uFF0C\u7136\u540E\u7528 browser-cli ziniao set \u91CD\u65B0\u914D\u7F6E\u3002";
1030
1081
  }
1082
+ if (/开通|权限|permission|授权|未开启|未启用|not enabled/i.test(message)) {
1083
+ return `\u7591\u4F3C\u672A\u5F00\u901A Webdriver \u6743\u9650\u6216\u8D26\u53F7\u6743\u9650\u4E0D\u8DB3\u3002${BOSS_GUIDANCE}`;
1084
+ }
1031
1085
  return null;
1032
1086
  }
1033
1087
  async function runZiNiaoDoctor(client) {
@@ -1265,7 +1319,7 @@ function registerFeikuaCommands(program2) {
1265
1319
  return;
1266
1320
  }
1267
1321
  console.log(
1268
- 'No paired shop browsers. Open the desktop app tray and choose "Pair a Shop Browser", then follow the on-screen code.'
1322
+ 'No paired shop browsers. In the desktop app tray, click \u300C\u914D\u5BF9\u98DE\u8DE8\u6D4F\u89C8\u5668\u2026\u300D/ "Pair a Feikua Browser\u2026" (older desktop versions: \u300C\u914D\u5BF9\u65B0\u5E97\u94FA\u6D4F\u89C8\u5668\u2026\u300D/ "Pair a Shop Browser\u2026"), then follow the on-screen code.'
1269
1323
  );
1270
1324
  return;
1271
1325
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/browser-cli",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {