@xapp/stentor-service-generative-ai 1.89.0 → 1.90.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.
Files changed (88) hide show
  1. package/lib/AWSBedrockService.d.ts +67 -0
  2. package/lib/AWSBedrockService.js +133 -0
  3. package/lib/AWSBedrockService.js.map +1 -0
  4. package/lib/ClaudeService.d.ts +77 -0
  5. package/lib/ClaudeService.js +142 -0
  6. package/lib/ClaudeService.js.map +1 -0
  7. package/lib/FallbackLLMService.d.ts +46 -0
  8. package/lib/FallbackLLMService.js +83 -0
  9. package/lib/FallbackLLMService.js.map +1 -0
  10. package/lib/GenerativeAIService.d.ts +49 -0
  11. package/lib/GenerativeAIService.js +157 -0
  12. package/lib/GenerativeAIService.js.map +1 -0
  13. package/lib/OpenAIService.d.ts +33 -0
  14. package/lib/OpenAIService.js +76 -0
  15. package/lib/OpenAIService.js.map +1 -0
  16. package/lib/http/HTTPService.d.ts +18 -0
  17. package/lib/http/HTTPService.js +4 -0
  18. package/lib/http/HTTPService.js.map +1 -0
  19. package/lib/http/NodeHTTPService.d.ts +8 -0
  20. package/lib/http/NodeHTTPService.js +70 -0
  21. package/lib/http/NodeHTTPService.js.map +1 -0
  22. package/lib/http/index.d.ts +3 -0
  23. package/lib/http/index.js +20 -0
  24. package/lib/http/index.js.map +1 -0
  25. package/lib/index.d.ts +10 -0
  26. package/lib/index.js +27 -0
  27. package/lib/index.js.map +1 -0
  28. package/lib/models/ChatSummary.d.ts +10 -0
  29. package/lib/models/ChatSummary.js +4 -0
  30. package/lib/models/ChatSummary.js.map +1 -0
  31. package/lib/models/EmailAnalysis.d.ts +73 -0
  32. package/lib/models/EmailAnalysis.js +4 -0
  33. package/lib/models/EmailAnalysis.js.map +1 -0
  34. package/lib/models/EngagementAnalysis.d.ts +93 -0
  35. package/lib/models/EngagementAnalysis.js +4 -0
  36. package/lib/models/EngagementAnalysis.js.map +1 -0
  37. package/lib/models/GenerativeAIService.d.ts +65 -0
  38. package/lib/models/GenerativeAIService.js +3 -0
  39. package/lib/models/GenerativeAIService.js.map +1 -0
  40. package/lib/models/LLMService.d.ts +24 -0
  41. package/lib/models/LLMService.js +4 -0
  42. package/lib/models/LLMService.js.map +1 -0
  43. package/lib/models/LeadAnalysis.d.ts +105 -0
  44. package/lib/models/LeadAnalysis.js +4 -0
  45. package/lib/models/LeadAnalysis.js.map +1 -0
  46. package/lib/models/Prompt.d.ts +37 -0
  47. package/lib/models/Prompt.js +8 -0
  48. package/lib/models/Prompt.js.map +1 -0
  49. package/lib/models/PromptGenerator.d.ts +6 -0
  50. package/lib/models/PromptGenerator.js +4 -0
  51. package/lib/models/PromptGenerator.js.map +1 -0
  52. package/lib/models/ResponseParser.d.ts +5 -0
  53. package/lib/models/ResponseParser.js +4 -0
  54. package/lib/models/ResponseParser.js.map +1 -0
  55. package/lib/models/WebsiteAnalysis.d.ts +48 -0
  56. package/lib/models/WebsiteAnalysis.js +4 -0
  57. package/lib/models/WebsiteAnalysis.js.map +1 -0
  58. package/lib/models/errors.d.ts +28 -0
  59. package/lib/models/errors.js +40 -0
  60. package/lib/models/errors.js.map +1 -0
  61. package/lib/models/index.d.ts +10 -0
  62. package/lib/models/index.js +27 -0
  63. package/lib/models/index.js.map +1 -0
  64. package/lib/prompts/AnalyzeEmail.d.ts +37 -0
  65. package/lib/prompts/AnalyzeEmail.js +389 -0
  66. package/lib/prompts/AnalyzeEmail.js.map +1 -0
  67. package/lib/prompts/AnalyzeLead.d.ts +60 -0
  68. package/lib/prompts/AnalyzeLead.js +400 -0
  69. package/lib/prompts/AnalyzeLead.js.map +1 -0
  70. package/lib/prompts/AnalyzeTranscript.d.ts +25 -0
  71. package/lib/prompts/AnalyzeTranscript.js +206 -0
  72. package/lib/prompts/AnalyzeTranscript.js.map +1 -0
  73. package/lib/prompts/AnalyzeWebsite.d.ts +10 -0
  74. package/lib/prompts/AnalyzeWebsite.js +176 -0
  75. package/lib/prompts/AnalyzeWebsite.js.map +1 -0
  76. package/lib/prompts/ChatSummary.d.ts +62 -0
  77. package/lib/prompts/ChatSummary.js +67 -0
  78. package/lib/prompts/ChatSummary.js.map +1 -0
  79. package/lib/prompts/index.d.ts +5 -0
  80. package/lib/prompts/index.js +22 -0
  81. package/lib/prompts/index.js.map +1 -0
  82. package/lib/utils/extractJSON.d.ts +10 -0
  83. package/lib/utils/extractJSON.js +17 -0
  84. package/lib/utils/extractJSON.js.map +1 -0
  85. package/lib/utils/standardizeTerms.d.ts +15 -0
  86. package/lib/utils/standardizeTerms.js +53 -0
  87. package/lib/utils/standardizeTerms.js.map +1 -0
  88. package/package.json +8 -7
