next-anteater 0.2.10 → 0.2.12

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/lib/scaffold.mjs +67 -5
  2. package/package.json +1 -1
package/lib/scaffold.mjs CHANGED
@@ -105,7 +105,12 @@ async function patchApiRouteMutationGuardIfMissing(path) {
105
105
  async function patchRunsRouteMutationGuardIfMissing(path) {
106
106
  try {
107
107
  const existing = await readFile(path, "utf-8");
108
- if (existing.includes("Same-origin guard for mutating runs endpoint")) {
108
+ if (
109
+ existing.includes("Same-origin guard for mutating runs endpoint") &&
110
+ existing.includes("export async function DELETE(request") &&
111
+ existing.indexOf("Same-origin guard for mutating runs endpoint") >
112
+ existing.indexOf("export async function DELETE(request")
113
+ ) {
109
114
  return false;
110
115
  }
111
116
 
@@ -134,10 +139,22 @@ async function patchRunsRouteMutationGuardIfMissing(path) {
134
139
  "",
135
140
  ].join("\n");
136
141
 
137
- const patched = existing.replace(
138
- " const gh = (url",
139
- `${guardBlock} const gh = (url`,
140
- );
142
+ const deleteFnPattern =
143
+ /(export async function DELETE\(request[^\n]*\) \{[\s\S]*?if \(!requestId\) \{[\s\S]*?\n \}\n\s*)/;
144
+ let patched = existing;
145
+
146
+ if (deleteFnPattern.test(existing)) {
147
+ patched = existing.replace(deleteFnPattern, `$1${guardBlock}`);
148
+ } else {
149
+ return false;
150
+ }
151
+
152
+ // Clean up buggy older patch where guard was accidentally inserted in GET.
153
+ const getGuardPattern =
154
+ /(export async function GET\(\) \{[\s\S]*?)\n \/\/ Same-origin guard for mutating runs endpoint[\s\S]*? const gh = \(url/g;
155
+ if (getGuardPattern.test(patched)) {
156
+ patched = patched.replace(getGuardPattern, "$1\n const gh = (url");
157
+ }
141
158
 
142
159
  if (patched === existing) {
143
160
  return false;
@@ -149,6 +166,48 @@ async function patchRunsRouteMutationGuardIfMissing(path) {
149
166
  }
150
167
  }
151
168
 
169
+ async function patchRunsRouteFailedTtlIfMissing(path) {
170
+ try {
171
+ const existing = await readFile(path, "utf-8");
172
+ if (existing.includes("failedCutoffMs")) {
173
+ return false;
174
+ }
175
+
176
+ const replacement = [
177
+ " // Sort newest first, cap at 5",
178
+ " // Drop stale failed runs (>1h) so old errors don't clutter the bar",
179
+ " const failedCutoffMs = 60 * 60 * 1000;",
180
+ " const freshRuns = runs.filter((r) => {",
181
+ ' if (r.step !== "error") return true;',
182
+ " const startedAtMs = new Date(r.startedAt).getTime();",
183
+ " if (Number.isNaN(startedAtMs)) return true;",
184
+ " return Date.now() - startedAtMs <= failedCutoffMs;",
185
+ " });",
186
+ "",
187
+ " freshRuns.sort((a, b) => new Date(b.startedAt).getTime() - new Date(a.startedAt).getTime());",
188
+ "",
189
+ ' return NextResponse.json' + (existing.includes("<AnteaterRunsResponse>") ? "<AnteaterRunsResponse>" : "") + "(",
190
+ " { runs: freshRuns.slice(0, 5), deploymentId: process.env.VERCEL_DEPLOYMENT_ID }",
191
+ " );",
192
+ ].join("\n");
193
+
194
+ const sortAndReturnPattern =
195
+ / \/\/ Sort newest first, cap at 5[\s\S]*? return NextResponse\.json(?:<AnteaterRunsResponse>)?\([\s\S]*?\n \);/;
196
+ if (!sortAndReturnPattern.test(existing)) {
197
+ return false;
198
+ }
199
+
200
+ const patched = existing.replace(sortAndReturnPattern, replacement);
201
+ if (patched === existing) {
202
+ return false;
203
+ }
204
+ await writeFile(path, patched, "utf-8");
205
+ return true;
206
+ } catch {
207
+ return false;
208
+ }
209
+ }
210
+
152
211
  /**
153
212
  * Generate anteater.config.ts
154
213
  */
@@ -1067,6 +1126,9 @@ export async function scaffoldFiles(cwd, options) {
1067
1126
  if (await patchRunsRouteMutationGuardIfMissing(runsPath)) {
1068
1127
  results.push(`${join(runsDir, runsRoute.filename)} (patched same-origin guard)`);
1069
1128
  }
1129
+ if (await patchRunsRouteFailedTtlIfMissing(runsPath)) {
1130
+ results.push(`${join(runsDir, runsRoute.filename)} (patched failed-run TTL)`);
1131
+ }
1070
1132
  }
1071
1133
 
1072
1134
  // GitHub Action workflow
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-anteater",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "AI-powered live editing for your Next.js app",
5
5
  "bin": {
6
6
  "anteater": "bin/setup-anteater.mjs",