Skip to content

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

Send a whole-millisecond x-exchange-deadline header (#5227)

Gergő Móricz32dd7bc08c2f
diff --git a/apps/api/src/services/alexandria/client.test.ts b/apps/api/src/services/alexandria/client.test.ts
index 656f1cd26..97eb14b0b 100644
--- a/apps/api/src/services/alexandria/client.test.ts
+++ b/apps/api/src/services/alexandria/client.test.ts
@@ -50,4 +50,16 @@ describe("exchangeRequest", () => {
});
expect(headersOf()).not.toHaveProperty("x-exchange-connectors");
});
+
+ it("sends the deadline as a whole number of milliseconds", async () => {
+ await exchangeRequest({
+ teamId: "team",
+ path: "/v1/retrieve",
+ body: {},
+ timeoutMs: 12345,
+ maximumCredits: 10,
+ });
+ const deadline = Number(headersOf()["x-exchange-deadline"]);
+ expect(Number.isSafeInteger(deadline)).toBe(true);
+ });
});
diff --git a/apps/api/src/services/alexandria/client.ts b/apps/api/src/services/alexandria/client.ts
index ebea3b135..ce45d05be 100644
--- a/apps/api/src/services/alexandria/client.ts
+++ b/apps/api/src/services/alexandria/client.ts
@@ -52,9 +52,11 @@ export async function exchangeRequest(input: {
"x-exchange-max-credits": String(input.maximumCredits),
// Leave the Exchange a margin to answer before our own timeout.
"x-exchange-deadline": String(
- Date.now() +
- input.timeoutMs -
- Math.min(2000, input.timeoutMs / 10),
+ Math.floor(
+ Date.now() +
+ input.timeoutMs -
+ Math.min(2000, input.timeoutMs / 10),
+ ),
),
}),
},