@erdoai/cli 0.262.0 → 0.264.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 +73 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2472,6 +2472,23 @@ var ErdoClient = class {
|
|
|
2472
2472
|
listKnowledgeAssets(objectID) {
|
|
2473
2473
|
return this.request("GET", `/v1/knowledge/${encodeURIComponent(objectID)}/attachments`);
|
|
2474
2474
|
}
|
|
2475
|
+
uploadFile(input) {
|
|
2476
|
+
return this.request("POST", "/v1/files", input);
|
|
2477
|
+
}
|
|
2478
|
+
listFiles(options) {
|
|
2479
|
+
const params = new URLSearchParams();
|
|
2480
|
+
for (const key of ["limit", "offset", "source", "media_type", "query"]) {
|
|
2481
|
+
const value = options?.[key];
|
|
2482
|
+
if (value !== void 0 && value !== "") params.set(key, String(value));
|
|
2483
|
+
}
|
|
2484
|
+
return this.request("GET", `/v1/files${params.size ? `?${params}` : ""}`);
|
|
2485
|
+
}
|
|
2486
|
+
getFile(id) {
|
|
2487
|
+
return this.request("GET", `/v1/files/${encodeURIComponent(id)}`);
|
|
2488
|
+
}
|
|
2489
|
+
deleteFile(id) {
|
|
2490
|
+
return this.request("DELETE", `/v1/files/${encodeURIComponent(id)}`);
|
|
2491
|
+
}
|
|
2475
2492
|
// --- automations ---
|
|
2476
2493
|
listHeartbeats(opts = {}) {
|
|
2477
2494
|
const params = new URLSearchParams();
|
|
@@ -11573,6 +11590,62 @@ declarationsCmd.command("upsert").description("Write one declaration. The same n
|
|
|
11573
11590
|
}
|
|
11574
11591
|
});
|
|
11575
11592
|
var knowledgeCmd = program.command("knowledge").description("Knowledge objects");
|
|
11593
|
+
var filesCmd = program.command("files").description("Organization files");
|
|
11594
|
+
filesCmd.command("upload [path]").description("Upload a local file or download a public URL into the selected organization").option("--url <url>", "HTTP(S) source URL (downloaded by the service)").option("--filename <name>", "filename for a URL download").option("--source-ref <ref>", "stable retry target; the same bytes and ref return the existing file").option("--source <source>", "provenance: upload, download, generated, screenshot, code_output, email, or attachment_backfill").option("--access <access>", "org or private", "org").action(async (path, opts) => {
|
|
11595
|
+
try {
|
|
11596
|
+
if (Boolean(opts.url) === Boolean(path)) throw new Error("provide exactly one local path or --url");
|
|
11597
|
+
if (!(opts.access === "org" || opts.access === "private")) throw new Error("--access must be org or private");
|
|
11598
|
+
let input;
|
|
11599
|
+
if (opts.url) {
|
|
11600
|
+
const sourceURL = new URL(opts.url);
|
|
11601
|
+
if (!["http:", "https:"].includes(sourceURL.protocol) || sourceURL.username || sourceURL.password) throw new Error("--url must be an HTTP(S) URL without credentials");
|
|
11602
|
+
let filename = opts.filename;
|
|
11603
|
+
if (!filename) {
|
|
11604
|
+
try {
|
|
11605
|
+
filename = basename2(decodeURIComponent(sourceURL.pathname));
|
|
11606
|
+
} catch {
|
|
11607
|
+
filename = basename2(sourceURL.pathname);
|
|
11608
|
+
}
|
|
11609
|
+
}
|
|
11610
|
+
if (!filename || filename === "/") throw new Error("provide --filename when the URL has no filename");
|
|
11611
|
+
input = { filename: basename2(filename), source_url: opts.url, source: opts.source ?? "download", access: opts.access };
|
|
11612
|
+
} else {
|
|
11613
|
+
if (!path) throw new Error("provide a local path or --url");
|
|
11614
|
+
if (statSync2(path).size > 50 * 1024 * 1024) throw new Error("file exceeds the 50 MiB limit");
|
|
11615
|
+
const bytes = readFileSync5(path);
|
|
11616
|
+
if (!bytes.length) throw new Error("file is empty");
|
|
11617
|
+
if (bytes.length > 50 * 1024 * 1024) throw new Error("file exceeds the 50 MiB limit");
|
|
11618
|
+
input = { filename: basename2(path), content_base64: bytes.toString("base64"), source: opts.source ?? "upload", access: opts.access };
|
|
11619
|
+
}
|
|
11620
|
+
if (opts.sourceRef) input.source_ref = opts.sourceRef;
|
|
11621
|
+
print(await new ErdoClient().uploadFile(input));
|
|
11622
|
+
} catch (e) {
|
|
11623
|
+
fail(e);
|
|
11624
|
+
}
|
|
11625
|
+
});
|
|
11626
|
+
filesCmd.command("list").description("List files in the selected organization").option("--limit <n>", "page size (default 50, maximum 100)", (v) => parseInt(v, 10)).option("--offset <n>", "page offset", (v) => parseInt(v, 10)).option("--source <source>", "filter by source").option("--media-type <type>", "filter by media type").option("--query <text>", "search filenames").action(async (opts) => {
|
|
11627
|
+
try {
|
|
11628
|
+
if (opts.limit !== void 0 && (!Number.isInteger(opts.limit) || opts.limit < 1 || opts.limit > 100)) throw new Error("--limit must be an integer from 1 to 100");
|
|
11629
|
+
if (opts.offset !== void 0 && (!Number.isInteger(opts.offset) || opts.offset < 0)) throw new Error("--offset must be a non-negative integer");
|
|
11630
|
+
print(await new ErdoClient().listFiles({ limit: opts.limit, offset: opts.offset, source: opts.source, media_type: opts.mediaType, query: opts.query }));
|
|
11631
|
+
} catch (e) {
|
|
11632
|
+
fail(e);
|
|
11633
|
+
}
|
|
11634
|
+
});
|
|
11635
|
+
filesCmd.command("get <id>").description("Get file metadata and a short-lived signed URL").action(async (id) => {
|
|
11636
|
+
try {
|
|
11637
|
+
print(await new ErdoClient().getFile(id));
|
|
11638
|
+
} catch (e) {
|
|
11639
|
+
fail(e);
|
|
11640
|
+
}
|
|
11641
|
+
});
|
|
11642
|
+
filesCmd.command("delete <id>").description("Delete a file and its bytes").action(async (id) => {
|
|
11643
|
+
try {
|
|
11644
|
+
print(await new ErdoClient().deleteFile(id));
|
|
11645
|
+
} catch (e) {
|
|
11646
|
+
fail(e);
|
|
11647
|
+
}
|
|
11648
|
+
});
|
|
11576
11649
|
knowledgeCmd.command("create").description("Create a Knowledge object").requiredOption("--title <title>", "title").requiredOption("--body <body>", "body text, or @file").option("--description <description>", "short description").option(
|
|
11577
11650
|
"--type <type>",
|
|
11578
11651
|
"snippet (durable context), skill (reusable instructions), dataset_note, or integration_model (a dated provider/API fact: needs --provider, --source-url, --verified-at and --stale-after)",
|