@flutchai/flutch-sdk 0.1.9 → 0.1.11
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 +266 -284
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -30
- package/dist/index.d.ts +39 -30
- package/dist/index.js +267 -284
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -2,21 +2,22 @@ import { JSONSchema7 } from 'json-schema';
|
|
|
2
2
|
import * as _nestjs_common from '@nestjs/common';
|
|
3
3
|
import { OnModuleInit, Logger, Type, CanActivate, ExecutionContext, DynamicModule } from '@nestjs/common';
|
|
4
4
|
import { ConfigService } from '@nestjs/config';
|
|
5
|
-
import { HumanMessage } from '@langchain/core/messages';
|
|
5
|
+
import { HumanMessage, AIMessageChunk } from '@langchain/core/messages';
|
|
6
6
|
import { BaseChannel, CompiledStateGraph, LangGraphRunnableConfig } from '@langchain/langgraph';
|
|
7
7
|
import Redis from 'ioredis';
|
|
8
8
|
import { Registry } from 'prom-client';
|
|
9
9
|
import { Response, Request } from 'express';
|
|
10
10
|
import { DiscoveryService, MetadataScanner, ModuleRef } from '@nestjs/core';
|
|
11
|
-
import { StructuredTool } from '@langchain/core/tools';
|
|
12
|
-
import { RunnableConfig } from '@langchain/core/runnables';
|
|
11
|
+
import { DynamicStructuredTool, StructuredTool } from '@langchain/core/tools';
|
|
12
|
+
import { Runnable, RunnableConfig } from '@langchain/core/runnables';
|
|
13
13
|
import { ChatAnthropic } from '@langchain/anthropic';
|
|
14
14
|
import { ChatCohere } from '@langchain/cohere';
|
|
15
15
|
import { ChatMistralAI } from '@langchain/mistralai';
|
|
16
16
|
import { ChatOpenAI } from '@langchain/openai';
|
|
17
|
-
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
17
|
+
import { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models';
|
|
18
18
|
import { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';
|
|
19
19
|
import { Embeddings } from '@langchain/core/embeddings';
|
|
20
|
+
import { BaseLanguageModelInput } from '@langchain/core/language_models/base';
|
|
20
21
|
import { Document } from '@langchain/core/documents';
|
|
21
22
|
|
|
22
23
|
interface RequestContext {
|
|
@@ -210,7 +211,7 @@ type CitationValue = {
|
|
|
210
211
|
};
|
|
211
212
|
};
|
|
212
213
|
|
|
213
|
-
interface
|
|
214
|
+
interface IContentBlock {
|
|
214
215
|
index: number;
|
|
215
216
|
type: "text" | "tool_use";
|
|
216
217
|
text?: string;
|
|
@@ -220,10 +221,13 @@ interface IReasoningStep {
|
|
|
220
221
|
input?: string;
|
|
221
222
|
output?: string;
|
|
222
223
|
}
|
|
223
|
-
interface
|
|
224
|
-
|
|
224
|
+
interface IContentChain {
|
|
225
|
+
channel: string;
|
|
226
|
+
steps: IContentBlock[];
|
|
225
227
|
isComplete: boolean;
|
|
226
228
|
}
|
|
229
|
+
type IReasoningStep = IContentBlock;
|
|
230
|
+
type IReasoningChain = IContentChain;
|
|
227
231
|
|
|
228
232
|
type TracingLevel = "info" | "warn" | "error" | "debug";
|
|
229
233
|
interface IToolCall {
|
|
@@ -242,11 +246,12 @@ interface ITracingEvent {
|
|
|
242
246
|
}
|
|
243
247
|
|
|
244
248
|
interface IStoredMessageContent {
|
|
245
|
-
|
|
249
|
+
contentChains?: IContentChain[];
|
|
246
250
|
attachments?: IAttachment[];
|
|
247
251
|
metadata?: Record<string, any>;
|
|
248
|
-
|
|
252
|
+
text?: string;
|
|
249
253
|
reasoningChains?: IReasoningChain[];
|
|
254
|
+
tracingEvents?: ITracingEvent[];
|
|
250
255
|
hasReasoningProcess?: boolean;
|
|
251
256
|
currentToolCall?: IToolCall | null;
|
|
252
257
|
}
|
|
@@ -285,8 +290,7 @@ interface IUsageMetrics {
|
|
|
285
290
|
|
|
286
291
|
declare enum StreamChannel {
|
|
287
292
|
TEXT = "text",
|
|
288
|
-
PROCESSING = "processing"
|
|
289
|
-
TOOLS = "tools"
|
|
293
|
+
PROCESSING = "processing"
|
|
290
294
|
}
|
|
291
295
|
|
|
292
296
|
interface IGraphService {
|
|
@@ -1117,21 +1121,24 @@ interface LLMCallRecord {
|
|
|
1117
1121
|
timestamp: number;
|
|
1118
1122
|
nodeName?: string;
|
|
1119
1123
|
}
|
|
1124
|
+
interface ChannelState {
|
|
1125
|
+
contentChain: IContentBlock[];
|
|
1126
|
+
currentBlock: IContentBlock | null;
|
|
1127
|
+
}
|
|
1120
1128
|
interface StreamAccumulator {
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
llmCalls: LLMCallRecord[];
|
|
1129
|
+
channels: Map<StreamChannel, ChannelState>;
|
|
1130
|
+
attachments: IAttachment[];
|
|
1131
|
+
metadata: Record<string, any>;
|
|
1125
1132
|
traceEvents: IGraphTraceEvent[];
|
|
1126
1133
|
traceStartedAt: number | null;
|
|
1127
1134
|
traceCompletedAt: number | null;
|
|
1128
|
-
currentReasoningSteps: IReasoningStep[];
|
|
1129
|
-
currentToolUse: IReasoningStep | null;
|
|
1130
1135
|
}
|
|
1131
1136
|
declare class EventProcessor {
|
|
1132
1137
|
private readonly logger;
|
|
1133
1138
|
createAccumulator(): StreamAccumulator;
|
|
1134
1139
|
private normalizeContentBlocks;
|
|
1140
|
+
private sendDelta;
|
|
1141
|
+
private processContentStream;
|
|
1135
1142
|
private mapReasoningSteps;
|
|
1136
1143
|
processEvent(acc: StreamAccumulator, event: any, onPartial?: (chunk: string) => void): void;
|
|
1137
1144
|
getResult(acc: StreamAccumulator): {
|
|
@@ -1142,7 +1149,6 @@ declare class EventProcessor {
|
|
|
1142
1149
|
completedAt: number;
|
|
1143
1150
|
durationMs: number;
|
|
1144
1151
|
totalEvents: number;
|
|
1145
|
-
totalModelCalls: number;
|
|
1146
1152
|
} | null;
|
|
1147
1153
|
};
|
|
1148
1154
|
private captureTraceEvent;
|
|
@@ -1217,6 +1223,8 @@ interface ModelByIdConfig {
|
|
|
1217
1223
|
modelId: string;
|
|
1218
1224
|
temperature?: number;
|
|
1219
1225
|
maxTokens?: number;
|
|
1226
|
+
toolsConfig?: IAgentToolConfig[];
|
|
1227
|
+
customTools?: DynamicStructuredTool[];
|
|
1220
1228
|
}
|
|
1221
1229
|
type ModelConfigFetcher = (modelId: string) => Promise<ModelConfigWithToken>;
|
|
1222
1230
|
interface ModelConfigWithToken {
|
|
@@ -1234,7 +1242,9 @@ type ModelCreator = (config: ModelConfig & {
|
|
|
1234
1242
|
customApiToken?: string;
|
|
1235
1243
|
}) => LLModel;
|
|
1236
1244
|
|
|
1237
|
-
type
|
|
1245
|
+
type ChatModelWithTools = Runnable<BaseLanguageModelInput, AIMessageChunk, BaseChatModelCallOptions>;
|
|
1246
|
+
type ChatModelOrRunnable = BaseChatModel | ChatModelWithTools;
|
|
1247
|
+
type Model = BaseChatModel | ChatModelWithTools | BaseDocumentCompressor | Embeddings;
|
|
1238
1248
|
interface ModelByIdWithTypeConfig extends ModelByIdConfig {
|
|
1239
1249
|
modelType: ModelType;
|
|
1240
1250
|
}
|
|
@@ -1245,11 +1255,11 @@ interface ModelConfigWithTokenAndType extends ModelConfigWithToken {
|
|
|
1245
1255
|
supportedFormats?: string[];
|
|
1246
1256
|
}
|
|
1247
1257
|
interface IModelInitializer {
|
|
1248
|
-
createChatModelById(modelId: string): Promise<
|
|
1258
|
+
createChatModelById(modelId: string): Promise<ChatModelOrRunnable>;
|
|
1249
1259
|
createRerankModelById(modelId: string): Promise<BaseDocumentCompressor>;
|
|
1250
1260
|
createEmbeddingModelById(modelId: string): Promise<Embeddings>;
|
|
1251
1261
|
createModelById(modelId: string, expectedType?: ModelType): Promise<Model>;
|
|
1252
|
-
initializeChatModel(config: ModelByIdConfig): Promise<
|
|
1262
|
+
initializeChatModel(config: ModelByIdConfig): Promise<ChatModelOrRunnable>;
|
|
1253
1263
|
initializeRerankModel(config: ModelByIdConfig): Promise<BaseDocumentCompressor>;
|
|
1254
1264
|
initializeEmbeddingModel(config: ModelByIdConfig): Promise<Embeddings>;
|
|
1255
1265
|
initializeModelByType(config: ModelByIdWithTypeConfig): Promise<Model>;
|
|
@@ -1274,15 +1284,17 @@ declare class ModelInitializer implements IModelInitializer {
|
|
|
1274
1284
|
private modelConfigCache;
|
|
1275
1285
|
private modelInstanceCache;
|
|
1276
1286
|
constructor(configFetcher?: ModelConfigFetcher, logger?: Logger);
|
|
1287
|
+
private hashToolsConfig;
|
|
1277
1288
|
private generateModelCacheKey;
|
|
1278
1289
|
private requiresMaxCompletionTokens;
|
|
1279
1290
|
private readonly chatModelCreators;
|
|
1280
1291
|
private readonly rerankModelCreators;
|
|
1281
1292
|
private readonly embeddingModelCreators;
|
|
1282
|
-
initializeChatModel(config: ModelByIdConfig): Promise<BaseChatModel
|
|
1293
|
+
initializeChatModel(config: ModelByIdConfig): Promise<BaseChatModel | Runnable<BaseLanguageModelInput, AIMessageChunk, BaseChatModelCallOptions>>;
|
|
1294
|
+
private bindToolsToModel;
|
|
1283
1295
|
initializeRerankModel(config: ModelByIdConfig): Promise<BaseDocumentCompressor>;
|
|
1284
1296
|
initializeEmbeddingModel(config: ModelByIdConfig): Promise<Embeddings>;
|
|
1285
|
-
createChatModelById(modelId: string): Promise<
|
|
1297
|
+
createChatModelById(modelId: string): Promise<ChatModelOrRunnable>;
|
|
1286
1298
|
createRerankModelById(modelId: string): Promise<BaseDocumentCompressor>;
|
|
1287
1299
|
createEmbeddingModelById(modelId: string): Promise<Embeddings>;
|
|
1288
1300
|
createModelById(modelId: string, expectedType?: ModelType): Promise<Model>;
|
|
@@ -1300,11 +1312,6 @@ declare class ModelInitializer implements IModelInitializer {
|
|
|
1300
1312
|
};
|
|
1301
1313
|
private fetchFromApi;
|
|
1302
1314
|
}
|
|
1303
|
-
declare function prepareModelWithTools(model: BaseChatModel, tools: StructuredTool[], baseConfig?: any): {
|
|
1304
|
-
modelWithTools: any;
|
|
1305
|
-
finalConfig: any;
|
|
1306
|
-
toolsMethod: "bindTools" | "manual" | "none";
|
|
1307
|
-
};
|
|
1308
1315
|
|
|
1309
1316
|
interface VoyageAIRerankConfig {
|
|
1310
1317
|
apiKey?: string;
|
|
@@ -1330,6 +1337,7 @@ interface IToolCatalog extends IBaseEntity {
|
|
|
1330
1337
|
isActive: boolean;
|
|
1331
1338
|
toolVersion?: string;
|
|
1332
1339
|
configSchema?: IToolConfigOption[];
|
|
1340
|
+
supportsDynamicSchema?: boolean;
|
|
1333
1341
|
}
|
|
1334
1342
|
interface IToolConfigOption {
|
|
1335
1343
|
key: string;
|
|
@@ -1352,6 +1360,7 @@ interface IToolConfigOption {
|
|
|
1352
1360
|
provider?: ModelProvider;
|
|
1353
1361
|
isActive?: boolean;
|
|
1354
1362
|
};
|
|
1363
|
+
includeInSchema?: boolean;
|
|
1355
1364
|
}
|
|
1356
1365
|
|
|
1357
1366
|
interface IAgentToolConfig {
|
|
@@ -1418,7 +1427,7 @@ declare class McpToolFilter {
|
|
|
1418
1427
|
private readonly logger;
|
|
1419
1428
|
private readonly mcpConverter;
|
|
1420
1429
|
constructor(mcpRuntimeUrl?: string);
|
|
1421
|
-
getFilteredTools(
|
|
1430
|
+
getFilteredTools(toolsConfig?: IAgentToolConfig[]): Promise<StructuredTool[]>;
|
|
1422
1431
|
getAllTools(): Promise<StructuredTool[]>;
|
|
1423
1432
|
isHealthy(): Promise<boolean>;
|
|
1424
1433
|
getAvailableToolNames(): Promise<string[]>;
|
|
@@ -1556,4 +1565,4 @@ declare class StaticDiscovery implements ServiceDiscoveryProvider {
|
|
|
1556
1565
|
}>>;
|
|
1557
1566
|
}
|
|
1558
1567
|
|
|
1559
|
-
export { type ACLValidationResult, AbstractGraphBuilder, type ApiCallTracerOptions, AttachmentType, type AuditEntry, 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 ChartType, ChatFeature, type ChatModelCreator, type CitationValue, type CompiledGraphFor, type ConcreteModels, type CustomDocument, DEFAULT_TRACER_OPTIONS, type DataEnvelope, ENDPOINT_METADATA_KEY, type EmbeddingModelCreator, Endpoint, type EndpointDescriptor, type EndpointHandler, type EndpointMetadata, type EndpointOptions, EndpointRegistry, EventProcessor, type ExtendedCallbackContext, type ExtendedCallbackHandler, FileBasedDiscovery, GraphController, GraphEngineFactory, GraphEngineType, GraphManifestSchema, GraphManifestValidator, GraphServiceTokens, GraphTypeUtils, type IAgentToolConfig, type IAgentToolConfiguration, type IAttachment, type IBaseEntity, type IChartDataPoint, type IChartDataset, type IChartValue, type IDeletionInfo, type IGenericGraphType, type IGraphBuilder, type IGraphCompiler, type IGraphConfigurable, type IGraphEngine, 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 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 ModelConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreator, type ModelCreators, ModelInitializer, ModelProvider, ModelType, 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, bootstrap, createEndpointDescriptors, findCallbackMethod, findEndpointMethod, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints,
|
|
1568
|
+
export { type ACLValidationResult, AbstractGraphBuilder, type ApiCallTracerOptions, AttachmentType, type AuditEntry, 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 ConcreteModels, type CustomDocument, DEFAULT_TRACER_OPTIONS, type DataEnvelope, ENDPOINT_METADATA_KEY, type EmbeddingModelCreator, Endpoint, type EndpointDescriptor, type EndpointHandler, type EndpointMetadata, type EndpointOptions, EndpointRegistry, EventProcessor, type ExtendedCallbackContext, type ExtendedCallbackHandler, 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 IGraphBuilder, type IGraphCompiler, type IGraphConfigurable, type IGraphEngine, 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 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 ModelConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreator, type ModelCreators, ModelInitializer, ModelProvider, ModelType, 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, bootstrap, createEndpointDescriptors, findCallbackMethod, findEndpointMethod, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, traceApiCall };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,21 +2,22 @@ import { JSONSchema7 } from 'json-schema';
|
|
|
2
2
|
import * as _nestjs_common from '@nestjs/common';
|
|
3
3
|
import { OnModuleInit, Logger, Type, CanActivate, ExecutionContext, DynamicModule } from '@nestjs/common';
|
|
4
4
|
import { ConfigService } from '@nestjs/config';
|
|
5
|
-
import { HumanMessage } from '@langchain/core/messages';
|
|
5
|
+
import { HumanMessage, AIMessageChunk } from '@langchain/core/messages';
|
|
6
6
|
import { BaseChannel, CompiledStateGraph, LangGraphRunnableConfig } from '@langchain/langgraph';
|
|
7
7
|
import Redis from 'ioredis';
|
|
8
8
|
import { Registry } from 'prom-client';
|
|
9
9
|
import { Response, Request } from 'express';
|
|
10
10
|
import { DiscoveryService, MetadataScanner, ModuleRef } from '@nestjs/core';
|
|
11
|
-
import { StructuredTool } from '@langchain/core/tools';
|
|
12
|
-
import { RunnableConfig } from '@langchain/core/runnables';
|
|
11
|
+
import { DynamicStructuredTool, StructuredTool } from '@langchain/core/tools';
|
|
12
|
+
import { Runnable, RunnableConfig } from '@langchain/core/runnables';
|
|
13
13
|
import { ChatAnthropic } from '@langchain/anthropic';
|
|
14
14
|
import { ChatCohere } from '@langchain/cohere';
|
|
15
15
|
import { ChatMistralAI } from '@langchain/mistralai';
|
|
16
16
|
import { ChatOpenAI } from '@langchain/openai';
|
|
17
|
-
import { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
17
|
+
import { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models';
|
|
18
18
|
import { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';
|
|
19
19
|
import { Embeddings } from '@langchain/core/embeddings';
|
|
20
|
+
import { BaseLanguageModelInput } from '@langchain/core/language_models/base';
|
|
20
21
|
import { Document } from '@langchain/core/documents';
|
|
21
22
|
|
|
22
23
|
interface RequestContext {
|
|
@@ -210,7 +211,7 @@ type CitationValue = {
|
|
|
210
211
|
};
|
|
211
212
|
};
|
|
212
213
|
|
|
213
|
-
interface
|
|
214
|
+
interface IContentBlock {
|
|
214
215
|
index: number;
|
|
215
216
|
type: "text" | "tool_use";
|
|
216
217
|
text?: string;
|
|
@@ -220,10 +221,13 @@ interface IReasoningStep {
|
|
|
220
221
|
input?: string;
|
|
221
222
|
output?: string;
|
|
222
223
|
}
|
|
223
|
-
interface
|
|
224
|
-
|
|
224
|
+
interface IContentChain {
|
|
225
|
+
channel: string;
|
|
226
|
+
steps: IContentBlock[];
|
|
225
227
|
isComplete: boolean;
|
|
226
228
|
}
|
|
229
|
+
type IReasoningStep = IContentBlock;
|
|
230
|
+
type IReasoningChain = IContentChain;
|
|
227
231
|
|
|
228
232
|
type TracingLevel = "info" | "warn" | "error" | "debug";
|
|
229
233
|
interface IToolCall {
|
|
@@ -242,11 +246,12 @@ interface ITracingEvent {
|
|
|
242
246
|
}
|
|
243
247
|
|
|
244
248
|
interface IStoredMessageContent {
|
|
245
|
-
|
|
249
|
+
contentChains?: IContentChain[];
|
|
246
250
|
attachments?: IAttachment[];
|
|
247
251
|
metadata?: Record<string, any>;
|
|
248
|
-
|
|
252
|
+
text?: string;
|
|
249
253
|
reasoningChains?: IReasoningChain[];
|
|
254
|
+
tracingEvents?: ITracingEvent[];
|
|
250
255
|
hasReasoningProcess?: boolean;
|
|
251
256
|
currentToolCall?: IToolCall | null;
|
|
252
257
|
}
|
|
@@ -285,8 +290,7 @@ interface IUsageMetrics {
|
|
|
285
290
|
|
|
286
291
|
declare enum StreamChannel {
|
|
287
292
|
TEXT = "text",
|
|
288
|
-
PROCESSING = "processing"
|
|
289
|
-
TOOLS = "tools"
|
|
293
|
+
PROCESSING = "processing"
|
|
290
294
|
}
|
|
291
295
|
|
|
292
296
|
interface IGraphService {
|
|
@@ -1117,21 +1121,24 @@ interface LLMCallRecord {
|
|
|
1117
1121
|
timestamp: number;
|
|
1118
1122
|
nodeName?: string;
|
|
1119
1123
|
}
|
|
1124
|
+
interface ChannelState {
|
|
1125
|
+
contentChain: IContentBlock[];
|
|
1126
|
+
currentBlock: IContentBlock | null;
|
|
1127
|
+
}
|
|
1120
1128
|
interface StreamAccumulator {
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
llmCalls: LLMCallRecord[];
|
|
1129
|
+
channels: Map<StreamChannel, ChannelState>;
|
|
1130
|
+
attachments: IAttachment[];
|
|
1131
|
+
metadata: Record<string, any>;
|
|
1125
1132
|
traceEvents: IGraphTraceEvent[];
|
|
1126
1133
|
traceStartedAt: number | null;
|
|
1127
1134
|
traceCompletedAt: number | null;
|
|
1128
|
-
currentReasoningSteps: IReasoningStep[];
|
|
1129
|
-
currentToolUse: IReasoningStep | null;
|
|
1130
1135
|
}
|
|
1131
1136
|
declare class EventProcessor {
|
|
1132
1137
|
private readonly logger;
|
|
1133
1138
|
createAccumulator(): StreamAccumulator;
|
|
1134
1139
|
private normalizeContentBlocks;
|
|
1140
|
+
private sendDelta;
|
|
1141
|
+
private processContentStream;
|
|
1135
1142
|
private mapReasoningSteps;
|
|
1136
1143
|
processEvent(acc: StreamAccumulator, event: any, onPartial?: (chunk: string) => void): void;
|
|
1137
1144
|
getResult(acc: StreamAccumulator): {
|
|
@@ -1142,7 +1149,6 @@ declare class EventProcessor {
|
|
|
1142
1149
|
completedAt: number;
|
|
1143
1150
|
durationMs: number;
|
|
1144
1151
|
totalEvents: number;
|
|
1145
|
-
totalModelCalls: number;
|
|
1146
1152
|
} | null;
|
|
1147
1153
|
};
|
|
1148
1154
|
private captureTraceEvent;
|
|
@@ -1217,6 +1223,8 @@ interface ModelByIdConfig {
|
|
|
1217
1223
|
modelId: string;
|
|
1218
1224
|
temperature?: number;
|
|
1219
1225
|
maxTokens?: number;
|
|
1226
|
+
toolsConfig?: IAgentToolConfig[];
|
|
1227
|
+
customTools?: DynamicStructuredTool[];
|
|
1220
1228
|
}
|
|
1221
1229
|
type ModelConfigFetcher = (modelId: string) => Promise<ModelConfigWithToken>;
|
|
1222
1230
|
interface ModelConfigWithToken {
|
|
@@ -1234,7 +1242,9 @@ type ModelCreator = (config: ModelConfig & {
|
|
|
1234
1242
|
customApiToken?: string;
|
|
1235
1243
|
}) => LLModel;
|
|
1236
1244
|
|
|
1237
|
-
type
|
|
1245
|
+
type ChatModelWithTools = Runnable<BaseLanguageModelInput, AIMessageChunk, BaseChatModelCallOptions>;
|
|
1246
|
+
type ChatModelOrRunnable = BaseChatModel | ChatModelWithTools;
|
|
1247
|
+
type Model = BaseChatModel | ChatModelWithTools | BaseDocumentCompressor | Embeddings;
|
|
1238
1248
|
interface ModelByIdWithTypeConfig extends ModelByIdConfig {
|
|
1239
1249
|
modelType: ModelType;
|
|
1240
1250
|
}
|
|
@@ -1245,11 +1255,11 @@ interface ModelConfigWithTokenAndType extends ModelConfigWithToken {
|
|
|
1245
1255
|
supportedFormats?: string[];
|
|
1246
1256
|
}
|
|
1247
1257
|
interface IModelInitializer {
|
|
1248
|
-
createChatModelById(modelId: string): Promise<
|
|
1258
|
+
createChatModelById(modelId: string): Promise<ChatModelOrRunnable>;
|
|
1249
1259
|
createRerankModelById(modelId: string): Promise<BaseDocumentCompressor>;
|
|
1250
1260
|
createEmbeddingModelById(modelId: string): Promise<Embeddings>;
|
|
1251
1261
|
createModelById(modelId: string, expectedType?: ModelType): Promise<Model>;
|
|
1252
|
-
initializeChatModel(config: ModelByIdConfig): Promise<
|
|
1262
|
+
initializeChatModel(config: ModelByIdConfig): Promise<ChatModelOrRunnable>;
|
|
1253
1263
|
initializeRerankModel(config: ModelByIdConfig): Promise<BaseDocumentCompressor>;
|
|
1254
1264
|
initializeEmbeddingModel(config: ModelByIdConfig): Promise<Embeddings>;
|
|
1255
1265
|
initializeModelByType(config: ModelByIdWithTypeConfig): Promise<Model>;
|
|
@@ -1274,15 +1284,17 @@ declare class ModelInitializer implements IModelInitializer {
|
|
|
1274
1284
|
private modelConfigCache;
|
|
1275
1285
|
private modelInstanceCache;
|
|
1276
1286
|
constructor(configFetcher?: ModelConfigFetcher, logger?: Logger);
|
|
1287
|
+
private hashToolsConfig;
|
|
1277
1288
|
private generateModelCacheKey;
|
|
1278
1289
|
private requiresMaxCompletionTokens;
|
|
1279
1290
|
private readonly chatModelCreators;
|
|
1280
1291
|
private readonly rerankModelCreators;
|
|
1281
1292
|
private readonly embeddingModelCreators;
|
|
1282
|
-
initializeChatModel(config: ModelByIdConfig): Promise<BaseChatModel
|
|
1293
|
+
initializeChatModel(config: ModelByIdConfig): Promise<BaseChatModel | Runnable<BaseLanguageModelInput, AIMessageChunk, BaseChatModelCallOptions>>;
|
|
1294
|
+
private bindToolsToModel;
|
|
1283
1295
|
initializeRerankModel(config: ModelByIdConfig): Promise<BaseDocumentCompressor>;
|
|
1284
1296
|
initializeEmbeddingModel(config: ModelByIdConfig): Promise<Embeddings>;
|
|
1285
|
-
createChatModelById(modelId: string): Promise<
|
|
1297
|
+
createChatModelById(modelId: string): Promise<ChatModelOrRunnable>;
|
|
1286
1298
|
createRerankModelById(modelId: string): Promise<BaseDocumentCompressor>;
|
|
1287
1299
|
createEmbeddingModelById(modelId: string): Promise<Embeddings>;
|
|
1288
1300
|
createModelById(modelId: string, expectedType?: ModelType): Promise<Model>;
|
|
@@ -1300,11 +1312,6 @@ declare class ModelInitializer implements IModelInitializer {
|
|
|
1300
1312
|
};
|
|
1301
1313
|
private fetchFromApi;
|
|
1302
1314
|
}
|
|
1303
|
-
declare function prepareModelWithTools(model: BaseChatModel, tools: StructuredTool[], baseConfig?: any): {
|
|
1304
|
-
modelWithTools: any;
|
|
1305
|
-
finalConfig: any;
|
|
1306
|
-
toolsMethod: "bindTools" | "manual" | "none";
|
|
1307
|
-
};
|
|
1308
1315
|
|
|
1309
1316
|
interface VoyageAIRerankConfig {
|
|
1310
1317
|
apiKey?: string;
|
|
@@ -1330,6 +1337,7 @@ interface IToolCatalog extends IBaseEntity {
|
|
|
1330
1337
|
isActive: boolean;
|
|
1331
1338
|
toolVersion?: string;
|
|
1332
1339
|
configSchema?: IToolConfigOption[];
|
|
1340
|
+
supportsDynamicSchema?: boolean;
|
|
1333
1341
|
}
|
|
1334
1342
|
interface IToolConfigOption {
|
|
1335
1343
|
key: string;
|
|
@@ -1352,6 +1360,7 @@ interface IToolConfigOption {
|
|
|
1352
1360
|
provider?: ModelProvider;
|
|
1353
1361
|
isActive?: boolean;
|
|
1354
1362
|
};
|
|
1363
|
+
includeInSchema?: boolean;
|
|
1355
1364
|
}
|
|
1356
1365
|
|
|
1357
1366
|
interface IAgentToolConfig {
|
|
@@ -1418,7 +1427,7 @@ declare class McpToolFilter {
|
|
|
1418
1427
|
private readonly logger;
|
|
1419
1428
|
private readonly mcpConverter;
|
|
1420
1429
|
constructor(mcpRuntimeUrl?: string);
|
|
1421
|
-
getFilteredTools(
|
|
1430
|
+
getFilteredTools(toolsConfig?: IAgentToolConfig[]): Promise<StructuredTool[]>;
|
|
1422
1431
|
getAllTools(): Promise<StructuredTool[]>;
|
|
1423
1432
|
isHealthy(): Promise<boolean>;
|
|
1424
1433
|
getAvailableToolNames(): Promise<string[]>;
|
|
@@ -1556,4 +1565,4 @@ declare class StaticDiscovery implements ServiceDiscoveryProvider {
|
|
|
1556
1565
|
}>>;
|
|
1557
1566
|
}
|
|
1558
1567
|
|
|
1559
|
-
export { type ACLValidationResult, AbstractGraphBuilder, type ApiCallTracerOptions, AttachmentType, type AuditEntry, 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 ChartType, ChatFeature, type ChatModelCreator, type CitationValue, type CompiledGraphFor, type ConcreteModels, type CustomDocument, DEFAULT_TRACER_OPTIONS, type DataEnvelope, ENDPOINT_METADATA_KEY, type EmbeddingModelCreator, Endpoint, type EndpointDescriptor, type EndpointHandler, type EndpointMetadata, type EndpointOptions, EndpointRegistry, EventProcessor, type ExtendedCallbackContext, type ExtendedCallbackHandler, FileBasedDiscovery, GraphController, GraphEngineFactory, GraphEngineType, GraphManifestSchema, GraphManifestValidator, GraphServiceTokens, GraphTypeUtils, type IAgentToolConfig, type IAgentToolConfiguration, type IAttachment, type IBaseEntity, type IChartDataPoint, type IChartDataset, type IChartValue, type IDeletionInfo, type IGenericGraphType, type IGraphBuilder, type IGraphCompiler, type IGraphConfigurable, type IGraphEngine, 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 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 ModelConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreator, type ModelCreators, ModelInitializer, ModelProvider, ModelType, 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, bootstrap, createEndpointDescriptors, findCallbackMethod, findEndpointMethod, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints,
|
|
1568
|
+
export { type ACLValidationResult, AbstractGraphBuilder, type ApiCallTracerOptions, AttachmentType, type AuditEntry, 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 ConcreteModels, type CustomDocument, DEFAULT_TRACER_OPTIONS, type DataEnvelope, ENDPOINT_METADATA_KEY, type EmbeddingModelCreator, Endpoint, type EndpointDescriptor, type EndpointHandler, type EndpointMetadata, type EndpointOptions, EndpointRegistry, EventProcessor, type ExtendedCallbackContext, type ExtendedCallbackHandler, 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 IGraphBuilder, type IGraphCompiler, type IGraphConfigurable, type IGraphEngine, 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 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 ModelConfig, type ModelConfigFetcher, type ModelConfigWithToken, type ModelConfigWithTokenAndType, type ModelCreator, type ModelCreators, ModelInitializer, ModelProvider, ModelType, 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, bootstrap, createEndpointDescriptors, findCallbackMethod, findEndpointMethod, getCallbackMetadata, getEndpointMetadata, getUIEndpointClassMetadata, getUIEndpointMethodsMetadata, hasCallbacks, hasUIEndpoints, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, traceApiCall };
|