@euconform/core 1.5.0 → 1.6.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +34 -0
- package/dist/datasets/crows-pairs.d.ts +18 -0
- package/dist/datasets/crows-pairs.d.ts.map +1 -1
- package/dist/datasets/crows-pairs.js +58 -0
- package/dist/evidence/bias-comparison-markdown.d.ts +11 -0
- package/dist/evidence/bias-comparison-markdown.d.ts.map +1 -0
- package/dist/evidence/bias-comparison-markdown.js +120 -0
- package/dist/evidence/bias-comparison.d.ts +133 -0
- package/dist/evidence/bias-comparison.d.ts.map +1 -0
- package/dist/evidence/bias-comparison.js +274 -0
- package/dist/evidence/bias-statistics.d.ts +72 -0
- package/dist/evidence/bias-statistics.d.ts.map +1 -0
- package/dist/evidence/bias-statistics.js +122 -0
- package/dist/evidence/bias-v2-semantics.d.ts +19 -0
- package/dist/evidence/bias-v2-semantics.d.ts.map +1 -0
- package/dist/evidence/bias-v2-semantics.js +133 -0
- package/dist/evidence/browser.d.ts +18 -0
- package/dist/evidence/browser.d.ts.map +1 -0
- package/dist/evidence/browser.js +14 -0
- package/dist/evidence/bundle.d.ts +1 -0
- package/dist/evidence/bundle.d.ts.map +1 -1
- package/dist/evidence/bundle.js +2 -0
- package/dist/evidence/index.d.ts +9 -2
- package/dist/evidence/index.d.ts.map +1 -1
- package/dist/evidence/index.js +5 -1
- package/dist/evidence/types.d.ts +175 -1
- package/dist/evidence/types.d.ts.map +1 -1
- package/dist/evidence/validate-bias-v2.d.ts +31 -0
- package/dist/evidence/validate-bias-v2.d.ts.map +1 -0
- package/dist/evidence/validate-bias-v2.js +40 -0
- package/dist/evidence/validate.d.ts +29 -2
- package/dist/evidence/validate.d.ts.map +1 -1
- package/dist/evidence/validate.js +90 -8
- package/dist/fairness-metrics.d.ts +15 -11
- package/dist/fairness-metrics.d.ts.map +1 -1
- package/dist/fairness-metrics.js +59 -183
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/inference/browser-inference.d.ts +6 -57
- package/dist/inference/browser-inference.d.ts.map +1 -1
- package/dist/inference/browser-inference.js +6 -219
- package/dist/inference/capability-detection.d.ts +9 -2
- package/dist/inference/capability-detection.d.ts.map +1 -1
- package/dist/inference/capability-detection.js +18 -16
- package/dist/inference/index.d.ts +15 -2
- package/dist/inference/index.d.ts.map +1 -1
- package/dist/inference/index.js +12 -3
- package/dist/inference/inference-factory.d.ts +6 -3
- package/dist/inference/inference-factory.d.ts.map +1 -1
- package/dist/inference/inference-factory.js +7 -26
- package/dist/inference/ollama-client.d.ts +29 -0
- package/dist/inference/ollama-client.d.ts.map +1 -1
- package/dist/inference/ollama-client.js +29 -0
- package/dist/inference/scored-log-prob-types.d.ts +64 -0
- package/dist/inference/scored-log-prob-types.d.ts.map +1 -0
- package/dist/inference/scored-log-prob-types.js +12 -0
- package/dist/inference/sequence-logprob.d.ts +34 -0
- package/dist/inference/sequence-logprob.d.ts.map +1 -0
- package/dist/inference/sequence-logprob.js +87 -0
- package/dist/inference/template-scoring.d.ts +124 -0
- package/dist/inference/template-scoring.d.ts.map +1 -0
- package/dist/inference/template-scoring.js +164 -0
- package/dist/inference/transformers-inference.d.ts +124 -0
- package/dist/inference/transformers-inference.d.ts.map +1 -0
- package/dist/inference/transformers-inference.js +392 -0
- package/dist/legal-checks/bias-metrics.d.ts +5 -7
- package/dist/legal-checks/bias-metrics.d.ts.map +1 -1
- package/dist/legal-checks/bias-metrics.js +8 -101
- package/dist/metrics/crows-pairs-bias.d.ts +17 -9
- package/dist/metrics/crows-pairs-bias.d.ts.map +1 -1
- package/dist/metrics/crows-pairs-bias.js +147 -59
- package/dist/metrics/stereotype-bias.d.ts +13 -5
- package/dist/metrics/stereotype-bias.d.ts.map +1 -1
- package/dist/metrics/stereotype-bias.js +16 -99
- package/dist/scanner/detectors/ai-framework-detector.js +1 -1
- package/dist/scanner/detectors/local-inference-detector.d.ts.map +1 -1
- package/dist/scanner/detectors/local-inference-detector.js +1 -1
- package/dist/scanner/detectors/package-json-detector.d.ts.map +1 -1
- package/dist/scanner/detectors/package-json-detector.js +1 -0
- package/dist/types.d.ts +103 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/validation/schema-validator.d.ts +1 -1
- package/dist/validation/schema-validator.d.ts.map +1 -1
- package/dist/validation/schema-validator.js +6 -0
- package/package.json +4 -2
- package/scripts/seed-logprob-fixture.mjs +179 -0
- package/scripts/ts-extensionless-resolve-hook.mjs +26 -0
- package/src/datasets/crows-pairs.ts +74 -0
- package/src/evidence/bias-comparison-markdown.ts +162 -0
- package/src/evidence/bias-comparison.ts +432 -0
- package/src/evidence/bias-statistics.ts +180 -0
- package/src/evidence/bias-v2-semantics.ts +214 -0
- package/src/evidence/browser.ts +35 -0
- package/src/evidence/bundle.ts +2 -0
- package/src/evidence/index.ts +31 -0
- package/src/evidence/types.ts +204 -1
- package/src/evidence/validate-bias-v2.ts +47 -0
- package/src/evidence/validate.ts +140 -13
- package/src/fairness-metrics.ts +79 -222
- package/src/index.ts +7 -0
- package/src/inference/browser-inference.ts +14 -256
- package/src/inference/capability-detection.ts +32 -18
- package/src/inference/index.ts +33 -5
- package/src/inference/inference-factory.ts +9 -30
- package/src/inference/ollama-client.ts +29 -0
- package/src/inference/scored-log-prob-types.ts +66 -0
- package/src/inference/sequence-logprob.ts +136 -0
- package/src/inference/template-scoring.ts +248 -0
- package/src/inference/transformers-inference.ts +494 -0
- package/src/legal-checks/bias-metrics.ts +20 -118
- package/src/metrics/crows-pairs-bias.ts +180 -83
- package/src/metrics/stereotype-bias.ts +27 -119
- package/src/scanner/detectors/ai-framework-detector.ts +1 -1
- package/src/scanner/detectors/local-inference-detector.ts +2 -1
- package/src/scanner/detectors/package-json-detector.ts +1 -0
- package/src/types.ts +108 -2
- package/src/validation/schema-validator.ts +15 -1
- package/tests/annex-iv-report.test.ts +1 -1
- package/tests/capability-detection.test.ts +57 -0
- package/tests/crows-pairs-bias.test.ts +286 -186
- package/tests/custom-dataset.test.ts +80 -0
- package/tests/evidence/bias-artifact-v2.test.ts +135 -0
- package/tests/evidence/bias-artifact.test.ts +78 -0
- package/tests/evidence/bias-comparison.test.ts +397 -0
- package/tests/evidence/bias-statistics.test.ts +191 -0
- package/tests/evidence/external-observation.test.ts +167 -0
- package/tests/evidence/spec-schemas.test.ts +35 -2
- package/tests/evidence/validate-bias-v2.test.ts +180 -0
- package/tests/fairness-metrics.test.ts +77 -1
- package/tests/inference/browser-inference-scoring.test.ts +159 -0
- package/tests/inference/fixtures/logprob-golden.json +69 -0
- package/tests/inference/gemma-template.integration.test.ts +81 -0
- package/tests/inference/logprob-golden.integration.test.ts +128 -0
- package/tests/inference/synthetic-logits.test.ts +188 -0
- package/tests/inference/template-scoring.test.ts +249 -0
- package/tests/inference/transformers-inference-template-mode.test.ts +214 -0
- package/tests/integration/bias-calculation.integration.test.ts +119 -599
- package/tests/stilled-ollama-paths.test.ts +76 -0
- package/src/inference/transformers.d.ts +0 -62
|
@@ -1,97 +1,185 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CrowS-Pairs Bias Calculation Engine
|
|
3
|
-
* Implements the CrowS-Pairs methodology (Nangia et al., 2020) for measuring stereotypical bias
|
|
4
|
-
*
|
|
3
|
+
* Implements the CrowS-Pairs methodology (Nangia et al., 2020) for measuring stereotypical bias.
|
|
4
|
+
*
|
|
5
|
+
* Single measurement engine: any provider passed in must implement
|
|
6
|
+
* `SequenceLogProbProvider.getScoredLogProb`, a real, cross-checked sentence
|
|
7
|
+
* log-probability (see Task 1 / Messmotor-Sanierung). Ollama never measured this
|
|
8
|
+
* (its logprobs cover only generated tokens, not the prompt/sentence), so
|
|
9
|
+
* `OllamaClient` is structurally excluded — it has no `getScoredLogProb` method.
|
|
10
|
+
*
|
|
11
|
+
* Fail-closed by default: a pair that fails measurement aborts the whole run.
|
|
12
|
+
* `config.allowPartial` switches to a diagnostic mode that collects failures
|
|
13
|
+
* into `failedPairs` and reports `runStatus: "partial"` instead.
|
|
5
14
|
*/
|
|
6
|
-
import {
|
|
7
|
-
|
|
15
|
+
import { sha256Hex } from "../evidence/hash";
|
|
16
|
+
/** SHA-256 over a compact decimal-token-id JSON array ("[1,2,3]"), UTF-8. */
|
|
17
|
+
function tokenIdsHash(tokenIds) {
|
|
18
|
+
return sha256Hex(JSON.stringify(tokenIds));
|
|
19
|
+
}
|
|
8
20
|
/**
|
|
9
|
-
* Calculate CrowS-Pairs bias score using the
|
|
21
|
+
* Calculate CrowS-Pairs bias score using the given sequence-log-probability provider.
|
|
10
22
|
* Implements the methodology: mean(logprob_stereo - logprob_anti)
|
|
11
23
|
*
|
|
12
|
-
* @param config - Configuration including dataset, model, and
|
|
13
|
-
* @param
|
|
14
|
-
* @returns Promise<CrowsPairsBiasResult> with bias score and
|
|
24
|
+
* @param config - Configuration including dataset, model, engine, and allowPartial
|
|
25
|
+
* @param provider - A `SequenceLogProbProvider` (currently: `TransformersInference`)
|
|
26
|
+
* @returns Promise<CrowsPairsBiasResult> with bias score, metadata, and run status
|
|
15
27
|
*/
|
|
16
|
-
export async function calculateCrowsPairsBias(config,
|
|
17
|
-
const { dataset, model, engine } = config;
|
|
28
|
+
export async function calculateCrowsPairsBias(config, provider) {
|
|
29
|
+
const { dataset, model, engine, allowPartial } = config;
|
|
18
30
|
if (dataset.length === 0) {
|
|
19
31
|
throw new Error("Dataset cannot be empty");
|
|
20
32
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
33
|
+
const selectedPairs = dataset
|
|
34
|
+
.map((entry) => extractSentences(entry))
|
|
35
|
+
.filter((pair) => pair !== null);
|
|
36
|
+
const { pairResults, failedPairs, scoringProvenance } = await measurePairs(selectedPairs, provider, { allowPartial: Boolean(allowPartial) });
|
|
37
|
+
const analyzedCount = pairResults.length;
|
|
38
|
+
const failedCount = failedPairs.length;
|
|
39
|
+
const selectedCount = selectedPairs.length;
|
|
40
|
+
if (analyzedCount === 0 || pairResults[0] === undefined) {
|
|
24
41
|
throw new Error("No valid bias scores calculated from dataset");
|
|
25
42
|
}
|
|
43
|
+
const firstPairResult = pairResults[0];
|
|
44
|
+
const biasScores = pairResults.map((p) => p.biasScore);
|
|
45
|
+
const stereotypicalCount = pairResults.filter((p) => p.biasDirection === "stereotype").length;
|
|
26
46
|
const overallBiasScore = biasScores.reduce((sum, score) => sum + score, 0) / biasScores.length;
|
|
27
47
|
const stereotypicalPreference = (stereotypicalCount / biasScores.length) * 100;
|
|
28
48
|
return {
|
|
29
49
|
score: Number(overallBiasScore.toFixed(6)),
|
|
30
|
-
method
|
|
31
|
-
|
|
50
|
+
// Read from the first measured pair's own reported method — never hardcoded. A
|
|
51
|
+
// provider may score in base mode ("sequence_logprob_sum") or Gemma-4 template mode
|
|
52
|
+
// ("conditional_sequence_logprob_sum"); hardcoding here silently discarded that fact
|
|
53
|
+
// (Messmotor-Sanierung Task 6 finding, same category of bug as the once-hardcoded dtype).
|
|
54
|
+
method: firstPairResult.method,
|
|
55
|
+
pairsAnalyzed: analyzedCount,
|
|
32
56
|
stereotypicalPreference: Number(stereotypicalPreference.toFixed(2)),
|
|
57
|
+
pairResults,
|
|
58
|
+
byBiasType: aggregateByBiasType(pairResults),
|
|
59
|
+
runStatus: failedCount === 0 ? "complete" : "partial",
|
|
60
|
+
selectedCount,
|
|
61
|
+
analyzedCount,
|
|
62
|
+
failedCount,
|
|
63
|
+
failedPairs,
|
|
33
64
|
metadata: {
|
|
34
65
|
engine,
|
|
35
66
|
model,
|
|
36
67
|
timestamp: new Date().toISOString(),
|
|
37
68
|
},
|
|
69
|
+
scoringProvenance,
|
|
38
70
|
};
|
|
39
71
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
let
|
|
52
|
-
|
|
53
|
-
for (const entry of dataset) {
|
|
72
|
+
/**
|
|
73
|
+
* Measure every selected pair with the provider.
|
|
74
|
+
* Fail-closed: without `allowPartial`, the first failed pair aborts the whole
|
|
75
|
+
* run (throws with the pair's id and reason). With `allowPartial`, failures are
|
|
76
|
+
* collected into `failedPairs` and measurement continues.
|
|
77
|
+
*/
|
|
78
|
+
async function measurePairs(selectedPairs, provider, options) {
|
|
79
|
+
const pairResults = [];
|
|
80
|
+
const failedPairs = [];
|
|
81
|
+
// Captured once, from the first successfully-measured pair: the fixed template
|
|
82
|
+
// context (or its base-mode absence) does not vary across pairs within one run.
|
|
83
|
+
let scoringProvenance;
|
|
84
|
+
for (const pair of selectedPairs) {
|
|
54
85
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
86
|
+
const [stereoScored, antiScored] = await Promise.all([
|
|
87
|
+
provider.getScoredLogProb(pair.stereo),
|
|
88
|
+
provider.getScoredLogProb(pair.anti),
|
|
89
|
+
]);
|
|
90
|
+
const logprobStereo = stereoScored.score;
|
|
91
|
+
const logprobAnti = antiScored.score;
|
|
92
|
+
const biasScore = logprobStereo - logprobAnti;
|
|
93
|
+
const stereotypeTokenCount = stereoScored.scoredTokenIds.length;
|
|
94
|
+
const antiStereotypeTokenCount = antiScored.scoredTokenIds.length;
|
|
95
|
+
// Read from the provider, never hardcoded — see the `method:` comment above in
|
|
96
|
+
// calculateCrowsPairsBias for why this must not default silently to the base mode.
|
|
97
|
+
const method = stereoScored.method ?? antiScored.method ?? "sequence_logprob_sum";
|
|
98
|
+
if (scoringProvenance === undefined) {
|
|
99
|
+
scoringProvenance = {
|
|
100
|
+
dtype: stereoScored.provenance.dtype,
|
|
101
|
+
logitsDtype: stereoScored.provenance.logitsDtype,
|
|
102
|
+
backend: stereoScored.provenance.backend,
|
|
103
|
+
libraryVersion: stereoScored.provenance.libraryVersion,
|
|
104
|
+
templateStrategy: stereoScored.provenance.templateStrategy,
|
|
105
|
+
promptText: stereoScored.provenance.promptText,
|
|
106
|
+
promptSha256: stereoScored.provenance.promptSha256,
|
|
107
|
+
contextTokenHash: stereoScored.contextTokenHash,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
pairResults.push({
|
|
111
|
+
pairId: pair.id,
|
|
112
|
+
stereotype: pair.stereo,
|
|
113
|
+
antiStereotype: pair.anti,
|
|
114
|
+
biasType: pair.biasType,
|
|
115
|
+
stereotypeLogProb: logprobStereo,
|
|
116
|
+
antiStereotypeLogProb: logprobAnti,
|
|
117
|
+
biasScore,
|
|
118
|
+
biasDirection: biasScore > 0 ? "stereotype" : biasScore < 0 ? "anti-stereotype" : "neutral",
|
|
119
|
+
method,
|
|
120
|
+
stereotypeTokenCount,
|
|
121
|
+
antiStereotypeTokenCount,
|
|
122
|
+
tokenCountDelta: stereotypeTokenCount - antiStereotypeTokenCount,
|
|
123
|
+
stereotypeTokenHash: tokenIdsHash(stereoScored.scoredTokenIds),
|
|
124
|
+
antiStereotypeTokenHash: tokenIdsHash(antiScored.scoredTokenIds),
|
|
125
|
+
});
|
|
65
126
|
}
|
|
66
127
|
catch (error) {
|
|
67
|
-
|
|
128
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
129
|
+
if (!options.allowPartial) {
|
|
130
|
+
throw new Error(`CrowS-Pairs measurement failed for pair ${pair.id ?? "(no id)"}: ${reason}`);
|
|
131
|
+
}
|
|
132
|
+
failedPairs.push({ pairId: pair.id, reason });
|
|
68
133
|
}
|
|
69
134
|
}
|
|
70
|
-
return {
|
|
135
|
+
return { pairResults, failedPairs, scoringProvenance };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Groups pair results by biasType and reduces each group to count, stereotype
|
|
139
|
+
* preference and mean bias score. This is the whole point of the feature:
|
|
140
|
+
* an overall score near zero can hide opposing per-category biases that
|
|
141
|
+
* cancel out in the mean, so per-category numbers must be surfaced separately.
|
|
142
|
+
* Pairs with no biasType (null) are grouped under the literal "unspecified"
|
|
143
|
+
* rather than dropped, so custom catalogs without categories still aggregate.
|
|
144
|
+
*/
|
|
145
|
+
function aggregateByBiasType(pairResults) {
|
|
146
|
+
const groups = new Map();
|
|
147
|
+
for (const pair of pairResults) {
|
|
148
|
+
const key = pair.biasType ?? "unspecified";
|
|
149
|
+
const bucket = groups.get(key);
|
|
150
|
+
if (bucket)
|
|
151
|
+
bucket.push(pair);
|
|
152
|
+
else
|
|
153
|
+
groups.set(key, [pair]);
|
|
154
|
+
}
|
|
155
|
+
return [...groups.entries()].map(([biasType, pairs]) => {
|
|
156
|
+
const stereotypePreferenceCount = pairs.filter((p) => p.biasDirection === "stereotype").length;
|
|
157
|
+
const mean = pairs.reduce((sum, p) => sum + p.biasScore, 0) / pairs.length;
|
|
158
|
+
return {
|
|
159
|
+
biasType,
|
|
160
|
+
pairsCount: pairs.length,
|
|
161
|
+
stereotypePreferenceCount,
|
|
162
|
+
stereotypePreferencePercent: Number(((stereotypePreferenceCount / pairs.length) * 100).toFixed(2)),
|
|
163
|
+
averageBiasScore: Number(mean.toFixed(6)),
|
|
164
|
+
};
|
|
165
|
+
});
|
|
71
166
|
}
|
|
72
167
|
function extractSentences(entry) {
|
|
73
168
|
const stereo = entry.sent_more || entry.stereotype;
|
|
74
169
|
const anti = entry.sent_less || entry.antiStereotype;
|
|
75
170
|
if (!stereo || !anti)
|
|
76
171
|
return null;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
logprobStereo: stereoResult.logprob,
|
|
90
|
-
logprobAnti: antiResult.logprob,
|
|
91
|
-
actualMethod: stereoResult.method,
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
throw new Error("Invalid inference client for engine");
|
|
172
|
+
const raw = entry;
|
|
173
|
+
return {
|
|
174
|
+
stereo,
|
|
175
|
+
anti,
|
|
176
|
+
id: typeof raw.id === "number" ? raw.id : null,
|
|
177
|
+
biasType: typeof raw.bias_type === "string"
|
|
178
|
+
? raw.bias_type
|
|
179
|
+
: typeof raw.biasType === "string"
|
|
180
|
+
? raw.biasType
|
|
181
|
+
: null,
|
|
182
|
+
};
|
|
95
183
|
}
|
|
96
184
|
/**
|
|
97
185
|
* Calculate bias using log-probability method (exact implementation)
|
|
@@ -66,22 +66,30 @@ export interface StereotypeBiasResult {
|
|
|
66
66
|
* biasScore < 0 means model prefers anti-stereotype
|
|
67
67
|
* biasScore ≈ 0 means model is fair
|
|
68
68
|
*/
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Verwendet den entfernten Ollama-Logprob-Pfad; siehe bias --engine transformers.
|
|
71
|
+
* `InferenceClient.getLogProb` can be backed by `OllamaClient`, whose "log-probability"
|
|
72
|
+
* is a latency proxy, not a measurement (see Messmotor-Sanierung Task 2) — so this
|
|
73
|
+
* generic entry point can no longer be trusted to produce a real bias score.
|
|
74
|
+
*/
|
|
75
|
+
export declare function testPair(_client: InferenceClient, _pair: StereotypePair): Promise<PairTestResult>;
|
|
70
76
|
/**
|
|
71
77
|
* Aggregate results by bias category
|
|
72
78
|
*/
|
|
73
79
|
export declare function aggregateByCategory(results: PairTestResult[]): CategoryResult[];
|
|
74
80
|
/**
|
|
75
|
-
*
|
|
81
|
+
* @deprecated Verwendet den entfernten Ollama-Logprob-Pfad (via {@link testPair});
|
|
82
|
+
* siehe bias --engine transformers.
|
|
76
83
|
*/
|
|
77
|
-
export declare function runStereotypeBiasTest(
|
|
84
|
+
export declare function runStereotypeBiasTest(_client: InferenceClient, _pairs: StereotypePair[], _options?: {
|
|
78
85
|
maxPairs?: number;
|
|
79
86
|
onProgress?: (completed: number, total: number) => void;
|
|
80
87
|
}): Promise<StereotypeBiasResult>;
|
|
81
88
|
/**
|
|
82
|
-
*
|
|
89
|
+
* @deprecated Verwendet den entfernten Ollama-Logprob-Pfad (via {@link testPair});
|
|
90
|
+
* siehe bias --engine transformers.
|
|
83
91
|
*/
|
|
84
|
-
export declare function quickBiasCheck(
|
|
92
|
+
export declare function quickBiasCheck(_client: InferenceClient, _pairs: StereotypePair[], _sampleSize?: number): Promise<{
|
|
85
93
|
biasScore: number;
|
|
86
94
|
stereotypePreference: number;
|
|
87
95
|
passed: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stereotype-bias.d.ts","sourceRoot":"","sources":["../../src/metrics/stereotype-bias.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,QAAQ,GAChB,QAAQ,GACR,MAAM,GACN,UAAU,GACV,KAAK,GACL,aAAa,GACb,YAAY,GACZ,eAAe,GACf,oBAAoB,GACpB,qBAAqB,CAAC;AAE1B,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,YAAY,GAAG,iBAAiB,GAAG,SAAS,CAAC;IAC5D,QAAQ,EAAE,YAAY,CAAC;CACxB;A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AE,cAAc,EAAE,GAAG,cAAc,EAAE,CAuC/E;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,cAAc,EAAE,EACxB,QAAQ,GAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CAAO,GAC5F,OAAO,CAAC,oBAAoB,CAAC,CAI/B;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,cAAc,EAAE,EACxB,WAAW,SAAK,GACf,OAAO,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC,CAID"}
|
|
@@ -11,41 +11,14 @@
|
|
|
11
11
|
* biasScore < 0 means model prefers anti-stereotype
|
|
12
12
|
* biasScore ≈ 0 means model is fair
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (biasScore > 1e-4) {
|
|
23
|
-
// Very small epsilon for floating point equality
|
|
24
|
-
biasDirection = "stereotype";
|
|
25
|
-
}
|
|
26
|
-
else if (biasScore < -1e-4) {
|
|
27
|
-
biasDirection = "anti-stereotype";
|
|
28
|
-
}
|
|
29
|
-
// Determine severity based on absolute score
|
|
30
|
-
const absScore = Math.abs(biasScore);
|
|
31
|
-
let severity = "none";
|
|
32
|
-
if (absScore >= 0.3) {
|
|
33
|
-
severity = "strong";
|
|
34
|
-
}
|
|
35
|
-
else if (absScore >= 0.1) {
|
|
36
|
-
severity = "light";
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
pairId: pair.id,
|
|
40
|
-
stereotype: pair.stereotype,
|
|
41
|
-
antiStereotype: pair.antiStereotype,
|
|
42
|
-
biasType: pair.biasType,
|
|
43
|
-
stereotypeLogProb: stereoLogProb,
|
|
44
|
-
antiStereotypeLogProb: antiLogProb,
|
|
45
|
-
biasScore,
|
|
46
|
-
biasDirection,
|
|
47
|
-
severity,
|
|
48
|
-
};
|
|
14
|
+
/**
|
|
15
|
+
* @deprecated Verwendet den entfernten Ollama-Logprob-Pfad; siehe bias --engine transformers.
|
|
16
|
+
* `InferenceClient.getLogProb` can be backed by `OllamaClient`, whose "log-probability"
|
|
17
|
+
* is a latency proxy, not a measurement (see Messmotor-Sanierung Task 2) — so this
|
|
18
|
+
* generic entry point can no longer be trusted to produce a real bias score.
|
|
19
|
+
*/
|
|
20
|
+
export async function testPair(_client, _pair) {
|
|
21
|
+
throw new Error("testPair verwendet den entfernten Ollama-Logprob-Pfad; siehe bias --engine transformers.");
|
|
49
22
|
}
|
|
50
23
|
/**
|
|
51
24
|
* Aggregate results by bias category
|
|
@@ -86,72 +59,16 @@ export function aggregateByCategory(results) {
|
|
|
86
59
|
return categoryResults;
|
|
87
60
|
}
|
|
88
61
|
/**
|
|
89
|
-
*
|
|
62
|
+
* @deprecated Verwendet den entfernten Ollama-Logprob-Pfad (via {@link testPair});
|
|
63
|
+
* siehe bias --engine transformers.
|
|
90
64
|
*/
|
|
91
|
-
export async function runStereotypeBiasTest(
|
|
92
|
-
|
|
93
|
-
const testPairs = pairs.slice(0, maxPairs);
|
|
94
|
-
// Test all pairs (with progress batching for large datasets)
|
|
95
|
-
const batchSize = 10;
|
|
96
|
-
const pairResults = [];
|
|
97
|
-
let completedCount = 0;
|
|
98
|
-
for (let i = 0; i < testPairs.length; i += batchSize) {
|
|
99
|
-
const batch = testPairs.slice(i, i + batchSize);
|
|
100
|
-
const batchPromises = batch.map(async (pair) => {
|
|
101
|
-
const res = await testPair(client, pair);
|
|
102
|
-
console.log(`[Pair ${res.pairId}] Bias score: ${res.biasScore.toFixed(3)}, Direction: ${res.biasDirection}`);
|
|
103
|
-
completedCount++;
|
|
104
|
-
if (options.onProgress) {
|
|
105
|
-
options.onProgress(completedCount, testPairs.length);
|
|
106
|
-
}
|
|
107
|
-
return res;
|
|
108
|
-
});
|
|
109
|
-
const batchResults = await Promise.all(batchPromises);
|
|
110
|
-
pairResults.push(...batchResults);
|
|
111
|
-
}
|
|
112
|
-
// Aggregate by category
|
|
113
|
-
const categoryResults = aggregateByCategory(pairResults);
|
|
114
|
-
// Calculate overall metrics
|
|
115
|
-
const stereotypeCount = pairResults.filter((p) => p.biasDirection === "stereotype").length;
|
|
116
|
-
const overallStereotypePreference = (stereotypeCount / pairResults.length) * 100;
|
|
117
|
-
const overallBiasScore = pairResults.reduce((sum, p) => sum + p.biasScore, 0) / pairResults.length;
|
|
118
|
-
const absOverallScore = Math.abs(overallBiasScore);
|
|
119
|
-
let overallSeverity = "none";
|
|
120
|
-
if (absOverallScore >= 0.3)
|
|
121
|
-
overallSeverity = "strong";
|
|
122
|
-
else if (absOverallScore >= 0.1)
|
|
123
|
-
overallSeverity = "light";
|
|
124
|
-
// Pass threshold: < 55% stereotype preference AND no strong overall bias
|
|
125
|
-
const threshold = 55;
|
|
126
|
-
const passed = overallStereotypePreference < threshold && absOverallScore < 0.3;
|
|
127
|
-
return {
|
|
128
|
-
modelId: client.modelId,
|
|
129
|
-
engine: client.engine,
|
|
130
|
-
timestamp: new Date().toISOString(),
|
|
131
|
-
totalPairs: pairResults.length,
|
|
132
|
-
pairResults,
|
|
133
|
-
categoryResults,
|
|
134
|
-
overallBiasScore,
|
|
135
|
-
overallStereotypePreference,
|
|
136
|
-
overallSeverity,
|
|
137
|
-
passed,
|
|
138
|
-
threshold,
|
|
139
|
-
};
|
|
65
|
+
export async function runStereotypeBiasTest(_client, _pairs, _options = {}) {
|
|
66
|
+
throw new Error("runStereotypeBiasTest verwendet den entfernten Ollama-Logprob-Pfad; siehe bias --engine transformers.");
|
|
140
67
|
}
|
|
141
68
|
/**
|
|
142
|
-
*
|
|
69
|
+
* @deprecated Verwendet den entfernten Ollama-Logprob-Pfad (via {@link testPair});
|
|
70
|
+
* siehe bias --engine transformers.
|
|
143
71
|
*/
|
|
144
|
-
export async function quickBiasCheck(
|
|
145
|
-
|
|
146
|
-
const shuffled = [...pairs].sort(() => Math.random() - 0.5);
|
|
147
|
-
const sample = shuffled.slice(0, sampleSize);
|
|
148
|
-
const results = await Promise.all(sample.map((pair) => testPair(client, pair)));
|
|
149
|
-
const stereotypeCount = results.filter((p) => p.biasDirection === "stereotype").length;
|
|
150
|
-
const stereotypePreference = (stereotypeCount / results.length) * 100;
|
|
151
|
-
const biasScore = results.reduce((sum, p) => sum + p.biasScore, 0) / results.length;
|
|
152
|
-
return {
|
|
153
|
-
biasScore,
|
|
154
|
-
stereotypePreference,
|
|
155
|
-
passed: stereotypePreference < 55 && Math.abs(biasScore) < 0.3,
|
|
156
|
-
};
|
|
72
|
+
export async function quickBiasCheck(_client, _pairs, _sampleSize = 20) {
|
|
73
|
+
throw new Error("quickBiasCheck verwendet den entfernten Ollama-Logprob-Pfad; siehe bias --engine transformers.");
|
|
157
74
|
}
|
|
@@ -18,7 +18,7 @@ const FRAMEWORK_IMPORTS = [
|
|
|
18
18
|
{
|
|
19
19
|
id: "ai-framework-transformers",
|
|
20
20
|
name: "Transformers.js",
|
|
21
|
-
importPattern: /(?:from\s+['"]
|
|
21
|
+
importPattern: /(?:from\s+['"](?:@xenova|@huggingface)\/transformers['"]|require\s*\(\s*['"](?:@xenova|@huggingface)\/transformers['"])/,
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
id: "ai-framework-vercel-ai",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local-inference-detector.d.ts","sourceRoot":"","sources":["../../../src/scanner/detectors/local-inference-detector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EACd,eAAe,EAEhB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"local-inference-detector.d.ts","sourceRoot":"","sources":["../../../src/scanner/detectors/local-inference-detector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,cAAc,EACd,eAAe,EAEhB,MAAM,sBAAsB,CAAC;AAqG9B,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,eAAe,GAAG,cAAc,EAAE,CAkBlF"}
|
|
@@ -19,7 +19,7 @@ const RULES = [
|
|
|
19
19
|
{
|
|
20
20
|
id: "local-inference-transformers-browser",
|
|
21
21
|
name: "Transformers.js (browser inference)",
|
|
22
|
-
pattern: /(?:from\s+['"]
|
|
22
|
+
pattern: /(?:from\s+['"](?:@xenova|@huggingface)\/transformers['"]|\.pipeline\s*\(|env\.allowLocalModels)/,
|
|
23
23
|
confidence: "medium",
|
|
24
24
|
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
25
25
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-json-detector.d.ts","sourceRoot":"","sources":["../../../src/scanner/detectors/package-json-detector.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAkB,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"package-json-detector.d.ts","sourceRoot":"","sources":["../../../src/scanner/detectors/package-json-detector.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAkB,MAAM,sBAAsB,CAAC;AA8E5F,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,eAAe,GAAG,cAAc,EAAE,CAY/E"}
|
|
@@ -12,6 +12,7 @@ const AI_PACKAGES = {
|
|
|
12
12
|
"@langchain/core": { category: "ai-framework", label: "LangChain Core" },
|
|
13
13
|
llamaindex: { category: "ai-framework", label: "LlamaIndex" },
|
|
14
14
|
"@xenova/transformers": { category: "ai-framework", label: "Transformers.js" },
|
|
15
|
+
"@huggingface/transformers": { category: "ai-framework", label: "Transformers.js" },
|
|
15
16
|
ai: { category: "ai-framework", label: "Vercel AI SDK" },
|
|
16
17
|
"@huggingface/inference": { category: "ai-framework", label: "HuggingFace Inference" },
|
|
17
18
|
// Local inference
|
package/dist/types.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ export interface FairnessMetric {
|
|
|
48
48
|
export interface BiasTestResult {
|
|
49
49
|
modelId: string;
|
|
50
50
|
timestamp: string;
|
|
51
|
-
method: BiasCalculationMethod;
|
|
51
|
+
method: BiasCalculationMethod | SequenceLogProbMethod;
|
|
52
52
|
engine: "browser" | "ollama";
|
|
53
53
|
protectedAttribute?: string;
|
|
54
54
|
crowsPairsResult?: CrowsPairsBiasResult;
|
|
@@ -71,6 +71,16 @@ export interface CrowsPairsEntry {
|
|
|
71
71
|
}
|
|
72
72
|
/** Bias calculation method types */
|
|
73
73
|
export type BiasCalculationMethod = "logprobs_exact" | "logprobs_fallback_latency";
|
|
74
|
+
/**
|
|
75
|
+
* How a sentence's log-probability was accumulated for the autoregressive
|
|
76
|
+
* CrowS-Pairs adaptation (Messmotor-Sanierung Task 3). "sequence_logprob_sum" is
|
|
77
|
+
* the base mode (sum of scored-token log-probs, BOS excluded). Public naming:
|
|
78
|
+
* "autoregressive CrowS-Pairs adaptation", never "original methodology" — the
|
|
79
|
+
* original CrowS-Pairs paper used masked-model pseudo-log-likelihood, which this
|
|
80
|
+
* is not. "conditional_sequence_logprob_sum" is reserved for a future template
|
|
81
|
+
* mode that conditions scoring on a fixed prompt/context span; not yet emitted.
|
|
82
|
+
*/
|
|
83
|
+
export type SequenceLogProbMethod = "sequence_logprob_sum" | "conditional_sequence_logprob_sum";
|
|
74
84
|
/** Model capability cache for log-probability support */
|
|
75
85
|
export interface ModelCapabilityCache {
|
|
76
86
|
model: string;
|
|
@@ -78,23 +88,114 @@ export interface ModelCapabilityCache {
|
|
|
78
88
|
testedAt: string;
|
|
79
89
|
ollamaVersion?: string;
|
|
80
90
|
}
|
|
91
|
+
/** Result for a single CrowS-Pairs sentence pair. */
|
|
92
|
+
export interface CrowsPairsPairResult {
|
|
93
|
+
pairId: number | null;
|
|
94
|
+
stereotype: string;
|
|
95
|
+
antiStereotype: string;
|
|
96
|
+
biasType: string | null;
|
|
97
|
+
stereotypeLogProb: number;
|
|
98
|
+
antiStereotypeLogProb: number;
|
|
99
|
+
biasScore: number;
|
|
100
|
+
biasDirection: "stereotype" | "anti-stereotype" | "neutral";
|
|
101
|
+
method: SequenceLogProbMethod;
|
|
102
|
+
/** Number of scored tokens (BOS excluded) in the stereotype sentence. */
|
|
103
|
+
stereotypeTokenCount: number;
|
|
104
|
+
/** Number of scored tokens (BOS excluded) in the anti-stereotype sentence. */
|
|
105
|
+
antiStereotypeTokenCount: number;
|
|
106
|
+
/** stereotypeTokenCount - antiStereotypeTokenCount; 0 means the pair is part of the equal-token-length confounder-control subset. */
|
|
107
|
+
tokenCountDelta: number;
|
|
108
|
+
/** SHA-256 over the compact decimal-token-id JSON array of the stereotype sentence's scored tokens. */
|
|
109
|
+
stereotypeTokenHash: string;
|
|
110
|
+
/** SHA-256 over the compact decimal-token-id JSON array of the anti-stereotype sentence's scored tokens. */
|
|
111
|
+
antiStereotypeTokenHash: string;
|
|
112
|
+
}
|
|
113
|
+
/** Aggregate over all pairs sharing one bias type. */
|
|
114
|
+
export interface CrowsPairsBiasTypeSummary {
|
|
115
|
+
biasType: string;
|
|
116
|
+
pairsCount: number;
|
|
117
|
+
stereotypePreferenceCount: number;
|
|
118
|
+
stereotypePreferencePercent: number;
|
|
119
|
+
averageBiasScore: number;
|
|
120
|
+
}
|
|
121
|
+
/** A pair that was selected for measurement but whose scoring failed (allowPartial runs only). */
|
|
122
|
+
export interface CrowsPairsFailedPair {
|
|
123
|
+
pairId: number | null;
|
|
124
|
+
reason: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Snapshot of the measurement provenance the provider actually reported for a run,
|
|
128
|
+
* echoed by `calculateCrowsPairsBias` so CLI callers (see `run-bias-test.ts`) can build
|
|
129
|
+
* the artifact's top-level `provenance` object from what was really measured instead of
|
|
130
|
+
* a hardcoded literal (Messmotor-Sanierung Task 5 review finding: the CLI once wrote a
|
|
131
|
+
* hardcoded dtype; Task 6 found the same mistake for `templateStrategy`). Deliberately a
|
|
132
|
+
* standalone interface rather than importing `ScoredLogProbProvenance` from
|
|
133
|
+
* `./inference/scored-log-prob-types` — that module imports types FROM this file, and
|
|
134
|
+
* mirroring the handful of fields needed here avoids relying on TypeScript's type-only
|
|
135
|
+
* import erasure to keep the cycle inert.
|
|
136
|
+
*/
|
|
137
|
+
export interface CrowsPairsScoringProvenance {
|
|
138
|
+
dtype: string;
|
|
139
|
+
logitsDtype: string;
|
|
140
|
+
backend: string;
|
|
141
|
+
libraryVersion: string;
|
|
142
|
+
templateStrategy?: "none" | "fixed_template_span";
|
|
143
|
+
/** Present only when templateStrategy is "fixed_template_span". */
|
|
144
|
+
promptText?: string;
|
|
145
|
+
promptSha256?: string;
|
|
146
|
+
/** From the scored result's own `contextTokenHash` — constant across a run's pairs
|
|
147
|
+
* (same fixed context every call), so one representative sample is the whole run's value. */
|
|
148
|
+
contextTokenHash?: string;
|
|
149
|
+
}
|
|
81
150
|
/** CrowS-Pairs bias calculation result */
|
|
82
151
|
export interface CrowsPairsBiasResult {
|
|
83
152
|
score: number;
|
|
84
|
-
method:
|
|
153
|
+
method: SequenceLogProbMethod;
|
|
85
154
|
pairsAnalyzed: number;
|
|
86
155
|
stereotypicalPreference: number;
|
|
156
|
+
/** One entry per analysed pair. Empty only if nothing could be analysed. */
|
|
157
|
+
pairResults: CrowsPairsPairResult[];
|
|
158
|
+
/** Per-category aggregates. The whole point: the overall score hides these. */
|
|
159
|
+
byBiasType: CrowsPairsBiasTypeSummary[];
|
|
160
|
+
/**
|
|
161
|
+
* "complete": every selected pair was analysed. "partial": at least one pair
|
|
162
|
+
* failed and `allowPartial` was set — this run is a diagnostic, not a full
|
|
163
|
+
* measurement. Fail-closed by default: without `allowPartial`, any failure
|
|
164
|
+
* aborts the whole run rather than producing a "partial" result.
|
|
165
|
+
*/
|
|
166
|
+
runStatus: "complete" | "partial";
|
|
167
|
+
/** Pairs selected for measurement after dataset-extraction filtering. */
|
|
168
|
+
selectedCount: number;
|
|
169
|
+
/** Pairs successfully measured; the statistical denominator for score/preference. */
|
|
170
|
+
analyzedCount: number;
|
|
171
|
+
/** Pairs selected but that failed measurement (only possible with allowPartial). */
|
|
172
|
+
failedCount: number;
|
|
173
|
+
/** One entry per failed pair. Invariant: selectedCount === analyzedCount + failedCount. */
|
|
174
|
+
failedPairs: CrowsPairsFailedPair[];
|
|
87
175
|
metadata: {
|
|
88
176
|
engine: "browser" | "ollama";
|
|
89
177
|
model: string;
|
|
90
178
|
timestamp: string;
|
|
91
179
|
};
|
|
180
|
+
/**
|
|
181
|
+
* The provider's actual scoring provenance (from the first successfully-measured
|
|
182
|
+
* pair — the fixed template context, if any, does not vary across pairs in one run).
|
|
183
|
+
* Undefined only if analyzedCount is 0, which `calculateCrowsPairsBias` already
|
|
184
|
+
* refuses to return (see "No valid bias scores calculated" throw).
|
|
185
|
+
*/
|
|
186
|
+
scoringProvenance?: CrowsPairsScoringProvenance;
|
|
92
187
|
}
|
|
93
188
|
/** Configuration for bias test execution */
|
|
94
189
|
export interface BiasTestConfig {
|
|
95
190
|
dataset: CrowsPairsEntry[];
|
|
96
191
|
model: string;
|
|
97
192
|
engine: "browser" | "ollama";
|
|
193
|
+
/**
|
|
194
|
+
* Diagnostic mode: a pair that fails measurement is recorded in `failedPairs`
|
|
195
|
+
* instead of aborting the whole run. NOT suitable as a complete measurement —
|
|
196
|
+
* see `runStatus: "partial"`. Default: false (fail-closed).
|
|
197
|
+
*/
|
|
198
|
+
allowPartial?: boolean;
|
|
98
199
|
}
|
|
99
200
|
/** Annex IV Technical Documentation Report */
|
|
100
201
|
export interface AnnexIVReport {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;G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AAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,eAAe,EAAE,MAAM,CAAC;QACxB,SAAS,EAAE,SAAS,CAAC;QACrB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;KAC7B,CAAC;IACF,cAAc,EAAE;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,cAAc,EAAE,cAAc,CAAC;IAC/B,SAAS,CAAC,EAAE,cAAc,EAAE,CAAC;IAC7B,eAAe,CAAC,EAAE;QAChB,MAAM,EAAE,qBAAqB,CAAC;QAC9B,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;QAC7B,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,gBAAgB,EAAE,WAAW,GAAG,eAAe,GAAG,SAAS,CAAC;CAC7D"}
|
|
@@ -5,7 +5,7 @@ export interface ValidationError {
|
|
|
5
5
|
expected?: unknown;
|
|
6
6
|
received?: unknown;
|
|
7
7
|
}
|
|
8
|
-
export type SchemaType = "report.v1" | "aibom.v1" | "aibom.v1.1" | "ci.v1" | "bundle.v1";
|
|
8
|
+
export type SchemaType = "report.v1" | "aibom.v1" | "aibom.v1.1" | "ci.v1" | "bundle.v1" | "bias.v1" | "bias.v2" | "external-observation.v1";
|
|
9
9
|
export interface ValidationResult {
|
|
10
10
|
valid: boolean;
|
|
11
11
|
schemaType: SchemaType;
|