MCPcopy
hub / github.com/ModelEngine-Group/nexent / fetchAgentSharedGroups

Function fetchAgentSharedGroups

frontend/services/memoryService.ts:244–293  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

242}
243
244export async function fetchAgentSharedGroups(): Promise<MemoryGroup[]> {
245 // Parallel requests: memory list + full Agent list
246 const [{ items }, agentsRes] = await Promise.all([
247 listMemories("agent"),
248 fetchAllAgents(),
249 ]);
250
251 // First group results with memories by agent_id
252 const groupMap: Record<string, MemoryItem[]> = {};
253 items.forEach((item) => {
254 if (!item.agent_id) return;
255 if (!groupMap[item.agent_id]) groupMap[item.agent_id] = [];
256 groupMap[item.agent_id].push(item);
257 });
258
259 // Complete groups with agents that have no memories
260 const agentList: Array<{
261 agent_id: string;
262 name?: string;
263 display_name?: string;
264 }> = (agentsRes as any)?.success ? (agentsRes as any).data : [];
265
266 const groups: MemoryGroup[] = [];
267
268 // Build groups in Agent list order to ensure completeness
269 agentList.forEach((agent) => {
270 const agentId = agent.agent_id;
271 const list = groupMap[agentId] || [];
272 groups.push({
273 title: i18next.t("memoryService.agentSharedGroupTitle", {
274 agentName: agent.display_name || agent.name || agentId,
275 }),
276 key: `agent-${agentId}`,
277 items: list,
278 });
279 });
280
281 // If still no agent info, return placeholder group
282 if (groups.length === 0) {
283 return [
284 {
285 title: i18next.t("memoryService.agentSharedPlaceholder"),
286 key: "agent-placeholder",
287 items: [],
288 },
289 ];
290 }
291
292 return groups;
293}
294
295export async function fetchUserPersonalGroup(): Promise<MemoryGroup> {
296 const { items } = await listMemories("user");

Callers 1

loadGroupsForActiveTabFunction · 0.90

Calls 3

fetchAllAgentsFunction · 0.90
listMemoriesFunction · 0.85
allMethod · 0.45

Tested by

no test coverage detected