@@ -45,6 +45,7 @@ import type { ExecutionContext, OrchestratorResult } from '@/lib/copilot/request
4545import { persistChatResources } from '@/lib/copilot/resources/persistence'
4646import { prepareExecutionContext } from '@/lib/copilot/tools/handlers/context'
4747import { getEffectiveDecryptedEnv } from '@/lib/environment/utils'
48+ import { computeWorkspaceEntitlements } from '@/lib/workflows/custom-blocks/operations'
4849import { resolveWorkflowIdForUser } from '@/lib/workflows/utils'
4950import {
5051 getUserEntityPermissions ,
@@ -174,6 +175,7 @@ type UnifiedChatBranch =
174175 contexts : Array < { type : string ; content : string ; tag ?: string ; path ?: string } >
175176 fileAttachments ?: UnifiedChatRequest [ 'fileAttachments' ]
176177 userPermission ?: string
178+ entitlements ?: string [ ]
177179 userTimezone ?: string
178180 userMetadata ?: { name ?: string ; email ?: string ; timezone ?: string }
179181 workflowId : string
@@ -211,6 +213,7 @@ type UnifiedChatBranch =
211213 contexts : Array < { type : string ; content : string ; tag ?: string ; path ?: string } >
212214 fileAttachments ?: UnifiedChatRequest [ 'fileAttachments' ]
213215 userPermission ?: string
216+ entitlements ?: string [ ]
214217 userTimezone ?: string
215218 userMetadata ?: { name ?: string ; email ?: string ; timezone ?: string }
216219 workspaceContext ?: string
@@ -623,6 +626,7 @@ async function resolveBranch(params: {
623626 workspaceContext : payloadParams . workspaceContext ,
624627 vfs : payloadParams . vfs ,
625628 userPermission : payloadParams . userPermission ,
629+ entitlements : payloadParams . entitlements ,
626630 userTimezone : payloadParams . userTimezone ,
627631 userMetadata : payloadParams . userMetadata ,
628632 } ,
@@ -678,6 +682,7 @@ async function resolveBranch(params: {
678682 workspaceContext : payloadParams . workspaceContext ,
679683 vfs : payloadParams . vfs ,
680684 userPermission : payloadParams . userPermission ,
685+ entitlements : payloadParams . entitlements ,
681686 userTimezone : payloadParams . userTimezone ,
682687 userMetadata : payloadParams . userMetadata ,
683688 includeMothershipTools : true ,
@@ -898,6 +903,9 @@ export async function handleUnifiedChatPost(req: NextRequest) {
898903 }
899904 )
900905 : Promise . resolve ( null )
906+ const entitlementsPromise = workspaceId
907+ ? computeWorkspaceEntitlements ( workspaceId , authenticatedUserId )
908+ : Promise . resolve ( [ ] )
901909 // Wrap the pre-LLM prep work in spans so the trace waterfall shows
902910 // where time is going between "request received" and "llm.stream
903911 // opens". Previously these ran bare under the root and inflated the
@@ -952,10 +960,11 @@ export async function handleUnifiedChatPost(req: NextRequest) {
952960 activeOtelRoot . context
953961 )
954962
955- const [ agentContexts , userPermission , workspaceSnapshot , , executionContext ] =
963+ const [ agentContexts , userPermission , entitlements , workspaceSnapshot , , executionContext ] =
956964 await Promise . all ( [
957965 agentContextsPromise ,
958966 userPermissionPromise ,
967+ entitlementsPromise ,
959968 workspaceContextPromise ,
960969 persistUserMessagePromise ,
961970 executionContextPromise ,
@@ -990,6 +999,7 @@ export async function handleUnifiedChatPost(req: NextRequest) {
990999 contexts : agentContexts ,
9911000 fileAttachments : body . fileAttachments ,
9921001 userPermission : userPermission ?? undefined ,
1002+ entitlements,
9931003 userTimezone : body . userTimezone ,
9941004 userMetadata,
9951005 workflowId : branch . workflowId ,
@@ -1011,6 +1021,7 @@ export async function handleUnifiedChatPost(req: NextRequest) {
10111021 contexts : agentContexts ,
10121022 fileAttachments : body . fileAttachments ,
10131023 userPermission : userPermission ?? undefined ,
1024+ entitlements,
10141025 userTimezone : body . userTimezone ,
10151026 userMetadata,
10161027 workspaceContext,
0 commit comments