@aumos/agentshield 0.1.0
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 +139 -0
- package/dist/client.d.ts +87 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +110 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/scanner.d.ts +60 -0
- package/dist/scanner.d.ts.map +1 -0
- package/dist/scanner.js +208 -0
- package/dist/scanner.js.map +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/package.json +34 -0
- package/src/client.ts +240 -0
- package/src/index.ts +27 -0
- package/src/scanner.ts +338 -0
- package/src/types.ts +149 -0
- package/tsconfig.json +25 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript interfaces for the AgentShield defense layer.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Pydantic models defined in:
|
|
5
|
+
* agentshield.schemas.threats
|
|
6
|
+
* agentshield.schemas.scan
|
|
7
|
+
* agentshield.schemas.defense
|
|
8
|
+
*
|
|
9
|
+
* All interfaces use readonly fields to match Python's frozen Pydantic models.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Severity level of a detected threat.
|
|
13
|
+
* Maps to ThreatLevel enum in Python.
|
|
14
|
+
*/
|
|
15
|
+
export type ThreatLevel = "critical" | "high" | "medium" | "low" | "info";
|
|
16
|
+
/**
|
|
17
|
+
* The layer of the defense pipeline that produced a finding.
|
|
18
|
+
* Maps to DefenseLayer enum in Python.
|
|
19
|
+
*/
|
|
20
|
+
export type DefenseLayer = "input_validation" | "output_validation" | "tool_call_validation" | "pii_detection" | "prompt_injection" | "malicious_payload";
|
|
21
|
+
/** A single threat or anomaly detected by one defense rule. */
|
|
22
|
+
export interface ThreatFinding {
|
|
23
|
+
/** Unique identifier for this finding. */
|
|
24
|
+
readonly finding_id: string;
|
|
25
|
+
/** Defense layer that produced this finding. */
|
|
26
|
+
readonly layer: DefenseLayer;
|
|
27
|
+
/** Threat severity. */
|
|
28
|
+
readonly level: ThreatLevel;
|
|
29
|
+
/** Short rule identifier (e.g. "PI-001", "PII-EMAIL"). */
|
|
30
|
+
readonly rule_id: string;
|
|
31
|
+
/** Human-readable description of the finding. */
|
|
32
|
+
readonly description: string;
|
|
33
|
+
/** Character offset in the scanned content where the issue begins (-1 if not applicable). */
|
|
34
|
+
readonly offset: number;
|
|
35
|
+
/** Redacted excerpt of the offending content (never the raw payload). */
|
|
36
|
+
readonly excerpt: string;
|
|
37
|
+
/** Arbitrary metadata from the rule implementation. */
|
|
38
|
+
readonly metadata: Readonly<Record<string, unknown>>;
|
|
39
|
+
}
|
|
40
|
+
/** Result of scanning a single piece of content through the defense pipeline. */
|
|
41
|
+
export interface ScanResult {
|
|
42
|
+
/** Unique identifier for this scan operation. */
|
|
43
|
+
readonly scan_id: string;
|
|
44
|
+
/** ISO-8601 UTC timestamp of when the scan completed. */
|
|
45
|
+
readonly scanned_at: string;
|
|
46
|
+
/** Agent that triggered the scan. */
|
|
47
|
+
readonly agent_id: string;
|
|
48
|
+
/** Whether any finding at level "high" or "critical" was detected. */
|
|
49
|
+
readonly blocked: boolean;
|
|
50
|
+
/** All findings produced by the scan, ordered by severity descending. */
|
|
51
|
+
readonly findings: readonly ThreatFinding[];
|
|
52
|
+
/** Highest threat level across all findings ("info" when no threats found). */
|
|
53
|
+
readonly max_level: ThreatLevel;
|
|
54
|
+
/** Total scan duration in milliseconds. */
|
|
55
|
+
readonly duration_ms: number;
|
|
56
|
+
}
|
|
57
|
+
/** Aggregated threat statistics for a single agent over a time window. */
|
|
58
|
+
export interface ThreatDetectionResult {
|
|
59
|
+
/** Agent being reported on. */
|
|
60
|
+
readonly agent_id: string;
|
|
61
|
+
/** ISO-8601 UTC start of the reporting window. */
|
|
62
|
+
readonly window_start: string;
|
|
63
|
+
/** ISO-8601 UTC end of the reporting window. */
|
|
64
|
+
readonly window_end: string;
|
|
65
|
+
/** Total number of scans in this window. */
|
|
66
|
+
readonly total_scans: number;
|
|
67
|
+
/** Number of scans that triggered a block action. */
|
|
68
|
+
readonly blocked_count: number;
|
|
69
|
+
/** Breakdown of finding counts by threat level. */
|
|
70
|
+
readonly findings_by_level: Readonly<Record<ThreatLevel, number>>;
|
|
71
|
+
/** Breakdown of finding counts by defense layer. */
|
|
72
|
+
readonly findings_by_layer: Readonly<Record<DefenseLayer, number>>;
|
|
73
|
+
/** Most frequently triggered rule_ids in this window. */
|
|
74
|
+
readonly top_rules: readonly string[];
|
|
75
|
+
}
|
|
76
|
+
/** Request to validate a proposed tool call before execution. */
|
|
77
|
+
export interface ToolCallValidationRequest {
|
|
78
|
+
/** Agent submitting the tool call. */
|
|
79
|
+
readonly agent_id: string;
|
|
80
|
+
/** Name of the tool being called. */
|
|
81
|
+
readonly tool_name: string;
|
|
82
|
+
/** Arguments that will be passed to the tool. */
|
|
83
|
+
readonly tool_arguments: Readonly<Record<string, unknown>>;
|
|
84
|
+
/** Optional session context for policy decisions. */
|
|
85
|
+
readonly session_id?: string;
|
|
86
|
+
}
|
|
87
|
+
/** Outcome of a tool-call validation check. */
|
|
88
|
+
export interface ToolCallValidationResult {
|
|
89
|
+
/** Whether the tool call is permitted to proceed. */
|
|
90
|
+
readonly allowed: boolean;
|
|
91
|
+
/** Reason the call was blocked, or null if allowed. */
|
|
92
|
+
readonly block_reason: string | null;
|
|
93
|
+
/** Findings raised during validation. */
|
|
94
|
+
readonly findings: readonly ThreatFinding[];
|
|
95
|
+
/** Validation duration in milliseconds. */
|
|
96
|
+
readonly duration_ms: number;
|
|
97
|
+
}
|
|
98
|
+
/** Standard error payload returned by the AgentShield API. */
|
|
99
|
+
export interface ApiError {
|
|
100
|
+
readonly error: string;
|
|
101
|
+
readonly detail: string;
|
|
102
|
+
}
|
|
103
|
+
/** Result type for all client operations. */
|
|
104
|
+
export type ApiResult<T> = {
|
|
105
|
+
readonly ok: true;
|
|
106
|
+
readonly data: T;
|
|
107
|
+
} | {
|
|
108
|
+
readonly ok: false;
|
|
109
|
+
readonly error: ApiError;
|
|
110
|
+
readonly status: number;
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"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"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript interfaces for the AgentShield defense layer.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Pydantic models defined in:
|
|
5
|
+
* agentshield.schemas.threats
|
|
6
|
+
* agentshield.schemas.scan
|
|
7
|
+
* agentshield.schemas.defense
|
|
8
|
+
*
|
|
9
|
+
* All interfaces use readonly fields to match Python's frozen Pydantic models.
|
|
10
|
+
*/
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aumos/agentshield",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript client for the AumOS AgentShield defense layer — threat detection, input/output scanning, and tool-call validation",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"typescript": "^5.3.0"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"aumos",
|
|
24
|
+
"agentshield",
|
|
25
|
+
"threat-detection",
|
|
26
|
+
"prompt-injection",
|
|
27
|
+
"defense",
|
|
28
|
+
"typescript"
|
|
29
|
+
],
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/invincible-jha/agentshield"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP client for the AgentShield defense API.
|
|
3
|
+
*
|
|
4
|
+
* Uses the Fetch API (available natively in Node 18+, browsers, and Deno).
|
|
5
|
+
* No external dependencies required.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { createAgentShieldClient } from "@aumos/agentshield";
|
|
10
|
+
*
|
|
11
|
+
* const client = createAgentShieldClient({ baseUrl: "http://localhost:8091" });
|
|
12
|
+
*
|
|
13
|
+
* const result = await client.scanInput({
|
|
14
|
+
* agent_id: "my-agent",
|
|
15
|
+
* content: userMessage,
|
|
16
|
+
* session_id: "session-abc",
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* if (result.ok && result.data.blocked) {
|
|
20
|
+
* console.warn("Input blocked:", result.data.findings);
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import type {
|
|
26
|
+
ApiError,
|
|
27
|
+
ApiResult,
|
|
28
|
+
ScanResult,
|
|
29
|
+
ThreatDetectionResult,
|
|
30
|
+
ToolCallValidationRequest,
|
|
31
|
+
ToolCallValidationResult,
|
|
32
|
+
} from "./types.js";
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Client configuration
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
/** Configuration options for the AgentShieldClient. */
|
|
39
|
+
export interface AgentShieldClientConfig {
|
|
40
|
+
/** Base URL of the AgentShield server (e.g. "http://localhost:8091"). */
|
|
41
|
+
readonly baseUrl: string;
|
|
42
|
+
/** Optional request timeout in milliseconds (default: 10000). */
|
|
43
|
+
readonly timeoutMs?: number;
|
|
44
|
+
/** Optional extra HTTP headers sent with every request. */
|
|
45
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Scan request types
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
|
|
52
|
+
/** Request body for input or output scanning. */
|
|
53
|
+
export interface ContentScanRequest {
|
|
54
|
+
/** Agent that produced or received the content. */
|
|
55
|
+
readonly agent_id: string;
|
|
56
|
+
/** Raw content string to scan. */
|
|
57
|
+
readonly content: string;
|
|
58
|
+
/** Optional session context. */
|
|
59
|
+
readonly session_id?: string;
|
|
60
|
+
/** Arbitrary metadata forwarded to rule implementations. */
|
|
61
|
+
readonly metadata?: Readonly<Record<string, unknown>>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// Internal helpers
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
async function fetchJson<T>(
|
|
69
|
+
url: string,
|
|
70
|
+
init: RequestInit,
|
|
71
|
+
timeoutMs: number,
|
|
72
|
+
): Promise<ApiResult<T>> {
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
const response = await fetch(url, { ...init, signal: controller.signal });
|
|
78
|
+
clearTimeout(timeoutId);
|
|
79
|
+
|
|
80
|
+
const body = await response.json() as unknown;
|
|
81
|
+
|
|
82
|
+
if (!response.ok) {
|
|
83
|
+
const errorBody = body as Partial<ApiError>;
|
|
84
|
+
return {
|
|
85
|
+
ok: false,
|
|
86
|
+
error: {
|
|
87
|
+
error: errorBody.error ?? "Unknown error",
|
|
88
|
+
detail: errorBody.detail ?? "",
|
|
89
|
+
},
|
|
90
|
+
status: response.status,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return { ok: true, data: body as T };
|
|
95
|
+
} catch (err: unknown) {
|
|
96
|
+
clearTimeout(timeoutId);
|
|
97
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
98
|
+
return {
|
|
99
|
+
ok: false,
|
|
100
|
+
error: { error: "Network error", detail: message },
|
|
101
|
+
status: 0,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function buildHeaders(
|
|
107
|
+
extraHeaders: Readonly<Record<string, string>> | undefined,
|
|
108
|
+
): Record<string, string> {
|
|
109
|
+
return {
|
|
110
|
+
"Content-Type": "application/json",
|
|
111
|
+
Accept: "application/json",
|
|
112
|
+
...extraHeaders,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// Client interface
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
/** Typed HTTP client for the AgentShield defense server. */
|
|
121
|
+
export interface AgentShieldClient {
|
|
122
|
+
/**
|
|
123
|
+
* Scan content arriving as agent input (e.g. user messages, tool results).
|
|
124
|
+
*
|
|
125
|
+
* @param request - Content and context to scan.
|
|
126
|
+
* @returns ScanResult with findings and a blocked flag.
|
|
127
|
+
*/
|
|
128
|
+
scanInput(request: ContentScanRequest): Promise<ApiResult<ScanResult>>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Scan content produced as agent output (e.g. LLM responses, tool invocations).
|
|
132
|
+
*
|
|
133
|
+
* @param request - Content and context to scan.
|
|
134
|
+
* @returns ScanResult with findings and a blocked flag.
|
|
135
|
+
*/
|
|
136
|
+
scanOutput(request: ContentScanRequest): Promise<ApiResult<ScanResult>>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Retrieve aggregated threat detection statistics for an agent.
|
|
140
|
+
*
|
|
141
|
+
* @param options - Agent and optional time-window filters.
|
|
142
|
+
* @returns ThreatDetectionResult summarising threat activity.
|
|
143
|
+
*/
|
|
144
|
+
getThreatReport(options: {
|
|
145
|
+
agentId: string;
|
|
146
|
+
windowStart?: string;
|
|
147
|
+
windowEnd?: string;
|
|
148
|
+
}): Promise<ApiResult<ThreatDetectionResult>>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Validate a proposed tool call before it is executed.
|
|
152
|
+
*
|
|
153
|
+
* @param request - Tool name, arguments, and calling-agent context.
|
|
154
|
+
* @returns ToolCallValidationResult indicating whether execution is permitted.
|
|
155
|
+
*/
|
|
156
|
+
validateToolCall(
|
|
157
|
+
request: ToolCallValidationRequest,
|
|
158
|
+
): Promise<ApiResult<ToolCallValidationResult>>;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
// Client factory
|
|
163
|
+
// ---------------------------------------------------------------------------
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Create a typed HTTP client for the AgentShield server.
|
|
167
|
+
*
|
|
168
|
+
* @param config - Client configuration including base URL.
|
|
169
|
+
* @returns An AgentShieldClient instance.
|
|
170
|
+
*/
|
|
171
|
+
export function createAgentShieldClient(
|
|
172
|
+
config: AgentShieldClientConfig,
|
|
173
|
+
): AgentShieldClient {
|
|
174
|
+
const { baseUrl, timeoutMs = 10_000, headers: extraHeaders } = config;
|
|
175
|
+
const baseHeaders = buildHeaders(extraHeaders);
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
async scanInput(
|
|
179
|
+
request: ContentScanRequest,
|
|
180
|
+
): Promise<ApiResult<ScanResult>> {
|
|
181
|
+
return fetchJson<ScanResult>(
|
|
182
|
+
`${baseUrl}/scan/input`,
|
|
183
|
+
{
|
|
184
|
+
method: "POST",
|
|
185
|
+
headers: baseHeaders,
|
|
186
|
+
body: JSON.stringify(request),
|
|
187
|
+
},
|
|
188
|
+
timeoutMs,
|
|
189
|
+
);
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
async scanOutput(
|
|
193
|
+
request: ContentScanRequest,
|
|
194
|
+
): Promise<ApiResult<ScanResult>> {
|
|
195
|
+
return fetchJson<ScanResult>(
|
|
196
|
+
`${baseUrl}/scan/output`,
|
|
197
|
+
{
|
|
198
|
+
method: "POST",
|
|
199
|
+
headers: baseHeaders,
|
|
200
|
+
body: JSON.stringify(request),
|
|
201
|
+
},
|
|
202
|
+
timeoutMs,
|
|
203
|
+
);
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
async getThreatReport(options: {
|
|
207
|
+
agentId: string;
|
|
208
|
+
windowStart?: string;
|
|
209
|
+
windowEnd?: string;
|
|
210
|
+
}): Promise<ApiResult<ThreatDetectionResult>> {
|
|
211
|
+
const params = new URLSearchParams({ agent_id: options.agentId });
|
|
212
|
+
if (options.windowStart !== undefined) {
|
|
213
|
+
params.set("window_start", options.windowStart);
|
|
214
|
+
}
|
|
215
|
+
if (options.windowEnd !== undefined) {
|
|
216
|
+
params.set("window_end", options.windowEnd);
|
|
217
|
+
}
|
|
218
|
+
return fetchJson<ThreatDetectionResult>(
|
|
219
|
+
`${baseUrl}/threats/report?${params.toString()}`,
|
|
220
|
+
{ method: "GET", headers: baseHeaders },
|
|
221
|
+
timeoutMs,
|
|
222
|
+
);
|
|
223
|
+
},
|
|
224
|
+
|
|
225
|
+
async validateToolCall(
|
|
226
|
+
request: ToolCallValidationRequest,
|
|
227
|
+
): Promise<ApiResult<ToolCallValidationResult>> {
|
|
228
|
+
return fetchJson<ToolCallValidationResult>(
|
|
229
|
+
`${baseUrl}/validate/tool-call`,
|
|
230
|
+
{
|
|
231
|
+
method: "POST",
|
|
232
|
+
headers: baseHeaders,
|
|
233
|
+
body: JSON.stringify(request),
|
|
234
|
+
},
|
|
235
|
+
timeoutMs,
|
|
236
|
+
);
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aumos/agentshield
|
|
3
|
+
*
|
|
4
|
+
* TypeScript client for the AumOS AgentShield defense layer.
|
|
5
|
+
* Provides HTTP client, synchronous input scanner, and threat-detection type definitions.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Client and configuration
|
|
9
|
+
export type { AgentShieldClient, AgentShieldClientConfig, ContentScanRequest } from "./client.js";
|
|
10
|
+
export { createAgentShieldClient } from "./client.js";
|
|
11
|
+
|
|
12
|
+
// Core types
|
|
13
|
+
export type {
|
|
14
|
+
ThreatLevel,
|
|
15
|
+
DefenseLayer,
|
|
16
|
+
ThreatFinding,
|
|
17
|
+
ScanResult,
|
|
18
|
+
ThreatDetectionResult,
|
|
19
|
+
ToolCallValidationRequest,
|
|
20
|
+
ToolCallValidationResult,
|
|
21
|
+
ApiError,
|
|
22
|
+
ApiResult,
|
|
23
|
+
} from "./types.js";
|
|
24
|
+
|
|
25
|
+
// Input scanner
|
|
26
|
+
export type { InputScanner, ScanOptions } from "./scanner.js";
|
|
27
|
+
export { createInputScanner } from "./scanner.js";
|