Scaffold attachment actions in chat UI
This commit is contained in:
1 parent
e5e13a38f1
commit
3672554706
5 files changed
+49
-2
No files matched your search
@@ -177,6 +177,11 @@ private fun OpenClawRoot(appState: OpenClawAppState) {
|
|||||||
appState.sendMessage(activeSession.id, text)
|
appState.sendMessage(activeSession.id, text)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onSendAttachmentStub = {
|
||||||
|
coroutineScope.launch {
|
||||||
|
appState.sendMessage(activeSession.id, "[附件占位] demo.txt")
|
||||||
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
appState.selectedTab == MainTab.Sessions -> SessionListScreen(
|
appState.selectedTab == MainTab.Sessions -> SessionListScreen(
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ data class ChatMessage(
|
|||||||
|
|
||||||
enum class MessageRole { User, Assistant, System }
|
enum class MessageRole { User, Assistant, System }
|
||||||
|
|
||||||
enum class MessageKind { Text, Thinking, Tool, ToolResult }
|
enum class MessageKind { Text, Thinking, Tool, ToolResult, Attachment }
|
||||||
|
|
||||||
data class ServerStatus(
|
data class ServerStatus(
|
||||||
val online: Boolean,
|
val online: Boolean,
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ fun ChatScreen(
|
|||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
onRetry: () -> Unit,
|
onRetry: () -> Unit,
|
||||||
onSend: (String) -> Unit,
|
onSend: (String) -> Unit,
|
||||||
|
onSendAttachmentStub: () -> Unit,
|
||||||
) {
|
) {
|
||||||
var input by remember { mutableStateOf("") }
|
var input by remember { mutableStateOf("") }
|
||||||
val listState = rememberLazyListState()
|
val listState = rememberLazyListState()
|
||||||
@@ -138,7 +139,7 @@ fun ChatScreen(
|
|||||||
) {
|
) {
|
||||||
QuickActionButton("帮我总结") { onSend("帮我总结一下当前会话") }
|
QuickActionButton("帮我总结") { onSend("帮我总结一下当前会话") }
|
||||||
QuickActionButton("看状态") { onSend("看一下当前状态") }
|
QuickActionButton("看状态") { onSend("看一下当前状态") }
|
||||||
QuickActionButton("下一步") { onSend("下一步建议做什么") }
|
QuickActionButton("发附件") { onSendAttachmentStub() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,13 @@ import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
|
|||||||
import io.ktor.client.request.get
|
import io.ktor.client.request.get
|
||||||
import io.ktor.client.request.header
|
import io.ktor.client.request.header
|
||||||
import io.ktor.client.request.post
|
import io.ktor.client.request.post
|
||||||
|
import io.ktor.client.request.forms.MultiPartFormDataContent
|
||||||
|
import io.ktor.client.request.forms.formData
|
||||||
import io.ktor.client.request.put
|
import io.ktor.client.request.put
|
||||||
import io.ktor.client.request.setBody
|
import io.ktor.client.request.setBody
|
||||||
|
import io.ktor.http.ContentDisposition
|
||||||
import io.ktor.http.ContentType
|
import io.ktor.http.ContentType
|
||||||
|
import io.ktor.http.Headers
|
||||||
import io.ktor.http.HttpHeaders
|
import io.ktor.http.HttpHeaders
|
||||||
import io.ktor.http.contentType
|
import io.ktor.http.contentType
|
||||||
import io.ktor.http.encodeURLPathPart
|
import io.ktor.http.encodeURLPathPart
|
||||||
@@ -69,6 +73,32 @@ class MobileGatewayApi(
|
|||||||
}.body()
|
}.body()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun uploadAttachment(
|
||||||
|
sessionId: String,
|
||||||
|
fileName: String,
|
||||||
|
bytes: ByteArray,
|
||||||
|
contentType: ContentType = ContentType.Application.OctetStream,
|
||||||
|
): UploadAttachmentResponseDto {
|
||||||
|
val encodedId = sessionId.encodeURLPathPart()
|
||||||
|
return client.post("${baseUrl.trimEnd('/')}/api/sessions/$encodedId/attachments") {
|
||||||
|
authHeader()
|
||||||
|
setBody(
|
||||||
|
MultiPartFormDataContent(
|
||||||
|
formData {
|
||||||
|
append(
|
||||||
|
key = "file",
|
||||||
|
value = bytes,
|
||||||
|
headers = Headers.build {
|
||||||
|
append(HttpHeaders.ContentType, contentType.toString())
|
||||||
|
append(HttpHeaders.ContentDisposition, ContentDisposition.File.withParameter(ContentDisposition.Parameters.FileName, fileName).toString())
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}.body()
|
||||||
|
}
|
||||||
|
|
||||||
private fun io.ktor.client.request.HttpRequestBuilder.authHeader() {
|
private fun io.ktor.client.request.HttpRequestBuilder.authHeader() {
|
||||||
val token = tokenProvider().trim()
|
val token = tokenProvider().trim()
|
||||||
if (token.isNotBlank()) {
|
if (token.isNotBlank()) {
|
||||||
|
|||||||
@@ -70,3 +70,14 @@ data class UpdateDefaultAgentResponseDto(
|
|||||||
val defaultAgent: String,
|
val defaultAgent: String,
|
||||||
val updatedAt: String,
|
val updatedAt: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class UploadAttachmentResponseDto(
|
||||||
|
val accepted: Boolean,
|
||||||
|
val sessionId: String,
|
||||||
|
val attachmentId: String,
|
||||||
|
val fileName: String,
|
||||||
|
val contentType: String? = null,
|
||||||
|
val sizeBytes: Int,
|
||||||
|
val queuedAt: String,
|
||||||
|
)
|
||||||
Reference in new issue
Block a user