echo-ai-sdk-ts 2.2.0 → 2.4.0
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/README.md +35 -0
- package/dist/index.d.mts +181 -2
- package/dist/index.d.ts +181 -2
- package/dist/index.js +472 -112
- package/dist/index.mjs +455 -104
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -113,6 +113,41 @@ bot.use(async ({ sessionId, message }) => {
|
|
|
113
113
|
});
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
+
|
|
117
|
+
### 🚀 Tier 2 Pro-Grade Features
|
|
118
|
+
|
|
119
|
+
#### 🌐 Omnichannel Sync
|
|
120
|
+
Connect your bot to Slack and Telegram while maintaining a single user context.
|
|
121
|
+
```typescript
|
|
122
|
+
import { TelegramAdapter, SlackAdapter } from "echo-ai-sdk";
|
|
123
|
+
|
|
124
|
+
const tg = new TelegramAdapter({ bot, token: "TG_TOKEN" });
|
|
125
|
+
await tg.start();
|
|
126
|
+
|
|
127
|
+
const slack = new SlackAdapter({ bot, signingSecret: "...", token: "..." });
|
|
128
|
+
await slack.start();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### 💾 Persistent Session Store
|
|
132
|
+
Move beyond memory. Use `FileSessionStore` for local persistence or implement `SessionStore` for Redis.
|
|
133
|
+
```typescript
|
|
134
|
+
import { FileSessionStore } from "echo-ai-sdk";
|
|
135
|
+
const bot = new CustomerSupportBot({
|
|
136
|
+
sessionStore: new FileSessionStore("./sessions"),
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### 📈 Outcome-Based Billing & ROI
|
|
141
|
+
Track the *real value* of your AI by recording business outcomes.
|
|
142
|
+
```typescript
|
|
143
|
+
// Inside a tool or middleware
|
|
144
|
+
bot.trackOutcome(sessionId, "lead_captured", 50.0);
|
|
145
|
+
|
|
146
|
+
const stats = bot.analytics.getSnapshot();
|
|
147
|
+
console.log(`ROI: ${stats.roi * 100}%`);
|
|
148
|
+
console.log(`Value Generated: $${stats.totalValueGeneratedUsd}`);
|
|
149
|
+
```
|
|
150
|
+
|
|
116
151
|
---
|
|
117
152
|
|
|
118
153
|
## Installation
|
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.
|
|
@@ -626,6 +655,7 @@ interface ConversationRecord {
|
|
|
626
655
|
topQueries: string[];
|
|
627
656
|
responseTimes: number[];
|
|
628
657
|
model?: string;
|
|
658
|
+
variantId?: string;
|
|
629
659
|
}
|
|
630
660
|
interface AnalyticsSnapshot {
|
|
631
661
|
totalConversations: number;
|
|
@@ -636,6 +666,14 @@ interface AnalyticsSnapshot {
|
|
|
636
666
|
avgResponseTimeMs: number;
|
|
637
667
|
totalTokensUsed: number;
|
|
638
668
|
totalCostUsd: number;
|
|
669
|
+
totalValueGeneratedUsd: number;
|
|
670
|
+
roi: number;
|
|
671
|
+
variants?: Record<string, {
|
|
672
|
+
totalConversations: number;
|
|
673
|
+
totalValueGeneratedUsd: number;
|
|
674
|
+
resolutionRate: number;
|
|
675
|
+
roi: number;
|
|
676
|
+
}>;
|
|
639
677
|
avgTokensPerConversation: number;
|
|
640
678
|
avgCostPerConversation: number;
|
|
641
679
|
topQueries: {
|
|
@@ -651,9 +689,11 @@ declare const OPENAI_PRICING: Record<string, {
|
|
|
651
689
|
declare class ConversationAnalytics {
|
|
652
690
|
private records;
|
|
653
691
|
private queryFrequency;
|
|
692
|
+
outcomeTracker?: OutcomeTracker;
|
|
693
|
+
constructor(outcomeTracker?: OutcomeTracker);
|
|
654
694
|
estimateTokens(text: string): number;
|
|
655
695
|
calculateCost(model: string, tokens: number, type?: "input" | "output"): number;
|
|
656
|
-
startConversation(sessionId: string, model?: string): void;
|
|
696
|
+
startConversation(sessionId: string, model?: string, variantId?: string): void;
|
|
657
697
|
recordQuery(sessionId: string, query: string): void;
|
|
658
698
|
recordResponse(sessionId: string, reply: string, latencyMs: number): void;
|
|
659
699
|
markResolved(sessionId: string): void;
|
|
@@ -718,6 +758,76 @@ declare class HandoffManager {
|
|
|
718
758
|
private dispatchWebhook;
|
|
719
759
|
}
|
|
720
760
|
|
|
761
|
+
/**
|
|
762
|
+
* Interface for pluggable session storage (Memory, Redis, File, DB).
|
|
763
|
+
*/
|
|
764
|
+
interface SessionStore {
|
|
765
|
+
get(sessionId: string): Promise<any | null>;
|
|
766
|
+
set(sessionId: string, data: any): Promise<void>;
|
|
767
|
+
delete(sessionId: string): Promise<void>;
|
|
768
|
+
clear(): Promise<void>;
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Default in-memory session store.
|
|
772
|
+
*/
|
|
773
|
+
declare class MemorySessionStore implements SessionStore {
|
|
774
|
+
private store;
|
|
775
|
+
get(sessionId: string): Promise<any | null>;
|
|
776
|
+
set(sessionId: string, data: any): Promise<void>;
|
|
777
|
+
delete(sessionId: string): Promise<void>;
|
|
778
|
+
clear(): Promise<void>;
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Pro-grade local file session store for persistence across restarts.
|
|
782
|
+
*/
|
|
783
|
+
declare class FileSessionStore implements SessionStore {
|
|
784
|
+
private dir;
|
|
785
|
+
constructor(dir?: string);
|
|
786
|
+
private getPath;
|
|
787
|
+
private ensureDir;
|
|
788
|
+
get(sessionId: string): Promise<any | null>;
|
|
789
|
+
set(sessionId: string, data: any): Promise<void>;
|
|
790
|
+
delete(sessionId: string): Promise<void>;
|
|
791
|
+
clear(): Promise<void>;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
interface RedactionRule {
|
|
795
|
+
name: string;
|
|
796
|
+
pattern: RegExp;
|
|
797
|
+
placeholder: string;
|
|
798
|
+
}
|
|
799
|
+
declare const DEFAULT_REDACTION_RULES: RedactionRule[];
|
|
800
|
+
declare class PIIRedactor {
|
|
801
|
+
private rules;
|
|
802
|
+
constructor(rules?: RedactionRule[]);
|
|
803
|
+
/** Scans text and replaces any matched patterns with their placeholders. */
|
|
804
|
+
redact(text: string): string;
|
|
805
|
+
/** Adds custom redaction rules to the engine. */
|
|
806
|
+
addRule(rule: RedactionRule): void;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
interface ExperimentVariant {
|
|
810
|
+
id: string;
|
|
811
|
+
weight: number;
|
|
812
|
+
config: Record<string, any>;
|
|
813
|
+
}
|
|
814
|
+
interface Experiment {
|
|
815
|
+
name: string;
|
|
816
|
+
variants: ExperimentVariant[];
|
|
817
|
+
}
|
|
818
|
+
declare class ExperimentManager {
|
|
819
|
+
private experiments;
|
|
820
|
+
constructor(experiments?: Experiment[]);
|
|
821
|
+
registerExperiment(exp: Experiment): void;
|
|
822
|
+
/**
|
|
823
|
+
* Assigns a user to a specific variant based on deterministic hashing of their sessionId.
|
|
824
|
+
* This guarantees 'sticky sessions' where the same user always gets the same A/B test variant.
|
|
825
|
+
*/
|
|
826
|
+
assignVariant(experimentName: string, sessionId: string): string | null;
|
|
827
|
+
/** Retrieves the variant config object for an assigned variant id. */
|
|
828
|
+
getVariantConfig(experimentName: string, variantId: string): Record<string, any> | null;
|
|
829
|
+
}
|
|
830
|
+
|
|
721
831
|
interface SupportBotConfig {
|
|
722
832
|
gateway: AIModelGateway;
|
|
723
833
|
companyName: string;
|
|
@@ -728,9 +838,12 @@ interface SupportBotConfig {
|
|
|
728
838
|
memory?: BaseMemoryStore;
|
|
729
839
|
telemetry?: AgentTelemetry;
|
|
730
840
|
customTools?: ToolContext[];
|
|
841
|
+
sessionStore?: SessionStore;
|
|
731
842
|
greeting?: string;
|
|
732
843
|
systemPrompt?: string;
|
|
733
844
|
maxIterations?: number;
|
|
845
|
+
enablePIIRedaction?: boolean;
|
|
846
|
+
experiments?: Experiment[];
|
|
734
847
|
}
|
|
735
848
|
type BotMiddleware = (ctx: {
|
|
736
849
|
sessionId: string;
|
|
@@ -747,12 +860,19 @@ declare class CustomerSupportBot {
|
|
|
747
860
|
private connector?;
|
|
748
861
|
knowledgeBase?: KnowledgeBase;
|
|
749
862
|
analytics: ConversationAnalytics;
|
|
863
|
+
outcomeTracker: OutcomeTracker;
|
|
864
|
+
sessionStore: SessionStore;
|
|
750
865
|
handoff?: HandoffManager;
|
|
866
|
+
piiRedactor?: PIIRedactor;
|
|
867
|
+
experimentManager?: ExperimentManager;
|
|
751
868
|
greeting: string;
|
|
869
|
+
private defaultSystemPrompt;
|
|
752
870
|
private middlewares;
|
|
753
871
|
constructor(config: SupportBotConfig);
|
|
754
872
|
/** Register a middleware function to run before every chat turn. */
|
|
755
873
|
use(middleware: BotMiddleware): void;
|
|
874
|
+
/** Record a business outcome for ROI tracking. */
|
|
875
|
+
trackOutcome(sessionId: string, type: string, valueUsd?: number, metadata?: Record<string, any>): void;
|
|
756
876
|
/** Process a customer message and return the bot's response. */
|
|
757
877
|
chat(sessionId: string, message: string): Promise<string>;
|
|
758
878
|
/** Start tracking analytics for a new session. */
|
|
@@ -803,4 +923,63 @@ declare function createChatHandler(bot: CustomerSupportBot): (req: any, res: any
|
|
|
803
923
|
*/
|
|
804
924
|
declare function startChatServer(config: ServerConfig): Promise<void>;
|
|
805
925
|
|
|
806
|
-
|
|
926
|
+
/**
|
|
927
|
+
* Base configuration for any channel adapter.
|
|
928
|
+
*/
|
|
929
|
+
interface ChannelConfig {
|
|
930
|
+
bot: CustomerSupportBot;
|
|
931
|
+
enabled?: boolean;
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Unified interface for messaging channels (Slack, Telegram, WhatsApp).
|
|
935
|
+
*/
|
|
936
|
+
declare abstract class ChannelAdapter {
|
|
937
|
+
protected bot: CustomerSupportBot;
|
|
938
|
+
constructor(config: ChannelConfig);
|
|
939
|
+
/** Initialize the channel listener/connection. */
|
|
940
|
+
abstract start(): Promise<void>;
|
|
941
|
+
/** Stop the channel listener. */
|
|
942
|
+
abstract stop(): Promise<void>;
|
|
943
|
+
/**
|
|
944
|
+
* Normalize incoming messages from different platforms
|
|
945
|
+
* and route them to the core bot brain.
|
|
946
|
+
*/
|
|
947
|
+
protected handleMessage(sessionId: string, text: string): Promise<string>;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* Pro-grade Slack Adapter (Skeleton).
|
|
952
|
+
* Standardized interface for Slack Bolt / Webhook integration.
|
|
953
|
+
*/
|
|
954
|
+
interface SlackConfig extends ChannelConfig {
|
|
955
|
+
signingSecret: string;
|
|
956
|
+
token: string;
|
|
957
|
+
appToken?: string;
|
|
958
|
+
}
|
|
959
|
+
declare class SlackAdapter extends ChannelAdapter {
|
|
960
|
+
constructor(config: SlackConfig);
|
|
961
|
+
start(): Promise<void>;
|
|
962
|
+
stop(): Promise<void>;
|
|
963
|
+
/** Handler for Slack events (to be used by Express middleware). */
|
|
964
|
+
handleEvent(event: any): Promise<void>;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Pro-grade Telegram Adapter.
|
|
969
|
+
* Uses the Telegram Bot API to connect your AI assistant to Telegram.
|
|
970
|
+
*/
|
|
971
|
+
interface TelegramConfig extends ChannelConfig {
|
|
972
|
+
token: string;
|
|
973
|
+
}
|
|
974
|
+
declare class TelegramAdapter extends ChannelAdapter {
|
|
975
|
+
private token;
|
|
976
|
+
private polling;
|
|
977
|
+
private offset;
|
|
978
|
+
constructor(config: TelegramConfig);
|
|
979
|
+
start(): Promise<void>;
|
|
980
|
+
stop(): Promise<void>;
|
|
981
|
+
private runPollingLoop;
|
|
982
|
+
private sendMessage;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
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, DEFAULT_REDACTION_RULES, EchoAI, EchoVoice, type EscalationTrigger, type Experiment, ExperimentManager, type ExperimentVariant, 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, PIIRedactor, PromptRegistry, PromptTemplate, PromptVersionError, ProviderDependencyError, type RedactionRule, 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.
|
|
@@ -626,6 +655,7 @@ interface ConversationRecord {
|
|
|
626
655
|
topQueries: string[];
|
|
627
656
|
responseTimes: number[];
|
|
628
657
|
model?: string;
|
|
658
|
+
variantId?: string;
|
|
629
659
|
}
|
|
630
660
|
interface AnalyticsSnapshot {
|
|
631
661
|
totalConversations: number;
|
|
@@ -636,6 +666,14 @@ interface AnalyticsSnapshot {
|
|
|
636
666
|
avgResponseTimeMs: number;
|
|
637
667
|
totalTokensUsed: number;
|
|
638
668
|
totalCostUsd: number;
|
|
669
|
+
totalValueGeneratedUsd: number;
|
|
670
|
+
roi: number;
|
|
671
|
+
variants?: Record<string, {
|
|
672
|
+
totalConversations: number;
|
|
673
|
+
totalValueGeneratedUsd: number;
|
|
674
|
+
resolutionRate: number;
|
|
675
|
+
roi: number;
|
|
676
|
+
}>;
|
|
639
677
|
avgTokensPerConversation: number;
|
|
640
678
|
avgCostPerConversation: number;
|
|
641
679
|
topQueries: {
|
|
@@ -651,9 +689,11 @@ declare const OPENAI_PRICING: Record<string, {
|
|
|
651
689
|
declare class ConversationAnalytics {
|
|
652
690
|
private records;
|
|
653
691
|
private queryFrequency;
|
|
692
|
+
outcomeTracker?: OutcomeTracker;
|
|
693
|
+
constructor(outcomeTracker?: OutcomeTracker);
|
|
654
694
|
estimateTokens(text: string): number;
|
|
655
695
|
calculateCost(model: string, tokens: number, type?: "input" | "output"): number;
|
|
656
|
-
startConversation(sessionId: string, model?: string): void;
|
|
696
|
+
startConversation(sessionId: string, model?: string, variantId?: string): void;
|
|
657
697
|
recordQuery(sessionId: string, query: string): void;
|
|
658
698
|
recordResponse(sessionId: string, reply: string, latencyMs: number): void;
|
|
659
699
|
markResolved(sessionId: string): void;
|
|
@@ -718,6 +758,76 @@ declare class HandoffManager {
|
|
|
718
758
|
private dispatchWebhook;
|
|
719
759
|
}
|
|
720
760
|
|
|
761
|
+
/**
|
|
762
|
+
* Interface for pluggable session storage (Memory, Redis, File, DB).
|
|
763
|
+
*/
|
|
764
|
+
interface SessionStore {
|
|
765
|
+
get(sessionId: string): Promise<any | null>;
|
|
766
|
+
set(sessionId: string, data: any): Promise<void>;
|
|
767
|
+
delete(sessionId: string): Promise<void>;
|
|
768
|
+
clear(): Promise<void>;
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Default in-memory session store.
|
|
772
|
+
*/
|
|
773
|
+
declare class MemorySessionStore implements SessionStore {
|
|
774
|
+
private store;
|
|
775
|
+
get(sessionId: string): Promise<any | null>;
|
|
776
|
+
set(sessionId: string, data: any): Promise<void>;
|
|
777
|
+
delete(sessionId: string): Promise<void>;
|
|
778
|
+
clear(): Promise<void>;
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Pro-grade local file session store for persistence across restarts.
|
|
782
|
+
*/
|
|
783
|
+
declare class FileSessionStore implements SessionStore {
|
|
784
|
+
private dir;
|
|
785
|
+
constructor(dir?: string);
|
|
786
|
+
private getPath;
|
|
787
|
+
private ensureDir;
|
|
788
|
+
get(sessionId: string): Promise<any | null>;
|
|
789
|
+
set(sessionId: string, data: any): Promise<void>;
|
|
790
|
+
delete(sessionId: string): Promise<void>;
|
|
791
|
+
clear(): Promise<void>;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
interface RedactionRule {
|
|
795
|
+
name: string;
|
|
796
|
+
pattern: RegExp;
|
|
797
|
+
placeholder: string;
|
|
798
|
+
}
|
|
799
|
+
declare const DEFAULT_REDACTION_RULES: RedactionRule[];
|
|
800
|
+
declare class PIIRedactor {
|
|
801
|
+
private rules;
|
|
802
|
+
constructor(rules?: RedactionRule[]);
|
|
803
|
+
/** Scans text and replaces any matched patterns with their placeholders. */
|
|
804
|
+
redact(text: string): string;
|
|
805
|
+
/** Adds custom redaction rules to the engine. */
|
|
806
|
+
addRule(rule: RedactionRule): void;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
interface ExperimentVariant {
|
|
810
|
+
id: string;
|
|
811
|
+
weight: number;
|
|
812
|
+
config: Record<string, any>;
|
|
813
|
+
}
|
|
814
|
+
interface Experiment {
|
|
815
|
+
name: string;
|
|
816
|
+
variants: ExperimentVariant[];
|
|
817
|
+
}
|
|
818
|
+
declare class ExperimentManager {
|
|
819
|
+
private experiments;
|
|
820
|
+
constructor(experiments?: Experiment[]);
|
|
821
|
+
registerExperiment(exp: Experiment): void;
|
|
822
|
+
/**
|
|
823
|
+
* Assigns a user to a specific variant based on deterministic hashing of their sessionId.
|
|
824
|
+
* This guarantees 'sticky sessions' where the same user always gets the same A/B test variant.
|
|
825
|
+
*/
|
|
826
|
+
assignVariant(experimentName: string, sessionId: string): string | null;
|
|
827
|
+
/** Retrieves the variant config object for an assigned variant id. */
|
|
828
|
+
getVariantConfig(experimentName: string, variantId: string): Record<string, any> | null;
|
|
829
|
+
}
|
|
830
|
+
|
|
721
831
|
interface SupportBotConfig {
|
|
722
832
|
gateway: AIModelGateway;
|
|
723
833
|
companyName: string;
|
|
@@ -728,9 +838,12 @@ interface SupportBotConfig {
|
|
|
728
838
|
memory?: BaseMemoryStore;
|
|
729
839
|
telemetry?: AgentTelemetry;
|
|
730
840
|
customTools?: ToolContext[];
|
|
841
|
+
sessionStore?: SessionStore;
|
|
731
842
|
greeting?: string;
|
|
732
843
|
systemPrompt?: string;
|
|
733
844
|
maxIterations?: number;
|
|
845
|
+
enablePIIRedaction?: boolean;
|
|
846
|
+
experiments?: Experiment[];
|
|
734
847
|
}
|
|
735
848
|
type BotMiddleware = (ctx: {
|
|
736
849
|
sessionId: string;
|
|
@@ -747,12 +860,19 @@ declare class CustomerSupportBot {
|
|
|
747
860
|
private connector?;
|
|
748
861
|
knowledgeBase?: KnowledgeBase;
|
|
749
862
|
analytics: ConversationAnalytics;
|
|
863
|
+
outcomeTracker: OutcomeTracker;
|
|
864
|
+
sessionStore: SessionStore;
|
|
750
865
|
handoff?: HandoffManager;
|
|
866
|
+
piiRedactor?: PIIRedactor;
|
|
867
|
+
experimentManager?: ExperimentManager;
|
|
751
868
|
greeting: string;
|
|
869
|
+
private defaultSystemPrompt;
|
|
752
870
|
private middlewares;
|
|
753
871
|
constructor(config: SupportBotConfig);
|
|
754
872
|
/** Register a middleware function to run before every chat turn. */
|
|
755
873
|
use(middleware: BotMiddleware): void;
|
|
874
|
+
/** Record a business outcome for ROI tracking. */
|
|
875
|
+
trackOutcome(sessionId: string, type: string, valueUsd?: number, metadata?: Record<string, any>): void;
|
|
756
876
|
/** Process a customer message and return the bot's response. */
|
|
757
877
|
chat(sessionId: string, message: string): Promise<string>;
|
|
758
878
|
/** Start tracking analytics for a new session. */
|
|
@@ -803,4 +923,63 @@ declare function createChatHandler(bot: CustomerSupportBot): (req: any, res: any
|
|
|
803
923
|
*/
|
|
804
924
|
declare function startChatServer(config: ServerConfig): Promise<void>;
|
|
805
925
|
|
|
806
|
-
|
|
926
|
+
/**
|
|
927
|
+
* Base configuration for any channel adapter.
|
|
928
|
+
*/
|
|
929
|
+
interface ChannelConfig {
|
|
930
|
+
bot: CustomerSupportBot;
|
|
931
|
+
enabled?: boolean;
|
|
932
|
+
}
|
|
933
|
+
/**
|
|
934
|
+
* Unified interface for messaging channels (Slack, Telegram, WhatsApp).
|
|
935
|
+
*/
|
|
936
|
+
declare abstract class ChannelAdapter {
|
|
937
|
+
protected bot: CustomerSupportBot;
|
|
938
|
+
constructor(config: ChannelConfig);
|
|
939
|
+
/** Initialize the channel listener/connection. */
|
|
940
|
+
abstract start(): Promise<void>;
|
|
941
|
+
/** Stop the channel listener. */
|
|
942
|
+
abstract stop(): Promise<void>;
|
|
943
|
+
/**
|
|
944
|
+
* Normalize incoming messages from different platforms
|
|
945
|
+
* and route them to the core bot brain.
|
|
946
|
+
*/
|
|
947
|
+
protected handleMessage(sessionId: string, text: string): Promise<string>;
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* Pro-grade Slack Adapter (Skeleton).
|
|
952
|
+
* Standardized interface for Slack Bolt / Webhook integration.
|
|
953
|
+
*/
|
|
954
|
+
interface SlackConfig extends ChannelConfig {
|
|
955
|
+
signingSecret: string;
|
|
956
|
+
token: string;
|
|
957
|
+
appToken?: string;
|
|
958
|
+
}
|
|
959
|
+
declare class SlackAdapter extends ChannelAdapter {
|
|
960
|
+
constructor(config: SlackConfig);
|
|
961
|
+
start(): Promise<void>;
|
|
962
|
+
stop(): Promise<void>;
|
|
963
|
+
/** Handler for Slack events (to be used by Express middleware). */
|
|
964
|
+
handleEvent(event: any): Promise<void>;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Pro-grade Telegram Adapter.
|
|
969
|
+
* Uses the Telegram Bot API to connect your AI assistant to Telegram.
|
|
970
|
+
*/
|
|
971
|
+
interface TelegramConfig extends ChannelConfig {
|
|
972
|
+
token: string;
|
|
973
|
+
}
|
|
974
|
+
declare class TelegramAdapter extends ChannelAdapter {
|
|
975
|
+
private token;
|
|
976
|
+
private polling;
|
|
977
|
+
private offset;
|
|
978
|
+
constructor(config: TelegramConfig);
|
|
979
|
+
start(): Promise<void>;
|
|
980
|
+
stop(): Promise<void>;
|
|
981
|
+
private runPollingLoop;
|
|
982
|
+
private sendMessage;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
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, DEFAULT_REDACTION_RULES, EchoAI, EchoVoice, type EscalationTrigger, type Experiment, ExperimentManager, type ExperimentVariant, 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, PIIRedactor, PromptRegistry, PromptTemplate, PromptVersionError, ProviderDependencyError, type RedactionRule, 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 };
|