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+corecreateGovernance(config: GovernanceConfig): GovernanceCreates a new governance instance with the provided configuration. The instance is the central object for all policy enforcement, agent registration, and audit logging.
| name | type | description |
|---|---|---|
config.rules | PolicyRule[] | Array of policy rules to evaluate on every enforce() call. |
config.storage | StorageAdapter | Storage backend. Defaults to in-memory. Use postgresStorage() for persistence. |
config.signingKey | string | HMAC signing key for tamper-evident audit chains. |
Governance— Governance instance with register(), enforce(), kill(), and on() methods.gov.registerv0.1.0+coregov.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.
| name | type | description |
|---|---|---|
agent.namerequired | string | Unique identifier for the agent. |
agent.framework | 'mastra' | 'vercel-ai' | 'langchain' | 'openai' | Framework the agent uses. |
agent.tools | string[] | List of tool names the agent can access. |
agent.hasAuth | boolean | Whether the agent has authentication enabled. |
agent.hasGuardrails | boolean | Whether the agent has guardrails configured. |
Promise<RegisteredAgent>— Registered agent with id, score, level, status, and assessment fields.gov.enforcev0.1.0+coreenforcementgov.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.
| name | type | description |
|---|---|---|
agentIdrequired | string | ID of the agent requesting the action (from gov.register()). |
action.toolrequired | string | Name of the tool being called. |
action.params | Record<string, unknown> | Tool parameters, logged to audit trail. |
Promise<EnforceResult>— { outcome: 'allow' | 'block', rule?: string, reason?: string, latencyMs: number }createKillSwitchv0.2.0+kill-switchcreateKillSwitch(gov: Governance): KillSwitchCreates 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.
| name | type | description |
|---|---|---|
govrequired | Governance | Governance instance from createGovernance(). |
KillSwitch— Kill switch with kill(), killAll(), revive(), reviveAll(), isKilled(), and getKillRecords() methods.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+securitydetectInjection(input: string): InjectionResultSynchronously scans a string for prompt injection patterns across 7 categories. Returns detection status, category, matched pattern, and confidence score.
| name | type | description |
|---|---|---|
inputrequired | string | User-provided string to scan. |
InjectionResult— { detected: boolean, category?: string, pattern?: string, score: number }Audit Integrity
import ... from 'governance-sdk/audit-integrity'HMAC-SHA256 hash-chained audit trail. Tamper detection with exact broken-link location.
createIntegrityChainv0.3.0+auditsecuritycreateIntegrityChain(config: ChainConfig): IntegrityChainCreates an HMAC-SHA256 hash-chained audit log. Each event includes the hash of the previous, making any modification detectable via chain.verify().
| name | type | description |
|---|---|---|
config.signingKeyrequired | string | Secret key for HMAC computation. Keep in environment variables. |
config.storage | StorageAdapter | Where to persist events. Defaults to in-memory. |
IntegrityChain— Chain with append(), verify(), and export() methods.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+compliancemapToEuAiAct(config: ComplianceConfig): ComplianceResultMaps 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.)
| name | type | description |
|---|---|---|
config.hasPolicies | boolean | Whether policy rules are configured (Article 9, 15). |
config.hasAuditTrail | boolean | Whether HMAC audit chain is enabled (Article 12). |
config.hasRequireApproval | boolean | Whether human oversight gates are active (Article 14). |
config.registeredAgents | number | Number of agents registered via gov.register() (Article 11). |
ComplianceResult— { score: number, covered: string[], gaps: string[], articles: ArticleStatus[] }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+enterprisecloudcreateGovernance({ serverUrl, apiKey, fallbackMode }): GovernanceInstanceConnect 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.
| name | type | description |
|---|---|---|
serverUrlrequired | string | Cloud API base URL (e.g., 'https://api.heygovernance.ai'). |
apiKeyrequired | string | Bearer token for your tenant. |
fallbackMode | 'allow' | 'block' | What to do when the API is unreachable. Default 'allow' (fail-open). |
timeout | number | Per-request timeout in ms. Default 30000. |
maxRetries | number | Retry attempts on transient failure. Default 3. |
GovernanceInstance— Same interface as the local SDK — enforce(), register(), audit, eval, recordOutcome — but routed through the Cloud.8-step setup guide with adapter examples and policy templates.