@memberjunction/core-entities 6.3.0-edge.0 → 6.3.0-edge.2

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 (193) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/custom/AnchoredConversationSecurity.d.ts +10 -1
  3. package/dist/custom/AnchoredConversationSecurity.d.ts.map +1 -1
  4. package/dist/custom/AnchoredConversationSecurity.js +15 -0
  5. package/dist/custom/AnchoredConversationSecurity.js.map +1 -1
  6. package/dist/custom/ArtifactLockValidation.d.ts +28 -0
  7. package/dist/custom/ArtifactLockValidation.d.ts.map +1 -0
  8. package/dist/custom/ArtifactLockValidation.js +867 -0
  9. package/dist/custom/ArtifactLockValidation.js.map +1 -0
  10. package/dist/custom/ArtifactPermissionDelegate.d.ts +288 -0
  11. package/dist/custom/ArtifactPermissionDelegate.d.ts.map +1 -0
  12. package/dist/custom/ArtifactPermissionDelegate.js +1779 -0
  13. package/dist/custom/ArtifactPermissionDelegate.js.map +1 -0
  14. package/dist/custom/ArtifactPreviewSnapshot.d.ts +199 -0
  15. package/dist/custom/ArtifactPreviewSnapshot.d.ts.map +1 -0
  16. package/dist/custom/ArtifactPreviewSnapshot.js +772 -0
  17. package/dist/custom/ArtifactPreviewSnapshot.js.map +1 -0
  18. package/dist/custom/ArtifactSynthesisEngine.d.ts +151 -0
  19. package/dist/custom/ArtifactSynthesisEngine.d.ts.map +1 -0
  20. package/dist/custom/ArtifactSynthesisEngine.js +1124 -0
  21. package/dist/custom/ArtifactSynthesisEngine.js.map +1 -0
  22. package/dist/custom/ConversationWriteAccess.d.ts +36 -0
  23. package/dist/custom/ConversationWriteAccess.d.ts.map +1 -1
  24. package/dist/custom/ConversationWriteAccess.js +109 -1
  25. package/dist/custom/ConversationWriteAccess.js.map +1 -1
  26. package/dist/custom/DocumentLiveBlockEngine.d.ts +612 -0
  27. package/dist/custom/DocumentLiveBlockEngine.d.ts.map +1 -0
  28. package/dist/custom/DocumentLiveBlockEngine.js +2352 -0
  29. package/dist/custom/DocumentLiveBlockEngine.js.map +1 -0
  30. package/dist/custom/MJQueryEntityExtended.d.ts.map +1 -1
  31. package/dist/custom/MJQueryEntityExtended.js +27 -11
  32. package/dist/custom/MJQueryEntityExtended.js.map +1 -1
  33. package/dist/custom/PermissionProviders/ArtifactPermissionProvider.d.ts.map +1 -1
  34. package/dist/custom/PermissionProviders/ArtifactPermissionProvider.js +31 -7
  35. package/dist/custom/PermissionProviders/ArtifactPermissionProvider.js.map +1 -1
  36. package/dist/custom/PermissionProviders/CollectionPermissionProvider.d.ts +3 -4
  37. package/dist/custom/PermissionProviders/CollectionPermissionProvider.d.ts.map +1 -1
  38. package/dist/custom/PermissionProviders/CollectionPermissionProvider.js +334 -47
  39. package/dist/custom/PermissionProviders/CollectionPermissionProvider.js.map +1 -1
  40. package/dist/custom/Permissions/BaseShareEntityExtended.d.ts +28 -3
  41. package/dist/custom/Permissions/BaseShareEntityExtended.d.ts.map +1 -1
  42. package/dist/custom/Permissions/BaseShareEntityExtended.js +150 -13
  43. package/dist/custom/Permissions/BaseShareEntityExtended.js.map +1 -1
  44. package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts +8 -6
  45. package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.d.ts.map +1 -1
  46. package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js +107 -43
  47. package/dist/custom/Permissions/MJArtifactPermissionEntityExtended.js.map +1 -1
  48. package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts +13 -5
  49. package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.d.ts.map +1 -1
  50. package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js +284 -49
  51. package/dist/custom/Permissions/MJCollectionPermissionEntityExtended.js.map +1 -1
  52. package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.d.ts +3 -1
  53. package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.d.ts.map +1 -1
  54. package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.js +83 -19
  55. package/dist/custom/Permissions/MJDashboardPermissionEntityExtended.js.map +1 -1
  56. package/dist/custom/Permissions/shareNotification.d.ts +14 -1
  57. package/dist/custom/Permissions/shareNotification.d.ts.map +1 -1
  58. package/dist/custom/Permissions/shareNotification.js +62 -8
  59. package/dist/custom/Permissions/shareNotification.js.map +1 -1
  60. package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.d.ts.map +1 -1
  61. package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js +120 -38
  62. package/dist/custom/ResourcePermissions/MJResourcePermissionEntityExtended.js.map +1 -1
  63. package/dist/custom/SlideDeckEngine.d.ts +469 -0
  64. package/dist/custom/SlideDeckEngine.d.ts.map +1 -0
  65. package/dist/custom/SlideDeckEngine.js +2168 -0
  66. package/dist/custom/SlideDeckEngine.js.map +1 -0
  67. package/dist/custom/SlideDeckPptxEngine.d.ts +25 -0
  68. package/dist/custom/SlideDeckPptxEngine.d.ts.map +1 -0
  69. package/dist/custom/SlideDeckPptxEngine.js +1311 -0
  70. package/dist/custom/SlideDeckPptxEngine.js.map +1 -0
  71. package/dist/custom/SpreadsheetEngine.d.ts +1377 -0
  72. package/dist/custom/SpreadsheetEngine.d.ts.map +1 -0
  73. package/dist/custom/SpreadsheetEngine.js +17652 -0
  74. package/dist/custom/SpreadsheetEngine.js.map +1 -0
  75. package/dist/custom/approvals.d.ts +31 -1
  76. package/dist/custom/approvals.d.ts.map +1 -1
  77. package/dist/custom/approvals.js +42 -2
  78. package/dist/custom/approvals.js.map +1 -1
  79. package/dist/custom/operations/ArtifactComplianceAuditOperation.d.ts +7 -0
  80. package/dist/custom/operations/ArtifactComplianceAuditOperation.d.ts.map +1 -0
  81. package/dist/custom/operations/ArtifactComplianceAuditOperation.js +7 -0
  82. package/dist/custom/operations/ArtifactComplianceAuditOperation.js.map +1 -0
  83. package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.d.ts +7 -0
  84. package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.d.ts.map +1 -0
  85. package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.js +7 -0
  86. package/dist/custom/operations/ArtifactEvaluateAiFormulaOperation.js.map +1 -0
  87. package/dist/custom/operations/ArtifactGuestShareOperations.d.ts +60 -0
  88. package/dist/custom/operations/ArtifactGuestShareOperations.d.ts.map +1 -0
  89. package/dist/custom/operations/ArtifactGuestShareOperations.js +6 -0
  90. package/dist/custom/operations/ArtifactGuestShareOperations.js.map +1 -0
  91. package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.d.ts +7 -0
  92. package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.d.ts.map +1 -0
  93. package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.js +7 -0
  94. package/dist/custom/operations/SynthesizeArtifactFromSourcesOperation.js.map +1 -0
  95. package/dist/custom/typedQuery.d.ts +162 -0
  96. package/dist/custom/typedQuery.d.ts.map +1 -0
  97. package/dist/custom/typedQuery.js +296 -0
  98. package/dist/custom/typedQuery.js.map +1 -0
  99. package/dist/engines/CanonGraphEngine.d.ts +115 -2
  100. package/dist/engines/CanonGraphEngine.d.ts.map +1 -1
  101. package/dist/engines/CanonGraphEngine.js +259 -34
  102. package/dist/engines/CanonGraphEngine.js.map +1 -1
  103. package/dist/engines/EncryptionEngineBase.js +2 -2
  104. package/dist/engines/EncryptionEngineBase.js.map +1 -1
  105. package/dist/engines/QueryEngine.js +2 -2
  106. package/dist/engines/QueryEngine.js.map +1 -1
  107. package/dist/engines/SearchEngineBase.d.ts +17 -3
  108. package/dist/engines/SearchEngineBase.d.ts.map +1 -1
  109. package/dist/engines/SearchEngineBase.js +100 -28
  110. package/dist/engines/SearchEngineBase.js.map +1 -1
  111. package/dist/engines/UserInfoEngine.d.ts +8 -0
  112. package/dist/engines/UserInfoEngine.d.ts.map +1 -1
  113. package/dist/engines/UserInfoEngine.js +50 -3
  114. package/dist/engines/UserInfoEngine.js.map +1 -1
  115. package/dist/engines/conversations.d.ts +74 -6
  116. package/dist/engines/conversations.d.ts.map +1 -1
  117. package/dist/engines/conversations.js +205 -24
  118. package/dist/engines/conversations.js.map +1 -1
  119. package/dist/generated/entities/__mj.d.ts +25652 -43408
  120. package/dist/generated/entities/__mj.d.ts.map +1 -1
  121. package/dist/generated/entities/__mj.js +50800 -83602
  122. package/dist/generated/entities/__mj.js.map +1 -1
  123. package/dist/generated/queries/__mj.d.ts +12 -12
  124. package/dist/generated/queries/__mj.d.ts.map +1 -1
  125. package/dist/generated/queries/__mj.js +1 -1
  126. package/dist/generated/queries/__mj.js.map +1 -1
  127. package/dist/generated/remote_operations.d.ts +970 -65
  128. package/dist/generated/remote_operations.d.ts.map +1 -1
  129. package/dist/generated/remote_operations.js +343 -8
  130. package/dist/generated/remote_operations.js.map +1 -1
  131. package/dist/generated/schemas/__mj.d.ts +27415 -0
  132. package/dist/generated/schemas/__mj.d.ts.map +1 -0
  133. package/dist/generated/schemas/__mj.js +45127 -0
  134. package/dist/generated/schemas/__mj.js.map +1 -0
  135. package/dist/generated/schemas.d.ts +2 -0
  136. package/dist/generated/schemas.d.ts.map +1 -0
  137. package/dist/generated/schemas.js +2 -0
  138. package/dist/generated/schemas.js.map +1 -0
  139. package/dist/graph/BaseGraphEdgeProvider.d.ts +33 -1
  140. package/dist/graph/BaseGraphEdgeProvider.d.ts.map +1 -1
  141. package/dist/graph/BaseGraphEdgeProvider.js +18 -3
  142. package/dist/graph/BaseGraphEdgeProvider.js.map +1 -1
  143. package/dist/graph/CanonDocumentRenderer.d.ts +43 -0
  144. package/dist/graph/CanonDocumentRenderer.d.ts.map +1 -0
  145. package/dist/graph/CanonDocumentRenderer.js +627 -0
  146. package/dist/graph/CanonDocumentRenderer.js.map +1 -0
  147. package/dist/graph/DomainClustering.d.ts +88 -0
  148. package/dist/graph/DomainClustering.d.ts.map +1 -0
  149. package/dist/graph/DomainClustering.js +327 -0
  150. package/dist/graph/DomainClustering.js.map +1 -0
  151. package/dist/graph/DomainProposalWriter.d.ts +25 -0
  152. package/dist/graph/DomainProposalWriter.d.ts.map +1 -0
  153. package/dist/graph/DomainProposalWriter.js +107 -0
  154. package/dist/graph/DomainProposalWriter.js.map +1 -0
  155. package/dist/graph/GraphAccessPolicy.d.ts +111 -0
  156. package/dist/graph/GraphAccessPolicy.d.ts.map +1 -0
  157. package/dist/graph/GraphAccessPolicy.js +123 -0
  158. package/dist/graph/GraphAccessPolicy.js.map +1 -0
  159. package/dist/graph/GraphEngine.d.ts +115 -7
  160. package/dist/graph/GraphEngine.d.ts.map +1 -1
  161. package/dist/graph/GraphEngine.js +432 -36
  162. package/dist/graph/GraphEngine.js.map +1 -1
  163. package/dist/graph/RecordRelations.d.ts +52 -0
  164. package/dist/graph/RecordRelations.d.ts.map +1 -0
  165. package/dist/graph/RecordRelations.js +90 -0
  166. package/dist/graph/RecordRelations.js.map +1 -0
  167. package/dist/graph/index.d.ts +9 -1
  168. package/dist/graph/index.d.ts.map +1 -1
  169. package/dist/graph/index.js +13 -1
  170. package/dist/graph/index.js.map +1 -1
  171. package/dist/graph/policies/ProvenanceAccessPolicies.d.ts +56 -0
  172. package/dist/graph/policies/ProvenanceAccessPolicies.d.ts.map +1 -0
  173. package/dist/graph/policies/ProvenanceAccessPolicies.js +228 -0
  174. package/dist/graph/policies/ProvenanceAccessPolicies.js.map +1 -0
  175. package/dist/graph/providers/QueryEdgeProvider.d.ts.map +1 -1
  176. package/dist/graph/providers/QueryEdgeProvider.js +2 -2
  177. package/dist/graph/providers/QueryEdgeProvider.js.map +1 -1
  178. package/dist/graph/providers/RecordLinkEdgeProvider.d.ts.map +1 -1
  179. package/dist/graph/providers/RecordLinkEdgeProvider.js +2 -2
  180. package/dist/graph/providers/RecordLinkEdgeProvider.js.map +1 -1
  181. package/dist/graph/providers/SharedConceptEdgeProvider.d.ts +54 -0
  182. package/dist/graph/providers/SharedConceptEdgeProvider.d.ts.map +1 -0
  183. package/dist/graph/providers/SharedConceptEdgeProvider.js +282 -0
  184. package/dist/graph/providers/SharedConceptEdgeProvider.js.map +1 -0
  185. package/dist/index.d.ts +12 -0
  186. package/dist/index.d.ts.map +1 -1
  187. package/dist/index.js +18 -0
  188. package/dist/index.js.map +1 -1
  189. package/dist/schemas.d.ts +6 -0
  190. package/dist/schemas.d.ts.map +1 -0
  191. package/dist/schemas.js +6 -0
  192. package/dist/schemas.js.map +1 -0
  193. package/package.json +17 -6
