diff --git a/src/cli.ts b/src/cli.ts index e1ea9757..28f7c761 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1716,6 +1716,13 @@ function buildDemoSessions(): DemoSession[] { ]; } +function jsonAuthHeaders(): Record { + const headers: Record = { "Content-Type": "application/json" }; + const secret = process.env["AGENTMEMORY_SECRET"]; + if (secret) headers["Authorization"] = `Bearer ${secret}`; + return headers; +} + async function postJson( url: string, body: unknown, @@ -1724,7 +1731,7 @@ async function postJson( try { const res = await fetch(url, { method: "POST", - headers: { "Content-Type": "application/json" }, + headers: jsonAuthHeaders(), body: JSON.stringify(body), signal: AbortSignal.timeout(timeoutMs), }); @@ -1742,7 +1749,7 @@ async function postJsonStrict( ): Promise { const res = await fetch(url, { method: "POST", - headers: { "Content-Type": "application/json" }, + headers: jsonAuthHeaders(), body: JSON.stringify(body), signal: AbortSignal.timeout(timeoutMs), });