@flutchai/flutch-sdk 0.6.3 → 0.6.6

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
@@ -8,13 +8,16 @@ import Redis from 'ioredis';
8
8
  import { Registry } from 'prom-client';
9
9
  import { Response, Request as Request$1 } from 'express';
10
10
  import { DiscoveryService, MetadataScanner, ModuleRef } from '@nestjs/core';
11
- import { AIMessageChunk, ToolMessage, AIMessage } from '@langchain/core/messages';
11
+ import { AIMessageChunk, BaseMessage, ToolMessage, AIMessage } from '@langchain/core/messages';
12
12
  import { Runnable, RunnableConfig } from '@langchain/core/runnables';
13
13
  import { DynamicStructuredTool, StructuredTool } from '@langchain/core/tools';
14
14
  import { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models';
15
15
  import { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';
16
16
  import { Embeddings } from '@langchain/core/embeddings';
17
17
  import { BaseLanguageModelInput } from '@langchain/core/language_models/base';
18
+ import { ChatBedrockConverse } from '@langchain/aws';
19
+ import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
20
+ import { ChatResult, ChatGenerationChunk } from '@langchain/core/outputs';
18
21
  import { Document } from '@langchain/core/documents';
19
22
 
20
23
  interface RequestContext {
@@ -1028,6 +1031,76 @@ declare function flutchHeaders(): Record<string, string>;
1028
1031
  declare function flutchMistralHook(req: Request): Request;
1029
1032
  declare function wrapCohereFetcher<T extends (args: any) => any>(inner: T): T;
1030
1033
 
1034
+ interface IAgentToolConfig {
1035
+ toolName: string;
1036
+ enabled: boolean;
1037
+ config?: Record<string, any>;
1038
+ }
1039
+ interface IAgentToolConfiguration {
1040
+ toolName: string;
1041
+ enabled: boolean;
1042
+ config?: Record<string, any>;
1043
+ credentials?: Record<string, string>;
1044
+ useGlobalCredentials?: boolean;
1045
+ }
1046
+ interface ISystemToolCredentials {
1047
+ toolName: string;
1048
+ credentials: Record<string, string>;
1049
+ createdBy: string;
1050
+ createdAt: Date;
1051
+ updatedAt: Date;
1052
+ }
1053
+ interface IToolExecutionContext {
1054
+ toolName: string;
1055
+ config: Record<string, any>;
1056
+ credentials: Record<string, string>;
1057
+ agentId: string;
1058
+ userId: string;
1059
+ threadId?: string;
1060
+ }
1061
+
1062
+ declare function isReasoningModel(modelName: string): boolean;
1063
+ declare function toOptionalNumber(value: unknown): number | undefined;
1064
+ declare const SAMPLING_PARAM_FREE_THRESHOLDS: Record<string, {
1065
+ major: number;
1066
+ minor: number;
1067
+ }>;
1068
+ declare function modelAcceptsSamplingParams(modelIdentifier?: string): boolean;
1069
+ declare const PROMPT_CACHE_MIN_VERSIONS: Record<string, {
1070
+ major: number;
1071
+ minor: number;
1072
+ }>;
1073
+ type PromptCacheTtl = "5m" | "1h";
1074
+ interface PromptCacheControl {
1075
+ type: "ephemeral";
1076
+ ttl?: PromptCacheTtl;
1077
+ }
1078
+ declare function modelSupportsPromptCache(modelIdentifier?: string): boolean;
1079
+ declare function resolvePromptCacheControl(modelIdentifiers: (string | undefined)[], promptCache?: boolean, ttl?: PromptCacheTtl): PromptCacheControl | undefined;
1080
+ type ReasoningEffort = "low" | "medium" | "high" | "xhigh" | "max";
1081
+ declare function buildEffortRequestFields(effort?: ReasoningEffort): {
1082
+ output_config: {
1083
+ effort: ReasoningEffort;
1084
+ };
1085
+ } | undefined;
1086
+ interface SamplingParams {
1087
+ temperature?: number;
1088
+ topP?: number;
1089
+ topK?: number;
1090
+ }
1091
+ interface ResolvedSamplingParams {
1092
+ params: SamplingParams;
1093
+ dropped: string[];
1094
+ accepted: boolean;
1095
+ }
1096
+ declare function resolveSamplingParams(modelIdentifiers: (string | undefined)[], requested: SamplingParams, supportsSamplingParams?: boolean): ResolvedSamplingParams;
1097
+ declare function hashToolsConfig(toolsConfig: IAgentToolConfig[]): string;
1098
+ declare function normalizeToolConfigs(tools?: ToolConfig[]): IAgentToolConfig[] | undefined;
1099
+ declare const DEFAULT_ROUTER_URL = "https://router.flutch.ai";
1100
+ declare function resolveRouterURL(baseURL?: string): string | undefined;
1101
+ declare function generateModelCacheKey(modelId: string, temperature?: number, maxTokens?: number, toolsConfig?: IAgentToolConfig[], baseURL?: string): string;
1102
+ declare function buildOpenAIModelConfig(modelName: string, temperature: number | undefined, maxTokens: number | undefined, apiToken: string): Record<string, any>;
1103
+
1031
1104
  type ToolConfig = string | {
1032
1105
  name: string;
1033
1106
  enabled?: boolean;
@@ -1042,28 +1115,37 @@ interface ModelConfig {
1042
1115
  tools?: ToolConfig[];
1043
1116
  baseURL?: string;
1044
1117
  providerConfig?: Record<string, any>;
1118
+ supportsSamplingParams?: boolean;
1045
1119
  }
1046
1120
  interface ModelByIdConfig {
1047
1121
  modelId: string;
1048
1122
  temperature?: number;
1049
1123
  maxTokens?: number;
1124
+ supportsSamplingParams?: boolean;
1050
1125
  baseURL?: string;
1051
1126
  toolsConfig?: IAgentToolConfig[];
1052
1127
  customTools?: DynamicStructuredTool[];
1053
1128
  mcpServers?: Record<string, any>[];
1054
1129
  mcpContext?: Record<string, any>;
1130
+ promptCache?: boolean;
1131
+ promptCacheTtl?: PromptCacheTtl;
1132
+ effort?: ReasoningEffort;
1055
1133
  }
1056
1134
  type ModelConfigFetcher = (modelId: string) => Promise<ModelConfigWithToken>;
1057
1135
  interface ModelConfigWithToken {
1058
1136
  modelId: string;
1059
1137
  modelName: string;
1060
1138
  provider: ModelProvider;
1061
- defaultTemperature: number;
1062
- defaultMaxTokens: number;
1139
+ defaultTemperature?: number;
1140
+ defaultMaxTokens?: number;
1063
1141
  apiToken?: string;
1064
1142
  requiresApiKey: boolean;
1143
+ supportsSamplingParams?: boolean;
1065
1144
  useBedrock?: boolean;
1066
1145
  bedrockModelId?: string;
1146
+ promptCache?: boolean;
1147
+ promptCacheTtl?: PromptCacheTtl;
1148
+ defaultEffort?: ReasoningEffort;
1067
1149
  baseURL?: string;
1068
1150
  }
1069
1151
  type ApiKeyResolver = (provider: ModelProvider) => string | undefined;
@@ -1094,7 +1176,7 @@ interface IModelInitializer {
1094
1176
  isModelTypeSupported(modelType: ModelType): boolean;
1095
1177
  getSupportedModelTypes(): ModelType[];
1096
1178
  }
1097
- type ChatModelCreator = (config: ModelConfigWithTokenAndType) => BaseChatModel;
1179
+ type ChatModelCreator = (config: ModelConfigWithTokenAndType, promptCacheControl?: PromptCacheControl) => BaseChatModel;
1098
1180
  type RerankModelCreator = (config: ModelConfigWithTokenAndType) => BaseDocumentCompressor;
1099
1181
  type EmbeddingModelCreator = (config: ModelConfigWithTokenAndType) => Embeddings;
1100
1182
  interface ModelCreators {
@@ -1115,6 +1197,7 @@ declare class ModelInitializer implements IModelInitializer {
1115
1197
  constructor(configFetcher?: ModelConfigFetcher, logger?: Logger, apiKeyResolver?: ApiKeyResolver);
1116
1198
  private resolveApiKey;
1117
1199
  private resolveBedrockRegion;
1200
+ private resolveSampling;
1118
1201
  private hashToolsConfig;
1119
1202
  private generateModelCacheKey;
1120
1203
  private readonly chatModelCreators;
@@ -1145,41 +1228,29 @@ declare class ModelInitializer implements IModelInitializer {
1145
1228
  private fetchFromApi;
1146
1229
  }
1147
1230
 
1148
- interface IAgentToolConfig {
1149
- toolName: string;
1150
- enabled: boolean;
1151
- config?: Record<string, any>;
1152
- }
1153
- interface IAgentToolConfiguration {
1154
- toolName: string;
1155
- enabled: boolean;
1156
- config?: Record<string, any>;
1157
- credentials?: Record<string, string>;
1158
- useGlobalCredentials?: boolean;
1159
- }
1160
- interface ISystemToolCredentials {
1161
- toolName: string;
1162
- credentials: Record<string, string>;
1163
- createdBy: string;
1164
- createdAt: Date;
1165
- updatedAt: Date;
1231
+ interface LangchainReasoningBlock {
1232
+ type: "reasoning_content";
1233
+ reasoningText?: {
1234
+ text?: string | null;
1235
+ signature?: string | null;
1236
+ } | null;
1237
+ redactedContent?: string | null;
1166
1238
  }
1167
- interface IToolExecutionContext {
1168
- toolName: string;
1169
- config: Record<string, any>;
1170
- credentials: Record<string, string>;
1171
- agentId: string;
1172
- userId: string;
1173
- threadId?: string;
1239
+ declare function isReasoningBlock(block: unknown): block is LangchainReasoningBlock;
1240
+ declare function isSendableReasoningBlock(block: LangchainReasoningBlock): boolean;
1241
+ declare function sanitizeMessageReasoning(message: BaseMessage): BaseMessage;
1242
+ interface SanitizedHistory {
1243
+ messages: BaseMessage[];
1244
+ sanitized: number;
1174
1245
  }
1246
+ declare function sanitizeReasoningForBedrock(messages: BaseMessage[]): SanitizedHistory;
1175
1247
 
1176
- declare function isReasoningModel(modelName: string): boolean;
1177
- declare function hashToolsConfig(toolsConfig: IAgentToolConfig[]): string;
1178
- declare function normalizeToolConfigs(tools?: ToolConfig[]): IAgentToolConfig[] | undefined;
1179
- declare const DEFAULT_ROUTER_URL = "https://router.flutch.ai";
1180
- declare function resolveRouterURL(baseURL?: string): string | undefined;
1181
- declare function generateModelCacheKey(modelId: string, temperature?: number, maxTokens?: number, toolsConfig?: IAgentToolConfig[], baseURL?: string): string;
1182
- declare function buildOpenAIModelConfig(modelName: string, temperature: number, maxTokens: number, apiToken: string): Record<string, any>;
1248
+ declare class FlutchChatBedrockConverse extends ChatBedrockConverse {
1249
+ static lc_name(): string;
1250
+ private sanitize;
1251
+ _generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
1252
+ _streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
1253
+ }
1183
1254
 
1184
1255
  interface VoyageAIRerankConfig {
1185
1256
  apiKey?: string;
@@ -1806,4 +1877,4 @@ declare class MongoTokenStore implements IOAuthTokenStore {
1806
1877
  private ensureIndex;
1807
1878
  }
1808
1879
 
1809
- 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_ROUTER_URL, 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, type FlutchContext, 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 ModelConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreators, ModelInitializer, ModelProvider, ModelType, type MongoDBConfig, MongoTokenStore, type OAuthProviderConfig, type OAuthProviderDef, OAuthTokenManager, type OAuthTokenManagerOptions, type OAuthTokens, type PostgresConfig, 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 ToolConfig, 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, buildOAuthAuthorizationUrl, buildOpenAIModelConfig, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, decryptTokens, dispatchAttachments, encryptTokens, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, flutchFetch, flutchHeaders, flutchMistralHook, generateAttachmentSummary, generateModelCacheKey, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getFlutchContext, getOAuthProvider, getOAuthProviderNames, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, hashToolsConfig, isInternalMode, isReasoningModel, loadOAuthProviders, normalizeToolConfigs, registerFinanceExampleCallback, registerUIEndpointsFromClass, resolveOAuthProviderConfig, resolveRouterURL, sanitizeTraceData, storeAttachmentData, traceApiCall, withFlutchContext, wrapCohereFetcher };
1880
+ 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_ROUTER_URL, 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, FlutchChatBedrockConverse, type FlutchContext, 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 LangchainReasoningBlock, type MappedChannels, McpConverter, type McpRuntimeClient, McpRuntimeHttpClient, type McpTool, McpToolFilter, type Model, type ModelByIdConfig, type ModelByIdWithTypeConfig, type ModelConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreators, ModelInitializer, ModelProvider, ModelType, type MongoDBConfig, MongoTokenStore, type OAuthProviderConfig, type OAuthProviderDef, OAuthTokenManager, type OAuthTokenManagerOptions, type OAuthTokens, PROMPT_CACHE_MIN_VERSIONS, type PostgresConfig, type PromptCacheControl, type PromptCacheTtl, type RateLimitConfig, type RateLimitResult, type ReasoningEffort, type RequestContext, type RerankModelCreator, type ResolvedSamplingParams, type RetrieveQueryOptions, type RetrieverConfig, RetrieverSearchType, RetrieverService, type RouterConfig, SAMPLING_PARAM_FREE_THRESHOLDS, type SamplingParams, type SanitizedHistory, type ServiceDiscoveryProvider, SmartCallbackRouter, StaticDiscovery, type StreamAccumulator, StreamChannel, type StrictGraphRunnableConfig, TelegramPatchHandler, type ToolConfig, 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, buildEffortRequestFields, buildOAuthAuthorizationUrl, buildOpenAIModelConfig, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, decryptTokens, dispatchAttachments, encryptTokens, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, flutchFetch, flutchHeaders, flutchMistralHook, generateAttachmentSummary, generateModelCacheKey, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getFlutchContext, getOAuthProvider, getOAuthProviderNames, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, hashToolsConfig, isInternalMode, isReasoningBlock, isReasoningModel, isSendableReasoningBlock, loadOAuthProviders, modelAcceptsSamplingParams, modelSupportsPromptCache, normalizeToolConfigs, registerFinanceExampleCallback, registerUIEndpointsFromClass, resolveOAuthProviderConfig, resolvePromptCacheControl, resolveRouterURL, resolveSamplingParams, sanitizeMessageReasoning, sanitizeReasoningForBedrock, sanitizeTraceData, storeAttachmentData, toOptionalNumber, traceApiCall, withFlutchContext, wrapCohereFetcher };
package/dist/index.d.ts CHANGED
@@ -8,13 +8,16 @@ import Redis from 'ioredis';
8
8
  import { Registry } from 'prom-client';
9
9
  import { Response, Request as Request$1 } from 'express';
10
10
  import { DiscoveryService, MetadataScanner, ModuleRef } from '@nestjs/core';
11
- import { AIMessageChunk, ToolMessage, AIMessage } from '@langchain/core/messages';
11
+ import { AIMessageChunk, BaseMessage, ToolMessage, AIMessage } from '@langchain/core/messages';
12
12
  import { Runnable, RunnableConfig } from '@langchain/core/runnables';
13
13
  import { DynamicStructuredTool, StructuredTool } from '@langchain/core/tools';
14
14
  import { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models';
15
15
  import { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';
16
16
  import { Embeddings } from '@langchain/core/embeddings';
17
17
  import { BaseLanguageModelInput } from '@langchain/core/language_models/base';
18
+ import { ChatBedrockConverse } from '@langchain/aws';
19
+ import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
20
+ import { ChatResult, ChatGenerationChunk } from '@langchain/core/outputs';
18
21
  import { Document } from '@langchain/core/documents';
19
22
 
20
23
  interface RequestContext {
@@ -1028,6 +1031,76 @@ declare function flutchHeaders(): Record<string, string>;
1028
1031
  declare function flutchMistralHook(req: Request): Request;
1029
1032
  declare function wrapCohereFetcher<T extends (args: any) => any>(inner: T): T;
1030
1033
 
1034
+ interface IAgentToolConfig {
1035
+ toolName: string;
1036
+ enabled: boolean;
1037
+ config?: Record<string, any>;
1038
+ }
1039
+ interface IAgentToolConfiguration {
1040
+ toolName: string;
1041
+ enabled: boolean;
1042
+ config?: Record<string, any>;
1043
+ credentials?: Record<string, string>;
1044
+ useGlobalCredentials?: boolean;
1045
+ }
1046
+ interface ISystemToolCredentials {
1047
+ toolName: string;
1048
+ credentials: Record<string, string>;
1049
+ createdBy: string;
1050
+ createdAt: Date;
1051
+ updatedAt: Date;
1052
+ }
1053
+ interface IToolExecutionContext {
1054
+ toolName: string;
1055
+ config: Record<string, any>;
1056
+ credentials: Record<string, string>;
1057
+ agentId: string;
1058
+ userId: string;
1059
+ threadId?: string;
1060
+ }
1061
+
1062
+ declare function isReasoningModel(modelName: string): boolean;
1063
+ declare function toOptionalNumber(value: unknown): number | undefined;
1064
+ declare const SAMPLING_PARAM_FREE_THRESHOLDS: Record<string, {
1065
+ major: number;
1066
+ minor: number;
1067
+ }>;
1068
+ declare function modelAcceptsSamplingParams(modelIdentifier?: string): boolean;
1069
+ declare const PROMPT_CACHE_MIN_VERSIONS: Record<string, {
1070
+ major: number;
1071
+ minor: number;
1072
+ }>;
1073
+ type PromptCacheTtl = "5m" | "1h";
1074
+ interface PromptCacheControl {
1075
+ type: "ephemeral";
1076
+ ttl?: PromptCacheTtl;
1077
+ }
1078
+ declare function modelSupportsPromptCache(modelIdentifier?: string): boolean;
1079
+ declare function resolvePromptCacheControl(modelIdentifiers: (string | undefined)[], promptCache?: boolean, ttl?: PromptCacheTtl): PromptCacheControl | undefined;
1080
+ type ReasoningEffort = "low" | "medium" | "high" | "xhigh" | "max";
1081
+ declare function buildEffortRequestFields(effort?: ReasoningEffort): {
1082
+ output_config: {
1083
+ effort: ReasoningEffort;
1084
+ };
1085
+ } | undefined;
1086
+ interface SamplingParams {
1087
+ temperature?: number;
1088
+ topP?: number;
1089
+ topK?: number;
1090
+ }
1091
+ interface ResolvedSamplingParams {
1092
+ params: SamplingParams;
1093
+ dropped: string[];
1094
+ accepted: boolean;
1095
+ }
1096
+ declare function resolveSamplingParams(modelIdentifiers: (string | undefined)[], requested: SamplingParams, supportsSamplingParams?: boolean): ResolvedSamplingParams;
1097
+ declare function hashToolsConfig(toolsConfig: IAgentToolConfig[]): string;
1098
+ declare function normalizeToolConfigs(tools?: ToolConfig[]): IAgentToolConfig[] | undefined;
1099
+ declare const DEFAULT_ROUTER_URL = "https://router.flutch.ai";
1100
+ declare function resolveRouterURL(baseURL?: string): string | undefined;
1101
+ declare function generateModelCacheKey(modelId: string, temperature?: number, maxTokens?: number, toolsConfig?: IAgentToolConfig[], baseURL?: string): string;
1102
+ declare function buildOpenAIModelConfig(modelName: string, temperature: number | undefined, maxTokens: number | undefined, apiToken: string): Record<string, any>;
1103
+
1031
1104
  type ToolConfig = string | {
1032
1105
  name: string;
1033
1106
  enabled?: boolean;
@@ -1042,28 +1115,37 @@ interface ModelConfig {
1042
1115
  tools?: ToolConfig[];
1043
1116
  baseURL?: string;
1044
1117
  providerConfig?: Record<string, any>;
1118
+ supportsSamplingParams?: boolean;
1045
1119
  }
1046
1120
  interface ModelByIdConfig {
1047
1121
  modelId: string;
1048
1122
  temperature?: number;
1049
1123
  maxTokens?: number;
1124
+ supportsSamplingParams?: boolean;
1050
1125
  baseURL?: string;
1051
1126
  toolsConfig?: IAgentToolConfig[];
1052
1127
  customTools?: DynamicStructuredTool[];
1053
1128
  mcpServers?: Record<string, any>[];
1054
1129
  mcpContext?: Record<string, any>;
1130
+ promptCache?: boolean;
1131
+ promptCacheTtl?: PromptCacheTtl;
1132
+ effort?: ReasoningEffort;
1055
1133
  }
1056
1134
  type ModelConfigFetcher = (modelId: string) => Promise<ModelConfigWithToken>;
1057
1135
  interface ModelConfigWithToken {
1058
1136
  modelId: string;
1059
1137
  modelName: string;
1060
1138
  provider: ModelProvider;
1061
- defaultTemperature: number;
1062
- defaultMaxTokens: number;
1139
+ defaultTemperature?: number;
1140
+ defaultMaxTokens?: number;
1063
1141
  apiToken?: string;
1064
1142
  requiresApiKey: boolean;
1143
+ supportsSamplingParams?: boolean;
1065
1144
  useBedrock?: boolean;
1066
1145
  bedrockModelId?: string;
1146
+ promptCache?: boolean;
1147
+ promptCacheTtl?: PromptCacheTtl;
1148
+ defaultEffort?: ReasoningEffort;
1067
1149
  baseURL?: string;
1068
1150
  }
1069
1151
  type ApiKeyResolver = (provider: ModelProvider) => string | undefined;
@@ -1094,7 +1176,7 @@ interface IModelInitializer {
1094
1176
  isModelTypeSupported(modelType: ModelType): boolean;
1095
1177
  getSupportedModelTypes(): ModelType[];
1096
1178
  }
1097
- type ChatModelCreator = (config: ModelConfigWithTokenAndType) => BaseChatModel;
1179
+ type ChatModelCreator = (config: ModelConfigWithTokenAndType, promptCacheControl?: PromptCacheControl) => BaseChatModel;
1098
1180
  type RerankModelCreator = (config: ModelConfigWithTokenAndType) => BaseDocumentCompressor;
1099
1181
  type EmbeddingModelCreator = (config: ModelConfigWithTokenAndType) => Embeddings;
1100
1182
  interface ModelCreators {
@@ -1115,6 +1197,7 @@ declare class ModelInitializer implements IModelInitializer {
1115
1197
  constructor(configFetcher?: ModelConfigFetcher, logger?: Logger, apiKeyResolver?: ApiKeyResolver);
1116
1198
  private resolveApiKey;
1117
1199
  private resolveBedrockRegion;
1200
+ private resolveSampling;
1118
1201
  private hashToolsConfig;
1119
1202
  private generateModelCacheKey;
1120
1203
  private readonly chatModelCreators;
@@ -1145,41 +1228,29 @@ declare class ModelInitializer implements IModelInitializer {
1145
1228
  private fetchFromApi;
1146
1229
  }
1147
1230
 
1148
- interface IAgentToolConfig {
1149
- toolName: string;
1150
- enabled: boolean;
1151
- config?: Record<string, any>;
1152
- }
1153
- interface IAgentToolConfiguration {
1154
- toolName: string;
1155
- enabled: boolean;
1156
- config?: Record<string, any>;
1157
- credentials?: Record<string, string>;
1158
- useGlobalCredentials?: boolean;
1159
- }
1160
- interface ISystemToolCredentials {
1161
- toolName: string;
1162
- credentials: Record<string, string>;
1163
- createdBy: string;
1164
- createdAt: Date;
1165
- updatedAt: Date;
1231
+ interface LangchainReasoningBlock {
1232
+ type: "reasoning_content";
1233
+ reasoningText?: {
1234
+ text?: string | null;
1235
+ signature?: string | null;
1236
+ } | null;
1237
+ redactedContent?: string | null;
1166
1238
  }
1167
- interface IToolExecutionContext {
1168
- toolName: string;
1169
- config: Record<string, any>;
1170
- credentials: Record<string, string>;
1171
- agentId: string;
1172
- userId: string;
1173
- threadId?: string;
1239
+ declare function isReasoningBlock(block: unknown): block is LangchainReasoningBlock;
1240
+ declare function isSendableReasoningBlock(block: LangchainReasoningBlock): boolean;
1241
+ declare function sanitizeMessageReasoning(message: BaseMessage): BaseMessage;
1242
+ interface SanitizedHistory {
1243
+ messages: BaseMessage[];
1244
+ sanitized: number;
1174
1245
  }
1246
+ declare function sanitizeReasoningForBedrock(messages: BaseMessage[]): SanitizedHistory;
1175
1247
 
1176
- declare function isReasoningModel(modelName: string): boolean;
1177
- declare function hashToolsConfig(toolsConfig: IAgentToolConfig[]): string;
1178
- declare function normalizeToolConfigs(tools?: ToolConfig[]): IAgentToolConfig[] | undefined;
1179
- declare const DEFAULT_ROUTER_URL = "https://router.flutch.ai";
1180
- declare function resolveRouterURL(baseURL?: string): string | undefined;
1181
- declare function generateModelCacheKey(modelId: string, temperature?: number, maxTokens?: number, toolsConfig?: IAgentToolConfig[], baseURL?: string): string;
1182
- declare function buildOpenAIModelConfig(modelName: string, temperature: number, maxTokens: number, apiToken: string): Record<string, any>;
1248
+ declare class FlutchChatBedrockConverse extends ChatBedrockConverse {
1249
+ static lc_name(): string;
1250
+ private sanitize;
1251
+ _generate(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): Promise<ChatResult>;
1252
+ _streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
1253
+ }
1183
1254
 
1184
1255
  interface VoyageAIRerankConfig {
1185
1256
  apiKey?: string;
@@ -1806,4 +1877,4 @@ declare class MongoTokenStore implements IOAuthTokenStore {
1806
1877
  private ensureIndex;
1807
1878
  }
1808
1879
 
1809
- 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_ROUTER_URL, 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, type FlutchContext, 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 ModelConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreators, ModelInitializer, ModelProvider, ModelType, type MongoDBConfig, MongoTokenStore, type OAuthProviderConfig, type OAuthProviderDef, OAuthTokenManager, type OAuthTokenManagerOptions, type OAuthTokens, type PostgresConfig, 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 ToolConfig, 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, buildOAuthAuthorizationUrl, buildOpenAIModelConfig, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, decryptTokens, dispatchAttachments, encryptTokens, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, flutchFetch, flutchHeaders, flutchMistralHook, generateAttachmentSummary, generateModelCacheKey, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getFlutchContext, getOAuthProvider, getOAuthProviderNames, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, hashToolsConfig, isInternalMode, isReasoningModel, loadOAuthProviders, normalizeToolConfigs, registerFinanceExampleCallback, registerUIEndpointsFromClass, resolveOAuthProviderConfig, resolveRouterURL, sanitizeTraceData, storeAttachmentData, traceApiCall, withFlutchContext, wrapCohereFetcher };
1880
+ 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_ROUTER_URL, 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, FlutchChatBedrockConverse, type FlutchContext, 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 LangchainReasoningBlock, type MappedChannels, McpConverter, type McpRuntimeClient, McpRuntimeHttpClient, type McpTool, McpToolFilter, type Model, type ModelByIdConfig, type ModelByIdWithTypeConfig, type ModelConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreators, ModelInitializer, ModelProvider, ModelType, type MongoDBConfig, MongoTokenStore, type OAuthProviderConfig, type OAuthProviderDef, OAuthTokenManager, type OAuthTokenManagerOptions, type OAuthTokens, PROMPT_CACHE_MIN_VERSIONS, type PostgresConfig, type PromptCacheControl, type PromptCacheTtl, type RateLimitConfig, type RateLimitResult, type ReasoningEffort, type RequestContext, type RerankModelCreator, type ResolvedSamplingParams, type RetrieveQueryOptions, type RetrieverConfig, RetrieverSearchType, RetrieverService, type RouterConfig, SAMPLING_PARAM_FREE_THRESHOLDS, type SamplingParams, type SanitizedHistory, type ServiceDiscoveryProvider, SmartCallbackRouter, StaticDiscovery, type StreamAccumulator, StreamChannel, type StrictGraphRunnableConfig, TelegramPatchHandler, type ToolConfig, 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, buildEffortRequestFields, buildOAuthAuthorizationUrl, buildOpenAIModelConfig, clearAttachmentDataStore, createEndpointDescriptors, createGraphAttachment, createMongoClientAdapter, createStaticMessage, decryptTokens, dispatchAttachments, encryptTokens, executeToolWithAttachments, findCallbackMethod, findEndpointMethod, flutchFetch, flutchHeaders, flutchMistralHook, generateAttachmentSummary, generateModelCacheKey, getAttachmentData, getCallbackMetadata, getEndpointMetadata, getFlutchContext, getOAuthProvider, getOAuthProviderNames, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, hashToolsConfig, isInternalMode, isReasoningBlock, isReasoningModel, isSendableReasoningBlock, loadOAuthProviders, modelAcceptsSamplingParams, modelSupportsPromptCache, normalizeToolConfigs, registerFinanceExampleCallback, registerUIEndpointsFromClass, resolveOAuthProviderConfig, resolvePromptCacheControl, resolveRouterURL, resolveSamplingParams, sanitizeMessageReasoning, sanitizeReasoningForBedrock, sanitizeTraceData, storeAttachmentData, toOptionalNumber, traceApiCall, withFlutchContext, wrapCohereFetcher };