@@ -1,8 +1,9 @@
1
- import { BaseEngine, EntityEventRowIsFree, ResolveEntityEventKey, ResolveEntityEventRow, RunQuery, RunView, TransformSimpleObjectToEntityObject } from "@memberjunction/core";
1
+ import { BaseEngine, EntityEventRowIsFree, EntityPermissionType, ResolveEntityEventKey, ResolveEntityEventRow, RunQuery, RunView, TransformSimpleObjectToEntityObject } from "@memberjunction/core";
2
2
  import { EscapeSQLString, IndexByUUID, NormalizeUUID, ToEpochMs, UUIDMap, UUIDSet, UUIDsEqual } from "@memberjunction/global";
3
3
  import { BehaviorSubject } from "rxjs";
4
4
  import { ArtifactMetadataEngine } from "./artifacts.js";
5
5
  import { ResourcePermissionEngine } from "../custom/ResourcePermissions/ResourcePermissionEngine.js";
6
+ import { CONVERSATION_DELETE_REFUSED_REASON, ConversationDeleteAllowed } from "../custom/ConversationWriteAccess.js";
6
7
  import { FilterAnchoredConversationsForUser, IsConversationHiddenByFieldSecurity, ParseConversationAnchorMetadata } from "../custom/AnchoredConversationSecurity.js";
