@verana-labs/vs-agent-plugin-chat 2.0.0-dev.134 → 2.0.0-dev.136
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.
|
@@ -1,197 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.chatEvents = void 0;
|
|
4
|
-
const didcomm_calls_1 = require("@credo-ts/didcomm-calls");
|
|
5
|
-
const didcomm_media_sharing_1 = require("@credo-ts/didcomm-media-sharing");
|
|
6
|
-
const didcomm_reactions_1 = require("@credo-ts/didcomm-reactions");
|
|
7
|
-
const didcomm_user_profile_1 = require("@credo-ts/didcomm-user-profile");
|
|
8
|
-
const didcomm_action_menu_1 = require("@credo-ts/didcomm-action-menu");
|
|
9
4
|
const didcomm_1 = require("@credo-ts/didcomm");
|
|
10
|
-
const didcomm_question_answer_1 = require("@credo-ts/didcomm-question-answer");
|
|
11
|
-
const vs_agent_model_1 = require("@verana-labs/vs-agent-model");
|
|
12
|
-
const vs_agent_sdk_1 = require("@verana-labs/vs-agent-sdk");
|
|
13
|
-
const parsers_1 = require("../utils/parsers");
|
|
14
5
|
const chatEvents = async (agent, logger) => {
|
|
15
6
|
agent.events.on(didcomm_1.DidCommConnectionEventTypes.DidCommConnectionStateChanged, async ({ payload }) => {
|
|
16
7
|
if (payload.connectionRecord.state === didcomm_1.DidCommDidExchangeState.Completed) {
|
|
17
8
|
await agent.modules.userProfile.requestUserProfile({ connectionId: payload.connectionRecord.id });
|
|
18
9
|
}
|
|
19
10
|
});
|
|
20
|
-
// FIXME: timestamps are currently taken from reception date. They should be get from the originating DIDComm message
|
|
21
|
-
// as soon as the corresponding extension is added to them
|
|
22
|
-
agent.events.on(didcomm_1.DidCommEventTypes.DidCommMessageProcessed, async ({ payload }) => {
|
|
23
|
-
var _a, _b, _c, _d, _e;
|
|
24
|
-
logger.debug(`DidCommMessageProcessedEvent received: ${JSON.stringify(payload.message)}`);
|
|
25
|
-
const { message, connection } = payload;
|
|
26
|
-
if (!connection) {
|
|
27
|
-
logger.warn(`[chatEvents] Received contactless message of type ${message.type}. Not supported yet.`);
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
// Basic Message protocol messages
|
|
31
|
-
if (message.type === didcomm_1.DidCommBasicMessage.type.messageTypeUri) {
|
|
32
|
-
const msg = new vs_agent_model_1.TextMessage({
|
|
33
|
-
connectionId: connection.id,
|
|
34
|
-
content: payload.message.content,
|
|
35
|
-
id: payload.message.id,
|
|
36
|
-
threadId: (_a = payload.message.thread) === null || _a === void 0 ? void 0 : _a.parentThreadId,
|
|
37
|
-
timestamp: new Date(),
|
|
38
|
-
});
|
|
39
|
-
if (msg.threadId)
|
|
40
|
-
msg.threadId = await (0, vs_agent_sdk_1.getRecordId)(agent, msg.threadId);
|
|
41
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
42
|
-
}
|
|
43
|
-
// Action Menu protocol messages
|
|
44
|
-
if (message.type === didcomm_action_menu_1.DidCommMenuRequestMessage.type.messageTypeUri) {
|
|
45
|
-
const msg = new vs_agent_model_1.ContextualMenuRequestMessage({
|
|
46
|
-
connectionId: connection.id,
|
|
47
|
-
id: connection.id,
|
|
48
|
-
timestamp: new Date(),
|
|
49
|
-
});
|
|
50
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
51
|
-
}
|
|
52
|
-
if (message.type === didcomm_action_menu_1.DidCommPerformMessage.type.messageTypeUri) {
|
|
53
|
-
const msg = new vs_agent_model_1.ContextualMenuSelectMessage({
|
|
54
|
-
selectionId: message.name,
|
|
55
|
-
connectionId: connection.id,
|
|
56
|
-
id: message.id,
|
|
57
|
-
timestamp: new Date(),
|
|
58
|
-
});
|
|
59
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
60
|
-
}
|
|
61
|
-
// Question Answer protocol messages
|
|
62
|
-
if (message.type === didcomm_question_answer_1.DidCommAnswerMessage.type.messageTypeUri) {
|
|
63
|
-
const record = await agent.dependencyManager
|
|
64
|
-
.resolve(didcomm_question_answer_1.DidCommQuestionAnswerService)
|
|
65
|
-
.getByThreadAndConnectionId(agent.context, connection.id, message.threadId);
|
|
66
|
-
const textIdMapping = record.metadata.get('text-id-mapping');
|
|
67
|
-
if (!textIdMapping) {
|
|
68
|
-
logger.warn(`[chatEvents] No text-id mapping found for Menu message. Using responded text as identifier`);
|
|
69
|
-
}
|
|
70
|
-
const selectionId = textIdMapping
|
|
71
|
-
? textIdMapping[message.response]
|
|
72
|
-
: message.response;
|
|
73
|
-
const msg = new vs_agent_model_1.MenuSelectMessage({
|
|
74
|
-
threadId: message.threadId,
|
|
75
|
-
connectionId: connection.id,
|
|
76
|
-
menuItems: [{ id: selectionId }],
|
|
77
|
-
id: message.id,
|
|
78
|
-
});
|
|
79
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
80
|
-
}
|
|
81
|
-
if (message.type === didcomm_calls_1.CallOfferMessage.type.messageTypeUri) {
|
|
82
|
-
const callOffer = message;
|
|
83
|
-
const msg = new vs_agent_model_1.CallOfferRequestMessage({
|
|
84
|
-
id: await (0, vs_agent_sdk_1.getRecordId)(agent, message.id),
|
|
85
|
-
connectionId: connection.id,
|
|
86
|
-
offerExpirationTime: (_b = callOffer.offerExpirationTime) !== null && _b !== void 0 ? _b : undefined,
|
|
87
|
-
offerStartTime: (_c = callOffer.offerStartTime) !== null && _c !== void 0 ? _c : undefined,
|
|
88
|
-
description: callOffer.description,
|
|
89
|
-
parameters: callOffer.parameters,
|
|
90
|
-
threadId: (_d = message.thread) === null || _d === void 0 ? void 0 : _d.threadId,
|
|
91
|
-
timestamp: new Date(),
|
|
92
|
-
});
|
|
93
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
94
|
-
}
|
|
95
|
-
if (message.type === didcomm_calls_1.CallEndMessage.type.messageTypeUri) {
|
|
96
|
-
const thread = message.thread;
|
|
97
|
-
const msg = new vs_agent_model_1.CallEndRequestMessage({
|
|
98
|
-
id: await (0, vs_agent_sdk_1.getRecordId)(agent, message.id),
|
|
99
|
-
connectionId: connection.id,
|
|
100
|
-
threadId: thread === null || thread === void 0 ? void 0 : thread.threadId,
|
|
101
|
-
timestamp: new Date(),
|
|
102
|
-
});
|
|
103
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
104
|
-
}
|
|
105
|
-
if (message.type === didcomm_calls_1.CallAcceptMessage.type.messageTypeUri) {
|
|
106
|
-
const parameters = message.parameters;
|
|
107
|
-
const msg = new vs_agent_model_1.CallAcceptRequestMessage({
|
|
108
|
-
id: await (0, vs_agent_sdk_1.getRecordId)(agent, message.id),
|
|
109
|
-
connectionId: connection.id,
|
|
110
|
-
parameters: parameters,
|
|
111
|
-
threadId: (_e = message.thread) === null || _e === void 0 ? void 0 : _e.threadId,
|
|
112
|
-
timestamp: new Date(),
|
|
113
|
-
});
|
|
114
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
115
|
-
}
|
|
116
|
-
if (message.type === didcomm_calls_1.CallRejectMessage.type.messageTypeUri) {
|
|
117
|
-
const thread = message.thread;
|
|
118
|
-
const msg = new vs_agent_model_1.CallRejectRequestMessage({
|
|
119
|
-
id: await (0, vs_agent_sdk_1.getRecordId)(agent, message.id),
|
|
120
|
-
connectionId: connection.id,
|
|
121
|
-
threadId: thread === null || thread === void 0 ? void 0 : thread.threadId,
|
|
122
|
-
timestamp: new Date(),
|
|
123
|
-
});
|
|
124
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
// Media protocol events
|
|
128
|
-
agent.events.on(didcomm_media_sharing_1.DidCommMediaSharingEventTypes.StateChanged, async ({ payload }) => {
|
|
129
|
-
var _a;
|
|
130
|
-
const record = payload.mediaSharingRecord;
|
|
131
|
-
logger.debug(`MediaSharingStateChangedEvent received. Role: ${record.role} Connection id: ${record.connectionId}. Items: ${JSON.stringify(record.items)}`);
|
|
132
|
-
if (record.state === didcomm_media_sharing_1.DidCommMediaSharingState.MediaShared &&
|
|
133
|
-
record.role === didcomm_media_sharing_1.DidCommMediaSharingRole.Receiver) {
|
|
134
|
-
if (record.items) {
|
|
135
|
-
const message = new vs_agent_model_1.MediaMessage({
|
|
136
|
-
connectionId: record.connectionId,
|
|
137
|
-
id: record.threadId,
|
|
138
|
-
threadId: record.parentThreadId,
|
|
139
|
-
timestamp: record.createdAt,
|
|
140
|
-
items: (_a = record.items) === null || _a === void 0 ? void 0 : _a.map(item => {
|
|
141
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
142
|
-
return ({
|
|
143
|
-
id: item.id,
|
|
144
|
-
ciphering: item.ciphering,
|
|
145
|
-
uri: item.uri,
|
|
146
|
-
mimeType: item.mimeType,
|
|
147
|
-
byteCount: item.byteCount,
|
|
148
|
-
description: item.description,
|
|
149
|
-
filename: item.fileName,
|
|
150
|
-
duration: (_a = item.metadata) === null || _a === void 0 ? void 0 : _a.duration,
|
|
151
|
-
preview: (_b = item.metadata) === null || _b === void 0 ? void 0 : _b.preview,
|
|
152
|
-
width: (_c = item.metadata) === null || _c === void 0 ? void 0 : _c.width,
|
|
153
|
-
height: (_d = item.metadata) === null || _d === void 0 ? void 0 : _d.height,
|
|
154
|
-
title: (_e = item.metadata) === null || _e === void 0 ? void 0 : _e.title,
|
|
155
|
-
icon: (_f = item.metadata) === null || _f === void 0 ? void 0 : _f.icon,
|
|
156
|
-
openingMode: (_g = item.metadata) === null || _g === void 0 ? void 0 : _g.openingMode,
|
|
157
|
-
screenOrientation: (_h = item.metadata) === null || _h === void 0 ? void 0 : _h.screenOrientation,
|
|
158
|
-
});
|
|
159
|
-
}),
|
|
160
|
-
});
|
|
161
|
-
if (message.threadId)
|
|
162
|
-
message.threadId = await (0, vs_agent_sdk_1.getRecordId)(agent, message.threadId);
|
|
163
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(message));
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
// Reactions protocol events
|
|
168
|
-
agent.events.on(didcomm_reactions_1.DidCommReactionsEventTypes.DidCommMessageReactionsReceived, async ({ payload }) => {
|
|
169
|
-
const { connectionId, reactions } = payload;
|
|
170
|
-
logger.debug(`DidCommMessageReactionsReceivedEvent received. Connection id: ${connectionId}. Reactions: ${JSON.stringify(reactions)}`);
|
|
171
|
-
const msg = new vs_agent_model_1.ReactionMessage({
|
|
172
|
-
connectionId,
|
|
173
|
-
reactions: reactions.map(r => ({
|
|
174
|
-
messageId: r.messageId,
|
|
175
|
-
emoji: r.emoji,
|
|
176
|
-
action: r.action,
|
|
177
|
-
timestamp: r.timestamp,
|
|
178
|
-
})),
|
|
179
|
-
});
|
|
180
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
181
|
-
});
|
|
182
|
-
agent.events.on(didcomm_user_profile_1.DidCommProfileEventTypes.ConnectionProfileUpdated, async ({ payload: { connection, profile } }) => {
|
|
183
|
-
const { displayName, displayPicture, displayIcon, description, preferredLanguage } = profile;
|
|
184
|
-
logger.debug(`ConnectionProfileUpdatedEvent received. Connection id: ${connection.id} Profile: ${JSON.stringify(profile)}`);
|
|
185
|
-
const msg = new vs_agent_model_1.ProfileMessage({
|
|
186
|
-
connectionId: connection.id,
|
|
187
|
-
displayName,
|
|
188
|
-
displayImageUrl: displayPicture && (0, parsers_1.createDataUrl)(displayPicture),
|
|
189
|
-
displayIconUrl: displayIcon && (0, parsers_1.createDataUrl)(displayIcon),
|
|
190
|
-
description,
|
|
191
|
-
preferredLanguage,
|
|
192
|
-
});
|
|
193
|
-
(0, vs_agent_sdk_1.emitVsAgentEvent)(agent, vs_agent_sdk_1.VsAgentEventTypes.MessageReceived, (0, vs_agent_sdk_1.msgToEvent)(msg));
|
|
194
|
-
});
|
|
195
11
|
};
|
|
196
12
|
exports.chatEvents = chatEvents;
|
|
197
13
|
//# sourceMappingURL=ChatEvents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatEvents.js","sourceRoot":"","sources":["../../src/events/ChatEvents.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ChatEvents.js","sourceRoot":"","sources":["../../src/events/ChatEvents.ts"],"names":[],"mappings":";;;AAGA,+CAI0B;AAGnB,MAAM,UAAU,GAAG,KAAK,EAAE,KAAgC,EAAE,MAAkB,EAAE,EAAE;IACvF,KAAK,CAAC,MAAM,CAAC,EAAE,CACb,qCAA2B,CAAC,6BAA6B,EACzD,KAAK,EAAE,EAAE,OAAO,EAAsC,EAAE,EAAE;QACxD,IAAI,OAAO,CAAC,gBAAgB,CAAC,KAAK,KAAK,iCAAuB,CAAC,SAAS,EAAE,CAAC;YACzE,MAAM,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,gBAAgB,CAAC,EAAE,EAAE,CAAC,CAAA;QACnG,CAAC;IACH,CAAC,CACF,CAAA;AACH,CAAC,CAAA;AATY,QAAA,UAAU,cAStB"}
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"default": "./build/index.js"
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
|
-
"version": "2.0.0-dev.
|
|
12
|
+
"version": "2.0.0-dev.136",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "https://github.com/verana-labs/vs-agent"
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"description": "Chat DIDComm plugin for VS Agent",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@credo-ts/core": "0.8.0-alpha-
|
|
27
|
-
"@credo-ts/didcomm": "0.8.0-alpha-
|
|
26
|
+
"@credo-ts/core": "0.8.0-alpha-20261128092258",
|
|
27
|
+
"@credo-ts/didcomm": "0.8.0-alpha-20261128092258",
|
|
28
28
|
"@credo-ts/didcomm-action-menu": "0.8.0",
|
|
29
29
|
"@credo-ts/didcomm-calls": "0.2.0",
|
|
30
30
|
"@credo-ts/didcomm-media-sharing": "0.2.0",
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@nestjs/swagger": "^8.0.7",
|
|
37
37
|
"class-transformer": "0.5.1",
|
|
38
38
|
"class-validator": "0.14.1",
|
|
39
|
-
"@verana-labs/vs-agent-model": "2.0.0-dev.
|
|
40
|
-
"@verana-labs/vs-agent-sdk": "2.0.0-dev.
|
|
39
|
+
"@verana-labs/vs-agent-model": "2.0.0-dev.136",
|
|
40
|
+
"@verana-labs/vs-agent-sdk": "2.0.0-dev.136"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@credo-ts/core": "0.8.0-alpha-
|
|
43
|
+
"@credo-ts/core": "0.8.0-alpha-20261128092258"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "pnpm run clean && pnpm run compile",
|
package/build/utils/parsers.d.ts
DELETED
package/build/utils/parsers.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createDataUrl = createDataUrl;
|
|
4
|
-
function createDataUrl(pictureData) {
|
|
5
|
-
if (pictureData.base64 && pictureData.mimeType) {
|
|
6
|
-
return `data:${pictureData.mimeType};base64,${pictureData.base64}`;
|
|
7
|
-
}
|
|
8
|
-
else if (pictureData.links && pictureData.links.length > 0) {
|
|
9
|
-
return pictureData.links[0];
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=parsers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parsers.js","sourceRoot":"","sources":["../../src/utils/parsers.ts"],"names":[],"mappings":";;AAEA,sCAMC;AAND,SAAgB,aAAa,CAAC,WAAwB;IACpD,IAAI,WAAW,CAAC,MAAM,IAAI,WAAW,CAAC,QAAQ,EAAE,CAAC;QAC/C,OAAO,QAAQ,WAAW,CAAC,QAAQ,WAAW,WAAW,CAAC,MAAM,EAAE,CAAA;IACpE,CAAC;SAAM,IAAI,WAAW,CAAC,KAAK,IAAI,WAAW,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC7B,CAAC;AACH,CAAC"}
|