@xapp/stentor-service-generative-ai 1.85.1 → 1.89.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.
- package/lib/GenerativeAIService.d.ts +11 -2
- package/lib/GenerativeAIService.js +22 -0
- package/lib/GenerativeAIService.js.map +1 -1
- package/lib/models/EngagementAnalysis.d.ts +93 -0
- package/lib/models/EngagementAnalysis.js +4 -0
- package/lib/models/EngagementAnalysis.js.map +1 -0
- package/lib/models/GenerativeAIService.d.ts +11 -1
- package/lib/models/index.d.ts +1 -0
- package/lib/models/index.js +1 -0
- package/lib/models/index.js.map +1 -1
- package/lib/prompts/AnalyzeTranscript.d.ts +24 -0
- package/lib/prompts/AnalyzeTranscript.js +202 -0
- package/lib/prompts/AnalyzeTranscript.js.map +1 -0
- package/lib/prompts/index.d.ts +1 -0
- package/lib/prompts/index.js +1 -0
- package/lib/prompts/index.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*! Copyright (c) 2026, XAPP AI */
|
|
2
|
-
import type { ExternalLead } from "stentor-models";
|
|
3
|
-
import type { AnalyzeLeadOptions, AnalyzeWebsiteData, IGenerativeAIService, LeadAnalysis, LLMService, LLMServiceResponse, Prompt } from "./models";
|
|
2
|
+
import type { ExternalLead, Message } from "stentor-models";
|
|
3
|
+
import type { AnalyzeLeadOptions, AnalyzeWebsiteData, EngagementAnalysis, EngagementAnalysisConfig, IGenerativeAIService, LeadAnalysis, LLMService, LLMServiceResponse, Prompt } from "./models";
|
|
4
4
|
import type { EmailAnalysisInput, EmailLeadAnalysis } from "./models/EmailAnalysis";
|
|
5
5
|
import type { ChatSummary } from "./models/ChatSummary";
|
|
6
6
|
import { WebsiteAnalysis } from "./models/WebsiteAnalysis";
|
|
@@ -30,6 +30,15 @@ export declare class GenerativeAIService implements IGenerativeAIService {
|
|
|
30
30
|
* @param options - Optional business context and LLM call options.
|
|
31
31
|
*/
|
|
32
32
|
analyzeEmail(email: EmailAnalysisInput, options?: AnalyzeLeadOptions): Promise<EmailLeadAnalysis>;
|
|
33
|
+
/**
|
|
34
|
+
* Analyze a completed conversation transcript to derive engagement metadata: sentiment,
|
|
35
|
+
* topics, whether the AI agent contained/resolved the conversation without human handoff,
|
|
36
|
+
* escalation, and business-defined categories.
|
|
37
|
+
*
|
|
38
|
+
* @param transcript - The chat transcript to analyze.
|
|
39
|
+
* @param config - Optional categories and business context to customize the analysis.
|
|
40
|
+
*/
|
|
41
|
+
analyzeTranscript(transcript: Message[], config?: EngagementAnalysisConfig): Promise<EngagementAnalysis>;
|
|
33
42
|
/**
|
|
34
43
|
* Summarize a chat transcript
|
|
35
44
|
* @param transcript
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.GenerativeAIService = void 0;
|
|
13
13
|
const AnalyzeEmail_1 = require("./prompts/AnalyzeEmail");
|
|
14
14
|
const AnalyzeLead_1 = require("./prompts/AnalyzeLead");
|
|
15
|
+
const AnalyzeTranscript_1 = require("./prompts/AnalyzeTranscript");
|
|
15
16
|
const prompts_1 = require("./prompts");
|
|
16
17
|
const AnalyzeWebsite_1 = require("./prompts/AnalyzeWebsite");
|
|
17
18
|
class GenerativeAIService {
|
|
@@ -83,6 +84,27 @@ class GenerativeAIService {
|
|
|
83
84
|
return analysis;
|
|
84
85
|
});
|
|
85
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Analyze a completed conversation transcript to derive engagement metadata: sentiment,
|
|
89
|
+
* topics, whether the AI agent contained/resolved the conversation without human handoff,
|
|
90
|
+
* escalation, and business-defined categories.
|
|
91
|
+
*
|
|
92
|
+
* @param transcript - The chat transcript to analyze.
|
|
93
|
+
* @param config - Optional categories and business context to customize the analysis.
|
|
94
|
+
*/
|
|
95
|
+
analyzeTranscript(transcript, config) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
const prompt = (0, AnalyzeTranscript_1.generateAnalyzeTranscript)({
|
|
98
|
+
transcript,
|
|
99
|
+
businessContext: config === null || config === void 0 ? void 0 : config.businessContext,
|
|
100
|
+
categories: config === null || config === void 0 ? void 0 : config.categories
|
|
101
|
+
});
|
|
102
|
+
const llmResponse = yield this.llmService.generate(prompt);
|
|
103
|
+
const analysis = (0, AnalyzeTranscript_1.analyzeTranscriptResponseParse)(llmResponse.text);
|
|
104
|
+
analysis.analysisVersion = AnalyzeTranscript_1.ANALYZE_TRANSCRIPT_VERSION;
|
|
105
|
+
return analysis;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
86
108
|
/**
|
|
87
109
|
* Summarize a chat transcript
|
|
88
110
|
* @param transcript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerativeAIService.js","sourceRoot":"","sources":["../src/GenerativeAIService.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"GenerativeAIService.js","sourceRoot":"","sources":["../src/GenerativeAIService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAgBA,yDAAgH;AAChH,uDAAsF;AACtF,mEAAoI;AACpI,uCAAkG;AAGlG,6DAA+F;AAE/F,MAAa,mBAAmB;IAG5B,YAAY,UAAsB;QAC9B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;IAED;;;;OAIG;IACG,YAAY,CAAC,MAAc;;YAC7B,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC5C,CAAC;KAAA;IAED;;;;OAIG;IACG,WAAW,CAAC,IAAkB,EAAE,OAA4B;;YAC9D,MAAM,MAAM,GAAG,IAAA,iCAAmB,EAAC;gBAC/B,OAAO,EAAE,IAAI,CAAC,MAAM;gBACpB,mBAAmB,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,KAAI,EAAE;gBACvD,wBAAwB,EAAE,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,wBA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AA2B,EAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACzD,CAAC;KAAA;CACJ;AAtHD,kDAsHC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*! Copyright (c) 2026, XAPP AI */
|
|
2
|
+
/**
|
|
3
|
+
* Overall sentiment expressed by the customer over the course of the conversation.
|
|
4
|
+
*/
|
|
5
|
+
export type EngagementSentiment = "POSITIVE" | "NEUTRAL" | "NEGATIVE";
|
|
6
|
+
/**
|
|
7
|
+
* A single category that a business wants engagement transcripts classified against.
|
|
8
|
+
*/
|
|
9
|
+
export interface EngagementAnalysisCategory {
|
|
10
|
+
/**
|
|
11
|
+
* A unique key for the category, e.g. "BILLING_QUESTION". Returned back in the analysis
|
|
12
|
+
* `categories` array and used as the enum value in the structured-output json_schema.
|
|
13
|
+
*/
|
|
14
|
+
key: string;
|
|
15
|
+
/**
|
|
16
|
+
* A description of when this category applies, injected into the system prompt so the
|
|
17
|
+
* LLM can decide whether the transcript matches it.
|
|
18
|
+
*/
|
|
19
|
+
description: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Configuration for `GenerativeAIService.analyzeTranscript()`. Lets a business customize the
|
|
23
|
+
* categories a transcript is classified against and provide additional business context.
|
|
24
|
+
*/
|
|
25
|
+
export interface EngagementAnalysisConfig {
|
|
26
|
+
/**
|
|
27
|
+
* The categories to classify the transcript against. Injected into the system prompt and
|
|
28
|
+
* the structured-output json_schema enum. Defaults to `DEFAULT_ENGAGEMENT_CATEGORIES` when
|
|
29
|
+
* omitted.
|
|
30
|
+
*/
|
|
31
|
+
categories?: EngagementAnalysisCategory[];
|
|
32
|
+
/**
|
|
33
|
+
* Additional context about the business to help the LLM understand the transcript.
|
|
34
|
+
*/
|
|
35
|
+
businessContext?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A category that was determined to apply to the transcript, from the set provided in
|
|
39
|
+
* `EngagementAnalysisConfig.categories` (or the default categories when none was provided).
|
|
40
|
+
*/
|
|
41
|
+
export interface EngagementAnalysisCategoryResult {
|
|
42
|
+
key: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The result of analyzing an engagement (chat transcript) between a customer and an AI agent.
|
|
46
|
+
* Returned by `GenerativeAIService.analyzeTranscript()`.
|
|
47
|
+
*/
|
|
48
|
+
export interface EngagementAnalysis {
|
|
49
|
+
/**
|
|
50
|
+
* The version of the analysis that was performed. This changes when major changes are made
|
|
51
|
+
* to the analysis process. It can be used to determine if the analysis is up to date and
|
|
52
|
+
* needs to be re-run.
|
|
53
|
+
*/
|
|
54
|
+
analysisVersion?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The overall sentiment expressed by the customer.
|
|
57
|
+
*/
|
|
58
|
+
sentiment?: EngagementSentiment;
|
|
59
|
+
/**
|
|
60
|
+
* The main topics discussed in the conversation.
|
|
61
|
+
*/
|
|
62
|
+
topics?: string[];
|
|
63
|
+
/**
|
|
64
|
+
* Whether the AI agent was able to resolve the customer's need without any human handoff.
|
|
65
|
+
*/
|
|
66
|
+
containment?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Whether the customer's issue or question was resolved by the end of the conversation,
|
|
69
|
+
* regardless of who resolved it (AI or human).
|
|
70
|
+
*/
|
|
71
|
+
resolved?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether the conversation was or needs to be escalated to a human agent.
|
|
74
|
+
*/
|
|
75
|
+
escalation?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* A summary of the conversation.
|
|
78
|
+
*/
|
|
79
|
+
summary?: string;
|
|
80
|
+
/**
|
|
81
|
+
* A 2-3 word concise summary of the conversation, main use for this is in a word cloud and
|
|
82
|
+
* on a dashboard list item.
|
|
83
|
+
*/
|
|
84
|
+
conciseSummary?: string;
|
|
85
|
+
/**
|
|
86
|
+
* The categories (from `EngagementAnalysisConfig.categories`) that apply to this conversation.
|
|
87
|
+
*/
|
|
88
|
+
categories?: EngagementAnalysisCategoryResult[];
|
|
89
|
+
/**
|
|
90
|
+
* An analysis of how the LLM came to its conclusions.
|
|
91
|
+
*/
|
|
92
|
+
analysis?: string;
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EngagementAnalysis.js","sourceRoot":"","sources":["../../src/models/EngagementAnalysis.ts"],"names":[],"mappings":";AAAA,kCAAkC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/*! Copyright (c) 2026, XAPP AI */
|
|
2
|
-
import type { ExternalLead } from "stentor-models";
|
|
2
|
+
import type { ExternalLead, Message } from "stentor-models";
|
|
3
3
|
import type { EmailAnalysisInput, EmailLeadAnalysis } from "./EmailAnalysis";
|
|
4
|
+
import type { EngagementAnalysis, EngagementAnalysisConfig } from "./EngagementAnalysis";
|
|
4
5
|
import type { LeadAnalysis } from "./LeadAnalysis";
|
|
5
6
|
import type { WebsiteAnalysis } from "./WebsiteAnalysis";
|
|
6
7
|
import type { ChatSummary } from "./ChatSummary";
|
|
@@ -39,6 +40,15 @@ export interface IGenerativeAIService {
|
|
|
39
40
|
* @param options - Optional business context and LLM call options.
|
|
40
41
|
*/
|
|
41
42
|
analyzeEmail(email: EmailAnalysisInput, options?: AnalyzeLeadOptions): Promise<EmailLeadAnalysis>;
|
|
43
|
+
/**
|
|
44
|
+
* Analyze a completed conversation transcript to derive engagement metadata: sentiment,
|
|
45
|
+
* topics, whether the AI agent contained/resolved the conversation without human handoff,
|
|
46
|
+
* escalation, and business-defined categories.
|
|
47
|
+
*
|
|
48
|
+
* @param transcript - The chat transcript to analyze.
|
|
49
|
+
* @param config - Optional categories and business context to customize the analysis.
|
|
50
|
+
*/
|
|
51
|
+
analyzeTranscript(transcript: Message[], config?: EngagementAnalysisConfig): Promise<EngagementAnalysis>;
|
|
42
52
|
/**
|
|
43
53
|
* Summarize a chat transcript
|
|
44
54
|
* @param transcript
|
package/lib/models/index.d.ts
CHANGED
package/lib/models/index.js
CHANGED
|
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
__exportStar(require("./EmailAnalysis"), exports);
|
|
19
|
+
__exportStar(require("./EngagementAnalysis"), exports);
|
|
19
20
|
__exportStar(require("./errors"), exports);
|
|
20
21
|
__exportStar(require("./GenerativeAIService"), exports);
|
|
21
22
|
__exportStar(require("./LeadAnalysis"), exports);
|
package/lib/models/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,kDAAgC;AAChC,2CAAyB;AACzB,wDAAsC;AACtC,iDAA+B;AAC/B,+CAA6B;AAC7B,2CAAyB;AACzB,oDAAkC;AAClC,mDAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,kDAAgC;AAChC,uDAAqC;AACrC,2CAAyB;AACzB,wDAAsC;AACtC,iDAA+B;AAC/B,+CAA6B;AAC7B,2CAAyB;AACzB,oDAAkC;AAClC,mDAAiC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*! Copyright (c) 2026, XAPP AI */
|
|
2
|
+
import type { Message } from "stentor-models";
|
|
3
|
+
import type { CompletionPrompt, EngagementAnalysis, EngagementAnalysisCategory, PromptGenerator, ResponseParser } from "../models";
|
|
4
|
+
export declare const ANALYZE_TRANSCRIPT_VERSION = "1.0.0";
|
|
5
|
+
/**
|
|
6
|
+
* Sensible default engagement categories used when a business does not provide its own
|
|
7
|
+
* `EngagementAnalysisConfig.categories`.
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_ENGAGEMENT_CATEGORIES: EngagementAnalysisCategory[];
|
|
10
|
+
export interface AnalyzeTranscriptProps {
|
|
11
|
+
transcript: Message[];
|
|
12
|
+
businessContext?: string;
|
|
13
|
+
categories?: EngagementAnalysisCategory[];
|
|
14
|
+
}
|
|
15
|
+
export type AnalyzeTranscriptLLMOverrides = Partial<Pick<CompletionPrompt, "model" | "max_tokens" | "temperature" | "top_p" | "frequency_penalty" | "presence_penalty">>;
|
|
16
|
+
/**
|
|
17
|
+
* Generates a prompt that can be used in an LLM to analyze a completed chat transcript between
|
|
18
|
+
* a customer and an AI agent representing a business, deriving engagement metadata.
|
|
19
|
+
*
|
|
20
|
+
* @param props - The transcript to analyze, along with optional categories and business context.
|
|
21
|
+
* @param overrides - Optional overrides for LLM call parameters.
|
|
22
|
+
*/
|
|
23
|
+
export declare const generateAnalyzeTranscript: PromptGenerator<AnalyzeTranscriptProps, AnalyzeTranscriptLLMOverrides, CompletionPrompt>;
|
|
24
|
+
export declare const analyzeTranscriptResponseParse: ResponseParser<EngagementAnalysis>;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyzeTranscriptResponseParse = exports.generateAnalyzeTranscript = exports.DEFAULT_ENGAGEMENT_CATEGORIES = exports.ANALYZE_TRANSCRIPT_VERSION = void 0;
|
|
4
|
+
const extractJSON_1 = require("../utils/extractJSON");
|
|
5
|
+
const AnalyzeLead_1 = require("./AnalyzeLead");
|
|
6
|
+
exports.ANALYZE_TRANSCRIPT_VERSION = "1.0.0";
|
|
7
|
+
/**
|
|
8
|
+
* Sensible default engagement categories used when a business does not provide its own
|
|
9
|
+
* `EngagementAnalysisConfig.categories`.
|
|
10
|
+
*/
|
|
11
|
+
exports.DEFAULT_ENGAGEMENT_CATEGORIES = [
|
|
12
|
+
{
|
|
13
|
+
key: "GENERAL_INQUIRY",
|
|
14
|
+
description: "A general question about the business, its products, or services."
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
key: "SUPPORT_REQUEST",
|
|
18
|
+
description: "The customer needed help with an existing product, service, or account issue."
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
key: "COMPLAINT",
|
|
22
|
+
description: "The customer expressed dissatisfaction with the business, product, or service."
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
key: "COMPLIMENT",
|
|
26
|
+
description: "The customer gave positive feedback about the business, staff, or product."
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
key: "SALES_INQUIRY",
|
|
30
|
+
description: "The customer was interested in purchasing a product or service, or requested pricing."
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "TECHNICAL_ISSUE",
|
|
34
|
+
description: "The customer reported a bug, error, or something not working as expected."
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
key: "OTHER",
|
|
38
|
+
description: "The conversation does not fit any of the other categories."
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
/**
|
|
42
|
+
* Generates a prompt that can be used in an LLM to analyze a completed chat transcript between
|
|
43
|
+
* a customer and an AI agent representing a business, deriving engagement metadata.
|
|
44
|
+
*
|
|
45
|
+
* @param props - The transcript to analyze, along with optional categories and business context.
|
|
46
|
+
* @param overrides - Optional overrides for LLM call parameters.
|
|
47
|
+
*/
|
|
48
|
+
const generateAnalyzeTranscript = ({ transcript, businessContext, categories }, overrides) => {
|
|
49
|
+
const resolvedCategories = categories && categories.length > 0 ? categories : exports.DEFAULT_ENGAGEMENT_CATEGORIES;
|
|
50
|
+
let intro = `You are a knowledgeable employee of a business.`;
|
|
51
|
+
if (businessContext) {
|
|
52
|
+
intro = `
|
|
53
|
+
You are a knowledgeable employee of a business with the following context:
|
|
54
|
+
|
|
55
|
+
===
|
|
56
|
+
${businessContext}
|
|
57
|
+
===`;
|
|
58
|
+
}
|
|
59
|
+
const categoryDefinitions = resolvedCategories.map(({ key, description }) => `${key}: ${description}`).join("\n");
|
|
60
|
+
const categoryKeys = resolvedCategories.map(({ key }) => key);
|
|
61
|
+
const system = `
|
|
62
|
+
${intro}
|
|
63
|
+
|
|
64
|
+
Your job is to analyze the following chat transcript that occurred between a customer or potential customer and an AI agent representing the business.
|
|
65
|
+
|
|
66
|
+
You will return your analysis as a JSON object with the following properties:
|
|
67
|
+
|
|
68
|
+
- sentiment
|
|
69
|
+
- topics
|
|
70
|
+
- containment
|
|
71
|
+
- resolved
|
|
72
|
+
- escalation
|
|
73
|
+
- categories
|
|
74
|
+
- summary
|
|
75
|
+
- conciseSummary
|
|
76
|
+
- analysis
|
|
77
|
+
|
|
78
|
+
"sentiment" definitions are as follows:
|
|
79
|
+
POSITIVE: The customer expressed satisfaction, gratitude, or an overall positive tone.
|
|
80
|
+
NEUTRAL: The customer's tone was neutral or transactional, or sentiment could not be determined.
|
|
81
|
+
NEGATIVE: The customer expressed frustration, dissatisfaction, or an overall negative tone.
|
|
82
|
+
|
|
83
|
+
Provide the main topics discussed in the conversation as an array of short (2-4 word) strings in the value "topics".
|
|
84
|
+
|
|
85
|
+
"containment" is true if the AI agent was able to fully address the customer's need without any human handoff being requested or required. It is false if a human needed to be, or was, involved at any point.
|
|
86
|
+
|
|
87
|
+
"resolved" is true if the customer's issue or question was addressed by the end of the conversation, regardless of whether it was the AI agent or a human who resolved it. It is false if the conversation ended without resolution.
|
|
88
|
+
|
|
89
|
+
"escalation" is true if the conversation was escalated, or should be escalated, to a human agent.
|
|
90
|
+
|
|
91
|
+
For "categories", return an array of objects with a "key" property containing every category below that applies to this conversation. Include at least one category. The definitions of each category are as follows:
|
|
92
|
+
${categoryDefinitions}
|
|
93
|
+
|
|
94
|
+
Provide a summary of the conversation which will be placed in the value "summary". The summary should not exceed 250 characters.
|
|
95
|
+
|
|
96
|
+
Provide a concise 2–3 word phrase describing the main topic of the conversation. Return this in the value "conciseSummary".
|
|
97
|
+
|
|
98
|
+
Provide your analysis of why you made these decisions which will be placed in the value "analysis". Include why you made decisions for sentiment, containment, resolved, escalation, and categories. The analysis should be concise and provide enough detail to understand your reasoning. The analysis should not exceed 500 characters.
|
|
99
|
+
`;
|
|
100
|
+
const messages = (0, AnalyzeLead_1.transcriptToMessages)(system, transcript);
|
|
101
|
+
const max_tokens = 768;
|
|
102
|
+
return Object.assign(Object.assign({ model: "claude-haiku-4-5-20251001", max_tokens, frequency_penalty: 0, temperature: 1, top_p: 1, presence_penalty: 0 }, overrides), { response_format: {
|
|
103
|
+
type: "json_schema",
|
|
104
|
+
json_schema: {
|
|
105
|
+
name: "analyze_transcript",
|
|
106
|
+
strict: false,
|
|
107
|
+
schema: {
|
|
108
|
+
type: "object",
|
|
109
|
+
additionalProperties: false,
|
|
110
|
+
required: [
|
|
111
|
+
"sentiment",
|
|
112
|
+
"topics",
|
|
113
|
+
"containment",
|
|
114
|
+
"resolved",
|
|
115
|
+
"escalation",
|
|
116
|
+
"categories",
|
|
117
|
+
"summary",
|
|
118
|
+
"conciseSummary",
|
|
119
|
+
"analysis"
|
|
120
|
+
],
|
|
121
|
+
properties: {
|
|
122
|
+
sentiment: {
|
|
123
|
+
type: "string",
|
|
124
|
+
enum: ["POSITIVE", "NEUTRAL", "NEGATIVE"]
|
|
125
|
+
},
|
|
126
|
+
topics: {
|
|
127
|
+
type: "array",
|
|
128
|
+
items: {
|
|
129
|
+
type: "string"
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
containment: {
|
|
133
|
+
type: "boolean"
|
|
134
|
+
},
|
|
135
|
+
resolved: {
|
|
136
|
+
type: "boolean"
|
|
137
|
+
},
|
|
138
|
+
escalation: {
|
|
139
|
+
type: "boolean"
|
|
140
|
+
},
|
|
141
|
+
categories: {
|
|
142
|
+
type: "array",
|
|
143
|
+
items: {
|
|
144
|
+
type: "object",
|
|
145
|
+
additionalProperties: false,
|
|
146
|
+
required: ["key"],
|
|
147
|
+
properties: {
|
|
148
|
+
key: {
|
|
149
|
+
type: "string",
|
|
150
|
+
enum: categoryKeys
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
summary: {
|
|
156
|
+
type: "string"
|
|
157
|
+
},
|
|
158
|
+
conciseSummary: {
|
|
159
|
+
type: "string"
|
|
160
|
+
},
|
|
161
|
+
analysis: {
|
|
162
|
+
type: "string"
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}, type: "completions", messages });
|
|
168
|
+
};
|
|
169
|
+
exports.generateAnalyzeTranscript = generateAnalyzeTranscript;
|
|
170
|
+
const defaultEngagementAnalysis = {
|
|
171
|
+
sentiment: "NEUTRAL",
|
|
172
|
+
topics: [],
|
|
173
|
+
containment: false,
|
|
174
|
+
resolved: false,
|
|
175
|
+
escalation: false,
|
|
176
|
+
categories: [],
|
|
177
|
+
summary: "A summary could not be generated.",
|
|
178
|
+
analysis: "An analysis could not be generated."
|
|
179
|
+
};
|
|
180
|
+
const analyzeTranscriptResponseParse = (response) => {
|
|
181
|
+
try {
|
|
182
|
+
const { sentiment, topics, containment, resolved, escalation, categories, summary, conciseSummary, analysis } = JSON.parse((0, extractJSON_1.extractJSON)(response));
|
|
183
|
+
const draftAnalysis = Object.assign(Object.assign({}, defaultEngagementAnalysis), { sentiment: (sentiment === null || sentiment === void 0 ? void 0 : sentiment.toUpperCase()) || defaultEngagementAnalysis.sentiment, containment: (containment === null || containment === void 0 ? void 0 : containment.toString().toLocaleLowerCase()) === "true" || defaultEngagementAnalysis.containment, resolved: (resolved === null || resolved === void 0 ? void 0 : resolved.toString().toLocaleLowerCase()) === "true" || defaultEngagementAnalysis.resolved, escalation: (escalation === null || escalation === void 0 ? void 0 : escalation.toString().toLocaleLowerCase()) === "true" || defaultEngagementAnalysis.escalation, summary: summary || defaultEngagementAnalysis.summary, analysis: analysis || defaultEngagementAnalysis.analysis });
|
|
184
|
+
if (conciseSummary) {
|
|
185
|
+
draftAnalysis.conciseSummary = conciseSummary;
|
|
186
|
+
}
|
|
187
|
+
if (Array.isArray(topics)) {
|
|
188
|
+
draftAnalysis.topics = topics.filter((topic) => typeof topic === "string");
|
|
189
|
+
}
|
|
190
|
+
if (Array.isArray(categories)) {
|
|
191
|
+
// Preserve the exact key casing from the config's categories rather than normalizing it,
|
|
192
|
+
// since (unlike contactType/urgency) categories are business-defined, not a fixed enum.
|
|
193
|
+
draftAnalysis.categories = categories.filter((category) => category && typeof category.key === "string" && category.key.length > 0);
|
|
194
|
+
}
|
|
195
|
+
return draftAnalysis;
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
return Object.assign({}, defaultEngagementAnalysis);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
exports.analyzeTranscriptResponseParse = analyzeTranscriptResponseParse;
|
|
202
|
+
//# sourceMappingURL=AnalyzeTranscript.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnalyzeTranscript.js","sourceRoot":"","sources":["../../src/prompts/AnalyzeTranscript.ts"],"names":[],"mappings":";;;AAIA,sDAAmD;AACnD,+CAAqD;AAExC,QAAA,0BAA0B,GAAG,OAAO,CAAC;AAElD;;;GAGG;AACU,QAAA,6BAA6B,GAAiC;IACvE;QACI,GAAG,EAAE,iBAAiB;QACtB,WAAW,EAAE,mEAAmE;KACnF;IACD;QACI,GAAG,EAAE,iBAAiB;QACtB,WAAW,EAAE,+EAA+E;KAC/F;IACD;QACI,GAAG,EAAE,WAAW;QAChB,WAAW,EAAE,gFAAgF;KAChG;IACD;QACI,GAAG,EAAE,YAAY;QACjB,WAAW,EAAE,4EAA4E;KAC5F;IACD;QACI,GAAG,EAAE,eAAe;QACpB,WAAW,EAAE,uFAAuF;KACvG;IACD;QACI,GAAG,EAAE,iBAAiB;QACtB,WAAW,EAAE,2EAA2E;KAC3F;IACD;QACI,GAAG,EAAE,OAAO;QACZ,WAAW,EAAE,4DAA4D;KAC5E;CACJ,CAAC;AAYF;;;;;;GAMG;AACI,MAAM,yBAAyB,GAA6F,CAC/H,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,EAC3C,SAAS,EACO,EAAE;IA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,UAAU,GAAG,UAAU,CAAC,MAAM,CACxC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,IAAI,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ,IAAI,QAAQ,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CACxF,CAAC;QACN,CAAC;QAED,OAAO,aAAa,CAAC;IACzB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,yBAAY,yBAAyB,EAAG;IAC5C,CAAC;AACL,CAAC,CAAC;AApCW,QAAA,8BAA8B,kCAoCzC"}
|
package/lib/prompts/index.d.ts
CHANGED
package/lib/prompts/index.js
CHANGED
|
@@ -17,5 +17,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
__exportStar(require("./AnalyzeEmail"), exports);
|
|
19
19
|
__exportStar(require("./AnalyzeLead"), exports);
|
|
20
|
+
__exportStar(require("./AnalyzeTranscript"), exports);
|
|
20
21
|
__exportStar(require("./ChatSummary"), exports);
|
|
21
22
|
//# sourceMappingURL=index.js.map
|
package/lib/prompts/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,iDAA+B;AAC/B,gDAA8B;AAC9B,gDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;;;;;;;;;;;;;;AAElC,iDAA+B;AAC/B,gDAA8B;AAC9B,sDAAoC;AACpC,gDAA8B"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.89.1",
|
|
8
8
|
"description": "Generative AI Service",
|
|
9
9
|
"types": "lib/index",
|
|
10
10
|
"main": "lib/index",
|
|
@@ -41,10 +41,11 @@
|
|
|
41
41
|
"stentor-utils": "1.x"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
+
"prepack": "yarn build",
|
|
44
45
|
"build": "tsc -d true -p .",
|
|
45
46
|
"clean": "rm -rf ./lib/*",
|
|
46
47
|
"test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\"",
|
|
47
48
|
"ftest": "mocha --recursive -r ts-node/register \"./src/**/*.ftest.ts\""
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "3a345719866a5c39329b605545f04c465e6baf48"
|
|
50
51
|
}
|