agentid-sdk 0.1.12 → 0.1.13

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/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AgentID, a as AgentIDCallbackHandler, G as GuardParams, b as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions } from './langchain-BGP3qxvW.mjs';
1
+ export { A as AgentID, a as AgentIDCallbackHandler, G as GuardParams, b as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions } from './langchain-CUyC7jmr.mjs';
2
2
 
3
3
  type PIIMapping = Record<string, string>;
4
4
  declare class PIIManager {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as AgentID, a as AgentIDCallbackHandler, G as GuardParams, b as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions } from './langchain-BGP3qxvW.js';
1
+ export { A as AgentID, a as AgentIDCallbackHandler, G as GuardParams, b as GuardResponse, L as LogParams, P as PreparedInput, R as RequestOptions } from './langchain-CUyC7jmr.js';
2
2
 
3
3
  type PIIMapping = Record<string, string>;
4
4
  declare class PIIManager {
package/dist/index.js CHANGED
@@ -1882,6 +1882,13 @@ function isUuidLike(value) {
1882
1882
  value
1883
1883
  );
1884
1884
  }
1885
+ function createEventId(seed) {
1886
+ if (isUuidLike(seed)) return seed;
1887
+ if (typeof globalThis.crypto?.randomUUID === "function") {
1888
+ return globalThis.crypto.randomUUID();
1889
+ }
1890
+ return `evt_${Date.now()}_${Math.random().toString(36).slice(2)}`;
1891
+ }
1885
1892
  function createCorrelationId(seed) {
1886
1893
  if (isUuidLike(seed)) return seed;
1887
1894
  if (typeof globalThis.crypto?.randomUUID === "function") {
@@ -1968,6 +1975,7 @@ function createCompletionChunkCollector() {
1968
1975
  var AgentID = class {
1969
1976
  constructor(config) {
1970
1977
  this.injectionScanner = getInjectionScanner();
1978
+ this.requestClientEventIds = /* @__PURE__ */ new WeakMap();
1971
1979
  this.apiKey = config.apiKey.trim();
1972
1980
  this.baseUrl = normalizeBaseUrl3(config.baseUrl ?? "https://app.getagentid.com/api/v1");
1973
1981
  this.piiMasking = Boolean(config.piiMasking);
@@ -1996,6 +2004,26 @@ var AgentID = class {
1996
2004
  }
1997
2005
  return this.apiKey;
1998
2006
  }
2007
+ resolveClientEventId(requestBody) {
2008
+ const directClientEventId = requestBody.client_event_id;
2009
+ if (typeof directClientEventId === "string" && isUuidLike(directClientEventId)) {
2010
+ return directClientEventId;
2011
+ }
2012
+ const metadata = requestBody.metadata;
2013
+ if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
2014
+ const metadataClientEventId = metadata.client_event_id;
2015
+ if (typeof metadataClientEventId === "string" && isUuidLike(metadataClientEventId)) {
2016
+ return metadataClientEventId;
2017
+ }
2018
+ }
2019
+ const cached = this.requestClientEventIds.get(requestBody);
2020
+ if (cached) {
2021
+ return cached;
2022
+ }
2023
+ const generated = createEventId();
2024
+ this.requestClientEventIds.set(requestBody, generated);
2025
+ return generated;
2026
+ }
1999
2027
  async getCapabilityConfig(force = false, options) {
2000
2028
  const effectiveApiKey = this.resolveApiKey(options?.apiKey);
2001
2029
  return ensureCapabilityConfig({
@@ -2375,7 +2403,7 @@ var AgentID = class {
2375
2403
  void (async () => {
2376
2404
  try {
2377
2405
  const effectiveApiKey = this.resolveApiKey(options?.apiKey);
2378
- const eventId = params.event_id ?? (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `evt_${Date.now()}_${Math.random().toString(36).slice(2)}`);
2406
+ const eventId = params.event_id ?? createEventId();
2379
2407
  const timestamp = params.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
2380
2408
  void this.getCapabilityConfig(false, { apiKey: effectiveApiKey }).catch(() => void 0);
2381
2409
  const metadata = {
@@ -2501,7 +2529,7 @@ var AgentID = class {
2501
2529
  "AgentID: No user message found. Security guard requires string input."
2502
2530
  );
2503
2531
  }
2504
- const clientEventId = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `evt_${Date.now()}_${Math.random().toString(36).slice(2)}`;
2532
+ const clientEventId = this.resolveClientEventId(req);
2505
2533
  const verdict = await this.guard({
2506
2534
  input: maskedText,
2507
2535
  system_id: systemId,
package/dist/index.mjs CHANGED
@@ -1844,6 +1844,13 @@ function isUuidLike(value) {
1844
1844
  value
1845
1845
  );
1846
1846
  }
1847
+ function createEventId(seed) {
1848
+ if (isUuidLike(seed)) return seed;
1849
+ if (typeof globalThis.crypto?.randomUUID === "function") {
1850
+ return globalThis.crypto.randomUUID();
1851
+ }
1852
+ return `evt_${Date.now()}_${Math.random().toString(36).slice(2)}`;
1853
+ }
1847
1854
  function createCorrelationId(seed) {
1848
1855
  if (isUuidLike(seed)) return seed;
1849
1856
  if (typeof globalThis.crypto?.randomUUID === "function") {
@@ -1930,6 +1937,7 @@ function createCompletionChunkCollector() {
1930
1937
  var AgentID = class {
1931
1938
  constructor(config) {
1932
1939
  this.injectionScanner = getInjectionScanner();
1940
+ this.requestClientEventIds = /* @__PURE__ */ new WeakMap();
1933
1941
  this.apiKey = config.apiKey.trim();
1934
1942
  this.baseUrl = normalizeBaseUrl3(config.baseUrl ?? "https://app.getagentid.com/api/v1");
1935
1943
  this.piiMasking = Boolean(config.piiMasking);
@@ -1958,6 +1966,26 @@ var AgentID = class {
1958
1966
  }
1959
1967
  return this.apiKey;
1960
1968
  }
1969
+ resolveClientEventId(requestBody) {
1970
+ const directClientEventId = requestBody.client_event_id;
1971
+ if (typeof directClientEventId === "string" && isUuidLike(directClientEventId)) {
1972
+ return directClientEventId;
1973
+ }
1974
+ const metadata = requestBody.metadata;
1975
+ if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
1976
+ const metadataClientEventId = metadata.client_event_id;
1977
+ if (typeof metadataClientEventId === "string" && isUuidLike(metadataClientEventId)) {
1978
+ return metadataClientEventId;
1979
+ }
1980
+ }
1981
+ const cached = this.requestClientEventIds.get(requestBody);
1982
+ if (cached) {
1983
+ return cached;
1984
+ }
1985
+ const generated = createEventId();
1986
+ this.requestClientEventIds.set(requestBody, generated);
1987
+ return generated;
1988
+ }
1961
1989
  async getCapabilityConfig(force = false, options) {
1962
1990
  const effectiveApiKey = this.resolveApiKey(options?.apiKey);
1963
1991
  return ensureCapabilityConfig({
@@ -2337,7 +2365,7 @@ var AgentID = class {
2337
2365
  void (async () => {
2338
2366
  try {
2339
2367
  const effectiveApiKey = this.resolveApiKey(options?.apiKey);
2340
- const eventId = params.event_id ?? (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `evt_${Date.now()}_${Math.random().toString(36).slice(2)}`);
2368
+ const eventId = params.event_id ?? createEventId();
2341
2369
  const timestamp = params.timestamp ?? (/* @__PURE__ */ new Date()).toISOString();
2342
2370
  void this.getCapabilityConfig(false, { apiKey: effectiveApiKey }).catch(() => void 0);
2343
2371
  const metadata = {
@@ -2463,7 +2491,7 @@ var AgentID = class {
2463
2491
  "AgentID: No user message found. Security guard requires string input."
2464
2492
  );
2465
2493
  }
2466
- const clientEventId = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `evt_${Date.now()}_${Math.random().toString(36).slice(2)}`;
2494
+ const clientEventId = this.resolveClientEventId(req);
2467
2495
  const verdict = await this.guard({
2468
2496
  input: maskedText,
2469
2497
  system_id: systemId,
@@ -82,9 +82,11 @@ declare class AgentID {
82
82
  private pii;
83
83
  private localEnforcer;
84
84
  private injectionScanner;
85
+ private requestClientEventIds;
85
86
  constructor(config: AgentIDConfig);
86
87
  private buildClientCapabilities;
87
88
  private resolveApiKey;
89
+ private resolveClientEventId;
88
90
  getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
89
91
  private getCachedCapabilityConfig;
90
92
  prepareInputForDispatch(params: {
@@ -82,9 +82,11 @@ declare class AgentID {
82
82
  private pii;
83
83
  private localEnforcer;
84
84
  private injectionScanner;
85
+ private requestClientEventIds;
85
86
  constructor(config: AgentIDConfig);
86
87
  private buildClientCapabilities;
87
88
  private resolveApiKey;
89
+ private resolveClientEventId;
88
90
  getCapabilityConfig(force?: boolean, options?: RequestOptions): Promise<CapabilityConfig>;
89
91
  private getCachedCapabilityConfig;
90
92
  prepareInputForDispatch(params: {
@@ -1 +1 @@
1
- export { a as AgentIDCallbackHandler } from './langchain-BGP3qxvW.mjs';
1
+ export { a as AgentIDCallbackHandler } from './langchain-CUyC7jmr.mjs';
@@ -1 +1 @@
1
- export { a as AgentIDCallbackHandler } from './langchain-BGP3qxvW.js';
1
+ export { a as AgentIDCallbackHandler } from './langchain-CUyC7jmr.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentid-sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "AgentID JavaScript/TypeScript SDK for guard, ingest, tracing, and analytics.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://agentid.ai",