@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.
Files changed (141) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +34 -0
  3. package/dist/datasets/crows-pairs.d.ts +18 -0
  4. package/dist/datasets/crows-pairs.d.ts.map +1 -1
  5. package/dist/datasets/crows-pairs.js +58 -0
  6. package/dist/evidence/bias-comparison-markdown.d.ts +11 -0
  7. package/dist/evidence/bias-comparison-markdown.d.ts.map +1 -0
  8. package/dist/evidence/bias-comparison-markdown.js +120 -0
  9. package/dist/evidence/bias-comparison.d.ts +133 -0
  10. package/dist/evidence/bias-comparison.d.ts.map +1 -0
  11. package/dist/evidence/bias-comparison.js +274 -0
  12. package/dist/evidence/bias-statistics.d.ts +72 -0
  13. package/dist/evidence/bias-statistics.d.ts.map +1 -0
  14. package/dist/evidence/bias-statistics.js +122 -0
  15. package/dist/evidence/bias-v2-semantics.d.ts +19 -0
  16. package/dist/evidence/bias-v2-semantics.d.ts.map +1 -0
  17. package/dist/evidence/bias-v2-semantics.js +133 -0
  18. package/dist/evidence/browser.d.ts +18 -0
  19. package/dist/evidence/browser.d.ts.map +1 -0
  20. package/dist/evidence/browser.js +14 -0
  21. package/dist/evidence/bundle.d.ts +1 -0
  22. package/dist/evidence/bundle.d.ts.map +1 -1
  23. package/dist/evidence/bundle.js +2 -0
  24. package/dist/evidence/index.d.ts +9 -2
  25. package/dist/evidence/index.d.ts.map +1 -1
  26. package/dist/evidence/index.js +5 -1
  27. package/dist/evidence/types.d.ts +175 -1
  28. package/dist/evidence/types.d.ts.map +1 -1
  29. package/dist/evidence/validate-bias-v2.d.ts +31 -0
  30. package/dist/evidence/validate-bias-v2.d.ts.map +1 -0
  31. package/dist/evidence/validate-bias-v2.js +40 -0
  32. package/dist/evidence/validate.d.ts +29 -2
  33. package/dist/evidence/validate.d.ts.map +1 -1
  34. package/dist/evidence/validate.js +90 -8
  35. package/dist/fairness-metrics.d.ts +15 -11
  36. package/dist/fairness-metrics.d.ts.map +1 -1
  37. package/dist/fairness-metrics.js +59 -183
  38. package/dist/index.d.ts +2 -2
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/inference/browser-inference.d.ts +6 -57
  42. package/dist/inference/browser-inference.d.ts.map +1 -1
  43. package/dist/inference/browser-inference.js +6 -219
  44. package/dist/inference/capability-detection.d.ts +9 -2
  45. package/dist/inference/capability-detection.d.ts.map +1 -1
  46. package/dist/inference/capability-detection.js +18 -16
  47. package/dist/inference/index.d.ts +15 -2
  48. package/dist/inference/index.d.ts.map +1 -1
  49. package/dist/inference/index.js +12 -3
  50. package/dist/inference/inference-factory.d.ts +6 -3
  51. package/dist/inference/inference-factory.d.ts.map +1 -1
  52. package/dist/inference/inference-factory.js +7 -26
  53. package/dist/inference/ollama-client.d.ts +29 -0
  54. package/dist/inference/ollama-client.d.ts.map +1 -1
  55. package/dist/inference/ollama-client.js +29 -0
  56. package/dist/inference/scored-log-prob-types.d.ts +64 -0
  57. package/dist/inference/scored-log-prob-types.d.ts.map +1 -0
  58. package/dist/inference/scored-log-prob-types.js +12 -0
  59. package/dist/inference/sequence-logprob.d.ts +34 -0
  60. package/dist/inference/sequence-logprob.d.ts.map +1 -0
  61. package/dist/inference/sequence-logprob.js +87 -0
  62. package/dist/inference/template-scoring.d.ts +124 -0
  63. package/dist/inference/template-scoring.d.ts.map +1 -0
  64. package/dist/inference/template-scoring.js +164 -0
  65. package/dist/inference/transformers-inference.d.ts +124 -0
  66. package/dist/inference/transformers-inference.d.ts.map +1 -0
  67. package/dist/inference/transformers-inference.js +392 -0
  68. package/dist/legal-checks/bias-metrics.d.ts +5 -7
  69. package/dist/legal-checks/bias-metrics.d.ts.map +1 -1
  70. package/dist/legal-checks/bias-metrics.js +8 -101
  71. package/dist/metrics/crows-pairs-bias.d.ts +17 -9
  72. package/dist/metrics/crows-pairs-bias.d.ts.map +1 -1
  73. package/dist/metrics/crows-pairs-bias.js +147 -59
  74. package/dist/metrics/stereotype-bias.d.ts +13 -5
  75. package/dist/metrics/stereotype-bias.d.ts.map +1 -1
  76. package/dist/metrics/stereotype-bias.js +16 -99
  77. package/dist/scanner/detectors/ai-framework-detector.js +1 -1
  78. package/dist/scanner/detectors/local-inference-detector.d.ts.map +1 -1
  79. package/dist/scanner/detectors/local-inference-detector.js +1 -1
  80. package/dist/scanner/detectors/package-json-detector.d.ts.map +1 -1
  81. package/dist/scanner/detectors/package-json-detector.js +1 -0
  82. package/dist/types.d.ts +103 -2
  83. package/dist/types.d.ts.map +1 -1
  84. package/dist/validation/schema-validator.d.ts +1 -1
  85. package/dist/validation/schema-validator.d.ts.map +1 -1
  86. package/dist/validation/schema-validator.js +6 -0
  87. package/package.json +4 -2
  88. package/scripts/seed-logprob-fixture.mjs +179 -0
  89. package/scripts/ts-extensionless-resolve-hook.mjs +26 -0
  90. package/src/datasets/crows-pairs.ts +74 -0
  91. package/src/evidence/bias-comparison-markdown.ts +162 -0
  92. package/src/evidence/bias-comparison.ts +432 -0
  93. package/src/evidence/bias-statistics.ts +180 -0
  94. package/src/evidence/bias-v2-semantics.ts +214 -0
  95. package/src/evidence/browser.ts +35 -0
  96. package/src/evidence/bundle.ts +2 -0
  97. package/src/evidence/index.ts +31 -0
  98. package/src/evidence/types.ts +204 -1
  99. package/src/evidence/validate-bias-v2.ts +47 -0
  100. package/src/evidence/validate.ts +140 -13
  101. package/src/fairness-metrics.ts +79 -222
  102. package/src/index.ts +7 -0
  103. package/src/inference/browser-inference.ts +14 -256
  104. package/src/inference/capability-detection.ts +32 -18
  105. package/src/inference/index.ts +33 -5
  106. package/src/inference/inference-factory.ts +9 -30
  107. package/src/inference/ollama-client.ts +29 -0
  108. package/src/inference/scored-log-prob-types.ts +66 -0
  109. package/src/inference/sequence-logprob.ts +136 -0
  110. package/src/inference/template-scoring.ts +248 -0
  111. package/src/inference/transformers-inference.ts +494 -0
  112. package/src/legal-checks/bias-metrics.ts +20 -118
  113. package/src/metrics/crows-pairs-bias.ts +180 -83
  114. package/src/metrics/stereotype-bias.ts +27 -119
  115. package/src/scanner/detectors/ai-framework-detector.ts +1 -1
  116. package/src/scanner/detectors/local-inference-detector.ts +2 -1
  117. package/src/scanner/detectors/package-json-detector.ts +1 -0
  118. package/src/types.ts +108 -2
  119. package/src/validation/schema-validator.ts +15 -1
  120. package/tests/annex-iv-report.test.ts +1 -1
  121. package/tests/capability-detection.test.ts +57 -0
  122. package/tests/crows-pairs-bias.test.ts +286 -186
  123. package/tests/custom-dataset.test.ts +80 -0
  124. package/tests/evidence/bias-artifact-v2.test.ts +135 -0
  125. package/tests/evidence/bias-artifact.test.ts +78 -0
  126. package/tests/evidence/bias-comparison.test.ts +397 -0
  127. package/tests/evidence/bias-statistics.test.ts +191 -0
  128. package/tests/evidence/external-observation.test.ts +167 -0
  129. package/tests/evidence/spec-schemas.test.ts +35 -2
  130. package/tests/evidence/validate-bias-v2.test.ts +180 -0
  131. package/tests/fairness-metrics.test.ts +77 -1
  132. package/tests/inference/browser-inference-scoring.test.ts +159 -0
  133. package/tests/inference/fixtures/logprob-golden.json +69 -0
  134. package/tests/inference/gemma-template.integration.test.ts +81 -0
  135. package/tests/inference/logprob-golden.integration.test.ts +128 -0
  136. package/tests/inference/synthetic-logits.test.ts +188 -0
  137. package/tests/inference/template-scoring.test.ts +249 -0
  138. package/tests/inference/transformers-inference-template-mode.test.ts +214 -0
  139. package/tests/integration/bias-calculation.integration.test.ts +119 -599
  140. package/tests/stilled-ollama-paths.test.ts +76 -0
  141. package/src/inference/transformers.d.ts +0 -62
