@naylence/agent-sdk 0.3.9 → 0.3.11

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.
@@ -4305,9 +4305,6 @@
4305
4305
  }
4306
4306
 
4307
4307
  const textEncoder$2 = ensureEncoder();
4308
- const textDecoder$1 = ensureDecoder();
4309
- const STORAGE_SEED_KEY = 'naylence:fame:seed';
4310
- let cachedBrowserSeed = null;
4311
4308
  function ensureEncoder() {
4312
4309
  if (typeof TextEncoder !== 'undefined') {
4313
4310
  return new TextEncoder();
@@ -4319,17 +4316,6 @@
4319
4316
  const { TextEncoder: ImportedTextEncoder } = require('util');
4320
4317
  return new ImportedTextEncoder();
4321
4318
  }
4322
- function ensureDecoder() {
4323
- if (typeof TextDecoder !== 'undefined') {
4324
- return new TextDecoder();
4325
- }
4326
- const util = globalThis.util;
4327
- if (util?.TextDecoder) {
4328
- return new util.TextDecoder();
4329
- }
4330
- const { TextDecoder: ImportedTextDecoder } = require('util');
4331
- return new ImportedTextDecoder();
4332
- }
4333
4319
  function decodeBase64$2(str) {
4334
4320
  if (typeof atob === 'function') {
4335
4321
  return atob(str);
@@ -4371,111 +4357,34 @@
4371
4357
  }
4372
4358
  return fallbackHash(data);
4373
4359
  }
4374
- function getCanonicalArgv() {
4375
- return 'browser';
4376
- }
4377
- async function getDefaultBrowserFingerprint(extraMaterial) {
4378
- const hostFingerprint = `seed:${getStableBrowserSeed()}`;
4379
- const codeFingerprint = getCanonicalArgv();
4380
- const parts = [`${hostFingerprint}`, `${codeFingerprint}`];
4381
- if (extraMaterial !== undefined && extraMaterial !== null) {
4382
- let salt;
4383
- if (typeof extraMaterial === 'string') {
4384
- salt = extraMaterial;
4385
- }
4386
- else if (extraMaterial instanceof Uint8Array) {
4387
- salt = textDecoder$1.decode(extraMaterial);
4388
- }
4389
- else {
4390
- salt = String(extraMaterial);
4391
- }
4392
- parts.push(`salt:${salt}`);
4393
- }
4394
- const payload = parts.join('|');
4395
- return textEncoder$2.encode(payload);
4396
- }
4397
- function getStableBrowserSeed() {
4398
- if (cachedBrowserSeed) {
4399
- return cachedBrowserSeed;
4400
- }
4401
- const storages = getWritableStorages();
4402
- for (const storage of storages) {
4403
- const stored = readSeed(storage);
4404
- if (stored) {
4405
- cachedBrowserSeed = stored;
4406
- return stored;
4407
- }
4408
- }
4409
- const seed = generateSeed();
4410
- for (const storage of storages) {
4411
- if (writeSeed(storage, seed)) {
4412
- cachedBrowserSeed = seed;
4413
- return seed;
4414
- }
4415
- }
4416
- cachedBrowserSeed = seed;
4417
- return seed;
4418
- }
4419
- function readSeed(storage) {
4420
- try {
4421
- return storage.getItem(STORAGE_SEED_KEY);
4422
- }
4423
- catch {
4424
- return null;
4425
- }
4426
- }
4427
- function writeSeed(storage, seed) {
4428
- try {
4429
- storage.setItem(STORAGE_SEED_KEY, seed);
4430
- return true;
4431
- }
4432
- catch {
4433
- return false;
4434
- }
4435
- }
4436
- function getWritableStorages() {
4437
- const storages = [];
4438
- const storageNames = [
4439
- 'localStorage',
4440
- 'sessionStorage',
4441
- ];
4442
- for (const name of storageNames) {
4443
- const storage = resolveStorage(name);
4444
- if (storage) {
4445
- storages.push(storage);
4446
- }
4447
- }
4448
- return storages;
4449
- }
4450
- function resolveStorage(name) {
4451
- try {
4452
- const storage = globalThis[name];
4453
- if (!storage) {
4454
- return null;
4455
- }
4456
- const probeKey = `${STORAGE_SEED_KEY}:probe`;
4457
- storage.setItem(probeKey, '1');
4458
- storage.removeItem(probeKey);
4459
- return storage;
4460
- }
4461
- catch {
4462
- return null;
4463
- }
4464
- }
4465
- function generateSeed() {
4466
- const bytes = getRandomBytes$1(16);
4467
- return Array.from(bytes, (byte) => byte.toString(16).padStart(2, '0')).join('');
4468
- }
4360
+ /**
4361
+ * Synchronous ID generation in the browser.
4362
+ *
4363
+ * - mode: "random" → generates a random ID using crypto.getRandomValues when available
4364
+ * - mode: "fingerprint" → falls back to random behavior (fingerprinting requires async)
4365
+ *
4366
+ * Note: In the browser, deterministic fingerprinting requires async operations.
4367
+ * Use generateIdAsync with explicit `material` for deterministic IDs.
4368
+ */
4469
4369
  function generateId(options = {}) {
4470
4370
  const { length = 16, mode = 'random', blacklist = BLACKLIST_ID_WORDS, } = options;
4471
4371
  if (mode !== 'random' && mode !== 'fingerprint') {
4472
4372
  throw new Error("mode must be 'random' or 'fingerprint'");
4473
4373
  }
4474
- if (mode === 'random') {
4475
- return generateRandomCandidate(length, getRandomBytes$1, blacklist);
4476
- }
4477
- throw new Error('Browser environment requires async ID generation - use generateIdAsync instead');
4374
+ // In the browser, both modes use random generation for the sync API
4375
+ // Fingerprinting requires async operations and explicit material
4376
+ return generateRandomCandidate(length, getRandomBytes$1, blacklist);
4478
4377
  }
4378
+ /**
4379
+ * Asynchronous ID generation in the browser.
4380
+ *
4381
+ * - mode: "random" → generates a random ID using crypto.getRandomValues when available
4382
+ * - mode: "fingerprint" WITH explicit `material` → generates a deterministic ID by hashing the provided material
4383
+ * - mode: "fingerprint" WITHOUT `material` → falls back to random behavior (no implicit fingerprinting)
4384
+ *
4385
+ * Note: This implementation does NOT create browser fingerprints or use localStorage/sessionStorage.
4386
+ * For deterministic IDs, you must explicitly provide `material` in fingerprint mode.
4387
+ */
4479
4388
  async function generateIdAsync(options = {}) {
4480
4389
  const { length = 16, mode = 'random', material, blacklist = BLACKLIST_ID_WORDS, hashAlg = 'sha256', } = options;
4481
4390
  if (mode !== 'random' && mode !== 'fingerprint') {
@@ -4484,14 +4393,13 @@
4484
4393
  if (mode === 'random') {
4485
4394
  return generateRandomCandidate(length, getRandomBytes$1, blacklist);
4486
4395
  }
4487
- let materialBytes;
4396
+ // Fingerprint mode: only deterministic if material is explicitly provided
4488
4397
  if (material === undefined || material === null) {
4489
- const envSalt = globalThis.process?.env?.FAME_NODE_ID_SALT;
4490
- materialBytes = await getDefaultBrowserFingerprint(envSalt ?? '');
4491
- }
4492
- else {
4493
- materialBytes = materialToBytes(material, textEncoder$2);
4398
+ // No implicit fingerprinting - fall back to random
4399
+ return generateRandomCandidate(length, getRandomBytes$1, blacklist);
4494
4400
  }
4401
+ // Deterministic ID generation using explicit material
4402
+ const materialBytes = materialToBytes(material, textEncoder$2);
4495
4403
  const initialDigest = await hashAsync(materialBytes, hashAlg);
4496
4404
  return rehashUntilCleanAsync(initialDigest, length, (input) => hashAsync(input, hashAlg), blacklist);
4497
4405
  }
@@ -15692,12 +15600,12 @@
15692
15600
  // --- END ENV SHIM ---
15693
15601
 
15694
15602
  // This file is auto-generated during build - do not edit manually
15695
- // Generated from package.json version: 0.3.10
15603
+ // Generated from package.json version: 0.3.12
15696
15604
  /**
15697
15605
  * The package version, injected at build time.
15698
15606
  * @internal
15699
15607
  */
15700
- const VERSION$1 = '0.3.10';
15608
+ const VERSION$1 = '0.3.12';
15701
15609
 
15702
15610
  /**
15703
15611
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -34611,6 +34519,7 @@
34611
34519
  throw new FameTransportClose('WebSocket object is null', 1006);
34612
34520
  }
34613
34521
  // Use a timeout to prevent hanging during shutdown scenarios
34522
+ // Increased to 1 hour to match server-side keep-alive and prevent idle disconnects
34614
34523
  const receiveTimeout = 30000; // 30 seconds
34615
34524
  if (this._isFastApiLike && this._websocket.receive_bytes) {
34616
34525
  // FastAPI-style server WebSocket