@n8n/n8n-nodes-langchain
Version:

67 lines • 2.27 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var base_exports = {};
__export(base_exports, {
runStageGuardrails: () => runStageGuardrails
});
module.exports = __toCommonJS(base_exports);
var import_types = require("../actions/types");
const wrapInGuardrailError = (guardrailName, promise) => {
return promise.catch((error) => {
throw new import_types.GuardrailError(
guardrailName,
error?.description || error?.message || "Unknown error",
error?.description
);
});
};
async function runStageGuardrails({
stageGuardrails,
stage,
inputText,
failOnlyOnErrors
}) {
const guardrailPromises = [];
for (const guardrail of stageGuardrails[stage]) {
guardrailPromises.push(
wrapInGuardrailError(
guardrail.name,
// ensure the check is async
Promise.resolve().then(async () => await guardrail.check(inputText))
)
);
}
const results = await Promise.allSettled(guardrailPromises);
const passed = [];
const failed = [];
for (const result of results) {
const checkFailed = failOnlyOnErrors ? result.status === "rejected" || !!result.value.executionFailed : result.status === "rejected" || !!result.value.tripwireTriggered;
if (result.status === "fulfilled" && !checkFailed) {
passed.push(result);
} else {
failed.push(result);
}
}
return { passed, failed };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
runStageGuardrails
});
//# sourceMappingURL=base.js.map