@messenger-box/platform-server 10.0.3-alpha.2 → 10.0.3-alpha.202

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 (303) hide show
  1. package/lib/channels/ack-reactions.d.ts +46 -0
  2. package/lib/channels/ack-reactions.js +48 -0
  3. package/lib/channels/ack-reactions.js.map +1 -0
  4. package/lib/channels/allowlist-match.d.ts +38 -0
  5. package/lib/channels/allowlist-match.js +67 -0
  6. package/lib/channels/allowlist-match.js.map +1 -0
  7. package/lib/channels/channel-config.d.ts +46 -0
  8. package/lib/channels/channel-config.js +63 -0
  9. package/lib/channels/channel-config.js.map +1 -0
  10. package/lib/channels/command-gating.d.ts +47 -0
  11. package/lib/channels/command-gating.js +52 -0
  12. package/lib/channels/command-gating.js.map +1 -0
  13. package/lib/channels/conversation-label.d.ts +23 -0
  14. package/lib/channels/conversation-label.js +43 -0
  15. package/lib/channels/conversation-label.js.map +1 -0
  16. package/lib/channels/index.d.ts +18 -0
  17. package/lib/channels/mention-gating.d.ts +50 -0
  18. package/lib/channels/mention-gating.js +72 -0
  19. package/lib/channels/mention-gating.js.map +1 -0
  20. package/lib/channels/registry.d.ts +23 -0
  21. package/lib/channels/registry.js +282 -0
  22. package/lib/channels/registry.js.map +1 -0
  23. package/lib/channels/sender-identity.d.ts +11 -0
  24. package/lib/channels/sender-identity.js +48 -0
  25. package/lib/channels/sender-identity.js.map +1 -0
  26. package/lib/channels/session.d.ts +63 -0
  27. package/lib/channels/session.js +29 -0
  28. package/lib/channels/session.js.map +1 -0
  29. package/lib/channels/types.d.ts +147 -0
  30. package/lib/channels/types.js +28 -0
  31. package/lib/channels/types.js.map +1 -0
  32. package/lib/channels/typing.d.ts +62 -0
  33. package/lib/channels/typing.js +37 -0
  34. package/lib/channels/typing.js.map +1 -0
  35. package/lib/channels/typing.test.d.ts +1 -0
  36. package/lib/config/env-config.d.ts +7 -0
  37. package/lib/config/env-config.js +21 -1
  38. package/lib/config/env-config.js.map +1 -1
  39. package/lib/constants/default-channel-props.d.ts +11 -0
  40. package/lib/constants/default-channel-props.js +32 -0
  41. package/lib/constants/default-channel-props.js.map +1 -0
  42. package/lib/constants/default-notify-props.js.map +1 -1
  43. package/lib/constants/index.d.ts +1 -0
  44. package/lib/constants/query.constants.js.map +1 -1
  45. package/lib/containers/containers.js +13 -7
  46. package/lib/containers/containers.js.map +1 -1
  47. package/lib/containers/context-services-from-container.d.ts +2 -2
  48. package/lib/containers/context-services-from-container.js +7 -7
  49. package/lib/containers/context-services-from-container.js.map +1 -1
  50. package/lib/gateway/channel-registry.d.ts +10 -0
  51. package/lib/gateway/gateway-service.d.ts +23 -0
  52. package/lib/gateway/index.d.ts +4 -0
  53. package/lib/gateway/message-router.d.ts +20 -0
  54. package/lib/gateway/types.d.ts +270 -0
  55. package/lib/graphql/resolvers/channel-capabilities.d.ts +13 -0
  56. package/lib/graphql/resolvers/channel-capabilities.js +179 -0
  57. package/lib/graphql/resolvers/channel-capabilities.js.map +1 -0
  58. package/lib/graphql/resolvers/channel-member.d.ts +3 -3
  59. package/lib/graphql/resolvers/channel-member.js +30 -5
  60. package/lib/graphql/resolvers/channel-member.js.map +1 -1
  61. package/lib/graphql/resolvers/channel.d.ts +3 -3
  62. package/lib/graphql/resolvers/channel.js +348 -55
  63. package/lib/graphql/resolvers/channel.js.map +1 -1
  64. package/lib/graphql/resolvers/chat-configuration.d.ts +59 -0
  65. package/lib/graphql/resolvers/chat-configuration.js +89 -0
  66. package/lib/graphql/resolvers/chat-configuration.js.map +1 -0
  67. package/lib/graphql/resolvers/extended-token-account.d.ts +3 -32
  68. package/lib/graphql/resolvers/extended-token-account.js +90 -23
  69. package/lib/graphql/resolvers/extended-token-account.js.map +1 -1
  70. package/lib/graphql/resolvers/gateway.d.ts +18 -0
  71. package/lib/graphql/resolvers/index.d.ts +47 -26
  72. package/lib/graphql/resolvers/index.js +1 -1
  73. package/lib/graphql/resolvers/index.js.map +1 -1
  74. package/lib/graphql/resolvers/post-thread.d.ts +2 -3
  75. package/lib/graphql/resolvers/post-thread.js +294 -132
  76. package/lib/graphql/resolvers/post-thread.js.map +1 -1
  77. package/lib/graphql/resolvers/post.d.ts +2 -3
  78. package/lib/graphql/resolvers/post.js +772 -238
  79. package/lib/graphql/resolvers/post.js.map +1 -1
  80. package/lib/graphql/resolvers/reaction.d.ts +3 -3
  81. package/lib/graphql/resolvers/reaction.js +96 -14
  82. package/lib/graphql/resolvers/reaction.js.map +1 -1
  83. package/lib/graphql/resolvers/streaming.d.ts +20 -0
  84. package/lib/graphql/resolvers/streaming.js +147 -0
  85. package/lib/graphql/resolvers/streaming.js.map +1 -0
  86. package/lib/graphql/schema/channel-capabilities.graphql +492 -0
  87. package/lib/graphql/schema/channel-capabilities.graphql.js +1 -0
  88. package/lib/graphql/schema/channel-capabilities.graphql.js.map +1 -0
  89. package/lib/graphql/schema/channel-member.graphql +110 -21
  90. package/lib/graphql/schema/channel-member.graphql.js +1 -1
  91. package/lib/graphql/schema/channel.graphql +465 -24
  92. package/lib/graphql/schema/channel.graphql.js +1 -1
  93. package/lib/graphql/schema/chat-configuration.graphql +77 -0
  94. package/lib/graphql/schema/chat-configuration.graphql.js +1 -0
  95. package/lib/graphql/schema/chat-configuration.graphql.js.map +1 -0
  96. package/lib/graphql/schema/gateway.graphql +363 -0
  97. package/lib/graphql/schema/index.js +2 -2
  98. package/lib/graphql/schema/index.js.map +1 -1
  99. package/lib/graphql/schema/post-thread.graphql +167 -21
  100. package/lib/graphql/schema/post-thread.graphql.js +1 -1
  101. package/lib/graphql/schema/post.graphql +440 -36
  102. package/lib/graphql/schema/post.graphql.js +1 -1
  103. package/lib/graphql/schema/preferences.graphql +190 -3
  104. package/lib/graphql/schema/preferences.graphql.js +1 -1
  105. package/lib/graphql/schema/reaction.graphql +71 -13
  106. package/lib/graphql/schema/reaction.graphql.js +1 -1
  107. package/lib/graphql/schema/services.graphql +18 -0
  108. package/lib/graphql/schema/streaming.graphql +224 -0
  109. package/lib/graphql/schema/streaming.graphql.js +1 -0
  110. package/lib/graphql/schema/streaming.graphql.js.map +1 -0
  111. package/lib/graphql/schema/users.graphql +76 -13
  112. package/lib/graphql/schema/users.graphql.js +1 -1
  113. package/lib/graphql/schema/workflow-service.graphql +82 -0
  114. package/lib/index.d.ts +3 -1
  115. package/lib/index.js +1 -1
  116. package/lib/index.js.map +1 -1
  117. package/lib/interfaces/index.d.ts +0 -2
  118. package/lib/interfaces/services.d.ts +1 -3
  119. package/lib/migrations/dbMigrations/AddChannelConfigurationsMigration.d.ts +42 -0
  120. package/lib/migrations/dbMigrations/AddChannelConfigurationsMigration.js +60 -0
  121. package/lib/migrations/dbMigrations/AddChannelConfigurationsMigration.js.map +1 -0
  122. package/lib/migrations/dbMigrations/AddChatConfigurationsMigration.d.ts +21 -0
  123. package/lib/migrations/dbMigrations/AddChatConfigurationsMigration.js +30 -0
  124. package/lib/migrations/dbMigrations/AddChatConfigurationsMigration.js.map +1 -0
  125. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.d.ts +17 -0
  126. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js +44 -0
  127. package/lib/migrations/dbMigrations/AddPostsConfigurationsMigration.js.map +1 -0
  128. package/lib/migrations/dbMigrations/index.d.ts +3 -0
  129. package/lib/migrations/index.d.ts +1 -0
  130. package/lib/migrations/mail-template-migration.d.ts +3 -6
  131. package/lib/migrations/mail-template-migration.js +8 -21
  132. package/lib/migrations/mail-template-migration.js.map +1 -1
  133. package/lib/migrations/message-notification-template-migration.d.ts +4 -7
  134. package/lib/migrations/message-notification-template-migration.js +8 -25
  135. package/lib/migrations/message-notification-template-migration.js.map +1 -1
  136. package/lib/module.d.ts +1 -1
  137. package/lib/module.js +3 -10
  138. package/lib/module.js.map +1 -1
  139. package/lib/plugins/ChannelMoleculerService.d.ts +39 -0
  140. package/lib/plugins/ChannelMoleculerService.js +58 -0
  141. package/lib/plugins/ChannelMoleculerService.js.map +1 -0
  142. package/lib/plugins/ExtendedTokenAccountMoleculerService.d.ts +65 -0
  143. package/lib/plugins/ExtendedTokenAccountMoleculerService.js +88 -0
  144. package/lib/plugins/ExtendedTokenAccountMoleculerService.js.map +1 -0
  145. package/lib/plugins/MessengerNotificationMoleculerService.d.ts +52 -0
  146. package/lib/plugins/MessengerNotificationMoleculerService.js +84 -0
  147. package/lib/plugins/MessengerNotificationMoleculerService.js.map +1 -0
  148. package/lib/plugins/PostMoleculerService.d.ts +65 -0
  149. package/lib/plugins/PostMoleculerService.js +87 -0
  150. package/lib/plugins/PostMoleculerService.js.map +1 -0
  151. package/lib/plugins/PostThreadMoleculerService.d.ts +40 -0
  152. package/lib/plugins/PostThreadMoleculerService.js +59 -0
  153. package/lib/plugins/PostThreadMoleculerService.js.map +1 -0
  154. package/lib/plugins/ReactionMoleculerService.d.ts +37 -0
  155. package/lib/plugins/ReactionMoleculerService.js +56 -0
  156. package/lib/plugins/ReactionMoleculerService.js.map +1 -0
  157. package/lib/plugins/index.d.ts +18 -6
  158. package/lib/preferences/permissions/inbox-permission-contribution.js +58 -97
  159. package/lib/preferences/permissions/inbox-permission-contribution.js.map +1 -1
  160. package/lib/preferences/permissions/inbox-roles-permission-overwrite.js +144 -144
  161. package/lib/preferences/permissions/inbox-roles-permission-overwrite.js.map +1 -1
  162. package/lib/preferences/settings/channel-settings.d.ts +39 -0
  163. package/lib/preferences/settings/channel-settings.js +180 -0
  164. package/lib/preferences/settings/channel-settings.js.map +1 -0
  165. package/lib/preferences/settings/chat-settings.d.ts +248 -0
  166. package/lib/preferences/settings/chat-settings.js +1152 -0
  167. package/lib/preferences/settings/chat-settings.js.map +1 -0
  168. package/lib/preferences/settings/index.d.ts +3 -0
  169. package/lib/preferences/settings/messenger-channels-contribution.d.ts +39 -0
  170. package/lib/preferences/settings/messenger-channels-contribution.js +355 -0
  171. package/lib/preferences/settings/messenger-channels-contribution.js.map +1 -0
  172. package/lib/preferences/settings/post-settings.d.ts +16 -0
  173. package/lib/preferences/settings/post-settings.js +75 -3
  174. package/lib/preferences/settings/post-settings.js.map +1 -1
  175. package/lib/services/channel-service.d.ts +215 -34
  176. package/lib/services/channel-service.js +1058 -273
  177. package/lib/services/channel-service.js.map +1 -1
  178. package/lib/services/extended-token-account-service.d.ts +175 -20
  179. package/lib/services/extended-token-account-service.js +636 -56
  180. package/lib/services/extended-token-account-service.js.map +1 -1
  181. package/lib/services/messenger-notification-service.d.ts +177 -17
  182. package/lib/services/messenger-notification-service.js +975 -421
  183. package/lib/services/messenger-notification-service.js.map +1 -1
  184. package/lib/services/post-service.d.ts +245 -18
  185. package/lib/services/post-service.js +1027 -113
  186. package/lib/services/post-service.js.map +1 -1
  187. package/lib/services/post-thread-service.d.ts +153 -6
  188. package/lib/services/post-thread-service.js +475 -9
  189. package/lib/services/post-thread-service.js.map +1 -1
  190. package/lib/services/proxy-services/ChannelProxyService.d.ts +27 -0
  191. package/lib/services/proxy-services/ChannelProxyService.js +31 -0
  192. package/lib/services/proxy-services/ChannelProxyService.js.map +1 -0
  193. package/lib/services/proxy-services/ExtendedTokenAccountProxyService.d.ts +42 -0
  194. package/lib/services/proxy-services/ExtendedTokenAccountProxyService.js +46 -0
  195. package/lib/services/proxy-services/ExtendedTokenAccountProxyService.js.map +1 -0
  196. package/lib/services/proxy-services/MessengerNotificationProxyService.d.ts +44 -0
  197. package/lib/services/proxy-services/MessengerNotificationProxyService.js +54 -0
  198. package/lib/services/proxy-services/MessengerNotificationProxyService.js.map +1 -0
  199. package/lib/services/proxy-services/PostProxyService.d.ts +42 -0
  200. package/lib/services/proxy-services/PostProxyService.js +46 -0
  201. package/lib/services/proxy-services/PostProxyService.js.map +1 -0
  202. package/lib/services/proxy-services/PostThreadProxyService.d.ts +32 -0
  203. package/lib/services/proxy-services/PostThreadProxyService.js +36 -0
  204. package/lib/services/proxy-services/PostThreadProxyService.js.map +1 -0
  205. package/lib/services/proxy-services/ReactionProxyService.d.ts +41 -0
  206. package/lib/services/proxy-services/ReactionProxyService.js +45 -0
  207. package/lib/services/proxy-services/ReactionProxyService.js.map +1 -0
  208. package/lib/services/proxy-services/index.d.ts +17 -5
  209. package/lib/services/reaction-service.d.ts +124 -4
  210. package/lib/services/reaction-service.js +413 -3
  211. package/lib/services/reaction-service.js.map +1 -1
  212. package/lib/store/models/account-token-store.d.ts +1 -1
  213. package/lib/store/models/account-token-store.js.map +1 -1
  214. package/lib/store/models/channel.d.ts +2 -3
  215. package/lib/store/models/channel.js +216 -70
  216. package/lib/store/models/channel.js.map +1 -1
  217. package/lib/store/models/post-thread.d.ts +3 -3
  218. package/lib/store/models/post-thread.js +96 -14
  219. package/lib/store/models/post-thread.js.map +1 -1
  220. package/lib/store/models/post.d.ts +2 -3
  221. package/lib/store/models/post.js +143 -23
  222. package/lib/store/models/post.js.map +1 -1
  223. package/lib/store/models/reaction.d.ts +2 -3
  224. package/lib/store/models/reaction.js +67 -8
  225. package/lib/store/models/reaction.js.map +1 -1
  226. package/lib/store/repositories/__tests__/__fixtures__/team-repository.d.ts +3 -3
  227. package/lib/store/repositories/channel-repository.d.ts +6 -6
  228. package/lib/store/repositories/channel-repository.js +5 -2
  229. package/lib/store/repositories/channel-repository.js.map +1 -1
  230. package/lib/store/repositories/post-repository.d.ts +6 -6
  231. package/lib/store/repositories/post-repository.js +5 -2
  232. package/lib/store/repositories/post-repository.js.map +1 -1
  233. package/lib/store/repositories/post-thread-repository.d.ts +6 -6
  234. package/lib/store/repositories/post-thread-repository.js +5 -2
  235. package/lib/store/repositories/post-thread-repository.js.map +1 -1
  236. package/lib/store/repositories/reaction-repository.d.ts +6 -6
  237. package/lib/store/repositories/reaction-repository.js +5 -2
  238. package/lib/store/repositories/reaction-repository.js.map +1 -1
  239. package/lib/streaming/block-chunker.d.ts +40 -0
  240. package/lib/streaming/block-chunker.js +103 -0
  241. package/lib/streaming/block-chunker.js.map +1 -0
  242. package/lib/streaming/block-chunker.test.d.ts +1 -0
  243. package/lib/streaming/index.d.ts +4 -0
  244. package/lib/streaming/stream-service.d.ts +71 -0
  245. package/lib/streaming/stream-service.js +325 -0
  246. package/lib/streaming/stream-service.js.map +1 -0
  247. package/lib/streaming/stream-service.test.d.ts +16 -0
  248. package/lib/streaming/streaming-post.integration.test.d.ts +10 -0
  249. package/lib/streaming/types.d.ts +33 -0
  250. package/lib/streaming/types.js +37 -0
  251. package/lib/streaming/types.js.map +1 -0
  252. package/lib/templates/constants/CONTRIBUTION_POINTS.ts.template +78 -0
  253. package/lib/templates/constants/SERVER_TYPES.ts.template +1 -4
  254. package/lib/templates/constants/WorkflowNamespace.ts.template +10 -0
  255. package/lib/templates/repositories/ChannelRepository.ts.template +3 -3
  256. package/lib/templates/repositories/PostRepository.ts.template +3 -3
  257. package/lib/templates/repositories/PostThreadRepository.ts.template +3 -3
  258. package/lib/templates/repositories/ReactionRepository.ts.template +3 -4
  259. package/lib/templates/services/ChannelService.ts.template +290 -39
  260. package/lib/templates/services/ExtendedTokenAccountService.ts.template +107 -3
  261. package/lib/templates/services/MessengerNotificationService.ts.template +94 -19
  262. package/lib/templates/services/MessengerStreamService.ts.template +131 -0
  263. package/lib/templates/services/PostService.ts.template +228 -20
  264. package/lib/templates/services/PostThreadService.ts.template +151 -6
  265. package/lib/templates/services/ReactionService.ts.template +129 -3
  266. package/lib/templates/services/RedisCacheManager.ts.template +22 -0
  267. package/package.json +10 -6
  268. package/lib/interfaces/context.d.ts +0 -14
  269. package/lib/plugins/channel-moleculer-service.d.ts +0 -8
  270. package/lib/plugins/channel-moleculer-service.js +0 -129
  271. package/lib/plugins/channel-moleculer-service.js.map +0 -1
  272. package/lib/plugins/extended-token-account-moleculer-service.d.ts +0 -8
  273. package/lib/plugins/extended-token-account-moleculer-service.js +0 -47
  274. package/lib/plugins/extended-token-account-moleculer-service.js.map +0 -1
  275. package/lib/plugins/messenger-notification-moleculer-service.d.ts +0 -9
  276. package/lib/plugins/messenger-notification-moleculer-service.js +0 -116
  277. package/lib/plugins/messenger-notification-moleculer-service.js.map +0 -1
  278. package/lib/plugins/post-moleculer-service.d.ts +0 -35
  279. package/lib/plugins/post-moleculer-service.js +0 -393
  280. package/lib/plugins/post-moleculer-service.js.map +0 -1
  281. package/lib/plugins/post-thread-moleculer-service.d.ts +0 -8
  282. package/lib/plugins/post-thread-moleculer-service.js +0 -33
  283. package/lib/plugins/post-thread-moleculer-service.js.map +0 -1
  284. package/lib/plugins/reaction-moleculer-service.d.ts +0 -8
  285. package/lib/plugins/reaction-moleculer-service.js +0 -20
  286. package/lib/plugins/reaction-moleculer-service.js.map +0 -1
  287. package/lib/services/proxy-services/channel-microservice.d.ts +0 -44
  288. package/lib/services/proxy-services/channel-microservice.js +0 -199
  289. package/lib/services/proxy-services/channel-microservice.js.map +0 -1
  290. package/lib/services/proxy-services/messenger-notification-microservice.d.ts +0 -16
  291. package/lib/services/proxy-services/messenger-notification-microservice.js +0 -54
  292. package/lib/services/proxy-services/messenger-notification-microservice.js.map +0 -1
  293. package/lib/services/proxy-services/post-microservice.d.ts +0 -22
  294. package/lib/services/proxy-services/post-microservice.js +0 -64
  295. package/lib/services/proxy-services/post-microservice.js.map +0 -1
  296. package/lib/services/proxy-services/post-thread-microservice.d.ts +0 -10
  297. package/lib/services/proxy-services/post-thread-microservice.js +0 -15
  298. package/lib/services/proxy-services/post-thread-microservice.js.map +0 -1
  299. package/lib/services/proxy-services/reaction-microservice.d.ts +0 -9
  300. package/lib/services/proxy-services/reaction-microservice.js +0 -10
  301. package/lib/services/proxy-services/reaction-microservice.js.map +0 -1
  302. package/lib/store/models/common-options.js +0 -20
  303. package/lib/store/models/common-options.js.map +0 -1
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Messenger Stream Service Interface
3
+ * -----------------------------------
4
+ *
5
+ * This interface defines the service layer for real-time AI/LLM response streaming
6
+ * within the messenger platform. It bridges LLM token output to GraphQL PubSub,
7
+ * providing delta accumulation, throttling, and optional block chunking.
8
+ *
9
+ * Key capabilities:
10
+ * - Stream lifecycle management (start, push, end, cancel, error)
11
+ * - Delta accumulation with monotonic sequence numbering
12
+ * - 150ms delta coalescing (throttled publish)
13
+ * - Optional block chunking for messaging channels (Telegram, Slack, etc.)
14
+ * - PubSub integration for GraphQL subscription delivery
15
+ *
16
+ * Inspired by openclaw's agent-events + server-chat + BlockChunker orchestration.
17
+ */
18
+
19
+ import {
20
+ IMessengerStreamDelta,
21
+ IMessengerStreamStatusEvent,
22
+ IMessengerStreamBlock,
23
+ IMessengerStartStreamInput,
24
+ IMessengerPushDeltaInput,
25
+ IMessengerStreamStartResult,
26
+ MessengerStreamStatus,
27
+ Disposable,
28
+ } from 'common/server';
29
+
30
+ /**
31
+ * Coalesce configuration for block chunking — controls when buffered text
32
+ * is flushed to subscribers as a block.
33
+ */
34
+ export interface IBlockCoalesceConfig {
35
+ /** Minimum characters before flushing a block */
36
+ minChars: number;
37
+ /** Idle time (ms) before flushing whatever is buffered */
38
+ idleMs: number;
39
+ }
40
+
41
+ /**
42
+ * Extended start stream params with server-side fields.
43
+ */
44
+ export interface IStartStreamParams extends IMessengerStartStreamInput {
45
+ /** Generated unique run ID for this stream */
46
+ runId: string;
47
+ /** Custom coalesce config (from channel dock settings) */
48
+ coalesceConfig?: Partial<IBlockCoalesceConfig>;
49
+ }
50
+
51
+ /**
52
+ * Active stream state snapshot (returned by getStreamState).
53
+ */
54
+ export interface IStreamState {
55
+ runId: string;
56
+ channelId: string;
57
+ threadId?: string;
58
+ postId?: string;
59
+ seq: number;
60
+ text: string;
61
+ status: MessengerStreamStatus;
62
+ }
63
+
64
+ /**
65
+ * Stream completion event — emitted when endStream() completes successfully.
66
+ * Bridges ephemeral streaming pipeline to persistent post storage.
67
+ */
68
+ export interface IStreamCompleteEvent {
69
+ runId: string;
70
+ channelId: string;
71
+ threadId?: string;
72
+ postId?: string;
73
+ /** The full accumulated text from the stream */
74
+ text: string;
75
+ }
76
+
77
+ /** Handler type for stream completion callbacks. */
78
+ export type StreamCompleteHandler = (event: IStreamCompleteEvent) => Promise<void>;
79
+
80
+ /**
81
+ * Service interface for managing AI/LLM response streaming.
82
+ */
83
+ export interface IMessengerStreamService extends Disposable {
84
+ /**
85
+ * Set the PubSub instance. Called during resolver initialization
86
+ * since PubSub comes from IResolverOptions, not from DI container.
87
+ */
88
+ setPubSub(pubsub: any): void;
89
+
90
+ /**
91
+ * Register a handler called when a stream completes.
92
+ * Used by PostService to finalize streamed content into a Post record.
93
+ */
94
+ onStreamComplete(handler: StreamCompleteHandler): void;
95
+
96
+ /**
97
+ * Start a new stream. Call this when an AI/LLM response begins.
98
+ */
99
+ startStream(params: IStartStreamParams): Promise<void>;
100
+
101
+ /**
102
+ * Push a text delta into an active stream.
103
+ * Call for each token/chunk received from the LLM provider.
104
+ */
105
+ pushDelta(runId: string, delta: string): Promise<void>;
106
+
107
+ /**
108
+ * End a stream successfully. Flushes any pending data.
109
+ */
110
+ endStream(runId: string): Promise<void>;
111
+
112
+ /**
113
+ * Cancel a stream. Discards pending data.
114
+ */
115
+ cancelStream(runId: string): Promise<void>;
116
+
117
+ /**
118
+ * Error a stream.
119
+ */
120
+ errorStream(runId: string, error: string): Promise<void>;
121
+
122
+ /**
123
+ * Get the current state of an active stream (for reconnection / catch-up).
124
+ */
125
+ getStreamState(runId: string): IStreamState | undefined;
126
+
127
+ /**
128
+ * Dispose / cleanup the service.
129
+ */
130
+ dispose(): void;
131
+ }
@@ -1,42 +1,250 @@
1
- import { IBaseService } from '@common-stack/store-mongo';
2
- import { IFileInfo, IMessageIdentifier, IPost, IPostThread, IThreadMessageInput, IUploadedFileInput } from 'common';
1
+ /**
2
+ * Post Service Interface
3
+ * ----------------------
4
+ *
5
+ * This interface defines the business logic layer for post and message management
6
+ * within the messenger platform. It provides comprehensive operations for handling
7
+ * messages, file attachments, threading, and message state management across
8
+ * different channels and communication contexts.
9
+ *
10
+ * Key capabilities:
11
+ * - Post lifecycle management (creation, updates, deletion)
12
+ * - File upload and attachment handling (single and batch operations)
13
+ * - Message threading and conversation management
14
+ * - Message delivery and read status tracking
15
+ * - File management and cleanup operations
16
+ * - Cross-channel message coordination
17
+ * - Post-thread relationship management
18
+ * - Message state synchronization
19
+ *
20
+ * The service layer abstracts complex messaging operations and provides a
21
+ * cohesive API for post-related functionality throughout the messaging platform,
22
+ * handling file storage, threading logic, and message state consistency.
23
+ */
3
24
 
