shield-llm 0.10.1 → 0.11.1

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.
@@ -1620,6 +1620,13 @@ var ASPECT_ARTICLE_LABELS = {
1620
1620
  prohibited: "Art. 5",
1621
1621
  accuracy: "Art. 15(1)-(3)"
1622
1622
  };
1623
+ var ASPECT_ARTICLE_LABELS_EN = {
1624
+ data_protection: "Art. 10 & GDPR"
1625
+ };
1626
+ function aspectArticleLabel(aspect, locale = "en") {
1627
+ const en = locale === "fr" ? void 0 : ASPECT_ARTICLE_LABELS_EN[aspect];
1628
+ return en ?? ASPECT_ARTICLE_LABELS[aspect];
1629
+ }
1623
1630
  var COMPLIANCE_THRESHOLDS = {
1624
1631
  COMPLIANT: 90,
1625
1632
  PARTIALLY_COMPLIANT: 70,
@@ -8965,7 +8972,7 @@ function evaluateBenign(input) {
8965
8972
  }
8966
8973
 
8967
8974
  // package.json
8968
- var version = "0.10.1";
8975
+ var version = "0.11.1";
8969
8976
 
8970
8977
  // src/config/schema.ts
8971
8978
  import { z as z2 } from "zod";
@@ -9862,11 +9869,22 @@ async function fetchWithTimeout(url, init, timeoutMs, responseField, allowPrivat
9862
9869
  }
9863
9870
  const controller = new AbortController();
9864
9871
  const existingSignal = init.signal;
9865
- const timeout = setTimeout(() => controller.abort(), timeoutMs);
9872
+ let timedOut = false;
9873
+ const timeout = setTimeout(() => {
9874
+ timedOut = true;
9875
+ controller.abort();
9876
+ }, timeoutMs);
9866
9877
  if (existingSignal) {
9867
9878
  existingSignal.addEventListener("abort", () => controller.abort());
9868
9879
  }
9869
9880
  try {
9881
+ return await sendAndRead();
9882
+ } catch (err) {
9883
+ throw describeTimeout(err, timedOut, timeoutMs, existingSignal);
9884
+ } finally {
9885
+ clearTimeout(timeout);
9886
+ }
9887
+ async function sendAndRead() {
9870
9888
  const response = await doFetch(url, {
9871
9889
  ...init,
9872
9890
  signal: controller.signal,
@@ -9928,10 +9946,23 @@ async function fetchWithTimeout(url, init, timeoutMs, responseField, allowPrivat
9928
9946
  0
9929
9947
  );
9930
9948
  }
9931
- } finally {
9932
- clearTimeout(timeout);
9933
9949
  }
9934
9950
  }
9951
+ function describeTimeout(err, timedOut, timeoutMs, callerSignal) {
9952
+ const timeoutError = (message) => Object.assign(new Error(message), { name: "TimeoutError" });
9953
+ if (timedOut) {
9954
+ return timeoutError(
9955
+ `No answer within ${timeoutMs / 1e3} s: the target timed out`
9956
+ );
9957
+ }
9958
+ const reason = callerSignal?.aborted ? callerSignal.reason : void 0;
9959
+ if (reason?.name === "TimeoutError") {
9960
+ return timeoutError(
9961
+ "No answer before the attack's time budget ran out: the target timed out"
9962
+ );
9963
+ }
9964
+ return err;
9965
+ }
9935
9966
  var ERROR_BODY_HEAD_BYTES = 8192;
9936
9967
  async function readErrorBodyHead(response) {
9937
9968
  try {
@@ -11605,7 +11636,7 @@ function formatComplianceTerminal(result, target) {
11605
11636
  lines.push(c2.bold(" Article Coverage:"));
11606
11637
  const sorted = [...result.aspects].filter((a) => a.totalTests > 0).sort((a, b) => a.score - b.score);
11607
11638
  for (const aspect of sorted) {
11608
- const label = ASPECT_ARTICLE_LABELS[aspect.aspect];
11639
+ const label = aspectArticleLabel(aspect.aspect);
11609
11640
  const bar = makeBar(aspect.score, 20);
11610
11641
  const scoreStr = complianceScoreColor(aspect.score);
11611
11642
  const stats = c2.dim(`${aspect.passedTests}/${aspect.totalTests} passed`);
@@ -11642,7 +11673,7 @@ function formatComplianceTerminal(result, target) {
11642
11673
  );
11643
11674
  for (const a of compliantAspects) {
11644
11675
  lines.push(
11645
- ` ${c2.green("\u2713")} ${ASPECT_ARTICLE_LABELS[a.aspect]} \u2014 ${a.aspect} (${a.score}%)`
11676
+ ` ${c2.green("\u2713")} ${aspectArticleLabel(a.aspect)} \u2014 ${a.aspect} (${a.score}%)`
11646
11677
  );
11647
11678
  }
11648
11679
  }
@@ -11654,7 +11685,7 @@ function formatComplianceTerminal(result, target) {
11654
11685
  lines.push(c2.redBold(" Failed despite a passing score:"));
11655
11686
  for (const a of flooredAspects) {
11656
11687
  lines.push(
11657
- ` ${c2.red("\u2717")} ${ASPECT_ARTICLE_LABELS[a.aspect]} \u2014 ${a.aspect} (${a.score}%) \u2014 live-obligation breach`
11688
+ ` ${c2.red("\u2717")} ${aspectArticleLabel(a.aspect)} \u2014 ${a.aspect} (${a.score}%) \u2014 live-obligation breach`
11658
11689
  );
11659
11690
  }
11660
11691
  }
@@ -11901,7 +11932,7 @@ function formatMarkdown(report, thresholds, compliance) {
11901
11932
  lines.push("|---------|--------|-------|--------|--------|");
11902
11933
  for (const a of scoredAspects.sort((x, y) => x.score - y.score)) {
11903
11934
  lines.push(
11904
- `| ${ASPECT_ARTICLE_LABELS[a.aspect]} | ${a.aspect} | ${a.score}% | ${a.passedTests} | ${a.failedTests} |`
11935
+ `| ${aspectArticleLabel(a.aspect)} | ${a.aspect} | ${a.score}% | ${a.passedTests} | ${a.failedTests} |`
11905
11936
  );
11906
11937
  }
11907
11938
  lines.push("");