Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ function formatBodyPreview(body: Record<string, unknown>): string {
// existing importers and `instanceof` checks see one class.
export { VapiApiError };

const REQUEST_DELAY_MS = 700; // Delay between requests to avoid rate limits
// Minimum gap between writes, to stay under rate limits. Reads skip it: a pull
// is a handful of list requests, and a 700ms gap before each one was most of a
// pull's run time. A 429 on a read is still retried with backoff.
const REQUEST_DELAY_MS = 700;

let lastRequestTime = 0;

Expand Down Expand Up @@ -190,7 +193,6 @@ export async function vapiGet<T = unknown>(endpoint: string): Promise<T> {
const url = `${VAPI_BASE_URL}${endpoint}`;

for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
await throttle();
const response = await fetch(url, {
method: "GET",
headers: {
Expand Down
8 changes: 7 additions & 1 deletion src/pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,13 @@ export async function runPull(options: PullOptions = {}): Promise<PullResult> {
const bothDivergedResources: BothDivergedResource[] = [];
let idsByType: Map<ResourceType, string[]> | undefined;

if (force && process.env.CI !== "true") {
// setup turns the pause off for the pulls it runs itself: the warning is for
// someone typing --force, and the wizard can run one --force pull per type.
if (
force &&
process.env.CI !== "true" &&
process.env.VAPI_GITOPS_FORCE_PAUSE !== "off"
) {
console.warn(
"\n⚠️ --force will overwrite local files without showing you direction labels or surfacing 3-way conflicts.",
);
Expand Down
28 changes: 25 additions & 3 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,17 @@ async function deleteExistingOrg(slug: string): Promise<void> {
// Pull integration
// ─────────────────────────────────────────────────────────────────────────────

// "all" downloads everything with one full pull rather than one pull per type,
// each of which starts a process and re-fetches credentials and its list.
function invokePull(
slug: string,
selectedIds: Set<string>,
selectedIds: Set<string> | "all",
token: string,
baseUrl: string,
): void {
// Group selected resources by type so we can pass --id per invocation
const byType = new Map<string, string[]>();
for (const id of selectedIds) {
for (const id of selectedIds === "all" ? [] : selectedIds) {
const sep = id.indexOf("::");
const typeKey = id.substring(0, sep);
const uuid = id.substring(sep + 2);
Expand All @@ -332,6 +334,7 @@ function invokePull(
VAPI_PRIVATE_API_KEY: token,
VAPI_TOKEN: token,
VAPI_BASE_URL: baseUrl,
VAPI_GITOPS_FORCE_PAUSE: "off",
};

execSync(`tsx src/pull.ts ${slug} --bootstrap --bindings-only`, {
Expand All @@ -340,6 +343,15 @@ function invokePull(
env,
});

if (selectedIds === "all") {
execSync(`tsx src/pull.ts ${slug} --force --skip-bindings`, {
cwd: BASE_DIR,
stdio: "inherit",
env,
});
return;
}

for (const [typeKey, uuids] of byType) {
const idArgs = uuids.flatMap((id) => ["--id", id]);
const cmd = [
Expand Down Expand Up @@ -704,6 +716,7 @@ async function main(): Promise<void> {

// selectedIds: "typeKey::resourceUUID"
let selectedIds: Set<string>;
let downloadAll = false;

// eslint-disable-next-line no-constant-condition
while (true) {
Expand Down Expand Up @@ -738,6 +751,7 @@ async function main(): Promise<void> {

selectedIds = new Set(picked);
} else {
downloadAll = true;
selectedIds = new Set(
nonEmpty.flatMap((snap) =>
snap.resources.map((r) => `${snap.key}::${r.id as string}`),
Expand Down Expand Up @@ -796,10 +810,18 @@ async function main(): Promise<void> {

await writeEnvFile(slug, trimmedKey, vapiBaseUrl);
console.log(c.green(` ✓ Created .env.${slug}\n`));
// Before the first pull, as non-interactive setup does: the org pin
// (.vapi-org.json) is only written into a folder that already exists.
await mkdir(resourceDir, { recursive: true });

console.log(c.bold(" Downloading...\n"));

invokePull(slug, selectedIds, trimmedKey, vapiBaseUrl);
invokePull(
slug,
downloadAll ? "all" : selectedIds,
trimmedKey,
vapiBaseUrl,
);

// ── Done ──────────────────────────────────────────────────────────────

Expand Down
Loading