catalist-support-agent 1.0.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/dist/admin-portal.d.ts +43 -0
- package/dist/admin-portal.d.ts.map +1 -0
- package/dist/admin-portal.js +166 -0
- package/dist/admin-portal.js.map +1 -0
- package/dist/analysis/entities.d.ts +73 -0
- package/dist/analysis/entities.d.ts.map +1 -0
- package/dist/analysis/entities.js +378 -0
- package/dist/analysis/entities.js.map +1 -0
- package/dist/analysis/index.d.ts +44 -0
- package/dist/analysis/index.d.ts.map +1 -0
- package/dist/analysis/index.js +243 -0
- package/dist/analysis/index.js.map +1 -0
- package/dist/analysis/intent.d.ts +49 -0
- package/dist/analysis/intent.d.ts.map +1 -0
- package/dist/analysis/intent.js +320 -0
- package/dist/analysis/intent.js.map +1 -0
- package/dist/analysis/sentiment.d.ts +57 -0
- package/dist/analysis/sentiment.d.ts.map +1 -0
- package/dist/analysis/sentiment.js +351 -0
- package/dist/analysis/sentiment.js.map +1 -0
- package/dist/brand/compliance.d.ts +122 -0
- package/dist/brand/compliance.d.ts.map +1 -0
- package/dist/brand/compliance.js +378 -0
- package/dist/brand/compliance.js.map +1 -0
- package/dist/brand/forbidden-terms.d.ts +99 -0
- package/dist/brand/forbidden-terms.d.ts.map +1 -0
- package/dist/brand/forbidden-terms.js +265 -0
- package/dist/brand/forbidden-terms.js.map +1 -0
- package/dist/brand/index.d.ts +10 -0
- package/dist/brand/index.d.ts.map +1 -0
- package/dist/brand/index.js +12 -0
- package/dist/brand/index.js.map +1 -0
- package/dist/config.d.ts +325 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +492 -0
- package/dist/config.js.map +1 -0
- package/dist/delivery/index.d.ts +84 -0
- package/dist/delivery/index.d.ts.map +1 -0
- package/dist/delivery/index.js +435 -0
- package/dist/delivery/index.js.map +1 -0
- package/dist/embeddings/cache.d.ts +96 -0
- package/dist/embeddings/cache.d.ts.map +1 -0
- package/dist/embeddings/cache.js +193 -0
- package/dist/embeddings/cache.js.map +1 -0
- package/dist/embeddings/index.d.ts +152 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +337 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/embeddings/openai-client.d.ts +67 -0
- package/dist/embeddings/openai-client.d.ts.map +1 -0
- package/dist/embeddings/openai-client.js +190 -0
- package/dist/embeddings/openai-client.js.map +1 -0
- package/dist/errors.d.ts +302 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +508 -0
- package/dist/errors.js.map +1 -0
- package/dist/escalation/index.d.ts +93 -0
- package/dist/escalation/index.d.ts.map +1 -0
- package/dist/escalation/index.js +436 -0
- package/dist/escalation/index.js.map +1 -0
- package/dist/extraction/deduplication.d.ts +97 -0
- package/dist/extraction/deduplication.d.ts.map +1 -0
- package/dist/extraction/deduplication.js +271 -0
- package/dist/extraction/deduplication.js.map +1 -0
- package/dist/extraction/gmail-extractor.d.ts +160 -0
- package/dist/extraction/gmail-extractor.d.ts.map +1 -0
- package/dist/extraction/gmail-extractor.js +396 -0
- package/dist/extraction/gmail-extractor.js.map +1 -0
- package/dist/extraction/gmail-token-manager.d.ts +36 -0
- package/dist/extraction/gmail-token-manager.d.ts.map +1 -0
- package/dist/extraction/gmail-token-manager.js +146 -0
- package/dist/extraction/gmail-token-manager.js.map +1 -0
- package/dist/extraction/index.d.ts +13 -0
- package/dist/extraction/index.d.ts.map +1 -0
- package/dist/extraction/index.js +20 -0
- package/dist/extraction/index.js.map +1 -0
- package/dist/extraction/pii-handler.d.ts +100 -0
- package/dist/extraction/pii-handler.d.ts.map +1 -0
- package/dist/extraction/pii-handler.js +295 -0
- package/dist/extraction/pii-handler.js.map +1 -0
- package/dist/extraction/pipeline.d.ts +94 -0
- package/dist/extraction/pipeline.d.ts.map +1 -0
- package/dist/extraction/pipeline.js +380 -0
- package/dist/extraction/pipeline.js.map +1 -0
- package/dist/extraction/quality-filter.d.ts +99 -0
- package/dist/extraction/quality-filter.d.ts.map +1 -0
- package/dist/extraction/quality-filter.js +370 -0
- package/dist/extraction/quality-filter.js.map +1 -0
- package/dist/extraction/rate-limiter.d.ts +90 -0
- package/dist/extraction/rate-limiter.d.ts.map +1 -0
- package/dist/extraction/rate-limiter.js +242 -0
- package/dist/extraction/rate-limiter.js.map +1 -0
- package/dist/extraction/state-manager.d.ts +126 -0
- package/dist/extraction/state-manager.d.ts.map +1 -0
- package/dist/extraction/state-manager.js +344 -0
- package/dist/extraction/state-manager.js.map +1 -0
- package/dist/generation/index.d.ts +75 -0
- package/dist/generation/index.d.ts.map +1 -0
- package/dist/generation/index.js +641 -0
- package/dist/generation/index.js.map +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +233 -0
- package/dist/index.js.map +1 -0
- package/dist/intake/index.d.ts +15 -0
- package/dist/intake/index.d.ts.map +1 -0
- package/dist/intake/index.js +19 -0
- package/dist/intake/index.js.map +1 -0
- package/dist/intake/normalizer.d.ts +163 -0
- package/dist/intake/normalizer.d.ts.map +1 -0
- package/dist/intake/normalizer.js +309 -0
- package/dist/intake/normalizer.js.map +1 -0
- package/dist/intake/postmark.d.ts +72 -0
- package/dist/intake/postmark.d.ts.map +1 -0
- package/dist/intake/postmark.js +276 -0
- package/dist/intake/postmark.js.map +1 -0
- package/dist/intake/slack.d.ts +106 -0
- package/dist/intake/slack.d.ts.map +1 -0
- package/dist/intake/slack.js +378 -0
- package/dist/intake/slack.js.map +1 -0
- package/dist/intake/twilio.d.ts +86 -0
- package/dist/intake/twilio.d.ts.map +1 -0
- package/dist/intake/twilio.js +283 -0
- package/dist/intake/twilio.js.map +1 -0
- package/dist/knowledge/index.d.ts +100 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +516 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/invoice-resolver.d.ts +62 -0
- package/dist/knowledge/invoice-resolver.d.ts.map +1 -0
- package/dist/knowledge/invoice-resolver.js +267 -0
- package/dist/knowledge/invoice-resolver.js.map +1 -0
- package/dist/types.d.ts +535 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +48 -0
- package/dist/types.js.map +1 -0
- package/ga-service-account.json +13 -0
- package/gmail-knowledge-migration.sql +149 -0
- package/nul +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Catalist Support AI Agent SDK
|
|
3
|
+
*
|
|
4
|
+
* Production-grade support agent that autonomously handles customer
|
|
5
|
+
* communications across email, SMS, and Slack while strictly enforcing
|
|
6
|
+
* Catalist's brand positioning as an "AI-native B2B marketplace."
|
|
7
|
+
*
|
|
8
|
+
* Key Capabilities:
|
|
9
|
+
* - Multi-channel message intake (Postmark, Twilio, Slack)
|
|
10
|
+
* - Intent classification and sentiment analysis
|
|
11
|
+
* - Knowledge retrieval from customer and product data
|
|
12
|
+
* - Brand-compliant response generation
|
|
13
|
+
* - Automatic escalation for sensitive topics
|
|
14
|
+
* - Multi-channel delivery with retry logic
|
|
15
|
+
*
|
|
16
|
+
* Critical Brand Constraint:
|
|
17
|
+
* This agent operates exclusively in "public brand mode" - any request
|
|
18
|
+
* requiring Amazon/Walmart-specific language, ungating assistance, or
|
|
19
|
+
* competitor pricing discussions is automatically escalated to humans.
|
|
20
|
+
*/
|
|
21
|
+
export { config, createConfig, getAllForbiddenTerms, isChannelEnabled, getEscalationChannels, getSlaTarget, validateAuthentication, classifyConfidence, shouldEscalateByConfidence, isAutonomousResponseAllowed, type Config, type CreateConfigOptions, type AuthenticationMode, type AuthenticationStatus, type ConfidenceLevel, } from './config.js';
|
|
22
|
+
export { type ConversationId, type MessageId, type CustomerId, type EscalationId, type ResponseId, type DeliveryId, createConversationId, createMessageId, createCustomerId, createEscalationId, createResponseId, createDeliveryId, type SupportChannel, type MessageDirection, type ConversationState, type DeliveryStatus, type BrandComplianceStatus, type IntentCategory, type SentimentCategory, type UrgencyLevel, type EscalationTrigger, type EscalationSeverity, type BounceType, type ResolutionType, getConversationStatus, isDeliverySuccessful, canRetryDelivery, isBrandCompliant, type InboundMessage, type SenderInfo, type ChannelMetadata, type EmailMetadata, type SmsMetadata, type SlackMetadata, type Attachment, type AnalysisResult, type IntentClassification, type SentimentAnalysis, type ExtractedEntities, type ExtractedDate, type MonetaryAmount, type KnowledgeContext, type CustomerContext, type ProductContext, type OrderContext, type InvoiceContext, type ResolvedInvoice, type PolicyContext, type SimilarConversation, type ResponseTemplate, type GeneratedResponse, type ChannelFormatting, type Citation, type EscalationContext, type EscalationResult, type EscalationDelivery, type Conversation, type ConversationRecord, type MessageRecord, type AnalysisRecord, type ResponseRecord, type EscalationRecord, type DeliveryRecord, } from './types.js';
|
|
23
|
+
export { SupportAgentError, IntakeError, WebhookValidationError, DuplicateMessageError, AnalysisError, IntentClassificationError, KnowledgeError, CustomerNotFoundError, GenerationError, ResponseQualityError, DeliveryError, PermanentDeliveryFailure, EscalationError, AllEscalationChannelsFailedError, BrandComplianceError, ForbiddenTermsDetectedError, DatabaseError, EmbeddingError, TimeoutError, isSupportAgentError, isIntakeError, isAnalysisError, isKnowledgeError, isGenerationError, isDeliveryError, isEscalationError, isBrandComplianceError, isDatabaseError, isTimeoutError, isEmbeddingError, isRecoverableError, toSupportAgentError, getErrorMessage, shouldRetry, requiresImmediateEscalation, type DeliveryChannel, type EscalationChannel, type EmbeddingErrorType, } from './errors.js';
|
|
24
|
+
export { ForbiddenTermsDetector, BrandTerminologyEnforcer, BrandComplianceChecker, performBrandTest, checkBrandCompliance, scanMessageContent, createComplianceStatusFromScan, requiresEscalationForForbiddenTerms, validateResponseForBrand, applyBrandTerminologyCorrections, getBrandVoiceGuidelines, getDefaultDetector, getDefaultChecker, containsForbiddenTerms, scanForForbiddenTerms, scanForForbiddenTermsDetailed, type ForbiddenTermMatch, type ForbiddenTermsScanResult, type TerminologyCorrection, type BrandComplianceCheckResult, type ResponseValidationResult, } from './brand/index.js';
|
|
25
|
+
export { MessageNormalizer, getMessageNormalizer, normalizePostmarkEmail, normalizeTwilioSms, normalizeSlackMessage, generateContentHash, extractThreadIdentifier, getSenderIdentifier, normalizePhoneNumber, validateMessageContent, scanAndAnnotateMessage, type PostmarkInboundEmail, type TwilioInboundSms, type SlackMessageEvent, type SlackEventWrapper, validatePostmarkWebhook, processPostmarkEmail, handlePostmarkInbound, isAutoReply, isLikelySpam, classifyEmail, extractEmailThread, extractQuotedContent, type PostmarkWebhookPayload, type PostmarkProcessResult, validateTwilioSignature, validateTwilioWebhook, parseTwilioBody, processTwilioSms, handleTwilioInbound, isOptOutMessage, isHelpRequest, classifySms, hasMmsAttachments, extractMmsMedia, extractCountryCode, isNorthAmericanNumber, generateTwimlResponse, generateOptOutResponse, generateHelpResponse, type TwilioProcessResult, validateSlackSignature, validateSlackWebhook, isUrlVerification, isMessageEvent, isDirectMessage, isBotMessage, processSlackMessage, handleSlackEvent, extractMentions, extractChannelReferences, extractLinks, cleanSlackText, isB2BCustomerChannel, shouldProcessSlackMessage, formatForSlack, generateSlackBlocks, type SlackProcessResult, type SlackUrlVerification, } from './intake/index.js';
|
|
26
|
+
export { analyzeMessage, type AnalysisPipelineOptions, IntentClassificationService, getIntentClassificationService, classifyIntent, classifyIntentHeuristic, getIntentDescription, isHighPriorityIntent, isAutonomouslyHandleableIntent, SentimentAnalysisService, getSentimentAnalysisService, analyzeSentiment, analyzeSentimentHeuristic, shouldConsiderEscalationBySentiment, getUrgencyScore, combineUrgency, EntityExtractionService, getEntityExtractionService, extractEntities, extractEntitiesRegex, mergeEntities, hasOrderReference, hasProductReference, getPrimaryOrderNumber, getTotalAmount, } from './analysis/index.js';
|
|
27
|
+
export { KnowledgeRetrievalService, getKnowledgeRetrievalService, getKnowledgeService, retrieveKnowledge, hassufficientContext, calculateContextConfidence, } from './knowledge/index.js';
|
|
28
|
+
export { ResponseGenerationService, getResponseGenerationService, generateResponse, humanizeResponse, isResponseReadyToSend, } from './generation/index.js';
|
|
29
|
+
export { EscalationService, getEscalationService, buildEscalationContext, shouldEscalate, containsHumanRequest, } from './escalation/index.js';
|
|
30
|
+
export { DeliveryService, getDeliveryService, type RecipientInfo, type DeliveryResult, } from './delivery/index.js';
|
|
31
|
+
export declare const VERSION = "1.0.0";
|
|
32
|
+
export declare const SDK_NAME = "catalist-support-agent";
|
|
33
|
+
import type { InboundMessage, AnalysisResult, GeneratedResponse, KnowledgeContext, ConversationId } from './types.js';
|
|
34
|
+
/**
|
|
35
|
+
* Result from processing a message through the support agent pipeline
|
|
36
|
+
*/
|
|
37
|
+
export interface ProcessResult {
|
|
38
|
+
/** The analysis results from triage */
|
|
39
|
+
analysis: AnalysisResult;
|
|
40
|
+
/** The generated response (if not escalated) */
|
|
41
|
+
response?: GeneratedResponse;
|
|
42
|
+
/** The knowledge context retrieved */
|
|
43
|
+
knowledge: KnowledgeContext;
|
|
44
|
+
/** Whether the message was escalated to a human */
|
|
45
|
+
escalated: boolean;
|
|
46
|
+
/** Reason for escalation (if applicable) */
|
|
47
|
+
escalationReason?: string;
|
|
48
|
+
/** Total processing time in milliseconds */
|
|
49
|
+
processingTimeMs: number;
|
|
50
|
+
/** Conversation ID for this interaction */
|
|
51
|
+
conversationId: ConversationId;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Options for processing a message
|
|
55
|
+
*/
|
|
56
|
+
export interface ProcessMessageOptions {
|
|
57
|
+
/** Run in shadow mode - generate response but don't send */
|
|
58
|
+
shadowMode?: boolean;
|
|
59
|
+
/** Override the target channel for response formatting */
|
|
60
|
+
targetChannel?: 'email' | 'sms' | 'slack';
|
|
61
|
+
/** Skip knowledge retrieval (use minimal context) */
|
|
62
|
+
skipKnowledge?: boolean;
|
|
63
|
+
/** Force escalation regardless of analysis */
|
|
64
|
+
forceEscalation?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Catalist Support Agent
|
|
68
|
+
*
|
|
69
|
+
* The main agent class that orchestrates the full support pipeline:
|
|
70
|
+
* 1. Message intake and normalization
|
|
71
|
+
* 2. Intent classification and sentiment analysis
|
|
72
|
+
* 3. Knowledge retrieval (customer, orders, products)
|
|
73
|
+
* 4. Response generation with brand compliance
|
|
74
|
+
* 5. Escalation handling
|
|
75
|
+
* 6. Multi-channel delivery
|
|
76
|
+
*/
|
|
77
|
+
export declare class SupportAgent {
|
|
78
|
+
private initialized;
|
|
79
|
+
/**
|
|
80
|
+
* Initialize the agent (pre-warm services, validate config)
|
|
81
|
+
*/
|
|
82
|
+
initialize(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Process an inbound message through the full support pipeline
|
|
85
|
+
*/
|
|
86
|
+
processMessage(message: InboundMessage, options?: ProcessMessageOptions): Promise<ProcessResult>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the singleton SupportAgent instance
|
|
90
|
+
*/
|
|
91
|
+
export declare function getSupportAgent(): SupportAgent;
|
|
92
|
+
/**
|
|
93
|
+
* Create a new SupportAgent instance (not singleton)
|
|
94
|
+
*/
|
|
95
|
+
export declare function createSupportAgent(): SupportAgent;
|
|
96
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAMH,OAAO,EACL,MAAM,EACN,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,EAC1B,2BAA2B,EAC3B,KAAK,MAAM,EACX,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,eAAe,GACrB,MAAM,aAAa,CAAC;AAMrB,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,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I,YAAY,CAEjD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Catalist Support AI Agent SDK
|
|
3
|
+
*
|
|
4
|
+
* Production-grade support agent that autonomously handles customer
|
|
5
|
+
* communications across email, SMS, and Slack while strictly enforcing
|
|
6
|
+
* Catalist's brand positioning as an "AI-native B2B marketplace."
|
|
7
|
+
*
|
|
8
|
+
* Key Capabilities:
|
|
9
|
+
* - Multi-channel message intake (Postmark, Twilio, Slack)
|
|
10
|
+
* - Intent classification and sentiment analysis
|
|
11
|
+
* - Knowledge retrieval from customer and product data
|
|
12
|
+
* - Brand-compliant response generation
|
|
13
|
+
* - Automatic escalation for sensitive topics
|
|
14
|
+
* - Multi-channel delivery with retry logic
|
|
15
|
+
*
|
|
16
|
+
* Critical Brand Constraint:
|
|
17
|
+
* This agent operates exclusively in "public brand mode" - any request
|
|
18
|
+
* requiring Amazon/Walmart-specific language, ungating assistance, or
|
|
19
|
+
* competitor pricing discussions is automatically escalated to humans.
|
|
20
|
+
*/
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// Configuration
|
|
23
|
+
// =============================================================================
|
|
24
|
+
export { config, createConfig, getAllForbiddenTerms, isChannelEnabled, getEscalationChannels, getSlaTarget, validateAuthentication, classifyConfidence, shouldEscalateByConfidence, isAutonomousResponseAllowed, } from './config.js';
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// Types
|
|
27
|
+
// =============================================================================
|
|
28
|
+
export { createConversationId, createMessageId, createCustomerId, createEscalationId, createResponseId, createDeliveryId,
|
|
29
|
+
// Helper functions
|
|
30
|
+
getConversationStatus, isDeliverySuccessful, canRetryDelivery, isBrandCompliant, } from './types.js';
|
|
31
|
+
// =============================================================================
|
|
32
|
+
// Errors
|
|
33
|
+
// =============================================================================
|
|
34
|
+
export { SupportAgentError, IntakeError, WebhookValidationError, DuplicateMessageError, AnalysisError, IntentClassificationError, KnowledgeError, CustomerNotFoundError, GenerationError, ResponseQualityError, DeliveryError, PermanentDeliveryFailure, EscalationError, AllEscalationChannelsFailedError, BrandComplianceError, ForbiddenTermsDetectedError, DatabaseError, EmbeddingError, TimeoutError, isSupportAgentError, isIntakeError, isAnalysisError, isKnowledgeError, isGenerationError, isDeliveryError, isEscalationError, isBrandComplianceError, isDatabaseError, isTimeoutError, isEmbeddingError, isRecoverableError, toSupportAgentError, getErrorMessage, shouldRetry, requiresImmediateEscalation, } from './errors.js';
|
|
35
|
+
// =============================================================================
|
|
36
|
+
// Brand Compliance
|
|
37
|
+
// =============================================================================
|
|
38
|
+
export { ForbiddenTermsDetector, BrandTerminologyEnforcer, BrandComplianceChecker, performBrandTest, checkBrandCompliance, scanMessageContent, createComplianceStatusFromScan, requiresEscalationForForbiddenTerms, validateResponseForBrand, applyBrandTerminologyCorrections, getBrandVoiceGuidelines, getDefaultDetector, getDefaultChecker, containsForbiddenTerms, scanForForbiddenTerms, scanForForbiddenTermsDetailed, } from './brand/index.js';
|
|
39
|
+
// =============================================================================
|
|
40
|
+
// Intake Pipeline
|
|
41
|
+
// =============================================================================
|
|
42
|
+
export {
|
|
43
|
+
// Message Normalization
|
|
44
|
+
MessageNormalizer, getMessageNormalizer, normalizePostmarkEmail, normalizeTwilioSms, normalizeSlackMessage, generateContentHash, extractThreadIdentifier, getSenderIdentifier, normalizePhoneNumber, validateMessageContent, scanAndAnnotateMessage,
|
|
45
|
+
// Postmark (Email)
|
|
46
|
+
validatePostmarkWebhook, processPostmarkEmail, handlePostmarkInbound, isAutoReply, isLikelySpam, classifyEmail, extractEmailThread, extractQuotedContent,
|
|
47
|
+
// Twilio (SMS)
|
|
48
|
+
validateTwilioSignature, validateTwilioWebhook, parseTwilioBody, processTwilioSms, handleTwilioInbound, isOptOutMessage, isHelpRequest, classifySms, hasMmsAttachments, extractMmsMedia, extractCountryCode, isNorthAmericanNumber, generateTwimlResponse, generateOptOutResponse, generateHelpResponse,
|
|
49
|
+
// Slack
|
|
50
|
+
validateSlackSignature, validateSlackWebhook, isUrlVerification, isMessageEvent, isDirectMessage, isBotMessage, processSlackMessage, handleSlackEvent, extractMentions, extractChannelReferences, extractLinks, cleanSlackText, isB2BCustomerChannel, shouldProcessSlackMessage, formatForSlack, generateSlackBlocks, } from './intake/index.js';
|
|
51
|
+
// =============================================================================
|
|
52
|
+
// Analysis Pipeline
|
|
53
|
+
// =============================================================================
|
|
54
|
+
export {
|
|
55
|
+
// Main Pipeline
|
|
56
|
+
analyzeMessage,
|
|
57
|
+
// Intent Classification
|
|
58
|
+
IntentClassificationService, getIntentClassificationService, classifyIntent, classifyIntentHeuristic, getIntentDescription, isHighPriorityIntent, isAutonomouslyHandleableIntent,
|
|
59
|
+
// Sentiment Analysis
|
|
60
|
+
SentimentAnalysisService, getSentimentAnalysisService, analyzeSentiment, analyzeSentimentHeuristic, shouldConsiderEscalationBySentiment, getUrgencyScore, combineUrgency,
|
|
61
|
+
// Entity Extraction
|
|
62
|
+
EntityExtractionService, getEntityExtractionService, extractEntities, extractEntitiesRegex, mergeEntities, hasOrderReference, hasProductReference, getPrimaryOrderNumber, getTotalAmount, } from './analysis/index.js';
|
|
63
|
+
// =============================================================================
|
|
64
|
+
// Knowledge Retrieval
|
|
65
|
+
// =============================================================================
|
|
66
|
+
export { KnowledgeRetrievalService, getKnowledgeRetrievalService, getKnowledgeService, retrieveKnowledge, hassufficientContext, calculateContextConfidence, } from './knowledge/index.js';
|
|
67
|
+
// =============================================================================
|
|
68
|
+
// Response Generation
|
|
69
|
+
// =============================================================================
|
|
70
|
+
export { ResponseGenerationService, getResponseGenerationService, generateResponse, humanizeResponse, isResponseReadyToSend, } from './generation/index.js';
|
|
71
|
+
// =============================================================================
|
|
72
|
+
// Escalation System
|
|
73
|
+
// =============================================================================
|
|
74
|
+
export { EscalationService, getEscalationService, buildEscalationContext, shouldEscalate, containsHumanRequest, } from './escalation/index.js';
|
|
75
|
+
// =============================================================================
|
|
76
|
+
// Delivery Pipeline
|
|
77
|
+
// =============================================================================
|
|
78
|
+
export { DeliveryService, getDeliveryService, } from './delivery/index.js';
|
|
79
|
+
// =============================================================================
|
|
80
|
+
// Version Info
|
|
81
|
+
// =============================================================================
|
|
82
|
+
export const VERSION = '1.0.0';
|
|
83
|
+
export const SDK_NAME = 'catalist-support-agent';
|
|
84
|
+
import { createConversationId } from './types.js';
|
|
85
|
+
import { config } from './config.js';
|
|
86
|
+
import { analyzeMessage } from './analysis/index.js';
|
|
87
|
+
import { retrieveKnowledge } from './knowledge/index.js';
|
|
88
|
+
import { generateResponse as doGenerateResponse } from './generation/index.js';
|
|
89
|
+
import { shouldEscalate, buildEscalationContext } from './escalation/index.js';
|
|
90
|
+
/**
|
|
91
|
+
* Helper to create an empty knowledge context for fallback scenarios
|
|
92
|
+
*/
|
|
93
|
+
function createEmptyKnowledgeContext() {
|
|
94
|
+
return {
|
|
95
|
+
assembledAt: new Date().toISOString(),
|
|
96
|
+
confidenceScores: {
|
|
97
|
+
customerData: 0,
|
|
98
|
+
productData: 0,
|
|
99
|
+
policyData: 0,
|
|
100
|
+
similarConversations: 0,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Catalist Support Agent
|
|
106
|
+
*
|
|
107
|
+
* The main agent class that orchestrates the full support pipeline:
|
|
108
|
+
* 1. Message intake and normalization
|
|
109
|
+
* 2. Intent classification and sentiment analysis
|
|
110
|
+
* 3. Knowledge retrieval (customer, orders, products)
|
|
111
|
+
* 4. Response generation with brand compliance
|
|
112
|
+
* 5. Escalation handling
|
|
113
|
+
* 6. Multi-channel delivery
|
|
114
|
+
*/
|
|
115
|
+
export class SupportAgent {
|
|
116
|
+
initialized = false;
|
|
117
|
+
/**
|
|
118
|
+
* Initialize the agent (pre-warm services, validate config)
|
|
119
|
+
*/
|
|
120
|
+
async initialize() {
|
|
121
|
+
// Validate required configuration
|
|
122
|
+
if (!config.claude.apiKey) {
|
|
123
|
+
console.warn('[SupportAgent] ANTHROPIC_API_KEY not configured - response generation will fail');
|
|
124
|
+
}
|
|
125
|
+
if (!config.supabase.url || !config.supabase.serviceRoleKey) {
|
|
126
|
+
console.warn('[SupportAgent] Supabase not configured - knowledge retrieval will fail');
|
|
127
|
+
}
|
|
128
|
+
this.initialized = true;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Process an inbound message through the full support pipeline
|
|
132
|
+
*/
|
|
133
|
+
async processMessage(message, options = {}) {
|
|
134
|
+
const startTime = Date.now();
|
|
135
|
+
// Ensure conversation ID exists
|
|
136
|
+
const conversationId = message.conversationId ?? createConversationId(`conv-${Date.now()}`);
|
|
137
|
+
// 1. Analyze the message (intent, sentiment, entities)
|
|
138
|
+
const analysis = await analyzeMessage(message);
|
|
139
|
+
// 2. Check if we should escalate before proceeding
|
|
140
|
+
const escalationCheck = shouldEscalate(analysis);
|
|
141
|
+
if (options.forceEscalation || escalationCheck.required) {
|
|
142
|
+
const emptyKnowledge = createEmptyKnowledgeContext();
|
|
143
|
+
const trigger = escalationCheck.trigger ?? 'human_takeover';
|
|
144
|
+
const severity = escalationCheck.severity ?? 'medium';
|
|
145
|
+
const reason = escalationCheck.reasons.join('; ') || 'Forced escalation';
|
|
146
|
+
const escalationContext = buildEscalationContext(message, analysis, emptyKnowledge, trigger, severity, reason);
|
|
147
|
+
return {
|
|
148
|
+
analysis,
|
|
149
|
+
knowledge: emptyKnowledge,
|
|
150
|
+
escalated: true,
|
|
151
|
+
escalationReason: escalationContext.trigger,
|
|
152
|
+
processingTimeMs: Date.now() - startTime,
|
|
153
|
+
conversationId,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
// 3. Retrieve knowledge context
|
|
157
|
+
let knowledge = createEmptyKnowledgeContext();
|
|
158
|
+
if (!options.skipKnowledge) {
|
|
159
|
+
try {
|
|
160
|
+
knowledge = await retrieveKnowledge(message, analysis);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
console.warn('[SupportAgent] Knowledge retrieval failed:', error);
|
|
164
|
+
// Continue with minimal context
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
// 4. Check for escalation based on knowledge context (e.g., VIP customer, sensitive issue)
|
|
168
|
+
const postKnowledgeCheck = shouldEscalate(analysis);
|
|
169
|
+
if (postKnowledgeCheck.required) {
|
|
170
|
+
const trigger = postKnowledgeCheck.trigger ?? 'customer_request';
|
|
171
|
+
const severity = postKnowledgeCheck.severity ?? 'medium';
|
|
172
|
+
const reason = postKnowledgeCheck.reasons.join('; ') || 'Post-knowledge escalation';
|
|
173
|
+
const escalationContext = buildEscalationContext(message, analysis, knowledge, trigger, severity, reason);
|
|
174
|
+
return {
|
|
175
|
+
analysis,
|
|
176
|
+
knowledge,
|
|
177
|
+
escalated: true,
|
|
178
|
+
escalationReason: escalationContext.trigger,
|
|
179
|
+
processingTimeMs: Date.now() - startTime,
|
|
180
|
+
conversationId,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
// 5. Generate response
|
|
184
|
+
let response;
|
|
185
|
+
try {
|
|
186
|
+
response = await doGenerateResponse(message, analysis, knowledge, {
|
|
187
|
+
targetChannel: options.targetChannel ?? message.channel,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
console.error('[SupportAgent] Response generation failed:', error);
|
|
192
|
+
// Escalate on generation failure
|
|
193
|
+
return {
|
|
194
|
+
analysis,
|
|
195
|
+
knowledge,
|
|
196
|
+
escalated: true,
|
|
197
|
+
escalationReason: `generation_failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
198
|
+
processingTimeMs: Date.now() - startTime,
|
|
199
|
+
conversationId,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
// 6. In shadow mode, we don't deliver - just return the result
|
|
203
|
+
// In production mode, delivery would happen here
|
|
204
|
+
return {
|
|
205
|
+
analysis,
|
|
206
|
+
response,
|
|
207
|
+
knowledge,
|
|
208
|
+
escalated: false,
|
|
209
|
+
processingTimeMs: Date.now() - startTime,
|
|
210
|
+
conversationId,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// =============================================================================
|
|
215
|
+
// Factory Functions
|
|
216
|
+
// =============================================================================
|
|
217
|
+
let supportAgentInstance = null;
|
|
218
|
+
/**
|
|
219
|
+
* Get the singleton SupportAgent instance
|
|
220
|
+
*/
|
|
221
|
+
export function getSupportAgent() {
|
|
222
|
+
if (!supportAgentInstance) {
|
|
223
|
+
supportAgentInstance = new SupportAgent();
|
|
224
|
+
}
|
|
225
|
+
return supportAgentInstance;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Create a new SupportAgent instance (not singleton)
|
|
229
|
+
*/
|
|
230
|
+
export function createSupportAgent() {
|
|
231
|
+
return new SupportAgent();
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,gFAAgF;AAChF,gBAAgB;AAChB,gFAAgF;AAEhF,OAAO,EACL,MAAM,EACN,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACZ,sBAAsB,EACtB,kBAAkB,EAClB,0BAA0B,EAC1B,2BAA2B,GAM5B,MAAM,aAAa,CAAC;AAErB,gFAAgF;AAChF,QAAQ;AACR,gFAAgF;AAEhF,OAAO,EAQL,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,gBAAgB;AAgBhB,mBAAmB;AACnB,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,gBAAgB,GAwCjB,MAAM,YAAY,CAAC;AAEpB,gFAAgF;AAChF,SAAS;AACT,gFAAgF;AAEhF,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,sBAAsB,EACtB,qBAAqB,EACrB,aAAa,E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CAAiC;YACjC,OAAO;gBACL,QAAQ;gBACR,SAAS;gBACT,SAAS,EAAE,IAAI;gBACf,gBAAgB,EAAE,sBAAsB,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;gBAChG,gBAAgB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;gBACxC,cAAc;aACf,CAAC;QACJ,CAAC;QAED,+DAA+D;QAC/D,iDAAiD;QAEjD,OAAO;YACL,QAAQ;YACR,QAAQ;YACR,SAAS;YACT,SAAS,EAAE,KAAK;YAChB,gBAAgB,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;YACxC,cAAc;SACf,CAAC;IACJ,CAAC;CACF;AAED,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF,IAAI,oBAAoB,GAAwB,IAAI,CAAC;AAErD;;GAEG;AACH,MAAM,UAAU,eAAe;IAC7B,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC1B,oBAAoB,GAAG,IAAI,YAAY,EAAE,CAAC;IAC5C,CAAC;IACD,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,YAAY,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message Intake Module
|
|
3
|
+
*
|
|
4
|
+
* Handles inbound message reception from all channels:
|
|
5
|
+
* - Email (via Postmark)
|
|
6
|
+
* - SMS (via Twilio)
|
|
7
|
+
* - Slack (via Events API)
|
|
8
|
+
*
|
|
9
|
+
* Provides message normalization, deduplication, and threading services.
|
|
10
|
+
*/
|
|
11
|
+
export { MessageNormalizer, getMessageNormalizer, normalizePostmarkEmail, normalizeTwilioSms, normalizeSlackMessage, generateContentHash, extractThreadIdentifier, getSenderIdentifier, normalizePhoneNumber, validateMessageContent, scanAndAnnotateMessage, type PostmarkInboundEmail, type TwilioInboundSms, type SlackMessageEvent, type SlackEventWrapper, } from './normalizer.js';
|
|
12
|
+
export { validatePostmarkWebhook, processPostmarkEmail, handlePostmarkInbound, isAutoReply, isLikelySpam, classifyEmail, extractEmailThread, extractQuotedContent, type PostmarkWebhookPayload, type PostmarkProcessResult, } from './postmark.js';
|
|
13
|
+
export { validateTwilioSignature, validateTwilioWebhook, parseTwilioBody, processTwilioSms, handleTwilioInbound, isOptOutMessage, isHelpRequest, classifySms, hasMmsAttachments, extractMmsMedia, extractCountryCode, isNorthAmericanNumber, generateTwimlResponse, generateOptOutResponse, generateHelpResponse, type TwilioProcessResult, } from './twilio.js';
|
|
14
|
+
export { validateSlackSignature, validateSlackWebhook, isUrlVerification, isMessageEvent, isDirectMessage, isBotMessage, processSlackMessage, handleSlackEvent, extractMentions, extractChannelReferences, extractLinks, cleanSlackText, isB2BCustomerChannel, shouldProcessSlackMessage, formatForSlack, generateSlackBlocks, type SlackProcessResult, type SlackUrlVerification, } from './slack.js';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/intake/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,GAC3B,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,EACpB,KAAK,mBAAmB,GACzB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,yBAAyB,EACzB,cAAc,EACd,mBAAmB,EACnB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,GAC1B,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message Intake Module
|
|
3
|
+
*
|
|
4
|
+
* Handles inbound message reception from all channels:
|
|
5
|
+
* - Email (via Postmark)
|
|
6
|
+
* - SMS (via Twilio)
|
|
7
|
+
* - Slack (via Events API)
|
|
8
|
+
*
|
|
9
|
+
* Provides message normalization, deduplication, and threading services.
|
|
10
|
+
*/
|
|
11
|
+
// Message normalizer
|
|
12
|
+
export { MessageNormalizer, getMessageNormalizer, normalizePostmarkEmail, normalizeTwilioSms, normalizeSlackMessage, generateContentHash, extractThreadIdentifier, getSenderIdentifier, normalizePhoneNumber, validateMessageContent, scanAndAnnotateMessage, } from './normalizer.js';
|
|
13
|
+
// Postmark email handler
|
|
14
|
+
export { validatePostmarkWebhook, processPostmarkEmail, handlePostmarkInbound, isAutoReply, isLikelySpam, classifyEmail, extractEmailThread, extractQuotedContent, } from './postmark.js';
|
|
15
|
+
// Twilio SMS handler
|
|
16
|
+
export { validateTwilioSignature, validateTwilioWebhook, parseTwilioBody, processTwilioSms, handleTwilioInbound, isOptOutMessage, isHelpRequest, classifySms, hasMmsAttachments, extractMmsMedia, extractCountryCode, isNorthAmericanNumber, generateTwimlResponse, generateOptOutResponse, generateHelpResponse, } from './twilio.js';
|
|
17
|
+
// Slack event handler
|
|
18
|
+
export { validateSlackSignature, validateSlackWebhook, isUrlVerification, isMessageEvent, isDirectMessage, isBotMessage, processSlackMessage, handleSlackEvent, extractMentions, extractChannelReferences, extractLinks, cleanSlackText, isB2BCustomerChannel, shouldProcessSlackMessage, formatForSlack, generateSlackBlocks, } from './slack.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/intake/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,qBAAqB;AACrB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,GAKvB,MAAM,iBAAiB,CAAC;AAEzB,yBAAyB;AACzB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,oBAAoB,GAGrB,MAAM,eAAe,CAAC;AAEvB,qBAAqB;AACrB,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,oBAAoB,GAErB,MAAM,aAAa,CAAC;AAErB,sBAAsB;AACtB,OAAO,EACL,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,wBAAwB,EACxB,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,yBAAyB,EACzB,cAAc,EACd,mBAAmB,GAGpB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message Normalizer
|
|
3
|
+
*
|
|
4
|
+
* Transforms channel-specific message formats into a unified InboundMessage interface.
|
|
5
|
+
* Handles content extraction, sender identification, and metadata normalization.
|
|
6
|
+
*/
|
|
7
|
+
import type { InboundMessage } from '../types.js';
|
|
8
|
+
export interface PostmarkInboundEmail {
|
|
9
|
+
From: string;
|
|
10
|
+
FromName?: string;
|
|
11
|
+
FromFull?: {
|
|
12
|
+
Email: string;
|
|
13
|
+
Name: string;
|
|
14
|
+
};
|
|
15
|
+
To: string;
|
|
16
|
+
ToFull?: Array<{
|
|
17
|
+
Email: string;
|
|
18
|
+
Name: string;
|
|
19
|
+
}>;
|
|
20
|
+
Cc?: string;
|
|
21
|
+
CcFull?: Array<{
|
|
22
|
+
Email: string;
|
|
23
|
+
Name: string;
|
|
24
|
+
}>;
|
|
25
|
+
ReplyTo?: string;
|
|
26
|
+
Subject?: string;
|
|
27
|
+
MessageID: string;
|
|
28
|
+
Date: string;
|
|
29
|
+
TextBody?: string;
|
|
30
|
+
HtmlBody?: string;
|
|
31
|
+
StrippedTextReply?: string;
|
|
32
|
+
Headers?: Array<{
|
|
33
|
+
Name: string;
|
|
34
|
+
Value: string;
|
|
35
|
+
}>;
|
|
36
|
+
Attachments?: Array<{
|
|
37
|
+
Name: string;
|
|
38
|
+
Content: string;
|
|
39
|
+
ContentType: string;
|
|
40
|
+
ContentLength: number;
|
|
41
|
+
ContentID?: string;
|
|
42
|
+
}>;
|
|
43
|
+
OriginalRecipient?: string;
|
|
44
|
+
InReplyTo?: string;
|
|
45
|
+
References?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface TwilioInboundSms {
|
|
48
|
+
MessageSid: string;
|
|
49
|
+
AccountSid: string;
|
|
50
|
+
From: string;
|
|
51
|
+
To: string;
|
|
52
|
+
Body: string;
|
|
53
|
+
NumMedia?: string;
|
|
54
|
+
NumSegments?: string;
|
|
55
|
+
FromCity?: string;
|
|
56
|
+
FromState?: string;
|
|
57
|
+
FromZip?: string;
|
|
58
|
+
FromCountry?: string;
|
|
59
|
+
ToCity?: string;
|
|
60
|
+
ToState?: string;
|
|
61
|
+
ToZip?: string;
|
|
62
|
+
ToCountry?: string;
|
|
63
|
+
MediaUrl0?: string;
|
|
64
|
+
MediaContentType0?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface SlackMessageEvent {
|
|
67
|
+
type: 'message';
|
|
68
|
+
subtype?: string;
|
|
69
|
+
channel: string;
|
|
70
|
+
user: string;
|
|
71
|
+
text: string;
|
|
72
|
+
ts: string;
|
|
73
|
+
thread_ts?: string;
|
|
74
|
+
team: string;
|
|
75
|
+
event_ts: string;
|
|
76
|
+
channel_type?: 'im' | 'channel' | 'group';
|
|
77
|
+
files?: Array<{
|
|
78
|
+
id: string;
|
|
79
|
+
name: string;
|
|
80
|
+
mimetype: string;
|
|
81
|
+
size: number;
|
|
82
|
+
url_private?: string;
|
|
83
|
+
url_private_download?: string;
|
|
84
|
+
}>;
|
|
85
|
+
blocks?: unknown[];
|
|
86
|
+
}
|
|
87
|
+
export interface SlackEventWrapper {
|
|
88
|
+
token: string;
|
|
89
|
+
team_id: string;
|
|
90
|
+
api_app_id: string;
|
|
91
|
+
event: SlackMessageEvent;
|
|
92
|
+
type: 'event_callback' | 'url_verification';
|
|
93
|
+
event_id: string;
|
|
94
|
+
event_time: number;
|
|
95
|
+
authed_users?: string[];
|
|
96
|
+
challenge?: string;
|
|
97
|
+
}
|
|
98
|
+
export declare class MessageNormalizer {
|
|
99
|
+
/**
|
|
100
|
+
* Normalize a Postmark inbound email
|
|
101
|
+
*/
|
|
102
|
+
normalizePostmarkEmail(email: PostmarkInboundEmail): InboundMessage;
|
|
103
|
+
/**
|
|
104
|
+
* Normalize a Twilio inbound SMS
|
|
105
|
+
*/
|
|
106
|
+
normalizeTwilioSms(sms: TwilioInboundSms): InboundMessage;
|
|
107
|
+
/**
|
|
108
|
+
* Normalize a Slack message event
|
|
109
|
+
*/
|
|
110
|
+
normalizeSlackMessage(event: SlackMessageEvent, teamId: string): InboundMessage;
|
|
111
|
+
/**
|
|
112
|
+
* Convert Postmark headers array to record
|
|
113
|
+
*/
|
|
114
|
+
private headersToRecord;
|
|
115
|
+
/**
|
|
116
|
+
* Normalize Postmark attachments
|
|
117
|
+
*/
|
|
118
|
+
private normalizePostmarkAttachments;
|
|
119
|
+
/**
|
|
120
|
+
* Normalize Twilio MMS media
|
|
121
|
+
*/
|
|
122
|
+
private normalizeTwilioMedia;
|
|
123
|
+
/**
|
|
124
|
+
* Normalize Slack file attachments
|
|
125
|
+
*/
|
|
126
|
+
private normalizeSlackFiles;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Generate a content hash for deduplication
|
|
130
|
+
*/
|
|
131
|
+
export declare function generateContentHash(message: InboundMessage): string;
|
|
132
|
+
/**
|
|
133
|
+
* Extract conversation thread identifier from message
|
|
134
|
+
*/
|
|
135
|
+
export declare function extractThreadIdentifier(message: InboundMessage): string | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Get sender identifier for customer matching
|
|
138
|
+
*/
|
|
139
|
+
export declare function getSenderIdentifier(message: InboundMessage): {
|
|
140
|
+
type: 'email' | 'phone' | 'slack';
|
|
141
|
+
value: string;
|
|
142
|
+
} | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* Normalize phone number to E.164 format
|
|
145
|
+
*/
|
|
146
|
+
export declare function normalizePhoneNumber(phone: string): string;
|
|
147
|
+
/**
|
|
148
|
+
* Validate message content is not empty
|
|
149
|
+
*/
|
|
150
|
+
export declare function validateMessageContent(message: InboundMessage): void;
|
|
151
|
+
/**
|
|
152
|
+
* Check message for forbidden terms and annotate
|
|
153
|
+
*/
|
|
154
|
+
export declare function scanAndAnnotateMessage(message: InboundMessage): {
|
|
155
|
+
message: InboundMessage;
|
|
156
|
+
hasForbiddenTerms: boolean;
|
|
157
|
+
detectedTerms: string[];
|
|
158
|
+
};
|
|
159
|
+
export declare function getMessageNormalizer(): MessageNormalizer;
|
|
160
|
+
export declare function normalizePostmarkEmail(email: PostmarkInboundEmail): InboundMessage;
|
|
161
|
+
export declare function normalizeTwilioSms(sms: TwilioInboundSms): InboundMessage;
|
|
162
|
+
export declare function normalizeSlackMessage(event: SlackMessageEvent, teamId: string): InboundMessage;
|
|
163
|
+
//# sourceMappingURL=normalizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizer.d.ts","sourceRoot":"","sources":["../../src/intake/normalizer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,cAAc,EAUf,MAAM,aAAa,CAAC;AASrB,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE;QACT,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,CAAC,EAAE,KAAK,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,MAAM,CAAC,EAAE,KAAK,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,C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