RoomAuditSink

class RoomAuditSink(context: Context, retention: Duration = Duration.ofDays(7), scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)) : AuditSink

Room-backed AuditSink persisting every HTTP tools/call to a private on-device database.

Wire it into the server with DroidMcp.Builder.withAuditSink(...). Writes are fire-and-forget on a background scope, so record returns immediately and a DB hiccup can never fail a tool call. Each write also prunes rows older than retention.

Privacy note: the persisted ToolCallAudit.argumentsJson contains whatever the LLM passed — message text, contact names, file paths, coordinates. The database lives in the host app's private storage; the host owns its retention, export, and deletion. Set retention to Duration.ZERO to keep rows indefinitely (pruning is then skipped).

Constructors

Link copied to clipboard
constructor(context: Context, retention: Duration = Duration.ofDays(7), scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO))

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
suspend fun clear()

Delete the entire audit history.

Link copied to clipboard
fun close()

Cancel the write scope and close the database.

Link copied to clipboard
suspend fun count(): Int
Link copied to clipboard
suspend fun exportJson(): String

Serialize the full history (oldest-first) to a JSON array string.

Link copied to clipboard
fun observe(limit: Int = 100): Flow<List<ToolCallAudit>>

Reactive newest-first stream for a browse UI.

Link copied to clipboard
suspend fun pruneNow(): Int

Force a retention sweep now. @return rows deleted. No-op if retention is zero.

Link copied to clipboard
suspend fun recent(limit: Int = 100): List<ToolCallAudit>

Most recent limit calls, newest first.

Link copied to clipboard
open override fun record(entry: ToolCallAudit)