Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Fix search country parameter to default to undefined when location is set (#2283)

devin-ai-integration[bot]fff8609902ae
diff --git a/apps/api/src/__tests__/snips/v1/search.test.ts b/apps/api/src/__tests__/snips/v1/search.test.ts
index 875b9572f..3ee367ea5 100644
--- a/apps/api/src/__tests__/snips/v1/search.test.ts
+++ b/apps/api/src/__tests__/snips/v1/search.test.ts
@@ -78,4 +78,19 @@ describe("Search tests", () => {
},
60000,
);
+
+ it.concurrent(
+ "country defaults to undefined when location is set",
+ async () => {
+ const res = await search(
+ {
+ query: "firecrawl",
+ location: "San Francisco",
+ },
+ identity,
+ );
+ expect(res.length).toBeGreaterThan(0);
+ },
+ 60000,
+ );
});
diff --git a/apps/api/src/__tests__/snips/v2/search.test.ts b/apps/api/src/__tests__/snips/v2/search.test.ts
index 91247b330..0b1d82a84 100644
--- a/apps/api/src/__tests__/snips/v2/search.test.ts
+++ b/apps/api/src/__tests__/snips/v2/search.test.ts
@@ -190,4 +190,20 @@ describe("Search tests", () => {
},
60000,
);
+
+ it.concurrent(
+ "country defaults to undefined when location is set",
+ async () => {
+ const res = await search(
+ {
+ query: "firecrawl",
+ location: "San Francisco",
+ },
+ identity,
+ );
+ expect(res.web).toBeDefined();
+ expect(res.web?.length).toBeGreaterThan(0);
+ },
+ 60000,
+ );
});
diff --git a/apps/api/src/controllers/v1/types.ts b/apps/api/src/controllers/v1/types.ts
index fc7c15109..4818966d4 100644
--- a/apps/api/src/controllers/v1/types.ts
+++ b/apps/api/src/controllers/v1/types.ts
@@ -1446,7 +1446,7 @@ export const searchRequestSchema = z
tbs: z.string().optional(),
filter: z.string().optional(),
lang: z.string().optional().default("en"),
- country: z.string().optional().default("us"),
+ country: z.string().optional(),
location: z.string().optional(),
origin: z.string().optional().default("api"),
integration: integrationSchema.optional().transform(val => val || null),
@@ -1480,6 +1480,8 @@ export const searchRequestSchema = z
.refine(x => waitForRefine(x.scrapeOptions), waitForRefineOpts)
.transform(x => ({
...x,
+ country:
+ x.country !== undefined ? x.country : x.location ? undefined : "us",
scrapeOptions: extractTransform(x.scrapeOptions),
}));
diff --git a/apps/api/src/controllers/v2/types.ts b/apps/api/src/controllers/v2/types.ts
index d9becd702..4cd9d707c 100644
--- a/apps/api/src/controllers/v2/types.ts
+++ b/apps/api/src/controllers/v2/types.ts
@@ -1453,11 +1453,17 @@ export const searchRequestSchema = z
// Array of strings (simple format)
z.array(z.enum(["github", "research", "pdf"])),
// Array of objects (advanced format)
- z.array(z.union([githubCategoryOptions, researchCategoryOptions, pdfCategoryOptions])),
+ z.array(
+ z.union([
+ githubCategoryOptions,
+ researchCategoryOptions,
+ pdfCategoryOptions,
+ ]),
+ ),
])
.optional(),
lang: z.string().optional().default("en"),
- country: z.string().optional().default("us"),
+ country: z.string().optional(),
location: z.string().optional(),
origin: z.string().optional().default("api"),
integration: integrationSchema.optional().transform(val => val || null),
@@ -1504,6 +1510,9 @@ export const searchRequestSchema = z
)
.refine(x => waitForRefine(x.scrapeOptions), waitForRefineOpts)
.transform(x => {
+ const country =
+ x.country !== undefined ? x.country : x.location ? undefined : "us";
+
// Transform string array sources to object format
let sources = x.sources;
if (sources && Array.isArray(sources) && sources.length > 0) {
@@ -1518,7 +1527,7 @@ export const searchRequestSchema = z
tbs: x.tbs,
filter: x.filter,
lang: x.lang,
- country: x.country,
+ country,
location: x.location,
};
case "images":
@@ -1531,7 +1540,7 @@ export const searchRequestSchema = z
type: "news" as const,
tbs: x.tbs,
lang: x.lang,
- country: x.country,
+ country,
location: x.location,
};
default:
@@ -1572,6 +1581,7 @@ export const searchRequestSchema = z
return {
...x,
+ country,
sources,
categories,
scrapeOptions: extractTransform(x.scrapeOptions),