@zanii/blackbox 0.2.0 → 0.4.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 (94) hide show
  1. package/README.md +26 -1
  2. package/dist/a2a/index.d.ts +77 -0
  3. package/dist/a2a/index.js +305 -0
  4. package/dist/agents/index.d.ts +8 -0
  5. package/dist/analysis/accuracy.d.ts +24 -0
  6. package/dist/analysis/accuracy.js +45 -0
  7. package/dist/analysis/credential.d.ts +101 -0
  8. package/dist/analysis/credential.js +142 -0
  9. package/dist/analysis/faults.js +115 -0
  10. package/dist/analysis/grounding.d.ts +122 -0
  11. package/dist/analysis/grounding.js +445 -0
  12. package/dist/analysis/hallucination.d.ts +32 -0
  13. package/dist/analysis/hallucination.js +357 -0
  14. package/dist/analysis/index.d.ts +23 -0
  15. package/dist/analysis/index.js +93 -0
  16. package/dist/analysis/memory.d.ts +8 -0
  17. package/dist/analysis/memory.js +35 -8
  18. package/dist/analysis/reference.d.ts +49 -0
  19. package/dist/analysis/reference.js +164 -0
  20. package/dist/analysis/taxonomy.d.ts +18 -0
  21. package/dist/analysis/taxonomy.js +66 -0
  22. package/dist/approvals/index.d.ts +23 -0
  23. package/dist/approvals/index.js +48 -0
  24. package/dist/archive/index.d.ts +39 -0
  25. package/dist/archive/index.js +96 -0
  26. package/dist/archive/parquet.d.ts +2 -0
  27. package/dist/archive/parquet.js +185 -0
  28. package/dist/badge/index.d.ts +16 -0
  29. package/dist/badge/index.js +48 -0
  30. package/dist/bom/index.d.ts +14 -0
  31. package/dist/bom/index.js +152 -0
  32. package/dist/cli.js +114 -10
  33. package/dist/compliance/art12.d.ts +35 -0
  34. package/dist/compliance/art12.js +190 -0
  35. package/dist/compliance/index.d.ts +36 -2
  36. package/dist/compliance/index.js +78 -11
  37. package/dist/compliance/zanii.d.ts +29 -0
  38. package/dist/compliance/zanii.js +84 -0
  39. package/dist/constitution/index.d.ts +57 -0
  40. package/dist/constitution/index.js +131 -0
  41. package/dist/cv/index.d.ts +39 -0
  42. package/dist/cv/index.js +108 -0
  43. package/dist/disclosure/index.d.ts +31 -0
  44. package/dist/disclosure/index.js +113 -0
  45. package/dist/encryption/index.d.ts +9 -0
  46. package/dist/encryption/index.js +31 -0
  47. package/dist/evidence/index.d.ts +60 -0
  48. package/dist/evidence/index.js +151 -0
  49. package/dist/federation/index.d.ts +35 -0
  50. package/dist/federation/index.js +102 -0
  51. package/dist/finance/index.d.ts +126 -0
  52. package/dist/finance/index.js +320 -0
  53. package/dist/fleet/index.js +9 -0
  54. package/dist/gov/index.d.ts +108 -0
  55. package/dist/gov/index.js +225 -0
  56. package/dist/health/index.d.ts +120 -0
  57. package/dist/health/index.js +233 -0
  58. package/dist/index.d.ts +34 -5
  59. package/dist/index.js +34 -5
  60. package/dist/memory/index.d.ts +36 -0
  61. package/dist/memory/index.js +85 -0
  62. package/dist/occurrence/index.d.ts +11 -0
  63. package/dist/occurrence/index.js +18 -0
  64. package/dist/ocsf/index.d.ts +1 -1
  65. package/dist/ocsf/index.js +36 -3
  66. package/dist/otlp/index.d.ts +8 -1
  67. package/dist/otlp/index.js +258 -1
  68. package/dist/packs/index.js +44 -4
  69. package/dist/policy/delta.js +7 -1
  70. package/dist/policy/index.d.ts +40 -6
  71. package/dist/policy/index.js +186 -8
  72. package/dist/policy/zanii.d.ts +31 -0
  73. package/dist/policy/zanii.js +87 -0
  74. package/dist/pq/index.d.ts +23 -0
  75. package/dist/pq/index.js +104 -0
  76. package/dist/search/index.d.ts +23 -0
  77. package/dist/search/index.js +69 -0
  78. package/dist/session/index.d.ts +107 -1
  79. package/dist/session/index.js +189 -11
  80. package/dist/sla/index.d.ts +61 -0
  81. package/dist/sla/index.js +197 -0
  82. package/dist/succession/index.d.ts +50 -0
  83. package/dist/succession/index.js +123 -0
  84. package/dist/timestamp/index.d.ts +24 -0
  85. package/dist/timestamp/index.js +274 -0
  86. package/dist/tokens/index.d.ts +6 -0
  87. package/dist/tokens/index.js +46 -0
  88. package/dist/transparency/index.d.ts +188 -0
  89. package/dist/transparency/index.js +712 -0
  90. package/dist/version.d.ts +1 -1
  91. package/dist/version.js +1 -1
  92. package/dist/walls/index.d.ts +31 -0
  93. package/dist/walls/index.js +119 -0
  94. package/package.json +1 -1
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.2.0";
1
+ export declare const VERSION = "0.4.0";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // The SDK version, on its own so the CLI can print it without loading the whole SDK.
2
- export const VERSION = "0.2.0";
2
+ export const VERSION = "0.4.0";
@@ -0,0 +1,31 @@
1
+ export interface Wall {
2
+ id: string;
3
+ regulator: string;
4
+ scopes: string[];
5
+ denies: string[];
6
+ forbidden: string[];
7
+ note: string;
8
+ }
9
+ export declare const WALLS: Readonly<Record<string, Wall>>;
10
+ /** Zanii's wall manifest hash: the id and its sorted scopes and denies (order-independent). */
11
+ export declare const wallManifestHash: (w: Wall) => string;
12
+ /** Zanii's heuristic: an output crosses the wall when it holds a forbidden phrase. */
13
+ export declare function checkOutput(w: Wall, text: string): {
14
+ ok: boolean;
15
+ violations: string[];
16
+ };
17
+ /**
18
+ * spec/governance.md §5: WALL_CROSSED for each model response that holds a phrase one of the
19
+ * walls forbids; one finding per response and wall, naming the first phrase.
20
+ */
21
+ export declare function wallFindings(lines: readonly string[], bodies: (hash: string) => Uint8Array | undefined, wallIds: readonly string[]): {
22
+ code: string;
23
+ source: string;
24
+ severity: "warning";
25
+ ref: {
26
+ seq: number;
27
+ wall: string;
28
+ phrase: string;
29
+ };
30
+ detail: string;
31
+ }[];
@@ -0,0 +1,119 @@
1
+ // Zanii's UAE vertical walls (spec/governance.md §5): the table from spec/walls/v1.json, embedded
2
+ // (a test checks it matches), and the output check. Mirrors sdks/python/src/zanii_blackbox/walls.py.
3
+ import { jcsHash } from "@zanii/core";
4
+ export const WALLS = {
5
+ "sca-trading": {
6
+ id: "sca-trading",
7
+ regulator: "SCA",
8
+ scopes: ["trading.education.*", "market.read.*"],
9
+ denies: ["trading.execute.*", "trading.advise.*", "trading.recommend.*"],
10
+ forbidden: [
11
+ "buy this",
12
+ "sell this",
13
+ "you should buy",
14
+ "you should sell",
15
+ "i recommend buying",
16
+ "i recommend selling",
17
+ "guaranteed return",
18
+ "guaranteed profit",
19
+ "this will go up",
20
+ "will moon",
21
+ ],
22
+ note: 'education only; NEVER "buy this" — investment advice/execution is a licensed SCA activity',
23
+ },
24
+ "rera-realty": {
25
+ id: "rera-realty",
26
+ regulator: "RERA/DLD",
27
+ scopes: ["realty.inform.*", "realty.read.*"],
28
+ denies: ["realty.broker.*", "realty.list.*"],
29
+ forbidden: ["i can broker", "i will list", "sign the deal"],
30
+ note: "informs; never brokers or lists unpermitted properties",
31
+ },
32
+ "tdra-messaging": {
33
+ id: "tdra-messaging",
34
+ regulator: "TDRA",
35
+ scopes: ["messaging.send.optin.*"],
36
+ denies: ["messaging.send.bulk.*", "messaging.send.nonoptin.*"],
37
+ forbidden: [],
38
+ note: "opt-in only; must announce it is a bot",
39
+ },
40
+ "legal-drafting": {
41
+ id: "legal-drafting",
42
+ regulator: "Legal Affairs",
43
+ scopes: ["legal.draft.*", "legal.read.*"],
44
+ denies: ["legal.opine.*", "legal.advise.*"],
45
+ forbidden: ["my legal opinion is", "you should sue", "this is legally binding advice"],
46
+ note: "drafts; never gives legal opinions",
47
+ },
48
+ "consumer-due": {
49
+ id: "consumer-due",
50
+ regulator: "Consumer Protection / Central Bank",
51
+ scopes: ["collections.remind.*"],
52
+ denies: ["collections.threaten.*"],
53
+ forbidden: ["we will sue you", "legal action today", "you will be arrested"],
54
+ note: "reminds; never threatens; frequency limits",
55
+ },
56
+ "difc-dp": {
57
+ id: "difc-dp",
58
+ regulator: "DIFC (DP Law 2020)",
59
+ scopes: ["data.process.difc.*"],
60
+ denies: ["data.export.nonadequate.*"],
61
+ forbidden: [],
62
+ note: "DIFC free-zone data protection; select per deployment (not federal PDPL)",
63
+ },
64
+ "adgm-dp": {
65
+ id: "adgm-dp",
66
+ regulator: "ADGM (DP Regs 2021)",
67
+ scopes: ["data.process.adgm.*"],
68
+ denies: ["data.export.nonadequate.*"],
69
+ forbidden: [],
70
+ note: "ADGM free-zone data protection; select per deployment (not federal PDPL)",
71
+ },
72
+ };
73
+ /** Zanii's wall manifest hash: the id and its sorted scopes and denies (order-independent). */
74
+ export const wallManifestHash = (w) => jcsHash({ id: w.id, scopes: [...w.scopes].sort(), denies: [...w.denies].sort() });
75
+ /** Zanii's heuristic: an output crosses the wall when it holds a forbidden phrase. */
76
+ export function checkOutput(w, text) {
77
+ const lower = text.toLowerCase();
78
+ const violations = w.forbidden.filter((p) => lower.includes(p));
79
+ return { ok: violations.length === 0, violations };
80
+ }
81
+ const decoder = new TextDecoder();
82
+ /**
83
+ * spec/governance.md §5: WALL_CROSSED for each model response that holds a phrase one of the
84
+ * walls forbids; one finding per response and wall, naming the first phrase.
85
+ */
86
+ export function wallFindings(lines, bodies, wallIds) {
87
+ const walls = wallIds.map((id) => WALLS[id]).filter((w) => w !== undefined);
88
+ const out = [];
89
+ if (walls.length === 0)
90
+ return out;
91
+ // a response's bytes are its chunks' bodies, joined in order (spec/api.md: llm.chunk)
92
+ const chunks = new Map();
93
+ for (const l of lines) {
94
+ const e = JSON.parse(l);
95
+ if (e.kind === "llm.chunk") {
96
+ const body = bodies(e.body_hash);
97
+ const list = chunks.get(e.meta.request_seq) ?? [];
98
+ list.push(body ? decoder.decode(body) : "");
99
+ chunks.set(e.meta.request_seq, list);
100
+ }
101
+ if (e.kind !== "llm.response")
102
+ continue;
103
+ const text = (chunks.get(e.meta.request_seq) ?? []).join("");
104
+ if (!text)
105
+ continue;
106
+ for (const w of walls) {
107
+ const check = checkOutput(w, text);
108
+ if (!check.ok)
109
+ out.push({
110
+ code: "WALL_CROSSED",
111
+ source: "detectors",
112
+ severity: "warning",
113
+ ref: { seq: e.seq, wall: w.id, phrase: check.violations[0] },
114
+ detail: `The model's answer crossed the ${w.regulator} wall: ${w.note}`,
115
+ });
116
+ }
117
+ }
118
+ return out;
119
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zanii/blackbox",
3
3
  "license": "Apache-2.0",
4
- "version": "0.2.0",
4
+ "version": "0.4.0",
5
5
  "description": "The flight recorder for AI agents: sessions, a zero-loss spool, framework hooks, approvals, and offline verification of the gateway's hash-chained record.",
6
6
  "keywords": [
7
7
  "ai-agents",