@flutchai/flutch-sdk 0.6.7 → 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 +105 -80
- 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 +105 -81
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
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",
|
|
@@ -5114,15 +5135,48 @@ function _ts_decorate21(decorators, target, key, desc) {
|
|
|
5114
5135
|
}
|
|
5115
5136
|
__name(_ts_decorate21, "_ts_decorate");
|
|
5116
5137
|
function joinTextSteps(parts) {
|
|
5138
|
+
const kept = parts.filter(Boolean);
|
|
5139
|
+
for (let i = 1; i < kept.length; i++) {
|
|
5140
|
+
for (const paragraph of paragraphsOf(kept[i])) {
|
|
5141
|
+
for (let j = 0; j < i; j++) {
|
|
5142
|
+
kept[j] = removeNearDuplicate(kept[j], paragraph);
|
|
5143
|
+
}
|
|
5144
|
+
}
|
|
5145
|
+
}
|
|
5117
5146
|
let out = "";
|
|
5118
|
-
for (const part of
|
|
5119
|
-
if (!part) continue;
|
|
5147
|
+
for (const part of kept) {
|
|
5148
|
+
if (!part.trim()) continue;
|
|
5120
5149
|
if (!out || /\s$/.test(out) || /^\s/.test(part)) out += part;
|
|
5121
5150
|
else out += "\n\n" + part;
|
|
5122
5151
|
}
|
|
5123
|
-
return out;
|
|
5152
|
+
return out.replace(/\n{3,}/g, "\n\n");
|
|
5124
5153
|
}
|
|
5125
5154
|
__name(joinTextSteps, "joinTextSteps");
|
|
5155
|
+
var MIN_DUPLICATE_WORDS = 8;
|
|
5156
|
+
var DUPLICATE_SIMILARITY = 0.75;
|
|
5157
|
+
function paragraphsOf(text) {
|
|
5158
|
+
return text.split(/\n\s*\n/).map((p) => p.trim()).filter(Boolean);
|
|
5159
|
+
}
|
|
5160
|
+
__name(paragraphsOf, "paragraphsOf");
|
|
5161
|
+
function wordsOf(text) {
|
|
5162
|
+
return new Set(text.toLowerCase().match(/[\p{L}\p{N}$]+/gu) ?? []);
|
|
5163
|
+
}
|
|
5164
|
+
__name(wordsOf, "wordsOf");
|
|
5165
|
+
function similarity(a, b) {
|
|
5166
|
+
let common = 0;
|
|
5167
|
+
for (const w of a) if (b.has(w)) common++;
|
|
5168
|
+
return common / (a.size + b.size - common);
|
|
5169
|
+
}
|
|
5170
|
+
__name(similarity, "similarity");
|
|
5171
|
+
function removeNearDuplicate(text, paragraph) {
|
|
5172
|
+
const target = wordsOf(paragraph);
|
|
5173
|
+
if (target.size < MIN_DUPLICATE_WORDS) return text;
|
|
5174
|
+
return paragraphsOf(text).filter((p) => {
|
|
5175
|
+
const words = wordsOf(p);
|
|
5176
|
+
return words.size < MIN_DUPLICATE_WORDS || similarity(words, target) < DUPLICATE_SIMILARITY;
|
|
5177
|
+
}).join("\n\n");
|
|
5178
|
+
}
|
|
5179
|
+
__name(removeNearDuplicate, "removeNearDuplicate");
|
|
5126
5180
|
exports.EventProcessor = class _EventProcessor {
|
|
5127
5181
|
static {
|
|
5128
5182
|
__name(this, "EventProcessor");
|
|
@@ -6276,7 +6330,7 @@ function buildCheckpointerProviders(options) {
|
|
|
6276
6330
|
if (!mongoUri) {
|
|
6277
6331
|
throw new Error("[UniversalGraphModule] MongoDB checkpointer: provide mongodb.uri or set the MONGODB_URI environment variable.");
|
|
6278
6332
|
}
|
|
6279
|
-
logger3.log(`Checkpointer: MongoDB (${mongoUri
|
|
6333
|
+
logger3.log(`Checkpointer: MongoDB (${redactConnectionString(mongoUri)})`);
|
|
6280
6334
|
await mongoose__default.default.connect(mongoUri, {
|
|
6281
6335
|
dbName
|
|
6282
6336
|
});
|
|
@@ -6575,60 +6629,52 @@ var McpConverter = class _McpConverter {
|
|
|
6575
6629
|
mcpRuntimeUrl;
|
|
6576
6630
|
constructor(mcpRuntimeUrl = "http://localhost:3004") {
|
|
6577
6631
|
this.mcpRuntimeUrl = mcpRuntimeUrl;
|
|
6578
|
-
this.logger.log(`\u{1F527} McpConverter initialized
|
|
6632
|
+
this.logger.log(`\u{1F527} McpConverter initialized (MCP JSON Schema passed through)`);
|
|
6579
6633
|
}
|
|
6580
6634
|
/**
|
|
6581
|
-
*
|
|
6582
|
-
*
|
|
6583
|
-
|
|
6584
|
-
|
|
6585
|
-
|
|
6586
|
-
|
|
6587
|
-
|
|
6588
|
-
|
|
6589
|
-
|
|
6590
|
-
|
|
6591
|
-
|
|
6592
|
-
|
|
6593
|
-
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6597
|
-
|
|
6598
|
-
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
|
|
6602
|
-
|
|
6603
|
-
|
|
6604
|
-
|
|
6605
|
-
|
|
6606
|
-
|
|
6607
|
-
|
|
6608
|
-
|
|
6609
|
-
|
|
6610
|
-
|
|
6611
|
-
|
|
6612
|
-
|
|
6613
|
-
default:
|
|
6614
|
-
zodProp = zod.z.any();
|
|
6615
|
-
}
|
|
6616
|
-
if (prop.description) {
|
|
6617
|
-
zodProp = zodProp.describe(prop.description);
|
|
6618
|
-
}
|
|
6619
|
-
if (!jsonSchema.required?.includes(key)) {
|
|
6620
|
-
zodProp = zodProp.optional();
|
|
6621
|
-
}
|
|
6622
|
-
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;
|
|
6623
6667
|
}
|
|
6624
|
-
|
|
6668
|
+
out[key] = resolve2(value, depth);
|
|
6625
6669
|
}
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
|
|
6631
|
-
|
|
6670
|
+
return out;
|
|
6671
|
+
}, "resolve");
|
|
6672
|
+
const schema = resolve2(root, 0);
|
|
6673
|
+
return {
|
|
6674
|
+
...schema,
|
|
6675
|
+
type: "object",
|
|
6676
|
+
properties: schema.properties ?? {}
|
|
6677
|
+
};
|
|
6632
6678
|
}
|
|
6633
6679
|
/**
|
|
6634
6680
|
* Convert a single MCP tool to LangChain DynamicStructuredTool
|
|
@@ -6653,30 +6699,8 @@ Parameters:
|
|
|
6653
6699
|
${paramDescriptions.join("\n")}`;
|
|
6654
6700
|
}
|
|
6655
6701
|
}
|
|
6656
|
-
const schema =
|
|
6657
|
-
logger3.debug(`\u{1F527} [${mcpTool.name}]
|
|
6658
|
-
logger3.debug(`\u{1F527} [${mcpTool.name}] Using schema type: ${schema?._def?.typeName ?? "unknown"}`);
|
|
6659
|
-
if (schema?._def?.shape && typeof schema._def.shape === "function") {
|
|
6660
|
-
try {
|
|
6661
|
-
const shape = schema._def.shape();
|
|
6662
|
-
logger3.debug(`\u{1F527} [${mcpTool.name}] Converted Zod schema shape:`, JSON.stringify(Object.entries(shape).reduce((acc, [key, val]) => {
|
|
6663
|
-
acc[key] = {
|
|
6664
|
-
type: val?._def?.typeName,
|
|
6665
|
-
description: val?._def?.description,
|
|
6666
|
-
optional: val?._def?.typeName === "ZodOptional"
|
|
6667
|
-
};
|
|
6668
|
-
return acc;
|
|
6669
|
-
}, {}), null, 2));
|
|
6670
|
-
} catch (error) {
|
|
6671
|
-
logger3.debug(`\u{1F527} [${mcpTool.name}] Could not extract Zod schema shape: ${error}`);
|
|
6672
|
-
}
|
|
6673
|
-
}
|
|
6674
|
-
try {
|
|
6675
|
-
const convertedJsonSchema = zodToJsonSchema.zodToJsonSchema(schema);
|
|
6676
|
-
logger3.warn(`\u{1F527} [${mcpTool.name}] JSON Schema that LangChain will use:`, JSON.stringify(convertedJsonSchema, null, 2));
|
|
6677
|
-
} catch (error) {
|
|
6678
|
-
logger3.warn(`\u{1F527} [${mcpTool.name}] Could not convert Zod to JSON Schema: ${error}`);
|
|
6679
|
-
}
|
|
6702
|
+
const schema = _McpConverter.toModelSchema(mcpTool.inputSchema);
|
|
6703
|
+
logger3.debug(`\u{1F527} [${mcpTool.name}] Schema for the model: ${JSON.stringify(schema)}`);
|
|
6680
6704
|
return new tools.DynamicStructuredTool({
|
|
6681
6705
|
name: mcpTool.name,
|
|
6682
6706
|
description: enhancedDescription,
|
|
@@ -8698,6 +8722,7 @@ exports.loadOAuthProviders = loadOAuthProviders;
|
|
|
8698
8722
|
exports.modelAcceptsSamplingParams = modelAcceptsSamplingParams;
|
|
8699
8723
|
exports.modelSupportsPromptCache = modelSupportsPromptCache;
|
|
8700
8724
|
exports.normalizeToolConfigs = normalizeToolConfigs;
|
|
8725
|
+
exports.redactConnectionString = redactConnectionString;
|
|
8701
8726
|
exports.registerFinanceExampleCallback = registerFinanceExampleCallback;
|
|
8702
8727
|
exports.registerUIEndpointsFromClass = registerUIEndpointsFromClass;
|
|
8703
8728
|
exports.resolveOAuthProviderConfig = resolveOAuthProviderConfig;
|