mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-13 18:43:58 +00:00
fix(tools): bound memory forget requests (#1451)
This commit is contained in:
parent
7f448d55d8
commit
82dae50ef4
2 changed files with 23 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
|||
const DEFAULT_BASE_URL = "https://api.supermemory.ai"
|
||||
const FETCH_TIMEOUT_MS = 30_000
|
||||
|
||||
export interface ForgetMemoryParams {
|
||||
containerTag: string
|
||||
|
|
@ -7,6 +8,10 @@ export interface ForgetMemoryParams {
|
|||
reason?: string
|
||||
}
|
||||
|
||||
export interface ForgetMemoryRequestOptions {
|
||||
signal?: AbortSignal
|
||||
}
|
||||
|
||||
/**
|
||||
* Marks a memory as forgotten via `DELETE /v4/memories`.
|
||||
*
|
||||
|
|
@ -19,6 +24,7 @@ export async function forgetMemoryRequest(
|
|||
apiKey: string,
|
||||
params: ForgetMemoryParams,
|
||||
baseUrl: string = DEFAULT_BASE_URL,
|
||||
options?: ForgetMemoryRequestOptions,
|
||||
): Promise<void> {
|
||||
const response = await fetch(`${baseUrl}/v4/memories`, {
|
||||
method: "DELETE",
|
||||
|
|
@ -27,6 +33,7 @@ export async function forgetMemoryRequest(
|
|||
Authorization: `Bearer ${apiKey}`,
|
||||
},
|
||||
body: JSON.stringify(params),
|
||||
signal: options?.signal ?? AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
|
|
|
|||
|
|
@ -109,6 +109,22 @@ describe("memoryForget", () => {
|
|||
id: "mem_1",
|
||||
reason: "outdated",
|
||||
})
|
||||
expect(init.signal).toBeInstanceOf(AbortSignal)
|
||||
})
|
||||
|
||||
it("uses a caller-provided signal instead of creating a timeout", async () => {
|
||||
const fetchMock = stubFetch()
|
||||
const controller = new AbortController()
|
||||
|
||||
await forgetMemoryRequest(
|
||||
API_KEY,
|
||||
{ containerTag: "user_1", id: "mem_1" },
|
||||
undefined,
|
||||
{ signal: controller.signal },
|
||||
)
|
||||
|
||||
const [, init] = fetchMock.mock.calls[0] as [string, RequestInit]
|
||||
expect(init.signal).toBe(controller.signal)
|
||||
})
|
||||
|
||||
it("throws a descriptive error on non-2xx responses", async () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue