@flutchai/flutch-sdk 0.2.9 → 0.2.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.d.cts CHANGED
@@ -3,7 +3,7 @@ import * as _nestjs_common from '@nestjs/common';
3
3
  import { OnModuleInit, Logger, CanActivate, ExecutionContext, Type, DynamicModule } from '@nestjs/common';
4
4
  import { ConfigService } from '@nestjs/config';
5
5
  import { BaseChannel, OverwriteValue, CompiledStateGraph, LangGraphRunnableConfig } from '@langchain/langgraph';
6
- import { MongoClient } from 'mongodb';
6
+ import { MongoClient, Db } from 'mongodb';
7
7
  import Redis from 'ioredis';
8
8
  import { Registry } from 'prom-client';
9
9
  import { Response, Request } from 'express';
@@ -1664,4 +1664,63 @@ declare class StaticDiscovery implements ServiceDiscoveryProvider {
1664
1664
  }>>;
1665
1665
  }
1666
1666
 
1667
- export { type ACLValidationResult, AbstractGraphBuilder, type ApiCallTracerOptions, type ApiKeyResolver, AttachmentType, type AuditEntry, type BaseGraphConfig, type BaseGraphContext, GraphController as BaseGraphServiceController, UniversalGraphModule as BaseGraphServiceModule, type BaseGraphState, BuilderRegistryService, Callback, CallbackACL, CallbackAuditAction, CallbackAuditor, type CallbackContext, CallbackController, type CallbackEntry, type CallbackHandler, type CallbackMetadata, CallbackMetrics, type CallbackPatch, type CallbackPatchHandler, CallbackPatchService, CallbackRateLimiter, type CallbackRecord, CallbackRegistry, type CallbackRequest, type CallbackResult, CallbackStore, CallbackTokenGuard, type CallbackUser, type ChannelState, type ChartType, ChatFeature, type ChatModelCreator, type ChatModelOrRunnable, type ChatModelWithTools, type CitationValue, type CompiledGraphFor, type CustomDocument, DEFAULT_ATTACHMENT_THRESHOLD, DEFAULT_TRACER_OPTIONS, type DataEnvelope, ENDPOINT_METADATA_KEY, type EmbeddingModelCreator, Endpoint, type EndpointDescriptor, type EndpointHandler, type EndpointMetadata, type EndpointOptions, EndpointRegistry, EventProcessor, type ExecuteToolWithAttachmentsParams, type ExecuteToolWithAttachmentsResult, type ExtendedCallbackContext, type ExtendedCallbackHandler, ExternalGraphBuilder, FileBasedDiscovery, GraphController, GraphEngineFactory, GraphEngineType, GraphManifestSchema, GraphManifestValidator, GraphServiceTokens, GraphTypeUtils, type IAgentToolConfig, type IAgentToolConfiguration, type IAttachment, type IBaseEntity, type IChartDataPoint, type IChartDataset, type IChartValue, type IContentBlock, type IContentChain, type IDeletionInfo, type IGenericGraphType, type IGraphAttachment, type IGraphBuilder, type IGraphCompiler, type IGraphConfigurable, type IGraphEngine, type IGraphLogger, type IGraphManifest, type IGraphMetadata, type IGraphMetadataRegistry, type IGraphRequestPayload, type IGraphResponsePayload, type IGraphRunnableConfig, type IGraphService, type IGraphServiceRegistry, type IGraphSettingsRepository, type IGraphTraceEvent, type IGraphTracer, type IGraphTypeMetadata, type IGraphTypeRegistry, type ILangGraphConfig, type IModelInitializer, type IReasoningChain, type IReasoningStep, type IStoredMessageContent, type ISystemToolCredentials, type IToolCall, type IToolCatalog, type IToolConfigOption, type IToolExecutionContext, type ITracingEvent, type IUsageMetrics, type IUsageRecorder, type IdempotencyConfig, type IdempotencyEntry, IdempotencyManager, IdempotencyStatus, type KnowledgeBaseInfo, type LLMCallRecord, type LLMConfig, type LLModel, LangGraphEngine, type MappedChannels, McpConverter, type McpRuntimeClient, McpRuntimeHttpClient, type McpTool, McpToolFilter, type Model, type ModelByIdConfig, type ModelByIdWithTypeConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreators, ModelInitializer, ModelProvider, ModelType, type MongoDBConfig, type RateLimitConfig, type RateLimitResult, type RequestContext, type RerankModelCreator, type RetrieveQueryOptions, type RetrieverConfig, RetrieverSearchType, RetrieverService, type RouterConfig, type ServiceDiscoveryProvider, SmartCallbackRouter, StaticDiscovery, type StreamAccumulator, StreamChannel, type StrictGraphRunnableConfig, TelegramPatchHandler, type ToolExecutionResult, type TraceApiCallResult, type TracingLevel, UIDispatchController, type UIDispatchDto, UIEndpoint, type UIEndpointClassMetadata, type UIEndpointMethodMetadata, UIEndpointsDiscoveryService, UniversalCallbackService, UniversalGraphModule, type UniversalGraphModuleOptions, UniversalGraphService, type VersionResolution, type VersionResolutionOptions, type VersionRoute, VersionedGraphService, type VersioningConfig, VoyageAIRerank, type VoyageAIRerankConfig, WebPatchHandler, WithCallbacks, WithEndpoints, WithUIEndpoints, _internals, bootstrap, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, dispatchAttachments, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, generateAttachmentSummary, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, storeAttachmentData, traceApiCall };
1667
+ interface OAuthTokens {
1668
+ accessToken: string;
1669
+ refreshToken: string;
1670
+ expiresAt: number;
1671
+ }
1672
+ interface OAuthProviderConfig {
1673
+ provider: string;
1674
+ tokenUrl: string;
1675
+ clientId: string;
1676
+ clientSecret: string;
1677
+ }
1678
+ interface IOAuthTokenStore {
1679
+ get(provider: string): Promise<string | null>;
1680
+ save(provider: string, encrypted: string): Promise<void>;
1681
+ delete(provider: string): Promise<void>;
1682
+ }
1683
+ interface OAuthTokenManagerOptions {
1684
+ store: IOAuthTokenStore;
1685
+ encryptionKey: string;
1686
+ }
1687
+
1688
+ declare class OAuthTokenManager {
1689
+ private readonly store;
1690
+ private readonly encryptionKey;
1691
+ private readonly cache;
1692
+ constructor(options: OAuthTokenManagerOptions);
1693
+ getAccessToken(config: OAuthProviderConfig): Promise<string>;
1694
+ saveTokens(provider: string, tokens: OAuthTokens): Promise<void>;
1695
+ revokeTokens(provider: string): Promise<void>;
1696
+ hasTokens(provider: string): Promise<boolean>;
1697
+ private refreshAccessToken;
1698
+ private persistTokens;
1699
+ private setCache;
1700
+ }
1701
+
1702
+ declare function encryptTokens(tokens: OAuthTokens, key: string): string;
1703
+ declare function decryptTokens(encrypted: string, key: string): OAuthTokens;
1704
+
1705
+ declare class FileTokenStore implements IOAuthTokenStore {
1706
+ private readonly filePath;
1707
+ constructor(filePath: string);
1708
+ get(provider: string): Promise<string | null>;
1709
+ save(provider: string, encrypted: string): Promise<void>;
1710
+ delete(provider: string): Promise<void>;
1711
+ private readFile;
1712
+ private writeFile;
1713
+ }
1714
+
1715
+ declare class MongoTokenStore implements IOAuthTokenStore {
1716
+ private readonly db;
1717
+ private readonly collectionName;
1718
+ private initialized;
1719
+ constructor(db: Db, collectionName?: string);
1720
+ get(provider: string): Promise<string | null>;
1721
+ save(provider: string, encrypted: string): Promise<void>;
1722
+ delete(provider: string): Promise<void>;
1723
+ private ensureIndex;
1724
+ }
1725
+
1726
+ export { type ACLValidationResult, AbstractGraphBuilder, type ApiCallTracerOptions, type ApiKeyResolver, AttachmentType, type AuditEntry, type BaseGraphConfig, type BaseGraphContext, GraphController as BaseGraphServiceController, UniversalGraphModule as BaseGraphServiceModule, type BaseGraphState, BuilderRegistryService, Callback, CallbackACL, CallbackAuditAction, CallbackAuditor, type CallbackContext, CallbackController, type CallbackEntry, type CallbackHandler, type CallbackMetadata, CallbackMetrics, type CallbackPatch, type CallbackPatchHandler, CallbackPatchService, CallbackRateLimiter, type CallbackRecord, CallbackRegistry, type CallbackRequest, type CallbackResult, CallbackStore, CallbackTokenGuard, type CallbackUser, type ChannelState, type ChartType, ChatFeature, type ChatModelCreator, type ChatModelOrRunnable, type ChatModelWithTools, type CitationValue, type CompiledGraphFor, type CustomDocument, DEFAULT_ATTACHMENT_THRESHOLD, DEFAULT_TRACER_OPTIONS, type DataEnvelope, ENDPOINT_METADATA_KEY, type EmbeddingModelCreator, Endpoint, type EndpointDescriptor, type EndpointHandler, type EndpointMetadata, type EndpointOptions, EndpointRegistry, EventProcessor, type ExecuteToolWithAttachmentsParams, type ExecuteToolWithAttachmentsResult, type ExtendedCallbackContext, type ExtendedCallbackHandler, ExternalGraphBuilder, FileBasedDiscovery, FileTokenStore, GraphController, GraphEngineFactory, GraphEngineType, GraphManifestSchema, GraphManifestValidator, GraphServiceTokens, GraphTypeUtils, type IAgentToolConfig, type IAgentToolConfiguration, type IAttachment, type IBaseEntity, type IChartDataPoint, type IChartDataset, type IChartValue, type IContentBlock, type IContentChain, type IDeletionInfo, type IGenericGraphType, type IGraphAttachment, type IGraphBuilder, type IGraphCompiler, type IGraphConfigurable, type IGraphEngine, type IGraphLogger, type IGraphManifest, type IGraphMetadata, type IGraphMetadataRegistry, type IGraphRequestPayload, type IGraphResponsePayload, type IGraphRunnableConfig, type IGraphService, type IGraphServiceRegistry, type IGraphSettingsRepository, type IGraphTraceEvent, type IGraphTracer, type IGraphTypeMetadata, type IGraphTypeRegistry, type ILangGraphConfig, type IModelInitializer, type IOAuthTokenStore, type IReasoningChain, type IReasoningStep, type IStoredMessageContent, type ISystemToolCredentials, type IToolCall, type IToolCatalog, type IToolConfigOption, type IToolExecutionContext, type ITracingEvent, type IUsageMetrics, type IUsageRecorder, type IdempotencyConfig, type IdempotencyEntry, IdempotencyManager, IdempotencyStatus, type KnowledgeBaseInfo, type LLMCallRecord, type LLMConfig, type LLModel, LangGraphEngine, type MappedChannels, McpConverter, type McpRuntimeClient, McpRuntimeHttpClient, type McpTool, McpToolFilter, type Model, type ModelByIdConfig, type ModelByIdWithTypeConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreators, ModelInitializer, ModelProvider, ModelType, type MongoDBConfig, MongoTokenStore, type OAuthProviderConfig, OAuthTokenManager, type OAuthTokenManagerOptions, type OAuthTokens, type RateLimitConfig, type RateLimitResult, type RequestContext, type RerankModelCreator, type RetrieveQueryOptions, type RetrieverConfig, RetrieverSearchType, RetrieverService, type RouterConfig, type ServiceDiscoveryProvider, SmartCallbackRouter, StaticDiscovery, type StreamAccumulator, StreamChannel, type StrictGraphRunnableConfig, TelegramPatchHandler, type ToolExecutionResult, type TraceApiCallResult, type TracingLevel, UIDispatchController, type UIDispatchDto, UIEndpoint, type UIEndpointClassMetadata, type UIEndpointMethodMetadata, UIEndpointsDiscoveryService, UniversalCallbackService, UniversalGraphModule, type UniversalGraphModuleOptions, UniversalGraphService, type VersionResolution, type VersionResolutionOptions, type VersionRoute, VersionedGraphService, type VersioningConfig, VoyageAIRerank, type VoyageAIRerankConfig, WebPatchHandler, WithCallbacks, WithEndpoints, WithUIEndpoints, _internals, bootstrap, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, decryptTokens, dispatchAttachments, encryptTokens, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, generateAttachmentSummary, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, storeAttachmentData, traceApiCall };
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import * as _nestjs_common from '@nestjs/common';
3
3
  import { OnModuleInit, Logger, CanActivate, ExecutionContext, Type, DynamicModule } from '@nestjs/common';
