Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/2385-memory-csrf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed memory settings, catalog indexing and per-agent memory-config updates failing with a 403 "CSRF token missing" on a cookie-authenticated session: the three mutating calls in the Memory API client did not send the double-submit token.
14 changes: 8 additions & 6 deletions desktop/src/lib/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* Memory API client */
/* ------------------------------------------------------------------ */

import { withCsrf } from "./csrf";

const API = '/api';

async function fetchJson<T>(url: string, fallback: T, init?: RequestInit): Promise<T> {
Expand Down Expand Up @@ -87,11 +89,11 @@ export async function fetchMemorySettings(): Promise<Record<string, any>> {
}

export async function updateMemorySettings(settings: Record<string, any>): Promise<Record<string, any>> {
return fetchJson(`${API}/memory/settings`, {}, {
return fetchJson(`${API}/memory/settings`, {}, withCsrf({
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(settings),
});
}));
}

export async function fetchMemoryEndpoint(): Promise<TaOSmdEndpoint> {
Expand Down Expand Up @@ -128,11 +130,11 @@ export async function triggerCatalogIndex(body: {
end_date?: string;
force?: boolean;
}): Promise<any> {
return fetchJson(`${API}/memory/catalog/index`, {}, {
return fetchJson(`${API}/memory/catalog/index`, {}, withCsrf({
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
}));
}

export async function fetchCatalogSearch(query: string): Promise<any[]> {
Expand All @@ -152,9 +154,9 @@ export async function fetchAgentMemoryConfig(name: string): Promise<Record<strin
}

export async function updateAgentMemoryConfig(name: string, config: Record<string, any>): Promise<Record<string, any>> {
return fetchJson(`${API}/agents/${encodeURIComponent(name)}/memory-config`, {}, {
return fetchJson(`${API}/agents/${encodeURIComponent(name)}/memory-config`, {}, withCsrf({
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(config),
});
}));
}
Loading