@optima-chat/browser-cli 0.9.0 → 0.10.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 +33 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -257,7 +257,14 @@ var BrowserAPI = class {
|
|
|
257
257
|
const deadline = Date.now() + timeoutMs;
|
|
258
258
|
for (; ; ) {
|
|
259
259
|
const task = await request(`/api/script-tasks/${started.id}`);
|
|
260
|
-
if (task.status === "completed")
|
|
260
|
+
if (task.status === "completed") {
|
|
261
|
+
if (!task.output) {
|
|
262
|
+
throw new Error(
|
|
263
|
+
`recipe ${name} reported completed but returned no output (task ${started.id})`
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
return task.output;
|
|
267
|
+
}
|
|
261
268
|
if (task.status === "failed" || task.status === "needs_fallback") {
|
|
262
269
|
throw new Error(task.error || task.output?.error || `recipe ${task.status}`);
|
|
263
270
|
}
|
|
@@ -339,6 +346,12 @@ var BrowserAPI = class {
|
|
|
339
346
|
async getScriptTask(taskId) {
|
|
340
347
|
return request(`/api/script-tasks/${taskId}`);
|
|
341
348
|
}
|
|
349
|
+
async sendFile(src, dest) {
|
|
350
|
+
return request("/api/files/send", {
|
|
351
|
+
method: "POST",
|
|
352
|
+
body: JSON.stringify({ src, dest })
|
|
353
|
+
});
|
|
354
|
+
}
|
|
342
355
|
};
|
|
343
356
|
var api = new BrowserAPI();
|
|
344
357
|
|
|
@@ -1031,6 +1044,11 @@ async function runExport(script, params, out, timeoutMs) {
|
|
|
1031
1044
|
const outPath = resolve2(out);
|
|
1032
1045
|
const result = await api.runRecipeScript(script, { ...params, out_path: outPath }, 2e3, timeoutMs);
|
|
1033
1046
|
if (!result.path) {
|
|
1047
|
+
if (!result.artifact_path) {
|
|
1048
|
+
throw new Error(
|
|
1049
|
+
`Script ${script} finished but delivered no file \u2014 no workspace path and no staged artifact. Nothing was written to ${outPath}.`
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1034
1052
|
writeFileSync4(outPath, await api.fetchArtifact(result.artifact_path));
|
|
1035
1053
|
}
|
|
1036
1054
|
console.log(`Saved ${result.filename} -> ${outPath} (${result.size} bytes)`);
|
|
@@ -1086,6 +1104,19 @@ function registerBitBrowserCommands(program2) {
|
|
|
1086
1104
|
});
|
|
1087
1105
|
}
|
|
1088
1106
|
|
|
1107
|
+
// src/commands/files.ts
|
|
1108
|
+
function registerFileCommands(program2) {
|
|
1109
|
+
program2.command("send-file").description("Send a file from your workspace to your local download folder").requiredOption("--src <path>", "Source path in your workspace (e.g. ~/output/report.pdf)").requiredOption("--dest <path>", "Destination path relative to the download folder").action(async (opts) => {
|
|
1110
|
+
try {
|
|
1111
|
+
const result = await api.sendFile(opts.src, opts.dest);
|
|
1112
|
+
console.log(result.local_path);
|
|
1113
|
+
} catch (err) {
|
|
1114
|
+
console.error(formatError(err));
|
|
1115
|
+
process.exit(1);
|
|
1116
|
+
}
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1089
1120
|
// src/index.ts
|
|
1090
1121
|
var require2 = createRequire(import.meta.url);
|
|
1091
1122
|
var { version } = require2("../package.json");
|
|
@@ -1106,4 +1137,5 @@ registerScriptCommands(program);
|
|
|
1106
1137
|
registerZiNiaoCommands(program);
|
|
1107
1138
|
registerRecipeCommands(program);
|
|
1108
1139
|
registerBitBrowserCommands(program);
|
|
1140
|
+
registerFileCommands(program);
|
|
1109
1141
|
program.parse();
|