UNPKG

@n8n/n8n-nodes-langchain

Version:

![Banner image](https://user-images.githubusercontent.com/10284570/173569848-c624317f-42b1-45a6-ab09-f0ea3c247648.png)

100 lines 4.32 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var mappers_exports = {}; __export(mappers_exports, { mapGuardrailErrorsToMessage: () => mapGuardrailErrorsToMessage, mapGuardrailResultToUserResult: () => mapGuardrailResultToUserResult, wrapResultsToNodeExecutionData: () => wrapResultsToNodeExecutionData }); module.exports = __toCommonJS(mappers_exports); var import_omit = __toESM(require("lodash/omit")); var import_types = require("../actions/types"); const mapGuardrailResultToUserResult = (result) => { const formatInfo = (info) => { return (0, import_omit.default)(info ?? {}, ["maskEntities"]); }; if ("status" in result) { if (result.status === "fulfilled") { return { name: result.value.guardrailName, triggered: result.value.tripwireTriggered, confidenceScore: result.value.confidenceScore, executionFailed: result.value.executionFailed, exception: result.value.originalException ? { name: result.value.originalException.name, description: result.value.originalException.message } : void 0, info: formatInfo(result.value.info) }; } else { return { name: result.reason instanceof import_types.GuardrailError ? result.reason.guardrailName : "Unknown Guardrail", triggered: true, executionFailed: true, exception: result.reason instanceof Error ? { name: result.reason.name, description: result.reason.message } : { name: "Unknown Exception", description: "Unknown exception occurred" } }; } } return { name: result.guardrailName, triggered: result.tripwireTriggered, confidenceScore: result.confidenceScore, executionFailed: result.executionFailed, exception: result.originalException ? { name: result.originalException.name, description: result.originalException.message } : void 0, info: formatInfo(result.info) }; }; const mapGuardrailErrorsToMessage = (results) => { const failedChecks = results.filter((r) => r.status === "rejected" || r.status === "fulfilled" && r.value.executionFailed).map((result) => { const originalException = result.status === "rejected" ? result.reason : result.value.originalException; const message = originalException?.message ?? "Unknown exception occurred"; const guardrailName = result.status === "rejected" ? originalException?.guardrailName ?? "Unknown Guardrail" : result.value.guardrailName; return `${guardrailName} - ${message}`; }).join(",\n"); return `Failed checks: ${failedChecks}`; }; const wrapResultsToNodeExecutionData = (checks, itemIndex) => { return checks.length > 0 ? [ { json: { checks }, pairedItem: { item: itemIndex } } ] : []; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { mapGuardrailErrorsToMessage, mapGuardrailResultToUserResult, wrapResultsToNodeExecutionData }); //# sourceMappingURL=mappers.js.map