@flutchai/flutch-sdk 0.6.8 → 0.6.11
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 +72 -79
- 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 +72 -80
- 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
|
});
|
|
@@ -6366,9 +6387,10 @@ exports.UniversalGraphModule = class _UniversalGraphModule {
|
|
|
6366
6387
|
// Graph engines
|
|
6367
6388
|
{
|
|
6368
6389
|
provide: exports.LangGraphEngine,
|
|
6369
|
-
useFactory: /* @__PURE__ */ __name((eventProcessor) => new exports.LangGraphEngine(eventProcessor,
|
|
6390
|
+
useFactory: /* @__PURE__ */ __name((eventProcessor, configService) => new exports.LangGraphEngine(eventProcessor, configService), "useFactory"),
|
|
6370
6391
|
inject: [
|
|
6371
|
-
exports.EventProcessor
|
|
6392
|
+
exports.EventProcessor,
|
|
6393
|
+
config.ConfigService
|
|
6372
6394
|
]
|
|
6373
6395
|
},
|
|
6374
6396
|
exports.BuilderRegistryService,
|
|
@@ -6608,60 +6630,52 @@ var McpConverter = class _McpConverter {
|
|
|
6608
6630
|
mcpRuntimeUrl;
|
|
6609
6631
|
constructor(mcpRuntimeUrl = "http://localhost:3004") {
|
|
6610
6632
|
this.mcpRuntimeUrl = mcpRuntimeUrl;
|
|
6611
|
-
this.logger.log(`\u{1F527} McpConverter initialized
|
|
6633
|
+
this.logger.log(`\u{1F527} McpConverter initialized (MCP JSON Schema passed through)`);
|
|
6612
6634
|
}
|
|
6613
6635
|
/**
|
|
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;
|
|
6636
|
+
* The tool's own JSON Schema, ready for the model.
|
|
6637
|
+
*
|
|
6638
|
+
* It used to be rebuilt as Zod by hand, which kept only top-level primitive
|
|
6639
|
+
* types: a list of objects, an `anyOf`, a `$ref` — all became "any", and the
|
|
6640
|
+
* model guessed the shape (a filter list sent as one object, rejected by the
|
|
6641
|
+
* server). LangChain takes JSON Schema directly, so the schema now goes
|
|
6642
|
+
* through as is; only local `$ref`s are inlined, because not every provider
|
|
6643
|
+
* resolves them, and the meta keys providers reject are dropped.
|
|
6644
|
+
*/
|
|
6645
|
+
static toModelSchema(inputSchema) {
|
|
6646
|
+
const root = inputSchema && typeof inputSchema === "object" ? inputSchema : {};
|
|
6647
|
+
const defs = {
|
|
6648
|
+
...root.definitions ?? {},
|
|
6649
|
+
...root.$defs ?? {}
|
|
6650
|
+
};
|
|
6651
|
+
const resolve2 = /* @__PURE__ */ __name((node, depth) => {
|
|
6652
|
+
if (Array.isArray(node)) return node.map((item) => resolve2(item, depth));
|
|
6653
|
+
if (!node || typeof node !== "object") return node;
|
|
6654
|
+
if (typeof node.$ref === "string") {
|
|
6655
|
+
const match = /^#\/(?:\$defs|definitions)\/(.+)$/.exec(node.$ref);
|
|
6656
|
+
const target = match ? defs[decodeURIComponent(match[1])] : void 0;
|
|
6657
|
+
if (!target || depth > 8) return {};
|
|
6658
|
+
const { $ref: _ref, ...siblings } = node;
|
|
6659
|
+
return resolve2({
|
|
6660
|
+
...target,
|
|
6661
|
+
...siblings
|
|
6662
|
+
}, depth + 1);
|
|
6663
|
+
}
|
|
6664
|
+
const out = {};
|
|
6665
|
+
for (const [key, value] of Object.entries(node)) {
|
|
6666
|
+
if (key === "$defs" || key === "definitions" || key === "$schema" || key === "$id") {
|
|
6667
|
+
continue;
|
|
6656
6668
|
}
|
|
6657
|
-
|
|
6669
|
+
out[key] = resolve2(value, depth);
|
|
6658
6670
|
}
|
|
6659
|
-
|
|
6660
|
-
|
|
6661
|
-
|
|
6662
|
-
|
|
6663
|
-
|
|
6664
|
-
|
|
6671
|
+
return out;
|
|
6672
|
+
}, "resolve");
|
|
6673
|
+
const schema = resolve2(root, 0);
|
|
6674
|
+
return {
|
|
6675
|
+
...schema,
|
|
6676
|
+
type: "object",
|
|
6677
|
+
properties: schema.properties ?? {}
|
|
6678
|
+
};
|
|
6665
6679
|
}
|
|
6666
6680
|
/**
|
|
6667
6681
|
* Convert a single MCP tool to LangChain DynamicStructuredTool
|
|
@@ -6686,30 +6700,8 @@ Parameters:
|
|
|
6686
6700
|
${paramDescriptions.join("\n")}`;
|
|
6687
6701
|
}
|
|
6688
6702
|
}
|
|
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
|
-
}
|
|
6703
|
+
const schema = _McpConverter.toModelSchema(mcpTool.inputSchema);
|
|
6704
|
+
logger3.debug(`\u{1F527} [${mcpTool.name}] Schema for the model: ${JSON.stringify(schema)}`);
|
|
6713
6705
|
return new tools.DynamicStructuredTool({
|
|
6714
6706
|
name: mcpTool.name,
|
|
6715
6707
|
description: enhancedDescription,
|
|
@@ -8731,6 +8723,7 @@ exports.loadOAuthProviders = loadOAuthProviders;
|
|
|
8731
8723
|
exports.modelAcceptsSamplingParams = modelAcceptsSamplingParams;
|
|
8732
8724
|
exports.modelSupportsPromptCache = modelSupportsPromptCache;
|
|
8733
8725
|
exports.normalizeToolConfigs = normalizeToolConfigs;
|
|
8726
|
+
exports.redactConnectionString = redactConnectionString;
|
|
8734
8727
|
exports.registerFinanceExampleCallback = registerFinanceExampleCallback;
|
|
8735
8728
|
exports.registerUIEndpointsFromClass = registerUIEndpointsFromClass;
|
|
8736
8729
|
exports.resolveOAuthProviderConfig = resolveOAuthProviderConfig;
|