Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥
TypeScript aiai-agentsai-crawlerai-scrapingai-searchcrawlerdata-extractionhtml-to-markdownllmmarkdownscraperscrapingweb-crawlerweb-dataweb-data-extractionweb-scraperweb-scrapingweb-searchwebscraping
feat(api): forward the caller credential to Exchange on every execution (#4964)
Developers Digest4a4309edaafa
diff --git a/apps/api/src/services/alexandria/README.md b/apps/api/src/services/alexandria/README.mdindex 5d1db77ee..40b685cad 100644--- a/apps/api/src/services/alexandria/README.md+++ b/apps/api/src/services/alexandria/README.md@@ -87,8 +87,12 @@ API, Redis, Exchange (`FIRE_EXCHANGE_URL`; a non-blankexecution. Paid settlement is covered by mocked tests only and has not runagainst an Autumn sandbox.-Bash source loading (`firecrawl/bash` with `options.requestId`) must be sent as a-single-call request. Mixed batches are rejected before billing or dispatch because-caller authorization is request-scoped. Workspace reuse (`options.workspaceId`)-does not forward the caller credential. Exchange consumes the forwarded credential-only in its Bash saved-scrape reader; provider integrations use their own credentials.+The caller's `Authorization` header is forwarded to Exchange on every execution+request (`/v1/retrieve`), never on quote or authorization requests, and is never+stored. It lets Exchange tools that call Firecrawl on the caller's behalf (the+caller pays) authenticate upstream. Exchange decides which tools read it;+provider integrations use their own credentials.++Bash source loading (`firecrawl/bash` with `options.requestId`), SQL and enrichment+must still be sent as single-call requests. Mixed batches are rejected before billing+or dispatch.diff --git a/apps/api/src/services/alexandria/retrieve.test.ts b/apps/api/src/services/alexandria/retrieve.test.tsindex 1e7f54d0c..44c2e645a 100644--- a/apps/api/src/services/alexandria/retrieve.test.ts+++ b/apps/api/src/services/alexandria/retrieve.test.ts@@ -337,7 +337,7 @@ it.each([options: { requestId: "source" },},{ provider: "other", capability: "bash", options: { requestId: "source" } },-])("does not forward credentials for other calls: %j", async other => {+])("forwards credentials with execution for mixed calls: %j", async other => {exchangeAnswers({success: true,creditsCost: 0,@@ -350,11 +350,11 @@ it.each([expect(await run({ calls: [call, other], resultAuthorization: "Bearer caller" }),).toMatchObject({ status: 200, executed: true });- expect(executions()[0][0].resultAuthorization).toBeUndefined();+ expect(executions()[0][0].resultAuthorization).toBe("Bearer caller");});it.each([123, null, false, {}, []])(- "never forwards credentials for a non-string Bash requestId: %j",+ "forwards credentials with execution for a non-string Bash requestId: %j",async requestId => {const bash = {provider: "firecrawl",@@ -369,7 +369,7 @@ it.each([123, null, false, {}, []])(await run({ calls: [call, bash], resultAuthorization: "Bearer caller" }),).toMatchObject({ status: 400 });expect(executions()).toHaveLength(1);- expect(executions()[0][0].resultAuthorization).toBeUndefined();+ expect(executions()[0][0].resultAuthorization).toBe("Bearer caller");},);@@ -533,7 +533,7 @@ it.each([expect(mocks.lock).not.toHaveBeenCalled();expect(mocks.store.size).toBe(0);});-it("does not forward credentials to another provider's sql capability", async () => {+it("forwards credentials with execution for another provider's sql capability", async () => {const other = { ...sqlCall, provider: "other" };exchangeAnswers({success: true,@@ -543,7 +543,7 @@ it("does not forward credentials to another provider's sql capability", async ()expect(await run({ calls: [other], resultAuthorization: "Bearer caller" }),).toMatchObject({ status: 200, executed: true });- expect(executions()[0][0].resultAuthorization).toBeUndefined();+ expect(executions()[0][0].resultAuthorization).toBe("Bearer caller");});const enrichmentCall = {@@ -594,7 +594,7 @@ it.each([expect(mocks.store.size).toBe(0);},);-it("does not forward credentials to another provider's enrich capability", async () => {+it("forwards credentials with execution for another provider's enrich capability", async () => {const other = { ...enrichmentCall, provider: "other" };exchangeAnswers({success: true,@@ -604,5 +604,42 @@ it("does not forward credentials to another provider's enrich capability", asyncexpect(await run({ calls: [other], resultAuthorization: "Bearer caller" }),).toMatchObject({ status: 200, executed: true });+ expect(executions()[0][0].resultAuthorization).toBe("Bearer caller");+});++it("forwards credentials with execution for any provider, never to quote or authorization, and never retains them", async () => {+ const plain = {+ provider: "fred",+ capability: "series/observations",+ options: { series_id: "GDP" },+ };+ exchangeAnswers({+ success: true,+ creditsCost: 0,+ results: [{ ...plain, creditsCost: 0, data: {} }],+ });+ expect(+ await run({ calls: [plain], 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("sends no credentials when the caller supplied none", async () => {+ exchangeAnswers({+ success: true,+ creditsCost: 0,+ results: [{ ...call, creditsCost: 0, data: {} }],+ });+ expect(await run({ calls: [call] })).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.tsindex 104299538..b0db2f2b1 100644--- a/apps/api/src/services/alexandria/retrieve.ts+++ b/apps/api/src/services/alexandria/retrieve.ts@@ -369,8 +369,9 @@ export async function retrieveProviders(input: {body: { requests: input.calls },timeoutMs: remaining(),requestId: id,- ...((loadsSavedResult || usesSql || usesEnrichment) &&- input.resultAuthorization+ // Sent with every execution so Exchange tools that call Firecrawl as the caller+ // (the caller pays) can authenticate upstream. Exchange decides which tools read it.+ ...(input.resultAuthorization? { resultAuthorization: input.resultAuthorization }: {}),...(termsIdentity ? { termsIdentity } : {}),