4
- export interface IPostServiceInput extends Omit<IPost, 'id' | 'files' | 'isRead' | 'isDelivered'> {
25
+ import {
26
+ IFileInfo,
27
+ IMessageIdentifier,
28
+ IPost,
29
+ IPostModel,
30
+ IPostThread,
31
+ IThreadMessageInput,
32
+ IUploadedFileInput,
33
+ Disposable,
34
+ AsDomainType,
35
+ IBaseService,
36
+ IFileUpdateResponse
37
+ } from 'common/server';
38
+
39
+ /**
40
+ * Code Agent Request Interface
41
+ *
42
+ * @description Input parameters for code agent operations,
43
+ * containing project details and configuration.
44
+ */
45
+ // export enum AiAgentMessageRole {
46
+ // USER = 'USER',
47
+ // ASSISTANT = 'ASSISTANT',
48
+ // }
49
+
50
+ // export enum AiAgentMessageType {
51
+ // RESULT = 'RESULT',
52
+ // ERROR = 'ERROR',
53
+ // }
54
+
55
+
56
+ /**
57
+ * Post Service Input Interface
58
+ *
59
+ * @description Input parameters for post creation operations,
60
+ * excluding auto-generated and system-managed fields.
61
+ */
62
+ export interface IPostServiceInput extends Omit<IPostModel, 'id' | 'files' | 'isRead' | 'isDelivered' | '_id'> {
63
+ /** Array of file identifiers to attach to the post */
5
64
  files: string[];
65
+ /** Optional MongoDB ObjectId for the post */
6
66
  _id?: any;
7
67
  }
8
68
 
69
+ /**
70
+ * Post Thread Creation Options
71
+ *
72
+ * @description Configuration parameters for creating posts with associated threads.
73
+ */
9
74
  export type CreatePostThreadOptions = {
75
+ /** Thread message input data */
10
76
  threadMessageInput: IThreadMessageInput;
77
+ /** Channel identifier where the post will be created */
11
78
  channelId: string;
79
+ /** Optional responder user identifier */
12
80
  responderId?: string;
81
+ /** Optional parent post identifier for threading */
13
82
  postParentId?: string;
83
+ /** Optional existing post identifier */
14
84
  postId?: string;
85
+ /** Account identifier of the post creator */
15
86
  accountId: string;
87
+ /** Optional organization identifier */
16
88
  orgId?: string;
89
+ /** Optional existing post thread identifier */
17
90
  postThreadId?: string;
18
91
  };
19
92
 
20
- export interface IPostService extends IBaseService<IPost, IPostServiceInput, Partial<IPost>> {
21
- createFileUploadLink(postId: string, filename: string, userId: string): Promise<string>;
22
- attachUploadedFile(postId: string, file: IUploadedFileInput, createdBy: string): Promise<IFileInfo>;
93
+ /**
94
+ * Post Service Interface
95
+ *
96
+ * @description Provides comprehensive post and message management capabilities
97
+ * including file handling, threading, and message state management.
98
+ */
99
+ export interface IPostService extends IBaseService<IPostModel, IPostServiceInput, Partial<IPostModel>>, Disposable {
100
+ /**
101
+ * Creates a file upload link for a specific post
102
+ *
103
+ * @description Generates a secure upload URL for attaching a single file
104
+ * to an existing post, handling authentication and storage permissions.
105
+ *
106
+ * @param {string} postId - The unique identifier of the post
107
+ * @param {string} filename - The name of the file to upload
108
+ * @param {string} userId - The identifier of the user performing the upload
109
+ * @returns {Promise<string | Error>} - Upload URL or error
110
+ */
111
+ createFileUploadLink(postId: string, filename: string, userId: string): Promise<string | Error>;
112
+
113
+ /**
114
+ * Attaches an uploaded file to a post
115
+ *
116
+ * @description Associates a successfully uploaded file with a post,
117
+ * updating the post's file attachments and metadata.
118
+ *
119
+ * @param {string} postId - The unique identifier of the post
120
+ * @param {IUploadedFileInput} file - The uploaded file information
121
+ * @param {string} createdBy - The identifier of the user who uploaded the file
122
+ * @returns {Promise<IFileInfo | Error>} - File information or error
123
+ */
124
+ attachUploadedFile(postId: string, file: IUploadedFileInput, createdBy: string): Promise<IFileInfo | Error>;
125
+
126
+ /**
127
+ * Creates multiple file upload links for a post
128
+ *
129
+ * @description Generates secure upload URLs for attaching multiple files
130
+ * to an existing post in a single operation.
131
+ *
132
+ * @param {string} postId - The unique identifier of the post
133
+ * @param {string[]} filenames - Array of file names to upload
134
+ * @param {string} userId - The identifier of the user performing the upload
135
+ * @returns {Promise<string[] | Error>} - Array of upload URLs or error
136
+ */
137
+ createFilesUploadLink(postId: string, filenames: string[], userId: string): Promise<string[] | Error>;
138
+
139
+ /**
140
+ * Attaches multiple uploaded files to a post
141
+ *
142
+ * @description Associates multiple successfully uploaded files with a post
143
+ * in a single batch operation, optimizing performance and consistency.
144
+ *
145
+ * @param {string} postId - The unique identifier of the post
146
+ * @param {IUploadedFileInput[]} files - Array of uploaded file information
147
+ * @param {string} createdBy - The identifier of the user who uploaded the files
148
+ * @returns {Promise<IFileInfo[] | Error>} - Array of file information or error
149
+ */
150
+ attachUploadedFiles(postId: string, files: IUploadedFileInput[], createdBy: string): Promise<IFileInfo[] | Error>;
151
+
152
+ /**
153
+ * Deletes a file from storage
154
+ *
155
+ * @description Permanently removes a file from the storage system,
156
+ * typically used for cleanup or when files are no longer needed.
157
+ *
158
+ * @param {string} url - The URL or identifier of the file to delete
159
+ * @returns {Promise<boolean | Error>} - Success status or error
160
+ */
161
+ deleteFile(url: string): Promise<boolean | Error>;
162
+
163
+ /**
164
+ * Marks a message as read by a user
165
+ *
166
+ * @description Updates the read status of a message for a specific user,
167
+ * affecting unread counts and notification states.
168
+ *
169
+ * @param {IMessageIdentifier} messageId - The message identifier
170
+ * @param {string} user - The identifier of the user marking the message as read
171
+ * @returns {Promise<boolean | Error>} - Success status or error
172
+ */
173
+ readMessage(messageId: IMessageIdentifier, user: string): Promise<boolean | Error>;
174
+
175
+ /**
176
+ * Marks a message as delivered to a user
177
+ *
178
+ * @description Updates the delivery status of a message, indicating
179
+ * successful delivery to the target user's device or client.
180
+ *
181
+ * @param {IMessageIdentifier} messageId - The message identifier
182
+ * @param {string} user - The identifier of the user who received the message
183
+ * @returns {Promise<boolean | Error>} - Success status or error
184
+ */
185
+ deliverMessage(messageId: IMessageIdentifier, user: string): Promise<boolean | Error>;
186
+
187
+ /**
188
+ * Creates a post without triggering subscriptions
189
+ *
190
+ * @description Creates a new post while bypassing real-time subscription
191
+ * notifications, useful for bulk operations or system-generated content.
192
+ *
193
+ * @param {IPostServiceInput} data - The post creation data
194
+ * @returns {Promise<AsDomainType<IPostModel> | Error>} - Created post or error
195
+ */
196
+ createWithoutSubscription(data: IPostServiceInput): Promise<AsDomainType<IPostModel> | Error>;
23
197
 
24
- createFilesUploadLink(postId: string, filenames: string[], userId: string): Promise<string[]>;
25
- attachUploadedFiles(postId: string, files: IUploadedFileInput[], createdBy: string): Promise<IFileInfo[]>;
198
+ /**
199
+ * Creates a post with an associated thread
200
+ *
201
+ * @description Creates both a post and its associated thread in a single
202
+ * transaction, ensuring data consistency and proper relationship setup.
203
+ *
204
+ * @param {CreatePostThreadOptions} options - The post and thread creation options
205
+ * @returns {Promise<{ post: AsDomainType<IPostModel>; postThread: IPostThread } | Error>} - Created post and thread or error
206
+ */
207
+ createPostWithPostThread(options: CreatePostThreadOptions): Promise<{ post: AsDomainType<IPostModel>; postThread: IPostThread } | Error>;
26
208
 
27
- deleteFile(url: string): Promise<boolean>;
209
+ /**
210
+ * Retrieves the most recent message from a channel
211
+ *
212
+ * @description Fetches the latest post/message from a specific channel,
213
+ * useful for displaying channel previews and recent activity.
214
+ *
215
+ * @param {string} channelId - The unique identifier of the channel
216
+ * @returns {Promise<AsDomainType<IPostModel> | Error>} - Latest message or error
217
+ */
218
+ getLastMessage(channelId: string): Promise<AsDomainType<IPostModel> | Error>;
28
219
 
29
- readMessage(messageId: IMessageIdentifier, user: string): Promise<boolean>;
220
+ /**
221
+ * Retrieves previous messages from a channel
222
+ *
223
+ * @description Fetches a specified number of recent messages from a channel,
224
+ * formatted for display with associated file attachments. Returns messages
225
+ * in reverse chronological order (newest to oldest).
226
+ *
227
+ * @param {string} channelId - The unique identifier of the channel
228
+ * @param {number} limit - Maximum number of messages to retrieve (default: 5)
229
+ * @returns {Promise<Array<IPostModel> | Error>} - Array of formatted messages or error
230
+ */
231
+ getPreviousMessagesByProjectId(projectId: string, limit?: number): Promise<Array<IPostModel> | Error>;
30
232
 
31
- deliverMessage(messageId: IMessageIdentifier, user: string): Promise<boolean>;
32
- createWithoutSubscription(data: IPostServiceInput): Promise<IPost>;
233
+ /**
234
+ * Finalize a streamed post — creates or updates a Post with the accumulated
235
+ * text from a completed stream. Bridges streaming pipeline to persistent storage.
236
+ *
237
+ * @param event - The stream completion event containing final text and routing info
238
+ * @param authorId - The author (user/agent) who generated the streamed content
239
+ * @returns The created or updated post, or undefined on error
240
+ */
241
+ finalizeStreamedPost(
242
+ event: { runId: string; channelId: string; threadId?: string; postId?: string; text: string },
243
+ authorId?: string,
244
+ ): Promise<AsDomainType<IPostModel> | undefined>;
33
245
 
34
- createPostWithPostThread({
35
- threadMessageInput,
36
- channelId,
37
- responderId,
38
- postParentId,
39
- postId,
40
- accountId,
41
- }: CreatePostThreadOptions): Promise<{ post: IPost; postThread: IPostThread }>;
246
+ /**
247
+ * Disposes of resources used by the service
248
+ */
249
+ dispose(): void;
42
250
  }
@@ -1,10 +1,155 @@
1
- import { IPostThread } from 'common';
2
- import { IBaseService } from '@common-stack/store-mongo';
1
+ /**
2
+ * Post Thread Service Interface
3
+ * -----------------------------
4
+ *
5
+ * This interface defines the business logic layer for post thread management
6
+ * within the messenger platform. It provides comprehensive operations for handling
7
+ * threaded conversations, reply management, and discussion organization across
8
+ * different channels and messaging contexts.
9
+ *
10
+ * Key capabilities:
11
+ * - Thread lifecycle management (creation, updates, deletion)
12
+ * - Reply and response tracking within threads
13
+ * - Thread participant management and notifications
14
+ * - Thread statistics and metrics collection
15
+ * - Nested conversation organization
16
+ * - Thread visibility and access control
17
+ * - Cross-channel thread coordination
18
+ * - Thread state synchronization
19
+ *
20
+ * The service layer abstracts complex threading operations and provides a
21
+ * cohesive API for thread-related functionality throughout the messaging platform,
22
+ * handling conversation hierarchies, participant tracking, and thread state management.
23
+ */
3
24
 
4
- export interface IPostThreadServiceInput extends Omit<IPostThread, 'id'> {}
25
+ import { IPostThreadModel, Disposable, AsDomainType,IBaseService } from 'common/server';
5
26
 
6
- // export type IPostThreadService = IBaseService<IPostThread>;
7
27
 
8
- export interface IPostThreadService extends IBaseService<IPostThread> {
9
- getPostThread(data: any): Promise<IPostThread>;
28
+ /**
29
+ * Post Thread Service Input Interface
30
+ *
31
+ * @description Input parameters for post thread creation and update operations,
32
+ * excluding auto-generated fields like ID. Used for operations that modify
33
+ * thread data before it becomes a domain object.
34
+ */
35
+ export interface IPostThreadServiceInput extends Omit<IPostThreadModel, 'id'> {
36
+ // Add any additional input-specific fields here if needed
37
+ }
38
+
39
+ /**
40
+ * Post Thread Service Interface
41
+ *
42
+ * @description Provides comprehensive post thread management capabilities
43
+ * including thread creation, participant tracking, and conversation organization.
44
+ * All operations return domain objects wrapped with AsDomainType for consistency.
45
+ */
46
+ export interface IPostThreadService extends IBaseService<IPostThreadModel>, Disposable {
47
+ /**
48
+ * Retrieves a specific post thread with its metadata
49
+ *
50
+ * @description Fetches a complete post thread including all replies,
51
+ * participant information, and thread statistics for display and interaction.
52
+ *
53
+ * @param {string} threadId - The ID of the thread to retrieve
54
+ * @returns {Promise<AsDomainType<IPostThreadModel> | Error>} - Post thread data or error
55
+ */
56
+ getPostThread(threadId: string): Promise<AsDomainType<IPostThreadModel> | Error>;
57
+
58
+ /**
59
+ * Retrieves the total count of posts within a thread
60
+ *
61
+ * @description Calculates and returns the number of posts/replies
62
+ * within a specific thread for pagination and display purposes.
63
+ *
64
+ * @param {string} threadId - The ID of the thread to count posts for
65
+ * @returns {Promise<number | Error>} - Thread post count or error
66
+ */
67
+ getPostThreadCount(threadId: string): Promise<number | Error>;
68
+
69
+ /**
70
+ * Updates a post thread
71
+ *
72
+ * @description Updates the specified thread with new data while maintaining
73
+ * thread integrity and participant notifications.
74
+ *
75
+ * @param {string} threadId - The ID of the thread to update
76
+ * @param {Partial<IPostThreadServiceInput>} updates - The updates to apply
77
+ * @returns {Promise<AsDomainType<IPostThreadModel> | Error>} - Updated thread or error
78
+ */
79
+ updateThread(threadId: string, updates: Partial<IPostThreadServiceInput>): Promise<AsDomainType<IPostThreadModel> | Error>;
80
+
81
+ /**
82
+ * Deletes a post thread
83
+ *
84
+ * @description Soft deletes a thread while maintaining data integrity
85
+ * and notifying participants.
86
+ *
87
+ * @param {string} threadId - The ID of the thread to delete
88
+ * @returns {Promise<boolean | Error>} - Success status or error
89
+ */
90
+ deleteThread(threadId: string): Promise<boolean | Error>;
91
+
92
+ /**
93
+ * Gets threads by post ID
94
+ *
95
+ * @description Retrieves all threads associated with a specific post,
96
+ * useful for viewing conversation context.
97
+ *
98
+ * @param {string} postId - The ID of the post
99
+ * @returns {Promise<Array<AsDomainType<IPostThreadModel>> | Error>} - Array of threads or error
100
+ */
101
+ getThreadsByPost(postId: string): Promise<Array<AsDomainType<IPostThreadModel>> | Error>;
102
+
103
+ /**
104
+ * Gets threads by channel with pagination
105
+ *
106
+ * @description Retrieves paginated threads for a specific channel,
107
+ * ordered by relevance or time.
108
+ *
109
+ * @param {string} channelId - The ID of the channel
110
+ * @param {number} [limit] - Maximum number of threads to return
111
+ * @param {number} [offset] - Number of threads to skip
112
+ * @returns {Promise<Array<AsDomainType<IPostThreadModel>> | Error>} - Array of threads or error
113
+ */
114
+ getThreadsByChannel(channelId: string, limit?: number, offset?: number): Promise<Array<AsDomainType<IPostThreadModel>> | Error>;
115
+
116
+ /**
117
+ * Gets thread participants
118
+ *
119
+ * @description Retrieves all participants in a thread, including
120
+ * their participation status and roles.
121
+ *
122
+ * @param {string} threadId - The ID of the thread
123
+ * @returns {Promise<Array<string> | Error>} - Array of participant IDs or error
124
+ */
125
+ getThreadParticipants(threadId: string): Promise<Array<string> | Error>;
126
+
127
+ /**
128
+ * Adds a participant to a thread
129
+ *
130
+ * @description Adds a user as a participant to a thread,
131
+ * enabling notifications and access.
132
+ *
133
+ * @param {string} threadId - The ID of the thread
134
+ * @param {string} userId - The ID of the user to add
135
+ * @returns {Promise<boolean | Error>} - Success status or error
136
+ */
137
+ addParticipant(threadId: string, userId: string): Promise<boolean | Error>;
138
+
139
+ /**
140
+ * Removes a participant from a thread
141
+ *
142
+ * @description Removes a user's participation from a thread,
143
+ * updating notifications and access accordingly.
144
+ *
145
+ * @param {string} threadId - The ID of the thread
146
+ * @param {string} userId - The ID of the user to remove
147
+ * @returns {Promise<boolean | Error>} - Success status or error
148
+ */
149
+ removeParticipant(threadId: string, userId: string): Promise<boolean | Error>;
150
+
151
+ /**
152
+ * Disposes of resources used by the service
153
+ */
154
+ dispose(): void;
10
155
  }