guardrail-plug-sdk 1.0.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/dist/Guardrail.d.ts +20 -0
- package/dist/Guardrail.js +49 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/types.d.ts +87 -0
- package/dist/types.js +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SDKChatRequest, SDKChatResponse } from './types.js';
|
|
2
|
+
export interface GuardrailOptions {
|
|
3
|
+
endpoint?: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
provider?: 'openai' | 'gemini' | 'ollama' | 'mock' | string;
|
|
6
|
+
model?: string;
|
|
7
|
+
applicationName?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare class Guardrail {
|
|
10
|
+
private endpoint;
|
|
11
|
+
private apiKey;
|
|
12
|
+
private provider;
|
|
13
|
+
private model;
|
|
14
|
+
private applicationName;
|
|
15
|
+
constructor(options: GuardrailOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Routes chat completions through the Guardrail Middleware Gateway
|
|
18
|
+
*/
|
|
19
|
+
chat(request: SDKChatRequest): Promise<SDKChatResponse>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export class Guardrail {
|
|
2
|
+
endpoint;
|
|
3
|
+
apiKey;
|
|
4
|
+
provider;
|
|
5
|
+
model;
|
|
6
|
+
applicationName;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
this.endpoint = options.endpoint || 'http://localhost:5050';
|
|
9
|
+
this.apiKey = options.apiKey;
|
|
10
|
+
this.provider = options.provider || 'openai';
|
|
11
|
+
this.model = options.model || 'gpt-4o-mini';
|
|
12
|
+
this.applicationName = options.applicationName || 'SDK Application';
|
|
13
|
+
if (!this.apiKey) {
|
|
14
|
+
throw new Error('[Guardrail SDK] Initialisation Error: API Key (apiKey) is required.');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Routes chat completions through the Guardrail Middleware Gateway
|
|
19
|
+
*/
|
|
20
|
+
async chat(request) {
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(`${this.endpoint}/api/chat`, {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
headers: {
|
|
25
|
+
'Content-Type': 'application/json',
|
|
26
|
+
'Authorization': `Bearer ${this.apiKey}`
|
|
27
|
+
},
|
|
28
|
+
body: JSON.stringify({
|
|
29
|
+
messages: request.messages,
|
|
30
|
+
userId: request.userId || 'sdk_user',
|
|
31
|
+
sessionId: request.sessionId || 'sdk_session',
|
|
32
|
+
provider: request.provider || this.provider,
|
|
33
|
+
model: request.model || this.model,
|
|
34
|
+
applicationName: request.applicationName || this.applicationName,
|
|
35
|
+
metadata: request.metadata || {}
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
if (!response.ok) {
|
|
39
|
+
const errorText = await response.text();
|
|
40
|
+
throw new Error(`Guardrail Middleware Error [${response.status}]: ${errorText}`);
|
|
41
|
+
}
|
|
42
|
+
return await response.json();
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
console.error('[Guardrail SDK] Chat Request Failed:', err.message);
|
|
46
|
+
throw err;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export interface Message {
|
|
2
|
+
role: 'user' | 'assistant' | 'system';
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
export interface SDKChatRequest {
|
|
6
|
+
messages: Message[];
|
|
7
|
+
userId?: string;
|
|
8
|
+
sessionId?: string;
|
|
9
|
+
provider?: string;
|
|
10
|
+
model?: string;
|
|
11
|
+
applicationName?: string;
|
|
12
|
+
metadata?: Record<string, any>;
|
|
13
|
+
groundingSource?: 'kb' | 'web';
|
|
14
|
+
}
|
|
15
|
+
export interface Citation {
|
|
16
|
+
citationId: string;
|
|
17
|
+
documentId: string;
|
|
18
|
+
documentName: string;
|
|
19
|
+
content: string;
|
|
20
|
+
score: number;
|
|
21
|
+
}
|
|
22
|
+
export interface Claim {
|
|
23
|
+
claim: string;
|
|
24
|
+
status: 'SUPPORTED' | 'PARTIALLY_SUPPORTED' | 'UNSUPPORTED';
|
|
25
|
+
explanation: string;
|
|
26
|
+
citationId?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface PolicyResult {
|
|
29
|
+
decision: 'APPROVED' | 'FLAGGED' | 'BLOCKED';
|
|
30
|
+
violatedRules: string[];
|
|
31
|
+
explanation: string;
|
|
32
|
+
}
|
|
33
|
+
export interface TokenUsage {
|
|
34
|
+
promptTokens: number;
|
|
35
|
+
completionTokens: number;
|
|
36
|
+
totalTokens: number;
|
|
37
|
+
}
|
|
38
|
+
export interface Metrics {
|
|
39
|
+
totalLatencyMs: number;
|
|
40
|
+
llmLatencyMs: number;
|
|
41
|
+
ragLatencyMs: number;
|
|
42
|
+
verificationLatencyMs: number;
|
|
43
|
+
tokenUsage: TokenUsage;
|
|
44
|
+
costUsd: number;
|
|
45
|
+
}
|
|
46
|
+
export interface SDKChatResponse {
|
|
47
|
+
auditId: string;
|
|
48
|
+
text: string;
|
|
49
|
+
decision: 'APPROVED' | 'FLAGGED' | 'BLOCKED';
|
|
50
|
+
hallucinationScore: number;
|
|
51
|
+
factualTrustScore: number;
|
|
52
|
+
riskLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL';
|
|
53
|
+
citations: Citation[];
|
|
54
|
+
claims: Claim[];
|
|
55
|
+
policyExplanation: string;
|
|
56
|
+
metrics: Metrics;
|
|
57
|
+
rawThinking?: string;
|
|
58
|
+
thinkingClaims?: Claim[];
|
|
59
|
+
rawResponseBeforeBlock?: string;
|
|
60
|
+
}
|
|
61
|
+
export interface UploadedDocument {
|
|
62
|
+
id: string;
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
uploadedAt: string;
|
|
66
|
+
size: number;
|
|
67
|
+
status: 'indexing' | 'indexed' | 'failed';
|
|
68
|
+
version: number;
|
|
69
|
+
owner?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface DocumentChunk {
|
|
72
|
+
id: string;
|
|
73
|
+
documentId: string;
|
|
74
|
+
documentName: string;
|
|
75
|
+
content: string;
|
|
76
|
+
embedding?: number[];
|
|
77
|
+
metadata?: Record<string, any>;
|
|
78
|
+
}
|
|
79
|
+
export interface ProviderConfig {
|
|
80
|
+
providerId: string;
|
|
81
|
+
name: string;
|
|
82
|
+
enabled: boolean;
|
|
83
|
+
defaultModel: string;
|
|
84
|
+
apiKey?: string;
|
|
85
|
+
healthStatus: 'healthy' | 'unhealthy' | 'unknown';
|
|
86
|
+
latency: number;
|
|
87
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "guardrail-plug-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A plug-and-play AI Auditing & Hallucination Detection SDK. Intercepts LLM inputs/outputs, verifies factual grounding against your knowledge base, and blocks or flags unverified responses.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc",
|
|
20
|
+
"prepublishOnly": "npm run build"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/sharma-10-personal/ai-authentication-plugin.git"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"ai",
|
|
28
|
+
"guardrail",
|
|
29
|
+
"hallucination",
|
|
30
|
+
"auditing",
|
|
31
|
+
"middleware",
|
|
32
|
+
"llm",
|
|
33
|
+
"gemini",
|
|
34
|
+
"openai",
|
|
35
|
+
"rag",
|
|
36
|
+
"fact-checking",
|
|
37
|
+
"trust-score",
|
|
38
|
+
"policy-engine",
|
|
39
|
+
"sdk"
|
|
40
|
+
],
|
|
41
|
+
"author": "Sharma S S <sharmas@wekancode.com>",
|
|
42
|
+
"license": "ISC",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/sharma-10-personal/ai-authentication-plugin/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/sharma-10-personal/ai-authentication-plugin#readme",
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@types/node": "^20.11.24",
|
|
53
|
+
"typescript": "^5.3.3"
|
|
54
|
+
}
|
|
55
|
+
}
|