@futdevpro/nts-dynamo 1.15.2 → 1.15.5

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.
Files changed (192) hide show
  1. package/.cursor/rules/__assistant_guide.mdc +30 -0
  2. package/.cursor/rules/__main.mdc +64 -0
  3. package/.cursor/rules/_ag_backend-structure.mdc +86 -0
  4. package/.cursor/rules/_ag_backend.mdc +16 -0
  5. package/.cursor/rules/_ag_debug.mdc +8 -0
  6. package/.cursor/rules/_ag_documentation_writing_rules.mdc +372 -0
  7. package/.cursor/rules/_ag_file-refactoring.mdc +113 -0
  8. package/.cursor/rules/_ag_fixes_rules.mdc +6 -0
  9. package/.cursor/rules/_ag_frontend-structure.mdc +87 -0
  10. package/.cursor/rules/_ag_frontend.mdc +40 -0
  11. package/.cursor/rules/_ag_import-rules.mdc +45 -0
  12. package/.cursor/rules/_ag_naming.mdc +116 -0
  13. package/.cursor/rules/_ag_running_commands.mdc +5 -0
  14. package/.cursor/rules/_ag_server-controller.mdc +6 -0
  15. package/.cursor/rules/_ag_should-be.mdc +7 -0
  16. package/.cursor/rules/_ag_swearing.mdc +47 -0
  17. package/.cursor/rules/ai_development_guide.md +61 -0
  18. package/.cursor/rules/ai_directives.md +114 -0
  19. package/.cursor/rules/cursor-rules.md +160 -0
  20. package/.cursor/rules/default-command.mdc +465 -0
  21. package/.cursor/rules/error_code_pattern.md +40 -0
  22. package/.cursor/rules/saved rule mcp server use.md +16 -0
  23. package/_specifications/BACKLOG.md +15 -0
  24. package/_specifications/TODO.md +15 -0
  25. package/build/_modules/ai/_models/ai-test-generation-result.interface.d.ts +17 -0
  26. package/build/_modules/ai/_models/ai-test-generation-result.interface.d.ts.map +1 -0
  27. package/build/_modules/ai/_models/ai-test-generation-result.interface.js +3 -0
  28. package/build/_modules/ai/_models/ai-test-generation-result.interface.js.map +1 -0
  29. package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.d.ts +36 -0
  30. package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.d.ts.map +1 -0
  31. package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.js +118 -0
  32. package/build/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.js.map +1 -0
  33. package/build/_modules/ai/_modules/anthropic/index.d.ts +3 -0
  34. package/build/_modules/ai/_modules/anthropic/index.d.ts.map +1 -0
  35. package/build/_modules/ai/_modules/anthropic/index.js +8 -0
  36. package/build/_modules/ai/_modules/anthropic/index.js.map +1 -0
  37. package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.d.ts +35 -0
  38. package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.d.ts.map +1 -0
  39. package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.js +129 -0
  40. package/build/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.js.map +1 -0
  41. package/build/_modules/ai/_modules/fdp-ai/index.d.ts +3 -0
  42. package/build/_modules/ai/_modules/fdp-ai/index.d.ts.map +1 -0
  43. package/build/_modules/ai/_modules/fdp-ai/index.js +8 -0
  44. package/build/_modules/ai/_modules/fdp-ai/index.js.map +1 -0
  45. package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.d.ts +40 -0
  46. package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.d.ts.map +1 -0
  47. package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.js +111 -0
  48. package/build/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.js.map +1 -0
  49. package/build/_modules/ai/_modules/open-ai/index.d.ts +1 -0
  50. package/build/_modules/ai/_modules/open-ai/index.d.ts.map +1 -1
  51. package/build/_modules/ai/_modules/open-ai/index.js +1 -0
  52. package/build/_modules/ai/_modules/open-ai/index.js.map +1 -1
  53. package/build/_modules/ai/_services/ai-user-key.service-base.d.ts +45 -0
  54. package/build/_modules/ai/_services/ai-user-key.service-base.d.ts.map +1 -0
  55. package/build/_modules/ai/_services/ai-user-key.service-base.js +15 -0
  56. package/build/_modules/ai/_services/ai-user-key.service-base.js.map +1 -0
  57. package/build/_modules/ai/index.d.ts +2 -0
  58. package/build/_modules/ai/index.d.ts.map +1 -1
  59. package/build/_modules/ai/index.js +2 -0
  60. package/build/_modules/ai/index.js.map +1 -1
  61. package/build/_modules/custom-data/custom-data.controller.d.ts.map +1 -1
  62. package/build/_modules/custom-data/custom-data.controller.js +1 -2
  63. package/build/_modules/custom-data/custom-data.controller.js.map +1 -1
  64. package/build/_modules/socket/app-extended.server.js +1 -1
  65. package/build/_modules/socket/app-extended.server.js.map +1 -1
  66. package/build/_services/base/data.service.d.ts +1 -1
  67. package/build/_services/base/data.service.js +1 -1
  68. package/build/_services/base/db.service.d.ts +1 -1
  69. package/build/_services/base/db.service.js +1 -1
  70. package/build/_services/core/api.service.d.ts.map +1 -1
  71. package/build/_services/core/api.service.js +1 -0
  72. package/build/_services/core/api.service.js.map +1 -1
  73. package/build/_services/core/auth.service.d.ts +2 -2
  74. package/build/_services/core/auth.service.js +1 -1
  75. package/build/_services/core/email.service.js +1 -1
  76. package/build/_services/core/email.service.js.map +1 -1
  77. package/build/_services/core/global.service.d.ts +1 -1
  78. package/build/_services/core/global.service.js +2 -2
  79. package/build/_services/core/global.service.js.map +1 -1
  80. package/build/_services/server/app.server.d.ts.map +1 -1
  81. package/build/_services/server/app.server.js +11 -1
  82. package/build/_services/server/app.server.js.map +1 -1
  83. package/package.json +18 -4
  84. package/scripts/run-coverage-tests.js +5 -1
  85. package/spec/support/helpers/spec-reporter-loader.js +359 -0
  86. package/spec/support/helpers/ts-node-helper.js +84 -0
  87. package/spec/support/jasmine.coverage.json +2 -1
  88. package/spec/support/jasmine.json +3 -3
  89. package/src/_collections/archive.util.spec.ts +36 -0
  90. package/src/_collections/get-environment-settings.util.spec.ts +210 -0
  91. package/src/_collections/star.controller.spec.ts +224 -0
  92. package/src/_models/control-models/api-call-params.control-model.spec.ts +62 -3
  93. package/src/_models/control-models/app-ext-system-controls.control-model.spec.ts +52 -0
  94. package/src/_models/control-models/app-params.control-model.spec.ts +158 -2
  95. package/src/_models/control-models/endpoint-params.control-model.spec.ts +578 -0
  96. package/src/_modules/ai/_models/ai-test-generation-result.interface.ts +16 -0
  97. package/src/_modules/ai/_modules/anthropic/_services/aai-user-key.control-service.ts +138 -0
  98. package/src/_modules/ai/_modules/anthropic/index.ts +5 -0
  99. package/src/_modules/ai/_modules/document-ai/_collections/dai-chunking.util.spec.ts +242 -0
  100. package/src/_modules/ai/_modules/document-ai/_collections/dai-document.util.spec.ts +209 -0
  101. package/src/_modules/ai/_modules/fdp-ai/_services/fdpai-user-key.control-service.ts +189 -0
  102. package/src/_modules/ai/_modules/fdp-ai/index.ts +5 -0
  103. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-document.data-service.spec.ts +342 -0
  104. package/src/_modules/ai/_modules/open-ai/_services/data-services/oai-vector-data.service.spec.ts +550 -0
  105. package/src/_modules/ai/_modules/open-ai/_services/oai-embedding.control-service.spec.ts +240 -0
  106. package/src/_modules/ai/_modules/open-ai/_services/oai-llm-chat.service-base.spec.ts +462 -0
  107. package/src/_modules/ai/_modules/open-ai/_services/oai-llm.service-base.spec.ts +437 -0
  108. package/src/_modules/ai/_modules/open-ai/_services/oai-user-key.control-service.ts +157 -0
  109. package/src/_modules/ai/_modules/open-ai/index.ts +1 -0
  110. package/src/_modules/ai/_services/ai-embedding.service-base.spec.ts +98 -0
  111. package/src/_modules/ai/_services/ai-llm-chat.service-base.spec.ts +229 -0
  112. package/src/_modules/ai/_services/ai-llm.service-base.spec.ts +250 -0
  113. package/src/_modules/ai/_services/ai-provider.service-base.spec.ts +79 -0
  114. package/src/_modules/ai/_services/ai-user-key.service-base.ts +59 -0
  115. package/src/_modules/ai/index.ts +2 -0
  116. package/src/_modules/assistant/_collections/ass.util.spec.ts +176 -0
  117. package/src/_modules/assistant/_services/ass-io.control-service.spec.ts +140 -0
  118. package/src/_modules/assistant/_services/ass-main.control-service.spec.ts +192 -0
  119. package/src/_modules/bot/_modules/discord-bot/_services/dib-messaging-provider.control-service.spec.ts +431 -0
  120. package/src/_modules/bot/_modules/dynamo-bot/_collections/dyb-operations.util.spec.ts +160 -0
  121. package/src/_modules/bot/_modules/dynamo-bot/_services/dyb-messaging-provider.control-service.spec.ts +374 -0
  122. package/src/_modules/bot/_modules/slack-bot/_services/slb-messaging-provider.control-service.spec.ts +344 -0
  123. package/src/_modules/bot/_modules/teams-bot/_services/teb-messaging-provider.control-service.spec.ts +345 -0
  124. package/src/_modules/bot/_services/bot-commands.control-service.spec.ts +116 -0
  125. package/src/_modules/bot/_services/bot-io.control-service.spec.ts +285 -0
  126. package/src/_modules/bot/_services/bot-main.control-service.spec.ts +208 -0
  127. package/src/_modules/bot/_services/bot-messaging-provider.service-base.spec.ts +349 -0
  128. package/src/_modules/bot/_services/bot-routines.control-service.spec.ts +111 -0
  129. package/src/_modules/custom-data/custom-data.controller.spec.ts +49 -0
  130. package/src/_modules/custom-data/custom-data.controller.ts +1 -3
  131. package/src/_modules/custom-data/custom-data.data-service.spec.ts +54 -0
  132. package/src/_modules/custom-data/get-custom-data-routing-module.util.spec.ts +28 -0
  133. package/src/_modules/defaults/_services/default-auth.service.spec.ts +269 -0
  134. package/src/_modules/defaults/_services/default-socket-events.service.spec.ts +42 -0
  135. package/src/_modules/defaults/_services/default-user.data-service.spec.ts +187 -0
  136. package/src/_modules/discord-assistant/_collections/dias.util.spec.ts +366 -0
  137. package/src/_modules/discord-assistant/_services/dias-io.control-service.spec.ts +108 -0
  138. package/src/_modules/discord-assistant/_services/dias-main.control-service.spec.ts +22 -0
  139. package/src/_modules/discord-assistant/_services/dias.service-base.spec.ts +195 -0
  140. package/src/_modules/discord-assistant-voiced/_services/dias-discord-bot.control-service.spec.ts +34 -0
  141. package/src/_modules/discord-bot/_collections/dibo-operations.util.spec.ts +214 -0
  142. package/src/_modules/discord-bot/_services/dibo-commands.control-service.spec.ts +154 -0
  143. package/src/_modules/discord-bot/_services/dibo-io.control-service.spec.ts +264 -0
  144. package/src/_modules/discord-bot/_services/dibo-main.control-service.spec.ts +408 -0
  145. package/src/_modules/discord-bot/_services/dibo-routines.control-service.spec.ts +105 -0
  146. package/src/_modules/local-vector-search/_services/lvs-doc-chunk-data.service.spec.ts +418 -0
  147. package/src/_modules/local-vector-search/_services/lvs-local-vector-search.data-service.spec.ts +345 -0
  148. package/src/_modules/messaging/_collections/msg.util.spec.ts +226 -0
  149. package/src/_modules/messaging/_services/msg-events.service.spec.ts +219 -0
  150. package/src/_modules/messaging/_services/msg-main.control-service.spec.ts +147 -0
  151. package/src/_modules/messaging/_services/msg.controller.spec.ts +201 -0
  152. package/src/_modules/mock/data-model.mock.spec.ts +27 -24
  153. package/src/_modules/oauth2/_routes/oauth2.controller.spec.ts +107 -0
  154. package/src/_modules/oauth2/_services/oauth2.auth-service.spec.ts +254 -0
  155. package/src/_modules/oauth2/_services/oauth2.control-service.spec.ts +585 -0
  156. package/src/_modules/server/errors/errors.control-service.spec.ts +230 -0
  157. package/src/_modules/server/errors/errors.controller.spec.ts +165 -0
  158. package/src/_modules/server/errors/errors.data-service.spec.ts +355 -0
  159. package/src/_modules/server/server-status/server-status-snapshot.control-service.spec.ts +70 -0
  160. package/src/_modules/server/server-status/server-status-snapshot.data-service.spec.ts +77 -0
  161. package/src/_modules/server/server-status/server-status.control-service.spec.ts +516 -0
  162. package/src/_modules/server/server-status/server-status.controller.spec.ts +156 -0
  163. package/src/_modules/socket/_models/socket-client-service-params.control-model.spec.ts +6 -3
  164. package/src/_modules/socket/_models/socket-presence.control-model.spec.ts +164 -0
  165. package/src/_modules/socket/_services/socket-client.service.spec.ts +15 -0
  166. package/src/_modules/socket/app-extended.server.ts +1 -1
  167. package/src/_modules/test/get-test-routing-module.util.spec.ts +28 -0
  168. package/src/_modules/test/test.controller.spec.ts +72 -0
  169. package/src/_modules/usage/usage.controller.spec.ts +81 -0
  170. package/src/_modules/usage/usage.data-service.spec.ts +332 -0
  171. package/src/_services/base/api.service-base.spec.ts +125 -0
  172. package/src/_services/base/archive-data.service.spec.ts +196 -0
  173. package/src/_services/base/data.service.spec.ts +493 -0
  174. package/src/_services/base/data.service.ts +1 -1
  175. package/src/_services/base/db.service.spec.ts +59 -18
  176. package/src/_services/base/db.service.ts +1 -1
  177. package/src/_services/base/singleton.service-base.spec.ts +28 -0
  178. package/src/_services/base/singleton.service.spec.ts +114 -0
  179. package/src/_services/core/api.service.ts +1 -0
  180. package/src/_services/core/auth.service.spec.ts +159 -0
  181. package/src/_services/core/auth.service.ts +2 -2
  182. package/src/_services/core/email.service.spec.ts +14 -22
  183. package/src/_services/core/email.service.ts +1 -1
  184. package/src/_services/core/global.service.spec.ts +275 -0
  185. package/src/_services/core/global.service.ts +2 -2
  186. package/src/_services/core/service-collection.service.spec.ts +46 -0
  187. package/src/_services/route/controller.service.ts +1 -1
  188. package/src/_services/route/routing-module.service.spec.ts +8 -6
  189. package/src/_services/server/app.server.ts +17 -1
  190. package/src/_services/shared.static-service.spec.ts +89 -0
  191. package/src/_modules/socket/app-extended.server.spec.ts +0 -227
  192. package/src/_services/server/app.server.spec.ts +0 -138
