@desplega.ai/agent-swarm 1.78.0 → 1.78.1
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/package.json
CHANGED
|
@@ -443,6 +443,36 @@ describe("parseRateLimitResetTime", () => {
|
|
|
443
443
|
expect(parsed.getUTCHours()).toBe(0);
|
|
444
444
|
});
|
|
445
445
|
|
|
446
|
+
test("parses 'resets May 14, 5pm (UTC)' with date prefix", () => {
|
|
447
|
+
const result = parseRateLimitResetTime("You've hit your limit · resets May 14, 5pm (UTC)");
|
|
448
|
+
expect(result).toBeDefined();
|
|
449
|
+
const parsed = new Date(result!);
|
|
450
|
+
expect(parsed.getUTCMonth()).toBe(4); // May = index 4
|
|
451
|
+
expect(parsed.getUTCDate()).toBe(14);
|
|
452
|
+
expect(parsed.getUTCHours()).toBe(17);
|
|
453
|
+
expect(parsed.getUTCMinutes()).toBe(0);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
test("parses dated reset without comma", () => {
|
|
457
|
+
const result = parseRateLimitResetTime("resets Jan 3 9:30am (UTC)");
|
|
458
|
+
expect(result).toBeDefined();
|
|
459
|
+
const parsed = new Date(result!);
|
|
460
|
+
expect(parsed.getUTCMonth()).toBe(0);
|
|
461
|
+
expect(parsed.getUTCDate()).toBe(3);
|
|
462
|
+
expect(parsed.getUTCHours()).toBe(9);
|
|
463
|
+
expect(parsed.getUTCMinutes()).toBe(30);
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
test("dated reset in the past rolls to next year", () => {
|
|
467
|
+
const now = new Date();
|
|
468
|
+
// Pick a month/day in the past relative to "now"
|
|
469
|
+
const pastMonth = now.getUTCMonth() === 0 ? "December" : "January";
|
|
470
|
+
const result = parseRateLimitResetTime(`resets ${pastMonth} 1, 12pm (UTC)`);
|
|
471
|
+
expect(result).toBeDefined();
|
|
472
|
+
const parsed = new Date(result!);
|
|
473
|
+
expect(parsed.getTime()).toBeGreaterThan(now.getTime());
|
|
474
|
+
});
|
|
475
|
+
|
|
446
476
|
test("parses 'retry after N seconds'", () => {
|
|
447
477
|
const before = Date.now();
|
|
448
478
|
const result = parseRateLimitResetTime("Rate limited. retry after 60 seconds");
|
|
@@ -165,16 +165,70 @@ export function trackErrorFromJson(
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
const MONTH_NAMES: Record<string, number> = {
|
|
169
|
+
jan: 0,
|
|
170
|
+
january: 0,
|
|
171
|
+
feb: 1,
|
|
172
|
+
february: 1,
|
|
173
|
+
mar: 2,
|
|
174
|
+
march: 2,
|
|
175
|
+
apr: 3,
|
|
176
|
+
april: 3,
|
|
177
|
+
may: 4,
|
|
178
|
+
jun: 5,
|
|
179
|
+
june: 5,
|
|
180
|
+
jul: 6,
|
|
181
|
+
july: 6,
|
|
182
|
+
aug: 7,
|
|
183
|
+
august: 7,
|
|
184
|
+
sep: 8,
|
|
185
|
+
sept: 8,
|
|
186
|
+
september: 8,
|
|
187
|
+
oct: 9,
|
|
188
|
+
october: 9,
|
|
189
|
+
nov: 10,
|
|
190
|
+
november: 10,
|
|
191
|
+
dec: 11,
|
|
192
|
+
december: 11,
|
|
193
|
+
};
|
|
194
|
+
|
|
168
195
|
/**
|
|
169
196
|
* Parse a rate limit error message to extract a reset time, returning an ISO datetime string.
|
|
170
197
|
* Handles patterns like:
|
|
171
198
|
* - "resets 3pm (UTC)" / "resets 3:30pm (UTC)"
|
|
199
|
+
* - "resets May 14, 5pm (UTC)" / "resets May 14 5pm (UTC)"
|
|
172
200
|
* - "retry after 60 seconds" / "wait 120 seconds"
|
|
173
201
|
* - "retry after 2 minutes"
|
|
174
202
|
* Returns undefined if no parseable reset time is found.
|
|
175
203
|
*/
|
|
176
204
|
export function parseRateLimitResetTime(errorMessage: string): string | undefined {
|
|
177
|
-
// Pattern
|
|
205
|
+
// Pattern 1a: "resets <Month> <day>[,] <time> (UTC)" — e.g. "resets May 14, 5pm (UTC)"
|
|
206
|
+
const datedMatch = errorMessage.match(
|
|
207
|
+
/resets?\s+([A-Za-z]+)\s+(\d{1,2})(?:st|nd|rd|th)?,?\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)\s*\(?\s*UTC\s*\)?/i,
|
|
208
|
+
);
|
|
209
|
+
if (datedMatch) {
|
|
210
|
+
const monthIdx = MONTH_NAMES[datedMatch[1]!.toLowerCase()];
|
|
211
|
+
if (monthIdx !== undefined) {
|
|
212
|
+
const day = Number.parseInt(datedMatch[2]!, 10);
|
|
213
|
+
let hours = Number.parseInt(datedMatch[3]!, 10);
|
|
214
|
+
const minutes = datedMatch[4] ? Number.parseInt(datedMatch[4], 10) : 0;
|
|
215
|
+
const ampm = datedMatch[5]!.toLowerCase();
|
|
216
|
+
if (ampm === "pm" && hours !== 12) hours += 12;
|
|
217
|
+
if (ampm === "am" && hours === 12) hours = 0;
|
|
218
|
+
|
|
219
|
+
const now = new Date();
|
|
220
|
+
let year = now.getUTCFullYear();
|
|
221
|
+
let resetDate = new Date(Date.UTC(year, monthIdx, day, hours, minutes, 0));
|
|
222
|
+
// If the parsed date is in the past (date wrapped around year-end), assume next year.
|
|
223
|
+
if (resetDate.getTime() <= now.getTime()) {
|
|
224
|
+
year += 1;
|
|
225
|
+
resetDate = new Date(Date.UTC(year, monthIdx, day, hours, minutes, 0));
|
|
226
|
+
}
|
|
227
|
+
return resetDate.toISOString();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Pattern 1b: "resets <time> (UTC)" — e.g. "resets 3pm (UTC)", "resets 3:30pm (UTC)"
|
|
178
232
|
const resetTimeMatch = errorMessage.match(
|
|
179
233
|
/resets?\s+(\d{1,2})(?::(\d{2}))?\s*(am|pm)\s*\(?\s*UTC\s*\)?/i,
|
|
180
234
|
);
|