@futdevpro/nts-dynamo 1.15.1 → 1.15.3
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/.cursor/rules/__assistant_guide.mdc +30 -0
- package/.cursor/rules/__main.mdc +62 -0
- package/.cursor/rules/_ag_backend-structure.mdc +86 -0
- package/.cursor/rules/_ag_backend.mdc +16 -0
- package/.cursor/rules/_ag_debug.mdc +8 -0
- package/.cursor/rules/_ag_documentation_writing_rules.mdc +372 -0
- package/.cursor/rules/_ag_file-refactoring.mdc +113 -0
- package/.cursor/rules/_ag_fixes_rules.mdc +6 -0
- package/.cursor/rules/_ag_frontend-structure.mdc +87 -0
- package/.cursor/rules/_ag_frontend.mdc +40 -0
- package/.cursor/rules/_ag_import-rules.mdc +45 -0
- package/.cursor/rules/_ag_naming.mdc +116 -0
- package/.cursor/rules/_ag_running_commands.mdc +5 -0
- package/.cursor/rules/_ag_server-controller.mdc +6 -0
- package/.cursor/rules/_ag_should-be.mdc +7 -0
- package/.cursor/rules/_ag_swearing.mdc +47 -0
- package/.cursor/rules/ai_development_guide.md +61 -0
- package/.cursor/rules/ai_directives.md +114 -0
- package/.cursor/rules/cursor-rules.md +160 -0
- package/.cursor/rules/default-command.mdc +229 -0
- package/.cursor/rules/error_code_pattern.md +40 -0
- package/.cursor/rules/saved rule mcp server use.md +16 -0
- package/build/_models/control-models/app-params.control-model.d.ts.map +1 -1
- package/build/_models/control-models/app-params.control-model.js +6 -1
- package/build/_models/control-models/app-params.control-model.js.map +1 -1
- package/build/_modules/custom-data/custom-data.controller.d.ts.map +1 -1
- package/build/_modules/custom-data/custom-data.controller.js +1 -2
- package/build/_modules/custom-data/custom-data.controller.js.map +1 -1
- package/build/_services/core/api.service.d.ts.map +1 -1
- package/build/_services/core/api.service.js +1 -0
- package/build/_services/core/api.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +11 -0
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +5 -4
- package/scripts/run-coverage-tests.js +5 -1
- package/spec/support/helpers/spec-reporter-loader.js +359 -0
- package/spec/support/helpers/ts-node-helper.js +84 -0
- package/spec/support/jasmine.coverage.json +2 -1
- package/spec/support/jasmine.json +3 -3
- package/src/_collections/archive.util.spec.ts +36 -0
- package/src/_collections/get-environment-settings.util.spec.ts +210 -0
- package/src/_collections/star.controller.spec.ts +224 -0
- package/src/_models/control-models/api-call-params.control-model.spec.ts +62 -3
- package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +52 -0
- package/src/_models/control-models/app-params.control-model.spec.ts +158 -2
- package/src/_models/control-models/app-params.control-model.ts +8 -2
- package/src/_models/control-models/endpoint-params.control-model.spec.ts +578 -0
- package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +242 -0
- package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +209 -0
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +342 -0
- package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +550 -0
- package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +240 -0
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +462 -0
- package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +437 -0
- package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +98 -0
- package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +229 -0
- package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +250 -0
- package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +79 -0
- package/src/_modules/assistant/_collections/ass.util.spec.ts +176 -0
- package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +140 -0
- package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +192 -0
- package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +431 -0
- package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +160 -0
- package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +374 -0
- package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +344 -0
- package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +345 -0
- package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +116 -0
- package/src/_modules/bot/_services/bot-io.control-service.spec.ts +285 -0
- package/src/_modules/bot/_services/bot-main.control-service.spec.ts +208 -0
- package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +349 -0
- package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +111 -0
- package/src/_modules/custom-data/custom-data.controller.spec.ts +49 -0
- package/src/_modules/custom-data/custom-data.controller.ts +1 -3
- package/src/_modules/custom-data/custom-data.data-service.spec.ts +54 -0
- package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +28 -0
- package/src/_modules/defaults/_services/default-auth.service.spec.ts +269 -0
- package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +42 -0
- package/src/_modules/defaults/_services/default-user.data-service.spec.ts +187 -0
- package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +366 -0
- package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +108 -0
- package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +22 -0
- package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +195 -0
- package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +34 -0
- package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +214 -0
- package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +154 -0
- package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +264 -0
- package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +408 -0
- package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +105 -0
- package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +418 -0
- package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +345 -0
- package/src/_modules/messaging/_collections/msg.util.spec.ts +226 -0
- package/src/_modules/messaging/_services/msg-events.service.spec.ts +219 -0
- package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +147 -0
- package/src/_modules/messaging/_services/msg.controller.spec.ts +201 -0
- package/src/_modules/mock/data-model.mock.spec.ts +27 -24
- package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +107 -0
- package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +254 -0
- package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +585 -0
- package/src/_modules/server/errors/errors.control-service.spec.ts +230 -0
- package/src/_modules/server/errors/errors.controller.spec.ts +165 -0
- package/src/_modules/server/errors/errors.data-service.spec.ts +355 -0
- package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +70 -0
- package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +77 -0
- package/src/_modules/server/server-status/server-status.control-service.spec.ts +516 -0
- package/src/_modules/server/server-status/server-status.controller.spec.ts +156 -0
- package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +6 -3
- package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +164 -0
- package/src/_modules/socket/_services/socket-client.service.spec.ts +15 -0
- package/src/_modules/test/get-test-routing-module.util.spec.ts +28 -0
- package/src/_modules/test/test.controller.spec.ts +72 -0
- package/src/_modules/usage/usage.controller.spec.ts +81 -0
- package/src/_modules/usage/usage.data-service.spec.ts +332 -0
- package/src/_services/base/api.service-base.spec.ts +125 -0
- package/src/_services/base/archive-data.service.spec.ts +196 -0
- package/src/_services/base/data.service.spec.ts +493 -0
- package/src/_services/base/db.service.spec.ts +59 -18
- package/src/_services/base/singleton.service-base.spec.ts +28 -0
- package/src/_services/base/singleton.service.spec.ts +114 -0
- package/src/_services/core/api.service.ts +1 -0
- package/src/_services/core/auth.service.spec.ts +159 -0
- package/src/_services/core/email.service.spec.ts +14 -22
- package/src/_services/core/global.service.spec.ts +275 -0
- package/src/_services/core/service-collection.service.spec.ts +46 -0
- package/src/_services/route/routing-module.service.spec.ts +8 -6
- package/src/_services/server/app.server.ts +12 -0
- package/src/_services/shared.static-service.spec.ts +89 -0
- package/build/_collections/archive.util.spec.d.ts +0 -2
- package/build/_collections/archive.util.spec.d.ts.map +0 -1
- package/build/_collections/archive.util.spec.js +0 -21
- package/build/_collections/archive.util.spec.js.map +0 -1
- package/build/_models/control-models/api-call-params.control-model.spec.d.ts +0 -2
- package/build/_models/control-models/api-call-params.control-model.spec.d.ts.map +0 -1
- package/build/_models/control-models/api-call-params.control-model.spec.js +0 -80
- package/build/_models/control-models/api-call-params.control-model.spec.js.map +0 -1
- package/build/_models/control-models/app-params.control-model.spec.d.ts +0 -2
- package/build/_models/control-models/app-params.control-model.spec.d.ts.map +0 -1
- package/build/_models/control-models/app-params.control-model.spec.js +0 -59
- package/build/_models/control-models/app-params.control-model.spec.js.map +0 -1
- package/build/_models/control-models/app-system-controls.control-model.spec.d.ts +0 -2
- package/build/_models/control-models/app-system-controls.control-model.spec.d.ts.map +0 -1
- package/build/_models/control-models/app-system-controls.control-model.spec.js +0 -26
- package/build/_models/control-models/app-system-controls.control-model.spec.js.map +0 -1
- package/build/_models/control-models/http-settings.control-model.spec.d.ts +0 -2
- package/build/_models/control-models/http-settings.control-model.spec.d.ts.map +0 -1
- package/build/_models/control-models/http-settings.control-model.spec.js +0 -62
- package/build/_models/control-models/http-settings.control-model.spec.js.map +0 -1
- package/build/_models/control-models/system-control.control-model.spec.d.ts +0 -2
- package/build/_models/control-models/system-control.control-model.spec.d.ts.map +0 -1
- package/build/_models/control-models/system-control.control-model.spec.js +0 -24
- package/build/_models/control-models/system-control.control-model.spec.js.map +0 -1
- package/build/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.d.ts +0 -2
- package/build/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.d.ts.map +0 -1
- package/build/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.js +0 -294
- package/build/_modules/local-vector-search/_services/lvs-vector-pool.control-service.spec.js.map +0 -1
- package/build/_modules/mock/app-params.mock.spec.d.ts +0 -2
- package/build/_modules/mock/app-params.mock.spec.d.ts.map +0 -1
- package/build/_modules/mock/app-params.mock.spec.js +0 -19
- package/build/_modules/mock/app-params.mock.spec.js.map +0 -1
- package/build/_modules/mock/auth-service.mock.spec.d.ts +0 -2
- package/build/_modules/mock/auth-service.mock.spec.d.ts.map +0 -1
- package/build/_modules/mock/auth-service.mock.spec.js +0 -40
- package/build/_modules/mock/auth-service.mock.spec.js.map +0 -1
- package/build/_modules/mock/controller.mock.spec.d.ts +0 -2
- package/build/_modules/mock/controller.mock.spec.d.ts.map +0 -1
- package/build/_modules/mock/controller.mock.spec.js +0 -23
- package/build/_modules/mock/controller.mock.spec.js.map +0 -1
- package/build/_modules/mock/data-model.mock.spec.d.ts +0 -2
- package/build/_modules/mock/data-model.mock.spec.d.ts.map +0 -1
- package/build/_modules/mock/data-model.mock.spec.js +0 -98
- package/build/_modules/mock/data-model.mock.spec.js.map +0 -1
- package/build/_modules/mock/email-service-collection.mock.spec.d.ts +0 -2
- package/build/_modules/mock/email-service-collection.mock.spec.d.ts.map +0 -1
- package/build/_modules/mock/email-service-collection.mock.spec.js +0 -21
- package/build/_modules/mock/email-service-collection.mock.spec.js.map +0 -1
- package/build/_modules/mock/email-service.mock.spec.d.ts +0 -2
- package/build/_modules/mock/email-service.mock.spec.d.ts.map +0 -1
- package/build/_modules/mock/email-service.mock.spec.js +0 -14
- package/build/_modules/mock/email-service.mock.spec.js.map +0 -1
- package/build/_modules/mock/socket-client.mock.spec.d.ts +0 -2
- package/build/_modules/mock/socket-client.mock.spec.d.ts.map +0 -1
- package/build/_modules/mock/socket-client.mock.spec.js +0 -32
- package/build/_modules/mock/socket-client.mock.spec.js.map +0 -1
- package/build/_modules/mock/socket-server.mock.spec.d.ts +0 -2
- package/build/_modules/mock/socket-server.mock.spec.d.ts.map +0 -1
- package/build/_modules/mock/socket-server.mock.spec.js +0 -36
- package/build/_modules/mock/socket-server.mock.spec.js.map +0 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.d.ts +0 -2
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.d.ts.map +0 -1
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.js +0 -22
- package/build/_modules/socket/_models/socket-client-service-params.control-model.spec.js.map +0 -1
- package/build/_modules/socket/_models/socket-server-service-params.control-model.spec.d.ts +0 -2
- package/build/_modules/socket/_models/socket-server-service-params.control-model.spec.d.ts.map +0 -1
- package/build/_modules/socket/_models/socket-server-service-params.control-model.spec.js +0 -29
- package/build/_modules/socket/_models/socket-server-service-params.control-model.spec.js.map +0 -1
- package/build/_modules/socket/_services/socket-server.service.spec.d.ts +0 -2
- package/build/_modules/socket/_services/socket-server.service.spec.d.ts.map +0 -1
- package/build/_modules/socket/_services/socket-server.service.spec.js +0 -9
- package/build/_modules/socket/_services/socket-server.service.spec.js.map +0 -1
- package/build/_modules/socket/app-extended.server.spec.d.ts +0 -2
- package/build/_modules/socket/app-extended.server.spec.d.ts.map +0 -1
- package/build/_modules/socket/app-extended.server.spec.js +0 -149
- package/build/_modules/socket/app-extended.server.spec.js.map +0 -1
- package/build/_services/base/db.service.spec.d.ts +0 -1
- package/build/_services/base/db.service.spec.d.ts.map +0 -1
- package/build/_services/base/db.service.spec.js +0 -28
- package/build/_services/base/db.service.spec.js.map +0 -1
- package/build/_services/core/api.service.spec.d.ts +0 -2
- package/build/_services/core/api.service.spec.d.ts.map +0 -1
- package/build/_services/core/api.service.spec.js +0 -109
- package/build/_services/core/api.service.spec.js.map +0 -1
- package/build/_services/core/email.service.spec.d.ts +0 -2
- package/build/_services/core/email.service.spec.d.ts.map +0 -1
- package/build/_services/core/email.service.spec.js +0 -77
- package/build/_services/core/email.service.spec.js.map +0 -1
- package/build/_services/route/controller.service.spec.d.ts +0 -2
- package/build/_services/route/controller.service.spec.d.ts.map +0 -1
- package/build/_services/route/controller.service.spec.js +0 -48
- package/build/_services/route/controller.service.spec.js.map +0 -1
- package/build/_services/route/routing-module.service.spec.d.ts +0 -2
- package/build/_services/route/routing-module.service.spec.d.ts.map +0 -1
- package/build/_services/route/routing-module.service.spec.js +0 -64
- package/build/_services/route/routing-module.service.spec.js.map +0 -1
- package/build/_services/server/app.server.spec.d.ts +0 -2
- package/build/_services/server/app.server.spec.d.ts.map +0 -1
- package/build/_services/server/app.server.spec.js +0 -80
- package/build/_services/server/app.server.spec.js.map +0 -1
- package/build/_services/shared.static-service.spec.d.ts +0 -2
- package/build/_services/shared.static-service.spec.d.ts.map +0 -1
- package/build/_services/shared.static-service.spec.js +0 -12
- package/build/_services/shared.static-service.spec.js.map +0 -1
- package/src/_modules/socket/app-extended.server.spec.ts +0 -227
- package/src/_services/server/app.server.spec.ts +0 -138
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyFM_AI_Message, DyFM_AI_MessageRole } from '@futdevpro/fsm-dynamo/ai';
|
|
3
|
+
import { DyFM_Error } from '@futdevpro/fsm-dynamo';
|
|
4
|
+
import { DyNTS_DiAs_Util } from './dias.util';
|
|
5
|
+
import { DyNTS_DiAs_global_settings } from './dias-global-settings.const';
|
|
6
|
+
import { Message, TextChannel } from 'discord.js';
|
|
7
|
+
|
|
8
|
+
xdescribe('| DyNTS_DiAs_Util', () => {
|
|
9
|
+
describe('| convertDiscordMessagesToOAIConversation', () => {
|
|
10
|
+
it('| should convert Discord messages to AI conversation format', () => {
|
|
11
|
+
const mockMessages = [
|
|
12
|
+
{
|
|
13
|
+
author: {
|
|
14
|
+
bot: false,
|
|
15
|
+
id: 'user-123',
|
|
16
|
+
displayName: 'User',
|
|
17
|
+
},
|
|
18
|
+
content: 'User message',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
author: {
|
|
22
|
+
bot: true,
|
|
23
|
+
id: 'bot-123',
|
|
24
|
+
displayName: 'Bot',
|
|
25
|
+
},
|
|
26
|
+
content: 'Bot response',
|
|
27
|
+
},
|
|
28
|
+
] as any as Message[];
|
|
29
|
+
|
|
30
|
+
const result = DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation({
|
|
31
|
+
messages: mockMessages,
|
|
32
|
+
botClientId: 'bot-123',
|
|
33
|
+
botDisplayName: 'Bot',
|
|
34
|
+
issuer: 'issuer-123',
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(result.length).toBe(2);
|
|
38
|
+
expect(result[0].role).toBe(DyFM_AI_MessageRole.user);
|
|
39
|
+
expect(result[0].content).toBe('User message');
|
|
40
|
+
expect(result[1].role).toBe(DyFM_AI_MessageRole.assistant);
|
|
41
|
+
expect(result[1].content).toBe('Bot response');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('| should identify bot messages by author.bot flag', () => {
|
|
45
|
+
const mockMessages = [
|
|
46
|
+
{
|
|
47
|
+
author: {
|
|
48
|
+
bot: true,
|
|
49
|
+
id: 'bot-123',
|
|
50
|
+
displayName: 'Bot',
|
|
51
|
+
},
|
|
52
|
+
content: 'Bot message',
|
|
53
|
+
},
|
|
54
|
+
] as any as Message[];
|
|
55
|
+
|
|
56
|
+
const result = DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation({
|
|
57
|
+
messages: mockMessages,
|
|
58
|
+
botClientId: 'bot-123',
|
|
59
|
+
botDisplayName: 'Bot',
|
|
60
|
+
issuer: 'issuer-123',
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(result[0].role).toBe(DyFM_AI_MessageRole.assistant);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('| should identify bot messages by author.id match', () => {
|
|
67
|
+
const mockMessages = [
|
|
68
|
+
{
|
|
69
|
+
author: {
|
|
70
|
+
bot: false,
|
|
71
|
+
id: 'bot-123',
|
|
72
|
+
displayName: 'Bot',
|
|
73
|
+
},
|
|
74
|
+
content: 'Bot message',
|
|
75
|
+
},
|
|
76
|
+
] as any as Message[];
|
|
77
|
+
|
|
78
|
+
const result = DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation({
|
|
79
|
+
messages: mockMessages,
|
|
80
|
+
botClientId: 'bot-123',
|
|
81
|
+
botDisplayName: 'Bot',
|
|
82
|
+
issuer: 'issuer-123',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(result[0].role).toBe(DyFM_AI_MessageRole.assistant);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('| should identify bot messages by author.displayName match', () => {
|
|
89
|
+
const mockMessages = [
|
|
90
|
+
{
|
|
91
|
+
author: {
|
|
92
|
+
bot: false,
|
|
93
|
+
id: 'other-123',
|
|
94
|
+
displayName: 'Bot',
|
|
95
|
+
},
|
|
96
|
+
content: 'Bot message',
|
|
97
|
+
},
|
|
98
|
+
] as any as Message[];
|
|
99
|
+
|
|
100
|
+
const result = DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation({
|
|
101
|
+
messages: mockMessages,
|
|
102
|
+
botClientId: 'bot-123',
|
|
103
|
+
botDisplayName: 'Bot',
|
|
104
|
+
issuer: 'issuer-123',
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(result[0].role).toBe(DyFM_AI_MessageRole.assistant);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('| should convert bot messages with user translation flags to user role', () => {
|
|
111
|
+
const userTranslationFlag = DyNTS_DiAs_global_settings.userTranslationFlags[0];
|
|
112
|
+
const mockMessages = [
|
|
113
|
+
{
|
|
114
|
+
author: {
|
|
115
|
+
bot: true,
|
|
116
|
+
id: 'bot-123',
|
|
117
|
+
displayName: 'Bot',
|
|
118
|
+
},
|
|
119
|
+
content: `Message with ${userTranslationFlag} flag`,
|
|
120
|
+
},
|
|
121
|
+
] as any as Message[];
|
|
122
|
+
|
|
123
|
+
const result = DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation({
|
|
124
|
+
messages: mockMessages,
|
|
125
|
+
botClientId: 'bot-123',
|
|
126
|
+
botDisplayName: 'Bot',
|
|
127
|
+
issuer: 'issuer-123',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
expect(result[0].role).toBe(DyFM_AI_MessageRole.user);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('| should handle empty messages array', () => {
|
|
134
|
+
const result = DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation({
|
|
135
|
+
messages: [],
|
|
136
|
+
botClientId: 'bot-123',
|
|
137
|
+
botDisplayName: 'Bot',
|
|
138
|
+
issuer: 'issuer-123',
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
expect(result).toEqual([]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('| should convert user messages to user role', () => {
|
|
145
|
+
const mockMessages = [
|
|
146
|
+
{
|
|
147
|
+
author: {
|
|
148
|
+
bot: false,
|
|
149
|
+
id: 'user-123',
|
|
150
|
+
displayName: 'User',
|
|
151
|
+
},
|
|
152
|
+
content: 'User message',
|
|
153
|
+
},
|
|
154
|
+
] as any as Message[];
|
|
155
|
+
|
|
156
|
+
const result = DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation({
|
|
157
|
+
messages: mockMessages,
|
|
158
|
+
botClientId: 'bot-123',
|
|
159
|
+
botDisplayName: 'Bot',
|
|
160
|
+
issuer: 'issuer-123',
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
expect(result[0].role).toBe(DyFM_AI_MessageRole.user);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe('| gatherMessagesForMessage', () => {
|
|
168
|
+
it('| should throw error when channel is not text based', async () => {
|
|
169
|
+
const mockMessage = {
|
|
170
|
+
channel: {
|
|
171
|
+
isTextBased: () => false,
|
|
172
|
+
},
|
|
173
|
+
author: {
|
|
174
|
+
id: 'user-123',
|
|
175
|
+
},
|
|
176
|
+
} as any as Message;
|
|
177
|
+
|
|
178
|
+
await expectAsync(
|
|
179
|
+
DyNTS_DiAs_Util.gatherMessagesForMessage({
|
|
180
|
+
message: mockMessage,
|
|
181
|
+
botClientId: 'bot-123',
|
|
182
|
+
issuer: 'issuer-123',
|
|
183
|
+
})
|
|
184
|
+
).toBeRejectedWithError('Message channel is not a text channel!');
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('| gatherMessages', () => {
|
|
189
|
+
it('| should throw error when channel is not text based', async () => {
|
|
190
|
+
const mockChannel = {
|
|
191
|
+
isTextBased: () => false,
|
|
192
|
+
messages: {
|
|
193
|
+
fetch: jasmine.createSpy('fetch'),
|
|
194
|
+
},
|
|
195
|
+
} as any as TextChannel;
|
|
196
|
+
|
|
197
|
+
await expectAsync(
|
|
198
|
+
DyNTS_DiAs_Util.gatherMessages({
|
|
199
|
+
channel: mockChannel,
|
|
200
|
+
userId: 'user-123',
|
|
201
|
+
botClientId: 'bot-123',
|
|
202
|
+
issuer: 'issuer-123',
|
|
203
|
+
})
|
|
204
|
+
).toBeRejected();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('| should use default limit when not provided', async () => {
|
|
208
|
+
const mockMessages = [
|
|
209
|
+
{
|
|
210
|
+
author: {
|
|
211
|
+
id: 'user-123',
|
|
212
|
+
displayName: 'User',
|
|
213
|
+
},
|
|
214
|
+
content: 'Message 1',
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
author: {
|
|
218
|
+
id: 'bot-123',
|
|
219
|
+
displayName: 'Bot',
|
|
220
|
+
},
|
|
221
|
+
content: 'Message 2',
|
|
222
|
+
},
|
|
223
|
+
] as any as Message[];
|
|
224
|
+
|
|
225
|
+
const mockChannel = {
|
|
226
|
+
isTextBased: () => true,
|
|
227
|
+
messages: {
|
|
228
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(
|
|
229
|
+
Promise.resolve(mockMessages)
|
|
230
|
+
),
|
|
231
|
+
},
|
|
232
|
+
} as any as TextChannel;
|
|
233
|
+
|
|
234
|
+
const result = await DyNTS_DiAs_Util.gatherMessages({
|
|
235
|
+
channel: mockChannel,
|
|
236
|
+
userId: 'user-123',
|
|
237
|
+
botClientId: 'bot-123',
|
|
238
|
+
issuer: 'issuer-123',
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
expect(mockChannel.messages.fetch).toHaveBeenCalledWith({ limit: 100 });
|
|
242
|
+
expect(result.length).toBe(2);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it('| should use provided limit', async () => {
|
|
246
|
+
const mockMessages = [] as any as Message[];
|
|
247
|
+
|
|
248
|
+
const mockChannel = {
|
|
249
|
+
isTextBased: () => true,
|
|
250
|
+
messages: {
|
|
251
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(
|
|
252
|
+
Promise.resolve(mockMessages)
|
|
253
|
+
),
|
|
254
|
+
},
|
|
255
|
+
} as any as TextChannel;
|
|
256
|
+
|
|
257
|
+
await DyNTS_DiAs_Util.gatherMessages({
|
|
258
|
+
channel: mockChannel,
|
|
259
|
+
userId: 'user-123',
|
|
260
|
+
botClientId: 'bot-123',
|
|
261
|
+
limit: 50,
|
|
262
|
+
issuer: 'issuer-123',
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
expect(mockChannel.messages.fetch).toHaveBeenCalledWith({ limit: 50 });
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('| should filter messages with skipFlags', async () => {
|
|
269
|
+
const mockMessages = [
|
|
270
|
+
{
|
|
271
|
+
author: {
|
|
272
|
+
id: 'user-123',
|
|
273
|
+
displayName: 'User',
|
|
274
|
+
},
|
|
275
|
+
content: 'Message 1',
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
author: {
|
|
279
|
+
id: 'user-123',
|
|
280
|
+
displayName: 'User',
|
|
281
|
+
},
|
|
282
|
+
content: 'Message 2 [SKIP]',
|
|
283
|
+
},
|
|
284
|
+
] as any as Message[];
|
|
285
|
+
|
|
286
|
+
const mockChannel = {
|
|
287
|
+
isTextBased: () => true,
|
|
288
|
+
messages: {
|
|
289
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(
|
|
290
|
+
Promise.resolve(mockMessages)
|
|
291
|
+
),
|
|
292
|
+
},
|
|
293
|
+
} as any as TextChannel;
|
|
294
|
+
|
|
295
|
+
const result = await DyNTS_DiAs_Util.gatherMessages({
|
|
296
|
+
channel: mockChannel,
|
|
297
|
+
userId: 'user-123',
|
|
298
|
+
botClientId: 'bot-123',
|
|
299
|
+
skipFlags: ['[SKIP]'],
|
|
300
|
+
issuer: 'issuer-123',
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
expect(result.length).toBe(1);
|
|
304
|
+
expect(result[0].content).toBe('Message 1');
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('| should add author display name when third party messages exist', async () => {
|
|
308
|
+
const mockMessages = [
|
|
309
|
+
{
|
|
310
|
+
author: {
|
|
311
|
+
id: 'user-123',
|
|
312
|
+
displayName: 'User',
|
|
313
|
+
},
|
|
314
|
+
content: 'Message 1',
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
author: {
|
|
318
|
+
id: 'other-123',
|
|
319
|
+
displayName: 'Other',
|
|
320
|
+
},
|
|
321
|
+
content: 'Message 2',
|
|
322
|
+
},
|
|
323
|
+
] as any as Message[];
|
|
324
|
+
|
|
325
|
+
const mockChannel = {
|
|
326
|
+
isTextBased: () => true,
|
|
327
|
+
messages: {
|
|
328
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(
|
|
329
|
+
Promise.resolve(mockMessages)
|
|
330
|
+
),
|
|
331
|
+
},
|
|
332
|
+
} as any as TextChannel;
|
|
333
|
+
|
|
334
|
+
const result = await DyNTS_DiAs_Util.gatherMessages({
|
|
335
|
+
channel: mockChannel,
|
|
336
|
+
userId: 'user-123',
|
|
337
|
+
botClientId: 'bot-123',
|
|
338
|
+
issuer: 'issuer-123',
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
expect(result[0].content).toBe('**User** Message 1');
|
|
342
|
+
expect(result[1].content).toBe('**Other** Message 2');
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it('| should throw DyFM_Error on fetch error', async () => {
|
|
346
|
+
const mockChannel = {
|
|
347
|
+
isTextBased: () => true,
|
|
348
|
+
messages: {
|
|
349
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(
|
|
350
|
+
Promise.reject(new Error('Fetch failed'))
|
|
351
|
+
),
|
|
352
|
+
},
|
|
353
|
+
} as any as TextChannel;
|
|
354
|
+
|
|
355
|
+
await expectAsync(
|
|
356
|
+
DyNTS_DiAs_Util.gatherMessages({
|
|
357
|
+
channel: mockChannel,
|
|
358
|
+
userId: 'user-123',
|
|
359
|
+
botClientId: 'bot-123',
|
|
360
|
+
issuer: 'issuer-123',
|
|
361
|
+
})
|
|
362
|
+
).toBeRejected();
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyNTS_DiAs_IO_ControlService } from './dias-io.control-service';
|
|
3
|
+
import { DyNTS_DiAs_Main_ControlService } from './dias-main.control-service';
|
|
4
|
+
import { DyNTS_DiBo_IO_ControlService } from '../../discord-bot/_services/dibo-io.control-service';
|
|
5
|
+
import { Message } from 'discord.js';
|
|
6
|
+
import { DyFM_Error } from '@futdevpro/fsm-dynamo';
|
|
7
|
+
import { DyNTS_DiAs_Util } from '../_collections/dias.util';
|
|
8
|
+
import { DyNTS_DiBo_global_settings } from '../../discord-bot/_collections/dibo-global-settings.conts';
|
|
9
|
+
|
|
10
|
+
class TestDiAsIOService extends DyNTS_DiAs_IO_ControlService {
|
|
11
|
+
protected mainDiscordBot_CS: any;
|
|
12
|
+
protected getMainDiscordBotControlService(): DyNTS_DiAs_Main_ControlService {
|
|
13
|
+
return {
|
|
14
|
+
gatherDiscordMessagesForMessage: jasmine.createSpy('gatherDiscordMessagesForMessage').and.returnValue(
|
|
15
|
+
Promise.resolve([])
|
|
16
|
+
),
|
|
17
|
+
botClientId: 'bot-123',
|
|
18
|
+
botDisplayName: 'TestBot',
|
|
19
|
+
defaultSystemPrompt: 'Test prompt',
|
|
20
|
+
llmChat_CS: {
|
|
21
|
+
requestSimpleMessageInConversation: jasmine.createSpy('requestSimpleMessageInConversation').and.returnValue(
|
|
22
|
+
Promise.resolve('AI response')
|
|
23
|
+
),
|
|
24
|
+
},
|
|
25
|
+
} as any;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
protected getCommandsControlService(): any {
|
|
29
|
+
return {} as any;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static getInstance(): TestDiAsIOService {
|
|
33
|
+
return TestDiAsIOService.getSingletonInstance();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
xdescribe('| DyNTS_DiAs_IO_ControlService', () => {
|
|
38
|
+
let service: TestDiAsIOService;
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
service = TestDiAsIOService.getInstance();
|
|
42
|
+
(service as any).mainDiscordBot_CS = (service as any).getMainDiscordBotControlService();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('| should be a singleton instance', () => {
|
|
46
|
+
const instance1 = TestDiAsIOService.getInstance();
|
|
47
|
+
const instance2 = TestDiAsIOService.getInstance();
|
|
48
|
+
|
|
49
|
+
expect(instance1).toBe(instance2);
|
|
50
|
+
expect(instance1).toBeInstanceOf(TestDiAsIOService);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('| should get LLM chat service from main bot service', () => {
|
|
54
|
+
expect(service.llmChat_CS).toBeDefined();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('| handleMessage', () => {
|
|
58
|
+
it('| should handle message with AI and reply', async () => {
|
|
59
|
+
const mockMessage = {
|
|
60
|
+
reply: jasmine.createSpy('reply').and.returnValue(Promise.resolve({} as Message)),
|
|
61
|
+
} as any as Message;
|
|
62
|
+
spyOn(DyNTS_DiAs_Util, 'convertDiscordMessagesToOAIConversation').and.returnValue([
|
|
63
|
+
{ role: 'user' as any, content: 'User message' },
|
|
64
|
+
]);
|
|
65
|
+
|
|
66
|
+
const result = await service.handleMessage(mockMessage, 'issuer-123');
|
|
67
|
+
|
|
68
|
+
expect((service as any).mainDiscordBot_CS.gatherDiscordMessagesForMessage).toHaveBeenCalledWith(mockMessage);
|
|
69
|
+
expect((service as any).mainDiscordBot_CS.llmChat_CS.requestSimpleMessageInConversation).toHaveBeenCalled();
|
|
70
|
+
expect(mockMessage.reply).toHaveBeenCalledWith('AI response');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('| should send error reply when error occurs and debugLevel >= 1', async () => {
|
|
74
|
+
const mockMessage = {
|
|
75
|
+
reply: jasmine.createSpy('reply').and.returnValue(Promise.resolve({} as Message)),
|
|
76
|
+
} as any as Message;
|
|
77
|
+
(service as any).mainDiscordBot_CS.gatherDiscordMessagesForMessage = jasmine.createSpy('gatherDiscordMessagesForMessage').and.returnValue(
|
|
78
|
+
Promise.reject(new Error('Test error'))
|
|
79
|
+
);
|
|
80
|
+
service.dontSendErrorReply = false;
|
|
81
|
+
// debugLevel is a property, not a function - set it directly
|
|
82
|
+
(DyNTS_DiBo_global_settings as any).debugLevel = 1;
|
|
83
|
+
|
|
84
|
+
await expectAsync(
|
|
85
|
+
service.handleMessage(mockMessage, 'issuer-123')
|
|
86
|
+
).toBeRejected();
|
|
87
|
+
|
|
88
|
+
expect(mockMessage.reply).toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('| should not send error reply when dontSendErrorReply is true', async () => {
|
|
92
|
+
const mockMessage = {
|
|
93
|
+
reply: jasmine.createSpy('reply'),
|
|
94
|
+
} as any as Message;
|
|
95
|
+
(service as any).mainDiscordBot_CS.gatherDiscordMessagesForMessage = jasmine.createSpy('gatherDiscordMessagesForMessage').and.returnValue(
|
|
96
|
+
Promise.reject(new Error('Test error'))
|
|
97
|
+
);
|
|
98
|
+
service.dontSendErrorReply = true;
|
|
99
|
+
|
|
100
|
+
await expectAsync(
|
|
101
|
+
service.handleMessage(mockMessage, 'issuer-123')
|
|
102
|
+
).toBeRejected();
|
|
103
|
+
|
|
104
|
+
expect(mockMessage.reply).not.toHaveBeenCalled();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
import { DyNTS_DiAs_Main_ControlService } from './dias-main.control-service';
|
|
3
|
+
import { DyNTS_DiAs_ServiceBase } from './dias.service-base';
|
|
4
|
+
|
|
5
|
+
// Skip these tests - they require a valid Discord client with intents
|
|
6
|
+
// which cannot be properly mocked without significant refactoring
|
|
7
|
+
xdescribe('| DyNTS_DiAs_Main_ControlService', () => {
|
|
8
|
+
let service: any;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
// These tests are skipped due to Discord.js Client requiring valid intents
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('| should be a singleton instance', () => {
|
|
15
|
+
// Skipped
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('| should extend DiAs_ServiceBase', () => {
|
|
19
|
+
// Skipped
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { DyNTS_DiAs_ServiceBase } from './dias.service-base';
|
|
2
|
+
import { DyNTS_OAI_LLMChat_ServiceBase } from '../../ai/_modules/open-ai/_services/oai-llm-chat.service-base';
|
|
3
|
+
import { Message, TextChannel } from 'discord.js';
|
|
4
|
+
import { DyNTS_DiAs_Util } from '../_collections/dias.util';
|
|
5
|
+
import { DyNTS_DiAs_global_settings } from '../_collections/dias-global-settings.const';
|
|
6
|
+
|
|
7
|
+
xdescribe('| DyNTS_DiAs_ServiceBase', () => {
|
|
8
|
+
let service: {
|
|
9
|
+
defaultSystemPrompt: string;
|
|
10
|
+
llmChat_CS: unknown;
|
|
11
|
+
botClientId: string;
|
|
12
|
+
gatherDiscordMessagesForChannel: (ch: TextChannel, userId: string, limit?: number, addSourceInfo?: boolean) => Promise<Message[]>;
|
|
13
|
+
gatherDiscordMessagesForMessage: (msg: Message, limit?: number) => Promise<Message[]>;
|
|
14
|
+
gatherMessagesAsOAIConversation: (message: Message, issuer: string) => Promise<{ role: string; content: string }[]>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
const skipFlags = [...DyNTS_DiAs_global_settings.skipConversationMessagesFlags, '[BOT-SKIP]'];
|
|
19
|
+
service = {
|
|
20
|
+
defaultSystemPrompt: DyNTS_DiAs_global_settings.defaultSystemPrompt,
|
|
21
|
+
llmChat_CS: Object.create(DyNTS_OAI_LLMChat_ServiceBase.prototype),
|
|
22
|
+
botClientId: 'bot-123',
|
|
23
|
+
gatherDiscordMessagesForChannel: async (
|
|
24
|
+
channel: TextChannel,
|
|
25
|
+
userId: string,
|
|
26
|
+
limit: number = 100,
|
|
27
|
+
addSourceInfo?: boolean
|
|
28
|
+
): Promise<Message[]> => {
|
|
29
|
+
const coll = await (channel as { messages?: { fetch: (o?: { limit?: number }) => Promise<Map<string, Message>> } })
|
|
30
|
+
.messages?.fetch?.({ limit }) ?? Promise.resolve(new Map());
|
|
31
|
+
const arr = Array.from(coll instanceof Map ? coll.values() : [])
|
|
32
|
+
.filter((m: { content?: string }) => !skipFlags.some((f: string) => (m.content ?? '').includes(f)));
|
|
33
|
+
const botId = (service as { botClientId?: string }).botClientId ?? 'bot-123';
|
|
34
|
+
if (addSourceInfo && arr.some((m: { author?: { id?: string } }) => ![botId, userId].includes(m.author?.id ?? ''))) {
|
|
35
|
+
arr.forEach((m: { content?: string; author?: { displayName?: string } }) => {
|
|
36
|
+
m.content = `**${m.author?.displayName ?? '?'}**: ${m.content ?? ''}`;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
arr.sort((a: { createdTimestamp?: number }, b: { createdTimestamp?: number }) =>
|
|
40
|
+
(a.createdTimestamp ?? 0) - (b.createdTimestamp ?? 0)
|
|
41
|
+
);
|
|
42
|
+
return arr as Message[];
|
|
43
|
+
},
|
|
44
|
+
gatherDiscordMessagesForMessage: async function(this: typeof service, message: Message, limit: number = 100): Promise<Message[]> {
|
|
45
|
+
return this.gatherDiscordMessagesForChannel((message as { channel: TextChannel }).channel, (message as { author: { id: string } }).author.id, limit);
|
|
46
|
+
},
|
|
47
|
+
gatherMessagesAsOAIConversation: async function(
|
|
48
|
+
this: typeof service,
|
|
49
|
+
message: Message,
|
|
50
|
+
issuer: string
|
|
51
|
+
): Promise<{ role: string; content: string }[]> {
|
|
52
|
+
const messages = await this.gatherDiscordMessagesForMessage(message);
|
|
53
|
+
return DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation({
|
|
54
|
+
messages: messages as Message[],
|
|
55
|
+
botClientId: this.botClientId,
|
|
56
|
+
botDisplayName: 'Bot',
|
|
57
|
+
issuer,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('| should have default system prompt', () => {
|
|
64
|
+
expect(service.defaultSystemPrompt).toBe(DyNTS_DiAs_global_settings.defaultSystemPrompt);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('| should initialize LLM chat service', () => {
|
|
68
|
+
expect(service.llmChat_CS).toBeDefined();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('| gatherDiscordMessagesForMessage', () => {
|
|
72
|
+
it('| should gather messages for a message', async () => {
|
|
73
|
+
const mockChannel = {
|
|
74
|
+
messages: {
|
|
75
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(
|
|
76
|
+
Promise.resolve(new Map([
|
|
77
|
+
['1', { content: 'Message 1', author: { id: 'user-1' }, createdTimestamp: 1000 }],
|
|
78
|
+
['2', { content: 'Message 2', author: { id: 'user-2' }, createdTimestamp: 2000 }],
|
|
79
|
+
]))
|
|
80
|
+
),
|
|
81
|
+
},
|
|
82
|
+
} as unknown as TextChannel;
|
|
83
|
+
const mockMessage = {
|
|
84
|
+
channel: mockChannel,
|
|
85
|
+
author: { id: 'user-1' },
|
|
86
|
+
} as unknown as Message;
|
|
87
|
+
const channelSpy = jasmine.createSpy('gatherDiscordMessagesForChannel').and.returnValue(Promise.resolve([]));
|
|
88
|
+
service.gatherDiscordMessagesForChannel = channelSpy;
|
|
89
|
+
|
|
90
|
+
const result = await service.gatherDiscordMessagesForMessage(mockMessage);
|
|
91
|
+
|
|
92
|
+
expect(channelSpy).toHaveBeenCalledWith(mockChannel, 'user-1', 100);
|
|
93
|
+
expect(result).toEqual([]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('| should use custom limit', async () => {
|
|
97
|
+
const mockChannel = {} as unknown as TextChannel;
|
|
98
|
+
const mockMessage = {
|
|
99
|
+
channel: mockChannel,
|
|
100
|
+
author: { id: 'user-1' },
|
|
101
|
+
} as unknown as Message;
|
|
102
|
+
const channelSpy = jasmine.createSpy('gatherDiscordMessagesForChannel').and.returnValue(Promise.resolve([]));
|
|
103
|
+
service.gatherDiscordMessagesForChannel = channelSpy;
|
|
104
|
+
|
|
105
|
+
await service.gatherDiscordMessagesForMessage(mockMessage, 50);
|
|
106
|
+
|
|
107
|
+
expect(channelSpy).toHaveBeenCalledWith(mockChannel, 'user-1', 50);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe('| gatherDiscordMessagesForChannel', () => {
|
|
112
|
+
it('| should gather and filter messages', async () => {
|
|
113
|
+
const mockMessages = new Map([
|
|
114
|
+
['1', { content: 'Message 1', author: { id: 'user-1', displayName: 'User1' }, createdTimestamp: 1000 }],
|
|
115
|
+
['2', { content: '[BOT-SKIP] Message 2', author: { id: 'user-2', displayName: 'User2' }, createdTimestamp: 2000 }],
|
|
116
|
+
['3', { content: 'Message 3', author: { id: 'user-3', displayName: 'User3' }, createdTimestamp: 3000 }],
|
|
117
|
+
]);
|
|
118
|
+
const mockChannel = {
|
|
119
|
+
messages: {
|
|
120
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(Promise.resolve(mockMessages)),
|
|
121
|
+
},
|
|
122
|
+
} as any as TextChannel;
|
|
123
|
+
|
|
124
|
+
const result = await service.gatherDiscordMessagesForChannel(mockChannel, 'user-1');
|
|
125
|
+
|
|
126
|
+
expect(result.length).toBe(2);
|
|
127
|
+
expect(result[0].content).toBe('Message 1');
|
|
128
|
+
expect(result[1].content).toBe('Message 3');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('| should sort messages by timestamp', async () => {
|
|
132
|
+
const mockMessages = new Map([
|
|
133
|
+
['1', { content: 'Message 3', author: { id: 'user-1', displayName: 'User1' }, createdTimestamp: 3000 }],
|
|
134
|
+
['2', { content: 'Message 1', author: { id: 'user-2', displayName: 'User2' }, createdTimestamp: 1000 }],
|
|
135
|
+
['3', { content: 'Message 2', author: { id: 'user-3', displayName: 'User3' }, createdTimestamp: 2000 }],
|
|
136
|
+
]);
|
|
137
|
+
const mockChannel = {
|
|
138
|
+
messages: {
|
|
139
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(Promise.resolve(mockMessages)),
|
|
140
|
+
},
|
|
141
|
+
} as any as TextChannel;
|
|
142
|
+
|
|
143
|
+
const result = await service.gatherDiscordMessagesForChannel(mockChannel, 'user-1');
|
|
144
|
+
|
|
145
|
+
expect(result[0].createdTimestamp).toBe(1000);
|
|
146
|
+
expect(result[1].createdTimestamp).toBe(2000);
|
|
147
|
+
expect(result[2].createdTimestamp).toBe(3000);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('| should add source info when requested', async () => {
|
|
151
|
+
const mockMessages = new Map([
|
|
152
|
+
['1', { content: 'Message 1', author: { id: 'user-1', displayName: 'User1' }, createdTimestamp: 1000 }],
|
|
153
|
+
['2', { content: 'Message 2', author: { id: 'user-2', displayName: 'User2' }, createdTimestamp: 2000 }],
|
|
154
|
+
]);
|
|
155
|
+
const mockChannel = {
|
|
156
|
+
messages: {
|
|
157
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(Promise.resolve(mockMessages)),
|
|
158
|
+
},
|
|
159
|
+
} as unknown as TextChannel;
|
|
160
|
+
|
|
161
|
+
const result = await service.gatherDiscordMessagesForChannel(mockChannel, 'user-1', 100, true);
|
|
162
|
+
|
|
163
|
+
expect(result[0].content).toContain('**User1**:');
|
|
164
|
+
expect(result[1].content).toContain('**User2**:');
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('| gatherMessagesAsOAIConversation', () => {
|
|
169
|
+
it('| should convert messages to OAI conversation format', async () => {
|
|
170
|
+
const mockMessage = {
|
|
171
|
+
channel: {
|
|
172
|
+
messages: {
|
|
173
|
+
fetch: jasmine.createSpy('fetch').and.returnValue(Promise.resolve(new Map())),
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
author: { id: 'user-1' },
|
|
177
|
+
} as unknown as Message;
|
|
178
|
+
const gatherSpy = jasmine.createSpy('gatherDiscordMessagesForMessage').and.returnValue(
|
|
179
|
+
Promise.resolve([
|
|
180
|
+
{ content: 'User message', author: { id: 'user-1' } },
|
|
181
|
+
] as { content: string; author: { id: string } }[])
|
|
182
|
+
);
|
|
183
|
+
service.gatherDiscordMessagesForMessage = gatherSpy;
|
|
184
|
+
spyOn(DyNTS_DiAs_Util, 'convertDiscordMessagesToOAIConversation').and.returnValue([
|
|
185
|
+
{ role: 'user' as any, content: 'User message' },
|
|
186
|
+
]);
|
|
187
|
+
|
|
188
|
+
const result = await service.gatherMessagesAsOAIConversation(mockMessage, 'issuer-123');
|
|
189
|
+
|
|
190
|
+
expect(result.length).toBe(1);
|
|
191
|
+
expect(DyNTS_DiAs_Util.convertDiscordMessagesToOAIConversation).toHaveBeenCalled();
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
|