@erdoai/cli 0.247.0 → 0.253.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 +65 -11
  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, statSync as statSync2, writeFileSync as writeFileSync3 } from "fs";
128
+ import { mkdirSync as mkdirSync3, readFileSync as readFileSync5, statSync as statSync2, writeFileSync as writeFileSync3 } from "fs";
129
129
 
130
130
  // src/script-edits.ts
131
131
  function parseScriptEdits(text) {
@@ -144,7 +144,7 @@ function parseScriptEdits(text) {
144
144
  }
145
145
 
146
146
  // src/index.ts
147
- import { basename as basename2 } from "path";
147
+ import { basename as basename2, resolve } from "path";
148
148
 
149
149
  // src/csv.ts
150
150
  function parseCSV(text) {
@@ -463,7 +463,7 @@ function networkErrorFor(method, path, err) {
463
463
  const detail = code ? `${code} (${causeMsg})` : causeMsg;
464
464
  return new ErdoNetworkError(`${method} ${path} failed: ${detail}`, cause);
465
465
  }
466
- var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
466
+ var sleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
467
467
  async function rawRequest(baseURL, token, orgId, projectId, method, path, body, retryNetworkFailures = true) {
468
468
  const headers = { Authorization: `Bearer ${token}` };
469
469
  if (orgId) headers["X-Organization-ID"] = orgId;
@@ -935,6 +935,9 @@ var ErdoClient = class {
935
935
  getSentEmail(emailID) {
936
936
  return this.request("GET", `/v1/emails/${encodeURIComponent(emailID)}`);
937
937
  }
938
+ previewEmail(input) {
939
+ return this.request("POST", "/v1/email/preview", input);
940
+ }
938
941
  // Phone conversation records: inbound calls to a voice agent's own number and
939
942
  // the outbound calls Erdo placed. Website chat widget conversations are a
940
943
  // different resource — they live under /v1/voice/widget-conversations.
@@ -1617,13 +1620,29 @@ var ErdoClient = class {
1617
1620
  // after the HTTP call returns, so without this the first poll on a reused thread
1618
1621
  // would return that prior (already-terminal) run and print a stale answer. We
1619
1622
  // skip it and wait for a genuinely new run to appear.
1623
+ //
1624
+ // invocationID names the run the send started. Watchers post their own runs on
1625
+ // the thread after the answer, so the newest run is not necessarily ours; an
1626
+ // older backend that returns no invocation id falls back to locking onto the
1627
+ // first new run.
1620
1628
  async waitForThreadRun(threadID, opts = {}) {
1621
1629
  const intervalMs = opts.intervalMs ?? 3e3;
1622
1630
  const deadline = Date.now() + (opts.timeoutMs ?? 15 * 60 * 1e3);
1631
+ let lockedRunID;
1623
1632
  while (Date.now() < deadline) {
1624
- const { runs } = await this.listAgentRuns({ thread: threadID, limit: 1 });
1625
- const run = runs[0];
1626
- if (run && run.id !== opts.ignoreRunID) {
1633
+ let run;
1634
+ if (opts.invocationID) {
1635
+ const { runs } = await this.listAgentRuns({ thread: threadID, invocation: opts.invocationID, limit: 1 });
1636
+ run = runs[0];
1637
+ } else if (lockedRunID) {
1638
+ run = (await this.getAgentRun(lockedRunID)).run;
1639
+ } else {
1640
+ const { runs } = await this.listAgentRuns({ thread: threadID, limit: 1 });
1641
+ const candidate = runs[0];
1642
+ if (candidate && candidate.id !== opts.ignoreRunID) lockedRunID = candidate.id;
1643
+ run = candidate && candidate.id !== opts.ignoreRunID ? candidate : void 0;
1644
+ }
1645
+ if (run) {
1627
1646
  opts.onTick?.(run.status);
1628
1647
  if (POLL_STOP_STATUSES.has(run.status)) return run;
1629
1648
  }
@@ -2735,7 +2754,7 @@ function parsePastedCode(input, state) {
2735
2754
  return { error: "couldn't find an authorization code in that \u2014 paste the full localhost callback URL" };
2736
2755
  }
2737
2756
  function waitForCode(state) {
2738
- return new Promise((resolve, reject) => {
2757
+ return new Promise((resolve2, reject) => {
2739
2758
  let settled = false;
2740
2759
  let server;
2741
2760
  let rl;
@@ -2763,7 +2782,7 @@ function waitForCode(state) {
2763
2782
  );
2764
2783
  if (gotState !== state) return finish(() => reject(new Error("state mismatch \u2014 login aborted")));
2765
2784
  if (!code) return finish(() => reject(new Error("no authorization code returned")));
2766
- finish(() => resolve(code));
2785
+ finish(() => resolve2(code));
2767
2786
  });
2768
2787
  server.on("error", (err) => {
2769
2788
  if (err.code === "EADDRINUSE") {
@@ -2808,7 +2827,7 @@ If it doesn't open, visit:
2808
2827
  console.log(` \u2717 ${parsed.error}`);
2809
2828
  return;
2810
2829
  }
2811
- finish(() => resolve(parsed.code));
2830
+ finish(() => resolve2(parsed.code));
2812
2831
  return;
2813
2832
  }
2814
2833
  if (key?.name === "backspace") {
@@ -5226,6 +5245,7 @@ thread: ${res.thread_id}`);
5226
5245
  process.stderr.write(`thread: ${res.thread_id}
5227
5246
  running\u2026`);
5228
5247
  const run = await client.waitForThreadRun(res.thread_id, {
5248
+ invocationID: res.invocation_id,
5229
5249
  onTick: () => process.stderr.write(".")
5230
5250
  });
5231
5251
  process.stderr.write("\n");
@@ -5271,6 +5291,7 @@ agentCmd.command("send <threadId> <message>").description("Send a message to a t
5271
5291
  process.stderr.write("running\u2026");
5272
5292
  const run = await client.waitForThreadRun(threadId, {
5273
5293
  ignoreRunID: baselineRunID,
5294
+ invocationID: res.invocation_id,
5274
5295
  onTick: () => process.stderr.write(".")
5275
5296
  });
5276
5297
  process.stderr.write("\n");
@@ -5362,7 +5383,7 @@ thread: ${response.thread_id}`);
5362
5383
  }
5363
5384
  process.stderr.write(`thread: ${response.thread_id}
5364
5385
  running\u2026`);
5365
- const run = await client.waitForThreadRun(response.thread_id, { onTick: () => process.stderr.write(".") });
5386
+ const run = await client.waitForThreadRun(response.thread_id, { invocationID: response.invocation_id, onTick: () => process.stderr.write(".") });
5366
5387
  process.stderr.write("\n");
5367
5388
  if (!run) throw new Error(timedOutMessage(response.thread_id));
5368
5389
  if (run.status === "awaiting_approval") throw new Error(awaitingApprovalMessage(response.thread_id));
@@ -7181,7 +7202,40 @@ domainsCmd.command("transfer <domain> <targetOrg>").description("Move a domain t
7181
7202
  fail(e);
7182
7203
  }
7183
7204
  });
7184
- var emailCmd = program.command("email").description("The domain Erdo sends your outbound agent email from, and the mail that comes back");
7205
+ var emailCmd = program.command("email").description("Preview outbound emails, manage their sending domain, and read replies");
7206
+ emailCmd.command("preview").description("Render an email at phone and desktop widths without sending it").option("--subject <text>", "Email subject").option("--html <html|@path>", "Authored HTML, or @path to an HTML file").option("--template <slug>", "Saved email template slug").option("--data <json|@path>", "Template data as JSON or @path to a JSON file").option("--out <directory>", "Directory for email-375.png and email-640.png", ".").action(async (opts) => {
7207
+ try {
7208
+ if (opts.html !== void 0 && opts.template !== void 0) {
7209
+ throw new Error("pass either --html or --template, not both");
7210
+ }
7211
+ const input = { subject: opts.subject };
7212
+ if (opts.html !== void 0) input.html_content = readMaybeFile(opts.html);
7213
+ if (opts.template !== void 0) input.template_slug = opts.template;
7214
+ if (opts.data !== void 0) {
7215
+ try {
7216
+ input.data = JSON.parse(readMaybeFile(opts.data) ?? "");
7217
+ } catch (error) {
7218
+ throw new Error(`--data must be valid JSON: ${error instanceof Error ? error.message : String(error)}`);
7219
+ }
7220
+ }
7221
+ if (input.data !== void 0 && (typeof input.data !== "object" || input.data === null || Array.isArray(input.data))) {
7222
+ throw new Error("--data must be a JSON object");
7223
+ }
7224
+ const preview = await new ErdoClient().previewEmail(input);
7225
+ const widths = new Set(preview.images.map((image) => image.width));
7226
+ if (preview.images.length !== 2 || widths.size !== 2 || !widths.has(375) || !widths.has(640)) {
7227
+ throw new Error("preview must return one image at each of 375px and 640px");
7228
+ }
7229
+ const outDir = resolve(opts.out);
7230
+ mkdirSync3(outDir, { recursive: true });
7231
+ for (const image of preview.images) {
7232
+ writeFileSync3(resolve(outDir, `email-${image.width}.png`), Buffer.from(image.png_base64, "base64"));
7233
+ }
7234
+ console.log(preview.plain_text);
7235
+ } catch (error) {
7236
+ fail(error);
7237
+ }
7238
+ });
7185
7239
  var sendingDomainsCmd = emailCmd.command("domains").description("Sending domains \u2014 the verified domain outreach is sent from (one per org)");
7186
7240
  function printSendingDomain(d) {
7187
7241
  console.log(`${d.domain} ${d.status}${d.error_reason ? ` ${d.error_reason}` : ""}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erdoai/cli",
3
- "version": "0.247.0",
3
+ "version": "0.253.0",
4
4
  "description": "Erdo CLI \u2014 drive datasets, pages, and evals from the terminal or CI",
5
5
  "type": "module",
6
6
  "bin": {