Skip to content

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

Accept optional Search objective and client model (#4881)

Kris Oeie76d5b6fcdce
diff --git a/apps/api/src/__tests__/snips/v2/search-feedback.test.ts b/apps/api/src/__tests__/snips/v2/search-feedback.test.ts
index df36ad307..036f0b14f 100644
--- a/apps/api/src/__tests__/snips/v2/search-feedback.test.ts
+++ b/apps/api/src/__tests__/snips/v2/search-feedback.test.ts
@@ -35,13 +35,37 @@ describeIf(TEST_PRODUCTION)("Search feedback tests", () => {
"records feedback and refunds 1 credit on first submission",
async () => {
const raw = await searchRawFull(
- { query: "firecrawl", limit: 3 },
+ {
+ query: "firecrawl",
+ objective: "Find official Firecrawl information",
+ clientModel: "claude-sonnet-4-6",
+ limit: 3,
+ },
identity,
);
expect(raw.statusCode).toBe(200);
expect(typeof raw.body.id).toBe("string");
expect((raw.body.data?.web ?? []).length).toBeGreaterThan(0);
+ let searchRow: { options: unknown } | undefined;
+ for (let attempt = 0; attempt < 20 && !searchRow; attempt++) {
+ [searchRow] = await db
+ .select({ options: schema.searches.options })
+ .from(schema.searches)
+ .where(
+ and(
+ eq(schema.searches.id, raw.body.id),
+ eq(schema.searches.team_id, identity.teamId),
+ ),
+ )
+ .limit(1);
+ if (!searchRow) await new Promise(resolve => setTimeout(resolve, 100));
+ }
+ expect(searchRow?.options).toMatchObject({
+ objective: "Find official Firecrawl information",
+ clientModel: "claude-sonnet-4-6",
+ });
+
const result = await searchFeedback(
raw.body.id,
{
@@ -73,6 +97,12 @@ describeIf(TEST_PRODUCTION)("Search feedback tests", () => {
expect(result.creditsRefunded).toBe(1);
expect(result.alreadySubmitted).toBeFalsy();
expect(typeof result.feedbackId).toBe("string");
+ const [feedbackRow] = await db
+ .select({ searchId: schema.search_feedback.search_id })
+ .from(schema.search_feedback)
+ .where(eq(schema.search_feedback.id, result.feedbackId!))
+ .limit(1);
+ expect(feedbackRow?.searchId).toBe(raw.body.id);
},
90000,
);
diff --git a/apps/api/src/__tests__/snips/v2/search.test.ts b/apps/api/src/__tests__/snips/v2/search.test.ts
index 3c00ee095..845bfd8c1 100644
--- a/apps/api/src/__tests__/snips/v2/search.test.ts
+++ b/apps/api/src/__tests__/snips/v2/search.test.ts
@@ -35,6 +35,35 @@ describeIf(TEST_PRODUCTION || HAS_SEARCH || HAS_PROXY)("Search tests", () => {
60000,
);
+ it.concurrent(
+ "accepts optional agent task context",
+ async () => {
+ const res = await search(
+ {
+ query: "firecrawl documentation",
+ objective: "Find official Firecrawl API documentation",
+ clientModel: "claude-sonnet-4-6",
+ limit: 1,
+ },
+ identity,
+ );
+ expect(res.web?.length).toBeGreaterThan(0);
+ },
+ 60000,
+ );
+
+ it.concurrent(
+ "ignores invalid agent task context instead of failing the search",
+ async () => {
+ const res = await search(
+ { query: "firecrawl", objective: "x".repeat(5001), limit: 1 },
+ identity,
+ );
+ expect(res.web?.length).toBeGreaterThan(0);
+ },
+ 60000,
+ );
+
it.concurrent(
"works with includeDomains",
async () => {
diff --git a/apps/api/src/controllers/v2/search-schema.test.ts b/apps/api/src/controllers/v2/search-schema.test.ts
index bd30c2c05..0106125a1 100644
--- a/apps/api/src/controllers/v2/search-schema.test.ts
+++ b/apps/api/src/controllers/v2/search-schema.test.ts
@@ -50,4 +50,42 @@ describe("searchRequestSchema highlights", () => {
expect(request.highlights).toBe(false);
});
+
+ it("accepts optional agent task context without changing search defaults", () => {
+ const request = searchRequestSchema.parse({
+ query: "React memo docs",
+ objective:
+ " Find official guidance on preventing unnecessary rerenders ",
+ clientModel: " claude-sonnet-4-6 ",
+ });
+
+ expect(request).toMatchObject({
+ query: "React memo docs",
+ objective: "Find official guidance on preventing unnecessary rerenders",
+ clientModel: "claude-sonnet-4-6",
+ limit: 10,
+ });
+ expect(
+ searchRequestSchema.parse({ query: "React memo docs" }),
+ ).not.toHaveProperty("objective");
+ });
+
+ it.each([
+ { objective: " " },
+ { objective: "x".repeat(5001) },
+ { objective: null },
+ { clientModel: " " },
+ { clientModel: "x".repeat(129) },
+ { clientModel: 42 },
+ ])("drops invalid agent task context without failing the search %j", context => {
+ const result = searchRequestSchema.safeParse({
+ query: "React memo docs",
+ ...context,
+ });
+
+ expect(result.success).toBe(true);
+ expect(result.data?.objective).toBeUndefined();
+ expect(result.data?.clientModel).toBeUndefined();
+ expect(result.data?.limit).toBe(10);
+ });
});
diff --git a/apps/api/src/controllers/v2/types.ts b/apps/api/src/controllers/v2/types.ts
index 5ef2669ca..280d1021b 100644
--- a/apps/api/src/controllers/v2/types.ts
+++ b/apps/api/src/controllers/v2/types.ts
@@ -2494,6 +2494,8 @@ const searchDomainSchema = z
export const searchRequestSchema = z
.strictObject({
query: z.string(),
+ objective: z.string().trim().min(1).max(5000).optional().catch(undefined),
+ clientModel: z.string().trim().min(1).max(128).optional().catch(undefined),
limit: z.int().positive().finite().max(100).optional().prefault(10),
tbs: z.string().optional(),
filter: z.string().optional(),
diff --git a/apps/api/src/services/logging/log_job.test.ts b/apps/api/src/services/logging/log_job.test.ts
index 315687dfa..6f2f1af6b 100644
--- a/apps/api/src/services/logging/log_job.test.ts
+++ b/apps/api/src/services/logging/log_job.test.ts
@@ -233,6 +233,44 @@ describe("logSearch", () => {
);
});
+ it("stores optional task context with the search options", async () => {
+ const options = {
+ query: "React memo docs",
+ objective: "Find official rerender guidance",
+ clientModel: "claude-sonnet-4-6",
+ };
+
+ await logSearch(makeSearch({ query: options.query, options }));
+
+ expect(values.mock.calls[0][0].options).toMatchObject(options);
+ const published = JSON.parse(
+ publishMessage.mock.calls[0][0].data.toString(),
+ );
+ expect(published.options).toMatchObject(options);
+ });
+
+ it("does not retain task context for ZDR searches", async () => {
+ await logSearch(
+ makeSearch({
+ options: {
+ query: "React memo docs",
+ objective: "Find official rerender guidance",
+ clientModel: "claude-sonnet-4-6",
+ enterprise: ["zdr"],
+ },
+ zeroDataRetention: true,
+ }),
+ );
+
+ expect(values.mock.calls[0][0].options).not.toHaveProperty("objective");
+ expect(values.mock.calls[0][0].options).not.toHaveProperty("clientModel");
+ const published = JSON.parse(
+ publishMessage.mock.calls[0][0].data.toString(),
+ );
+ expect(published.options).not.toHaveProperty("objective");
+ expect(published.options).not.toHaveProperty("clientModel");
+ });
+
it("fails the log call on a serialization failure before touching PostgreSQL", async () => {
const search = makeSearch({ options: { unsupported: 1n } });