@erdoai/cli 0.223.0 → 0.225.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 +82 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -126,6 +126,24 @@ function describeFreshnessTarget(state) {
126
126
 
127
127
  // src/index.ts
128
128
  import { readFileSync as readFileSync5, writeFileSync as writeFileSync3 } from "fs";
129
+
130
+ // src/script-edits.ts
131
+ function parseScriptEdits(text) {
132
+ const parsed = JSON.parse(text);
133
+ const list = Array.isArray(parsed) ? parsed : parsed && typeof parsed === "object" && Array.isArray(parsed.edits) ? parsed.edits : null;
134
+ if (!list || list.length === 0) {
135
+ throw new Error('--edits must be a JSON array of {"old_string", "new_string"} (or {"edits": [...]}) with at least one edit');
136
+ }
137
+ return list.map((edit, i) => {
138
+ const e = edit;
139
+ if (typeof e?.old_string !== "string" || e.old_string === "" || typeof e.new_string !== "string") {
140
+ throw new Error(`edit ${i}: needs a non-empty string old_string and a string new_string`);
141
+ }
142
+ return { old_string: e.old_string, new_string: e.new_string };
143
+ });
144
+ }
145
+
146
+ // src/index.ts
129
147
  import { basename as basename2 } from "path";
130
148
 
131
149
  // src/csv.ts
@@ -2529,9 +2547,12 @@ var ErdoClient = class {
2529
2547
  if (audience) body.audience = audience;
2530
2548
  return this.request("POST", "/v1/page-reviews", body);
2531
2549
  }
2532
- reviewAd(input) {
2550
+ reviewCritic(input) {
2533
2551
  return this.request("POST", "/v1/critic/reviews", input);
2534
2552
  }
2553
+ reviewAd(input) {
2554
+ return this.reviewCritic(input);
2555
+ }
2535
2556
  assessInvestigation(input) {
2536
2557
  return this.request("POST", "/v1/investigations", input);
2537
2558
  }
@@ -6849,16 +6870,35 @@ reviewsCmd.command("decide <id>").description(
6849
6870
  );
6850
6871
  var pagesCmd = program.command("pages").description("Create and manage pages/artifacts");
6851
6872
  var criticCmd = program.command("critic").description("Review campaign creative");
6852
- criticCmd.command("review").description("Review an ad creative request from a JSON file and print per-lens findings").requiredOption("-f, --file <path>", "JSON file containing the full critic review request envelope").option("--json", "print the complete raw JSON response").action(async (opts) => {
6853
- try {
6854
- const input = JSON.parse(readFileSync5(opts.file, "utf8"));
6855
- const result = await new ErdoClient().reviewAd(input);
6873
+ criticCmd.command("review").description("Review an ad or document and print per-lens findings").option("-f, --file <path>", "JSON file containing the full critic review request envelope").option("--text <text>", "Document text to review (use instead of --file)").option("--claims-dataset <slug>", "Claims dataset slug for document reviews").option("--wait", "Poll a running document review's run until it completes").option("--json", "print the complete raw JSON response").action(async (opts) => {
6874
+ try {
6875
+ if (!opts.file && !opts.text) throw new Error("provide --file or --text");
6876
+ const input = opts.text ? { subject_kind: "document", document: { text: opts.text, claims_dataset_slug: opts.claimsDataset } } : JSON.parse(readFileSync5(opts.file, "utf8"));
6877
+ const result = await new ErdoClient().reviewCritic(input);
6878
+ let finalResult = result;
6879
+ if (opts.wait && result.status === "running" && result.run_id) {
6880
+ for (; ; ) {
6881
+ await sleep2(5e3);
6882
+ const run = await new ErdoClient().getAgentRun(result.run_id);
6883
+ if (!["running", "pending", "queued"].includes(run.run.status)) {
6884
+ if (!run.run.output) throw new Error(run.run.error || `critic run ended with status ${run.run.status}`);
6885
+ finalResult = JSON.parse(run.run.output);
6886
+ break;
6887
+ }
6888
+ }
6889
+ }
6856
6890
  if (opts.json) {
6857
- print(result);
6891
+ print(finalResult);
6858
6892
  return;
6859
6893
  }
6860
- console.log(result.summary);
6861
- for (const lens of result.lenses) {
6894
+ if (finalResult.status === "running") {
6895
+ console.log("Review is running.");
6896
+ if (finalResult.run_id) console.log(`run id: ${finalResult.run_id}`);
6897
+ if (finalResult.review_thread_id) console.log(`review thread id: ${finalResult.review_thread_id}`);
6898
+ return;
6899
+ }
6900
+ console.log(finalResult.summary);
6901
+ for (const lens of finalResult.lenses) {
6862
6902
  console.log(`
6863
6903
  ${lens.lens_slug}: ${lens.summary}`);
6864
6904
  for (const finding of lens.findings) {
@@ -6866,7 +6906,13 @@ ${lens.lens_slug}: ${lens.summary}`);
6866
6906
  console.log(` Evidence: ${finding.evidence}`);
6867
6907
  console.log(` Suggested rewrite: ${finding.suggested_rewrite}`);
6868
6908
  }
6909
+ for (const claim of lens.claims ?? []) {
6910
+ console.log(` Claim ${claim.claim_id}: ${claim.verdict} \u2014 ${claim.claim}`);
6911
+ if (claim.note) console.log(` Note: ${claim.note}`);
6912
+ }
6869
6913
  }
6914
+ if (finalResult.usage) console.log(`
6915
+ Usage: ${JSON.stringify(finalResult.usage)}`);
6870
6916
  } catch (e) {
6871
6917
  fail(e);
6872
6918
  }
@@ -9340,7 +9386,7 @@ datasetsCmd.command("configure-integration <dataset-id>").description(
9340
9386
  }
9341
9387
  );
9342
9388
  var refreshCmd = datasetsCmd.command("refresh").description(
9343
- "The recipe that keeps a dataset current, and the triggers that run it \u2014 read it with `show`, install or replace it with `set`, and run it once now with `run`"
9389
+ "The recipe that keeps a dataset current, and the triggers that run it \u2014 read it with `show`, install or replace it with `set`, change part of its script with `edit`, and run it once now with `run`"
9344
9390
  );
9345
9391
  var REFRESH_STRATEGIES = ["script", "script_js", "agent_run", "live_webhook"];
9346
9392
  function readRefreshJSONFile(value, label) {
@@ -9645,6 +9691,33 @@ refreshCmd.command("set <slug>").description(
9645
9691
  }
9646
9692
  }
9647
9693
  );
9694
+ refreshCmd.command("edit <slug>").description(
9695
+ "Change part of a dataset's saved script or transform_js without resending it: each old_string must match the saved source exactly once. Only the source changes; the schedule and every other setting stay as saved. The edited recipe is compile-checked and test-run like `set`"
9696
+ ).requiredOption("--edits <@file>", 'JSON file: [{"old_string": "...", "new_string": "..."}, ...], applied in order').action(async (slug, opts) => {
9697
+ try {
9698
+ const path = opts.edits.startsWith("@") ? opts.edits.slice(1) : opts.edits;
9699
+ const edits = parseScriptEdits(readFileSync5(path, "utf8"));
9700
+ const client = new ErdoClient();
9701
+ const current = await client.getDatasetRefresh(slug);
9702
+ if (!current.configured || !current.strategy) {
9703
+ fail(new Error(`${slug} has no saved refresh to edit; install one with: erdo datasets refresh set ${slug}`));
9704
+ return;
9705
+ }
9706
+ const res = await client.setDatasetRefresh(slug, { strategy: current.strategy, script_edits: edits });
9707
+ console.log(`Edited the ${res.strategy} source of ${res.dataset_slug} (${edits.length} ${edits.length === 1 ? "edit" : "edits"}); every other setting is unchanged`);
9708
+ if (res.test_run) {
9709
+ if (res.test_run.success) {
9710
+ console.log(`test run: passed in ${res.test_run.duration_ms} ms`);
9711
+ } else {
9712
+ console.error(`test run: FAILED after ${res.test_run.duration_ms} ms \u2014 ${res.test_run.error || "no error reported"}`);
9713
+ console.error("The edit is saved but the recipe does not run. Fix it with another edit.");
9714
+ process.exitCode = 1;
9715
+ }
9716
+ }
9717
+ } catch (e) {
9718
+ fail(e);
9719
+ }
9720
+ });
9648
9721
  refreshCmd.command("run <slug>").description(
9649
9722
  "Run a dataset's configured refresh once, now \u2014 the same recipe a cron or a page view would run, without waiting for either. It is asynchronous: this answers with the execution it started, and `datasets refresh show <slug>` carries the outcome once it finishes."
9650
9723
  ).option("--json", "print the raw JSON result instead of a summary").action(async (slug, opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.223.0",
3
+ "version": "0.225.0",
4
4
  "description": "Erdo CLI \u2014 drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {