UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

411 lines 14.3 kB
import { __awaiter } from "tslib"; /* Custom modules */ import { createNodeDescriptor } from "../../createNodeDescriptor"; import { TranscriptEntrySource, TranscriptEntryType, TranscriptRole } from "../../../interfaces/transcripts/transcripts"; /** * Node name: 'addTranscriptStep' * * Purpose: * Add a transcript step to the current session */ export const ADD_TRANSCRIPT_STEP = createNodeDescriptor({ type: "addTranscriptStep", defaultLabel: "Add Transcript Step", summary: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__SUMMARY", appearance: { showIcon: false }, fields: [ { key: "role", type: "select", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__ROLE__LABEL", defaultValue: TranscriptRole.USER, params: { options: [ { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__ROLE__OPTIONS__USER", value: TranscriptRole.USER, }, { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__ROLE__OPTIONS__ASSISTANT", value: TranscriptRole.ASSISTANT, }, { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__ROLE__OPTIONS__AGENT", value: TranscriptRole.AGENT, }, { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__ROLE__OPTIONS__SYSTEM", value: TranscriptRole.SYSTEM, }, { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__ROLE__OPTIONS__TOOL", value: TranscriptRole.TOOL, }, ], }, }, { key: "assistantType", type: "select", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__LABEL", defaultValue: TranscriptEntryType.OUTPUT, params: { options: [ { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__OPTIONS__OUTPUT", value: TranscriptEntryType.OUTPUT, }, { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__OPTIONS__TOOL_CALL", value: TranscriptEntryType.TOOL_CALL, }, ], }, condition: { key: "role", value: TranscriptRole.ASSISTANT, }, }, { key: "agentType", type: "select", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__LABEL", defaultValue: TranscriptEntryType.OUTPUT, params: { options: [ { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__OPTIONS__OUTPUT", value: TranscriptEntryType.OUTPUT, } ], disabled: true }, condition: { key: "role", value: TranscriptRole.AGENT, }, }, { key: "userType", type: "select", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__LABEL", defaultValue: TranscriptEntryType.INPUT, params: { options: [ { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__OPTIONS__INPUT", value: TranscriptEntryType.INPUT, }, ], disabled: true }, condition: { key: "role", value: TranscriptRole.USER, }, }, { key: "systemType", type: "select", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__LABEL", defaultValue: TranscriptEntryType.DEBUG_LOG, params: { options: [ { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__OPTIONS__DEBUG_LOG", value: TranscriptEntryType.DEBUG_LOG, }, ], disabled: true }, condition: { key: "role", value: TranscriptRole.SYSTEM, }, }, { key: "toolType", type: "select", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__LABEL", defaultValue: TranscriptEntryType.TOOL_ANSWER, params: { options: [ { label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TYPE__OPTIONS__TOOL_ANSWER", value: TranscriptEntryType.TOOL_ANSWER, }, ], disabled: true }, condition: { key: "role", value: TranscriptRole.TOOL, }, }, { key: "text", type: "cognigyText", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TEXT__LABEL", defaultValue: "", condition: { or: [ { key: "role", value: TranscriptRole.USER, }, { key: "role", value: TranscriptRole.AGENT, }, { and: [{ key: "role", value: TranscriptRole.ASSISTANT }, { key: "assistantType", value: TranscriptEntryType.OUTPUT }] }, ], }, }, { key: "data", type: "json", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__DATA__LABEL", defaultValue: "", condition: { or: [ { key: "role", value: TranscriptRole.USER, }, { key: "role", value: TranscriptRole.AGENT, }, { and: [{ key: "role", value: TranscriptRole.ASSISTANT }, { key: "assistantType", value: TranscriptEntryType.OUTPUT }] }, ], }, }, { key: "name", type: "cognigyText", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__NAME__LABEL", defaultValue: "", condition: { or: [ { and: [{ key: "role", value: TranscriptRole.ASSISTANT }, { key: "assistantType", value: TranscriptEntryType.TOOL_CALL }] }, { key: "role", value: TranscriptRole.TOOL, } ], }, }, { key: "id", type: "cognigyText", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__ID__LABEL", defaultValue: "", condition: { and: [{ key: "role", value: TranscriptRole.ASSISTANT }, { key: "assistantType", value: TranscriptEntryType.TOOL_CALL }] }, }, { key: "input", type: "json", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__INPUT__LABEL", defaultValue: "", condition: { and: [{ key: "role", value: TranscriptRole.ASSISTANT }, { key: "assistantType", value: TranscriptEntryType.TOOL_CALL }] }, }, { key: "toolCallId", type: "cognigyText", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__TOOL_CALL_ID__LABEL", defaultValue: "", condition: { key: "role", value: TranscriptRole.TOOL, }, }, { key: "content", type: "cognigyText", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__CONTENT__LABEL", defaultValue: "", condition: { key: "role", value: TranscriptRole.TOOL, }, }, { key: "header", type: "cognigyText", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__HEADER__LABEL", defaultValue: "", condition: { key: "role", value: TranscriptRole.SYSTEM, }, }, { key: "message", type: "cognigyText", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__MESSAGE__LABEL", defaultValue: "", condition: { key: "role", value: TranscriptRole.SYSTEM, }, }, { key: "metadata", type: "json", label: "UI__NODE_EDITOR__ADD_TRANSCRIPT_STEP__FIELDS__METADATA__LABEL", defaultValue: "", condition: { key: "role", value: TranscriptRole.SYSTEM, }, }, ], form: [ { type: "field", key: "role" }, { type: "field", key: "userType" }, { type: "field", key: "assistantType" }, { type: "field", key: "agentType" }, { type: "field", key: "systemType" }, { type: "field", key: "toolType" }, { type: "field", key: "text" }, { type: "field", key: "data" }, { type: "field", key: "name" }, { type: "field", key: "id" }, { type: "field", key: "input" }, { type: "field", key: "toolCallId" }, { type: "field", key: "content" }, { type: "field", key: "header" }, { type: "field", key: "message" }, { type: "field", key: "metadata" }, ], preview: { key: "role", type: "text" }, tags: ["service", "transcripts"], function: ({ cognigy, config }) => __awaiter(void 0, void 0, void 0, function* () { const { role, agentType, text, data, name, id, input, toolCallId, content, header, message, metadata } = config; const { api } = cognigy; let log = null; switch (role) { case TranscriptRole.USER: log = { role: TranscriptRole.USER, type: TranscriptEntryType.INPUT, source: TranscriptEntrySource.SYSTEM, payload: { text, data } }; break; case TranscriptRole.ASSISTANT: if (agentType === TranscriptEntryType.OUTPUT) { log = { role: TranscriptRole.ASSISTANT, type: TranscriptEntryType.OUTPUT, source: TranscriptEntrySource.SYSTEM, payload: { text, data } }; } else if (agentType === TranscriptEntryType.TOOL_CALL) { log = { role: TranscriptRole.ASSISTANT, type: TranscriptEntryType.TOOL_CALL, source: TranscriptEntrySource.SYSTEM, payload: { name, id, input } }; } break; case TranscriptRole.AGENT: log = { role: TranscriptRole.AGENT, type: TranscriptEntryType.OUTPUT, source: TranscriptEntrySource.SYSTEM, payload: { text, data } }; break; case TranscriptRole.SYSTEM: log = { role: TranscriptRole.SYSTEM, type: TranscriptEntryType.DEBUG_LOG, source: TranscriptEntrySource.SYSTEM, payload: { header, message, metadata } }; break; case TranscriptRole.TOOL: log = { role: TranscriptRole.TOOL, type: TranscriptEntryType.TOOL_ANSWER, source: TranscriptEntrySource.SYSTEM, payload: { toolCallId, name, content, } }; break; default: break; } if (log) yield api.addTranscriptStep(log); }) }); //# sourceMappingURL=addTranscriptStep.js.map