房间会话(Session)服务(Service)

A persistent SessionService backed by a Room/SQLite database in the consumer app's private storage.

Sessions, events, and app/user state survive process death and device reboot. Use this in place of InMemorySessionService when constructing a Runner in an Android consumer app.

Default usage — one instance per Application:

val sessionService = RoomSessionService.fromContext(applicationContext)

Pass a distinct databaseName to give an agent its own SQLite file (e.g. when two agents in the same app should not see each other's sessions even within the same appName):

val agentASessions = RoomSessionService.fromContext(context, "agent_a.db")
val agentBSessions = RoomSessionService.fromContext(context, "agent_b.db")

Dispatching is handled by Room — suspend fun DAO calls run on Room's internal transaction executor, so this class does not need to wrap calls in withContext.

类型

Link copied to clipboard
object Companion

函数

Link copied to clipboard
open suspend override fun appendEvent(session: Session, event: Event): Event

追加(数据) 事件 给……;发送到…… session将该状态变化(即 “状态增量”)应用到内存中的会话数据中,并记录这一事件。 temp: 这些键会被应用到内存中的状态数据上(这样后续参与调用的代理程序就可以读取这些数据),但之后会从内存中删除这些键。 事件 在数据被持久化(即存储到数据库中)之前。

Link copied to clipboard
open override fun close()

关闭底层的 Room 数据库,并释放相应的文件句柄。这种方法主要用于那些需要反复创建和销毁服务(即服务实例)的测试场景。在普通的应用程序中,数据库会一直保持打开状态,直到进程结束;因为 Android 系统本身并不要求开发者显式地关闭数据库。

Link copied to clipboard
open suspend fun closeSession(session: Session)

关闭会话。

Link copied to clipboard
open suspend override fun createSession(key: SessionKey, state: Map<String, Any>? = null): Session

使用指定的参数创建一个新的会话。

Link copied to clipboard
open suspend override fun deleteSession(key: SessionKey)

删除特定的会话。

Link copied to clipboard
open suspend fun flush(key: SessionKey? = null)

在此调用之前,系统会等待所有要写入的数据被追加完成后再进行持久化处理。具体来说,就是那些需要被写入的数据…… key或者,在每次会话开始时(即每次用户登录时)…… key 是 null取消呼叫者的操作会停止等待过程,但不会影响数据的写入操作。

Link copied to clipboard
open suspend override fun getSession(key: SessionKey, config: GetSessionConfig? = null): Session?

检索特定的会话(session),并可选择性地过滤其中包含的事件(events)。

Link copied to clipboard
open suspend override fun listEvents(key: SessionKey): ListEventsResponse

列出特定会话中的所有事件。

Link copied to clipboard
open suspend override fun listSessions(appName: String, userId: String): ListSessionsResponse

列出与特定应用程序和用户关联的会话(session)。