@apotech-os/support-kit 2.6.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 +67 -0
- package/dist/chunk-KDOL3MLH.js +1766 -0
- package/dist/chunk-KDOL3MLH.js.map +1 -0
- package/dist/index.cjs +5744 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2010 -0
- package/dist/index.d.ts +2010 -0
- package/dist/index.js +3965 -0
- package/dist/index.js.map +1 -0
- package/dist/ui/index.cjs +4946 -0
- package/dist/ui/index.cjs.map +1 -0
- package/dist/ui/index.d.cts +25 -0
- package/dist/ui/index.d.ts +25 -0
- package/dist/ui/index.js +4464 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,1766 @@
|
|
|
1
|
+
import { FieldType } from '@apotech-os/app-kit';
|
|
2
|
+
|
|
3
|
+
// src/domain/classification.ts
|
|
4
|
+
var REASONING_MAX_LEN = 280;
|
|
5
|
+
|
|
6
|
+
// src/domain/profile.ts
|
|
7
|
+
var DEFAULT_PROFILE_KEY = "customer";
|
|
8
|
+
var WHATSAPP_MODES = ["escalate_only", "draft_only", "auto_reply"];
|
|
9
|
+
var DEFAULT_WHATSAPP_MODE = "escalate_only";
|
|
10
|
+
function whatsappModeFromLegacyBoolean(escalateOnly) {
|
|
11
|
+
return escalateOnly ?? true ? "escalate_only" : "draft_only";
|
|
12
|
+
}
|
|
13
|
+
var DEFAULT_CHANNEL_PROMPT_EMAIL = "shared/style-email";
|
|
14
|
+
var DEFAULT_CHANNEL_PROMPT_WHATSAPP = "shared/style-whatsapp";
|
|
15
|
+
|
|
16
|
+
// src/domain/evaluation-verdict.ts
|
|
17
|
+
var EVALUATION_VERDICTS = ["send", "send_and_escalate", "hold"];
|
|
18
|
+
function isEvaluationVerdict(value) {
|
|
19
|
+
return EVALUATION_VERDICTS.includes(value);
|
|
20
|
+
}
|
|
21
|
+
function isSendableVerdict(verdict) {
|
|
22
|
+
return verdict === "send" || verdict === "send_and_escalate";
|
|
23
|
+
}
|
|
24
|
+
function requiresFollowup(verdict) {
|
|
25
|
+
return verdict === "send_and_escalate";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/graph/state.ts
|
|
29
|
+
function initialState() {
|
|
30
|
+
return {
|
|
31
|
+
conversation: null,
|
|
32
|
+
classification: null,
|
|
33
|
+
escalated: false,
|
|
34
|
+
draft: null,
|
|
35
|
+
verdict: null,
|
|
36
|
+
reviseCount: 0,
|
|
37
|
+
guardrailHits: [],
|
|
38
|
+
proposedActions: [],
|
|
39
|
+
outcome: null
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
var NODE_NAMES = [
|
|
43
|
+
"fetchContext",
|
|
44
|
+
"triage",
|
|
45
|
+
"escalate",
|
|
46
|
+
"draft",
|
|
47
|
+
"evaluate",
|
|
48
|
+
"revise",
|
|
49
|
+
"guardrails",
|
|
50
|
+
"authorize",
|
|
51
|
+
"act"
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
// src/graph/ports.ts
|
|
55
|
+
var AGENT_TOOLS = {
|
|
56
|
+
get_order: { name: "get_order", policy: "read" },
|
|
57
|
+
get_tracking: { name: "get_tracking", policy: "read" },
|
|
58
|
+
search_knowledge: { name: "search_knowledge", policy: "read" },
|
|
59
|
+
find_similar_tickets: { name: "find_similar_tickets", policy: "read" }
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/guardrails/constants.ts
|
|
63
|
+
var CANDIDATE_MIN_LENGTH = 20;
|
|
64
|
+
var CLOCK_SKEW_MARGIN_MS = 6e4;
|
|
65
|
+
var UNCERTAINTY_MARKERS = Object.freeze([
|
|
66
|
+
"je ne suis pas sur",
|
|
67
|
+
// normalised form of "je ne suis pas sûr"
|
|
68
|
+
"je ne peux pas",
|
|
69
|
+
"contactez le service",
|
|
70
|
+
"malheureusement je n'ai pas"
|
|
71
|
+
]);
|
|
72
|
+
var STOP_PHRASES = /* @__PURE__ */ new Set([
|
|
73
|
+
"stop",
|
|
74
|
+
// the bare, universal opt-out keyword
|
|
75
|
+
"stop sms",
|
|
76
|
+
// the regulated French premium-SMS opt-out ("STOP SMS")
|
|
77
|
+
"stop pub",
|
|
78
|
+
// its marketing-specific variant ("STOP PUB")
|
|
79
|
+
"stop tout"
|
|
80
|
+
// "stop everything" — a customer opting out of all contact
|
|
81
|
+
]);
|
|
82
|
+
var AGENT_GUARDRAILS = [
|
|
83
|
+
"whatsapp",
|
|
84
|
+
"whatsapp_stop",
|
|
85
|
+
"not_customer_turn",
|
|
86
|
+
"judgeme",
|
|
87
|
+
"noreply_sender",
|
|
88
|
+
"triage_not_high",
|
|
89
|
+
"escalated",
|
|
90
|
+
"blocklist",
|
|
91
|
+
"attachment",
|
|
92
|
+
"short_answer",
|
|
93
|
+
"uncertainty_marker",
|
|
94
|
+
"evaluation_missing"
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
// src/guardrails/text.ts
|
|
98
|
+
function normalise(s) {
|
|
99
|
+
return s.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/guardrails/channel-pre-gates.ts
|
|
103
|
+
function isStopMessage(message) {
|
|
104
|
+
const cleaned = normalise(message).replace(/^[^\p{L}\d]+|[^\p{L}\d]+$/gu, "").replace(/\s+/g, " ");
|
|
105
|
+
return STOP_PHRASES.has(cleaned);
|
|
106
|
+
}
|
|
107
|
+
function firstCustomerMessage(conversation) {
|
|
108
|
+
return conversation.messages.find((m) => m.role === "user")?.content ?? null;
|
|
109
|
+
}
|
|
110
|
+
function lastCustomerMessage(conversation) {
|
|
111
|
+
const { messages } = conversation;
|
|
112
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
113
|
+
const message = messages[i];
|
|
114
|
+
if (message?.role === "user") return message.content;
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
function stopOptOut(conversation) {
|
|
119
|
+
if (conversation.sourceChannel !== "whatsapp") return [];
|
|
120
|
+
const last = lastCustomerMessage(conversation);
|
|
121
|
+
return last !== null && isStopMessage(last) ? ["whatsapp_stop"] : [];
|
|
122
|
+
}
|
|
123
|
+
function channelPreGates(conversation) {
|
|
124
|
+
if (conversation.sourceChannel !== "whatsapp") return [];
|
|
125
|
+
const hits = [...stopOptOut(conversation)];
|
|
126
|
+
const lastIsOurs = conversation.lastAgentReplyAt !== null && conversation.lastMessageAt !== null && conversation.lastAgentReplyAt.getTime() >= conversation.lastMessageAt.getTime();
|
|
127
|
+
if (lastIsOurs) hits.push("not_customer_turn");
|
|
128
|
+
return hits;
|
|
129
|
+
}
|
|
130
|
+
function isJudgemeConversation(subject, firstMessage) {
|
|
131
|
+
if (/a ecrit un avis \d+ etoile/.test(normalise(subject ?? ""))) return true;
|
|
132
|
+
const first = normalise(firstMessage ?? "");
|
|
133
|
+
return first.includes("judge.me") && /avis \d+ etoile/.test(first);
|
|
134
|
+
}
|
|
135
|
+
function isAutomatedSenderEmail(email, senders) {
|
|
136
|
+
const normalisedEmail = normalise(email ?? "").trim();
|
|
137
|
+
if (!normalisedEmail) return false;
|
|
138
|
+
return senders.some((entry) => {
|
|
139
|
+
const e = normalise(entry).trim();
|
|
140
|
+
if (!e) return false;
|
|
141
|
+
if (e.startsWith("@")) return normalisedEmail.endsWith(e);
|
|
142
|
+
if (e.endsWith("@")) return normalisedEmail.startsWith(e);
|
|
143
|
+
return normalisedEmail === e;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// src/guardrails/raw-ticket.ts
|
|
148
|
+
var WHATSAPP_NOTE_CHEVRON = ">";
|
|
149
|
+
function isInternalNoteChannel(message) {
|
|
150
|
+
return message.channel === "internal-note" || message.source?.type === "internal-note";
|
|
151
|
+
}
|
|
152
|
+
function isWhatsappChevronNote(message, isWhatsappConversation) {
|
|
153
|
+
if (!isWhatsappConversation) return false;
|
|
154
|
+
return isInternalNoteChannel(message) && message?.from_agent === true && typeof message?.body_text === "string" && message.body_text.startsWith(WHATSAPP_NOTE_CHEVRON);
|
|
155
|
+
}
|
|
156
|
+
function hasCustomerAttachment(rawTicket) {
|
|
157
|
+
return (rawTicket?.messages ?? []).some(
|
|
158
|
+
(m) => !isInternalNoteChannel(m) && !m.from_agent && (m.attachments?.length ?? 0) > 0
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
function isWhatsappTicket(rawTicket) {
|
|
162
|
+
if (rawTicket?.channel === "whatsapp") return true;
|
|
163
|
+
return (rawTicket?.messages ?? []).some((m) => m.channel === "whatsapp");
|
|
164
|
+
}
|
|
165
|
+
function isJudgemeTicket(rawTicket) {
|
|
166
|
+
const firstCustomer = (rawTicket?.messages ?? []).find(
|
|
167
|
+
(m) => !isInternalNoteChannel(m) && !m.from_agent && (m.body_text ?? "").trim().length > 0
|
|
168
|
+
);
|
|
169
|
+
return isJudgemeConversation(rawTicket?.subject ?? null, firstCustomer?.body_text ?? null);
|
|
170
|
+
}
|
|
171
|
+
function isAutomatedSenderTicket(rawTicket, senders) {
|
|
172
|
+
const email = normalise(rawTicket?.customer?.email ?? "").trim();
|
|
173
|
+
if (!email) return false;
|
|
174
|
+
for (const entry of senders) {
|
|
175
|
+
const e = normalise(entry).trim();
|
|
176
|
+
if (!e) continue;
|
|
177
|
+
if (e.startsWith("@") && email.endsWith(e)) return true;
|
|
178
|
+
if (e.endsWith("@") && email.startsWith(e)) return true;
|
|
179
|
+
if (email === e) return true;
|
|
180
|
+
}
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
function isTicketClosed(rawTicket) {
|
|
184
|
+
return rawTicket?.status === "closed";
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// src/guardrails/run-guardrails.ts
|
|
188
|
+
function runGuardrails(input) {
|
|
189
|
+
const hits = [];
|
|
190
|
+
const { firstCustomerMessage: firstCustomerMessage2, candidateAnswer, hasAttachment, blocklist } = input;
|
|
191
|
+
const normalisedMessage = normalise(firstCustomerMessage2);
|
|
192
|
+
for (const term of blocklist) {
|
|
193
|
+
if (normalisedMessage.includes(normalise(term))) {
|
|
194
|
+
hits.push(`blocklist:${term}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (hasAttachment) {
|
|
198
|
+
hits.push("attachment");
|
|
199
|
+
}
|
|
200
|
+
if (candidateAnswer.trim().length < CANDIDATE_MIN_LENGTH) {
|
|
201
|
+
hits.push("short_answer");
|
|
202
|
+
}
|
|
203
|
+
const normalisedAnswer = normalise(candidateAnswer);
|
|
204
|
+
for (const marker of UNCERTAINTY_MARKERS) {
|
|
205
|
+
if (normalisedAnswer.includes(marker)) {
|
|
206
|
+
hits.push("uncertainty_marker");
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return hits;
|
|
211
|
+
}
|
|
212
|
+
function guardrailBucket(hit) {
|
|
213
|
+
return hit.split(":")[0] ?? hit;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/guardrails/verify-reply.ts
|
|
217
|
+
function verifyReply(input) {
|
|
218
|
+
const { settings, triageConfidence, minConfidence, candidateAnswer } = input;
|
|
219
|
+
if ((settings.auto_reply_whatsapp_mode ?? DEFAULT_WHATSAPP_MODE) === "escalate_only" && input.isWhatsapp) {
|
|
220
|
+
return {
|
|
221
|
+
decision: "hold",
|
|
222
|
+
confidence: 0,
|
|
223
|
+
reason: "whatsapp channel \u2014 escalate only",
|
|
224
|
+
guardrailHits: ["whatsapp"]
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if ((settings.auto_reply_judgeme_escalate_only ?? true) && input.isJudgeme) {
|
|
228
|
+
return {
|
|
229
|
+
decision: "hold",
|
|
230
|
+
confidence: 0,
|
|
231
|
+
reason: "judgeme review notification \u2014 escalate only",
|
|
232
|
+
guardrailHits: ["judgeme"]
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
if (input.isAutomatedSender) {
|
|
236
|
+
return {
|
|
237
|
+
decision: "hold",
|
|
238
|
+
confidence: 0,
|
|
239
|
+
reason: "automated no-reply sender \u2014 escalate only",
|
|
240
|
+
guardrailHits: ["noreply_sender"]
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
if (settings.auto_reply_require_high_triage && triageConfidence !== "high") {
|
|
244
|
+
return {
|
|
245
|
+
decision: "hold",
|
|
246
|
+
confidence: 0,
|
|
247
|
+
reason: "triage confidence not high",
|
|
248
|
+
guardrailHits: ["triage_not_high"]
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
if (input.escalated === true) {
|
|
252
|
+
return {
|
|
253
|
+
decision: "hold",
|
|
254
|
+
confidence: 0,
|
|
255
|
+
reason: "ticket escalated to human",
|
|
256
|
+
guardrailHits: ["escalated"]
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
const guardrailHits = runGuardrails({
|
|
260
|
+
firstCustomerMessage: input.firstCustomerMessage,
|
|
261
|
+
candidateAnswer,
|
|
262
|
+
hasAttachment: input.hasAttachment,
|
|
263
|
+
blocklist: settings.auto_reply_blocklist ?? []
|
|
264
|
+
});
|
|
265
|
+
if (guardrailHits.length > 0) {
|
|
266
|
+
return {
|
|
267
|
+
decision: "hold",
|
|
268
|
+
confidence: 0,
|
|
269
|
+
reason: `guardrail: ${guardrailHits.join(", ")}`,
|
|
270
|
+
guardrailHits
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
const { evaluation } = input;
|
|
274
|
+
if (!evaluation) {
|
|
275
|
+
return {
|
|
276
|
+
decision: "hold",
|
|
277
|
+
confidence: 0,
|
|
278
|
+
reason: "no evaluation verdict \u2014 auto-send requires the evaluation agent",
|
|
279
|
+
guardrailHits: ["evaluation_missing"]
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
const decision = isSendableVerdict(evaluation.verdict) && evaluation.confidence >= minConfidence ? "send" : "hold";
|
|
283
|
+
return {
|
|
284
|
+
decision,
|
|
285
|
+
confidence: evaluation.confidence,
|
|
286
|
+
reason: evaluation.reason,
|
|
287
|
+
guardrailHits: []
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// src/verdict/policy.ts
|
|
292
|
+
function isSendable(verdict, profile) {
|
|
293
|
+
const node = profile.nodes.evaluate;
|
|
294
|
+
if (!node || !verdict || verdict.status !== "success") return false;
|
|
295
|
+
if (!isSendableVerdict(verdict.verdict)) return false;
|
|
296
|
+
if ((verdict.confidence ?? 0) < node.minConfidence) return false;
|
|
297
|
+
return !requiresFollowup(verdict.verdict) || node.escalationEnabled;
|
|
298
|
+
}
|
|
299
|
+
function isAutoSendEligible(state, deps) {
|
|
300
|
+
const isWhatsapp = state.conversation?.sourceChannel === "whatsapp";
|
|
301
|
+
const whatsappMode = deps.profile.guardrails.params.whatsappMode;
|
|
302
|
+
const whatsappDraftOnly = isWhatsapp && whatsappMode === "draft_only";
|
|
303
|
+
const hasSenderForMode = isWhatsapp && whatsappMode === "auto_reply" || !!deps.profile.autoSend.senderEmail;
|
|
304
|
+
return deps.profile.autoSend.enabled && deps.category.autoReplyEnabled && hasSenderForMode && !!state.verdict && !whatsappDraftOnly;
|
|
305
|
+
}
|
|
306
|
+
function needsRevision(verdict, profile, reviseCount) {
|
|
307
|
+
if (!profile.nodes.revise) return false;
|
|
308
|
+
if (reviseCount >= 1) return false;
|
|
309
|
+
if (!verdict || verdict.status !== "success") return false;
|
|
310
|
+
return !isSendableVerdict(verdict.verdict);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// src/graph/nodes/fetch-context.ts
|
|
314
|
+
var fetchContext = async (_state, deps) => {
|
|
315
|
+
try {
|
|
316
|
+
const conversation = await deps.ports.conversation.read(deps.ref);
|
|
317
|
+
return { conversation };
|
|
318
|
+
} catch (err) {
|
|
319
|
+
deps.log(`fetchContext: read failed for ${deps.ref.id}: ${err.message}`);
|
|
320
|
+
return { conversation: null, outcome: "failed" };
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// src/graph/nodes/triage.ts
|
|
325
|
+
var TRIAGE_SCHEMA = {
|
|
326
|
+
type: "object",
|
|
327
|
+
properties: {
|
|
328
|
+
tag: { type: "string" },
|
|
329
|
+
confidence: { type: "string", enum: ["high", "low"] },
|
|
330
|
+
reasoning: { type: "string", maxLength: REASONING_MAX_LEN },
|
|
331
|
+
conversationOver: { type: "boolean" }
|
|
332
|
+
},
|
|
333
|
+
required: ["tag", "confidence", "reasoning", "conversationOver"],
|
|
334
|
+
additionalProperties: false
|
|
335
|
+
};
|
|
336
|
+
function renderCategories(categories) {
|
|
337
|
+
return JSON.stringify(
|
|
338
|
+
categories.map(({ name, tag, desc, examples }) => ({
|
|
339
|
+
...name !== void 0 ? { name } : {},
|
|
340
|
+
tag,
|
|
341
|
+
desc,
|
|
342
|
+
...examples ? { examples } : {}
|
|
343
|
+
})),
|
|
344
|
+
null,
|
|
345
|
+
2
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
function fallback(unknownTag, reason) {
|
|
349
|
+
return {
|
|
350
|
+
category: unknownTag,
|
|
351
|
+
confidence: "low",
|
|
352
|
+
reasoning: reason.slice(0, REASONING_MAX_LEN),
|
|
353
|
+
isFallback: true,
|
|
354
|
+
conversationOver: false
|
|
355
|
+
// fail-safe (§5.2): never close on an error
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
var triage = async (state, deps) => {
|
|
359
|
+
const { profile } = deps;
|
|
360
|
+
const conversation = state.conversation;
|
|
361
|
+
if (!conversation) return {};
|
|
362
|
+
const message = firstCustomerMessage(conversation);
|
|
363
|
+
if (!message) {
|
|
364
|
+
return { classification: fallback(profile.audit.unknownTag, "No customer message found in ticket") };
|
|
365
|
+
}
|
|
366
|
+
const node = profile.nodes.triage;
|
|
367
|
+
const userParts = [];
|
|
368
|
+
if (conversation.customer.orderContext) userParts.push(`## Contexte client
|
|
369
|
+
${conversation.customer.orderContext}`);
|
|
370
|
+
userParts.push(`## Message \xE0 classifier
|
|
371
|
+
${message}`);
|
|
372
|
+
const last = lastCustomerMessage(conversation);
|
|
373
|
+
if (last && last !== message) userParts.push(`## Dernier message client
|
|
374
|
+
${last}`);
|
|
375
|
+
const resolvedPrompt = await deps.ports.prompt.resolve(profile.prompts.triage, {
|
|
376
|
+
categories: renderCategories(deps.categories)
|
|
377
|
+
});
|
|
378
|
+
try {
|
|
379
|
+
const result = await deps.ports.llm.complete({
|
|
380
|
+
label: "triage",
|
|
381
|
+
// The resolved Langfuse prompt's own model config WINS over the
|
|
382
|
+
// profile's fallback (I16) — see `PromptPort.resolve`'s doc.
|
|
383
|
+
model: resolvedPrompt.config?.model ?? node.model,
|
|
384
|
+
reasoning: node.reasoning,
|
|
385
|
+
messages: [
|
|
386
|
+
{ role: "system", content: resolvedPrompt.text },
|
|
387
|
+
{ role: "user", content: userParts.join("\n\n") }
|
|
388
|
+
],
|
|
389
|
+
responseSchema: TRIAGE_SCHEMA,
|
|
390
|
+
signal: deps.budget.signal,
|
|
391
|
+
promptRef: { name: resolvedPrompt.name, version: resolvedPrompt.version, resolve: false }
|
|
392
|
+
});
|
|
393
|
+
deps.budget.charge("triage", result.usage, { usd: 0, pricingMissing: true });
|
|
394
|
+
const parsed = JSON.parse(result.text ?? "");
|
|
395
|
+
if (typeof parsed.tag !== "string" || parsed.confidence !== "high" && parsed.confidence !== "low") {
|
|
396
|
+
throw new Error(`Invalid triage payload: ${result.text}`);
|
|
397
|
+
}
|
|
398
|
+
return {
|
|
399
|
+
classification: {
|
|
400
|
+
category: parsed.tag,
|
|
401
|
+
confidence: parsed.confidence,
|
|
402
|
+
reasoning: String(parsed.reasoning ?? "").slice(0, REASONING_MAX_LEN),
|
|
403
|
+
isFallback: false,
|
|
404
|
+
conversationOver: parsed.conversationOver === true
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
} catch (err) {
|
|
408
|
+
return { classification: fallback(profile.audit.unknownTag, `Fallback after error: ${err.message}`) };
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// src/graph/nodes/escalate.ts
|
|
413
|
+
var ESCALATION_SCHEMA = {
|
|
414
|
+
type: "object",
|
|
415
|
+
properties: {
|
|
416
|
+
escalate: { type: "boolean" },
|
|
417
|
+
confidence: { type: "string", enum: ["high", "low"] },
|
|
418
|
+
reasoning: { type: "string", maxLength: REASONING_MAX_LEN }
|
|
419
|
+
},
|
|
420
|
+
required: ["escalate", "confidence", "reasoning"],
|
|
421
|
+
additionalProperties: false
|
|
422
|
+
};
|
|
423
|
+
var escalate = async (state, deps) => {
|
|
424
|
+
const { profile } = deps;
|
|
425
|
+
const node = profile.nodes.escalate;
|
|
426
|
+
const conversation = state.conversation;
|
|
427
|
+
if (!node || !conversation) return { escalated: false };
|
|
428
|
+
const message = firstCustomerMessage(conversation);
|
|
429
|
+
if (!message) return { escalated: false };
|
|
430
|
+
try {
|
|
431
|
+
const userParts = [];
|
|
432
|
+
if (conversation.customer.orderContext) userParts.push(`## Contexte client
|
|
433
|
+
${conversation.customer.orderContext}`);
|
|
434
|
+
userParts.push(`## Message \xE0 classifier
|
|
435
|
+
${message}`);
|
|
436
|
+
const resolvedPrompt = await deps.ports.prompt.resolve(profile.prompts.escalate);
|
|
437
|
+
const result = await deps.ports.llm.complete({
|
|
438
|
+
label: "escalation",
|
|
439
|
+
model: resolvedPrompt.config?.model ?? node.model,
|
|
440
|
+
reasoning: node.reasoning,
|
|
441
|
+
messages: [
|
|
442
|
+
{ role: "system", content: resolvedPrompt.text },
|
|
443
|
+
{ role: "user", content: userParts.join("\n\n") }
|
|
444
|
+
],
|
|
445
|
+
responseSchema: ESCALATION_SCHEMA,
|
|
446
|
+
signal: deps.budget.signal,
|
|
447
|
+
promptRef: { name: resolvedPrompt.name, version: resolvedPrompt.version, resolve: false }
|
|
448
|
+
});
|
|
449
|
+
deps.budget.charge("escalate", result.usage, { usd: 0, pricingMissing: true });
|
|
450
|
+
const parsed = JSON.parse(result.text ?? "");
|
|
451
|
+
if (typeof parsed.escalate !== "boolean") throw new Error(`Invalid escalate payload: ${result.text}`);
|
|
452
|
+
return { escalated: parsed.escalate };
|
|
453
|
+
} catch {
|
|
454
|
+
return { escalated: false };
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
// src/graph/nodes/guardrails.ts
|
|
459
|
+
var guardrails = async (state, deps) => {
|
|
460
|
+
const { profile } = deps;
|
|
461
|
+
const conversation = state.conversation;
|
|
462
|
+
if (!conversation || !state.draft) return { guardrailHits: [] };
|
|
463
|
+
const { params, active } = profile.guardrails;
|
|
464
|
+
const hits = [...channelPreGates(conversation)];
|
|
465
|
+
if (params.whatsappMode === "escalate_only" && conversation.sourceChannel === "whatsapp") hits.push("whatsapp");
|
|
466
|
+
if (params.judgemeEscalateOnly && isJudgemeConversation(conversation.subject, firstCustomerMessage(conversation))) {
|
|
467
|
+
hits.push("judgeme");
|
|
468
|
+
}
|
|
469
|
+
if (isAutomatedSenderEmail(conversation.customer.email, params.noreplySenders)) hits.push("noreply_sender");
|
|
470
|
+
if (profile.autoSend.requireHighTriage && state.classification?.confidence !== "high") hits.push("triage_not_high");
|
|
471
|
+
const contentHits = runGuardrails({
|
|
472
|
+
firstCustomerMessage: firstCustomerMessage(conversation) ?? "",
|
|
473
|
+
candidateAnswer: state.draft.text,
|
|
474
|
+
hasAttachment: conversation.hasCustomerAttachment,
|
|
475
|
+
blocklist: params.blocklist
|
|
476
|
+
}).filter((hit) => active.includes(guardrailBucket(hit)));
|
|
477
|
+
return { guardrailHits: [...hits, ...contentHits] };
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
// src/graph/nodes/authorize.ts
|
|
481
|
+
var authorize = async (state, deps) => {
|
|
482
|
+
const kind = "send_reply";
|
|
483
|
+
const decision = deps.profile.authorization[kind] ?? "forbidden";
|
|
484
|
+
return {
|
|
485
|
+
proposedActions: [
|
|
486
|
+
{
|
|
487
|
+
kind,
|
|
488
|
+
args: { text: state.draft?.text ?? "" },
|
|
489
|
+
idempotencyKey: `${deps.ref.channel}:${deps.ref.id}:${kind}`,
|
|
490
|
+
decision
|
|
491
|
+
}
|
|
492
|
+
]
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
|
|
496
|
+
// src/graph/tools/read-tools.ts
|
|
497
|
+
function requireString(args, key) {
|
|
498
|
+
const value = args[key];
|
|
499
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
500
|
+
throw new Error(`Missing or invalid argument "${key}": expected a non-empty string.`);
|
|
501
|
+
}
|
|
502
|
+
return value;
|
|
503
|
+
}
|
|
504
|
+
function optionalPositiveNumber(args, key, fallback2) {
|
|
505
|
+
const value = args[key];
|
|
506
|
+
if (value === void 0) return fallback2;
|
|
507
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) {
|
|
508
|
+
throw new Error(`Invalid argument "${key}": expected a positive number.`);
|
|
509
|
+
}
|
|
510
|
+
return value;
|
|
511
|
+
}
|
|
512
|
+
var orderIdSchema = {
|
|
513
|
+
type: "object",
|
|
514
|
+
properties: {
|
|
515
|
+
orderId: { type: "string", description: 'The order id, e.g. "WPL-42".' }
|
|
516
|
+
},
|
|
517
|
+
required: ["orderId"],
|
|
518
|
+
additionalProperties: false
|
|
519
|
+
};
|
|
520
|
+
var getOrder = {
|
|
521
|
+
name: "get_order",
|
|
522
|
+
description: "Look up an order by its id and return its current status.",
|
|
523
|
+
inputSchema: orderIdSchema,
|
|
524
|
+
async run(args, ctx) {
|
|
525
|
+
const orderId = requireString(args, "orderId");
|
|
526
|
+
const order = await ctx.getOrder(orderId);
|
|
527
|
+
if (!order) return `No order found for id "${orderId}".`;
|
|
528
|
+
const placed = order.placedAt ? `, placed on ${order.placedAt}` : "";
|
|
529
|
+
return `Order ${order.id}: status "${order.status}"${placed}.`;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
var getTracking = {
|
|
533
|
+
name: "get_tracking",
|
|
534
|
+
description: "Look up shipment tracking information for an order.",
|
|
535
|
+
inputSchema: orderIdSchema,
|
|
536
|
+
async run(args, ctx) {
|
|
537
|
+
const orderId = requireString(args, "orderId");
|
|
538
|
+
const tracking = await ctx.getTracking(orderId);
|
|
539
|
+
if (!tracking) return `No tracking information found for order "${orderId}".`;
|
|
540
|
+
const url = tracking.url ? ` (${tracking.url})` : "";
|
|
541
|
+
return `Order ${tracking.orderId}: ${tracking.carrier} tracking ${tracking.trackingNumber}, status "${tracking.status}"${url}.`;
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
var searchKnowledge = {
|
|
545
|
+
name: "search_knowledge",
|
|
546
|
+
description: "Search the support knowledge base for information relevant to a query.",
|
|
547
|
+
inputSchema: {
|
|
548
|
+
type: "object",
|
|
549
|
+
properties: {
|
|
550
|
+
query: { type: "string", description: "What to search for." }
|
|
551
|
+
},
|
|
552
|
+
required: ["query"],
|
|
553
|
+
additionalProperties: false
|
|
554
|
+
},
|
|
555
|
+
async run(args, ctx) {
|
|
556
|
+
const query = requireString(args, "query");
|
|
557
|
+
const hits = await ctx.searchKnowledge(query);
|
|
558
|
+
if (hits.length === 0) return `No knowledge base entries found for "${query}".`;
|
|
559
|
+
return hits.map((hit) => `- ${hit.title}: ${hit.content}`).join("\n");
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
var DEFAULT_SIMILAR_TICKETS_LIMIT = 5;
|
|
563
|
+
var findSimilarTickets = {
|
|
564
|
+
name: "find_similar_tickets",
|
|
565
|
+
description: "Find previously handled tickets similar to a query, to see how they were resolved.",
|
|
566
|
+
inputSchema: {
|
|
567
|
+
type: "object",
|
|
568
|
+
properties: {
|
|
569
|
+
query: { type: "string", description: "What to search for." },
|
|
570
|
+
limit: { type: "number", description: `Maximum number of results (default ${DEFAULT_SIMILAR_TICKETS_LIMIT}).` }
|
|
571
|
+
},
|
|
572
|
+
required: ["query"],
|
|
573
|
+
additionalProperties: false
|
|
574
|
+
},
|
|
575
|
+
async run(args, ctx) {
|
|
576
|
+
const query = requireString(args, "query");
|
|
577
|
+
const limit = optionalPositiveNumber(args, "limit", DEFAULT_SIMILAR_TICKETS_LIMIT);
|
|
578
|
+
const tickets = await ctx.findSimilarTickets(query, limit);
|
|
579
|
+
if (tickets.length === 0) return `No similar tickets found for "${query}".`;
|
|
580
|
+
return tickets.map((ticket) => `- [${ticket.category}] ${ticket.excerpt}`).join("\n");
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
var READ_TOOLS = {
|
|
584
|
+
get_order: getOrder,
|
|
585
|
+
get_tracking: getTracking,
|
|
586
|
+
search_knowledge: searchKnowledge,
|
|
587
|
+
find_similar_tickets: findSimilarTickets
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
// src/graph/tools/registry.ts
|
|
591
|
+
function resolveFor(profile, name) {
|
|
592
|
+
if (!profile.tools.includes(name)) return null;
|
|
593
|
+
const catalogued = AGENT_TOOLS[name];
|
|
594
|
+
if (!catalogued || catalogued.policy !== "read") return null;
|
|
595
|
+
return { name: catalogued.name, policy: catalogued.policy };
|
|
596
|
+
}
|
|
597
|
+
function buildToolSpecs(profile) {
|
|
598
|
+
const specs = [];
|
|
599
|
+
for (const name of profile.tools) {
|
|
600
|
+
if (!resolveFor(profile, name)) continue;
|
|
601
|
+
const impl = READ_TOOLS[name];
|
|
602
|
+
if (!impl) continue;
|
|
603
|
+
specs.push({ name: impl.name, description: impl.description, inputSchema: impl.inputSchema });
|
|
604
|
+
}
|
|
605
|
+
return specs;
|
|
606
|
+
}
|
|
607
|
+
function outcome(call, observation, isError) {
|
|
608
|
+
return { observation, isError, record: { name: call.name, arguments: call.arguments, observation } };
|
|
609
|
+
}
|
|
610
|
+
async function runToolCall(profile, call, ctx) {
|
|
611
|
+
if (!resolveFor(profile, call.name)) {
|
|
612
|
+
return outcome(call, `Tool "${call.name}" is not available for this profile.`, true);
|
|
613
|
+
}
|
|
614
|
+
const impl = READ_TOOLS[call.name];
|
|
615
|
+
if (!impl) {
|
|
616
|
+
return outcome(call, `Tool "${call.name}" is not implemented.`, true);
|
|
617
|
+
}
|
|
618
|
+
try {
|
|
619
|
+
const observation = await impl.run(call.arguments, ctx);
|
|
620
|
+
return outcome(call, observation, false);
|
|
621
|
+
} catch (err) {
|
|
622
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
623
|
+
return outcome(call, message, true);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
// src/graph/draft.ts
|
|
628
|
+
var MAX_LOOP_ROUNDS = 25;
|
|
629
|
+
async function draftWithTools(params) {
|
|
630
|
+
const { profile, llm, budget, toolContext, messages, label, model, promptRef } = params;
|
|
631
|
+
const node = profile.nodes.draft;
|
|
632
|
+
if (!node) throw new Error("draftWithTools requires profile.nodes.draft to be configured.");
|
|
633
|
+
const conversation = [...messages];
|
|
634
|
+
const sources = [];
|
|
635
|
+
for (let round = 0; round < MAX_LOOP_ROUNDS; round++) {
|
|
636
|
+
const offerTools = !budget.exhausted();
|
|
637
|
+
const tools = offerTools ? toolsOrUndefined(buildToolSpecs(profile)) : [];
|
|
638
|
+
const result = await llm.complete({
|
|
639
|
+
label,
|
|
640
|
+
model: model ?? node.model,
|
|
641
|
+
reasoning: node.reasoning,
|
|
642
|
+
messages: conversation,
|
|
643
|
+
tools,
|
|
644
|
+
signal: budget.signal,
|
|
645
|
+
promptRef
|
|
646
|
+
});
|
|
647
|
+
budget.charge("draft", result.usage, { usd: 0, pricingMissing: true });
|
|
648
|
+
if (result.toolCalls.length === 0) return finish(result.text, sources, attributionOf(result, promptRef));
|
|
649
|
+
conversation.push({ role: "assistant", content: result.text, toolCalls: result.toolCalls });
|
|
650
|
+
for (const call of result.toolCalls) {
|
|
651
|
+
budget.consumeToolCall();
|
|
652
|
+
const { observation, record } = await runToolCall(profile, call, toolContext);
|
|
653
|
+
sources.push(record);
|
|
654
|
+
conversation.push({ role: "tool", toolCallId: call.id, content: observation });
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return finish(null, sources, null);
|
|
658
|
+
}
|
|
659
|
+
function finish(text, sources, attribution) {
|
|
660
|
+
const trimmed = (text ?? "").trim();
|
|
661
|
+
if (!trimmed) throw new Error("Provider returned empty response");
|
|
662
|
+
return { text: trimmed, sources, revised: false, ...attribution ? { attribution } : {} };
|
|
663
|
+
}
|
|
664
|
+
function attributionOf(result, promptRef) {
|
|
665
|
+
return {
|
|
666
|
+
traceId: result.traceId ?? null,
|
|
667
|
+
observationId: result.observationId ?? null,
|
|
668
|
+
promptName: promptRef?.name ?? null,
|
|
669
|
+
promptVersion: promptRef?.version ?? null
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function toolsOrUndefined(specs) {
|
|
673
|
+
return specs.length > 0 ? specs : void 0;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// src/graph/nodes/shared.ts
|
|
677
|
+
var AGENT_NAME_PLACEHOLDER = /\{\{\s*agent_name\s*\}\}/gi;
|
|
678
|
+
var AGENT_NAME_PLACEHOLDER_TEST = /\{\{\s*agent_name\s*\}\}/i;
|
|
679
|
+
function applySignature(systemPrompt, agentName) {
|
|
680
|
+
const trimmedName = (typeof agentName === "string" ? agentName.trim() : "").slice(0, 200);
|
|
681
|
+
if (AGENT_NAME_PLACEHOLDER_TEST.test(systemPrompt)) {
|
|
682
|
+
const replaced = systemPrompt.replace(AGENT_NAME_PLACEHOLDER, () => trimmedName);
|
|
683
|
+
return replaced.replace(/\n{3,}/g, "\n\n").trim();
|
|
684
|
+
}
|
|
685
|
+
if (trimmedName) {
|
|
686
|
+
return `${systemPrompt}
|
|
687
|
+
|
|
688
|
+
Signe toujours la r\xE9ponse avec ce nom : ${trimmedName}.`;
|
|
689
|
+
}
|
|
690
|
+
return systemPrompt;
|
|
691
|
+
}
|
|
692
|
+
function writerSystemPrompt(resolvedPrompt, conversation) {
|
|
693
|
+
return applySignature(resolvedPrompt, conversation.sourceChannel === "whatsapp" ? "" : void 0);
|
|
694
|
+
}
|
|
695
|
+
function buildDraftMessages(conversation, systemPrompt) {
|
|
696
|
+
const context = conversation.customer.orderContext;
|
|
697
|
+
const system = [systemPrompt, context ? `## Informations client
|
|
698
|
+
${context}` : null].filter((part) => !!part).join("\n\n");
|
|
699
|
+
const turns = conversation.messages.map((m) => ({ role: m.role, content: m.content }));
|
|
700
|
+
return system ? [{ role: "system", content: system }, ...turns] : turns;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// src/graph/nodes/draft.ts
|
|
704
|
+
var LABEL = "fast-response";
|
|
705
|
+
var draft = async (state, deps) => {
|
|
706
|
+
const { profile } = deps;
|
|
707
|
+
const node = profile.nodes.draft;
|
|
708
|
+
if (!state.conversation || !node) return {};
|
|
709
|
+
const resolvedPrompt = await deps.ports.prompt.resolve(profile.prompts.draft);
|
|
710
|
+
const messages = buildDraftMessages(state.conversation, writerSystemPrompt(resolvedPrompt.text, state.conversation));
|
|
711
|
+
const result = await draftWithTools({
|
|
712
|
+
profile,
|
|
713
|
+
llm: deps.ports.llm,
|
|
714
|
+
budget: deps.budget,
|
|
715
|
+
toolContext: deps.toolContext,
|
|
716
|
+
messages,
|
|
717
|
+
label: LABEL,
|
|
718
|
+
// The resolved Langfuse prompt's own model config WINS over the
|
|
719
|
+
// profile's fallback (I16) — see `PromptPort.resolve`'s doc.
|
|
720
|
+
model: resolvedPrompt.config?.model ?? node.model,
|
|
721
|
+
promptRef: { name: resolvedPrompt.name, version: resolvedPrompt.version, resolve: false }
|
|
722
|
+
});
|
|
723
|
+
return { draft: result };
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
// src/graph/nodes/evaluate.ts
|
|
727
|
+
var EVALUATION_SCHEMA = {
|
|
728
|
+
type: "object",
|
|
729
|
+
properties: {
|
|
730
|
+
verdict: { type: "string", enum: [...EVALUATION_VERDICTS] },
|
|
731
|
+
confidence: { type: "number", minimum: 0, maximum: 1 },
|
|
732
|
+
reason: { type: "string", maxLength: REASONING_MAX_LEN }
|
|
733
|
+
},
|
|
734
|
+
required: ["verdict", "confidence", "reason"],
|
|
735
|
+
additionalProperties: false
|
|
736
|
+
};
|
|
737
|
+
function failed(err) {
|
|
738
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
739
|
+
return {
|
|
740
|
+
verdict: null,
|
|
741
|
+
confidence: null,
|
|
742
|
+
reason: `evaluation error: ${message}`.slice(0, REASONING_MAX_LEN),
|
|
743
|
+
status: "error"
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
var evaluate = async (state, deps) => {
|
|
747
|
+
const { profile } = deps;
|
|
748
|
+
const node = profile.nodes.evaluate;
|
|
749
|
+
if (!node || !state.conversation || !state.draft) {
|
|
750
|
+
return { verdict: failed(new Error("evaluate ran without a configured node, conversation or draft")) };
|
|
751
|
+
}
|
|
752
|
+
try {
|
|
753
|
+
const evaluatePrompt = await deps.ports.prompt.resolve(profile.prompts.evaluate);
|
|
754
|
+
const draftPrompt = await deps.ports.prompt.resolve(profile.prompts.draft);
|
|
755
|
+
const result = await (deps.ports.evaluator ?? deps.ports.llm).complete({
|
|
756
|
+
label: "evaluation",
|
|
757
|
+
// The resolved Langfuse prompt's own model config WINS over the
|
|
758
|
+
// profile's fallback (I16) — see `PromptPort.resolve`'s doc.
|
|
759
|
+
model: evaluatePrompt.config?.model ?? node.model,
|
|
760
|
+
reasoning: node.reasoning,
|
|
761
|
+
messages: buildMessages({
|
|
762
|
+
conversation: state.conversation,
|
|
763
|
+
candidateAnswer: state.draft.text,
|
|
764
|
+
systemPrompt: evaluatePrompt.text,
|
|
765
|
+
writerKnowledge: writerSystemPrompt(draftPrompt.text, state.conversation)
|
|
766
|
+
}),
|
|
767
|
+
responseSchema: EVALUATION_SCHEMA,
|
|
768
|
+
signal: deps.budget.signal,
|
|
769
|
+
promptRef: { name: evaluatePrompt.name, version: evaluatePrompt.version, resolve: false }
|
|
770
|
+
});
|
|
771
|
+
deps.budget.charge("evaluate", result.usage, { usd: 0, pricingMissing: true });
|
|
772
|
+
return { verdict: parseVerdict(result.text) };
|
|
773
|
+
} catch (err) {
|
|
774
|
+
return { verdict: failed(err) };
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
function parseVerdict(text) {
|
|
778
|
+
const parsed = JSON.parse(text ?? "");
|
|
779
|
+
const confidence = parsed.confidence;
|
|
780
|
+
if (!isEvaluationVerdict(parsed.verdict)) throw new Error(`Invalid evaluation verdict: ${text}`);
|
|
781
|
+
if (typeof confidence !== "number" || !Number.isFinite(confidence) || confidence < 0 || confidence > 1) {
|
|
782
|
+
throw new Error(`Evaluation confidence out of range: ${String(confidence)}`);
|
|
783
|
+
}
|
|
784
|
+
return {
|
|
785
|
+
verdict: parsed.verdict,
|
|
786
|
+
confidence,
|
|
787
|
+
reason: String(parsed.reason ?? "").slice(0, REASONING_MAX_LEN),
|
|
788
|
+
status: "success"
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
function buildMessages(input) {
|
|
792
|
+
const { conversation, candidateAnswer, systemPrompt, writerKnowledge } = input;
|
|
793
|
+
const transcript = conversation.messages.map((m) => `[${m.role === "user" ? "Client" : "Agent"}]: ${m.content}`).join("\n");
|
|
794
|
+
const sections = [
|
|
795
|
+
section("Instructions & connaissances du r\xE9dacteur", writerKnowledge),
|
|
796
|
+
section("Infos client / commandes", conversation.customer.orderContext),
|
|
797
|
+
section("Conversation", transcript),
|
|
798
|
+
section("R\xE9ponse candidate \xE0 \xE9valuer", candidateAnswer)
|
|
799
|
+
].filter((part) => !!part);
|
|
800
|
+
return [
|
|
801
|
+
{ role: "system", content: systemPrompt },
|
|
802
|
+
{ role: "user", content: sections.join("\n\n") }
|
|
803
|
+
];
|
|
804
|
+
}
|
|
805
|
+
function section(title, body) {
|
|
806
|
+
const trimmed = body?.trim();
|
|
807
|
+
return trimmed ? `## ${title}
|
|
808
|
+
${trimmed}` : null;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// src/graph/revise.ts
|
|
812
|
+
async function reviseDraft(params) {
|
|
813
|
+
const { profile, llm, budget, draft: draft2, verdict, messages, label, model, promptRef } = params;
|
|
814
|
+
const node = profile.nodes.revise;
|
|
815
|
+
if (!node) return draft2;
|
|
816
|
+
let result;
|
|
817
|
+
try {
|
|
818
|
+
result = await llm.complete({
|
|
819
|
+
label,
|
|
820
|
+
model: model ?? node.model,
|
|
821
|
+
reasoning: node.reasoning,
|
|
822
|
+
messages: [...messages, ...buildRevisionTurn(draft2, verdict)],
|
|
823
|
+
tools: [],
|
|
824
|
+
// tool-free by design (§6.4)
|
|
825
|
+
signal: budget.signal,
|
|
826
|
+
promptRef
|
|
827
|
+
});
|
|
828
|
+
} catch (err) {
|
|
829
|
+
if (err?.name === "AbortError") throw err;
|
|
830
|
+
return draft2;
|
|
831
|
+
}
|
|
832
|
+
budget.charge("revise", result.usage, { usd: 0, pricingMissing: true });
|
|
833
|
+
const revisedText = result.text?.trim();
|
|
834
|
+
if (!revisedText) return draft2;
|
|
835
|
+
return { text: revisedText, sources: draft2.sources, revised: true, attribution: attributionOf(result, promptRef) };
|
|
836
|
+
}
|
|
837
|
+
function buildRevisionTurn(draft2, verdict) {
|
|
838
|
+
return [
|
|
839
|
+
{ role: "assistant", content: draft2.text },
|
|
840
|
+
{
|
|
841
|
+
role: "user",
|
|
842
|
+
content: [
|
|
843
|
+
"Ta r\xE9ponse a \xE9t\xE9 refus\xE9e par le relecteur pour la raison suivante :",
|
|
844
|
+
verdict.reason,
|
|
845
|
+
"",
|
|
846
|
+
"R\xE9\xE9cris la r\xE9ponse en corrigeant ce point. Garde le m\xEAme ton, ne r\xE9ponds",
|
|
847
|
+
"que par le texte corrig\xE9, sans commentaire ni pr\xE9ambule."
|
|
848
|
+
].join("\n")
|
|
849
|
+
}
|
|
850
|
+
];
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
// src/graph/nodes/revise.ts
|
|
854
|
+
var revise = async (state, deps) => {
|
|
855
|
+
const { profile } = deps;
|
|
856
|
+
const node = profile.nodes.revise;
|
|
857
|
+
if (!node || !state.conversation || !state.draft || !state.verdict) return {};
|
|
858
|
+
const draftPrompt = await deps.ports.prompt.resolve(profile.prompts.draft);
|
|
859
|
+
const messages = buildDraftMessages(state.conversation, writerSystemPrompt(draftPrompt.text, state.conversation));
|
|
860
|
+
const revisePrompt = await deps.ports.prompt.resolve(profile.prompts.revise);
|
|
861
|
+
const revised = await reviseDraft({
|
|
862
|
+
profile,
|
|
863
|
+
llm: deps.ports.llm,
|
|
864
|
+
budget: deps.budget,
|
|
865
|
+
draft: state.draft,
|
|
866
|
+
verdict: state.verdict,
|
|
867
|
+
messages,
|
|
868
|
+
label: "revise",
|
|
869
|
+
model: revisePrompt.config?.model ?? node.model,
|
|
870
|
+
promptRef: { name: revisePrompt.name, version: revisePrompt.version, resolve: false }
|
|
871
|
+
});
|
|
872
|
+
return { draft: revised, reviseCount: 1 };
|
|
873
|
+
};
|
|
874
|
+
|
|
875
|
+
// src/graph/markdown-to-html.ts
|
|
876
|
+
function escapeHtml(s) {
|
|
877
|
+
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
|
878
|
+
}
|
|
879
|
+
function markdownToHtml(markdown) {
|
|
880
|
+
let html = escapeHtml(markdown);
|
|
881
|
+
html = html.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, '<a href="$2">$1</a>');
|
|
882
|
+
html = html.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
|
|
883
|
+
html = html.replace(/(^|\s)\*([^\s*](?:[^*\n]*[^\s*])?)\*(?=$|\s|[.,;:!?)])/g, "$1<em>$2</em>");
|
|
884
|
+
return html.split(/\n{2,}/).map((p) => `<p>${p.trim().replace(/\n/g, "<br>")}</p>`).join("");
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// src/graph/nodes/act.ts
|
|
888
|
+
function hasAgentRepliedSince(lastAgentReplyAt, queuedAt) {
|
|
889
|
+
if (!lastAgentReplyAt) return false;
|
|
890
|
+
if (!queuedAt) return true;
|
|
891
|
+
return lastAgentReplyAt.getTime() > queuedAt.getTime() - CLOCK_SKEW_MARGIN_MS;
|
|
892
|
+
}
|
|
893
|
+
function hasDiverged(fresh, generatedFrom) {
|
|
894
|
+
return fresh.messageCount !== generatedFrom.messageCount || (fresh.lastMessageAt?.getTime() ?? null) !== (generatedFrom.lastMessageAt?.getTime() ?? null);
|
|
895
|
+
}
|
|
896
|
+
var act = async (state, deps) => {
|
|
897
|
+
const generatedFrom = state.conversation;
|
|
898
|
+
const draft2 = state.draft;
|
|
899
|
+
const action = state.proposedActions[0];
|
|
900
|
+
if (!generatedFrom || !draft2 || !action) return {};
|
|
901
|
+
const mode = generatedFrom.sourceChannel === "whatsapp" ? "whatsapp_note" : "email";
|
|
902
|
+
const fresh = await deps.ports.conversation.read(deps.ref);
|
|
903
|
+
if (mode === "email" && !fresh.customer.email) return { guardrailHits: ["customer_email_missing"] };
|
|
904
|
+
if (fresh.isClosed) return { guardrailHits: ["ticket_closed"] };
|
|
905
|
+
if (hasAgentRepliedSince(fresh.lastAgentReplyAt, deps.queuedAt ?? null)) {
|
|
906
|
+
return { guardrailHits: ["agent_replied"] };
|
|
907
|
+
}
|
|
908
|
+
if (hasDiverged(fresh, generatedFrom)) return { guardrailHits: ["diverged"] };
|
|
909
|
+
if (deps.budget.signal.aborted) return { guardrailHits: ["run_deadline"] };
|
|
910
|
+
const claimed = deps.send.mode === "claimed" ? await deps.send.claim({ draft: draft2, verdict: state.verdict }) : true;
|
|
911
|
+
if (!claimed) return {};
|
|
912
|
+
const reply = mode === "email" ? {
|
|
913
|
+
mode: "email",
|
|
914
|
+
bodyText: draft2.text,
|
|
915
|
+
// The draft is markdown; the email channel's HTML body must be
|
|
916
|
+
// rendered, not the raw source.
|
|
917
|
+
bodyHtml: markdownToHtml(draft2.text),
|
|
918
|
+
subject: fresh.subject,
|
|
919
|
+
fromAddress: deps.profile.autoSend.senderEmail ?? "",
|
|
920
|
+
receiverName: fresh.customer.name,
|
|
921
|
+
// Guaranteed non-null by the `customer_email_missing` gate above,
|
|
922
|
+
// in email mode — `?? ''` is belt-and-braces for the type, not a
|
|
923
|
+
// real fallback.
|
|
924
|
+
receiverEmail: fresh.customer.email ?? "",
|
|
925
|
+
idempotencyKey: action.idempotencyKey
|
|
926
|
+
} : {
|
|
927
|
+
mode: "whatsapp_note",
|
|
928
|
+
// Raw draft text: no markdown-to-HTML rendering (§4.2/§6.4) — the
|
|
929
|
+
// note carries the model's text as-is, the chevron prefix is the
|
|
930
|
+
// adapter's job.
|
|
931
|
+
bodyText: draft2.text,
|
|
932
|
+
idempotencyKey: action.idempotencyKey
|
|
933
|
+
};
|
|
934
|
+
const { messageId } = await deps.ports.reply.post(deps.ref, reply);
|
|
935
|
+
if (deps.send.mode === "claimed") await deps.send.commit(messageId);
|
|
936
|
+
return {};
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
// src/graph/run-ticket.ts
|
|
940
|
+
function merge(state, patch) {
|
|
941
|
+
return { ...state, ...patch };
|
|
942
|
+
}
|
|
943
|
+
async function step(name, node, state, deps) {
|
|
944
|
+
if (!deps.trace) return merge(state, await node(state, deps));
|
|
945
|
+
const startedAt = Date.now();
|
|
946
|
+
try {
|
|
947
|
+
const patch = await node(state, deps);
|
|
948
|
+
deps.trace({ node: name, patch: structuredClone(patch), durationMs: Date.now() - startedAt });
|
|
949
|
+
return merge(state, patch);
|
|
950
|
+
} catch (err) {
|
|
951
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
952
|
+
deps.trace({ node: name, patch: {}, durationMs: Date.now() - startedAt, error });
|
|
953
|
+
throw err;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
async function applyOutcomeTags(outcome2, verdict, deps) {
|
|
957
|
+
const { ports, ref, audit } = deps;
|
|
958
|
+
if (outcome2 === "needs_human") await ports.state.flag(ref, audit.needsHumanTag);
|
|
959
|
+
if (outcome2 === "guardrail_hold") await ports.state.flag(ref, audit.escalationTag);
|
|
960
|
+
if (outcome2 === "sent") {
|
|
961
|
+
await ports.state.flag(ref, audit.sentTag);
|
|
962
|
+
if (requiresFollowup(verdict?.verdict ?? null)) await ports.state.flag(ref, audit.followupTag);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
async function finish2(state, deps, outcome2) {
|
|
966
|
+
const final = { ...state, outcome: outcome2 };
|
|
967
|
+
const { audit } = deps.profile;
|
|
968
|
+
if (final.classification) await deps.ports.state.record(deps.ref, final.classification, audit);
|
|
969
|
+
await applyOutcomeTags(outcome2, final.verdict, { ports: deps.ports, ref: deps.ref, audit });
|
|
970
|
+
return final;
|
|
971
|
+
}
|
|
972
|
+
function isConversationOver(classification) {
|
|
973
|
+
return classification?.conversationOver === true;
|
|
974
|
+
}
|
|
975
|
+
function isFallbackClassification(classification) {
|
|
976
|
+
return classification?.isFallback === true;
|
|
977
|
+
}
|
|
978
|
+
function hasNoDraftNode(profile) {
|
|
979
|
+
return !profile.nodes.draft;
|
|
980
|
+
}
|
|
981
|
+
async function runTicket(deps, options = {}) {
|
|
982
|
+
const { profile } = deps;
|
|
983
|
+
const { resume, until } = options;
|
|
984
|
+
let s = initialState();
|
|
985
|
+
s = await step("fetchContext", fetchContext, s, deps);
|
|
986
|
+
if (s.outcome === "failed") return finish2(s, deps, "failed");
|
|
987
|
+
if (resume) {
|
|
988
|
+
s = merge(s, { classification: resume.classification, escalated: resume.escalated });
|
|
989
|
+
} else {
|
|
990
|
+
s = await step("triage", triage, s, deps);
|
|
991
|
+
if (profile.nodes.escalate) s = await step("escalate", escalate, s, deps);
|
|
992
|
+
}
|
|
993
|
+
if (until === "triage") return s;
|
|
994
|
+
if (s.escalated) return finish2(s, deps, "escalated");
|
|
995
|
+
const stopHits = s.conversation ? stopOptOut(s.conversation) : [];
|
|
996
|
+
if (stopHits.length) return finish2(merge(s, { guardrailHits: stopHits }), deps, "guardrail_hold");
|
|
997
|
+
if (isConversationOver(s.classification)) return finish2(s, deps, "no_reply_needed");
|
|
998
|
+
if (isFallbackClassification(s.classification)) return finish2(s, deps, "triaged_only");
|
|
999
|
+
if (hasNoDraftNode(profile)) return finish2(s, deps, "triaged_only");
|
|
1000
|
+
if (s.conversation) {
|
|
1001
|
+
const preGateHits = channelPreGates(s.conversation);
|
|
1002
|
+
if (preGateHits.length) return finish2(merge(s, { guardrailHits: preGateHits }), deps, "guardrail_hold");
|
|
1003
|
+
}
|
|
1004
|
+
s = await step("draft", draft, s, deps);
|
|
1005
|
+
if (profile.nodes.evaluate) {
|
|
1006
|
+
s = await step("evaluate", evaluate, s, deps);
|
|
1007
|
+
if (needsRevision(s.verdict, profile, s.reviseCount)) {
|
|
1008
|
+
s = await step("revise", revise, s, deps);
|
|
1009
|
+
s = await step("evaluate", evaluate, s, deps);
|
|
1010
|
+
}
|
|
1011
|
+
if (!isSendable(s.verdict, profile)) return finish2(s, deps, "needs_human");
|
|
1012
|
+
}
|
|
1013
|
+
if (!isAutoSendEligible(s, deps)) return finish2(s, deps, "ready");
|
|
1014
|
+
s = await step("guardrails", guardrails, s, deps);
|
|
1015
|
+
if (s.guardrailHits.length) return finish2(s, deps, "guardrail_hold");
|
|
1016
|
+
s = await step("authorize", authorize, s, deps);
|
|
1017
|
+
if (s.proposedActions.some((a) => a.decision !== "auto")) return finish2(s, deps, "awaiting_approval");
|
|
1018
|
+
s = await step("act", act, s, deps);
|
|
1019
|
+
return finish2(s, deps, s.guardrailHits.length ? "guardrail_hold" : "sent");
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
// src/status/machine.ts
|
|
1023
|
+
var GENERATED_RESPONSE_STATUSES = [
|
|
1024
|
+
"pending",
|
|
1025
|
+
"ready",
|
|
1026
|
+
"sending",
|
|
1027
|
+
"sent",
|
|
1028
|
+
"failed",
|
|
1029
|
+
"no_reply_needed",
|
|
1030
|
+
"invalidated",
|
|
1031
|
+
"expired"
|
|
1032
|
+
];
|
|
1033
|
+
function isGeneratedResponseStatus(value) {
|
|
1034
|
+
return typeof value === "string" && GENERATED_RESPONSE_STATUSES.includes(value);
|
|
1035
|
+
}
|
|
1036
|
+
var ALLOWED_TRANSITIONS = {
|
|
1037
|
+
pending: ["ready", "failed", "no_reply_needed", "sending"],
|
|
1038
|
+
ready: ["sending", "invalidated", "expired"],
|
|
1039
|
+
sending: ["sent", "ready"],
|
|
1040
|
+
sent: [],
|
|
1041
|
+
failed: [],
|
|
1042
|
+
no_reply_needed: [],
|
|
1043
|
+
invalidated: [],
|
|
1044
|
+
expired: []
|
|
1045
|
+
};
|
|
1046
|
+
function canTransition(from, to) {
|
|
1047
|
+
if (!isGeneratedResponseStatus(from) || !isGeneratedResponseStatus(to)) return false;
|
|
1048
|
+
return ALLOWED_TRANSITIONS[from].includes(to);
|
|
1049
|
+
}
|
|
1050
|
+
function isTerminalStatus(status) {
|
|
1051
|
+
if (!isGeneratedResponseStatus(status)) return false;
|
|
1052
|
+
return ALLOWED_TRANSITIONS[status].length === 0;
|
|
1053
|
+
}
|
|
1054
|
+
var InvalidStatusTransitionError = class extends Error {
|
|
1055
|
+
from;
|
|
1056
|
+
to;
|
|
1057
|
+
constructor(from, to) {
|
|
1058
|
+
super(`generated-response: illegal status transition "${from}" -> "${to}"`);
|
|
1059
|
+
this.name = "InvalidStatusTransitionError";
|
|
1060
|
+
this.from = from;
|
|
1061
|
+
this.to = to;
|
|
1062
|
+
}
|
|
1063
|
+
};
|
|
1064
|
+
function assertTransition(from, to) {
|
|
1065
|
+
if (!canTransition(from, to)) throw new InvalidStatusTransitionError(from, to);
|
|
1066
|
+
}
|
|
1067
|
+
function openTicketKeyFor(status, ticketId) {
|
|
1068
|
+
return isTerminalStatus(status) ? null : ticketId;
|
|
1069
|
+
}
|
|
1070
|
+
function reclaimStalledSend() {
|
|
1071
|
+
return { status: "ready", autoSendDecision: "hold" };
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
// src/prompts/slots.ts
|
|
1075
|
+
var PROMPT_SLOTS = [
|
|
1076
|
+
"triage",
|
|
1077
|
+
"escalation",
|
|
1078
|
+
"evaluation",
|
|
1079
|
+
"suggest",
|
|
1080
|
+
"diff-analysis",
|
|
1081
|
+
"shared/style-email",
|
|
1082
|
+
"shared/style-whatsapp"
|
|
1083
|
+
];
|
|
1084
|
+
function resolvePromptName(slot, config) {
|
|
1085
|
+
return config.promptNames?.[slot] ?? `${config.promptPrefix}${slot}`;
|
|
1086
|
+
}
|
|
1087
|
+
function resolveReviseName(config) {
|
|
1088
|
+
return config.promptNames?.revise ?? `${config.promptPrefix}revise`;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// src/records/ids.ts
|
|
1092
|
+
var CATEGORY_OBJECT_UID = "8a1c8de3-c288-40a5-9294-a883e1c89784";
|
|
1093
|
+
var CATEGORY_GROUP_OBJECT_UID = "71ed9161-838a-431b-886c-b99d8a9099a6";
|
|
1094
|
+
var AGENT_OBJECT_UID = "47c3b216-c5b2-49bb-b1d9-e87db60b7c02";
|
|
1095
|
+
var TRIAGE_DECISION_OBJECT_UID = "e6483697-b3ab-424e-b070-a572ad74f899";
|
|
1096
|
+
var GENERATED_RESPONSE_OBJECT_UID = "367263bd-438d-4cec-8cd7-14f9e0dc780a";
|
|
1097
|
+
var RESPONSE_COMPARISON_OBJECT_UID = "a349d47c-fe21-4e09-9475-979f69fbab88";
|
|
1098
|
+
var EVALUATION_OBJECT_UID = "8a73e22c-d814-47ba-a4ae-f2ca8fff1f35";
|
|
1099
|
+
var DIFF_ANALYSIS_OBJECT_UID = "7ebb67c3-0f0a-4987-b320-0672a877bb0d";
|
|
1100
|
+
var PIPELINE_STATE_OBJECT_UID = "812c8498-736c-43bd-8a86-5a979940351e";
|
|
1101
|
+
var PROMPT_CACHE_OBJECT_UID = "c01e6c2b-461b-4c3d-8de3-424478457fc5";
|
|
1102
|
+
var CATEGORY_FIELD_NAME_UID = "a688aa9e-3cb9-49f6-bc15-07caf0cad481";
|
|
1103
|
+
var CATEGORY_FIELD_TAG_NAME_UID = "4df1f653-8e24-45cb-acf9-dcb293c3a110";
|
|
1104
|
+
var CATEGORY_FIELD_ORDER_UID = "25e85490-f365-4d28-98cd-87f93b24f653";
|
|
1105
|
+
var CATEGORY_FIELD_GROUP_ID_UID = "667697a4-9877-4df7-9b41-86e60b8b0039";
|
|
1106
|
+
var CATEGORY_FIELD_AGENT_ID_UID = "96e36d98-537c-4db1-ab84-2bb3c188b078";
|
|
1107
|
+
var CATEGORY_FIELD_EXTRA_TAGS_UID = "8673a239-1a7d-4e4f-b951-b6c5c9d4787e";
|
|
1108
|
+
var CATEGORY_FIELD_EXAMPLES_UID = "39e52ad6-34b1-4151-a70b-7f996648b9b0";
|
|
1109
|
+
var CATEGORY_FIELD_FAST_RESPONSE_ENABLED_UID = "4fa75e78-b826-4741-9612-b6cf28bde9f9";
|
|
1110
|
+
var CATEGORY_FIELD_AUTO_REPLY_ENABLED_UID = "c6822551-821f-4255-b220-be40c9b56052";
|
|
1111
|
+
var CATEGORY_INDEX_TAG_NAME_UID = "5463dac5-715d-4545-ad75-905477d868eb";
|
|
1112
|
+
var CATEGORY_INDEX_NAME_UID = "2eda6e49-387a-4e08-94a8-06250652692d";
|
|
1113
|
+
var CATEGORY_INDEX_ORDER_UID = "bf4b1f9c-2dc8-4480-8fcb-dba789e8fe62";
|
|
1114
|
+
var CATEGORY_GROUP_FIELD_NAME_UID = "5feee22b-95dd-4c30-87ea-68a6fd5c4e7a";
|
|
1115
|
+
var CATEGORY_GROUP_FIELD_ORDER_UID = "975be023-fa11-4168-9a7d-e24b03f7a60e";
|
|
1116
|
+
var CATEGORY_GROUP_INDEX_NAME_UID = "e3b2e5cb-9c3a-4824-8b0e-32a9abfed4fd";
|
|
1117
|
+
var AGENT_FIELD_NAME_UID = "e9cfec6f-15c6-4d02-8f79-0667f64b9eb5";
|
|
1118
|
+
var AGENT_FIELD_PROVIDER_UID = "e522b809-e8a7-4439-a2df-936158d04389";
|
|
1119
|
+
var AGENT_FIELD_MODEL_ID_UID = "d95977ba-362c-44d6-a2f0-24156c76cf8a";
|
|
1120
|
+
var AGENT_FIELD_STATUS_UID = "348725a0-a896-4f8d-8a56-86f4193234a8";
|
|
1121
|
+
var AGENT_FIELD_DEFAULT_KEY_UID = "0134491a-c969-4c42-894c-36ad4880fed3";
|
|
1122
|
+
var AGENT_FIELD_PROMPT_NAME_UID = "32e7f234-00bb-44d2-917b-be28f32f7214";
|
|
1123
|
+
var AGENT_FIELD_PROMPT_LABEL_UID = "bdee53ff-571a-4df6-91ec-00b513a70fe0";
|
|
1124
|
+
var AGENT_FIELD_PROMPT_VERSION_UID = "e7c66f99-e1e0-4fc2-9f9e-3bafe3af8e88";
|
|
1125
|
+
var AGENT_FIELD_SYSTEM_PROMPT_SNAPSHOT_UID = "710b73c6-929b-48b7-abc0-792849adf1c2";
|
|
1126
|
+
var AGENT_FIELD_REASONING_EFFORT_UID = "aa57fc6e-c989-47d3-9fc8-e04184b1e67c";
|
|
1127
|
+
var AGENT_FIELD_MAX_TOOL_CALLS_UID = "6948a5ca-48ef-45d7-9118-c7ab195343a3";
|
|
1128
|
+
var AGENT_INDEX_DEFAULT_KEY_UID = "084db2ee-6aae-4b92-af6c-ed9c8dfda075";
|
|
1129
|
+
var TRIAGE_DECISION_FIELD_TICKET_ID_UID = "c3df59f1-248f-4396-aa70-7d6ada5edec7";
|
|
1130
|
+
var TRIAGE_DECISION_FIELD_DECIDED_AT_UID = "8048f69b-2cfe-45e4-9be9-b6d667e92021";
|
|
1131
|
+
var TRIAGE_DECISION_FIELD_CATEGORY_ID_UID = "1a9f8b77-219b-4b73-935c-620cb228491f";
|
|
1132
|
+
var TRIAGE_DECISION_FIELD_TAG_UID = "d8e814b8-d4ac-4cd4-9892-b27e19c66e20";
|
|
1133
|
+
var TRIAGE_DECISION_FIELD_CONFIDENCE_UID = "9fb1be7b-f697-455f-a7d0-a0e00f8cf634";
|
|
1134
|
+
var TRIAGE_DECISION_FIELD_REASONING_UID = "75716a98-d430-4c42-ad82-cdf091d8ebf2";
|
|
1135
|
+
var TRIAGE_DECISION_FIELD_CONVERSATION_OVER_UID = "60ffd534-7cda-497e-8b8f-6b6b10de70c1";
|
|
1136
|
+
var TRIAGE_DECISION_FIELD_ESCALATED_UID = "dd8384af-b3d1-48af-a883-8e9f0655960c";
|
|
1137
|
+
var TRIAGE_DECISION_FIELD_ESCALATION_CONFIDENCE_UID = "ebdf3a2d-17f7-4da6-a1c4-d0c35febf879";
|
|
1138
|
+
var TRIAGE_DECISION_FIELD_ESCALATION_REASONING_UID = "d07aa556-b417-479b-a30b-fd29d51ff9e3";
|
|
1139
|
+
var TRIAGE_DECISION_FIELD_STATUS_UID = "7583d228-4449-40ef-9e7e-44e34897e020";
|
|
1140
|
+
var TRIAGE_DECISION_FIELD_ERROR_UID = "b271362b-a1b3-4110-a197-0b7a2ec6b152";
|
|
1141
|
+
var TRIAGE_DECISION_FIELD_RUN_ID_UID = "a1e244d6-8f4f-4cd5-8794-14f6e419b64e";
|
|
1142
|
+
var TRIAGE_DECISION_FIELD_SUBJECT_RENAMED_UID = "449f1960-be88-4e42-96ee-43cd90f36f4c";
|
|
1143
|
+
var TRIAGE_DECISION_INDEX_TICKET_ID_UID = "20433066-e029-4faf-8033-c205cf5de0fb";
|
|
1144
|
+
var TRIAGE_DECISION_INDEX_DECIDED_AT_UID = "94040f6d-1d55-498f-8db8-abe5aed17c0a";
|
|
1145
|
+
var TRIAGE_DECISION_INDEX_ESCALATED_UID = "1c0ac4c3-9a48-4858-bbbf-0c689bbb5be5";
|
|
1146
|
+
var GENERATED_RESPONSE_FIELD_TICKET_ID_UID = "5e4cc51f-a22d-4772-8c81-287baa51fa25";
|
|
1147
|
+
var GENERATED_RESPONSE_FIELD_OPEN_TICKET_KEY_UID = "a05b435a-e297-476b-9147-42dd7e69f5bd";
|
|
1148
|
+
var GENERATED_RESPONSE_FIELD_STATUS_UID = "674975e4-d61f-4b4c-9e70-5b4a9133cd0d";
|
|
1149
|
+
var GENERATED_RESPONSE_FIELD_TRIAGE_DECISION_ID_UID = "fdb4a0fb-9d78-4758-b9aa-e420b854d277";
|
|
1150
|
+
var GENERATED_RESPONSE_FIELD_CATEGORY_ID_UID = "8710988e-9409-4632-83b5-4bb6609cd384";
|
|
1151
|
+
var GENERATED_RESPONSE_FIELD_AGENT_ID_UID = "be4d2c06-5108-467a-89fb-24212c82801d";
|
|
1152
|
+
var GENERATED_RESPONSE_FIELD_CHANNEL_UID = "4fc8cd40-3e59-4da8-a981-81171da4323a";
|
|
1153
|
+
var GENERATED_RESPONSE_FIELD_RESPONSE_TEXT_UID = "917926c0-38c6-48b8-835e-922f539777bc";
|
|
1154
|
+
var GENERATED_RESPONSE_FIELD_SOURCES_UID = "99774717-7a7b-454a-b384-c4f5c8770079";
|
|
1155
|
+
var GENERATED_RESPONSE_FIELD_TRACED_INPUT_UID = "3b6540dd-2532-4ef3-99a9-9539bf3ac743";
|
|
1156
|
+
var GENERATED_RESPONSE_FIELD_VERDICT_UID = "b727b513-77c9-4414-a3c3-282ff1e3712c";
|
|
1157
|
+
var GENERATED_RESPONSE_FIELD_GUARDRAIL_HITS_UID = "2b010fe3-949f-45f9-9547-a3f5425dc849";
|
|
1158
|
+
var GENERATED_RESPONSE_FIELD_AUTO_SEND_DECISION_UID = "aa050341-446d-448b-a83f-30bccd328962";
|
|
1159
|
+
var GENERATED_RESPONSE_FIELD_FOLLOWUP_REQUIRED_UID = "c598a05b-7354-4445-b114-a4e6e388f965";
|
|
1160
|
+
var GENERATED_RESPONSE_FIELD_SERVED_COUNT_UID = "d5c4f8c3-316e-4a53-a9c8-b3bf1e367620";
|
|
1161
|
+
var GENERATED_RESPONSE_FIELD_SERVED_TO_UID = "a744d0c8-61ed-4869-ad53-2aab2505ae3f";
|
|
1162
|
+
var GENERATED_RESPONSE_FIELD_GENERATED_AT_UID = "229ab5da-a68e-49eb-85d4-7fab7941dca0";
|
|
1163
|
+
var GENERATED_RESPONSE_FIELD_EXPIRES_AT_UID = "6d2fc2f8-16d7-4eed-b307-41972caea350";
|
|
1164
|
+
var GENERATED_RESPONSE_FIELD_SENT_AT_UID = "a35c9745-e4bf-4dc2-9e70-1aad4649a112";
|
|
1165
|
+
var GENERATED_RESPONSE_FIELD_SENT_MESSAGE_ID_UID = "65b0ae06-32a7-4938-9464-b31bdb4cdf26";
|
|
1166
|
+
var GENERATED_RESPONSE_FIELD_LANGFUSE_TRACE_ID_UID = "c107c692-ec5e-47f6-8fcc-e0817c22ebf9";
|
|
1167
|
+
var GENERATED_RESPONSE_FIELD_LANGFUSE_OBSERVATION_ID_UID = "789c0773-63ce-4536-b1a0-e182feefd529";
|
|
1168
|
+
var GENERATED_RESPONSE_FIELD_PROMPT_NAME_UID = "ffab81da-3764-4aba-969e-1a5030fb0a92";
|
|
1169
|
+
var GENERATED_RESPONSE_FIELD_PROMPT_VERSION_UID = "aa91867a-41c4-4ebe-ba7a-0baeeb82f9c5";
|
|
1170
|
+
var GENERATED_RESPONSE_FIELD_ERROR_UID = "40994b59-75f0-4c84-8a8a-a8d3c6cc2b09";
|
|
1171
|
+
var GENERATED_RESPONSE_FIELD_GENERATED_MESSAGE_COUNT_UID = "33a282d3-7a1c-45a3-945e-a39ea459c5f8";
|
|
1172
|
+
var GENERATED_RESPONSE_FIELD_GENERATED_LAST_MESSAGE_AT_UID = "94c4594f-4ad0-4e3b-8a0b-76402b437434";
|
|
1173
|
+
var GENERATED_RESPONSE_FIELD_SENDING_AT_UID = "2ae9634b-79bb-42d2-a949-8b0f1ac9c763";
|
|
1174
|
+
var GENERATED_RESPONSE_INDEX_TICKET_ID_UID = "a4534d26-8f43-4510-9c03-0b28c3d3f8e2";
|
|
1175
|
+
var GENERATED_RESPONSE_INDEX_OPEN_TICKET_KEY_UID = "3d430166-07a2-43c2-911b-89ec25d13f64";
|
|
1176
|
+
var GENERATED_RESPONSE_INDEX_STATUS_UID = "f5c4e5d4-0810-424d-8a14-617e9555a7f3";
|
|
1177
|
+
var GENERATED_RESPONSE_INDEX_TRIAGE_DECISION_ID_UID = "576b670e-7351-4867-bd5b-45df97bb26f0";
|
|
1178
|
+
var GENERATED_RESPONSE_INDEX_GENERATED_AT_UID = "4f4ffdb2-c690-407a-bb4f-f82240d6c49f";
|
|
1179
|
+
var GENERATED_RESPONSE_INDEX_EXPIRES_AT_UID = "311d793a-0c21-45d4-85fa-76d3e48a5cfa";
|
|
1180
|
+
var RESPONSE_COMPARISON_FIELD_GENERATED_TEXT_UID = "44ca17c2-6cf2-4008-81e3-d7d5ccf3ab4d";
|
|
1181
|
+
var RESPONSE_COMPARISON_FIELD_SENT_TEXT_UID = "a2877acd-1521-49b3-98a3-8a112e6f6adf";
|
|
1182
|
+
var RESPONSE_COMPARISON_FIELD_CAPTURED_AT_UID = "ab66db96-027e-4f10-8c05-19c9714fa668";
|
|
1183
|
+
var RESPONSE_COMPARISON_FIELD_TICKET_ID_UID = "befa0d7f-6c54-403e-bbfe-55dabe305ada";
|
|
1184
|
+
var RESPONSE_COMPARISON_FIELD_TICKET_URL_UID = "137d66e9-c0b2-40b8-809f-e384b06ded8c";
|
|
1185
|
+
var RESPONSE_COMPARISON_FIELD_AGENT_ID_UID = "9c968f5f-9f0e-439d-bef1-2189e95c16f6";
|
|
1186
|
+
var RESPONSE_COMPARISON_FIELD_LANGFUSE_TRACE_ID_UID = "2297cb14-6a69-457a-9f73-440b8c54c773";
|
|
1187
|
+
var RESPONSE_COMPARISON_FIELD_LANGFUSE_OBSERVATION_ID_UID = "96461793-0636-4d0d-997f-0bec2870237c";
|
|
1188
|
+
var RESPONSE_COMPARISON_FIELD_PROMPT_NAME_UID = "9142e145-2245-419f-bf46-224dcfe4d946";
|
|
1189
|
+
var RESPONSE_COMPARISON_FIELD_PROMPT_VERSION_UID = "6fb501a7-dbbc-41ff-b97f-8afdbdfab3a1";
|
|
1190
|
+
var RESPONSE_COMPARISON_FIELD_CONVERSATION_MESSAGES_UID = "90695301-55fc-4a85-b998-7433cd1e1c8c";
|
|
1191
|
+
var RESPONSE_COMPARISON_FIELD_DIFF_UID = "8333eade-5440-4e75-a2b3-d5d55a6af706";
|
|
1192
|
+
var RESPONSE_COMPARISON_INDEX_CAPTURED_AT_UID = "c5d87db7-7983-4fcc-bf6d-6e61d9ad5b9e";
|
|
1193
|
+
var RESPONSE_COMPARISON_INDEX_TICKET_ID_UID = "ccfbe23d-447d-4488-ae4d-3b9c63a917f7";
|
|
1194
|
+
var EVALUATION_FIELD_AGENT_ID_UID = "4bdde88b-1e83-4df3-986a-f141b4cf0ebe";
|
|
1195
|
+
var EVALUATION_FIELD_SATISFIED_UID = "9df4c966-954b-4ffa-941d-954102048607";
|
|
1196
|
+
var EVALUATION_FIELD_MESSAGES_UID = "85aaf232-11de-4916-959b-a4d4833a6d7b";
|
|
1197
|
+
var EVALUATION_FIELD_TICKET_URL_UID = "fcf28597-ecce-4f40-9564-0144fecb0273";
|
|
1198
|
+
var EVALUATION_FIELD_LANGFUSE_TRACE_ID_UID = "5138f710-5cb0-4fa1-ae83-111f640a1aa3";
|
|
1199
|
+
var EVALUATION_FIELD_LANGFUSE_OBSERVATION_ID_UID = "3d09921f-b1d9-4294-acca-8a60bd005750";
|
|
1200
|
+
var EVALUATION_FIELD_SUPPORT_USER_KEY_ID_UID = "fad254c1-a76e-49a3-ba47-befbbc3fb8d4";
|
|
1201
|
+
var DIFF_ANALYSIS_FIELD_AGENT_ID_UID = "7b7fa88e-f54d-493e-a37a-a33c8d67a35e";
|
|
1202
|
+
var DIFF_ANALYSIS_FIELD_PROMPT_NAME_UID = "dbcae45f-6b17-44ac-b1fa-cb5fd30bc9b0";
|
|
1203
|
+
var DIFF_ANALYSIS_FIELD_PROMPT_VERSION_UID = "e301e7cd-f0d7-42f0-b3d9-24a9865faafb";
|
|
1204
|
+
var DIFF_ANALYSIS_FIELD_POINTS_UID = "8ed96b8f-96bc-44d9-b8f8-1c980e2b4906";
|
|
1205
|
+
var DIFF_ANALYSIS_FIELD_UNIQUE_KEY_UID = "9f4c33b9-5639-491a-8a21-0bb27a9446cd";
|
|
1206
|
+
var DIFF_ANALYSIS_INDEX_UNIQUE_KEY_UID = "1e656a9d-57d1-4a66-b05b-d653aa066cd5";
|
|
1207
|
+
var PIPELINE_STATE_FIELD_SOURCE_VIEW_ID_UID = "01a122d4-7b03-48af-8f9c-64c2c1e6ec8e";
|
|
1208
|
+
var PIPELINE_STATE_FIELD_LAST_TRIAGE_AT_UID = "b4ca3c4c-1933-429e-a9d8-1d2842c0b142";
|
|
1209
|
+
var PIPELINE_STATE_FIELD_LAST_SWEEP_AT_UID = "6036fdbf-42c5-4aa2-a813-87ccd5d92ce2";
|
|
1210
|
+
var PIPELINE_STATE_FIELD_SINGLETON_KEY_UID = "f4d2c40b-c137-42a2-82c9-981f39cb8c70";
|
|
1211
|
+
var PIPELINE_STATE_INDEX_SINGLETON_KEY_UID = "a257c7db-b63b-4535-a0b1-a7d05f5561b6";
|
|
1212
|
+
var PROMPT_CACHE_FIELD_PROMPT_KEY_UID = "d5e65781-23c1-4a8d-87d1-992bbf0408fc";
|
|
1213
|
+
var PROMPT_CACHE_FIELD_CONTENT_UID = "4a2a55e2-468e-4a8d-9a96-eae6e3e629f0";
|
|
1214
|
+
var PROMPT_CACHE_FIELD_VERSION_UID = "87b77921-6261-4179-a9e6-823e8321ccfd";
|
|
1215
|
+
var PROMPT_CACHE_FIELD_LABEL_UID = "ce36ed5b-42e2-45bd-8915-3ef0317e6665";
|
|
1216
|
+
var PROMPT_CACHE_FIELD_CONFIG_UID = "306cdb0b-433b-44c8-8a5b-6b993d3f0da3";
|
|
1217
|
+
var PROMPT_CACHE_INDEX_PROMPT_KEY_UID = "df06ab57-bfc0-4155-a3d6-e22edab8a853";
|
|
1218
|
+
|
|
1219
|
+
// src/records/agent.ts
|
|
1220
|
+
var AGENT_STATUSES = ["default", "available", "archived"];
|
|
1221
|
+
var REASONING_EFFORT_OPTIONS = ["off", "low", "medium", "high"];
|
|
1222
|
+
var DEFAULT_LLM_PROVIDER = "openai";
|
|
1223
|
+
var agentRecord = {
|
|
1224
|
+
universalIdentifier: AGENT_OBJECT_UID,
|
|
1225
|
+
objectKey: "agent",
|
|
1226
|
+
labelSingular: "Agent",
|
|
1227
|
+
labelPlural: "Agents",
|
|
1228
|
+
description: "A drafting agent: model, prompt binding, and default-agent flag.",
|
|
1229
|
+
fields: [
|
|
1230
|
+
{
|
|
1231
|
+
universalIdentifier: AGENT_FIELD_NAME_UID,
|
|
1232
|
+
name: "name",
|
|
1233
|
+
type: FieldType.TEXT,
|
|
1234
|
+
label: "Name",
|
|
1235
|
+
isNullable: false
|
|
1236
|
+
},
|
|
1237
|
+
{
|
|
1238
|
+
universalIdentifier: AGENT_FIELD_PROVIDER_UID,
|
|
1239
|
+
name: "provider",
|
|
1240
|
+
type: FieldType.TEXT,
|
|
1241
|
+
label: "Provider",
|
|
1242
|
+
description: "Free text (spec \xA73.4) \u2014 a new provider must not need a kit release.",
|
|
1243
|
+
isNullable: false,
|
|
1244
|
+
defaultValue: DEFAULT_LLM_PROVIDER
|
|
1245
|
+
},
|
|
1246
|
+
{
|
|
1247
|
+
universalIdentifier: AGENT_FIELD_MODEL_ID_UID,
|
|
1248
|
+
name: "modelId",
|
|
1249
|
+
type: FieldType.TEXT,
|
|
1250
|
+
label: "Model id",
|
|
1251
|
+
isNullable: false
|
|
1252
|
+
},
|
|
1253
|
+
{
|
|
1254
|
+
universalIdentifier: AGENT_FIELD_STATUS_UID,
|
|
1255
|
+
name: "status",
|
|
1256
|
+
type: FieldType.SELECT,
|
|
1257
|
+
label: "Status",
|
|
1258
|
+
isNullable: false,
|
|
1259
|
+
options: [...AGENT_STATUSES],
|
|
1260
|
+
defaultValue: "available"
|
|
1261
|
+
},
|
|
1262
|
+
{
|
|
1263
|
+
universalIdentifier: AGENT_FIELD_DEFAULT_KEY_UID,
|
|
1264
|
+
name: "defaultKey",
|
|
1265
|
+
type: FieldType.TEXT,
|
|
1266
|
+
label: "Default key",
|
|
1267
|
+
description: "Equals 'default' when status='default', absent otherwise. Unique.",
|
|
1268
|
+
isNullable: true
|
|
1269
|
+
},
|
|
1270
|
+
{
|
|
1271
|
+
universalIdentifier: AGENT_FIELD_PROMPT_NAME_UID,
|
|
1272
|
+
name: "promptName",
|
|
1273
|
+
type: FieldType.TEXT,
|
|
1274
|
+
label: "Prompt name",
|
|
1275
|
+
description: "Free Langfuse prompt name (ETL keeps legacy agent/<old id> names).",
|
|
1276
|
+
isNullable: false
|
|
1277
|
+
},
|
|
1278
|
+
{
|
|
1279
|
+
universalIdentifier: AGENT_FIELD_PROMPT_LABEL_UID,
|
|
1280
|
+
name: "promptLabel",
|
|
1281
|
+
type: FieldType.TEXT,
|
|
1282
|
+
label: "Prompt label",
|
|
1283
|
+
isNullable: true
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
universalIdentifier: AGENT_FIELD_PROMPT_VERSION_UID,
|
|
1287
|
+
name: "promptVersion",
|
|
1288
|
+
type: FieldType.NUMBER,
|
|
1289
|
+
label: "Prompt version",
|
|
1290
|
+
description: 'Pinning; absent means "follow the label".',
|
|
1291
|
+
isNullable: true
|
|
1292
|
+
},
|
|
1293
|
+
{
|
|
1294
|
+
universalIdentifier: AGENT_FIELD_SYSTEM_PROMPT_SNAPSHOT_UID,
|
|
1295
|
+
name: "systemPromptSnapshot",
|
|
1296
|
+
type: FieldType.TEXT,
|
|
1297
|
+
label: "System prompt snapshot",
|
|
1298
|
+
description: "Level-3 fallback of the prompt ladder (\xA73.7).",
|
|
1299
|
+
isNullable: true
|
|
1300
|
+
},
|
|
1301
|
+
{
|
|
1302
|
+
universalIdentifier: AGENT_FIELD_REASONING_EFFORT_UID,
|
|
1303
|
+
name: "reasoningEffort",
|
|
1304
|
+
type: FieldType.SELECT,
|
|
1305
|
+
label: "Reasoning effort",
|
|
1306
|
+
isNullable: true,
|
|
1307
|
+
options: [...REASONING_EFFORT_OPTIONS]
|
|
1308
|
+
},
|
|
1309
|
+
{
|
|
1310
|
+
universalIdentifier: AGENT_FIELD_MAX_TOOL_CALLS_UID,
|
|
1311
|
+
name: "maxToolCalls",
|
|
1312
|
+
type: FieldType.NUMBER,
|
|
1313
|
+
label: "Max tool calls",
|
|
1314
|
+
isNullable: true
|
|
1315
|
+
}
|
|
1316
|
+
],
|
|
1317
|
+
indexes: [{ universalIdentifier: AGENT_INDEX_DEFAULT_KEY_UID, fields: ["defaultKey"], isUnique: true }]
|
|
1318
|
+
};
|
|
1319
|
+
|
|
1320
|
+
// src/settings/fields.ts
|
|
1321
|
+
var SUPPORT_KIT_SETTINGS_FIELDS = [
|
|
1322
|
+
// Source
|
|
1323
|
+
{
|
|
1324
|
+
key: "gorgiasConnectionId",
|
|
1325
|
+
type: "string",
|
|
1326
|
+
label: "Gorgias connection",
|
|
1327
|
+
default: ""
|
|
1328
|
+
},
|
|
1329
|
+
{
|
|
1330
|
+
key: "sourceViewId",
|
|
1331
|
+
type: "string",
|
|
1332
|
+
label: "Gorgias source view"
|
|
1333
|
+
// No default — see module doc.
|
|
1334
|
+
},
|
|
1335
|
+
{ key: "batchLimit", type: "number", label: "Batch limit", default: 30 },
|
|
1336
|
+
{ key: "triageEnabled", type: "boolean", label: "Triage enabled", default: false },
|
|
1337
|
+
{
|
|
1338
|
+
key: "triageIntervalMinutes",
|
|
1339
|
+
type: "number",
|
|
1340
|
+
label: "Triage interval (minutes)",
|
|
1341
|
+
default: 15
|
|
1342
|
+
},
|
|
1343
|
+
{ key: "dryRun", type: "boolean", label: "Dry run", default: false },
|
|
1344
|
+
// Nodes
|
|
1345
|
+
// `{triage, escalate, draft, evaluate, revise}`, `null` per key disabling
|
|
1346
|
+
// that graph step (§3.6). NO default, same reasoning as `sourceViewId`:
|
|
1347
|
+
// the only shape that could be defaulted here ("every step null") is a
|
|
1348
|
+
// pipeline that triages nothing, and it would install itself silently.
|
|
1349
|
+
// `validateSettings` refuses to run until `nodes.triage` is configured.
|
|
1350
|
+
{ key: "nodes", type: "json", label: "Graph node overrides" },
|
|
1351
|
+
// Audit tags
|
|
1352
|
+
{ key: "unknownTag", type: "string", label: "Unknown tag", default: "wai-tag/unknown" },
|
|
1353
|
+
{ key: "handledTag", type: "string", label: "Handled tag", default: "wai-tag/triaged" },
|
|
1354
|
+
{ key: "escalationTag", type: "string", label: "Escalation tag", default: "wai/human-required" },
|
|
1355
|
+
{ key: "needsHumanTag", type: "string", label: "Needs-human tag", default: "wai/needs-human" },
|
|
1356
|
+
{ key: "autoRepliedTag", type: "string", label: "Auto-replied tag", default: "wai/auto-replied" },
|
|
1357
|
+
{ key: "needsReviewTag", type: "string", label: "Needs-review tag", default: "wai/needs-review" },
|
|
1358
|
+
{ key: "followupTag", type: "string", label: "Followup tag", default: "wai/followup-required" },
|
|
1359
|
+
// Sending
|
|
1360
|
+
{ key: "autoSendEnabled", type: "boolean", label: "Auto-send enabled", default: false },
|
|
1361
|
+
{ key: "senderEmail", type: "string", label: "Sender email", default: "" },
|
|
1362
|
+
{
|
|
1363
|
+
key: "requireHighTriageConfidence",
|
|
1364
|
+
type: "boolean",
|
|
1365
|
+
label: "Require high triage confidence",
|
|
1366
|
+
default: false
|
|
1367
|
+
},
|
|
1368
|
+
{
|
|
1369
|
+
key: "whatsappMode",
|
|
1370
|
+
type: "select",
|
|
1371
|
+
label: "WhatsApp mode",
|
|
1372
|
+
options: [...WHATSAPP_MODES],
|
|
1373
|
+
default: DEFAULT_WHATSAPP_MODE
|
|
1374
|
+
},
|
|
1375
|
+
// 14_400 minutes = 10 days, the legacy `fast_response_ttl_minutes` default
|
|
1376
|
+
// (`backoffice/src/models/AppSettings.ts`) — copied deliberately, not
|
|
1377
|
+
// chosen here. A pre-generated draft is only worth anything while the
|
|
1378
|
+
// ticket is still open, and a support ticket routinely sits days before
|
|
1379
|
+
// an agent opens it: a shorter TTL expires drafts nobody ever got to see
|
|
1380
|
+
// and shows up only as a silently collapsing reuse rate (I1).
|
|
1381
|
+
{ key: "responseTtlMinutes", type: "number", label: "Response TTL (minutes)", default: 14400 },
|
|
1382
|
+
// Guardrails
|
|
1383
|
+
// The whole catalogue, not an empty list: guardrails are what hold a reply
|
|
1384
|
+
// back, so an install that enables none is an install that sends
|
|
1385
|
+
// everything. Derived from `AGENT_GUARDRAILS` so a new rule is active by
|
|
1386
|
+
// default rather than silently off (I7).
|
|
1387
|
+
{ key: "guardrailsActive", type: "json", label: "Active guardrails", default: [...AGENT_GUARDRAILS] },
|
|
1388
|
+
{ key: "blocklist", type: "json", label: "Blocklist", default: [] },
|
|
1389
|
+
{ key: "noreplySenders", type: "json", label: "No-reply senders", default: [] },
|
|
1390
|
+
// Channel prompts
|
|
1391
|
+
{
|
|
1392
|
+
key: "channelPromptEmail",
|
|
1393
|
+
type: "string",
|
|
1394
|
+
label: "Email style prompt",
|
|
1395
|
+
default: DEFAULT_CHANNEL_PROMPT_EMAIL
|
|
1396
|
+
},
|
|
1397
|
+
{
|
|
1398
|
+
key: "channelPromptWhatsapp",
|
|
1399
|
+
type: "string",
|
|
1400
|
+
label: "WhatsApp style prompt",
|
|
1401
|
+
default: DEFAULT_CHANNEL_PROMPT_WHATSAPP
|
|
1402
|
+
},
|
|
1403
|
+
// Misc
|
|
1404
|
+
{ key: "renameEnabled", type: "boolean", label: "Rename enabled", default: false },
|
|
1405
|
+
// §3.6 lists a single `renameTemplate`, but the legacy rename carries TWO
|
|
1406
|
+
// semantically different strings: `ticket_rename_from` is a needle matched
|
|
1407
|
+
// against the subject with `includes`, and `ticket_rename_to` is the
|
|
1408
|
+
// replacement. Encoding both in one field needs a separator nobody specified,
|
|
1409
|
+
// which can collide with real subject text. Split instead — a documented
|
|
1410
|
+
// one-field deviation from §3.6, recorded for the spec owner.
|
|
1411
|
+
{ key: "renameFrom", type: "string", label: "Rename \u2014 subject pattern to match", default: "" },
|
|
1412
|
+
{ key: "renameTo", type: "string", label: "Rename \u2014 replacement subject", default: "" },
|
|
1413
|
+
{ key: "statsTimezone", type: "string", label: "Stats timezone (IANA)", default: "Europe/Paris" }
|
|
1414
|
+
];
|
|
1415
|
+
|
|
1416
|
+
// src/settings/validate.ts
|
|
1417
|
+
function validateSettings(settings) {
|
|
1418
|
+
const issues = [];
|
|
1419
|
+
if (!isNonEmptyString(settings.sourceViewId)) {
|
|
1420
|
+
issues.push({
|
|
1421
|
+
key: "sourceViewId",
|
|
1422
|
+
message: "sourceViewId is required \u2014 pick the Gorgias view this app owns."
|
|
1423
|
+
});
|
|
1424
|
+
}
|
|
1425
|
+
if (!isConfiguredNode(settings.nodes)) {
|
|
1426
|
+
issues.push({
|
|
1427
|
+
key: "nodes",
|
|
1428
|
+
message: "nodes.triage must be configured \u2014 a null triage step would triage nothing."
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
const autoSendEnabled = settings.autoSendEnabled === true;
|
|
1432
|
+
const isWhatsappAutoReply = settings.whatsappMode === "auto_reply";
|
|
1433
|
+
if (autoSendEnabled && !isWhatsappAutoReply && !isNonEmptyString(settings.senderEmail)) {
|
|
1434
|
+
issues.push({
|
|
1435
|
+
key: "senderEmail",
|
|
1436
|
+
message: "senderEmail is required when autoSendEnabled is on, unless whatsappMode is 'auto_reply'."
|
|
1437
|
+
});
|
|
1438
|
+
}
|
|
1439
|
+
return issues;
|
|
1440
|
+
}
|
|
1441
|
+
function isNonEmptyString(value) {
|
|
1442
|
+
return typeof value === "string" && value.length > 0;
|
|
1443
|
+
}
|
|
1444
|
+
function isConfiguredNode(nodes) {
|
|
1445
|
+
if (typeof nodes !== "object" || nodes === null) return false;
|
|
1446
|
+
const triage2 = nodes.triage;
|
|
1447
|
+
return typeof triage2 === "object" && triage2 !== null;
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
// src/settings/to-profile.ts
|
|
1451
|
+
var DEFAULT_REASONING = "off";
|
|
1452
|
+
var DEFAULT_MAX_TOOL_CALLS = 5;
|
|
1453
|
+
var DEFAULT_MIN_CONFIDENCE = 0.8;
|
|
1454
|
+
var DEFAULT_ESCALATION_ENABLED = false;
|
|
1455
|
+
var JUDGEME_ESCALATE_ONLY = true;
|
|
1456
|
+
var TRIAGE_CONCURRENCY = 1;
|
|
1457
|
+
var FAST_RESPONSE_CONCURRENCY = 3;
|
|
1458
|
+
var FAST_RESPONSE_INTERVAL_SECONDS = 0;
|
|
1459
|
+
var FAST_RESPONSE_BATCH_LIMIT = 1;
|
|
1460
|
+
function settingsToProfile(settings, prompts) {
|
|
1461
|
+
const evaluate2 = toEvaluateNode(settings.nodes.evaluate);
|
|
1462
|
+
return {
|
|
1463
|
+
key: DEFAULT_PROFILE_KEY,
|
|
1464
|
+
// One app installs one kit, so its profile is that app's only tenant —
|
|
1465
|
+
// the multi-tenant `key` of the legacy is now the app boundary itself.
|
|
1466
|
+
isDefault: true,
|
|
1467
|
+
enabled: settings.triageEnabled,
|
|
1468
|
+
source: { channel: "gorgias", viewOrTag: settings.sourceViewId },
|
|
1469
|
+
schedule: {
|
|
1470
|
+
triageIntervalMinutes: settings.triageIntervalMinutes,
|
|
1471
|
+
triageBatchLimit: settings.batchLimit,
|
|
1472
|
+
triageConcurrency: TRIAGE_CONCURRENCY,
|
|
1473
|
+
fastResponseIntervalSeconds: FAST_RESPONSE_INTERVAL_SECONDS,
|
|
1474
|
+
fastResponseBatchLimit: FAST_RESPONSE_BATCH_LIMIT,
|
|
1475
|
+
fastResponseConcurrency: FAST_RESPONSE_CONCURRENCY,
|
|
1476
|
+
fastResponseTtlMinutes: settings.responseTtlMinutes
|
|
1477
|
+
},
|
|
1478
|
+
nodes: {
|
|
1479
|
+
triage: baseNode(settings.nodes.triage),
|
|
1480
|
+
escalate: settings.nodes.escalate ? baseNode(settings.nodes.escalate) : null,
|
|
1481
|
+
draft: settings.nodes.draft ? {
|
|
1482
|
+
...baseNode(settings.nodes.draft),
|
|
1483
|
+
maxToolCalls: settings.nodes.draft.maxToolCalls ?? DEFAULT_MAX_TOOL_CALLS
|
|
1484
|
+
} : null,
|
|
1485
|
+
evaluate: evaluate2,
|
|
1486
|
+
revise: settings.nodes.revise ? baseNode(settings.nodes.revise) : null
|
|
1487
|
+
},
|
|
1488
|
+
prompts,
|
|
1489
|
+
// No settings surface for the §6.2 tool allowlist yet (the registry
|
|
1490
|
+
// already refuses every write tool on its own). Default-deny until
|
|
1491
|
+
// T22 has a real list to pass; an empty list only costs the `draft`
|
|
1492
|
+
// node its optional lookups, it never opens anything.
|
|
1493
|
+
tools: [],
|
|
1494
|
+
guardrails: {
|
|
1495
|
+
active: [...settings.guardrailsActive],
|
|
1496
|
+
params: {
|
|
1497
|
+
noreplySenders: [...settings.noreplySenders],
|
|
1498
|
+
blocklist: [...settings.blocklist],
|
|
1499
|
+
whatsappMode: settings.whatsappMode,
|
|
1500
|
+
judgemeEscalateOnly: JUDGEME_ESCALATE_ONLY,
|
|
1501
|
+
channelPromptEmail: settings.channelPromptEmail,
|
|
1502
|
+
channelPromptWhatsapp: settings.channelPromptWhatsapp
|
|
1503
|
+
}
|
|
1504
|
+
},
|
|
1505
|
+
// `authorize` is DEFAULT DENY on an absent kind, so the one action kind
|
|
1506
|
+
// that exists must be stated: auto-send on ⇒ the graph may send, off ⇒
|
|
1507
|
+
// a human approves. Nothing here can reach 'forbidden' — that decision
|
|
1508
|
+
// belongs to P3's per-role policy, which needs a runtime context this
|
|
1509
|
+
// pure mapper does not have.
|
|
1510
|
+
authorization: { send_reply: settings.autoSendEnabled ? "auto" : "needs_approval" },
|
|
1511
|
+
audit: {
|
|
1512
|
+
unknownTag: settings.unknownTag,
|
|
1513
|
+
handledTag: settings.handledTag,
|
|
1514
|
+
escalationTag: settings.escalationTag,
|
|
1515
|
+
sentTag: settings.autoRepliedTag,
|
|
1516
|
+
needsHumanTag: settings.needsReviewTag,
|
|
1517
|
+
followupTag: settings.followupTag
|
|
1518
|
+
},
|
|
1519
|
+
autoSend: {
|
|
1520
|
+
enabled: settings.autoSendEnabled,
|
|
1521
|
+
senderEmail: settings.senderEmail === "" ? null : settings.senderEmail,
|
|
1522
|
+
// The auto-send floor is the evaluation floor: a second, independent
|
|
1523
|
+
// threshold would be a silent way to send below the one an operator set.
|
|
1524
|
+
minConfidence: evaluate2?.minConfidence ?? DEFAULT_MIN_CONFIDENCE,
|
|
1525
|
+
requireHighTriage: settings.requireHighTriageConfidence
|
|
1526
|
+
},
|
|
1527
|
+
rename: settings.renameEnabled ? { enabled: true, from: settings.renameFrom, to: settings.renameTo } : null,
|
|
1528
|
+
// Locks and run stamps are per-run state: they live in the
|
|
1529
|
+
// `pipeline-state` record (§3.4), never in settings.
|
|
1530
|
+
runtime: {
|
|
1531
|
+
triageLock: { acquiredAt: null, owner: null },
|
|
1532
|
+
fastResponseLock: { acquiredAt: null, owner: null },
|
|
1533
|
+
triageLastRun: { startedAt: null, completedAt: null, status: null },
|
|
1534
|
+
fastResponseLastRun: { startedAt: null, completedAt: null, status: null },
|
|
1535
|
+
lastAutoSendDecisionAt: null
|
|
1536
|
+
}
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
function baseNode(node) {
|
|
1540
|
+
return {
|
|
1541
|
+
model: node.model,
|
|
1542
|
+
provider: node.provider ?? DEFAULT_LLM_PROVIDER,
|
|
1543
|
+
reasoning: node.reasoning ?? DEFAULT_REASONING
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
function toEvaluateNode(node) {
|
|
1547
|
+
if (!node) return null;
|
|
1548
|
+
return {
|
|
1549
|
+
...baseNode(node),
|
|
1550
|
+
minConfidence: node.minConfidence ?? DEFAULT_MIN_CONFIDENCE,
|
|
1551
|
+
escalationEnabled: node.escalationEnabled ?? DEFAULT_ESCALATION_ENABLED
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
// src/functions/records.ts
|
|
1556
|
+
function toAgent(record) {
|
|
1557
|
+
const data = record.data;
|
|
1558
|
+
return {
|
|
1559
|
+
id: record.id,
|
|
1560
|
+
name: data.name ?? "",
|
|
1561
|
+
provider: data.provider ?? "openai",
|
|
1562
|
+
modelId: data.modelId ?? "",
|
|
1563
|
+
status: data.status ?? "available",
|
|
1564
|
+
promptName: data.promptName ?? "",
|
|
1565
|
+
promptLabel: data.promptLabel ?? null,
|
|
1566
|
+
promptVersion: data.promptVersion ?? null,
|
|
1567
|
+
systemPromptSnapshot: data.systemPromptSnapshot ?? null
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
function toCategory(record) {
|
|
1571
|
+
const data = record.data;
|
|
1572
|
+
return {
|
|
1573
|
+
id: record.id,
|
|
1574
|
+
name: data.name ?? "",
|
|
1575
|
+
tagName: data.tagName ?? "",
|
|
1576
|
+
agentId: data.agentId ?? null,
|
|
1577
|
+
groupId: data.groupId ?? null,
|
|
1578
|
+
order: data.order ?? 0,
|
|
1579
|
+
extraTags: data.extraTags ?? [],
|
|
1580
|
+
examples: data.examples ?? null,
|
|
1581
|
+
autoReplyEnabled: data.autoReplyEnabled ?? false,
|
|
1582
|
+
fastResponseEnabled: data.fastResponseEnabled ?? false
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
function toCategoryGroup(record) {
|
|
1586
|
+
const data = record.data;
|
|
1587
|
+
return {
|
|
1588
|
+
id: record.id,
|
|
1589
|
+
name: data.name ?? "",
|
|
1590
|
+
order: data.order ?? 0
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
function toTriageDecision(record) {
|
|
1594
|
+
const data = record.data;
|
|
1595
|
+
return {
|
|
1596
|
+
id: record.id,
|
|
1597
|
+
ticketId: data.ticketId ?? "",
|
|
1598
|
+
decidedAt: data.decidedAt ?? null,
|
|
1599
|
+
categoryId: data.categoryId ?? null,
|
|
1600
|
+
tag: data.tag ?? null,
|
|
1601
|
+
confidence: data.confidence ?? null,
|
|
1602
|
+
reasoning: data.reasoning ?? null,
|
|
1603
|
+
conversationOver: data.conversationOver ?? false,
|
|
1604
|
+
escalated: data.escalated ?? false,
|
|
1605
|
+
escalationConfidence: data.escalationConfidence ?? null,
|
|
1606
|
+
escalationReasoning: data.escalationReasoning ?? null,
|
|
1607
|
+
status: data.status ?? null,
|
|
1608
|
+
error: data.error ?? null,
|
|
1609
|
+
runId: data.runId ?? null,
|
|
1610
|
+
subjectRenamed: data.subjectRenamed ?? false
|
|
1611
|
+
};
|
|
1612
|
+
}
|
|
1613
|
+
function toVerdict(raw) {
|
|
1614
|
+
if (raw === null || typeof raw !== "object") return null;
|
|
1615
|
+
const data = raw;
|
|
1616
|
+
const verdict = isEvaluationVerdict(data.verdict) ? data.verdict : null;
|
|
1617
|
+
const confidence = typeof data.confidence === "number" ? data.confidence : null;
|
|
1618
|
+
const reason = typeof data.reason === "string" ? data.reason : "";
|
|
1619
|
+
const status = data.status === "success" || data.status === "error" ? data.status : "error";
|
|
1620
|
+
return { verdict, confidence, reason, status };
|
|
1621
|
+
}
|
|
1622
|
+
function toGeneratedResponse(record) {
|
|
1623
|
+
const data = record.data;
|
|
1624
|
+
return {
|
|
1625
|
+
id: record.id,
|
|
1626
|
+
ticketId: data.ticketId ?? "",
|
|
1627
|
+
status: data.status ?? "",
|
|
1628
|
+
expiresAt: data.expiresAt ?? null,
|
|
1629
|
+
generatedMessageCount: data.generatedMessageCount ?? 0,
|
|
1630
|
+
generatedLastMessageAt: data.generatedLastMessageAt ?? null,
|
|
1631
|
+
generatedAt: data.generatedAt ?? null,
|
|
1632
|
+
responseText: data.responseText ?? null,
|
|
1633
|
+
categoryId: data.categoryId ?? null,
|
|
1634
|
+
agentId: data.agentId ?? null,
|
|
1635
|
+
langfuseTraceId: data.langfuseTraceId ?? null,
|
|
1636
|
+
langfuseObservationId: data.langfuseObservationId ?? null,
|
|
1637
|
+
promptName: data.promptName ?? null,
|
|
1638
|
+
promptVersion: data.promptVersion ?? null,
|
|
1639
|
+
servedCount: data.servedCount ?? 0,
|
|
1640
|
+
servedTo: data.servedTo ?? [],
|
|
1641
|
+
verdict: toVerdict(data.verdict),
|
|
1642
|
+
guardrailHits: data.guardrailHits ?? [],
|
|
1643
|
+
triageDecisionId: data.triageDecisionId ?? null,
|
|
1644
|
+
channel: data.channel ?? null,
|
|
1645
|
+
autoSendDecision: data.autoSendDecision ?? null,
|
|
1646
|
+
sentAt: data.sentAt ?? null,
|
|
1647
|
+
sentMessageId: data.sentMessageId ?? null,
|
|
1648
|
+
error: data.error ?? null
|
|
1649
|
+
};
|
|
1650
|
+
}
|
|
1651
|
+
function toResponseComparison(record) {
|
|
1652
|
+
const data = record.data;
|
|
1653
|
+
return {
|
|
1654
|
+
id: record.id,
|
|
1655
|
+
generatedText: data.generatedText ?? null,
|
|
1656
|
+
sentText: data.sentText ?? "",
|
|
1657
|
+
capturedAt: data.capturedAt ?? "",
|
|
1658
|
+
ticketId: data.ticketId ?? null,
|
|
1659
|
+
ticketUrl: data.ticketUrl ?? "",
|
|
1660
|
+
agentId: data.agentId ?? null,
|
|
1661
|
+
langfuseTraceId: data.langfuseTraceId ?? null,
|
|
1662
|
+
langfuseObservationId: data.langfuseObservationId ?? null,
|
|
1663
|
+
promptName: data.promptName ?? null,
|
|
1664
|
+
promptVersion: data.promptVersion ?? null,
|
|
1665
|
+
conversationMessages: data.conversationMessages ?? [],
|
|
1666
|
+
diff: data.diff ?? null
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
function toDiffAnalysis(record) {
|
|
1670
|
+
const data = record.data;
|
|
1671
|
+
return {
|
|
1672
|
+
id: record.id,
|
|
1673
|
+
agentId: data.agentId ?? "",
|
|
1674
|
+
promptName: data.promptName ?? "",
|
|
1675
|
+
promptVersion: data.promptVersion ?? 0,
|
|
1676
|
+
points: data.points ?? [],
|
|
1677
|
+
uniqueKey: data.uniqueKey ?? ""
|
|
1678
|
+
};
|
|
1679
|
+
}
|
|
1680
|
+
async function listCategories(api) {
|
|
1681
|
+
const page = await api.list("category", { limit: 500 });
|
|
1682
|
+
return page.items.map(toCategory);
|
|
1683
|
+
}
|
|
1684
|
+
function findCategoryByTag(categories, tag) {
|
|
1685
|
+
return categories.find((c) => c.tagName === tag) ?? null;
|
|
1686
|
+
}
|
|
1687
|
+
function toCategoryReferential(categories) {
|
|
1688
|
+
return categories.map((c) => ({
|
|
1689
|
+
name: c.name,
|
|
1690
|
+
tag: c.tagName,
|
|
1691
|
+
desc: c.examples ?? c.name,
|
|
1692
|
+
...c.examples ? { examples: c.examples } : {}
|
|
1693
|
+
}));
|
|
1694
|
+
}
|
|
1695
|
+
async function resolveDraftAgent(api, categoryAgentId) {
|
|
1696
|
+
if (categoryAgentId) {
|
|
1697
|
+
try {
|
|
1698
|
+
return toAgent(await api.get("agent", categoryAgentId));
|
|
1699
|
+
} catch {
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
const page = await api.list("agent", { filter: { status: "default" }, limit: 1 });
|
|
1703
|
+
const record = page.items[0];
|
|
1704
|
+
return record ? toAgent(record) : null;
|
|
1705
|
+
}
|
|
1706
|
+
function draftPromptRefFor(agent, config) {
|
|
1707
|
+
if (!agent) return { name: `${config.promptPrefix}no-agent-configured`, label: "production" };
|
|
1708
|
+
return {
|
|
1709
|
+
name: agent.promptName,
|
|
1710
|
+
label: agent.promptLabel ?? "production",
|
|
1711
|
+
...agent.systemPromptSnapshot ? { fallback: agent.systemPromptSnapshot } : {}
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
function buildPromptsTable(config, draft2) {
|
|
1715
|
+
const label = "production";
|
|
1716
|
+
const withFallback = (name, fallback2) => ({
|
|
1717
|
+
name,
|
|
1718
|
+
label,
|
|
1719
|
+
...fallback2 ? { fallback: fallback2 } : {}
|
|
1720
|
+
});
|
|
1721
|
+
return {
|
|
1722
|
+
triage: withFallback(resolvePromptName("triage", config), config.defaults?.prompts?.triage),
|
|
1723
|
+
escalate: withFallback(resolvePromptName("escalation", config), config.defaults?.prompts?.escalation),
|
|
1724
|
+
evaluate: withFallback(resolvePromptName("evaluation", config), config.defaults?.prompts?.evaluation),
|
|
1725
|
+
revise: withFallback(resolveReviseName(config), config.defaults?.prompts?.revise),
|
|
1726
|
+
draft: draft2
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
// src/functions/response-comparison-diff.ts
|
|
1731
|
+
function tokenize(text) {
|
|
1732
|
+
return (text ?? "").split(/(\s+)/).filter((token) => token.length > 0);
|
|
1733
|
+
}
|
|
1734
|
+
function computeWordDiff(generatedText, sentText) {
|
|
1735
|
+
const a = tokenize(generatedText);
|
|
1736
|
+
const b = tokenize(sentText);
|
|
1737
|
+
const m = a.length;
|
|
1738
|
+
const n = b.length;
|
|
1739
|
+
const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
1740
|
+
for (let i2 = 1; i2 <= m; i2++) {
|
|
1741
|
+
for (let j2 = 1; j2 <= n; j2++) {
|
|
1742
|
+
dp[i2][j2] = a[i2 - 1] === b[j2 - 1] ? dp[i2 - 1][j2 - 1] + 1 : Math.max(dp[i2 - 1][j2], dp[i2][j2 - 1]);
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
const ops = [];
|
|
1746
|
+
let i = m;
|
|
1747
|
+
let j = n;
|
|
1748
|
+
while (i > 0 || j > 0) {
|
|
1749
|
+
if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
|
|
1750
|
+
ops.push({ op: "equal", text: a[i - 1] });
|
|
1751
|
+
i--;
|
|
1752
|
+
j--;
|
|
1753
|
+
} else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
|
|
1754
|
+
ops.push({ op: "insert", text: b[j - 1] });
|
|
1755
|
+
j--;
|
|
1756
|
+
} else {
|
|
1757
|
+
ops.push({ op: "delete", text: a[i - 1] });
|
|
1758
|
+
i--;
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
return ops.reverse();
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
export { AGENT_GUARDRAILS, AGENT_STATUSES, AGENT_TOOLS, CANDIDATE_MIN_LENGTH, CATEGORY_FIELD_AGENT_ID_UID, CATEGORY_FIELD_AUTO_REPLY_ENABLED_UID, CATEGORY_FIELD_EXAMPLES_UID, CATEGORY_FIELD_EXTRA_TAGS_UID, CATEGORY_FIELD_FAST_RESPONSE_ENABLED_UID, CATEGORY_FIELD_GROUP_ID_UID, CATEGORY_FIELD_NAME_UID, CATEGORY_FIELD_ORDER_UID, CATEGORY_FIELD_TAG_NAME_UID, CATEGORY_GROUP_FIELD_NAME_UID, CATEGORY_GROUP_FIELD_ORDER_UID, CATEGORY_GROUP_INDEX_NAME_UID, CATEGORY_GROUP_OBJECT_UID, CATEGORY_INDEX_NAME_UID, CATEGORY_INDEX_ORDER_UID, CATEGORY_INDEX_TAG_NAME_UID, CATEGORY_OBJECT_UID, DEFAULT_CHANNEL_PROMPT_EMAIL, DEFAULT_CHANNEL_PROMPT_WHATSAPP, DEFAULT_LLM_PROVIDER, DEFAULT_PROFILE_KEY, DEFAULT_WHATSAPP_MODE, DIFF_ANALYSIS_FIELD_AGENT_ID_UID, DIFF_ANALYSIS_FIELD_POINTS_UID, DIFF_ANALYSIS_FIELD_PROMPT_NAME_UID, DIFF_ANALYSIS_FIELD_PROMPT_VERSION_UID, DIFF_ANALYSIS_FIELD_UNIQUE_KEY_UID, DIFF_ANALYSIS_INDEX_UNIQUE_KEY_UID, DIFF_ANALYSIS_OBJECT_UID, EVALUATION_FIELD_AGENT_ID_UID, EVALUATION_FIELD_LANGFUSE_OBSERVATION_ID_UID, EVALUATION_FIELD_LANGFUSE_TRACE_ID_UID, EVALUATION_FIELD_MESSAGES_UID, EVALUATION_FIELD_SATISFIED_UID, EVALUATION_FIELD_SUPPORT_USER_KEY_ID_UID, EVALUATION_FIELD_TICKET_URL_UID, EVALUATION_OBJECT_UID, EVALUATION_VERDICTS, GENERATED_RESPONSE_FIELD_AGENT_ID_UID, GENERATED_RESPONSE_FIELD_AUTO_SEND_DECISION_UID, GENERATED_RESPONSE_FIELD_CATEGORY_ID_UID, GENERATED_RESPONSE_FIELD_CHANNEL_UID, GENERATED_RESPONSE_FIELD_ERROR_UID, GENERATED_RESPONSE_FIELD_EXPIRES_AT_UID, GENERATED_RESPONSE_FIELD_FOLLOWUP_REQUIRED_UID, GENERATED_RESPONSE_FIELD_GENERATED_AT_UID, GENERATED_RESPONSE_FIELD_GENERATED_LAST_MESSAGE_AT_UID, GENERATED_RESPONSE_FIELD_GENERATED_MESSAGE_COUNT_UID, GENERATED_RESPONSE_FIELD_GUARDRAIL_HITS_UID, GENERATED_RESPONSE_FIELD_LANGFUSE_OBSERVATION_ID_UID, GENERATED_RESPONSE_FIELD_LANGFUSE_TRACE_ID_UID, GENERATED_RESPONSE_FIELD_OPEN_TICKET_KEY_UID, GENERATED_RESPONSE_FIELD_PROMPT_NAME_UID, GENERATED_RESPONSE_FIELD_PROMPT_VERSION_UID, GENERATED_RESPONSE_FIELD_RESPONSE_TEXT_UID, GENERATED_RESPONSE_FIELD_SENDING_AT_UID, GENERATED_RESPONSE_FIELD_SENT_AT_UID, GENERATED_RESPONSE_FIELD_SENT_MESSAGE_ID_UID, GENERATED_RESPONSE_FIELD_SERVED_COUNT_UID, GENERATED_RESPONSE_FIELD_SERVED_TO_UID, GENERATED_RESPONSE_FIELD_SOURCES_UID, GENERATED_RESPONSE_FIELD_STATUS_UID, GENERATED_RESPONSE_FIELD_TICKET_ID_UID, GENERATED_RESPONSE_FIELD_TRACED_INPUT_UID, GENERATED_RESPONSE_FIELD_TRIAGE_DECISION_ID_UID, GENERATED_RESPONSE_FIELD_VERDICT_UID, GENERATED_RESPONSE_INDEX_EXPIRES_AT_UID, GENERATED_RESPONSE_INDEX_GENERATED_AT_UID, GENERATED_RESPONSE_INDEX_OPEN_TICKET_KEY_UID, GENERATED_RESPONSE_INDEX_STATUS_UID, GENERATED_RESPONSE_INDEX_TICKET_ID_UID, GENERATED_RESPONSE_INDEX_TRIAGE_DECISION_ID_UID, GENERATED_RESPONSE_OBJECT_UID, GENERATED_RESPONSE_STATUSES, InvalidStatusTransitionError, NODE_NAMES, PIPELINE_STATE_FIELD_LAST_SWEEP_AT_UID, PIPELINE_STATE_FIELD_LAST_TRIAGE_AT_UID, PIPELINE_STATE_FIELD_SINGLETON_KEY_UID, PIPELINE_STATE_FIELD_SOURCE_VIEW_ID_UID, PIPELINE_STATE_INDEX_SINGLETON_KEY_UID, PIPELINE_STATE_OBJECT_UID, PROMPT_CACHE_FIELD_CONFIG_UID, PROMPT_CACHE_FIELD_CONTENT_UID, PROMPT_CACHE_FIELD_LABEL_UID, PROMPT_CACHE_FIELD_PROMPT_KEY_UID, PROMPT_CACHE_FIELD_VERSION_UID, PROMPT_CACHE_INDEX_PROMPT_KEY_UID, PROMPT_CACHE_OBJECT_UID, PROMPT_SLOTS, REASONING_MAX_LEN, RESPONSE_COMPARISON_FIELD_AGENT_ID_UID, RESPONSE_COMPARISON_FIELD_CAPTURED_AT_UID, RESPONSE_COMPARISON_FIELD_CONVERSATION_MESSAGES_UID, RESPONSE_COMPARISON_FIELD_DIFF_UID, RESPONSE_COMPARISON_FIELD_GENERATED_TEXT_UID, RESPONSE_COMPARISON_FIELD_LANGFUSE_OBSERVATION_ID_UID, RESPONSE_COMPARISON_FIELD_LANGFUSE_TRACE_ID_UID, RESPONSE_COMPARISON_FIELD_PROMPT_NAME_UID, RESPONSE_COMPARISON_FIELD_PROMPT_VERSION_UID, RESPONSE_COMPARISON_FIELD_SENT_TEXT_UID, RESPONSE_COMPARISON_FIELD_TICKET_ID_UID, RESPONSE_COMPARISON_FIELD_TICKET_URL_UID, RESPONSE_COMPARISON_INDEX_CAPTURED_AT_UID, RESPONSE_COMPARISON_INDEX_TICKET_ID_UID, RESPONSE_COMPARISON_OBJECT_UID, STOP_PHRASES, SUPPORT_KIT_SETTINGS_FIELDS, TRIAGE_DECISION_FIELD_CATEGORY_ID_UID, TRIAGE_DECISION_FIELD_CONFIDENCE_UID, TRIAGE_DECISION_FIELD_CONVERSATION_OVER_UID, TRIAGE_DECISION_FIELD_DECIDED_AT_UID, TRIAGE_DECISION_FIELD_ERROR_UID, TRIAGE_DECISION_FIELD_ESCALATED_UID, TRIAGE_DECISION_FIELD_ESCALATION_CONFIDENCE_UID, TRIAGE_DECISION_FIELD_ESCALATION_REASONING_UID, TRIAGE_DECISION_FIELD_REASONING_UID, TRIAGE_DECISION_FIELD_RUN_ID_UID, TRIAGE_DECISION_FIELD_STATUS_UID, TRIAGE_DECISION_FIELD_SUBJECT_RENAMED_UID, TRIAGE_DECISION_FIELD_TAG_UID, TRIAGE_DECISION_FIELD_TICKET_ID_UID, TRIAGE_DECISION_INDEX_DECIDED_AT_UID, TRIAGE_DECISION_INDEX_ESCALATED_UID, TRIAGE_DECISION_INDEX_TICKET_ID_UID, TRIAGE_DECISION_OBJECT_UID, UNCERTAINTY_MARKERS, WHATSAPP_MODES, WHATSAPP_NOTE_CHEVRON, act, agentRecord, applyOutcomeTags, applySignature, assertTransition, buildPromptsTable, canTransition, channelPreGates, computeWordDiff, draftPromptRefFor, findCategoryByTag, firstCustomerMessage, guardrailBucket, hasCustomerAttachment, hasNoDraftNode, initialState, isAutoSendEligible, isAutomatedSenderEmail, isAutomatedSenderTicket, isConversationOver, isEvaluationVerdict, isFallbackClassification, isGeneratedResponseStatus, isJudgemeConversation, isJudgemeTicket, isSendable, isSendableVerdict, isTerminalStatus, isTicketClosed, isWhatsappChevronNote, isWhatsappTicket, lastCustomerMessage, listCategories, needsRevision, openTicketKeyFor, reclaimStalledSend, requiresFollowup, resolveDraftAgent, resolvePromptName, resolveReviseName, runGuardrails, runTicket, settingsToProfile, stopOptOut, toAgent, toCategory, toCategoryGroup, toCategoryReferential, toDiffAnalysis, toGeneratedResponse, toResponseComparison, toTriageDecision, validateSettings, verifyReply, whatsappModeFromLegacyBoolean };
|
|
1765
|
+
//# sourceMappingURL=chunk-KDOL3MLH.js.map
|
|
1766
|
+
//# sourceMappingURL=chunk-KDOL3MLH.js.map
|