agentshield-sdk 7.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/CHANGELOG.md +191 -0
- package/LICENSE +21 -0
- package/README.md +975 -0
- package/bin/agent-shield.js +680 -0
- package/package.json +118 -0
- package/src/adaptive.js +330 -0
- package/src/agent-protocol.js +998 -0
- package/src/alert-tuning.js +480 -0
- package/src/allowlist.js +603 -0
- package/src/audit-immutable.js +914 -0
- package/src/audit-streaming.js +469 -0
- package/src/badges.js +196 -0
- package/src/behavior-profiling.js +289 -0
- package/src/benchmark-harness.js +804 -0
- package/src/canary.js +271 -0
- package/src/certification.js +563 -0
- package/src/circuit-breaker.js +321 -0
- package/src/compliance.js +617 -0
- package/src/confidence-tuning.js +324 -0
- package/src/confused-deputy.js +624 -0
- package/src/context-scoring.js +360 -0
- package/src/conversation.js +494 -0
- package/src/cost-optimizer.js +1024 -0
- package/src/ctf.js +462 -0
- package/src/detector-core.js +1999 -0
- package/src/distributed.js +359 -0
- package/src/document-scanner.js +795 -0
- package/src/embedding.js +307 -0
- package/src/encoding.js +429 -0
- package/src/enterprise.js +405 -0
- package/src/errors.js +100 -0
- package/src/eu-ai-act.js +523 -0
- package/src/fuzzer.js +764 -0
- package/src/honeypot.js +328 -0
- package/src/i18n-patterns.js +523 -0
- package/src/index.js +430 -0
- package/src/integrations.js +528 -0
- package/src/llm-redteam.js +670 -0
- package/src/main.js +741 -0
- package/src/main.mjs +38 -0
- package/src/mcp-bridge.js +542 -0
- package/src/mcp-certification.js +846 -0
- package/src/mcp-sdk-integration.js +355 -0
- package/src/mcp-security-runtime.js +741 -0
- package/src/mcp-server.js +740 -0
- package/src/middleware.js +208 -0
- package/src/model-finetuning.js +884 -0
- package/src/model-fingerprint.js +1042 -0
- package/src/multi-agent-trust.js +453 -0
- package/src/multi-agent.js +404 -0
- package/src/multimodal.js +296 -0
- package/src/nist-mapping.js +505 -0
- package/src/observability.js +330 -0
- package/src/openclaw.js +450 -0
- package/src/otel.js +544 -0
- package/src/owasp-2025.js +483 -0
- package/src/pii.js +390 -0
- package/src/plugin-marketplace.js +628 -0
- package/src/plugin-system.js +349 -0
- package/src/policy-dsl.js +775 -0
- package/src/policy-extended.js +635 -0
- package/src/policy.js +443 -0
- package/src/presets.js +409 -0
- package/src/production.js +557 -0
- package/src/prompt-leakage.js +321 -0
- package/src/rag-vulnerability.js +579 -0
- package/src/redteam.js +475 -0
- package/src/response-handler.js +429 -0
- package/src/scanners.js +357 -0
- package/src/self-healing.js +363 -0
- package/src/semantic.js +339 -0
- package/src/shield-score.js +250 -0
- package/src/sso-saml.js +897 -0
- package/src/stream-scanner.js +806 -0
- package/src/testing.js +505 -0
- package/src/threat-encyclopedia.js +629 -0
- package/src/threat-intel-network.js +1017 -0
- package/src/token-analysis.js +467 -0
- package/src/tool-guard.js +412 -0
- package/src/tool-output-validator.js +354 -0
- package/src/utils.js +83 -0
- package/src/watermark.js +235 -0
- package/src/worker-scanner.js +601 -0
- package/types/index.d.ts +2088 -0
package/src/eu-ai-act.js
ADDED
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Agent Shield — EU AI Act Compliance Artifact Generator
|
|
5
|
+
*
|
|
6
|
+
* Generates risk classifications, conformity assessments, transparency reports,
|
|
7
|
+
* and incident reports per the EU AI Act. Tracks deadlines and enforcement dates.
|
|
8
|
+
*
|
|
9
|
+
* All processing runs locally — no data ever leaves your environment.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// =========================================================================
|
|
13
|
+
// EU AI Act Requirements
|
|
14
|
+
// =========================================================================
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* EU AI Act requirements by risk level.
|
|
18
|
+
* @type {object}
|
|
19
|
+
*/
|
|
20
|
+
const EU_AI_ACT_REQUIREMENTS = {
|
|
21
|
+
prohibited: {
|
|
22
|
+
riskLevel: 'unacceptable',
|
|
23
|
+
articles: [
|
|
24
|
+
{ article: 'Art. 5(1)(a)', title: 'Subliminal Manipulation', description: 'AI systems deploying subliminal techniques to distort behavior', deadline: '2025-02-02', penalty: 'EUR 35M or 7% turnover' },
|
|
25
|
+
{ article: 'Art. 5(1)(b)', title: 'Exploitation of Vulnerabilities', description: 'AI exploiting vulnerabilities of specific groups (age, disability)', deadline: '2025-02-02', penalty: 'EUR 35M or 7% turnover' },
|
|
26
|
+
{ article: 'Art. 5(1)(c)', title: 'Social Scoring', description: 'AI systems for social scoring by public authorities', deadline: '2025-02-02', penalty: 'EUR 35M or 7% turnover' },
|
|
27
|
+
{ article: 'Art. 5(1)(d)', title: 'Real-time Biometric ID', description: 'Real-time remote biometric identification in public spaces', deadline: '2025-02-02', penalty: 'EUR 35M or 7% turnover' },
|
|
28
|
+
{ article: 'Art. 5(1)(e)', title: 'Emotion Inference', description: 'AI inferring emotions in workplace and education', deadline: '2025-02-02', penalty: 'EUR 35M or 7% turnover' },
|
|
29
|
+
{ article: 'Art. 5(1)(f)', title: 'Predictive Policing', description: 'AI for individual predictive policing based solely on profiling', deadline: '2025-02-02', penalty: 'EUR 35M or 7% turnover' }
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
highRisk: {
|
|
33
|
+
riskLevel: 'high',
|
|
34
|
+
articles: [
|
|
35
|
+
{ article: 'Art. 9', title: 'Risk Management System', description: 'Establish and maintain AI risk management system', requirements: ['risk identification', 'risk analysis', 'risk evaluation', 'risk treatment'], deadline: '2026-08-02' },
|
|
36
|
+
{ article: 'Art. 10', title: 'Data Governance', description: 'Data governance and management practices for training, validation, and testing', requirements: ['data quality', 'bias examination', 'data documentation'], deadline: '2026-08-02' },
|
|
37
|
+
{ article: 'Art. 11', title: 'Technical Documentation', description: 'Draw up technical documentation before placing on market', requirements: ['system description', 'design specifications', 'monitoring', 'risk controls'], deadline: '2026-08-02' },
|
|
38
|
+
{ article: 'Art. 12', title: 'Record-Keeping', description: 'Automatic recording of events (logs) for traceability', requirements: ['event logging', 'audit trail', 'log retention'], deadline: '2026-08-02' },
|
|
39
|
+
{ article: 'Art. 13', title: 'Transparency', description: 'Designed to allow users to interpret output and use appropriately', requirements: ['user instructions', 'capability disclosure', 'limitation disclosure'], deadline: '2026-08-02' },
|
|
40
|
+
{ article: 'Art. 14', title: 'Human Oversight', description: 'Enable human oversight during AI system operation', requirements: ['human control measures', 'override capability', 'intervention mechanisms'], deadline: '2026-08-02' },
|
|
41
|
+
{ article: 'Art. 15', title: 'Accuracy & Robustness', description: 'Achieve appropriate level of accuracy, robustness, and cybersecurity', requirements: ['accuracy metrics', 'resilience testing', 'security measures'], deadline: '2026-08-02' },
|
|
42
|
+
{ article: 'Art. 17', title: 'Quality Management', description: 'Quality management system for high-risk AI', requirements: ['QMS procedures', 'compliance strategy', 'documentation management'], deadline: '2026-08-02' }
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
limitedRisk: {
|
|
46
|
+
riskLevel: 'limited',
|
|
47
|
+
articles: [
|
|
48
|
+
{ article: 'Art. 50(1)', title: 'AI Interaction Disclosure', description: 'Users must be informed they are interacting with AI', requirements: ['disclosure notice'], deadline: '2025-08-02' },
|
|
49
|
+
{ article: 'Art. 50(2)', title: 'Deepfake Labeling', description: 'AI-generated content must be labeled', requirements: ['content labeling'], deadline: '2025-08-02' },
|
|
50
|
+
{ article: 'Art. 50(3)', title: 'Emotion Recognition Disclosure', description: 'Inform persons exposed to emotion recognition systems', requirements: ['disclosure'], deadline: '2025-08-02' }
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
gpai: {
|
|
54
|
+
riskLevel: 'general-purpose',
|
|
55
|
+
articles: [
|
|
56
|
+
{ article: 'Art. 53(1)(a)', title: 'Technical Documentation', description: 'GPAI providers must maintain technical documentation', requirements: ['model card', 'training methodology', 'evaluation results'], deadline: '2025-08-02' },
|
|
57
|
+
{ article: 'Art. 53(1)(b)', title: 'Downstream Provider Info', description: 'Provide information to downstream providers', requirements: ['integration guide', 'capability description', 'limitations'], deadline: '2025-08-02' },
|
|
58
|
+
{ article: 'Art. 53(1)(c)', title: 'Copyright Compliance', description: 'Put in place a policy to comply with copyright law', requirements: ['copyright policy', 'training data summary'], deadline: '2025-08-02' },
|
|
59
|
+
{ article: 'Art. 53(1)(d)', title: 'Training Data Summary', description: 'Make available a detailed summary of training data', requirements: ['data sources', 'data preparation', 'data characteristics'], deadline: '2025-08-02' }
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// =========================================================================
|
|
65
|
+
// RiskClassifier
|
|
66
|
+
// =========================================================================
|
|
67
|
+
|
|
68
|
+
class RiskClassifier {
|
|
69
|
+
/**
|
|
70
|
+
* @param {object} [options]
|
|
71
|
+
* @param {string} [options.sector] - Deployment sector
|
|
72
|
+
* @param {string} [options.purpose] - System purpose
|
|
73
|
+
* @param {string[]} [options.dataTypes] - Types of data processed
|
|
74
|
+
* @param {string[]} [options.affectedPersons] - Categories of affected persons
|
|
75
|
+
*/
|
|
76
|
+
constructor(options = {}) {
|
|
77
|
+
this.sector = options.sector || '';
|
|
78
|
+
this.purpose = options.purpose || '';
|
|
79
|
+
this.dataTypes = options.dataTypes || [];
|
|
80
|
+
this.affectedPersons = options.affectedPersons || [];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Classifies the AI system risk level per EU AI Act.
|
|
85
|
+
* @param {string} [systemDescription=''] - System description
|
|
86
|
+
* @returns {{ riskLevel: string, confidence: string, applicableArticles: Array, reasoning: string }}
|
|
87
|
+
*/
|
|
88
|
+
classify(systemDescription = '') {
|
|
89
|
+
const desc = (systemDescription + ' ' + this.purpose + ' ' + this.sector).toLowerCase();
|
|
90
|
+
|
|
91
|
+
// Check prohibited
|
|
92
|
+
if (/social\s+scor/i.test(desc) || /subliminal/i.test(desc) || /biometric.*real[\s-]*time/i.test(desc) || /predictive\s+polic/i.test(desc)) {
|
|
93
|
+
return { riskLevel: 'prohibited', confidence: 'high', applicableArticles: EU_AI_ACT_REQUIREMENTS.prohibited.articles, reasoning: 'System matches prohibited AI practices under Article 5' };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Check high-risk (Annex III sectors)
|
|
97
|
+
const highRiskSectors = ['critical infrastructure', 'education', 'employment', 'law enforcement', 'migration', 'judiciary', 'democratic', 'healthcare', 'safety component'];
|
|
98
|
+
const isHighRisk = highRiskSectors.some(s => desc.includes(s));
|
|
99
|
+
const processesSpecialData = this.dataTypes.some(d => /biometric|health|genetic|political|religious|ethnic/i.test(d));
|
|
100
|
+
|
|
101
|
+
if (isHighRisk || processesSpecialData) {
|
|
102
|
+
return { riskLevel: 'high', confidence: isHighRisk ? 'high' : 'medium', applicableArticles: EU_AI_ACT_REQUIREMENTS.highRisk.articles, reasoning: `System operates in high-risk sector or processes special category data` };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Check limited risk (chatbots, deepfakes)
|
|
106
|
+
if (/chatbot|conversational|assistant|generative|deepfake/i.test(desc)) {
|
|
107
|
+
return { riskLevel: 'limited', confidence: 'high', applicableArticles: EU_AI_ACT_REQUIREMENTS.limitedRisk.articles, reasoning: 'System is a conversational AI or generates content requiring transparency obligations' };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Check GPAI
|
|
111
|
+
if (/general[\s-]*purpose|foundation\s+model|large\s+language/i.test(desc)) {
|
|
112
|
+
return { riskLevel: 'gpai', confidence: 'high', applicableArticles: EU_AI_ACT_REQUIREMENTS.gpai.articles, reasoning: 'System is a general-purpose AI model with broad capabilities' };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return { riskLevel: 'minimal', confidence: 'medium', applicableArticles: [], reasoning: 'System does not match high-risk, limited-risk, or GPAI criteria' };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Returns which EU AI Act articles apply.
|
|
120
|
+
* @returns {Array<object>}
|
|
121
|
+
*/
|
|
122
|
+
getApplicableArticles() {
|
|
123
|
+
const result = this.classify();
|
|
124
|
+
return result.applicableArticles;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Generates a formal risk assessment document.
|
|
129
|
+
* @returns {object}
|
|
130
|
+
*/
|
|
131
|
+
generateRiskAssessment() {
|
|
132
|
+
const classification = this.classify();
|
|
133
|
+
return {
|
|
134
|
+
title: 'EU AI Act Risk Assessment',
|
|
135
|
+
generatedAt: new Date().toISOString(),
|
|
136
|
+
system: { sector: this.sector, purpose: this.purpose, dataTypes: this.dataTypes, affectedPersons: this.affectedPersons },
|
|
137
|
+
classification,
|
|
138
|
+
nextSteps: this._getNextSteps(classification.riskLevel)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** @private */
|
|
143
|
+
_getNextSteps(riskLevel) {
|
|
144
|
+
const steps = {
|
|
145
|
+
prohibited: ['Immediately cease operation of this AI system', 'Consult legal counsel for decommissioning'],
|
|
146
|
+
high: ['Complete conformity assessment (Art. 43)', 'Prepare technical documentation (Art. 11)', 'Register in EU database (Art. 49)', 'Implement quality management system (Art. 17)', 'Arrange third-party audit if required'],
|
|
147
|
+
limited: ['Implement AI interaction disclosure', 'Add content labeling for generated content', 'Document transparency measures'],
|
|
148
|
+
gpai: ['Prepare model card and technical documentation', 'Create training data summary', 'Establish copyright compliance policy'],
|
|
149
|
+
minimal: ['No mandatory requirements — consider voluntary codes of conduct']
|
|
150
|
+
};
|
|
151
|
+
return steps[riskLevel] || steps.minimal;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// =========================================================================
|
|
156
|
+
// ConformityAssessment
|
|
157
|
+
// =========================================================================
|
|
158
|
+
|
|
159
|
+
class ConformityAssessment {
|
|
160
|
+
/**
|
|
161
|
+
* @param {object} systemInfo
|
|
162
|
+
* @param {string} systemInfo.name - System name
|
|
163
|
+
* @param {string} [systemInfo.provider] - Provider name
|
|
164
|
+
* @param {string} [systemInfo.version] - Version
|
|
165
|
+
* @param {string} [systemInfo.purpose] - Purpose
|
|
166
|
+
* @param {string} [systemInfo.riskLevel] - Risk level
|
|
167
|
+
*/
|
|
168
|
+
constructor(systemInfo = {}) {
|
|
169
|
+
this.systemInfo = systemInfo;
|
|
170
|
+
this.evidence = {};
|
|
171
|
+
this.requirements = EU_AI_ACT_REQUIREMENTS.highRisk.articles;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Attaches evidence for a requirement.
|
|
176
|
+
* @param {string} reqArticle - Article ID (e.g., 'Art. 9')
|
|
177
|
+
* @param {object} evidence - { description, documentRef, verifiedDate }
|
|
178
|
+
*/
|
|
179
|
+
addEvidence(reqArticle, evidence) {
|
|
180
|
+
if (!this.evidence[reqArticle]) this.evidence[reqArticle] = [];
|
|
181
|
+
this.evidence[reqArticle].push({ ...evidence, addedAt: new Date().toISOString() });
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Checks if a specific requirement is met.
|
|
186
|
+
* @param {string} reqArticle
|
|
187
|
+
* @returns {{ met: boolean, evidence: Array }}
|
|
188
|
+
*/
|
|
189
|
+
checkRequirement(reqArticle) {
|
|
190
|
+
const ev = this.evidence[reqArticle] || [];
|
|
191
|
+
return { met: ev.length > 0, evidence: ev };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Returns overall conformity status.
|
|
196
|
+
* @returns {{ status: string, metCount: number, totalCount: number, percentage: number }}
|
|
197
|
+
*/
|
|
198
|
+
getStatus() {
|
|
199
|
+
const total = this.requirements.length;
|
|
200
|
+
const met = this.requirements.filter(r => (this.evidence[r.article] || []).length > 0).length;
|
|
201
|
+
const percentage = Math.round((met / total) * 100);
|
|
202
|
+
const status = percentage === 100 ? 'conforming' : percentage >= 70 ? 'partially_conforming' : 'non_conforming';
|
|
203
|
+
return { status, metCount: met, totalCount: total, percentage };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Generates a conformity assessment report.
|
|
208
|
+
* @param {'text'|'json'|'markdown'} [format='json']
|
|
209
|
+
* @returns {string}
|
|
210
|
+
*/
|
|
211
|
+
generateReport(format = 'json') {
|
|
212
|
+
const status = this.getStatus();
|
|
213
|
+
const report = {
|
|
214
|
+
title: 'EU AI Act Conformity Assessment',
|
|
215
|
+
generatedAt: new Date().toISOString(),
|
|
216
|
+
system: this.systemInfo,
|
|
217
|
+
status,
|
|
218
|
+
requirements: this.requirements.map(r => ({
|
|
219
|
+
article: r.article,
|
|
220
|
+
title: r.title,
|
|
221
|
+
met: (this.evidence[r.article] || []).length > 0,
|
|
222
|
+
evidenceCount: (this.evidence[r.article] || []).length
|
|
223
|
+
}))
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
if (format === 'json') return JSON.stringify(report, null, 2);
|
|
227
|
+
if (format === 'markdown') {
|
|
228
|
+
const lines = [
|
|
229
|
+
'# EU AI Act Conformity Assessment',
|
|
230
|
+
'',
|
|
231
|
+
`**System:** ${this.systemInfo.name}`,
|
|
232
|
+
`**Status:** ${status.status} (${status.percentage}%)`,
|
|
233
|
+
'',
|
|
234
|
+
'## Requirements',
|
|
235
|
+
''
|
|
236
|
+
];
|
|
237
|
+
for (const r of report.requirements) {
|
|
238
|
+
const icon = r.met ? 'x' : ' ';
|
|
239
|
+
lines.push(`- [${icon}] **${r.article}** ${r.title} (${r.evidenceCount} evidence items)`);
|
|
240
|
+
}
|
|
241
|
+
return lines.join('\n');
|
|
242
|
+
}
|
|
243
|
+
return JSON.stringify(report, null, 2);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Generates Article 11 technical documentation.
|
|
248
|
+
* @returns {object}
|
|
249
|
+
*/
|
|
250
|
+
generateTechnicalDocumentation() {
|
|
251
|
+
return {
|
|
252
|
+
title: 'Technical Documentation (Article 11)',
|
|
253
|
+
generatedAt: new Date().toISOString(),
|
|
254
|
+
system: this.systemInfo,
|
|
255
|
+
sections: [
|
|
256
|
+
{ section: 'A', title: 'General Description', content: `System: ${this.systemInfo.name}. Purpose: ${this.systemInfo.purpose || 'Not specified'}.` },
|
|
257
|
+
{ section: 'B', title: 'Detailed Description of Elements', content: 'See attached design specifications.' },
|
|
258
|
+
{ section: 'C', title: 'Monitoring, Functioning, and Control', content: 'Agent Shield provides real-time monitoring via detector-core, behavior-profiling, and observability modules.' },
|
|
259
|
+
{ section: 'D', title: 'Risk Management', content: 'Risk management implemented via shield-score, owasp-2025 coverage matrix, and NIST AI RMF mapping.' },
|
|
260
|
+
{ section: 'E', title: 'Changes and Modifications', content: 'All changes tracked via immutable audit log and version control.' }
|
|
261
|
+
]
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Generates Article 47 EU declaration of conformity.
|
|
267
|
+
* @returns {object}
|
|
268
|
+
*/
|
|
269
|
+
generateDeclarationOfConformity() {
|
|
270
|
+
return {
|
|
271
|
+
title: 'EU Declaration of Conformity (Article 47)',
|
|
272
|
+
generatedAt: new Date().toISOString(),
|
|
273
|
+
provider: this.systemInfo.provider || 'Not specified',
|
|
274
|
+
system: { name: this.systemInfo.name, version: this.systemInfo.version || '1.0' },
|
|
275
|
+
declaration: `This AI system has been assessed for conformity with the requirements of Regulation (EU) 2024/1689 (EU AI Act).`,
|
|
276
|
+
conformityStatus: this.getStatus().status,
|
|
277
|
+
signedBy: '[Authorized Representative]',
|
|
278
|
+
date: new Date().toISOString().split('T')[0]
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// =========================================================================
|
|
284
|
+
// TransparencyReporter — GPAI obligations
|
|
285
|
+
// =========================================================================
|
|
286
|
+
|
|
287
|
+
class TransparencyReporter {
|
|
288
|
+
/**
|
|
289
|
+
* @param {object} [options]
|
|
290
|
+
* @param {string} [options.providerName] - Provider name
|
|
291
|
+
*/
|
|
292
|
+
constructor(options = {}) {
|
|
293
|
+
this.providerName = options.providerName || 'Provider';
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Generates a structured model card per Article 53.
|
|
298
|
+
* @param {object} modelInfo - { name, version, type, parameters, capabilities, limitations, evaluationResults }
|
|
299
|
+
* @returns {object}
|
|
300
|
+
*/
|
|
301
|
+
generateModelCard(modelInfo = {}) {
|
|
302
|
+
return {
|
|
303
|
+
title: `Model Card: ${modelInfo.name || 'Unknown Model'}`,
|
|
304
|
+
generatedAt: new Date().toISOString(),
|
|
305
|
+
provider: this.providerName,
|
|
306
|
+
model: { name: modelInfo.name, version: modelInfo.version, type: modelInfo.type, parameters: modelInfo.parameters },
|
|
307
|
+
intendedUse: modelInfo.capabilities || 'Not specified',
|
|
308
|
+
limitations: modelInfo.limitations || 'Not specified',
|
|
309
|
+
evaluationResults: modelInfo.evaluationResults || 'Not yet evaluated',
|
|
310
|
+
ethicalConsiderations: 'See provider ethics policy.',
|
|
311
|
+
article: 'Art. 53(1)(a)'
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Generates training data summary per Article 53(1)(d).
|
|
317
|
+
* @param {object} dataInfo - { sources, size, preparation, characteristics, biasAnalysis }
|
|
318
|
+
* @returns {object}
|
|
319
|
+
*/
|
|
320
|
+
generateTrainingDataSummary(dataInfo = {}) {
|
|
321
|
+
return {
|
|
322
|
+
title: 'Training Data Summary',
|
|
323
|
+
generatedAt: new Date().toISOString(),
|
|
324
|
+
provider: this.providerName,
|
|
325
|
+
sources: dataInfo.sources || [],
|
|
326
|
+
size: dataInfo.size || 'Unknown',
|
|
327
|
+
preparation: dataInfo.preparation || 'Not documented',
|
|
328
|
+
characteristics: dataInfo.characteristics || 'Not documented',
|
|
329
|
+
biasAnalysis: dataInfo.biasAnalysis || 'Not conducted',
|
|
330
|
+
article: 'Art. 53(1)(d)'
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Generates copyright compliance policy per Article 53(1)(c).
|
|
336
|
+
* @returns {object}
|
|
337
|
+
*/
|
|
338
|
+
generateCopyrightPolicy() {
|
|
339
|
+
return {
|
|
340
|
+
title: 'Copyright Compliance Policy',
|
|
341
|
+
generatedAt: new Date().toISOString(),
|
|
342
|
+
provider: this.providerName,
|
|
343
|
+
policy: 'This provider maintains a copyright compliance policy in accordance with EU AI Act Article 53(1)(c).',
|
|
344
|
+
measures: [
|
|
345
|
+
'Training data sources are documented and reviewed for copyright status',
|
|
346
|
+
'Opt-out mechanisms are respected per Article 53(1)(c)',
|
|
347
|
+
'A publicly available summary of training data content is maintained'
|
|
348
|
+
],
|
|
349
|
+
article: 'Art. 53(1)(c)'
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Generates energy consumption report.
|
|
355
|
+
* @param {object} metrics - { trainingEnergy, inferenceEnergy, carbonFootprint }
|
|
356
|
+
* @returns {object}
|
|
357
|
+
*/
|
|
358
|
+
generateEnergyReport(metrics = {}) {
|
|
359
|
+
return {
|
|
360
|
+
title: 'Energy Consumption Report',
|
|
361
|
+
generatedAt: new Date().toISOString(),
|
|
362
|
+
provider: this.providerName,
|
|
363
|
+
training: { energyKWh: metrics.trainingEnergy || 'Unknown', duration: metrics.trainingDuration || 'Unknown' },
|
|
364
|
+
inference: { energyPerRequestKWh: metrics.inferenceEnergy || 'Unknown' },
|
|
365
|
+
carbonFootprint: metrics.carbonFootprint || 'Unknown'
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// =========================================================================
|
|
371
|
+
// IncidentReporter
|
|
372
|
+
// =========================================================================
|
|
373
|
+
|
|
374
|
+
class IncidentReporter {
|
|
375
|
+
/**
|
|
376
|
+
* @param {object} [options]
|
|
377
|
+
* @param {string} [options.providerName] - Provider name
|
|
378
|
+
* @param {string} [options.contactEmail] - Contact email
|
|
379
|
+
* @param {string} [options.nationalAuthority] - National authority
|
|
380
|
+
*/
|
|
381
|
+
constructor(options = {}) {
|
|
382
|
+
this.providerName = options.providerName || 'Provider';
|
|
383
|
+
this.contactEmail = options.contactEmail || '';
|
|
384
|
+
this.nationalAuthority = options.nationalAuthority || 'National AI Authority';
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Creates a formatted incident report per Article 62.
|
|
389
|
+
* @param {object} incident - { type, severity, description, affectedUsers, date, mitigationTaken }
|
|
390
|
+
* @returns {object}
|
|
391
|
+
*/
|
|
392
|
+
createReport(incident = {}) {
|
|
393
|
+
return {
|
|
394
|
+
title: 'Serious Incident Report (Article 62)',
|
|
395
|
+
reportId: `IR-${Date.now()}`,
|
|
396
|
+
generatedAt: new Date().toISOString(),
|
|
397
|
+
provider: this.providerName,
|
|
398
|
+
contact: this.contactEmail,
|
|
399
|
+
authority: this.nationalAuthority,
|
|
400
|
+
incident: {
|
|
401
|
+
type: incident.type || 'unspecified',
|
|
402
|
+
severity: incident.severity || 'unknown',
|
|
403
|
+
description: incident.description || '',
|
|
404
|
+
affectedUsers: incident.affectedUsers || 'unknown',
|
|
405
|
+
date: incident.date || new Date().toISOString(),
|
|
406
|
+
mitigationTaken: incident.mitigationTaken || 'Under investigation'
|
|
407
|
+
},
|
|
408
|
+
deadline: this.getNotificationDeadline(incident.severity),
|
|
409
|
+
correctiveActions: this.generateCorrective(incident)
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Returns notification deadline based on severity.
|
|
415
|
+
* @param {string} [severity='unknown']
|
|
416
|
+
* @returns {string}
|
|
417
|
+
*/
|
|
418
|
+
getNotificationDeadline(severity = 'unknown') {
|
|
419
|
+
if (severity === 'critical') return '24 hours from discovery';
|
|
420
|
+
if (severity === 'high') return '72 hours from discovery';
|
|
421
|
+
return '15 days from discovery';
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Generates corrective action plan.
|
|
426
|
+
* @param {object} incident
|
|
427
|
+
* @returns {Array<string>}
|
|
428
|
+
*/
|
|
429
|
+
generateCorrective(incident = {}) {
|
|
430
|
+
return [
|
|
431
|
+
'Identify root cause of the incident',
|
|
432
|
+
'Implement immediate containment measures',
|
|
433
|
+
'Notify affected users and national authority within deadline',
|
|
434
|
+
'Document all actions taken in audit trail',
|
|
435
|
+
'Implement preventive measures to avoid recurrence',
|
|
436
|
+
'Update risk management documentation'
|
|
437
|
+
];
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// =========================================================================
|
|
442
|
+
// EUAIActDashboard
|
|
443
|
+
// =========================================================================
|
|
444
|
+
|
|
445
|
+
class EUAIActDashboard {
|
|
446
|
+
/**
|
|
447
|
+
* @param {RiskClassifier} [riskClassifier]
|
|
448
|
+
* @param {ConformityAssessment} [conformity]
|
|
449
|
+
*/
|
|
450
|
+
constructor(riskClassifier, conformity) {
|
|
451
|
+
this.classifier = riskClassifier || new RiskClassifier();
|
|
452
|
+
this.conformity = conformity;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Returns overall compliance dashboard data.
|
|
457
|
+
* @returns {object}
|
|
458
|
+
*/
|
|
459
|
+
getComplianceStatus() {
|
|
460
|
+
const classification = this.classifier.classify();
|
|
461
|
+
const conformityStatus = this.conformity ? this.conformity.getStatus() : null;
|
|
462
|
+
|
|
463
|
+
return {
|
|
464
|
+
riskLevel: classification.riskLevel,
|
|
465
|
+
conformity: conformityStatus,
|
|
466
|
+
deadlines: this.getDeadlines(),
|
|
467
|
+
actionItems: this.getActionItems()
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Returns upcoming compliance deadlines.
|
|
473
|
+
* @returns {Array<object>}
|
|
474
|
+
*/
|
|
475
|
+
getDeadlines() {
|
|
476
|
+
const now = new Date();
|
|
477
|
+
const deadlines = [
|
|
478
|
+
{ date: '2025-02-02', description: 'Prohibited AI practices enforced', status: now >= new Date('2025-02-02') ? 'active' : 'upcoming' },
|
|
479
|
+
{ date: '2025-08-02', description: 'GPAI transparency obligations', status: now >= new Date('2025-08-02') ? 'active' : 'upcoming' },
|
|
480
|
+
{ date: '2026-08-02', description: 'High-risk AI system requirements', status: now >= new Date('2026-08-02') ? 'active' : 'upcoming' },
|
|
481
|
+
{ date: '2027-08-02', description: 'Full enforcement for all AI systems', status: now >= new Date('2027-08-02') ? 'active' : 'upcoming' }
|
|
482
|
+
];
|
|
483
|
+
return deadlines;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Returns prioritized action items.
|
|
488
|
+
* @returns {Array<object>}
|
|
489
|
+
*/
|
|
490
|
+
getActionItems() {
|
|
491
|
+
const items = [];
|
|
492
|
+
const classification = this.classifier.classify();
|
|
493
|
+
|
|
494
|
+
if (classification.riskLevel === 'high') {
|
|
495
|
+
items.push({ priority: 'critical', action: 'Complete conformity assessment before Aug 2026', deadline: '2026-08-02' });
|
|
496
|
+
items.push({ priority: 'high', action: 'Prepare technical documentation (Art. 11)', deadline: '2026-08-02' });
|
|
497
|
+
items.push({ priority: 'high', action: 'Register in EU AI database (Art. 49)', deadline: '2026-08-02' });
|
|
498
|
+
items.push({ priority: 'high', action: 'Implement quality management system (Art. 17)', deadline: '2026-08-02' });
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (classification.riskLevel === 'gpai' || classification.riskLevel === 'limited') {
|
|
502
|
+
items.push({ priority: 'high', action: 'Ensure transparency obligations met', deadline: '2025-08-02' });
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
items.push({ priority: 'medium', action: 'Document AI risk management processes' });
|
|
506
|
+
items.push({ priority: 'low', action: 'Consider voluntary codes of conduct' });
|
|
507
|
+
|
|
508
|
+
return items;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// =========================================================================
|
|
513
|
+
// Exports
|
|
514
|
+
// =========================================================================
|
|
515
|
+
|
|
516
|
+
module.exports = {
|
|
517
|
+
EU_AI_ACT_REQUIREMENTS,
|
|
518
|
+
RiskClassifier,
|
|
519
|
+
ConformityAssessment,
|
|
520
|
+
TransparencyReporter,
|
|
521
|
+
IncidentReporter,
|
|
522
|
+
EUAIActDashboard
|
|
523
|
+
};
|