retell-sync-cli 2.0.0 → 2.1.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/cli.js +76 -3
  2. package/package.json +3 -2
package/dist/cli.js CHANGED
@@ -135459,20 +135459,93 @@ async function deploy({
135459
135459
  return { id: id2, name: agentNames.get(id2) ?? id2 };
135460
135460
  }));
135461
135461
  spinner.stop(source_default.dim("Done"));
135462
- let publishedCount = 0;
135462
+ const publishedAgentIds = [];
135463
135463
  for (const result of publishResults) {
135464
135464
  if (result.status === "fulfilled") {
135465
135465
  console.log(source_default.green(`Published ${source_default.bold(result.value.name)}`));
135466
- publishedCount++;
135466
+ publishedAgentIds.push(result.value.id);
135467
135467
  } else {
135468
135468
  console.log(source_default.red(`Failed to publish: ${result.reason}`));
135469
135469
  }
135470
135470
  }
135471
- console.log(source_default.green(`Published ${pluralize("agent", publishedCount, true)}`));
135471
+ console.log(source_default.green(`Published ${pluralize("agent", publishedAgentIds.length, true)}`));
135472
+ if (publishedAgentIds.length > 0) {
135473
+ await updatePhoneNumberVersions(publishedAgentIds, agentNames);
135474
+ }
135472
135475
  }
135473
135476
  console.log(source_default.bold("Syncing latest state..."));
135474
135477
  await pull({ agentsDir, configFormat, agentIds });
135475
135478
  }
135479
+ async function updatePhoneNumberVersions(publishedAgentIds, agentNames) {
135480
+ const spinner = createSpinner("Updating phone numbers...");
135481
+ const [phoneNumbers, ...agentVersionLists] = await Promise.all([
135482
+ retell.phoneNumber.list(),
135483
+ ...publishedAgentIds.map((id2) => retell.agent.getVersions(id2))
135484
+ ]);
135485
+ const publishedVersions = new Map;
135486
+ for (const [i5, agentId] of publishedAgentIds.entries()) {
135487
+ const versions2 = agentVersionLists[i5];
135488
+ if (!versions2)
135489
+ continue;
135490
+ const latestPublished = versions2.filter((v10) => v10.is_published).sort((a7, b7) => (b7.version ?? 0) - (a7.version ?? 0))[0];
135491
+ if (latestPublished?.version != null) {
135492
+ publishedVersions.set(agentId, latestPublished.version);
135493
+ }
135494
+ }
135495
+ const publishedAgentIdSet = new Set(publishedAgentIds);
135496
+ const updates = [];
135497
+ for (const phone of phoneNumbers) {
135498
+ const inboundVersion = phone.inbound_agent_id && publishedAgentIdSet.has(phone.inbound_agent_id) ? publishedVersions.get(phone.inbound_agent_id) : undefined;
135499
+ const outboundVersion = phone.outbound_agent_id && publishedAgentIdSet.has(phone.outbound_agent_id) ? publishedVersions.get(phone.outbound_agent_id) : undefined;
135500
+ if (inboundVersion != null || outboundVersion != null) {
135501
+ updates.push({
135502
+ phoneNumber: phone.phone_number,
135503
+ inboundVersion,
135504
+ outboundVersion
135505
+ });
135506
+ }
135507
+ }
135508
+ if (updates.length === 0) {
135509
+ spinner.stop(source_default.dim("No phone numbers to update"));
135510
+ return;
135511
+ }
135512
+ const updateResults = await Promise.allSettled(updates.map(async ({ phoneNumber, inboundVersion, outboundVersion }) => {
135513
+ await retell.phoneNumber.update(phoneNumber, {
135514
+ ...inboundVersion != null && {
135515
+ inbound_agent_version: inboundVersion
135516
+ },
135517
+ ...outboundVersion != null && {
135518
+ outbound_agent_version: outboundVersion
135519
+ }
135520
+ });
135521
+ return phoneNumber;
135522
+ }));
135523
+ spinner.stop(source_default.dim("Done"));
135524
+ let updatedCount = 0;
135525
+ for (const result of updateResults) {
135526
+ if (result.status === "fulfilled") {
135527
+ const phone = updates.find((u4) => u4.phoneNumber === result.value);
135528
+ const agentInfo = [];
135529
+ if (phone?.inboundVersion != null) {
135530
+ const inboundPhone = phoneNumbers.find((p4) => p4.phone_number === result.value);
135531
+ const agentId = inboundPhone?.inbound_agent_id;
135532
+ const name = agentId ? agentNames.get(agentId) ?? agentId : "unknown";
135533
+ agentInfo.push(`inbound: ${name} v${phone.inboundVersion}`);
135534
+ }
135535
+ if (phone?.outboundVersion != null) {
135536
+ const outboundPhone = phoneNumbers.find((p4) => p4.phone_number === result.value);
135537
+ const agentId = outboundPhone?.outbound_agent_id;
135538
+ const name = agentId ? agentNames.get(agentId) ?? agentId : "unknown";
135539
+ agentInfo.push(`outbound: ${name} v${phone.outboundVersion}`);
135540
+ }
135541
+ console.log(source_default.green(`Updated ${source_default.bold(result.value)} (${agentInfo.join(", ")})`));
135542
+ updatedCount++;
135543
+ } else {
135544
+ console.log(source_default.red(`Failed to update phone number: ${result.reason}`));
135545
+ }
135546
+ }
135547
+ console.log(source_default.green(`Updated ${pluralize("phone number", updatedCount, true)}`));
135548
+ }
135476
135549
  function computeChanges(local, remote) {
135477
135550
  const changes = {
135478
135551
  agents: [],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "retell-sync-cli",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "CLI tool for syncing Retell AI agents between local filesystem and API",
5
5
  "keywords": [
6
6
  "agents",
@@ -18,7 +18,8 @@
18
18
  "scripts": {
19
19
  "check": "bunx tsc --noEmit && bun fix",
20
20
  "fix": "oxlint --type-aware --fix-suggestions && prettier . --write",
21
- "build": "bun build ./src/cli.ts --target bun --outdir dist"
21
+ "build": "bun check && bun build ./src/cli.ts --target bun --outdir dist",
22
+ "prepublishOnly": "bun run build"
22
23
  },
23
24
  "dependencies": {
24
25
  "@inquirer/prompts": "^8.1.0",