@vaspera/guard
TypeScript SDK for VasperaGuard - AI Agent Safety & Governance.
Installation
npm install @vaspera/guard
yarn add @vaspera/guard
pnpm add @vaspera/guard
Quick Start
import { Guard } from '@vaspera/guard';
const guard = new Guard({ apiKey: 'vg_...' });
const result = await guard.check('rm -rf ./temp');
if (result.allowed) {
console.log('Command is safe to execute');
} else if (result.requiresApproval) {
console.log('Command requires human approval');
const approval = await guard.requestApproval(result.checkId, {
channel: 'slack',
slackChannel: '#devops-approvals'
});
} else {
console.log('Command blocked:', result.reason);
console.log('Suggestions:', result.suggestions);
}
Features
- Command Safety Analysis - Check commands before execution
- Human-in-the-Loop Approval - Request approval via Slack, email, or webhook
- Policy Management - Create and manage safety policies
- Audit Trail - Query audit logs for compliance
- TypeScript First - Full type definitions included
API Reference
Constructor
const guard = new Guard({
apiKey: 'vg_...',
baseUrl: 'https://...',
timeout: 30000,
environment: 'production',
project: 'my-app',
policies: ['policy-1']
});
Check Command
const result = await guard.check('npm run build', {
agentId: 'my-agent',
context: {
environment: 'production',
project: 'backend-api'
}
});
{
allowed: boolean;
blocked: boolean;
requiresApproval: boolean;
riskScore: number;
riskLevel: 'low' | 'medium' | 'high' | 'critical';
reason: string;
suggestions: string[];
patterns: string[];
nearMisses: NearMiss[];
checkId: string;
timestamp: string;
}
Check and Execute
import { execSync } from 'child_process';
const { result, check } = await guard.checkAndExecute(
'ls -la',
async (cmd) => execSync(cmd).toString()
);
Request Approval
const approval = await guard.requestApproval(checkId, {
channel: 'slack',
slackChannel: '#devops',
timeoutMinutes: 30
});
const approval = await guard.requestApproval(checkId, {
channel: 'email',
emails: ['admin@company.com'],
timeoutMinutes: 60
});
const approval = await guard.requestApproval(checkId, {
channel: 'webhook',
webhookUrl: 'https://your-app.com/webhooks/approval',
webhookHeaders: { 'X-Custom-Header': 'value' }
});
Wait for Approval
const approval = await guard.waitForApproval(approvalId, {
timeoutMs: 300000,
pollIntervalMs: 5000
});
if (approval.status === 'approved') {
}
Policy Management
const policy = await guard.createPolicy({
name: 'production-safety',
rules: [
{ pattern: 'DROP TABLE', action: 'block' },
{ pattern: 'rm -rf /', action: 'block' },
{ pattern: 'chmod 777', action: 'require_approval' }
]
});
const policies = await guard.getPolicies();
const policy = await guard.getPolicy('policy-id');
await guard.deletePolicy('policy-id');
Audit Log
const audit = await guard.getAuditLog({
limit: 100,
riskLevel: 'critical',
agentId: 'my-agent',
startDate: '2024-01-01T00:00:00Z'
});
for (const entry of audit.entries) {
console.log(entry.command, entry.riskLevel, entry.checkResult);
}
Error Handling
import {
Guard,
GuardError,
AuthenticationError,
RateLimitError
} from '@vaspera/guard';
try {
await guard.check('some command');
} catch (error) {
if (error instanceof AuthenticationError) {
console.log('Invalid API key');
} else if (error instanceof RateLimitError) {
console.log('Rate limited, retry after:', error.retryAfter);
} else if (error instanceof GuardError) {
console.log('API error:', error.code, error.message);
}
}
License
MIT