Skip to content

The open alternative to Salesforce, designed for AI.

feat(ai): surface AI chat stream failures through one typed error channel (#22434)

Félix Malfaitd709467902a3
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
index 46703a0519b..0072461209a 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.graphql
@@ -2824,9 +2824,15 @@ type AiSystemPromptPreview {
estimatedTokenCount: Int!
}
+type ChatStreamError {
+ code: String!
+ message: String!
+}
+
type ChatStreamCatchupChunks {
chunks: [JSON!]!
maxSeq: Int!
+ error: ChatStreamError
}
type SendChatMessageResult {
@@ -3373,6 +3379,7 @@ type Mutation {
updateCalendarChannel(input: UpdateCalendarChannelInput!): CalendarChannel!
createChatThread: AgentChatThread!
sendChatMessage(threadId: UUID!, text: String!, messageId: UUID!, browsingContext: JSON, modelId: String, fileAttachments: [FileAttachmentInput!]): SendChatMessageResult!
+ retryChatMessage(threadId: UUID!, modelId: String): SendChatMessageResult!
stopAgentChatStream(threadId: UUID!): Boolean!
renameChatThread(id: UUID!, title: String!): AgentChatThread!
archiveChatThread(id: UUID!): AgentChatThread!
diff --git a/packages/twenty-client-sdk/src/metadata/generated/schema.ts b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
index 462cdbbc638..d8bce60e1c4 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/schema.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/schema.ts
@@ -2508,9 +2508,16 @@ export interface AiSystemPromptPreview {
__typename: 'AiSystemPromptPreview'
}
+export interface ChatStreamError {
+ code: Scalars['String']
+ message: Scalars['String']
+ __typename: 'ChatStreamError'
+}
+
export interface ChatStreamCatchupChunks {
chunks: Scalars['JSON'][]
maxSeq: Scalars['Int']
+ error?: ChatStreamError
__typename: 'ChatStreamCatchupChunks'
}
@@ -2904,6 +2911,7 @@ export interface Mutation {
updateCalendarChannel: CalendarChannel
createChatThread: AgentChatThread
sendChatMessage: SendChatMessageResult
+ retryChatMessage: SendChatMessageResult
stopAgentChatStream: Scalars['Boolean']
renameChatThread: AgentChatThread
archiveChatThread: AgentChatThread
@@ -5632,9 +5640,17 @@ export interface AiSystemPromptPreviewGenqlSelection{
__scalar?: boolean | number
}
+export interface ChatStreamErrorGenqlSelection{
+ code?: boolean | number
+ message?: boolean | number
+ __typename?: boolean | number
+ __scalar?: boolean | number
+}
+
export interface ChatStreamCatchupChunksGenqlSelection{
chunks?: boolean | number
maxSeq?: boolean | number
+ error?: ChatStreamErrorGenqlSelection
__typename?: boolean | number
__scalar?: boolean | number
}
@@ -6071,6 +6087,7 @@ export interface MutationGenqlSelection{
updateCalendarChannel?: (CalendarChannelGenqlSelection & { __args: {input: UpdateCalendarChannelInput} })
createChatThread?: AgentChatThreadGenqlSelection
sendChatMessage?: (SendChatMessageResultGenqlSelection & { __args: {threadId: Scalars['UUID'], text: Scalars['String'], messageId: Scalars['UUID'], browsingContext?: (Scalars['JSON'] | null), modelId?: (Scalars['String'] | null), fileAttachments?: (FileAttachmentInput[] | null)} })
+ retryChatMessage?: (SendChatMessageResultGenqlSelection & { __args: {threadId: Scalars['UUID'], modelId?: (Scalars['String'] | null)} })
stopAgentChatStream?: { __args: {threadId: Scalars['UUID']} }
renameChatThread?: (AgentChatThreadGenqlSelection & { __args: {id: Scalars['UUID'], title: Scalars['String']} })
archiveChatThread?: (AgentChatThreadGenqlSelection & { __args: {id: Scalars['UUID']} })
@@ -8452,6 +8469,14 @@ export interface LogicFunctionLogsInput {applicationId?: (Scalars['UUID'] | null
+ const ChatStreamError_possibleTypes: string[] = ['ChatStreamError']
+ export const isChatStreamError = (obj?: { __typename?: any } | null): obj is ChatStreamError => {
+ if (!obj?.__typename) throw new Error('__typename is missing in "isChatStreamError"')
+ return ChatStreamError_possibleTypes.includes(obj.__typename)
+ }
+
+
+
const ChatStreamCatchupChunks_possibleTypes: string[] = ['ChatStreamCatchupChunks']
export const isChatStreamCatchupChunks = (obj?: { __typename?: any } | null): obj is ChatStreamCatchupChunks => {
if (!obj?.__typename) throw new Error('__typename is missing in "isChatStreamCatchupChunks"')
diff --git a/packages/twenty-client-sdk/src/metadata/generated/types.ts b/packages/twenty-client-sdk/src/metadata/generated/types.ts
index 78dffd2ab4a..3dbd67db620 100644
--- a/packages/twenty-client-sdk/src/metadata/generated/types.ts
+++ b/packages/twenty-client-sdk/src/metadata/generated/types.ts
@@ -71,18 +71,18 @@ export default {
276,
277,
284,
- 323,
324,
325,
326,
- 328,
- 330,
- 341,
- 348,
- 355,
- 438,
- 483,
- 492
+ 327,
+ 329,
+ 331,
+ 342,
+ 349,
+ 356,
+ 439,
+ 484,
+ 493
],
"types": {
"BillingProductDTO": {
@@ -5656,6 +5656,17 @@ export default {
1
]
},
+ "ChatStreamError": {
+ "code": [
+ 1
+ ],
+ "message": [
+ 1
+ ],
+ "__typename": [
+ 1
+ ]
+ },
"ChatStreamCatchupChunks": {
"chunks": [
15
@@ -5663,6 +5674,9 @@ export default {
"maxSeq": [
21
],
+ "error": [
+ 316
+ ],
"__typename": [
1
]
@@ -5723,7 +5737,7 @@ export default {
3
],
"evaluations": [
- 319
+ 320
],
"messages": [
312
@@ -5757,19 +5771,19 @@ export default {
1
],
"syncStatus": [
- 323
+ 324
],
"syncStage": [
- 324
+ 325
],
"visibility": [
- 325
+ 326
],
"isContactAutoCreationEnabled": [
6
],
"contactAutoCreationPolicy": [
- 326
+ 327
],
"isSyncEnabled": [
6
@@ -5820,7 +5834,7 @@ export default {
1
],
"pendingSyncAction": [
- 328
+ 329
],
"messageChannelId": [
3
@@ -5838,7 +5852,7 @@ export default {
"MessageFolderPendingSyncAction": {},
"CollectionHash": {
"collectionName": [
- 330
+ 331
],
"hash": [
1
@@ -5902,13 +5916,13 @@ export default {
},
"MinimalMetadata": {
"objectMetadataItems": [
- 331
+ 332
],
"views": [
- 332
+ 333
],
"collectionHashes": [
- 329
+ 330
],
"__typename": [
1
@@ -6061,7 +6075,7 @@ export default {
2,
{
"input": [
- 335,
+ 336,
"GetApiKeyInput!"
]
}
@@ -6164,7 +6178,7 @@ export default {
25,
{
"input": [
- 336,
+ 337,
"AgentIdInput!"
]
}
@@ -6220,7 +6234,7 @@ export default {
41,
{
"input": [
- 337,
+ 338,
"LogicFunctionIdInput!"
]
}
@@ -6232,7 +6246,7 @@ export default {
15,
{
"input": [
- 337,
+ 338,
"LogicFunctionIdInput!"
]
}
@@ -6241,7 +6255,7 @@ export default {
1,
{
"input": [
- 337,
+ 338,
"LogicFunctionIdInput!"
]
}
@@ -6407,7 +6421,7 @@ export default {
279,
{
"input": [
- 338,
+ 339,
"PreviewMessageCampaignAudienceInput!"
]
}
@@ -6457,7 +6471,7 @@ export default {
}
],
"myMessageFolders": [
- 327,
+ 328,
{
"messageChannelId": [
3
@@ -6465,7 +6479,7 @@ export default {
}
],
"myCalendarChannels": [
- 322,
+ 323,
{
"connectedAccountId": [
3
@@ -6473,13 +6487,13 @@ export default {
}
],
"minimalMetadata": [
- 333
+ 334
],
"appConnections": [
214,
{
"filter": [
- 339
+ 340
]
}
],
@@ -6493,7 +6507,7 @@ export default {
}
],
"findWorkspaceAiStats": [
- 321
+ 322
],
"chatThreads": [
313
@@ -6517,7 +6531,7 @@ export default {
}
],
"chatStreamCatchupChunks": [
- 316,
+ 317,
{
"threadId": [
3,
@@ -6541,7 +6555,7 @@ export default {
}
],
"agentTurns": [
- 320,
+ 321,
{
"agentId": [
3,
@@ -6610,7 +6624,7 @@ export default {
310,
{
"input": [
- 340,
+ 341,
"EventLogQueryInput!"
]
}
@@ -6619,7 +6633,7 @@ export default {
304,
{
"input": [
- 344,
+ 345,
"PieChartDataInput!"
]
}
@@ -6628,7 +6642,7 @@ export default {
302,
{
"input": [
- 345,
+ 346,
"LineChartDataInput!"
]
}
@@ -6637,7 +6651,7 @@ export default {
299,
{
"input": [
- 346,
+ 347,
"BarChartDataInput!"
]
}
@@ -6687,7 +6701,7 @@ export default {
260,
{
"input": [
- 347
+ 348
]
}
],
@@ -6761,10 +6775,10 @@ export default {
},
"EventLogQueryInput": {
"table": [
- 341
+ 342
],
"filters": [
- 342
+ 343
],
"first": [
21
@@ -6785,7 +6799,7 @@ export default {
1
],
"dateRange": [
- 343
+ 344
],
"recordId": [
1
@@ -6852,7 +6866,7 @@ export default {
1
],
"operationTypes": [
- 348
+ 349
],
"__typename": [
1
@@ -6864,7 +6878,7 @@ export default {
6,
{
"input": [
- 350,
+ 351,
"AddQuerySubscriptionInput!"
]
}
@@ -6873,7 +6887,7 @@ export default {
6,
{
"input": [
- 351,
+ 352,
"RemoveQueryFromEventStreamInput!"
]
}
@@ -6882,7 +6896,7 @@ export default {
156,
{
"inputs": [
- 352,
+ 353,
"[CreateNavigationMenuItemInput!]!"
]
}
@@ -6891,7 +6905,7 @@ export default {
156,
{
"input": [
- 352,
+ 353,
"CreateNavigationMenuItemInput!"
]
}
@@ -6900,7 +6914,7 @@ export default {
156,
{
"inputs": [
- 353,
+ 354,
"[UpdateOneNavigationMenuItemInput!]!"
]
}
@@ -6909,7 +6923,7 @@ export default {
156,
{
"input": [
- 353,
+ 354,
"UpdateOneNavigationMenuItemInput!"
]
}
@@ -6936,7 +6950,7 @@ export default {
127,
{
"file": [
- 355,
+ 356,
"Upload!"
]
}
@@ -6957,7 +6971,7 @@ export default {
127,
{
"file": [
- 355,
+ 356,
"Upload!"
]
}
@@ -6966,7 +6980,7 @@ export default {
127,
{
"file": [
- 355,
+ 356,
"Upload!"
]
}
@@ -6975,7 +6989,7 @@ export default {
127,
{
"file": [
- 355,
+ 356,
"Upload!"
]
}
@@ -6984,7 +6998,7 @@ export default {
127,
{
"file": [
- 355,
+ 356,
"Upload!"
]
}
@@ -6993,7 +7007,7 @@ export default {
127,
{
"file": [
- 355,
+ 356,
"Upload!"
],
"fieldMetadataId": [
@@ -7006,7 +7020,7 @@ export default {
127,
{
"file": [
- 355,
+ 356,
"Upload!"
],
"fieldMetadataUniversalIdentifier": [
@@ -7019,7 +7033,7 @@ export default {
58,
{
"input": [
- 356,
+ 357,
"CreateViewFilterGroupInput!"
]
}
@@ -7032,7 +7046,7 @@ export default {
"String!"
],
"input": [
- 357,
+ 358,
"UpdateViewFilterGroupInput!"
]
}
@@ -7059,7 +7073,7 @@ export default {
60,
{
"input": [
- 358,
+ 359,
"CreateViewFilterInput!"
]
}
@@ -7068,7 +7082,7 @@ export default {
60,
{
"input": [
- 359,
+ 360,
"UpdateViewFilterInput!"
]
}
@@ -7077,7 +7091,7 @@ export default {
60,
{
"input": [
- 361,
+ 362,
"DeleteViewFilterInput!"
]
}
@@ -7086,7 +7100,7 @@ export default {
60,
{
"input": [
- 362,
+ 363,
"DestroyViewFilterInput!"
]
}
@@ -7095,7 +7109,7 @@ export default {
66,
{
"input": [
- 363,
+ 364,
"CreateViewInput!"
]
}
@@ -7108,7 +7122,7 @@ export default {
"String!"
],
"input": [
- 364,
+ 365,
"UpdateViewInput!"
]
}
@@ -7135,7 +7149,7 @@ export default {
66,
{
"input": [
- 365,
+ 366,
"UpsertViewWidgetInput!"
]
}
@@ -7144,7 +7158,7 @@ export default {
63,
{
"input": [
- 370,
+ 371,
"CreateViewSortInput!"
]
}
@@ -7153,7 +7167,7 @@ export default {
63,
{
"input": [
- 371,
+ 372,
"UpdateViewSortInput!"
]
}
@@ -7162,7 +7176,7 @@ export default {
6,
{
"input": [
- 373,
+ 374,
"DeleteViewSortInput!"
]
}
@@ -7171,7 +7185,7 @@ export default {
6,
{
"input": [
- 374,
+ 375,
"DestroyViewSortInput!"
]
}
@@ -7180,7 +7194,7 @@ export default {
56,
{
"input": [
- 375,
+ 376,
"UpdateViewFieldInput!"
]
}
@@ -7189,7 +7203,7 @@ export default {
56,
{
"input": [
- 377,
+ 378,
"CreateViewFieldInput!"
]
}
@@ -7198,7 +7212,7 @@ export default {
56,
{
"inputs": [
- 377,
+ 378,
"[CreateViewFieldInput!]!"
]
}
@@ -7207,7 +7221,7 @@ export default {
56,
{
"input": [
- 378,
+ 379,
"DeleteViewFieldInput!"
]
}
@@ -7216,7 +7230,7 @@ export default {
56,
{
"input": [
- 379,
+ 380,
"DestroyViewFieldInput!"
]
}
@@ -7225,7 +7239,7 @@ export default {
65,
{
"input": [
- 380,
+ 381,
"UpdateViewFieldGroupInput!"
]
}
@@ -7234,7 +7248,7 @@ export default {
65,
{
"input": [
- 382,
+ 383,
"CreateViewFieldGroupInput!"
]
}
@@ -7243,7 +7257,7 @@ export default {
65,
{
"inputs": [
- 382,
+ 383,
"[CreateViewFieldGroupInput!]!"
]
}
@@ -7252,7 +7266,7 @@ export default {
65,
{
"input": [
- 383,
+ 384,
"DeleteViewFieldGroupInput!"
]
}
@@ -7261,7 +7275,7 @@ export default {
65,
{
"input": [
- 384,
+ 385,
"DestroyViewFieldGroupInput!"
]
}
@@ -7270,7 +7284,7 @@ export default {
66,
{
"input": [
- 385,
+ 386,
"UpsertFieldsWidgetInput!"
]
}
@@ -7279,7 +7293,7 @@ export default {
2,
{
"input": [
- 388,
+ 389,
"CreateApiKeyInput!"
]
}
@@ -7288,7 +7302,7 @@ export default {
2,
{
"input": [
- 389,
+ 390,
"UpdateApiKeyInput!"
]
}
@@ -7297,7 +7311,7 @@ export default {
2,
{
"input": [
- 390,
+ 391,
"RevokeApiKeyInput!"
]
}
@@ -7455,7 +7469,7 @@ export default {
126,
{
"input": [
- 391,
+ 392,
"CreateApprovedAccessDomainInput!"
]
}
@@ -7464,7 +7478,7 @@ export default {
6,
{
"input": [
- 392,
+ 393,
"DeleteApprovedAccessDomainInput!"
]
}
@@ -7473,7 +7487,7 @@ export default {
126,
{
"input": [
- 393,
+ 394,
"ValidateApprovedAccessDomainInput!"
]
}
@@ -7482,7 +7496,7 @@ export default {
119,
{
"input": [
- 394,
+ 395,
"CreatePageLayoutTabInput!"
]
}
@@ -7495,7 +7509,7 @@ export default {
"String!"
],
"input": [
- 395,
+ 396,
"UpdatePageLayoutTabInput!"
]
}
@@ -7513,7 +7527,7 @@ export default {
120,
{
"input": [
- 396,
+ 397,
"CreatePageLayoutInput!"
]
}
@@ -7526,7 +7540,7 @@ export default {
"String!"
],
"input": [
- 397,
+ 398,
"UpdatePageLayoutInput!"
]
}
@@ -7548,7 +7562,7 @@ export default {
"String!"
],
"input": [
- 398,
+ 399,
"UpdatePageLayoutWithTabsInput!"
]
}
@@ -7584,7 +7598,7 @@ export default {
81,
{
"input": [
- 402,
+ 403,
"CreatePageLayoutWidgetInput!"
]
}
@@ -7597,7 +7611,7 @@ export default {
"String!"
],
"input": [
- 403,
+ 404,
"UpdatePageLayoutWidgetInput!"
]
}
@@ -7615,7 +7629,7 @@ export default {
25,
{
"input": [
- 404,
+ 405,
"CreateAgentInput!"
]
}
@@ -7624,7 +7638,7 @@ export default {
25,
{
"input": [
- 405,
+ 406,
"UpdateAgentInput!"
]
}
@@ -7633,7 +7647,7 @@ export default {
25,
{
"input": [
- 336,
+ 337,
"AgentIdInput!"
]
}
@@ -7642,7 +7656,7 @@ export default {
52,
{
"input": [
- 406,
+ 407,
"CreateOneObjectInput!"
]
}
@@ -7651,7 +7665,7 @@ export default {
52,
{
"input": [
- 408,
+ 409,
"DeleteOneObjectInput!"
]
}
@@ -7660,7 +7674,7 @@ export default {
52,
{
"input": [
- 409,
+ 410,
"UpdateOneObjectInput!"
]
}
@@ -7669,7 +7683,7 @@ export default {
45,
{
"input": [
- 411,
+ 412,
"CreateOneIndexInput!"
]
}
@@ -7678,7 +7692,7 @@ export default {
45,
{
"input": [
- 414,
+ 415,
"DeleteOneIndexInput!"
]
}
@@ -7687,7 +7701,7 @@ export default {
41,
{
"input": [
- 337,
+ 338,
"LogicFunctionIdInput!"
]
}
@@ -7696,7 +7710,7 @@ export default {
41,
{
"input": [
- 415,
+ 416,
"CreateLogicFunctionFromSourceInput!"
]
}
@@ -7705,7 +7719,7 @@ export default {
165,
{
"input": [
- 416,
+ 417,
"ExecuteOneLogicFunctionInput!"
]
}
@@ -7714,7 +7728,7 @@ export default {
6,
{
"input": [
- 417,
+ 418,
"UpdateLogicFunctionFromSourceInput!"
]
}
@@ -7723,7 +7737,7 @@ export default {
35,
{
"input": [
- 419,
+ 420,
"CreateCommandMenuItemInput!"
]
}
@@ -7732,7 +7746,7 @@ export default {
35,
{
"input": [
- 420,
+ 421,
"UpdateCommandMenuItemInput!"
]
}
@@ -7759,7 +7773,7 @@ export default {
34,
{
"input": [
- 421,
+ 422,
"CreateFrontComponentInput!"
]
}
@@ -7768,7 +7782,7 @@ export default {
34,
{
"input": [
- 422,
+ 423,
"UpdateFrontComponentInput!"
]
}
@@ -7786,7 +7800,7 @@ export default {
72,
{
"data": [
- 424,
+ 425,
"ActivateWorkspaceInput!"
]
}
@@ -7795,7 +7809,7 @@ export default {
72,
{
"data": [
- 425,
+ 426,
"UpdateWorkspaceInput!"
]
}
@@ -7810,7 +7824,7 @@ export default {
43,
{
"input": [
- 426,
+ 427,
"CreateOneFieldMetadataInput!"
]
}
@@ -7819,7 +7833,7 @@ export default {
43,
{
"input": [
- 428,
+ 429,
"UpdateOneFieldMetadataInput!"
]
}
@@ -7828,7 +7842,7 @@ export default {
43,
{
"input": [
- 430,
+ 431,
"DeleteOneFieldInput!"
]
}
@@ -7837,7 +7851,7 @@ export default {
62,
{
"input": [
- 431,
+ 432,
"CreateViewGroupInput!"
]
}
@@ -7846,7 +7860,7 @@ export default {
62,
{
"inputs": [
- 431,
+ 432,
"[CreateViewGroupInput!]!"
]
}
@@ -7855,7 +7869,7 @@ export default {
62,
{
"input": [
- 432,
+ 433,
"UpdateViewGroupInput!"
]
}
@@ -7864,7 +7878,7 @@ export default {
62,
{
"inputs": [
- 432,
+ 433,
"[UpdateViewGroupInput!]!"
]
}
@@ -7873,7 +7887,7 @@ export default {
62,
{
"input": [
- 434,
+ 435,
"DeleteViewGroupInput!"
]
}
@@ -7882,7 +7896,7 @@ export default {
62,
{
"input": [
- 435,
+ 436,
"DestroyViewGroupInput!"
]
}
@@ -7891,7 +7905,7 @@ export default {
6,
{
"workspaceMigration": [
- 436,
+ 437,
"WorkspaceMigrationInput!"
]
}
@@ -7922,7 +7936,7 @@ export default {
29,
{
"createRoleInput": [
- 439,
+ 440,
"CreateRoleInput!"
]
}
@@ -7931,7 +7945,7 @@ export default {
29,
{
"updateRoleInput": [
- 440,
+ 441,
"UpdateRoleInput!"
]
}
@@ -7949,7 +7963,7 @@ export default {
16,
{
"upsertObjectPermissionsInput": [
- 442,
+ 443,
"UpsertObjectPermissionsInput!"
]
}
@@ -7958,7 +7972,7 @@ export default {
27,
{
"upsertPermissionFlagsInput": [
- 444,
+ 445,
"UpsertPermissionFlagsInput!"
]
}
@@ -7967,7 +7981,7 @@ export default {
26,
{
"upsertFieldPermissionsInput": [
- 445,
+ 446,
"UpsertFieldPermissionsInput!"
]
}
@@ -7976,7 +7990,7 @@ export default {
230,
{
"input": [
- 447,
+ 448,
"UpsertRowLevelPermissionPredicatesInput!"
]
}
@@ -8007,7 +8021,7 @@ export default {
196,
{
"input": [
- 450,
+ 451,
"CreateApplicationRegistrationInput!"
]
}
@@ -8016,7 +8030,7 @@ export default {
7,
{
"input": [
- 451,
+ 452,
"UpdateApplicationRegistrationInput!"
]
}
@@ -8043,7 +8057,7 @@ export default {
5,
{
"input": [
- 453,
+ 454,
"CreateApplicationRegistrationVariableInput!"
]
}
@@ -8052,7 +8066,7 @@ export default {
5,
{
"input": [
- 454,
+ 455,
"UpdateApplicationRegistrationVariableInput!"
]
}
@@ -8070,7 +8084,7 @@ export default {
7,
{
"file": [
- 355,
+ 356,
"Upload!"
],
"universalIdentifier": [
@@ -8095,7 +8109,7 @@ export default {
280,
{
"input": [
- 456,
+ 457,
"SendEmailViaDomainInput!"
]
}
@@ -8104,7 +8118,7 @@ export default {
282,
{
"input": [
- 457,
+ 458,
"SendMessageCampaignInput!"
]
}
@@ -8113,7 +8127,7 @@ export default {
283,
{
"input": [
- 458,
+ 459,
"CreateUnsubscribeTopicInput!"
]
}
@@ -8122,7 +8136,7 @@ export default {
283,
{
"input": [
- 459,
+ 460,
"UpdateUnsubscribeTopicInput!"
]
}
@@ -8140,7 +8154,7 @@ export default {
270,
{
"input": [
- 460,
+ 461,
"UpdateMessageChannelInput!"
]
}
@@ -8149,7 +8163,7 @@ export default {
278,
{
"input": [
- 462,
+ 463,
"CreateEmailGroupChannelInput!"
]
}
@@ -8167,7 +8181,7 @@ export default {
268,
{
"input": [
- 463,
+ 464,
"CreateEmailingDomainInput!"
]
}
@@ -8203,7 +8217,7 @@ export default {
295,
{
"input": [
- 464,
+ 465,
"RunAgentInput!"
]
}
@@ -8212,7 +8226,7 @@ export default {
292,
{
"input": [
- 465,
+ 466,
"CreateWebhookInput!"
]
}
@@ -8221,7 +8235,7 @@ export default {
292,
{
"input": [
- 466,
+ 467,
"UpdateWebhookInput!"
]
}
@@ -8236,28 +8250,28 @@ export default {
}
],
"updateMessageFolder": [
- 327,
+ 328,
{
"input": [
- 468,
+ 469,
"UpdateMessageFolderInput!"
]
}
],
"updateMessageFolders": [
- 327,
+ 328,
{
"input": [
- 470,
+ 471,
"UpdateMessageFoldersInput!"
]
}
],
"updateCalendarChannel": [
- 322,
+ 323,
{
"input": [
- 471,
+ 472,
"UpdateCalendarChannelInput!"
]
}
@@ -8266,7 +8280,7 @@ export default {
313
],
"sendChatMessage": [
- 317,
+ 318,
{
"threadId": [
3,
@@ -8287,11 +8301,23 @@ export default {
1
],
"fileAttachments": [
- 473,
+ 474,
"[FileAttachmentInput!]"
]
}
],
+ "retryChatMessage": [
+ 318,
+ {
+ "threadId": [
+ 3,
+ "UUID!"
+ ],
+ "modelId": [
+ 1
+ ]
+ }
+ ],
"stopAgentChatStream": [
6,
{
@@ -8354,7 +8380,7 @@ export default {
311,
{
"input": [
- 474,
+ 475,
"CreateSkillInput!"
]
}
@@ -8363,7 +8389,7 @@ export default {
311,
{
"input": [
- 475,
+ 476,
"UpdateSkillInput!"
]
}
@@ -8396,7 +8422,7 @@ export default {
}
],
"evaluateAgentTurn": [
- 319,
+ 320,
{
"turnId": [
3,
@@ -8405,7 +8431,7 @@ export default {
}
],
"runEvaluationInput": [
- 320,
+ 321,
{
"agentId": [
3,
@@ -8421,7 +8447,7 @@ export default {
243,
{
"input": [
- 476,
+ 477,
"GetAuthorizationUrlForSSOInput!"
]
}
@@ -8587,7 +8613,7 @@ export default {
246,
{
"input": [
- 477
+ 478
]
}
],
@@ -8599,7 +8625,7 @@ export default {
"String!"
],
"file": [
- 355,
+ 356,
"Upload!"
]
}
@@ -8742,7 +8768,7 @@ export default {
6,
{
"input": [
- 478,
+ 479,
"UpdateWorkspaceMemberSettingsInput!"
]
}
@@ -8776,7 +8802,7 @@ export default {
221,
{
"input": [
- 479,
+ 480,
"SetupOIDCSsoInput!"
]
}
@@ -8785,7 +8811,7 @@ export default {
221,
{
"input": [
- 480,
+ 481,
"SetupSAMLSsoInput!"
]
}
@@ -8794,7 +8820,7 @@ export default {
217,
{
"input": [
- 481,
+ 482,
"DeleteSsoInput!"
]
}
@@ -8803,7 +8829,7 @@ export default {
218,
{
"input": [
- 482,
+ 483,
"EditSsoInput!"
]
}
@@ -8832,7 +8858,7 @@ export default {
307,
{
"type": [
- 483,
+ 484,
"AnalyticsType!"
],
"name": [
@@ -8872,7 +8898,7 @@ export default {
297,
{
"input": [
- 484,
+ 485,
"CreateCalendarEventInput!"
]
}
@@ -8881,7 +8907,7 @@ export default {
306,
{
"input": [
- 485,
+ 486,
"SendEmailInput!"
]
}
@@ -8903,7 +8929,7 @@ export default {
"String!"
],
"connectionParameters": [
- 487,
+ 488,
"EmailAccountConnectionParameters!"
],
"id": [
@@ -8915,7 +8941,7 @@ export default {
167,
{
"input": [
- 489,
+ 490,
"UpdateLabPublicFeatureFlagInput!"
]
}
@@ -8955,7 +8981,7 @@ export default {
74,
{
"input": [
- 490,
+ 491,
"CreateOneAppTokenInput!"
]
}
@@ -9025,7 +9051,7 @@ export default {
263,
{
"file": [
- 355,
+ 356,
"Upload!"
],
"applicationUniversalIdentifier": [
@@ -9033,7 +9059,7 @@ export default {
"String!"
],
"fileFolder": [
- 492,
+ 493,
"FileFolder!"
],
"filePath": [
@@ -9142,7 +9168,7 @@ export default {
3
],
"update": [
- 354
+ 355
],
"__typename": [
1
@@ -9252,7 +9278,7 @@ export default {
3
],
"update": [
- 360
+ 361
],
"__typename": [
1
@@ -9417,16 +9443,16 @@ export default {
3
],
"viewFields": [
- 366
+ 367
],
"viewFilters": [
- 367
+ 368
],
"viewFilterGroups": [
- 368
+ 369
],
"viewSorts": [
- 369
+ 370
],
"__typename": [
1
@@ -9537,7 +9563,7 @@ export default {
3
],
"update": [
- 372
+ 373
],
"__typename": [
1
@@ -9575,7 +9601,7 @@ export default {
3
],
"update": [
- 376
+ 377
],
"__typename": [
1
@@ -9651,7 +9677,7 @@ export default {
3
],
"update": [
- 381
+ 382
],
"__typename": [
1
@@ -9715,10 +9741,10 @@ export default {
3
],
"groups": [
- 386
+ 387
],
"fields": [
- 387
+ 388
],
"__typename": [
1
@@ -9738,7 +9764,7 @@ export default {
6
],
"fields": [
- 387
+ 388
],
"__typename": [
1
@@ -9906,7 +9932,7 @@ export default {
3
],
"tabs": [
- 399
+ 400
],
"__typename": [
1
@@ -9929,7 +9955,7 @@ export default {
85
],
"widgets": [
- 400
+ 401
],
"__typename": [
1
@@ -9952,7 +9978,7 @@ export default {
3
],
"gridPosition": [
- 401
+ 402
],
"position": [
15
@@ -10001,7 +10027,7 @@ export default {
3
],
"gridPosition": [
- 401
+ 402
],
"position": [
15
@@ -10027,7 +10053,7 @@ export default {
3
],
"gridPosition": [
- 401
+ 402
],
"position": [
15
@@ -10120,7 +10146,7 @@ export default {
},
"CreateOneObjectInput": {
"object": [
- 407
+ 408
],
"__typename": [
1
@@ -10180,7 +10206,7 @@ export default {
},
"UpdateOneObjectInput": {
"update": [
- 410
+ 411
],
"id": [
3
@@ -10235,7 +10261,7 @@ export default {
},
"CreateOneIndexInput": {
"index": [
- 412
+ 413
],
"__typename": [
1
@@ -10246,7 +10272,7 @@ export default {
3
],
"fields": [
- 413
+ 414
],
"indexType": [
46
@@ -10331,7 +10357,7 @@ export default {
3
],
"update": [
- 418
+ 419
],
"__typename": [
1
@@ -10491,7 +10517,7 @@ export default {
3
],
"update": [
- 423
+ 424
],
"__typename": [
1
@@ -10595,7 +10621,7 @@ export default {
},
"CreateOneFieldMetadataInput": {
"field": [
- 427
+ 428
],
"__typename": [
1
@@ -10668,7 +10694,7 @@ export default {
3
],
"update": [
- 429
+ 430
],
"__typename": [
1
@@ -10763,7 +10789,7 @@ export default {
3
],
"update": [
- 433
+ 434
],
"__typename": [
1
@@ -10804,7 +10830,7 @@ export default {
},
"WorkspaceMigrationInput": {
"actions": [
- 437
+ 438
],
"__typename": [
1
@@ -10812,10 +10838,10 @@ export default {
},
"WorkspaceMigrationDeleteActionInput": {
"type": [
- 438
+ 439
],
"metadataName": [
- 330
+ 331
],
"universalIdentifier": [
1
@@ -10871,7 +10897,7 @@ export default {
},
"UpdateRoleInput": {
"update": [
- 441
+ 442
],
"id": [
3
@@ -10926,7 +10952,7 @@ export default {
3
],
"objectPermissions": [
- 443
+ 444
],
"__typename": [
1
@@ -10968,7 +10994,7 @@ export default {
3
],
"fieldPermissions": [
- 446
+ 447
],
"__typename": [
1
@@ -10999,10 +11025,10 @@ export default {
3
],
"predicates": [
- 448
+ 449
],
"predicateGroups": [
- 449
+ 450
],
"__typename": [
1
@@ -11082,7 +11108,7 @@ export default {
1
],
"update": [
- 452
+ 453
],
"__typename": [
1
@@ -11133,7 +11159,7 @@ export default {
1
],
"update": [
- 455
+ 456
],
"__typename": [
1
@@ -11241,7 +11267,7 @@ export default {
3
],
"update": [
- 461
+ 462
],
"__typename": [
1
@@ -11325,7 +11351,7 @@ export default {
3
],
"update": [
- 467
+ 468
],
"__typename": [
1
@@ -11353,7 +11379,7 @@ export default {
3
],
"update": [
- 469
+ 470
],
"__typename": [
1
@@ -11372,7 +11398,7 @@ export default {
3
],
"update": [
- 469
+ 470
],
"__typename": [
1
@@ -11383,7 +11409,7 @@ export default {
3
],
"update": [
- 472
+ 473
],
"__typename": [
1
@@ -11391,13 +11417,13 @@ export default {
},
"UpdateCalendarChannelInputUpdates": {
"visibility": [
- 325
+ 326
],
"isContactAutoCreationEnabled": [
6
],
"contactAutoCreationPolicy": [
- 326
+ 327
],
"isSyncEnabled": [
6
@@ -11623,7 +11649,7 @@ export default {
1
],
"files": [
- 486
+ 487
],
"__typename": [
1
@@ -11642,13 +11668,13 @@ export default {
},
"EmailAccountConnectionParameters": {
"IMAP": [
- 488
+ 489
],
"SMTP": [
- 488
+ 489
],
"CALDAV": [
- 488
+ 489
],
"__typename": [
1
@@ -11687,7 +11713,7 @@ export default {
},
"CreateOneAppTokenInput": {
"appToken": [
- 491
+ 492
],
"__typename": [
1
@@ -11716,13 +11742,13 @@ export default {
231,
{
"input": [
- 494,
+ 495,
"LogicFunctionLogsInput!"
]
}
],
"onAgentChatEvent": [
- 318,
+ 319,
{
"threadId": [
3,
@@ -11734,7 +11760,7 @@ export default {
308,
{
"table": [
- 341,
+ 342,
"EventLogTable!"
]
}
diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts
index b7f30c58a3a..2a870825e2b 100644
--- a/packages/twenty-front/src/generated-metadata/graphql.ts
+++ b/packages/twenty-front/src/generated-metadata/graphql.ts
@@ -862,9 +862,16 @@ export enum ChartNumberFormat {
export type ChatStreamCatchupChunks = {
__typename?: 'ChatStreamCatchupChunks';
chunks: Array<Scalars['JSON']['output']>;
+ error?: Maybe<ChatStreamError>;
maxSeq: Scalars['Int']['output'];
};
+export type ChatStreamError = {
+ __typename?: 'ChatStreamError';
+ code: Scalars['String']['output'];
+ message: Scalars['String']['output'];
+};
+
export type CheckUserExist = {
__typename?: 'CheckUserExist';
availableWorkspacesCount: Scalars['Float']['output'];
@@ -2577,6 +2584,7 @@ export type Mutation = {
resetPageLayoutTabToDefault: PageLayoutTab;
resetPageLayoutToDefault: PageLayout;
resetPageLayoutWidgetToDefault: PageLayoutWidget;
+ retryChatMessage: SendChatMessageResult;
revokeApiKey?: Maybe<ApiKey>;
rotateApplicationRegistrationClientSecret: RotateClientSecret;
runAgent: RunAgentResult;
@@ -3300,6 +3308,12 @@ export type MutationResetPageLayoutWidgetToDefaultArgs = {
};
+export type MutationRetryChatMessageArgs = {
+ modelId?: InputMaybe<Scalars['String']['input']>;
+ threadId: Scalars['UUID']['input'];
+};
+
+
export type MutationRevokeApiKeyArgs = {
input: RevokeApiKeyInput;
};
@@ -6450,6 +6464,14 @@ export type RenameChatThreadMutationVariables = Exact<{
export type RenameChatThreadMutation = { __typename?: 'Mutation', renameChatThread: { __typename?: 'AgentChatThread', id: string, title?: string | null, updatedAt: string } };
+export type RetryChatMessageMutationVariables = Exact<{
+ threadId: Scalars['UUID']['input'];
+ modelId?: InputMaybe<Scalars['String']['input']>;
+}>;
+
+
+export type RetryChatMessageMutation = { __typename?: 'Mutation', retryChatMessage: { __typename?: 'SendChatMessageResult', messageId: string, queued: boolean, streamId?: string | null } };
+
export type RunEvaluationInputMutationVariables = Exact<{
agentId: Scalars['UUID']['input'];
input: Scalars['String']['input'];
@@ -6546,7 +6568,7 @@ export type GetChatMessagesQueryVariables = Exact<{
}>;
-export type GetChatMessagesQuery = { __typename?: 'Query', chatMessages: Array<{ __typename?: 'AgentMessage', id: string, threadId: string, turnId?: string | null, role: string, status: string, createdAt: string, parts: Array<{ __typename?: 'AgentMessagePart', id: string, messageId: string, orderIndex: number, type: string, textContent?: string | null, reasoningContent?: string | null, toolName?: string | null, toolCallId?: string | null, toolInput?: any | null, toolOutput?: any | null, state?: string | null, providerExecuted?: boolean | null, errorMessage?: string | null, errorDetails?: any | null, sourceUrlSourceId?: string | null, sourceUrlUrl?: string | null, sourceUrlTitle?: string | null, sourceDocumentSourceId?: string | null, sourceDocumentMediaType?: string | null, sourceDocumentTitle?: string | null, sourceDocumentFilename?: string | null, fileMediaType?: string | null, fileFilename?: string | null, fileUrl?: string | null, fileId?: string | null, providerMetadata?: any | null, createdAt: string }> }>, chatStreamCatchupChunks: { __typename?: 'ChatStreamCatchupChunks', chunks: Array<any>, maxSeq: number } };
+export type GetChatMessagesQuery = { __typename?: 'Query', chatMessages: Array<{ __typename?: 'AgentMessage', id: string, threadId: string, turnId?: string | null, role: string, status: string, createdAt: string, parts: Array<{ __typename?: 'AgentMessagePart', id: string, messageId: string, orderIndex: number, type: string, textContent?: string | null, reasoningContent?: string | null, toolName?: string | null, toolCallId?: string | null, toolInput?: any | null, toolOutput?: any | null, state?: string | null, providerExecuted?: boolean | null, errorMessage?: string | null, errorDetails?: any | null, sourceUrlSourceId?: string | null, sourceUrlUrl?: string | null, sourceUrlTitle?: string | null, sourceDocumentSourceId?: string | null, sourceDocumentMediaType?: string | null, sourceDocumentTitle?: string | null, sourceDocumentFilename?: string | null, fileMediaType?: string | null, fileFilename?: string | null, fileUrl?: string | null, fileId?: string | null, providerMetadata?: any | null, createdAt: string }> }>, chatStreamCatchupChunks: { __typename?: 'ChatStreamCatchupChunks', chunks: Array<any>, maxSeq: number, error?: { __typename?: 'ChatStreamError', code: string, message: string } | null } };
export type GetChatThreadsQueryVariables = Exact<{ [key: string]: never; }>;
@@ -8702,6 +8724,7 @@ export const DeleteSkillDocument = {"kind":"Document","definitions":[{"kind":"Op
export const EvaluateAgentTurnDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"EvaluateAgentTurn"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"turnId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"evaluateAgentTurn"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"turnId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"turnId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"turnId"}},{"kind":"Field","name":{"kind":"Name","value":"score"}},{"kind":"Field","name":{"kind":"Name","value":"comment"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}}]}}]}}]} as unknown as DocumentNode<EvaluateAgentTurnMutation, EvaluateAgentTurnMutationVariables>;
export const RemoveRoleFromAgentDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"RemoveRoleFromAgent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"removeRoleFromAgent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"agentId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}}}]}]}}]} as unknown as DocumentNode<RemoveRoleFromAgentMutation, RemoveRoleFromAgentMutationVariables>;
export const RenameChatThreadDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"RenameChatThread"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"title"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"renameChatThread"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}},{"kind":"Argument","name":{"kind":"Name","value":"title"},"value":{"kind":"Variable","name":{"kind":"Name","value":"title"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]}}]} as unknown as DocumentNode<RenameChatThreadMutation, RenameChatThreadMutationVariables>;
+export const RetryChatMessageDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"RetryChatMessage"},"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":"modelId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"retryChatMessage"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}},{"kind":"Argument","name":{"kind":"Name","value":"modelId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"modelId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"messageId"}},{"kind":"Field","name":{"kind":"Name","value":"queued"}},{"kind":"Field","name":{"kind":"Name","value":"streamId"}}]}}]}}]} as unknown as DocumentNode<RetryChatMessageMutation, RetryChatMessageMutationVariables>;
export const RunEvaluationInputDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"RunEvaluationInput"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}},"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":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"runEvaluationInput"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"agentId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}}},{"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"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"agentId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"evaluations"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"score"}},{"kind":"Field","name":{"kind":"Name","value":"comment"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}}]}}]}}]}}]} as unknown as DocumentNode<RunEvaluationInputMutation, RunEvaluationInputMutationVariables>;
export const SendChatMessageDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"SendChatMessage"},"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":"text"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"messageId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"browsingContext"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"JSON"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"modelId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"fileAttachments"}},"type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"FileAttachmentInput"}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"sendChatMessage"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}},{"kind":"Argument","name":{"kind":"Name","value":"text"},"value":{"kind":"Variable","name":{"kind":"Name","value":"text"}}},{"kind":"Argument","name":{"kind":"Name","value":"messageId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"messageId"}}},{"kind":"Argument","name":{"kind":"Name","value":"browsingContext"},"value":{"kind":"Variable","name":{"kind":"Name","value":"browsingContext"}}},{"kind":"Argument","name":{"kind":"Name","value":"modelId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"modelId"}}},{"kind":"Argument","name":{"kind":"Name","value":"fileAttachments"},"value":{"kind":"Variable","name":{"kind":"Name","value":"fileAttachments"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"messageId"}},{"kind":"Field","name":{"kind":"Name","value":"queued"}},{"kind":"Field","name":{"kind":"Name","value":"streamId"}}]}}]}}]} as unknown as DocumentNode<SendChatMessageMutation, SendChatMessageMutationVariables>;
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>;
@@ -8715,7 +8738,7 @@ export const FindOneAgentDocument = {"kind":"Document","definitions":[{"kind":"O
export const FindOneSkillDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindOneSkill"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"skill"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}],"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":"isCustom"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode<FindOneSkillQuery, FindOneSkillQueryVariables>;
export const FindWorkspaceAiStatsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"FindWorkspaceAiStats"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"findWorkspaceAiStats"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"conversationsCount"}},{"kind":"Field","name":{"kind":"Name","value":"skillsCount"}},{"kind":"Field","name":{"kind":"Name","value":"toolsCount"}}]}}]}}]} as unknown as DocumentNode<FindWorkspaceAiStatsQuery, FindWorkspaceAiStatsQueryVariables>;
export const GetAgentTurnsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetAgentTurns"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UUID"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"agentTurns"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"agentId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"agentId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"agentId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"evaluations"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"score"}},{"kind":"Field","name":{"kind":"Name","value":"comment"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}}]}},{"kind":"Field","name":{"kind":"Name","value":"messages"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"parts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"textContent"}},{"kind":"Field","name":{"kind":"Name","value":"reasoningContent"}},{"kind":"Field","name":{"kind":"Name","value":"toolName"}},{"kind":"Field","name":{"kind":"Name","value":"toolCallId"}},{"kind":"Field","name":{"kind":"Name","value":"toolInput"}},{"kind":"Field","name":{"kind":"Name","value":"toolOutput"}},{"kind":"Field","name":{"kind":"Name","value":"errorMessage"}},{"kind":"Field","name":{"kind":"Name","value":"state"}},{"kind":"Field","name":{"kind":"Name","value":"providerExecuted"}},{"kind":"Field","name":{"kind":"Name","value":"errorDetails"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlUrl"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"fileFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileUrl"}},{"kind":"Field","name":{"kind":"Name","value":"providerMetadata"}}]}}]}}]}}]}}]} as unknown as DocumentNode<GetAgentTurnsQuery, GetAgentTurnsQueryVariables>;
-export const GetChatMessagesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetChatMessages"},"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":"chatMessages"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"turnId"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"parts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"messageId"}},{"kind":"Field","name":{"kind":"Name","value":"orderIndex"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"textContent"}},{"kind":"Field","name":{"kind":"Name","value":"reasoningContent"}},{"kind":"Field","name":{"kind":"Name","value":"toolName"}},{"kind":"Field","name":{"kind":"Name","value":"toolCallId"}},{"kind":"Field","name":{"kind":"Name","value":"toolInput"}},{"kind":"Field","name":{"kind":"Name","value":"toolOutput"}},{"kind":"Field","name":{"kind":"Name","value":"state"}},{"kind":"Field","name":{"kind":"Name","value":"providerExecuted"}},{"kind":"Field","name":{"kind":"Name","value":"errorMessage"}},{"kind":"Field","name":{"kind":"Name","value":"errorDetails"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlUrl"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"fileFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileUrl"}},{"kind":"Field","name":{"kind":"Name","value":"fileId"}},{"kind":"Field","name":{"kind":"Name","value":"providerMetadata"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"chatStreamCatchupChunks"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chunks"}},{"kind":"Field","name":{"kind":"Name","value":"maxSeq"}}]}}]}}]} as unknown as DocumentNode<GetChatMessagesQuery, GetChatMessagesQueryVariables>;
+export const GetChatMessagesDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetChatMessages"},"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":"chatMessages"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"threadId"}},{"kind":"Field","name":{"kind":"Name","value":"turnId"}},{"kind":"Field","name":{"kind":"Name","value":"role"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"parts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"messageId"}},{"kind":"Field","name":{"kind":"Name","value":"orderIndex"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"textContent"}},{"kind":"Field","name":{"kind":"Name","value":"reasoningContent"}},{"kind":"Field","name":{"kind":"Name","value":"toolName"}},{"kind":"Field","name":{"kind":"Name","value":"toolCallId"}},{"kind":"Field","name":{"kind":"Name","value":"toolInput"}},{"kind":"Field","name":{"kind":"Name","value":"toolOutput"}},{"kind":"Field","name":{"kind":"Name","value":"state"}},{"kind":"Field","name":{"kind":"Name","value":"providerExecuted"}},{"kind":"Field","name":{"kind":"Name","value":"errorMessage"}},{"kind":"Field","name":{"kind":"Name","value":"errorDetails"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlUrl"}},{"kind":"Field","name":{"kind":"Name","value":"sourceUrlTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentSourceId"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentTitle"}},{"kind":"Field","name":{"kind":"Name","value":"sourceDocumentFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileMediaType"}},{"kind":"Field","name":{"kind":"Name","value":"fileFilename"}},{"kind":"Field","name":{"kind":"Name","value":"fileUrl"}},{"kind":"Field","name":{"kind":"Name","value":"fileId"}},{"kind":"Field","name":{"kind":"Name","value":"providerMetadata"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"chatStreamCatchupChunks"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"threadId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"threadId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chunks"}},{"kind":"Field","name":{"kind":"Name","value":"maxSeq"}},{"kind":"Field","name":{"kind":"Name","value":"error"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"code"}},{"kind":"Field","name":{"kind":"Name","value":"message"}}]}}]}}]}}]} as unknown as DocumentNode<GetChatMessagesQuery, GetChatMessagesQueryVariables>;
export const GetChatThreadsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetChatThreads"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"chatThreads"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"totalInputTokens"}},{"kind":"Field","name":{"kind":"Name","value":"totalOutputTokens"}},{"kind":"Field","name":{"kind":"Name","value":"contextWindowTokens"}},{"kind":"Field","name":{"kind":"Name","value":"conversationSize"}},{"kind":"Field","name":{"kind":"Name","value":"totalInputCredits"}},{"kind":"Field","name":{"kind":"Name","value":"totalOutputCredits"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"lastMessageAt"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]}}]} as unknown as DocumentNode<GetChatThreadsQuery, GetChatThreadsQueryVariables>;
export const GetToolIndexDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetToolIndex"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"getToolIndex"},"selectionSet":{"kind":"SelectionSet","selections":[{"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":"category"}},{"kind":"Field","name":{"kind":"Name","value":"objectName"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}}]}}]}}]} as unknown as DocumentNode<GetToolIndexQuery, GetToolIndexQueryVariables>;
export const GetToolInputSchemaDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetToolInputSchema"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"toolName"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"getToolInputSchema"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"toolName"},"value":{"kind":"Variable","name":{"kind":"Name","value":"toolName"}}}]}]}}]} as unknown as DocumentNode<GetToolInputSchemaQuery, GetToolInputSchemaQueryVariables>;
diff --git a/packages/twenty-front/src/modules/ai/components/AgentChatMessagesFetchEffect.tsx b/packages/twenty-front/src/modules/ai/components/AgentChatMessagesFetchEffect.tsx
index a21fa8351de..a622d5bbdc0 100644
--- a/packages/twenty-front/src/modules/ai/components/AgentChatMessagesFetchEffect.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AgentChatMessagesFetchEffect.tsx
@@ -14,6 +14,7 @@ import { agentChatQueuedMessagesComponentFamilyState } from '@/ai/states/agentCh
import { currentAiChatThreadState } from '@/ai/states/currentAiChatThreadState';
import { skipMessagesSkeletonUntilLoadedState } from '@/ai/states/skipMessagesSkeletonUntilLoadedState';
import { mapDBMessagesToUIMessages } from '@/ai/utils/mapDBMessagesToUIMessages';
+import { SSE_CLIENT_RECONNECTED_EVENT_NAME } from '@/sse-db-event/constants/SseClientReconnectedEventName';
import { useQueryWithCallbacks } from '@/apollo/hooks/useQueryWithCallbacks';
import { useListenToBrowserEvent } from '@/browser-event/hooks/useListenToBrowserEvent';
import { useAtomComponentFamilyStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentFamilyStateCallbackState';
@@ -87,7 +88,7 @@ export const AgentChatMessagesFetchEffect = () => {
const catchup = data.chatStreamCatchupChunks;
- if (!isDefined(catchup) || catchup.chunks.length === 0) {
+ if (!isDefined(catchup)) {
return;
}
@@ -122,6 +123,15 @@ export const AgentChatMessagesFetchEffect = () => {
seq: chunkSeq,
} as AgentChatSubscriptionEvent);
}
+
+ // Never replay a persisted error into an active live stream.
+ if (isDefined(catchup.error) && firstLiveSeq === null) {
+ handleEvent({
+ type: 'stream-error',
+ code: catchup.error.code,
+ message: catchup.error.message,
+ } as AgentChatSubscriptionEvent);
+ }
},
[
setAgentChatFetchedMessages,
@@ -168,5 +178,11 @@ export const AgentChatMessagesFetchEffect = () => {
onBrowserEvent: handleRefetchMessages,
});
+ // Replay events missed while the SSE connection was down.
+ useListenToBrowserEvent({
+ eventName: SSE_CLIENT_RECONNECTED_EVENT_NAME,
+ onBrowserEvent: handleRefetchMessages,
+ });
+
return null;
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatErrorMessage.tsx b/packages/twenty-front/src/modules/ai/components/AiChatErrorMessage.tsx
index 8304eb9428d..a9d54dc868f 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatErrorMessage.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatErrorMessage.tsx
@@ -1,8 +1,10 @@
import { CombinedGraphQLErrors } from '@apollo/client/errors';
import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
-import { IconAlertCircle } from 'twenty-ui/icon';
+import { IconAlertCircle, IconRefresh } from 'twenty-ui/icon';
+import { Button } from 'twenty-ui/input';
import { useContext } from 'react';
+import { isDefined } from 'twenty-shared/utils';
import { type AiChatError } from '@/ai/types/AiChatError';
import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';
@@ -45,9 +47,13 @@ const StyledErrorMessage = styled.div`
type AiChatErrorMessageProps = {
error: AiChatError;
+ onRetry?: () => void;
};
-export const AiChatErrorMessage = ({ error }: AiChatErrorMessageProps) => {
+export const AiChatErrorMessage = ({
+ error,
+ onRetry,
+}: AiChatErrorMessageProps) => {
const { theme } = useContext(ThemeContext);
const errorMessage = CombinedGraphQLErrors.is(error)
? getErrorMessageFromApolloError(error)
@@ -64,6 +70,15 @@ export const AiChatErrorMessage = ({ error }: AiChatErrorMessageProps) => {
{errorMessage || t`An error occurred while processing your message`}
</StyledErrorMessage>
</StyledErrorContent>
+ {isDefined(onRetry) && (
+ <Button
+ variant="secondary"
+ size="small"
+ Icon={IconRefresh}
+ onClick={onRetry}
+ title={t`Retry`}
+ />
+ )}
</StyledErrorContainer>
);
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatErrorRenderer.tsx b/packages/twenty-front/src/modules/ai/components/AiChatErrorRenderer.tsx
index cf3a6b01a1c..c5f43eb96c8 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatErrorRenderer.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatErrorRenderer.tsx
@@ -6,9 +6,13 @@ import { isGraphqlErrorOfType } from '~/utils/is-graphql-error-of-type.util';
type AiChatErrorRendererProps = {
error: AiChatError;
+ onRetry?: () => void;
};
-export const AiChatErrorRenderer = ({ error }: AiChatErrorRendererProps) => {
+export const AiChatErrorRenderer = ({
+ error,
+ onRetry,
+}: AiChatErrorRendererProps) => {
if (isGraphqlErrorOfType(error, AiChatErrorCode.BILLING_CREDITS_EXHAUSTED)) {
//Handle by AIChatNoMoreBillingCreditsBanner
return null;
@@ -18,5 +22,5 @@ export const AiChatErrorRenderer = ({ error }: AiChatErrorRendererProps) => {
return <AiChatApiKeyNotConfiguredMessage />;
}
- return <AiChatErrorMessage error={error} />;
+ return <AiChatErrorMessage error={error} onRetry={onRetry} />;
};
diff --git a/packages/twenty-front/src/modules/ai/components/AiChatErrorUnderMessageList.tsx b/packages/twenty-front/src/modules/ai/components/AiChatErrorUnderMessageList.tsx
index 6bc7eae80f7..5fd7061d4bd 100644
--- a/packages/twenty-front/src/modules/ai/components/AiChatErrorUnderMessageList.tsx
+++ b/packages/twenty-front/src/modules/ai/components/AiChatErrorUnderMessageList.tsx
@@ -1,5 +1,6 @@
import { AiChatErrorRenderer } from '@/ai/components/AiChatErrorRenderer';
import { AgentMessageRole } from '@/ai/constants/AgentMessageRole';
+import { useRetryChatMessage } from '@/ai/hooks/useRetryChatMessage';
import { agentChatDisplayedThreadState } from '@/ai/states/agentChatDisplayedThreadState';
import { agentChatErrorComponentFamilyState } from '@/ai/states/agentChatErrorComponentFamilyState';
import { agentChatIsStreamingComponentFamilyState } from '@/ai/states/agentChatIsStreamingComponentFamilyState';
@@ -17,6 +18,7 @@ const StyledErrorWrapper = styled.div`
`;
export const AiChatErrorUnderMessageList = () => {
+ const { retryChatMessage } = useRetryChatMessage();
const agentChatDisplayedThread = useAtomStateValue(
agentChatDisplayedThreadState,
);
@@ -50,7 +52,7 @@ export const AiChatErrorUnderMessageList = () => {
return (
<StyledErrorWrapper>
- <AiChatErrorRenderer error={agentChatError} />
+ <AiChatErrorRenderer error={agentChatError} onRetry={retryChatMessage} />
</StyledErrorWrapper>
);
};
diff --git a/packages/twenty-front/src/modules/ai/graphql/mutations/retryChatMessage.ts b/packages/twenty-front/src/modules/ai/graphql/mutations/retryChatMessage.ts
new file mode 100644
index 00000000000..47692c4af11
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/graphql/mutations/retryChatMessage.ts
@@ -0,0 +1,11 @@
+import { gql } from '@apollo/client';
+
+export const RETRY_CHAT_MESSAGE = gql`
+ mutation RetryChatMessage($threadId: UUID!, $modelId: String) {
+ retryChatMessage(threadId: $threadId, modelId: $modelId) {
+ messageId
+ queued
+ streamId
+ }
+ }
+`;
diff --git a/packages/twenty-front/src/modules/ai/graphql/queries/getChatMessages.ts b/packages/twenty-front/src/modules/ai/graphql/queries/getChatMessages.ts
index f3b58464ffe..13e15d20fd3 100644
--- a/packages/twenty-front/src/modules/ai/graphql/queries/getChatMessages.ts
+++ b/packages/twenty-front/src/modules/ai/graphql/queries/getChatMessages.ts
@@ -42,6 +42,10 @@ export const GET_CHAT_MESSAGES = gql`
chatStreamCatchupChunks(threadId: $threadId) {
chunks
maxSeq
+ error {
+ code
+ message
+ }
}
}
`;
diff --git a/packages/twenty-front/src/modules/ai/hooks/useRetryChatMessage.ts b/packages/twenty-front/src/modules/ai/hooks/useRetryChatMessage.ts
new file mode 100644
index 00000000000..37c50da8067
--- /dev/null
+++ b/packages/twenty-front/src/modules/ai/hooks/useRetryChatMessage.ts
@@ -0,0 +1,53 @@
+import { useApolloClient } from '@apollo/client/react';
+import { useStore } from 'jotai';
+import { useCallback } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+
+import { AGENT_CHAT_INSTANCE_ID } from '@/ai/constants/AgentChatInstanceId';
+import { AGENT_CHAT_REFETCH_MESSAGES_EVENT_NAME } from '@/ai/constants/AgentChatRefetchMessagesEventName';
+import { RETRY_CHAT_MESSAGE } from '@/ai/graphql/mutations/retryChatMessage';
+import { useAgentChatModelId } from '@/ai/hooks/useAgentChatModelId';
+import { agentChatDisplayedThreadState } from '@/ai/states/agentChatDisplayedThreadState';
+import { agentChatErrorComponentFamilyState } from '@/ai/states/agentChatErrorComponentFamilyState';
+import { dispatchBrowserEvent } from '@/browser-event/utils/dispatchBrowserEvent';
+
+export const useRetryChatMessage = () => {
+ const apolloClient = useApolloClient();
+ const store = useStore();
+ const { modelIdForRequest } = useAgentChatModelId();
+
+ const retryChatMessage = useCallback(async () => {
+ const threadId = store.get(agentChatDisplayedThreadState.atom);
+
+ if (!isDefined(threadId)) {
+ return;
+ }
+
+ const errorAtom = agentChatErrorComponentFamilyState.atomFamily({
+ instanceId: AGENT_CHAT_INSTANCE_ID,
+ familyKey: { threadId },
+ });
+ const previousError = store.get(errorAtom);
+
+ store.set(errorAtom, null);
+
+ try {
+ await apolloClient.mutate({
+ mutation: RETRY_CHAT_MESSAGE,
+ variables: {
+ threadId,
+ modelId: modelIdForRequest ?? undefined,
+ },
+ });
+
+ dispatchBrowserEvent(AGENT_CHAT_REFETCH_MESSAGES_EVENT_NAME);
+ } catch (retryError) {
+ store.set(
+ errorAtom,
+ retryError instanceof Error ? retryError : previousError,
+ );
+ }
+ }, [apolloClient, store, modelIdForRequest]);
+
+ return { retryChatMessage };
+};
diff --git a/packages/twenty-server/jest.config.mjs b/packages/twenty-server/jest.config.mjs
index 1a5079a0609..9657ee5bd53 100644
--- a/packages/twenty-server/jest.config.mjs
+++ b/packages/twenty-server/jest.config.mjs
@@ -18,9 +18,10 @@ const jestConfig = {
setupFilesAfterEnv: ['./setupTests.ts'],
transformIgnorePatterns: [
// jsdom 29 pulls ESM-only transitive deps (parse5, entities, tough-cookie,
- // @exodus/bytes via html-encoding-sniffer, @csstools/@asamuzakjp css engine).
+ // @exodus/bytes via html-encoding-sniffer, @csstools/@asamuzakjp css engine),
+ // and e2b/@e2b pull ESM-only chalk.
// jest's CJS runtime can't load their `export` syntax, so let swc transform them.
- '/node_modules/(?!(file-type|@file-type|strtok3|token-types|@borewit|@tokenizer|uint8array-extras|read-next-line|digest-fetch|md5|js-sha256|js-sha512|base-64|charenc|crypt|email-reply-parser|jsdom|html-encoding-sniffer|whatwg-encoding|@exodus|parse5|entities|tough-cookie|@csstools|@asamuzakjp|graphql-upload|fs-capacitor)/)',
+ '/node_modules/(?!(file-type|@file-type|strtok3|token-types|@borewit|@tokenizer|uint8array-extras|read-next-line|digest-fetch|md5|js-sha256|js-sha512|base-64|charenc|crypt|email-reply-parser|jsdom|html-encoding-sniffer|whatwg-encoding|@exodus|parse5|entities|tough-cookie|@csstools|@asamuzakjp|graphql-upload|fs-capacitor|e2b|@e2b|chalk)/)',
],
testRegex: '.*\\.spec\\.ts$',
transform: {
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-19/2-19-instance-command-fast-1821000000000-add-last-stream-error-to-agent-chat-thread.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-19/2-19-instance-command-fast-1821000000000-add-last-stream-error-to-agent-chat-thread.ts
new file mode 100644
index 00000000000..dde3259f973
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-19/2-19-instance-command-fast-1821000000000-add-last-stream-error-to-agent-chat-thread.ts
@@ -0,0 +1,21 @@
+import { QueryRunner } from 'typeorm';
+
+import { RegisteredInstanceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-instance-command.decorator';
+import { FastInstanceCommand } from 'src/engine/core-modules/upgrade/interfaces/fast-instance-command.interface';
+
+@RegisteredInstanceCommand('2.19.0', 1821000000000)
+export class AddLastStreamErrorToAgentChatThreadFastInstanceCommand
+ implements FastInstanceCommand
+{
+ public async up(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(
+ `ALTER TABLE "core"."agentChatThread" ADD COLUMN IF NOT EXISTS "lastStreamError" jsonb`,
+ );
+ }
+
+ public async down(queryRunner: QueryRunner): Promise<void> {
+ await queryRunner.query(
+ `ALTER TABLE "core"."agentChatThread" DROP COLUMN IF EXISTS "lastStreamError"`,
+ );
+ }
+}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-19/__tests__/add-last-stream-error-to-agent-chat-thread.instance-command.spec.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-19/__tests__/add-last-stream-error-to-agent-chat-thread.instance-command.spec.ts
new file mode 100644
index 00000000000..53b8ac4600a
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-19/__tests__/add-last-stream-error-to-agent-chat-thread.instance-command.spec.ts
@@ -0,0 +1,37 @@
+import { type QueryRunner } from 'typeorm';
+
+import { AddLastStreamErrorToAgentChatThreadFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-19/2-19-instance-command-fast-1821000000000-add-last-stream-error-to-agent-chat-thread';
+
+describe('AddLastStreamErrorToAgentChatThreadFastInstanceCommand', () => {
+ let command: AddLastStreamErrorToAgentChatThreadFastInstanceCommand;
+
+ beforeEach(() => {
+ command = new AddLastStreamErrorToAgentChatThreadFastInstanceCommand();
+ });
+
+ describe('up', () => {
+ it('adds the lastStreamError column without mutating data', async () => {
+ const query = jest.fn().mockResolvedValue(undefined);
+ const queryRunner = { query } as unknown as QueryRunner;
+
+ await command.up(queryRunner);
+
+ expect(query.mock.calls.map((call) => call[0] as string)).toEqual([
+ 'ALTER TABLE "core"."agentChatThread" ADD COLUMN IF NOT EXISTS "lastStreamError" jsonb',
+ ]);
+ });
+ });
+
+ describe('down', () => {
+ it('drops the lastStreamError column', async () => {
+ const query = jest.fn().mockResolvedValue(undefined);
+ const queryRunner = { query } as unknown as QueryRunner;
+
+ await command.down(queryRunner);
+
+ expect(query.mock.calls.map((call) => call[0] as string)).toEqual([
+ 'ALTER TABLE "core"."agentChatThread" DROP COLUMN IF EXISTS "lastStreamError"',
+ ]);
+ });
+ });
+});
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-19/add-last-stream-error-to-agent-chat-thread-upgrade-command-name.constant.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-19/add-last-stream-error-to-agent-chat-thread-upgrade-command-name.constant.ts
new file mode 100644
index 00000000000..cc879cab166
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-19/add-last-stream-error-to-agent-chat-thread-upgrade-command-name.constant.ts
@@ -0,0 +1,4 @@
+// Referenced by @WasIntroducedInUpgrade on the "lastStreamError" column so
+// pre-2.19 upgrade steps don't SELECT it before this command adds it.
+export const ADD_LAST_STREAM_ERROR_TO_AGENT_CHAT_THREAD_UPGRADE_COMMAND_NAME =
+ '2.19.0_AddLastStreamErrorToAgentChatThreadFastInstanceCommand_1821000000000';
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts
index a2ca66bd31a..e0e8845143b 100644
--- a/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/instance-commands.constant.ts
@@ -42,6 +42,7 @@ import { CreateApplicationTranslationCoreTableFastInstanceCommand } from 'src/da
import { AddTsVectorFieldMetadataIdToSearchFieldMetadataFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-18/2-18-instance-command-fast-1810000001000-add-ts-vector-field-metadata-id-to-search-field-metadata';
import { BackfillTsVectorFieldMetadataIdOnSearchFieldMetadataSlowInstanceCommand } from 'src/database/commands/upgrade-version-command/2-18/2-18-instance-command-slow-1810000003000-backfill-ts-vector-field-metadata-id-on-search-field-metadata';
import { AddMetadataOverridesColumnFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-19/2-19-instance-command-fast-1820000100000-add-metadata-overrides-column';
+import { AddLastStreamErrorToAgentChatThreadFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-19/2-19-instance-command-fast-1821000000000-add-last-stream-error-to-agent-chat-thread';
import { BackfillMetadataOverridesSlowInstanceCommand } from 'src/database/commands/upgrade-version-command/2-19/2-19-instance-command-slow-1820000110000-backfill-metadata-overrides';
import { AddCacheTokensToAgentChatThreadFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-2/2-2-instance-command-fast-1777455269302-add-cache-tokens-to-agent-chat-thread';
import { AddLogoToApplicationFastInstanceCommand } from 'src/database/commands/upgrade-version-command/2-2/2-2-instance-command-fast-1777539664664-add-logo-to-application';
@@ -175,5 +176,6 @@ export const INSTANCE_COMMANDS = [
BackfillTsVectorFieldMetadataIdOnSearchFieldMetadataSlowInstanceCommand,
AddMetadataOverridesColumnFastInstanceCommand,
BackfillMetadataOverridesSlowInstanceCommand,
+ AddLastStreamErrorToAgentChatThreadFastInstanceCommand,
DropMetadataStandardOverridesColumnFastInstanceCommand,
];
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/chat-stream-catchup-chunks.dto.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/chat-stream-catchup-chunks.dto.ts
index 9ffed4c37d3..ab9c99d43a2 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/chat-stream-catchup-chunks.dto.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/chat-stream-catchup-chunks.dto.ts
@@ -2,6 +2,8 @@ import { Field, Int, ObjectType } from '@nestjs/graphql';
import GraphQLJSON from 'graphql-type-json';
+import { ChatStreamErrorDTO } from 'src/engine/metadata-modules/ai/ai-chat/dtos/chat-stream-error.dto';
+
@ObjectType('ChatStreamCatchupChunks')
export class ChatStreamCatchupChunksDTO {
@Field(() => [GraphQLJSON])
@@ -9,4 +11,7 @@ export class ChatStreamCatchupChunksDTO {
@Field(() => Int)
maxSeq: number;
+
+ @Field(() => ChatStreamErrorDTO, { nullable: true })
+ error: ChatStreamErrorDTO | null;
}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/chat-stream-error.dto.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/chat-stream-error.dto.ts
new file mode 100644
index 00000000000..73f8eb6f364
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/dtos/chat-stream-error.dto.ts
@@ -0,0 +1,10 @@
+import { Field, ObjectType } from '@nestjs/graphql';
+
+@ObjectType('ChatStreamError')
+export class ChatStreamErrorDTO {
+ @Field(() => String)
+ code: string;
+
+ @Field(() => String)
+ message: string;
+}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/entities/agent-chat-thread.entity.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/entities/agent-chat-thread.entity.ts
index 4f174d6a55a..b638e4e8270 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/entities/agent-chat-thread.entity.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/entities/agent-chat-thread.entity.ts
@@ -10,9 +10,12 @@ import {
UpdateDateColumn,
} from 'typeorm';
+import { ADD_LAST_STREAM_ERROR_TO_AGENT_CHAT_THREAD_UPGRADE_COMMAND_NAME } from 'src/database/commands/upgrade-version-command/2-19/add-last-stream-error-to-agent-chat-thread-upgrade-command-name.constant';
+import { WasIntroducedInUpgrade } from 'src/engine/core-modules/upgrade/decorators/was-introduced-in-upgrade.decorator';
import { UserWorkspaceEntity } from 'src/engine/core-modules/user-workspace/user-workspace.entity';
import { AgentMessageEntity } from 'src/engine/metadata-modules/ai/ai-agent-execution/entities/agent-message.entity';
import { AgentTurnEntity } from 'src/engine/metadata-modules/ai/ai-agent-execution/entities/agent-turn.entity';
+import { type AgentChatThreadLastStreamError } from 'src/engine/metadata-modules/ai/ai-chat/types/agent-chat-thread-last-stream-error.type';
import type { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
import { EntityRelation } from 'src/engine/workspace-manager/workspace-migration/types/entity-relation.interface';
@@ -70,6 +73,13 @@ export class AgentChatThreadEntity {
@Column({ type: 'varchar', nullable: true })
activeStreamId: string | null;
+ @WasIntroducedInUpgrade({
+ upgradeCommandName:
+ ADD_LAST_STREAM_ERROR_TO_AGENT_CHAT_THREAD_UPGRADE_COMMAND_NAME,
+ })
+ @Column({ type: 'jsonb', nullable: true })
+ lastStreamError: AgentChatThreadLastStreamError | null;
+
@OneToMany(() => AgentTurnEntity, (turn) => turn.thread)
turns: EntityRelation<AgentTurnEntity[]>;
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/jobs/stream-agent-chat.job.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/jobs/stream-agent-chat.job.ts
index 15d52a6e63d..0707e13ab23 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/jobs/stream-agent-chat.job.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/jobs/stream-agent-chat.job.ts
@@ -28,6 +28,7 @@ import { AgentChatStreamingService } from 'src/engine/metadata-modules/ai/ai-cha
import { AgentChatService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat.service';
import { ChatExecutionService } from 'src/engine/metadata-modules/ai/ai-chat/services/chat-execution.service';
import { getCancelChannel } from 'src/engine/metadata-modules/ai/ai-chat/utils/get-cancel-channel.util';
+import { mapErrorToStreamError } from 'src/engine/metadata-modules/ai/ai-chat/utils/map-error-to-stream-error.util';
import type { AiModelConfig } from 'src/engine/metadata-modules/ai/ai-models/types/ai-model-config.type';
import { InjectWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/inject-workspace-scoped-repository.decorator';
import { WorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/workspace-scoped-repository';
@@ -55,6 +56,8 @@ export class StreamAgentChatJob {
@Process(STREAM_AGENT_CHAT_JOB_NAME)
async handle(data: StreamAgentChatJobData): Promise<void> {
+ await this.eventPublisherService.resetStreamState(data.threadId);
+
const workspace = await this.workspaceRepository.findOne({
where: { id: data.workspaceId },
});
@@ -87,17 +90,33 @@ export class StreamAgentChatJob {
this.logger.error(
`Stream ${data.streamId} failed: ${error instanceof Error ? error.message : String(error)}`,
);
+ const streamError = mapErrorToStreamError(error);
+
+ await this.threadRepository
+ .update(
+ data.workspaceId,
+ { id: data.threadId },
+ {
+ lastStreamError: {
+ ...streamError,
+ failedAt: new Date().toISOString(),
+ },
+ },
+ )
+ .catch((persistError) => {
+ this.logger.error(
+ `Failed to persist stream error for thread ${data.threadId}: ${persistError instanceof Error ? persistError.message : String(persistError)}`,
+ );
+ });
+
await this.eventPublisherService
.publish({
threadId: data.threadId,
workspaceId: data.workspaceId,
event: {
type: 'stream-error',
- code: 'STREAM_EXECUTION_FAILED',
- message:
- error instanceof Error
- ? error.message
- : 'Stream execution failed',
+ code: streamError.code,
+ message: streamError.message,
},
})
.catch(() => {});
@@ -197,6 +216,7 @@ export class StreamAgentChatJob {
let lastStepConversationSize = 0;
let totalCacheCreationTokens = 0;
let streamError: unknown;
+ let streamFinishError: unknown;
let checkHasNoMoreAvailableCredits: () => boolean = () => false;
// onFinish fires before the uiStream is fully drained. We use this
@@ -282,6 +302,7 @@ export class StreamAgentChatJob {
});
},
onFinish: async ({ responseMessage, isAborted }) => {
+ // Rejecting here would race chunks still draining.
try {
await this.handleStreamFinish({
assistantMessageId,
@@ -299,15 +320,23 @@ export class StreamAgentChatJob {
userMessagePromise,
});
await titleWritePromise;
- resolveStreamFinished();
} catch (error) {
- reject(error);
+ streamFinishError = error;
+ } finally {
+ resolveStreamFinished();
}
},
sendReasoning: true,
}),
);
},
+ // Errors thrown before the model stream merges never reach onFinish.
+ onError: (error) => {
+ streamError = error;
+ resolveStreamFinished();
+
+ return error instanceof Error ? error.message : String(error);
+ },
});
// Publish all chunks first, then signal completion. This guarantees
@@ -315,6 +344,10 @@ export class StreamAgentChatJob {
void (async () => {
try {
for await (const chunk of uiStream) {
+ if ((chunk as { type?: string }).type === 'error') {
+ continue;
+ }
+
await this.eventPublisherService.publish({
threadId: data.threadId,
workspaceId: data.workspaceId,
@@ -329,6 +362,8 @@ export class StreamAgentChatJob {
if (streamError) {
reject(streamError);
+ } else if (streamFinishError) {
+ reject(streamFinishError);
} else if (checkHasNoMoreAvailableCredits()) {
await this.eventPublisherService.publish({
threadId: data.threadId,
@@ -545,6 +580,7 @@ export class StreamAgentChatJob {
`"totalCacheCreationTokens" + ${totalCacheCreationTokens}`,
contextWindowTokens: modelConfig.contextWindowTokens,
conversationSize: lastStepConversationSize,
+ lastStreamError: null,
},
);
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/resolvers/agent-chat.resolver.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/resolvers/agent-chat.resolver.ts
index 74029003219..c04700139ee 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/resolvers/agent-chat.resolver.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/resolvers/agent-chat.resolver.ts
@@ -102,13 +102,25 @@ export class AgentChatResolver {
@AuthUserWorkspaceId() userWorkspaceId: string,
@AuthWorkspace() { id: workspaceId }: WorkspaceEntity,
) {
- await this.agentChatService.getThreadById({
+ const thread = await this.agentChatService.getThreadById({
threadId,
userWorkspaceId,
workspaceId,
});
- return this.eventPublisherService.getAccumulatedChunks(threadId);
+ const { chunks, maxSeq } =
+ await this.eventPublisherService.getAccumulatedChunks(threadId);
+
+ return {
+ chunks,
+ maxSeq,
+ error: thread.lastStreamError
+ ? {
+ code: thread.lastStreamError.code,
+ message: thread.lastStreamError.message,
+ }
+ : null,
+ };
}
@Mutation(() => AgentChatThreadDTO)
@@ -211,6 +223,42 @@ export class AgentChatResolver {
};
}
+ @Mutation(() => SendChatMessageResultDTO)
+ async retryChatMessage(
+ @Args('threadId', { type: () => UUIDScalarType }) threadId: string,
+ @Args('modelId', { type: () => String, nullable: true })
+ modelId: string | undefined,
+ @AuthUserWorkspaceId() userWorkspaceId: string,
+ @AuthWorkspace() workspace: WorkspaceEntity,
+ ): Promise<SendChatMessageResultDTO> {
+ if (this.aiModelRegistryService.getAvailableModels().length === 0) {
+ throw new AiException(
+ 'No AI models are available. Configure at least one AI provider.',
+ AiExceptionCode.API_KEY_NOT_CONFIGURED,
+ );
+ }
+
+ this.aiModelRegistryService.validateModelAvailability(
+ modelId ?? workspace.smartModel,
+ workspace,
+ );
+
+ await this.billingUsageService.hasAvailableCreditsOrThrow(workspace.id);
+
+ const result = await this.agentChatStreamingService.retryLastFailedTurn({
+ threadId,
+ userWorkspaceId,
+ workspace,
+ modelId,
+ });
+
+ return {
+ messageId: result.messageId,
+ queued: false,
+ streamId: result.streamId,
+ };
+ }
+
@Mutation(() => Boolean)
async stopAgentChatStream(
@Args('threadId', { type: () => UUIDScalarType }) threadId: string,
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/__tests__/agent-chat-streaming.service.retry.spec.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/__tests__/agent-chat-streaming.service.retry.spec.ts
new file mode 100644
index 00000000000..794f454fb1f
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/__tests__/agent-chat-streaming.service.retry.spec.ts
@@ -0,0 +1,142 @@
+import { type WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
+import {
+ AgentMessageRole,
+ AgentMessageStatus,
+ type AgentMessageEntity,
+} from 'src/engine/metadata-modules/ai/ai-agent-execution/entities/agent-message.entity';
+import { type AgentChatThreadEntity } from 'src/engine/metadata-modules/ai/ai-chat/entities/agent-chat-thread.entity';
+import { AgentChatStreamingService } from 'src/engine/metadata-modules/ai/ai-chat/services/agent-chat-streaming.service';
+import { AiExceptionCode } from 'src/engine/metadata-modules/ai/ai.exception';
+
+describe('AgentChatStreamingService.retryLastFailedTurn', () => {
+ const workspace = { id: 'workspace-id' } as WorkspaceEntity;
+
+ const failedThread = {
+ id: 'thread-id',
+ title: 'Thread title',
+ conversationSize: 42,
+ activeStreamId: null,
+ lastStreamError: {
+ code: 'STREAM_EXECUTION_FAILED',
+ message: 'Provider timed out',
+ failedAt: '2026-01-01T00:00:00.000Z',
+ },
+ } as unknown as AgentChatThreadEntity;
+
+ const userMessageEntity = {
+ id: 'user-message-id',
+ role: AgentMessageRole.USER,
+ status: AgentMessageStatus.SENT,
+ parts: [{ type: 'text', textContent: 'hello', orderIndex: 0 }],
+ createdAt: new Date('2026-01-01T00:00:00.000Z'),
+ } as unknown as AgentMessageEntity;
+
+ const buildService = ({
+ thread = failedThread,
+ lastUserMessage = { id: 'user-message-id', turnId: 'turn-id' },
+ threadMessages = [userMessageEntity],
+ } = {}) => {
+ const threadRepository = {
+ findOne: jest.fn().mockResolvedValue(thread),
+ update: jest.fn().mockResolvedValue(undefined),
+ };
+ const messageQueueService = { add: jest.fn().mockResolvedValue(undefined) };
+ const agentChatService = {
+ findLatestSentUserMessage: jest.fn().mockResolvedValue(lastUserMessage),
+ deleteAssistantMessagesForTurn: jest.fn().mockResolvedValue(undefined),
+ getMessagesForThread: jest.fn().mockResolvedValue(threadMessages),
+ };
+
+ const service = new AgentChatStreamingService(
+ threadRepository as never,
+ { find: jest.fn() } as never,
+ messageQueueService as never,
+ agentChatService as never,
+ { publish: jest.fn() } as never,
+ { signFileByIdUrl: jest.fn() } as never,
+ );
+
+ return { service, threadRepository, messageQueueService, agentChatService };
+ };
+
+ const retryArguments = {
+ threadId: 'thread-id',
+ userWorkspaceId: 'user-workspace-id',
+ workspace,
+ };
+
+ it('rejects when the thread has no persisted stream error', async () => {
+ const { service, messageQueueService } = buildService({
+ thread: { ...failedThread, lastStreamError: null },
+ });
+
+ await expect(
+ service.retryLastFailedTurn(retryArguments),
+ ).rejects.toMatchObject({
+ code: AiExceptionCode.NO_FAILED_TURN_TO_RETRY,
+ });
+ expect(messageQueueService.add).not.toHaveBeenCalled();
+ });
+
+ it('rejects when a stream is already active', async () => {
+ const { service, messageQueueService } = buildService({
+ thread: { ...failedThread, activeStreamId: 'stream-id' },
+ });
+
+ await expect(
+ service.retryLastFailedTurn(retryArguments),
+ ).rejects.toMatchObject({
+ code: AiExceptionCode.NO_FAILED_TURN_TO_RETRY,
+ });
+ expect(messageQueueService.add).not.toHaveBeenCalled();
+ });
+
+ it('rejects without clearing state when a newer message exists', async () => {
+ const newerAssistantMessage = {
+ ...userMessageEntity,
+ id: 'newer-message-id',
+ role: AgentMessageRole.ASSISTANT,
+ } as unknown as AgentMessageEntity;
+ const { service, threadRepository } = buildService({
+ threadMessages: [userMessageEntity, newerAssistantMessage],
+ });
+
+ await expect(
+ service.retryLastFailedTurn(retryArguments),
+ ).rejects.toMatchObject({
+ code: AiExceptionCode.NO_FAILED_TURN_TO_RETRY,
+ });
+ expect(threadRepository.update).not.toHaveBeenCalled();
+ });
+
+ it('drops the failed output, re-enqueues the turn, and clears the error', async () => {
+ const { service, threadRepository, messageQueueService, agentChatService } =
+ buildService();
+
+ const result = await service.retryLastFailedTurn({
+ ...retryArguments,
+ modelId: 'model-id',
+ });
+
+ expect(
+ agentChatService.deleteAssistantMessagesForTurn,
+ ).toHaveBeenCalledWith({ turnId: 'turn-id', workspaceId: 'workspace-id' });
+ expect(messageQueueService.add).toHaveBeenCalledWith(
+ expect.any(String),
+ expect.objectContaining({
+ threadId: 'thread-id',
+ existingTurnId: 'turn-id',
+ lastUserMessageText: 'hello',
+ modelId: 'model-id',
+ hasTitle: true,
+ conversationSizeTokens: 42,
+ }),
+ );
+ expect(threadRepository.update).toHaveBeenCalledWith(
+ 'workspace-id',
+ { id: 'thread-id' },
+ { activeStreamId: result.streamId, lastStreamError: null },
+ );
+ expect(result.messageId).toBe('user-message-id');
+ });
+});
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-event-publisher.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-event-publisher.service.ts
index c7b40780fd9..a6661879754 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-event-publisher.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat-event-publisher.service.ts
@@ -55,6 +55,12 @@ export class AgentChatEventPublisherService {
});
}
+ async resetStreamState(threadId: string): Promise<void> {
+ const redis = this.redisClientService.getClient();
+
+ await redis.del(this.getStreamChunksKey(threadId));
+ }
+
async getAccumulatedChunks(threadId: string): Promise<{
chunks: Record<string, unknown>[];
maxSeq: number;
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 8c8f5483484..dabfeb9a72a 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
@@ -7,6 +7,7 @@ import {
isExtendedFileUIPart,
} from 'twenty-shared/ai';
import { FileFolder } from 'twenty-shared/types';
+import { isDefined } from 'twenty-shared/utils';
import { In, Like } from 'typeorm';
import { FileEntity } from 'src/engine/core-modules/file/entities/file.entity';
@@ -139,12 +140,108 @@ export class AgentChatStreamingService {
await this.threadRepository.update(
workspace.id,
{ id: thread.id },
- { activeStreamId: streamId },
+ { activeStreamId: streamId, lastStreamError: null },
);
return { streamId, messageId: savedUserMessage.id };
}
+ async retryLastFailedTurn({
+ threadId,
+ userWorkspaceId,
+ workspace,
+ modelId,
+ }: {
+ threadId: string;
+ userWorkspaceId: string;
+ workspace: WorkspaceEntity;
+ modelId?: string;
+ }): Promise<{ streamId: string; messageId: string }> {
+ const thread = await this.threadRepository.findOne(workspace.id, {
+ where: { id: threadId, userWorkspaceId },
+ });
+
+ if (!thread) {
+ throw new AiException(
+ 'Thread not found',
+ AiExceptionCode.THREAD_NOT_FOUND,
+ );
+ }
+
+ if (
+ !isDefined(thread.lastStreamError) ||
+ isDefined(thread.activeStreamId)
+ ) {
+ throw new AiException(
+ 'There is no failed turn to retry on this thread',
+ AiExceptionCode.NO_FAILED_TURN_TO_RETRY,
+ );
+ }
+
+ const lastUserMessage =
+ await this.agentChatService.findLatestSentUserMessage({
+ threadId,
+ workspaceId: workspace.id,
+ });
+
+ if (!isDefined(lastUserMessage) || !isDefined(lastUserMessage.turnId)) {
+ throw new AiException(
+ 'There is no failed turn to retry on this thread',
+ AiExceptionCode.NO_FAILED_TURN_TO_RETRY,
+ );
+ }
+
+ await this.agentChatService.deleteAssistantMessagesForTurn({
+ turnId: lastUserMessage.turnId,
+ workspaceId: workspace.id,
+ });
+
+ const messages = await this.loadMessagesFromDB(
+ threadId,
+ userWorkspaceId,
+ workspace.id,
+ );
+
+ const retriedMessage = messages[messages.length - 1];
+
+ if (!retriedMessage || retriedMessage.id !== lastUserMessage.id) {
+ throw new AiException(
+ 'There is no failed turn to retry on this thread',
+ AiExceptionCode.NO_FAILED_TURN_TO_RETRY,
+ );
+ }
+
+ const textPart = retriedMessage.parts.find((part) => part.type === 'text');
+
+ const streamId = generateId();
+
+ await this.messageQueueService.add<StreamAgentChatJobData>(
+ STREAM_AGENT_CHAT_JOB_NAME,
+ {
+ threadId,
+ streamId,
+ userWorkspaceId,
+ workspaceId: workspace.id,
+ messages,
+ browsingContext: null,
+ modelId,
+ lastUserMessageText: textPart?.text ?? '',
+ lastUserMessageParts: retriedMessage.parts,
+ hasTitle: !!thread.title,
+ conversationSizeTokens: thread.conversationSize,
+ existingTurnId: lastUserMessage.turnId,
+ },
+ );
+
+ await this.threadRepository.update(
+ workspace.id,
+ { id: threadId },
+ { activeStreamId: streamId, lastStreamError: null },
+ );
+
+ return { streamId, messageId: lastUserMessage.id };
+ }
+
async flushNextQueuedMessage(
threadId: string,
userWorkspaceId: string,
@@ -252,7 +349,7 @@ export class AgentChatStreamingService {
await this.threadRepository.update(
workspaceId,
{ id: threadId },
- { activeStreamId: streamId },
+ { activeStreamId: streamId, lastStreamError: null },
);
}
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat.service.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat.service.ts
index 634cc83ae14..19f76c9e85a 100644
--- a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat.service.ts
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/services/agent-chat.service.ts
@@ -260,6 +260,37 @@ export class AgentChatService {
} as AgentMessageEntity;
}
+ async findLatestSentUserMessage({
+ threadId,
+ workspaceId,
+ }: {
+ threadId: string;
+ workspaceId: string;
+ }): Promise<Pick<AgentMessageEntity, 'id' | 'turnId'> | null> {
+ return this.messageRepository.findOne(workspaceId, {
+ where: {
+ threadId,
+ role: AgentMessageRole.USER,
+ status: AgentMessageStatus.SENT,
+ },
+ order: { createdAt: 'DESC', id: 'DESC' },
+ select: ['id', 'turnId'],
+ });
+ }
+
+ async deleteAssistantMessagesForTurn({
+ turnId,
+ workspaceId,
+ }: {
+ turnId: string;
+ workspaceId: string;
+ }): Promise<void> {
+ await this.messageRepository.delete(workspaceId, {
+ turnId,
+ role: AgentMessageRole.ASSISTANT,
+ });
+ }
+
async hasAssistantMessageForTurn({
turnId,
workspaceId,
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/types/agent-chat-thread-last-stream-error.type.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/types/agent-chat-thread-last-stream-error.type.ts
new file mode 100644
index 00000000000..75fc614334d
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/types/agent-chat-thread-last-stream-error.type.ts
@@ -0,0 +1,5 @@
+import { type StreamErrorPayload } from 'src/engine/metadata-modules/ai/ai-chat/utils/map-error-to-stream-error.util';
+
+export type AgentChatThreadLastStreamError = StreamErrorPayload & {
+ failedAt: string;
+};
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/__tests__/map-error-to-stream-error.util.spec.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/__tests__/map-error-to-stream-error.util.spec.ts
new file mode 100644
index 00000000000..5f01b800d7c
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/__tests__/map-error-to-stream-error.util.spec.ts
@@ -0,0 +1,49 @@
+import {
+ AiException,
+ AiExceptionCode,
+} from 'src/engine/metadata-modules/ai/ai.exception';
+import {
+ STREAM_EXECUTION_FAILED_CODE,
+ mapErrorToStreamError,
+} from 'src/engine/metadata-modules/ai/ai-chat/utils/map-error-to-stream-error.util';
+
+describe('mapErrorToStreamError', () => {
+ it('maps an AiException to its typed code and message', () => {
+ const error = new AiException(
+ 'No AI models are available. Configure at least one AI provider.',
+ AiExceptionCode.API_KEY_NOT_CONFIGURED,
+ );
+
+ expect(mapErrorToStreamError(error)).toEqual({
+ code: AiExceptionCode.API_KEY_NOT_CONFIGURED,
+ message:
+ 'No AI models are available. Configure at least one AI provider.',
+ });
+ });
+
+ it('collapses a generic Error to the fallback code but keeps its message', () => {
+ expect(mapErrorToStreamError(new Error('Provider timed out'))).toEqual({
+ code: STREAM_EXECUTION_FAILED_CODE,
+ message: 'Provider timed out',
+ });
+ });
+
+ it('handles non-Error values with a stable fallback', () => {
+ expect(mapErrorToStreamError('boom')).toEqual({
+ code: STREAM_EXECUTION_FAILED_CODE,
+ message: 'Stream execution failed',
+ });
+ });
+
+ it('truncates oversized provider messages before they are persisted', () => {
+ const result = mapErrorToStreamError(new Error('x'.repeat(10_000)));
+
+ expect(result.code).toBe(STREAM_EXECUTION_FAILED_CODE);
+ expect(result.message.length).toBe(2001);
+ expect(result.message.endsWith('…')).toBe(true);
+ });
+
+ it('leaves short messages untouched', () => {
+ expect(mapErrorToStreamError(new Error('short')).message).toBe('short');
+ });
+});
diff --git a/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/map-error-to-stream-error.util.ts b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/map-error-to-stream-error.util.ts
new file mode 100644
index 00000000000..c214cc09c8a
--- /dev/null
+++ b/packages/twenty-server/src/engine/metadata-modules/ai/ai-chat/utils/map-error-to-stream-error.util.ts
@@ -0,0 +1,28 @@
+import { AiException } from 'src/engine/metadata-modules/ai/ai.exception';
+
+export const STREAM_EXECUTION_FAILED_CODE = 'STREAM_EXECUTION_FAILED';
+
+const STREAM_ERROR_MESSAGE_MAX_LENGTH = 2000;
+
+export type StreamErrorPayload = {
+ code: string;
+ message: string;
+};
+
+const truncateMessage = (message: string): string =>
+ message.length > STREAM_ERROR_MESSAGE_MAX_LENGTH
+ ? `${message.slice(0, STREAM_ERROR_MESSAGE_MAX_LENGTH)}…`
+ : message;
+
+export const mapErrorToStreamError = (error: unknown): StreamErrorPayload => {
+ if (error instanceof AiException) {
+ return { code: error.code, message: truncateMessage(error.message) };
+ }
+
+ return {
+ code: STREAM_EXECUTION_FAILED_CODE,
+ message: truncateMessage(
+ error instanceof Error ? error.message : 'Stream execution failed',
+ ),
+ };
+};
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 d84b3149e6c..28f001b784c 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
@@ -17,6 +17,7 @@ export enum AiExceptionCode {
USER_WORKSPACE_ID_NOT_FOUND = 'USER_WORKSPACE_ID_NOT_FOUND',
ROLE_NOT_FOUND = 'ROLE_NOT_FOUND',
ROLE_CANNOT_BE_ASSIGNED_TO_AGENTS = 'ROLE_CANNOT_BE_ASSIGNED_TO_AGENTS',
+ NO_FAILED_TURN_TO_RETRY = 'NO_FAILED_TURN_TO_RETRY',
}
const getAiExceptionUserFriendlyMessage = (code: AiExceptionCode) => {
@@ -45,6 +46,8 @@ const getAiExceptionUserFriendlyMessage = (code: AiExceptionCode) => {
return msg`Role not found.`;
case AiExceptionCode.ROLE_CANNOT_BE_ASSIGNED_TO_AGENTS:
return msg`This role cannot be assigned to agents.`;
+ case AiExceptionCode.NO_FAILED_TURN_TO_RETRY:
+ return msg`There is no failed message to retry.`;
default:
assertUnreachable(code);
}
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 1d42ec28d08..5243dd64049 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
@@ -30,6 +30,7 @@ export const aiGraphqlApiExceptionHandler = (error: Error) => {
case AiExceptionCode.INVALID_CHAT_THREAD_TITLE:
throw new UserInputError(error);
case AiExceptionCode.AGENT_ALREADY_EXISTS:
+ case AiExceptionCode.NO_FAILED_TURN_TO_RETRY:
throw new ConflictError(error);
case AiExceptionCode.AGENT_IS_STANDARD:
case AiExceptionCode.ROLE_CANNOT_BE_ASSIGNED_TO_AGENTS: