@lssm/example.ai-support-bot 0.0.0-canary-20251217060834 → 0.0.0-canary-20251217072406
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/.turbo/turbo-build$colon$bundle.log +66 -13
- package/.turbo/turbo-build.log +65 -12
- package/CHANGELOG.md +6 -5
- package/dist/docs/ai-support-bot.docblock.js +27 -12
- package/dist/docs/index.js +1 -1
- package/dist/example.js +38 -1
- package/dist/index.js +5 -1
- package/dist/libs/contracts/dist/docs/PUBLISHING.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/accessibility_wcag_compliance_specs.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/index.js +29 -0
- package/dist/libs/contracts/dist/docs/presentations.js +71 -0
- package/dist/libs/contracts/dist/docs/registry.js +44 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_1_QUICKSTART.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_2_AI_NATIVE_OPERATIONS.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_3_AUTO_EVOLUTION.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_4_PERSONALIZATION_ENGINE.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/PHASE_5_ZERO_TOUCH_OPERATIONS.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/auth/better-auth-nextjs.docblock.js +80 -0
- package/dist/libs/contracts/dist/docs/tech/contracts/openapi-export.docblock.js +57 -0
- package/dist/libs/contracts/dist/docs/tech/lifecycle-stage-system.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/llm/llm-integration.docblock.js +357 -0
- package/dist/libs/contracts/dist/docs/tech/mcp-endpoints.docblock.js +37 -0
- package/dist/libs/contracts/dist/docs/tech/presentation-runtime.docblock.js +16 -0
- package/dist/libs/contracts/dist/docs/tech/schema/README.docblock.js +20 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-events.docblock.js +48 -0
- package/dist/libs/contracts/dist/docs/tech/studio/learning-journeys.docblock.js +79 -0
- package/dist/libs/contracts/dist/docs/tech/studio/platform-admin-panel.docblock.js +84 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-access-teams.docblock.js +45 -0
- package/dist/libs/contracts/dist/docs/tech/studio/project-routing.docblock.js +67 -0
- package/dist/libs/contracts/dist/docs/tech/studio/sandbox-unlogged.docblock.js +40 -0
- package/dist/libs/contracts/dist/docs/tech/studio/team-invitations.docblock.js +69 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspace-ops.docblock.js +47 -0
- package/dist/libs/contracts/dist/docs/tech/studio/workspaces.docblock.js +62 -0
- package/dist/libs/contracts/dist/docs/tech/telemetry-ingest.docblock.js +155 -0
- package/dist/libs/contracts/dist/docs/tech/templates/runtime.docblock.js +20 -0
- package/dist/libs/contracts/dist/docs/tech/vscode-extension.docblock.js +101 -0
- package/dist/libs/contracts/dist/docs/tech/workflows/overview.docblock.js +20 -0
- package/dist/libs/logger/dist/context.node.js +78 -0
- package/dist/libs/logger/dist/elysia-plugin.js +3 -0
- package/dist/libs/logger/dist/formatters.js +163 -0
- package/dist/libs/logger/dist/index.js +7 -0
- package/dist/libs/logger/dist/logger.node.js +189 -0
- package/dist/libs/logger/dist/timer.js +126 -0
- package/dist/libs/logger/dist/tracer.node.js +115 -0
- package/dist/libs/logger/dist/types.js +13 -0
- package/dist/libs/support-bot/dist/bot/auto-responder.js +83 -0
- package/dist/libs/support-bot/dist/bot/index.js +2 -0
- package/dist/libs/support-bot/dist/bot/tools.js +71 -0
- package/dist/libs/support-bot/dist/rag/ticket-resolver.js +63 -0
- package/dist/libs/support-bot/dist/tickets/classifier.js +198 -0
- package/dist/setup.js +47 -1
- package/package.json +8 -7
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { LogContext } from "./context.node.js";
|
|
2
|
+
import { LogLevel } from "./types.js";
|
|
3
|
+
import { TimerManager } from "./timer.js";
|
|
4
|
+
import { Tracer } from "./tracer.node.js";
|
|
5
|
+
import { DevFormatter, ProductionFormatter } from "./formatters.js";
|
|
6
|
+
|
|
7
|
+
//#region ../../libs/logger/dist/logger.node.mjs
|
|
8
|
+
var Logger = class Logger$1 {
|
|
9
|
+
config;
|
|
10
|
+
formatter;
|
|
11
|
+
context;
|
|
12
|
+
tracer;
|
|
13
|
+
timerManager;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = {
|
|
16
|
+
level: LogLevel.INFO,
|
|
17
|
+
environment: process.env.NODE_ENV || "development",
|
|
18
|
+
enableTracing: true,
|
|
19
|
+
enableTiming: true,
|
|
20
|
+
enableContext: true,
|
|
21
|
+
enableColors: true,
|
|
22
|
+
maxContextDepth: 10,
|
|
23
|
+
timestampFormat: "iso",
|
|
24
|
+
...config
|
|
25
|
+
};
|
|
26
|
+
this.context = LogContext.getInstance();
|
|
27
|
+
this.tracer = new Tracer();
|
|
28
|
+
this.timerManager = new TimerManager();
|
|
29
|
+
this.formatter = this.config.environment === "production" ? new ProductionFormatter() : new DevFormatter(this.config.enableColors);
|
|
30
|
+
}
|
|
31
|
+
traceLog(message, metadata) {
|
|
32
|
+
this.log(LogLevel.TRACE, message, metadata);
|
|
33
|
+
}
|
|
34
|
+
debug(message, metadata) {
|
|
35
|
+
this.log(LogLevel.DEBUG, message, metadata);
|
|
36
|
+
}
|
|
37
|
+
info(message, metadata) {
|
|
38
|
+
this.log(LogLevel.INFO, message, metadata);
|
|
39
|
+
}
|
|
40
|
+
warn(message, metadata) {
|
|
41
|
+
this.log(LogLevel.WARN, message, metadata);
|
|
42
|
+
}
|
|
43
|
+
error(message, metadata, error) {
|
|
44
|
+
this.log(LogLevel.ERROR, message, metadata, error);
|
|
45
|
+
}
|
|
46
|
+
fatal(message, metadata, error) {
|
|
47
|
+
this.log(LogLevel.FATAL, message, metadata, error);
|
|
48
|
+
}
|
|
49
|
+
withContext(context, fn) {
|
|
50
|
+
return this.context.run(context, fn);
|
|
51
|
+
}
|
|
52
|
+
extendContext(additionalContext, fn) {
|
|
53
|
+
return this.context.extend(additionalContext, fn);
|
|
54
|
+
}
|
|
55
|
+
setContext(key, value) {
|
|
56
|
+
this.context.set(key, value);
|
|
57
|
+
}
|
|
58
|
+
getContext() {
|
|
59
|
+
return this.context.getContext();
|
|
60
|
+
}
|
|
61
|
+
trace = async (options, fn) => {
|
|
62
|
+
if (!this.config.enableTracing) return await fn();
|
|
63
|
+
return this.tracer.trace(options, fn);
|
|
64
|
+
};
|
|
65
|
+
getTraceId() {
|
|
66
|
+
return this.tracer.getCurrentTrace()?.traceId;
|
|
67
|
+
}
|
|
68
|
+
startSpan(options) {
|
|
69
|
+
if (!this.config.enableTracing) return null;
|
|
70
|
+
return this.tracer.startSpan(options);
|
|
71
|
+
}
|
|
72
|
+
finishSpan(spanId) {
|
|
73
|
+
if (!this.config.enableTracing) return;
|
|
74
|
+
return this.tracer.finishSpan(spanId);
|
|
75
|
+
}
|
|
76
|
+
addTraceMetadata(key, value) {
|
|
77
|
+
if (this.config.enableTracing) this.tracer.addMetadata(key, value);
|
|
78
|
+
}
|
|
79
|
+
addTraceTags(...tags) {
|
|
80
|
+
if (this.config.enableTracing) this.tracer.addTags(...tags);
|
|
81
|
+
}
|
|
82
|
+
startTimer(id) {
|
|
83
|
+
if (!this.config.enableTiming) return null;
|
|
84
|
+
return this.timerManager.start(id);
|
|
85
|
+
}
|
|
86
|
+
stopTimer(id) {
|
|
87
|
+
if (!this.config.enableTiming) return;
|
|
88
|
+
return this.timerManager.stop(id);
|
|
89
|
+
}
|
|
90
|
+
getTimer(id) {
|
|
91
|
+
return this.timerManager.get(id);
|
|
92
|
+
}
|
|
93
|
+
child(context) {
|
|
94
|
+
const childLogger = new Logger$1(this.config);
|
|
95
|
+
Object.entries(context).forEach(([key, value]) => {
|
|
96
|
+
childLogger.setContext(key, value);
|
|
97
|
+
});
|
|
98
|
+
return childLogger;
|
|
99
|
+
}
|
|
100
|
+
setLevel(level) {
|
|
101
|
+
this.config.level = level;
|
|
102
|
+
}
|
|
103
|
+
setFormatter(formatter) {
|
|
104
|
+
this.formatter = formatter;
|
|
105
|
+
}
|
|
106
|
+
async profile(operationName, fn, options) {
|
|
107
|
+
const timer = this.startTimer(`profile-${operationName}`);
|
|
108
|
+
const startTime = performance.now();
|
|
109
|
+
try {
|
|
110
|
+
const result = await this.tracer.trace({
|
|
111
|
+
operationType: "custom",
|
|
112
|
+
operationName: `profile:${operationName}`,
|
|
113
|
+
autoTiming: true
|
|
114
|
+
}, fn);
|
|
115
|
+
const duration = performance.now() - startTime;
|
|
116
|
+
timer?.stop();
|
|
117
|
+
const logLevel = options?.logLevel || LogLevel.DEBUG;
|
|
118
|
+
this.log(logLevel, `Profile: ${operationName} completed`, {
|
|
119
|
+
operation: operationName,
|
|
120
|
+
duration: `${duration.toFixed(2)}ms`,
|
|
121
|
+
result: options?.logResult ? result : "[result hidden]"
|
|
122
|
+
});
|
|
123
|
+
return result;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
const duration = performance.now() - startTime;
|
|
126
|
+
timer?.stop();
|
|
127
|
+
this.error(`Profile: ${operationName} failed`, {
|
|
128
|
+
operation: operationName,
|
|
129
|
+
duration: `${duration.toFixed(2)}ms`,
|
|
130
|
+
error: error.message
|
|
131
|
+
}, error);
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
logRequest(method, url, statusCode, duration) {
|
|
136
|
+
const level = this.getHttpLogLevel(statusCode);
|
|
137
|
+
const message = `${method.toUpperCase()} ${url}${statusCode ? ` ${statusCode}` : ""}`;
|
|
138
|
+
this.log(level, message, {
|
|
139
|
+
method,
|
|
140
|
+
url,
|
|
141
|
+
statusCode,
|
|
142
|
+
duration: duration ? `${duration.toFixed(2)}ms` : void 0,
|
|
143
|
+
type: "http_request"
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
async flush() {
|
|
147
|
+
this.timerManager.clear();
|
|
148
|
+
}
|
|
149
|
+
getStats() {
|
|
150
|
+
return {
|
|
151
|
+
activeTimers: this.timerManager.getActive().length,
|
|
152
|
+
activeSpans: this.tracer.getActiveSpans().length,
|
|
153
|
+
config: { ...this.config }
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
output(message, level) {
|
|
157
|
+
if (level >= LogLevel.ERROR) console.error(message);
|
|
158
|
+
else console.log(message);
|
|
159
|
+
}
|
|
160
|
+
log(level, message, metadata, error) {
|
|
161
|
+
if (level < this.config.level) return;
|
|
162
|
+
const currentTrace = this.config.enableTracing ? this.tracer.getCurrentTrace() : void 0;
|
|
163
|
+
const contextData = this.config.enableContext ? this.context.getContext() : void 0;
|
|
164
|
+
const entry = {
|
|
165
|
+
level,
|
|
166
|
+
message,
|
|
167
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
168
|
+
traceId: currentTrace?.traceId,
|
|
169
|
+
parentId: currentTrace?.parentId,
|
|
170
|
+
spanId: currentTrace?.spanId,
|
|
171
|
+
context: contextData,
|
|
172
|
+
metadata,
|
|
173
|
+
error,
|
|
174
|
+
tags: currentTrace?.tags
|
|
175
|
+
};
|
|
176
|
+
if (currentTrace?.metadata?.duration) entry.duration = currentTrace.metadata.duration;
|
|
177
|
+
const formatted = this.formatter.format(entry);
|
|
178
|
+
this.output(formatted, level);
|
|
179
|
+
}
|
|
180
|
+
getHttpLogLevel(statusCode) {
|
|
181
|
+
if (!statusCode) return LogLevel.INFO;
|
|
182
|
+
if (statusCode >= 500) return LogLevel.ERROR;
|
|
183
|
+
if (statusCode >= 400) return LogLevel.WARN;
|
|
184
|
+
return LogLevel.INFO;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
export { Logger };
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
//#region ../../libs/logger/dist/timer.mjs
|
|
2
|
+
var Timer = class {
|
|
3
|
+
id;
|
|
4
|
+
startTime;
|
|
5
|
+
laps = [];
|
|
6
|
+
stopped = false;
|
|
7
|
+
stopTime;
|
|
8
|
+
constructor(id) {
|
|
9
|
+
this.id = id || crypto.randomUUID();
|
|
10
|
+
this.startTime = performance.now();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Stop the timer and return elapsed time in milliseconds
|
|
14
|
+
*/
|
|
15
|
+
stop() {
|
|
16
|
+
if (this.stopped) return this.getElapsed();
|
|
17
|
+
this.stopTime = performance.now();
|
|
18
|
+
this.stopped = true;
|
|
19
|
+
const elapsed = this.stopTime - this.startTime;
|
|
20
|
+
this.laps.push({
|
|
21
|
+
label: "stop",
|
|
22
|
+
time: this.stopTime,
|
|
23
|
+
elapsed
|
|
24
|
+
});
|
|
25
|
+
return elapsed;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Record a lap time and return elapsed time since start
|
|
29
|
+
*/
|
|
30
|
+
lap(label) {
|
|
31
|
+
if (this.stopped) return this.getElapsed();
|
|
32
|
+
const now = performance.now();
|
|
33
|
+
const elapsed = now - this.startTime;
|
|
34
|
+
this.laps.push({
|
|
35
|
+
label: label || `lap-${this.laps.length + 1}`,
|
|
36
|
+
time: now,
|
|
37
|
+
elapsed
|
|
38
|
+
});
|
|
39
|
+
return elapsed;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get elapsed time without stopping the timer
|
|
43
|
+
*/
|
|
44
|
+
getElapsed() {
|
|
45
|
+
if (this.stopped && this.stopTime) return this.stopTime - this.startTime;
|
|
46
|
+
return performance.now() - this.startTime;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get all recorded laps
|
|
50
|
+
*/
|
|
51
|
+
getLaps() {
|
|
52
|
+
return [...this.laps];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get timer summary with total time and laps
|
|
56
|
+
*/
|
|
57
|
+
getSummary() {
|
|
58
|
+
return {
|
|
59
|
+
id: this.id,
|
|
60
|
+
totalTime: this.getElapsed(),
|
|
61
|
+
isRunning: !this.stopped,
|
|
62
|
+
laps: this.getLaps()
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Reset the timer (starts a new timing session)
|
|
67
|
+
*/
|
|
68
|
+
reset() {
|
|
69
|
+
this.startTime = performance.now();
|
|
70
|
+
this.laps = [];
|
|
71
|
+
this.stopped = false;
|
|
72
|
+
this.stopTime = void 0;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Utility class for managing multiple timers
|
|
77
|
+
*/
|
|
78
|
+
var TimerManager = class {
|
|
79
|
+
timers = /* @__PURE__ */ new Map();
|
|
80
|
+
/**
|
|
81
|
+
* Start a new timer
|
|
82
|
+
*/
|
|
83
|
+
start(id) {
|
|
84
|
+
const timer = new Timer(id);
|
|
85
|
+
this.timers.set(timer.id, timer);
|
|
86
|
+
return timer;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get an existing timer
|
|
90
|
+
*/
|
|
91
|
+
get(id) {
|
|
92
|
+
return this.timers.get(id);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Stop and remove a timer
|
|
96
|
+
*/
|
|
97
|
+
stop(id) {
|
|
98
|
+
const timer = this.timers.get(id);
|
|
99
|
+
if (timer) {
|
|
100
|
+
const elapsed = timer.stop();
|
|
101
|
+
this.timers.delete(id);
|
|
102
|
+
return elapsed;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get all active timers
|
|
107
|
+
*/
|
|
108
|
+
getActive() {
|
|
109
|
+
return Array.from(this.timers.values()).filter((timer) => !timer.getSummary().isRunning === false);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Clear all timers
|
|
113
|
+
*/
|
|
114
|
+
clear() {
|
|
115
|
+
this.timers.clear();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Get summary of all timers
|
|
119
|
+
*/
|
|
120
|
+
getSummary() {
|
|
121
|
+
return Array.from(this.timers.values()).map((timer) => timer.getSummary());
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
//#endregion
|
|
126
|
+
export { Timer, TimerManager };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { LogContext } from "./context.node.js";
|
|
2
|
+
import { Timer } from "./timer.js";
|
|
3
|
+
|
|
4
|
+
//#region ../../libs/logger/dist/tracer.node.mjs
|
|
5
|
+
var Tracer = class {
|
|
6
|
+
context;
|
|
7
|
+
activeSpans = /* @__PURE__ */ new Map();
|
|
8
|
+
constructor() {
|
|
9
|
+
this.context = LogContext.getInstance();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Start a new trace span
|
|
13
|
+
*/
|
|
14
|
+
startSpan(options) {
|
|
15
|
+
const parentTrace = this.context.getCurrentTrace();
|
|
16
|
+
const span = {
|
|
17
|
+
traceId: parentTrace?.traceId || this.generateTraceId(),
|
|
18
|
+
parentId: parentTrace?.spanId,
|
|
19
|
+
spanId: this.generateSpanId(),
|
|
20
|
+
operationType: options.operationType,
|
|
21
|
+
operationName: options.operationName,
|
|
22
|
+
startTime: performance.now(),
|
|
23
|
+
metadata: { ...options.metadata },
|
|
24
|
+
tags: [...options.tags || []]
|
|
25
|
+
};
|
|
26
|
+
this.activeSpans.set(span.spanId, span);
|
|
27
|
+
this.context.setTrace(span);
|
|
28
|
+
return span;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Finish a trace span
|
|
32
|
+
*/
|
|
33
|
+
finishSpan(spanId) {
|
|
34
|
+
const span = this.activeSpans.get(spanId);
|
|
35
|
+
if (!span) return;
|
|
36
|
+
const duration = performance.now() - span.startTime;
|
|
37
|
+
this.activeSpans.delete(spanId);
|
|
38
|
+
if (this.context.getCurrentTrace()?.spanId === spanId && span.parentId) {
|
|
39
|
+
const parentSpan = this.findSpanById(span.parentId);
|
|
40
|
+
if (parentSpan) this.context.setTrace(parentSpan);
|
|
41
|
+
}
|
|
42
|
+
return duration;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Execute a function within a trace span
|
|
46
|
+
*/
|
|
47
|
+
async trace(options, fn) {
|
|
48
|
+
const span = this.startSpan(options);
|
|
49
|
+
const timer = options.autoTiming !== false ? new Timer(`trace-${span.spanId}`) : void 0;
|
|
50
|
+
try {
|
|
51
|
+
const result = await fn();
|
|
52
|
+
const duration = this.finishSpan(span.spanId);
|
|
53
|
+
if (timer) timer.stop();
|
|
54
|
+
if (duration !== void 0) span.metadata.duration = duration;
|
|
55
|
+
return result;
|
|
56
|
+
} catch (error) {
|
|
57
|
+
span.metadata.error = {
|
|
58
|
+
name: error.name || "Unknown",
|
|
59
|
+
message: error.message || "Unknown error",
|
|
60
|
+
stack: error.stack
|
|
61
|
+
};
|
|
62
|
+
const duration = this.finishSpan(span.spanId);
|
|
63
|
+
span.metadata.duration = duration;
|
|
64
|
+
if (timer) timer.stop();
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Add metadata to current span
|
|
70
|
+
*/
|
|
71
|
+
addMetadata(key, value) {
|
|
72
|
+
const currentTrace = this.context.getCurrentTrace();
|
|
73
|
+
if (currentTrace) currentTrace.metadata[key] = value;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Add tags to current span
|
|
77
|
+
*/
|
|
78
|
+
addTags(...tags) {
|
|
79
|
+
const currentTrace = this.context.getCurrentTrace();
|
|
80
|
+
if (currentTrace) currentTrace.tags.push(...tags);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get current trace context
|
|
84
|
+
*/
|
|
85
|
+
getCurrentTrace() {
|
|
86
|
+
return this.context.getCurrentTrace();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get all active spans
|
|
90
|
+
*/
|
|
91
|
+
getActiveSpans() {
|
|
92
|
+
return Array.from(this.activeSpans.values());
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Find a span by ID
|
|
96
|
+
*/
|
|
97
|
+
findSpanById(spanId) {
|
|
98
|
+
return this.activeSpans.get(spanId);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Generate a unique trace ID
|
|
102
|
+
*/
|
|
103
|
+
generateTraceId() {
|
|
104
|
+
return crypto.randomUUID().replace(/-/g, "");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Generate a unique span ID
|
|
108
|
+
*/
|
|
109
|
+
generateSpanId() {
|
|
110
|
+
return crypto.randomUUID().replace(/-/g, "").substring(0, 16);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
export { Tracer };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region ../../libs/logger/dist/types.mjs
|
|
2
|
+
let LogLevel = /* @__PURE__ */ function(LogLevel$1) {
|
|
3
|
+
LogLevel$1[LogLevel$1["TRACE"] = 0] = "TRACE";
|
|
4
|
+
LogLevel$1[LogLevel$1["DEBUG"] = 1] = "DEBUG";
|
|
5
|
+
LogLevel$1[LogLevel$1["INFO"] = 2] = "INFO";
|
|
6
|
+
LogLevel$1[LogLevel$1["WARN"] = 3] = "WARN";
|
|
7
|
+
LogLevel$1[LogLevel$1["ERROR"] = 4] = "ERROR";
|
|
8
|
+
LogLevel$1[LogLevel$1["FATAL"] = 5] = "FATAL";
|
|
9
|
+
return LogLevel$1;
|
|
10
|
+
}({});
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { LogLevel };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
//#region ../../libs/support-bot/dist/bot/auto-responder.js
|
|
2
|
+
var AutoResponder = class {
|
|
3
|
+
llm;
|
|
4
|
+
model;
|
|
5
|
+
tone;
|
|
6
|
+
closing;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.llm = options?.llm;
|
|
9
|
+
this.model = options?.model;
|
|
10
|
+
this.tone = options?.tone ?? "friendly";
|
|
11
|
+
this.closing = options?.closing ?? (this.tone === "friendly" ? "We remain available if you need anything else." : "Please let us know if you require additional assistance.");
|
|
12
|
+
}
|
|
13
|
+
async draft(ticket, resolution, classification) {
|
|
14
|
+
if (this.llm) return this.generateWithLLM(ticket, resolution, classification);
|
|
15
|
+
return this.generateTemplate(ticket, resolution, classification);
|
|
16
|
+
}
|
|
17
|
+
async generateWithLLM(ticket, resolution, classification) {
|
|
18
|
+
const prompt = `You are a ${this.tone} support agent. Draft an email response.
|
|
19
|
+
Ticket Subject: ${ticket.subject}
|
|
20
|
+
Ticket Body: ${ticket.body}
|
|
21
|
+
Detected Category: ${classification.category}
|
|
22
|
+
Detected Priority: ${classification.priority}
|
|
23
|
+
Resolution:
|
|
24
|
+
${resolution.answer}
|
|
25
|
+
Citations: ${resolution.citations.map((c) => c.label).join(", ")}`;
|
|
26
|
+
const body = (await this.llm.chat([{
|
|
27
|
+
role: "system",
|
|
28
|
+
content: [{
|
|
29
|
+
type: "text",
|
|
30
|
+
text: "Write empathetic, accurate support replies that cite sources when relevant."
|
|
31
|
+
}]
|
|
32
|
+
}, {
|
|
33
|
+
role: "user",
|
|
34
|
+
content: [{
|
|
35
|
+
type: "text",
|
|
36
|
+
text: prompt
|
|
37
|
+
}]
|
|
38
|
+
}], { model: this.model })).message.content.map((part) => "text" in part ? part.text : "").join("").trim();
|
|
39
|
+
return this.buildDraft(ticket, resolution, classification, body);
|
|
40
|
+
}
|
|
41
|
+
generateTemplate(ticket, resolution, classification) {
|
|
42
|
+
const body = `${ticket.customerName ? `Hi ${ticket.customerName},` : "Hi there,"}
|
|
43
|
+
|
|
44
|
+
Thanks for contacting us about "${ticket.subject}". ${this.renderCategoryIntro(classification)}
|
|
45
|
+
|
|
46
|
+
${resolution.answer}
|
|
47
|
+
|
|
48
|
+
${this.renderCitations(resolution)}
|
|
49
|
+
${this.closing}
|
|
50
|
+
|
|
51
|
+
— ContractSpec Support`;
|
|
52
|
+
return this.buildDraft(ticket, resolution, classification, body);
|
|
53
|
+
}
|
|
54
|
+
buildDraft(ticket, resolution, classification, body) {
|
|
55
|
+
return {
|
|
56
|
+
ticketId: ticket.id,
|
|
57
|
+
subject: ticket.subject.startsWith("Re:") ? ticket.subject : `Re: ${ticket.subject}`,
|
|
58
|
+
body,
|
|
59
|
+
confidence: Math.min(resolution.confidence, classification.confidence),
|
|
60
|
+
requiresEscalation: resolution.actions.some((action) => action.type === "escalate") || Boolean(classification.escalationRequired),
|
|
61
|
+
citations: resolution.citations
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
renderCategoryIntro(classification) {
|
|
65
|
+
switch (classification.category) {
|
|
66
|
+
case "billing": return "I understand billing issues can be stressful, so let me clarify the situation.";
|
|
67
|
+
case "technical": return "I see you encountered a technical issue. Here is what happened and how to fix it.";
|
|
68
|
+
case "product": return "Thanks for sharing feedback about the product. Here are the next steps.";
|
|
69
|
+
case "account": return "Account access is critical, so let me walk you through the resolution.";
|
|
70
|
+
case "compliance": return "Compliance questions require precision. See the policy-aligned answer below.";
|
|
71
|
+
default: return "Here is what we found after reviewing your request.";
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
renderCitations(resolution) {
|
|
75
|
+
if (!resolution.citations.length) return "";
|
|
76
|
+
return `References:\n${resolution.citations.map((citation, index) => {
|
|
77
|
+
return `- ${citation.label || `Source ${index + 1}`}${citation.url ? ` (${citation.url})` : ""}`;
|
|
78
|
+
}).join("\n")}`;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
//#endregion
|
|
83
|
+
export { AutoResponder };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
|
|
3
|
+
//#region ../../libs/support-bot/dist/bot/tools.js
|
|
4
|
+
const ticketSchema = z.object({
|
|
5
|
+
id: z.string(),
|
|
6
|
+
subject: z.string(),
|
|
7
|
+
body: z.string(),
|
|
8
|
+
channel: z.enum([
|
|
9
|
+
"email",
|
|
10
|
+
"chat",
|
|
11
|
+
"phone",
|
|
12
|
+
"portal"
|
|
13
|
+
]),
|
|
14
|
+
customerName: z.string().optional(),
|
|
15
|
+
customerEmail: z.string().optional(),
|
|
16
|
+
metadata: z.object().optional()
|
|
17
|
+
});
|
|
18
|
+
const supportCitationSchema = z.object({
|
|
19
|
+
label: z.string(),
|
|
20
|
+
url: z.string().optional(),
|
|
21
|
+
snippet: z.string().optional(),
|
|
22
|
+
score: z.number().optional()
|
|
23
|
+
});
|
|
24
|
+
const supportActionSchema = z.object({
|
|
25
|
+
type: z.enum([
|
|
26
|
+
"respond",
|
|
27
|
+
"escalate",
|
|
28
|
+
"refund",
|
|
29
|
+
"manual"
|
|
30
|
+
]),
|
|
31
|
+
label: z.string(),
|
|
32
|
+
payload: z.record(z.string(), z.string())
|
|
33
|
+
});
|
|
34
|
+
const supportResolutionSchema = z.object({
|
|
35
|
+
ticketId: z.string(),
|
|
36
|
+
answer: z.string(),
|
|
37
|
+
confidence: z.number(),
|
|
38
|
+
citations: supportCitationSchema.array(),
|
|
39
|
+
actions: supportActionSchema.array(),
|
|
40
|
+
escalationReason: z.string().optional(),
|
|
41
|
+
knowledgeUpdates: z.array(z.string()).optional()
|
|
42
|
+
});
|
|
43
|
+
const ticketClassificationSchema = z.object({
|
|
44
|
+
ticketId: z.string(),
|
|
45
|
+
category: z.enum([
|
|
46
|
+
"billing",
|
|
47
|
+
"technical",
|
|
48
|
+
"product",
|
|
49
|
+
"account",
|
|
50
|
+
"compliance",
|
|
51
|
+
"other"
|
|
52
|
+
]),
|
|
53
|
+
priority: z.enum([
|
|
54
|
+
"urgent",
|
|
55
|
+
"high",
|
|
56
|
+
"medium",
|
|
57
|
+
"low"
|
|
58
|
+
]),
|
|
59
|
+
sentiment: z.enum([
|
|
60
|
+
"positive",
|
|
61
|
+
"neutral",
|
|
62
|
+
"negative",
|
|
63
|
+
"frustrated"
|
|
64
|
+
]),
|
|
65
|
+
intents: z.array(z.string()),
|
|
66
|
+
tags: z.array(z.string()),
|
|
67
|
+
confidence: z.number(),
|
|
68
|
+
escalationRequired: z.boolean().optional()
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//#region ../../libs/support-bot/dist/rag/ticket-resolver.js
|
|
2
|
+
var TicketResolver = class {
|
|
3
|
+
knowledge;
|
|
4
|
+
minConfidence;
|
|
5
|
+
prependPrompt;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
this.knowledge = options.knowledge;
|
|
8
|
+
this.minConfidence = options.minConfidence ?? .65;
|
|
9
|
+
this.prependPrompt = options.prependPrompt;
|
|
10
|
+
}
|
|
11
|
+
async resolve(ticket) {
|
|
12
|
+
const question = this.buildQuestion(ticket);
|
|
13
|
+
const answer = await this.knowledge.query(question);
|
|
14
|
+
return this.toResolution(ticket, answer);
|
|
15
|
+
}
|
|
16
|
+
buildQuestion(ticket) {
|
|
17
|
+
const header = [`Subject: ${ticket.subject}`, `Channel: ${ticket.channel}`];
|
|
18
|
+
if (ticket.customerName) header.push(`Customer: ${ticket.customerName}`);
|
|
19
|
+
return [
|
|
20
|
+
this.prependPrompt,
|
|
21
|
+
header.join("\n"),
|
|
22
|
+
"---",
|
|
23
|
+
ticket.body
|
|
24
|
+
].filter(Boolean).join("\n");
|
|
25
|
+
}
|
|
26
|
+
toResolution(ticket, answer) {
|
|
27
|
+
const citations = answer.references.map((ref) => {
|
|
28
|
+
return {
|
|
29
|
+
label: typeof ref.payload?.title === "string" ? ref.payload.title : typeof ref.payload?.documentId === "string" ? ref.payload.documentId : ref.id,
|
|
30
|
+
url: typeof ref.payload?.url === "string" ? ref.payload.url : void 0,
|
|
31
|
+
snippet: typeof ref.payload?.text === "string" ? ref.payload.text.slice(0, 280) : void 0,
|
|
32
|
+
score: ref.score
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
const confidence = this.deriveConfidence(answer);
|
|
36
|
+
const escalate = confidence < this.minConfidence || citations.length === 0;
|
|
37
|
+
return {
|
|
38
|
+
ticketId: ticket.id,
|
|
39
|
+
answer: answer.answer,
|
|
40
|
+
confidence,
|
|
41
|
+
citations,
|
|
42
|
+
actions: [escalate ? {
|
|
43
|
+
type: "escalate",
|
|
44
|
+
label: "Escalate for human review"
|
|
45
|
+
} : {
|
|
46
|
+
type: "respond",
|
|
47
|
+
label: "Send automated response"
|
|
48
|
+
}],
|
|
49
|
+
escalationReason: escalate ? "Insufficient confidence or missing knowledge references" : void 0,
|
|
50
|
+
knowledgeUpdates: escalate ? [ticket.body.slice(0, 200)] : void 0
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
deriveConfidence(answer) {
|
|
54
|
+
if (!answer.references.length) return .3;
|
|
55
|
+
const topScore = answer.references[0]?.score ?? .4;
|
|
56
|
+
const normalized = Math.min(1, Math.max(0, topScore));
|
|
57
|
+
const tokenPenalty = answer.usage?.completionTokens ? Math.min(answer.usage.completionTokens / 1e3, .2) : 0;
|
|
58
|
+
return Number((normalized - tokenPenalty).toFixed(2));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { TicketResolver };
|