@optima-chat/browser-cli 0.15.3 → 0.16.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 +28 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -354,10 +354,10 @@ var BrowserAPI = class {
354
354
  return this.getState(sessionId);
355
355
  }
356
356
  // Script methods
357
- async submitScript(name, code) {
357
+ async submitScript(name, files) {
358
358
  return request(`/api/scripts`, {
359
359
  method: "POST",
360
- body: JSON.stringify({ name, code })
360
+ body: JSON.stringify({ name, files })
361
361
  });
362
362
  }
363
363
  async updateScript(name, code) {
@@ -771,7 +771,7 @@ function registerTabCommands(program2) {
771
771
  }
772
772
 
773
773
  // src/commands/script.ts
774
- import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, statSync, writeFileSync as writeFileSync3 } from "fs";
774
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, readdirSync, statSync, writeFileSync as writeFileSync3 } from "fs";
775
775
  import { tmpdir } from "os";
776
776
  import { basename, dirname, isAbsolute, join as join3, relative, resolve } from "path";
777
777
  var POLL_INTERVAL_MS = 2e3;
@@ -887,7 +887,10 @@ function formatScriptTask(task) {
887
887
  }
888
888
  lines.push("");
889
889
  }
890
- lines.push("Session is still open \u2014 use browser-cli dom/click/input to continue");
890
+ const sid = task.session_id;
891
+ lines.push(
892
+ 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"
893
+ );
891
894
  } else if (task.status === "failed") {
892
895
  lines.push(`\u2717 Script failed: ${task.error ?? "unknown error"}`);
893
896
  } else {
@@ -895,11 +898,28 @@ function formatScriptTask(task) {
895
898
  }
896
899
  return lines.join("\n");
897
900
  }
901
+ function collectSkillDir(dir) {
902
+ const files = {};
903
+ for (const name of readdirSync(dir).sort()) {
904
+ if (!name.endsWith(".py")) continue;
905
+ if (name !== "script.py" && !name.startsWith("_")) continue;
906
+ if (!statSync(join3(dir, name)).isFile()) continue;
907
+ files[name] = readFileSync3(join3(dir, name), "utf-8");
908
+ }
909
+ if (files["script.py"] === void 0) throw new Error(`${dir} \u91CC\u6CA1\u6709 script.py`);
910
+ return files;
911
+ }
912
+ function resolveSubmitSource(opts) {
913
+ if (opts.codeFile && opts.codeDir) throw new Error("--code-file \u4E0E --code-dir \u53EA\u80FD\u7ED9\u4E00\u4E2A");
914
+ if (opts.codeDir) return collectSkillDir(opts.codeDir);
915
+ if (opts.codeFile) return { "script.py": readFileSync3(opts.codeFile, "utf-8") };
916
+ throw new Error("\u5FC5\u987B\u7ED9 --code-file \u6216 --code-dir");
917
+ }
898
918
  function registerScriptCommands(program2) {
899
- program2.command("submit-script").description("Submit a script (write to EFS)").requiredOption("--name <name>", "Script name").requiredOption("--code-file <path>", "Path to Python script file").action(async (opts) => {
919
+ program2.command("submit-script").description("Submit a script (write to EFS)").requiredOption("--name <name>", "Script name").option("--code-file <path>", "Path to Python script file (\u7B49\u4EF7\u4E8E\u300C\u53EA\u6709 script.py\u300D)").option("--code-dir <dir>", "Path to a skill directory (script.py + _*.py \u4E00\u8D77\u9001)").action(async (opts) => {
900
920
  try {
901
- const code = readFileSync3(opts.codeFile, "utf-8");
902
- const result = await api.submitScript(opts.name, code);
921
+ const files = resolveSubmitSource(opts);
922
+ const result = await api.submitScript(opts.name, files);
903
923
  console.log(`\u2713 Script ${result.name} ${result.created ? "created" : "updated"}`);
904
924
  } catch (err) {
905
925
  console.error(formatError(err));
@@ -990,6 +1010,7 @@ ${downloadHint(result)}`);
990
1010
  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) => {
991
1011
  try {
992
1012
  const task = await api.getScriptTask(taskId);
1013
+ if (task.status === "needs_fallback" && task.session_id) saveSessionId(task.session_id);
993
1014
  if (opts.download === void 0) {
994
1015
  console.log(formatScriptTask(task));
995
1016
  if (hasStagedArtifact(task)) console.log(downloadHint(task));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optima-chat/browser-cli",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "bin": {