agentid-sdk 0.1.5 → 0.1.6

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
@@ -42,6 +42,7 @@ const openai = new OpenAI();
42
42
  const agent = new AgentID({
43
43
  apiKey: "ag_prod_...",
44
44
  strictMode: false, // default (fail-open on timeout/unreachable AgentID API)
45
+ guardTimeoutMs: 6000, // optional: timeout for AgentID /guard call in ms
45
46
  // strictMode: true, // fail-closed for high-risk workloads
46
47
  });
47
48
 
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-CIIL2j4R.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-C6HJAK2b.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-CIIL2j4R.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-C6HJAK2b.js';
2
2
 
3
3
  type PIIMapping = Record<string, string>;
4
4
  declare class PIIManager {
package/dist/index.js CHANGED
@@ -392,7 +392,7 @@ var CONFIG_TTL_MS = 5 * 60 * 1e3;
392
392
  var CONFIG_TIMEOUT_MS = 8e3;
393
393
  var CONFIG_RETRY_DELAY_MS = 1e3;
394
394
  var MAX_CAPABILITY_CACHE_ENTRIES = 500;
395
- var AGENTID_SDK_VERSION_HEADER = "js-1.0.4";
395
+ var AGENTID_SDK_VERSION_HEADER = "js-1.0.6";
396
396
  var CapabilityConfigFetchError = class extends Error {
397
397
  constructor(message, params) {
398
398
  super(message);
@@ -980,10 +980,67 @@ function getInjectionScanner() {
980
980
  }
981
981
 
982
982
  // src/agentid.ts
983
- var AGENTID_SDK_VERSION_HEADER2 = "js-1.0.4";
983
+ var AGENTID_SDK_VERSION_HEADER2 = "js-1.0.6";
984
+ var DEFAULT_GUARD_TIMEOUT_MS = 6e3;
985
+ var MIN_GUARD_TIMEOUT_MS = 1e3;
986
+ var MAX_GUARD_TIMEOUT_MS = 3e4;
984
987
  function normalizeBaseUrl3(baseUrl) {
985
988
  return baseUrl.replace(/\/+$/, "");
986
989
  }
990
+ function isAbortSignalLike(value) {
991
+ if (!value || typeof value !== "object") return false;
992
+ const candidate = value;
993
+ return typeof candidate.aborted === "boolean" && typeof candidate.addEventListener === "function";
994
+ }
995
+ function normalizeOpenAICreateArgs(rawArgs) {
996
+ if (!Array.isArray(rawArgs) || rawArgs.length === 0) {
997
+ return rawArgs;
998
+ }
999
+ const nextArgs = [...rawArgs];
1000
+ const firstArg = nextArgs[0];
1001
+ if (!firstArg || typeof firstArg !== "object" || Array.isArray(firstArg)) {
1002
+ return nextArgs;
1003
+ }
1004
+ const requestBody = { ...firstArg };
1005
+ const hasSignalInBody = Object.prototype.hasOwnProperty.call(requestBody, "signal");
1006
+ if (!hasSignalInBody) {
1007
+ nextArgs[0] = requestBody;
1008
+ return nextArgs;
1009
+ }
1010
+ const bodySignal = requestBody.signal;
1011
+ delete requestBody.signal;
1012
+ nextArgs[0] = requestBody;
1013
+ if (!isAbortSignalLike(bodySignal)) {
1014
+ return nextArgs;
1015
+ }
1016
+ const secondArg = nextArgs[1];
1017
+ if (typeof secondArg === "undefined") {
1018
+ nextArgs[1] = { signal: bodySignal };
1019
+ return nextArgs;
1020
+ }
1021
+ if (!secondArg || typeof secondArg !== "object" || Array.isArray(secondArg)) {
1022
+ return nextArgs;
1023
+ }
1024
+ const requestOptions = { ...secondArg };
1025
+ if (!Object.prototype.hasOwnProperty.call(requestOptions, "signal")) {
1026
+ requestOptions.signal = bodySignal;
1027
+ }
1028
+ nextArgs[1] = requestOptions;
1029
+ return nextArgs;
1030
+ }
1031
+ function normalizeGuardTimeoutMs(value) {
1032
+ if (!Number.isFinite(value)) {
1033
+ return DEFAULT_GUARD_TIMEOUT_MS;
1034
+ }
1035
+ const rounded = Math.trunc(value);
1036
+ if (rounded < MIN_GUARD_TIMEOUT_MS) {
1037
+ return MIN_GUARD_TIMEOUT_MS;
1038
+ }
1039
+ if (rounded > MAX_GUARD_TIMEOUT_MS) {
1040
+ return MAX_GUARD_TIMEOUT_MS;
1041
+ }
1042
+ return rounded;
1043
+ }
987
1044
  function isInfrastructureGuardReason(reason) {
988
1045
  if (!reason) return false;
989
1046
  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";
@@ -1005,6 +1062,7 @@ var AgentID = class {
1005
1062
  this.aiScanEnabled = config.aiScanEnabled !== false;
1006
1063
  this.storePii = config.storePii === true;
1007
1064
  this.strictMode = config.strictMode === true;
1065
+ this.guardTimeoutMs = normalizeGuardTimeoutMs(config.guardTimeoutMs);
1008
1066
  this.pii = new PIIManager();
1009
1067
  this.localEnforcer = new LocalSecurityEnforcer(this.pii);
1010
1068
  void this.getCapabilityConfig();
@@ -1161,7 +1219,7 @@ var AgentID = class {
1161
1219
  client_capabilities: params.client_capabilities ?? this.buildClientCapabilities()
1162
1220
  };
1163
1221
  const controller = new AbortController();
1164
- const timeoutId = setTimeout(() => controller.abort(), 2e3);
1222
+ const timeoutId = setTimeout(() => controller.abort(), this.guardTimeoutMs);
1165
1223
  try {
1166
1224
  const res = await fetch(`${this.baseUrl}/guard`, {
1167
1225
  method: "POST",
@@ -1283,7 +1341,8 @@ var AgentID = class {
1283
1341
  const originalCreate = Reflect.get(compTarget, compProp, compReceiver);
1284
1342
  if (typeof originalCreate !== "function") return originalCreate;
1285
1343
  return async (...args) => {
1286
- const req = args?.[0] ?? {};
1344
+ const normalizedCreateArgs = normalizeOpenAICreateArgs(args);
1345
+ const req = normalizedCreateArgs?.[0] ?? {};
1287
1346
  const requestLevelApiKey = options.resolveApiKey?.(req) ?? options.apiKey ?? options.api_key;
1288
1347
  const effectiveApiKey = this.resolveApiKey(requestLevelApiKey);
1289
1348
  const requestOptions = { apiKey: effectiveApiKey };
@@ -1292,7 +1351,7 @@ var AgentID = class {
1292
1351
  const userText = adapter.extractInput(req);
1293
1352
  let maskedText = userText;
1294
1353
  let maskedReq = req;
1295
- let createArgs = args;
1354
+ let createArgs = normalizedCreateArgs;
1296
1355
  let mapping = {};
1297
1356
  let shouldDeanonymize = false;
1298
1357
  if (userText) {
@@ -1310,7 +1369,9 @@ var AgentID = class {
1310
1369
  req,
1311
1370
  maskedText
1312
1371
  );
1313
- createArgs = [maskedReq, ...args.slice(1)];
1372
+ const nextCreateArgs = [...normalizedCreateArgs];
1373
+ nextCreateArgs[0] = maskedReq;
1374
+ createArgs = nextCreateArgs;
1314
1375
  }
1315
1376
  if (!capabilityConfig.block_pii_leakage && this.piiMasking) {
1316
1377
  if (stream) {
@@ -1324,7 +1385,9 @@ var AgentID = class {
1324
1385
  req,
1325
1386
  maskedText
1326
1387
  );
1327
- createArgs = [maskedReq, ...args.slice(1)];
1388
+ const nextCreateArgs = [...normalizedCreateArgs];
1389
+ nextCreateArgs[0] = maskedReq;
1390
+ createArgs = nextCreateArgs;
1328
1391
  }
1329
1392
  }
1330
1393
  }
package/dist/index.mjs CHANGED
@@ -354,7 +354,7 @@ var CONFIG_TTL_MS = 5 * 60 * 1e3;
354
354
  var CONFIG_TIMEOUT_MS = 8e3;
355
355
  var CONFIG_RETRY_DELAY_MS = 1e3;
356
356
  var MAX_CAPABILITY_CACHE_ENTRIES = 500;
357
- var AGENTID_SDK_VERSION_HEADER = "js-1.0.4";
357
+ var AGENTID_SDK_VERSION_HEADER = "js-1.0.6";
358
358
  var CapabilityConfigFetchError = class extends Error {
359
359
  constructor(message, params) {
360
360
  super(message);
@@ -942,10 +942,67 @@ function getInjectionScanner() {
942
942
  }
943
943
 
944
944
  // src/agentid.ts
945
- var AGENTID_SDK_VERSION_HEADER2 = "js-1.0.4";
945
+ var AGENTID_SDK_VERSION_HEADER2 = "js-1.0.6";
946
+ var DEFAULT_GUARD_TIMEOUT_MS = 6e3;
947
+ var MIN_GUARD_TIMEOUT_MS = 1e3;
948
+ var MAX_GUARD_TIMEOUT_MS = 3e4;
946
949
  function normalizeBaseUrl3(baseUrl) {
947
950
  return baseUrl.replace(/\/+$/, "");
948
951
  }
952
+ function isAbortSignalLike(value) {
953
+ if (!value || typeof value !== "object") return false;
954
+ const candidate = value;
955
+ return typeof candidate.aborted === "boolean" && typeof candidate.addEventListener === "function";
956
+ }
957
+ function normalizeOpenAICreateArgs(rawArgs) {
958
+ if (!Array.isArray(rawArgs) || rawArgs.length === 0) {
959
+ return rawArgs;
960
+ }
961
+ const nextArgs = [...rawArgs];
962
+ const firstArg = nextArgs[0];
963
+ if (!firstArg || typeof firstArg !== "object" || Array.isArray(firstArg)) {
964
+ return nextArgs;
965
+ }
966
+ const requestBody = { ...firstArg };
967
+ const hasSignalInBody = Object.prototype.hasOwnProperty.call(requestBody, "signal");
968
+ if (!hasSignalInBody) {
969
+ nextArgs[0] = requestBody;
970
+ return nextArgs;
971
+ }
972
+ const bodySignal = requestBody.signal;
973
+ delete requestBody.signal;
974
+ nextArgs[0] = requestBody;
975
+ if (!isAbortSignalLike(bodySignal)) {
976
+ return nextArgs;
977
+ }
978
+ const secondArg = nextArgs[1];
979
+ if (typeof secondArg === "undefined") {
980
+ nextArgs[1] = { signal: bodySignal };
981
+ return nextArgs;
982
+ }
983
+ if (!secondArg || typeof secondArg !== "object" || Array.isArray(secondArg)) {
984
+ return nextArgs;
985
+ }
986
+ const requestOptions = { ...secondArg };
987
+ if (!Object.prototype.hasOwnProperty.call(requestOptions, "signal")) {
988
+ requestOptions.signal = bodySignal;
989
+ }
990
+ nextArgs[1] = requestOptions;
991
+ return nextArgs;
992
+ }
993
+ function normalizeGuardTimeoutMs(value) {
994
+ if (!Number.isFinite(value)) {
995
+ return DEFAULT_GUARD_TIMEOUT_MS;
996
+ }
997
+ const rounded = Math.trunc(value);
998
+ if (rounded < MIN_GUARD_TIMEOUT_MS) {
999
+ return MIN_GUARD_TIMEOUT_MS;
1000
+ }
1001
+ if (rounded > MAX_GUARD_TIMEOUT_MS) {
1002
+ return MAX_GUARD_TIMEOUT_MS;
1003
+ }
1004
+ return rounded;
1005
+ }
949
1006
  function isInfrastructureGuardReason(reason) {
950
1007
  if (!reason) return false;
951
1008
  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";
@@ -967,6 +1024,7 @@ var AgentID = class {
967
1024
  this.aiScanEnabled = config.aiScanEnabled !== false;
968
1025
  this.storePii = config.storePii === true;
969
1026
  this.strictMode = config.strictMode === true;
1027
+ this.guardTimeoutMs = normalizeGuardTimeoutMs(config.guardTimeoutMs);
970
1028
  this.pii = new PIIManager();
971
1029
  this.localEnforcer = new LocalSecurityEnforcer(this.pii);
972
1030
  void this.getCapabilityConfig();
@@ -1123,7 +1181,7 @@ var AgentID = class {
1123
1181
  client_capabilities: params.client_capabilities ?? this.buildClientCapabilities()
1124
1182
  };
1125
1183
  const controller = new AbortController();
1126
- const timeoutId = setTimeout(() => controller.abort(), 2e3);
1184
+ const timeoutId = setTimeout(() => controller.abort(), this.guardTimeoutMs);
1127
1185
  try {
1128
1186
  const res = await fetch(`${this.baseUrl}/guard`, {
1129
1187
  method: "POST",
@@ -1245,7 +1303,8 @@ var AgentID = class {
1245
1303
  const originalCreate = Reflect.get(compTarget, compProp, compReceiver);
1246
1304
  if (typeof originalCreate !== "function") return originalCreate;
1247
1305
  return async (...args) => {
1248
- const req = args?.[0] ?? {};
1306
+ const normalizedCreateArgs = normalizeOpenAICreateArgs(args);
1307
+ const req = normalizedCreateArgs?.[0] ?? {};
1249
1308
  const requestLevelApiKey = options.resolveApiKey?.(req) ?? options.apiKey ?? options.api_key;
1250
1309
  const effectiveApiKey = this.resolveApiKey(requestLevelApiKey);
1251
1310
  const requestOptions = { apiKey: effectiveApiKey };
@@ -1254,7 +1313,7 @@ var AgentID = class {
1254
1313
  const userText = adapter.extractInput(req);
1255
1314
  let maskedText = userText;
1256
1315
  let maskedReq = req;
1257
- let createArgs = args;
1316
+ let createArgs = normalizedCreateArgs;
1258
1317
  let mapping = {};
1259
1318
  let shouldDeanonymize = false;
1260
1319
  if (userText) {
@@ -1272,7 +1331,9 @@ var AgentID = class {
1272
1331
  req,
1273
1332
  maskedText
1274
1333
  );
1275
- createArgs = [maskedReq, ...args.slice(1)];
1334
+ const nextCreateArgs = [...normalizedCreateArgs];
1335
+ nextCreateArgs[0] = maskedReq;
1336
+ createArgs = nextCreateArgs;
1276
1337
  }
1277
1338
  if (!capabilityConfig.block_pii_leakage && this.piiMasking) {
1278
1339
  if (stream) {
@@ -1286,7 +1347,9 @@ var AgentID = class {
1286
1347
  req,
1287
1348
  maskedText
1288
1349
  );
1289
- createArgs = [maskedReq, ...args.slice(1)];
1350
+ const nextCreateArgs = [...normalizedCreateArgs];
1351
+ nextCreateArgs[0] = maskedReq;
1352
+ createArgs = nextCreateArgs;
1290
1353
  }
1291
1354
  }
1292
1355
  }
@@ -55,6 +55,7 @@ type AgentIDConfig = {
55
55
  aiScanEnabled?: boolean;
56
56
  storePii?: boolean;
57
57
  strictMode?: boolean;
58
+ guardTimeoutMs?: number;
58
59
  };
59
60
 
60
61
  type PreparedInput = {
@@ -69,6 +70,7 @@ declare class AgentID {
69
70
  private aiScanEnabled;
70
71
  private storePii;
71
72
  private strictMode;
73
+ private guardTimeoutMs;
72
74
  private pii;
73
75
  private localEnforcer;
74
76
  private injectionScanner;
@@ -55,6 +55,7 @@ type AgentIDConfig = {
55
55
  aiScanEnabled?: boolean;
56
56
  storePii?: boolean;
57
57
  strictMode?: boolean;
58
+ guardTimeoutMs?: number;
58
59
  };
59
60
 
60
61
  type PreparedInput = {
@@ -69,6 +70,7 @@ declare class AgentID {
69
70
  private aiScanEnabled;
70
71
  private storePii;
71
72
  private strictMode;
73
+ private guardTimeoutMs;
72
74
  private pii;
73
75
  private localEnforcer;
74
76
  private injectionScanner;
@@ -1 +1 @@
1
- export { a as AgentIDCallbackHandler } from './langchain-CIIL2j4R.mjs';
1
+ export { a as AgentIDCallbackHandler } from './langchain-C6HJAK2b.mjs';
@@ -1 +1 @@
1
- export { a as AgentIDCallbackHandler } from './langchain-CIIL2j4R.js';
1
+ export { a as AgentIDCallbackHandler } from './langchain-C6HJAK2b.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentid-sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "AgentID JavaScript/TypeScript SDK for guard, ingest, tracing, and analytics.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://agentid.ai",