@contractspec/lib.support-bot 3.7.17 → 3.7.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bot/auto-responder.js +10 -732
- package/dist/bot/feedback-loop.js +5 -667
- package/dist/bot/index.js +11 -900
- package/dist/bot/tools.js +1 -131
- package/dist/browser/bot/auto-responder.js +10 -732
- package/dist/browser/bot/feedback-loop.js +5 -667
- package/dist/browser/bot/index.js +11 -900
- package/dist/browser/bot/tools.js +1 -131
- package/dist/browser/i18n/catalogs/en.js +2 -184
- package/dist/browser/i18n/catalogs/es.js +2 -184
- package/dist/browser/i18n/catalogs/fr.js +2 -184
- package/dist/browser/i18n/catalogs/index.js +4 -550
- package/dist/browser/i18n/index.js +4 -649
- package/dist/browser/i18n/keys.js +1 -71
- package/dist/browser/i18n/locale.js +1 -13
- package/dist/browser/i18n/messages.js +4 -564
- package/dist/browser/index.js +15 -1316
- package/dist/browser/rag/index.js +6 -701
- package/dist/browser/rag/ticket-resolver.js +6 -701
- package/dist/browser/spec.js +2 -32
- package/dist/browser/tickets/classifier.js +5 -944
- package/dist/browser/tickets/index.js +5 -944
- package/dist/i18n/catalogs/en.js +2 -184
- package/dist/i18n/catalogs/es.js +2 -184
- package/dist/i18n/catalogs/fr.js +2 -184
- package/dist/i18n/catalogs/index.js +4 -550
- package/dist/i18n/index.js +4 -649
- package/dist/i18n/keys.js +1 -71
- package/dist/i18n/locale.js +1 -13
- package/dist/i18n/messages.js +4 -564
- package/dist/index.js +15 -1316
- package/dist/node/bot/auto-responder.js +10 -732
- package/dist/node/bot/feedback-loop.js +5 -667
- package/dist/node/bot/index.js +11 -900
- package/dist/node/bot/tools.js +1 -131
- package/dist/node/i18n/catalogs/en.js +2 -184
- package/dist/node/i18n/catalogs/es.js +2 -184
- package/dist/node/i18n/catalogs/fr.js +2 -184
- package/dist/node/i18n/catalogs/index.js +4 -550
- package/dist/node/i18n/index.js +4 -649
- package/dist/node/i18n/keys.js +1 -71
- package/dist/node/i18n/locale.js +1 -13
- package/dist/node/i18n/messages.js +4 -564
- package/dist/node/index.js +15 -1316
- package/dist/node/rag/index.js +6 -701
- package/dist/node/rag/ticket-resolver.js +6 -701
- package/dist/node/spec.js +2 -32
- package/dist/node/tickets/classifier.js +5 -944
- package/dist/node/tickets/index.js +5 -944
- package/dist/rag/index.js +6 -701
- package/dist/rag/ticket-resolver.js +6 -701
- package/dist/spec.js +2 -32
- package/dist/tickets/classifier.js +5 -944
- package/dist/tickets/index.js +5 -944
- package/package.json +8 -8
package/dist/bot/tools.js
CHANGED
|
@@ -1,132 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
|
|
3
|
-
import * as z from "zod";
|
|
4
|
-
var ticketSchema = z.object({
|
|
5
|
-
id: z.string(),
|
|
6
|
-
subject: z.string(),
|
|
7
|
-
body: z.string(),
|
|
8
|
-
channel: z.enum(["email", "chat", "phone", "portal"]),
|
|
9
|
-
customerName: z.string().optional(),
|
|
10
|
-
customerEmail: z.string().optional(),
|
|
11
|
-
metadata: z.object().optional()
|
|
12
|
-
});
|
|
13
|
-
var supportCitationSchema = z.object({
|
|
14
|
-
label: z.string(),
|
|
15
|
-
url: z.string().optional(),
|
|
16
|
-
snippet: z.string().optional(),
|
|
17
|
-
score: z.number().optional()
|
|
18
|
-
});
|
|
19
|
-
var supportActionSchema = z.object({
|
|
20
|
-
type: z.enum(["respond", "escalate", "refund", "manual"]),
|
|
21
|
-
label: z.string(),
|
|
22
|
-
payload: z.record(z.string(), z.string())
|
|
23
|
-
});
|
|
24
|
-
var supportResolutionSchema = z.object({
|
|
25
|
-
ticketId: z.string(),
|
|
26
|
-
answer: z.string(),
|
|
27
|
-
confidence: z.number(),
|
|
28
|
-
citations: supportCitationSchema.array(),
|
|
29
|
-
actions: supportActionSchema.array(),
|
|
30
|
-
escalationReason: z.string().optional(),
|
|
31
|
-
knowledgeUpdates: z.array(z.string()).optional()
|
|
32
|
-
});
|
|
33
|
-
var ticketClassificationSchema = z.object({
|
|
34
|
-
ticketId: z.string(),
|
|
35
|
-
category: z.enum([
|
|
36
|
-
"billing",
|
|
37
|
-
"technical",
|
|
38
|
-
"product",
|
|
39
|
-
"account",
|
|
40
|
-
"compliance",
|
|
41
|
-
"other"
|
|
42
|
-
]),
|
|
43
|
-
priority: z.enum([
|
|
44
|
-
"urgent",
|
|
45
|
-
"high",
|
|
46
|
-
"medium",
|
|
47
|
-
"low"
|
|
48
|
-
]),
|
|
49
|
-
sentiment: z.enum([
|
|
50
|
-
"positive",
|
|
51
|
-
"neutral",
|
|
52
|
-
"negative",
|
|
53
|
-
"frustrated"
|
|
54
|
-
]),
|
|
55
|
-
intents: z.array(z.string()),
|
|
56
|
-
tags: z.array(z.string()),
|
|
57
|
-
confidence: z.number(),
|
|
58
|
-
escalationRequired: z.boolean().optional()
|
|
59
|
-
});
|
|
60
|
-
function ensureTicket(input) {
|
|
61
|
-
if (!input || typeof input !== "object" || !("ticket" in input)) {
|
|
62
|
-
throw new Error("Input must include ticket");
|
|
63
|
-
}
|
|
64
|
-
const ticket = input.ticket;
|
|
65
|
-
if (!ticket?.id)
|
|
66
|
-
throw new Error("Ticket is missing id");
|
|
67
|
-
return ticket;
|
|
68
|
-
}
|
|
69
|
-
function extractResolution(input) {
|
|
70
|
-
if (!input || typeof input !== "object" || !("resolution" in input))
|
|
71
|
-
return;
|
|
72
|
-
return input.resolution;
|
|
73
|
-
}
|
|
74
|
-
function extractClassification(input) {
|
|
75
|
-
if (!input || typeof input !== "object" || !("classification" in input))
|
|
76
|
-
return;
|
|
77
|
-
return input.classification;
|
|
78
|
-
}
|
|
79
|
-
function createSupportTools(options) {
|
|
80
|
-
const classifyTool = {
|
|
81
|
-
title: "support_classify_ticket",
|
|
82
|
-
description: "Classify a ticket for priority, sentiment, and category",
|
|
83
|
-
inputSchema: z.object({ ticket: ticketSchema }),
|
|
84
|
-
execute: async (input) => {
|
|
85
|
-
const ticket = ensureTicket(input);
|
|
86
|
-
const classification = await options.classifier.classify(ticket);
|
|
87
|
-
return {
|
|
88
|
-
content: JSON.stringify(classification),
|
|
89
|
-
metadata: { ticketId: ticket.id }
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
const resolveTool = {
|
|
94
|
-
title: "support_resolve_ticket",
|
|
95
|
-
description: "Generate a knowledge-grounded resolution for a ticket",
|
|
96
|
-
inputSchema: z.object({ ticket: ticketSchema }),
|
|
97
|
-
execute: async (input) => {
|
|
98
|
-
const ticket = ensureTicket(input);
|
|
99
|
-
const resolution = await options.resolver.resolve(ticket);
|
|
100
|
-
return {
|
|
101
|
-
content: JSON.stringify(resolution),
|
|
102
|
-
metadata: { ticketId: ticket.id }
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
const responderTool = {
|
|
107
|
-
title: "support_draft_response",
|
|
108
|
-
description: "Draft a user-facing reply based on resolution + classification",
|
|
109
|
-
inputSchema: z.object({
|
|
110
|
-
ticket: ticketSchema,
|
|
111
|
-
resolution: supportResolutionSchema,
|
|
112
|
-
classification: ticketClassificationSchema
|
|
113
|
-
}),
|
|
114
|
-
execute: async (input) => {
|
|
115
|
-
const ticket = ensureTicket(input);
|
|
116
|
-
const resolution = extractResolution(input);
|
|
117
|
-
const classification = extractClassification(input);
|
|
118
|
-
if (!resolution || !classification) {
|
|
119
|
-
throw new Error("resolution and classification are required");
|
|
120
|
-
}
|
|
121
|
-
const draft = await options.responder.draft(ticket, resolution, classification);
|
|
122
|
-
return {
|
|
123
|
-
content: JSON.stringify(draft),
|
|
124
|
-
metadata: { ticketId: ticket.id }
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
return [classifyTool, resolveTool, responderTool];
|
|
129
|
-
}
|
|
130
|
-
export {
|
|
131
|
-
createSupportTools
|
|
132
|
-
};
|
|
2
|
+
import*as t from"zod";var r=t.object({id:t.string(),subject:t.string(),body:t.string(),channel:t.enum(["email","chat","phone","portal"]),customerName:t.string().optional(),customerEmail:t.string().optional(),metadata:t.object().optional()}),f=t.object({label:t.string(),url:t.string().optional(),snippet:t.string().optional(),score:t.number().optional()}),d=t.object({type:t.enum(["respond","escalate","refund","manual"]),label:t.string(),payload:t.record(t.string(),t.string())}),k=t.object({ticketId:t.string(),answer:t.string(),confidence:t.number(),citations:f.array(),actions:d.array(),escalationReason:t.string().optional(),knowledgeUpdates:t.array(t.string()).optional()}),z=t.object({ticketId:t.string(),category:t.enum(["billing","technical","product","account","compliance","other"]),priority:t.enum(["urgent","high","medium","low"]),sentiment:t.enum(["positive","neutral","negative","frustrated"]),intents:t.array(t.string()),tags:t.array(t.string()),confidence:t.number(),escalationRequired:t.boolean().optional()});function c(e){if(!e||typeof e!=="object"||!("ticket"in e))throw Error("Input must include ticket");let s=e.ticket;if(!s?.id)throw Error("Ticket is missing id");return s}function m(e){if(!e||typeof e!=="object"||!("resolution"in e))return;return e.resolution}function y(e){if(!e||typeof e!=="object"||!("classification"in e))return;return e.classification}function T(e){let s={title:"support_classify_ticket",description:"Classify a ticket for priority, sentiment, and category",inputSchema:t.object({ticket:r}),execute:async(o)=>{let i=c(o),n=await e.classifier.classify(i);return{content:JSON.stringify(n),metadata:{ticketId:i.id}}}},l={title:"support_resolve_ticket",description:"Generate a knowledge-grounded resolution for a ticket",inputSchema:t.object({ticket:r}),execute:async(o)=>{let i=c(o),n=await e.resolver.resolve(i);return{content:JSON.stringify(n),metadata:{ticketId:i.id}}}},p={title:"support_draft_response",description:"Draft a user-facing reply based on resolution + classification",inputSchema:t.object({ticket:r,resolution:k,classification:z}),execute:async(o)=>{let i=c(o),n=m(o),a=y(o);if(!n||!a)throw Error("resolution and classification are required");let u=await e.responder.draft(i,n,a);return{content:JSON.stringify(u),metadata:{ticketId:i.id}}}};return[s,l,p]}export{T as createSupportTools};
|