@@ -0,0 +1,138 @@
1
+ import { DyFM_AI_Provider, DyFM_AI_Config } from '@futdevpro/fsm-dynamo/ai';
2
+ import { DyFM_AI_UserProviderConfig } from '@futdevpro/fsm-dynamo/ai';
3
+ import { DyFM_AAI_UserProviderConfig, DyFM_AAI_Model } from '@futdevpro/fsm-dynamo/ai/anthropic';
4
+ import { DyFM_Log } from '@futdevpro/fsm-dynamo';
5
+
6
+ import { DyNTS_AI_UserKey_ServiceBase } from '../../../_services/ai-user-key.service-base';
7
+ import { DyNTS_AI_TestGeneration_Result } from '../../../_models/ai-test-generation-result.interface';
8
+
9
+ /**
10
+ * Anthropic-specifikus user API key kezelo service
11
+ *
12
+ * A visszafejtett API kulcsbol Anthropic-specifikus konfigot allit ossze,
13
+ * es teszteli a kapcsolatot az Anthropic API-val.
14
+ */
15
+ export class DyNTS_AAI_UserKey_ControlService extends DyNTS_AI_UserKey_ServiceBase {
16
+
17
+ static getInstance(): DyNTS_AAI_UserKey_ControlService {
18
+ return DyNTS_AAI_UserKey_ControlService.getSingletonInstance();
19
+ }
20
+
21
+ readonly aiProvider: DyFM_AI_Provider = DyFM_AI_Provider.Anthropic;
22
+
23
+ /**
24
+ * Anthropic config osszeallitasa a visszafejtett kulcsbol
25
+ */
26
+ resolveConfig(
27
+ userProviderConfig: DyFM_AI_UserProviderConfig,
28
+ decryptedApiKey: string
29
+ ): DyFM_AI_Config {
30
+ const aaiConfig: DyFM_AAI_UserProviderConfig =
31
+ userProviderConfig as DyFM_AAI_UserProviderConfig;
32
+
33
+ return {
34
+ apiKey: decryptedApiKey,
35
+ baseURL: aaiConfig.baseURL,
36
+ };
37
+ }
38
+
39
+ /**
40
+ * Anthropic kapcsolat tesztelese egy minimal messages.create() hivassal
41
+ */
42
+ async testConnection(
43
+ userProviderConfig: DyFM_AI_UserProviderConfig,
44
+ decryptedApiKey: string
45
+ ): Promise<boolean> {
46
+ try {
47
+ const Anthropic = await import('@anthropic-ai/sdk');
48
+ const config: DyFM_AI_Config = this.resolveConfig(userProviderConfig, decryptedApiKey);
49
+
50
+ const client = new Anthropic.default({
51
+ apiKey: config.apiKey,
52
+ baseURL: config.baseURL || undefined,
53
+ });
54
+
55
+ await client.messages.create({
56
+ model: DyFM_AAI_Model.claude_3_haiku_latest,
57
+ max_tokens: 5,
58
+ messages: [{ role: 'user', content: 'test' }],
59
+ });
60
+
61
+ return true;
62
+ } catch (error) {
63
+ DyFM_Log.error(
64
+ 'DyNTS_AAI_UserKey_ControlService',
65
+ 'testConnection',
66
+ 'Anthropic connection test failed',
67
+ { error: error }
68
+ );
69
+
70
+ return false;
71
+ }
72
+ }
73
+
74
+ /**
75
+ * Elerheto Anthropic modellek lekerdezese
76
+ * Az Anthropic API nem ad model list endpoint-ot, ezert a DyFM_AAI_Model enum-bol szolgalja ki
77
+ */
78
+ async listAvailableModels(
79
+ _userProviderConfig: DyFM_AI_UserProviderConfig,
80
+ _decryptedApiKey: string
81
+ ): Promise<string[]> {
82
+ return Object.values(DyFM_AAI_Model);
83
+ }
84
+
85
+ /**
86
+ * Teszt generalas az Anthropic API-val
87
+ */
88
+ async testGeneration(set: {
89
+ userProviderConfig: DyFM_AI_UserProviderConfig;
90
+ decryptedApiKey: string;
91
+ model: string;
92
+ }): Promise<DyNTS_AI_TestGeneration_Result> {
93
+ const startTime: number = Date.now();
94
+
95
+ try {
96
+ const Anthropic = await import('@anthropic-ai/sdk');
97
+ const config: DyFM_AI_Config = this.resolveConfig(
98
+ set.userProviderConfig,
99
+ set.decryptedApiKey
100
+ );
101
+
102
+ const client = new Anthropic.default({
103
+ apiKey: config.apiKey,
104
+ baseURL: config.baseURL || undefined,
105
+ });
106
+
107
+ const response = await client.messages.create({
108
+ model: set.model,
109
+ max_tokens: 10,
110
+ messages: [{ role: 'user', content: 'Hello, this is a test. Reply with "OK".' }],
111
+ });
112
+
113
+ const textContent = response.content.find(
114
+ (block: { type: string }) => block.type === 'text'
115
+ );
116
+
117
+ return {
118
+ success: true,
119
+ response: (textContent as { type: string; text: string })?.text,
120
+ model: set.model,
121
+ latencyMs: Date.now() - startTime,
122
+ };
123
+ } catch (error) {
124
+ DyFM_Log.error(
125
+ 'DyNTS_AAI_UserKey_ControlService',
126
+ 'testGeneration',
127
+ 'Anthropic test generation failed',
128
+ { error: error }
129
+ );
130
+
131
+ return {
132
+ success: false,
133
+ model: set.model,
134
+ latencyMs: Date.now() - startTime,
135
+ };
136
+ }
137
+ }
138
+ }
@@ -0,0 +1,5 @@
1
+ // Re-export from FSM
2
+ export * from '@futdevpro/fsm-dynamo/ai/anthropic';
3
+
4
+ // SERVICES
5
+ export * from './_services/aai-user-key.control-service';
@@ -0,0 +1,242 @@
1
+
2
+ import { DyFM_Error, DyFM_Log } from '@futdevpro/fsm-dynamo';
3
+ import { DyNTS_DAI_DocChunking_Util } from './dai-chunking.util';
4
+ import { DyNTS_DAI_DocPage } from '../_models/data-models/dai-doc-page.data-model';
5
+ import { DyNTS_DAI_DocChunk } from '../_models/data-models/dai-doc-chunk.data-model';
6
+ import { DyNTS_global_settings } from '../../../../../_collections/global-settings.const';
7
+
8
+ describe('| DyNTS_DAI_DocChunking_Util', () => {
9
+ describe('| chunkMdContent', () => {
10
+ it('| should throw error when page documentId is not set', async () => {
11
+ const page = new DyNTS_DAI_DocPage({
12
+ name: 'Test Page',
13
+ content: 'Test content',
14
+ documentId: '',
15
+ _id: 'page-123',
16
+ parentedPath: [],
17
+ allFlaggedParents: [],
18
+ allFlaggedParentsMerged: '',
19
+ filePath: '',
20
+ });
21
+
22
+ const getPageLink = (page: any, issuer: string) => 'http://example.com/page';
23
+
24
+ await expectAsync(
25
+ DyNTS_DAI_DocChunking_Util.chunkMdContent(page, getPageLink, 'issuer-123')
26
+ ).toBeRejected();
27
+ });
28
+
29
+ it('| should throw error when page _id is not set', async () => {
30
+ const page = new DyNTS_DAI_DocPage({
31
+ name: 'Test Page',
32
+ content: 'Test content',
33
+ documentId: 'doc-123',
34
+ _id: '',
35
+ parentedPath: [],
36
+ allFlaggedParents: [],
37
+ allFlaggedParentsMerged: '',
38
+ filePath: '',
39
+ });
40
+
41
+ const getPageLink = (page: any, issuer: string) => 'http://example.com/page';
42
+
43
+ await expectAsync(
44
+ DyNTS_DAI_DocChunking_Util.chunkMdContent(page, getPageLink, 'issuer-123')
45
+ ).toBeRejected();
46
+ });
47
+
48
+ it('| should create chunks from markdown content', async () => {
49
+ const page = new DyNTS_DAI_DocPage({
50
+ name: 'Test Page',
51
+ content: '# Header 1\n\nThis is some content.\n\n## Header 2\n\nMore content here.',
52
+ documentId: 'doc-123',
53
+ _id: 'page-123',
54
+ parentedPath: [],
55
+ allFlaggedParents: [],
56
+ allFlaggedParentsMerged: '',
57
+ filePath: '',
58
+ });
59
+
60
+ const getPageLink = (page: any, issuer: string) => 'http://example.com/page';
61
+
62
+ const chunks = await DyNTS_DAI_DocChunking_Util.chunkMdContent(page, getPageLink, 'issuer-123');
63
+
64
+ expect(chunks.length).toBeGreaterThan(0);
65
+ expect(chunks[0]).toBeInstanceOf(DyNTS_DAI_DocChunk);
66
+ expect(chunks[0].documentId).toBe('doc-123');
67
+ expect(chunks[0].pageId).toBe('page-123');
68
+ expect(chunks[0].chunkContent).toBeDefined();
69
+ });
70
+
71
+ it('| should handle empty content', async () => {
72
+ const page = new DyNTS_DAI_DocPage({
73
+ name: 'Test Page',
74
+ content: '',
75
+ documentId: 'doc-123',
76
+ _id: 'page-123',
77
+ parentedPath: [],
78
+ allFlaggedParents: [],
79
+ allFlaggedParentsMerged: '',
80
+ filePath: '',
81
+ });
82
+
83
+ const getPageLink = (page: any, issuer: string) => 'http://example.com/page';
84
+
85
+ const chunks = await DyNTS_DAI_DocChunking_Util.chunkMdContent(page, getPageLink, 'issuer-123');
86
+
87
+ expect(chunks.length).toBe(0);
88
+ });
89
+
90
+ it('| should log warning for level 5+ headers', async () => {
91
+ const logSpy = spyOn(DyFM_Log, 'warn');
92
+ const page = new DyNTS_DAI_DocPage({
93
+ name: 'Test Page',
94
+ content: '##### Level 5 Header\n\nContent',
95
+ documentId: 'doc-123',
96
+ _id: 'page-123',
97
+ parentedPath: [],
98
+ allFlaggedParents: [],
99
+ allFlaggedParentsMerged: '',
100
+ filePath: '',
101
+ });
102
+
103
+ const getPageLink = (page: any, issuer: string) => 'http://example.com/page';
104
+
105
+ await DyNTS_DAI_DocChunking_Util.chunkMdContent(page, getPageLink, 'issuer-123');
106
+
107
+ expect(logSpy).toHaveBeenCalled();
108
+ });
109
+
110
+ it('| should respect maxChunkCount limit', async () => {
111
+ const logSpy = spyOn(DyFM_Log, 'warn');
112
+ const longContent = '# Header\n\n' + 'Content. '.repeat(10000);
113
+ const page = new DyNTS_DAI_DocPage({
114
+ name: 'Test Page',
115
+ content: longContent,
116
+ documentId: 'doc-123',
117
+ _id: 'page-123',
118
+ parentedPath: [],
119
+ allFlaggedParents: [],
120
+ allFlaggedParentsMerged: '',
121
+ filePath: '',
122
+ });
123
+
124
+ const getPageLink = (page: any, issuer: string) => 'http://example.com/page';
125
+
126
+ const chunks = await DyNTS_DAI_DocChunking_Util.chunkMdContent(page, getPageLink, 'issuer-123');
127
+
128
+ expect(chunks.length).toBeLessThanOrEqual(DyNTS_global_settings.docChunking.maxChunkCount);
129
+ if (chunks.length >= DyNTS_global_settings.docChunking.maxChunkCount) {
130
+ expect(logSpy).toHaveBeenCalled();
131
+ }
132
+ });
133
+ });
134
+
135
+ describe('| reassembleChunksToContent', () => {
136
+ it('| should reassemble chunks to content', () => {
137
+ const chunks = [
138
+ new DyNTS_DAI_DocChunk({
139
+ documentId: 'doc-123',
140
+ pageId: 'page-123',
141
+ filePathParents: [],
142
+ chunkHeadParents: [],
143
+ allFlaggedParents: [],
144
+ path: '',
145
+ documentName: 'Test Document',
146
+ pageName: 'Test Page',
147
+ pageLink: '',
148
+ chunkContent: 'First chunk content',
149
+ chunkIndex: 0,
150
+ _id: 'chunk-1',
151
+ } as any),
152
+ new DyNTS_DAI_DocChunk({
153
+ documentId: 'doc-123',
154
+ pageId: 'page-123',
155
+ filePathParents: [],
156
+ chunkHeadParents: [],
157
+ allFlaggedParents: [],
158
+ path: '',
159
+ documentName: 'Test Document',
160
+ pageName: 'Test Page',
161
+ pageLink: '',
162
+ chunkContent: 'Second chunk content',
163
+ chunkIndex: 1,
164
+ _id: 'chunk-2',
165
+ } as any),
166
+ ];
167
+
168
+ const result = DyNTS_DAI_DocChunking_Util.reassembleChunksToContent(chunks, 'issuer-123');
169
+
170
+ expect(result).toContain('First chunk content');
171
+ expect(result).toContain('Second chunk content');
172
+ });
173
+
174
+ it('| should handle empty chunks array', () => {
175
+ const result = DyNTS_DAI_DocChunking_Util.reassembleChunksToContent([], 'issuer-123');
176
+
177
+ expect(result).toBe('');
178
+ });
179
+
180
+ it('| should concatenate chunks in order', () => {
181
+ const chunks = [
182
+ new DyNTS_DAI_DocChunk({
183
+ documentId: 'doc-123',
184
+ pageId: 'page-123',
185
+ filePathParents: [],
186
+ chunkHeadParents: [],
187
+ allFlaggedParents: [],
188
+ path: '',
189
+ documentName: 'Test Document',
190
+ pageName: 'Test Page',
191
+ pageLink: '',
192
+ chunkContent: 'First',
193
+ chunkIndex: 0,
194
+ _id: 'chunk-1',
195
+ } as any),
196
+ new DyNTS_DAI_DocChunk({
197
+ documentId: 'doc-123',
198
+ pageId: 'page-123',
199
+ filePathParents: [],
200
+ chunkHeadParents: [],
201
+ allFlaggedParents: [],
202
+ path: '',
203
+ documentName: 'Test Document',
204
+ pageName: 'Test Page',
205
+ pageLink: '',
206
+ chunkContent: 'Second',
207
+ chunkIndex: 1,
208
+ _id: 'chunk-2',
209
+ } as any),
210
+ ];
211
+
212
+ const result = DyNTS_DAI_DocChunking_Util.reassembleChunksToContent(chunks, 'issuer-123');
213
+
214
+ expect(result).toBe('FirstSecond');
215
+ });
216
+
217
+ it('| should throw error when chunk is null', () => {
218
+ const chunks = [
219
+ new DyNTS_DAI_DocChunk({
220
+ documentId: 'doc-123',
221
+ pageId: 'page-123',
222
+ filePathParents: [],
223
+ chunkHeadParents: [],
224
+ allFlaggedParents: [],
225
+ path: '',
226
+ documentName: 'Test Document',
227
+ pageName: 'Test Page',
228
+ pageLink: '',
229
+ chunkContent: 'First',
230
+ chunkIndex: 0,
231
+ _id: 'chunk-1',
232
+ } as any),
233
+ null as any,
234
+ ];
235
+
236
+ expect(() => {
237
+ DyNTS_DAI_DocChunking_Util.reassembleChunksToContent(chunks, 'issuer-123');
238
+ }).toThrow();
239
+ });
240
+ });
241
+ });
242
+
@@ -0,0 +1,209 @@
1
+
2
+ import { DyNTS_DAI_Document_Util } from './dai-document.util';
3
+ import { DyNTS_DAI_DocPage } from '../_models/data-models/dai-doc-page.data-model';
4
+ import { DyFM_Log } from '@futdevpro/fsm-dynamo';
5
+
6
+ describe('| DyNTS_DAI_Document_Util', () => {
7
+ describe('| getClickupPageLink', () => {
8
+ it('| should generate ClickUp page link', () => {
9
+ const result = DyNTS_DAI_Document_Util.getClickupPageLink(
10
+ 'Test Page',
11
+ 'workspace-123',
12
+ 'doc-456',
13
+ 'page-789'
14
+ );
15
+
16
+ expect(result).toContain('Test Page');
17
+ expect(result).toContain('https://app.clickup.com/workspace-123/v/dc/doc-456/page-789');
18
+ expect(result).toMatch(/\[Test Page\]\(https:\/\/app\.clickup\.com\/workspace-123\/v\/dc\/doc-456\/page-789\)/);
19
+ });
20
+ });
21
+
22
+ describe('| validateDocumentPage', () => {
23
+ it('| should return true for valid page', () => {
24
+ const page = new DyNTS_DAI_DocPage({
25
+ name: 'Test Page',
26
+ content: 'Test content',
27
+ documentId: 'doc-123',
28
+ _id: 'page-123',
29
+ parentedPath: [],
30
+ allFlaggedParents: [],
31
+ allFlaggedParentsMerged: '',
32
+ filePath: '',
33
+ });
34
+
35
+ const result = DyNTS_DAI_Document_Util.validateDocumentPage(page);
36
+
37
+ expect(result).toBe(true);
38
+ });
39
+
40
+ it('| should return false when name is missing', () => {
41
+ const logSpy = spyOn(DyFM_Log, 'error');
42
+ const page = new DyNTS_DAI_DocPage({
43
+ name: '',
44
+ content: 'Test content',
45
+ documentId: 'doc-123',
46
+ _id: 'page-123',
47
+ parentedPath: [],
48
+ allFlaggedParents: [],
49
+ allFlaggedParentsMerged: '',
50
+ filePath: '',
51
+ });
52
+
53
+ const result = DyNTS_DAI_Document_Util.validateDocumentPage(page);
54
+
55
+ expect(result).toBe(false);
56
+ expect(logSpy).toHaveBeenCalled();
57
+ });
58
+
59
+ it('| should return false when content is missing', () => {
60
+ const logSpy = spyOn(DyFM_Log, 'error');
61
+ const page = new DyNTS_DAI_DocPage({
62
+ name: 'Test Page',
63
+ content: '',
64
+ documentId: 'doc-123',
65
+ _id: 'page-123',
66
+ parentedPath: [],
67
+ allFlaggedParents: [],
68
+ allFlaggedParentsMerged: '',
69
+ filePath: '',
70
+ });
71
+
72
+ const result = DyNTS_DAI_Document_Util.validateDocumentPage(page);
73
+
74
+ expect(result).toBe(false);
75
+ expect(logSpy).toHaveBeenCalled();
76
+ });
77
+ });
78
+
79
+ describe('| normalizeContent', () => {
80
+ it('| should normalize line endings from CRLF to LF', () => {
81
+ const content = 'Line 1\r\nLine 2\r\nLine 3';
82
+ const result = DyNTS_DAI_Document_Util.normalizeContent(content);
83
+
84
+ expect(result).toBe('Line 1\nLine 2\nLine 3');
85
+ });
86
+
87
+ it('| should normalize line endings from CR to LF', () => {
88
+ const content = 'Line 1\rLine 2\rLine 3';
89
+ const result = DyNTS_DAI_Document_Util.normalizeContent(content);
90
+
91
+ expect(result).toBe('Line 1\nLine 2\nLine 3');
92
+ });
93
+
94
+ it('| should trim leading and trailing whitespace', () => {
95
+ const content = ' Line 1\nLine 2 ';
96
+ const result = DyNTS_DAI_Document_Util.normalizeContent(content);
97
+
98
+ expect(result).toBe('Line 1\nLine 2');
99
+ });
100
+
101
+ it('| should handle mixed line endings', () => {
102
+ const content = 'Line 1\r\nLine 2\rLine 3\nLine 4';
103
+ const result = DyNTS_DAI_Document_Util.normalizeContent(content);
104
+
105
+ expect(result).toBe('Line 1\nLine 2\nLine 3\nLine 4');
106
+ });
107
+ });
108
+
109
+ describe('| extractMetadata', () => {
110
+ it('| should extract title from first header', () => {
111
+ const content = '# Title\n\nContent here';
112
+ const result = DyNTS_DAI_Document_Util.extractMetadata(content);
113
+
114
+ expect(result.title).toBe('Title');
115
+ });
116
+
117
+ it('| should extract word count', () => {
118
+ const content = 'This is a test content with multiple words';
119
+ const result = DyNTS_DAI_Document_Util.extractMetadata(content);
120
+
121
+ // Content.split(/\s+/) returns 8 words: "This", "is", "a", "test", "content", "with", "multiple", "words"
122
+ expect(result.wordCount).toBe(8);
123
+ });
124
+
125
+ it('| should extract character count', () => {
126
+ const content = 'Test content';
127
+ const result = DyNTS_DAI_Document_Util.extractMetadata(content);
128
+
129
+ expect(result.characterCount).toBe(content.length);
130
+ });
131
+
132
+ it('| should extract header count', () => {
133
+ const content = '# Header 1\n## Header 2\n### Header 3';
134
+ const result = DyNTS_DAI_Document_Util.extractMetadata(content);
135
+
136
+ expect(result.headerCount).toBe(3);
137
+ });
138
+
139
+ it('| should return 0 header count when no headers', () => {
140
+ const content = 'Just plain text without headers';
141
+ const result = DyNTS_DAI_Document_Util.extractMetadata(content);
142
+
143
+ expect(result.headerCount).toBe(0);
144
+ });
145
+
146
+ it('| should extract all metadata fields', () => {
147
+ const content = '# Document Title\n\nThis is the content of the document.';
148
+ const result = DyNTS_DAI_Document_Util.extractMetadata(content);
149
+
150
+ expect(result.title).toBe('Document Title');
151
+ expect(result.wordCount).toBeGreaterThan(0);
152
+ expect(result.characterCount).toBeGreaterThan(0);
153
+ expect(result.headerCount).toBe(1);
154
+ });
155
+ });
156
+
157
+ describe('| isEmpty', () => {
158
+ it('| should return true for empty string', () => {
159
+ expect(DyNTS_DAI_Document_Util.isEmpty('')).toBe(true);
160
+ });
161
+
162
+ it('| should return true for whitespace only', () => {
163
+ expect(DyNTS_DAI_Document_Util.isEmpty(' \n\t ')).toBe(true);
164
+ });
165
+
166
+ it('| should return false for content with text', () => {
167
+ expect(DyNTS_DAI_Document_Util.isEmpty('Some content')).toBe(false);
168
+ });
169
+
170
+ it('| should return true for null or undefined', () => {
171
+ expect(DyNTS_DAI_Document_Util.isEmpty(null as any)).toBe(true);
172
+ expect(DyNTS_DAI_Document_Util.isEmpty(undefined as any)).toBe(true);
173
+ });
174
+ });
175
+
176
+ describe('| getPreview', () => {
177
+ it('| should return full content when shorter than maxLength', () => {
178
+ const content = 'Short content';
179
+ const result = DyNTS_DAI_Document_Util.getPreview(content, 200);
180
+
181
+ expect(result).toBe('Short content');
182
+ });
183
+
184
+ it('| should truncate content when longer than maxLength', () => {
185
+ const content = 'A'.repeat(300);
186
+ const result = DyNTS_DAI_Document_Util.getPreview(content, 200);
187
+
188
+ expect(result.length).toBe(203); // 200 + '...'
189
+ expect(result.endsWith('...')).toBe(true);
190
+ });
191
+
192
+ it('| should use default maxLength of 200', () => {
193
+ const content = 'A'.repeat(250);
194
+ const result = DyNTS_DAI_Document_Util.getPreview(content);
195
+
196
+ expect(result.length).toBe(203); // 200 + '...'
197
+ expect(result.endsWith('...')).toBe(true);
198
+ });
199
+
200
+ it('| should handle exact maxLength', () => {
201
+ const content = 'A'.repeat(200);
202
+ const result = DyNTS_DAI_Document_Util.getPreview(content, 200);
203
+
204
+ expect(result).toBe(content);
205
+ expect(result.endsWith('...')).toBe(false);
206
+ });
207
+ });
208
+ });
209
+