From bcd7bbd5492aa11a22f1e7030ac996d3a77c8715 Mon Sep 17 00:00:00 2001 From: davidliu Date: Thu, 19 Mar 2026 21:34:23 +0900 Subject: [PATCH 1/2] Fix TranscriptionAttributes not being converted correctly --- .../android/room/types/AgentTypesExt.kt | 2 +- .../room/types/TranscriptionAttributesTest.kt | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt diff --git a/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt b/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt index f8a3944b7..199e578ae 100644 --- a/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt +++ b/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt @@ -107,5 +107,5 @@ fun TranscriptionAttributes.Companion.fromStringMap(map: Map): T val TRANSCRIPTION_ATTRIBUTES_CONVERSION = mapOf JsonElement?>( "lk.segment_id" to { json -> JsonPrimitive(json) }, "lk.transcribed_track_id" to { json -> JsonPrimitive(json) }, - "lk.transcription_final" to { json -> json?.let { jsonSerializer.decodeFromString(json) } }, + "lk.transcription_final" to { json -> json?.let { JsonPrimitive(json.toBooleanStrictOrNull()) } }, ) diff --git a/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt b/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt new file mode 100644 index 000000000..d575a3fd0 --- /dev/null +++ b/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt @@ -0,0 +1,22 @@ +package io.livekit.android.room.types + +import org.junit.Assert.assertEquals +import org.junit.Test + +class TranscriptionAttributesTest { + + @Test + fun simpleConversion() { + val attributes = mapOf( + "lk.transcribed_track_id" to "track_id", + "lk.transcription_final" to "false", + "lk.segment_id" to "segment_id", + ) + + val transcriptionAttributes = TranscriptionAttributes.fromStringMap(attributes) + + assertEquals("track_id", transcriptionAttributes.lkTranscribedTrackID) + assertEquals(false, transcriptionAttributes.lkTranscriptionFinal) + assertEquals("segment_id", transcriptionAttributes.lkSegmentID) + } +} From 168fa10e43a42775d7892ec937105b28f5cdc4ad Mon Sep 17 00:00:00 2001 From: davidliu Date: Thu, 19 Mar 2026 21:43:49 +0900 Subject: [PATCH 2/2] changesets and spotless --- .changeset/strong-readers-matter.md | 5 +++++ .../livekit/android/room/types/AgentTypesExt.kt | 9 +++++++++ .../room/types/TranscriptionAttributesTest.kt | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 .changeset/strong-readers-matter.md diff --git a/.changeset/strong-readers-matter.md b/.changeset/strong-readers-matter.md new file mode 100644 index 000000000..3ffb18a5c --- /dev/null +++ b/.changeset/strong-readers-matter.md @@ -0,0 +1,5 @@ +--- +"client-sdk-android": patch +--- + +Fix transcription attributes not converting correctly diff --git a/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt b/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt index 199e578ae..63fae1f02 100644 --- a/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt +++ b/livekit-android-sdk/src/main/java/io/livekit/android/room/types/AgentTypesExt.kt @@ -17,6 +17,7 @@ package io.livekit.android.room.types import androidx.annotation.VisibleForTesting +import kotlinx.serialization.SerializationException import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonArray @@ -35,6 +36,8 @@ internal fun AgentAttributes.Companion.fromJsonObject(jsonObject: JsonObject) = jsonSerializer.decodeFromJsonElement(jsonObject) /** + * @throws [SerializationException] if the given JSON element is not a valid JSON input + * @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance * @suppress */ fun AgentAttributes.Companion.fromMap(map: Map): AgentAttributes { @@ -46,6 +49,8 @@ fun AgentAttributes.Companion.fromMap(map: Map): AgentAttri } /** + * @throws [SerializationException] if the given JSON element is not a valid JSON input + * @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance * @suppress */ fun AgentAttributes.Companion.fromStringMap(map: Map): AgentAttributes { @@ -75,6 +80,8 @@ internal fun TranscriptionAttributes.Companion.fromJsonObject(jsonObject: JsonOb jsonSerializer.decodeFromJsonElement(jsonObject) /** + * @throws [SerializationException] if the given JSON element is not a valid JSON input + * @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance * @suppress */ fun TranscriptionAttributes.Companion.fromMap(map: Map): TranscriptionAttributes { @@ -86,6 +93,8 @@ fun TranscriptionAttributes.Companion.fromMap(map: Map): Tr } /** + * @throws [SerializationException] if the given JSON element is not a valid JSON input + * @throws [IllegalArgumentException] if the decoded input cannot be represented as a valid instance * @suppress */ fun TranscriptionAttributes.Companion.fromStringMap(map: Map): TranscriptionAttributes { diff --git a/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt b/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt index d575a3fd0..9cc5ec557 100644 --- a/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt +++ b/livekit-android-test/src/test/java/io/livekit/android/room/types/TranscriptionAttributesTest.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2026 LiveKit, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package io.livekit.android.room.types import org.junit.Assert.assertEquals