@flutchai/flutch-sdk 0.6.8 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +69 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +69 -78
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -19,9 +19,7 @@ var LangGraph = require('@langchain/langgraph');
|
|
|
19
19
|
var async_hooks = require('async_hooks');
|
|
20
20
|
var dispatch = require('@langchain/core/callbacks/dispatch');
|
|
21
21
|
var tools = require('@langchain/core/tools');
|
|
22
|
-
var zod = require('zod');
|
|
23
22
|
var axios2 = require('axios');
|
|
24
|
-
var zodToJsonSchema = require('zod-to-json-schema');
|
|
25
23
|
var manager = require('@langchain/core/callbacks/manager');
|
|
26
24
|
var openai = require('@langchain/openai');
|
|
27
25
|
var aws = require('@langchain/aws');
|
|
@@ -2047,6 +2045,29 @@ function createMongoClientAdapter(mongooseClient) {
|
|
|
2047
2045
|
}
|
|
2048
2046
|
__name(createMongoClientAdapter, "createMongoClientAdapter");
|
|
2049
2047
|
|
|
2048
|
+
// src/utils/redact.utils.ts
|
|
2049
|
+
var SECRET_PARAM = /(pass|pwd|secret|token|key|credential)/i;
|
|
2050
|
+
function redactConnectionString(value) {
|
|
2051
|
+
if (!value) return "";
|
|
2052
|
+
const match = /^([a-z][a-z0-9+.-]*:\/\/)([^/?#]*)(.*)$/i.exec(value.trim());
|
|
2053
|
+
if (!match) return "[redacted]";
|
|
2054
|
+
const [, scheme, authority, rest] = match;
|
|
2055
|
+
const at = authority.lastIndexOf("@");
|
|
2056
|
+
const hosts = at >= 0 ? `***@${authority.slice(at + 1)}` : authority;
|
|
2057
|
+
const queryStart = rest.indexOf("?");
|
|
2058
|
+
if (queryStart < 0) return `${scheme}${hosts}${rest}`;
|
|
2059
|
+
const path4 = rest.slice(0, queryStart);
|
|
2060
|
+
const [query, fragment] = rest.slice(queryStart + 1).split("#", 2);
|
|
2061
|
+
const params = query.split("&").map((pair) => {
|
|
2062
|
+
const eq = pair.indexOf("=");
|
|
2063
|
+
if (eq < 0) return pair;
|
|
2064
|
+
const key = pair.slice(0, eq);
|
|
2065
|
+
return SECRET_PARAM.test(key) ? `${key}=***` : pair;
|
|
2066
|
+
}).join("&");
|
|
2067
|
+
return `${scheme}${hosts}${path4}?${params}${fragment !== void 0 ? `#${fragment}` : ""}`;
|
|
2068
|
+
}
|
|
2069
|
+
__name(redactConnectionString, "redactConnectionString");
|
|
2070
|
+
|
|
2050
2071
|
// src/graph/graph-service.interface.ts
|
|
2051
2072
|
var GraphServiceTokens = {
|
|
2052
2073
|
REGISTRY: "GRAPH_SERVICE_REGISTRY",
|
|
@@ -6309,7 +6330,7 @@ function buildCheckpointerProviders(options) {
|
|
|
6309
6330
|
if (!mongoUri) {
|
|
6310
6331
|
throw new Error("[UniversalGraphModule] MongoDB checkpointer: provide mongodb.uri or set the MONGODB_URI environment variable.");
|
|
6311
6332
|
}
|
|
6312
|
-
logger3.log(`Checkpointer: MongoDB (${mongoUri
|
|
6333
|
+
logger3.log(`Checkpointer: MongoDB (${redactConnectionString(mongoUri)})`);
|
|
6313
6334
|
await mongoose__default.default.connect(mongoUri, {
|
|
6314
6335
|
dbName
|
|
6315
6336
|
});
|
|
@@ -6608,60 +6629,52 @@ var McpConverter = class _McpConverter {
|
|
|
6608
6629
|
mcpRuntimeUrl;
|
|
6609
6630
|
constructor(mcpRuntimeUrl = "http://localhost:3004") {
|
|
6610
6631
|
this.mcpRuntimeUrl = mcpRuntimeUrl;
|
|
6611
|
-
this.logger.log(`\u{1F527} McpConverter initialized
|
|
6632
|
+
this.logger.log(`\u{1F527} McpConverter initialized (MCP JSON Schema passed through)`);
|
|
6612
6633
|
}
|
|
6613
6634
|
/**
|
|
6614
|
-
*
|
|
6615
|
-
*
|
|
6616
|
-
|
|
6617
|
-
|
|
6618
|
-
|
|
6619
|
-
|
|
6620
|
-
|
|
6621
|
-
|
|
6622
|
-
|
|
6623
|
-
|
|
6624
|
-
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6632
|
-
|
|
6633
|
-
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6644
|
-
|
|
6645
|
-
|
|
6646
|
-
default:
|
|
6647
|
-
zodProp = zod.z.any();
|
|
6648
|
-
}
|
|
6649
|
-
if (prop.description) {
|
|
6650
|
-
zodProp = zodProp.describe(prop.description);
|
|
6651
|
-
}
|
|
6652
|
-
if (!jsonSchema.required?.includes(key)) {
|
|
6653
|
-
zodProp = zodProp.optional();
|
|
6654
|
-
}
|
|
6655
|
-
shape[key] = zodProp;
|
|
6635
|
+
* The tool's own JSON Schema, ready for the model.
|
|
6636
|
+
*
|
|
6637
|
+
* It used to be rebuilt as Zod by hand, which kept only top-level primitive
|
|
6638
|
+
* types: a list of objects, an `anyOf`, a `$ref` — all became "any", and the
|
|
6639
|
+
* model guessed the shape (a filter list sent as one object, rejected by the
|
|
6640
|
+
* server). LangChain takes JSON Schema directly, so the schema now goes
|
|
6641
|
+
* through as is; only local `$ref`s are inlined, because not every provider
|
|
6642
|
+
* resolves them, and the meta keys providers reject are dropped.
|
|
6643
|
+
*/
|
|
6644
|
+
static toModelSchema(inputSchema) {
|
|
6645
|
+
const root = inputSchema && typeof inputSchema === "object" ? inputSchema : {};
|
|
6646
|
+
const defs = {
|
|
6647
|
+
...root.definitions ?? {},
|
|
6648
|
+
...root.$defs ?? {}
|
|
6649
|
+
};
|
|
6650
|
+
const resolve2 = /* @__PURE__ */ __name((node, depth) => {
|
|
6651
|
+
if (Array.isArray(node)) return node.map((item) => resolve2(item, depth));
|
|
6652
|
+
if (!node || typeof node !== "object") return node;
|
|
6653
|
+
if (typeof node.$ref === "string") {
|
|
6654
|
+
const match = /^#\/(?:\$defs|definitions)\/(.+)$/.exec(node.$ref);
|
|
6655
|
+
const target = match ? defs[decodeURIComponent(match[1])] : void 0;
|
|
6656
|
+
if (!target || depth > 8) return {};
|
|
6657
|
+
const { $ref: _ref, ...siblings } = node;
|
|
6658
|
+
return resolve2({
|
|
6659
|
+
...target,
|
|
6660
|
+
...siblings
|
|
6661
|
+
}, depth + 1);
|
|
6662
|
+
}
|
|
6663
|
+
const out = {};
|
|
6664
|
+
for (const [key, value] of Object.entries(node)) {
|
|
6665
|
+
if (key === "$defs" || key === "definitions" || key === "$schema" || key === "$id") {
|
|
6666
|
+
continue;
|
|
6656
6667
|
}
|
|
6657
|
-
|
|
6668
|
+
out[key] = resolve2(value, depth);
|
|
6658
6669
|
}
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6670
|
+
return out;
|
|
6671
|
+
}, "resolve");
|
|
6672
|
+
const schema = resolve2(root, 0);
|
|
6673
|
+
return {
|
|
6674
|
+
...schema,
|
|
6675
|
+
type: "object",
|
|
6676
|
+
properties: schema.properties ?? {}
|
|
6677
|
+
};
|
|
6665
6678
|
}
|
|
6666
6679
|
/**
|
|
6667
6680
|
* Convert a single MCP tool to LangChain DynamicStructuredTool
|
|
@@ -6686,30 +6699,8 @@ Parameters:
|
|
|
6686
6699
|
${paramDescriptions.join("\n")}`;
|
|
6687
6700
|
}
|
|
6688
6701
|
}
|
|
6689
|
-
const schema =
|
|
6690
|
-
logger3.debug(`\u{1F527} [${mcpTool.name}]
|
|
6691
|
-
logger3.debug(`\u{1F527} [${mcpTool.name}] Using schema type: ${schema?._def?.typeName ?? "unknown"}`);
|
|
6692
|
-
if (schema?._def?.shape && typeof schema._def.shape === "function") {
|
|
6693
|
-
try {
|
|
6694
|
-
const shape = schema._def.shape();
|
|
6695
|
-
logger3.debug(`\u{1F527} [${mcpTool.name}] Converted Zod schema shape:`, JSON.stringify(Object.entries(shape).reduce((acc, [key, val]) => {
|
|
6696
|
-
acc[key] = {
|
|
6697
|
-
type: val?._def?.typeName,
|
|
6698
|
-
description: val?._def?.description,
|
|
6699
|
-
optional: val?._def?.typeName === "ZodOptional"
|
|
6700
|
-
};
|
|
6701
|
-
return acc;
|
|
6702
|
-
}, {}), null, 2));
|
|
6703
|
-
} catch (error) {
|
|
6704
|
-
logger3.debug(`\u{1F527} [${mcpTool.name}] Could not extract Zod schema shape: ${error}`);
|
|
6705
|
-
}
|
|
6706
|
-
}
|
|
6707
|
-
try {
|
|
6708
|
-
const convertedJsonSchema = zodToJsonSchema.zodToJsonSchema(schema);
|
|
6709
|
-
logger3.warn(`\u{1F527} [${mcpTool.name}] JSON Schema that LangChain will use:`, JSON.stringify(convertedJsonSchema, null, 2));
|
|
6710
|
-
} catch (error) {
|
|
6711
|
-
logger3.warn(`\u{1F527} [${mcpTool.name}] Could not convert Zod to JSON Schema: ${error}`);
|
|
6712
|
-
}
|
|
6702
|
+
const schema = _McpConverter.toModelSchema(mcpTool.inputSchema);
|
|
6703
|
+
logger3.debug(`\u{1F527} [${mcpTool.name}] Schema for the model: ${JSON.stringify(schema)}`);
|
|
6713
6704
|
return new tools.DynamicStructuredTool({
|
|
6714
6705
|
name: mcpTool.name,
|
|
6715
6706
|
description: enhancedDescription,
|
|
@@ -8731,6 +8722,7 @@ exports.loadOAuthProviders = loadOAuthProviders;
|
|
|
8731
8722
|
exports.modelAcceptsSamplingParams = modelAcceptsSamplingParams;
|
|
8732
8723
|
exports.modelSupportsPromptCache = modelSupportsPromptCache;
|
|
8733
8724
|
exports.normalizeToolConfigs = normalizeToolConfigs;
|
|
8725
|
+
exports.redactConnectionString = redactConnectionString;
|
|
8734
8726
|
exports.registerFinanceExampleCallback = registerFinanceExampleCallback;
|
|
8735
8727
|
exports.registerUIEndpointsFromClass = registerUIEndpointsFromClass;
|
|
8736
8728
|
exports.resolveOAuthProviderConfig = resolveOAuthProviderConfig;
|