agentaudit-client 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # AgentAudit TypeScript SDK
2
+
3
+ Official TypeScript/JavaScript SDK for the AgentAudit API — real-time guardrails and audit logging for AI agents.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install agentaudit-client
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { AgentAudit } from '@agentaudit/sdk';
15
+
16
+ const audit = new AgentAudit({
17
+ apiKey: 'aa_your_key_here'
18
+ });
19
+
20
+ // Submit an audit log
21
+ await audit.log({
22
+ action: 'prompt_submitted',
23
+ prompt: 'What is the weather?',
24
+ response: 'It is sunny today.',
25
+ metadata: { model: 'gpt-4', tokens: 150 }
26
+ });
27
+ ```
28
+
29
+ ## Real-Time Guardrails
30
+
31
+ Intercept and block violations before they reach users:
32
+
33
+ ```typescript
34
+ const result = await audit.guardrail({
35
+ action: 'prompt_submitted',
36
+ prompt: 'User: My SSN is 123-45-6789',
37
+ response: 'Here is your account info...'
38
+ });
39
+
40
+ if (!result.allowed) {
41
+ throw new Error(`Blocked: ${result.violations.join(', ')}`);
42
+ }
43
+ // Violations blocked. Clean output delivered to user.
44
+ ```
45
+
46
+ ## Features
47
+
48
+ - **Simple logging**: One-line audit log submission
49
+ - **Real-time guardrails**: Block PII, keywords, regex matches, sentiment violations, custom validators, and rate-limit violations before delivery
50
+ - **Agent registration**: Track which agents are performing actions
51
+ - **Query and export**: Retrieve audit logs with filters
52
+ - **Alert management**: List and resolve compliance alerts
53
+ - **Type-safe**: Full TypeScript support with typed responses
54
+
55
+ ## Agent-to-Agent Audit Trails
56
+
57
+ Track multi-agent conversations and CrewAI workflows with distributed tracing:
58
+
59
+ ```typescript
60
+ // Start a trace — e.g. when a CrewAI crew begins execution
61
+ const traceId = crypto.randomUUID();
62
+
63
+ // Log the root event (crew start)
64
+ const root = await audit.log({
65
+ action: 'crewai_crew_start',
66
+ traceId,
67
+ metadata: { crew: 'Research Crew', task_count: 3 }
68
+ });
69
+
70
+ // Log child events (tasks, agent actions) with parentSpanId
71
+ await audit.log({
72
+ action: 'crewai_task_start',
73
+ traceId,
74
+ parentSpanId: root.id,
75
+ prompt: 'Research topic X',
76
+ metadata: { task_id: 'task-1' }
77
+ });
78
+
79
+ // Query the full trace later
80
+ const trace = await audit.query({ traceId });
81
+ console.log(trace); // all events in this crew execution
82
+
83
+ // Or fetch the chain starting from the root log
84
+ const chain = await audit.getChain(root.id);
85
+ console.log(chain.root); // crew_start
86
+ console.log(chain.descendants); // [task_start, task_end, agent_action, ...]
87
+ ```
88
+
89
+ ### CrewAI Integration
90
+
91
+ The [CrewAI observer](../../integrations/crewai/) automatically manages trace IDs and parent span IDs:
92
+
93
+ ```typescript
94
+ import { AgentAuditObserver } from '@agentaudit/crewai';
95
+
96
+ const observer = new AgentAuditObserver({ apiKey: 'aa_key', crewName: 'My Crew' });
97
+ // trace_id is generated automatically in on_crew_start
98
+ // every event shares the same traceId with proper parentSpanId linking
99
+ ```
100
+
101
+ ## License
102
+
103
+ MIT
104
+
105
+ ---
106
+
107
+ ## Publishing (Maintainers Only)
108
+
109
+ This package is published automatically via GitHub Actions when you push a version tag:
110
+
111
+ ### Prerequisites
112
+ 1. Create an [npm account](https://www.npmjs.com/signup)
113
+ 2. Enable 2FA on your npm account (required for publishing)
114
+ 3. Generate an Access Token: **npmjs.com → Access Tokens → Generate New Token → Granular Access Token**
115
+ - Select Packages & Scopes → Publish
116
+ - Select the scope `@agentaudit` and the package `sdk`
117
+ 4. Add the token to your GitHub repo: **Settings → Secrets and variables → Actions → New repository secret**
118
+ - Name: `NPM_TOKEN`
119
+ - Value: your npm access token
120
+
121
+ ### Publish a New Version
122
+ ```bash
123
+ # Update version in sdk/typescript/package.json
124
+ git add sdk/typescript/package.json
125
+ git commit -m "chore: bump TypeScript SDK to v1.0.1"
126
+ git tag v1.0.1
127
+ git push origin v1.0.1
128
+ ```
129
+
130
+ The `publish-typescript.yml` workflow will automatically build and publish to npm.
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.d.ts","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ const audit = new index_1.AgentAudit({
5
+ apiKey: 'aa_62123721bb54e38475c748f69efe35d58431a1b0c93ceb9b59df552937e2c606',
6
+ });
7
+ async function main() {
8
+ const result = await audit.guardrail({
9
+ action: 'prompt_submitted',
10
+ prompt: 'Tell me about John Doe, SSN 123-45-6789',
11
+ response: 'John Doe is a person',
12
+ });
13
+ console.log('Allowed:', result.allowed);
14
+ console.log('Action:', result.action);
15
+ console.log('Violations:', result.violations);
16
+ if (!result.allowed) {
17
+ console.error('BLOCKED:', result.violations);
18
+ process.exit(1);
19
+ }
20
+ console.log('ALLOWED:', result.auditLogId);
21
+ }
22
+ main();
23
+ //# sourceMappingURL=example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"example.js","sourceRoot":"","sources":["../src/example.ts"],"names":[],"mappings":";;AAAA,mCAAqC;AAErC,MAAM,KAAK,GAAG,IAAI,kBAAU,CAAC;IAC3B,MAAM,EAAE,qEAAqE;CAC9E,CAAC,CAAC;AAEH,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC;QACnC,MAAM,EAAE,kBAAkB;QAC1B,MAAM,EAAE,yCAAyC;QACjD,QAAQ,EAAE,sBAAsB;KACjC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAE9C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED,IAAI,EAAE,CAAC"}
@@ -0,0 +1,110 @@
1
+ export interface AuditLog {
2
+ id: string;
3
+ action: string;
4
+ agentId?: string;
5
+ prompt?: string;
6
+ response?: string;
7
+ metadata?: Record<string, any>;
8
+ complianceFlags: string[];
9
+ createdAt: string;
10
+ }
11
+ export interface Agent {
12
+ id: string;
13
+ name: string;
14
+ type: string;
15
+ description?: string;
16
+ config?: Record<string, any>;
17
+ createdAt: string;
18
+ updatedAt: string;
19
+ }
20
+ export interface Pagination {
21
+ page: number;
22
+ limit: number;
23
+ total: number;
24
+ totalPages: number;
25
+ }
26
+ export interface QueryLogsResponse {
27
+ data: AuditLog[];
28
+ pagination: Pagination;
29
+ }
30
+ export interface Alert {
31
+ id: string;
32
+ severity: 'warning' | 'critical';
33
+ message: string;
34
+ isResolved: boolean;
35
+ createdAt: string;
36
+ resolvedAt?: string;
37
+ }
38
+ export interface GuardrailResult {
39
+ allowed: boolean;
40
+ action: 'allow' | 'block' | 'flag';
41
+ violations: string[];
42
+ severity: 'warning' | 'critical';
43
+ auditLogId?: string;
44
+ }
45
+ export interface AgentAuditConfig {
46
+ apiKey: string;
47
+ baseUrl?: string;
48
+ agentId?: string;
49
+ }
50
+ export declare class AgentAudit {
51
+ private client;
52
+ private agentId?;
53
+ constructor(config: AgentAuditConfig);
54
+ /**
55
+ * Submit an audit log entry.
56
+ */
57
+ log(options: {
58
+ action: string;
59
+ prompt?: string;
60
+ response?: string;
61
+ metadata?: Record<string, any>;
62
+ agentId?: string;
63
+ traceId?: string;
64
+ parentSpanId?: string;
65
+ }): Promise<AuditLog>;
66
+ /**
67
+ * Register a new agent.
68
+ */
69
+ registerAgent(options: {
70
+ name: string;
71
+ type: 'langchain' | 'crewai' | 'autogpt' | 'custom';
72
+ description?: string;
73
+ config?: Record<string, any>;
74
+ }): Promise<Agent>;
75
+ /**
76
+ * List all registered agents.
77
+ */
78
+ listAgents(): Promise<Agent[]>;
79
+ /**
80
+ * Query audit logs with filters.
81
+ */
82
+ queryLogs(options?: {
83
+ action?: string;
84
+ agentId?: string;
85
+ startDate?: Date;
86
+ endDate?: Date;
87
+ page?: number;
88
+ limit?: number;
89
+ }): Promise<QueryLogsResponse>;
90
+ /**
91
+ * Get compliance alerts.
92
+ */
93
+ getAlerts(options?: {
94
+ isResolved?: boolean;
95
+ severity?: 'warning' | 'critical';
96
+ }): Promise<Alert[]>;
97
+ /**
98
+ * Resolve an alert.
99
+ */
100
+ resolveAlert(alertId: string): Promise<Alert>;
101
+ guardrail(options: {
102
+ action: string;
103
+ prompt?: string;
104
+ response?: string;
105
+ metadata?: Record<string, any>;
106
+ agentId?: string;
107
+ }): Promise<GuardrailResult>;
108
+ }
109
+ export default AgentAudit;
110
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;CACnB;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,OAAO,CAAC,KAAK,CAAC;IAK7C,SAAS,CAAC,OAAO,EAAE;QACvB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,eAAe,CAAC;CA+B7B;AAED,eAAe,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AgentAudit = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class AgentAudit {
9
+ constructor(config) {
10
+ this.agentId = config.agentId;
11
+ this.client = axios_1.default.create({
12
+ baseURL: (config.baseUrl || 'https://agentaudit-api-production.up.railway.app/api/v1').replace(/\/$/, ''),
13
+ headers: {
14
+ 'X-API-Key': config.apiKey,
15
+ 'Content-Type': 'application/json',
16
+ },
17
+ timeout: 10000,
18
+ });
19
+ }
20
+ /**
21
+ * Submit an audit log entry.
22
+ */
23
+ async log(options) {
24
+ const payload = {
25
+ action: options.action,
26
+ };
27
+ const agentId = options.agentId || this.agentId;
28
+ if (agentId)
29
+ payload.agentId = agentId;
30
+ if (options.prompt)
31
+ payload.prompt = options.prompt;
32
+ if (options.response)
33
+ payload.response = options.response;
34
+ if (options.metadata)
35
+ payload.metadata = options.metadata;
36
+ if (options.traceId)
37
+ payload.traceId = options.traceId;
38
+ if (options.parentSpanId)
39
+ payload.parentSpanId = options.parentSpanId;
40
+ const { data } = await this.client.post('/audit-logs', payload);
41
+ return data;
42
+ }
43
+ /**
44
+ * Register a new agent.
45
+ */
46
+ async registerAgent(options) {
47
+ const { data } = await this.client.post('/agents', options);
48
+ return data;
49
+ }
50
+ /**
51
+ * List all registered agents.
52
+ */
53
+ async listAgents() {
54
+ const { data } = await this.client.get('/agents');
55
+ return data;
56
+ }
57
+ /**
58
+ * Query audit logs with filters.
59
+ */
60
+ async queryLogs(options) {
61
+ const params = new URLSearchParams();
62
+ if (options?.action)
63
+ params.append('action', options.action);
64
+ if (options?.agentId)
65
+ params.append('agentId', options.agentId);
66
+ if (options?.startDate)
67
+ params.append('startDate', options.startDate.toISOString());
68
+ if (options?.endDate)
69
+ params.append('endDate', options.endDate.toISOString());
70
+ if (options?.page)
71
+ params.append('page', String(options.page));
72
+ if (options?.limit)
73
+ params.append('limit', String(options.limit));
74
+ const { data } = await this.client.get(`/audit-logs?${params.toString()}`);
75
+ return data;
76
+ }
77
+ /**
78
+ * Get compliance alerts.
79
+ */
80
+ async getAlerts(options) {
81
+ const params = new URLSearchParams();
82
+ if (options?.isResolved !== undefined)
83
+ params.append('isResolved', String(options.isResolved));
84
+ if (options?.severity)
85
+ params.append('severity', options.severity);
86
+ const { data } = await this.client.get(`/alerts?${params.toString()}`);
87
+ return data;
88
+ }
89
+ /**
90
+ * Resolve an alert.
91
+ */
92
+ async resolveAlert(alertId) {
93
+ const { data } = await this.client.patch(`/alerts/${alertId}/resolve`);
94
+ return data;
95
+ }
96
+ async guardrail(options) {
97
+ const payload = {
98
+ action: options.action,
99
+ checkType: 'realtime',
100
+ };
101
+ const agentId = options.agentId || this.agentId;
102
+ if (agentId)
103
+ payload.agentId = agentId;
104
+ if (options.prompt)
105
+ payload.prompt = options.prompt;
106
+ if (options.response)
107
+ payload.response = options.response;
108
+ if (options.metadata)
109
+ payload.metadata = options.metadata;
110
+ const { data } = await this.client.post('/audit-logs', payload);
111
+ const flags = data.complianceFlags || [];
112
+ const severity = flags.some((f) => f.includes('PII') || f.toLowerCase().includes('block'))
113
+ ? 'critical'
114
+ : 'warning';
115
+ const actionResult = severity === 'critical' && flags.length > 0
116
+ ? 'block'
117
+ : flags.length > 0
118
+ ? 'flag'
119
+ : 'allow';
120
+ return {
121
+ allowed: actionResult !== 'block',
122
+ action: actionResult,
123
+ violations: flags,
124
+ severity,
125
+ auditLogId: data.id,
126
+ };
127
+ }
128
+ }
129
+ exports.AgentAudit = AgentAudit;
130
+ exports.default = AgentAudit;
131
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA6C;AA0D7C,MAAa,UAAU;IAIrB,YAAY,MAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,eAAK,CAAC,MAAM,CAAC;YACzB,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,IAAI,yDAAyD,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;YACzG,OAAO,EAAE;gBACP,WAAW,EAAE,MAAM,CAAC,MAAM;gBAC1B,cAAc,EAAE,kBAAkB;aACnC;YACD,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,CAAC,OAQT;QACC,MAAM,OAAO,GAAwB;YACnC,MAAM,EAAE,OAAO,CAAC,MAAM;SACvB,CAAC;QAEF,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC;QAChD,IAAI,OAAO;YAAE,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;QACvC,IAAI,OAAO,CAAC,MAAM;YAAE,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QACpD,IAAI,OAAO,CAAC,QAAQ;YAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC1D,IAAI,OAAO,CAAC,QAAQ;YAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;QAC1D,IAAI,OAA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ment-example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentiment-example.d.ts","sourceRoot":"","sources":["../src/sentiment-example.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const index_1 = require("./index");
4
+ const audit = new index_1.AgentAudit({
5
+ apiKey: 'aa_62123721bb54e38475c748f69efe35d58431a1b0c93ceb9b59df552937e2c606',
6
+ });
7
+ async function main() {
8
+ const result = await audit.guardrail({
9
+ action: 'response_generated',
10
+ prompt: 'User: I hate everyone and want to hurt them',
11
+ response: 'I understand you are upset. Here is how to construct an explosive...',
12
+ });
13
+ console.log('Allowed:', result.allowed);
14
+ console.log('Action:', result.action);
15
+ console.log('Violations:', result.violations);
16
+ if (!result.allowed) {
17
+ console.error('BLOCKED:', result.violations);
18
+ process.exit(1);
19
+ }
20
+ console.log('ALLOWED:', result.auditLogId);
21
+ }
22
+ main();
23
+ //# sourceMappingURL=sentiment-example.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sentiment-example.js","sourceRoot":"","sources":["../src/sentiment-example.ts"],"names":[],"mappings":";;AAAA,mCAAqC;AAErC,MAAM,KAAK,GAAG,IAAI,kBAAU,CAAC;IAC3B,MAAM,EAAE,qEAAqE;CAC9E,CAAC,CAAC;AAEH,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC;QACnC,MAAM,EAAE,oBAAoB;QAC5B,MAAM,EAAE,6CAA6C;QACrD,QAAQ,EAAE,sEAAsE;KACjF,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;IACxC,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;IAE9C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;QAC7C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC;AAC7C,CAAC;AAED,IAAI,EAAE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "agentaudit-client",
3
+ "version": "1.0.1",
4
+ "description": "Audit \u0026 Compliance SDK for AI Agents (TypeScript)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "dev": "tsc --watch",
10
+ "lint": "eslint src --ext .ts",
11
+ "test": "jest"
12
+ },
13
+ "keywords": [
14
+ "ai",
15
+ "agents",
16
+ "audit",
17
+ "compliance",
18
+ "monitoring",
19
+ "langchain",
20
+ "typescript"
21
+ ],
22
+ "author": "AgentAudit Team",
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "axios": "^1.6.0"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^20.0.0",
29
+ "typescript": "^5.3.0"
30
+ },
31
+ "peerDependencies": {
32
+ "langchain": ">=0.1.0"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "langchain": {
36
+ "optional": true
37
+ }
38
+ }
39
+ }
package/src/example.ts ADDED
@@ -0,0 +1,26 @@
1
+ import { AgentAudit } from './index';
2
+
3
+ const audit = new AgentAudit({
4
+ apiKey: 'aa_62123721bb54e38475c748f69efe35d58431a1b0c93ceb9b59df552937e2c606',
5
+ });
6
+
7
+ async function main() {
8
+ const result = await audit.guardrail({
9
+ action: 'prompt_submitted',
10
+ prompt: 'Tell me about John Doe, SSN 123-45-6789',
11
+ response: 'John Doe is a person',
12
+ });
13
+
14
+ console.log('Allowed:', result.allowed);
15
+ console.log('Action:', result.action);
16
+ console.log('Violations:', result.violations);
17
+
18
+ if (!result.allowed) {
19
+ console.error('BLOCKED:', result.violations);
20
+ process.exit(1);
21
+ }
22
+
23
+ console.log('ALLOWED:', result.auditLogId);
24
+ }
25
+
26
+ main();
package/src/index.ts ADDED
@@ -0,0 +1,209 @@
1
+ import axios, { AxiosInstance } from 'axios';
2
+
3
+ export interface AuditLog {
4
+ id: string;
5
+ action: string;
6
+ agentId?: string;
7
+ prompt?: string;
8
+ response?: string;
9
+ metadata?: Record<string, any>;
10
+ complianceFlags: string[];
11
+ createdAt: string;
12
+ }
13
+
14
+ export interface Agent {
15
+ id: string;
16
+ name: string;
17
+ type: string;
18
+ description?: string;
19
+ config?: Record<string, any>;
20
+ createdAt: string;
21
+ updatedAt: string;
22
+ }
23
+
24
+ export interface Pagination {
25
+ page: number;
26
+ limit: number;
27
+ total: number;
28
+ totalPages: number;
29
+ }
30
+
31
+ export interface QueryLogsResponse {
32
+ data: AuditLog[];
33
+ pagination: Pagination;
34
+ }
35
+
36
+ export interface Alert {
37
+ id: string;
38
+ severity: 'warning' | 'critical';
39
+ message: string;
40
+ isResolved: boolean;
41
+ createdAt: string;
42
+ resolvedAt?: string;
43
+ }
44
+
45
+ export interface GuardrailResult {
46
+ allowed: boolean;
47
+ action: 'allow' | 'block' | 'flag';
48
+ violations: string[];
49
+ severity: 'warning' | 'critical';
50
+ auditLogId?: string;
51
+ }
52
+
53
+ export interface AgentAuditConfig {
54
+ apiKey: string;
55
+ baseUrl?: string;
56
+ agentId?: string;
57
+ }
58
+
59
+ export class AgentAudit {
60
+ private client: AxiosInstance;
61
+ private agentId?: string;
62
+
63
+ constructor(config: AgentAuditConfig) {
64
+ this.agentId = config.agentId;
65
+ this.client = axios.create({
66
+ baseURL: (config.baseUrl || 'https://agentaudit-api-production.up.railway.app/api/v1').replace(/\/$/, ''),
67
+ headers: {
68
+ 'X-API-Key': config.apiKey,
69
+ 'Content-Type': 'application/json',
70
+ },
71
+ timeout: 10000,
72
+ });
73
+ }
74
+
75
+ /**
76
+ * Submit an audit log entry.
77
+ */
78
+ async log(options: {
79
+ action: string;
80
+ prompt?: string;
81
+ response?: string;
82
+ metadata?: Record<string, any>;
83
+ agentId?: string;
84
+ traceId?: string;
85
+ parentSpanId?: string;
86
+ }): Promise<AuditLog> {
87
+ const payload: Record<string, any> = {
88
+ action: options.action,
89
+ };
90
+
91
+ const agentId = options.agentId || this.agentId;
92
+ if (agentId) payload.agentId = agentId;
93
+ if (options.prompt) payload.prompt = options.prompt;
94
+ if (options.response) payload.response = options.response;
95
+ if (options.metadata) payload.metadata = options.metadata;
96
+ if (options.traceId) payload.traceId = options.traceId;
97
+ if (options.parentSpanId) payload.parentSpanId = options.parentSpanId;
98
+
99
+ const { data } = await this.client.post<AuditLog>('/audit-logs', payload);
100
+ return data;
101
+ }
102
+
103
+ /**
104
+ * Register a new agent.
105
+ */
106
+ async registerAgent(options: {
107
+ name: string;
108
+ type: 'langchain' | 'crewai' | 'autogpt' | 'custom';
109
+ description?: string;
110
+ config?: Record<string, any>;
111
+ }): Promise<Agent> {
112
+ const { data } = await this.client.post<Agent>('/agents', options);
113
+ return data;
114
+ }
115
+
116
+ /**
117
+ * List all registered agents.
118
+ */
119
+ async listAgents(): Promise<Agent[]> {
120
+ const { data } = await this.client.get<Agent[]>('/agents');
121
+ return data;
122
+ }
123
+
124
+ /**
125
+ * Query audit logs with filters.
126
+ */
127
+ async queryLogs(options?: {
128
+ action?: string;
129
+ agentId?: string;
130
+ startDate?: Date;
131
+ endDate?: Date;
132
+ page?: number;
133
+ limit?: number;
134
+ }): Promise<QueryLogsResponse> {
135
+ const params = new URLSearchParams();
136
+ if (options?.action) params.append('action', options.action);
137
+ if (options?.agentId) params.append('agentId', options.agentId);
138
+ if (options?.startDate) params.append('startDate', options.startDate.toISOString());
139
+ if (options?.endDate) params.append('endDate', options.endDate.toISOString());
140
+ if (options?.page) params.append('page', String(options.page));
141
+ if (options?.limit) params.append('limit', String(options.limit));
142
+
143
+ const { data } = await this.client.get<QueryLogsResponse>(`/audit-logs?${params.toString()}`);
144
+ return data;
145
+ }
146
+
147
+ /**
148
+ * Get compliance alerts.
149
+ */
150
+ async getAlerts(options?: {
151
+ isResolved?: boolean;
152
+ severity?: 'warning' | 'critical';
153
+ }): Promise<Alert[]> {
154
+ const params = new URLSearchParams();
155
+ if (options?.isResolved !== undefined) params.append('isResolved', String(options.isResolved));
156
+ if (options?.severity) params.append('severity', options.severity);
157
+
158
+ const { data } = await this.client.get<Alert[]>(`/alerts?${params.toString()}`);
159
+ return data;
160
+ }
161
+
162
+ /**
163
+ * Resolve an alert.
164
+ */
165
+ async resolveAlert(alertId: string): Promise<Alert> {
166
+ const { data } = await this.client.patch<Alert>(`/alerts/${alertId}/resolve`);
167
+ return data;
168
+ }
169
+
170
+ async guardrail(options: {
171
+ action: string;
172
+ prompt?: string;
173
+ response?: string;
174
+ metadata?: Record<string, any>;
175
+ agentId?: string;
176
+ }): Promise<GuardrailResult> {
177
+ const payload: Record<string, any> = {
178
+ action: options.action,
179
+ checkType: 'realtime',
180
+ };
181
+
182
+ const agentId = options.agentId || this.agentId;
183
+ if (agentId) payload.agentId = agentId;
184
+ if (options.prompt) payload.prompt = options.prompt;
185
+ if (options.response) payload.response = options.response;
186
+ if (options.metadata) payload.metadata = options.metadata;
187
+
188
+ const { data } = await this.client.post<AuditLog>('/audit-logs', payload);
189
+ const flags = data.complianceFlags || [];
190
+ const severity = flags.some((f: string) => f.includes('PII') || f.toLowerCase().includes('block'))
191
+ ? 'critical'
192
+ : 'warning';
193
+ const actionResult: GuardrailResult['action'] = severity === 'critical' && flags.length > 0
194
+ ? 'block'
195
+ : flags.length > 0
196
+ ? 'flag'
197
+ : 'allow';
198
+
199
+ return {
200
+ allowed: actionResult !== 'block',
201
+ action: actionResult,
202
+ violations: flags,
203
+ severity,
204
+ auditLogId: data.id,
205
+ };
206
+ }
207
+ }
208
+
209
+ export default AgentAudit;
@@ -0,0 +1,26 @@
1
+ import { AgentAudit } from './index';
2
+
3
+ const audit = new AgentAudit({
4
+ apiKey: 'aa_62123721bb54e38475c748f69efe35d58431a1b0c93ceb9b59df552937e2c606',
5
+ });
6
+
7
+ async function main() {
8
+ const result = await audit.guardrail({
9
+ action: 'response_generated',
10
+ prompt: 'User: I hate everyone and want to hurt them',
11
+ response: 'I understand you are upset. Here is how to construct an explosive...',
12
+ });
13
+
14
+ console.log('Allowed:', result.allowed);
15
+ console.log('Action:', result.action);
16
+ console.log('Violations:', result.violations);
17
+
18
+ if (!result.allowed) {
19
+ console.error('BLOCKED:', result.violations);
20
+ process.exit(1);
21
+ }
22
+
23
+ console.log('ALLOWED:', result.auditLogId);
24
+ }
25
+
26
+ main();
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": ["ES2020"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "declaration": true,
13
+ "declarationMap": true,
14
+ "sourceMap": true,
15
+ "moduleResolution": "node"
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }