From d4e9de74cc4424d9bdf778a1edb03dd71f056e31 Mon Sep 17 00:00:00 2001 From: Sampson Date: Wed, 22 Apr 2026 09:14:30 -0500 Subject: [PATCH] fixes freshness parsing (#285) resolves #273 --- src/tools/news/params.ts | 11 +++++++++-- src/tools/videos/params.ts | 10 +++++++++- src/tools/web/params.ts | 10 +++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/tools/news/params.ts b/src/tools/news/params.ts index 623846c..c2168f2 100644 --- a/src/tools/news/params.ts +++ b/src/tools/news/params.ts @@ -54,8 +54,15 @@ export const params = z.object({ ) .optional(), freshness: z - .union([z.literal('pd'), z.literal('pw'), z.literal('pm'), z.literal('py'), z.string()]) - .default('pd') + .union([ + z.enum(['pd', 'pw', 'pm', 'py']), + z + .string() + .regex( + /^\d{4}-\d{2}-\d{2}to\d{4}-\d{2}-\d{2}$/, + "Use 'pd', 'pw', 'pm', or 'py' for a relative discovery window, or a custom range as YYYY-MM-DDtoYYYY-MM-DD (e.g. 2022-04-01to2022-07-30)." + ), + ]) .describe( "Filters search results by when they were discovered. The following values are supported: 'pd' - Discovered within the last 24 hours. 'pw' - Discovered within the last 7 Days. 'pm' - Discovered within the last 31 Days. 'py' - Discovered within the last 365 Days. 'YYYY-MM-DDtoYYYY-MM-DD' - Timeframe is also supported by specifying the date range e.g. 2022-04-01to2022-07-30." ) diff --git a/src/tools/videos/params.ts b/src/tools/videos/params.ts index c171ef7..bb7e70f 100644 --- a/src/tools/videos/params.ts +++ b/src/tools/videos/params.ts @@ -61,7 +61,15 @@ export const params = z.object({ ) .optional(), freshness: z - .union([z.literal('pd'), z.literal('pw'), z.literal('pm'), z.literal('py'), z.string()]) + .union([ + z.enum(['pd', 'pw', 'pm', 'py']), + z + .string() + .regex( + /^\d{4}-\d{2}-\d{2}to\d{4}-\d{2}-\d{2}$/, + "Use 'pd', 'pw', 'pm', or 'py' for a relative discovery window, or a custom range as YYYY-MM-DDtoYYYY-MM-DD (e.g. 2022-04-01to2022-07-30)." + ), + ]) .describe( "Filters search results by when they were discovered. The following values are supported: 'pd' - Discovered within the last 24 hours. 'pw' - Discovered within the last 7 days. 'pm' - Discovered within the last 31 days. 'py' - Discovered within the last 365 days. 'YYYY-MM-DDtoYYYY-MM-DD' - timeframe is also supported by specifying the date range (e.g. '2022-04-01to2022-07-30')." ) diff --git a/src/tools/web/params.ts b/src/tools/web/params.ts index 9470012..e474961 100644 --- a/src/tools/web/params.ts +++ b/src/tools/web/params.ts @@ -179,7 +179,15 @@ export const params = z.object({ ) .optional(), freshness: z - .enum(['pd', 'pw', 'pm', 'py', 'YYYY-MM-DDtoYYYY-MM-DD']) + .union([ + z.enum(['pd', 'pw', 'pm', 'py']), + z + .string() + .regex( + /^\d{4}-\d{2}-\d{2}to\d{4}-\d{2}-\d{2}$/, + "Use 'pd', 'pw', 'pm', or 'py' for a relative discovery window, or a custom range as YYYY-MM-DDtoYYYY-MM-DD (e.g. 2022-04-01to2022-07-30)." + ), + ]) .describe( "Filters search results by when they were discovered. The following values are supported: 'pd' - Discovered within the last 24 hours. 'pw' - Discovered within the last 7 days. 'pm' - Discovered within the last 31 days. 'py' - Discovered within the last 365 days. 'YYYY-MM-DDtoYYYY-MM-DD' - Timeframe is also supported by specifying the date range e.g. 2022-04-01to2022-07-30." )