@flutchai/flutch-sdk 0.1.9 → 0.1.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
@@ -210,7 +210,7 @@ type CitationValue = {
210
210
  };
211
211
  };
212
212
 
213
- interface IReasoningStep {
213
+ interface IContentBlock {
214
214
  index: number;
215
215
  type: "text" | "tool_use";
216
216
  text?: string;
@@ -220,10 +220,13 @@ interface IReasoningStep {
220
220
  input?: string;
221
221
  output?: string;
222
222
  }
223
- interface IReasoningChain {
224
- steps: IReasoningStep[];
223
+ interface IContentChain {
224
+ channel: string;
225
+ steps: IContentBlock[];
225
226
  isComplete: boolean;
226
227
  }
228
+ type IReasoningStep = IContentBlock;
229
+ type IReasoningChain = IContentChain;
227
230
 
228
231
  type TracingLevel = "info" | "warn" | "error" | "debug";
229
232
  interface IToolCall {
@@ -242,11 +245,12 @@ interface ITracingEvent {
242
245
  }
243
246
 
244
247
  interface IStoredMessageContent {
245
- text?: string;
248
+ contentChains?: IContentChain[];
246
249
  attachments?: IAttachment[];
247
250
  metadata?: Record<string, any>;
248
- tracingEvents?: ITracingEvent[];
251
+ text?: string;
249
252
  reasoningChains?: IReasoningChain[];
253
+ tracingEvents?: ITracingEvent[];
250
254
  hasReasoningProcess?: boolean;
251
255
  currentToolCall?: IToolCall | null;
252
256
  }
@@ -285,8 +289,7 @@ interface IUsageMetrics {
285
289
 
286
290
  declare enum StreamChannel {
287
291
  TEXT = "text",
288
- PROCESSING = "processing",
289
- TOOLS = "tools"
292
+ PROCESSING = "processing"
290
293
  }
291
294
 
292
295
  interface IGraphService {
@@ -1117,21 +1120,24 @@ interface LLMCallRecord {
1117
1120
  timestamp: number;
1118
1121
  nodeName?: string;
1119
1122
  }
1123
+ interface ChannelState {
1124
+ contentChain: IContentBlock[];
1125
+ currentBlock: IContentBlock | null;
1126
+ }
1120
1127
  interface StreamAccumulator {
1121
- streamedText: string;
1122
- reasoningChains: IReasoningChain[];
1123
- generation: IStoredMessageContent | null;
1124
- llmCalls: LLMCallRecord[];
1128
+ channels: Map<StreamChannel, ChannelState>;
1129
+ attachments: IAttachment[];
1130
+ metadata: Record<string, any>;
1125
1131
  traceEvents: IGraphTraceEvent[];
1126
1132
  traceStartedAt: number | null;
1127
1133
  traceCompletedAt: number | null;
1128
- currentReasoningSteps: IReasoningStep[];
1129
- currentToolUse: IReasoningStep | null;
1130
1134
  }
1131
1135
  declare class EventProcessor {
1132
1136
  private readonly logger;
1133
1137
  createAccumulator(): StreamAccumulator;
1134
1138
  private normalizeContentBlocks;
1139
+ private sendDelta;
1140
+ private processContentStream;
1135
1141
  private mapReasoningSteps;
1136
1142
  processEvent(acc: StreamAccumulator, event: any, onPartial?: (chunk: string) => void): void;
1137
1143
  getResult(acc: StreamAccumulator): {
@@ -1142,7 +1148,6 @@ declare class EventProcessor {
1142
1148
  completedAt: number;
1143
1149
  durationMs: number;
1144
1150
  totalEvents: number;
1145
- totalModelCalls: number;
1146
1151
  } | null;
1147
1152
  };
1148
1153
  private captureTraceEvent;
@@ -1556,4 +1561,4 @@ declare class StaticDiscovery implements ServiceDiscoveryProvider {
1556
1561
  }>>;
1557
1562
  }
1558
1563
 
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, prepareModelWithTools, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, traceApiCall };
1564
+ 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 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, prepareModelWithTools, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, traceApiCall };
package/dist/index.d.ts CHANGED
@@ -210,7 +210,7 @@ type CitationValue = {
210
210
  };
211
211
  };
212
212
 
213
- interface IReasoningStep {
213
+ interface IContentBlock {
214
214
  index: number;
215
215
  type: "text" | "tool_use";
216
216
  text?: string;
@@ -220,10 +220,13 @@ interface IReasoningStep {
220
220
  input?: string;
221
221
  output?: string;
222
222
  }
223
- interface IReasoningChain {
224
- steps: IReasoningStep[];
223
+ interface IContentChain {
224
+ channel: string;
225
+ steps: IContentBlock[];
225
226
  isComplete: boolean;
226
227
  }
228
+ type IReasoningStep = IContentBlock;
229
+ type IReasoningChain = IContentChain;
227
230
 
228
231
  type TracingLevel = "info" | "warn" | "error" | "debug";
229
232
  interface IToolCall {
@@ -242,11 +245,12 @@ interface ITracingEvent {
242
245
  }
243
246
 
244
247
  interface IStoredMessageContent {
245
- text?: string;
248
+ contentChains?: IContentChain[];
246
249
  attachments?: IAttachment[];
247
250
  metadata?: Record<string, any>;
248
- tracingEvents?: ITracingEvent[];
251
+ text?: string;
249
252
  reasoningChains?: IReasoningChain[];
253
+ tracingEvents?: ITracingEvent[];
250
254
  hasReasoningProcess?: boolean;
251
255
  currentToolCall?: IToolCall | null;
252
256
  }
@@ -285,8 +289,7 @@ interface IUsageMetrics {
285
289
 
286
290
  declare enum StreamChannel {
287
291
  TEXT = "text",
288
- PROCESSING = "processing",
289
- TOOLS = "tools"
292
+ PROCESSING = "processing"
290
293
  }
291
294
 
292
295
  interface IGraphService {
@@ -1117,21 +1120,24 @@ interface LLMCallRecord {
1117
1120
  timestamp: number;
1118
1121
  nodeName?: string;
1119
1122
  }
1123
+ interface ChannelState {
1124
+ contentChain: IContentBlock[];
1125
+ currentBlock: IContentBlock | null;
1126
+ }
1120
1127
  interface StreamAccumulator {
1121
- streamedText: string;
1122
- reasoningChains: IReasoningChain[];
1123
- generation: IStoredMessageContent | null;
1124
- llmCalls: LLMCallRecord[];
1128
+ channels: Map<StreamChannel, ChannelState>;
1129
+ attachments: IAttachment[];
1130
+ metadata: Record<string, any>;
1125
1131
  traceEvents: IGraphTraceEvent[];
1126
1132
  traceStartedAt: number | null;
1127
1133
  traceCompletedAt: number | null;
1128
- currentReasoningSteps: IReasoningStep[];
1129
- currentToolUse: IReasoningStep | null;
1130
1134
  }
1131
1135
  declare class EventProcessor {
1132
1136
  private readonly logger;
1133
1137
  createAccumulator(): StreamAccumulator;
1134
1138
  private normalizeContentBlocks;
1139
+ private sendDelta;
1140
+ private processContentStream;
1135
1141
  private mapReasoningSteps;
1136
1142
  processEvent(acc: StreamAccumulator, event: any, onPartial?: (chunk: string) => void): void;
1137
1143
  getResult(acc: StreamAccumulator): {
@@ -1142,7 +1148,6 @@ declare class EventProcessor {
1142
1148
  completedAt: number;
1143
1149
  durationMs: number;
1144
1150
  totalEvents: number;
1145
- totalModelCalls: number;
1146
1151
  } | null;
1147
1152
  };
1148
1153
  private captureTraceEvent;
@@ -1556,4 +1561,4 @@ declare class StaticDiscovery implements ServiceDiscoveryProvider {
1556
1561
  }>>;
1557
1562
  }
1558
1563
 
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, prepareModelWithTools, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, traceApiCall };
1564
+ 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 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, prepareModelWithTools, registerFinanceExampleCallback, registerUIEndpointsFromClass, sanitizeTraceData, traceApiCall };
package/dist/index.js CHANGED
@@ -3871,7 +3871,6 @@ var AttachmentType = /* @__PURE__ */ ((AttachmentType2) => {
3871
3871
  var StreamChannel = /* @__PURE__ */ ((StreamChannel2) => {
3872
3872
  StreamChannel2["TEXT"] = "text";
3873
3873
  StreamChannel2["PROCESSING"] = "processing";
3874
- StreamChannel2["TOOLS"] = "tools";
3875
3874
  return StreamChannel2;
3876
3875
  })(StreamChannel || {});
3877
3876
 
@@ -4414,15 +4413,15 @@ var EventProcessor = class {
4414
4413
  */
4415
4414
  createAccumulator() {
4416
4415
  return {
4417
- streamedText: "",
4418
- reasoningChains: [],
4419
- generation: null,
4420
- llmCalls: [],
4416
+ channels: /* @__PURE__ */ new Map([
4417
+ ["text" /* TEXT */, { contentChain: [], currentBlock: null }],
4418
+ ["processing" /* PROCESSING */, { contentChain: [], currentBlock: null }]
4419
+ ]),
4420
+ attachments: [],
4421
+ metadata: {},
4421
4422
  traceEvents: [],
4422
4423
  traceStartedAt: null,
4423
- traceCompletedAt: null,
4424
- currentReasoningSteps: [],
4425
- currentToolUse: null
4424
+ traceCompletedAt: null
4426
4425
  };
4427
4426
  }
4428
4427
  /**
@@ -4450,10 +4449,88 @@ var EventProcessor = class {
4450
4449
  }
4451
4450
  return [];
4452
4451
  }
4452
+ /**
4453
+ * Send delta to UI (unified format)
4454
+ */
4455
+ sendDelta(channel, delta, onPartial) {
4456
+ if (!onPartial) return;
4457
+ onPartial(
4458
+ JSON.stringify({
4459
+ channel,
4460
+ delta
4461
+ })
4462
+ );
4463
+ }
4464
+ /**
4465
+ * Process content stream blocks (universal for all channels)
4466
+ */
4467
+ processContentStream(acc, channel, blocks, onPartial) {
4468
+ const state = acc.channels.get(channel);
4469
+ for (const block of blocks) {
4470
+ if (block.type === "tool_use" || block.type === "tool_call") {
4471
+ if (state.currentBlock) {
4472
+ state.contentChain.push(state.currentBlock);
4473
+ }
4474
+ state.currentBlock = {
4475
+ index: state.contentChain.length,
4476
+ type: "tool_use",
4477
+ name: block.name,
4478
+ id: block.id,
4479
+ input: block.input || "",
4480
+ output: ""
4481
+ };
4482
+ this.sendDelta(
4483
+ channel,
4484
+ {
4485
+ type: "step_started",
4486
+ step: state.currentBlock
4487
+ },
4488
+ onPartial
4489
+ );
4490
+ } else if (block.type === "input_json_delta") {
4491
+ if (state.currentBlock && state.currentBlock.type === "tool_use") {
4492
+ const chunk = block.input || "";
4493
+ state.currentBlock.input += chunk;
4494
+ this.sendDelta(
4495
+ channel,
4496
+ {
4497
+ type: "tool_input_chunk",
4498
+ stepId: state.currentBlock.id,
4499
+ chunk
4500
+ },
4501
+ onPartial
4502
+ );
4503
+ }
4504
+ } else if (block.type === "text") {
4505
+ const textChunk = block.text || "";
4506
+ if (state.currentBlock && state.currentBlock.type === "text") {
4507
+ state.currentBlock.text = (state.currentBlock.text || "") + textChunk;
4508
+ } else {
4509
+ if (state.currentBlock) {
4510
+ state.contentChain.push(state.currentBlock);
4511
+ }
4512
+ state.currentBlock = {
4513
+ index: state.contentChain.length,
4514
+ type: "text",
4515
+ text: textChunk
4516
+ };
4517
+ }
4518
+ this.sendDelta(
4519
+ channel,
4520
+ {
4521
+ type: "text_chunk",
4522
+ text: textChunk
4523
+ },
4524
+ onPartial
4525
+ );
4526
+ }
4527
+ }
4528
+ }
4453
4529
  /**
4454
4530
  * Groups tool_use and input_json_delta into proper structure
4455
4531
  * tool_use.input → output (tool execution result)
4456
4532
  * input_json_delta.input → output (tool execution result, accumulated)
4533
+ * @deprecated This method is for legacy fallback only
4457
4534
  */
4458
4535
  mapReasoningSteps(rawSteps) {
4459
4536
  const steps = [];
@@ -4502,60 +4579,10 @@ var EventProcessor = class {
4502
4579
  */
4503
4580
  processEvent(acc, event, onPartial) {
4504
4581
  this.captureTraceEvent(acc, event);
4505
- if (event.event === "on_chat_model_stream" && event.metadata?.stream_channel === "text" /* TEXT */ && event.data?.chunk?.content) {
4506
- const chunk = event.data.chunk.content;
4507
- const blocks = this.normalizeContentBlocks(chunk);
4508
- if (blocks.length > 0 && onPartial) {
4509
- onPartial(JSON.stringify({ text: blocks }));
4510
- }
4511
- const textOnly = blocks.filter((block) => block?.type === "text").map((block) => block.text || "").join("");
4512
- if (textOnly) {
4513
- acc.streamedText += textOnly;
4514
- }
4515
- return;
4516
- }
4517
- if (event.event === "on_chat_model_stream" && event.metadata?.stream_channel === "processing" /* PROCESSING */ && event.data?.chunk?.content) {
4518
- const chunk = event.data.chunk.content;
4519
- const blocks = this.normalizeContentBlocks(chunk);
4520
- for (const block of blocks) {
4521
- if (block.type === "tool_use" || block.type === "tool_call") {
4522
- if (acc.currentToolUse) {
4523
- acc.currentReasoningSteps.push(acc.currentToolUse);
4524
- }
4525
- acc.currentToolUse = {
4526
- index: acc.currentReasoningSteps.length,
4527
- type: "tool_use",
4528
- name: block.name,
4529
- id: block.id,
4530
- input: block.input || "",
4531
- output: ""
4532
- };
4533
- if (onPartial) {
4534
- onPartial(
4535
- JSON.stringify({
4536
- processing_delta: {
4537
- type: "step_started",
4538
- step: acc.currentToolUse
4539
- }
4540
- })
4541
- );
4542
- }
4543
- } else if (block.type === "input_json_delta") {
4544
- if (acc.currentToolUse && onPartial) {
4545
- const chunk2 = block.input || "";
4546
- acc.currentToolUse.output += chunk2;
4547
- onPartial(
4548
- JSON.stringify({
4549
- processing_delta: {
4550
- type: "output_chunk",
4551
- stepId: acc.currentToolUse.id,
4552
- chunk: chunk2
4553
- }
4554
- })
4555
- );
4556
- }
4557
- }
4558
- }
4582
+ if (event.event === "on_chat_model_stream" && event.data?.chunk?.content) {
4583
+ const channel = event.metadata?.stream_channel ?? "text" /* TEXT */;
4584
+ const blocks = this.normalizeContentBlocks(event.data.chunk.content);
4585
+ this.processContentStream(acc, channel, blocks, onPartial);
4559
4586
  return;
4560
4587
  }
4561
4588
  if (event.event === "on_tool_start") {
@@ -4568,11 +4595,27 @@ var EventProcessor = class {
4568
4595
  return;
4569
4596
  }
4570
4597
  if (event.event === "on_tool_end") {
4571
- this.logger.log("\u2705 Tool execution completed", {
4572
- toolName: event.name,
4573
- output: typeof event.data?.output === "string" ? event.data.output.substring(0, 200) + (event.data.output.length > 200 ? "..." : "") : event.data?.output,
4574
- runId: event.run_id
4575
- });
4598
+ const channel = event.metadata?.stream_channel ?? "text" /* TEXT */;
4599
+ const state = acc.channels.get(channel);
4600
+ if (state?.currentBlock && state.currentBlock.type === "tool_use") {
4601
+ const output = event.data?.output;
4602
+ const outputString = typeof output === "string" ? output : JSON.stringify(output, null, 2);
4603
+ state.currentBlock.output = outputString;
4604
+ this.sendDelta(
4605
+ channel,
4606
+ {
4607
+ type: "tool_output_chunk",
4608
+ stepId: state.currentBlock.id,
4609
+ chunk: outputString
4610
+ },
4611
+ onPartial
4612
+ );
4613
+ this.logger.log("\u2705 Tool execution completed", {
4614
+ toolName: event.name,
4615
+ outputPreview: outputString.substring(0, 200) + (outputString.length > 200 ? "..." : ""),
4616
+ runId: event.run_id
4617
+ });
4618
+ }
4576
4619
  return;
4577
4620
  }
4578
4621
  if (event.event === "on_tool_error") {
@@ -4584,133 +4627,48 @@ var EventProcessor = class {
4584
4627
  return;
4585
4628
  }
4586
4629
  if (event.event === "on_chat_model_end") {
4587
- const output = event.data?.output;
4588
- const usageMetadata = output?.usage_metadata || output?.usageMetadata;
4589
- const modelId = event.metadata?.modelId;
4590
- if (usageMetadata && modelId) {
4591
- const llmCall = {
4592
- modelId,
4593
- promptTokens: usageMetadata.input_tokens || 0,
4594
- completionTokens: usageMetadata.output_tokens || 0,
4595
- totalTokens: usageMetadata.total_tokens || 0,
4596
- timestamp: Date.now(),
4597
- nodeName: event.metadata?.langgraph_node || event.name
4598
- };
4599
- acc.llmCalls.push(llmCall);
4600
- this.logger.log("\u2705 LLM call recorded", {
4601
- modelId,
4602
- tokens: llmCall.totalTokens,
4603
- nodeName: llmCall.nodeName,
4604
- totalRecorded: acc.llmCalls.length
4605
- });
4606
- } else {
4607
- this.logger.warn(
4608
- "\u26A0\uFE0F Missing usage metadata or modelId in on_chat_model_end",
4609
- {
4610
- hasUsageMetadata: !!usageMetadata,
4611
- hasModelId: !!modelId,
4612
- eventName: event.name,
4613
- metadataKeys: event.metadata ? Object.keys(event.metadata) : [],
4614
- outputKeys: output ? Object.keys(output) : []
4615
- }
4616
- );
4617
- }
4618
- if (event.metadata?.stream_channel === "processing" /* PROCESSING */) {
4619
- if (acc.currentToolUse) {
4620
- acc.currentReasoningSteps.push(acc.currentToolUse);
4621
- acc.currentToolUse = null;
4622
- }
4623
- if (acc.currentReasoningSteps.length > 0) {
4624
- acc.reasoningChains.push({
4625
- steps: acc.currentReasoningSteps,
4626
- isComplete: true
4627
- });
4628
- if (onPartial) {
4629
- onPartial(
4630
- JSON.stringify({
4631
- processing_delta: {
4632
- type: "chain_completed"
4633
- }
4634
- })
4635
- );
4636
- }
4637
- acc.currentReasoningSteps = [];
4638
- } else {
4639
- const stepsRaw = output?.content || // AIMessageChunk object (direct)
4640
- output?.kwargs?.content || // Serialized LangChain format
4641
- event.data?.chunk?.content || // Older version
4642
- [];
4643
- let steps;
4644
- if (Array.isArray(stepsRaw)) {
4645
- steps = this.mapReasoningSteps(stepsRaw);
4646
- } else if (typeof stepsRaw === "string" && stepsRaw.trim().length > 0) {
4647
- steps = [
4648
- {
4649
- index: 0,
4650
- type: "text",
4651
- text: stepsRaw.trim()
4652
- }
4653
- ];
4654
- } else {
4655
- steps = [];
4656
- }
4657
- if (steps.length > 0) {
4658
- acc.reasoningChains.push({
4659
- steps,
4660
- isComplete: true
4661
- });
4662
- if (onPartial) {
4663
- onPartial(
4664
- JSON.stringify({
4665
- processing_delta: {
4666
- type: "chain_completed"
4667
- }
4668
- })
4669
- );
4670
- }
4671
- }
4672
- }
4673
- }
4630
+ this.logger.debug("\u2705 LLM call completed", {
4631
+ nodeName: event.metadata?.langgraph_node || event.name,
4632
+ channel: event.metadata?.stream_channel
4633
+ });
4674
4634
  return;
4675
4635
  }
4676
- if (event.event === "on_chain_end" && event.metadata?.stream_channel === "text" /* TEXT */) {
4677
- const output = event.data.output;
4678
- let generation = null;
4679
- if (output?.answer?.text) {
4680
- generation = {
4681
- text: output.answer.text,
4682
- attachments: output.answer.attachments || [],
4683
- metadata: output.answer.metadata || {}
4684
- };
4685
- } else if (output?.generation?.text) {
4686
- generation = {
4687
- text: output.generation.text,
4688
- attachments: output.generation.attachments || [],
4689
- metadata: output.generation.metadata || {}
4690
- };
4691
- } else if (output?.generation?.content) {
4692
- generation = {
4693
- text: output.generation.content,
4694
- attachments: [],
4695
- metadata: {}
4696
- };
4697
- } else if (output?.text) {
4698
- generation = {
4699
- text: output.text,
4700
- attachments: output.attachments || [],
4701
- metadata: output.metadata || {}
4702
- };
4636
+ if (event.event === "on_chain_end") {
4637
+ const channel = event.metadata?.stream_channel ?? "text" /* TEXT */;
4638
+ if (channel === "text" /* TEXT */) {
4639
+ const output = event.data.output;
4640
+ if (output?.answer) {
4641
+ acc.attachments = output.answer.attachments || [];
4642
+ acc.metadata = output.answer.metadata || {};
4643
+ } else if (output?.generation) {
4644
+ acc.attachments = output.generation.attachments || [];
4645
+ acc.metadata = output.generation.metadata || {};
4646
+ } else if (output) {
4647
+ acc.attachments = output.attachments || [];
4648
+ acc.metadata = output.metadata || {};
4649
+ }
4703
4650
  }
4704
- acc.generation = generation;
4705
4651
  return;
4706
4652
  }
4707
4653
  }
4708
4654
  /**
4709
4655
  * Build final result from accumulator
4710
- * Uses generation if available, otherwise falls back to streamed text
4711
- * Returns content and trace events (metrics should be extracted from trace on backend)
4656
+ * Returns unified content chains from all channels
4712
4657
  */
4713
4658
  getResult(acc) {
4659
+ const allChains = [];
4660
+ for (const [channel, state] of acc.channels.entries()) {
4661
+ if (state.currentBlock) {
4662
+ state.contentChain.push(state.currentBlock);
4663
+ }
4664
+ if (state.contentChain.length > 0) {
4665
+ allChains.push({
4666
+ channel,
4667
+ steps: state.contentChain,
4668
+ isComplete: true
4669
+ });
4670
+ }
4671
+ }
4714
4672
  const startedAt = acc.traceStartedAt ?? Date.now();
4715
4673
  const completedAt = acc.traceCompletedAt ?? startedAt;
4716
4674
  const trace = acc.traceEvents.length > 0 ? {
@@ -4718,26 +4676,19 @@ var EventProcessor = class {
4718
4676
  startedAt,
4719
4677
  completedAt,
4720
4678
  durationMs: Math.max(0, completedAt - startedAt),
4721
- totalEvents: acc.traceEvents.length,
4722
- totalModelCalls: acc.llmCalls.length
4679
+ totalEvents: acc.traceEvents.length
4723
4680
  } : null;
4724
- if (trace) {
4725
- this.logger.log("\u{1F4CA} [EventProcessor] Final trace assembled", {
4726
- totalEvents: trace.totalEvents,
4727
- eventsArrayLength: trace.events.length,
4728
- firstEventType: trace.events[0]?.type,
4729
- lastEventType: trace.events[trace.events.length - 1]?.type,
4730
- firstEventSample: trace.events[0] ? JSON.stringify(trace.events[0]).substring(0, 150) : null,
4731
- allEventsNull: trace.events.every((e) => e === null),
4732
- someEventsNull: trace.events.some((e) => e === null)
4733
- });
4734
- }
4681
+ this.logger.log("\u{1F4CA} [EventProcessor] Final result assembled", {
4682
+ totalChains: allChains.length,
4683
+ textChains: allChains.filter((c) => c.channel === "text").length,
4684
+ processingChains: allChains.filter((c) => c.channel === "processing").length,
4685
+ totalSteps: allChains.reduce((sum, c) => sum + c.steps.length, 0)
4686
+ });
4735
4687
  return {
4736
4688
  content: {
4737
- text: acc.generation?.text || acc.streamedText || "",
4738
- attachments: acc.generation?.attachments || [],
4739
- metadata: acc.generation?.metadata || {},
4740
- reasoningChains: acc.reasoningChains.length > 0 ? acc.reasoningChains : void 0
4689
+ contentChains: allChains.length > 0 ? allChains : void 0,
4690
+ attachments: acc.attachments,
4691
+ metadata: acc.metadata
4741
4692
  },
4742
4693
  trace
4743
4694
  };
@@ -4858,8 +4809,7 @@ var LangGraphEngine = class {
4858
4809
  hasContent: !!content,
4859
4810
  hasContext: !!config.configurable?.context,
4860
4811
  hasTrace: !!trace,
4861
- traceEvents: trace?.events?.length || 0,
4862
- totalModelCalls: trace?.totalModelCalls || 0
4812
+ traceEvents: trace?.events?.length || 0
4863
4813
  });
4864
4814
  if (trace && trace.events.length > 0 && config.configurable?.context) {
4865
4815
  const context = config.configurable.context;
@@ -4877,7 +4827,6 @@ var LangGraphEngine = class {
4877
4827
  companyId: context.companyId || "unknown",
4878
4828
  events: trace.events,
4879
4829
  totalEvents: trace.totalEvents,
4880
- totalModelCalls: trace.totalModelCalls,
4881
4830
  startedAt: trace.startedAt,
4882
4831
  completedAt: trace.completedAt,
4883
4832
  durationMs: trace.durationMs
@@ -4960,7 +4909,6 @@ var LangGraphEngine = class {
4960
4909
  agentId: payload.agentId,
4961
4910
  companyId: payload.companyId,
4962
4911
  totalEvents: payload.totalEvents,
4963
- totalModelCalls: payload.totalModelCalls,
4964
4912
  startedAt: payload.startedAt,
4965
4913
  completedAt: payload.completedAt,
4966
4914
  durationMs: payload.durationMs,