Skip to content

Commit 0bcf573

Browse files
committed
fix: replace top-level await with synchronous require in AgentKeyManager
The top-level `await import('node:crypto')` breaks CJS output format (esbuild/tsx emit error: "Top-level await is currently not supported with the cjs output format"). Since node:crypto is a built-in module, a synchronous require() works in all Node.js environments and avoids the ESM-only TLA constraint.
1 parent 89036be commit 0bcf573

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/core/provenance/crypto/AgentKeyManager.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ import type { AgentKeySource } from '../types.js';
1212
// Runtime Detection
1313
// =============================================================================
1414

15+
/**
16+
* Lazily-resolved reference to Node.js `crypto` module.
17+
* Uses synchronous `require()` to avoid top-level `await`, which breaks CJS
18+
* output (esbuild / tsx emit `"cjs"` format that does not support TLA).
19+
* Falls back to `undefined` in browser / non-Node runtimes.
20+
*/
1521
let nodeCrypto: typeof import('node:crypto') | undefined;
1622
try {
17-
// Dynamic import for Node.js runtime
18-
nodeCrypto = await import('node:crypto');
23+
// eslint-disable-next-line @typescript-eslint/no-require-imports
24+
nodeCrypto = require('node:crypto');
1925
} catch {
20-
// Not in Node.js environment
26+
// Not in Node.js environment (browser, Deno without compat, etc.)
2127
}
2228

2329
// =============================================================================

0 commit comments

Comments
 (0)