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. Rows older than retention are pruned after a write, at most once per minute.

Writes run in a child job of scope, so close cancels only this sink's own pending writes — never a host-supplied scope such as lifecycleScope. Call flush first to wait for in-flight writes.

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 this sink's pending writes and close the database. Does not cancel the scope passed to the constructor. Call flush first to avoid dropping rows.

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
suspend fun flush()

Suspend until every write queued so far has finished.

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)