@n8n/n8n-nodes-langchain
Version:

155 lines • 5.88 kB
JavaScript
;
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 common_exports = {};
__export(common_exports, {
formatBuiltInTools: () => formatBuiltInTools,
prepareAdditionalResponsesParams: () => prepareAdditionalResponsesParams
});
module.exports = __toCommonJS(common_exports);
var import_get = __toESM(require("lodash/get"));
var import_isObject = __toESM(require("lodash/isObject"));
var import_n8n_workflow = require("n8n-workflow");
const removeEmptyProperties = (rest) => {
return Object.keys(rest).filter(
(k) => rest[k] !== "" && rest[k] !== void 0 && !((0, import_isObject.default)(rest[k]) && (0, import_n8n_workflow.isObjectEmpty)(rest[k]))
).reduce((a, k) => ({ ...a, [k]: rest[k] }), {});
};
const toArray = (str) => str.split(",").map((e) => e.trim()).filter(Boolean);
const formatBuiltInTools = (builtInTools) => {
const tools = [];
if (builtInTools) {
const webSearchOptions = (0, import_get.default)(builtInTools, "webSearch");
if (webSearchOptions) {
let allowedDomains;
const allowedDomainsRaw = (0, import_get.default)(webSearchOptions, "allowedDomains", "");
if (allowedDomainsRaw) {
allowedDomains = toArray(allowedDomainsRaw);
}
let userLocation;
if (webSearchOptions.country || webSearchOptions.city || webSearchOptions.region) {
userLocation = {
type: "approximate",
country: webSearchOptions.country,
city: webSearchOptions.city,
region: webSearchOptions.region
};
}
tools.push({
type: "web_search",
search_context_size: (0, import_get.default)(webSearchOptions, "searchContextSize", "medium"),
user_location: userLocation,
...allowedDomains && { filters: { allowed_domains: allowedDomains } }
});
}
if (builtInTools.codeInterpreter) {
tools.push({
type: "code_interpreter",
container: {
type: "auto"
}
});
}
if (builtInTools.fileSearch) {
const vectorStoreIds = (0, import_get.default)(builtInTools.fileSearch, "vectorStoreIds", "[]");
const filters = (0, import_get.default)(builtInTools.fileSearch, "filters", "{}");
tools.push({
type: "file_search",
vector_store_ids: (0, import_n8n_workflow.jsonParse)(vectorStoreIds, {
errorMessage: "Failed to parse vector store IDs"
}),
filters: filters ? (0, import_n8n_workflow.jsonParse)(filters, { errorMessage: "Failed to parse filters" }) : void 0,
max_num_results: (0, import_get.default)(builtInTools.fileSearch, "maxResults")
});
}
}
return tools;
};
const prepareAdditionalResponsesParams = (options) => {
const body = {
prompt_cache_key: options.promptCacheKey,
safety_identifier: options.safetyIdentifier,
service_tier: options.serviceTier,
top_logprobs: options.topLogprobs
};
if (options.conversationId) {
body.conversation = options.conversationId;
}
if (options.metadata) {
body.metadata = (0, import_n8n_workflow.jsonParse)(options.metadata, {
errorMessage: "Failed to parse metadata"
});
}
if (options.promptConfig) {
const prompt = (0, import_get.default)(options, "promptConfig.promptOptions", {});
body.prompt = removeEmptyProperties({
id: prompt.promptId,
version: prompt.version,
...prompt.variables && {
variables: (0, import_n8n_workflow.jsonParse)(prompt.variables, {
errorMessage: "Failed to parse prompt variables"
})
}
});
}
if (options.textFormat) {
const textOptions = (0, import_get.default)(options, "textFormat.textOptions", {});
const textConfig = {
verbosity: textOptions.verbosity
};
if (textOptions.type === "json_schema") {
textConfig.format = {
type: textOptions.type,
name: textOptions.name,
schema: (0, import_n8n_workflow.jsonParse)(textOptions.schema, {
errorMessage: "Failed to parse schema"
})
};
} else {
textConfig.format = {
type: textOptions.type
};
}
if (textConfig.format) {
textConfig.format = removeEmptyProperties(textConfig.format);
}
body.text = textConfig;
}
if (options.reasoningEffort) {
body.reasoning = {
effort: options.reasoningEffort
};
}
return body;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
formatBuiltInTools,
prepareAdditionalResponsesParams
});
//# sourceMappingURL=common.js.map