@n8n/n8n-nodes-langchain
Version:
34 lines • 1.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseExtraBody = parseExtraBody;
const is_record_1 = require("@n8n/utils/is-record");
const n8n_workflow_1 = require("n8n-workflow");
function isObjectLiteral(value) {
if (!(0, is_record_1.isRecord)(value))
return false;
const prototype = Object.getPrototypeOf(value);
return prototype === Object.prototype || prototype === null;
}
function parseExtraBody(ctx, value, itemIndex) {
let extraBody = value;
if (typeof value === 'string') {
try {
extraBody = (0, n8n_workflow_1.jsonParse)(value);
}
catch (error) {
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), 'The value in the "Extra Body" field is not valid JSON', { itemIndex, description: error instanceof Error ? error.message : String(error) });
}
}
if (!isObjectLiteral(extraBody)) {
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), 'The value in the "Extra Body" field must be a JSON object', { itemIndex });
}
const unsafeKey = Object.keys(extraBody).find((key) => !(0, n8n_workflow_1.isSafeObjectProperty)(key));
if (unsafeKey) {
throw new n8n_workflow_1.NodeOperationError(ctx.getNode(), `The "Extra Body" field cannot set "${unsafeKey}"`, {
itemIndex,
description: `"${unsafeKey}" is reserved and is not a model parameter. Remove it from the Extra Body field.`,
});
}
return extraBody;
}
//# sourceMappingURL=extra-body.js.map