chat: reconcile history by canonical message identity
This commit is contained in:
@@ -353,7 +353,7 @@ class PipelinesRepository(
|
||||
if (sessionId.isBlank()) throw ProtocolException("Select a chat session first.")
|
||||
val trimmed = text.trim()
|
||||
if (trimmed.isEmpty()) throw ProtocolException("Enter a message before sending.")
|
||||
return client.call(ChatProtocol.promptRequest(sessionId, trimmed, files, clientLabel, operationId)).chatQueued
|
||||
return client.call(ChatProtocol.promptRequest(sessionId, trimmed, files, clientLabel, operationId, nativeMessageId(operationId))).chatQueued
|
||||
}
|
||||
|
||||
suspend fun chatInterrupt(sessionId: String) {
|
||||
@@ -408,5 +408,12 @@ class PipelinesRepository(
|
||||
|
||||
/** A durable key for one chat-create intent; retain it when retrying. */
|
||||
fun newChatCreateOperationId(): String = "android-chat-" + UUID.randomUUID().toString()
|
||||
|
||||
/** OpenCode's optional caller id is the canonical bridge to history. */
|
||||
fun nativeMessageId(operationId: String): String =
|
||||
operationId.filter { character -> character.isLetterOrDigit() }.take(120)
|
||||
.takeIf { it.isNotEmpty() }
|
||||
?.let { "msg_" + it }
|
||||
.orEmpty()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ data class ChatPromptRequest(
|
||||
// a generic label when it is blank.
|
||||
val client: String = "",
|
||||
@SerialName("operation_id") val operationId: String = "",
|
||||
@SerialName("native_message_id") val nativeMessageId: String = "",
|
||||
)
|
||||
|
||||
/** One stored turn: a user turn is a single text part, an assistant turn holds text/reasoning/tool parts. */
|
||||
@@ -361,10 +362,10 @@ object ChatProtocol {
|
||||
* shape a text-only prompt has always sent). Built here (not inline in the
|
||||
* repository) so production and its unit test share the one wire shape.
|
||||
*/
|
||||
fun promptRequest(sessionId: String, text: String, files: List<String> = emptyList(), client: String = "", operationId: String = ""): Message =
|
||||
fun promptRequest(sessionId: String, text: String, files: List<String> = emptyList(), client: String = "", operationId: String = "", nativeMessageId: String = ""): Message =
|
||||
Message(
|
||||
type = Protocol.CHAT_PROMPT,
|
||||
chatPrompt = ChatPromptRequest(sessionId = sessionId, text = text, files = files, client = client, operationId = operationId),
|
||||
chatPrompt = ChatPromptRequest(sessionId = sessionId, text = text, files = files, client = client, operationId = operationId, nativeMessageId = nativeMessageId),
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user