4
4
  import { ConfigService } from '@nestjs/config';
5
5
  import { BaseChannel, OverwriteValue, CompiledStateGraph, LangGraphRunnableConfig } from '@langchain/langgraph';
6
- import { MongoClient } from 'mongodb';
6
+ import { MongoClient, Db } from 'mongodb';
7
7
  import Redis from 'ioredis';
8
8
  import { Registry } from 'prom-client';
9
9
  import { Response, Request } from 'express';
@@ -1664,4 +1664,63 @@ declare class StaticDiscovery implements ServiceDiscoveryProvider {
1664
1664
  }>>;
1665
1665
  }
1666
1666
 
1667
- export { type ACLValidationResult, AbstractGraphBuilder, type ApiCallTracerOptions, type ApiKeyResolver, AttachmentType, type AuditEntry, type BaseGraphConfig, type BaseGraphContext, GraphController as BaseGraphServiceController, UniversalGraphModule as BaseGraphServiceModule, type BaseGraphState, BuilderRegistryService, Callback, CallbackACL, CallbackAuditAction, CallbackAuditor, type CallbackContext, CallbackController, type CallbackEntry, type CallbackHandler, type CallbackMetadata, CallbackMetrics, type CallbackPatch, type CallbackPatchHandler, CallbackPatchService, CallbackRateLimiter, type CallbackRecord, CallbackRegistry, type CallbackRequest, type CallbackResult, CallbackStore, CallbackTokenGuard, type CallbackUser, type ChannelState, type ChartType, ChatFeature, type ChatModelCreator, type ChatModelOrRunnable, type ChatModelWithTools, type CitationValue, type CompiledGraphFor, type CustomDocument, DEFAULT_ATTACHMENT_THRESHOLD, DEFAULT_TRACER_OPTIONS, type DataEnvelope, ENDPOINT_METADATA_KEY, type EmbeddingModelCreator, Endpoint, type EndpointDescriptor, type EndpointHandler, type EndpointMetadata, type EndpointOptions, EndpointRegistry, EventProcessor, type ExecuteToolWithAttachmentsParams, type ExecuteToolWithAttachmentsResult, type ExtendedCallbackContext, type ExtendedCallbackHandler, ExternalGraphBuilder, FileBasedDiscovery, GraphController, GraphEngineFactory, GraphEngineType, GraphManifestSchema, GraphManifestValidator, GraphServiceTokens, GraphTypeUtils, type IAgentToolConfig, type IAgentToolConfiguration, type IAttachment, type IBaseEntity, type IChartDataPoint, type IChartDataset, type IChartValue, type IContentBlock, type IContentChain, type IDeletionInfo, type IGenericGraphType, type IGraphAttachment, type IGraphBuilder, type IGraphCompiler, type IGraphConfigurable, type IGraphEngine, type IGraphLogger, type IGraphManifest, type IGraphMetadata, type IGraphMetadataRegistry, type IGraphRequestPayload, type IGraphResponsePayload, type IGraphRunnableConfig, type IGraphService, type IGraphServiceRegistry, type IGraphSettingsRepository, type IGraphTraceEvent, type IGraphTracer, type IGraphTypeMetadata, type IGraphTypeRegistry, type ILangGraphConfig, type IModelInitializer, type IReasoningChain, type IReasoningStep, type IStoredMessageContent, type ISystemToolCredentials, type IToolCall, type IToolCatalog, type IToolConfigOption, type IToolExecutionContext, type ITracingEvent, type IUsageMetrics, type IUsageRecorder, type IdempotencyConfig, type IdempotencyEntry, IdempotencyManager, IdempotencyStatus, type KnowledgeBaseInfo, type LLMCallRecord, type LLMConfig, type LLModel, LangGraphEngine, type MappedChannels, McpConverter, type McpRuntimeClient, McpRuntimeHttpClient, type McpTool, McpToolFilter, type Model, type ModelByIdConfig, type ModelByIdWithTypeConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreators, ModelInitializer, ModelProvider, ModelType, type MongoDBConfig, type RateLimitConfig, type RateLimitResult, type RequestContext, type RerankModelCreator, type RetrieveQueryOptions, type RetrieverConfig, RetrieverSearchType, RetrieverService, type RouterConfig, type ServiceDiscoveryProvider, SmartCallbackRouter, StaticDiscovery, type StreamAccumulator, StreamChannel, type StrictGraphRunnableConfig, TelegramPatchHandler, type ToolExecutionResult, type TraceApiCallResult, type TracingLevel, UIDispatchController, type UIDispatchDto, UIEndpoint, type UIEndpointClassMetadata, type UIEndpointMethodMetadata, UIEndpointsDiscoveryService, UniversalCallbackService, UniversalGraphModule, type UniversalGraphModuleOptions, UniversalGraphService, type VersionResolution, type VersionResolutionOptions, type VersionRoute, VersionedGraphService, type VersioningConfig, VoyageAIRerank, type VoyageAIRerankConfig, WebPatchHandler, WithCallbacks, WithEndpoints, WithUIEndpoints, _internals, bootstrap, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, dispatchAttachments, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, generateAttachmentSummary, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, storeAttachmentData, traceApiCall };
1667
+ interface OAuthTokens {
1668
+ accessToken: string;
1669
+ refreshToken: string;
1670
+ expiresAt: number;
1671
+ }
1672
+ interface OAuthProviderConfig {
1673
+ provider: string;
1674
+ tokenUrl: string;
1675
+ clientId: string;
1676
+ clientSecret: string;
1677
+ }
1678
+ interface IOAuthTokenStore {
1679
+ get(provider: string): Promise<string | null>;
1680
+ save(provider: string, encrypted: string): Promise<void>;
1681
+ delete(provider: string): Promise<void>;
1682
+ }
1683
+ interface OAuthTokenManagerOptions {
1684
+ store: IOAuthTokenStore;
1685
+ encryptionKey: string;
1686
+ }
1687
+
1688
+ declare class OAuthTokenManager {
1689
+ private readonly store;
1690
+ private readonly encryptionKey;
1691
+ private readonly cache;
1692
+ constructor(options: OAuthTokenManagerOptions);
1693
+ getAccessToken(config: OAuthProviderConfig): Promise<string>;
1694
+ saveTokens(provider: string, tokens: OAuthTokens): Promise<void>;
1695
+ revokeTokens(provider: string): Promise<void>;
1696
+ hasTokens(provider: string): Promise<boolean>;
1697
+ private refreshAccessToken;
1698
+ private persistTokens;
1699
+ private setCache;
1700
+ }
1701
+
1702
+ declare function encryptTokens(tokens: OAuthTokens, key: string): string;
1703
+ declare function decryptTokens(encrypted: string, key: string): OAuthTokens;
1704
+
1705
+ declare class FileTokenStore implements IOAuthTokenStore {
1706
+ private readonly filePath;
1707
+ constructor(filePath: string);
1708
+ get(provider: string): Promise<string | null>;
1709
+ save(provider: string, encrypted: string): Promise<void>;
1710
+ delete(provider: string): Promise<void>;
1711
+ private readFile;
1712
+ private writeFile;
1713
+ }
1714
+
1715
+ declare class MongoTokenStore implements IOAuthTokenStore {
1716
+ private readonly db;
1717
+ private readonly collectionName;
1718
+ private initialized;
1719
+ constructor(db: Db, collectionName?: string);
1720
+ get(provider: string): Promise<string | null>;
1721
+ save(provider: string, encrypted: string): Promise<void>;
1722
+ delete(provider: string): Promise<void>;
1723
+ private ensureIndex;
1724
+ }
1725
+
1726
+ export { type ACLValidationResult, AbstractGraphBuilder, type ApiCallTracerOptions, type ApiKeyResolver, AttachmentType, type AuditEntry, type BaseGraphConfig, type BaseGraphContext, GraphController as BaseGraphServiceController, UniversalGraphModule as BaseGraphServiceModule, type BaseGraphState, BuilderRegistryService, Callback, CallbackACL, CallbackAuditAction, CallbackAuditor, type CallbackContext, CallbackController, type CallbackEntry, type CallbackHandler, type CallbackMetadata, CallbackMetrics, type CallbackPatch, type CallbackPatchHandler, CallbackPatchService, CallbackRateLimiter, type CallbackRecord, CallbackRegistry, type CallbackRequest, type CallbackResult, CallbackStore, CallbackTokenGuard, type CallbackUser, type ChannelState, type ChartType, ChatFeature, type ChatModelCreator, type ChatModelOrRunnable, type ChatModelWithTools, type CitationValue, type CompiledGraphFor, type CustomDocument, DEFAULT_ATTACHMENT_THRESHOLD, DEFAULT_TRACER_OPTIONS, type DataEnvelope, ENDPOINT_METADATA_KEY, type EmbeddingModelCreator, Endpoint, type EndpointDescriptor, type EndpointHandler, type EndpointMetadata, type EndpointOptions, EndpointRegistry, EventProcessor, type ExecuteToolWithAttachmentsParams, type ExecuteToolWithAttachmentsResult, type ExtendedCallbackContext, type ExtendedCallbackHandler, ExternalGraphBuilder, FileBasedDiscovery, FileTokenStore, GraphController, GraphEngineFactory, GraphEngineType, GraphManifestSchema, GraphManifestValidator, GraphServiceTokens, GraphTypeUtils, type IAgentToolConfig, type IAgentToolConfiguration, type IAttachment, type IBaseEntity, type IChartDataPoint, type IChartDataset, type IChartValue, type IContentBlock, type IContentChain, type IDeletionInfo, type IGenericGraphType, type IGraphAttachment, type IGraphBuilder, type IGraphCompiler, type IGraphConfigurable, type IGraphEngine, type IGraphLogger, type IGraphManifest, type IGraphMetadata, type IGraphMetadataRegistry, type IGraphRequestPayload, type IGraphResponsePayload, type IGraphRunnableConfig, type IGraphService, type IGraphServiceRegistry, type IGraphSettingsRepository, type IGraphTraceEvent, type IGraphTracer, type IGraphTypeMetadata, type IGraphTypeRegistry, type ILangGraphConfig, type IModelInitializer, type IOAuthTokenStore, type IReasoningChain, type IReasoningStep, type IStoredMessageContent, type ISystemToolCredentials, type IToolCall, type IToolCatalog, type IToolConfigOption, type IToolExecutionContext, type ITracingEvent, type IUsageMetrics, type IUsageRecorder, type IdempotencyConfig, type IdempotencyEntry, IdempotencyManager, IdempotencyStatus, type KnowledgeBaseInfo, type LLMCallRecord, type LLMConfig, type LLModel, LangGraphEngine, type MappedChannels, McpConverter, type McpRuntimeClient, McpRuntimeHttpClient, type McpTool, McpToolFilter, type Model, type ModelByIdConfig, type ModelByIdWithTypeConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreators, ModelInitializer, ModelProvider, ModelType, type MongoDBConfig, MongoTokenStore, type OAuthProviderConfig, OAuthTokenManager, type OAuthTokenManagerOptions, type OAuthTokens, type RateLimitConfig, type RateLimitResult, type RequestContext, type RerankModelCreator, type RetrieveQueryOptions, type RetrieverConfig, RetrieverSearchType, RetrieverService, type RouterConfig, type ServiceDiscoveryProvider, SmartCallbackRouter, StaticDiscovery, type StreamAccumulator, StreamChannel, type StrictGraphRunnableConfig, TelegramPatchHandler, type ToolExecutionResult, type TraceApiCallResult, type TracingLevel, UIDispatchController, type UIDispatchDto, UIEndpoint, type UIEndpointClassMetadata, type UIEndpointMethodMetadata, UIEndpointsDiscoveryService, UniversalCallbackService, UniversalGraphModule, type UniversalGraphModuleOptions, UniversalGraphService, type VersionResolution, type VersionResolutionOptions, type VersionRoute, VersionedGraphService, type VersioningConfig, VoyageAIRerank, type VoyageAIRerankConfig, WebPatchHandler, WithCallbacks, WithEndpoints, WithUIEndpoints, _internals, bootstrap, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, decryptTokens, dispatchAttachments, encryptTokens, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, generateAttachmentSummary, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, storeAttachmentData, traceApiCall };
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@ import * as net from 'net';
9
9
  import { ConfigService, ConfigModule } from '@nestjs/config';
