API Reference

Complete reference for governance-sdk v0.11.2. 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'

54-pattern regex injection scanner (F1 ≈ 0.48 — defense in depth, not a sole control). 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 Mapping

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

Self-assessment cross-reference of your governance configuration against EU AI Act Articles 9, 11, 12, 14, 15, and 50. Not a certified audit; not legal advice.

mapToEuAiActv0.3.0+compliance
mapToEuAiAct(config: ComplianceConfig): ComplianceResult

Maps your governance configuration against 6 EU AI Act articles and returns a self-assessment score with covered/gap breakdown. (Aliased as `assessCompliance` for backward compatibility.)

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 (Lua Governance Cloud)

import ... from 'governance-sdk'

Enterprise governance runs on Lua Governance Cloud, the hosted product — not a separate npm package. Connect your SDK instance via serverUrl + apiKey on createGovernance(). Adds multi-tenant isolation, RBAC, distributed kill switch, ML injection detection, durable audit chain, approval queue, anomaly detection, and scheduled compliance reports.

createGovernance (remote mode)v0.5.0+enterprisecloud
createGovernance({ serverUrl, apiKey, fallbackMode }): GovernanceInstance

Connect the SDK to Lua Governance Cloud. enforce() and register() POST to the Cloud API instead of running in-process. fallbackMode controls behaviour when the API is unreachable after retries.

Parameters
nametypedescription
serverUrlrequiredstringCloud API base URL (e.g., 'https://api.heygovernance.ai').
apiKeyrequiredstringBearer token for your tenant.
fallbackMode'allow' | 'block'What to do when the API is unreachable. Default 'allow' (fail-open).
timeoutnumberPer-request timeout in ms. Default 30000.
maxRetriesnumberRetry attempts on transient failure. Default 3.
Returns
GovernanceInstanceSame interface as the local SDK — enforce(), register(), audit, eval, recordOutcome — but routed through the Cloud.
Example
ts
Need the full quickstart?

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