7
8
  /**
8
9
  * `MJ: Resource Types.ID` for Conversations. Conversations that the current
@@ -27,6 +28,7 @@ export const CONVERSATION_TYPE_CODES = {
27
28
  ROUTINE: 'ROUTINE',
28
29
  MEETING_ROOM: 'MEETING_ROOM',
29
30
  COMMENT: 'COMMENT',
31
+ AGENT_CHANNEL: 'AGENT_CHANNEL',
30
32
  };
31
33
  /**
32
34
  * Seeded primary-key UUIDs for built-in `MJ: Conversation Types` rows, used as deterministic
@@ -38,6 +40,7 @@ export const BUILT_IN_CONVERSATION_TYPE_IDS = {
38
40
  ROUTINE: '18D12ABA-BE8C-4087-B440-835B6D077DD7',
39
41
  MEETING_ROOM: '2E9EF85D-D18A-4B8E-B6AB-F65C7F91A926',
40
42
  COMMENT: '17E6A105-AE51-43A2-9D56-290BC8D1D6BB',
43
+ AGENT_CHANNEL: '09E7A069-DB29-4329-BB29-4DF8CB998D94',
41
44
  };
42
45
  const BUILT_IN_CONVERSATION_TYPE_NAMES = {
43
46
  chat: 'CHAT',
@@ -46,6 +49,8 @@ const BUILT_IN_CONVERSATION_TYPE_NAMES = {
46
49
  'meeting room': 'MEETING_ROOM',
47
50
  meeting_room: 'MEETING_ROOM',
48
51
  comment: 'COMMENT',
52
+ 'agent channel': 'AGENT_CHANNEL',
53
+ agent_channel: 'AGENT_CHANNEL',
49
54
  };
50
55
  /**
51
56
  * Canonical built-in `MJ: Comment Types.Code` constants.
@@ -726,16 +731,29 @@ export class ConversationEngine extends BaseEngine {
726
731
  return this._sharedByByConversationId.get(NormalizeUUID(conversationId)) ?? null;
727
732
  }
728
733
  /**
729
- * True when the user may grant others access to the conversation: they own it,
730
- * or hold an Owner-level grant on it. Mirrors the server's share gate in
731
- * `MJResourcePermissionEntityExtended`, so the UI never offers a share the save
732
- * would refuse.
734
+ * True when this conversation has an explicit `MJ: Resource Permissions` share record
735
+ * granting the current user access (distinct from implicit folder inheritance).
736
+ */
737
+ IsConversationExplicitlyShared(conversationId) {
738
+ return this._explicitSharedConversationIds.has(NormalizeUUID(conversationId));
739
+ }
740
+ /**
741
+ * True only when the user owns the conversation (`conversation.UserID === userId`).
742
+ * Mirrors the server's owner-only sharing gate in `MJResourcePermissionEntityServer`:
743
+ * non-owner recipients—even with an `'Owner'`-level grant—cannot reshare or revoke
744
+ * shares on a conversation (including private `ParentID` side threads).
733
745
  */
