agentid-sdk 0.1.28 → 0.1.30

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/README.md CHANGED
@@ -114,6 +114,16 @@ Wrapped OpenAI calls persist telemetry for both regular and streamed completions
114
114
 
115
115
  > Scope note: AgentID compliance/risk controls apply to the specific SDK-wrapped LLM calls (`guard()`, `wrapOpenAI()`, LangChain callback-wrapped flows). They do not automatically classify unrelated code paths in your whole monolithic application.
116
116
 
117
+ ### Vercel AI SDK Wrapper
118
+
119
+ If your app already uses Vercel AI SDK primitives such as `generateText()` or `streamText()`, prefer the dedicated wrapper package instead of rebuilding the lifecycle manually:
120
+
121
+ ```bash
122
+ npm install ai agentid-vercel-sdk @ai-sdk/openai
123
+ ```
124
+
125
+ `agentid-vercel-sdk` keeps AgentID backend-first by default, blocks before provider billing on denied prompts, and finalizes telemetry after completion or stream close.
126
+
117
127
  ### LangChain Integration
118
128
 
119
129
  ```bash
@@ -172,7 +182,7 @@ await agent.log({
172
182
  When rendering disclosure UI, log proof-of-render telemetry so you can demonstrate the end-user actually saw the badge.
173
183
 
174
184
  ```tsx
175
- import { AgentIDTransparencyBadge } from "agentid-sdk";
185
+ import { AgentIDTransparencyBadge } from "agentid-sdk/transparency-badge";
176
186
 
177
187
  <AgentIDTransparencyBadge
178
188
  telemetry={{
@@ -1419,8 +1419,135 @@ async function sha256Hex(text) {
1419
1419
  const buf = await subtle.digest("SHA-256", data);
1420
1420
  return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
1421
1421
  }
1422
- const nodeCrypto = await import("crypto");
1423
- return nodeCrypto.createHash("sha256").update(data).digest("hex");
1422
+ return sha256HexFallback(data);
1423
+ }
1424
+ function sha256HexFallback(data) {
1425
+ const K = [
1426
+ 1116352408,
1427
+ 1899447441,
1428
+ 3049323471,
1429
+ 3921009573,
1430
+ 961987163,
1431
+ 1508970993,
1432
+ 2453635748,
1433
+ 2870763221,
1434
+ 3624381080,
1435
+ 310598401,
1436
+ 607225278,
1437
+ 1426881987,
1438
+ 1925078388,
1439
+ 2162078206,
1440
+ 2614888103,
1441
+ 3248222580,
1442
+ 3835390401,
1443
+ 4022224774,
1444
+ 264347078,
1445
+ 604807628,
1446
+ 770255983,
1447
+ 1249150122,
1448
+ 1555081692,
1449
+ 1996064986,
1450
+ 2554220882,
1451
+ 2821834349,
1452
+ 2952996808,
1453
+ 3210313671,
1454
+ 3336571891,
1455
+ 3584528711,
1456
+ 113926993,
1457
+ 338241895,
1458
+ 666307205,
1459
+ 773529912,
1460
+ 1294757372,
1461
+ 1396182291,
1462
+ 1695183700,
1463
+ 1986661051,
1464
+ 2177026350,
1465
+ 2456956037,
1466
+ 2730485921,
1467
+ 2820302411,
1468
+ 3259730800,
1469
+ 3345764771,
1470
+ 3516065817,
1471
+ 3600352804,
1472
+ 4094571909,
1473
+ 275423344,
1474
+ 430227734,
1475
+ 506948616,
1476
+ 659060556,
1477
+ 883997877,
1478
+ 958139571,
1479
+ 1322822218,
1480
+ 1537002063,
1481
+ 1747873779,
1482
+ 1955562222,
1483
+ 2024104815,
1484
+ 2227730452,
1485
+ 2361852424,
1486
+ 2428436474,
1487
+ 2756734187,
1488
+ 3204031479,
1489
+ 3329325298
1490
+ ];
1491
+ const H = [
1492
+ 1779033703,
1493
+ 3144134277,
1494
+ 1013904242,
1495
+ 2773480762,
1496
+ 1359893119,
1497
+ 2600822924,
1498
+ 528734635,
1499
+ 1541459225
1500
+ ];
1501
+ const length = data.length;
1502
+ const bitLengthHi = Math.floor(length * 8 / 4294967296);
1503
+ const bitLengthLo = length * 8 >>> 0;
1504
+ const paddedLength = length + 9 + 63 >> 6 << 6 >>> 0;
1505
+ const padded = new Uint8Array(paddedLength);
1506
+ padded.set(data);
1507
+ padded[length] = 128;
1508
+ const view = new DataView(padded.buffer);
1509
+ view.setUint32(paddedLength - 8, bitLengthHi, false);
1510
+ view.setUint32(paddedLength - 4, bitLengthLo, false);
1511
+ const w = new Uint32Array(64);
1512
+ for (let offset = 0; offset < paddedLength; offset += 64) {
1513
+ for (let i = 0; i < 16; i += 1) {
1514
+ w[i] = view.getUint32(offset + i * 4, false);
1515
+ }
1516
+ for (let i = 16; i < 64; i += 1) {
1517
+ const s0 = rightRotate(w[i - 15], 7) ^ rightRotate(w[i - 15], 18) ^ w[i - 15] >>> 3;
1518
+ const s1 = rightRotate(w[i - 2], 17) ^ rightRotate(w[i - 2], 19) ^ w[i - 2] >>> 10;
1519
+ w[i] = (w[i - 16] + s0 >>> 0) + (w[i - 7] + s1 >>> 0) >>> 0;
1520
+ }
1521
+ let [a, b, c, d, e, f, g, h] = H;
1522
+ for (let i = 0; i < 64; i += 1) {
1523
+ const S1 = rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25);
1524
+ const ch = e & f ^ ~e & g;
1525
+ const temp1 = ((h + S1 >>> 0) + (ch + K[i] >>> 0) >>> 0) + w[i] >>> 0;
1526
+ const S0 = rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22);
1527
+ const maj = a & b ^ a & c ^ b & c;
1528
+ const temp2 = S0 + maj >>> 0;
1529
+ h = g;
1530
+ g = f;
1531
+ f = e;
1532
+ e = d + temp1 >>> 0;
1533
+ d = c;
1534
+ c = b;
1535
+ b = a;
1536
+ a = temp1 + temp2 >>> 0;
1537
+ }
1538
+ H[0] = H[0] + a >>> 0;
1539
+ H[1] = H[1] + b >>> 0;
1540
+ H[2] = H[2] + c >>> 0;
1541
+ H[3] = H[3] + d >>> 0;
1542
+ H[4] = H[4] + e >>> 0;
1543
+ H[5] = H[5] + f >>> 0;
1544
+ H[6] = H[6] + g >>> 0;
1545
+ H[7] = H[7] + h >>> 0;
1546
+ }
1547
+ return H.map((value) => value.toString(16).padStart(8, "0")).join("");
1548
+ }
1549
+ function rightRotate(value, shift) {
1550
+ return value >>> shift | value << 32 - shift;
1424
1551
  }
