@@ -164,6 +164,7 @@ type UnifiedChatBranch =
164164 fileAttachments ?: UnifiedChatRequest [ 'fileAttachments' ]
165165 userPermission ?: string
166166 userTimezone ?: string
167+ userMetadata ?: { name ?: string ; timezone ?: string }
167168 workflowId : string
168169 workflowName ?: string
169170 workspaceId ?: string
@@ -198,6 +199,7 @@ type UnifiedChatBranch =
198199 fileAttachments ?: UnifiedChatRequest [ 'fileAttachments' ]
199200 userPermission ?: string
200201 userTimezone ?: string
202+ userMetadata ?: { name ?: string ; timezone ?: string }
201203 workspaceContext ?: string
202204 } ) => Promise < Record < string , unknown > >
203205 buildExecutionContext : ( params : {
@@ -586,6 +588,7 @@ async function resolveBranch(params: {
586588 workspaceContext : payloadParams . workspaceContext ,
587589 userPermission : payloadParams . userPermission ,
588590 userTimezone : payloadParams . userTimezone ,
591+ userMetadata : payloadParams . userMetadata ,
589592 } ,
590593 { selectedModel }
591594 ) ,
@@ -644,6 +647,7 @@ async function resolveBranch(params: {
644647 workspaceContext : payloadParams . workspaceContext ,
645648 userPermission : payloadParams . userPermission ,
646649 userTimezone : payloadParams . userTimezone ,
650+ userMetadata : payloadParams . userMetadata ,
647651 includeMothershipTools : true ,
648652 } ,
649653 { selectedModel : '' }
@@ -686,8 +690,14 @@ export async function handleUnifiedChatPost(req: NextRequest) {
686690 }
687691 const authenticatedUserId = session . user . id
688692 const authenticatedUserEmail = session . user . email
693+ const authenticatedUserName =
694+ typeof session . user . name === 'string' ? session . user . name : undefined
689695
690696 const body = ChatMessageSchema . parse ( await req . json ( ) )
697+ const userMetadata = {
698+ ...( authenticatedUserName ? { name : authenticatedUserName } : { } ) ,
699+ ...( body . userTimezone ? { timezone : body . userTimezone } : { } ) ,
700+ }
691701 const normalizedContexts = normalizeContexts ( body . contexts ) ?? [ ]
692702 userMessageId = body . userMessageId || generateId ( )
693703
@@ -853,15 +863,14 @@ export async function handleUnifiedChatPost(req: NextRequest) {
853863 // opens". Previously these ran bare under the root and inflated the
854864 // apparent "gap" before the model call. Each promise is its own
855865 // span; they run concurrently under Promise.all below.
856- const workspaceContextPromise =
857- workspaceId
858- ? withCopilotSpan (
859- TraceSpan . CopilotChatBuildWorkspaceContext ,
860- { [ TraceAttr . WorkspaceId ] : workspaceId } ,
861- ( ) => generateWorkspaceContext ( workspaceId , authenticatedUserId ) ,
862- activeOtelRoot . context
863- )
864- : Promise . resolve ( undefined )
866+ const workspaceContextPromise = workspaceId
867+ ? withCopilotSpan (
868+ TraceSpan . CopilotChatBuildWorkspaceContext ,
869+ { [ TraceAttr . WorkspaceId ] : workspaceId } ,
870+ ( ) => generateWorkspaceContext ( workspaceId , authenticatedUserId ) ,
871+ activeOtelRoot . context
872+ )
873+ : Promise . resolve ( undefined )
865874 const agentContextsPromise = withCopilotSpan (
866875 TraceSpan . CopilotChatResolveAgentContexts ,
867876 {
@@ -944,6 +953,7 @@ export async function handleUnifiedChatPost(req: NextRequest) {
944953 fileAttachments : body . fileAttachments ,
945954 userPermission : userPermission ?? undefined ,
946955 userTimezone : body . userTimezone ,
956+ userMetadata,
947957 workflowId : branch . workflowId ,
948958 workflowName : branch . workflowName ,
949959 workspaceId : branch . workspaceId ,
@@ -963,6 +973,7 @@ export async function handleUnifiedChatPost(req: NextRequest) {
963973 fileAttachments : body . fileAttachments ,
964974 userPermission : userPermission ?? undefined ,
965975 userTimezone : body . userTimezone ,
976+ userMetadata,
966977 workspaceContext,
967978 } ) ,
968979 activeOtelRoot . context
0 commit comments