diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt index 21a2c94..28e31fb 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/App.kt @@ -177,6 +177,11 @@ private fun OpenClawRoot(appState: OpenClawAppState) { appState.sendMessage(activeSession.id, text) } }, + onSendAttachmentStub = { + coroutineScope.launch { + appState.sendMessage(activeSession.id, "[附件占位] demo.txt") + } + }, ) appState.selectedTab == MainTab.Sessions -> SessionListScreen( diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt index 4532f30..7f47747 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/data/Models.kt @@ -29,7 +29,7 @@ data class ChatMessage( enum class MessageRole { User, Assistant, System } -enum class MessageKind { Text, Thinking, Tool, ToolResult } +enum class MessageKind { Text, Thinking, Tool, ToolResult, Attachment } data class ServerStatus( val online: Boolean, diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt index f476c94..630cb43 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/feature/chat/ChatScreen.kt @@ -52,6 +52,7 @@ fun ChatScreen( onBack: () -> Unit, onRetry: () -> Unit, onSend: (String) -> Unit, + onSendAttachmentStub: () -> Unit, ) { var input by remember { mutableStateOf("") } val listState = rememberLazyListState() @@ -138,7 +139,7 @@ fun ChatScreen( ) { QuickActionButton("帮我总结") { onSend("帮我总结一下当前会话") } QuickActionButton("看状态") { onSend("看一下当前状态") } - QuickActionButton("下一步") { onSend("下一步建议做什么") } + QuickActionButton("发附件") { onSendAttachmentStub() } } } diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayApi.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayApi.kt index 9bb0e27..d3c2df1 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayApi.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayApi.kt @@ -6,9 +6,13 @@ import io.ktor.client.plugins.contentnegotiation.ContentNegotiation import io.ktor.client.request.get import io.ktor.client.request.header 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.setBody +import io.ktor.http.ContentDisposition import io.ktor.http.ContentType +import io.ktor.http.Headers import io.ktor.http.HttpHeaders import io.ktor.http.contentType import io.ktor.http.encodeURLPathPart @@ -69,6 +73,32 @@ class MobileGatewayApi( }.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() { val token = tokenProvider().trim() if (token.isNotBlank()) { diff --git a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt index e6c2603..f9bbb5c 100644 --- a/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt +++ b/composeApp/src/commonMain/kotlin/cn/xiaobai/openclawapp/network/MobileGatewayDtos.kt @@ -70,3 +70,14 @@ data class UpdateDefaultAgentResponseDto( val defaultAgent: 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, +)