From f3c2f67c9f4d88298e0162bc1df97277fcc779a0 Mon Sep 17 00:00:00 2001 From: marcus-daily <111281783+marcus-daily@users.noreply.github.com> Date: Fri, 4 Oct 2024 19:13:10 +0100 Subject: [PATCH] RTVI 0.2.0 --- gradle/libs.versions.toml | 10 ++-- rtvi-client-android-daily/build.gradle.kts | 2 +- .../java/ai/rtvi/client/daily/MainTests.kt | 49 ++++++++++--------- .../ai/rtvi/client/daily/DailyTransport.kt | 36 +++++++------- .../ai/rtvi/client/daily/DailyVoiceClient.kt | 15 +++--- .../main/java/ai/rtvi/client/daily/Utils.kt | 10 ++-- 6 files changed, 61 insertions(+), 61 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6163b15..1f60100 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,14 +1,14 @@ [versions] -agp = "8.5.1" -daily-android-client = "0.23.0" -kotlin = "2.0.0" +agp = "8.5.2" +daily-android-client = "0.24.0" +kotlin = "2.0.20" coreKtx = "1.13.1" kotlinxCoroutinesTest = "1.8.1" kotlinxSerializationJson = "1.7.1" -kotlinxSerializationPlugin = "2.0.0" +kotlinxSerializationPlugin = "2.0.20" dokka = "1.9.20" androidxTest = "1.6.1" -rtviClient = "0.1.4" +rtviClient = "0.2.0" [libraries] androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } diff --git a/rtvi-client-android-daily/build.gradle.kts b/rtvi-client-android-daily/build.gradle.kts index b07f1d4..2643789 100644 --- a/rtvi-client-android-daily/build.gradle.kts +++ b/rtvi-client-android-daily/build.gradle.kts @@ -64,7 +64,7 @@ publishing { register("release") { groupId = "ai.rtvi" artifactId = "client-daily" - version = "0.1.5" + version = "0.2.0" pom { name.set("RTVI Client Daily Transport") diff --git a/rtvi-client-android-daily/src/androidTest/java/ai/rtvi/client/daily/MainTests.kt b/rtvi-client-android-daily/src/androidTest/java/ai/rtvi/client/daily/MainTests.kt index cd8ea5e..7f16eb4 100644 --- a/rtvi-client-android-daily/src/androidTest/java/ai/rtvi/client/daily/MainTests.kt +++ b/rtvi-client-android-daily/src/androidTest/java/ai/rtvi/client/daily/MainTests.kt @@ -1,12 +1,13 @@ package ai.rtvi.client.daily -import ai.rtvi.client.VoiceClientOptions -import ai.rtvi.client.VoiceEventCallbacks +import ai.rtvi.client.RTVIClientOptions +import ai.rtvi.client.RTVIClientParams +import ai.rtvi.client.RTVIEventCallbacks import ai.rtvi.client.helper.LLMContext import ai.rtvi.client.helper.LLMContextMessage import ai.rtvi.client.helper.LLMHelper +import ai.rtvi.client.result.RTVIError import ai.rtvi.client.result.Result -import ai.rtvi.client.result.VoiceError import ai.rtvi.client.types.ActionDescription import ai.rtvi.client.types.Config import ai.rtvi.client.types.Option @@ -28,25 +29,28 @@ import org.junit.Test class MainTests { companion object { - private val options = VoiceClientOptions( + private val options = RTVIClientOptions( services = listOf( ServiceRegistration("tts", "cartesia"), ServiceRegistration("llm", "together"), ), - config = listOf( - ServiceConfig( - "tts", listOf( - Option("voice", "79a125e8-cd45-4c13-8a67-188112f4dd22") - ) - ), - ServiceConfig( - "llm", listOf( - Option("model", "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo"), - Option( - "initial_messages", Value.Array( - Value.Object( - "role" to Value.Str("system"), - "content" to Value.Str("You are a helpful voice assistant.") + params = RTVIClientParams( + baseUrl = testUrl, + config = listOf( + ServiceConfig( + "tts", listOf( + Option("voice", "79a125e8-cd45-4c13-8a67-188112f4dd22") + ) + ), + ServiceConfig( + "llm", listOf( + Option("model", "meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo"), + Option( + "initial_messages", Value.Array( + Value.Object( + "role" to Value.Str("system"), + "content" to Value.Str("You are a helpful voice assistant.") + ) ) ) ) @@ -67,8 +71,7 @@ class MainTests { val client = DailyVoiceClient( context = context, - baseUrl = testUrl, - callbacks = object : VoiceEventCallbacks() { + callbacks = object : RTVIEventCallbacks() { override fun onBackendError(message: String) { throw Exception("onBackendError: $message") } @@ -78,7 +81,7 @@ class MainTests { val llmHelper = client.registerHelper("llm", LLMHelper(object : LLMHelper.Callbacks() {})) - client.start().await() + client.connect().await() Assert.assertEquals(TransportState.Ready, client.state) @@ -151,7 +154,7 @@ class MainTests { @Test fun testActionInvalid() = runTestWithConnectedClient { Assert.assertEquals( - Result.Err(VoiceError.ErrorResponse(message = "Action abc123:say not registered")), + Result.Err(RTVIError.ErrorResponse(message = "Action abc123:say not registered")), client.action( "abc123", "say", @@ -163,7 +166,7 @@ class MainTests { @Test fun testGetConfig() = runTestWithConnectedClient { Assert.assertEquals( - Config(config = options.config), + Config(config = options.params.config), client.getConfig().await() ) } diff --git a/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/DailyTransport.kt b/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/DailyTransport.kt index c8e6e09..400cb93 100644 --- a/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/DailyTransport.kt +++ b/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/DailyTransport.kt @@ -1,7 +1,7 @@ package ai.rtvi.client.daily import ai.rtvi.client.result.Future -import ai.rtvi.client.result.VoiceError +import ai.rtvi.client.result.RTVIError import ai.rtvi.client.result.resolvedPromiseErr import ai.rtvi.client.result.resolvedPromiseOk import ai.rtvi.client.result.withPromise @@ -55,7 +55,7 @@ class DailyTransport( private val thread = transportContext.thread private val appContext = androidContext.applicationContext - private var state = TransportState.Idle + private var state = TransportState.Disconnected private var devicesInitialized = false @@ -197,7 +197,7 @@ class DailyTransport( } } - override fun initDevices(): Future = withPromise(thread) { promise -> + override fun initDevices(): Future = withPromise(thread) { promise -> thread.runOnThread { @@ -223,7 +223,7 @@ class DailyTransport( } } - if (state == TransportState.Idle) { + if (state == TransportState.Disconnected) { setState(TransportState.Initialized) } @@ -232,12 +232,12 @@ class DailyTransport( } catch (e: Exception) { Log.e(TAG, "Exception in initDevices", e) - promise.resolveErr(VoiceError.ExceptionThrown(e)) + promise.resolveErr(RTVIError.ExceptionThrown(e)) } } } - override fun connect(authBundle: AuthBundle): Future = + override fun connect(authBundle: AuthBundle): Future = thread.runOnThreadReturningFuture { Log.i(TAG, "connect(${authBundle.data})") @@ -247,7 +247,7 @@ class DailyTransport( } catch (e: Exception) { return@runOnThreadReturningFuture resolvedPromiseErr( thread, - VoiceError.ExceptionThrown(e) + RTVIError.ExceptionThrown(e) ) } @@ -268,7 +268,7 @@ class DailyTransport( ) { if (it.isError) { setState(TransportState.Error) - promise.resolveErr(it.error.toVoiceError()) + promise.resolveErr(it.error.toRTVIError()) return@join } @@ -288,7 +288,7 @@ class DailyTransport( } } - override fun disconnect(): Future = thread.runOnThreadReturningFuture { + override fun disconnect(): Future = thread.runOnThreadReturningFuture { withCall { callClient -> withPromise(thread) { promise -> callClient.leave(promise::resolveWithDailyResult) @@ -298,7 +298,7 @@ class DailyTransport( override fun sendMessage( message: MsgClientToServer, - ): Future = thread.runOnThreadReturningFuture { + ): Future = thread.runOnThreadReturningFuture { withCall { callClient -> withPromise(thread) { promise -> callClient.sendAppMessage( @@ -321,10 +321,10 @@ class DailyTransport( transportContext.callbacks.onTransportStateChanged(state) } - override fun getAllCams(): Future, VoiceError> = + override fun getAllCams(): Future, RTVIError> = resolvedPromiseOk(thread, getAllCamsInternal()) - override fun getAllMics(): Future, VoiceError> = + override fun getAllMics(): Future, RTVIError> = resolvedPromiseOk(thread, getAllMicsInternal()) private fun getAllCamsInternal() = @@ -333,7 +333,7 @@ class DailyTransport( private fun getAllMicsInternal() = call?.availableDevices()?.audio?.map { it.toRtvi() } ?: emptyList() - override fun updateMic(micId: MediaDeviceId): Future = + override fun updateMic(micId: MediaDeviceId): Future = thread.runOnThreadReturningFuture { withCall { callClient -> withPromise(thread) { promise -> @@ -342,7 +342,7 @@ class DailyTransport( } } - override fun updateCam(camId: MediaDeviceId): Future = + override fun updateCam(camId: MediaDeviceId): Future = thread.runOnThreadReturningFuture { withCall { callClient -> withPromise(thread) { promise -> @@ -369,7 +369,7 @@ class DailyTransport( override fun isMicEnabled() = call?.inputs()?.microphone?.isEnabled ?: false - override fun enableMic(enable: Boolean): Future = + override fun enableMic(enable: Boolean): Future = thread.runOnThreadReturningFuture { withCall { callClient -> withPromise(thread) { promise -> @@ -386,7 +386,7 @@ class DailyTransport( override fun expiry() = thread.assertCurrent { expiry } - override fun enableCam(enable: Boolean): Future = + override fun enableCam(enable: Boolean): Future = thread.runOnThreadReturningFuture { withCall { callClient -> withPromise(thread) { promise -> @@ -431,14 +431,14 @@ class DailyTransport( call = null } - private fun withCall(action: (CallClient) -> Future): Future { + private fun withCall(action: (CallClient) -> Future): Future { thread.assertCurrent() val currentClient = call return if (currentClient == null) { - resolvedPromiseErr(thread, VoiceError.TransportNotInitialized) + resolvedPromiseErr(thread, RTVIError.TransportNotInitialized) } else { return action(currentClient) } diff --git a/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/DailyVoiceClient.kt b/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/DailyVoiceClient.kt index fde5700..b0e66da 100644 --- a/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/DailyVoiceClient.kt +++ b/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/DailyVoiceClient.kt @@ -1,8 +1,8 @@ package ai.rtvi.client.daily -import ai.rtvi.client.VoiceClient -import ai.rtvi.client.VoiceClientOptions -import ai.rtvi.client.VoiceEventCallbacks +import ai.rtvi.client.RTVIClient +import ai.rtvi.client.RTVIClientOptions +import ai.rtvi.client.RTVIEventCallbacks import android.content.Context /** @@ -10,17 +10,14 @@ import android.content.Context * streaming. * * @param context The Android context object - * @param baseUrl URL of the Daily Bots backend. * @param callbacks Callbacks invoked when changes occur in the voice session. * @param options Additional options for configuring the client and backend. */ class DailyVoiceClient( context: Context, - baseUrl: String, - callbacks: VoiceEventCallbacks, - options: VoiceClientOptions = VoiceClientOptions() -) : VoiceClient( - baseUrl = baseUrl, + callbacks: RTVIEventCallbacks, + options: RTVIClientOptions +) : RTVIClient( transport = DailyTransport.Factory(context), callbacks = callbacks, options = options diff --git a/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/Utils.kt b/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/Utils.kt index 4a617e5..5860cbf 100644 --- a/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/Utils.kt +++ b/rtvi-client-android-daily/src/main/java/ai/rtvi/client/daily/Utils.kt @@ -1,7 +1,7 @@ package ai.rtvi.client.daily import ai.rtvi.client.result.Promise -import ai.rtvi.client.result.VoiceError +import ai.rtvi.client.result.RTVIError import ai.rtvi.client.types.MediaDeviceId import ai.rtvi.client.types.MediaDeviceInfo import ai.rtvi.client.types.MediaTrackId @@ -17,12 +17,12 @@ import kotlinx.serialization.json.contentOrNull internal val JSON_INSTANCE = Json { ignoreUnknownKeys = true } -internal fun RequestError?.toVoiceError() = - VoiceError.OtherError("Error from Daily client: ${this?.msg}") +internal fun RequestError?.toRTVIError() = + RTVIError.OtherError("Error from Daily client: ${this?.msg}") -internal fun Promise.resolveWithDailyResult(result: RequestResult) { +internal fun Promise.resolveWithDailyResult(result: RequestResult) { if (result.isError) { - resolveErr(result.error.toVoiceError()) + resolveErr(result.error.toRTVIError()) } else { resolveOk(Unit) }