1425
1552
  function safeJsonParse(raw) {
1426
1553
  try {
@@ -1683,7 +1810,7 @@ function getInjectionScanner() {
1683
1810
 
1684
1811
  // src/sdk-version.ts
1685
1812
  var FALLBACK_SDK_VERSION = "js-0.0.0-dev";
1686
- var AGENTID_SDK_VERSION_HEADER = "js-0.1.28".trim().length > 0 ? "js-0.1.28" : FALLBACK_SDK_VERSION;
1813
+ var AGENTID_SDK_VERSION_HEADER = "js-0.1.30".trim().length > 0 ? "js-0.1.30" : FALLBACK_SDK_VERSION;
1687
1814
 
1688
1815
  // src/local-security-enforcer.ts
1689
1816
  var DEFAULT_FAIL_OPEN_CONFIG = {
package/dist/index.d.mts CHANGED
@@ -1,6 +1,4 @@
1
- import { T as TransparencyMetadata } from './agentid-agvYW2vW.mjs';
2
- export { A as AgentID, D as DependencyError, G as GuardParams, a as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions, S as SecurityBlockError } from './agentid-agvYW2vW.mjs';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ export { A as AgentID, D as DependencyError, G as GuardParams, a as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions, S as SecurityBlockError, T as TransparencyMetadata } from './agentid-agvYW2vW.mjs';
4
2
 
5
3
  type PIIMapping = Record<string, string>;
6
4
  declare class PIIManager {
@@ -62,25 +60,4 @@ declare class InjectionScanner {
62
60
  }
63
61
  declare function getInjectionScanner(): InjectionScanner;
64
62
 
65
- type AgentIDTransparencyBadgeTelemetry = {
66
- systemId: string;
67
- apiKey?: string;
68
- ingestUrl?: string;
69
- baseUrl?: string;
70
- userId?: string;
71
- model?: string;
72
- headers?: Record<string, string>;
73
- metadata?: Record<string, unknown>;
74
- onError?: (error: unknown) => void;
75
- };
76
- type AgentIDTransparencyBadgeProps = {
77
- telemetry: AgentIDTransparencyBadgeTelemetry;
78
- metadata?: TransparencyMetadata | null;
79
- message?: string;
80
- placement?: "chat-header" | "watermark-overlay";
81
- fixed?: boolean;
82
- className?: string;
83
- };
84
- declare function AgentIDTransparencyBadge(props: AgentIDTransparencyBadgeProps): react_jsx_runtime.JSX.Element;
85
-
86
- export { AgentIDTransparencyBadge, type AgentIDTransparencyBadgeProps, type AgentIDTransparencyBadgeTelemetry, type InjectionScanParams, InjectionScanner, type LLMAdapter, OpenAIAdapter, PIIManager, type PIIMapping, type TokenUsage, TransparencyMetadata, getInjectionScanner, scanWithRegex };
63
+ export { type InjectionScanParams, InjectionScanner, type LLMAdapter, OpenAIAdapter, PIIManager, type PIIMapping, type TokenUsage, getInjectionScanner, scanWithRegex };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { T as TransparencyMetadata } from './agentid-agvYW2vW.js';
2
- export { A as AgentID, D as DependencyError, G as GuardParams, a as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions, S as SecurityBlockError } from './agentid-agvYW2vW.js';
3
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ export { A as AgentID, D as DependencyError, G as GuardParams, a as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions, S as SecurityBlockError, T as TransparencyMetadata } from './agentid-agvYW2vW.js';
4
2
 
5
3
  type PIIMapping = Record<string, string>;
6
4
  declare class PIIManager {
@@ -62,25 +60,4 @@ declare class InjectionScanner {
62
60
  }
63
61
  declare function getInjectionScanner(): InjectionScanner;
64
62
 
65
- type AgentIDTransparencyBadgeTelemetry = {
66
- systemId: string;
67
- apiKey?: string;
68
- ingestUrl?: string;
69
- baseUrl?: string;
70
- userId?: string;
71
- model?: string;
72
- headers?: Record<string, string>;
73
- metadata?: Record<string, unknown>;
74
- onError?: (error: unknown) => void;
75
- };
76
- type AgentIDTransparencyBadgeProps = {
77
- telemetry: AgentIDTransparencyBadgeTelemetry;
78
- metadata?: TransparencyMetadata | null;
79
- message?: string;
80
- placement?: "chat-header" | "watermark-overlay";
81
- fixed?: boolean;
82
- className?: string;
83
- };
84
- declare function AgentIDTransparencyBadge(props: AgentIDTransparencyBadgeProps): react_jsx_runtime.JSX.Element;
85
-
86
- export { AgentIDTransparencyBadge, type AgentIDTransparencyBadgeProps, type AgentIDTransparencyBadgeTelemetry, type InjectionScanParams, InjectionScanner, type LLMAdapter, OpenAIAdapter, PIIManager, type PIIMapping, type TokenUsage, TransparencyMetadata, getInjectionScanner, scanWithRegex };
63
+ export { type InjectionScanParams, InjectionScanner, type LLMAdapter, OpenAIAdapter, PIIManager, type PIIMapping, type TokenUsage, getInjectionScanner, scanWithRegex };
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,21 +15,12 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
31
21
  var index_exports = {};
32
22
  __export(index_exports, {
33
23
  AgentID: () => AgentID,
34
- AgentIDTransparencyBadge: () => AgentIDTransparencyBadge,
35
24
  DependencyError: () => DependencyError,
36
25
  InjectionScanner: () => InjectionScanner,
37
26
  OpenAIAdapter: () => OpenAIAdapter,
@@ -86,7 +75,7 @@ var OpenAIAdapter = class {
86
75
 
87
76
  // src/sdk-version.ts
88
77
  var FALLBACK_SDK_VERSION = "js-0.0.0-dev";
89
- var AGENTID_SDK_VERSION_HEADER = "js-0.1.28".trim().length > 0 ? "js-0.1.28" : FALLBACK_SDK_VERSION;
78
+ var AGENTID_SDK_VERSION_HEADER = "js-0.1.30".trim().length > 0 ? "js-0.1.30" : FALLBACK_SDK_VERSION;
90
79
 
91
80
  // src/pii-national-identifiers.ts
92
81
  var MAX_CANDIDATES_PER_RULE = 256;
@@ -1831,8 +1820,135 @@ async function sha256Hex(text) {
1831
1820
  const buf = await subtle.digest("SHA-256", data);
1832
1821
  return Array.from(new Uint8Array(buf)).map((b) => b.toString(16).padStart(2, "0")).join("");
1833
1822
  }
1834
- const nodeCrypto = await import("crypto");
1835
- return nodeCrypto.createHash("sha256").update(data).digest("hex");
1823
+ return sha256HexFallback(data);
1824
+ }
1825
+ function sha256HexFallback(data) {
1826
+ const K = [
1827
+ 1116352408,
1828
+ 1899447441,
1829
+ 3049323471,
1830
+ 3921009573,
1831
+ 961987163,
1832
+ 1508970993,
1833
+ 2453635748,
1834
+ 2870763221,
1835
+ 3624381080,
1836
+ 310598401,
1837
+ 607225278,
1838
+ 1426881987,
1839
+ 1925078388,
1840
+ 2162078206,
1841
+ 2614888103,
1842
+ 3248222580,
1843
+ 3835390401,
1844
+ 4022224774,
1845
+ 264347078,
1846
+ 604807628,
1847
+ 770255983,
1848
+ 1249150122,
1849
+ 1555081692,
1850
+ 1996064986,
1851
+ 2554220882,
1852
+ 2821834349,
1853
+ 2952996808,
1854
+ 3210313671,
1855
+ 3336571891,
1856
+ 3584528711,
1857
+ 113926993,
1858
+ 338241895,
1859
+ 666307205,
1860
+ 773529912,
1861
+ 1294757372,
1862
+ 1396182291,
1863
+ 1695183700,
1864
+ 1986661051,
1865
+ 2177026350,
1866
+ 2456956037,
1867
+ 2730485921,
1868
+ 2820302411,
1869
+ 3259730800,
1870
+ 3345764771,
1871
+ 3516065817,
1872
+ 3600352804,
1873
+ 4094571909,
1874
+ 275423344,
1875
+ 430227734,
1876
+ 506948616,
1877
+ 659060556,
1878
+ 883997877,
1879
+ 958139571,
1880
+ 1322822218,
1881
+ 1537002063,
1882
+ 1747873779,
1883
+ 1955562222,
1884
+ 2024104815,
1885
+ 2227730452,
1886
+ 2361852424,
1887
+ 2428436474,
1888
+ 2756734187,
1889
+ 3204031479,
1890
+ 3329325298
1891
+ ];
1892
+ const H = [
1893
+ 1779033703,
1894
+ 3144134277,
1895
+ 1013904242,
1896
+ 2773480762,
1897
+ 1359893119,
1898
+ 2600822924,
1899
+ 528734635,
1900
+ 1541459225
1901
+ ];
1902
+ const length = data.length;
1903
+ const bitLengthHi = Math.floor(length * 8 / 4294967296);
1904
+ const bitLengthLo = length * 8 >>> 0;
1905
+ const paddedLength = length + 9 + 63 >> 6 << 6 >>> 0;
1906
+ const padded = new Uint8Array(paddedLength);
1907
+ padded.set(data);
1908
+ padded[length] = 128;
1909
+ const view = new DataView(padded.buffer);
1910
+ view.setUint32(paddedLength - 8, bitLengthHi, false);
1911
+ view.setUint32(paddedLength - 4, bitLengthLo, false);
1912
+ const w = new Uint32Array(64);
1913
+ for (let offset = 0; offset < paddedLength; offset += 64) {
1914
+ for (let i = 0; i < 16; i += 1) {
1915
+ w[i] = view.getUint32(offset + i * 4, false);
1916
+ }
1917
+ for (let i = 16; i < 64; i += 1) {
1918
+ const s0 = rightRotate(w[i - 15], 7) ^ rightRotate(w[i - 15], 18) ^ w[i - 15] >>> 3;
1919
+ const s1 = rightRotate(w[i - 2], 17) ^ rightRotate(w[i - 2], 19) ^ w[i - 2] >>> 10;
1920
+ w[i] = (w[i - 16] + s0 >>> 0) + (w[i - 7] + s1 >>> 0) >>> 0;
1921
+ }
1922
+ let [a, b, c, d, e, f, g, h] = H;
1923
+ for (let i = 0; i < 64; i += 1) {
1924
+ const S1 = rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25);
1925
+ const ch = e & f ^ ~e & g;
1926
+ const temp1 = ((h + S1 >>> 0) + (ch + K[i] >>> 0) >>> 0) + w[i] >>> 0;
1927
+ const S0 = rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22);
1928
+ const maj = a & b ^ a & c ^ b & c;
1929
+ const temp2 = S0 + maj >>> 0;
1930
+ h = g;
1931
+ g = f;
1932
+ f = e;
1933
+ e = d + temp1 >>> 0;
1934
+ d = c;
1935
+ c = b;
1936
+ b = a;
1937
+ a = temp1 + temp2 >>> 0;
1938
+ }
1939
+ H[0] = H[0] + a >>> 0;
1940
+ H[1] = H[1] + b >>> 0;
1941
+ H[2] = H[2] + c >>> 0;
1942
+ H[3] = H[3] + d >>> 0;
1943
+ H[4] = H[4] + e >>> 0;
1944
+ H[5] = H[5] + f >>> 0;
1945
+ H[6] = H[6] + g >>> 0;
1946
+ H[7] = H[7] + h >>> 0;
1947
+ }
1948
+ return H.map((value) => value.toString(16).padStart(8, "0")).join("");
1949
+ }
1950
+ function rightRotate(value, shift) {
1951
+ return value >>> shift | value << 32 - shift;
1836
1952
  }
1837
1953
  function safeJsonParse(raw) {
1838
1954
  try {
@@ -3521,169 +3637,9 @@ var AgentID = class {
3521
3637
  });
3522
3638
  }
3523
3639
  };
3524
-
3525
- // src/transparency-badge.tsx
3526
- var React = __toESM(require("react"));
3527
- var import_jsx_runtime = require("react/jsx-runtime");
3528
- var DEFAULT_MESSAGE = "You are interacting with an AI.";
3529
- var DEFAULT_BASE_URL = "https://api.getagentid.com/v1";
3530
- function resolveBadgeMessage(params) {
3531
- if (typeof params.message === "string" && params.message.trim().length > 0) {
3532
- return params.message.trim();
3533
- }
3534
- if (params.metadata?.disclosure) {
3535
- return params.metadata.disclosure;
3536
- }
3537
- return DEFAULT_MESSAGE;
3538
- }
3539
- function normalizeBaseUrl4(baseUrl) {
3540
- const candidate = typeof baseUrl === "string" && baseUrl.trim().length > 0 ? baseUrl.trim() : DEFAULT_BASE_URL;
3541
- return candidate.replace(/\/+$/, "");
3542
- }
3543
- function createEventId3() {
3544
- try {
3545
- if (typeof globalThis !== "undefined" && globalThis.crypto?.randomUUID) {
3546
- return globalThis.crypto.randomUUID();
3547
- }
3548
- } catch {
3549
- }
3550
- const seed = Math.random().toString(16).slice(2).padEnd(12, "0").slice(0, 12);
3551
- return `00000000-0000-4000-8000-${seed}`;
3552
- }
3553
- async function sendTransparencyBadgeRenderedTelemetry(params) {
3554
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
3555
- const eventId = createEventId3();
3556
- const payload = {
3557
- event_id: eventId,
3558
- system_id: params.telemetry.systemId,
3559
- input: "__agentid_transparency_badge_rendered__",
3560
- output: params.disclosureText,
3561
- model: params.telemetry.model ?? "agentid-transparency-badge",
3562
- user_id: params.telemetry.userId,
3563
- event_type: "transparency_badge_rendered",
3564
- severity: "info",
3565
- timestamp,
3566
- metadata: {
3567
- compliance_event: "transparency_badge_rendered",
3568
- rendered_at: timestamp,
3569
- placement: params.placement,
3570
- disclosure_text: params.disclosureText,
3571
- ...params.telemetry.metadata ?? {}
3572
- }
3573
- };
3574
- const targetIngestUrl = typeof params.telemetry.ingestUrl === "string" && params.telemetry.ingestUrl.trim().length > 0 ? params.telemetry.ingestUrl.trim() : `${normalizeBaseUrl4(params.telemetry.baseUrl)}/ingest`;
3575
- const headers = {
3576
- "Content-Type": "application/json",
3577
- "X-AgentID-SDK-Version": "js-1.1.0",
3578
- ...params.telemetry.headers ?? {}
3579
- };
3580
- if (typeof params.telemetry.apiKey === "string" && params.telemetry.apiKey.trim().length > 0) {
3581
- headers["x-agentid-api-key"] = params.telemetry.apiKey.trim();
3582
- }
3583
- const response = await fetch(targetIngestUrl, {
3584
- method: "POST",
3585
- headers,
3586
- body: JSON.stringify(payload),
3587
- keepalive: true
3588
- });
3589
- if (!response.ok) {
3590
- throw new Error(
3591
- `AgentID transparency badge telemetry failed (status=${response.status})`
3592
- );
3593
- }
3594
- }
3595
- function AgentIDTransparencyBadge(props) {
3596
- const placement = props.placement ?? "chat-header";
3597
- const fixed = props.fixed ?? true;
3598
- const text = resolveBadgeMessage({
3599
- metadata: props.metadata,
3600
- message: props.message
3601
- });
3602
- const hasLoggedRenderRef = React.useRef(false);
3603
- React.useEffect(() => {
3604
- if (hasLoggedRenderRef.current) {
3605
- return;
3606
- }
3607
- hasLoggedRenderRef.current = true;
3608
- void sendTransparencyBadgeRenderedTelemetry({
3609
- telemetry: props.telemetry,
3610
- disclosureText: text,
3611
- placement
3612
- }).catch((error) => {
3613
- if (typeof props.telemetry.onError === "function") {
3614
- props.telemetry.onError(error);
3615
- return;
3616
- }
3617
- console.warn(error);
3618
- });
3619
- }, [placement, props.telemetry, text]);
3620
- const containerStyle = placement === "watermark-overlay" ? {
3621
- position: fixed ? "fixed" : "absolute",
3622
- right: 16,
3623
- bottom: 16,
3624
- zIndex: 2147483e3,
3625
- pointerEvents: "none",
3626
- opacity: 0.95
3627
- } : {
3628
- position: fixed ? "fixed" : "sticky",
3629
- top: 0,
3630
- left: 0,
3631
- right: 0,
3632
- zIndex: 2147483e3,
3633
- pointerEvents: "none"
3634
- };
3635
- const badgeStyle = placement === "watermark-overlay" ? {
3636
- display: "inline-flex",
3637
- alignItems: "center",
3638
- gap: 8,
3639
- background: "rgba(15, 23, 42, 0.9)",
3640
- color: "#f8fafc",
3641
- borderRadius: 9999,
3642
- padding: "8px 12px",
3643
- fontFamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif",
3644
- fontSize: 12,
3645
- fontWeight: 600,
3646
- boxShadow: "0 8px 24px rgba(15, 23, 42, 0.28)",
3647
- pointerEvents: "none"
3648
- } : {
3649
- display: "flex",
3650
- alignItems: "center",
3651
- justifyContent: "center",
3652
- gap: 8,
3653
- background: "#0f172a",
3654
- color: "#f8fafc",
3655
- borderBottom: "1px solid rgba(148, 163, 184, 0.35)",
3656
- padding: "9px 12px",
3657
- fontFamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif",
3658
- fontSize: 13,
3659
- fontWeight: 600,
3660
- pointerEvents: "none"
3661
- };
3662
- const iconStyle = {
3663
- width: 22,
3664
- height: 22,
3665
- minWidth: 22,
3666
- borderRadius: 9999,
3667
- background: "#2563eb",
3668
- color: "#eff6ff",
3669
- display: "inline-flex",
3670
- alignItems: "center",
3671
- justifyContent: "center",
3672
- fontSize: 10,
3673
- fontWeight: 800,
3674
- letterSpacing: 0.5,
3675
- lineHeight: 1,
3676
- border: "1px solid rgba(191, 219, 254, 0.55)"
3677
- };
3678
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: props.className, style: containerStyle, "aria-live": "polite", role: "status", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: badgeStyle, children: [
3679
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": "true", style: iconStyle, children: "AI" }),
3680
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: text })
3681
- ] }) });
3682
- }
3683
3640
  // Annotate the CommonJS export names for ESM import in node:
