fix(android): fix android build error (#13117)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Improved chat session and history retrieval with support for paginated results in the chat interface. * **Bug Fixes** * Enhanced reliability when loading large numbers of chat messages and histories. * **Refactor** * Updated chat data handling to align with the latest backend schema and pagination model. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package app.affine.pro.ai.chat
|
package app.affine.pro.ai.chat
|
||||||
|
|
||||||
import com.affine.pro.graphql.GetCopilotHistoriesQuery
|
import com.affine.pro.graphql.GetCopilotHistoriesQuery
|
||||||
|
import com.affine.pro.graphql.fragment.CopilotChatHistory
|
||||||
|
import com.affine.pro.graphql.fragment.CopilotChatMessage
|
||||||
import kotlinx.datetime.Clock
|
import kotlinx.datetime.Clock
|
||||||
import kotlinx.datetime.Instant
|
import kotlinx.datetime.Instant
|
||||||
|
|
||||||
@@ -51,7 +53,7 @@ data class ChatMessage(
|
|||||||
createAt = Clock.System.now(),
|
createAt = Clock.System.now(),
|
||||||
)
|
)
|
||||||
|
|
||||||
fun from(message: GetCopilotHistoriesQuery.Message) = ChatMessage(
|
fun from(message: CopilotChatMessage) = ChatMessage(
|
||||||
id = message.id,
|
id = message.id,
|
||||||
role = Role.fromValue(message.role),
|
role = Role.fromValue(message.role),
|
||||||
content = message.content,
|
content = message.content,
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import com.affine.pro.graphql.GetCopilotHistoryIdsQuery
|
|||||||
import com.affine.pro.graphql.GetCopilotSessionsQuery
|
import com.affine.pro.graphql.GetCopilotSessionsQuery
|
||||||
import com.affine.pro.graphql.type.CreateChatMessageInput
|
import com.affine.pro.graphql.type.CreateChatMessageInput
|
||||||
import com.affine.pro.graphql.type.CreateChatSessionInput
|
import com.affine.pro.graphql.type.CreateChatSessionInput
|
||||||
import com.affine.pro.graphql.type.QueryChatSessionsInput
|
import com.affine.pro.graphql.type.PaginationInput
|
||||||
|
import com.affine.pro.graphql.type.QueryChatHistoriesInput
|
||||||
import com.apollographql.apollo.ApolloClient
|
import com.apollographql.apollo.ApolloClient
|
||||||
import com.apollographql.apollo.api.Mutation
|
import com.apollographql.apollo.api.Mutation
|
||||||
import com.apollographql.apollo.api.Optional
|
import com.apollographql.apollo.api.Optional
|
||||||
@@ -29,12 +30,15 @@ class GraphQLService @Inject constructor() {
|
|||||||
GetCopilotSessionsQuery(
|
GetCopilotSessionsQuery(
|
||||||
workspaceId = workspaceId,
|
workspaceId = workspaceId,
|
||||||
docId = Optional.present(docId),
|
docId = Optional.present(docId),
|
||||||
options = Optional.present(QueryChatSessionsInput(action = Optional.present(false)))
|
pagination = PaginationInput(
|
||||||
|
first = Optional.present(100)
|
||||||
|
),
|
||||||
|
options = Optional.present(QueryChatHistoriesInput(action = Optional.present(false)))
|
||||||
)
|
)
|
||||||
).mapCatching { data ->
|
).mapCatching { data ->
|
||||||
data.currentUser?.copilot?.sessions?.find {
|
data.currentUser?.copilot?.chats?.paginatedCopilotChats?.edges?.map { item -> item.node.copilotChatHistory }?.find {
|
||||||
it.parentSessionId == null
|
it.parentSessionId == null
|
||||||
}?.id ?: error(ERROR_NULL_SESSION_ID)
|
}?.sessionId ?: error(ERROR_NULL_SESSION_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun createCopilotSession(
|
suspend fun createCopilotSession(
|
||||||
@@ -60,12 +64,15 @@ class GraphQLService @Inject constructor() {
|
|||||||
) = query(
|
) = query(
|
||||||
GetCopilotHistoriesQuery(
|
GetCopilotHistoriesQuery(
|
||||||
workspaceId = workspaceId,
|
workspaceId = workspaceId,
|
||||||
|
pagination = PaginationInput(
|
||||||
|
first = Optional.present(100)
|
||||||
|
),
|
||||||
docId = Optional.present(docId),
|
docId = Optional.present(docId),
|
||||||
)
|
)
|
||||||
).mapCatching { data ->
|
).mapCatching { data ->
|
||||||
data.currentUser?.copilot?.histories?.firstOrNull { history ->
|
data.currentUser?.copilot?.chats?.paginatedCopilotChats?.edges?.map { item -> item.node.copilotChatHistory }?.firstOrNull { history ->
|
||||||
history.sessionId == sessionId
|
history.sessionId == sessionId
|
||||||
}?.messages ?: emptyList()
|
}?.messages?.map { msg -> msg.copilotChatMessage } ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getCopilotHistoryIds(
|
suspend fun getCopilotHistoryIds(
|
||||||
@@ -76,9 +83,12 @@ class GraphQLService @Inject constructor() {
|
|||||||
GetCopilotHistoryIdsQuery(
|
GetCopilotHistoryIdsQuery(
|
||||||
workspaceId = workspaceId,
|
workspaceId = workspaceId,
|
||||||
docId = Optional.present(docId),
|
docId = Optional.present(docId),
|
||||||
|
pagination = PaginationInput(
|
||||||
|
first = Optional.present(100)
|
||||||
|
),
|
||||||
)
|
)
|
||||||
).mapCatching { data ->
|
).mapCatching { data ->
|
||||||
data.currentUser?.copilot?.histories?.firstOrNull { history ->
|
data.currentUser?.copilot?.chats?.edges?.map { item -> item.node }?.firstOrNull { history ->
|
||||||
history.sessionId == sessionId
|
history.sessionId == sessionId
|
||||||
}?.messages ?: emptyList()
|
}?.messages ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user