ai-sentinel-sdk
v0.1.4
Published
Standalone SDK for building AI security middleware. ML classification (ONNX), custom blocklist and regex rules, SQLite audit logging, and Prometheus metrics. Works with any Node.js gateway or framework.
Maintainers
Readme
ai-sentinel-sdk
AI Sentinel SDK for OpenClaw — prompt injection detection and defense-in-depth protection for agentic AI gateways.
Installation
npm install ai-sentinel-sdkQuick Start
import { AISentinel } from 'ai-sentinel-sdk';
const sentinel = new AISentinel({
classifier: {
mode: 'hybrid',
localModelPath: './models/sentinel-v1.onnx',
remoteEndpoint: 'https://api.zetro.ai/v1/classify',
remoteApiKey: process.env.AI_SENTINEL_API_KEY,
timeout: 500,
},
thresholds: {
default: 0.7,
channels: {
email: 0.6,
slack: 0.75,
},
},
policy: {
onDetection: 'block',
onClassifierFailure: 'block',
},
audit: {
enabled: true,
destination: 'sqlite',
path: './data/sentinel-audit.db',
retentionDays: 30,
},
});
await sentinel.initialize();
// Classify a message
const result = await sentinel.classify('Hello, how are you?', {
type: 'message',
channel: 'whatsapp',
senderTrusted: false,
});
console.log(result.action); // 'allowed'
console.log(result.score); // 0.0OpenClaw Integration
import { AISentinel } from 'ai-sentinel-sdk';
const sentinel = new AISentinel({ /* config */ });
await sentinel.initialize();
const middleware = sentinel.createMiddleware();
export default {
middleware: {
message: [middleware.messageHandler()],
toolOutput: [middleware.toolOutputHandler()],
documentIngestion: [middleware.documentHandler()],
},
hooks: {
onSkillInstall: middleware.skillInstallHandler(),
},
};Custom Rules
// Add a blocklist rule (all tiers)
await sentinel.addBlocklistRule({
name: 'block-competitor',
type: 'substring',
pattern: 'switch to ChatGPT',
caseSensitive: false,
});
// Add a regex rule (Pro+ only)
await sentinel.addRegexRule({
name: 'base64-injection',
pattern: '(?:[A-Za-z0-9+/]{50,})={0,2}',
maxScore: 0.4,
});
// Test a rule before adding
const validation = await sentinel.testRule({
name: 'test',
type: 'substring',
pattern: 'ignore previous',
});
console.log(`FP rate: ${(validation.falsePositiveRate * 100).toFixed(1)}%`);Testing
import { AISentinel, testPayloads } from 'ai-sentinel-sdk';
const sentinel = new AISentinel({ /* config */ });
await sentinel.initialize();
for (const payload of testPayloads.injections) {
const result = await sentinel.classify(payload.content, payload.source);
assert(result.action === 'blocked', `Failed: ${payload.name}`);
}
for (const payload of testPayloads.benign) {
const result = await sentinel.classify(payload.content, payload.source);
assert(result.action === 'allowed', `False positive: ${payload.name}`);
}Product Tiers
| Feature | Community (Free) | Pro ($29/mo) | Enterprise | |---------|:---:|:---:|:---:| | Core SDK & middleware | ✓ | ✓ | ✓ | | Local ONNX model | ✓ | ✓ | ✓ | | SQLite audit logging | ✓ | ✓ | ✓ | | Prometheus metrics | ✓ | ✓ | ✓ | | Custom blocklist rules | ✓ (50 max) | ✓ (200 max) | Unlimited | | Regex rules | — | ✓ | ✓ | | Per-channel thresholds | — | ✓ | ✓ | | Web dashboard | — | ✓ | ✓ | | SOC/SIEM integrations | — | — | ✓ |
License
Apache-2.0
