agentid-sdk 0.1.10 → 0.1.12

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-DVPOWfCC.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-BGP3qxvW.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-DVPOWfCC.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-BGP3qxvW.js';
2
2
 
3
3
  type PIIMapping = Record<string, string>;
4
4
  declare class PIIManager {
package/dist/index.js CHANGED
@@ -466,12 +466,20 @@ function inferRegionsFromAnchors(hits) {
466
466
  }
467
467
  function resolveRegions(text, locale) {
468
468
  const localeRegion = parseLocaleRegion(locale);
469
- if (localeRegion) return [localeRegion];
470
469
  const normalizedLocale = locale?.toLowerCase().trim() ?? "";
471
470
  const inferred = inferRegionsFromAnchors(
472
471
  scanAnchorHits(text, Date.now(), DEFAULT_PREFILTER_DEADLINE_MS)
473
472
  );
474
- if (inferred.length > 0) return inferred;
473
+ const regions = /* @__PURE__ */ new Set();
474
+ if (localeRegion) {
475
+ regions.add(localeRegion);
476
+ }
477
+ for (const region of inferred) {
478
+ regions.add(region);
479
+ }
480
+ if (regions.size > 0) {
481
+ return Array.from(regions);
482
+ }
475
483
  if (normalizedLocale.startsWith("uk")) {
476
484
  return ["czsk", "pl", "ro", "de", "hu", "fr", "es", "it", "nl", "at"];
477
485
  }
@@ -1196,7 +1204,7 @@ var CONFIG_TTL_MS = 5 * 60 * 1e3;
1196
1204
  var CONFIG_TIMEOUT_MS = 8e3;
1197
1205
  var CONFIG_RETRY_DELAY_MS = 1e3;
1198
1206
  var MAX_CAPABILITY_CACHE_ENTRIES = 500;
1199
- var AGENTID_SDK_VERSION_HEADER = "js-1.0.7";
1207
+ var AGENTID_SDK_VERSION_HEADER = "js-1.0.8";
1200
1208
  var CapabilityConfigFetchError = class extends Error {
1201
1209
  constructor(message, params) {
1202
1210
  super(message);
@@ -1795,10 +1803,12 @@ function getInjectionScanner() {
1795
1803
  }
1796
1804
 
1797
1805
  // src/agentid.ts
1798
- var AGENTID_SDK_VERSION_HEADER2 = "js-1.0.7";
1799
- var DEFAULT_GUARD_TIMEOUT_MS = 3500;
1806
+ var AGENTID_SDK_VERSION_HEADER2 = "js-1.0.8";
1807
+ var DEFAULT_GUARD_TIMEOUT_MS = 1e4;
1800
1808
  var MIN_GUARD_TIMEOUT_MS = 500;
1801
- var MAX_GUARD_TIMEOUT_MS = 1e4;
1809
+ var MAX_GUARD_TIMEOUT_MS = 15e3;
1810
+ var GUARD_MAX_ATTEMPTS = 3;
1811
+ var GUARD_RETRY_DELAYS_MS = [250, 500];
1802
1812
  function normalizeBaseUrl3(baseUrl) {
1803
1813
  return baseUrl.replace(/\/+$/, "");
1804
1814
  }
@@ -1866,6 +1876,24 @@ function isInfrastructureGuardReason(reason) {
1866
1876
  if (!reason) return false;
1867
1877
  return reason === "system_failure" || reason === "system_failure_db_unavailable" || reason === "logging_failed" || reason === "server_error" || reason === "guard_unreachable" || reason === "api_key_pepper_missing" || reason === "encryption_key_missing";
1868
1878
  }
1879
+ function isUuidLike(value) {
1880
+ if (!value) return false;
1881
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
1882
+ value
1883
+ );
1884
+ }
1885
+ function createCorrelationId(seed) {
1886
+ if (isUuidLike(seed)) return seed;
1887
+ if (typeof globalThis.crypto?.randomUUID === "function") {
1888
+ return globalThis.crypto.randomUUID();
1889
+ }
1890
+ return `cid_${Date.now()}_${Math.random().toString(36).slice(2)}`;
1891
+ }
1892
+ async function waitForRetry(attemptIndex) {
1893
+ const delay = GUARD_RETRY_DELAYS_MS[attemptIndex];
1894
+ if (!delay) return;
1895
+ await new Promise((resolve) => setTimeout(resolve, delay));
1896
+ }
1869
1897
  async function safeReadJson2(response) {
1870
1898
  try {
1871
1899
  return await response.json();
@@ -2125,79 +2153,124 @@ var AgentID = class {
2125
2153
  ...params,
2126
2154
  client_capabilities: params.client_capabilities ?? this.buildClientCapabilities()
2127
2155
  };
2128
- const controller = new AbortController();
2129
- const timeoutId = setTimeout(() => controller.abort(), this.guardTimeoutMs);
2130
- try {
2131
- const res = await fetch(`${this.baseUrl}/guard`, {
2132
- method: "POST",
2133
- headers: {
2134
- "Content-Type": "application/json",
2135
- "x-agentid-api-key": effectiveApiKey,
2136
- "X-AgentID-SDK-Version": AGENTID_SDK_VERSION_HEADER2
2137
- },
2138
- body: JSON.stringify(payload),
2139
- signal: controller.signal
2140
- });
2141
- const responseBody = await safeReadJson2(res);
2142
- if (responseBody && typeof responseBody.allowed === "boolean") {
2143
- const verdict = responseBody;
2144
- if (verdict.allowed === false && (isInfrastructureGuardReason(verdict.reason) || res.status >= 500)) {
2145
- if (this.strictMode) {
2156
+ const correlationId = createCorrelationId(payload.client_event_id);
2157
+ let lastStatusCode = null;
2158
+ let lastAbort = false;
2159
+ let lastError = null;
2160
+ for (let attempt = 0; attempt < GUARD_MAX_ATTEMPTS; attempt += 1) {
2161
+ const controller = new AbortController();
2162
+ const timeoutId = setTimeout(() => controller.abort(), this.guardTimeoutMs);
2163
+ try {
2164
+ const res = await fetch(`${this.baseUrl}/guard`, {
2165
+ method: "POST",
2166
+ headers: {
2167
+ "Content-Type": "application/json",
2168
+ "x-agentid-api-key": effectiveApiKey,
2169
+ "X-AgentID-SDK-Version": AGENTID_SDK_VERSION_HEADER2,
2170
+ "x-correlation-id": correlationId
2171
+ },
2172
+ body: JSON.stringify(payload),
2173
+ signal: controller.signal
2174
+ });
2175
+ lastStatusCode = res.status;
2176
+ const responseBody = await safeReadJson2(res);
2177
+ if (responseBody && typeof responseBody.allowed === "boolean") {
2178
+ const verdict = responseBody;
2179
+ const infrastructureFailure = verdict.allowed === false && (isInfrastructureGuardReason(verdict.reason) || res.status >= 500);
2180
+ if (infrastructureFailure) {
2181
+ if (attempt < GUARD_MAX_ATTEMPTS - 1) {
2182
+ await waitForRetry(attempt);
2183
+ continue;
2184
+ }
2185
+ if (this.strictMode) {
2186
+ console.warn(
2187
+ `[AgentID] Guard API infrastructure failure in strict mode (${verdict.reason ?? `http_${res.status}`}). Blocking request.`
2188
+ );
2189
+ return { allowed: false, reason: verdict.reason ?? "network_error_strict_mode" };
2190
+ }
2146
2191
  console.warn(
2147
- `[AgentID] Guard API infrastructure failure in strict mode (${verdict.reason ?? `http_${res.status}`}). Blocking request.`
2192
+ `[AgentID] Guard API infrastructure fallback in fail-open mode (${verdict.reason ?? `http_${res.status}`}).`
2148
2193
  );
2149
- return { allowed: false, reason: verdict.reason ?? "network_error_strict_mode" };
2194
+ this.logGuardFallback({
2195
+ reason: verdict.reason ?? `http_${res.status}`,
2196
+ status: "upstream_error",
2197
+ guardParams: params,
2198
+ apiKey: effectiveApiKey
2199
+ });
2200
+ return { allowed: true, reason: "system_failure_fail_open" };
2201
+ }
2202
+ return verdict;
2203
+ }
2204
+ if (!res.ok) {
2205
+ if (res.status >= 500 && attempt < GUARD_MAX_ATTEMPTS - 1) {
2206
+ await waitForRetry(attempt);
2207
+ continue;
2150
2208
  }
2151
- console.warn(
2152
- `[AgentID] Guard API infrastructure fallback in fail-open mode (${verdict.reason ?? `http_${res.status}`}).`
2153
- );
2209
+ throw new Error(`API Error ${res.status}`);
2210
+ }
2211
+ throw new Error("Invalid guard response");
2212
+ } catch (error) {
2213
+ lastError = error;
2214
+ const isAbortError2 = Boolean(
2215
+ error && typeof error === "object" && error.name === "AbortError"
2216
+ );
2217
+ lastAbort = isAbortError2;
2218
+ if (attempt < GUARD_MAX_ATTEMPTS - 1) {
2219
+ await waitForRetry(attempt);
2220
+ continue;
2221
+ }
2222
+ if (isAbortError2) {
2223
+ const timeoutMessage = "AgentID API Warning: Connection timeout exceeded.";
2224
+ console.warn(timeoutMessage);
2154
2225
  this.logGuardFallback({
2155
- reason: verdict.reason ?? `http_${res.status}`,
2156
- status: "upstream_error",
2226
+ reason: "timeout_fallback",
2227
+ status: "latency_timeout",
2157
2228
  guardParams: params,
2158
2229
  apiKey: effectiveApiKey
2159
2230
  });
2160
- return { allowed: true, reason: "system_failure_fail_open" };
2231
+ if (this.strictMode) {
2232
+ return { allowed: false, reason: "network_error_strict_mode" };
2233
+ }
2234
+ return { allowed: true, reason: "timeout_fallback" };
2161
2235
  }
2162
- return verdict;
2163
- }
2164
- if (!res.ok) {
2165
- throw new Error(`API Error ${res.status}`);
2166
- }
2167
- throw new Error("Invalid guard response");
2168
- } catch (error) {
2169
- const isAbortError2 = error && typeof error === "object" && error.name === "AbortError";
2170
- if (isAbortError2) {
2171
- const timeoutMessage = "AgentID API Warning: Connection timeout exceeded.";
2172
- console.warn(timeoutMessage);
2236
+ console.warn(
2237
+ this.strictMode ? "[AgentID] Guard check failed (Strict mode active):" : "[AgentID] Guard check failed (Fail-Open active):",
2238
+ error
2239
+ );
2173
2240
  this.logGuardFallback({
2174
- reason: "timeout_fallback",
2175
- status: "latency_timeout",
2241
+ reason: "guard_unreachable",
2242
+ status: "guard_unreachable",
2176
2243
  guardParams: params,
2177
2244
  apiKey: effectiveApiKey
2178
2245
  });
2179
2246
  if (this.strictMode) {
2180
2247
  return { allowed: false, reason: "network_error_strict_mode" };
2181
2248
  }
2182
- return { allowed: true, reason: "timeout_fallback" };
2249
+ return { allowed: true, reason: "guard_unreachable" };
2250
+ } finally {
2251
+ clearTimeout(timeoutId);
2183
2252
  }
2184
- console.warn(
2185
- this.strictMode ? "[AgentID] Guard check failed (Strict mode active):" : "[AgentID] Guard check failed (Fail-Open active):",
2186
- error
2187
- );
2188
- this.logGuardFallback({
2189
- reason: "guard_unreachable",
2190
- status: "guard_unreachable",
2191
- guardParams: params,
2192
- apiKey: effectiveApiKey
2193
- });
2253
+ }
2254
+ if (lastAbort) {
2194
2255
  if (this.strictMode) {
2195
2256
  return { allowed: false, reason: "network_error_strict_mode" };
2196
2257
  }
2197
- return { allowed: true, reason: "guard_unreachable" };
2198
- } finally {
2199
- clearTimeout(timeoutId);
2258
+ return { allowed: true, reason: "timeout_fallback" };
2259
+ }
2260
+ if (typeof lastStatusCode === "number" && lastStatusCode >= 500) {
2261
+ if (this.strictMode) {
2262
+ return { allowed: false, reason: "server_error" };
2263
+ }
2264
+ return { allowed: true, reason: "system_failure_fail_open" };
2265
+ }
2266
+ console.warn(
2267
+ this.strictMode ? "[AgentID] Guard check failed (Strict mode active):" : "[AgentID] Guard check failed (Fail-Open active):",
2268
+ lastError
2269
+ );
2270
+ if (this.strictMode) {
2271
+ return { allowed: false, reason: "network_error_strict_mode" };
2200
2272
  }
2273
+ return { allowed: true, reason: "guard_unreachable" };
2201
2274
  }
2202
2275
  extractStreamChunkText(chunk) {
2203
2276
  if (typeof chunk === "string") {
package/dist/index.mjs CHANGED
@@ -428,12 +428,20 @@ function inferRegionsFromAnchors(hits) {
428
428
  }
429
429
  function resolveRegions(text, locale) {
430
430
  const localeRegion = parseLocaleRegion(locale);
431
- if (localeRegion) return [localeRegion];
432
431
  const normalizedLocale = locale?.toLowerCase().trim() ?? "";
433
432
  const inferred = inferRegionsFromAnchors(
434
433
  scanAnchorHits(text, Date.now(), DEFAULT_PREFILTER_DEADLINE_MS)
435
434
  );
436
- if (inferred.length > 0) return inferred;
435
+ const regions = /* @__PURE__ */ new Set();
436
+ if (localeRegion) {
437
+ regions.add(localeRegion);
438
+ }
439
+ for (const region of inferred) {
440
+ regions.add(region);
441
+ }
442
+ if (regions.size > 0) {
443
+ return Array.from(regions);
444
+ }
437
445
  if (normalizedLocale.startsWith("uk")) {
438
446
  return ["czsk", "pl", "ro", "de", "hu", "fr", "es", "it", "nl", "at"];
439
447
  }
@@ -1158,7 +1166,7 @@ var CONFIG_TTL_MS = 5 * 60 * 1e3;
1158
1166
  var CONFIG_TIMEOUT_MS = 8e3;
1159
1167
  var CONFIG_RETRY_DELAY_MS = 1e3;
1160
1168
  var MAX_CAPABILITY_CACHE_ENTRIES = 500;
1161
- var AGENTID_SDK_VERSION_HEADER = "js-1.0.7";
1169
+ var AGENTID_SDK_VERSION_HEADER = "js-1.0.8";
1162
1170
  var CapabilityConfigFetchError = class extends Error {
1163
1171
  constructor(message, params) {
1164
1172
  super(message);
@@ -1757,10 +1765,12 @@ function getInjectionScanner() {
1757
1765
  }
1758
1766
 
1759
1767
  // src/agentid.ts
1760
- var AGENTID_SDK_VERSION_HEADER2 = "js-1.0.7";
1761
- var DEFAULT_GUARD_TIMEOUT_MS = 3500;
1768
+ var AGENTID_SDK_VERSION_HEADER2 = "js-1.0.8";
1769
+ var DEFAULT_GUARD_TIMEOUT_MS = 1e4;
1762
1770
  var MIN_GUARD_TIMEOUT_MS = 500;
1763
- var MAX_GUARD_TIMEOUT_MS = 1e4;
1771
+ var MAX_GUARD_TIMEOUT_MS = 15e3;
1772
+ var GUARD_MAX_ATTEMPTS = 3;
1773
+ var GUARD_RETRY_DELAYS_MS = [250, 500];
1764
1774
  function normalizeBaseUrl3(baseUrl) {
1765
1775
  return baseUrl.replace(/\/+$/, "");
1766
1776
  }
@@ -1828,6 +1838,24 @@ function isInfrastructureGuardReason(reason) {
1828
1838
  if (!reason) return false;
1829
1839
  return reason === "system_failure" || reason === "system_failure_db_unavailable" || reason === "logging_failed" || reason === "server_error" || reason === "guard_unreachable" || reason === "api_key_pepper_missing" || reason === "encryption_key_missing";
1830
1840
  }
1841
+ function isUuidLike(value) {
1842
+ if (!value) return false;
1843
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
1844
+ value
1845
+ );
1846
+ }
1847
+ function createCorrelationId(seed) {
1848
+ if (isUuidLike(seed)) return seed;
1849
+ if (typeof globalThis.crypto?.randomUUID === "function") {
1850
+ return globalThis.crypto.randomUUID();
1851
+ }
1852
+ return `cid_${Date.now()}_${Math.random().toString(36).slice(2)}`;
1853
+ }
1854
+ async function waitForRetry(attemptIndex) {
1855
+ const delay = GUARD_RETRY_DELAYS_MS[attemptIndex];
1856
+ if (!delay) return;
1857
+ await new Promise((resolve) => setTimeout(resolve, delay));
1858
+ }
1831
1859
  async function safeReadJson2(response) {
1832
1860
  try {
1833
1861
  return await response.json();
@@ -2087,79 +2115,124 @@ var AgentID = class {
2087
2115
  ...params,
2088
2116
  client_capabilities: params.client_capabilities ?? this.buildClientCapabilities()
2089
2117
  };
2090
- const controller = new AbortController();
2091
- const timeoutId = setTimeout(() => controller.abort(), this.guardTimeoutMs);
2092
- try {
2093
- const res = await fetch(`${this.baseUrl}/guard`, {
2094
- method: "POST",
2095
- headers: {
2096
- "Content-Type": "application/json",
2097
- "x-agentid-api-key": effectiveApiKey,
2098
- "X-AgentID-SDK-Version": AGENTID_SDK_VERSION_HEADER2
2099
- },
2100
- body: JSON.stringify(payload),
2101
- signal: controller.signal
2102
- });
2103
- const responseBody = await safeReadJson2(res);
2104
- if (responseBody && typeof responseBody.allowed === "boolean") {
2105
- const verdict = responseBody;
2106
- if (verdict.allowed === false && (isInfrastructureGuardReason(verdict.reason) || res.status >= 500)) {
2107
- if (this.strictMode) {
2118
+ const correlationId = createCorrelationId(payload.client_event_id);
2119
+ let lastStatusCode = null;
2120
+ let lastAbort = false;
2121
+ let lastError = null;
2122
+ for (let attempt = 0; attempt < GUARD_MAX_ATTEMPTS; attempt += 1) {
2123
+ const controller = new AbortController();
2124
+ const timeoutId = setTimeout(() => controller.abort(), this.guardTimeoutMs);
2125
+ try {
2126
+ const res = await fetch(`${this.baseUrl}/guard`, {
2127
+ method: "POST",
2128
+ headers: {
2129
+ "Content-Type": "application/json",
2130
+ "x-agentid-api-key": effectiveApiKey,
2131
+ "X-AgentID-SDK-Version": AGENTID_SDK_VERSION_HEADER2,
2132
+ "x-correlation-id": correlationId
2133
+ },
2134
+ body: JSON.stringify(payload),
2135
+ signal: controller.signal
2136
+ });
2137
+ lastStatusCode = res.status;
2138
+ const responseBody = await safeReadJson2(res);
2139
+ if (responseBody && typeof responseBody.allowed === "boolean") {
2140
+ const verdict = responseBody;
2141
+ const infrastructureFailure = verdict.allowed === false && (isInfrastructureGuardReason(verdict.reason) || res.status >= 500);
2142
+ if (infrastructureFailure) {
2143
+ if (attempt < GUARD_MAX_ATTEMPTS - 1) {
2144
+ await waitForRetry(attempt);
2145
+ continue;
2146
+ }
2147
+ if (this.strictMode) {
2148
+ console.warn(
2149
+ `[AgentID] Guard API infrastructure failure in strict mode (${verdict.reason ?? `http_${res.status}`}). Blocking request.`
2150
+ );
2151
+ return { allowed: false, reason: verdict.reason ?? "network_error_strict_mode" };
2152
+ }
2108
2153
  console.warn(
2109
- `[AgentID] Guard API infrastructure failure in strict mode (${verdict.reason ?? `http_${res.status}`}). Blocking request.`
2154
+ `[AgentID] Guard API infrastructure fallback in fail-open mode (${verdict.reason ?? `http_${res.status}`}).`
2110
2155
  );
2111
- return { allowed: false, reason: verdict.reason ?? "network_error_strict_mode" };
2156
+ this.logGuardFallback({
2157
+ reason: verdict.reason ?? `http_${res.status}`,
2158
+ status: "upstream_error",
2159
+ guardParams: params,
2160
+ apiKey: effectiveApiKey
2161
+ });
2162
+ return { allowed: true, reason: "system_failure_fail_open" };
2112
2163
  }
2113
- console.warn(
2114
- `[AgentID] Guard API infrastructure fallback in fail-open mode (${verdict.reason ?? `http_${res.status}`}).`
2115
- );
2164
+ return verdict;
2165
+ }
2166
+ if (!res.ok) {
2167
+ if (res.status >= 500 && attempt < GUARD_MAX_ATTEMPTS - 1) {
2168
+ await waitForRetry(attempt);
2169
+ continue;
2170
+ }
2171
+ throw new Error(`API Error ${res.status}`);
2172
+ }
2173
+ throw new Error("Invalid guard response");
2174
+ } catch (error) {
2175
+ lastError = error;
2176
+ const isAbortError2 = Boolean(
2177
+ error && typeof error === "object" && error.name === "AbortError"
2178
+ );
2179
+ lastAbort = isAbortError2;
2180
+ if (attempt < GUARD_MAX_ATTEMPTS - 1) {
2181
+ await waitForRetry(attempt);
2182
+ continue;
2183
+ }
2184
+ if (isAbortError2) {
2185
+ const timeoutMessage = "AgentID API Warning: Connection timeout exceeded.";
2186
+ console.warn(timeoutMessage);
2116
2187
  this.logGuardFallback({
2117
- reason: verdict.reason ?? `http_${res.status}`,
2118
- status: "upstream_error",
2188
+ reason: "timeout_fallback",
2189
+ status: "latency_timeout",
2119
2190
  guardParams: params,
2120
2191
  apiKey: effectiveApiKey
2121
2192
  });
2122
- return { allowed: true, reason: "system_failure_fail_open" };
2193
+ if (this.strictMode) {
2194
+ return { allowed: false, reason: "network_error_strict_mode" };
2195
+ }
2196
+ return { allowed: true, reason: "timeout_fallback" };
2123
2197
  }
2124
- return verdict;
2125
- }
2126
- if (!res.ok) {
2127
- throw new Error(`API Error ${res.status}`);
2128
- }
2129
- throw new Error("Invalid guard response");
2130
- } catch (error) {
2131
- const isAbortError2 = error && typeof error === "object" && error.name === "AbortError";
2132
- if (isAbortError2) {
2133
- const timeoutMessage = "AgentID API Warning: Connection timeout exceeded.";
2134
- console.warn(timeoutMessage);
2198
+ console.warn(
2199
+ this.strictMode ? "[AgentID] Guard check failed (Strict mode active):" : "[AgentID] Guard check failed (Fail-Open active):",
2200
+ error
2201
+ );
2135
2202
  this.logGuardFallback({
2136
- reason: "timeout_fallback",
2137
- status: "latency_timeout",
2203
+ reason: "guard_unreachable",
2204
+ status: "guard_unreachable",
2138
2205
  guardParams: params,
2139
2206
  apiKey: effectiveApiKey
2140
2207
  });
2141
2208
  if (this.strictMode) {
2142
2209
  return { allowed: false, reason: "network_error_strict_mode" };
2143
2210
  }
2144
- return { allowed: true, reason: "timeout_fallback" };
2211
+ return { allowed: true, reason: "guard_unreachable" };
2212
+ } finally {
2213
+ clearTimeout(timeoutId);
2145
2214
  }
2146
- console.warn(
2147
- this.strictMode ? "[AgentID] Guard check failed (Strict mode active):" : "[AgentID] Guard check failed (Fail-Open active):",
2148
- error
2149
- );
2150
- this.logGuardFallback({
2151
- reason: "guard_unreachable",
2152
- status: "guard_unreachable",
2153
- guardParams: params,
2154
- apiKey: effectiveApiKey
2155
- });
2215
+ }
2216
+ if (lastAbort) {
2156
2217
  if (this.strictMode) {
2157
2218
  return { allowed: false, reason: "network_error_strict_mode" };
2158
2219
  }
2159
- return { allowed: true, reason: "guard_unreachable" };
2160
- } finally {
2161
- clearTimeout(timeoutId);
2220
+ return { allowed: true, reason: "timeout_fallback" };
2221
+ }
2222
+ if (typeof lastStatusCode === "number" && lastStatusCode >= 500) {
2223
+ if (this.strictMode) {
2224
+ return { allowed: false, reason: "server_error" };
2225
+ }
2226
+ return { allowed: true, reason: "system_failure_fail_open" };
2227
+ }
2228
+ console.warn(
2229
+ this.strictMode ? "[AgentID] Guard check failed (Strict mode active):" : "[AgentID] Guard check failed (Fail-Open active):",
2230
+ lastError
2231
+ );
2232
+ if (this.strictMode) {
2233
+ return { allowed: false, reason: "network_error_strict_mode" };
2162
2234
  }
2235
+ return { allowed: true, reason: "guard_unreachable" };
2163
2236
  }
2164
2237
  extractStreamChunkText(chunk) {
2165
2238
  if (typeof chunk === "string") {
@@ -25,6 +25,8 @@ interface GuardResponse {
25
25
  reason?: string;
26
26
  detected_pii?: boolean;
27
27
  transformed_input?: string;
28
+ guard_event_id?: string;
29
+ client_event_id?: string;
28
30
  shadow_mode?: boolean;
29
31
  simulated_decision?: "allowed" | "masked" | "blocked";
30
32
  }
@@ -25,6 +25,8 @@ interface GuardResponse {
25
25
  reason?: string;
26
26
  detected_pii?: boolean;
27
27
  transformed_input?: string;
28
+ guard_event_id?: string;
29
+ client_event_id?: string;
28
30
  shadow_mode?: boolean;
29
31
  simulated_decision?: "allowed" | "masked" | "blocked";
30
32
  }
@@ -1 +1 @@
1
- export { a as AgentIDCallbackHandler } from './langchain-DVPOWfCC.mjs';
1
+ export { a as AgentIDCallbackHandler } from './langchain-BGP3qxvW.mjs';
@@ -1 +1 @@
1
- export { a as AgentIDCallbackHandler } from './langchain-DVPOWfCC.js';
1
+ export { a as AgentIDCallbackHandler } from './langchain-BGP3qxvW.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentid-sdk",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "AgentID JavaScript/TypeScript SDK for guard, ingest, tracing, and analytics.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://agentid.ai",