@erdoai/cli 0.244.1 → 0.245.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 +22 -7
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -125,7 +125,7 @@ function describeFreshnessTarget(state) {
125
125
  }
126
126
 
127
127
  // src/index.ts
128
- import { readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
128
+ import { readFileSync as readFileSync5, statSync as statSync2, writeFileSync as writeFileSync3 } from "fs";
129
129
 
130
130
  // src/script-edits.ts
131
131
  function parseScriptEdits(text) {
@@ -11473,22 +11473,37 @@ knowledgeCmd.command("delete <id>").description("Delete a Knowledge object you c
11473
11473
  fail(e);
11474
11474
  }
11475
11475
  });
11476
- knowledgeCmd.command("attach <objectId> <file>").description(
11476
+ knowledgeCmd.command("attach <objectId> [file]").description(
11477
11477
  "Attach an image or other small binary to a knowledge object as an org-hosted asset, and print its asset id \u2014 the value a page's assetId field takes. Pass a local path, or --url to have the service download it (the only path for video)."
11478
- ).option("--url <sourceUrl>", "download from this URL instead of reading a local file").option(
11478
+ ).option("--url <sourceUrl>", "download from this URL instead of reading a local file").addOption(new Option2("--caption <text>", "caption describing the attachment").conflicts("description")).option("--role <prefix>", "filename role prefix, e.g. customer-logo; already prefixed names are preserved").option(
11479
11479
  "-d, --description <text>",
11480
11480
  "caption for the asset; for an image this is the only text search can match, so describe what is in the picture"
11481
11481
  ).option("--media-type <mime>", "MIME type hint, e.g. image/jpeg; detected from the filename otherwise").action(
11482
11482
  async (objectId, file, opts) => {
11483
11483
  try {
11484
- const body = opts.url ? { filename: basename2(file), source_url: opts.url } : {
11485
- filename: basename2(file),
11486
- content_base64: readFileSync5(file).toString("base64")
11487
- };
11484
+ let body;
11485
+ if (opts.url) {
11486
+ const source = new URL(opts.url);
11487
+ if (!["http:", "https:"].includes(source.protocol) || source.username || source.password) {
11488
+ throw new Error("--url must be an HTTP(S) URL without credentials");
11489
+ }
11490
+ const filename = file ? basename2(file) : basename2(decodeURIComponent(source.pathname));
11491
+ if (!filename || filename === "/") throw new Error("provide a filename for this download URL");
11492
+ body = { filename, source_url: opts.url };
11493
+ } else {
11494
+ if (!file) throw new Error("provide a local file or --url URL");
11495
+ if (statSync2(file).size > 20 * 1024 * 1024) throw new Error("file exceeds the 20 MiB limit; use --url for larger files");
11496
+ const content = readFileSync5(file);
11497
+ if (!content.length) throw new Error("attachment file is empty");
11498
+ if (content.length > 20 * 1024 * 1024) throw new Error("file exceeds the 20 MiB limit; use --url for larger files");
11499
+ body = { filename: basename2(file), content_base64: content.toString("base64") };
11500
+ }
11488
11501
  print(
11489
11502
  await new ErdoClient().attachKnowledgeAsset(objectId, {
11490
11503
  ...body,
11491
11504
  description: opts.description,
11505
+ caption: opts.caption,
11506
+ role: opts.role,
11492
11507
  media_type: opts.mediaType
11493
11508
  })
11494
11509
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.244.1",
3
+ "version": "0.245.0",
4
4
  "description": "Erdo CLI \u2014 drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {