@memberjunction/server 6.2.0-edge.3 → 6.2.0-edge.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/agentSessions/BridgeHostInstance.d.ts +25 -0
- package/dist/agentSessions/BridgeHostInstance.d.ts.map +1 -0
- package/dist/agentSessions/BridgeHostInstance.js +30 -0
- package/dist/agentSessions/BridgeHostInstance.js.map +1 -0
- package/dist/agentSessions/HostInstance.d.ts +75 -11
- package/dist/agentSessions/HostInstance.d.ts.map +1 -1
- package/dist/agentSessions/HostInstance.js +99 -28
- package/dist/agentSessions/HostInstance.js.map +1 -1
- package/dist/agentSessions/ReturningVisitorRecap.d.ts.map +1 -1
- package/dist/agentSessions/ReturningVisitorRecap.js +7 -3
- package/dist/agentSessions/ReturningVisitorRecap.js.map +1 -1
- package/dist/agentSessions/SessionJanitor.d.ts +173 -25
- package/dist/agentSessions/SessionJanitor.d.ts.map +1 -1
- package/dist/agentSessions/SessionJanitor.js +452 -54
- package/dist/agentSessions/SessionJanitor.js.map +1 -1
- package/dist/agentSessions/SessionManager.d.ts +43 -2
- package/dist/agentSessions/SessionManager.d.ts.map +1 -1
- package/dist/agentSessions/SessionManager.js +99 -8
- package/dist/agentSessions/SessionManager.js.map +1 -1
- package/dist/agentSessions/SessionRunIDVerifier.d.ts +63 -0
- package/dist/agentSessions/SessionRunIDVerifier.d.ts.map +1 -0
- package/dist/agentSessions/SessionRunIDVerifier.js +129 -0
- package/dist/agentSessions/SessionRunIDVerifier.js.map +1 -0
- package/dist/agentSessions/index.d.ts +2 -0
- package/dist/agentSessions/index.d.ts.map +1 -1
- package/dist/agentSessions/index.js +10 -3
- package/dist/agentSessions/index.js.map +1 -1
- package/dist/auth/actionAuthorization.d.ts +40 -0
- package/dist/auth/actionAuthorization.d.ts.map +1 -0
- package/dist/auth/actionAuthorization.js +94 -0
- package/dist/auth/actionAuthorization.js.map +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +3 -10
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/magicLink/MagicLinkService.d.ts.map +1 -1
- package/dist/auth/magicLink/MagicLinkService.js +6 -3
- package/dist/auth/magicLink/MagicLinkService.js.map +1 -1
- package/dist/auth/newUsers.d.ts +10 -0
- package/dist/auth/newUsers.d.ts.map +1 -1
- package/dist/auth/newUsers.js +80 -11
- package/dist/auth/newUsers.js.map +1 -1
- package/dist/config.d.ts +2378 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +123 -0
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +8 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +14 -11
- package/dist/context.js.map +1 -1
- package/dist/generated/graphql-schemas/__mj.d.ts +135 -0
- package/dist/generated/graphql-schemas/__mj.d.ts.map +1 -1
- package/dist/generated/graphql-schemas/__mj.js +706 -0
- package/dist/generated/graphql-schemas/__mj.js.map +1 -1
- package/dist/generic/OrphanedConversationDetailReconciler.js +3 -3
- package/dist/generic/OrphanedConversationDetailReconciler.js.map +1 -1
- package/dist/generic/ResolverBase.d.ts +20 -4
- package/dist/generic/ResolverBase.d.ts.map +1 -1
- package/dist/generic/ResolverBase.js +39 -10
- package/dist/generic/ResolverBase.js.map +1 -1
- package/dist/generic/RunViewResolver.d.ts.map +1 -1
- package/dist/generic/RunViewResolver.js +4 -0
- package/dist/generic/RunViewResolver.js.map +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +120 -131
- package/dist/index.js.map +1 -1
- package/dist/isolatedProvider.d.ts +20 -0
- package/dist/isolatedProvider.d.ts.map +1 -0
- package/dist/isolatedProvider.js +22 -0
- package/dist/isolatedProvider.js.map +1 -0
- package/dist/realtimeProxy/RealtimeProxyServer.d.ts +44 -4
- package/dist/realtimeProxy/RealtimeProxyServer.d.ts.map +1 -1
- package/dist/realtimeProxy/RealtimeProxyServer.js +121 -16
- package/dist/realtimeProxy/RealtimeProxyServer.js.map +1 -1
- package/dist/realtimeProxy/RealtimeRelayTunnel.d.ts +171 -0
- package/dist/realtimeProxy/RealtimeRelayTunnel.d.ts.map +1 -0
- package/dist/realtimeProxy/RealtimeRelayTunnel.js +532 -0
- package/dist/realtimeProxy/RealtimeRelayTunnel.js.map +1 -0
- package/dist/realtimeSessions/RealtimeSessionEventService.d.ts +148 -0
- package/dist/realtimeSessions/RealtimeSessionEventService.d.ts.map +1 -0
- package/dist/realtimeSessions/RealtimeSessionEventService.js +191 -0
- package/dist/realtimeSessions/RealtimeSessionEventService.js.map +1 -0
- package/dist/realtimeSessions/RealtimeSessionVerificationService.d.ts +66 -0
- package/dist/realtimeSessions/RealtimeSessionVerificationService.d.ts.map +1 -0
- package/dist/realtimeSessions/RealtimeSessionVerificationService.js +138 -0
- package/dist/realtimeSessions/RealtimeSessionVerificationService.js.map +1 -0
- package/dist/realtimeSessions/RealtimeVerifyRouter.d.ts +38 -0
- package/dist/realtimeSessions/RealtimeVerifyRouter.d.ts.map +1 -0
- package/dist/realtimeSessions/RealtimeVerifyRouter.js +98 -0
- package/dist/realtimeSessions/RealtimeVerifyRouter.js.map +1 -0
- package/dist/realtimeSessions/SessionVerificationPortsBase.d.ts +61 -0
- package/dist/realtimeSessions/SessionVerificationPortsBase.d.ts.map +1 -0
- package/dist/realtimeSessions/SessionVerificationPortsBase.js +149 -0
- package/dist/realtimeSessions/SessionVerificationPortsBase.js.map +1 -0
- package/dist/realtimeSessions/SlidingWindowRateLimiter.d.ts +57 -0
- package/dist/realtimeSessions/SlidingWindowRateLimiter.d.ts.map +1 -0
- package/dist/realtimeSessions/SlidingWindowRateLimiter.js +69 -0
- package/dist/realtimeSessions/SlidingWindowRateLimiter.js.map +1 -0
- package/dist/realtimeSessions/index.d.ts +17 -0
- package/dist/realtimeSessions/index.d.ts.map +1 -0
- package/dist/realtimeSessions/index.js +17 -0
- package/dist/realtimeSessions/index.js.map +1 -0
- package/dist/realtimeSessions/sessionAccess.d.ts +86 -0
- package/dist/realtimeSessions/sessionAccess.d.ts.map +1 -0
- package/dist/realtimeSessions/sessionAccess.js +90 -0
- package/dist/realtimeSessions/sessionAccess.js.map +1 -0
- package/dist/realtimeSessions/sessionConfigStamps.d.ts +70 -0
- package/dist/realtimeSessions/sessionConfigStamps.d.ts.map +1 -0
- package/dist/realtimeSessions/sessionConfigStamps.js +93 -0
- package/dist/realtimeSessions/sessionConfigStamps.js.map +1 -0
- package/dist/realtimeSessions/subscriptionAuthorization.d.ts +65 -0
- package/dist/realtimeSessions/subscriptionAuthorization.d.ts.map +1 -0
- package/dist/realtimeSessions/subscriptionAuthorization.js +71 -0
- package/dist/realtimeSessions/subscriptionAuthorization.js.map +1 -0
- package/dist/realtimeSessions/verificationCore.d.ts +243 -0
- package/dist/realtimeSessions/verificationCore.d.ts.map +1 -0
- package/dist/realtimeSessions/verificationCore.js +356 -0
- package/dist/realtimeSessions/verificationCore.js.map +1 -0
- package/dist/realtimeSessions/verificationPages.d.ts +66 -0
- package/dist/realtimeSessions/verificationPages.d.ts.map +1 -0
- package/dist/realtimeSessions/verificationPages.js +110 -0
- package/dist/realtimeSessions/verificationPages.js.map +1 -0
- package/dist/realtimeSessions/verificationPolicy.d.ts +147 -0
- package/dist/realtimeSessions/verificationPolicy.d.ts.map +1 -0
- package/dist/realtimeSessions/verificationPolicy.js +249 -0
- package/dist/realtimeSessions/verificationPolicy.js.map +1 -0
- package/dist/realtimeSessions/verificationWorkflow.d.ts +263 -0
- package/dist/realtimeSessions/verificationWorkflow.d.ts.map +1 -0
- package/dist/realtimeSessions/verificationWorkflow.js +435 -0
- package/dist/realtimeSessions/verificationWorkflow.js.map +1 -0
- package/dist/realtimeWidget/widgetGuestElevation.d.ts +20 -2
- package/dist/realtimeWidget/widgetGuestElevation.d.ts.map +1 -1
- package/dist/realtimeWidget/widgetGuestElevation.js +31 -2
- package/dist/realtimeWidget/widgetGuestElevation.js.map +1 -1
- package/dist/resolvers/ActionResolver.d.ts +31 -5
- package/dist/resolvers/ActionResolver.d.ts.map +1 -1
- package/dist/resolvers/ActionResolver.js +75 -14
- package/dist/resolvers/ActionResolver.js.map +1 -1
- package/dist/resolvers/AdhocQueryResolver.d.ts +14 -1
- package/dist/resolvers/AdhocQueryResolver.d.ts.map +1 -1
- package/dist/resolvers/AdhocQueryResolver.js +21 -5
- package/dist/resolvers/AdhocQueryResolver.js.map +1 -1
- package/dist/resolvers/CacheStatsResolver.d.ts +27 -0
- package/dist/resolvers/CacheStatsResolver.d.ts.map +1 -1
- package/dist/resolvers/CacheStatsResolver.js +113 -2
- package/dist/resolvers/CacheStatsResolver.js.map +1 -1
- package/dist/resolvers/ClientToolRequestResolver.d.ts +4 -2
- package/dist/resolvers/ClientToolRequestResolver.d.ts.map +1 -1
- package/dist/resolvers/ClientToolRequestResolver.js +28 -10
- package/dist/resolvers/ClientToolRequestResolver.js.map +1 -1
- package/dist/resolvers/FetchEntityVectorsResolver.d.ts +12 -1
- package/dist/resolvers/FetchEntityVectorsResolver.d.ts.map +1 -1
- package/dist/resolvers/FetchEntityVectorsResolver.js +83 -2
- package/dist/resolvers/FetchEntityVectorsResolver.js.map +1 -1
- package/dist/resolvers/HumanHandoffResolver.d.ts.map +1 -1
- package/dist/resolvers/HumanHandoffResolver.js +7 -1
- package/dist/resolvers/HumanHandoffResolver.js.map +1 -1
- package/dist/resolvers/MCPResolver.d.ts.map +1 -1
- package/dist/resolvers/MCPResolver.js +9 -4
- package/dist/resolvers/MCPResolver.js.map +1 -1
- package/dist/resolvers/RealtimeBridgeResolver.d.ts +54 -2
- package/dist/resolvers/RealtimeBridgeResolver.d.ts.map +1 -1
- package/dist/resolvers/RealtimeBridgeResolver.js +155 -10
- package/dist/resolvers/RealtimeBridgeResolver.js.map +1 -1
- package/dist/resolvers/RealtimeClientSessionResolver.d.ts +155 -25
- package/dist/resolvers/RealtimeClientSessionResolver.d.ts.map +1 -1
- package/dist/resolvers/RealtimeClientSessionResolver.js +394 -90
- package/dist/resolvers/RealtimeClientSessionResolver.js.map +1 -1
- package/dist/resolvers/RealtimeSessionEventsResolver.d.ts +61 -0
- package/dist/resolvers/RealtimeSessionEventsResolver.d.ts.map +1 -0
- package/dist/resolvers/RealtimeSessionEventsResolver.js +130 -0
- package/dist/resolvers/RealtimeSessionEventsResolver.js.map +1 -0
- package/dist/resolvers/RealtimeSessionVerificationResolver.d.ts +85 -0
- package/dist/resolvers/RealtimeSessionVerificationResolver.d.ts.map +1 -0
- package/dist/resolvers/RealtimeSessionVerificationResolver.js +188 -0
- package/dist/resolvers/RealtimeSessionVerificationResolver.js.map +1 -0
- package/dist/resolvers/RemoteBrowserActionResolver.d.ts +2 -0
- package/dist/resolvers/RemoteBrowserActionResolver.d.ts.map +1 -1
- package/dist/resolvers/RemoteBrowserActionResolver.js +5 -1
- package/dist/resolvers/RemoteBrowserActionResolver.js.map +1 -1
- package/dist/resolvers/RunAIAgentResolver.d.ts +10 -0
- package/dist/resolvers/RunAIAgentResolver.d.ts.map +1 -1
- package/dist/resolvers/RunAIAgentResolver.js +68 -11
- package/dist/resolvers/RunAIAgentResolver.js.map +1 -1
- package/dist/resolvers/RunTemplateResolver.d.ts.map +1 -1
- package/dist/resolvers/RunTemplateResolver.js +12 -11
- package/dist/resolvers/RunTemplateResolver.js.map +1 -1
- package/dist/resolvers/SyncDataResolver.d.ts.map +1 -1
- package/dist/resolvers/SyncDataResolver.js +6 -2
- package/dist/resolvers/SyncDataResolver.js.map +1 -1
- package/dist/resolvers/SyncRolesUsersResolver.d.ts +2 -0
- package/dist/resolvers/SyncRolesUsersResolver.d.ts.map +1 -1
- package/dist/resolvers/SyncRolesUsersResolver.js +23 -6
- package/dist/resolvers/SyncRolesUsersResolver.js.map +1 -1
- package/dist/resolvers/UserAvatarResolver.d.ts +16 -0
- package/dist/resolvers/UserAvatarResolver.d.ts.map +1 -0
- package/dist/resolvers/UserAvatarResolver.js +124 -0
- package/dist/resolvers/UserAvatarResolver.js.map +1 -0
- package/dist/resolvers/UserResolver.d.ts.map +1 -1
- package/dist/resolvers/UserResolver.js +2 -17
- package/dist/resolvers/UserResolver.js.map +1 -1
- package/dist/resolvers/agentVisionConsentAudit.d.ts +37 -0
- package/dist/resolvers/agentVisionConsentAudit.d.ts.map +1 -0
- package/dist/resolvers/agentVisionConsentAudit.js +63 -0
- package/dist/resolvers/agentVisionConsentAudit.js.map +1 -0
- package/dist/resolvers/avatarInputValidation.d.ts +40 -0
- package/dist/resolvers/avatarInputValidation.d.ts.map +1 -0
- package/dist/resolvers/avatarInputValidation.js +97 -0
- package/dist/resolvers/avatarInputValidation.js.map +1 -0
- package/dist/resolvers/currentUserRoles.d.ts +29 -0
- package/dist/resolvers/currentUserRoles.d.ts.map +1 -1
- package/dist/resolvers/currentUserRoles.js +30 -0
- package/dist/resolvers/currentUserRoles.js.map +1 -1
- package/dist/resolvers/meetings/meetingMutations.d.ts +6 -0
- package/dist/resolvers/meetings/meetingMutations.d.ts.map +1 -1
- package/dist/resolvers/meetings/meetingMutations.js +21 -0
- package/dist/resolvers/meetings/meetingMutations.js.map +1 -1
- package/dist/services/TaskGraphContinuationDeliverer.d.ts +4 -3
- package/dist/services/TaskGraphContinuationDeliverer.d.ts.map +1 -1
- package/dist/services/TaskGraphContinuationDeliverer.js +13 -7
- package/dist/services/TaskGraphContinuationDeliverer.js.map +1 -1
- package/dist/sharedCache.d.ts +105 -0
- package/dist/sharedCache.d.ts.map +1 -0
- package/dist/sharedCache.js +276 -0
- package/dist/sharedCache.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +97 -95
- package/src/__tests__/ActionResolver.authorization.test.ts +353 -0
- package/src/__tests__/AdhocQueryResolver.sqlAuthorizer.test.ts +104 -0
- package/src/__tests__/BridgeHostInstance.test.ts +232 -0
- package/src/__tests__/ClientToolRequestResolver.test.ts +116 -0
- package/src/__tests__/FetchEntityVectorsResolver.test.ts +285 -0
- package/src/__tests__/HostInstance.test.ts +84 -0
- package/src/__tests__/HumanHandoffResolver.test.ts +17 -0
- package/src/__tests__/MeetingResolver.test.ts +75 -1
- package/src/__tests__/RealtimeBridgeResolver.test.ts +415 -6
- package/src/__tests__/RealtimeClientSessionResolver.configTamper.test.ts +383 -0
- package/src/__tests__/RealtimeClientSessionResolver.test.ts +682 -58
- package/src/__tests__/RealtimeProxyServer.test.ts +16 -1
- package/src/__tests__/RealtimeRelay.test.ts +876 -0
- package/src/__tests__/RemoteBrowserActionResolver.goalRunLink.test.ts +129 -0
- package/src/__tests__/ResolverBase.aggregateScreen.test.ts +174 -0
- package/src/__tests__/ResolverBase.clientOldValues.test.ts +6 -3
- package/src/__tests__/ReturningVisitorRecap.test.ts +115 -0
- package/src/__tests__/RunAIAgentResolver.branch.test.ts +169 -0
- package/src/__tests__/RunAIAgentResolver.historyFrom.test.ts +4 -4
- package/src/__tests__/RunAIAgentResolver.stoppedPredecessor.test.ts +166 -0
- package/src/__tests__/RunTemplateResolver.test.ts +132 -0
- package/src/__tests__/RunViewResolver.cacheCheckForwarding.test.ts +63 -0
- package/src/__tests__/SessionJanitor.test.ts +845 -18
- package/src/__tests__/SessionManager.test.ts +213 -17
- package/src/__tests__/SessionRunIDVerifier.test.ts +251 -0
- package/src/__tests__/SyncRolesUsersResolver.userRoles.test.ts +97 -0
- package/src/__tests__/TaskGraphContinuationDeliverer.test.ts +50 -3
- package/src/__tests__/UserAvatarResolver.test.ts +255 -0
- package/src/__tests__/UserResolver.currentUser.test.ts +16 -1
- package/src/__tests__/actionAuthorization.test.ts +130 -0
- package/src/__tests__/agentVisionConsentAudit.test.ts +118 -0
- package/src/__tests__/avatarInputValidation.test.ts +160 -0
- package/src/__tests__/isolatedProviderTransactions.test.ts +169 -0
- package/src/__tests__/magicLinkService.consume.test.ts +6 -0
- package/src/__tests__/magicLinkService.provisionLog.test.ts +5 -0
- package/src/__tests__/newUsers.template.test.ts +151 -0
- package/src/__tests__/newUsers.test.ts +74 -5
- package/src/__tests__/orphanedConversationDetailReconciler.test.ts +17 -2
- package/src/__tests__/realtimeSessions/RealtimeSessionEventService.test.ts +201 -0
- package/src/__tests__/realtimeSessions/RealtimeSessionEventsResolver.test.ts +215 -0
- package/src/__tests__/realtimeSessions/RealtimeSessionVerificationResolver.test.ts +102 -0
- package/src/__tests__/realtimeSessions/RealtimeSessionVerificationService.test.ts +349 -0
- package/src/__tests__/realtimeSessions/RealtimeVerifyRouter.test.ts +131 -0
- package/src/__tests__/realtimeSessions/SlidingWindowRateLimiter.test.ts +56 -0
- package/src/__tests__/realtimeSessions/helpers.ts +4 -0
- package/src/__tests__/realtimeSessions/sessionAccess.test.ts +129 -0
- package/src/__tests__/realtimeSessions/sessionConfigStamps.test.ts +124 -0
- package/src/__tests__/realtimeSessions/verificationCore.test.ts +355 -0
- package/src/__tests__/realtimeSessions/verificationPages.test.ts +84 -0
- package/src/__tests__/realtimeSessions/verificationPolicy.test.ts +226 -0
- package/src/__tests__/realtimeSessions/verificationWorkflow.test.ts +633 -0
- package/src/__tests__/resolverBase.fls.test.ts +87 -4
- package/src/__tests__/serverExtensionReservedRoots.test.ts +2 -0
- package/src/__tests__/sharedCache.test.ts +310 -0
- package/src/__tests__/widgetGuestElevation.test.ts +44 -0
- package/src/agentSessions/BridgeHostInstance.ts +32 -0
- package/src/agentSessions/HostInstance.ts +124 -28
- package/src/agentSessions/ReturningVisitorRecap.ts +7 -3
- package/src/agentSessions/SessionJanitor.ts +543 -57
- package/src/agentSessions/SessionManager.ts +125 -25
- package/src/agentSessions/SessionRunIDVerifier.ts +171 -0
- package/src/agentSessions/index.ts +10 -3
- package/src/auth/actionAuthorization.ts +116 -0
- package/src/auth/index.ts +3 -8
- package/src/auth/magicLink/MagicLinkService.ts +6 -3
- package/src/auth/newUsers.ts +99 -11
- package/src/config.ts +125 -0
- package/src/context.ts +15 -10
- package/src/generated/graphql-schemas/__mj.ts +496 -1
- package/src/generic/OrphanedConversationDetailReconciler.ts +3 -3
- package/src/generic/ResolverBase.ts +39 -9
- package/src/generic/RunViewResolver.ts +4 -0
- package/src/index.ts +132 -143
- package/src/isolatedProvider.ts +22 -0
- package/src/realtimeProxy/RealtimeProxyServer.ts +148 -16
- package/src/realtimeProxy/RealtimeRelayTunnel.ts +645 -0
- package/src/realtimeSessions/README.md +179 -0
- package/src/realtimeSessions/RealtimeSessionEventService.ts +274 -0
- package/src/realtimeSessions/RealtimeSessionVerificationService.ts +167 -0
- package/src/realtimeSessions/RealtimeVerifyRouter.ts +108 -0
- package/src/realtimeSessions/SessionVerificationPortsBase.ts +189 -0
- package/src/realtimeSessions/SlidingWindowRateLimiter.ts +92 -0
- package/src/realtimeSessions/index.ts +16 -0
- package/src/realtimeSessions/sessionAccess.ts +141 -0
- package/src/realtimeSessions/sessionConfigStamps.ts +123 -0
- package/src/realtimeSessions/subscriptionAuthorization.ts +116 -0
- package/src/realtimeSessions/verificationCore.ts +502 -0
- package/src/realtimeSessions/verificationPages.ts +149 -0
- package/src/realtimeSessions/verificationPolicy.ts +321 -0
- package/src/realtimeSessions/verificationWorkflow.ts +702 -0
- package/src/realtimeWidget/widgetGuestElevation.ts +34 -2
- package/src/resolvers/ActionResolver.ts +84 -21
- package/src/resolvers/AdhocQueryResolver.ts +24 -6
- package/src/resolvers/CacheStatsResolver.ts +89 -2
- package/src/resolvers/ClientToolRequestResolver.ts +25 -7
- package/src/resolvers/FetchEntityVectorsResolver.ts +97 -2
- package/src/resolvers/HumanHandoffResolver.ts +8 -0
- package/src/resolvers/MCPResolver.ts +8 -5
- package/src/resolvers/RealtimeBridgeResolver.ts +163 -11
- package/src/resolvers/RealtimeClientSessionResolver.ts +501 -96
- package/src/resolvers/RealtimeSessionEventsResolver.ts +133 -0
- package/src/resolvers/RealtimeSessionVerificationResolver.ts +174 -0
- package/src/resolvers/RemoteBrowserActionResolver.ts +11 -1
- package/src/resolvers/RunAIAgentResolver.ts +78 -11
- package/src/resolvers/RunTemplateResolver.ts +13 -12
- package/src/resolvers/SyncDataResolver.ts +6 -2
- package/src/resolvers/SyncRolesUsersResolver.ts +24 -6
- package/src/resolvers/UserAvatarResolver.ts +111 -0
- package/src/resolvers/UserResolver.ts +2 -16
- package/src/resolvers/agentVisionConsentAudit.ts +82 -0
- package/src/resolvers/avatarInputValidation.ts +123 -0
- package/src/resolvers/currentUserRoles.ts +32 -1
- package/src/resolvers/meetings/meetingMutations.ts +21 -0
- package/src/services/TaskGraphContinuationDeliverer.ts +13 -7
- package/src/sharedCache.ts +302 -0
- package/src/types.ts +7 -0
|
@@ -7,8 +7,10 @@ import {
|
|
|
7
7
|
} from '@memberjunction/core-entities';
|
|
8
8
|
import { AIAgentPermissionHelper } from '@memberjunction/ai-engine-base';
|
|
9
9
|
import { RealtimeClientSessionService, RealtimeChannelServerHost } from '@memberjunction/ai-agents';
|
|
10
|
+
import type { BridgeDisconnectReason } from '@memberjunction/ai-bridge-base';
|
|
10
11
|
import { GetHostInstanceID } from './HostInstance.js';
|
|
11
12
|
import { WriteReturningVisitorRecap } from './ReturningVisitorRecap.js';
|
|
13
|
+
import { SessionRunIDVerifier, SessionRunIDs } from './SessionRunIDVerifier.js';
|
|
12
14
|
import { ResolveScopedAnonymousRunUser } from '../realtimeWidget/widgetGuestElevation.js';
|
|
13
15
|
|
|
14
16
|
/** Entity names — centralised so the `MJ:`-prefix convention is applied in exactly one place. */
|
|
@@ -16,18 +18,6 @@ const SESSION_ENTITY = 'MJ: AI Agent Sessions';
|
|
|
16
18
|
const SESSION_CHANNEL_ENTITY = 'MJ: AI Agent Session Channels';
|
|
17
19
|
const CONVERSATION_ENTITY = 'MJ: Conversations';
|
|
18
20
|
|
|
19
|
-
/**
|
|
20
|
-
* Shape of the observability run ids a realtime voice session persists in `AIAgentSession.Config_`.
|
|
21
|
-
* Read on {@link SessionManager.CloseSession} to finalize the co-agent runs. All fields optional —
|
|
22
|
-
* a non-voice session (or one whose run creation was skipped) carries none of them.
|
|
23
|
-
*/
|
|
24
|
-
interface SessionRunConfig {
|
|
25
|
-
coAgentRunID?: string;
|
|
26
|
-
promptRunID?: string;
|
|
27
|
-
/** The co-agent run's single system-prompt `MJ: AI Agent Run Steps` row id (its Timeline entry). */
|
|
28
|
-
coAgentRunStepID?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
21
|
/**
|
|
32
22
|
* Inputs for {@link SessionManager.CreateSession}. `conversationID`/`lastSessionID`/`config`
|
|
33
23
|
* are optional — when no `conversationID` is supplied a fresh Conversation is created and linked.
|
|
@@ -54,6 +44,24 @@ export interface CreateSessionInput {
|
|
|
54
44
|
*/
|
|
55
45
|
export type SessionCloseReason = 'Explicit' | 'Janitor' | 'Shutdown' | 'Error';
|
|
56
46
|
|
|
47
|
+
/**
|
|
48
|
+
* The {@link SessionCloseReason} for a session whose bridged agent has left (see
|
|
49
|
+
* {@link SessionManager.CloseSessionForEndedBridge}). The bridge's reason carries over where the session has the same one;
|
|
50
|
+
* `HostEnded` (everyone left the room, the call hung up) closes it as `Explicit`, people ending it, as phone calls close
|
|
51
|
+
* theirs.
|
|
52
|
+
*/
|
|
53
|
+
function sessionCloseReasonForBridgeEnd(reason: BridgeDisconnectReason): SessionCloseReason {
|
|
54
|
+
switch (reason) {
|
|
55
|
+
case 'Error':
|
|
56
|
+
case 'Janitor':
|
|
57
|
+
case 'Shutdown':
|
|
58
|
+
return reason;
|
|
59
|
+
case 'Explicit':
|
|
60
|
+
case 'HostEnded':
|
|
61
|
+
return 'Explicit';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
/**
|
|
58
66
|
* Thrown by {@link SessionManager.CreateSession} when the caller lacks `CanRun` on the target
|
|
59
67
|
* agent. No session row is created — denial happens before any write. Distinct error type so the
|
|
@@ -126,6 +134,9 @@ export class SessionManager {
|
|
|
126
134
|
*/
|
|
127
135
|
private readonly realtimeClientSessionService: RealtimeClientSessionService;
|
|
128
136
|
|
|
137
|
+
/** Checks the run ids read from a session's owner-editable `Config_` before they are used. */
|
|
138
|
+
private readonly runIDVerifier = new SessionRunIDVerifier();
|
|
139
|
+
|
|
129
140
|
/**
|
|
130
141
|
* @param realtimeClientSessionService The shared {@link RealtimeClientSessionService} instance to
|
|
131
142
|
* finalize observability runs through. Pass the SAME instance your resolver/service used to create
|
|
@@ -211,6 +222,68 @@ export class SessionManager {
|
|
|
211
222
|
return true;
|
|
212
223
|
}
|
|
213
224
|
|
|
225
|
+
/**
|
|
226
|
+
* Closes a session that was created for one bridged agent (a bot in a meeting room) once that agent's bridge has
|
|
227
|
+
* ended, whatever ended it: the agent was stopped, the meeting was ended, everyone left, the model session was lost.
|
|
228
|
+
* Without this the session stays `Active` until the janitor's staleness sweep closes it, 15 minutes or more later.
|
|
229
|
+
*
|
|
230
|
+
* The close is {@link CloseSession}, the one the janitor runs, with the bridge's reason: `Explicit` for a stop, an
|
|
231
|
+
* ended meeting or an emptied room (`HostEnded`), otherwise the bridge's own (`Error`, `Janitor`, `Shutdown`). A
|
|
232
|
+
* session already closed (by the janitor, or by its user) keeps its reason.
|
|
233
|
+
*
|
|
234
|
+
* Never throws: it runs as the bridge's end-of-session bookkeeping. A failure is logged and leaves the session to the
|
|
235
|
+
* janitor, as before.
|
|
236
|
+
*
|
|
237
|
+
* @param agentSessionID The session created for the bridged agent.
|
|
238
|
+
* @param reason Why the bridge ended.
|
|
239
|
+
* @param contextUser The user the session was created for.
|
|
240
|
+
* @param provider The metadata provider the session was created through.
|
|
241
|
+
* @returns `true` when the session is (or already was) closed.
|
|
242
|
+
*/
|
|
243
|
+
public async CloseSessionForEndedBridge(
|
|
244
|
+
agentSessionID: string,
|
|
245
|
+
reason: BridgeDisconnectReason,
|
|
246
|
+
contextUser: UserInfo,
|
|
247
|
+
provider: IMetadataProvider,
|
|
248
|
+
): Promise<boolean> {
|
|
249
|
+
try {
|
|
250
|
+
return await this.CloseSession(agentSessionID, contextUser, provider, sessionCloseReasonForBridgeEnd(reason));
|
|
251
|
+
} catch (e) {
|
|
252
|
+
LogError(
|
|
253
|
+
`SessionManager.CloseSessionForEndedBridge could not close agent session ${agentSessionID} after its bridge ended ` +
|
|
254
|
+
`(${reason}); the janitor will: ${e instanceof Error ? e.message : String(e)}`,
|
|
255
|
+
);
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Closes a session that was created for one agent's time in a room when that agent failed to start: its model session
|
|
262
|
+
* could not open, the bot's token could not be minted, the bridge did not start. The agent never joined, so no
|
|
263
|
+
* end-of-session hook will close the session; without this it stays `Active` until the janitor's staleness sweep.
|
|
264
|
+
*
|
|
265
|
+
* The close is {@link CloseSession} with reason `Error`. A session already closed keeps its reason.
|
|
266
|
+
*
|
|
267
|
+
* Never throws: it runs while the caller handles the failed start, whose error is the one the caller reports. A failure
|
|
268
|
+
* is logged and leaves the session to the janitor.
|
|
269
|
+
*
|
|
270
|
+
* @param agentSessionID The session created for the agent.
|
|
271
|
+
* @param contextUser The user the session was created for.
|
|
272
|
+
* @param provider The metadata provider the session was created through.
|
|
273
|
+
* @returns `true` when the session is (or already was) closed.
|
|
274
|
+
*/
|
|
275
|
+
public async CloseSessionForFailedStart(agentSessionID: string, contextUser: UserInfo, provider: IMetadataProvider): Promise<boolean> {
|
|
276
|
+
try {
|
|
277
|
+
return await this.CloseSession(agentSessionID, contextUser, provider, 'Error');
|
|
278
|
+
} catch (e) {
|
|
279
|
+
LogError(
|
|
280
|
+
`SessionManager.CloseSessionForFailedStart could not close agent session ${agentSessionID} after its agent failed ` +
|
|
281
|
+
`to start; the janitor will: ${e instanceof Error ? e.message : String(e)}`,
|
|
282
|
+
);
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
214
287
|
/**
|
|
215
288
|
* Notifies the server-side channel-plugin host that a session started, so it can resolve the
|
|
216
289
|
* ACTIVE `MJ: AI Agent Channels` rows' `ServerPluginClass` plugins (one fresh instance per
|
|
@@ -260,7 +333,8 @@ export class SessionManager {
|
|
|
260
333
|
|
|
261
334
|
/**
|
|
262
335
|
* Finalizes the co-agent observability runs a realtime voice session stored in its `Config_`
|
|
263
|
-
* (see `RealtimeClientSessionResolver`).
|
|
336
|
+
* (see `RealtimeClientSessionResolver`). Only run ids that are records of the session are
|
|
337
|
+
* finalized, because the owner can edit `Config_`. No-op when none remain. Tolerant: a
|
|
264
338
|
* malformed config or a finalize failure is swallowed so it can never break session close.
|
|
265
339
|
*/
|
|
266
340
|
private async finalizeObservabilityRuns(
|
|
@@ -268,8 +342,8 @@ export class SessionManager {
|
|
|
268
342
|
contextUser: UserInfo,
|
|
269
343
|
provider: IMetadataProvider,
|
|
270
344
|
): Promise<void> {
|
|
271
|
-
const
|
|
272
|
-
if (!
|
|
345
|
+
const claimed = this.parseSessionRunConfig(session.Config_);
|
|
346
|
+
if (!claimed.CoAgentRunID && !claimed.PromptRunID && !claimed.CoAgentRunStepID) {
|
|
273
347
|
return;
|
|
274
348
|
}
|
|
275
349
|
try {
|
|
@@ -277,36 +351,54 @@ export class SessionManager {
|
|
|
277
351
|
// for a scoped anonymous session, so an owner-initiated (or error) close must finalize
|
|
278
352
|
// under it too — the caller's role holds no grants on the AI run entities. Janitor and
|
|
279
353
|
// shutdown sweeps already close as the system user and pass through unchanged.
|
|
354
|
+
const runUser = ResolveScopedAnonymousRunUser(contextUser);
|
|
355
|
+
const runIDs = await this.runIDVerifier.Verify(session.ID, claimed, runUser, provider);
|
|
356
|
+
if (!runIDs.CoAgentRunID && !runIDs.PromptRunID && !runIDs.CoAgentRunStepID) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
280
359
|
await this.realtimeClientSessionService.FinalizeCoAgentRun(
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
360
|
+
runIDs.CoAgentRunID ?? null,
|
|
361
|
+
runIDs.PromptRunID ?? null,
|
|
362
|
+
runUser,
|
|
284
363
|
provider,
|
|
285
364
|
true,
|
|
286
|
-
|
|
365
|
+
runIDs.CoAgentRunStepID ?? null,
|
|
287
366
|
);
|
|
288
367
|
} catch (e) {
|
|
289
368
|
LogError(`SessionManager.finalizeObservabilityRuns failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
290
369
|
}
|
|
291
370
|
}
|
|
292
371
|
|
|
293
|
-
/** Parses the session's `Config_` for observability run ids; returns
|
|
294
|
-
private parseSessionRunConfig(raw: string | null):
|
|
372
|
+
/** Parses the session's `Config_` for observability run ids; returns none on any error. */
|
|
373
|
+
private parseSessionRunConfig(raw: string | null): SessionRunIDs {
|
|
295
374
|
if (!raw) {
|
|
296
375
|
return {};
|
|
297
376
|
}
|
|
298
377
|
try {
|
|
299
|
-
const parsed = JSON.parse(raw) as
|
|
378
|
+
const parsed = JSON.parse(raw) as { coAgentRunID?: unknown; promptRunID?: unknown; coAgentRunStepID?: unknown };
|
|
300
379
|
return {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
380
|
+
CoAgentRunID: typeof parsed.coAgentRunID === 'string' ? parsed.coAgentRunID : undefined,
|
|
381
|
+
PromptRunID: typeof parsed.promptRunID === 'string' ? parsed.promptRunID : undefined,
|
|
382
|
+
CoAgentRunStepID: typeof parsed.coAgentRunStepID === 'string' ? parsed.coAgentRunStepID : undefined,
|
|
304
383
|
};
|
|
305
384
|
} catch {
|
|
306
385
|
return {};
|
|
307
386
|
}
|
|
308
387
|
}
|
|
309
388
|
|
|
389
|
+
/** The session's co-agent run id from its `Config_`, when it is a run of the session. */
|
|
390
|
+
private async verifiedCoAgentRunID(
|
|
391
|
+
session: MJAIAgentSessionEntity,
|
|
392
|
+
runUser: UserInfo,
|
|
393
|
+
provider: IMetadataProvider,
|
|
394
|
+
): Promise<string | undefined> {
|
|
395
|
+
const { CoAgentRunID } = this.parseSessionRunConfig(session.Config_);
|
|
396
|
+
if (!CoAgentRunID) {
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
return (await this.runIDVerifier.Verify(session.ID, { CoAgentRunID }, runUser, provider)).CoAgentRunID;
|
|
400
|
+
}
|
|
401
|
+
|
|
310
402
|
/**
|
|
311
403
|
* Record activity on a session. Coalesces persisted writes so at most one `LastActiveAt` update
|
|
312
404
|
* lands per session per {@link HEARTBEAT_MIN_WRITE_INTERVAL_MS}; intervening calls return `true`
|
|
@@ -565,6 +657,14 @@ export class SessionManager {
|
|
|
565
657
|
const saved = await this.saveOrLog(session, 'Heartbeat');
|
|
566
658
|
if (saved) {
|
|
567
659
|
this.heartbeatLastWrite.Set(agentSessionID.toLowerCase(), Date.now());
|
|
660
|
+
// A live session keeps its co-agent run live too — on whichever instance gets its heartbeats —
|
|
661
|
+
// or the agent-run watchdog force-fails the run mid-call. Same elevation as the finalize path.
|
|
662
|
+
const runUser = ResolveScopedAnonymousRunUser(contextUser);
|
|
663
|
+
this.realtimeClientSessionService.KeepCoAgentRunAlive(
|
|
664
|
+
await this.verifiedCoAgentRunID(session, runUser, provider),
|
|
665
|
+
provider,
|
|
666
|
+
runUser,
|
|
667
|
+
);
|
|
568
668
|
}
|
|
569
669
|
return saved;
|
|
570
670
|
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Checks the run ids a realtime session keeps in its `Config` before server code
|
|
3
|
+
* acts on them.
|
|
4
|
+
*
|
|
5
|
+
* @module @memberjunction/server
|
|
6
|
+
*/
|
|
7
|
+
import { IMetadataProvider, LogError, RunView, RunViewParams, UserInfo } from '@memberjunction/core';
|
|
8
|
+
import { EscapeSQLString, IsValidUUID, UUIDsEqual } from '@memberjunction/global';
|
|
9
|
+
import { UserCache } from '@memberjunction/generic-database-provider';
|
|
10
|
+
|
|
11
|
+
const AGENT_RUN_ENTITY = 'MJ: AI Agent Runs';
|
|
12
|
+
const AGENT_RUN_STEP_ENTITY = 'MJ: AI Agent Run Steps';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The run ids a realtime voice session keeps in its `Config` JSON. Server code reads and writes the
|
|
16
|
+
* records they point at, often as an elevated user.
|
|
17
|
+
*/
|
|
18
|
+
export interface SessionRunIDs {
|
|
19
|
+
/** The co-agent observability run (`MJ: AI Agent Runs`). */
|
|
20
|
+
CoAgentRunID?: string;
|
|
21
|
+
/** The co-agent prompt run (`MJ: AI Prompt Runs`), linked through the co-agent run's prompt step. */
|
|
22
|
+
PromptRunID?: string;
|
|
23
|
+
/** The co-agent run's system-prompt step (`MJ: AI Agent Run Steps`). */
|
|
24
|
+
CoAgentRunStepID?: string;
|
|
25
|
+
/** A delegated run (`MJ: AI Agent Runs`) that paused for the user's answer. */
|
|
26
|
+
PendingFeedbackRunID?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** A row of the run-step lookup. */
|
|
30
|
+
interface RunStepRow {
|
|
31
|
+
ID: string;
|
|
32
|
+
StepType: string;
|
|
33
|
+
TargetLogID: string | null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A row of either lookup; the run lookup returns only `ID`. */
|
|
37
|
+
type LookupRow = Partial<RunStepRow> & { ID: string };
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Keeps the run ids from a session's `Config` that are records of that session.
|
|
41
|
+
*
|
|
42
|
+
* The session owner can edit `Config`, so its run ids are claims. A run id is kept when it is the
|
|
43
|
+
* UUID of an `MJ: AI Agent Runs` row whose `AgentSessionID` is the session. The step id and the
|
|
44
|
+
* prompt run id are kept when they belong to that co-agent run: the step's `AgentRunID` is the
|
|
45
|
+
* co-agent run, and the prompt run is the `TargetLogID` of one of its `Prompt` steps.
|
|
46
|
+
*
|
|
47
|
+
* The lookups run as the system user when one is cached, else as the acting user. They are pinned
|
|
48
|
+
* to the session's id and return nothing to the caller, and row-level security can hide a session's
|
|
49
|
+
* own runs from its owner (a web-widget guest's delegated runs carry no `ConversationID`, which the
|
|
50
|
+
* guest's run filter keys on).
|
|
51
|
+
*
|
|
52
|
+
* Each call reads the database again (`BypassCache`) and keeps no result, because the links can
|
|
53
|
+
* change after a lookup: a run's `AgentSessionID` and a step's `AgentRunID` and `TargetLogID` are
|
|
54
|
+
* updatable.
|
|
55
|
+
*/
|
|
56
|
+
export class SessionRunIDVerifier {
|
|
57
|
+
/**
|
|
58
|
+
* Returns the subset of `claimed` that belongs to the session now. Never throws: when a lookup
|
|
59
|
+
* fails, nothing is kept.
|
|
60
|
+
*
|
|
61
|
+
* @param sessionID The `MJ: AI Agent Sessions` id the claims were read from. The caller must have
|
|
62
|
+
* checked that the session is the caller's own.
|
|
63
|
+
* @param claimed The run ids read from the session's `Config`.
|
|
64
|
+
* @param contextUser The acting user; the lookups run as it only when no system user is cached.
|
|
65
|
+
* @param provider The request-scoped metadata provider.
|
|
66
|
+
* @returns The claims that are records of the session.
|
|
67
|
+
*/
|
|
68
|
+
public async Verify(
|
|
69
|
+
sessionID: string,
|
|
70
|
+
claimed: SessionRunIDs,
|
|
71
|
+
contextUser: UserInfo,
|
|
72
|
+
provider: IMetadataProvider,
|
|
73
|
+
): Promise<SessionRunIDs> {
|
|
74
|
+
const candidates = this.keepUUIDs(claimed);
|
|
75
|
+
if (!candidates.CoAgentRunID && !candidates.PendingFeedbackRunID) {
|
|
76
|
+
return {};
|
|
77
|
+
}
|
|
78
|
+
return (await this.lookUpOwned(sessionID.trim(), candidates, contextUser, provider)) ?? {};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Drops every claim that is not a UUID. The prompt run and step need a co-agent run to hang off. */
|
|
82
|
+
private keepUUIDs(claimed: SessionRunIDs): SessionRunIDs {
|
|
83
|
+
const coAgentRunID = this.uuidOrUndefined(claimed.CoAgentRunID);
|
|
84
|
+
return {
|
|
85
|
+
CoAgentRunID: coAgentRunID,
|
|
86
|
+
PromptRunID: coAgentRunID ? this.uuidOrUndefined(claimed.PromptRunID) : undefined,
|
|
87
|
+
CoAgentRunStepID: coAgentRunID ? this.uuidOrUndefined(claimed.CoAgentRunStepID) : undefined,
|
|
88
|
+
PendingFeedbackRunID: this.uuidOrUndefined(claimed.PendingFeedbackRunID),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private uuidOrUndefined(value: string | undefined): string | undefined {
|
|
93
|
+
return value && IsValidUUID(value) ? value.trim() : undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Runs the lookups; `null` when one of them fails. */
|
|
97
|
+
private async lookUpOwned(
|
|
98
|
+
sessionID: string,
|
|
99
|
+
candidates: SessionRunIDs,
|
|
100
|
+
contextUser: UserInfo,
|
|
101
|
+
provider: IMetadataProvider,
|
|
102
|
+
): Promise<SessionRunIDs | null> {
|
|
103
|
+
const stepsQuery = this.stepsQuery(candidates);
|
|
104
|
+
const queries = stepsQuery ? [this.runsQuery(sessionID, candidates), stepsQuery] : [this.runsQuery(sessionID, candidates)];
|
|
105
|
+
try {
|
|
106
|
+
const lookupUser = UserCache.Instance.GetSystemUser() ?? contextUser;
|
|
107
|
+
const [runs, steps] = await RunView.FromMetadataProvider(provider).RunViews<LookupRow>(queries, lookupUser);
|
|
108
|
+
const failed = [runs, steps].find((result) => result && !result.Success);
|
|
109
|
+
if (!runs || failed) {
|
|
110
|
+
LogError(`SessionRunIDVerifier: run lookup failed for session ${sessionID}: ${failed?.ErrorMessage ?? 'no result'}`);
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
return this.pickOwned(candidates, runs.Results, steps?.Results ?? []);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
LogError(`SessionRunIDVerifier: run lookup failed for session ${sessionID}: ${error instanceof Error ? error.message : String(error)}`);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The claimed runs that carry this session's id. */
|
|
121
|
+
private runsQuery(sessionID: string, candidates: SessionRunIDs): RunViewParams {
|
|
122
|
+
const ids = [candidates.CoAgentRunID, candidates.PendingFeedbackRunID]
|
|
123
|
+
.filter((id): id is string => !!id)
|
|
124
|
+
.map((id) => `'${EscapeSQLString(id)}'`);
|
|
125
|
+
return {
|
|
126
|
+
EntityName: AGENT_RUN_ENTITY,
|
|
127
|
+
ExtraFilter: `AgentSessionID='${EscapeSQLString(sessionID)}' AND ID IN (${ids.join(', ')})`,
|
|
128
|
+
Fields: ['ID'],
|
|
129
|
+
ResultType: 'simple',
|
|
130
|
+
BypassCache: true,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The claimed co-agent run's steps that match the claimed step or prompt run; `null` when neither is claimed. */
|
|
135
|
+
private stepsQuery(candidates: SessionRunIDs): RunViewParams | null {
|
|
136
|
+
const matches: string[] = [];
|
|
137
|
+
if (candidates.CoAgentRunStepID) {
|
|
138
|
+
matches.push(`ID='${EscapeSQLString(candidates.CoAgentRunStepID)}'`);
|
|
139
|
+
}
|
|
140
|
+
if (candidates.PromptRunID) {
|
|
141
|
+
matches.push(`TargetLogID='${EscapeSQLString(candidates.PromptRunID)}'`);
|
|
142
|
+
}
|
|
143
|
+
if (!candidates.CoAgentRunID || matches.length === 0) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
EntityName: AGENT_RUN_STEP_ENTITY,
|
|
148
|
+
ExtraFilter: `AgentRunID='${EscapeSQLString(candidates.CoAgentRunID)}' AND (${matches.join(' OR ')})`,
|
|
149
|
+
Fields: ['ID', 'StepType', 'TargetLogID'],
|
|
150
|
+
ResultType: 'simple',
|
|
151
|
+
BypassCache: true,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private pickOwned(candidates: SessionRunIDs, runs: LookupRow[], steps: LookupRow[]): SessionRunIDs {
|
|
156
|
+
const isOwnedRun = (id: string | undefined): boolean => !!id && runs.some((row) => UUIDsEqual(row.ID, id));
|
|
157
|
+
const coAgentRunID = isOwnedRun(candidates.CoAgentRunID) ? candidates.CoAgentRunID : undefined;
|
|
158
|
+
const ownedSteps = coAgentRunID ? steps : [];
|
|
159
|
+
const stepID = candidates.CoAgentRunStepID;
|
|
160
|
+
const promptRunID = candidates.PromptRunID;
|
|
161
|
+
return {
|
|
162
|
+
CoAgentRunID: coAgentRunID,
|
|
163
|
+
CoAgentRunStepID: stepID && ownedSteps.some((row) => UUIDsEqual(row.ID, stepID)) ? stepID : undefined,
|
|
164
|
+
PromptRunID:
|
|
165
|
+
promptRunID && ownedSteps.some((row) => row.StepType === 'Prompt' && UUIDsEqual(row.TargetLogID, promptRunID))
|
|
166
|
+
? promptRunID
|
|
167
|
+
: undefined,
|
|
168
|
+
PendingFeedbackRunID: isOwnedRun(candidates.PendingFeedbackRunID) ? candidates.PendingFeedbackRunID : undefined,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* @fileoverview AI Agent Session lifecycle substrate (server-side, record + janitor layer).
|
|
3
3
|
*
|
|
4
4
|
* Exposes the session-record lifecycle manager, the orphan-reconciliation janitor, and the
|
|
5
|
-
*
|
|
6
|
-
* realtime
|
|
5
|
+
* host-instance identity (`hostname:port:pid:bootId`) the janitor matches sessions by, which the
|
|
6
|
+
* realtime bridge engine is given for its bridge rows too (`BindBridgeEngineHostInstance`). The
|
|
7
|
+
* audio/media (WebRTC) transport and the long-lived realtime agent run are deliberately **not**
|
|
8
|
+
* part of this layer — they arrive in P5.
|
|
7
9
|
*
|
|
8
10
|
* @module @memberjunction/server
|
|
9
11
|
*/
|
|
10
|
-
import { LoadWhiteboardChannelServer, LoadMeetingControlsChannelServer, LoadMediaChannelServer, LoadClientContextChannelServer } from '@memberjunction/ai-agents';
|
|
12
|
+
import { LoadWhiteboardChannelServer, LoadMeetingControlsChannelServer, LoadMediaChannelServer, LoadClientContextChannelServer, LoadClientOnlyChannelServer, LoadIdentityVerificationChannelServer, LoadInteractiveComponentChannelServer } from '@memberjunction/ai-agents';
|
|
11
13
|
import { LoadRemoteBrowserChannel } from '@memberjunction/remote-browser-server';
|
|
12
14
|
import { LoadSelfHostRemoteBrowser } from '@memberjunction/remote-browser-selfhost';
|
|
13
15
|
import { BindRemoteBrowserGoalEngine } from './remoteBrowserGoalEngine.js';
|
|
@@ -19,6 +21,9 @@ LoadWhiteboardChannelServer();
|
|
|
19
21
|
LoadMeetingControlsChannelServer();
|
|
20
22
|
LoadMediaChannelServer();
|
|
21
23
|
LoadClientContextChannelServer();
|
|
24
|
+
LoadClientOnlyChannelServer();
|
|
25
|
+
LoadIdentityVerificationChannelServer();
|
|
26
|
+
LoadInteractiveComponentChannelServer();
|
|
22
27
|
// Remote Browser native channel (client-direct): the lifecycle-only server channel plugin + the
|
|
23
28
|
// Self-Hosted Chrome backend driver (whose default runner launches a local headless Chromium via
|
|
24
29
|
// Playwright — pulled in transitively through the SelfHost package, documented and acceptable).
|
|
@@ -30,5 +35,7 @@ BindRemoteBrowserGoalEngine();
|
|
|
30
35
|
|
|
31
36
|
export * from './remoteBrowserGoalEngine.js';
|
|
32
37
|
export * from './HostInstance.js';
|
|
38
|
+
export * from './BridgeHostInstance.js';
|
|
33
39
|
export * from './SessionManager.js';
|
|
34
40
|
export * from './SessionJanitor.js';
|
|
41
|
+
export * from './SessionRunIDVerifier.js';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { AuthorizationInfo, AuthorizationRoleInfo, AuthorizationRoleType, IMetadataProvider, UserInfo } from '@memberjunction/core';
|
|
2
|
+
import { FilterByUUIDs, IndexByUUID, NormalizeUUID, UUIDMap, UUIDsEqual } from '@memberjunction/global';
|
|
3
|
+
|
|
4
|
+
/** The outcome of {@link EvaluateActionRunAuthorization}. */
|
|
5
|
+
export interface ActionRunAuthorization {
|
|
6
|
+
/** True when the user may run the action. */
|
|
7
|
+
Allowed: boolean;
|
|
8
|
+
/** Why the run is allowed or refused. */
|
|
9
|
+
Reason: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** One provider's authorization tree and the role grants on it. */
|
|
13
|
+
export type AuthorizationMetadata = Pick<IMetadataProvider, 'Authorizations' | 'AuthorizationRoles'>;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* True when the user is an Owner, MJ's superuser type. The column is nchar, so the stored value is
|
|
17
|
+
* padded.
|
|
18
|
+
*/
|
|
19
|
+
export function IsOwner(user: UserInfo): boolean {
|
|
20
|
+
return user.Type?.trim().toLowerCase() === 'owner';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Decides whether a user may run an action through a public entry point such as the `RunAction`
|
|
25
|
+
* mutation. It fails closed:
|
|
26
|
+
*
|
|
27
|
+
* - An Owner may run any action.
|
|
28
|
+
* - An action with `MJ: Action Authorizations` rows runs for a user who holds at least one of the
|
|
29
|
+
* linked authorizations. A linked authorization counts only when it is active and none of the
|
|
30
|
+
* user's roles is denied it; the user may then hold it directly or through an ancestor.
|
|
31
|
+
* - An action with no such rows runs for any user when its class authorizes its caller itself
|
|
32
|
+
* (`BaseAction.AuthorizesCaller`), so the action's own check decides. Otherwise it runs for
|
|
33
|
+
* Owners only.
|
|
34
|
+
*
|
|
35
|
+
* The authorizations, their parents and their role grants are read only from `metadata`, never
|
|
36
|
+
* from the global provider. Pass the provider the `MJ: Action Authorizations` rows were read from.
|
|
37
|
+
*
|
|
38
|
+
* Refuse scope-limited sessions before calling this; see `IsScopeLimitedPrincipal`.
|
|
39
|
+
*
|
|
40
|
+
* @param user the caller
|
|
41
|
+
* @param actionAuthorizationIDs the AuthorizationID of each `MJ: Action Authorizations` row for the action
|
|
42
|
+
* @param metadata the provider whose authorizations and role grants decide
|
|
43
|
+
* @param actionAuthorizesCaller true when the action's class authorizes its caller itself
|
|
44
|
+
* @returns whether the run is allowed, and why
|
|
45
|
+
*/
|
|
46
|
+
export function EvaluateActionRunAuthorization(
|
|
47
|
+
user: UserInfo,
|
|
48
|
+
actionAuthorizationIDs: readonly string[],
|
|
49
|
+
metadata: AuthorizationMetadata,
|
|
50
|
+
actionAuthorizesCaller: boolean
|
|
51
|
+
): ActionRunAuthorization {
|
|
52
|
+
if (IsOwner(user)) {
|
|
53
|
+
return { Allowed: true, Reason: 'The user is an Owner.' };
|
|
54
|
+
}
|
|
55
|
+
if (actionAuthorizationIDs.length === 0) {
|
|
56
|
+
return actionAuthorizesCaller
|
|
57
|
+
? { Allowed: true, Reason: 'The action authorizes its caller itself.' }
|
|
58
|
+
: { Allowed: false, Reason: 'No Action Authorization grants this action to any role, and the action does not authorize its caller itself; only an Owner may run it.' };
|
|
59
|
+
}
|
|
60
|
+
const authorizationsByID = IndexByUUID(metadata.Authorizations);
|
|
61
|
+
const userGrants = grantsToUserRoles(user, metadata.AuthorizationRoles);
|
|
62
|
+
const granted = actionAuthorizationIDs
|
|
63
|
+
.map((id) => authorizationsByID.Get(id))
|
|
64
|
+
.filter((auth): auth is AuthorizationInfo => auth !== undefined)
|
|
65
|
+
.find((auth) => holdsLinkedAuthorization(auth, authorizationsByID, userGrants));
|
|
66
|
+
return granted
|
|
67
|
+
? { Allowed: true, Reason: `The user holds the "${granted.Name}" authorization.` }
|
|
68
|
+
: { Allowed: false, Reason: 'None of your roles holds an authorization this action requires.' };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The role grants that name one of the user's roles. */
|
|
72
|
+
function grantsToUserRoles(user: UserInfo, grants: readonly AuthorizationRoleInfo[]): AuthorizationRoleInfo[] {
|
|
73
|
+
const userRoleIDs = (user.UserRoles ?? []).map((userRole) => userRole.RoleID);
|
|
74
|
+
return FilterByUUIDs(grants, userRoleIDs, (grant) => grant.RoleID);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* True when the user holds a linked authorization: it is active, none of the user's roles is denied
|
|
79
|
+
* it, and the user holds it directly or through an ancestor. The first two are checked on the linked
|
|
80
|
+
* authorization itself, because the ancestor walk would otherwise grant it through the parent.
|
|
81
|
+
*/
|
|
82
|
+
function holdsLinkedAuthorization(auth: AuthorizationInfo, authorizationsByID: UUIDMap<AuthorizationInfo>, userGrants: readonly AuthorizationRoleInfo[]): boolean {
|
|
83
|
+
if (!auth.IsActive || grantTypes(auth, userGrants).includes(AuthorizationRoleType.Deny)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return holdsDirectlyOrThroughAncestor(auth, authorizationsByID, userGrants);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* True when the user holds the authorization or one of its ancestors, following `ParentID` within
|
|
91
|
+
* `authorizationsByID`. This is the walk `AuthorizationEvaluator.UserCanExecuteWithAncestors` does,
|
|
92
|
+
* with the role grants taken from the same provider as the authorizations.
|
|
93
|
+
*/
|
|
94
|
+
function holdsDirectlyOrThroughAncestor(auth: AuthorizationInfo, authorizationsByID: UUIDMap<AuthorizationInfo>, userGrants: readonly AuthorizationRoleInfo[]): boolean {
|
|
95
|
+
const visited = new Set<string>();
|
|
96
|
+
let node: AuthorizationInfo | undefined = auth;
|
|
97
|
+
while (node && !visited.has(NormalizeUUID(node.ID))) {
|
|
98
|
+
if (holdsDirectly(node, userGrants)) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
visited.add(NormalizeUUID(node.ID));
|
|
102
|
+
node = node.ParentID ? authorizationsByID.Get(node.ParentID) : undefined;
|
|
103
|
+
}
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** True when the authorization is active and the user's roles have an Allow and no Deny on it. */
|
|
108
|
+
function holdsDirectly(auth: AuthorizationInfo, userGrants: readonly AuthorizationRoleInfo[]): boolean {
|
|
109
|
+
const types = grantTypes(auth, userGrants);
|
|
110
|
+
return auth.IsActive && types.includes(AuthorizationRoleType.Allow) && !types.includes(AuthorizationRoleType.Deny);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Allow or Deny, for each of the user's role grants on the authorization. */
|
|
114
|
+
function grantTypes(auth: AuthorizationInfo, userGrants: readonly AuthorizationRoleInfo[]): AuthorizationRoleType[] {
|
|
115
|
+
return userGrants.filter((grant) => UUIDsEqual(grant.AuthorizationID, auth.ID)).map((grant) => grant.AuthorizationType());
|
|
116
|
+
}
|
package/src/auth/index.ts
CHANGED
|
@@ -253,14 +253,9 @@ export const VerifyUserRecord = async (
|
|
|
253
253
|
): Promise<UserInfo | undefined> => {
|
|
254
254
|
if (!email) return undefined;
|
|
255
255
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
// DB requires non-null but this is just an extra check and we could in theory have a blank string in the DB
|
|
260
|
-
console.error(`SYSTEM METADATA ISSUE: User ${u.ID} has no email address`);
|
|
261
|
-
return false;
|
|
262
|
-
} else return u.Email.toLowerCase().trim() === email.toLowerCase().trim();
|
|
263
|
-
});
|
|
256
|
+
// FindUser, not Users.find: a user this process has not loaded yet (created seconds ago on
|
|
257
|
+
// another server) is looked up in the database instead of being treated as nonexistent.
|
|
258
|
+
let user = await UserCache.Instance.FindUser({ Email: email });
|
|
264
259
|
|
|
265
260
|
if (!user) {
|
|
266
261
|
// NOTE: `requestDomain` (parsed from the spoofable `Origin` header) is deliberately NOT part of
|
|
@@ -34,6 +34,7 @@ import { ResolveConfiguredPrincipal } from '../principals.js';
|
|
|
34
34
|
import { CommunicationEngine } from '@memberjunction/communication-engine';
|
|
35
35
|
import { Message } from '@memberjunction/communication-types';
|
|
36
36
|
import { configInfo, type MagicLinkConfig } from '../../config.js';
|
|
37
|
+
import { CreateIsolatedProvider } from '../../isolatedProvider.js';
|
|
37
38
|
import { MagicLinkKeyManager } from './MagicLinkKeys.js';
|
|
38
39
|
import { GenerateRawToken, GenerateSessionId, HashToken, EvaluateInvite, BuildSessionClaims, BuildConsumeInvitePostgresSQL, CanIssueInvites, IsRoleGrantable, MAGIC_LINK_TOKEN_PREFIX } from './magicLinkCore.js';
|
|
39
40
|
import type {
|
|
@@ -521,9 +522,11 @@ export class MagicLinkService {
|
|
|
521
522
|
/** Creates a new user with exactly the restricted role + single app, transactionally. */
|
|
522
523
|
private async createScopedUser(invite: MJMagicLinkInviteEntity, role: RoleInfo, contextUser: UserInfo): Promise<ProvisionResult> {
|
|
523
524
|
// Single provider for BOTH the transaction and the entity writes, so the
|
|
524
|
-
// BeginTransaction/Save/Commit are provably on the same connection.
|
|
525
|
-
//
|
|
526
|
-
|
|
525
|
+
// BeginTransaction/Save/Commit are provably on the same connection. Redemption runs
|
|
526
|
+
// pre-auth, with no per-request provider yet, and the global Metadata.Provider is shared
|
|
527
|
+
// by every concurrent request: a transaction opened there nests into anyone else's and
|
|
528
|
+
// swallows their writes. So it gets its own (see CreateIsolatedProvider).
|
|
529
|
+
const provider = await CreateIsolatedProvider();
|
|
527
530
|
const email = invite.Email;
|
|
528
531
|
// The invite does not persist a name; provision a sensible default. (The
|
|
529
532
|
// create-invite params accept first/last name but there is no column to
|