From 92438dc3c45fe4a851ef1f686cc7854b0f7cba55 Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Mon, 9 Mar 2026 17:25:38 +0100 Subject: [PATCH 1/2] Refactor Signed-off-by: Milen Pivchev --- .../Assistant/Chat/NCAssistantChatModel.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/iOSClient/Assistant/Chat/NCAssistantChatModel.swift b/iOSClient/Assistant/Chat/NCAssistantChatModel.swift index 06bf1c6330..0bee7ea50b 100644 --- a/iOSClient/Assistant/Chat/NCAssistantChatModel.swift +++ b/iOSClient/Assistant/Chat/NCAssistantChatModel.swift @@ -63,15 +63,15 @@ class NCAssistantChatModel { showRetryResponseGenerationButton = false currentSession = nil - await loadAllMessages() - currentSession = await checkChatSession(sessionId: selectedConversation.id) - chatMessageTaskId = currentSession?.messageTaskId + await loadAllMessages() + currentSession = await checkChatSession(sessionId: selectedConversation.id) + chatMessageTaskId = currentSession?.messageTaskId - if messages.last?.isFromHuman == true, chatMessageTaskId == nil, isSending == false { - showRetryResponseGenerationButton = true - } else if chatMessageTaskId != nil { - startPollingForResponse() - } + if messages.last?.isFromHuman == true, chatMessageTaskId == nil, isSending == false { + showRetryResponseGenerationButton = true + } else if chatMessageTaskId != nil { + startPollingForResponse() + } } func generateChatSession() async { From b6cabad926577b1d3178bf4e7585875dfa1e7fce Mon Sep 17 00:00:00 2001 From: Milen Pivchev Date: Tue, 10 Mar 2026 17:26:23 +0100 Subject: [PATCH 2/2] WIP Signed-off-by: Milen Pivchev --- iOSClient/Assistant/Chat/NCAssistantChatModel.swift | 3 ++- iOSClient/NCGlobal.swift | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/iOSClient/Assistant/Chat/NCAssistantChatModel.swift b/iOSClient/Assistant/Chat/NCAssistantChatModel.swift index 0bee7ea50b..e29e34e8db 100644 --- a/iOSClient/Assistant/Chat/NCAssistantChatModel.swift +++ b/iOSClient/Assistant/Chat/NCAssistantChatModel.swift @@ -110,7 +110,8 @@ class NCAssistantChatModel { let result = await NextcloudKit.shared.checkAssistantChatGeneration(taskId: chatMessageTaskId, sessionId: selectedConversation?.id ?? 0, account: ncSession.account) - if result.error != .success { + // API sends expectation failed error (417) when a message is not ready yet. We should continue polling. + if result.error != .success, result.error.errorCode != NCGlobal.shared.errorExpectationFailed { stopPolling() await showErrorBanner(windowScene: windowScene, title: "_error_", text: "_assistant_error_generate_response_", errorCode: result.error.errorCode) return diff --git a/iOSClient/NCGlobal.swift b/iOSClient/NCGlobal.swift index 70364d60bd..35425dc0c8 100644 --- a/iOSClient/NCGlobal.swift +++ b/iOSClient/NCGlobal.swift @@ -164,6 +164,7 @@ final class NCGlobal: Sendable { let errorConflict: Int = 409 let errorPreconditionFailed: Int = 412 let errorUnsupportedMediaType: Int = 415 + let errorExpectationFailed: Int = 417 let errorInternalServerError: Int = 500 let errorMaintenance: Int = 503 let errorQuota: Int = 507