734
746
  CanShareConversation(conversation, userId) {
735
- if (conversation.UserID && UUIDsEqual(conversation.UserID, userId)) {
736
- return true;
737
- }
738
- return this.GetSharedByInfo(conversation.ID)?.Level === 'Owner';
747
+ return Boolean(conversation?.UserID && userId && UUIDsEqual(conversation.UserID, userId));
748
+ }
749
+ /**
750
+ * True when the user may delete the conversation for everyone: they own it, hold an
751
+ * Owner-level grant on it, or are in the Developer or Integration role. An Edit grant
752
+ * is not enough. Mirrors the server's delete gate in `MJConversationEntityServer`, so
753
+ * the UI never offers a delete the server would refuse.
754
+ */
755
+ CanDeleteConversation(conversation, user) {
756
+ return ConversationDeleteAllowed(conversation.UserID, user, this.GetSharedByInfo(conversation.ID)?.Level ?? null);
739
757
  }
740
758
  /**
741
759
  * True when the user may move the conversation to another folder or change whether it inherits its
@@ -1025,7 +1043,8 @@ export class ConversationEngine extends BaseEngine {
1025
1043
  visibleConversations.push(conv);
1026
1044
  continue;
1027
1045
  }
1028
- if (conv.ProjectID &&
1046
+ if (!conv.ParentID &&
1047
+ conv.ProjectID &&
1029
1048
  IsInheritingFolderAccess(conv) &&
1030
1049
  sharedProjectIdSet.has(NormalizeUUID(conv.ProjectID))) {
1031
1050
  visibleConversations.push(conv);
@@ -1103,6 +1122,34 @@ export class ConversationEngine extends BaseEngine {
1103
1122
  }
1104
1123
  return [...byProjectId.values()];
1105
1124
  }
1125
+ /**
1126
+ * True when one of the user's roles grants this kind of write on folders (`MJ: Projects`) with no row-level
1127
+ * filter. A user whose folder writes are all filtered (the UI role: own folders only) writes only folders they
1128
+ * own: they cannot make a folder Public (no owner) or rename, move or delete a Public folder or someone else's.
1129
+ * Answers false when the folder entity's metadata is not loaded.
1130
+ *
1131
+ * @param provider the metadata provider the caller works against; defaults to the engine's.
1132
+ */
1133
+ CanWriteAnyProject(user, type, provider) {
1134
+ if (!user) {
1135
+ return false;
1136
+ }
1137
+ const entity = (provider ?? this.ProviderToUse)?.EntityByName('MJ: Projects');
1138
+ return !!entity && entity.UserExemptFromRowLevelSecurity(user, type);
1139
+ }
1140
+ /**
1141
+ * True when the user may rename or delete this folder from the sidebar: they own it, or their folder writes
1142
+ * are not row-filtered (see {@link CanWriteAnyProject}).
1143
+ */
1144
+ CanManageProject(project, user, provider) {
1145
+ if (!project || !user) {
1146
+ return false;
1147
+ }
1148
+ if (project.OwnerUserID && UUIDsEqual(project.OwnerUserID, user.ID)) {
1149
+ return true;
1150
+ }
1151
+ return this.CanWriteAnyProject(user, EntityPermissionType.Update, provider);
1152
+ }
1106
1153
  /**
1107
1154
  * Returns the three-tier visibility mode (`'Private' | 'Shared' | 'Public'`) for a folder:
1108
1155
  * - `'Public'`: `OwnerUserID == null` (environment-wide)
@@ -1227,13 +1274,21 @@ export class ConversationEngine extends BaseEngine {
1227
1274
  await ResourcePermissionEngine.Instance.Config(false, contextUser);
1228
1275
  return ResourcePermissionEngine.Instance.GetUserAvailableResources(contextUser, CONVERSATIONS_RESOURCE_TYPE_ID);
1229
1276
  }
1277
+ isAgentChannelTypeId(typeId) {
1278
+ if (!typeId) {
1279
+ return false;
1280
+ }
1281
+ const agentChannelTypeId = this.ResolveConversationTypeID(CONVERSATION_TYPE_CODES.AGENT_CHANNEL) ??
1282
+ BUILT_IN_CONVERSATION_TYPE_IDS.AGENT_CHANNEL;
1283
+ return UUIDsEqual(typeId, agentChannelTypeId);
1284
+ }
1230
1285
  buildVisibleConversationsFilter(environmentId, userId, sharedConversationIds, options, sharedProjectIds = []) {
1231
1286
  const ownershipClause = `UserID='${userId}'`;
1232
1287
  const sharedClause = sharedConversationIds.length > 0
1233
1288
  ? ` OR ID IN (${sharedConversationIds.map((id) => `'${EscapeSQLString(id)}'`).join(',')})`
1234
1289
  : '';
1235
1290
  const sharedFolderClause = sharedProjectIds.length > 0
1236
- ? ` OR (ProjectID IN (${sharedProjectIds.map((id) => `'${EscapeSQLString(id)}'`).join(',')}) AND ${INHERIT_FOLDER_ACCESS_SQL_CLAUSE})`
1291
+ ? ` OR (ParentID IS NULL AND ProjectID IN (${sharedProjectIds.map((id) => `'${EscapeSQLString(id)}'`).join(',')}) AND ${INHERIT_FOLDER_ACCESS_SQL_CLAUSE})`
1237
1292
  : '';
1238
1293
  // The main chat view shows Global and Both. App-scoped conversations live inside
1239
1294
  // their owning Application's embedded surface.
@@ -1250,7 +1305,14 @@ export class ConversationEngine extends BaseEngine {
1250
1305
  const recordLinkedClause = options?.includeRecordLinked
1251
1306
  ? ''
1252
1307
  : ` AND LinkedEntityID IS NULL`;
1253
- return `EnvironmentID='${environmentId}' AND (${ownershipClause}${sharedClause}${sharedFolderClause}) AND (IsArchived IS NULL OR IsArchived=0)${scopeClause}${anchorClause}${recordLinkedClause}`;
1308
+ // Agent-to-agent coordination channels live in My Agents -> Agent Channels rather than
1309
+ // the human Chat sidebar list unless explicitly requested.
1310
+ const agentChannelTypeId = this.ResolveConversationTypeID(CONVERSATION_TYPE_CODES.AGENT_CHANNEL) ??
1311
+ BUILT_IN_CONVERSATION_TYPE_IDS.AGENT_CHANNEL;
1312
+ const agentChannelClause = options?.includeAgentChannels
1313
+ ? ''
1314
+ : ` AND (TypeID IS NULL OR TypeID <> '${EscapeSQLString(agentChannelTypeId)}')`;
1315
+ return `EnvironmentID='${environmentId}' AND (${ownershipClause}${sharedClause}${sharedFolderClause}) AND (IsArchived IS NULL OR IsArchived=0)${scopeClause}${anchorClause}${recordLinkedClause}${agentChannelClause}`;
1254
1316
  }
1255
1317
  /**
1256
1318
  * Populates {@link _sharedByByConversationId}. Resolves grantor emails via
@@ -1435,6 +1497,8 @@ export class ConversationEngine extends BaseEngine {
1435
1497
  * 2. Reparents direct child folders to this folder's parent (one level up).
1436
1498
  * 3. Deletes the now-unreferenced folder.
1437
1499
  * Conversations and subfolders are preserved — only the folder itself is removed.
1500
+ * Steps 1 and 2 cover the rows the caller can change; the server's folder delete
1501
+ * (`MJProjectEntityServer.Delete`) moves the rest in the delete's transaction.
1438
1502
  *
1439
1503
  * Note: this does NOT reassign Tasks that reference the project; if a Task still
1440
1504
  * references it, the final delete will fail and this throws with the DB message.
@@ -1458,9 +1522,10 @@ export class ConversationEngine extends BaseEngine {
1458
1522
  }
1459
1523
  const newParentId = project.ParentID ?? null;
1460
1524
  // 1. Unassign conversations directly in this folder that the caller can edit.
1461
- // View-only conversations owned by other users in a shared folder cannot be edited
1462
- // by this caller; if any still exist in the DB, the delete below will surface
1463
- // FK_Conversation_Project via ExplainProjectDeleteFailure.
1525
+ // Conversations owned by other users in a shared folder cannot be edited by this
1526
+ // caller; the server's folder delete takes them out of the folder in the delete's
1527
+ // transaction (on a server without that, the delete below surfaces
1528
+ // FK_Conversation_Project via ExplainProjectDeleteFailure).
1464
1529
  const directConversations = this._conversations$.value.filter(c => c.ProjectID && UUIDsEqual(c.ProjectID, id));
1465
1530
  for (const conv of directConversations) {
1466
1531
  if (!contextUser?.ID || !conv.UserID || this.CanEditConversation(conv, contextUser.ID)) {
@@ -1477,21 +1542,27 @@ export class ConversationEngine extends BaseEngine {
1477
1542
  // RESTRICT foreign key with no ON DELETE clause, so the delete below would then fail
1478
1543
  // with a raw constraint message, about a row the user is not allowed to know exists.
1479
1544
  //
1480
- // The read carries NO ownership clause, deliberately. Deleting a folder needs
1481
- // CanDelete on the entity, which the UI role does not hold; the roles that do also
1482
- // hold unfiltered read, which makes them exempt from the row-level filter — so this
1483
- // read returns the complete child set for every principal that can actually reach
1484
- // here. Should a deployment grant delete to a filtered role anyway, the server still
1485
- // narrows the read, and step 3's guard turns the resulting FK failure into something
1486
- // legible rather than "Failed to save project".
1545
+ // The read carries no ownership clause; the server narrows it to what the caller
1546
+ // may read. A subfolder another user owns may refuse the move (only its owner moves
1547
+ // it, and a row-filtered caller writes only their own folders): that one is left in
1548
+ // place, and the server's folder delete moves it, as the system user and in the
1549
+ // delete's transaction, once the caller's Delete permission and row filter pass. On a
1550
+ // server without that, the delete below fails on the foreign key and step 3's guard
1551
+ // explains it.
1487
1552
  const childFolders = await this.readChildFolders(id, contextUser);
1488
1553
  if (childFolders.length > 0) {
1489
1554
  this._selfMutating = true;
1490
1555
  try {
1491
1556
  for (const child of childFolders) {
1557
+ const previousParentId = child.ParentID;
1492
1558
  child.ParentID = newParentId;
1493
1559
  const saved = await child.Save();
1494
1560
  if (!saved) {
1561
+ const ownedByOther = !!child.OwnerUserID && !!contextUser?.ID && !UUIDsEqual(child.OwnerUserID, contextUser.ID);
1562
+ if (ownedByOther) {
1563
+ child.ParentID = previousParentId; // left for the server's folder delete
1564
+ continue;
1565
+ }
1495
1566
  throw new Error(child.LatestResult?.CompleteMessage || 'Failed to reparent subfolder');
1496
1567
  }
1497
1568
  }
@@ -1654,6 +1725,7 @@ export class ConversationEngine extends BaseEngine {
1654
1725
  if (conversation.ApplicationScope !== 'Application' &&
1655
1726
  conversation.AnchorType == null &&
1656
1727
  conversation.LinkedEntityID == null &&
1728
+ !this.isAgentChannelTypeId(conversation.TypeID) &&
1657
1729
  !this.GetConversation(conversation.ID)) {
1658
1730
  const updated = [conversation, ...this._conversations$.value];
1659
1731
  this._conversations$.next(updated);
@@ -2110,7 +2182,8 @@ export class ConversationEngine extends BaseEngine {
2110
2182
  // surface, not the main-chat list this engine caches — mirror CreateConversation and skip them.
2111
2183
  if (conversation.ApplicationScope === 'Application' ||
2112
2184
  conversation.AnchorType != null ||
2113
- conversation.LinkedEntityID != null) {
2185
+ conversation.LinkedEntityID != null ||
2186
+ this.isAgentChannelTypeId(conversation.TypeID)) {
2114
2187
  return conversation;
2115
2188
  }
2116
2189
  // Re-check under the loaded row in case a concurrent emit added it meanwhile.
@@ -2120,13 +2193,32 @@ export class ConversationEngine extends BaseEngine {
2120
2193
  this._conversations$.next([conversation, ...this._conversations$.value]);
2121
2194
  return conversation;
2122
2195
  }
2196
+ /**
2197
+ * Verifies current server readability for a conversation deep link by performing a fresh
2198
+ * single-row `Load(id)`. Unlike {@link EnsureConversationLoaded}, this never trusts a
2199
+ * stale client cache entry for non-owned conversations; if access was revoked server-side,
2200
+ * the cached entry is evicted and `null` is returned so the UI denies access cleanly.
2201
+ */
2202
+ async VerifyConversationAccess(id, contextUser) {
2203
+ const md = this.ProviderToUse;
2204
+ const conversation = await md.GetEntityObject('MJ: Conversations', contextUser);
2205
+ const loaded = await conversation.Load(id);
2206
+ if (!loaded) {
2207
+ const existing = this.GetConversation(id);
2208
+ if (existing) {
2209
+ this._conversations$.next(this._conversations$.value.filter((c) => !UUIDsEqual(c.ID, id)));
2210
+ }
2211
+ return null;
2212
+ }
2213
+ return conversation;
2214
+ }
2123
2215
  /**
2124
2216
  * Deletes a conversation from the database and removes it from the cached list.
2125
2217
  *
2126
2218
  * @param id - The conversation ID to delete
2127
2219
  * @param contextUser - The current user context
2128
2220
  * @returns true if successful
2129
- * @throws Error if conversation not found or delete fails
2221
+ * @throws Error if conversation not found, the user may not delete it ({@link CanDeleteConversation}), or delete fails
2130
2222
  */
