@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 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.substring(0, 50)}...)`);
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 with SDK version 0.1.8 (manual jsonSchemaToZod)`);
6632
+ this.logger.log(`\u{1F527} McpConverter initialized (MCP JSON Schema passed through)`);
6612
6633
  }
6613
6634
  /**
6614
- * Convert JSON Schema to Zod schema manually
6615
- * This creates a standard Zod schema that zodToJsonSchema can convert back properly
6616
- */
6617
- jsonSchemaToZod(jsonSchema) {
6618
- if (!jsonSchema || typeof jsonSchema !== "object") {
6619
- return zod.z.any();
6620
- }
6621
- try {
6622
- if (jsonSchema.type === "object" && jsonSchema.properties) {
6623
- const shape = {};
6624
- for (const [key, propSchema] of Object.entries(jsonSchema.properties)) {
6625
- const prop = propSchema;
6626
- let zodProp;
6627
- switch (prop.type) {
6628
- case "string":
6629
- zodProp = zod.z.string();
6630
- break;
6631
- case "number":
6632
- zodProp = zod.z.number();
6633
- break;
6634
- case "boolean":
6635
- zodProp = zod.z.boolean();
6636
- break;
6637
- case "integer":
6638
- zodProp = zod.z.number().int();
6639
- break;
6640
- case "array":
6641
- zodProp = zod.z.array(zod.z.any());
6642
- break;
6643
- case "object":
6644
- zodProp = zod.z.record(zod.z.any());
6645
- break;
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
- return zod.z.object(shape);
6668
+ out[key] = resolve2(value, depth);
6658
6669
  }
6659
- this.logger.warn(`Unsupported JSON Schema structure, falling back to z.any()`);
6660
- return zod.z.any();
6661
- } catch (error) {
6662
- this.logger.warn(`Failed to convert JSON Schema, falling back to z.any(): ${error}`);
6663
- return zod.z.any();
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 = this.jsonSchemaToZod(mcpTool.inputSchema);
6690
- logger3.debug(`\u{1F527} [${mcpTool.name}] Original schema:`, JSON.stringify(mcpTool.inputSchema, null, 2));
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;