forked from NateBJones-Projects/OB1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread-only.ts
More file actions
33 lines (28 loc) · 872 Bytes
/
Copy pathread-only.ts
File metadata and controls
33 lines (28 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
export const READ_ONLY_ERROR = {
error: "read_only_mode",
message: "Agent Memory API is read-only for this environment.",
};
const TRUE_VALUES = new Set(["1", "true", "yes", "on"]);
const WRITE_ENDPOINTS = new Set([
"POST /recall",
"POST /writeback",
"POST /recall/:request_id/usage",
"PATCH /memories/:id/review",
]);
export function parseBooleanEnv(value: string | undefined): boolean {
if (!value) return false;
return TRUE_VALUES.has(value.trim().toLowerCase());
}
export function readOnlyEnabledFromEnv(
value = Deno.env.get("AGENT_MEMORY_READ_ONLY"),
): boolean {
return parseBooleanEnv(value);
}
export function shouldBlockWriteEndpoint(
method: string,
endpointPattern: string,
readOnlyEnabled: boolean,
): boolean {
if (!readOnlyEnabled) return false;
return WRITE_ENDPOINTS.has(`${method.toUpperCase()} ${endpointPattern}`);
}