Skip to content

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

Feat/pass request id to fire engine search (#4402)

Thomas Kosmas143d3b070306
diff --git a/apps/api/src/lib/retry-utils.ts b/apps/api/src/lib/retry-utils.ts
index 6246e8a9c..e32269949 100644
--- a/apps/api/src/lib/retry-utils.ts
+++ b/apps/api/src/lib/retry-utils.ts
@@ -11,6 +11,7 @@ export async function attemptRequest<T>(
url: string,
data: string,
abort?: AbortSignal,
+ requestId?: string,
): Promise<T | null> {
try {
const response = await fetch(url, {
@@ -18,6 +19,7 @@ export async function attemptRequest<T>(
headers: {
"Content-Type": "application/json",
"X-Disable-Cache": "true",
+ ...(requestId ? { "X-Request-ID": requestId } : {}),
},
body: data,
signal: abort,
diff --git a/apps/api/src/search/execute.ts b/apps/api/src/search/execute.ts
index 5867d00d9..341e751c1 100644
--- a/apps/api/src/search/execute.ts
+++ b/apps/api/src/search/execute.ts
@@ -129,6 +129,7 @@ export async function executeSearch(
: ((await search({
query: searchQuery,
logger,
+ requestId: context.requestId,
advanced: false,
num_results: num_results_buffer,
tbs: options.tbs,
diff --git a/apps/api/src/search/v2/fireEngine-v2.ts b/apps/api/src/search/v2/fireEngine-v2.ts
index b5b174b08..bbd91817e 100644
--- a/apps/api/src/search/v2/fireEngine-v2.ts
+++ b/apps/api/src/search/v2/fireEngine-v2.ts
@@ -40,6 +40,7 @@ function normalizeSearchTypes(
export async function fire_engine_search_v2(
q: string,
options: {
+ requestId?: string;
tbs?: string;
filter?: string;
lang?: string;
@@ -78,7 +79,7 @@ export async function fire_engine_search_v2(
const data = JSON.stringify(payload);
const result = await executeWithRetry<SearchV2Response>(
- () => attemptRequest<SearchV2Response>(url, data, abort),
+ () => attemptRequest<SearchV2Response>(url, data, abort, options.requestId),
(response): response is SearchV2Response => response !== null,
abort,
);
diff --git a/apps/api/src/search/v2/index.ts b/apps/api/src/search/v2/index.ts
index 271e5d431..999dec3df 100644
--- a/apps/api/src/search/v2/index.ts
+++ b/apps/api/src/search/v2/index.ts
@@ -8,6 +8,7 @@ import { Logger } from "winston";
export async function search({
query,
logger,
+ requestId,
advanced = false,
num_results = 5,
tbs = undefined,
@@ -24,6 +25,7 @@ export async function search({
}: {
query: string;
logger: Logger;
+ requestId?: string;
advanced?: boolean;
num_results?: number;
tbs?: string;
@@ -42,6 +44,7 @@ export async function search({
if (config.FIRE_ENGINE_BETA_URL) {
logger.info("Using fire engine search");
const results = await fire_engine_search_v2(query, {
+ requestId,
numResults: num_results,
tbs,
filter,