3684
3641
  0 && (module.exports = {
3685
3642
  AgentID,
3686
- AgentIDTransparencyBadge,
3687
3643
  DependencyError,
3688
3644
  InjectionScanner,
3689
3645
  OpenAIAdapter,
package/dist/index.mjs CHANGED
@@ -7,169 +7,9 @@ import {
7
7
  SecurityBlockError,
8
8
  getInjectionScanner,
9
9
  scanWithRegex
10
- } from "./chunk-W37A4DPR.mjs";
11
-
12
- // src/transparency-badge.tsx
13
- import * as React from "react";
14
- import { jsx, jsxs } from "react/jsx-runtime";
15
- var DEFAULT_MESSAGE = "You are interacting with an AI.";
16
- var DEFAULT_BASE_URL = "https://api.getagentid.com/v1";
17
- function resolveBadgeMessage(params) {
18
- if (typeof params.message === "string" && params.message.trim().length > 0) {
19
- return params.message.trim();
20
- }
21
- if (params.metadata?.disclosure) {
22
- return params.metadata.disclosure;
23
- }
24
- return DEFAULT_MESSAGE;
25
- }
26
- function normalizeBaseUrl(baseUrl) {
27
- const candidate = typeof baseUrl === "string" && baseUrl.trim().length > 0 ? baseUrl.trim() : DEFAULT_BASE_URL;
28
- return candidate.replace(/\/+$/, "");
29
- }
30
- function createEventId() {
31
- try {
32
- if (typeof globalThis !== "undefined" && globalThis.crypto?.randomUUID) {
33
- return globalThis.crypto.randomUUID();
34
- }
35
- } catch {
36
- }
37
- const seed = Math.random().toString(16).slice(2).padEnd(12, "0").slice(0, 12);
38
- return `00000000-0000-4000-8000-${seed}`;
39
- }
40
- async function sendTransparencyBadgeRenderedTelemetry(params) {
41
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
42
- const eventId = createEventId();
43
- const payload = {
44
- event_id: eventId,
45
- system_id: params.telemetry.systemId,
46
- input: "__agentid_transparency_badge_rendered__",
47
- output: params.disclosureText,
48
- model: params.telemetry.model ?? "agentid-transparency-badge",
49
- user_id: params.telemetry.userId,
50
- event_type: "transparency_badge_rendered",
51
- severity: "info",
52
- timestamp,
53
- metadata: {
54
- compliance_event: "transparency_badge_rendered",
55
- rendered_at: timestamp,
56
- placement: params.placement,
57
- disclosure_text: params.disclosureText,
58
- ...params.telemetry.metadata ?? {}
59
- }
60
- };
61
- const targetIngestUrl = typeof params.telemetry.ingestUrl === "string" && params.telemetry.ingestUrl.trim().length > 0 ? params.telemetry.ingestUrl.trim() : `${normalizeBaseUrl(params.telemetry.baseUrl)}/ingest`;
62
- const headers = {
63
- "Content-Type": "application/json",
64
- "X-AgentID-SDK-Version": "js-1.1.0",
65
- ...params.telemetry.headers ?? {}
66
- };
67
- if (typeof params.telemetry.apiKey === "string" && params.telemetry.apiKey.trim().length > 0) {
68
- headers["x-agentid-api-key"] = params.telemetry.apiKey.trim();
69
- }
70
- const response = await fetch(targetIngestUrl, {
71
- method: "POST",
72
- headers,
73
- body: JSON.stringify(payload),
74
- keepalive: true
75
- });
76
- if (!response.ok) {
77
- throw new Error(
78
- `AgentID transparency badge telemetry failed (status=${response.status})`
79
- );
80
- }
81
- }
82
- function AgentIDTransparencyBadge(props) {
83
- const placement = props.placement ?? "chat-header";
84
- const fixed = props.fixed ?? true;
85
- const text = resolveBadgeMessage({
86
- metadata: props.metadata,
87
- message: props.message
88
- });
89
- const hasLoggedRenderRef = React.useRef(false);
90
- React.useEffect(() => {
91
- if (hasLoggedRenderRef.current) {
92
- return;
93
- }
94
- hasLoggedRenderRef.current = true;
95
- void sendTransparencyBadgeRenderedTelemetry({
96
- telemetry: props.telemetry,
97
- disclosureText: text,
98
- placement
99
- }).catch((error) => {
100
- if (typeof props.telemetry.onError === "function") {
101
- props.telemetry.onError(error);
102
- return;
103
- }
104
- console.warn(error);
105
- });
106
- }, [placement, props.telemetry, text]);
107
- const containerStyle = placement === "watermark-overlay" ? {
108
- position: fixed ? "fixed" : "absolute",
109
- right: 16,
110
- bottom: 16,
111
- zIndex: 2147483e3,
112
- pointerEvents: "none",
113
- opacity: 0.95
114
- } : {
115
- position: fixed ? "fixed" : "sticky",
116
- top: 0,
117
- left: 0,
118
- right: 0,
119
- zIndex: 2147483e3,
120
- pointerEvents: "none"
121
- };
122
- const badgeStyle = placement === "watermark-overlay" ? {
123
- display: "inline-flex",
124
- alignItems: "center",
125
- gap: 8,
126
- background: "rgba(15, 23, 42, 0.9)",
127
- color: "#f8fafc",
128
- borderRadius: 9999,
129
- padding: "8px 12px",
130
- fontFamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif",
131
- fontSize: 12,
132
- fontWeight: 600,
133
- boxShadow: "0 8px 24px rgba(15, 23, 42, 0.28)",
134
- pointerEvents: "none"
135
- } : {
136
- display: "flex",
137
- alignItems: "center",
138
- justifyContent: "center",
139
- gap: 8,
140
- background: "#0f172a",
141
- color: "#f8fafc",
142
- borderBottom: "1px solid rgba(148, 163, 184, 0.35)",
143
- padding: "9px 12px",
144
- fontFamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif",
145
- fontSize: 13,
146
- fontWeight: 600,
147
- pointerEvents: "none"
148
- };
149
- const iconStyle = {
150
- width: 22,
151
- height: 22,
152
- minWidth: 22,
153
- borderRadius: 9999,
154
- background: "#2563eb",
155
- color: "#eff6ff",
156
- display: "inline-flex",
157
- alignItems: "center",
158
- justifyContent: "center",
159
- fontSize: 10,
160
- fontWeight: 800,
161
- letterSpacing: 0.5,
162
- lineHeight: 1,
163
- border: "1px solid rgba(191, 219, 254, 0.55)"
164
- };
165
- return /* @__PURE__ */ jsx("div", { className: props.className, style: containerStyle, "aria-live": "polite", role: "status", children: /* @__PURE__ */ jsxs("div", { style: badgeStyle, children: [
166
- /* @__PURE__ */ jsx("span", { "aria-hidden": "true", style: iconStyle, children: "AI" }),
167
- /* @__PURE__ */ jsx("span", { children: text })
168
- ] }) });
169
- }
10
+ } from "./chunk-W3LROAHO.mjs";
170
11
  export {
171
12
  AgentID,
172
- AgentIDTransparencyBadge,
173
13
  DependencyError,
174
14
  InjectionScanner,
175
15
  OpenAIAdapter,
package/dist/langchain.js CHANGED
@@ -27,7 +27,7 @@ var import_base = require("@langchain/core/callbacks/base");
27
27
 
28
28
  // src/sdk-version.ts
29
29
  var FALLBACK_SDK_VERSION = "js-0.0.0-dev";
30
- var AGENTID_SDK_VERSION_HEADER = "js-0.1.28".trim().length > 0 ? "js-0.1.28" : FALLBACK_SDK_VERSION;
30
+ var AGENTID_SDK_VERSION_HEADER = "js-0.1.30".trim().length > 0 ? "js-0.1.30" : FALLBACK_SDK_VERSION;
31
31
 
32
32
  // src/pii-national-identifiers.ts
33
33
  var REGION_ANCHORS = {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  SecurityBlockError
3
- } from "./chunk-W37A4DPR.mjs";
3
+ } from "./chunk-W3LROAHO.mjs";
4
4
 
5
5
  // src/langchain.ts
6
6
  import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
@@ -0,0 +1,25 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { T as TransparencyMetadata } from './agentid-agvYW2vW.mjs';
3
+
4
+ type AgentIDTransparencyBadgeTelemetry = {
5
+ systemId: string;
6
+ apiKey?: string;
7
+ ingestUrl?: string;
8
+ baseUrl?: string;
9
+ userId?: string;
10
+ model?: string;
11
+ headers?: Record<string, string>;
12
+ metadata?: Record<string, unknown>;
13
+ onError?: (error: unknown) => void;
14
+ };
15
+ type AgentIDTransparencyBadgeProps = {
16
+ telemetry: AgentIDTransparencyBadgeTelemetry;
17
+ metadata?: TransparencyMetadata | null;
18
+ message?: string;
19
+ placement?: "chat-header" | "watermark-overlay";
20
+ fixed?: boolean;
21
+ className?: string;
22
+ };
23
+ declare function AgentIDTransparencyBadge(props: AgentIDTransparencyBadgeProps): react_jsx_runtime.JSX.Element;
24
+
25
+ export { AgentIDTransparencyBadge, type AgentIDTransparencyBadgeProps, type AgentIDTransparencyBadgeTelemetry };
@@ -0,0 +1,25 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { T as TransparencyMetadata } from './agentid-agvYW2vW.js';
3
+
4
+ type AgentIDTransparencyBadgeTelemetry = {
5
+ systemId: string;
6
+ apiKey?: string;
7
+ ingestUrl?: string;
8
+ baseUrl?: string;
9
+ userId?: string;
10
+ model?: string;
11
+ headers?: Record<string, string>;
12
+ metadata?: Record<string, unknown>;
13
+ onError?: (error: unknown) => void;
14
+ };
15
+ type AgentIDTransparencyBadgeProps = {
16
+ telemetry: AgentIDTransparencyBadgeTelemetry;
17
+ metadata?: TransparencyMetadata | null;
18
+ message?: string;
19
+ placement?: "chat-header" | "watermark-overlay";
20
+ fixed?: boolean;
21
+ className?: string;
22
+ };
23
+ declare function AgentIDTransparencyBadge(props: AgentIDTransparencyBadgeProps): react_jsx_runtime.JSX.Element;
24
+
25
+ export { AgentIDTransparencyBadge, type AgentIDTransparencyBadgeProps, type AgentIDTransparencyBadgeTelemetry };
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ "use client";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/transparency-badge.tsx
32
+ var transparency_badge_exports = {};
33
+ __export(transparency_badge_exports, {
34
+ AgentIDTransparencyBadge: () => AgentIDTransparencyBadge
35
+ });
36
+ module.exports = __toCommonJS(transparency_badge_exports);
37
+ var React = __toESM(require("react"));
38
+ var import_jsx_runtime = require("react/jsx-runtime");
39
+ var DEFAULT_MESSAGE = "You are interacting with an AI.";
40
+ var DEFAULT_BASE_URL = "https://api.getagentid.com/v1";
41
+ function resolveBadgeMessage(params) {
42
+ if (typeof params.message === "string" && params.message.trim().length > 0) {
43
+ return params.message.trim();
44
+ }
45
+ if (params.metadata?.disclosure) {
46
+ return params.metadata.disclosure;
47
+ }
48
+ return DEFAULT_MESSAGE;
49
+ }
50
+ function normalizeBaseUrl(baseUrl) {
51
+ const candidate = typeof baseUrl === "string" && baseUrl.trim().length > 0 ? baseUrl.trim() : DEFAULT_BASE_URL;
52
+ return candidate.replace(/\/+$/, "");
53
+ }
54
+ function createEventId() {
55
+ try {
56
+ if (typeof globalThis !== "undefined" && globalThis.crypto?.randomUUID) {
57
+ return globalThis.crypto.randomUUID();
58
+ }
59
+ } catch {
60
+ }
61
+ const seed = Math.random().toString(16).slice(2).padEnd(12, "0").slice(0, 12);
62
+ return `00000000-0000-4000-8000-${seed}`;
63
+ }
64
+ async function sendTransparencyBadgeRenderedTelemetry(params) {
65
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
66
+ const eventId = createEventId();
67
+ const payload = {
68
+ event_id: eventId,
69
+ system_id: params.telemetry.systemId,
70
+ input: "__agentid_transparency_badge_rendered__",
71
+ output: params.disclosureText,
72
+ model: params.telemetry.model ?? "agentid-transparency-badge",
73
+ user_id: params.telemetry.userId,
74
+ event_type: "transparency_badge_rendered",
75
+ severity: "info",
76
+ timestamp,
77
+ metadata: {
78
+ compliance_event: "transparency_badge_rendered",
79
+ rendered_at: timestamp,
80
+ placement: params.placement,
81
+ disclosure_text: params.disclosureText,
82
+ ...params.telemetry.metadata ?? {}
83
+ }
84
+ };
85
+ const targetIngestUrl = typeof params.telemetry.ingestUrl === "string" && params.telemetry.ingestUrl.trim().length > 0 ? params.telemetry.ingestUrl.trim() : `${normalizeBaseUrl(params.telemetry.baseUrl)}/ingest`;
86
+ const headers = {
87
+ "Content-Type": "application/json",
88
+ "X-AgentID-SDK-Version": "js-1.1.0",
89
+ ...params.telemetry.headers ?? {}
90
+ };
91
+ if (typeof params.telemetry.apiKey === "string" && params.telemetry.apiKey.trim().length > 0) {
92
+ headers["x-agentid-api-key"] = params.telemetry.apiKey.trim();
93
+ }
94
+ const response = await fetch(targetIngestUrl, {
95
+ method: "POST",
96
+ headers,
97
+ body: JSON.stringify(payload),
98
+ keepalive: true
99
+ });
100
+ if (!response.ok) {
101
+ throw new Error(
102
+ `AgentID transparency badge telemetry failed (status=${response.status})`
103
+ );
104
+ }
105
+ }
106
+ function AgentIDTransparencyBadge(props) {
107
+ const placement = props.placement ?? "chat-header";
108
+ const fixed = props.fixed ?? true;
109
+ const text = resolveBadgeMessage({
110
+ metadata: props.metadata,
111
+ message: props.message
112
+ });
113
+ const hasLoggedRenderRef = React.useRef(false);
114
+ React.useEffect(() => {
115
+ if (hasLoggedRenderRef.current) {
116
+ return;
117
+ }
118
+ hasLoggedRenderRef.current = true;
119
+ void sendTransparencyBadgeRenderedTelemetry({
120
+ telemetry: props.telemetry,
121
+ disclosureText: text,
122
+ placement
123
+ }).catch((error) => {
124
+ if (typeof props.telemetry.onError === "function") {
125
+ props.telemetry.onError(error);
126
+ return;
127
+ }
128
+ console.warn(error);
129
+ });
130
+ }, [placement, props.telemetry, text]);
131
+ const containerStyle = placement === "watermark-overlay" ? {
132
+ position: fixed ? "fixed" : "absolute",
133
+ right: 16,
134
+ bottom: 16,
135
+ zIndex: 2147483e3,
136
+ pointerEvents: "none",
137
+ opacity: 0.95
138
+ } : {
139
+ position: fixed ? "fixed" : "sticky",
140
+ top: 0,
141
+ left: 0,
142
+ right: 0,
143
+ zIndex: 2147483e3,
144
+ pointerEvents: "none"
145
+ };
146
+ const badgeStyle = placement === "watermark-overlay" ? {
147
+ display: "inline-flex",
148
+ alignItems: "center",
149
+ gap: 8,
150
+ background: "rgba(15, 23, 42, 0.9)",
151
+ color: "#f8fafc",
152
+ borderRadius: 9999,
153
+ padding: "8px 12px",
154
+ fontFamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif",
155
+ fontSize: 12,
156
+ fontWeight: 600,
157
+ boxShadow: "0 8px 24px rgba(15, 23, 42, 0.28)",
158
+ pointerEvents: "none"
159
+ } : {
160
+ display: "flex",
161
+ alignItems: "center",
162
+ justifyContent: "center",
163
+ gap: 8,
164
+ background: "#0f172a",
165
+ color: "#f8fafc",
166
+ borderBottom: "1px solid rgba(148, 163, 184, 0.35)",
167
+ padding: "9px 12px",
168
+ fontFamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif",
169
+ fontSize: 13,
170
+ fontWeight: 600,
171
+ pointerEvents: "none"
172
+ };
173
+ const iconStyle = {
174
+ width: 22,
175
+ height: 22,
176
+ minWidth: 22,
177
+ borderRadius: 9999,
178
+ background: "#2563eb",
179
+ color: "#eff6ff",
180
+ display: "inline-flex",
181
+ alignItems: "center",
182
+ justifyContent: "center",
183
+ fontSize: 10,
184
+ fontWeight: 800,
185
+ letterSpacing: 0.5,
186
+ lineHeight: 1,
187
+ border: "1px solid rgba(191, 219, 254, 0.55)"
188
+ };
189
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: props.className, style: containerStyle, "aria-live": "polite", role: "status", children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: badgeStyle, children: [
190
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { "aria-hidden": "true", style: iconStyle, children: "AI" }),
191
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: text })
192
+ ] }) });
193
+ }
194
+ // Annotate the CommonJS export names for ESM import in node:
195
+ 0 && (module.exports = {
196
+ AgentIDTransparencyBadge
197
+ });
@@ -0,0 +1,163 @@
1
+ "use client";
2
+
3
+ // src/transparency-badge.tsx
4
+ import * as React from "react";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ var DEFAULT_MESSAGE = "You are interacting with an AI.";
7
+ var DEFAULT_BASE_URL = "https://api.getagentid.com/v1";
8
+ function resolveBadgeMessage(params) {
9
+ if (typeof params.message === "string" && params.message.trim().length > 0) {
10
+ return params.message.trim();
11
+ }
12
+ if (params.metadata?.disclosure) {
13
+ return params.metadata.disclosure;
14
+ }
15
+ return DEFAULT_MESSAGE;
16
+ }
17
+ function normalizeBaseUrl(baseUrl) {
18
+ const candidate = typeof baseUrl === "string" && baseUrl.trim().length > 0 ? baseUrl.trim() : DEFAULT_BASE_URL;
19
+ return candidate.replace(/\/+$/, "");
20
+ }
21
+ function createEventId() {
22
+ try {
23
+ if (typeof globalThis !== "undefined" && globalThis.crypto?.randomUUID) {
24
+ return globalThis.crypto.randomUUID();
25
+ }
26
+ } catch {
27
+ }
28
+ const seed = Math.random().toString(16).slice(2).padEnd(12, "0").slice(0, 12);
29
+ return `00000000-0000-4000-8000-${seed}`;
30
+ }
31
+ async function sendTransparencyBadgeRenderedTelemetry(params) {
32
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
33
+ const eventId = createEventId();
34
+ const payload = {
35
+ event_id: eventId,
36
+ system_id: params.telemetry.systemId,
37
+ input: "__agentid_transparency_badge_rendered__",
38
+ output: params.disclosureText,
39
+ model: params.telemetry.model ?? "agentid-transparency-badge",
40
+ user_id: params.telemetry.userId,
41
+ event_type: "transparency_badge_rendered",
42
+ severity: "info",
43
+ timestamp,
44
+ metadata: {
45
+ compliance_event: "transparency_badge_rendered",
46
+ rendered_at: timestamp,
47
+ placement: params.placement,
48
+ disclosure_text: params.disclosureText,
49
+ ...params.telemetry.metadata ?? {}
50
+ }
51
+ };
52
+ const targetIngestUrl = typeof params.telemetry.ingestUrl === "string" && params.telemetry.ingestUrl.trim().length > 0 ? params.telemetry.ingestUrl.trim() : `${normalizeBaseUrl(params.telemetry.baseUrl)}/ingest`;
53
+ const headers = {
54
+ "Content-Type": "application/json",
55
+ "X-AgentID-SDK-Version": "js-1.1.0",
56
+ ...params.telemetry.headers ?? {}
57
+ };
58
+ if (typeof params.telemetry.apiKey === "string" && params.telemetry.apiKey.trim().length > 0) {
59
+ headers["x-agentid-api-key"] = params.telemetry.apiKey.trim();
60
+ }
61
+ const response = await fetch(targetIngestUrl, {
62
+ method: "POST",
63
+ headers,
64
+ body: JSON.stringify(payload),
65
+ keepalive: true
66
+ });
67
+ if (!response.ok) {
68
+ throw new Error(
69
+ `AgentID transparency badge telemetry failed (status=${response.status})`
70
+ );
71
+ }
72
+ }
73
+ function AgentIDTransparencyBadge(props) {
74
+ const placement = props.placement ?? "chat-header";
75
+ const fixed = props.fixed ?? true;
76
+ const text = resolveBadgeMessage({
77
+ metadata: props.metadata,
78
+ message: props.message
79
+ });
80
+ const hasLoggedRenderRef = React.useRef(false);
81
+ React.useEffect(() => {
82
+ if (hasLoggedRenderRef.current) {
83
+ return;
84
+ }
85
+ hasLoggedRenderRef.current = true;
86
+ void sendTransparencyBadgeRenderedTelemetry({
87
+ telemetry: props.telemetry,
88
+ disclosureText: text,
89
+ placement
90
+ }).catch((error) => {
91
+ if (typeof props.telemetry.onError === "function") {
92
+ props.telemetry.onError(error);
93
+ return;
94
+ }
95
+ console.warn(error);
96
+ });
97
+ }, [placement, props.telemetry, text]);
98
+ const containerStyle = placement === "watermark-overlay" ? {
99
+ position: fixed ? "fixed" : "absolute",
100
+ right: 16,
101
+ bottom: 16,
102
+ zIndex: 2147483e3,
103
+ pointerEvents: "none",
104
+ opacity: 0.95
105
+ } : {
106
+ position: fixed ? "fixed" : "sticky",
107
+ top: 0,
108
+ left: 0,
109
+ right: 0,
110
+ zIndex: 2147483e3,
111
+ pointerEvents: "none"
112
+ };
113
+ const badgeStyle = placement === "watermark-overlay" ? {
114
+ display: "inline-flex",
115
+ alignItems: "center",
116
+ gap: 8,
117
+ background: "rgba(15, 23, 42, 0.9)",
118
+ color: "#f8fafc",
119
+ borderRadius: 9999,
120
+ padding: "8px 12px",
121
+ fontFamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif",
122
+ fontSize: 12,
123
+ fontWeight: 600,
124
+ boxShadow: "0 8px 24px rgba(15, 23, 42, 0.28)",
125
+ pointerEvents: "none"
126
+ } : {
127
+ display: "flex",
128
+ alignItems: "center",
129
+ justifyContent: "center",
130
+ gap: 8,
131
+ background: "#0f172a",
132
+ color: "#f8fafc",
133
+ borderBottom: "1px solid rgba(148, 163, 184, 0.35)",
134
+ padding: "9px 12px",
135
+ fontFamily: "ui-sans-serif, -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial, sans-serif",
136
+ fontSize: 13,
137
+ fontWeight: 600,
138
+ pointerEvents: "none"
139
+ };
140
+ const iconStyle = {
141
+ width: 22,
142
+ height: 22,
143
+ minWidth: 22,
144
+ borderRadius: 9999,
145
+ background: "#2563eb",
146
+ color: "#eff6ff",
147
+ display: "inline-flex",
148
+ alignItems: "center",
149
+ justifyContent: "center",
150
+ fontSize: 10,
151
+ fontWeight: 800,
152
+ letterSpacing: 0.5,
153
+ lineHeight: 1,
154
+ border: "1px solid rgba(191, 219, 254, 0.55)"
155
+ };
156
+ return /* @__PURE__ */ jsx("div", { className: props.className, style: containerStyle, "aria-live": "polite", role: "status", children: /* @__PURE__ */ jsxs("div", { style: badgeStyle, children: [
157
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", style: iconStyle, children: "AI" }),
158
+ /* @__PURE__ */ jsx("span", { children: text })
159
+ ] }) });
160
+ }
161
+ export {
162
+ AgentIDTransparencyBadge
163
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentid-sdk",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "AgentID JavaScript/TypeScript SDK for guard, ingest, tracing, and analytics.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://agentid.ai",
@@ -26,6 +26,11 @@
26
26
  "import": "./dist/langchain.mjs",
27
27
  "require": "./dist/langchain.js"
28
28
  },
29
+ "./transparency-badge": {
30
+ "types": "./dist/transparency-badge.d.ts",
31
+ "import": "./dist/transparency-badge.mjs",
32
+ "require": "./dist/transparency-badge.js"
33
+ },
29
34
  "./package.json": "./package.json"
30
35
  },
31
36
  "files": [
@@ -33,6 +38,7 @@
33
38
  ],
34
39
  "scripts": {
35
40
  "build": "tsup --config tsup.config.ts",
41
+ "release:check": "npm run build && npm pack --dry-run",
36
42
  "prepublishOnly": "npm run build"
37
43
  },
38
44
  "publishConfig": {