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/errors.js
ADDED
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Support Agent Error Hierarchy
|
|
3
|
+
*
|
|
4
|
+
* Custom error classes for the Support AI Agent SDK.
|
|
5
|
+
* Enables type-safe error handling, consistent error codes,
|
|
6
|
+
* and better recovery strategies.
|
|
7
|
+
*
|
|
8
|
+
* Error Categories:
|
|
9
|
+
* - IntakeError: Message reception and normalization failures
|
|
10
|
+
* - AnalysisError: Intent/sentiment/entity extraction failures
|
|
11
|
+
* - KnowledgeError: Customer/product data retrieval failures
|
|
12
|
+
* - GenerationError: Response generation failures
|
|
13
|
+
* - DeliveryError: Message delivery failures
|
|
14
|
+
* - EscalationError: Human escalation failures
|
|
15
|
+
* - BrandComplianceError: Brand rule violations
|
|
16
|
+
*/
|
|
17
|
+
// =============================================================================
|
|
18
|
+
// Base Error Class
|
|
19
|
+
// =============================================================================
|
|
20
|
+
/**
|
|
21
|
+
* Base error class for all support agent errors
|
|
22
|
+
*/
|
|
23
|
+
export class SupportAgentError extends Error {
|
|
24
|
+
code;
|
|
25
|
+
context;
|
|
26
|
+
timestamp;
|
|
27
|
+
recoverable;
|
|
28
|
+
conversationId;
|
|
29
|
+
messageId;
|
|
30
|
+
constructor(message, code, options) {
|
|
31
|
+
super(message, { cause: options?.cause });
|
|
32
|
+
this.name = 'SupportAgentError';
|
|
33
|
+
this.code = code;
|
|
34
|
+
this.context = options?.context;
|
|
35
|
+
this.timestamp = new Date();
|
|
36
|
+
this.recoverable = options?.recoverable ?? false;
|
|
37
|
+
this.conversationId = options?.conversationId;
|
|
38
|
+
this.messageId = options?.messageId;
|
|
39
|
+
// Ensure proper prototype chain for instanceof checks
|
|
40
|
+
Object.setPrototypeOf(this, SupportAgentError.prototype);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Serialize error for logging and storage
|
|
44
|
+
*/
|
|
45
|
+
toJSON() {
|
|
46
|
+
return {
|
|
47
|
+
name: this.name,
|
|
48
|
+
message: this.message,
|
|
49
|
+
code: this.code,
|
|
50
|
+
context: this.context,
|
|
51
|
+
timestamp: this.timestamp.toISOString(),
|
|
52
|
+
recoverable: this.recoverable,
|
|
53
|
+
conversationId: this.conversationId,
|
|
54
|
+
messageId: this.messageId,
|
|
55
|
+
stack: this.stack,
|
|
56
|
+
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// =============================================================================
|
|
61
|
+
// Intake Errors
|
|
62
|
+
// =============================================================================
|
|
63
|
+
/**
|
|
64
|
+
* Error during message intake (webhook reception, parsing, normalization)
|
|
65
|
+
*/
|
|
66
|
+
export class IntakeError extends SupportAgentError {
|
|
67
|
+
channel;
|
|
68
|
+
stage;
|
|
69
|
+
constructor(message, channel, stage, options) {
|
|
70
|
+
super(message, 'INTAKE_ERROR', {
|
|
71
|
+
context: { ...options?.context, channel, stage },
|
|
72
|
+
recoverable: stage === 'webhook', // Webhook errors can be retried
|
|
73
|
+
cause: options?.cause,
|
|
74
|
+
conversationId: options?.conversationId,
|
|
75
|
+
messageId: options?.messageId,
|
|
76
|
+
});
|
|
77
|
+
this.name = 'IntakeError';
|
|
78
|
+
this.channel = channel;
|
|
79
|
+
this.stage = stage;
|
|
80
|
+
Object.setPrototypeOf(this, IntakeError.prototype);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Error when webhook signature validation fails
|
|
85
|
+
*/
|
|
86
|
+
export class WebhookValidationError extends IntakeError {
|
|
87
|
+
constructor(channel, options) {
|
|
88
|
+
super(`Invalid webhook signature for ${channel}`, channel, 'validation', {
|
|
89
|
+
...options,
|
|
90
|
+
context: { ...options?.context, securityEvent: true },
|
|
91
|
+
});
|
|
92
|
+
this.name = 'WebhookValidationError';
|
|
93
|
+
Object.setPrototypeOf(this, WebhookValidationError.prototype);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Error when a duplicate message is detected
|
|
98
|
+
*/
|
|
99
|
+
export class DuplicateMessageError extends IntakeError {
|
|
100
|
+
originalMessageId;
|
|
101
|
+
constructor(channel, originalMessageId, options) {
|
|
102
|
+
super(`Duplicate message detected: ${originalMessageId}`, channel, 'deduplication', {
|
|
103
|
+
context: { ...options?.context, originalMessageId },
|
|
104
|
+
});
|
|
105
|
+
this.name = 'DuplicateMessageError';
|
|
106
|
+
this.originalMessageId = originalMessageId;
|
|
107
|
+
Object.setPrototypeOf(this, DuplicateMessageError.prototype);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
// =============================================================================
|
|
111
|
+
// Analysis Errors
|
|
112
|
+
// =============================================================================
|
|
113
|
+
/**
|
|
114
|
+
* Error during message analysis (intent, sentiment, entities)
|
|
115
|
+
*/
|
|
116
|
+
export class AnalysisError extends SupportAgentError {
|
|
117
|
+
analysisType;
|
|
118
|
+
constructor(message, analysisType, options) {
|
|
119
|
+
super(message, 'ANALYSIS_ERROR', {
|
|
120
|
+
context: { ...options?.context, analysisType },
|
|
121
|
+
recoverable: true, // Analysis can be retried
|
|
122
|
+
cause: options?.cause,
|
|
123
|
+
conversationId: options?.conversationId,
|
|
124
|
+
messageId: options?.messageId,
|
|
125
|
+
});
|
|
126
|
+
this.name = 'AnalysisError';
|
|
127
|
+
this.analysisType = analysisType;
|
|
128
|
+
Object.setPrototypeOf(this, AnalysisError.prototype);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Error when intent classification fails or returns low confidence
|
|
133
|
+
*/
|
|
134
|
+
export class IntentClassificationError extends AnalysisError {
|
|
135
|
+
confidence;
|
|
136
|
+
constructor(message, confidence, options) {
|
|
137
|
+
super(message, 'intent', {
|
|
138
|
+
...options,
|
|
139
|
+
context: { ...options?.context, confidence },
|
|
140
|
+
});
|
|
141
|
+
this.name = 'IntentClassificationError';
|
|
142
|
+
this.confidence = confidence;
|
|
143
|
+
Object.setPrototypeOf(this, IntentClassificationError.prototype);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// =============================================================================
|
|
147
|
+
// Knowledge Errors
|
|
148
|
+
// =============================================================================
|
|
149
|
+
/**
|
|
150
|
+
* Error during knowledge retrieval (customer data, products, policies)
|
|
151
|
+
*/
|
|
152
|
+
export class KnowledgeError extends SupportAgentError {
|
|
153
|
+
knowledgeType;
|
|
154
|
+
constructor(message, knowledgeType, options) {
|
|
155
|
+
super(message, 'KNOWLEDGE_ERROR', {
|
|
156
|
+
context: { ...options?.context, knowledgeType },
|
|
157
|
+
recoverable: true, // Knowledge retrieval can be retried
|
|
158
|
+
cause: options?.cause,
|
|
159
|
+
conversationId: options?.conversationId,
|
|
160
|
+
messageId: options?.messageId,
|
|
161
|
+
});
|
|
162
|
+
this.name = 'KnowledgeError';
|
|
163
|
+
this.knowledgeType = knowledgeType;
|
|
164
|
+
Object.setPrototypeOf(this, KnowledgeError.prototype);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Error when customer cannot be identified or found
|
|
169
|
+
*/
|
|
170
|
+
export class CustomerNotFoundError extends KnowledgeError {
|
|
171
|
+
identifiers;
|
|
172
|
+
constructor(identifiers, options) {
|
|
173
|
+
super('Customer not found with provided identifiers', 'customer', {
|
|
174
|
+
...options,
|
|
175
|
+
context: { ...options?.context, identifiers },
|
|
176
|
+
});
|
|
177
|
+
this.name = 'CustomerNotFoundError';
|
|
178
|
+
this.identifiers = identifiers;
|
|
179
|
+
Object.setPrototypeOf(this, CustomerNotFoundError.prototype);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// =============================================================================
|
|
183
|
+
// Generation Errors
|
|
184
|
+
// =============================================================================
|
|
185
|
+
/**
|
|
186
|
+
* Error during response generation
|
|
187
|
+
*/
|
|
188
|
+
export class GenerationError extends SupportAgentError {
|
|
189
|
+
stage;
|
|
190
|
+
constructor(message, stage, options) {
|
|
191
|
+
super(message, 'GENERATION_ERROR', {
|
|
192
|
+
context: { ...options?.context, stage },
|
|
193
|
+
recoverable: true, // Generation can be retried
|
|
194
|
+
cause: options?.cause,
|
|
195
|
+
conversationId: options?.conversationId,
|
|
196
|
+
messageId: options?.messageId,
|
|
197
|
+
});
|
|
198
|
+
this.name = 'GenerationError';
|
|
199
|
+
this.stage = stage;
|
|
200
|
+
Object.setPrototypeOf(this, GenerationError.prototype);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Error when response quality check fails
|
|
205
|
+
*/
|
|
206
|
+
export class ResponseQualityError extends GenerationError {
|
|
207
|
+
qualityScore;
|
|
208
|
+
issues;
|
|
209
|
+
constructor(qualityScore, issues, options) {
|
|
210
|
+
super(`Response failed quality check (score: ${qualityScore})`, 'post_processing', {
|
|
211
|
+
...options,
|
|
212
|
+
context: { ...options?.context, qualityScore, issues },
|
|
213
|
+
});
|
|
214
|
+
this.name = 'ResponseQualityError';
|
|
215
|
+
this.qualityScore = qualityScore;
|
|
216
|
+
this.issues = issues;
|
|
217
|
+
Object.setPrototypeOf(this, ResponseQualityError.prototype);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Error during message delivery
|
|
222
|
+
*/
|
|
223
|
+
export class DeliveryError extends SupportAgentError {
|
|
224
|
+
channel;
|
|
225
|
+
deliveryStage;
|
|
226
|
+
constructor(message, channel, deliveryStage, options) {
|
|
227
|
+
super(message, 'DELIVERY_ERROR', {
|
|
228
|
+
context: { ...options?.context, channel, deliveryStage },
|
|
229
|
+
recoverable: options?.recoverable ?? true, // Most delivery errors can be retried
|
|
230
|
+
cause: options?.cause,
|
|
231
|
+
conversationId: options?.conversationId,
|
|
232
|
+
messageId: options?.messageId,
|
|
233
|
+
});
|
|
234
|
+
this.name = 'DeliveryError';
|
|
235
|
+
this.channel = channel;
|
|
236
|
+
this.deliveryStage = deliveryStage;
|
|
237
|
+
Object.setPrototypeOf(this, DeliveryError.prototype);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Error when message bounces or permanently fails
|
|
242
|
+
*/
|
|
243
|
+
export class PermanentDeliveryFailure extends DeliveryError {
|
|
244
|
+
failureReason;
|
|
245
|
+
constructor(channel, failureReason, options) {
|
|
246
|
+
super(`Permanent delivery failure: ${failureReason}`, channel, 'confirmation', {
|
|
247
|
+
...options,
|
|
248
|
+
context: { ...options?.context, failureReason },
|
|
249
|
+
recoverable: false, // Permanent failures cannot be retried
|
|
250
|
+
});
|
|
251
|
+
this.name = 'PermanentDeliveryFailure';
|
|
252
|
+
this.failureReason = failureReason;
|
|
253
|
+
Object.setPrototypeOf(this, PermanentDeliveryFailure.prototype);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Error during escalation to human agents
|
|
258
|
+
*/
|
|
259
|
+
export class EscalationError extends SupportAgentError {
|
|
260
|
+
escalationChannel;
|
|
261
|
+
constructor(message, options) {
|
|
262
|
+
super(message, 'ESCALATION_ERROR', {
|
|
263
|
+
context: { ...options?.context, channel: options?.channel },
|
|
264
|
+
recoverable: true, // Escalation can be retried on different channel
|
|
265
|
+
cause: options?.cause,
|
|
266
|
+
conversationId: options?.conversationId,
|
|
267
|
+
messageId: options?.messageId,
|
|
268
|
+
});
|
|
269
|
+
this.name = 'EscalationError';
|
|
270
|
+
this.escalationChannel = options?.channel;
|
|
271
|
+
Object.setPrototypeOf(this, EscalationError.prototype);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Error when ALL escalation channels have failed
|
|
276
|
+
* Not recoverable via retry - requires fallback handling
|
|
277
|
+
*/
|
|
278
|
+
export class AllEscalationChannelsFailedError extends SupportAgentError {
|
|
279
|
+
channelErrors;
|
|
280
|
+
escalationId;
|
|
281
|
+
constructor(channelErrors, options) {
|
|
282
|
+
super('All escalation channels failed', 'ALL_ESCALATION_CHANNELS_FAILED', {
|
|
283
|
+
context: { ...options?.context, channelErrors, escalationId: options?.escalationId },
|
|
284
|
+
recoverable: false, // All channels failed
|
|
285
|
+
conversationId: options?.conversationId,
|
|
286
|
+
messageId: options?.messageId,
|
|
287
|
+
});
|
|
288
|
+
this.name = 'AllEscalationChannelsFailedError';
|
|
289
|
+
this.channelErrors = channelErrors;
|
|
290
|
+
this.escalationId = options?.escalationId;
|
|
291
|
+
Object.setPrototypeOf(this, AllEscalationChannelsFailedError.prototype);
|
|
292
|
+
}
|
|
293
|
+
getSummary() {
|
|
294
|
+
return this.channelErrors.map((e) => `${e.channel}: ${e.error}`).join('; ');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// =============================================================================
|
|
298
|
+
// Brand Compliance Errors
|
|
299
|
+
// =============================================================================
|
|
300
|
+
/**
|
|
301
|
+
* Error when brand compliance rules are violated
|
|
302
|
+
* These errors ALWAYS require escalation - never recoverable by retry
|
|
303
|
+
*/
|
|
304
|
+
export class BrandComplianceError extends SupportAgentError {
|
|
305
|
+
violationType;
|
|
306
|
+
detectedTerms;
|
|
307
|
+
complianceScore;
|
|
308
|
+
constructor(message, violationType, options) {
|
|
309
|
+
super(message, 'BRAND_COMPLIANCE_ERROR', {
|
|
310
|
+
context: {
|
|
311
|
+
...options?.context,
|
|
312
|
+
violationType,
|
|
313
|
+
detectedTerms: options?.detectedTerms,
|
|
314
|
+
complianceScore: options?.complianceScore,
|
|
315
|
+
},
|
|
316
|
+
recoverable: false, // Brand compliance errors require human intervention
|
|
317
|
+
conversationId: options?.conversationId,
|
|
318
|
+
messageId: options?.messageId,
|
|
319
|
+
});
|
|
320
|
+
this.name = 'BrandComplianceError';
|
|
321
|
+
this.violationType = violationType;
|
|
322
|
+
this.detectedTerms = options?.detectedTerms;
|
|
323
|
+
this.complianceScore = options?.complianceScore;
|
|
324
|
+
Object.setPrototypeOf(this, BrandComplianceError.prototype);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Error when forbidden terms are detected in incoming or outgoing messages
|
|
329
|
+
*/
|
|
330
|
+
export class ForbiddenTermsDetectedError extends BrandComplianceError {
|
|
331
|
+
terms;
|
|
332
|
+
source;
|
|
333
|
+
constructor(terms, source, options) {
|
|
334
|
+
super(`Forbidden terms detected in ${source}: ${terms.join(', ')}`, 'forbidden_term_detected', {
|
|
335
|
+
...options,
|
|
336
|
+
detectedTerms: terms,
|
|
337
|
+
context: { ...options?.context, source },
|
|
338
|
+
});
|
|
339
|
+
this.name = 'ForbiddenTermsDetectedError';
|
|
340
|
+
this.terms = terms;
|
|
341
|
+
this.source = source;
|
|
342
|
+
Object.setPrototypeOf(this, ForbiddenTermsDetectedError.prototype);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// =============================================================================
|
|
346
|
+
// Database Errors
|
|
347
|
+
// =============================================================================
|
|
348
|
+
/**
|
|
349
|
+
* Database operation errors
|
|
350
|
+
*/
|
|
351
|
+
export class DatabaseError extends SupportAgentError {
|
|
352
|
+
operation;
|
|
353
|
+
table;
|
|
354
|
+
constructor(message, operation, options) {
|
|
355
|
+
super(message, 'DATABASE_ERROR', {
|
|
356
|
+
context: { ...options?.context, operation, table: options?.table },
|
|
357
|
+
recoverable: true, // DB errors are often transient
|
|
358
|
+
cause: options?.cause,
|
|
359
|
+
conversationId: options?.conversationId,
|
|
360
|
+
messageId: options?.messageId,
|
|
361
|
+
});
|
|
362
|
+
this.name = 'DatabaseError';
|
|
363
|
+
this.operation = operation;
|
|
364
|
+
this.table = options?.table;
|
|
365
|
+
Object.setPrototypeOf(this, DatabaseError.prototype);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Error during embedding generation
|
|
370
|
+
*/
|
|
371
|
+
export class EmbeddingError extends SupportAgentError {
|
|
372
|
+
errorType;
|
|
373
|
+
constructor(message, errorType, options) {
|
|
374
|
+
super(message, 'EMBEDDING_ERROR', {
|
|
375
|
+
context: { ...options?.context, errorType },
|
|
376
|
+
recoverable: errorType === 'rate_limit' || errorType === 'timeout', // Rate limits and timeouts can be retried
|
|
377
|
+
cause: options?.cause,
|
|
378
|
+
conversationId: options?.conversationId,
|
|
379
|
+
messageId: options?.messageId,
|
|
380
|
+
});
|
|
381
|
+
this.name = 'EmbeddingError';
|
|
382
|
+
this.errorType = errorType;
|
|
383
|
+
Object.setPrototypeOf(this, EmbeddingError.prototype);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// =============================================================================
|
|
387
|
+
// Timeout Errors
|
|
388
|
+
// =============================================================================
|
|
389
|
+
/**
|
|
390
|
+
* Operation timeout errors
|
|
391
|
+
*/
|
|
392
|
+
export class TimeoutError extends SupportAgentError {
|
|
393
|
+
operationType;
|
|
394
|
+
timeoutMs;
|
|
395
|
+
constructor(operationType, timeoutMs, options) {
|
|
396
|
+
super(`Operation timed out after ${timeoutMs}ms: ${operationType}`, 'TIMEOUT_ERROR', {
|
|
397
|
+
context: { ...options?.context, operationType, timeoutMs },
|
|
398
|
+
recoverable: true, // Timeouts can be retried
|
|
399
|
+
cause: options?.cause,
|
|
400
|
+
conversationId: options?.conversationId,
|
|
401
|
+
messageId: options?.messageId,
|
|
402
|
+
});
|
|
403
|
+
this.name = 'TimeoutError';
|
|
404
|
+
this.operationType = operationType;
|
|
405
|
+
this.timeoutMs = timeoutMs;
|
|
406
|
+
Object.setPrototypeOf(this, TimeoutError.prototype);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
// =============================================================================
|
|
410
|
+
// Type Guards
|
|
411
|
+
// =============================================================================
|
|
412
|
+
export function isSupportAgentError(error) {
|
|
413
|
+
return error instanceof SupportAgentError;
|
|
414
|
+
}
|
|
415
|
+
export function isIntakeError(error) {
|
|
416
|
+
return error instanceof IntakeError;
|
|
417
|
+
}
|
|
418
|
+
export function isAnalysisError(error) {
|
|
419
|
+
return error instanceof AnalysisError;
|
|
420
|
+
}
|
|
421
|
+
export function isKnowledgeError(error) {
|
|
422
|
+
return error instanceof KnowledgeError;
|
|
423
|
+
}
|
|
424
|
+
export function isGenerationError(error) {
|
|
425
|
+
return error instanceof GenerationError;
|
|
426
|
+
}
|
|
427
|
+
export function isDeliveryError(error) {
|
|
428
|
+
return error instanceof DeliveryError;
|
|
429
|
+
}
|
|
430
|
+
export function isEscalationError(error) {
|
|
431
|
+
return error instanceof EscalationError;
|
|
432
|
+
}
|
|
433
|
+
export function isBrandComplianceError(error) {
|
|
434
|
+
return error instanceof BrandComplianceError;
|
|
435
|
+
}
|
|
436
|
+
export function isDatabaseError(error) {
|
|
437
|
+
return error instanceof DatabaseError;
|
|
438
|
+
}
|
|
439
|
+
export function isTimeoutError(error) {
|
|
440
|
+
return error instanceof TimeoutError;
|
|
441
|
+
}
|
|
442
|
+
export function isEmbeddingError(error) {
|
|
443
|
+
return error instanceof EmbeddingError;
|
|
444
|
+
}
|
|
445
|
+
export function isRecoverableError(error) {
|
|
446
|
+
if (isSupportAgentError(error)) {
|
|
447
|
+
return error.recoverable;
|
|
448
|
+
}
|
|
449
|
+
return false;
|
|
450
|
+
}
|
|
451
|
+
// =============================================================================
|
|
452
|
+
// Error Conversion Utilities
|
|
453
|
+
// =============================================================================
|
|
454
|
+
/**
|
|
455
|
+
* Convert unknown error to SupportAgentError
|
|
456
|
+
*/
|
|
457
|
+
export function toSupportAgentError(error, options) {
|
|
458
|
+
if (isSupportAgentError(error)) {
|
|
459
|
+
return error;
|
|
460
|
+
}
|
|
461
|
+
if (error instanceof Error) {
|
|
462
|
+
return new SupportAgentError(error.message, 'UNKNOWN_ERROR', {
|
|
463
|
+
cause: error,
|
|
464
|
+
recoverable: false,
|
|
465
|
+
conversationId: options?.conversationId,
|
|
466
|
+
messageId: options?.messageId,
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
return new SupportAgentError(String(error), 'UNKNOWN_ERROR', {
|
|
470
|
+
recoverable: false,
|
|
471
|
+
conversationId: options?.conversationId,
|
|
472
|
+
messageId: options?.messageId,
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Extract error message from any error type
|
|
477
|
+
*/
|
|
478
|
+
export function getErrorMessage(error) {
|
|
479
|
+
if (error instanceof Error) {
|
|
480
|
+
return error.message;
|
|
481
|
+
}
|
|
482
|
+
return String(error);
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Check if an error should trigger a retry
|
|
486
|
+
*/
|
|
487
|
+
export function shouldRetry(error, attemptCount, maxAttempts) {
|
|
488
|
+
if (attemptCount >= maxAttempts) {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
if (isSupportAgentError(error)) {
|
|
492
|
+
return error.recoverable;
|
|
493
|
+
}
|
|
494
|
+
return false;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* Check if an error requires immediate escalation
|
|
498
|
+
*/
|
|
499
|
+
export function requiresImmediateEscalation(error) {
|
|
500
|
+
if (isBrandComplianceError(error)) {
|
|
501
|
+
return true;
|
|
502
|
+
}
|
|
503
|
+
if (error instanceof AllEscalationChannelsFailedError) {
|
|
504
|
+
return true;
|
|
505
|
+
}
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1B,IAAI,CAAS;IACb,OAAO,CAA2B;IAClC,SAA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SAAS;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,eAAe,EAAE;QAC3D,WAAW,EAAE,KAAK;QAClB,cAAc,EAAE,OAAO,EAAE,cAAc;QACvC,SAAS,EAAE,OAAO,EAAE,SAAS;KAC9B,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,KAAc,EAAE,YAAoB,EAAE,WAAmB;IACnF,IAAI,YAAY,IAAI,WAAW,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,mBAAmB,CAAC,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC,WAAW,CAAC;IAC3B,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,2BAA2B,CAAC,KAAc;IACxD,IAAI,sBAAsB,CAAC,KAAK,CAAC,EAAE,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,KAAK,YAAY,gCAAgC,EAAE,CAAC;QACtD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escalation System Module
|
|
3
|
+
*
|
|
4
|
+
* Routes conversations requiring human attention:
|
|
5
|
+
* - Forbidden terms detection
|
|
6
|
+
* - Low confidence responses
|
|
7
|
+
* - Customer complaints
|
|
8
|
+
* - Explicit human requests
|
|
9
|
+
* - N-failure tracking
|
|
10
|
+
*/
|
|
11
|
+
import type { EscalationContext, EscalationResult, EscalationTrigger, EscalationSeverity, EscalationId, InboundMessage, AnalysisResult, GeneratedResponse, KnowledgeContext } from '../types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Determine if escalation is required based on analysis
|
|
14
|
+
*/
|
|
15
|
+
export declare function shouldEscalate(analysis: AnalysisResult): {
|
|
16
|
+
required: boolean;
|
|
17
|
+
trigger?: EscalationTrigger;
|
|
18
|
+
severity?: EscalationSeverity;
|
|
19
|
+
reasons: string[];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Check for explicit human assistance request
|
|
23
|
+
*/
|
|
24
|
+
export declare function containsHumanRequest(text: string): boolean;
|
|
25
|
+
export declare class EscalationService {
|
|
26
|
+
private supabase;
|
|
27
|
+
constructor();
|
|
28
|
+
/**
|
|
29
|
+
* Create and route an escalation
|
|
30
|
+
*/
|
|
31
|
+
escalate(context: EscalationContext): Promise<EscalationResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Build context data for escalation record
|
|
34
|
+
*/
|
|
35
|
+
private buildContextData;
|
|
36
|
+
/**
|
|
37
|
+
* Send notification via a specific channel
|
|
38
|
+
*/
|
|
39
|
+
private notifyChannel;
|
|
40
|
+
/**
|
|
41
|
+
* Check if a channel is properly configured
|
|
42
|
+
*/
|
|
43
|
+
private isChannelConfigured;
|
|
44
|
+
/**
|
|
45
|
+
* Build notification content
|
|
46
|
+
*/
|
|
47
|
+
private buildNotificationContent;
|
|
48
|
+
/**
|
|
49
|
+
* Send email notification (placeholder - would use Postmark)
|
|
50
|
+
*/
|
|
51
|
+
private sendEmailNotification;
|
|
52
|
+
/**
|
|
53
|
+
* Send SMS notification (placeholder - would use Twilio)
|
|
54
|
+
*/
|
|
55
|
+
private sendSmsNotification;
|
|
56
|
+
/**
|
|
57
|
+
* Send Slack notification (placeholder - would use Slack API)
|
|
58
|
+
*/
|
|
59
|
+
private sendSlackNotification;
|
|
60
|
+
/**
|
|
61
|
+
* Create database fallback when all notification channels fail
|
|
62
|
+
*/
|
|
63
|
+
private createDatabaseFallback;
|
|
64
|
+
/**
|
|
65
|
+
* Track response attempt failures
|
|
66
|
+
*/
|
|
67
|
+
trackResponseAttempt(conversationId: string, success: boolean, error?: string): Promise<{
|
|
68
|
+
shouldEscalate: boolean;
|
|
69
|
+
attemptCount: number;
|
|
70
|
+
}>;
|
|
71
|
+
/**
|
|
72
|
+
* Detect human takeover (human responded in escalated conversation)
|
|
73
|
+
*/
|
|
74
|
+
detectHumanTakeover(conversationId: string): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Resolve an escalation
|
|
77
|
+
*/
|
|
78
|
+
resolveEscalation(escalationId: EscalationId, resolution: {
|
|
79
|
+
action: string;
|
|
80
|
+
notes?: string;
|
|
81
|
+
responderId: string;
|
|
82
|
+
}): Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
export declare function getEscalationService(): EscalationService;
|
|
85
|
+
/**
|
|
86
|
+
* Create and route an escalation
|
|
87
|
+
*/
|
|
88
|
+
export declare function escalateConversation(context: EscalationContext): Promise<EscalationResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Build escalation context from analysis
|
|
91
|
+
*/
|
|
92
|
+
export declare function buildEscalationContext(message: InboundMessage, analysis: AnalysisResult, knowledge: KnowledgeContext, trigger: EscalationTrigger, severity: EscalationSeverity, reason: string, attemptedResponses?: GeneratedResponse[]): EscalationContext;
|
|
93
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/escalation/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH,OAAO,KAAK,EACV,iBAAiB,EACjB,gBAAgB,EAEhB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAOrB;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,cAAc,GA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