@replayio/app-building 1.8.3 → 1.9.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.
package/dist/fly.d.ts CHANGED
@@ -3,10 +3,10 @@
3
3
  */
4
4
  export declare function createApp(token: string, name: string, org?: string): Promise<void>;
5
5
  /**
6
- * Create a Fly Volume in the app's primary region.
6
+ * Create a Fly Volume in the given region.
7
7
  * Returns the volume ID.
8
8
  */
9
- export declare function createVolume(app: string, token: string, name: string, sizeGb?: number): Promise<string>;
9
+ export declare function createVolume(app: string, token: string, name: string, region: string, sizeGb?: number): Promise<string>;
10
10
  /**
11
11
  * Delete a Fly Volume.
12
12
  */
package/dist/fly.js CHANGED
@@ -52,14 +52,15 @@ export async function createApp(token, name, org) {
52
52
  await gqlFetch(allocateMutation, { input: { appId: name, type: "v6" } });
53
53
  }
54
54
  /**
55
- * Create a Fly Volume in the app's primary region.
55
+ * Create a Fly Volume in the given region.
56
56
  * Returns the volume ID.
57
57
  */
58
- export async function createVolume(app, token, name, sizeGb = 50) {
58
+ export async function createVolume(app, token, name, region, sizeGb = 50) {
59
59
  const res = await flyFetch(`/apps/${app}/volumes`, token, {
60
60
  method: "POST",
61
61
  body: JSON.stringify({
62
62
  name,
63
+ region,
63
64
  size_gb: sizeGb,
64
65
  encrypted: true,
65
66
  require_unique_zone: false,
@@ -82,70 +83,66 @@ export async function deleteVolume(app, token, volumeId) {
82
83
  * Returns the machine ID and volume ID.
83
84
  */
84
85
  export async function createMachine(app, token, image, env, name) {
85
- // Create a volume for /repo storage
86
86
  const volumeName = `repo_${name.replace(/-/g, "_")}`.slice(0, 30);
87
- const volumeId = await createVolume(app, token, volumeName, 50);
87
+ // Regions to try in order. dfw and iad have the most reliable capacity for
88
+ // performance machines. Fall back to ord and sjc if needed.
89
+ const regions = ["dfw", "iad", "ord", "sjc"];
88
90
  // Delete unattached volumes in parallel with creating the new machine.
89
- const cleanupDone = listVolumes(app, token).then(vols => Promise.all(vols.map(async ({ id, attached_machine_id }) => {
90
- if (attached_machine_id || id == volumeId)
91
- return;
92
- await deleteVolume(app, token, id).catch(() => { });
93
- })));
94
- const machineBody = JSON.stringify({
95
- name,
96
- config: {
97
- image,
98
- env,
99
- auto_destroy: true,
100
- restart: { policy: "no" },
101
- guest: {
102
- cpu_kind: "performance",
103
- cpus: 16,
104
- memory_mb: 32768,
105
- },
106
- mounts: [{ volume: volumeId, path: "/repo" }],
107
- services: [
108
- {
109
- ports: [{ port: 443, handlers: ["tls", "http"] }],
110
- protocol: "tcp",
111
- internal_port: 3000,
112
- autostart: false,
113
- autostop: "off",
114
- },
115
- ],
116
- },
117
- });
118
- try {
119
- // Retry machine creation volume may take a moment to become available
120
- let lastErr;
121
- for (let attempt = 0; attempt < 5; attempt++) {
122
- try {
123
- const res = await flyFetch(`/apps/${app}/machines`, token, {
124
- method: "POST",
125
- body: machineBody,
126
- });
127
- const data = (await res.json());
128
- await cleanupDone;
129
- return { machineId: data.id, volumeId };
130
- }
131
- catch (err) {
132
- const msg = err instanceof Error ? err.message : String(err);
133
- if (msg.includes("volume not found") && attempt < 4) {
134
- console.log(`Volume not yet available, retrying in 3s... (attempt ${attempt + 1})`);
135
- await new Promise((r) => setTimeout(r, 3000));
136
- lastErr = err;
137
- continue;
138
- }
139
- throw err;
91
+ let cleanupDone;
92
+ for (const region of regions) {
93
+ const volumeId = await createVolume(app, token, volumeName, region, 50);
94
+ // Start cleanup on first attempt only
95
+ if (!cleanupDone) {
96
+ cleanupDone = listVolumes(app, token).then(vols => Promise.all(vols.map(async ({ id, attached_machine_id }) => {
97
+ if (attached_machine_id || id === volumeId)
98
+ return;
99
+ await deleteVolume(app, token, id).catch(() => { });
100
+ })));
101
+ }
102
+ try {
103
+ const res = await flyFetch(`/apps/${app}/machines`, token, {
104
+ method: "POST",
105
+ body: JSON.stringify({
106
+ name,
107
+ region,
108
+ config: {
109
+ image,
110
+ env,
111
+ auto_destroy: true,
112
+ restart: { policy: "no" },
113
+ guest: {
114
+ cpu_kind: "performance",
115
+ cpus: 16,
116
+ memory_mb: 32768,
117
+ },
118
+ mounts: [{ volume: volumeId, path: "/repo" }],
119
+ services: [
120
+ {
121
+ ports: [{ port: 443, handlers: ["tls", "http"] }],
122
+ protocol: "tcp",
123
+ internal_port: 3000,
124
+ autostart: false,
125
+ autostop: "off",
126
+ },
127
+ ],
128
+ },
129
+ }),
130
+ });
131
+ const data = (await res.json());
132
+ await cleanupDone;
133
+ return { machineId: data.id, volumeId };
134
+ }
135
+ catch (err) {
136
+ await deleteVolume(app, token, volumeId).catch(() => { });
137
+ const msg = err instanceof Error ? err.message : String(err);
138
+ if (msg.includes("412")) {
139
+ console.log(`Insufficient resources in ${region}, trying next region...`);
140
+ continue;
140
141
  }
142
+ throw err;
141
143
  }
142
- throw lastErr;
143
- }
144
- catch (err) {
145
- // Clean up volume if machine creation fails
146
- await deleteVolume(app, token, volumeId).catch(() => { });
147
- throw err;
148
144
  }
145
+ throw new Error("Failed to create machine after exhausting retries");
149
146
  }
150
147
  /**
151
148
  * Wait for a Fly Machine to reach the "started" state.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@replayio/app-building",
3
- "version": "1.8.3",
3
+ "version": "1.9.0",
4
4
  "description": "Library for managing agentic app-building containers",
5
5
  "type": "module",
6
6
  "exports": {