Skip to content

The open alternative to Salesforce, designed for AI.

Track unresolved mentions per member (#28719)

Raphaël Bosi23bb25b3fc56
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
index a3ee1d8c6ca..c7d6ceee207 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
@@ -123,6 +123,7 @@ type AgentChatThreadParticipant {
isSubscribed: Boolean!
lastMentionedAt: DateTime
lastReadAt: DateTime
+ mentionsResolvedAt: DateTime
snoozedUntil: DateTime
threadId: UUID!
updatedAt: DateTime!
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
index 69022aa07f1..3ff5591754b 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
@@ -120,6 +120,7 @@ export interface AgentChatThreadParticipant {
isSubscribed: Scalars['Boolean']
lastMentionedAt?: Scalars['DateTime']
lastReadAt?: Scalars['DateTime']
+ mentionsResolvedAt?: Scalars['DateTime']
snoozedUntil?: Scalars['DateTime']
threadId: Scalars['UUID']
updatedAt: Scalars['DateTime']
@@ -4323,6 +4324,7 @@ export interface AgentChatThreadParticipantGenqlSelection{
isSubscribed?: boolean | number
lastMentionedAt?: boolean | number
lastReadAt?: boolean | number
+ mentionsResolvedAt?: boolean | number
snoozedUntil?: boolean | number
threadId?: boolean | number
updatedAt?: boolean | number
diff --git a/packages/twenty-client-sdk/src/metadata/generated/types.ts b/packages/twenty-client-sdk/src/metadata/generated/types.ts
index 3373e1c7b65..cd0e0a30c09 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/types.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/types.ts
@@ -390,6 +390,9 @@ export default {
"lastReadAt": [
209
],
+ "mentionsResolvedAt": [
+ 209
+ ],
"snoozedUntil": [
209
],
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index ff8d50195ab..dbd7b4ea493 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -72,7 +72,7 @@ export type FindManyTimelineActivityTypesQueryVariables = Exact<{ [key: string]:
export type FindManyTimelineActivityTypesQuery = { timelineActivityTypes: Array<{ __typename: 'TimelineActivityType', id: string, applicationId: string | null, universalIdentifier: string, name: string, label: string, icon: string | null, frontComponentUniversalIdentifier: string | null, isActive: boolean, emit: { __typename: 'TimelineActivityTypeEmit', on: string, objectUniversalIdentifier: string | null } | null }> };
-export type AgentChatThreadParticipantFieldsFragment = { __typename: 'AgentChatThreadParticipant', id: string, threadId: string, lastReadAt: string | null, archivedAt: string | null, snoozedUntil: string | null, isSubscribed: boolean, lastMentionedAt: string | null, updatedAt: string };
+export type AgentChatThreadParticipantFieldsFragment = { __typename: 'AgentChatThreadParticipant', id: string, threadId: string, lastReadAt: string | null, archivedAt: string | null, snoozedUntil: string | null, isSubscribed: boolean, lastMentionedAt: string | null, mentionsResolvedAt: string | null, updatedAt: string };
export type AgentFieldsFragment = { __typename: 'Agent', id: string, name: string, label: string, description: string | null, icon: string | null, prompt: string, modelId: string, responseFormat: any, roleId: string | null, isSystem: boolean, isActive: boolean, modelConfiguration: any, triggers: Array<any>, applicationId: string | null, createdAt: string, updatedAt: string };
@@ -249,7 +249,7 @@ export type UpdateAgentChatThreadInboxStateMutationVariables = Exact<{
}>;
-export type UpdateAgentChatThreadInboxStateMutation = { updateAgentChatThreadInboxState: Array<{ __typename: 'AgentChatThreadParticipant', id: string, threadId: string, lastReadAt: string | null, archivedAt: string | null, snoozedUntil: string | null, isSubscribed: boolean, lastMentionedAt: string | null, updatedAt: string }> };
+export type UpdateAgentChatThreadInboxStateMutation = { updateAgentChatThreadInboxState: Array<{ __typename: 'AgentChatThreadParticipant', id: string, threadId: string, lastReadAt: string | null, archivedAt: string | null, snoozedUntil: string | null, isSubscribed: boolean, lastMentionedAt: string | null, mentionsResolvedAt: string | null, updatedAt: string }> };
export type UpdateOneAgentMutationVariables = Exact<{
input: Types.UpdateAgentInput;
@@ -2849,7 +2849,7 @@ export type FindManyMarketplaceAppsForToolTableQueryVariables = Exact<{ [key: st
export type FindManyMarketplaceAppsForToolTableQuery = { findManyMarketplaceApps: Array<{ __typename: 'MarketplaceApp', id: string, logoUrl: string | null }> };
-export const AgentChatThreadParticipantFieldsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentChatThreadParticipantFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"AgentChatThreadParticipant"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"lastReadAt"}},{"kind":"Field","name":{"kind":"Name","value":"archivedAt"}},{"kind":"Field","name":{"kind":"Name","value":"snoozedUntil"}},{"kind":"Field","name":{"kind":"Name","value":"isSubscribed"}},{"kind":"Field","name":{"kind":"Name","value":"lastMentionedAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<AgentChatThreadParticipantFieldsFragment, unknown>;
+export const AgentChatThreadParticipantFieldsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentChatThreadParticipantFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"AgentChatThreadParticipant"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"lastReadAt"}},{"kind":"Field","name":{"kind":"Name","value":"archivedAt"}},{"kind":"Field","name":{"kind":"Name","value":"snoozedUntil"}},{"kind":"Field","name":{"kind":"Name","value":"isSubscribed"}},{"kind":"Field","name":{"kind":"Name","value":"lastMentionedAt"}},{"kind":"Field","name":{"kind":"Name","value":"mentionsResolvedAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<AgentChatThreadParticipantFieldsFragment, unknown>;
export const SkillFieldsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SkillFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Skill"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<SkillFieldsFragment, unknown>;
export const AgentFieldsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Agent"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"responseFormat"}},{"kind":"Field","name":{"kind":"Name","value":"roleId"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"modelConfiguration"}},{"kind":"Field","name":{"kind":"Name","value":"triggers"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<AgentFieldsFragment, unknown>;
export const ObjectMetadataFieldsFragmentDoc = {"kind":"Document","definitions":[{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ObjectMetadataFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Object"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"universalIdentifier"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}},{"kind":"Field","name":{"kind":"Name","value":"labelSingular"}},{"kind":"Field","name":{"kind":"Name","value":"labelPlural"}},{"kind":"Field","name":{"kind":"Name","value":"color"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"isRemote"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isAuditLogged"}},{"kind":"Field","name":{"kind":"Name","value":"isUIEditable"}},{"kind":"Field","name":{"kind":"Name","value":"isUICreatable"}},{"kind":"Field","name":{"kind":"Name","value":"writability"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"labelIdentifierFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"imageIdentifierFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"shortcut"}},{"kind":"Field","name":{"kind":"Name","value":"isLabelSyncedWithName"}},{"kind":"Field","name":{"kind":"Name","value":"isSearchable"}},{"kind":"Field","name":{"kind":"Name","value":"openRecordIn"}},{"kind":"Field","name":{"kind":"Name","value":"sharingReach"}},{"kind":"Field","name":{"kind":"Name","value":"readability"}},{"kind":"Field","name":{"kind":"Name","value":"duplicateCriteria"}},{"kind":"Field","name":{"kind":"Name","value":"searchFieldMetadataList"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"tsVectorFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}},{"kind":"Field","name":{"kind":"Name","value":"indexMetadataList"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"indexWhereClause"}},{"kind":"Field","name":{"kind":"Name","value":"indexType"}},{"kind":"Field","name":{"kind":"Name","value":"isUnique"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"isSystemSideEffect"}},{"kind":"Field","name":{"kind":"Name","value":"indexFieldMetadataList"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"subFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"order"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"fieldsList"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"universalIdentifier"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isUIEditable"}},{"kind":"Field","name":{"kind":"Name","value":"writability"}},{"kind":"Field","name":{"kind":"Name","value":"isNullable"}},{"kind":"Field","name":{"kind":"Name","value":"isUnique"}},{"kind":"Field","name":{"kind":"Name","value":"isSearchable"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"defaultValue"}},{"kind":"Field","name":{"kind":"Name","value":"options"}},{"kind":"Field","name":{"kind":"Name","value":"settings"}},{"kind":"Field","name":{"kind":"Name","value":"isLabelSyncedWithName"}},{"kind":"Field","name":{"kind":"Name","value":"morphId"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"relation"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"sourceObjectMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}}]}},{"kind":"Field","name":{"kind":"Name","value":"targetObjectMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}}]}},{"kind":"Field","name":{"kind":"Name","value":"sourceFieldMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"targetFieldMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"morphRelations"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"sourceObjectMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}}]}},{"kind":"Field","name":{"kind":"Name","value":"targetObjectMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"nameSingular"}},{"kind":"Field","name":{"kind":"Name","value":"namePlural"}}]}},{"kind":"Field","name":{"kind":"Name","value":"sourceFieldMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}},{"kind":"Field","name":{"kind":"Name","value":"targetFieldMetadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}}]}}]}}]}}]}}]} as unknown as DocumentNode<ObjectMetadataFieldsFragment, unknown>;
@@ -2931,7 +2931,7 @@ export const SendChatMessageDocument = {"kind":"Document","definitions":[{"kind"
export const SnoozeAgentChatThreadInChannelDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SnoozeAgentChatThreadInChannel"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"snoozedUntil"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"snoozeAgentChatThreadInChannel"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}},{"kind":"Argument","name":{"kind":"Name","value":"snoozedUntil"},"value":{"kind":"Variable","name":{"kind":"Name","value":"snoozedUntil"}}}]}]}}]} as unknown as DocumentNode<SnoozeAgentChatThreadInChannelMutation, SnoozeAgentChatThreadInChannelMutationVariables>;
export const StopAgentChatStreamDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"StopAgentChatStream"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"stopAgentChatStream"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}}]}]}}]} as unknown as DocumentNode<StopAgentChatStreamMutation, StopAgentChatStreamMutationVariables>;
export const UpdateAgentChatChannelDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateAgentChatChannel"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"channelId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateAgentChatChannelInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateAgentChatChannel"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"channelId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"channelId"}}},{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode<UpdateAgentChatChannelMutation, UpdateAgentChatChannelMutationVariables>;
-export const UpdateAgentChatThreadInboxStateDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateAgentChatThreadInboxState"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"threadIds"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"action"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AgentChatInboxAction"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"snoozedUntil"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateAgentChatThreadInboxState"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadIds"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadIds"}}},{"kind":"Argument","name":{"kind":"Name","value":"action"},"value":{"kind":"Variable","name":{"kind":"Name","value":"action"}}},{"kind":"Argument","name":{"kind":"Name","value":"snoozedUntil"},"value":{"kind":"Variable","name":{"kind":"Name","value":"snoozedUntil"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AgentChatThreadParticipantFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentChatThreadParticipantFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"AgentChatThreadParticipant"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"lastReadAt"}},{"kind":"Field","name":{"kind":"Name","value":"archivedAt"}},{"kind":"Field","name":{"kind":"Name","value":"snoozedUntil"}},{"kind":"Field","name":{"kind":"Name","value":"isSubscribed"}},{"kind":"Field","name":{"kind":"Name","value":"lastMentionedAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<UpdateAgentChatThreadInboxStateMutation, UpdateAgentChatThreadInboxStateMutationVariables>;
+export const UpdateAgentChatThreadInboxStateDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateAgentChatThreadInboxState"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"threadIds"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"action"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"AgentChatInboxAction"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"snoozedUntil"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"DateTime"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateAgentChatThreadInboxState"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadIds"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadIds"}}},{"kind":"Argument","name":{"kind":"Name","value":"action"},"value":{"kind":"Variable","name":{"kind":"Name","value":"action"}}},{"kind":"Argument","name":{"kind":"Name","value":"snoozedUntil"},"value":{"kind":"Variable","name":{"kind":"Name","value":"snoozedUntil"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AgentChatThreadParticipantFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentChatThreadParticipantFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"AgentChatThreadParticipant"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"lastReadAt"}},{"kind":"Field","name":{"kind":"Name","value":"archivedAt"}},{"kind":"Field","name":{"kind":"Name","value":"snoozedUntil"}},{"kind":"Field","name":{"kind":"Name","value":"isSubscribed"}},{"kind":"Field","name":{"kind":"Name","value":"lastMentionedAt"}},{"kind":"Field","name":{"kind":"Name","value":"mentionsResolvedAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<UpdateAgentChatThreadInboxStateMutation, UpdateAgentChatThreadInboxStateMutationVariables>;
export const UpdateOneAgentDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateOneAgent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateAgentInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateOneAgent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AgentFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Agent"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"responseFormat"}},{"kind":"Field","name":{"kind":"Name","value":"roleId"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"modelConfiguration"}},{"kind":"Field","name":{"kind":"Name","value":"triggers"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<UpdateOneAgentMutation, UpdateOneAgentMutationVariables>;
export const UpdateSkillDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateSkill"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateSkillInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateSkill"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"SkillFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SkillFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Skill"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"content"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<UpdateSkillMutation, UpdateSkillMutationVariables>;
export const FindManyAgentsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindManyAgents"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"findManyAgents"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AgentFields"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AgentFields"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Agent"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"responseFormat"}},{"kind":"Field","name":{"kind":"Name","value":"roleId"}},{"kind":"Field","name":{"kind":"Name","value":"isSystem"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"modelConfiguration"}},{"kind":"Field","name":{"kind":"Name","value":"triggers"}},{"kind":"Field","name":{"kind":"Name","value":"applicationId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<FindManyAgentsQuery, FindManyAgentsQueryVariables>;
diff --git a/packages/twenty-front/src/generated-metadata/schema.ts b/packages/twenty-front/src/generated-metadata/schema.ts
index d7fb37bbe46..f833e81dc5a 100644
--- a/packages/twenty-front/src/generated-metadata/schema.ts
+++ b/packages/twenty-front/src/generated-metadata/schema.ts
@@ -150,6 +150,7 @@ export type AgentChatThreadParticipant = {
isSubscribed: Scalars['Boolean']['output'];
lastMentionedAt?: Maybe<Scalars['DateTime']['output']>;
lastReadAt?: Maybe<Scalars['DateTime']['output']>;
+ mentionsResolvedAt?: Maybe<Scalars['DateTime']['output']>;
snoozedUntil?: Maybe<Scalars['DateTime']['output']>;
threadId: Scalars['UUID']['output'];
updatedAt: Scalars['DateTime']['output'];
diff --git a/packages/twenty-front/src/modules/ai/components/AgentChatThreadMarkAsReadEffect.tsx b/packages/twenty-front/src/modules/ai/components/AgentChatThreadMarkAsReadEffect.tsx
index 54e0acb4762..2634a9d8a2b 100644
--- a/packages/twenty-front/src/modules/ai/components/AgentChatThreadMarkAsReadEffect.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AgentChatThreadMarkAsReadEffect.tsx
@@ -6,7 +6,10 @@ import { useUpdateAgentChatThreadInboxState } from '@/ai/hooks/useUpdateAgentCha
import { agentChatDisplayedThreadState } from '@/ai/states/agentChatDisplayedThreadState';
import { agentChatThreadOpenViewCountState } from '@/ai/states/agentChatThreadOpenViewCountState';
import { agentChatThreadParticipantsState } from '@/ai/states/agentChatThreadParticipantsState';
-import { agentChatThreadVisitState } from '@/ai/states/agentChatThreadVisitState';
+import {
+ type AgentChatThreadVisit,
+ agentChatThreadVisitState,
+} from '@/ai/states/agentChatThreadVisitState';
import { agentChatThreadRecordFamilySelector } from '@/ai/states/selectors/agentChatThreadRecordFamilySelector';
import { getAgentChatThreadInboxStatus } from '@/ai/utils/getAgentChatThreadInboxStatus';
import { isAgentChatThreadSettledForMember } from '@/ai/utils/isAgentChatThreadSettledForMember';
@@ -106,29 +109,46 @@ export const AgentChatThreadMarkAsReadEffect = () => {
lastActivityAt,
participant,
});
- const visit = store.get(agentChatThreadVisitState.atom);
+ const storedVisit = store.get(agentChatThreadVisitState.atom);
// Taken once per visit, before the read mark, so it sees where the member
// left off
- if (visit?.threadId !== threadId) {
- store.set(agentChatThreadVisitState.atom, {
- threadId,
- isUnread,
- lastReadAt: participant?.lastReadAt ?? null,
- isKeptUnread: false,
- });
+ const newVisit: AgentChatThreadVisit = {
+ threadId,
+ isUnread,
+ lastReadAt: participant?.lastReadAt ?? null,
+ isKeptUnread: false,
+ };
+ const visit = storedVisit?.threadId === threadId ? storedVisit : newVisit;
+
+ if (visit !== storedVisit) {
+ store.set(agentChatThreadVisitState.atom, visit);
}
- const isKeptUnread = visit?.threadId === threadId && visit.isKeptUnread;
+ const isReadRequested =
+ visit.readRequestedForActivityAt === lastActivityAt &&
+ visit.readRequestedForParticipantUpdatedAt === participant?.updatedAt;
// Opening a chat the member does not participate in yet starts tracking
// it for them, so later activity in it reads as unread
- if ((isUnread || !isDefined(participant)) && !isKeptUnread) {
- void updateAgentChatThreadInboxState({
- threadIds: [threadId],
- action: AgentChatInboxAction.READ,
- });
+ if (
+ (!isUnread && isDefined(participant)) ||
+ visit.isKeptUnread ||
+ isReadRequested
+ ) {
+ return;
}
+
+ store.set(agentChatThreadVisitState.atom, {
+ ...visit,
+ readRequestedForActivityAt: lastActivityAt,
+ readRequestedForParticipantUpdatedAt: participant?.updatedAt,
+ });
+
+ void updateAgentChatThreadInboxState({
+ threadIds: [threadId],
+ action: AgentChatInboxAction.READ,
+ });
}, [
isVisible,
lastActivityAt,
diff --git a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadDetailsStatus.stories.tsx b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadDetailsStatus.stories.tsx
index 2fa97b29a4e..98afa0a4dcc 100644
--- a/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadDetailsStatus.stories.tsx
+++ b/packages/twenty-front/src/modules/ai/components/__stories__/AiChatThreadDetailsStatus.stories.tsx
@@ -67,6 +67,7 @@ const PARTICIPANT: AgentChatThreadParticipantFieldsFragment = {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: ACTIVITY_AT,
};
diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AgentChatThreadMarkAsReadEffect.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AgentChatThreadMarkAsReadEffect.test.tsx
index 8cbfb57dfda..431c6d64adc 100644
--- a/packages/twenty-front/src/modules/ai/components/__tests__/AgentChatThreadMarkAsReadEffect.test.tsx
+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AgentChatThreadMarkAsReadEffect.test.tsx
@@ -44,6 +44,7 @@ const PARTICIPANT: AgentChatThreadParticipantFieldsFragment = {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: LAST_ACTIVITY_AT,
__typename: 'AgentChatThreadParticipant',
};
@@ -63,13 +64,16 @@ describe('AgentChatThreadMarkAsReadEffect', () => {
{
__typename: 'AgentChatThread',
id: THREAD_ID,
+ title: null,
+ createdAt: LAST_ACTIVITY_AT,
+ updatedAt: LAST_ACTIVITY_AT,
deletedAt: null,
lastActivityAt: LAST_ACTIVITY_AT,
lastMessageSenderWorkspaceMemberId: null,
workspaceMemberId: WORKSPACE_MEMBER_ID,
assigneeId: null,
pendingQuestionMessageId: null,
- } as never,
+ },
]);
jotaiStore.set(currentWorkspaceMemberState.atom, CURRENT_WORKSPACE_MEMBER);
jotaiStore.set(agentChatThreadParticipantsState.atom, {
@@ -90,6 +94,8 @@ describe('AgentChatThreadMarkAsReadEffect', () => {
isUnread: true,
lastReadAt: '2026-10-01T09:00:00.000Z',
isKeptUnread: false,
+ readRequestedForActivityAt: LAST_ACTIVITY_AT,
+ readRequestedForParticipantUpdatedAt: PARTICIPANT.updatedAt,
});
});
@@ -108,6 +114,7 @@ describe('AgentChatThreadMarkAsReadEffect', () => {
isUnread: false,
lastReadAt: null,
isKeptUnread: false,
+ readRequestedForActivityAt: LAST_ACTIVITY_AT,
});
});
diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AgentChatThreadParticipantOperationsEffect.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AgentChatThreadParticipantOperationsEffect.test.tsx
index 9568d08d58d..785e387fd98 100644
--- a/packages/twenty-front/src/modules/ai/components/__tests__/AgentChatThreadParticipantOperationsEffect.test.tsx
+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AgentChatThreadParticipantOperationsEffect.test.tsx
@@ -42,6 +42,7 @@ const READ_PARTICIPANT: AgentChatThreadParticipantFieldsFragment = {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: '2026-10-01T10:00:00.000Z',
__typename: 'AgentChatThreadParticipant',
};
diff --git a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadListItemActions.test.tsx b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadListItemActions.test.tsx
index a3043a42d63..c24f6f8d78a 100644
--- a/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadListItemActions.test.tsx
+++ b/packages/twenty-front/src/modules/ai/components/__tests__/AiChatThreadListItemActions.test.tsx
@@ -169,6 +169,7 @@ const renderThread = async ({
snoozedUntil: scope === 'SNOOZED' ? SNOOZED_UNTIL : null,
lastReadAt: THREAD_ACTIVITY_AT,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: INBOX_EVENT_AT,
},
});
diff --git a/packages/twenty-front/src/modules/ai/constants/AgentChatThreadListRecordGqlFields.ts b/packages/twenty-front/src/modules/ai/constants/AgentChatThreadListRecordGqlFields.ts
index 474f903312c..17898b2946b 100644
--- a/packages/twenty-front/src/modules/ai/constants/AgentChatThreadListRecordGqlFields.ts
+++ b/packages/twenty-front/src/modules/ai/constants/AgentChatThreadListRecordGqlFields.ts
@@ -32,6 +32,7 @@ export const AGENT_CHAT_THREAD_LIST_RECORD_GQL_FIELDS = {
snoozedUntil: true,
isSubscribed: true,
lastMentionedAt: true,
+ mentionsResolvedAt: true,
updatedAt: true,
},
} satisfies RecordGqlFields;
diff --git a/packages/twenty-front/src/modules/ai/graphql/fragments/agentChatThreadParticipantFragment.ts b/packages/twenty-front/src/modules/ai/graphql/fragments/agentChatThreadParticipantFragment.ts
index c08f68e54c7..38e95dc4804 100644
--- a/packages/twenty-front/src/modules/ai/graphql/fragments/agentChatThreadParticipantFragment.ts
+++ b/packages/twenty-front/src/modules/ai/graphql/fragments/agentChatThreadParticipantFragment.ts
@@ -9,6 +9,7 @@ export const AGENT_CHAT_THREAD_PARTICIPANT_FRAGMENT = gql`
snoozedUntil
isSubscribed
lastMentionedAt
+ mentionsResolvedAt
updatedAt
}
`;
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useLeaveRemovedAiChatThread.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useLeaveRemovedAiChatThread.test.tsx
index a7a36a7009f..9ad41bf0693 100644
--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useLeaveRemovedAiChatThread.test.tsx
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useLeaveRemovedAiChatThread.test.tsx
@@ -49,6 +49,7 @@ const buildFollowedParticipant = (threadId: string) => ({
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: '2026-09-20T00:00:00.000Z',
});
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useOptimisticallyRestoreOnSend.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useOptimisticallyRestoreOnSend.test.tsx
index fbdf8b544ce..bb81e3b05a0 100644
--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useOptimisticallyRestoreOnSend.test.tsx
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useOptimisticallyRestoreOnSend.test.tsx
@@ -16,6 +16,7 @@ const ARCHIVED_PARTICIPANT = {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
id: 'participant-id',
updatedAt: '2026-10-01T11:00:00.000Z',
};
@@ -61,6 +62,7 @@ describe('useOptimisticallyRestoreOnSend', () => {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
id: 'participant-id',
updatedAt: ARCHIVED_PARTICIPANT.updatedAt,
});
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useRefreshAgentChatThreads.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useRefreshAgentChatThreads.test.tsx
index 8d912bd0bab..6e23f5c492a 100644
--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useRefreshAgentChatThreads.test.tsx
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useRefreshAgentChatThreads.test.tsx
@@ -149,6 +149,7 @@ describe('useRefreshAgentChatThreads', () => {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt,
});
const streamedParticipant = {
@@ -160,6 +161,7 @@ describe('useRefreshAgentChatThreads', () => {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: '2026-10-01T10:05:00.000Z',
};
store.set(agentChatThreadStreamedParticipantsState.atom, {
@@ -220,6 +222,7 @@ describe('useRefreshAgentChatThreads', () => {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: '2026-10-01T10:00:00.000Z',
},
'thread-2': streamedParticipant,
diff --git a/packages/twenty-front/src/modules/ai/hooks/__tests__/useUpdateAgentChatThreadInboxState.test.tsx b/packages/twenty-front/src/modules/ai/hooks/__tests__/useUpdateAgentChatThreadInboxState.test.tsx
index 3985842cd77..9894befca5c 100644
--- a/packages/twenty-front/src/modules/ai/hooks/__tests__/useUpdateAgentChatThreadInboxState.test.tsx
+++ b/packages/twenty-front/src/modules/ai/hooks/__tests__/useUpdateAgentChatThreadInboxState.test.tsx
@@ -19,6 +19,7 @@ const READ_PARTICIPANT = {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
id: 'participant-id',
updatedAt: '2026-10-01T10:00:00.000Z',
};
@@ -79,6 +80,8 @@ describe('useUpdateAgentChatThreadInboxState', () => {
archivedAt: null,
snoozedUntil: null,
isSubscribed: false,
+ lastMentionedAt: null,
+ mentionsResolvedAt: null,
});
});
diff --git a/packages/twenty-front/src/modules/ai/states/agentChatThreadVisitState.ts b/packages/twenty-front/src/modules/ai/states/agentChatThreadVisitState.ts
index 3c71ac835cb..9b871959512 100644
--- a/packages/twenty-front/src/modules/ai/states/agentChatThreadVisitState.ts
+++ b/packages/twenty-front/src/modules/ai/states/agentChatThreadVisitState.ts
@@ -8,6 +8,9 @@ export type AgentChatThreadVisit = {
lastReadAt: string | null;
// Marked unread while on screen, so the open view does not read it again
isKeptUnread: boolean;
+ // So a failed read is not sent again until the chat or the member's row changes
+ readRequestedForActivityAt?: string;
+ readRequestedForParticipantUpdatedAt?: string;
};
// The thread on screen in a visible tab
diff --git a/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatRecentThreadsSelector.test.ts b/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatRecentThreadsSelector.test.ts
index a8f955a4bd5..d60ed3bb4c0 100644
--- a/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatRecentThreadsSelector.test.ts
+++ b/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatRecentThreadsSelector.test.ts
@@ -43,6 +43,7 @@ describe('agentChatRecentThreadsSelector', () => {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: LAST_ACTIVITY_AT,
},
});
diff --git a/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatThreadInboxStatusFamilySelector.test.ts b/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatThreadInboxStatusFamilySelector.test.ts
index a88130dc70e..eeebe0ce348 100644
--- a/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatThreadInboxStatusFamilySelector.test.ts
+++ b/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatThreadInboxStatusFamilySelector.test.ts
@@ -36,6 +36,7 @@ const UNREAD_PARTICIPANT = {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: LAST_ACTIVITY_AT,
},
};
diff --git a/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatVisibleThreadsSelector.test.ts b/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatVisibleThreadsSelector.test.ts
index 114ded3d660..bb6b8ae58ca 100644
--- a/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatVisibleThreadsSelector.test.ts
+++ b/packages/twenty-front/src/modules/ai/states/selectors/__tests__/agentChatVisibleThreadsSelector.test.ts
@@ -14,6 +14,7 @@ const READ = {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: LAST_ACTIVITY_AT,
};
@@ -144,6 +145,7 @@ const THREADS: {
...READ,
archivedAt: null,
lastMentionedAt: '2026-10-01T09:00:00.000Z',
+ mentionsResolvedAt: null,
__typename: 'AgentChatThreadParticipant',
},
},
diff --git a/packages/twenty-front/src/modules/ai/utils/__tests__/getAgentChatThreadInboxStatus.test.ts b/packages/twenty-front/src/modules/ai/utils/__tests__/getAgentChatThreadInboxStatus.test.ts
index 19604761931..f630f930cea 100644
--- a/packages/twenty-front/src/modules/ai/utils/__tests__/getAgentChatThreadInboxStatus.test.ts
+++ b/packages/twenty-front/src/modules/ai/utils/__tests__/getAgentChatThreadInboxStatus.test.ts
@@ -10,6 +10,7 @@ const getStatus = ({
snoozedUntil = null,
isSubscribed = true,
lastMentionedAt = null,
+ mentionsResolvedAt = null,
}: {
lastActivityAt?: string | null;
lastReadAt?: string | null;
@@ -17,6 +18,7 @@ const getStatus = ({
snoozedUntil?: string | null;
isSubscribed?: boolean;
lastMentionedAt?: string | null;
+ mentionsResolvedAt?: string | null;
} = {}) =>
getAgentChatThreadInboxStatus({
lastActivityAt,
@@ -28,6 +30,7 @@ const getStatus = ({
snoozedUntil,
isSubscribed,
lastMentionedAt,
+ mentionsResolvedAt,
updatedAt: ARCHIVED_AT,
__typename: 'AgentChatThreadParticipant',
},
@@ -165,4 +168,35 @@ describe('getAgentChatThreadInboxStatus', () => {
getStatus({ lastMentionedAt: '2026-10-01T09:00:00.000Z' }).isMentioned,
).toBe(true);
});
+
+ it('keeps a mention unresolved after reading and snoozing', () => {
+ expect(
+ getStatus({
+ lastMentionedAt: '2026-10-01T09:00:00.000Z',
+ lastReadAt: ARCHIVED_AT,
+ archivedAt: ARCHIVED_AT,
+ snoozedUntil: '2026-10-02T09:00:00.000Z',
+ }).isMentioned,
+ ).toBe(true);
+ });
+
+ it('does not revive a resolved mention when later activity reopens the chat', () => {
+ expect(
+ getStatus({
+ lastMentionedAt: '2026-10-01T09:00:00.000Z',
+ mentionsResolvedAt: '2026-10-01T09:00:00.000Z',
+ archivedAt: ARCHIVED_AT,
+ lastActivityAt: '2026-10-01T11:00:00.000Z',
+ }),
+ ).toMatchObject({ scope: 'INBOX', isMentioned: false });
+ });
+
+ it('requires attention again when a new mention follows the resolution', () => {
+ expect(
+ getStatus({
+ lastMentionedAt: '2026-10-01T11:00:00.000Z',
+ mentionsResolvedAt: '2026-10-01T09:00:00.000Z',
+ }).isMentioned,
+ ).toBe(true);
+ });
});
diff --git a/packages/twenty-front/src/modules/ai/utils/__tests__/getAgentChatThreadParticipantFromRecord.test.ts b/packages/twenty-front/src/modules/ai/utils/__tests__/getAgentChatThreadParticipantFromRecord.test.ts
new file mode 100644
index 00000000000..bc44f34c625
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/utils/__tests__/getAgentChatThreadParticipantFromRecord.test.ts
@@ -0,0 +1,39 @@
+import { getAgentChatThreadParticipantFromRecord } from '@/ai/utils/getAgentChatThreadParticipantFromRecord';
+
+const RESOLVED_PARTICIPANT = {
+ __typename: 'AgentChatThreadParticipant',
+ id: 'participant',
+ threadId: 'thread',
+ lastReadAt: '2026-10-01T10:00:00.000Z',
+ archivedAt: null,
+ snoozedUntil: null,
+ isSubscribed: true,
+ lastMentionedAt: '2026-10-01T10:00:00.000Z',
+ mentionsResolvedAt: '2026-10-01T10:00:00.000Z',
+ updatedAt: '2026-10-01T10:01:00.000Z',
+};
+
+describe('getAgentChatThreadParticipantFromRecord', () => {
+ it('keeps the inbox fields of a record event, with its resolved mention', () => {
+ expect(
+ getAgentChatThreadParticipantFromRecord({
+ ...RESOLVED_PARTICIPANT,
+ workspaceMemberId: 'workspace-member',
+ }),
+ ).toEqual(RESOLVED_PARTICIPANT);
+ });
+
+ it('reads a record without a resolved mention as unresolved', () => {
+ expect(
+ getAgentChatThreadParticipantFromRecord({
+ id: 'participant',
+ threadId: 'thread',
+ lastMentionedAt: '2026-10-01T10:00:00.000Z',
+ updatedAt: '2026-10-01T10:01:00.000Z',
+ }),
+ ).toMatchObject({
+ lastMentionedAt: '2026-10-01T10:00:00.000Z',
+ mentionsResolvedAt: null,
+ });
+ });
+});
diff --git a/packages/twenty-front/src/modules/ai/utils/__tests__/isAgentChatThreadSettledForMember.test.ts b/packages/twenty-front/src/modules/ai/utils/__tests__/isAgentChatThreadSettledForMember.test.ts
index a92a29ca1da..0c7e0ef5c48 100644
--- a/packages/twenty-front/src/modules/ai/utils/__tests__/isAgentChatThreadSettledForMember.test.ts
+++ b/packages/twenty-front/src/modules/ai/utils/__tests__/isAgentChatThreadSettledForMember.test.ts
@@ -24,6 +24,7 @@ const READ_PARTICIPANT: AgentChatThreadParticipantFieldsFragment = {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: LAST_ACTIVITY_AT,
__typename: 'AgentChatThreadParticipant',
};
diff --git a/packages/twenty-front/src/modules/ai/utils/__tests__/mergeAgentChatThreadParticipants.test.ts b/packages/twenty-front/src/modules/ai/utils/__tests__/mergeAgentChatThreadParticipants.test.ts
index a004168b76c..52bd3798deb 100644
--- a/packages/twenty-front/src/modules/ai/utils/__tests__/mergeAgentChatThreadParticipants.test.ts
+++ b/packages/twenty-front/src/modules/ai/utils/__tests__/mergeAgentChatThreadParticipants.test.ts
@@ -9,6 +9,7 @@ const READ_PARTICIPANT = {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: '2026-10-01T10:00:00.000Z',
};
diff --git a/packages/twenty-front/src/modules/ai/utils/getAgentChatThreadInboxStatus.ts b/packages/twenty-front/src/modules/ai/utils/getAgentChatThreadInboxStatus.ts
index f53d390a0ca..159d8e8c8f9 100644
--- a/packages/twenty-front/src/modules/ai/utils/getAgentChatThreadInboxStatus.ts
+++ b/packages/twenty-front/src/modules/ai/utils/getAgentChatThreadInboxStatus.ts
@@ -1,4 +1,5 @@
import { isAfter } from 'date-fns';
+import { isAgentChatMentionUnresolved } from 'twenty-shared/ai';
import { isDefined } from 'twenty-shared/utils';
import { type AgentChatThreadInboxStatus } from '@/ai/types/AgentChatThreadInboxStatus';
@@ -25,7 +26,10 @@ export const getAgentChatThreadInboxStatus = ({
(!isDefined(participant.lastReadAt) ||
isAfter(lastActivityAt, participant.lastReadAt));
const isSubscribed = participant?.isSubscribed ?? false;
- const isMentioned = isDefined(participant?.lastMentionedAt);
+ const isMentioned = isAgentChatMentionUnresolved({
+ lastMentionedAt: participant?.lastMentionedAt,
+ mentionsResolvedAt: participant?.mentionsResolvedAt,
+ });
const archivedAt = participant?.archivedAt;
const snoozedUntil = participant?.snoozedUntil;
diff --git a/packages/twenty-front/src/modules/ai/utils/getAgentChatThreadParticipantFromRecord.ts b/packages/twenty-front/src/modules/ai/utils/getAgentChatThreadParticipantFromRecord.ts
index 58d2a0cdf14..ec577098251 100644
--- a/packages/twenty-front/src/modules/ai/utils/getAgentChatThreadParticipantFromRecord.ts
+++ b/packages/twenty-front/src/modules/ai/utils/getAgentChatThreadParticipantFromRecord.ts
@@ -13,5 +13,6 @@ export const getAgentChatThreadParticipantFromRecord = (
snoozedUntil: record.snoozedUntil ?? null,
isSubscribed: record.isSubscribed ?? true,
lastMentionedAt: record.lastMentionedAt ?? null,
+ mentionsResolvedAt: record.mentionsResolvedAt ?? null,
updatedAt: record.updatedAt,
});
diff --git a/packages/twenty-front/src/pages/ai-chat/__stories__/AiChatInboxPage.stories.tsx b/packages/twenty-front/src/pages/ai-chat/__stories__/AiChatInboxPage.stories.tsx
index 149557c4927..ff5df521502 100644
--- a/packages/twenty-front/src/pages/ai-chat/__stories__/AiChatInboxPage.stories.tsx
+++ b/packages/twenty-front/src/pages/ai-chat/__stories__/AiChatInboxPage.stories.tsx
@@ -301,6 +301,7 @@ const meta = {
archivedAt: null,
snoozedUntil: null,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: THREAD_ACTIVITY_AT,
},
]),
diff --git a/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx b/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx
index 9898bd0a487..5b736a0ed2a 100644
--- a/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx
+++ b/packages/twenty-front/src/pages/ai-chat/__tests__/AiChatInboxPage.test.tsx
@@ -286,6 +286,7 @@ describe('AiChatInboxPage', () => {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt,
},
]),
@@ -355,6 +356,7 @@ describe('AiChatInboxPage', () => {
snoozedUntil: null,
isSubscribed: true,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
updatedAt: '2026-09-08T00:00:00.000Z',
},
]),
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-54/2-54-upgrade-version-command.module.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-54/2-54-upgrade-version-command.module.ts
index 3f048222814..e7991209786 100644
--- a/packages/twenty-server/src/database/commands/upgrade-version-command/2-54/2-54-upgrade-version-command.module.ts
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-54/2-54-upgrade-version-command.module.ts
@@ -6,6 +6,7 @@ import { AddMergeWithRecordCommandMenuItemCommand } from 'src/database/commands/
import { UpdateCrmHygieneSkillMergeGuidanceCommand } from 'src/database/commands/upgrade-version-command/2-54/2-54-workspace-command-1793206127866-update-crm-hygiene-skill-merge-guidance.command';
import { RemoveMessageCampaignFlagCommand } from 'src/database/commands/upgrade-version-command/2-54/2-54-workspace-command-1793266150123-remove-message-campaign-flag.command';
import { AddCampaignsNavigationFolderCommand } from 'src/database/commands/upgrade-version-command/2-54/2-54-workspace-command-1793266210456-add-campaigns-navigation-folder.command';
+import { AddChatMentionResolutionCommand } from 'src/database/commands/upgrade-version-command/2-54/2-54-workspace-command-1793350721809-add-chat-mention-resolution.command';
import { ApplicationModule } from 'src/engine/core-modules/application/application.module';
import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache.module';
import { WorkspaceMigrationModule } from 'src/engine/workspace-manager/workspace-migration/workspace-migration.module';
@@ -23,6 +24,7 @@ import { WorkspaceMigrationModule } from 'src/engine/workspace-manager/workspace
UpdateCrmHygieneSkillMergeGuidanceCommand,
RemoveMessageCampaignFlagCommand,
AddCampaignsNavigationFolderCommand,
+ AddChatMentionResolutionCommand,
],
})
export class V2_54_UpgradeVersionCommandModule {}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-54/2-54-workspace-command-1793350721809-add-chat-mention-resolution.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-54/2-54-workspace-command-1793350721809-add-chat-mention-resolution.command.ts
new file mode 100644
index 00000000000..097aa81da6d
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-54/2-54-workspace-command-1793350721809-add-chat-mention-resolution.command.ts
@@ -0,0 +1,153 @@
+import { Command } from 'nest-commander';
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { STANDARD_OBJECTS } from 'twenty-shared/metadata';
+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';
+
+import { ProvisionedWorkspaceCommandRunner } from 'src/database/commands/command-runners/provisioned-workspace.command-runner';
+import { WorkspaceIteratorService } from 'src/database/commands/command-runners/workspace-iterator.service';
+import { type RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspace.command-runner';
+import { getStandardFlatEntitiesToCreateOrThrow } from 'src/database/commands/upgrade-version-command/2-10/utils/get-standard-flat-entities-to-create-or-throw.util';
+import { ApplicationService } from 'src/engine/core-modules/application/application.service';
+import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';
+import { findFlatEntityByUniversalIdentifier } from 'src/engine/metadata-modules/flat-entity/utils/find-flat-entity-by-universal-identifier.util';
+import { type FlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata.type';
+import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
+import { computeTwentyStandardApplicationAllFlatEntityMaps } from 'src/engine/workspace-manager/twenty-standard-application/utils/twenty-standard-application-all-flat-entity-maps.constant';
+import { WorkspaceMigrationBuilderException } from 'src/engine/workspace-manager/workspace-migration/exceptions/workspace-migration-builder-exception';
+import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';
+
+const MENTIONS_RESOLVED_AT_FIELD_UNIVERSAL_IDENTIFIER =
+ STANDARD_OBJECTS.agentChatThreadParticipant.fields.mentionsResolvedAt
+ .universalIdentifier;
+
+@RegisteredWorkspaceCommand('2.54.0', 1793350721809)
+@Command({
+ name: 'upgrade:2-54:add-chat-mention-resolution',
+ description: 'Track resolved chat mentions',
+})
+export class AddChatMentionResolutionCommand extends ProvisionedWorkspaceCommandRunner {
+ constructor(
+ protected readonly workspaceIteratorService: WorkspaceIteratorService,
+ private readonly applicationService: ApplicationService,
+ private readonly workspaceCacheService: WorkspaceCacheService,
+ private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,
+ ) {
+ super(workspaceIteratorService);
+ }
+
+ override async runOnWorkspace(args: RunOnWorkspaceArgs): Promise<void> {
+ await this.up(args);
+ }
+
+ async up({
+ workspaceId,
+ options,
+ }: Pick<RunOnWorkspaceArgs, 'workspaceId' | 'options'>): Promise<void> {
+ const { flatObjectMetadataMaps, flatFieldMetadataMaps } =
+ await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'flatObjectMetadataMaps',
+ 'flatFieldMetadataMaps',
+ ]);
+
+ if (
+ !isDefined(
+ flatObjectMetadataMaps.byUniversalIdentifier[
+ STANDARD_OBJECTS.agentChatThreadParticipant.universalIdentifier
+ ],
+ )
+ ) {
+ return;
+ }
+
+ if (options.dryRun) {
+ this.logger.log(
+ `[DRY RUN] Workspace ${workspaceId}: add mention resolution`,
+ );
+
+ return;
+ }
+
+ const { twentyStandardFlatApplication } =
+ await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(
+ { workspaceId },
+ );
+ const fieldsToCreate =
+ getStandardFlatEntitiesToCreateOrThrow<FlatFieldMetadata>({
+ standardFlatEntityMaps:
+ computeTwentyStandardApplicationAllFlatEntityMaps({
+ now: new Date().toISOString(),
+ workspaceId,
+ twentyStandardApplicationId: twentyStandardFlatApplication.id,
+ }).allFlatEntityMaps.flatFieldMetadataMaps,
+ existingFlatEntityMaps: flatFieldMetadataMaps,
+ universalIdentifiers: [MENTIONS_RESOLVED_AT_FIELD_UNIVERSAL_IDENTIFIER],
+ });
+
+ if (isNonEmptyArray(fieldsToCreate)) {
+ await this.migrateFieldsOrThrow({
+ workspaceId,
+ fieldsToCreate,
+ fieldsToDelete: [],
+ });
+ }
+ }
+
+ async down({
+ workspaceId,
+ options,
+ }: Pick<RunOnWorkspaceArgs, 'workspaceId' | 'options'>): Promise<void> {
+ const { flatFieldMetadataMaps } =
+ await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'flatFieldMetadataMaps',
+ ]);
+ const field = findFlatEntityByUniversalIdentifier<FlatFieldMetadata>({
+ flatEntityMaps: flatFieldMetadataMaps,
+ universalIdentifier: MENTIONS_RESOLVED_AT_FIELD_UNIVERSAL_IDENTIFIER,
+ });
+
+ if (!isDefined(field) || options.dryRun) {
+ return;
+ }
+
+ await this.migrateFieldsOrThrow({
+ workspaceId,
+ fieldsToCreate: [],
+ fieldsToDelete: [field],
+ });
+ }
+
+ private async migrateFieldsOrThrow({
+ workspaceId,
+ fieldsToCreate,
+ fieldsToDelete,
+ }: {
+ workspaceId: string;
+ fieldsToCreate: FlatFieldMetadata[];
+ fieldsToDelete: FlatFieldMetadata[];
+ }): Promise<void> {
+ const result =
+ await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(
+ {
+ shouldDeferActions: false,
+ workspaceId,
+ isSystemBuild: true,
+ applicationUniversalIdentifier:
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
+ allFlatEntityOperationByMetadataName: {
+ fieldMetadata: {
+ flatEntityToCreate: fieldsToCreate,
+ flatEntityToDelete: fieldsToDelete,
+ flatEntityToUpdate: [],
+ },
+ },
+ },
+ );
+
+ if (result.status === 'fail') {
+ throw new WorkspaceMigrationBuilderException(
+ result,
+ `Failed to migrate chat mention resolution for workspace ${workspaceId}`,
+ );
+ }
+ }
+}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/agent-chat-thread-participant.dto.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/agent-chat-thread-participant.dto.ts
index b9ba719703d..9d6a303391f 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/agent-chat-thread-participant.dto.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/agent-chat-thread-participant.dto.ts
@@ -25,6 +25,9 @@ export class AgentChatThreadParticipantDTO {
@Field(() => Date, { nullable: true })
lastMentionedAt: Date | null;
+ @Field(() => Date, { nullable: true })
+ mentionsResolvedAt: Date | null;
+
// Orders the copies a member's apps receive, so an older one never wins
@Field(() => Date)
updatedAt: Date;
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-sharing.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-sharing.service.ts
index 0df4f234fed..f5e5eae1f75 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-sharing.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-sharing.service.ts
@@ -1,3 +1,4 @@
+import { STANDARD_OBJECTS } from 'twenty-shared/metadata';
import { AgentChatChannelGrantService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat-channel-grant.service';
import { AuthException } from 'src/engine/core-modules/auth/auth.exception';
import { randomUUID } from 'node:crypto';
@@ -95,7 +96,31 @@ export class AgentChatSharingService {
return hasAgentChatThreadChannelField({ flatFieldMetadataMaps });
}
+ // TODO(@bosiraphael): remove once 2.54 leaves the cross-upgrade window
+ async assertHasMentionResolutionOrThrow(workspaceId: string): Promise<void> {
+ const { flatFieldMetadataMaps } =
+ await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'flatFieldMetadataMaps',
+ ]);
+
+ if (
+ !isDefined(
+ flatFieldMetadataMaps.byUniversalIdentifier[
+ STANDARD_OBJECTS.agentChatThreadParticipant.fields.mentionsResolvedAt
+ .universalIdentifier
+ ],
+ )
+ ) {
+ throw new AiException(
+ 'Chats are not available until this workspace finishes upgrading',
+ AiExceptionCode.CHAT_UPGRADE_IN_PROGRESS,
+ );
+ }
+ }
+
async getParticipantObjectMetadataId(workspaceId: string): Promise<string> {
+ await this.assertHasMentionResolutionOrThrow(workspaceId);
+
const { flatObjectMetadataMaps } =
await this.workspaceCacheService.getOrRecompute(workspaceId, [
'flatObjectMetadataMaps',
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-streaming.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-streaming.service.ts
index 5a7fdafeb35..8ad389e6a57 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-streaming.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-streaming.service.ts
@@ -39,6 +39,7 @@ import { AgentChatService } from 'src/engine/metadata-modules/ai/ai-chat/service
import { AgentChatThreadService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread.service';
import { AgentConversationReaderService } from 'src/engine/metadata-modules/ai/ai-history/services/agent-conversation-reader.service';
import { AgentChatThreadLifecycleService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread-lifecycle.service';
+import { AgentChatSharingService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat-sharing.service';
import { AiChatFileAttachment } from 'src/engine/metadata-modules/ai/ai-chat/types/ai-chat-file-attachment.type';
import { formatErrorWithCause } from 'src/engine/metadata-modules/ai/ai-chat/utils/format-error-with-cause.util';
import { mapErrorToStreamError } from 'src/engine/metadata-modules/ai/ai-history/utils/map-error-to-stream-error.util';
@@ -88,6 +89,7 @@ export class AgentChatStreamingService {
private readonly turnRecorderService: AgentTurnRecorderService,
private readonly agentRunSuspensionService: AgentRunSuspensionService,
private readonly threadLifecycleService: AgentChatThreadLifecycleService,
+ private readonly sharingService: AgentChatSharingService,
) {}
// a message sent while a reply or a run streams in the conversation waits in its queue
@@ -111,6 +113,8 @@ export class AgentChatStreamingService {
const threadId = thread.id;
const workspaceId = workspace.id;
+ await this.sharingService.assertHasMentionResolutionOrThrow(workspaceId);
+
const [conversationWait, hasQueuedBacklog] = await Promise.all([
this.agentRunSuspensionService.findConversationWait({
workspaceId,
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread-participant.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread-participant.service.ts
index 58eb847d129..7d5d084b7b5 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread-participant.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread-participant.service.ts
@@ -45,10 +45,14 @@ type BuildParticipantWriteQuery = (tables: {
const NEXT_PARTICIPANT_UPDATED_AT = `GREATEST(clock_timestamp(), participant."updatedAt" + interval '1 millisecond')`;
-// A snooze whose end is already due, which its queued end may have checked
-// before this write, is saved as ended. Filing a thread, done or snoozed,
-// follows it, so new activity or the snooze's end brings it back
-const buildArchiveQuery: BuildParticipantWriteQuery = ({ participantTable }) =>
+const ALL_MENTIONS_RESOLVED_AT = `GREATEST(participant."mentionsResolvedAt", participant."lastMentionedAt")`;
+
+const HAS_UNRESOLVED_MENTION = `(participant."lastMentionedAt" IS NOT NULL AND (participant."mentionsResolvedAt" IS NULL OR participant."lastMentionedAt" > participant."mentionsResolvedAt"))`;
+
+const IS_IN_INBOX = `(participant."isSubscribed" AND (participant."archivedAt" IS NULL OR thread."lastActivityAt" > participant."archivedAt"))`;
+
+// Saved as ended when already due, since its queued end may have run before this write
+const buildSnoozeQuery: BuildParticipantWriteQuery = ({ participantTable }) =>
`INSERT INTO ${participantTable} AS participant ("threadId", "workspaceMemberId", "archivedAt", "snoozedUntil", "isSubscribed")
VALUES ($1, $2, CASE WHEN $3::timestamptz <= clock_timestamp() THEN NULL ELSE clock_timestamp() END, $3, true)
ON CONFLICT ("threadId", "workspaceMemberId") DO UPDATE SET
@@ -58,9 +62,7 @@ const buildArchiveQuery: BuildParticipantWriteQuery = ({ participantTable }) =>
"updatedAt" = ${NEXT_PARTICIPANT_UPDATED_AT}
RETURNING *`;
-// The member's change for each action, written by the database so its
-// timestamps order against thread activity; applyAgentChatInboxAction makes
-// the same change for the copy apps show before the server answers
+// Mirrored by applyAgentChatInboxAction for the optimistic copy
const INBOX_ACTION_QUERIES: Record<
AgentChatInboxAction,
BuildParticipantWriteQuery
@@ -72,6 +74,7 @@ const INBOX_ACTION_QUERIES: Record<
SELECT thread.id, $2, thread."lastActivityAt", false FROM ${threadTable} thread WHERE thread.id = $1
ON CONFLICT ("threadId", "workspaceMemberId") DO UPDATE SET
"lastReadAt" = GREATEST(participant."lastReadAt", EXCLUDED."lastReadAt"),
+ "mentionsResolvedAt" = ${ALL_MENTIONS_RESOLVED_AT},
"updatedAt" = ${NEXT_PARTICIPANT_UPDATED_AT}
RETURNING *`,
[AgentChatInboxAction.UNREAD]: ({ participantTable }) =>
@@ -81,8 +84,17 @@ const INBOX_ACTION_QUERIES: Record<
"lastReadAt" = NULL,
"updatedAt" = ${NEXT_PARTICIPANT_UPDATED_AT}
RETURNING *`,
- [AgentChatInboxAction.ARCHIVE]: buildArchiveQuery,
- [AgentChatInboxAction.SNOOZE]: buildArchiveQuery,
+ [AgentChatInboxAction.ARCHIVE]: ({ participantTable }) =>
+ `INSERT INTO ${participantTable} AS participant ("threadId", "workspaceMemberId", "archivedAt", "isSubscribed")
+ VALUES ($1, $2, clock_timestamp(), true)
+ ON CONFLICT ("threadId", "workspaceMemberId") DO UPDATE SET
+ "archivedAt" = EXCLUDED."archivedAt",
+ "snoozedUntil" = NULL,
+ "isSubscribed" = true,
+ "mentionsResolvedAt" = ${ALL_MENTIONS_RESOLVED_AT},
+ "updatedAt" = ${NEXT_PARTICIPANT_UPDATED_AT}
+ RETURNING *`,
+ [AgentChatInboxAction.SNOOZE]: buildSnoozeQuery,
[AgentChatInboxAction.MOVE_TO_INBOX]: ({ participantTable }) =>
`INSERT INTO ${participantTable} AS participant ("threadId", "workspaceMemberId")
VALUES ($1, $2)
@@ -108,6 +120,7 @@ const INBOX_ACTION_QUERIES: Record<
"isSubscribed" = false,
"archivedAt" = EXCLUDED."archivedAt",
"snoozedUntil" = NULL,
+ "mentionsResolvedAt" = ${ALL_MENTIONS_RESOLVED_AT},
"updatedAt" = ${NEXT_PARTICIPANT_UPDATED_AT}
RETURNING *`,
};
@@ -121,7 +134,7 @@ const EMPTY_OPEN_THREADS_SUMMARY: AgentChatOpenThreadsSummaryDTO = {
hasUnreadAssignedThread: false,
};
-const PARTICIPANT_COLUMNS = `id, "workspaceMemberId", "threadId", "lastReadAt", "archivedAt", "snoozedUntil", "isSubscribed", "lastMentionedAt", "updatedAt"`;
+const PARTICIPANT_COLUMNS = `id, "workspaceMemberId", "threadId", "lastReadAt", "archivedAt", "snoozedUntil", "isSubscribed", "lastMentionedAt", "mentionsResolvedAt", "updatedAt"`;
// Timestamps compared against thread.lastActivityAt are stamped by Postgres
// (clock_timestamp), so ordering follows the database rather than app servers.
@@ -200,7 +213,7 @@ export class AgentChatThreadParticipantService {
return this.write(
{ ...memberArgs, threadIds: uniqueThreadIds, isEveryRowRequired: true },
INBOX_ACTION_QUERIES[action],
- action === AgentChatInboxAction.ARCHIVE || isSnooze ? [snoozeEnd] : [],
+ isSnooze ? [snoozeEnd] : [],
action === AgentChatInboxAction.UNSUBSCRIBE
? assertIsNotAssignee
: writeThread,
@@ -224,7 +237,11 @@ export class AgentChatThreadParticipantService {
"archivedAt" = NULL,
"snoozedUntil" = NULL,
"isSubscribed" = true,
- "lastMentionedAt" = EXCLUDED."lastMentionedAt",
+ "lastMentionedAt" = GREATEST(
+ EXCLUDED."lastMentionedAt",
+ participant."lastMentionedAt" + interval '1 millisecond',
+ participant."mentionsResolvedAt" + interval '1 millisecond'
+ ),
"updatedAt" = ${NEXT_PARTICIPANT_UPDATED_AT}
RETURNING *`,
);
@@ -331,6 +348,10 @@ export class AgentChatThreadParticipantService {
}
async isFollowing(args: AgentChatThreadAccessArgs): Promise<boolean> {
+ await this.sharingService.assertHasMentionResolutionOrThrow(
+ args.workspaceId,
+ );
+
const participant = await this.threadRepository.query(
args.workspaceId,
({ manager }) => this.findOne({ manager, ...args }),
@@ -341,6 +362,10 @@ export class AgentChatThreadParticipantService {
// For the row written along with a new thread
async emitParticipantCreated(args: AgentChatThreadAccessArgs): Promise<void> {
+ await this.sharingService.assertHasMentionResolutionOrThrow(
+ args.workspaceId,
+ );
+
const participant = await this.threadRepository.query(
args.workspaceId,
({ manager }) => this.findOne({ manager, ...args }),
@@ -471,6 +496,8 @@ export class AgentChatThreadParticipantService {
AgentChatThreadAccessArgs,
'threadId'
>): Promise<AgentChatOpenThreadsSummaryDTO> {
+ await this.sharingService.assertHasMentionResolutionOrThrow(workspaceId);
+
const authContext = await this.sharingService.getAuthContext({
workspaceId,
workspaceMemberId,
@@ -501,21 +528,20 @@ export class AgentChatThreadParticipantService {
>
>(
`WITH open_thread AS (
- SELECT thread."assigneeId", thread."pendingQuestionMessageId", participant."lastMentionedAt",
+ SELECT thread."assigneeId", thread."pendingQuestionMessageId", ${HAS_UNRESOLVED_MENTION} AS "hasUnresolvedMention",
thread."lastActivityAt" IS NOT NULL
AND (participant."lastReadAt" IS NULL OR thread."lastActivityAt" > participant."lastReadAt") AS "isUnread"
FROM (${readableThreads.getQuery()}) thread
JOIN ${getAgentChatThreadParticipantTable(workspaceId)} participant
ON participant."threadId" = thread.id AND participant."workspaceMemberId" = :summaryWorkspaceMemberId
- WHERE participant."isSubscribed"
- AND (participant."archivedAt" IS NULL OR thread."lastActivityAt" > participant."archivedAt")
+ WHERE ${IS_IN_INBOX}
)
SELECT
COUNT(*)::int AS "openThreadCount",
COUNT(*) FILTER (WHERE "isUnread")::int AS "unreadOpenThreadCount",
COUNT("pendingQuestionMessageId")::int AS "needsInputThreadCount",
COALESCE(BOOL_OR("isUnread"), false) AS "hasUnreadOpenThread",
- COALESCE(BOOL_OR("isUnread" AND "lastMentionedAt" IS NOT NULL), false) AS "hasUnreadMentionThread",
+ COALESCE(BOOL_OR("isUnread" AND "hasUnresolvedMention"), false) AS "hasUnreadMentionThread",
COALESCE(BOOL_OR("isUnread" AND "assigneeId" = :summaryWorkspaceMemberId), false) AS "hasUnreadAssignedThread"
FROM open_thread`,
{
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread.service.ts
index c6f85acb58b..c04f9bc0af8 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-thread.service.ts
@@ -211,6 +211,9 @@ export class AgentChatThreadService {
return;
}
+ const participantObjectMetadataId =
+ await this.sharingService.getParticipantObjectMetadataId(workspaceId);
+
const { generatedMaps: assignedThreads } =
await this.threadRepository.update(
workspaceId,
@@ -226,8 +229,6 @@ export class AgentChatThreadService {
}
const assignedThreadIds = assignedThreads.map(({ id }) => id);
- const participantObjectMetadataId =
- await this.sharingService.getParticipantObjectMetadataId(workspaceId);
const setUpThreads = await this.threadRepository.query(
workspaceId,
@@ -357,6 +358,10 @@ export class AgentChatThreadService {
participantArgs: AgentChatThreadAccessArgs,
) => Promise<void>;
}): Promise<string[]> {
+ await this.sharingService.assertHasMentionResolutionOrThrow(
+ args.workspaceId,
+ );
+
const thread = await this.getWritableThread(args);
const candidateMemberIds = [
...new Set(participantWorkspaceMemberIds),
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-history/standard-objects/agent-chat-thread-participant.workspace-entity.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-history/standard-objects/agent-chat-thread-participant.workspace-entity.ts
index b781b31738d..68636085a06 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-history/standard-objects/agent-chat-thread-participant.workspace-entity.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-history/standard-objects/agent-chat-thread-participant.workspace-entity.ts
@@ -14,4 +14,5 @@ export class AgentChatThreadParticipantWorkspaceEntity extends BaseWorkspaceEnti
snoozedUntil: string | null;
isSubscribed: boolean;
lastMentionedAt: string | null;
+ mentionsResolvedAt: string | null;
}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai.exception.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai.exception.ts
index 3859e14a466..fbe6c008b5d 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai.exception.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai.exception.ts
@@ -23,6 +23,7 @@ export enum AiExceptionCode {
CHAT_THREAD_CANNOT_LEAVE_CHANNEL = 'CHAT_THREAD_CANNOT_LEAVE_CHANNEL',
CHAT_CHANNEL_NOT_FOUND = 'CHAT_CHANNEL_NOT_FOUND',
CHAT_CHANNELS_UNAVAILABLE = 'CHAT_CHANNELS_UNAVAILABLE',
+ CHAT_UPGRADE_IN_PROGRESS = 'CHAT_UPGRADE_IN_PROGRESS',
CHAT_CHANNEL_NOT_EMPTY = 'CHAT_CHANNEL_NOT_EMPTY',
CHAT_CHANNEL_BUSY = 'CHAT_CHANNEL_BUSY',
CHAT_CHANNEL_IS_STANDARD = 'CHAT_CHANNEL_IS_STANDARD',
@@ -87,6 +88,8 @@ const getAiExceptionUserFriendlyMessage = (code: AiExceptionCode) => {
return msg`Channel not found.`;
case AiExceptionCode.CHAT_CHANNELS_UNAVAILABLE:
return msg`Channels are not available yet. Try again in a few minutes.`;
+ case AiExceptionCode.CHAT_UPGRADE_IN_PROGRESS:
+ return msg`Chats are not available yet. Try again in a few minutes.`;
case AiExceptionCode.CHAT_CHANNEL_NOT_EMPTY:
return msg`Move this channel's chats to another channel before deleting it.`;
case AiExceptionCode.CHAT_CHANNEL_BUSY:
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/utils/ai-graphql-api-exception-handler.util.ts b/packages/twenty-server/src/engine/metadata-modules/ai/utils/ai-graphql-api-exception-handler.util.ts
index 4c2bc8b4307..061e3fd9755 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/utils/ai-graphql-api-exception-handler.util.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/utils/ai-graphql-api-exception-handler.util.ts
@@ -45,6 +45,7 @@ export const aiGraphqlApiExceptionHandler = (error: Error) => {
case AiExceptionCode.AGENT_ALREADY_EXISTS:
case AiExceptionCode.NO_FAILED_TURN_TO_RETRY:
case AiExceptionCode.CHAT_CHANNELS_UNAVAILABLE:
+ case AiExceptionCode.CHAT_UPGRADE_IN_PROGRESS:
case AiExceptionCode.THREAD_AWAITING_ANSWER:
case AiExceptionCode.CHAT_THREAD_ASSIGNEE_CANNOT_UNSUBSCRIBE:
case AiExceptionCode.CHAT_CHANNEL_NOT_EMPTY:
diff --git a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/__tests__/__snapshots__/get-standard-object-metadata-related-entity-ids.util.spec.ts.snap b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/__tests__/__snapshots__/get-standard-object-metadata-related-entity-ids.util.spec.ts.snap
index b87f6899340..18e95a7c44d 100644
--- a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/__tests__/__snapshots__/get-standard-object-metadata-related-entity-ids.util.spec.ts.snap
+++ b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/__tests__/__snapshots__/get-standard-object-metadata-related-entity-ids.util.spec.ts.snap
@@ -127,6 +127,9 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
"lastReadAt": {
"id": "00000000-0000-0000-0000-000000001084",
},
+ "mentionsResolvedAt": {
+ "id": "00000000-0000-0000-0000-000000001089",
+ },
"snoozedUntil": {
"id": "00000000-0000-0000-0000-000000001086",
},
@@ -140,268 +143,268 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
"id": "00000000-0000-0000-0000-000000001083",
},
},
- "id": "00000000-0000-0000-0000-000000001089",
+ "id": "00000000-0000-0000-0000-000000001090",
"views": undefined,
},
"agentChatThreadTarget": {
"fields": {
"createdAt": {
- "id": "00000000-0000-0000-0000-000000001092",
+ "id": "00000000-0000-0000-0000-000000001093",
},
"deletedAt": {
- "id": "00000000-0000-0000-0000-000000001094",
+ "id": "00000000-0000-0000-0000-000000001095",
},
"id": {
- "id": "00000000-0000-0000-0000-000000001091",
+ "id": "00000000-0000-0000-0000-000000001092",
},
"target": {
- "id": "00000000-0000-0000-0000-000000001090",
+ "id": "00000000-0000-0000-0000-000000001091",
},
"targetCompany": {
- "id": "00000000-0000-0000-0000-000000001097",
+ "id": "00000000-0000-0000-0000-000000001098",
},
"targetOpportunity": {
- "id": "00000000-0000-0000-0000-000000001098",
+ "id": "00000000-0000-0000-0000-000000001099",
},
"targetPerson": {
- "id": "00000000-0000-0000-0000-000000001096",
+ "id": "00000000-0000-0000-0000-000000001097",
},
"thread": {
- "id": "00000000-0000-0000-0000-000000001095",
+ "id": "00000000-0000-0000-0000-000000001096",
},
"updatedAt": {
- "id": "00000000-0000-0000-0000-000000001093",
+ "id": "00000000-0000-0000-0000-000000001094",
},
},
- "id": "00000000-0000-0000-0000-000000001099",
+ "id": "00000000-0000-0000-0000-000000001100",
"views": {},
},
"agentMessage": {
"fields": {
"agentId": {
- "id": "00000000-0000-0000-0000-000000001124",
+ "id": "00000000-0000-0000-0000-000000001125",
},
"createdAt": {
- "id": "00000000-0000-0000-0000-000000001121",
+ "id": "00000000-0000-0000-0000-000000001122",
},
"deletedAt": {
- "id": "00000000-0000-0000-0000-000000001123",
+ "id": "00000000-0000-0000-0000-000000001124",
},
"id": {
- "id": "00000000-0000-0000-0000-000000001120",
+ "id": "00000000-0000-0000-0000-000000001121",
},
"parts": {
- "id": "00000000-0000-0000-0000-000000001132",
+ "id": "00000000-0000-0000-0000-000000001133",
},
"processedAt": {
- "id": "00000000-0000-0000-0000-000000001129",
+ "id": "00000000-0000-0000-0000-000000001130",
},
"reactions": {
- "id": "00000000-0000-0000-0000-000000001133",
+ "id": "00000000-0000-0000-0000-000000001134",
},
"role": {
- "id": "00000000-0000-0000-0000-000000001127",
+ "id": "00000000-0000-0000-0000-000000001128",
},
"senderApplicationId": {
- "id": "00000000-0000-0000-0000-000000001126",
+ "id": "00000000-0000-0000-0000-000000001127",
},
"senderWorkspaceMember": {
- "id": "00000000-0000-0000-0000-000000001125",
+ "id": "00000000-0000-0000-0000-000000001126",
},
"status": {
- "id": "00000000-0000-0000-0000-000000001128",
+ "id": "00000000-0000-0000-0000-000000001129",
},
"thread": {
- "id": "00000000-0000-0000-0000-000000001130",
+ "id": "00000000-0000-0000-0000-000000001131",
},
"turn": {
- "id": "00000000-0000-0000-0000-000000001131",
+ "id": "00000000-0000-0000-0000-000000001132",
},
"updatedAt": {
- "id": "00000000-0000-0000-0000-000000001122",
+ "id": "00000000-0000-0000-0000-000000001123",
},
},
- "id": "00000000-0000-0000-0000-000000001134",
+ "id": "00000000-0000-0000-0000-000000001135",
"views": undefined,
},
"agentMessagePart": {
"fields": {
"createdAt": {
- "id": "00000000-0000-0000-0000-000000001145",
+ "id": "00000000-0000-0000-0000-000000001146",
},
"deletedAt": {
- "id": "00000000-0000-0000-0000-000000001147",
+ "id": "00000000-0000-0000-0000-000000001148",
},
"errorDetails": {
- "id": "00000000-0000-0000-0000-000000001159",
+ "id": "00000000-0000-0000-0000-000000001160",
},
"errorMessage": {
- "id": "00000000-0000-0000-0000-000000001158",
+ "id": "00000000-0000-0000-0000-000000001159",
},
"fileFilename": {
- "id": "00000000-0000-0000-0000-000000001167",
+ "id": "00000000-0000-0000-0000-000000001168",
},
"fileId": {
- "id": "00000000-0000-0000-0000-000000001168",
+ "id": "00000000-0000-0000-0000-000000001169",
},
"id": {
- "id": "00000000-0000-0000-0000-000000001144",
+ "id": "00000000-0000-0000-0000-000000001145",
},
"message": {
- "id": "00000000-0000-0000-0000-000000001170",
+ "id": "00000000-0000-0000-0000-000000001171",
},
"orderIndex": {
- "id": "00000000-0000-0000-0000-000000001148",
+ "id": "00000000-0000-0000-0000-000000001149",
},
"providerExecuted": {
- "id": "00000000-0000-0000-0000-000000001157",
+ "id": "00000000-0000-0000-0000-000000001158",
},
"providerMetadata": {
- "id": "00000000-0000-0000-0000-000000001169",
+ "id": "00000000-0000-0000-0000-000000001170",
},
"reasoningContent": {
- "id": "00000000-0000-0000-0000-000000001151",
+ "id": "00000000-0000-0000-0000-000000001152",
},
"sourceDocumentFilename": {
- "id": "00000000-0000-0000-0000-000000001166",
+ "id": "00000000-0000-0000-0000-000000001167",
},
"sourceDocumentMediaType": {
- "id": "00000000-0000-0000-0000-000000001164",
+ "id": "00000000-0000-0000-0000-000000001165",
},
"sourceDocumentSourceId": {
- "id": "00000000-0000-0000-0000-000000001163",
+ "id": "00000000-0000-0000-0000-000000001164",
},
"sourceDocumentTitle": {
- "id": "00000000-0000-0000-0000-000000001165",
+ "id": "00000000-0000-0000-0000-000000001166",
},
"sourceUrlSourceId": {
- "id": "00000000-0000-0000-0000-000000001160",
+ "id": "00000000-0000-0000-0000-000000001161",
},
"sourceUrlTitle": {
- "id": "00000000-0000-0000-0000-000000001162",
+ "id": "00000000-0000-0000-0000-000000001163",
},
"sourceUrlUrl": {
- "id": "00000000-0000-0000-0000-000000001161",
+ "id": "00000000-0000-0000-0000-000000001162",
},
"state": {
- "id": "00000000-0000-0000-0000-000000001156",
+ "id": "00000000-0000-0000-0000-000000001157",
},
"textContent": {
- "id": "00000000-0000-0000-0000-000000001150",
+ "id": "00000000-0000-0000-0000-000000001151",
},
"toolCallId": {
- "id": "00000000-0000-0000-0000-000000001153",
+ "id": "00000000-0000-0000-0000-000000001154",
},
"toolInput": {
- "id": "00000000-0000-0000-0000-000000001154",
+ "id": "00000000-0000-0000-0000-000000001155",
},
"toolName": {
- "id": "00000000-0000-0000-0000-000000001152",
+ "id": "00000000-0000-0000-0000-000000001153",
},
"toolOutput": {
- "id": "00000000-0000-0000-0000-000000001155",
+ "id": "00000000-0000-0000-0000-000000001156",
},
"type": {
- "id": "00000000-0000-0000-0000-000000001149",
+ "id": "00000000-0000-0000-0000-000000001150",
},
"updatedAt": {
- "id": "00000000-0000-0000-0000-000000001146",
+ "id": "00000000-0000-0000-0000-000000001147",
},
},
- "id": "00000000-0000-0000-0000-000000001171",
+ "id": "00000000-0000-0000-0000-000000001172",
"views": undefined,
},
"agentMessageReaction": {
"fields": {
"agentId": {
- "id": "00000000-0000-0000-0000-000000001141",
+ "id": "00000000-0000-0000-0000-000000001142",
},
"createdAt": {
- "id": "00000000-0000-0000-0000-000000001136",
+ "id": "00000000-0000-0000-0000-000000001137",
},
"deletedAt": {
- "id": "00000000-0000-0000-0000-000000001138",
+ "id": "00000000-0000-0000-0000-000000001139",
},
"emoji": {
- "id": "00000000-0000-0000-0000-000000001142",
+ "id": "00000000-0000-0000-0000-000000001143",
},
"id": {
- "id": "00000000-0000-0000-0000-000000001135",
+ "id": "00000000-0000-0000-0000-000000001136",
},
"message": {
- "id": "00000000-0000-0000-0000-000000001139",
+ "id": "00000000-0000-0000-0000-000000001140",
},
"updatedAt": {
- "id": "00000000-0000-0000-0000-000000001137",
+ "id": "00000000-0000-0000-0000-000000001138",
},
"workspaceMember": {
- "id": "00000000-0000-0000-0000-000000001140",
+ "id": "00000000-0000-0000-0000-000000001141",
},
},
- "id": "00000000-0000-0000-0000-000000001143",
+ "id": "00000000-0000-0000-0000-000000001144",
"views": undefined,
},
"agentTurn": {
"fields": {
"agentId": {
- "id": "00000000-0000-0000-0000-000000001104",
+ "id": "00000000-0000-0000-0000-000000001105",
},
"cacheCreationTokens": {
- "id": "00000000-0000-0000-0000-000000001115",
+ "id": "00000000-0000-0000-0000-000000001116",
},
"cacheReadTokens": {
- "id": "00000000-0000-0000-0000-000000001114",
+ "id": "00000000-0000-0000-0000-000000001115",
},
"createdAt": {
- "id": "00000000-0000-0000-0000-000000001101",
+ "id": "00000000-0000-0000-0000-000000001102",
},
"createdBy": {
- "id": "00000000-0000-0000-0000-000000001118",
+ "id": "00000000-0000-0000-0000-000000001119",
},
"deletedAt": {
- "id": "00000000-0000-0000-0000-000000001103",
+ "id": "00000000-0000-0000-0000-000000001104",
},
"endedAt": {
- "id": "00000000-0000-0000-0000-000000001110",
+ "id": "00000000-0000-0000-0000-000000001111",
},
"error": {
- "id": "00000000-0000-0000-0000-000000001108",
+ "id": "00000000-0000-0000-0000-000000001109",
},
"id": {
- "id": "00000000-0000-0000-0000-000000001100",
+ "id": "00000000-0000-0000-0000-000000001101",
},
"inputCredits": {
- "id": "00000000-0000-0000-0000-000000001116",
+ "id": "00000000-0000-0000-0000-000000001117",
},
"inputTokens": {
- "id": "00000000-0000-0000-0000-000000001112",
+ "id": "00000000-0000-0000-0000-000000001113",
},
"messages": {
- "id": "00000000-0000-0000-0000-000000001106",
+ "id": "00000000-0000-0000-0000-000000001107",
},
"modelId": {
- "id": "00000000-0000-0000-0000-000000001111",
+ "id": "00000000-0000-0000-0000-000000001112",
},
"outputCredits": {
- "id": "00000000-0000-0000-0000-000000001117",
+ "id": "00000000-0000-0000-0000-000000001118",
},
"outputTokens": {
- "id": "00000000-0000-0000-0000-000000001113",
+ "id": "00000000-0000-0000-0000-000000001114",
},
"startedAt": {
- "id": "00000000-0000-0000-0000-000000001109",
+ "id": "00000000-0000-0000-0000-000000001110",
},
"status": {
- "id": "00000000-0000-0000-0000-000000001107",
+ "id": "00000000-0000-0000-0000-000000001108",
},
"thread": {
- "id": "00000000-0000-0000-0000-000000001105",
+ "id": "00000000-0000-0000-0000-000000001106",
},
"updatedAt": {
- "id": "00000000-0000-0000-0000-000000001102",
+ "id": "00000000-0000-0000-0000-000000001103",
},
},
- "id": "00000000-0000-0000-0000-000000001119",
+ "id": "00000000-0000-0000-0000-000000001120",
"views": undefined,
},
"attachment": {
@@ -1165,64 +1168,64 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
"campaignDelivery": {
"fields": {
"bouncedAt": {
- "id": "00000000-0000-0000-0000-000000001187",
+ "id": "00000000-0000-0000-0000-000000001188",
},
"campaignId": {
- "id": "00000000-0000-0000-0000-000000001176",
+ "id": "00000000-0000-0000-0000-000000001177",
},
"claimExpiresAt": {
- "id": "00000000-0000-0000-0000-000000001183",
+ "id": "00000000-0000-0000-0000-000000001184",
},
"claimToken": {
- "id": "00000000-0000-0000-0000-000000001182",
+ "id": "00000000-0000-0000-0000-000000001183",
},
"complainedAt": {
- "id": "00000000-0000-0000-0000-000000001188",
+ "id": "00000000-0000-0000-0000-000000001189",
},
"createdAt": {
- "id": "00000000-0000-0000-0000-000000001173",
+ "id": "00000000-0000-0000-0000-000000001174",
},
"deletedAt": {
- "id": "00000000-0000-0000-0000-000000001175",
+ "id": "00000000-0000-0000-0000-000000001176",
},
"deliveredAt": {
- "id": "00000000-0000-0000-0000-000000001186",
+ "id": "00000000-0000-0000-0000-000000001187",
},
"failureReason": {
- "id": "00000000-0000-0000-0000-000000001181",
+ "id": "00000000-0000-0000-0000-000000001182",
},
"id": {
- "id": "00000000-0000-0000-0000-000000001172",
+ "id": "00000000-0000-0000-0000-000000001173",
},
"personId": {
- "id": "00000000-0000-0000-0000-000000001177",
+ "id": "00000000-0000-0000-0000-000000001178",
},
"providerMessageId": {
- "id": "00000000-0000-0000-0000-000000001184",
+ "id": "00000000-0000-0000-0000-000000001185",
},
"recipientEmail": {
- "id": "00000000-0000-0000-0000-000000001178",
+ "id": "00000000-0000-0000-0000-000000001179",
},
"rejectedAt": {
- "id": "00000000-0000-0000-0000-000000001189",
+ "id": "00000000-0000-0000-0000-000000001190",
},
"renderingFailedAt": {
- "id": "00000000-0000-0000-0000-000000001190",
+ "id": "00000000-0000-0000-0000-000000001191",
},
"sentAt": {
- "id": "00000000-0000-0000-0000-000000001185",
+ "id": "00000000-0000-0000-0000-000000001186",
},
"skipReason": {
- "id": "00000000-0000-0000-0000-000000001180",
+ "id": "00000000-0000-0000-0000-000000001181",
},
"state": {
- "id": "00000000-0000-0000-0000-000000001179",
+ "id": "00000000-0000-0000-0000-000000001180",
},
"updatedAt": {
- "id": "00000000-0000-0000-0000-000000001174",
+ "id": "00000000-0000-0000-0000-000000001175",
},
},
- "id": "00000000-0000-0000-0000-000000001191",
+ "id": "00000000-0000-0000-0000-000000001192",
"views": undefined,
},
"company": {
@@ -2219,34 +2222,34 @@ exports[`getStandardObjectMetadataRelatedEntityIds should return standard object
"messageSuppression": {
"fields": {
"createdAt": {
- "id": "00000000-0000-0000-0000-000000001193",
+ "id": "00000000-0000-0000-0000-000000001194",
},
"deletedAt": {
- "id": "00000000-0000-0000-0000-000000001195",
+ "id": "00000000-0000-0000-0000-000000001196",
},
"emailAddress": {
- "id": "00000000-0000-0000-0000-000000001196",
+ "id": "00000000-0000-0000-0000-000000001197",
},
"id": {
- "id": "00000000-0000-0000-0000-000000001192",
+ "id": "00000000-0000-0000-0000-000000001193",
},
"providerEventId": {
- "id": "00000000-0000-0000-0000-000000001199",
+ "id": "00000000-0000-0000-0000-000000001200",
},
"reason": {
- "id": "00000000-0000-0000-0000-000000001197",
+ "id": "00000000-0000-0000-0000-000000001198",
},
"source": {
- "id": "00000000-0000-0000-0000-000000001198",
+ "id": "00000000-0000-0000-0000-000000001199",
},
"unsubscribeTopicId": {
- "id": "00000000-0000-0000-0000-000000001200",
+ "id": "00000000-0000-0000-0000-000000001201",
},
"updatedAt": {
- "id": "00000000-0000-0000-0000-000000001194",
+ "id": "00000000-0000-0000-0000-000000001195",
},
},
- "id": "00000000-0000-0000-0000-000000001201",
+ "id": "00000000-0000-0000-0000-000000001202",
"views": undefined,
},
"messageThread": {
diff --git a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/field-metadata/compute-agent-chat-thread-participant-standard-flat-field-metadata.util.ts b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/field-metadata/compute-agent-chat-thread-participant-standard-flat-field-metadata.util.ts
index 2ebb40418a0..73797353e2f 100644
--- a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/field-metadata/compute-agent-chat-thread-participant-standard-flat-field-metadata.util.ts
+++ b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/utils/field-metadata/compute-agent-chat-thread-participant-standard-flat-field-metadata.util.ts
@@ -316,4 +316,33 @@ export const buildAgentChatThreadParticipantStandardFlatFieldMetadatas = (
PLATFORM_WRITTEN_DISABLED_FIELD_PERMISSION_ACTIONS,
isAuditLogged: false,
},
+ mentionsResolvedAt: {
+ ...createStandardFieldFlatMetadata({
+ ...args,
+ context: {
+ fieldName: 'mentionsResolvedAt',
+ type: FieldMetadataType.DATE_TIME,
+ label: i18nLabel(
+ msg({
+ message: 'Mentions resolved at',
+ context: 'fieldMetadata.label',
+ }),
+ ),
+ description: i18nLabel(
+ msg({
+ message: 'Mentions up to this time are resolved for the member',
+ context: 'fieldMetadata.description',
+ }),
+ ),
+ icon: 'IconAt',
+ isSystem: true,
+ isUIEditable: false,
+ isNullable: true,
+ },
+ }),
+ writability: MetadataWritability.SYSTEM,
+ disabledFieldPermissionActions:
+ PLATFORM_WRITTEN_DISABLED_FIELD_PERMISSION_ACTIONS,
+ isAuditLogged: false,
+ },
});
diff --git a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant.integration-spec.ts b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant.integration-spec.ts
index 9ab6f9c7ba4..ee34424a08f 100644
--- a/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant.integration-spec.ts
+++ b/packages/twenty-server/test/integration/graphql/suites/chat-thread-participant.integration-spec.ts
@@ -31,7 +31,7 @@ import { WORKSPACE_MEMBER_DATA_SEED_IDS } from 'src/engine/workspace-manager/dev
const SCHEMA = getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID);
const PARTICIPANT_FIELDS =
- 'id threadId lastReadAt archivedAt snoozedUntil isSubscribed lastMentionedAt updatedAt';
+ 'id threadId lastReadAt archivedAt snoozedUntil isSubscribed lastMentionedAt mentionsResolvedAt updatedAt';
const UPDATE_INBOX_STATE = parse(
`mutation UpdateInboxState($threadIds: [UUID!]!, $action: AgentChatInboxAction!, $snoozedUntil: DateTime) { updateAgentChatThreadInboxState(threadIds: $threadIds, action: $action, snoozedUntil: $snoozedUntil) { ${PARTICIPANT_FIELDS} } }`,
@@ -87,6 +87,7 @@ type Participant = {
snoozedUntil: string | null;
isSubscribed: boolean;
lastMentionedAt: string | null;
+ mentionsResolvedAt: string | null;
};
const OPEN_THREADS_SUMMARY = parse(
@@ -1221,6 +1222,110 @@ describe('Chat thread participant state through the authenticated API', () => {
});
});
+ it('resolves the mention when the member reads the chat and keeps it when they mark it unread', async () => {
+ const threadId = await createTestThread();
+
+ await addParticipants(threadId, [WORKSPACE_MEMBER_DATA_SEED_IDS.JONY]);
+
+ for (const action of ['READ', 'UNREAD']) {
+ const response = await runInboxAction(action, threadId, {
+ token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ });
+ const participant = response.body.data.updateAgentChatThreadInboxState[0];
+
+ expect(response.body.errors).toBeUndefined();
+ expect(participant.mentionsResolvedAt).toBe(participant.lastMentionedAt);
+ }
+ });
+
+ it('preserves unresolved mentions while marking unread and snoozing', async () => {
+ const threadId = await createTestThread();
+
+ await addParticipants(threadId, [WORKSPACE_MEMBER_DATA_SEED_IDS.JONY]);
+
+ for (const action of ['UNREAD', 'SNOOZE']) {
+ const response = await runInboxAction(action, threadId, {
+ token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ snoozedUntil:
+ action === 'SNOOZE' ? buildFutureSnoozedUntil() : undefined,
+ });
+
+ expect(response.body.errors).toBeUndefined();
+ expect(
+ response.body.data.updateAgentChatThreadInboxState[0],
+ ).toMatchObject({
+ lastMentionedAt: expect.any(String),
+ mentionsResolvedAt: null,
+ });
+ }
+ });
+
+ it('keeps a mention resolved after Done until an explicit new mention arrives', async () => {
+ const threadId = await createTestThread();
+
+ await addParticipants(threadId, [WORKSPACE_MEMBER_DATA_SEED_IDS.JONY]);
+ await runInboxAction('ARCHIVE', threadId, {
+ token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ });
+
+ const doneParticipant = await findMyParticipant(
+ threadId,
+ APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ );
+
+ expect(doneParticipant!.mentionsResolvedAt).toBe(
+ doneParticipant!.lastMentionedAt,
+ );
+
+ await getAppProviderByClassName<AgentChatThreadService>(
+ 'AgentChatThreadService',
+ ).recordThreadActivity({
+ workspaceId: SEED_APPLE_WORKSPACE_ID,
+ threadId,
+ text: 'An unrelated update',
+ });
+ await runInboxAction('MOVE_TO_INBOX', threadId, {
+ token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ });
+
+ expect(
+ await findMyParticipant(threadId, APPLE_JONY_MEMBER_ACCESS_TOKEN),
+ ).toMatchObject({
+ lastMentionedAt: doneParticipant!.lastMentionedAt,
+ mentionsResolvedAt: doneParticipant!.mentionsResolvedAt,
+ });
+
+ await addParticipants(threadId, [WORKSPACE_MEMBER_DATA_SEED_IDS.JONY]);
+
+ const mentionedAgain = await findMyParticipant(
+ threadId,
+ APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ );
+
+ expect(
+ new Date(mentionedAgain!.lastMentionedAt!).getTime(),
+ ).toBeGreaterThan(new Date(mentionedAgain!.mentionsResolvedAt!).getTime());
+ });
+
+ it('resolves a mention when the member unsubscribes', async () => {
+ const threadId = await createTestThread();
+
+ await addParticipants(threadId, [WORKSPACE_MEMBER_DATA_SEED_IDS.JONY]);
+ await runInboxAction('UNSUBSCRIBE', threadId, {
+ token: APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ });
+
+ const unsubscribedParticipant = await findMyParticipant(
+ threadId,
+ APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ );
+
+ expect(unsubscribedParticipant).toMatchObject({
+ isSubscribed: false,
+ mentionsResolvedAt: unsubscribedParticipant!.lastMentionedAt,
+ });
+ });
+
it('delivers app recipients without creating or clearing an explicit mention', async () => {
const threadId = await createTestThread();
const threadService = getAppProviderByClassName<AgentChatThreadService>(
@@ -1241,6 +1346,7 @@ describe('Chat thread participant state through the authenticated API', () => {
isSubscribed: true,
lastReadAt: null,
lastMentionedAt: null,
+ mentionsResolvedAt: null,
});
await addParticipants(threadId, [WORKSPACE_MEMBER_DATA_SEED_IDS.JONY]);
@@ -1256,6 +1362,30 @@ describe('Chat thread participant state through the authenticated API', () => {
await findMyParticipant(threadId, APPLE_JONY_MEMBER_ACCESS_TOKEN),
).toMatchObject({
lastMentionedAt: mentionedParticipant!.lastMentionedAt,
+ mentionsResolvedAt: null,
});
});
+
+ it('orders a new mention after the resolved cursor at millisecond precision', async () => {
+ const threadId = await createTestThread();
+ const resolvedAt = new Date(Date.now() + 60_000).toISOString();
+
+ await addParticipants(threadId, [WORKSPACE_MEMBER_DATA_SEED_IDS.JONY]);
+ await global.testDataSource.query(
+ `UPDATE ${SCHEMA}."agentChatThreadParticipant"
+ SET "lastMentionedAt" = $3, "mentionsResolvedAt" = $3
+ WHERE "threadId" = $1 AND "workspaceMemberId" = $2`,
+ [threadId, WORKSPACE_MEMBER_DATA_SEED_IDS.JONY, resolvedAt],
+ );
+ await addParticipants(threadId, [WORKSPACE_MEMBER_DATA_SEED_IDS.JONY]);
+
+ const participant = await findMyParticipant(
+ threadId,
+ APPLE_JONY_MEMBER_ACCESS_TOKEN,
+ );
+
+ expect(new Date(participant!.lastMentionedAt!).getTime()).toBe(
+ new Date(resolvedAt).getTime() + 1,
+ );
+ });
});
diff --git a/packages/twenty-server/test/integration/upgrade/suites/2-54-workspace-command-1793350721809-add-chat-mention-resolution.integration-spec.ts b/packages/twenty-server/test/integration/upgrade/suites/2-54-workspace-command-1793350721809-add-chat-mention-resolution.integration-spec.ts
new file mode 100644
index 00000000000..6327511773f
--- /dev/null
+++ b/packages/twenty-server/test/integration/upgrade/suites/2-54-workspace-command-1793350721809-add-chat-mention-resolution.integration-spec.ts
@@ -0,0 +1,100 @@
+import { STANDARD_OBJECTS } from 'twenty-shared/metadata';
+import { isDefined } from 'twenty-shared/utils';
+
+import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';
+
+import { type AddChatMentionResolutionCommand } from 'src/database/commands/upgrade-version-command/2-54/2-54-workspace-command-1793350721809-add-chat-mention-resolution.command';
+import { type AgentChatSharingService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat-sharing.service';
+import { AiExceptionCode } from 'src/engine/metadata-modules/ai/ai.exception';
+import { type WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
+import { getWorkspaceSchemaName } from 'src/engine/workspace-datasource/utils/get-workspace-schema-name.util';
+import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';
+
+const RUN_ON_WORKSPACE_ARGS = {
+ workspaceId: SEED_APPLE_WORKSPACE_ID,
+ options: {},
+ index: 0,
+ total: 1,
+};
+const SCHEMA = getWorkspaceSchemaName(SEED_APPLE_WORKSPACE_ID);
+const MENTIONS_RESOLVED_AT_FIELD_UNIVERSAL_IDENTIFIER =
+ STANDARD_OBJECTS.agentChatThreadParticipant.fields.mentionsResolvedAt
+ .universalIdentifier;
+
+describe('2-54 workspace command - add chat mention resolution (integration)', () => {
+ let command: AddChatMentionResolutionCommand;
+ let workspaceCacheService: WorkspaceCacheService;
+ let sharingService: AgentChatSharingService;
+
+ const findResolutionMetadata = async () => {
+ const { flatFieldMetadataMaps } =
+ await workspaceCacheService.getOrRecompute(SEED_APPLE_WORKSPACE_ID, [
+ 'flatFieldMetadataMaps',
+ ]);
+ const columns: { column_name: string }[] =
+ await global.testDataSource.query(
+ `SELECT column_name FROM information_schema.columns
+ WHERE table_schema = $1 AND table_name = 'agentChatThreadParticipant'
+ AND column_name = 'mentionsResolvedAt'`,
+ [SCHEMA],
+ );
+
+ return {
+ hasField: isDefined(
+ flatFieldMetadataMaps.byUniversalIdentifier[
+ MENTIONS_RESOLVED_AT_FIELD_UNIVERSAL_IDENTIFIER
+ ],
+ ),
+ hasColumn: columns.length === 1,
+ };
+ };
+
+ beforeAll(() => {
+ command = getAppProviderByClassName<AddChatMentionResolutionCommand>(
+ 'AddChatMentionResolutionCommand',
+ );
+ workspaceCacheService = getAppProviderByClassName<WorkspaceCacheService>(
+ 'WorkspaceCacheService',
+ );
+ sharingService = getAppProviderByClassName<AgentChatSharingService>(
+ 'AgentChatSharingService',
+ );
+ });
+
+ afterAll(async () => {
+ await command.up(RUN_ON_WORKSPACE_ARGS);
+ });
+
+ it('removes the field and column on down, and fences participant access', async () => {
+ await command.down(RUN_ON_WORKSPACE_ARGS);
+
+ expect(await findResolutionMetadata()).toEqual({
+ hasField: false,
+ hasColumn: false,
+ });
+ await expect(
+ sharingService.getParticipantObjectMetadataId(SEED_APPLE_WORKSPACE_ID),
+ ).rejects.toMatchObject({ code: AiExceptionCode.CHAT_UPGRADE_IN_PROGRESS });
+ });
+
+ it('leaves the field absent on a dry run', async () => {
+ await command.up({ ...RUN_ON_WORKSPACE_ARGS, options: { dryRun: true } });
+
+ expect(await findResolutionMetadata()).toEqual({
+ hasField: false,
+ hasColumn: false,
+ });
+ });
+
+ it('adds the field and lifts the participant access fence', async () => {
+ await command.up(RUN_ON_WORKSPACE_ARGS);
+
+ expect(await findResolutionMetadata()).toEqual({
+ hasField: true,
+ hasColumn: true,
+ });
+ await expect(
+ sharingService.getParticipantObjectMetadataId(SEED_APPLE_WORKSPACE_ID),
+ ).resolves.toEqual(expect.any(String));
+ });
+});
diff --git a/packages/twenty-shared/src/ai/index.ts b/packages/twenty-shared/src/ai/index.ts
index 51fd0ba58cc..4ab3c0f7403 100644
--- a/packages/twenty-shared/src/ai/index.ts
+++ b/packages/twenty-shared/src/ai/index.ts
@@ -109,8 +109,10 @@ export { buildFallbackProposedToolCall } from './utils/build-fallback-proposed-t
export { extractRecordReferenceIds } from './utils/extract-record-reference-ids.util';
export { formatRecordReference } from './utils/format-record-reference.util';
export { formatSkillReference } from './utils/format-skill-reference.util';
+export { getAgentChatMentionsResolvedAt } from './utils/get-agent-chat-mentions-resolved-at.util';
export { getAiModelTierFromModelId } from './utils/get-ai-model-tier-from-model-id.util';
export { inferAiSdkPackage } from './utils/infer-ai-sdk-package.util';
+export { isAgentChatMentionUnresolved } from './utils/is-agent-chat-mention-unresolved.util';
export { isAiEvaluationQuestionType } from './utils/is-ai-evaluation-question-type.util';
export { isAiModelEffort } from './utils/is-ai-model-effort.util';
export { isAiModelTier } from './utils/is-ai-model-tier.util';
diff --git a/packages/twenty-shared/src/ai/types/AgentChatInboxState.ts b/packages/twenty-shared/src/ai/types/AgentChatInboxState.ts
index 8c16e7df58e..ed22c600ed2 100644
--- a/packages/twenty-shared/src/ai/types/AgentChatInboxState.ts
+++ b/packages/twenty-shared/src/ai/types/AgentChatInboxState.ts
@@ -3,4 +3,6 @@ export type AgentChatInboxState = {
archivedAt: string | null;
snoozedUntil: string | null;
isSubscribed: boolean;
+ lastMentionedAt: string | null;
+ mentionsResolvedAt: string | null;
};
diff --git a/packages/twenty-shared/src/ai/utils/__tests__/apply-agent-chat-inbox-action.util.spec.ts b/packages/twenty-shared/src/ai/utils/__tests__/apply-agent-chat-inbox-action.util.spec.ts
index 1f079165ca5..cbcde0ef1dc 100644
--- a/packages/twenty-shared/src/ai/utils/__tests__/apply-agent-chat-inbox-action.util.spec.ts
+++ b/packages/twenty-shared/src/ai/utils/__tests__/apply-agent-chat-inbox-action.util.spec.ts
@@ -11,6 +11,8 @@ const READ: AgentChatInboxState = {
archivedAt: null,
snoozedUntil: null,
isSubscribed: true,
+ lastMentionedAt: null,
+ mentionsResolvedAt: null,
};
const SNOOZED_UNSUBSCRIBED: AgentChatInboxState = {
...READ,
@@ -93,4 +95,53 @@ describe('applyAgentChatInboxAction', () => {
applyAgentChatInboxAction({ participant, action, now: NOW, ...options }),
).toEqual(expected);
});
+
+ it.each<AgentChatInboxAction>(['READ', 'ARCHIVE', 'UNSUBSCRIBE'])(
+ 'resolves the recorded mention on %s',
+ (action) => {
+ expect(
+ applyAgentChatInboxAction({
+ participant: { ...READ, lastMentionedAt: EARLIER },
+ action,
+ now: NOW,
+ }),
+ ).toMatchObject({
+ lastMentionedAt: EARLIER,
+ mentionsResolvedAt: EARLIER,
+ });
+ },
+ );
+
+ it('keeps a later mention resolution when marking done', () => {
+ expect(
+ applyAgentChatInboxAction({
+ participant: {
+ ...READ,
+ lastMentionedAt: EARLIER,
+ mentionsResolvedAt: LATER,
+ },
+ action: 'ARCHIVE',
+ now: NOW,
+ }).mentionsResolvedAt,
+ ).toBe(LATER);
+ });
+
+ it.each<AgentChatInboxAction>([
+ 'UNREAD',
+ 'SNOOZE',
+ 'MOVE_TO_INBOX',
+ 'SUBSCRIBE',
+ ])('preserves unresolved mentions on %s', (action) => {
+ expect(
+ applyAgentChatInboxAction({
+ participant: { ...READ, lastMentionedAt: EARLIER },
+ action,
+ now: NOW,
+ snoozedUntil: LATER,
+ }),
+ ).toMatchObject({
+ lastMentionedAt: EARLIER,
+ mentionsResolvedAt: null,
+ });
+ });
});
diff --git a/packages/twenty-shared/src/ai/utils/apply-agent-chat-inbox-action.util.ts b/packages/twenty-shared/src/ai/utils/apply-agent-chat-inbox-action.util.ts
index 361eb2993dd..0f19cefc7ce 100644
--- a/packages/twenty-shared/src/ai/utils/apply-agent-chat-inbox-action.util.ts
+++ b/packages/twenty-shared/src/ai/utils/apply-agent-chat-inbox-action.util.ts
@@ -1,5 +1,6 @@
import { type AgentChatInboxAction } from '@/ai/types/AgentChatInboxAction';
import { type AgentChatInboxState } from '@/ai/types/AgentChatInboxState';
+import { getAgentChatMentionsResolvedAt } from '@/ai/utils/get-agent-chat-mentions-resolved-at.util';
import { isDefined } from '@/utils/validation/isDefined';
// What a chat without the member's row reads as: one they can open but do
@@ -9,11 +10,11 @@ const DEFAULT_AGENT_CHAT_INBOX_STATE: AgentChatInboxState = {
archivedAt: null,
snoozedUntil: null,
isSubscribed: false,
+ lastMentionedAt: null,
+ mentionsResolvedAt: null,
};
-// The server writes each action as one SQL upsert stamped by the database
-// clock (AgentChatThreadParticipantService); this is the same change, for
-// the optimistic copy apps show before the server answers
+// Optimistic copy of AgentChatThreadParticipantService's write
export const applyAgentChatInboxAction = ({
participant,
action,
@@ -40,6 +41,7 @@ export const applyAgentChatInboxAction = ({
new Date(state.lastReadAt) > new Date(threadLastActivityAt))
? state.lastReadAt
: threadLastActivityAt,
+ mentionsResolvedAt: getAgentChatMentionsResolvedAt(state),
};
case 'UNREAD':
return { ...state, lastReadAt: null };
@@ -47,6 +49,7 @@ export const applyAgentChatInboxAction = ({
case 'ARCHIVE':
return {
...state,
+ mentionsResolvedAt: getAgentChatMentionsResolvedAt(state),
archivedAt: now.toISOString(),
snoozedUntil: null,
isSubscribed: true,
@@ -76,6 +79,7 @@ export const applyAgentChatInboxAction = ({
case 'UNSUBSCRIBE':
return {
...state,
+ mentionsResolvedAt: getAgentChatMentionsResolvedAt(state),
isSubscribed: false,
archivedAt: now.toISOString(),
snoozedUntil: null,
diff --git a/packages/twenty-shared/src/ai/utils/get-agent-chat-mentions-resolved-at.util.ts b/packages/twenty-shared/src/ai/utils/get-agent-chat-mentions-resolved-at.util.ts
new file mode 100644
index 00000000000..85a9fd107de
--- /dev/null
+++ b/packages/twenty-shared/src/ai/utils/get-agent-chat-mentions-resolved-at.util.ts
@@ -0,0 +1,15 @@
+import { isAgentChatMentionUnresolved } from '@/ai/utils/is-agent-chat-mention-unresolved.util';
+
+export const getAgentChatMentionsResolvedAt = ({
+ lastMentionedAt,
+ mentionsResolvedAt,
+}: {
+ lastMentionedAt?: string | null;
+ mentionsResolvedAt?: string | null;
+}): string | null => {
+ if (isAgentChatMentionUnresolved({ lastMentionedAt, mentionsResolvedAt })) {
+ return lastMentionedAt ?? null;
+ }
+
+ return mentionsResolvedAt ?? null;
+};
diff --git a/packages/twenty-shared/src/ai/utils/is-agent-chat-mention-unresolved.util.ts b/packages/twenty-shared/src/ai/utils/is-agent-chat-mention-unresolved.util.ts
new file mode 100644
index 00000000000..157d912f216
--- /dev/null
+++ b/packages/twenty-shared/src/ai/utils/is-agent-chat-mention-unresolved.util.ts
@@ -0,0 +1,12 @@
+import { isDefined } from '@/utils/validation/isDefined';
+
+export const isAgentChatMentionUnresolved = ({
+ lastMentionedAt,
+ mentionsResolvedAt,
+}: {
+ lastMentionedAt?: string | null;
+ mentionsResolvedAt?: string | null;
+}): boolean =>
+ isDefined(lastMentionedAt) &&
+ (!isDefined(mentionsResolvedAt) ||
+ new Date(lastMentionedAt) > new Date(mentionsResolvedAt));
diff --git a/packages/twenty-shared/src/metadata/__tests__/__snapshots__/standardObjectUniversalIdentifiers.test.ts.snap b/packages/twenty-shared/src/metadata/__tests__/__snapshots__/standardObjectUniversalIdentifiers.test.ts.snap
index 8269dc782f9..2df4ba88ce8 100644
--- a/packages/twenty-shared/src/metadata/__tests__/__snapshots__/standardObjectUniversalIdentifiers.test.ts.snap
+++ b/packages/twenty-shared/src/metadata/__tests__/__snapshots__/standardObjectUniversalIdentifiers.test.ts.snap
@@ -137,6 +137,9 @@ exports[`STANDARD_OBJECTS universal identifiers should never change without an e
"lastReadAt": {
"universalIdentifier": "7e3a8319-c127-4c4f-add4-6feac37ea555",
},
+ "mentionsResolvedAt": {
+ "universalIdentifier": "12c0b0c8-86b2-48e5-8e2f-56a9eb9162c4",
+ },
"snoozedUntil": {
"universalIdentifier": "65bc5785-877d-4363-b65c-95175ba20fd0",
},
diff --git a/packages/twenty-shared/src/metadata/constants/standard-object-fields.constant.ts b/packages/twenty-shared/src/metadata/constants/standard-object-fields.constant.ts
index 68f28da0e19..f3802519ff1 100644
--- a/packages/twenty-shared/src/metadata/constants/standard-object-fields.constant.ts
+++ b/packages/twenty-shared/src/metadata/constants/standard-object-fields.constant.ts
@@ -115,6 +115,9 @@ export const STANDARD_OBJECT_FIELDS = {
lastMentionedAt: {
universalIdentifier: '52a54602-633f-496a-966a-9a70437fa887',
},
+ mentionsResolvedAt: {
+ universalIdentifier: '12c0b0c8-86b2-48e5-8e2f-56a9eb9162c4',
+ },
},
agentChatThreadTarget: {
target: { universalIdentifier: '2c4cc537-39a2-4df9-81a1-dda26eb19658' },