Skip to content
Open
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
7 changes: 4 additions & 3 deletions src/triggers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ type FacetCount = { value: string; count: number };

function memoryFacets(
memories: Array<{ isLatest?: boolean; project?: string; agentId?: string; type?: string }>,
project?: string,
): { projects: FacetCount[]; agents: FacetCount[]; types: FacetCount[] } {
const tally = (pick: (m: (typeof memories)[number]) => string | undefined) => {
const counts = new Map<string, number>();
Expand All @@ -308,7 +309,7 @@ function memoryFacets(
return {
projects: tally((m) => m.project),
agents: tally((m) => m.agentId),
types: tally((m) => m.type),
types: tally((m) => !project || m.project === project ? m.type : undefined),
};
}

Expand Down Expand Up @@ -2770,9 +2771,9 @@ export function registerApiTriggers(
(includeOrphans && m.agentId === undefined),
);
}
const facets =
req.query_params?.["facets"] === "true" ? memoryFacets(filtered) : undefined;
const listQuery = parseListQuery(req.query_params);
const facets =
req.query_params?.["facets"] === "true" ? memoryFacets(filtered, listQuery.project) : undefined;
if (listQuery.project) filtered = filtered.filter((m) => m.project === listQuery.project);
if (listQuery.type) filtered = filtered.filter((m) => m.type === listQuery.type);
const fromSession = asNonEmptyString(req.query_params?.["sessionId"]);
Expand Down
Loading