10
10
  import mongoose from 'mongoose';
11
11
  import { MongoDBSaver } from '@langchain/langgraph-checkpoint-mongodb';
12
+ import * as crypto from 'crypto';
12
13
  import { createHash, randomUUID, randomBytes } from 'crypto';
13
14
  import { Registry, collectDefaultMetrics, Counter, Histogram, Gauge } from 'prom-client';
14
15
  import { ToolMessage, AIMessage } from '@langchain/core/messages';
@@ -1335,10 +1336,10 @@ var AbstractGraphBuilder = class {
1335
1336
  return null;
1336
1337
  }
1337
1338
  try {
1338
- const fs2 = await import('fs/promises');
1339
- const path3 = await import('path');
1340
- const manifestFullPath = path3.resolve(this.manifestPath);
1341
- const manifestContent = await fs2.readFile(manifestFullPath, "utf-8");
1339
+ const fs3 = await import('fs/promises');
1340
+ const path4 = await import('path');
1341
+ const manifestFullPath = path4.resolve(this.manifestPath);
1342
+ const manifestContent = await fs3.readFile(manifestFullPath, "utf-8");
1342
1343
  const manifest = JSON.parse(manifestContent);
1343
1344
  this.manifest = manifest;
1344
1345
  return manifest;
@@ -1357,10 +1358,10 @@ var AbstractGraphBuilder = class {
1357
1358
  return null;
1358
1359
  }
1359
1360
  try {
1360
- const fs2 = __require("fs");
1361
- const path3 = __require("path");
1362
- const manifestFullPath = path3.resolve(this.manifestPath);
1363
- const manifestContent = fs2.readFileSync(manifestFullPath, "utf-8");
1361
+ const fs3 = __require("fs");
1362
+ const path4 = __require("path");
1363
+ const manifestFullPath = path4.resolve(this.manifestPath);
1364
+ const manifestContent = fs3.readFileSync(manifestFullPath, "utf-8");
1364
1365
  const manifest = JSON.parse(manifestContent);
1365
1366
  this.manifest = manifest;
1366
1367
  return manifest;
@@ -1400,12 +1401,12 @@ var AbstractGraphBuilder = class {
1400
1401
  let configSchema = null;
1401
1402
  if (versionConfig.configSchemaPath) {
1402
1403
  try {
1403
- const fs2 = await import('fs/promises');
1404
+ const fs3 = await import('fs/promises');
1404
1405
  const schemaPath = path2.resolve(
1405
1406
  process.cwd(),
1406
1407
  versionConfig.configSchemaPath
1407
1408
  );
1408
- const schemaContent = await fs2.readFile(schemaPath, "utf-8");
1409
+ const schemaContent = await fs3.readFile(schemaPath, "utf-8");
1409
1410
  const schemaData = JSON.parse(schemaContent);
1410
1411
  configSchema = schemaData.schema;
1411
1412
  } catch (error) {
@@ -7295,7 +7296,206 @@ var StaticDiscovery = class {
7295
7296
  StaticDiscovery = __decorateClass([
7296
7297
  Injectable()
7297
7298
  ], StaticDiscovery);
7299
+ var ALGORITHM = "aes-256-cbc";
7300
+ var IV_LENGTH = 16;
7301
+ function encryptTokens(tokens, key) {
7302
+ const iv = crypto.randomBytes(IV_LENGTH);
7303
+ const cipher = crypto.createCipheriv(
7304
+ ALGORITHM,
7305
+ Buffer.from(key),
7306
+ iv
7307
+ );
7308
+ const json = JSON.stringify(tokens);
7309
+ let encrypted = cipher.update(json, "utf8", "hex");
7310
+ encrypted += cipher.final("hex");
7311
+ return iv.toString("hex") + ":" + encrypted;
7312
+ }
7313
+ function decryptTokens(encrypted, key) {
7314
+ const separatorIndex = encrypted.indexOf(":");
7315
+ if (separatorIndex === -1) {
7316
+ throw new Error("Invalid encrypted token format");
7317
+ }
7318
+ const ivHex = encrypted.substring(0, separatorIndex);
7319
+ const encryptedData = encrypted.substring(separatorIndex + 1);
7320
+ const iv = Buffer.from(ivHex, "hex");
7321
+ const decipher = crypto.createDecipheriv(
7322
+ ALGORITHM,
7323
+ Buffer.from(key),
7324
+ iv
7325
+ );
7326
+ let decrypted = decipher.update(encryptedData, "hex", "utf8");
7327
+ decrypted += decipher.final("utf8");
7328
+ return JSON.parse(decrypted);
7329
+ }
7330
+
7331
+ // src/oauth/oauth-token.manager.ts
7332
+ var EXPIRY_BUFFER_MS = 6e4;
7333
+ var OAuthTokenManager = class {
7334
+ store;
7335
+ encryptionKey;
7336
+ cache = /* @__PURE__ */ new Map();
7337
+ constructor(options) {
7338
+ if (!options.encryptionKey || options.encryptionKey.length < 32) {
7339
+ throw new Error(
7340
+ "OAUTH_ENCRYPTION_KEY must be at least 32 characters for AES-256-CBC"
7341
+ );
7342
+ }
7343
+ this.store = options.store;
7344
+ this.encryptionKey = options.encryptionKey;
7345
+ }
7346
+ /**
7347
+ * Get a fresh access token for the given provider.
7348
+ * Returns from cache → store → refresh flow (in that order).
7349
+ */
7350
+ async getAccessToken(config) {
7351
+ const cached = this.cache.get(config.provider);
7352
+ if (cached && cached.expiresAt > Date.now() + EXPIRY_BUFFER_MS) {
7353
+ return cached.token;
7354
+ }
7355
+ const encrypted = await this.store.get(config.provider);
7356
+ if (!encrypted) {
7357
+ throw new Error(
7358
+ `No OAuth tokens found for "${config.provider}". Complete the OAuth consent flow first and call saveTokens().`
7359
+ );
7360
+ }
7361
+ const tokens = decryptTokens(encrypted, this.encryptionKey);
7362
+ if (tokens.expiresAt > Date.now() + EXPIRY_BUFFER_MS) {
7363
+ this.setCache(config.provider, tokens.accessToken, tokens.expiresAt);
7364
+ return tokens.accessToken;
7365
+ }
7366
+ const refreshed = await this.refreshAccessToken(config, tokens.refreshToken);
7367
+ await this.persistTokens(config.provider, refreshed);
7368
+ return refreshed.accessToken;
7369
+ }
7370
+ /**
7371
+ * Store tokens after the initial OAuth consent flow.
7372
+ * Call this once after the user completes the OAuth redirect.
7373
+ */
7374
+ async saveTokens(provider, tokens) {
7375
+ await this.persistTokens(provider, tokens);
7376
+ }
7377
+ /**
7378
+ * Remove all tokens for a provider.
7379
+ */
7380
+ async revokeTokens(provider) {
7381
+ await this.store.delete(provider);
7382
+ this.cache.delete(provider);
7383
+ }
7384
+ /**
7385
+ * Check if tokens exist for a provider (without decrypting).
7386
+ */
7387
+ async hasTokens(provider) {
7388
+ const encrypted = await this.store.get(provider);
7389
+ return encrypted !== null;
7390
+ }
7391
+ async refreshAccessToken(config, refreshToken) {
7392
+ try {
7393
+ const response = await axios2.post(
7394
+ config.tokenUrl,
7395
+ new URLSearchParams({
7396
+ grant_type: "refresh_token",
7397
+ client_id: config.clientId,
7398
+ client_secret: config.clientSecret,
7399
+ refresh_token: refreshToken
7400
+ }).toString(),
7401
+ {
7402
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
7403
+ timeout: 1e4
7404
+ }
7405
+ );
7406
+ const data = response.data;
7407
+ return {
7408
+ accessToken: data.access_token,
7409
+ // Some providers rotate refresh tokens; keep the old one if not rotated
7410
+ refreshToken: data.refresh_token || refreshToken,
7411
+ expiresAt: Date.now() + (data.expires_in || 3600) * 1e3
7412
+ };
7413
+ } catch (error) {
7414
+ const status = error?.response?.status;
7415
+ const body = error?.response?.data;
7416
+ throw new Error(
7417
+ `OAuth refresh failed for "${config.provider}": ${status || "network error"} ${JSON.stringify(body) || error.message}`
7418
+ );
7419
+ }
7420
+ }
7421
+ async persistTokens(provider, tokens) {
7422
+ const encrypted = encryptTokens(tokens, this.encryptionKey);
7423
+ await this.store.save(provider, encrypted);
7424
+ this.setCache(provider, tokens.accessToken, tokens.expiresAt);
7425
+ }
7426
+ setCache(provider, token, expiresAt) {
7427
+ this.cache.set(provider, { token, expiresAt });
7428
+ }
7429
+ };
7430
+ var FileTokenStore = class {
7431
+ constructor(filePath) {
7432
+ this.filePath = filePath;
7433
+ }
7434
+ async get(provider) {
7435
+ const data = this.readFile();
7436
+ return data[provider] ?? null;
7437
+ }
7438
+ async save(provider, encrypted) {
7439
+ const data = this.readFile();
7440
+ data[provider] = encrypted;
7441
+ this.writeFile(data);
7442
+ }
7443
+ async delete(provider) {
7444
+ const data = this.readFile();
7445
+ delete data[provider];
7446
+ this.writeFile(data);
7447
+ }
7448
+ readFile() {
7449
+ try {
7450
+ if (fs.existsSync(this.filePath)) {
7451
+ const content = fs.readFileSync(this.filePath, "utf8");
7452
+ return JSON.parse(content);
7453
+ }
7454
+ } catch {
7455
+ }
7456
+ return {};
7457
+ }
7458
+ writeFile(data) {
7459
+ const dir = path2.dirname(this.filePath);
7460
+ if (!fs.existsSync(dir)) {
7461
+ fs.mkdirSync(dir, { recursive: true });
7462
+ }
7463
+ fs.writeFileSync(this.filePath, JSON.stringify(data, null, 2), "utf8");
7464
+ }
7465
+ };
7466
+
7467
+ // src/oauth/stores/mongo-token.store.ts
7468
+ var DEFAULT_COLLECTION = "oauth_tokens";
7469
+ var MongoTokenStore = class {
7470
+ constructor(db, collectionName) {
7471
+ this.db = db;
7472
+ this.collectionName = collectionName ?? DEFAULT_COLLECTION;
7473
+ }
7474
+ collectionName;
7475
+ initialized = false;
7476
+ async get(provider) {
7477
+ await this.ensureIndex();
7478
+ const doc = await this.db.collection(this.collectionName).findOne({ provider });
7479
+ return doc?.encrypted ?? null;
7480
+ }
7481
+ async save(provider, encrypted) {
7482
+ await this.ensureIndex();
7483
+ await this.db.collection(this.collectionName).updateOne(
7484
+ { provider },
7485
+ { $set: { provider, encrypted, updatedAt: /* @__PURE__ */ new Date() } },
7486
+ { upsert: true }
7487
+ );
7488
+ }
7489
+ async delete(provider) {
7490
+ await this.db.collection(this.collectionName).deleteOne({ provider });
7491
+ }
7492
+ async ensureIndex() {
7493
+ if (this.initialized) return;
7494
+ await this.db.collection(this.collectionName).createIndex({ provider: 1 }, { unique: true });
7495
+ this.initialized = true;
7496
+ }
7497
+ };
7298
7498
 
7299
- export { AbstractGraphBuilder, AttachmentType, GraphController as BaseGraphServiceController, UniversalGraphModule as BaseGraphServiceModule, BuilderRegistryService, Callback, CallbackACL, CallbackAuditAction, CallbackAuditor, CallbackController, CallbackMetrics, CallbackPatchService, CallbackRateLimiter, CallbackRegistry, CallbackStore, CallbackTokenGuard, ChatFeature, DEFAULT_ATTACHMENT_THRESHOLD, DEFAULT_TRACER_OPTIONS, ENDPOINT_METADATA_KEY, Endpoint, EndpointRegistry, EventProcessor, ExternalGraphBuilder, FileBasedDiscovery, GraphController, GraphEngineFactory, GraphEngineType, GraphManifestSchema, GraphManifestValidator, GraphServiceTokens, GraphTypeUtils, IdempotencyManager, IdempotencyStatus, LangGraphEngine, McpConverter, McpRuntimeHttpClient, McpToolFilter, ModelInitializer, ModelProvider, ModelType, RetrieverSearchType, RetrieverService, SmartCallbackRouter, StaticDiscovery, StreamChannel, TelegramPatchHandler, UIDispatchController, UIEndpoint, UIEndpointsDiscoveryService, UniversalCallbackService, UniversalGraphModule, UniversalGraphService, VersionedGraphService, VoyageAIRerank, WebPatchHandler, WithCallbacks, WithEndpoints, WithUIEndpoints, _internals, bootstrap, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, dispatchAttachments, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, generateAttachmentSummary, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, storeAttachmentData, traceApiCall };
7499
+ export { AbstractGraphBuilder, AttachmentType, GraphController as BaseGraphServiceController, UniversalGraphModule as BaseGraphServiceModule, BuilderRegistryService, Callback, CallbackACL, CallbackAuditAction, CallbackAuditor, CallbackController, CallbackMetrics, CallbackPatchService, CallbackRateLimiter, CallbackRegistry, CallbackStore, CallbackTokenGuard, ChatFeature, DEFAULT_ATTACHMENT_THRESHOLD, DEFAULT_TRACER_OPTIONS, ENDPOINT_METADATA_KEY, Endpoint, EndpointRegistry, EventProcessor, ExternalGraphBuilder, FileBasedDiscovery, FileTokenStore, GraphController, GraphEngineFactory, GraphEngineType, GraphManifestSchema, GraphManifestValidator, GraphServiceTokens, GraphTypeUtils, IdempotencyManager, IdempotencyStatus, LangGraphEngine, McpConverter, McpRuntimeHttpClient, McpToolFilter, ModelInitializer, ModelProvider, ModelType, MongoTokenStore, OAuthTokenManager, RetrieverSearchType, RetrieverService, SmartCallbackRouter, StaticDiscovery, StreamChannel, TelegramPatchHandler, UIDispatchController, UIEndpoint, UIEndpointsDiscoveryService, UniversalCallbackService, UniversalGraphModule, UniversalGraphService, VersionedGraphService, VoyageAIRerank, WebPatchHandler, WithCallbacks, WithEndpoints, WithUIEndpoints, _internals, bootstrap, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, decryptTokens, dispatchAttachments, encryptTokens, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, generateAttachmentSummary, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, storeAttachmentData, traceApiCall };
7300
7500
  //# sourceMappingURL=index.js.map
7301
7501
  //# sourceMappingURL=index.js.map