@flutchai/flutch-sdk 0.4.1 → 0.6.0

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
@@ -359,8 +359,8 @@ exports.ENDPOINT_METADATA_KEY = void 0; var UI_ENDPOINT_CLASS_METADATA_KEY, UI_E
359
359
  var init_endpoint_decorators = __esm({
360
360
  "src/agent-ui/endpoint.decorators.ts"() {
361
361
  exports.ENDPOINT_METADATA_KEY = "graph:endpoints";
362
- UI_ENDPOINT_CLASS_METADATA_KEY = Symbol("ui_endpoint_class");
363
- UI_ENDPOINT_METHOD_METADATA_KEY = Symbol("ui_endpoint_methods");
362
+ UI_ENDPOINT_CLASS_METADATA_KEY = /* @__PURE__ */ Symbol("ui_endpoint_class");
363
+ UI_ENDPOINT_METHOD_METADATA_KEY = /* @__PURE__ */ Symbol("ui_endpoint_methods");
364
364
  }
365
365
  });
366
366
  exports.UIEndpointsDiscoveryService = void 0;
@@ -373,6 +373,9 @@ var init_ui_endpoints_discovery = __esm({
373
373
  this.metadataScanner = metadataScanner;
374
374
  this.endpointRegistry = endpointRegistry;
375
375
  }
376
+ discoveryService;
377
+ metadataScanner;
378
+ endpointRegistry;
376
379
  logger = new common.Logger(exports.UIEndpointsDiscoveryService.name);
377
380
  async onModuleInit() {
378
381
  await this.discoverUIEndpoints();
@@ -449,6 +452,8 @@ var init_ui_dispatch_controller = __esm({
449
452
  this.endpointRegistry = endpointRegistry;
450
453
  this.builderRegistry = builderRegistry;
451
454
  }
455
+ endpointRegistry;
456
+ builderRegistry;
452
457
  logger = new common.Logger(exports.UIDispatchController.name);
453
458
  async dispatchUIEndpoint(dto) {
454
459
  this.logger.debug(
@@ -723,8 +728,8 @@ function findCallbackMethod(target, handler) {
723
728
  var CALLBACK_METADATA_KEY, CALLBACK_CLASS_METADATA_KEY;
724
729
  var init_callback_decorators = __esm({
725
730
  "src/callbacks/callback.decorators.ts"() {
726
- CALLBACK_METADATA_KEY = Symbol("callbacks");
727
- CALLBACK_CLASS_METADATA_KEY = Symbol("callback_class");
731
+ CALLBACK_METADATA_KEY = /* @__PURE__ */ Symbol("callbacks");
732
+ CALLBACK_CLASS_METADATA_KEY = /* @__PURE__ */ Symbol("callback_class");
728
733
  }
729
734
  });
730
735
 
@@ -1514,6 +1519,10 @@ exports.UniversalGraphService = class UniversalGraphService {
1514
1519
  this.logger.error("GRAPH_ENGINE is not properly injected!");
1515
1520
  }
1516
1521
  }
1522
+ configService;
1523
+ builders;
1524
+ engine;
1525
+ endpointRegistry;
1517
1526
  logger = new common.Logger(exports.UniversalGraphService.name);
1518
1527
  /**
1519
1528
  * Returns graph types supported by the service
@@ -2027,6 +2036,8 @@ exports.GraphController = class GraphController {
2027
2036
  this.graphService = graphService;
2028
2037
  this.builderRegistry = builderRegistry;
2029
2038
  }
2039
+ graphService;
2040
+ builderRegistry;
2030
2041
  logger = new common.Logger(exports.GraphController.name);
2031
2042
  async healthCheck() {
2032
2043
  try {
@@ -2413,6 +2424,7 @@ var CallbackStore = class {
2413
2424
  this.redis = redis;
2414
2425
  this.isProduction = process.env.NODE_ENV === "production";
2415
2426
  }
2427
+ redis;
2416
2428
  isProduction;
2417
2429
  /**
2418
2430
  * Issues a new callback token and persists its payload.
@@ -2619,6 +2631,7 @@ exports.IdempotencyManager = class IdempotencyManager {
2619
2631
  constructor(redis) {
2620
2632
  this.redis = redis;
2621
2633
  }
2634
+ redis;
2622
2635
  logger = new common.Logger(exports.IdempotencyManager.name);
2623
2636
  defaultConfig = {
2624
2637
  ttlSeconds: 3600,
@@ -2869,6 +2882,14 @@ exports.SmartCallbackRouter = class SmartCallbackRouter {
2869
2882
  this.idempotencyManager = idempotencyManager;
2870
2883
  this.patchService = patchService;
2871
2884
  }
2885
+ registry;
2886
+ store;
2887
+ acl;
2888
+ auditor;
2889
+ metrics;
2890
+ rateLimiter;
2891
+ idempotencyManager;
2892
+ patchService;
2872
2893
  logger = new common.Logger(exports.SmartCallbackRouter.name);
2873
2894
  circuitBreakers = /* @__PURE__ */ new Map();
2874
2895
  defaultConfig = {
@@ -3128,6 +3149,8 @@ var UniversalCallbackService = class {
3128
3149
  this.store = store;
3129
3150
  this.router = router;
3130
3151
  }
3152
+ store;
3153
+ router;
3131
3154
  async handle(record, user, metadata) {
3132
3155
  try {
3133
3156
  const result = await this.router.route(record, user, metadata);
@@ -3919,6 +3942,7 @@ exports.CallbackRateLimiter = class CallbackRateLimiter {
3919
3942
  constructor(redis) {
3920
3943
  this.redis = redis;
3921
3944
  }
3945
+ redis;
3922
3946
  logger = new common.Logger(exports.CallbackRateLimiter.name);
3923
3947
  defaultConfig = {
3924
3948
  windowMs: 6e4,
@@ -4084,6 +4108,8 @@ exports.CallbackPatchService = class CallbackPatchService {
4084
4108
  this.telegram = telegram;
4085
4109
  this.web = web;
4086
4110
  }
4111
+ telegram;
4112
+ web;
4087
4113
  logger = new common.Logger(exports.CallbackPatchService.name);
4088
4114
  async apply(record, patch, context) {
4089
4115
  if (!patch) return;
@@ -4144,6 +4170,8 @@ exports.CallbackTokenGuard = class CallbackTokenGuard {
4144
4170
  this.store = store;
4145
4171
  this.acl = acl;
4146
4172
  }
4173
+ store;
4174
+ acl;
4147
4175
  logger = new common.Logger(exports.CallbackTokenGuard.name);
4148
4176
  async canActivate(context) {
4149
4177
  const request = context.switchToHttp().getRequest();
@@ -4201,6 +4229,7 @@ exports.CallbackController = class CallbackController {
4201
4229
  constructor(callbackService) {
4202
4230
  this.callbackService = callbackService;
4203
4231
  }
4232
+ callbackService;
4204
4233
  async handleCallback(req) {
4205
4234
  return this.callbackService.handle(req.callbackRecord, req.user);
4206
4235
  }
@@ -4489,7 +4518,8 @@ async function executeToolWithAttachments(params) {
4489
4518
  injectIntoArg = "data",
4490
4519
  sourceAttachmentId,
4491
4520
  threadId,
4492
- toolSchema
4521
+ toolSchema,
4522
+ mcpServers
4493
4523
  } = params;
4494
4524
  const argsWithInjection = { ...enrichedArgs };
4495
4525
  try {
@@ -4520,7 +4550,8 @@ async function executeToolWithAttachments(params) {
4520
4550
  toolCall.name,
4521
4551
  argsWithInjection,
4522
4552
  executionContext,
4523
- config
4553
+ config,
4554
+ mcpServers
4524
4555
  );
4525
4556
  try {
4526
4557
  if (success && rawResult !== void 0 && content.length > threshold) {
@@ -4740,6 +4771,7 @@ exports.GraphEngineFactory = class GraphEngineFactory {
4740
4771
  constructor(langgraph) {
4741
4772
  this.langgraph = langgraph;
4742
4773
  }
4774
+ langgraph;
4743
4775
  /**
4744
4776
  * Get engine for the specified type
4745
4777
  */
@@ -5397,6 +5429,8 @@ exports.LangGraphEngine = class LangGraphEngine {
5397
5429
  this.logger.error("EventProcessor is undefined/null!");
5398
5430
  }
5399
5431
  }
5432
+ eventProcessor;
5433
+ configService;
5400
5434
  logger = new common.Logger(exports.LangGraphEngine.name);
5401
5435
  /**
5402
5436
  * Deserialize input recursively
@@ -6373,6 +6407,7 @@ var McpToolFilter = class _McpToolFilter {
6373
6407
  this.mcpRuntimeUrl = mcpRuntimeUrl;
6374
6408
  this.mcpConverter = new McpConverter(this.mcpRuntimeUrl);
6375
6409
  }
6410
+ mcpRuntimeUrl;
6376
6411
  logger = new common.Logger(_McpToolFilter.name);
6377
6412
  mcpConverter;
6378
6413
  /**
@@ -6380,12 +6415,13 @@ var McpToolFilter = class _McpToolFilter {
6380
6415
  * @param toolsConfig Array of tool configurations with dynamic config
6381
6416
  * @returns Array of LangChain Tool instances with dynamic schemas
6382
6417
  */
6383
- async getFilteredTools(toolsConfig = []) {
6418
+ async getFilteredTools(toolsConfig = [], mcpServers, context) {
6384
6419
  this.logger.debug(
6385
6420
  `[DEBUG] Getting filtered tools with dynamic schemas. Config: ${JSON.stringify(toolsConfig)}`
6386
6421
  );
6387
6422
  this.logger.debug(`[DEBUG] MCP Runtime URL: ${this.mcpRuntimeUrl}`);
6388
- if (toolsConfig.length === 0) {
6423
+ const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
6424
+ if (toolsConfig.length === 0 && !hasInlineServers) {
6389
6425
  this.logger.debug("No tools configured, returning empty array");
6390
6426
  return [];
6391
6427
  }
@@ -6393,10 +6429,13 @@ var McpToolFilter = class _McpToolFilter {
6393
6429
  this.logger.debug(
6394
6430
  `[DEBUG] Making HTTP POST request to: ${this.mcpRuntimeUrl}/tools/schemas`
6395
6431
  );
6396
- this.logger.debug(`[DEBUG] Request body: ${JSON.stringify(toolsConfig)}`);
6432
+ const requestBody = { tools: toolsConfig };
6433
+ if (hasInlineServers) requestBody.mcpServers = mcpServers;
6434
+ if (context) requestBody.context = context;
6435
+ this.logger.debug(`[DEBUG] Request body: ${JSON.stringify(requestBody)}`);
6397
6436
  const response = await axios2__default.default.post(
6398
6437
  `${this.mcpRuntimeUrl}/tools/schemas`,
6399
- { tools: toolsConfig },
6438
+ requestBody,
6400
6439
  {
6401
6440
  timeout: 5e3,
6402
6441
  headers: {
@@ -6413,14 +6452,14 @@ var McpToolFilter = class _McpToolFilter {
6413
6452
  );
6414
6453
  const mcpClient = {
6415
6454
  getTools: async () => dynamicTools,
6416
- executeTool: async (name, args, context) => {
6455
+ executeTool: async (name, args, context2) => {
6417
6456
  this.logger.debug(`[DEBUG] Executing tool ${name} with args:`, args);
6418
6457
  const response2 = await axios2__default.default.post(
6419
6458
  `${this.mcpRuntimeUrl}/tools/execute`,
6420
6459
  {
6421
6460
  name,
6422
6461
  arguments: args || {},
6423
- context
6462
+ context: context2
6424
6463
  }
6425
6464
  );
6426
6465
  return response2.data;
@@ -6559,7 +6598,7 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
6559
6598
  /**
6560
6599
  * Execute a tool by name with given arguments
6561
6600
  */
6562
- async executeTool(name, args, context) {
6601
+ async executeTool(name, args, context, mcpServers) {
6563
6602
  try {
6564
6603
  this.logger.debug(`Executing tool: ${name} with args:`, args);
6565
6604
  const payload = {
@@ -6569,6 +6608,9 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
6569
6608
  if (context) {
6570
6609
  payload.context = context;
6571
6610
  }
6611
+ if (mcpServers && mcpServers.length > 0) {
6612
+ payload.mcpServers = mcpServers;
6613
+ }
6572
6614
  const response = await this.httpClient.post("/tools/execute", payload);
6573
6615
  this.logger.log(`Tool ${name} executed successfully`);
6574
6616
  return response.data;
@@ -6619,7 +6661,7 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
6619
6661
  * @param config - RunnableConfig with callbacks
6620
6662
  * @returns Tool execution result with content
6621
6663
  */
6622
- async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config) {
6664
+ async executeToolWithEvents(toolCallId, toolName, enrichedArgs, executionContext, config, mcpServers) {
6623
6665
  const parsedConfig = manager.parseCallbackConfigArg(config);
6624
6666
  const callbackManager = manager.CallbackManager.configure(parsedConfig.callbacks);
6625
6667
  let runManager;
@@ -6641,7 +6683,8 @@ exports.McpRuntimeHttpClient = class McpRuntimeHttpClient {
6641
6683
  const result = await this.executeTool(
6642
6684
  toolName,
6643
6685
  enrichedArgs,
6644
- executionContext
6686
+ executionContext,
6687
+ mcpServers
6645
6688
  );
6646
6689
  const content = result.success ? JSON.stringify(result) : result.error || JSON.stringify(result);
6647
6690
  await runManager?.handleToolEnd(content);
@@ -6805,6 +6848,8 @@ var ModelInitializer = class _ModelInitializer {
6805
6848
  this.apiKeyResolver = apiKeyResolver;
6806
6849
  this.logger = logger2 || new common.Logger(_ModelInitializer.name);
6807
6850
  }
6851
+ configFetcher;
6852
+ apiKeyResolver;
6808
6853
  logger;
6809
6854
  // Cache for model configurations to avoid repeated API calls
6810
6855
  modelConfigCache = /* @__PURE__ */ new Map();
@@ -6850,13 +6895,17 @@ var ModelInitializer = class _ModelInitializer {
6850
6895
  * Example: "model123:0.7:4096" or "model123:0.7:4096:a1b2c3d4e5f6g7h8"
6851
6896
  */
6852
6897
  generateModelCacheKey(config) {
6853
- return generateModelCacheKey(
6898
+ const base = generateModelCacheKey(
6854
6899
  config.modelId,
6855
6900
  config.temperature,
6856
6901
  config.maxTokens,
6857
6902
  config.toolsConfig,
6858
6903
  config.baseURL
6859
6904
  );
6905
+ if (config.mcpServers && config.mcpServers.length > 0) {
6906
+ return `${base}:mcp:${JSON.stringify(config.mcpServers)}`;
6907
+ }
6908
+ return base;
6860
6909
  }
6861
6910
  // Chat model creators
6862
6911
  chatModelCreators = {
@@ -7132,11 +7181,13 @@ var ModelInitializer = class _ModelInitializer {
7132
7181
  ...model.metadata,
7133
7182
  modelId: config.modelId
7134
7183
  };
7135
- if (config.toolsConfig || config.customTools) {
7184
+ if (config.toolsConfig || config.customTools || config.mcpServers && config.mcpServers.length > 0) {
7136
7185
  const boundModel = await this.bindToolsToModel(
7137
7186
  model,
7138
7187
  config.toolsConfig,
7139
- config.customTools
7188
+ config.customTools,
7189
+ config.mcpServers,
7190
+ config.mcpContext
7140
7191
  );
7141
7192
  this.modelInstanceCache.set(cacheKey, boundModel);
7142
7193
  return boundModel;
@@ -7153,24 +7204,27 @@ var ModelInitializer = class _ModelInitializer {
7153
7204
  * - Runnable when tools are bound (model.bindTools returns Runnable)
7154
7205
  * - BaseChatModel when no tools
7155
7206
  */
7156
- async bindToolsToModel(model, toolsConfig, customTools) {
7207
+ async bindToolsToModel(model, toolsConfig, customTools, mcpServers, mcpContext) {
7157
7208
  const allTools = [];
7158
- if (toolsConfig && toolsConfig.length > 0) {
7209
+ const enabledToolsConfig = (toolsConfig || []).filter(
7210
+ (tc) => tc.enabled !== false
7211
+ );
7212
+ const hasInlineServers = !!(mcpServers && mcpServers.length > 0);
7213
+ if (enabledToolsConfig.length > 0 || hasInlineServers) {
7159
7214
  try {
7160
- const enabledToolsConfig = toolsConfig.filter(
7161
- (tc) => tc.enabled !== false
7215
+ this.logger.debug(
7216
+ `Fetching ${enabledToolsConfig.length} tools (+${mcpServers?.length || 0} inline server(s)) with dynamic schemas from MCP Runtime`
7162
7217
  );
7163
- if (enabledToolsConfig.length > 0) {
7164
- this.logger.debug(
7165
- `Fetching ${enabledToolsConfig.length} tools with dynamic schemas from MCP Runtime: ${enabledToolsConfig.map((tc) => tc.toolName).join(", ")}`
7166
- );
7167
- const mcpToolFilter = new McpToolFilter();
7168
- const mcpTools = await mcpToolFilter.getFilteredTools(enabledToolsConfig);
7169
- this.logger.debug(
7170
- `Successfully fetched ${mcpTools.length} tools with dynamic schemas from MCP Runtime`
7171
- );
7172
- allTools.push(...mcpTools);
7173
- }
7218
+ const mcpToolFilter = new McpToolFilter();
7219
+ const mcpTools = await mcpToolFilter.getFilteredTools(
7220
+ enabledToolsConfig,
7221
+ mcpServers,
7222
+ mcpContext
7223
+ );
7224
+ this.logger.debug(
7225
+ `Successfully fetched ${mcpTools.length} tools with dynamic schemas from MCP Runtime`
7226
+ );
7227
+ allTools.push(...mcpTools);
7174
7228
  } catch (error) {
7175
7229
  this.logger.error(
7176
7230
  `Failed to fetch tools from MCP Runtime: ${error instanceof Error ? error.message : String(error)}`
@@ -7689,6 +7743,7 @@ exports.StaticDiscovery = class StaticDiscovery {
7689
7743
  constructor(services) {
7690
7744
  this.services = services;
7691
7745
  }
7746
+ services;
7692
7747
  /**
7693
7748
  * Get list of services by category
7694
7749
  */
@@ -7881,6 +7936,7 @@ var FileTokenStore = class {
7881
7936
  constructor(filePath) {
7882
7937
  this.filePath = filePath;
7883
7938
  }
7939
+ filePath;
7884
7940
  async get(provider) {
7885
7941
  const data = this.readFile();
7886
7942
  return data[provider] ?? null;
@@ -7921,6 +7977,7 @@ var MongoTokenStore = class {
7921
7977
  this.db = db;
7922
7978
  this.collectionName = collectionName ?? DEFAULT_COLLECTION;
7923
7979
  }
7980
+ db;
7924
7981
  collectionName;
7925
7982
  initialized = false;
7926
7983
  async get(provider) {