2131
2223
  async DeleteConversation(id, contextUser) {
2132
2224
  // Try to use the cached entity object first to avoid a DB round-trip
@@ -2140,6 +2232,10 @@ export class ConversationEngine extends BaseEngine {
2140
2232
  throw new Error('Conversation not found');
2141
2233
  }
2142
2234
  }
2235
+ // Refuse before the optimistic removal below, so a refused conversation never leaves the list.
2236
+ if (!this.CanDeleteConversation(conversation, contextUser)) {
2237
+ throw new Error(CONVERSATION_DELETE_REFUSED_REASON);
2238
+ }
2143
2239
  // Remove from the list and cache BEFORE calling Delete(), because
2144
2240
  // BaseEntity.Delete() calls NewRecord() which wipes the entity's fields.
2145
2241
  // Since the cached entity is the same object reference in the list,
@@ -2262,6 +2358,8 @@ export class ConversationEngine extends BaseEngine {
2262
2358
  }
2263
2359
  /**
2264
2360
  * Deletes multiple conversations in a batch operation with per-item error tracking.
2361
+ * Conversations the user may not delete ({@link CanDeleteConversation}) are reported
2362
+ * as failed, by name, without a delete.
2265
2363
  *
2266
2364
  * @param ids - Array of conversation IDs to delete
2267
2365
  * @param contextUser - The current user context
@@ -2310,6 +2408,10 @@ export class ConversationEngine extends BaseEngine {
2310
2408
  try {
2311
2409
  for (const entity of entitiesToDelete) {
2312
2410
  const name = entity.Name || 'Unknown';
2411
+ if (!this.CanDeleteConversation(entity, contextUser)) {
2412
+ failed.push({ ID: entity.ID, Name: name, Error: CONVERSATION_DELETE_REFUSED_REASON });
2413
+ continue;
2414
+ }
2313
2415
  try {
2314
2416
  // Use DeleteConversation which handles Load + Delete properly
2315
2417
  // and removes from list/cache on success
@@ -3346,10 +3448,85 @@ export class ConversationEngine extends BaseEngine {
3346
3448
  static FilterToScope(scope, rows) {
3347
3449
  return ConversationEngine.FilterRowsToBranchPath(rows, scope.BranchID, scope.Branches);
3348
3450
  }
3451
+ /**
3452
+ * Client-safe query descriptor loading `MJ: Conversation Details.ID` values visible in `scope`,
3453
+ * optionally narrowed to `candidateDetailIds`. Runs directly against `MJ: Conversation Details`
3454
+ * so server `PostRunView` security hooks apply and `ClientClauseScreen` never rejects a base-view subquery.
3455
+ */
3456
+ static BuildScopedDetailIdsQuery(scope, candidateDetailIds) {
3457
+ let filter = ConversationEngine.ScopeFilter(scope);
3458
+ if (candidateDetailIds && candidateDetailIds.length > 0) {
3459
+ const uniqueEscaped = [...new Set(candidateDetailIds.map((id) => id.trim()).filter(Boolean))]
3460
+ .map((id) => `'${EscapeSQLString(id)}'`);
3461
+ if (uniqueEscaped.length > 0) {
3462
+ filter = `(${filter}) AND [ID] IN (${uniqueEscaped.join(',')})`;
3463
+ }
3464
+ }
3465
+ return {
3466
+ EntityName: 'MJ: Conversation Details',
3467
+ ExtraFilter: filter,
3468
+ Fields: ['ID'],
3469
+ ResultType: 'simple',
3470
+ IgnoreMaxRows: true
3471
+ };
3472
+ }
3473
+ /**
3474
+ * Loads lowercased `MJ: Conversation Details.ID` values visible in `scope` via `RunView`, returning
3475
+ * `null` if the read fails so callers can fail closed. Avoids emitting `[__mj].[vwConversationDetails]`
3476
+ * subqueries from GraphQL client filters.
3477
+ */
3478
+ static async LoadScopedDetailIds(scope, provider, contextUser, candidateDetailIds) {
3479
+ if (candidateDetailIds) {
3480
+ const unique = candidateDetailIds.map((id) => id.trim()).filter(Boolean);
3481
+ if (unique.length === 0) {
3482
+ return new Set();
3483
+ }
3484
+ }
3485
+ const rv = RunView.FromMetadataProvider(provider);
3486
+ const res = await rv.RunView(ConversationEngine.BuildScopedDetailIdsQuery(scope, candidateDetailIds), contextUser);
3487
+ if (!res?.Success || !Array.isArray(res.Results)) {
3488
+ return null;
3489
+ }
3490
+ const ids = new Set();
3491
+ for (const row of res.Results) {
3492
+ const id = typeof row.ID === 'string' ? row.ID.trim().toLowerCase() : '';
3493
+ if (id) {
3494
+ ids.add(id);
3495
+ }
3496
+ }
3497
+ return ids;
3498
+ }
3499
+ /**
3500
+ * Filters artifact versions to those visible in `scope` (`{@link ArtifactVersionScopeFilter}` semantics):
3501
+ * keeps versions linked in any direction to a detail in `scopedDetailIds`, plus versions that have
3502
+ * no `MJ: Conversation Detail Artifacts` link at all.
3503
+ */
3504
+ static FilterArtifactVersionsByScope(versions, links, scopedDetailIds) {
3505
+ const allLinkedVersionIds = new Set();
3506
+ const scopedLinkedVersionIds = new Set();
3507
+ for (const link of links) {
3508
+ const versionId = typeof link.ArtifactVersionID === 'string' ? link.ArtifactVersionID.trim().toLowerCase() : '';
3509
+ if (!versionId)
3510
+ continue;
3511
+ allLinkedVersionIds.add(versionId);
3512
+ const detailId = typeof link.ConversationDetailID === 'string' ? link.ConversationDetailID.trim().toLowerCase() : '';
3513
+ if (detailId && scopedDetailIds.has(detailId)) {
3514
+ scopedLinkedVersionIds.add(versionId);
3515
+ }
3516
+ }
3517
+ return versions.filter((v) => {
3518
+ const id = typeof v.ID === 'string' ? v.ID.trim().toLowerCase() : '';
3519
+ return id ? (!allLinkedVersionIds.has(id) || scopedLinkedVersionIds.has(id)) : false;
3520
+ });
3521
+ }
3349
3522
  /**
3350
3523
  * Filter over MJ: Artifact Versions for the versions of one artifact visible in scope: versions
3351
3524
  * linked (in any direction) from a message on the path, and versions with no conversation link
3352
3525
  * at all.
3526
+ *
3527
+ * Note: server/internal callers only — GraphQL clients must use {@link BuildScopedDetailIdsQuery} +
3528
+ * {@link FilterArtifactVersionsByScope} because `ClientClauseScreen` blocks `[__mj].[vwConversationDetails]`
3529
+ * subqueries in client-supplied `ExtraFilter`s.
3353
3530
  */
3354
3531
  static ArtifactVersionScopeFilter(scope, artifactId) {
3355
3532
  const path = ConversationEngine.ScopeFilter(scope);
@@ -4167,6 +4344,9 @@ export class ConversationEngine extends BaseEngine {
4167
4344
  const scope = data['ApplicationScope'];
4168
4345
  const anchorType = data['AnchorType'];
4169
4346
  const linkedEntityId = data['LinkedEntityID'];
4347
+ const typeId = data['TypeID'] ??
4348
+ event.baseEntity?.TypeID ??
4349
+ null;
4170
4350
  const environmentId = data['EnvironmentID'];
4171
4351
  const isArchived = data['IsArchived'] === true;
4172
4352
  const inLoadedEnvironment = !this._lastEnvironmentId ||
@@ -4174,6 +4354,7 @@ export class ConversationEngine extends BaseEngine {
4174
4354
  if (scope !== 'Application' &&
4175
4355
  anchorType == null &&
4176
4356
  linkedEntityId == null &&
4357
+ !this.isAgentChannelTypeId(typeId) &&
4177
4358
  !isArchived &&
4178
4359
  inLoadedEnvironment) {
4179
4360
  this._conversations$.next([event.baseEntity, ...this._conversations$.value]);