@optima-chat/browser-cli 0.15.4 → 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.
- package/dist/index.js +23 -6
- 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,
|
|
357
|
+
async submitScript(name, files) {
|
|
358
358
|
return request(`/api/scripts`, {
|
|
359
359
|
method: "POST",
|
|
360
|
-
body: JSON.stringify({ name,
|
|
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;
|
|
@@ -898,11 +898,28 @@ function formatScriptTask(task) {
|
|
|
898
898
|
}
|
|
899
899
|
return lines.join("\n");
|
|
900
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
|
+
}
|
|
901
918
|
function registerScriptCommands(program2) {
|
|
902
|
-
program2.command("submit-script").description("Submit a script (write to EFS)").requiredOption("--name <name>", "Script name").
|
|
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) => {
|
|
903
920
|
try {
|
|
904
|
-
const
|
|
905
|
-
const result = await api.submitScript(opts.name,
|
|
921
|
+
const files = resolveSubmitSource(opts);
|
|
922
|
+
const result = await api.submitScript(opts.name, files);
|
|
906
923
|
console.log(`\u2713 Script ${result.name} ${result.created ? "created" : "updated"}`);
|
|
907
924
|
} catch (err) {
|
|
908
925
|
console.error(formatError(err));
|