@@ -0,0 +1,76 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ runComprehensiveBiasAnalysisWithFactory,
4
+ runCrowsPairsBiasAnalysisWithFactory,
5
+ } from "../src/fairness-metrics";
6
+ import type { InferenceClient } from "../src/inference";
7
+ import { InferenceFactory } from "../src/inference/inference-factory";
8
+ import { runCrowsPairsLogProbTest } from "../src/legal-checks/bias-metrics";
9
+ import { quickBiasCheck, runStereotypeBiasTest, testPair } from "../src/metrics/stereotype-bias";
10
+ import type { BiasTestConfig } from "../src/types";
11
+
12
+ /**
13
+ * These entry points measured bias via Ollama's `getLogProb` (a latency proxy,
14
+ * not a real sentence log-probability — see Messmotor-Sanierung Task 2) and
15
+ * cannot be trivially converted to the new `SequenceLogProbProvider` contract
16
+ * without a real redesign (auto engine-selection, capability detection, etc.).
17
+ * They're stilled: calling them throws a speaking message pointing at the
18
+ * supported path instead of silently producing a broken measurement.
19
+ */
20
+ describe("stilled Ollama-era entry points", () => {
21
+ const dummyClient: InferenceClient = {
22
+ engine: "ollama",
23
+ modelId: "dummy",
24
+ generate: async () => "",
25
+ getLogProb: async () => 0,
26
+ };
27
+
28
+ it("testPair throws with a pointer to bias --engine transformers", async () => {
29
+ await expect(
30
+ testPair(dummyClient, {
31
+ id: 1,
32
+ stereotype: "a",
33
+ antiStereotype: "b",
34
+ biasType: "gender",
35
+ })
36
+ ).rejects.toThrow(/bias --engine transformers/);
37
+ });
38
+
39
+ it("runStereotypeBiasTest throws with a pointer to bias --engine transformers", async () => {
40
+ await expect(runStereotypeBiasTest(dummyClient, [])).rejects.toThrow(
41
+ /bias --engine transformers/
42
+ );
43
+ });
44
+
45
+ it("quickBiasCheck throws with a pointer to bias --engine transformers", async () => {
46
+ await expect(quickBiasCheck(dummyClient, [])).rejects.toThrow(/bias --engine transformers/);
47
+ });
48
+
49
+ it("runCrowsPairsLogProbTest throws with a pointer to bias --engine transformers", async () => {
50
+ await expect(runCrowsPairsLogProbTest(dummyClient, [])).rejects.toThrow(
51
+ /bias --engine transformers/
52
+ );
53
+ });
54
+
55
+ it("InferenceFactory.createBiasCalculation throws with a pointer to bias --engine transformers", async () => {
56
+ const factory = new InferenceFactory();
57
+ const config: BiasTestConfig = { dataset: [], model: "m", engine: "browser" };
58
+ await expect(factory.createBiasCalculation(config)).rejects.toThrow(
59
+ /bias --engine transformers/
60
+ );
61
+ });
62
+
63
+ it("runCrowsPairsBiasAnalysisWithFactory throws with a pointer to bias --engine transformers", async () => {
64
+ const config: BiasTestConfig = { dataset: [], model: "m", engine: "browser" };
65
+ await expect(runCrowsPairsBiasAnalysisWithFactory(config)).rejects.toThrow(
66
+ /bias --engine transformers/
67
+ );
68
+ });
69
+
70
+ it("runComprehensiveBiasAnalysisWithFactory throws with a pointer to bias --engine transformers", async () => {
71
+ const config: BiasTestConfig = { dataset: [], model: "m", engine: "browser" };
72
+ await expect(runComprehensiveBiasAnalysisWithFactory([], config, "gender")).rejects.toThrow(
73
+ /bias --engine transformers/
74
+ );
75
+ });
76
+ });
@@ -1,62 +0,0 @@
1
- /**
2
- * Type declarations for @xenova/transformers (optional dependency)
3
- *
4
- * This package is only needed for browser-based inference.
5
- * If not installed, browser inference will gracefully fall back.
6
- */
7
-
8
- declare module "@xenova/transformers" {
9
- export function pipeline(
10
- task: "text-generation",
11
- model: string,
12
- options?: {
13
- device?: "webgpu" | "cpu";
14
- }
15
- ): Promise<TextGenerationPipeline>;
16
-
17
- export type TextGenerationPipeline = (
18
- text: string,
19
- options?: {
20
- max_new_tokens?: number;
21
- temperature?: number;
22
- do_sample?: boolean;
23
- }
24
- ) => Promise<Array<{ generated_text: string }>>;
25
-
26
- export interface Tensor {
27
- data: Float32Array;
28
- dims: number[];
29
- }
30
-
31
- export interface ModelOutput {
32
- logits: Tensor;
33
- }
34
-
35
- export interface TokenizerOutput {
36
- input_ids: Tensor;
37
- }
38
-
39
- export interface AutoTokenizer {
40
- (text: string, options?: { return_tensors?: string }): Promise<TokenizerOutput>;
41
- from_pretrained(modelId: string): Promise<AutoTokenizer>;
42
- }
43
-
44
- export interface AutoModelForCausalLM {
45
- (inputs: TokenizerOutput): Promise<ModelOutput>;
46
- from_pretrained(
47
- modelId: string,
48
- options?: { device?: string; dtype?: string }
49
- ): Promise<AutoModelForCausalLM>;
50
- }
51
-
52
- export const AutoTokenizer: {
53
- from_pretrained(modelId: string): Promise<AutoTokenizer>;
54
- };
55
-
56
- export const AutoModelForCausalLM: {
57
- from_pretrained(
58
- modelId: string,
59
- options?: { device?: string; dtype?: string }
60
- ): Promise<AutoModelForCausalLM>;
61
- };
62
- }