App-Facing RPCs
These are callable by authenticated users (tenant members or MSP partners).rpc_get_or_request_narrative
Fetches the cached gap narrative for a tenant. If the cache is stale or missing, enqueues a regeneration job.The tenant to get the narrative for. Caller must be a member or linked MSP partner.
Set to
true to enqueue a new generation job regardless of cache state.JSONB
The generated narrative text, or null if none exists yet.
ISO timestamp of when the narrative was generated.
Which provider generated this content (e.g.
anthropic, openai).Whether a fallback provider was used instead of the primary.
One of
none (no content exists), fresh (content hash matches current data), or stale (content exists but data has changed).Whether a regeneration job is currently queued or running.
rpc_get_or_request_playbook
Fetches the cached remediation playbook for a control + cloud provider combination.The control to get the playbook for.
Cloud provider context (e.g.
aws, azure, gcp).The requesting tenant (for auth and budget tracking).
Set to
true to force regeneration.JSONB — same structure as narrative response, with playbook instead of narrative.
rpc_get_ai_health_summary
Returns the overall health of the AI content system. No parameters required. Returns:JSONB
Number of jobs currently in
queued status.Number of providers with closed circuits (available for use).
Total configured providers.
Number of providers with open circuits.
Timestamp of the most recent successful generation.
rpc_enqueue_ai_job
Low-level job enqueue. Prefer theget_or_request_* helpers which handle caching, dedup, and enqueue automatically.
One of
gap_narrative, remediation_playbook, evidence_suggestion, policy_suggestion.The tenant this job is for.
The specific entity ID (control_id, evidence_item_id, policy_version_id). Not required for
gap_narrative.Required for
remediation_playbook.UUID — the job ID.
compute_gap_narrative_hash
Utility function that computes the content hash for a tenant’s gap narrative inputs. Mostly used internally by the worker.The tenant to compute the hash for.
TEXT — the computed hash string.
Worker-Only RPCs
These require theservice_role key and are called by the ai_content_worker Edge Function.
| RPC | Purpose |
|---|---|
rpc_claim_ai_jobs | Atomically claim up to N queued jobs (sets status to running) |
rpc_complete_ai_job | Mark a job as completed, store the generated content |
rpc_fail_ai_job | Mark a job as failed, record error message, update circuit breaker |
rpc_record_provider_call | Record token usage and cost for a provider call |
rpc_get_available_providers | Get providers ordered by priority with closed circuits |
Admin-Only RPCs
rpc_test_enqueue_narrative
Manually enqueue a narrative generation job for testing.The tenant to generate a test narrative for.