File tree Expand file tree Collapse file tree 4 files changed +26
-4
lines changed
kotlin-wot-integration-tests
src/test/kotlin/integration
lmos-kotlin-sdk-base/src/main/kotlin/sdk/agents
lmos-kotlin-sdk-client/src/main/kotlin/sdk Expand file tree Collapse file tree 4 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -8,9 +8,9 @@ plugins {
88 id(" io.spring.dependency-management" ) version " 1.1.7"
99}
1010
11- // tasks.named<Test>("test") {
12- // enabled = false
13- // }
11+ tasks.named<Test >(" test" ) {
12+ enabled = false
13+ }
1414
1515dependencies {
1616 // Replace the following with the starter dependencies of specific modules you wish to use
Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ package ai.ancf.lmos.wot.integration
44import ai.ancf.lmos.sdk.agents.WotConversationalAgent
55import ai.ancf.lmos.sdk.agents.lastMessage
66import ai.ancf.lmos.sdk.agents.toAgentRequest
7- import ai.ancf.lmos.sdk.model.AgentEvent
87import kotlinx.coroutines.runBlocking
8+ import org.eclipse.lmos.arc.agents.AgentEvent
99import java.util.concurrent.CountDownLatch
1010import kotlin.test.Test
1111
@@ -36,10 +36,16 @@ class QuickTest {
3636
3737 val agent = WotConversationalAgent .create(" http://localhost:8181/scraper" )
3838
39+ /*
3940 agent.consumeEvent("agentEvent", AgentEvent::class) {
4041 println("Event: $it")
4142 latch.countDown()
4243 }
44+ */
45+ agent.consumeEvent(" agentEvent" , AgentEvent ::class ).collect {
46+ println (" Event: $it " )
47+ latch.countDown()
48+ }
4349
4450 // val command = "What is the state of my lamp?"
4551 val command = " Scrape the page https://eclipse.dev/lmos/\" "
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package ai.ancf.lmos.sdk.agents
33import ai.ancf.lmos.sdk.model.AgentRequest
44import ai.ancf.lmos.sdk.model.AgentResult
55import ai.ancf.lmos.sdk.model.Message
6+ import kotlinx.coroutines.flow.Flow
67import kotlin.reflect.KClass
78
89interface ConversationalAgent {
@@ -11,6 +12,7 @@ interface ConversationalAgent {
1112
1213interface ConsumedConversationalAgent : ConversationalAgent {
1314 suspend fun <T : Any > consumeEvent (eventName : String , clazz : KClass <T >, listener : EventListener <T >)
15+ suspend fun <T : Any > consumeEvent (eventName : String , clazz : KClass <T >) : Flow <T >
1416}
1517
1618fun interface EventListener <T > {
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import ai.ancf.lmos.wot.binding.http.HttpsProtocolClientFactory
1010import ai.ancf.lmos.wot.binding.websocket.WebSocketProtocolClientFactory
1111import ai.ancf.lmos.wot.thing.ConsumedThing
1212import io.opentelemetry.instrumentation.annotations.WithSpan
13+ import kotlinx.coroutines.flow.Flow
14+ import kotlinx.coroutines.flow.map
1315import org.slf4j.Logger
1416import org.slf4j.LoggerFactory
1517import kotlin.reflect.KClass
@@ -53,7 +55,19 @@ class WotConversationalAgent private constructor(private val thing : ConsumedThi
5355 listener.handleEvent(parsedEvent)
5456 } catch (e: Exception ) {
5557 log.error(" Failed to parse event" , e)
58+ throw e
5659 }
5760 })
5861 }
62+
63+ override suspend fun <T : Any > consumeEvent (eventName : String , clazz : KClass <T >): Flow <T > {
64+ return thing.consumeEvent(eventName).map { event ->
65+ try {
66+ JsonMapper .instance.treeToValue(event.value(), clazz.java)
67+ } catch (e: Exception ) {
68+ log.error(" Failed to parse event" , e)
69+ throw e
70+ }
71+ }
72+ }
5973}
You can’t perform that action at this time.
0 commit comments