@cognigy/rest-api-client
Version:
Cognigy REST-Client
48 lines • 2.22 kB
JavaScript
/**
* Processes profile data based on the specified memory type or agent option.
*
* @param type - The type of memory processing to apply
* @param cleanedProfile - The sanitized user profile data
* @param selectedFields - Optional array of field names to include when using selectedProfileFields
* @returns Processed profile data according to the specified type
*/
export const processMemoryByType = (type, cleanedProfile, selectedFields) => {
switch (type) {
case "completeProfile":
return cleanedProfile;
case "profileMemoriesOnly":
return { "memories": cleanedProfile.memories };
case "selectedProfileFields":
if (!(selectedFields === null || selectedFields === void 0 ? void 0 : selectedFields.length)) {
return {};
}
return selectedFields.reduce((acc, field) => {
if (cleanedProfile[field]) {
acc[field] = cleanedProfile[field];
}
return acc;
}, {});
default:
return {};
}
};
/**
* Retrieves the user memory based on the specified memory type and profile fields.
*
* @param memoryType - The type of memory to retrieve, as specified in the AI agent job parameters.
* @param selectedProfileFields - The profile fields selected in the AI agent job parameters.
* @param aiAgent - The AI agent instance containing contact profile options and selected profiles.
* @param cleanedProfile - The cleaned profile data as a partial flattened profile.
* @returns The user memory, which can be a partial flattened profile, an array of memory objects, or undefined.
*/
export const getUserMemory = (memoryType, selectedProfileFields, aiAgent, cleanedProfile) => {
let userMemory;
if (memoryType === "inherit" && (aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.contactProfilesOption)) {
userMemory = processMemoryByType(aiAgent.contactProfilesOption, cleanedProfile, aiAgent.contactProfilesSelected);
}
else {
userMemory = processMemoryByType(memoryType, cleanedProfile, selectedProfileFields);
}
return userMemory;
};
//# sourceMappingURL=getUserMemory.js.map