@@ -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,4 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2026, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=EngagementAnalysis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EngagementAnalysis.js","sourceRoot":"","sources":["../../src/models/EngagementAnalysis.ts"],"names":[],"mappings":";AAAA,kCAAkC"}
@@ -0,0 +1,65 @@
1
+ /*! Copyright (c) 2026, XAPP AI */
2
+ import type { ExternalLead, Message } from "stentor-models";
3
+ import type { EmailAnalysisInput, EmailLeadAnalysis } from "./EmailAnalysis";
4
+ import type { EngagementAnalysis, EngagementAnalysisConfig } from "./EngagementAnalysis";
5
+ import type { LeadAnalysis } from "./LeadAnalysis";
6
+ import type { WebsiteAnalysis } from "./WebsiteAnalysis";
7
+ import type { ChatSummary } from "./ChatSummary";
8
+ import { Prompt } from "./Prompt";
9
+ import { LLMServiceResponse } from "./LLMService";
10
+ export type AnalyzeWebsiteData = {
11
+ url: string;
12
+ };
13
+ export interface BaseOptions {
14
+ timeout?: number;
15
+ }
16
+ export interface AnalyzeLeadOptions extends BaseOptions {
17
+ businessDescription?: string;
18
+ highValueLeadDescription?: string;
19
+ }
20
+ export interface IGenerativeAIService {
21
+ /**
22
+ * Executes a custom prompt that the user is responsible for creating and parsing.
23
+ *
24
+ * @param prompt
25
+ */
26
+ customPrompt(prompt: Prompt): Promise<LLMServiceResponse>;
27
+ /**
28
+ * Analyze a lead to find summary
29
+ * @param lead
30
+ */
31
+ analyzeLead(lead: ExternalLead): Promise<LeadAnalysis>;
32
+ /**
33
+ * Analyze an inbound email (or email thread) to classify and extract lead information.
34
+ *
35
+ * Combines lead classification (contactType, serviceType, jobType, urgency) with
36
+ * structured contact extraction in a single LLM call. Handles direct customer emails,
37
+ * FSM/CRM lead notification emails, and multi-email threads.
38
+ *
39
+ * @param email - The email content and optional thread history to analyze.
40
+ * @param options - Optional business context and LLM call options.
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>;
52
+ /**
53
+ * Summarize a chat transcript
54
+ * @param transcript
55
+ * @returns Returns the summarized chat of a lead transcript
56
+ */
57
+ summarizeChatFromTranscript(transcript: ExternalLead["transcript"]): Promise<ChatSummary>;
58
+ /**
59
+ * Analyze a website to find information about the business, such as contact information, about us, and more.
60
+ *
61
+ * @param markdown
62
+ * @param data
63
+ */
64
+ analyzeWebsite(markdown: string, data: AnalyzeWebsiteData): Promise<WebsiteAnalysis>;
65
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=GenerativeAIService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenerativeAIService.js","sourceRoot":"","sources":["../../src/models/GenerativeAIService.ts"],"names":[],"mappings":""}
@@ -0,0 +1,24 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ import { Prompt } from "./Prompt";
3
+ /**
4
+ * A function that returns an API key, either synchronously or asynchronously
5
+ */
6
+ export type APIKeyGetter = () => string | Promise<string>;
7
+ export interface LLMServiceResponse {
8
+ text: string;
9
+ }
10
+ /**
11
+ * A service that can generate text based on a prompt sent to an LLM Service
12
+ */
13
+ export interface LLMService {
14
+ /**
15
+ * Generate a response based on the input
16
+ * @param input
17
+ * @param options - Optional parameters for the generation, such as timeout
18
+ * @returns A promise that resolves to the response from the LLM Service
19
+ * @throws Error if the LLM Service is not available or the prompt is invalid
20
+ */
21
+ generate(prompt: Prompt, options?: {
22
+ timeout?: number;
23
+ }): Promise<LLMServiceResponse>;
24
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=LLMService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LLMService.js","sourceRoot":"","sources":["../../src/models/LLMService.ts"],"names":[],"mappings":";AAAA,kCAAkC"}
@@ -0,0 +1,105 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ /**
3
+ * Categorizes the nature of the customer's interaction with the business.
4
+ *
5
+ * See LEAD_ANALYSIS_GUIDE.md for detailed definitions and examples.
6
+ *
7
+ * @remarks
8
+ * - BILLING_ISSUE: Concerns about charges, refunds, pricing discrepancies, or payments
9
+ * - CANCELLATION: Asking to cancel an appointment, service, subscription, or contract
10
+ * - COMPLAINT: Dissatisfaction with business, product, or service quality (excluding billing/scheduling)
11
+ * - COMPLIMENT: Positive feedback about the business, staff, or product
12
+ * - CONTACT_REQUEST: Request for contact without actionable details (use only for vague "call me" requests)
13
+ * - EMPLOYMENT_INQUIRY: Questions about jobs, openings, hiring, or how to apply
14
+ * - MISSED_APPOINTMENT: Reporting a no-show, missed call/visit, or confirmation confusion
15
+ * - QUESTION: General inquiry about business/services without requesting service or quote
16
+ * - QUOTE_REQUEST: Requesting a price, cost, estimate, quote, or ballpark figure
17
+ * - RESCHEDULE_REQUEST: Asking to change date/time of existing appointment or scheduled service
18
+ * - SERVICE_REQUEST: Requesting service, repair, installation, maintenance, inspection, or scheduling
19
+ * - SPAM: Unsolicited, irrelevant, deceptive, or low-value content
20
+ * - TEST: Test message, placeholder text, or internal system check
21
+ * - OTHER: Content cannot be reasonably determined
22
+ */
23
+ export type ContactType = "BILLING_ISSUE" | "CANCELLATION" | "COMPLAINT" | "COMPLIMENT" | "CONTACT_REQUEST" | "EMPLOYMENT_INQUIRY" | "MISSED_APPOINTMENT" | "QUESTION" | "QUOTE_REQUEST" | "RESCHEDULE_REQUEST" | "SERVICE_REQUEST" | "SPAM" | "TEST" | "OTHER";
24
+ /**
25
+ * Describes what kind of work the customer is requesting (high-level categorization).
26
+ *
27
+ * See LEAD_ANALYSIS_GUIDE.md for detailed definitions and examples.
28
+ *
29
+ * @remarks
30
+ * - CLEANING: Cleaning work (house, windows, ducts, carpet, gutters)
31
+ * - CONSULTATION: Requesting advice or guidance only, not execution
32
+ * - INSPECTION: Evaluation or assessment to check a condition or issue
33
+ * - INSTALLATION: New installation of a product or system
34
+ * - MAINTENANCE: Routine or recurring upkeep
35
+ * - REFINISH: Refinishing surfaces (floors, cabinets, painting, staining)
36
+ * - REMODEL: Renovating or improving an existing structure or space
37
+ * - REPAIR: Fixing an existing product or system
38
+ * - SUPPORT: Help with an issue or appointment related to service but not the work itself
39
+ * - TRANSPORT: Moving, hauling, or delivering items
40
+ * - TREATMENT: Active service to resolve or prevent an issue (pest control, mold remediation, etc.)
41
+ * - OTHER: Work that doesn't fit the above categories
42
+ */
43
+ export type ServiceType = "CLEANING" | "CONSULTATION" | "INSPECTION" | "INSTALLATION" | "MAINTENANCE" | "REFINISH" | "REMODEL" | "REPAIR" | "SUPPORT" | "TRANSPORT" | "TREATMENT" | "OTHER";
44
+ /**
45
+ * Identifies the specific trade or industry relevant to the request.
46
+ *
47
+ * See LEAD_ANALYSIS_GUIDE.md for detailed definitions and examples.
48
+ *
49
+ * @remarks
50
+ * Some categories have aliases (e.g., electrical/electrician, gutter/gutters) for flexibility.
51
+ */
52
+ export type JobType = "appliance_repair" | "blinds" | "carpentry" | "cleaning" | "construction" | "contractor" | "drywall" | "electrical" | "electrician" | "fencing" | "flooring" | "gutter" | "gutters" | "handyman" | "house_cleaning" | "hvac" | "junk_removal" | "landscaping" | "landscaper" | "legal_services" | "masonry" | "mold_remediation" | "moving" | "painting" | "painter" | "pest_control" | "plumbing" | "pressure_washing" | "remodeling" | "restoration" | "roofing" | "roofer" | "siding" | "tree_services" | "wildlife_control" | "window_cleaning" | "window_installation" | "windows_doors" | "other";
53
+ /**
54
+ * Indicates how quickly the issue should be addressed based on the nature of the problem.
55
+ *
56
+ * See LEAD_ANALYSIS_GUIDE.md for detailed definitions and examples.
57
+ *
58
+ * @remarks
59
+ * - LOW: Not time-sensitive, can be addressed at business's convenience
60
+ * - MEDIUM: Not time-sensitive, can be addressed within a couple of weeks
61
+ * - HIGH: Not life-threatening but should be addressed within a few days (may lead to property damage)
62
+ * - URGENT: Life-threatening or causing property damage, should be addressed ASAP (potentially same day)
63
+ * - NOT_SPECIFIED: Urgency could not be determined from available information
64
+ *
65
+ * Note: Urgency is determined by the nature of the issue itself, not solely by customer's stated urgency.
66
+ */
67
+ export type UrgencyType = "LOW" | "MEDIUM" | "HIGH" | "URGENT" | "NOT_SPECIFIED";
68
+ export interface LeadAnalysis {
69
+ /**
70
+ * The version of the analysis that was performed. This changes when major changes are made to the analysis process. It can be used to determine if the analysis is up to date and needs to be re-run.
71
+ */
72
+ analysisVersion?: string;
73
+ /**
74
+ * A description of the kind of message that was sent to the user.
75
+ */
76
+ contactType?: ContactType;
77
+ /**
78
+ * A description of the kind of service that the user is requesting.
79
+ */
80
+ serviceType?: ServiceType;
81
+ /**
82
+ * The type of job that the user is requesting.
83
+ */
84
+ jobType?: JobType;
85
+ /**
86
+ * The urgency of the message if it is necessary.
87
+ */
88
+ urgency?: UrgencyType;
89
+ /**
90
+ * Whether the lead is considered high value meaning it can generate significant revenue for the customer.
91
+ */
92
+ highValueLead?: boolean;
93
+ /**
94
+ * A summary of the conversation and the lead analysis.
95
+ */
96
+ summary?: string;
97
+ /**
98
+ * 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.
99
+ */
100
+ conciseSummary?: string;
101
+ /**
102
+ * An analysis of how the LLM came to its conclusion.
103
+ */
104
+ analysis?: string;
105
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=LeadAnalysis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LeadAnalysis.js","sourceRoot":"","sources":["../../src/models/LeadAnalysis.ts"],"names":[],"mappings":";AAAA,kCAAkC"}
@@ -0,0 +1,37 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ export type PromptType = "completions";
3
+ export interface Prompt {
4
+ type: PromptType;
5
+ }
6
+ export type CompletionContentMessageType = "text" | "json_object";
7
+ export interface CompletionResponseFormatText {
8
+ type: "text";
9
+ }
10
+ export interface CompletionResponseFormatJSONObject {
11
+ type: "json_object";
12
+ }
13
+ export interface CompletionResponseFormatJSONSchema {
14
+ type: "json_schema";
15
+ /**
16
+ * JSON schema for the response following the JSON schema specification
17
+ */
18
+ json_schema: object;
19
+ }
20
+ export type CompletionResponseFormat = CompletionResponseFormatText | CompletionResponseFormatJSONObject | CompletionResponseFormatJSONSchema;
21
+ export type CompletionContentMessage = string;
22
+ export interface CompletionMessage {
23
+ role: string;
24
+ content: CompletionContentMessage;
25
+ }
26
+ export interface CompletionPrompt extends Prompt {
27
+ type: "completions";
28
+ messages: CompletionMessage[];
29
+ model: string;
30
+ response_format: CompletionResponseFormat;
31
+ max_tokens: number;
32
+ temperature: number;
33
+ top_p: number;
34
+ frequency_penalty: number;
35
+ presence_penalty: number;
36
+ }
37
+ export declare function isCompletionPrompt(prompt: Prompt): prompt is CompletionPrompt;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.isCompletionPrompt = isCompletionPrompt;
5
+ function isCompletionPrompt(prompt) {
6
+ return (prompt === null || prompt === void 0 ? void 0 : prompt.type) === "completions";
7
+ }
8
+ //# sourceMappingURL=Prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Prompt.js","sourceRoot":"","sources":["../../src/models/Prompt.ts"],"names":[],"mappings":";AAAA,kCAAkC;;AA+ClC,gDAEC;AAFD,SAAgB,kBAAkB,CAAC,MAAc;IAC7C,OAAO,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,MAAK,aAAa,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,6 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ import { Prompt } from "./Prompt";
3
+ /**
4
+ * A generator that can return a prompt that is intended to be sent to an LLM Service.
5
+ */
6
+ export type PromptGenerator<PromptOptions, LLMOverrides extends object = {}, ReturnPrompt = Prompt> = (opts: PromptOptions, overrides?: LLMOverrides) => ReturnPrompt;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=PromptGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PromptGenerator.js","sourceRoot":"","sources":["../../src/models/PromptGenerator.ts"],"names":[],"mappings":";AAAA,kCAAkC"}
@@ -0,0 +1,5 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ /**
3
+ * A parser that can parse a response from a service
4
+ */
5
+ export type ResponseParser<T> = (response: string) => T;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=ResponseParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ResponseParser.js","sourceRoot":"","sources":["../../src/models/ResponseParser.ts"],"names":[],"mappings":";AAAA,kCAAkC"}
@@ -0,0 +1,48 @@
1
+ /*! Copyright (c) 2025, XAPP AI */
2
+ export type BusinessCategory = "business-coaching" | "consulting" | "contact-capture" | "financial-services" | "home-services-cleaning" | "home-services-contractors" | "home-services-outdoor" | "insurance" | "legal-services" | "life-coaching" | "radio" | "real-estate" | "technology-services" | "travel";
3
+ export interface BusinessAddress {
4
+ /**
5
+ * The full address as it was found on the website.
6
+ */
7
+ formatted?: string;
8
+ /**
9
+ * Street address, street number and street name.
10
+ */
11
+ streetAddress?: string;
12
+ /**
13
+ * The postal (zip) code
14
+ */
15
+ postalCode?: string;
16
+ /**
17
+ * City, Town or Locality. This is typically from the "city" of "city", "state"
18
+ */
19
+ locality?: string;
20
+ /**
21
+ * Typically the state.
22
+ */
23
+ region?: string;
24
+ /**
25
+ * The country
26
+ */
27
+ country?: string;
28
+ }
29
+ export interface WebsiteAnalysis {
30
+ organization_name?: string;
31
+ parked_domain?: boolean;
32
+ email?: {
33
+ email: string;
34
+ purpose?: string;
35
+ }[];
36
+ phone_numbers?: {
37
+ number: string;
38
+ purpose?: string;
39
+ }[];
40
+ addresses?: BusinessAddress[];
41
+ services?: string[];
42
+ calls_to_action?: {
43
+ url?: string;
44
+ callToAction: string;
45
+ }[];
46
+ description?: string;
47
+ industry_category?: BusinessCategory;
48
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2025, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=WebsiteAnalysis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebsiteAnalysis.js","sourceRoot":"","sources":["../../src/models/WebsiteAnalysis.ts"],"names":[],"mappings":";AAAA,kCAAkC"}
@@ -0,0 +1,28 @@
1
+ /*! Copyright (c) 2024, XAPP AI */
2
+ /**
3
+ * Error thrown when an unknown prompt type is provided to an LLM service
4
+ */
5
+ export declare class InvalidPromptTypeError extends Error {
6
+ constructor(type: string);
7
+ }
8
+ /**
9
+ * Thrown when an LLM replied but its response could not be parsed into the expected shape.
10
+ *
11
+ * Previously every response parser swallowed this and returned its default analysis, which made a
12
+ * model producing unusable output indistinguishable from a successful analysis. That defeats every
13
+ * guard downstream by construction: nothing throws, so a fallback LLM is never tried, and the
14
+ * default carries an `analysisVersion` so consumers cannot tell the difference either.
15
+ *
16
+ * The raw response is attached (truncated) because it is the only way to diagnose *why* a model's
17
+ * output stopped parsing — which is exactly what was missing when Claude Haiku began returning
18
+ * unparseable transcript analyses. Callers that log it should treat it as untrusted content.
19
+ */
20
+ export declare class LLMResponseParseError extends Error {
21
+ /** The raw model response, truncated to a loggable length. */
22
+ readonly rawResponse: string;
23
+ /** Which parser failed, e.g. "analyzeTranscript". */
24
+ readonly parser: string;
25
+ /** The underlying error, when the failure came from JSON.parse rather than validation. */
26
+ readonly cause?: unknown;
27
+ constructor(parser: string, rawResponse: string, cause?: unknown);
28
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2024, XAPP AI */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.LLMResponseParseError = exports.InvalidPromptTypeError = void 0;
5
+ /**
6
+ * Error thrown when an unknown prompt type is provided to an LLM service
7
+ */
8
+ class InvalidPromptTypeError extends Error {
9
+ constructor(type) {
10
+ super(`Unknown prompt type: ${type}`);
11
+ this.name = "InvalidPromptTypeError";
12
+ }
13
+ }
14
+ exports.InvalidPromptTypeError = InvalidPromptTypeError;
15
+ /** How much of the raw model response to retain on a parse failure. */
16
+ const RAW_RESPONSE_MAX_LENGTH = 2000;
17
+ /**
18
+ * Thrown when an LLM replied but its response could not be parsed into the expected shape.
19
+ *
20
+ * Previously every response parser swallowed this and returned its default analysis, which made a
21
+ * model producing unusable output indistinguishable from a successful analysis. That defeats every
22
+ * guard downstream by construction: nothing throws, so a fallback LLM is never tried, and the
23
+ * default carries an `analysisVersion` so consumers cannot tell the difference either.
24
+ *
25
+ * The raw response is attached (truncated) because it is the only way to diagnose *why* a model's
26
+ * output stopped parsing — which is exactly what was missing when Claude Haiku began returning
27
+ * unparseable transcript analyses. Callers that log it should treat it as untrusted content.
28
+ */
29
+ class LLMResponseParseError extends Error {
30
+ constructor(parser, rawResponse, cause) {
31
+ const reason = cause instanceof Error ? cause.message : cause ? String(cause) : "unparseable response";
32
+ super(`${parser}: could not parse the LLM response (${reason})`);
33
+ this.name = "LLMResponseParseError";
34
+ this.parser = parser;
35
+ this.rawResponse = (rawResponse || "").slice(0, RAW_RESPONSE_MAX_LENGTH);
36
+ this.cause = cause;
37
+ }
38
+ }
39
+ exports.LLMResponseParseError = LLMResponseParseError;
40
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/models/errors.ts"],"names":[],"mappings":";AAAA,kCAAkC;;;AAElC;;GAEG;AACH,MAAa,sBAAuB,SAAQ,KAAK;IAC7C,YAAY,IAAY;QACpB,KAAK,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACzC,CAAC;CACJ;AALD,wDAKC;AAED,uEAAuE;AACvE,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAErC;;;;;;;;;;;GAWG;AACH,MAAa,qBAAsB,SAAQ,KAAK;IAQ5C,YAAY,MAAc,EAAE,WAAmB,EAAE,KAAe;QAC5D,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC;QACvG,KAAK,CAAC,GAAG,MAAM,uCAAuC,MAAM,GAAG,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC;QACzE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAhBD,sDAgBC"}
@@ -0,0 +1,10 @@
1
+ /*! Copyright (c) 2026, XAPP AI */
2
+ export * from "./EmailAnalysis";
3
+ export * from "./EngagementAnalysis";
4
+ export * from "./errors";
5
+ export * from './GenerativeAIService';
6
+ export * from './LeadAnalysis';
7
+ export * from "./LLMService";
8
+ export * from "./Prompt";
9
+ export * from "./PromptGenerator";
10
+ export * from "./ResponseParser";
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ /*! Copyright (c) 2026, XAPP AI */
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./EmailAnalysis"), exports);
19
+ __exportStar(require("./EngagementAnalysis"), exports);
20
+ __exportStar(require("./errors"), exports);
21
+ __exportStar(require("./GenerativeAIService"), exports);
22
+ __exportStar(require("./LeadAnalysis"), exports);
23
+ __exportStar(require("./LLMService"), exports);
24
+ __exportStar(require("./Prompt"), exports);
25
+ __exportStar(require("./PromptGenerator"), exports);
26
+ __exportStar(require("./ResponseParser"), exports);
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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,37 @@
1
+ /*! Copyright (c) 2026, XAPP AI */
2
+ import type { CompletionPrompt, PromptGenerator, ResponseParser } from "../models";
3
+ import type { EmailAnalysisInput, EmailLeadAnalysis } from "../models/EmailAnalysis";
4
+ export declare const ANALYZE_EMAIL_VERSION = "1.1.0";
5
+ export interface AnalyzeEmailProps {
6
+ businessDescription?: string;
7
+ highValueLeadDescription?: string;
8
+ email: EmailAnalysisInput;
9
+ }
10
+ export type AnalyzeEmailLLMOverrides = Partial<Pick<CompletionPrompt, "model" | "max_tokens" | "temperature" | "top_p" | "frequency_penalty" | "presence_penalty">>;
11
+ /**
12
+ * Converts an email (with optional thread history) into the messages array for an LLM completion prompt.
13
+ *
14
+ * Thread history messages are prepended in order, with customer messages as "user" and
15
+ * agent/FSM-CRM messages as "assistant". The current email is always the final "user" message.
16
+ *
17
+ * @param system - The system instruction message.
18
+ * @param email - The email to analyze.
19
+ */
20
+ export declare function emailThreadToMessages(system: string, email: EmailAnalysisInput): {
21
+ role: "system" | "user" | "assistant";
22
+ content: string;
23
+ }[];
24
+ /**
25
+ * Generates a prompt that can be used in an LLM to analyze an inbound email for a business.
26
+ *
27
+ * Combines lead classification (contactType, serviceType, jobType, urgency) with contact
28
+ * information extraction in a single LLM call, returning an `EmailLeadAnalysis`.
29
+ *
30
+ * Handles:
31
+ * - Direct customer emails
32
+ * - FSM/CRM lead notification emails (Jobber, ServiceTitan, Housecall Pro, etc.)
33
+ * - Email threads with prior conversation history
34
+ */
35
+ export declare const generateAnalyzeEmail: PromptGenerator<AnalyzeEmailProps, AnalyzeEmailLLMOverrides, CompletionPrompt>;
36
+ export declare const defaultEmailLeadAnalysis: EmailLeadAnalysis;
37
+ export declare const analyzeEmailResponseParse: ResponseParser<EmailLeadAnalysis>;