echo-ai-sdk-ts 2.2.0 → 2.3.1

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.mts CHANGED
@@ -245,6 +245,7 @@ declare class AgentExecutor {
245
245
  systemPrompt?: string;
246
246
  telemetry?: AgentTelemetry;
247
247
  });
248
+ getMemory(): BaseMemoryStore;
248
249
  execute(sessionId: string, userInput: string, maxIterations?: number): Promise<string>;
249
250
  /**
250
251
  * Forces the LLM to output strictly structured JSON validated against the provided Zod schema.
@@ -609,6 +610,34 @@ declare class KnowledgeBase {
609
610
  private embedBatch;
610
611
  }
611
612
 
613
+ /**
614
+ * Outcome tracking module for value-based billing.
615
+ * Tracks successful business results (leads, sales, resolutions) to calculate ROI.
616
+ */
617
+ interface OutcomeRecord {
618
+ type: string;
619
+ valueUsd: number;
620
+ timestamp: number;
621
+ metadata?: Record<string, any>;
622
+ }
623
+ declare class OutcomeTracker {
624
+ private sessionOutcomes;
625
+ /** Record a successful business outcome for a session. */
626
+ record(sessionId: string, type: string, valueUsd?: number, metadata?: Record<string, any>): void;
627
+ /** Get all outcomes for a specific session. */
628
+ getSessionOutcomes(sessionId: string): OutcomeRecord[];
629
+ /** Calculate total value generated for a session. */
630
+ getSessionValue(sessionId: string): number;
631
+ /** Get global stats for all outcomes. */
632
+ getGlobalStats(): {
633
+ totalOutcomes: number;
634
+ totalValueUsd: number;
635
+ outcomesByType: Record<string, number>;
636
+ };
637
+ /** Reset all stats. */
638
+ clear(): void;
639
+ }
640
+
612
641
  /**
613
642
  * Enterprise Conversation Analytics Engine.
614
643
  * Tracks resolution rates, CSAT, response latency, token costs, and top queries.
@@ -636,6 +665,8 @@ interface AnalyticsSnapshot {
636
665
  avgResponseTimeMs: number;
637
666
  totalTokensUsed: number;
638
667
  totalCostUsd: number;
668
+ totalValueGeneratedUsd: number;
669
+ roi: number;
639
670
  avgTokensPerConversation: number;
640
671
  avgCostPerConversation: number;
641
672
  topQueries: {
@@ -651,6 +682,8 @@ declare const OPENAI_PRICING: Record<string, {
651
682
  declare class ConversationAnalytics {
652
683
  private records;
653
684
  private queryFrequency;
685
+ outcomeTracker?: OutcomeTracker;
686
+ constructor(outcomeTracker?: OutcomeTracker);
654
687
  estimateTokens(text: string): number;
655
688
  calculateCost(model: string, tokens: number, type?: "input" | "output"): number;
656
689
  startConversation(sessionId: string, model?: string): void;
@@ -718,6 +751,39 @@ declare class HandoffManager {
718
751
  private dispatchWebhook;
719
752
  }
720
753
 
754
+ /**
755
+ * Interface for pluggable session storage (Memory, Redis, File, DB).
756
+ */
757
+ interface SessionStore {
758
+ get(sessionId: string): Promise<any | null>;
759
+ set(sessionId: string, data: any): Promise<void>;
760
+ delete(sessionId: string): Promise<void>;
761
+ clear(): Promise<void>;
762
+ }
763
+ /**
764
+ * Default in-memory session store.
765
+ */
766
+ declare class MemorySessionStore implements SessionStore {
767
+ private store;
768
+ get(sessionId: string): Promise<any | null>;
769
+ set(sessionId: string, data: any): Promise<void>;
770
+ delete(sessionId: string): Promise<void>;
771
+ clear(): Promise<void>;
772
+ }
773
+ /**
774
+ * Pro-grade local file session store for persistence across restarts.
775
+ */
776
+ declare class FileSessionStore implements SessionStore {
777
+ private dir;
778
+ constructor(dir?: string);
779
+ private getPath;
780
+ private ensureDir;
781
+ get(sessionId: string): Promise<any | null>;
782
+ set(sessionId: string, data: any): Promise<void>;
783
+ delete(sessionId: string): Promise<void>;
784
+ clear(): Promise<void>;
785
+ }
786
+
721
787
  interface SupportBotConfig {
722
788
  gateway: AIModelGateway;
723
789
  companyName: string;
@@ -728,6 +794,7 @@ interface SupportBotConfig {
728
794
  memory?: BaseMemoryStore;
729
795
  telemetry?: AgentTelemetry;
730
796
  customTools?: ToolContext[];
797
+ sessionStore?: SessionStore;
731
798
  greeting?: string;
732
799
  systemPrompt?: string;
733
800
  maxIterations?: number;
@@ -747,12 +814,16 @@ declare class CustomerSupportBot {
747
814
  private connector?;
748
815
  knowledgeBase?: KnowledgeBase;
749
816
  analytics: ConversationAnalytics;
817
+ outcomeTracker: OutcomeTracker;
818
+ sessionStore: SessionStore;
750
819
  handoff?: HandoffManager;
751
820
  greeting: string;
752
821
  private middlewares;
753
822
  constructor(config: SupportBotConfig);
754
823
  /** Register a middleware function to run before every chat turn. */
755
824
  use(middleware: BotMiddleware): void;
825
+ /** Record a business outcome for ROI tracking. */
826
+ trackOutcome(sessionId: string, type: string, valueUsd?: number, metadata?: Record<string, any>): void;
756
827
  /** Process a customer message and return the bot's response. */
757
828
  chat(sessionId: string, message: string): Promise<string>;
758
829
  /** Start tracking analytics for a new session. */
@@ -803,4 +874,63 @@ declare function createChatHandler(bot: CustomerSupportBot): (req: any, res: any
803
874
  */
804
875
  declare function startChatServer(config: ServerConfig): Promise<void>;
805
876
 
806
- export { AIModelGateway, APIConnector, type APIConnectorConfig, AgentExecutor, AgentIterationLimitError, AgentPipeline, AgentRouter, type AgentTelemetry, type AnalyticsSnapshot, type BaseMemoryStore, BaseProvider, BaseSTTProvider, BaseSpeakerRecognizer, BaseTTSProvider, type BotMiddleware, CachedGateway, ChatAgent, type ChatMessage, ChatMessageSchema, type ChatRequest, ChatRequestSchema, type ChatResponse, ChatResponseSchema, ChatWidget, type ChatWidgetConfig, type ChatWidgetTheme, type ChunkOptions, ConfigurationError, ConversationAnalytics, type ConversationRecord, CustomerSupportBot, EchoAI, EchoVoice, type EscalationTrigger, type FetchResult, type GatewayMiddleware, GatewayRoutingError, type HandoffConfig, type HandoffEvent, HandoffManager, type IdentificationResult, InMemoryStore, KnowledgeBase, type KnowledgeBaseConfig, MemoryVectorStore, OPENAI_PRICING, OpenAITTS, OpenAIWhisperSTT, PromptRegistry, PromptTemplate, PromptVersionError, ProviderDependencyError, type STTOptions, type SearchResult, type ServerConfig, type SpeakerProfile, StructuredOutputError, type SupportBotConfig, type TTSFormat, type TTSOptions, type TTSResult, type TTSVoice, ToolAgent, type ToolContext, ToolExecutionError, type TranscriptionResult, type TranscriptionSegment, type UsageMetrics, UsageMetricsSchema, ValidationError, type VectorEntry, type VerificationResult, VoiceprintStore, applyRequestMiddleware, applyResponseMiddleware, calculatorTool, chunkText, createChatHandler, createTool, dateTimeTool, startChatServer, webSearchTool };
877
+ /**
878
+ * Base configuration for any channel adapter.
879
+ */
880
+ interface ChannelConfig {
881
+ bot: CustomerSupportBot;
882
+ enabled?: boolean;
883
+ }
884
+ /**
885
+ * Unified interface for messaging channels (Slack, Telegram, WhatsApp).
886
+ */
887
+ declare abstract class ChannelAdapter {
888
+ protected bot: CustomerSupportBot;
889
+ constructor(config: ChannelConfig);
890
+ /** Initialize the channel listener/connection. */
891
+ abstract start(): Promise<void>;
892
+ /** Stop the channel listener. */
893
+ abstract stop(): Promise<void>;
894
+ /**
895
+ * Normalize incoming messages from different platforms
896
+ * and route them to the core bot brain.
897
+ */
898
+ protected handleMessage(sessionId: string, text: string): Promise<string>;
899
+ }
900
+
901
+ /**
902
+ * Pro-grade Slack Adapter (Skeleton).
903
+ * Standardized interface for Slack Bolt / Webhook integration.
904
+ */
905
+ interface SlackConfig extends ChannelConfig {
906
+ signingSecret: string;
907
+ token: string;
908
+ appToken?: string;
909
+ }
910
+ declare class SlackAdapter extends ChannelAdapter {
911
+ constructor(config: SlackConfig);
912
+ start(): Promise<void>;
913
+ stop(): Promise<void>;
914
+ /** Handler for Slack events (to be used by Express middleware). */
915
+ handleEvent(event: any): Promise<void>;
916
+ }
917
+
918
+ /**
919
+ * Pro-grade Telegram Adapter.
920
+ * Uses the Telegram Bot API to connect your AI assistant to Telegram.
921
+ */
922
+ interface TelegramConfig extends ChannelConfig {
923
+ token: string;
924
+ }
925
+ declare class TelegramAdapter extends ChannelAdapter {
926
+ private token;
927
+ private polling;
928
+ private offset;
929
+ constructor(config: TelegramConfig);
930
+ start(): Promise<void>;
931
+ stop(): Promise<void>;
932
+ private runPollingLoop;
933
+ private sendMessage;
934
+ }
935
+
936
+ export { AIModelGateway, APIConnector, type APIConnectorConfig, AgentExecutor, AgentIterationLimitError, AgentPipeline, AgentRouter, type AgentTelemetry, type AnalyticsSnapshot, type BaseMemoryStore, BaseProvider, BaseSTTProvider, BaseSpeakerRecognizer, BaseTTSProvider, type BotMiddleware, CachedGateway, ChannelAdapter, type ChannelConfig, ChatAgent, type ChatMessage, ChatMessageSchema, type ChatRequest, ChatRequestSchema, type ChatResponse, ChatResponseSchema, ChatWidget, type ChatWidgetConfig, type ChatWidgetTheme, type ChunkOptions, ConfigurationError, ConversationAnalytics, type ConversationRecord, CustomerSupportBot, EchoAI, EchoVoice, type EscalationTrigger, type FetchResult, FileSessionStore, type GatewayMiddleware, GatewayRoutingError, type HandoffConfig, type HandoffEvent, HandoffManager, type IdentificationResult, InMemoryStore, KnowledgeBase, type KnowledgeBaseConfig, MemorySessionStore, MemoryVectorStore, OPENAI_PRICING, OpenAITTS, OpenAIWhisperSTT, type OutcomeRecord, OutcomeTracker, PromptRegistry, PromptTemplate, PromptVersionError, ProviderDependencyError, type STTOptions, type SearchResult, type ServerConfig, type SessionStore, SlackAdapter, type SlackConfig, type SpeakerProfile, StructuredOutputError, type SupportBotConfig, type TTSFormat, type TTSOptions, type TTSResult, type TTSVoice, TelegramAdapter, type TelegramConfig, ToolAgent, type ToolContext, ToolExecutionError, type TranscriptionResult, type TranscriptionSegment, type UsageMetrics, UsageMetricsSchema, ValidationError, type VectorEntry, type VerificationResult, VoiceprintStore, applyRequestMiddleware, applyResponseMiddleware, calculatorTool, chunkText, createChatHandler, createTool, dateTimeTool, startChatServer, webSearchTool };
package/dist/index.d.ts CHANGED
@@ -245,6 +245,7 @@ declare class AgentExecutor {
245
245
  systemPrompt?: string;
246
246
  telemetry?: AgentTelemetry;
247
247
  });
248
+ getMemory(): BaseMemoryStore;
248
249
  execute(sessionId: string, userInput: string, maxIterations?: number): Promise<string>;
249
250
  /**
250
251
  * Forces the LLM to output strictly structured JSON validated against the provided Zod schema.
@@ -609,6 +610,34 @@ declare class KnowledgeBase {
609
610
  private embedBatch;
610
611
  }
611
612
 
613
+ /**
614
+ * Outcome tracking module for value-based billing.
615
+ * Tracks successful business results (leads, sales, resolutions) to calculate ROI.
616
+ */
617
+ interface OutcomeRecord {
618
+ type: string;
619
+ valueUsd: number;
620
+ timestamp: number;
621
+ metadata?: Record<string, any>;
622
+ }
623
+ declare class OutcomeTracker {
624
+ private sessionOutcomes;
625
+ /** Record a successful business outcome for a session. */
626
+ record(sessionId: string, type: string, valueUsd?: number, metadata?: Record<string, any>): void;
627
+ /** Get all outcomes for a specific session. */
628
+ getSessionOutcomes(sessionId: string): OutcomeRecord[];
629
+ /** Calculate total value generated for a session. */
630
+ getSessionValue(sessionId: string): number;
631
+ /** Get global stats for all outcomes. */
632
+ getGlobalStats(): {
633
+ totalOutcomes: number;
634
+ totalValueUsd: number;
635
+ outcomesByType: Record<string, number>;
636
+ };
637
+ /** Reset all stats. */
638
+ clear(): void;
639
+ }
640
+
612
641
  /**
613
642
  * Enterprise Conversation Analytics Engine.
614
643
  * Tracks resolution rates, CSAT, response latency, token costs, and top queries.
@@ -636,6 +665,8 @@ interface AnalyticsSnapshot {
636
665
  avgResponseTimeMs: number;
637
666
  totalTokensUsed: number;
638
667
  totalCostUsd: number;
668
+ totalValueGeneratedUsd: number;
669
+ roi: number;
639
670
  avgTokensPerConversation: number;
640
671
  avgCostPerConversation: number;
641
672
  topQueries: {
@@ -651,6 +682,8 @@ declare const OPENAI_PRICING: Record<string, {
651
682
  declare class ConversationAnalytics {
652
683
  private records;
653
684
  private queryFrequency;
685
+ outcomeTracker?: OutcomeTracker;
686
+ constructor(outcomeTracker?: OutcomeTracker);
654
687
  estimateTokens(text: string): number;
655
688
  calculateCost(model: string, tokens: number, type?: "input" | "output"): number;
656
689
  startConversation(sessionId: string, model?: string): void;
@@ -718,6 +751,39 @@ declare class HandoffManager {
718
751
  private dispatchWebhook;
719
752
  }
720
753
 
754
+ /**
755
+ * Interface for pluggable session storage (Memory, Redis, File, DB).
756
+ */
757
+ interface SessionStore {
758
+ get(sessionId: string): Promise<any | null>;
759
+ set(sessionId: string, data: any): Promise<void>;
760
+ delete(sessionId: string): Promise<void>;
761
+ clear(): Promise<void>;
762
+ }
763
+ /**
764
+ * Default in-memory session store.
765
+ */
766
+ declare class MemorySessionStore implements SessionStore {
767
+ private store;
768
+ get(sessionId: string): Promise<any | null>;
769
+ set(sessionId: string, data: any): Promise<void>;
770
+ delete(sessionId: string): Promise<void>;
771
+ clear(): Promise<void>;
772
+ }
773
+ /**
774
+ * Pro-grade local file session store for persistence across restarts.
775
+ */
776
+ declare class FileSessionStore implements SessionStore {
777
+ private dir;
778
+ constructor(dir?: string);
779
+ private getPath;
780
+ private ensureDir;
781
+ get(sessionId: string): Promise<any | null>;
782
+ set(sessionId: string, data: any): Promise<void>;
783
+ delete(sessionId: string): Promise<void>;
784
+ clear(): Promise<void>;
785
+ }
786
+
721
787
  interface SupportBotConfig {
722
788
  gateway: AIModelGateway;
723
789
  companyName: string;
@@ -728,6 +794,7 @@ interface SupportBotConfig {
728
794
  memory?: BaseMemoryStore;
729
795
  telemetry?: AgentTelemetry;
730
796
  customTools?: ToolContext[];
797
+ sessionStore?: SessionStore;
731
798
  greeting?: string;
732
799
  systemPrompt?: string;
733
800
  maxIterations?: number;
@@ -747,12 +814,16 @@ declare class CustomerSupportBot {
747
814
  private connector?;
748
815
  knowledgeBase?: KnowledgeBase;
749
816
  analytics: ConversationAnalytics;
817
+ outcomeTracker: OutcomeTracker;
818
+ sessionStore: SessionStore;
750
819
  handoff?: HandoffManager;
751
820
  greeting: string;
752
821
  private middlewares;
753
822
  constructor(config: SupportBotConfig);
754
823
  /** Register a middleware function to run before every chat turn. */
755
824
  use(middleware: BotMiddleware): void;
825
+ /** Record a business outcome for ROI tracking. */
826
+ trackOutcome(sessionId: string, type: string, valueUsd?: number, metadata?: Record<string, any>): void;
756
827
  /** Process a customer message and return the bot's response. */
757
828
  chat(sessionId: string, message: string): Promise<string>;
758
829
  /** Start tracking analytics for a new session. */
@@ -803,4 +874,63 @@ declare function createChatHandler(bot: CustomerSupportBot): (req: any, res: any
803
874
  */
804
875
  declare function startChatServer(config: ServerConfig): Promise<void>;
805
876
 
806
- export { AIModelGateway, APIConnector, type APIConnectorConfig, AgentExecutor, AgentIterationLimitError, AgentPipeline, AgentRouter, type AgentTelemetry, type AnalyticsSnapshot, type BaseMemoryStore, BaseProvider, BaseSTTProvider, BaseSpeakerRecognizer, BaseTTSProvider, type BotMiddleware, CachedGateway, ChatAgent, type ChatMessage, ChatMessageSchema, type ChatRequest, ChatRequestSchema, type ChatResponse, ChatResponseSchema, ChatWidget, type ChatWidgetConfig, type ChatWidgetTheme, type ChunkOptions, ConfigurationError, ConversationAnalytics, type ConversationRecord, CustomerSupportBot, EchoAI, EchoVoice, type EscalationTrigger, type FetchResult, type GatewayMiddleware, GatewayRoutingError, type HandoffConfig, type HandoffEvent, HandoffManager, type IdentificationResult, InMemoryStore, KnowledgeBase, type KnowledgeBaseConfig, MemoryVectorStore, OPENAI_PRICING, OpenAITTS, OpenAIWhisperSTT, PromptRegistry, PromptTemplate, PromptVersionError, ProviderDependencyError, type STTOptions, type SearchResult, type ServerConfig, type SpeakerProfile, StructuredOutputError, type SupportBotConfig, type TTSFormat, type TTSOptions, type TTSResult, type TTSVoice, ToolAgent, type ToolContext, ToolExecutionError, type TranscriptionResult, type TranscriptionSegment, type UsageMetrics, UsageMetricsSchema, ValidationError, type VectorEntry, type VerificationResult, VoiceprintStore, applyRequestMiddleware, applyResponseMiddleware, calculatorTool, chunkText, createChatHandler, createTool, dateTimeTool, startChatServer, webSearchTool };
877
+ /**
878
+ * Base configuration for any channel adapter.
879
+ */
880
+ interface ChannelConfig {
881
+ bot: CustomerSupportBot;
882
+ enabled?: boolean;
883
+ }
884
+ /**
885
+ * Unified interface for messaging channels (Slack, Telegram, WhatsApp).
886
+ */
887
+ declare abstract class ChannelAdapter {
888
+ protected bot: CustomerSupportBot;
889
+ constructor(config: ChannelConfig);
890
+ /** Initialize the channel listener/connection. */
891
+ abstract start(): Promise<void>;
892
+ /** Stop the channel listener. */
893
+ abstract stop(): Promise<void>;
894
+ /**
895
+ * Normalize incoming messages from different platforms
896
+ * and route them to the core bot brain.
897
+ */
898
+ protected handleMessage(sessionId: string, text: string): Promise<string>;
899
+ }
900
+
901
+ /**
902
+ * Pro-grade Slack Adapter (Skeleton).
903
+ * Standardized interface for Slack Bolt / Webhook integration.
904
+ */
905
+ interface SlackConfig extends ChannelConfig {
906
+ signingSecret: string;
907
+ token: string;
908
+ appToken?: string;
909
+ }
910
+ declare class SlackAdapter extends ChannelAdapter {
911
+ constructor(config: SlackConfig);
912
+ start(): Promise<void>;
913
+ stop(): Promise<void>;
914
+ /** Handler for Slack events (to be used by Express middleware). */
915
+ handleEvent(event: any): Promise<void>;
916
+ }
917
+
918
+ /**
919
+ * Pro-grade Telegram Adapter.
920
+ * Uses the Telegram Bot API to connect your AI assistant to Telegram.
921
+ */
922
+ interface TelegramConfig extends ChannelConfig {
923
+ token: string;
924
+ }
925
+ declare class TelegramAdapter extends ChannelAdapter {
926
+ private token;
927
+ private polling;
928
+ private offset;
929
+ constructor(config: TelegramConfig);
930
+ start(): Promise<void>;
931
+ stop(): Promise<void>;
932
+ private runPollingLoop;
933
+ private sendMessage;
934
+ }
935
+
936
+ export { AIModelGateway, APIConnector, type APIConnectorConfig, AgentExecutor, AgentIterationLimitError, AgentPipeline, AgentRouter, type AgentTelemetry, type AnalyticsSnapshot, type BaseMemoryStore, BaseProvider, BaseSTTProvider, BaseSpeakerRecognizer, BaseTTSProvider, type BotMiddleware, CachedGateway, ChannelAdapter, type ChannelConfig, ChatAgent, type ChatMessage, ChatMessageSchema, type ChatRequest, ChatRequestSchema, type ChatResponse, ChatResponseSchema, ChatWidget, type ChatWidgetConfig, type ChatWidgetTheme, type ChunkOptions, ConfigurationError, ConversationAnalytics, type ConversationRecord, CustomerSupportBot, EchoAI, EchoVoice, type EscalationTrigger, type FetchResult, FileSessionStore, type GatewayMiddleware, GatewayRoutingError, type HandoffConfig, type HandoffEvent, HandoffManager, type IdentificationResult, InMemoryStore, KnowledgeBase, type KnowledgeBaseConfig, MemorySessionStore, MemoryVectorStore, OPENAI_PRICING, OpenAITTS, OpenAIWhisperSTT, type OutcomeRecord, OutcomeTracker, PromptRegistry, PromptTemplate, PromptVersionError, ProviderDependencyError, type STTOptions, type SearchResult, type ServerConfig, type SessionStore, SlackAdapter, type SlackConfig, type SpeakerProfile, StructuredOutputError, type SupportBotConfig, type TTSFormat, type TTSOptions, type TTSResult, type TTSVoice, TelegramAdapter, type TelegramConfig, ToolAgent, type ToolContext, ToolExecutionError, type TranscriptionResult, type TranscriptionSegment, type UsageMetrics, UsageMetricsSchema, ValidationError, type VectorEntry, type VerificationResult, VoiceprintStore, applyRequestMiddleware, applyResponseMiddleware, calculatorTool, chunkText, createChatHandler, createTool, dateTimeTool, startChatServer, webSearchTool };