@cognigy/rest-api-client
Version:
Cognigy REST-Client
194 lines • 6.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LOAD_AI_AGENT = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../../createNodeDescriptor");
/**
* Node name: 'loadAiAigent'
*
* Purpose:
* Loads the AI Agent configuration and stores it to context/input.
*/
exports.LOAD_AI_AGENT = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "loadAiAigent",
defaultLabel: "Load AI Agent",
summary: "UI__NODE_EDITOR__LOAD_AI_AGENT__SUMMARY",
appearance: {
showIcon: false
},
fields: [
{
key: "aiAgent",
type: "aiAgentSelect",
label: "UI__NODE_EDITOR__LOAD_AI_AGENT__AI_AGENT_SELECTOR__LABEL",
description: "UI__NODE_EDITOR__AI_AGENT__AI_AGENT_SELECTOR__DESCRIPTION",
params: {
required: true
},
},
{
key: "storeLocation",
type: "select",
label: "UI__NODE_EDITOR__LOAD_AI_AGENT__FIELDS__STORE_LOCATION__LABEL",
description: "UI__NODE_EDITOR__LOAD_AI_AGENT__FIELDS__STORE_LOCATION__DESCRIPTION",
defaultValue: "context",
params: {
options: [
{
label: "UI__NODE_EDITOR__LOAD_AI_AGENT__FIELDS__STORE_LOCATION__OPTIONS__INPUT__LABEL",
value: "input"
},
{
label: "UI__NODE_EDITOR__LOAD_AI_AGENT__FIELDS__STORE_LOCATION__OPTIONS__CONTEXT__LABEL",
value: "context"
}
],
required: true
},
},
{
key: "inputKey",
type: "cognigyText",
label: "UI__NODE_EDITOR__LOAD_AI_AGENT__FIELDS__INPUT_KEY__LABEL",
description: "UI__NODE_EDITOR__LOAD_AI_AGENT__FIELDS__INPUT_KEY__DESCRIPTION",
defaultValue: "aiAgentConfiguration",
condition: {
or: [
{
key: "storeLocation",
value: "input",
}
]
}
},
{
key: "contextKey",
type: "cognigyText",
label: "UI__NODE_EDITOR__LOAD_AI_AGENT__FIELDS__CONTEXT_KEY__LABEL",
description: "UI__NODE_EDITOR__LOAD_AI_AGENT__FIELDS__CONTEXT_KEY__DESCRIPTION",
defaultValue: "aiAgentConfiguration",
condition: {
key: "storeLocation",
value: "context",
}
},
{
key: "keyWarning",
type: "description",
label: " ",
params: {
text: "UI__NODE_EDITOR__LOAD_AI_AGENT__FIELDS__KEY_WARNING__TEXT"
},
condition: {
or: [
{
and: [
{
key: "storeLocation",
value: "input",
},
{
key: "inputKey",
value: "aiAgentConfiguration",
negate: true
}
]
},
{
and: [
{
key: "storeLocation",
value: "context",
},
{
key: "contextKey",
value: "aiAgentConfiguration",
negate: true
}
]
}
]
}
}
],
preview: {
key: "storeLocation",
type: "text",
},
form: [
{ type: "field", key: "aiAgent" },
{ type: "field", key: "storeLocation" },
{ type: "field", key: "inputKey" },
{ type: "field", key: "contextKey" },
{ type: "field", key: "keyWarning" }
],
tags: ["ai", "aiagent", "llm"],
tokens: [
{
label: "AI Agent Reference ID",
type: "input",
script: "(input.aiAgentConfiguration || context.aiAgentConfiguration)?.referenceId",
},
{
label: "AI Agent Name",
type: "input",
script: "(input.aiAgentConfiguration || context.aiAgentConfiguration)?.name",
},
{
label: "AI Agent Description",
type: "input",
script: "(input.aiAgentConfiguration || context.aiAgentConfiguration)?.description",
},
{
label: "AI Agent Instructions",
type: "input",
script: "(input.aiAgentConfiguration || context.aiAgentConfiguration)?.instructions",
},
{
label: "AI Agent Image URL",
type: "input",
script: "(input.aiAgentConfiguration || context.aiAgentConfiguration)?.image",
},
{
label: "AI Agent Knowledge Store ID",
type: "input",
script: "(input.aiAgentConfiguration || context.aiAgentConfiguration)?.knowledgeReferenceId",
},
],
function: async ({ cognigy, config }) => {
const { api } = cognigy;
const { aiAgent, storeLocation, contextKey, inputKey } = config;
if (storeLocation === "input" && !inputKey) {
throw new Error("Unable to add value to input. No input key was defined.");
}
if (storeLocation === "context" && !contextKey) {
throw new Error("Unable to add value to context. No context key was defined.");
}
if (!aiAgent) {
throw new Error("Unable to load AI Agent values. No AI agent was defined.");
}
const aiAgentData = {
referenceId: aiAgent.referenceId,
name: aiAgent.name,
description: aiAgent.description,
instructions: aiAgent.instructions,
image: aiAgent.image,
speakingStyle: aiAgent.speakingStyle,
safetySettings: aiAgent.safetySettings,
contactProfilesOption: aiAgent.contactProfilesOption,
contactProfilesSelected: aiAgent.contactProfilesSelected,
knowledgeReferenceId: aiAgent.knowledgeReferenceId,
enableVoiceConfigs: aiAgent.enableVoiceConfigs,
voiceConfigs: aiAgent.voiceConfigs,
};
switch (storeLocation) {
case "context":
// @ts-ignore
api.addToContext(contextKey, aiAgentData, "simple");
break;
default:
api.addToInput(inputKey, aiAgentData);
}
}
});
//# sourceMappingURL=loadAiAgent.js.map