API Reference

Complete reference for governance-sdk v0.5.0. All functions are TypeScript-native. Zero runtime dependencies. Start with the quickstart if you haven't set up governance yet.

Core

import ... from 'governance-sdk'

Primary API. Create governance instances, register agents, enforce policies.

createGovernancev0.1.0+core
createGovernance(config: GovernanceConfig): Governance

Creates a new governance instance with the provided configuration. The instance is the central object for all policy enforcement, agent registration, and audit logging.

Parameters
nametypedescription
config.rulesPolicyRule[]Array of policy rules to evaluate on every enforce() call.
config.storageStorageAdapterStorage backend. Defaults to in-memory. Use postgresStorage() for persistence.
config.signingKeystringHMAC signing key for tamper-evident audit chains.
Returns
GovernanceGovernance instance with register(), enforce(), kill(), and on() methods.
Example
ts
gov.registerv0.1.0+core
gov.register(agent: AgentRegistration): Promise<RegisteredAgent>

Registers an agent with the governance system. Computes a 7-dimension governance score (0–100) and assigns a governance level (L0–L4). Call once per agent at startup.

Parameters
nametypedescription
agent.namerequiredstringUnique identifier for the agent.
agent.framework'mastra' | 'vercel-ai' | 'langchain' | 'openai'Framework the agent uses.
agent.toolsstring[]List of tool names the agent can access.
agent.hasAuthbooleanWhether the agent has authentication enabled.
agent.hasGuardrailsbooleanWhether the agent has guardrails configured.
Returns
Promise<RegisteredAgent>Registered agent with id, score, level, status, and assessment fields.
Example
ts
gov.enforcev0.1.0+coreenforcement
gov.enforce(agentId: string, action: Action): Promise<EnforceResult>

Evaluates all policies against the proposed action before execution. Returns allow or block with the matching rule. Automatically writes to audit trail.

Parameters
nametypedescription
agentIdrequiredstringID of the agent requesting the action (from gov.register()).
action.toolrequiredstringName of the tool being called.
action.paramsRecord<string, unknown>Tool parameters, logged to audit trail.
Returns
Promise<EnforceResult>{ outcome: 'allow' | 'block', rule?: string, reason?: string, latencyMs: number }
Example
ts
createKillSwitchv0.2.0+kill-switch
createKillSwitch(gov: Governance): KillSwitch

Creates a kill switch instance bound to a governance engine. Use ks.kill() to halt a specific agent, ks.killAll() for fleet-wide emergency. Priority 999 overrides all other policies.

Parameters
nametypedescription
govrequiredGovernanceGovernance instance from createGovernance().
Returns
KillSwitchKill switch with kill(), killAll(), revive(), reviveAll(), isKilled(), and getKillRecords() methods.
Example
ts

Injection Detection

import ... from 'governance-sdk'

64+-pattern prompt injection scanner. Run on all user-sourced strings before agent processing.

detectInjectionv0.2.0+security
detectInjection(input: string): InjectionResult

Synchronously scans a string for prompt injection patterns across 7 categories. Returns detection status, category, matched pattern, and confidence score.

Parameters
nametypedescription
inputrequiredstringUser-provided string to scan.
Returns
InjectionResult{ detected: boolean, category?: string, pattern?: string, score: number }
Example
ts

Audit Integrity

import ... from 'governance-sdk/audit-integrity'

HMAC-SHA256 hash-chained audit trail. Tamper detection with exact broken-link location.

createIntegrityChainv0.3.0+auditsecurity
createIntegrityChain(config: ChainConfig): IntegrityChain

Creates an HMAC-SHA256 hash-chained audit log. Each event includes the hash of the previous, making any modification detectable via chain.verify().

Parameters
nametypedescription
config.signingKeyrequiredstringSecret key for HMAC computation. Keep in environment variables.
config.storageStorageAdapterWhere to persist events. Defaults to in-memory.
Returns
IntegrityChainChain with append(), verify(), and export() methods.
Example
ts

EU AI Act Compliance

import ... from 'governance-sdk/compliance'

Article-by-article EU AI Act coverage assessment. Tracks 6 articles across Articles 9, 11, 12, 14, 15, and 50.

assessCompliancev0.3.0+compliance
assessCompliance(config: ComplianceConfig): ComplianceResult

Evaluates your governance configuration against 6 EU AI Act articles and returns a compliance score with covered/gap breakdown.

Parameters
nametypedescription
config.hasPoliciesbooleanWhether policy rules are configured (Article 9, 15).
config.hasAuditTrailbooleanWhether HMAC audit chain is enabled (Article 12).
config.hasRequireApprovalbooleanWhether human oversight gates are active (Article 14).
config.registeredAgentsnumberNumber of agents registered via gov.register() (Article 11).
Returns
ComplianceResult{ score: number, covered: string[], gaps: string[], articles: ArticleStatus[] }
Example
ts

Enterprise

import ... from '@lua-ai-global/governance-enterprise'

Multi-tenant governance, RBAC, org-level analytics, and policy templates. Enterprise plan required.

bootstrapEnterpriseTenantv0.5.0+enterprise
bootstrapEnterpriseTenant(config: BootstrapConfig): Promise<EnterpriseTenant>

Creates a fully wired enterprise tenant with multi-tenancy, RBAC, analytics, compliance, health monitor, approval queue, and more — all from a single call.

Parameters
nametypedescription
config.namerequiredstringOrganization name.
config.slugrequiredstringURL-safe identifier for the tenant.
config.planrequired'pro' | 'enterprise'Licensing plan.
config.ownerIdrequiredstringOwner user ID.
config.frameworksstring[]Compliance frameworks to pre-load (e.g., ['hipaa', 'soc2']).
Returns
Promise<EnterpriseTenant>Enterprise tenant with gov, analytics, compliance, healthMonitor, events, and more.
Example
ts
Need the full quickstart?

8-step setup guide with adapter examples and policy templates.