@aichatwar/shared 1.0.144 → 1.0.146
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/build/events/agentChatEvents.d.ts +45 -0
- package/build/events/arEvents.d.ts +1 -45
- package/build/events/arEvents.js +2 -0
- package/build/events/subjects.d.ts +8 -16
- package/build/events/subjects.js +11 -18
- package/build/index.d.ts +4 -4
- package/build/index.js +7 -4
- package/build/middlewares/error-handler.js +11 -1
- package/build/observability/correlation.d.ts +6 -0
- package/build/observability/correlation.js +33 -0
- package/build/observability/express.d.ts +3 -0
- package/build/observability/express.js +39 -0
- package/build/observability/logger.d.ts +2 -0
- package/build/observability/logger.js +49 -0
- package/package.json +3 -2
- package/build/events/ecommerceEvents.d.ts +0 -63
- package/build/events/feedbackEvents.d.ts +0 -110
- package/build/events/feedbackEvents.js +0 -2
- package/build/events/recommendationEvents.d.ts +0 -76
- package/build/events/recommendationEvents.js +0 -2
- package/build/events/types/orderStatus.d.ts +0 -7
- package/build/events/types/orderStatus.js +0 -12
- /package/build/events/{ecommerceEvents.js → agentChatEvents.js} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Subjects } from './subjects';
|
|
2
|
+
export interface AgentChatMessageRequestEvent {
|
|
3
|
+
subject: Subjects.AgentChatMessageRequest;
|
|
4
|
+
data: {
|
|
5
|
+
messageId: string;
|
|
6
|
+
roomId: string;
|
|
7
|
+
agentId: string;
|
|
8
|
+
userId: string;
|
|
9
|
+
content: string;
|
|
10
|
+
timestamp: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export interface AgentChatStreamStartEvent {
|
|
14
|
+
subject: Subjects.AgentChatStreamStart;
|
|
15
|
+
data: {
|
|
16
|
+
streamId: string;
|
|
17
|
+
messageId: string;
|
|
18
|
+
roomId: string;
|
|
19
|
+
agentId: string;
|
|
20
|
+
userId: string;
|
|
21
|
+
startedAt: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export interface AgentChatStreamChunkEvent {
|
|
25
|
+
subject: Subjects.AgentChatStreamChunk;
|
|
26
|
+
data: {
|
|
27
|
+
streamId: string;
|
|
28
|
+
messageId: string;
|
|
29
|
+
roomId: string;
|
|
30
|
+
chunk: string;
|
|
31
|
+
chunkIndex: number;
|
|
32
|
+
timestamp: string;
|
|
33
|
+
isFinal: boolean;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export interface AgentChatStreamEndEvent {
|
|
37
|
+
subject: Subjects.AgentChatStreamEnd;
|
|
38
|
+
data: {
|
|
39
|
+
streamId: string;
|
|
40
|
+
messageId: string;
|
|
41
|
+
roomId: string;
|
|
42
|
+
totalChunks: number;
|
|
43
|
+
endedAt: string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -1,45 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export interface ARMessageRequestEvent {
|
|
3
|
-
subject: Subjects.ARMessageRequest;
|
|
4
|
-
data: {
|
|
5
|
-
messageId: string;
|
|
6
|
-
roomId: string;
|
|
7
|
-
agentId: string;
|
|
8
|
-
userId: string;
|
|
9
|
-
content: string;
|
|
10
|
-
timestamp: string;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
export interface ARStreamStartEvent {
|
|
14
|
-
subject: Subjects.ARStreamStart;
|
|
15
|
-
data: {
|
|
16
|
-
streamId: string;
|
|
17
|
-
messageId: string;
|
|
18
|
-
roomId: string;
|
|
19
|
-
agentId: string;
|
|
20
|
-
userId: string;
|
|
21
|
-
startedAt: string;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export interface ARStreamChunkEvent {
|
|
25
|
-
subject: Subjects.ARStreamChunk;
|
|
26
|
-
data: {
|
|
27
|
-
streamId: string;
|
|
28
|
-
messageId: string;
|
|
29
|
-
roomId: string;
|
|
30
|
-
chunk: string;
|
|
31
|
-
chunkIndex: number;
|
|
32
|
-
timestamp: string;
|
|
33
|
-
isFinal: boolean;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
export interface ARStreamEndEvent {
|
|
37
|
-
subject: Subjects.ARStreamEnd;
|
|
38
|
-
data: {
|
|
39
|
-
streamId: string;
|
|
40
|
-
messageId: string;
|
|
41
|
-
roomId: string;
|
|
42
|
-
totalChunks: number;
|
|
43
|
-
endedAt: string;
|
|
44
|
-
};
|
|
45
|
-
}
|
|
1
|
+
export type { AgentChatMessageRequestEvent as ARMessageRequestEvent, AgentChatStreamStartEvent as ARStreamStartEvent, AgentChatStreamChunkEvent as ARStreamChunkEvent, AgentChatStreamEndEvent as ARStreamEndEvent, } from './agentChatEvents';
|
package/build/events/arEvents.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
export declare enum Subjects {
|
|
2
|
-
EcommerceModelCreated = "ecommerce-model.created",
|
|
3
|
-
EcommerceModelUpdated = "ecommerce-model.updated",
|
|
4
|
-
EcommerceOrderCreated = "ecommerce-oreder.created",
|
|
5
|
-
EcommerceOrderCancelled = "ecommerce-order.cancelled",
|
|
6
|
-
EcommerceOrderExpired = "ecommerce-order.expired",
|
|
7
2
|
FriendshipRequested = "friendship.requested",
|
|
8
3
|
FriendshipAccepted = "friendship.accepted",
|
|
9
4
|
FriendshipUpdated = "friendship.updated",
|
|
@@ -50,11 +45,6 @@ export declare enum Subjects {
|
|
|
50
45
|
MediaDeleted = "media.deleted",
|
|
51
46
|
ReactionCreated = "reaction.created",
|
|
52
47
|
ReactionDeleted = "reaction.deleted",
|
|
53
|
-
FeedbackReplyReceived = "feedback.reply.received",
|
|
54
|
-
FeedbackReactionReceived = "feedback.reaction.received",
|
|
55
|
-
AgentLearningUpdated = "agent.learning.updated",
|
|
56
|
-
TrainingDatasetReady = "training.dataset.ready",
|
|
57
|
-
ModelUpdated = "model.updated",
|
|
58
48
|
SessionEnded = "session.ended",
|
|
59
49
|
RoomAgentInvited = "room.agent.invited",
|
|
60
50
|
AgentInviteRequested = "agent.invite.requested",
|
|
@@ -91,10 +81,12 @@ export declare enum Subjects {
|
|
|
91
81
|
AgentDraftCommentCreated = "agent.draft.comment.created",
|
|
92
82
|
AgentDraftReactionCreated = "agent.draft.reaction.created",
|
|
93
83
|
AgentDraftConnectionRequestCreated = "agent.draft.connection.request.created",
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
84
|
+
AgentChatMessageRequest = "agent-chat.message.request",
|
|
85
|
+
AgentChatStreamStart = "agent-chat.stream.start",
|
|
86
|
+
AgentChatStreamChunk = "agent-chat.stream.chunk",
|
|
87
|
+
AgentChatStreamEnd = "agent-chat.stream.end",
|
|
88
|
+
ARMessageRequest = "agent-chat.message.request",
|
|
89
|
+
ARStreamStart = "agent-chat.stream.start",
|
|
90
|
+
ARStreamChunk = "agent-chat.stream.chunk",
|
|
91
|
+
ARStreamEnd = "agent-chat.stream.end"
|
|
100
92
|
}
|
package/build/events/subjects.js
CHANGED
|
@@ -3,11 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Subjects = void 0;
|
|
4
4
|
var Subjects;
|
|
5
5
|
(function (Subjects) {
|
|
6
|
-
Subjects["EcommerceModelCreated"] = "ecommerce-model.created";
|
|
7
|
-
Subjects["EcommerceModelUpdated"] = "ecommerce-model.updated";
|
|
8
|
-
Subjects["EcommerceOrderCreated"] = "ecommerce-oreder.created";
|
|
9
|
-
Subjects["EcommerceOrderCancelled"] = "ecommerce-order.cancelled";
|
|
10
|
-
Subjects["EcommerceOrderExpired"] = "ecommerce-order.expired";
|
|
11
6
|
Subjects["FriendshipRequested"] = "friendship.requested";
|
|
12
7
|
Subjects["FriendshipAccepted"] = "friendship.accepted";
|
|
13
8
|
Subjects["FriendshipUpdated"] = "friendship.updated";
|
|
@@ -54,11 +49,6 @@ var Subjects;
|
|
|
54
49
|
Subjects["MediaDeleted"] = "media.deleted";
|
|
55
50
|
Subjects["ReactionCreated"] = "reaction.created";
|
|
56
51
|
Subjects["ReactionDeleted"] = "reaction.deleted";
|
|
57
|
-
Subjects["FeedbackReplyReceived"] = "feedback.reply.received";
|
|
58
|
-
Subjects["FeedbackReactionReceived"] = "feedback.reaction.received";
|
|
59
|
-
Subjects["AgentLearningUpdated"] = "agent.learning.updated";
|
|
60
|
-
Subjects["TrainingDatasetReady"] = "training.dataset.ready";
|
|
61
|
-
Subjects["ModelUpdated"] = "model.updated";
|
|
62
52
|
Subjects["SessionEnded"] = "session.ended";
|
|
63
53
|
// Agent Manager Events
|
|
64
54
|
Subjects["RoomAgentInvited"] = "room.agent.invited";
|
|
@@ -98,12 +88,15 @@ var Subjects;
|
|
|
98
88
|
Subjects["AgentDraftCommentCreated"] = "agent.draft.comment.created";
|
|
99
89
|
Subjects["AgentDraftReactionCreated"] = "agent.draft.reaction.created";
|
|
100
90
|
Subjects["AgentDraftConnectionRequestCreated"] = "agent.draft.connection.request.created";
|
|
101
|
-
//
|
|
102
|
-
Subjects["
|
|
103
|
-
Subjects["
|
|
104
|
-
|
|
105
|
-
Subjects["
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
Subjects["
|
|
91
|
+
// Agent Chat Events (renamed from AR chat)
|
|
92
|
+
Subjects["AgentChatMessageRequest"] = "agent-chat.message.request";
|
|
93
|
+
Subjects["AgentChatStreamStart"] = "agent-chat.stream.start";
|
|
94
|
+
Subjects["AgentChatStreamChunk"] = "agent-chat.stream.chunk";
|
|
95
|
+
Subjects["AgentChatStreamEnd"] = "agent-chat.stream.end";
|
|
96
|
+
// Backwards-compatible AR names (deprecated)
|
|
97
|
+
// NOTE: Values intentionally match the new agent-chat.* topics.
|
|
98
|
+
Subjects["ARMessageRequest"] = "agent-chat.message.request";
|
|
99
|
+
Subjects["ARStreamStart"] = "agent-chat.stream.start";
|
|
100
|
+
Subjects["ARStreamChunk"] = "agent-chat.stream.chunk";
|
|
101
|
+
Subjects["ARStreamEnd"] = "agent-chat.stream.end";
|
|
109
102
|
})(Subjects || (exports.Subjects = Subjects = {}));
|
package/build/index.d.ts
CHANGED
|
@@ -8,12 +8,14 @@ export * from "./middlewares/error-handler";
|
|
|
8
8
|
export * from "./middlewares/jwt-extractor";
|
|
9
9
|
export * from "./middlewares/login-required";
|
|
10
10
|
export * from "./middlewares/validate-request";
|
|
11
|
+
export * from "./observability/logger";
|
|
12
|
+
export * from "./observability/correlation";
|
|
13
|
+
export * from "./observability/express";
|
|
11
14
|
export * from "./events/nats/baseListener";
|
|
12
15
|
export * from "./events/nats/basePublisher";
|
|
13
16
|
export * from "./events/kafka/baseListener";
|
|
14
17
|
export * from "./events/kafka/basePublisher";
|
|
15
18
|
export type { EachMessagePayload } from "./events/kafka/baseListener";
|
|
16
|
-
export * from "./events/ecommerceEvents";
|
|
17
19
|
export * from "./events/subjects";
|
|
18
20
|
export * from "./events/profileEvents";
|
|
19
21
|
export * from "./events/friendshipEvents";
|
|
@@ -25,9 +27,7 @@ export * from "./events/roomEvents";
|
|
|
25
27
|
export * from "./events/messageEvents";
|
|
26
28
|
export * from "./events/messageIngestEvents";
|
|
27
29
|
export * from "./events/presenceEvents";
|
|
28
|
-
export * from "./events/feedbackEvents";
|
|
29
30
|
export * from "./events/sessionEvents";
|
|
30
|
-
export * from "./events/types/orderStatus";
|
|
31
31
|
export * from "./events/types/friendshipStatus";
|
|
32
32
|
export * from "./events/types/userStatus";
|
|
33
33
|
export * from "./events/types/visibility";
|
|
@@ -35,5 +35,5 @@ export * from "./events/types/postStatus";
|
|
|
35
35
|
export * from "./events/userEvents";
|
|
36
36
|
export * from "./events/mediaEvents";
|
|
37
37
|
export * from "./events/agentManagerEvents";
|
|
38
|
-
export * from "./events/
|
|
38
|
+
export * from "./events/agentChatEvents";
|
|
39
39
|
export * from "./events/arEvents";
|
package/build/index.js
CHANGED
|
@@ -24,11 +24,14 @@ __exportStar(require("./middlewares/error-handler"), exports);
|
|
|
24
24
|
__exportStar(require("./middlewares/jwt-extractor"), exports);
|
|
25
25
|
__exportStar(require("./middlewares/login-required"), exports);
|
|
26
26
|
__exportStar(require("./middlewares/validate-request"), exports);
|
|
27
|
+
// Observability (Phase 1)
|
|
28
|
+
__exportStar(require("./observability/logger"), exports);
|
|
29
|
+
__exportStar(require("./observability/correlation"), exports);
|
|
30
|
+
__exportStar(require("./observability/express"), exports);
|
|
27
31
|
__exportStar(require("./events/nats/baseListener"), exports);
|
|
28
32
|
__exportStar(require("./events/nats/basePublisher"), exports);
|
|
29
33
|
__exportStar(require("./events/kafka/baseListener"), exports);
|
|
30
34
|
__exportStar(require("./events/kafka/basePublisher"), exports);
|
|
31
|
-
__exportStar(require("./events/ecommerceEvents"), exports);
|
|
32
35
|
__exportStar(require("./events/subjects"), exports);
|
|
33
36
|
__exportStar(require("./events/profileEvents"), exports);
|
|
34
37
|
__exportStar(require("./events/friendshipEvents"), exports);
|
|
@@ -40,9 +43,7 @@ __exportStar(require("./events/roomEvents"), exports);
|
|
|
40
43
|
__exportStar(require("./events/messageEvents"), exports);
|
|
41
44
|
__exportStar(require("./events/messageIngestEvents"), exports);
|
|
42
45
|
__exportStar(require("./events/presenceEvents"), exports);
|
|
43
|
-
__exportStar(require("./events/feedbackEvents"), exports);
|
|
44
46
|
__exportStar(require("./events/sessionEvents"), exports);
|
|
45
|
-
__exportStar(require("./events/types/orderStatus"), exports);
|
|
46
47
|
__exportStar(require("./events/types/friendshipStatus"), exports);
|
|
47
48
|
__exportStar(require("./events/types/userStatus"), exports);
|
|
48
49
|
__exportStar(require("./events/types/visibility"), exports);
|
|
@@ -50,5 +51,7 @@ __exportStar(require("./events/types/postStatus"), exports);
|
|
|
50
51
|
__exportStar(require("./events/userEvents"), exports);
|
|
51
52
|
__exportStar(require("./events/mediaEvents"), exports);
|
|
52
53
|
__exportStar(require("./events/agentManagerEvents"), exports);
|
|
53
|
-
|
|
54
|
+
// Agent Chat (renamed from AR chat)
|
|
55
|
+
__exportStar(require("./events/agentChatEvents"), exports);
|
|
56
|
+
// Backwards-compatible exports (deprecated; kept to avoid breaking existing services)
|
|
54
57
|
__exportStar(require("./events/arEvents"), exports);
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.errorHandler = void 0;
|
|
4
4
|
const customError_1 = require("../errors/customError");
|
|
5
|
+
const correlation_1 = require("../observability/correlation");
|
|
6
|
+
const logger_1 = require("../observability/logger");
|
|
5
7
|
`common structure for errors:
|
|
6
8
|
{
|
|
7
9
|
errors:{
|
|
@@ -10,7 +12,15 @@ const customError_1 = require("../errors/customError");
|
|
|
10
12
|
}
|
|
11
13
|
`;
|
|
12
14
|
const errorHandler = (err, req, res, next) => {
|
|
13
|
-
|
|
15
|
+
const correlationId = (0, correlation_1.getCorrelationId)();
|
|
16
|
+
(0, logger_1.logger)().error({
|
|
17
|
+
correlationId,
|
|
18
|
+
err,
|
|
19
|
+
http: {
|
|
20
|
+
method: req.method,
|
|
21
|
+
path: req.originalUrl || req.url,
|
|
22
|
+
},
|
|
23
|
+
}, "request.error");
|
|
14
24
|
if (err instanceof customError_1.CustomError) {
|
|
15
25
|
return res.status(err.statusCode).send({ errors: err.serializeDetails() });
|
|
16
26
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type CorrelationContext = {
|
|
2
|
+
correlationId: string;
|
|
3
|
+
};
|
|
4
|
+
export declare function runWithCorrelationId<T>(correlationId: string | undefined, fn: () => T): T;
|
|
5
|
+
export declare function getCorrelationId(): string | undefined;
|
|
6
|
+
export declare function getOrCreateCorrelationId(incoming?: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.runWithCorrelationId = runWithCorrelationId;
|
|
7
|
+
exports.getCorrelationId = getCorrelationId;
|
|
8
|
+
exports.getOrCreateCorrelationId = getOrCreateCorrelationId;
|
|
9
|
+
const async_hooks_1 = require("async_hooks");
|
|
10
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
+
const storage = new async_hooks_1.AsyncLocalStorage();
|
|
12
|
+
function newCorrelationId() {
|
|
13
|
+
// Prefer Node's built-in UUID when available.
|
|
14
|
+
const anyCrypto = crypto_1.default;
|
|
15
|
+
if (typeof anyCrypto.randomUUID === 'function') {
|
|
16
|
+
return anyCrypto.randomUUID();
|
|
17
|
+
}
|
|
18
|
+
return crypto_1.default.randomBytes(16).toString('hex');
|
|
19
|
+
}
|
|
20
|
+
function runWithCorrelationId(correlationId, fn) {
|
|
21
|
+
const cid = correlationId && String(correlationId).trim() ? String(correlationId).trim() : newCorrelationId();
|
|
22
|
+
return storage.run({ correlationId: cid }, fn);
|
|
23
|
+
}
|
|
24
|
+
function getCorrelationId() {
|
|
25
|
+
var _a;
|
|
26
|
+
return (_a = storage.getStore()) === null || _a === void 0 ? void 0 : _a.correlationId;
|
|
27
|
+
}
|
|
28
|
+
function getOrCreateCorrelationId(incoming) {
|
|
29
|
+
const existing = getCorrelationId();
|
|
30
|
+
if (existing)
|
|
31
|
+
return existing;
|
|
32
|
+
return (incoming && String(incoming).trim()) || newCorrelationId();
|
|
33
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
+
export declare function correlationIdMiddleware(req: Request, res: Response, next: NextFunction): void;
|
|
3
|
+
export declare function requestLoggingMiddleware(req: Request, res: Response, next: NextFunction): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.correlationIdMiddleware = correlationIdMiddleware;
|
|
4
|
+
exports.requestLoggingMiddleware = requestLoggingMiddleware;
|
|
5
|
+
const correlation_1 = require("./correlation");
|
|
6
|
+
const logger_1 = require("./logger");
|
|
7
|
+
function correlationIdMiddleware(req, res, next) {
|
|
8
|
+
const incoming = req.headers['x-correlation-id'] || req.headers['x-request-id'];
|
|
9
|
+
(0, correlation_1.runWithCorrelationId)(incoming, () => {
|
|
10
|
+
const cid = (0, correlation_1.getCorrelationId)();
|
|
11
|
+
if (cid) {
|
|
12
|
+
res.setHeader('x-correlation-id', cid);
|
|
13
|
+
}
|
|
14
|
+
next();
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
function requestLoggingMiddleware(req, res, next) {
|
|
18
|
+
const start = Date.now();
|
|
19
|
+
const cid = () => (0, correlation_1.getCorrelationId)();
|
|
20
|
+
// Log at finish so that downstream middleware (e.g. JWT extractors) can attach context to req.
|
|
21
|
+
res.on('finish', () => {
|
|
22
|
+
const durationMs = Date.now() - start;
|
|
23
|
+
const statusCode = res.statusCode;
|
|
24
|
+
const level = statusCode >= 500 ? 'error' : statusCode >= 400 ? 'warn' : 'info';
|
|
25
|
+
const jwtPayload = req.jwtPayload;
|
|
26
|
+
const userId = (jwtPayload === null || jwtPayload === void 0 ? void 0 : jwtPayload.id) ? String(jwtPayload.id) : undefined;
|
|
27
|
+
(0, logger_1.logger)()[level]({
|
|
28
|
+
correlationId: cid(),
|
|
29
|
+
http: {
|
|
30
|
+
method: req.method,
|
|
31
|
+
path: req.originalUrl || req.url,
|
|
32
|
+
statusCode,
|
|
33
|
+
durationMs,
|
|
34
|
+
},
|
|
35
|
+
userId,
|
|
36
|
+
}, 'http.request');
|
|
37
|
+
});
|
|
38
|
+
next();
|
|
39
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.logger = logger;
|
|
7
|
+
const pino_1 = __importDefault(require("pino"));
|
|
8
|
+
let _logger = null;
|
|
9
|
+
function buildLogger() {
|
|
10
|
+
const isDev = (process.env.NODE_ENV || '').toLowerCase() !== 'production';
|
|
11
|
+
const base = {
|
|
12
|
+
service: process.env.SERVICE_NAME,
|
|
13
|
+
environment: process.env.NODE_ENV,
|
|
14
|
+
version: process.env.APP_VERSION,
|
|
15
|
+
};
|
|
16
|
+
// Keep redaction broad and safe. Services can add more redaction upstream.
|
|
17
|
+
const redactPaths = [
|
|
18
|
+
'req.headers.authorization',
|
|
19
|
+
'req.headers.cookie',
|
|
20
|
+
'req.headers["set-cookie"]',
|
|
21
|
+
'req.headers["x-api-key"]',
|
|
22
|
+
'password',
|
|
23
|
+
'token',
|
|
24
|
+
'accessToken',
|
|
25
|
+
'refreshToken',
|
|
26
|
+
'apiKey',
|
|
27
|
+
'authorization',
|
|
28
|
+
'cookie',
|
|
29
|
+
];
|
|
30
|
+
return (0, pino_1.default)({
|
|
31
|
+
level: process.env.LOG_LEVEL || (isDev ? 'debug' : 'info'),
|
|
32
|
+
timestamp: pino_1.default.stdTimeFunctions.isoTime,
|
|
33
|
+
base,
|
|
34
|
+
redact: { paths: redactPaths, remove: true },
|
|
35
|
+
formatters: {
|
|
36
|
+
level: (label) => ({ level: label }),
|
|
37
|
+
},
|
|
38
|
+
serializers: {
|
|
39
|
+
err: pino_1.default.stdSerializers.err,
|
|
40
|
+
req: pino_1.default.stdSerializers.req,
|
|
41
|
+
res: pino_1.default.stdSerializers.res,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function logger() {
|
|
46
|
+
if (!_logger)
|
|
47
|
+
_logger = buildLogger();
|
|
48
|
+
return _logger;
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aichatwar/shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.146",
|
|
4
4
|
"main": "./build/index.js",
|
|
5
5
|
"typs": "./build/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"jsonwebtoken": "^9.0.2",
|
|
32
32
|
"kafkajs": "^2.2.4",
|
|
33
33
|
"mongoose-update-if-current": "^1.4.0",
|
|
34
|
-
"node-nats-streaming": "^0.3.2"
|
|
34
|
+
"node-nats-streaming": "^0.3.2",
|
|
35
|
+
"pino": "^9.9.0"
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Subjects } from "./subjects";
|
|
2
|
-
import { OrderStatus } from "./types/orderStatus";
|
|
3
|
-
import { BaseEvent } from "./baseEvent";
|
|
4
|
-
interface EcommerceModelCreatedEvent extends BaseEvent {
|
|
5
|
-
subject: Subjects.EcommerceModelCreated;
|
|
6
|
-
data: {
|
|
7
|
-
id: string;
|
|
8
|
-
userId: string;
|
|
9
|
-
rank: number;
|
|
10
|
-
modelId: string;
|
|
11
|
-
price: number;
|
|
12
|
-
version: number;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
interface EcommerceModelUpdatedEvent extends BaseEvent {
|
|
16
|
-
subject: Subjects.EcommerceModelUpdated;
|
|
17
|
-
data: {
|
|
18
|
-
id: string;
|
|
19
|
-
rank: number;
|
|
20
|
-
modelId: string;
|
|
21
|
-
price: number;
|
|
22
|
-
userId: string;
|
|
23
|
-
version: number;
|
|
24
|
-
orderId?: string;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
interface EcommerceOrderCancelledEvent extends BaseEvent {
|
|
28
|
-
subject: Subjects.EcommerceOrderCancelled;
|
|
29
|
-
data: {
|
|
30
|
-
id: string;
|
|
31
|
-
userId: string;
|
|
32
|
-
version: number;
|
|
33
|
-
aiModelCard: {
|
|
34
|
-
cardRefId: string;
|
|
35
|
-
version?: number;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
interface EcommerceOrderCreatedEvent extends BaseEvent {
|
|
40
|
-
subject: Subjects.EcommerceOrderCreated;
|
|
41
|
-
data: {
|
|
42
|
-
id: string;
|
|
43
|
-
userId: string;
|
|
44
|
-
status: OrderStatus;
|
|
45
|
-
expirationDate: string;
|
|
46
|
-
version: number;
|
|
47
|
-
aiModelCard: {
|
|
48
|
-
id: string;
|
|
49
|
-
modelRefId: string;
|
|
50
|
-
price: number;
|
|
51
|
-
cardRefId: string;
|
|
52
|
-
userId: string;
|
|
53
|
-
version?: number;
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
interface EcommerceOrderExpiredEvent extends BaseEvent {
|
|
58
|
-
subject: Subjects.EcommerceOrderExpired;
|
|
59
|
-
data: {
|
|
60
|
-
id: string;
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
export { EcommerceModelCreatedEvent, EcommerceModelUpdatedEvent, BaseEvent, EcommerceOrderCreatedEvent, EcommerceOrderCancelledEvent, EcommerceOrderExpiredEvent };
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { BaseEvent } from "./baseEvent";
|
|
2
|
-
import { Subjects } from "./subjects";
|
|
3
|
-
interface AgentLearningUpdatedEvent extends BaseEvent {
|
|
4
|
-
subject: Subjects.AgentLearningUpdated;
|
|
5
|
-
data: {
|
|
6
|
-
agentId: string;
|
|
7
|
-
ownerUserId: string;
|
|
8
|
-
learningMetrics: {
|
|
9
|
-
sentimentScore: number;
|
|
10
|
-
engagementScore: number;
|
|
11
|
-
qualityScore: number;
|
|
12
|
-
preferenceWeights: {
|
|
13
|
-
topics: Record<string, number>;
|
|
14
|
-
communicationStyle: Record<string, number>;
|
|
15
|
-
responseLength: 'short' | 'medium' | 'long';
|
|
16
|
-
};
|
|
17
|
-
behaviorPatterns: {
|
|
18
|
-
commonPhrases: string[];
|
|
19
|
-
preferredTopics: string[];
|
|
20
|
-
interactionStyle: string;
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
feedbackStats: {
|
|
24
|
-
totalFeedback: number;
|
|
25
|
-
positiveCount: number;
|
|
26
|
-
negativeCount: number;
|
|
27
|
-
lastUpdated: string;
|
|
28
|
-
};
|
|
29
|
-
version: number;
|
|
30
|
-
updatedAt: string;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
interface TrainingDatasetReadyEvent extends BaseEvent {
|
|
34
|
-
subject: Subjects.TrainingDatasetReady;
|
|
35
|
-
data: {
|
|
36
|
-
agentId: string;
|
|
37
|
-
archetype?: string;
|
|
38
|
-
datasetId: string;
|
|
39
|
-
highQualityInteractions: Array<{
|
|
40
|
-
messageId: string;
|
|
41
|
-
userMessage: string;
|
|
42
|
-
agentResponse: string;
|
|
43
|
-
feedbackScore: number;
|
|
44
|
-
context: {
|
|
45
|
-
roomId: string;
|
|
46
|
-
timestamp: string;
|
|
47
|
-
};
|
|
48
|
-
}>;
|
|
49
|
-
learnedTraits: Record<string, number>;
|
|
50
|
-
feedbackStats: {
|
|
51
|
-
totalFeedback: number;
|
|
52
|
-
positiveCount: number;
|
|
53
|
-
averageSentiment: number;
|
|
54
|
-
};
|
|
55
|
-
timeWindow: {
|
|
56
|
-
start: string;
|
|
57
|
-
end: string;
|
|
58
|
-
};
|
|
59
|
-
createdAt: string;
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
interface ModelUpdatedEvent extends BaseEvent {
|
|
63
|
-
subject: Subjects.ModelUpdated;
|
|
64
|
-
data: {
|
|
65
|
-
agentId: string;
|
|
66
|
-
archetype?: string;
|
|
67
|
-
modelId: string;
|
|
68
|
-
provider: string;
|
|
69
|
-
trainingJobId: string;
|
|
70
|
-
status: 'completed' | 'failed';
|
|
71
|
-
metadata?: {
|
|
72
|
-
trainingExamples: number;
|
|
73
|
-
trainingDuration: number;
|
|
74
|
-
modelSize?: string;
|
|
75
|
-
};
|
|
76
|
-
updatedAt: string;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
interface FeedbackReplyReceivedEvent extends BaseEvent {
|
|
80
|
-
subject: Subjects.FeedbackReplyReceived;
|
|
81
|
-
data: {
|
|
82
|
-
roomId: string;
|
|
83
|
-
messageId: string;
|
|
84
|
-
replyToMessageId: string;
|
|
85
|
-
agentId: string;
|
|
86
|
-
agentMessageContent: string;
|
|
87
|
-
replyToSenderId?: string;
|
|
88
|
-
replyToSenderType?: 'human' | 'agent';
|
|
89
|
-
replyToSenderName?: string;
|
|
90
|
-
replySenderId: string;
|
|
91
|
-
replySenderType: 'human' | 'agent';
|
|
92
|
-
replySenderName?: string;
|
|
93
|
-
replyContent: string;
|
|
94
|
-
createdAt: string;
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
interface FeedbackReactionReceivedEvent extends BaseEvent {
|
|
98
|
-
subject: Subjects.FeedbackReactionReceived;
|
|
99
|
-
data: {
|
|
100
|
-
roomId: string;
|
|
101
|
-
messageId: string;
|
|
102
|
-
agentId: string;
|
|
103
|
-
agentMessageContent: string;
|
|
104
|
-
reactionUserId: string;
|
|
105
|
-
reactionUserType: 'human' | 'agent';
|
|
106
|
-
emoji: string;
|
|
107
|
-
createdAt: string;
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
export { FeedbackReplyReceivedEvent, FeedbackReactionReceivedEvent, AgentLearningUpdatedEvent, TrainingDatasetReadyEvent, ModelUpdatedEvent };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { Subjects } from './subjects';
|
|
2
|
-
/**
|
|
3
|
-
* ChatRecommendationRequestedEvent
|
|
4
|
-
* Published by: ai-chat-host service
|
|
5
|
-
* Consumed by: recommendation service
|
|
6
|
-
*
|
|
7
|
-
* Request for recommendations based on chat context
|
|
8
|
-
*/
|
|
9
|
-
export interface ChatRecommendationRequestedEvent {
|
|
10
|
-
subject: Subjects.ChatRecommendationRequested;
|
|
11
|
-
data: {
|
|
12
|
-
requestId: string;
|
|
13
|
-
userId: string;
|
|
14
|
-
contextType: 'chat';
|
|
15
|
-
roomId: string;
|
|
16
|
-
topics: string[];
|
|
17
|
-
sentiment: 'positive' | 'neutral' | 'negative';
|
|
18
|
-
intent: string;
|
|
19
|
-
domain: string;
|
|
20
|
-
agentsInRoom: string[];
|
|
21
|
-
participants: Array<{
|
|
22
|
-
userId: string;
|
|
23
|
-
type: 'human' | 'agent';
|
|
24
|
-
}>;
|
|
25
|
-
lastMessages?: Array<{
|
|
26
|
-
senderId: string;
|
|
27
|
-
type: 'human' | 'agent';
|
|
28
|
-
content: string;
|
|
29
|
-
}>;
|
|
30
|
-
language?: string;
|
|
31
|
-
messageCount: number;
|
|
32
|
-
lastActivityAt: string;
|
|
33
|
-
timestamp: string;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* ChatRecommendationsReadyEvent
|
|
38
|
-
* Published by: recommendation service
|
|
39
|
-
* Consumed by: ai-chat-host service
|
|
40
|
-
*
|
|
41
|
-
* Response with recommendations for chat context
|
|
42
|
-
* Separated by type for cleaner UI handling
|
|
43
|
-
*/
|
|
44
|
-
export interface ChatRecommendationsReadyEvent {
|
|
45
|
-
subject: Subjects.ChatRecommendationsReady;
|
|
46
|
-
data: {
|
|
47
|
-
requestId: string;
|
|
48
|
-
agentRecommendations: Recommendation[];
|
|
49
|
-
utilityRecommendations: Recommendation[];
|
|
50
|
-
metadata?: {
|
|
51
|
-
roomId?: string;
|
|
52
|
-
generatedAt: string;
|
|
53
|
-
totalCount: number;
|
|
54
|
-
};
|
|
55
|
-
timestamp: string;
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Recommendation
|
|
60
|
-
* Generic recommendation item that can be agent, utility action, ad, content, etc.
|
|
61
|
-
*/
|
|
62
|
-
export interface Recommendation {
|
|
63
|
-
type: 'agent' | 'utility' | 'ad' | 'content';
|
|
64
|
-
agentId?: string;
|
|
65
|
-
action?: string;
|
|
66
|
-
label?: string;
|
|
67
|
-
score: number;
|
|
68
|
-
reason?: string;
|
|
69
|
-
metadata?: {
|
|
70
|
-
matchReasons?: string[];
|
|
71
|
-
confidence?: number;
|
|
72
|
-
name?: string;
|
|
73
|
-
displayName?: string;
|
|
74
|
-
[key: string]: any;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrderStatus = void 0;
|
|
4
|
-
var OrderStatus;
|
|
5
|
-
(function (OrderStatus) {
|
|
6
|
-
OrderStatus["Created"] = "created";
|
|
7
|
-
OrderStatus["Completed"] = "completed";
|
|
8
|
-
OrderStatus["WaitingPayment"] = "waiting:payment";
|
|
9
|
-
OrderStatus["Cancelled"] = "cancelled";
|
|
10
|
-
OrderStatus["Expired"] = "expired";
|
|
11
|
-
})(OrderStatus || (exports.OrderStatus = OrderStatus = {}));
|
|
12
|
-
// TODO: expand more for analytics
|
|
File without changes
|