Skip to content

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

Forward caller authorization for standalone enrichment (#4851)

Developers Digeste8f556f93063
diff --git a/apps/api/src/services/alexandria/retrieve.test.ts b/apps/api/src/services/alexandria/retrieve.test.ts
index a75101ab7..1e7f54d0c 100644
--- a/apps/api/src/services/alexandria/retrieve.test.ts
+++ b/apps/api/src/services/alexandria/retrieve.test.ts
@@ -545,3 +545,64 @@ it("does not forward credentials to another provider's sql capability", async ()
).toMatchObject({ status: 200, executed: true });
expect(executions()[0][0].resultAuthorization).toBeUndefined();
});
+
+const enrichmentCall = {
+ provider: "firecrawl",
+ capability: "enrich",
+ options: { url: "https://ca.linkedin.com/in/example", format: "json" },
+};
+it("forwards standalone enrichment credentials only to execution without retaining them", async () => {
+ exchangeAnswers({
+ success: true,
+ creditsCost: 0,
+ results: [
+ {
+ ...enrichmentCall,
+ creditsCost: 0,
+ data: { status: "disabled", steps: [] },
+ },
+ ],
+ });
+ expect(
+ await run({
+ calls: [enrichmentCall],
+ resultAuthorization: "Bearer caller",
+ }),
+ ).toMatchObject({ status: 200, executed: true });
+ expect(executions()).toHaveLength(1);
+ expect(executions()[0][0].resultAuthorization).toBe("Bearer caller");
+ expect(
+ mocks.request.mock.calls
+ .filter(([arg]) => arg.path !== "/v1/retrieve")
+ .every(([arg]) => arg.resultAuthorization === undefined),
+ ).toBe(true);
+ expect([...mocks.store.values()].join("")).not.toContain("Bearer caller");
+});
+it.each([
+ { name: "enrichment first", calls: [enrichmentCall, call] },
+ { name: "enrichment last", calls: [call, enrichmentCall] },
+ { name: "two enrichment calls", calls: [enrichmentCall, enrichmentCall] },
+])(
+ "rejects batched enrichment before side effects: $name",
+ async ({ calls }) => {
+ expect(
+ await run({ calls, resultAuthorization: "Bearer caller" }),
+ ).toMatchObject({ status: 400, executed: false });
+ expect(mocks.request).not.toHaveBeenCalled();
+ expect(mocks.authorize).not.toHaveBeenCalled();
+ expect(mocks.lock).not.toHaveBeenCalled();
+ expect(mocks.store.size).toBe(0);
+ },
+);
+it("does not forward credentials to another provider's enrich capability", async () => {
+ const other = { ...enrichmentCall, provider: "other" };
+ exchangeAnswers({
+ success: true,
+ creditsCost: 0,
+ results: [{ ...other, creditsCost: 0, data: {} }],
+ });
+ expect(
+ await run({ calls: [other], resultAuthorization: "Bearer caller" }),
+ ).toMatchObject({ status: 200, executed: true });
+ expect(executions()[0][0].resultAuthorization).toBeUndefined();
+});
diff --git a/apps/api/src/services/alexandria/retrieve.ts b/apps/api/src/services/alexandria/retrieve.ts
index 094d64115..104299538 100644
--- a/apps/api/src/services/alexandria/retrieve.ts
+++ b/apps/api/src/services/alexandria/retrieve.ts
@@ -117,6 +117,17 @@ export async function retrieveProviders(input: {
),
);
+ const usesEnrichment = input.calls.some(
+ call => call.provider === "firecrawl" && call.capability === "enrich",
+ );
+ if (usesEnrichment && input.calls.length !== 1)
+ return notExecuted(
+ refusal(
+ 400,
+ "Enrichment must be sent as a separate request; do not batch it with other calls.",
+ ),
+ );
+
const loadsSavedResult = input.calls.some(
call =>
call.provider === "firecrawl" &&
@@ -358,7 +369,8 @@ export async function retrieveProviders(input: {
body: { requests: input.calls },
timeoutMs: remaining(),
requestId: id,
- ...((loadsSavedResult || usesSql) && input.resultAuthorization
+ ...((loadsSavedResult || usesSql || usesEnrichment) &&
+ input.resultAuthorization
? { resultAuthorization: input.resultAuthorization }
: {}),
...(termsIdentity ? { termsIdentity } : {}),