@xapp/stentor-service-generative-ai 2.0.1 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -247,6 +247,11 @@ export interface LeadAnalysis {
|
|
|
247
247
|
* A 2 - 3 word concise summary of the lead, main use for this is in a word cloud and on the lead list item dashboard.
|
|
248
248
|
*/
|
|
249
249
|
conciseSummary?: string;
|
|
250
|
+
/**
|
|
251
|
+
* The request in one plain phrase of at most 20 words, written to be read aloud on a phone call.
|
|
252
|
+
* It completes "<name> needs help with: …", so it has no trailing period.
|
|
253
|
+
*/
|
|
254
|
+
spokenSummary?: string;
|
|
250
255
|
/**
|
|
251
256
|
* An analysis of how the LLM came to its conclusion.
|
|
252
257
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LeadAnalysis.js","sourceRoot":"","sources":["../../src/models/LeadAnalysis.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;
|
|
1
|
+
{"version":3,"file":"LeadAnalysis.js","sourceRoot":"","sources":["../../src/models/LeadAnalysis.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAwSlC,kDA0BC;AAhUD;;;;;;;;;;;;;;;;;;;;GAoBG;AACU,QAAA,aAAa,GAAG;IACzB,eAAe;IACf,cAAc;IACd,WAAW;IACX,YAAY;IACZ,iBAAiB;IACjB,oBAAoB;IACpB,oBAAoB;IACpB,UAAU;IACV,eAAe;IACf,oBAAoB;IACpB,iBAAiB;IACjB,MAAM;IACN,MAAM;IACN,OAAO;CACD,CAAC;AAIX;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,aAAa,GAAG;IACzB,UAAU;IACV,cAAc;IACd,YAAY;IACZ,cAAc;IACd,aAAa;IACb,UAAU;IACV,SAAS;IACT,QAAQ;IACR,SAAS;IACT,WAAW;IACX,WAAW;IACX,OAAO;CACD,CAAC;AAIX;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACU,QAAA,oBAAo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WAAW,EAAE,CAAC;IACzD,IAAI,WAAW,EAAE,CAAC;QACd,GAAG,CAAC,WAAW,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAgB,CAAC;IACjG,CAAC;IAED,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,0CAAE,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACzE,IAAI,OAAO,EAAE,CAAC;QACV,kFAAkF;QAClF,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1H,GAAG,CAAC,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAE,OAAmB,CAAC,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC;IACxF,CAAC;IAED,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,0CAAE,WAAW,EAAE,CAAC;IACjD,IAAI,OAAO,EAAE,CAAC;QACV,GAAG,CAAC,OAAO,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAgB,CAAC;IAC7F,CAAC;IAED,OAAO,GAAG,CAAC;AACf,CAAC"}
|
|
@@ -13,10 +13,13 @@ import type { CompletionPrompt, LeadAnalysis, PromptGenerator, ResponseParser }
|
|
|
13
13
|
* of the leads arriving with no message at all, CONTACT_REQUEST fell from 42% on 1.2.0 to 3% on
|
|
14
14
|
* 1.3.1 while SERVICE_REQUEST rose to 77%, against an unchanged CONTACT_REQUEST definition.
|
|
15
15
|
* 1.4.1 (2026-10-01): highValueLead asked for. It was absent from the returned-properties list, so
|
|
16
|
-
* the model was given a definition and no instruction to emit anything -
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* the model was given a definition and no instruction to emit anything - the field lived only in
|
|
17
|
+
* the json_schema. OpenAI enforces response_format, so gpt-4o-mini always returned it; Bedrock
|
|
18
|
+
* ignores it (AWSBedrockService), so when lead analysis migrated to Bedrock on 2026-07-29 the
|
|
19
|
+
* field simply stopped being emitted and the parser defaulted it to false. Measured on the same
|
|
20
|
+
* prompt version either side of that migration: 1.2.0 before, 6.1% true of 9,497; 1.2.0 after,
|
|
21
|
+
* 0.4% of 2,174. 1.3.0's temperature 0 only removed the residue. Also asked for on AnalyzeEmail,
|
|
22
|
+
* which had the same gap.
|
|
20
23
|
* 1.4.0 (2026-09-25): one name per trade — the eight alias pairs retired, the old names kept in
|
|
21
24
|
* JOB_TYPE_VARIANTS so anything that already wrote them still resolves. "other" split: not_stated
|
|
22
25
|
* for a request that names no work, other for work in no listed trade. A price request on planned
|
|
@@ -30,6 +33,10 @@ export interface TranscriptMessage {
|
|
|
30
33
|
export interface AnalyzeLeadProps {
|
|
31
34
|
businessDescription?: string;
|
|
32
35
|
highValueLeadDescription?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Kept for callers that already pass it; the prompt no longer reads it. What shape the prompt
|
|
38
|
+
* takes follows from whether a transcript exists, not from where the lead came in.
|
|
39
|
+
*/
|
|
33
40
|
channel?: ExternalLead["source"];
|
|
34
41
|
fields?: ExternalLead["fields"];
|
|
35
42
|
transcript?: ExternalLead["transcript"];
|
|
@@ -64,7 +71,18 @@ export declare function translateTranscript(transcript: ExternalLead["transcript
|
|
|
64
71
|
* @param transcript
|
|
65
72
|
* @returns
|
|
66
73
|
*/
|
|
67
|
-
export declare function transcriptToMessages(system: string, transcript: Message[]
|
|
74
|
+
export declare function transcriptToMessages(system: string, transcript: Message[],
|
|
75
|
+
/**
|
|
76
|
+
* The rendered form fields, for a lead that has no transcript.
|
|
77
|
+
*
|
|
78
|
+
* They used to be appended to `system` and nothing else, which left the message list holding
|
|
79
|
+
* a single system turn. AWSBedrockService lifts every system turn out into Bedrock's own
|
|
80
|
+
* `system` parameter, so the request arrived with `messages: []` and Bedrock rejected it:
|
|
81
|
+
* "'messages' must not be empty". analyzeLeadSafely swallows that, so the lead was delivered
|
|
82
|
+
* carrying "An analysis could not be generated." and nothing looked wrong. The form-submission
|
|
83
|
+
* twin of the transcript bug in XappMedia/stentor-api#5622.
|
|
84
|
+
*/
|
|
85
|
+
formSubmission?: string): {
|
|
68
86
|
role: "system" | "user" | "assistant";
|
|
69
87
|
content: string;
|
|
70
88
|
}[];
|
|
@@ -23,10 +23,13 @@ const leadTaxonomyPrompt_1 = require("./leadTaxonomyPrompt");
|
|
|
23
23
|
* of the leads arriving with no message at all, CONTACT_REQUEST fell from 42% on 1.2.0 to 3% on
|
|
24
24
|
* 1.3.1 while SERVICE_REQUEST rose to 77%, against an unchanged CONTACT_REQUEST definition.
|
|
25
25
|
* 1.4.1 (2026-10-01): highValueLead asked for. It was absent from the returned-properties list, so
|
|
26
|
-
* the model was given a definition and no instruction to emit anything -
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* the model was given a definition and no instruction to emit anything - the field lived only in
|
|
27
|
+
* the json_schema. OpenAI enforces response_format, so gpt-4o-mini always returned it; Bedrock
|
|
28
|
+
* ignores it (AWSBedrockService), so when lead analysis migrated to Bedrock on 2026-07-29 the
|
|
29
|
+
* field simply stopped being emitted and the parser defaulted it to false. Measured on the same
|
|
30
|
+
* prompt version either side of that migration: 1.2.0 before, 6.1% true of 9,497; 1.2.0 after,
|
|
31
|
+
* 0.4% of 2,174. 1.3.0's temperature 0 only removed the residue. Also asked for on AnalyzeEmail,
|
|
32
|
+
* which had the same gap.
|
|
30
33
|
* 1.4.0 (2026-09-25): one name per trade — the eight alias pairs retired, the old names kept in
|
|
31
34
|
* JOB_TYPE_VARIANTS so anything that already wrote them still resolves. "other" split: not_stated
|
|
32
35
|
* for a request that names no work, other for work in no listed trade. A price request on planned
|
|
@@ -72,7 +75,18 @@ function translateTranscript(transcript) {
|
|
|
72
75
|
* @param transcript
|
|
73
76
|
* @returns
|
|
74
77
|
*/
|
|
75
|
-
function transcriptToMessages(system, transcript
|
|
78
|
+
function transcriptToMessages(system, transcript,
|
|
79
|
+
/**
|
|
80
|
+
* The rendered form fields, for a lead that has no transcript.
|
|
81
|
+
*
|
|
82
|
+
* They used to be appended to `system` and nothing else, which left the message list holding
|
|
83
|
+
* a single system turn. AWSBedrockService lifts every system turn out into Bedrock's own
|
|
84
|
+
* `system` parameter, so the request arrived with `messages: []` and Bedrock rejected it:
|
|
85
|
+
* "'messages' must not be empty". analyzeLeadSafely swallows that, so the lead was delivered
|
|
86
|
+
* carrying "An analysis could not be generated." and nothing looked wrong. The form-submission
|
|
87
|
+
* twin of the transcript bug in XappMedia/stentor-api#5622.
|
|
88
|
+
*/
|
|
89
|
+
formSubmission) {
|
|
76
90
|
const messages = [
|
|
77
91
|
{
|
|
78
92
|
role: "system",
|
|
@@ -96,6 +110,28 @@ function transcriptToMessages(system, transcript) {
|
|
|
96
110
|
`Respond with ONLY the JSON object described above. No prose, no preamble.`
|
|
97
111
|
});
|
|
98
112
|
}
|
|
113
|
+
else if (formSubmission) {
|
|
114
|
+
messages.push({
|
|
115
|
+
role: "user",
|
|
116
|
+
content: `Analyze the following form submission.\n\n` +
|
|
117
|
+
`=== FORM SUBMISSION START ===\n${formSubmission}\n=== FORM SUBMISSION END ===\n\n` +
|
|
118
|
+
`Respond with ONLY the JSON object described above. No prose, no preamble.`
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
// A lead with neither is rare but it still has to produce a well formed request, and the
|
|
123
|
+
// wording stays source-neutral because AnalyzeTranscript shares this helper. Returning
|
|
124
|
+
// just the system turn is the empty-`messages` bug over again, and a rejected call is
|
|
125
|
+
// indistinguishable downstream from the model having nothing to say -- analyzeLeadSafely
|
|
126
|
+
// swallows both into "An analysis could not be generated.". Say so explicitly instead, so
|
|
127
|
+
// the model answers with the schema and the emptiness is a judgement rather than a failure.
|
|
128
|
+
messages.push({
|
|
129
|
+
role: "user",
|
|
130
|
+
content: `No chat transcript or form submission was captured, so there is no customer ` +
|
|
131
|
+
`content to analyze.\n\n` +
|
|
132
|
+
`Respond with ONLY the JSON object described above. No prose, no preamble.`
|
|
133
|
+
});
|
|
134
|
+
}
|
|
99
135
|
return messages;
|
|
100
136
|
}
|
|
101
137
|
/**
|
|
@@ -135,12 +171,17 @@ function getHighValueLeadDescription(highValueLeadDescription) {
|
|
|
135
171
|
* @param lead - The lead to analyze with the business description and other options to customize the prompt.
|
|
136
172
|
* @returns
|
|
137
173
|
*/
|
|
138
|
-
const generateAnalyzeLead = ({
|
|
174
|
+
const generateAnalyzeLead = ({ businessDescription, highValueLeadDescription, transcript, fields }, overrides) => {
|
|
139
175
|
// determine max_tokens
|
|
140
176
|
// depending on if the lead is from chat or form, we provide different content.
|
|
141
177
|
// if form, we just put the gathered fields in the system message
|
|
142
178
|
// if chat, we add the chat transcript to the messages, bot is the system message and user is the chat transcript.
|
|
143
|
-
|
|
179
|
+
// The transcript decides the shape, not the channel. A widget lead whose chat produced no
|
|
180
|
+
// transcript has nothing chat-shaped to analyze: asking for a transcript analysis left its
|
|
181
|
+
// fields out of the messages entirely and the request reached Bedrock empty. Every lead that
|
|
182
|
+
// analyzes correctly today is unaffected -- a transcript makes this true either way, and
|
|
183
|
+
// without one the channel only ever picked between a broken prompt and a working one.
|
|
184
|
+
const isChat = (0, stentor_utils_1.existsAndNotEmpty)(transcript);
|
|
144
185
|
const hasBusinessDescription = !!businessDescription;
|
|
145
186
|
const hasHighValueLeadDescription = !!highValueLeadDescription;
|
|
146
187
|
let intro = `You are a knowledgeable employee of a business.`;
|
|
@@ -167,7 +208,7 @@ ${getHighValueLeadDescription(highValueLeadDescription)}
|
|
|
167
208
|
|
|
168
209
|
Return "highValueLead": true when the lead matches that definition and false when it does not. Always return one or the other - never omit it. Judge it only against the definition above, not against how urgent or how large the request seems.`;
|
|
169
210
|
}
|
|
170
|
-
|
|
211
|
+
const system = `
|
|
171
212
|
${intro}
|
|
172
213
|
|
|
173
214
|
${instructions}
|
|
@@ -180,7 +221,8 @@ You will return you analysis as a JSON object with the following properties:
|
|
|
180
221
|
- urgency
|
|
181
222
|
- analysis
|
|
182
223
|
- summary
|
|
183
|
-
- conciseSummary
|
|
224
|
+
- conciseSummary
|
|
225
|
+
- spokenSummary${hasHighValueLeadDescription ? "\n- highValueLead" : ""}
|
|
184
226
|
|
|
185
227
|
Provide your analysis of why you made these decisions which will be placed in the value "analysis". Include why you made decisions for contactType, serviceType, jobType and urgency. The analysis should be concise and provide enough detail to understand your reasoning. The analysis should not exceed 500 characters.
|
|
186
228
|
|
|
@@ -242,16 +284,18 @@ Examples:
|
|
|
242
284
|
- Message: "scorpion and cricket issues" → "scorpion cricket issues"
|
|
243
285
|
- Message: "i'm interested in filing bankruptcy" → "bankruptcy filing"
|
|
244
286
|
- Message (pest control company): "this is only for small casita housing. not big main house" → "casita housing service"
|
|
287
|
+
|
|
288
|
+
Provide a phrase of at most 20 words that completes the sentence "The customer needs help with ..." and will be read aloud to the business on a phone call. Return this in the value "spokenSummary". Say what the problem or job is and anything that affects when or how they want it done (damage, timing, size). Write it the way a dispatcher would say it out loud: plain spoken words, no abbreviations, symbols, lists or quotes, and no names, phone numbers, emails or addresses. Start in lowercase and do not end with a period.
|
|
289
|
+
Examples:
|
|
290
|
+
- Message: "water coming through ceiling in kitchen since the storm last night, need someone asap" → "a roof leak over the kitchen since last night's storm, and wants someone out as soon as possible"
|
|
291
|
+
- Message: "we need our backflow tested" → "getting their backflow tested"
|
|
292
|
+
- Message: "looking for a quote to replace 12 windows in a 2 story house" → "a quote to replace twelve windows on a two story house"
|
|
245
293
|
`;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
The following fields were collected from the customer or potential customer in the form submission:
|
|
250
|
-
${parsedFields}
|
|
251
|
-
`;
|
|
252
|
-
}
|
|
294
|
+
// Carried as a user turn rather than appended to `system`: a system-only message list reaches
|
|
295
|
+
// Bedrock empty. See transcriptToMessages.
|
|
296
|
+
const formSubmission = !isChat && (0, stentor_utils_1.existsAndNotEmpty)(fields) ? parseFields(fields) : undefined;
|
|
253
297
|
// console.log(system);
|
|
254
|
-
const messages = transcriptToMessages(system, transcript);
|
|
298
|
+
const messages = transcriptToMessages(system, transcript, formSubmission);
|
|
255
299
|
// determine max_tokens based on the length of the system message
|
|
256
300
|
// const systemMessageLength = JSON.stringify(system).length;
|
|
257
301
|
// const tokens = getTokens(system);
|
|
@@ -277,6 +321,7 @@ ${parsedFields}
|
|
|
277
321
|
"urgency",
|
|
278
322
|
"highValueLead",
|
|
279
323
|
"conciseSummary",
|
|
324
|
+
"spokenSummary",
|
|
280
325
|
"summary",
|
|
281
326
|
"analysis"
|
|
282
327
|
],
|
|
@@ -306,6 +351,9 @@ ${parsedFields}
|
|
|
306
351
|
conciseSummary: {
|
|
307
352
|
type: "string"
|
|
308
353
|
},
|
|
354
|
+
spokenSummary: {
|
|
355
|
+
type: "string"
|
|
356
|
+
},
|
|
309
357
|
analysis: {
|
|
310
358
|
type: "string"
|
|
311
359
|
}
|
|
@@ -324,13 +372,18 @@ exports.defaultLeadAnalysis = {
|
|
|
324
372
|
};
|
|
325
373
|
const analyzeLeadResponseParse = (response) => {
|
|
326
374
|
try {
|
|
327
|
-
const { contactType, jobType, serviceType, urgency, highValueLead, summary, analysis, conciseSummary } = JSON.parse((0, extractJSON_1.extractJSON)(response));
|
|
375
|
+
const { contactType, jobType, serviceType, urgency, highValueLead, summary, analysis, conciseSummary, spokenSummary } = JSON.parse((0, extractJSON_1.extractJSON)(response));
|
|
328
376
|
// Checked against the allowed values: Bedrock ignores the schema, so nothing else does.
|
|
329
377
|
const labels = (0, LeadAnalysis_1.normalizeLeadLabels)({ contactType, serviceType, jobType, urgency });
|
|
330
378
|
const draftAnalysis = Object.assign(Object.assign({}, exports.defaultLeadAnalysis), { contactType: labels.contactType || exports.defaultLeadAnalysis.contactType, urgency: labels.urgency || exports.defaultLeadAnalysis.urgency, highValueLead: (highValueLead === null || highValueLead === void 0 ? void 0 : highValueLead.toString().toLocaleLowerCase()) === "true" || exports.defaultLeadAnalysis.highValueLead, summary: summary || exports.defaultLeadAnalysis.summary, analysis: analysis || exports.defaultLeadAnalysis.analysis });
|
|
331
379
|
if (conciseSummary) {
|
|
332
380
|
draftAnalysis.conciseSummary = conciseSummary;
|
|
333
381
|
}
|
|
382
|
+
// It is spoken as the end of "... needs help with: <spokenSummary>." -- a period of its own would double up.
|
|
383
|
+
const spoken = typeof spokenSummary === "string" ? spokenSummary.trim().replace(/[.\s]+$/, "") : "";
|
|
384
|
+
if (spoken) {
|
|
385
|
+
draftAnalysis.spokenSummary = spoken;
|
|
386
|
+
}
|
|
334
387
|
if (labels.jobType) {
|
|
335
388
|
draftAnalysis.jobType = labels.jobType;
|
|
336
389
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnalyzeLead.js","sourceRoot":"","sources":["../../src/prompts/AnalyzeLead.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AnalyzeLead.js","sourceRoot":"","sources":["../../src/prompts/AnalyzeLead.ts"],"names":[],"mappings":";;;AA0EA,kDAMC;AAyBD,oDAkEC;AAOD,kCAaC;AAQD,kEAEC;AAvMD,iDAAkD;AAGlD,6CAAyD;AACzD,sDAAmD;AACnD,yDAAqH;AACrH,6DAAiH;AAEjH,kDAAkD;AAElD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACU,QAAA,oBAAoB,GAAG,OAAO,CAAC;AA2B5C,SAAS,OAAO,CAAC,OAA+C;IAC5D,mCAAmC;IACnC,OAAO,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,MAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,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