Skip to content

InMemoryPendingApprovalStore

Namespace AgentPrism · Assembly AgentPrism.Core.dll

A store that keeps pending approval requests in process memory.

public sealed class InMemoryPendingApprovalStore : IPendingApprovalStore

objectInMemoryPendingApprovalStore

IPendingApprovalStore

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Limits: process lifetime and a single node. In production, use AgentPrism.PostgreSql or AgentPrism.SqlServer/AgentPrism.Sqlite.

InMemoryPendingApprovalStore(ITenantContext?)

Section titled “ InMemoryPendingApprovalStore(ITenantContext?)”

Initializes a new in-memory approval store.

public InMemoryPendingApprovalStore(ITenantContext? tenantContext = null)

tenantContext ITenantContext?

The current tenant context. If this is not supplied, the store behaves as single tenant.

CreateAsync(PendingApproval, CancellationToken)

Section titled “ CreateAsync(PendingApproval, CancellationToken)”

Creates a new pending approval request.

public ValueTask CreateAsync(PendingApproval approval, CancellationToken cancellationToken = default)

approval PendingApproval

The request to save. PendingApproval.Status must be ApprovalStatus.Pending.

cancellationToken CancellationToken

The cancellation token.

ValueTask

DecideAsync(Guid, bool, string, DateTimeOffset, CancellationToken)

Section titled “ DecideAsync(Guid, bool, string, DateTimeOffset, CancellationToken)”

Writes a decision on a pending request.

public ValueTask<bool> DecideAsync(Guid id, bool approved, string decidedBy, DateTimeOffset decidedAt, CancellationToken cancellationToken = default)

id Guid

The request id.

approved bool

Whether the request is approved.

decidedBy string

The actor that made the decision.

decidedAt DateTimeOffset

The time of the decision.

cancellationToken CancellationToken

The cancellation token.

ValueTask<bool>

true when the decision is written; false when the request is not found in the caller’s tenant or is no longer in the ApprovalStatus.Pending state (a second decision is rejected silently).

ExpireAsync(DateTimeOffset, int, CancellationToken)

Section titled “ ExpireAsync(DateTimeOffset, int, CancellationToken)”

Closes the requests that expired before olderThan and are still in the ApprovalStatus.Pending state, marking them ApprovalStatus.Expired.

public ValueTask<IReadOnlyList<PendingApproval>> ExpireAsync(DateTimeOffset olderThan, int max, CancellationToken cancellationToken = default)

olderThan DateTimeOffset

Requests that expired before this time are closed (UTC).

max int

The upper number of requests closed in this round.

cancellationToken CancellationToken

The cancellation token.

ValueTask<IReadOnlyList<PendingApproval>>

The records of the closed requests.

[TenantAgnostic]: this is maintenance work and scans the expired requests of every tenant; filtering by the ambient tenant would leave the requests of the other tenants ApprovalStatus.Pending forever.

Returns a single pending approval request.

public ValueTask<PendingApproval?> GetAsync(Guid id, CancellationToken cancellationToken = default)

id Guid

The request id.

cancellationToken CancellationToken

The cancellation token.

ValueTask<PendingApproval?>

The request, or null when it is not found in the caller’s tenant.

Lists the pending requests of the caller’s tenant, ordered from oldest to newest.

public ValueTask<IReadOnlyList<PendingApproval>> ListPendingAsync(CancellationToken cancellationToken = default)

cancellationToken CancellationToken

The cancellation token.

ValueTask<IReadOnlyList<PendingApproval>>