@cognigy/rest-api-client
Version:
Cognigy REST-Client
53 lines • 2.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getUserMemory = exports.processMemoryByType = void 0;
/**
* 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
*/
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 {};
}
};
exports.processMemoryByType = processMemoryByType;
/**
* 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.
*/
const getUserMemory = (memoryType, selectedProfileFields, aiAgent, cleanedProfile) => {
let userMemory;
if (memoryType === "inherit" && (aiAgent === null || aiAgent === void 0 ? void 0 : aiAgent.contactProfilesOption)) {
userMemory = (0, exports.processMemoryByType)(aiAgent.contactProfilesOption, cleanedProfile, aiAgent.contactProfilesSelected);
}
else {
userMemory = (0, exports.processMemoryByType)(memoryType, cleanedProfile, selectedProfileFields);
}
return userMemory;
};
exports.getUserMemory = getUserMemory;
//# sourceMappingURL=getUserMemory.js.map