botguard 0.2.3 → 0.2.4
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/dist/client.d.ts +1 -4
- package/dist/client.js +7 -11
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
|
@@ -11,11 +11,8 @@ export declare class BotGuard {
|
|
|
11
11
|
get timeout(): number;
|
|
12
12
|
scanToolResponse(toolResponse: string, options?: {
|
|
13
13
|
toolName?: string;
|
|
14
|
-
sensitivity?: 'low' | 'medium' | 'high';
|
|
15
14
|
}): Promise<McpScanResult>;
|
|
16
|
-
scanChunks(chunks: string[]
|
|
17
|
-
sensitivity?: 'low' | 'medium' | 'high';
|
|
18
|
-
}): Promise<RagScanResult>;
|
|
15
|
+
scanChunks(chunks: string[]): Promise<RagScanResult>;
|
|
19
16
|
}
|
|
20
17
|
declare class ChatNamespace {
|
|
21
18
|
completions: Completions;
|
package/dist/client.js
CHANGED
|
@@ -50,21 +50,20 @@ class BotGuard {
|
|
|
50
50
|
return this.config.timeout;
|
|
51
51
|
}
|
|
52
52
|
// ── MCP: scan a tool response for indirect injection before passing it to the LLM ──
|
|
53
|
-
//
|
|
53
|
+
// Uses the shield configured in the constructor (shieldId).
|
|
54
|
+
// Usage: const result = await guard.scanToolResponse(mcpToolResult)
|
|
54
55
|
// if (result.blocked) throw new Error('Injection detected in tool response')
|
|
55
56
|
// return result.safeResponse
|
|
56
57
|
async scanToolResponse(toolResponse, options) {
|
|
57
|
-
const url = `${this.config.apiUrl}/api/mcp/
|
|
58
|
+
const url = `${this.config.apiUrl}/api/mcp/proxy/${this.config.shieldId}`;
|
|
58
59
|
const resp = await fetch(url, {
|
|
59
60
|
method: 'POST',
|
|
60
61
|
headers: {
|
|
61
|
-
'Authorization': `Bearer ${this.config.apiKey}`,
|
|
62
62
|
'Content-Type': 'application/json',
|
|
63
63
|
},
|
|
64
64
|
body: JSON.stringify({
|
|
65
65
|
toolResponse,
|
|
66
66
|
toolName: options?.toolName,
|
|
67
|
-
sensitivity: options?.sensitivity || 'medium',
|
|
68
67
|
}),
|
|
69
68
|
signal: AbortSignal.timeout(this.config.timeout),
|
|
70
69
|
});
|
|
@@ -75,21 +74,18 @@ class BotGuard {
|
|
|
75
74
|
return resp.json();
|
|
76
75
|
}
|
|
77
76
|
// ── RAG: scan retrieved document chunks for poisoning before building the LLM prompt ──
|
|
77
|
+
// Uses the shield configured in the constructor (shieldId).
|
|
78
78
|
// Usage: const result = await guard.scanChunks(retrievedChunks)
|
|
79
79
|
// const safeChunks = result.cleanChunks
|
|
80
80
|
// // only pass safeChunks into your LLM context
|
|
81
|
-
async scanChunks(chunks
|
|
82
|
-
const url = `${this.config.apiUrl}/api/rag/
|
|
81
|
+
async scanChunks(chunks) {
|
|
82
|
+
const url = `${this.config.apiUrl}/api/rag/proxy/${this.config.shieldId}`;
|
|
83
83
|
const resp = await fetch(url, {
|
|
84
84
|
method: 'POST',
|
|
85
85
|
headers: {
|
|
86
|
-
'Authorization': `Bearer ${this.config.apiKey}`,
|
|
87
86
|
'Content-Type': 'application/json',
|
|
88
87
|
},
|
|
89
|
-
body: JSON.stringify({
|
|
90
|
-
chunks,
|
|
91
|
-
sensitivity: options?.sensitivity || 'medium',
|
|
92
|
-
}),
|
|
88
|
+
body: JSON.stringify({ chunks }),
|
|
93
89
|
signal: AbortSignal.timeout(this.config.timeout),
|
|
94
90
|
});
|
|
95
91
|
if (!resp.ok) {
|