@atbash/sdk 0.17.0-dev.0 → 0.18.0-dev.0
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/LICENSE +202 -28
- package/NOTICE +10 -0
- package/README.md +1 -1
- package/THIRD-PARTY-NOTICES +10256 -0
- package/dist/browser.d.mts +183 -54
- package/dist/browser.mjs +125 -46
- package/dist/index.d.mts +183 -54
- package/dist/index.d.ts +183 -54
- package/dist/index.js +866 -41492
- package/dist/index.mjs +2535 -43189
- package/index.d.ts +19 -0
- package/index.js +61 -54
- package/package.json +10 -8
package/dist/browser.d.mts
CHANGED
|
@@ -136,14 +136,24 @@ interface MemoryScanOptions {
|
|
|
136
136
|
type Network = "public" | "private";
|
|
137
137
|
/**
|
|
138
138
|
* Per-call chain overrides. Pass exactly what you need to override —
|
|
139
|
-
* `network` selects between the SDK's known chains, `blockchainRid`
|
|
140
|
-
*
|
|
141
|
-
* to the SDK's defaults (or to org-resolved
|
|
139
|
+
* `network` selects between the SDK's known chains, `blockchainRid` pins a
|
|
140
|
+
* custom one, and `endpoint` names the Dashboard the calls travel over. Pass
|
|
141
|
+
* none of these to fall back to the SDK's defaults (or to the org-resolved
|
|
142
|
+
* chain when `orgName` is set).
|
|
142
143
|
*/
|
|
143
144
|
interface ChainOpts {
|
|
144
145
|
network?: Network;
|
|
145
146
|
blockchainRid?: string;
|
|
147
|
+
/**
|
|
148
|
+
* No longer dialled: memory reaches the chain through the Dashboard. Kept
|
|
149
|
+
* because callers and the other bindings still carry it as chain config.
|
|
150
|
+
*/
|
|
146
151
|
nodeUrls?: readonly string[];
|
|
152
|
+
/**
|
|
153
|
+
* Dashboard base URL. Memory reaches the chain through it, so this is where
|
|
154
|
+
* those requests go; defaults to the endpoint compiled into the core.
|
|
155
|
+
*/
|
|
156
|
+
endpoint?: string;
|
|
147
157
|
}
|
|
148
158
|
/** Canonical verdict after normalization. */
|
|
149
159
|
type Verdict = "ALLOW" | "HOLD" | "BLOCK" | "No verdict";
|
|
@@ -527,12 +537,6 @@ declare class Atbash {
|
|
|
527
537
|
*/
|
|
528
538
|
private _agentExistsCache;
|
|
529
539
|
private static readonly AGENT_EXISTS_TTL_MS;
|
|
530
|
-
/**
|
|
531
|
-
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
532
|
-
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
533
|
-
* server-side replay protection windows never expire it mid-session.
|
|
534
|
-
*/
|
|
535
|
-
private _authBearers;
|
|
536
540
|
/** Guards `logEnvironmentOnce` — hosts construct several clients. */
|
|
537
541
|
private static environmentLogged;
|
|
538
542
|
constructor(privkey: string, options?: AtbashOptions);
|
|
@@ -555,6 +559,48 @@ declare class Atbash {
|
|
|
555
559
|
* validated against the trusted allowlist / self-hosted policy; a
|
|
556
560
|
* self-hosted endpoint's `verifyPubKey` becomes the client default.
|
|
557
561
|
*/
|
|
562
|
+
/**
|
|
563
|
+
* Decide which key this client signs as.
|
|
564
|
+
*
|
|
565
|
+
* Most specific wins: a key passed in code, then a key file the host named,
|
|
566
|
+
* then the environment, then the default key file. `config.json` is absent
|
|
567
|
+
* from that list on purpose — it is a settings file, writable by anything
|
|
568
|
+
* that can write the user's home and read by every Atbash integration on the
|
|
569
|
+
* machine, so letting it name the key meant one stray value silently
|
|
570
|
+
* re-pointed who each of them signed as.
|
|
571
|
+
*
|
|
572
|
+
* A named `keyPath` that does not exist throws rather than falling through.
|
|
573
|
+
* The caller said which file holds its identity; quietly signing as a
|
|
574
|
+
* different one is the outcome worth refusing.
|
|
575
|
+
*
|
|
576
|
+
* @param options - The `fromConfig` options, read for `agentKey` and `keyPath`.
|
|
577
|
+
* @returns The resolved agent identity.
|
|
578
|
+
* @throws When a named key file is missing, or no identity can be found.
|
|
579
|
+
*/
|
|
580
|
+
private static resolveIdentity;
|
|
581
|
+
/**
|
|
582
|
+
* Add the one thing a machine with no key file needs to hear.
|
|
583
|
+
*
|
|
584
|
+
* This is the only path where the operator cannot see what happened: no key
|
|
585
|
+
* file, and the key they are looking for sits in `config.json`, which no
|
|
586
|
+
* longer selects the identity. A bare "key file not found" sends them hunting
|
|
587
|
+
* for a key they already have. Only this branch gets the hint — a caller who
|
|
588
|
+
* named a `keyPath` is told about that path, where a stranded key is noise.
|
|
589
|
+
*
|
|
590
|
+
* @param err - The "key file not found" error from the default lookup.
|
|
591
|
+
* @returns The same error, or one that also names the key in config.json.
|
|
592
|
+
*/
|
|
593
|
+
private static explainStrandedKey;
|
|
594
|
+
/**
|
|
595
|
+
* Say so when `config.json` still holds an agent key.
|
|
596
|
+
*
|
|
597
|
+
* Nothing signs with it any more, and silence would leave an operator
|
|
598
|
+
* believing one identity is in force while another is. The pubkey is named,
|
|
599
|
+
* not the key, so the line is safe in a log.
|
|
600
|
+
*
|
|
601
|
+
* @param logger - The host logger, when one was supplied.
|
|
602
|
+
*/
|
|
603
|
+
private static warnOnStrandedKey;
|
|
558
604
|
static fromConfig(options?: FromConfigOptions): Atbash;
|
|
559
605
|
get pubkey(): string;
|
|
560
606
|
get privkey(): string;
|
|
@@ -939,22 +985,6 @@ declare const BOOT_SYNC_HINT = "check the chain endpoint and orgName if the caus
|
|
|
939
985
|
*/
|
|
940
986
|
declare function bootSyncFailureLine(cause: unknown): string;
|
|
941
987
|
|
|
942
|
-
/**
|
|
943
|
-
* Make a chain query result crossable at the NAPI boundary.
|
|
944
|
-
*
|
|
945
|
-
* `postchain-client` decodes a Rell `byte_array` into a Node `Buffer`. The
|
|
946
|
-
* core's `parse*` functions take `serde_json::Value`, and NAPI-RS cannot
|
|
947
|
-
* convert a `Buffer` into one — it reaches the methods every `Uint8Array`
|
|
948
|
-
* inherits and fails with "JS functions cannot be represented as a
|
|
949
|
-
* serde_json::Value", which names functions for what is a plain Buffer.
|
|
950
|
-
*
|
|
951
|
-
* The conversion has to happen here because the failure is in the argument
|
|
952
|
-
* conversion, before any core code runs. Of the shapes the core accepts —
|
|
953
|
-
* hex string, `[u8]`, `{ data: [...] }` — hex is the cheapest to produce.
|
|
954
|
-
*/
|
|
955
|
-
/** Recursively rewrite byte containers to hex, leaving everything else as-is. */
|
|
956
|
-
declare function gtvToFfiSafe(value: unknown): unknown;
|
|
957
|
-
|
|
958
988
|
/** Derive the 32-byte AES key from an agent's secp256k1 privkey (hex). Deterministic — same privkey always yields the same key. */
|
|
959
989
|
declare function deriveMemoryKey(privkey: string): Promise<Buffer>;
|
|
960
990
|
/** Encrypt UTF-8 plaintext. `ciphertext` has the 16-byte GCM auth tag appended, matching the SDK's on-chain byte layout. */
|
|
@@ -993,7 +1023,7 @@ interface CommitMemoryOptions {
|
|
|
993
1023
|
filePath?: string;
|
|
994
1024
|
/** Org name — when set, the SDK resolves which chain the agent lives on. */
|
|
995
1025
|
orgName?: string;
|
|
996
|
-
/** Atbash service endpoint
|
|
1026
|
+
/** Atbash service endpoint — where memory reaches the chain, and the org→chain lookup. */
|
|
997
1027
|
endpoint?: string;
|
|
998
1028
|
/** Self-hosted judge response-signing pubkey; required with a non-allowlisted `endpoint`. */
|
|
999
1029
|
verifyPubKey?: string;
|
|
@@ -1001,6 +1031,7 @@ interface CommitMemoryOptions {
|
|
|
1001
1031
|
}
|
|
1002
1032
|
interface RollbackMemoryOptions {
|
|
1003
1033
|
orgName?: string;
|
|
1034
|
+
/** Atbash service endpoint — where memory reaches the chain, and the org→chain lookup. */
|
|
1004
1035
|
endpoint?: string;
|
|
1005
1036
|
/** Self-hosted judge response-signing pubkey; required with a non-allowlisted `endpoint`. */
|
|
1006
1037
|
verifyPubKey?: string;
|
|
@@ -1174,6 +1205,17 @@ interface GuardMemoryWriteInput extends ClassifyMemoryWriteOptions {
|
|
|
1174
1205
|
debug?: boolean;
|
|
1175
1206
|
/** Optional logger for debug probe + persist-failure warnings. */
|
|
1176
1207
|
logger?: GuardLogger;
|
|
1208
|
+
/** Agent home directory names to accept beyond the built-in list. */
|
|
1209
|
+
agentHomeDirs?: string[];
|
|
1210
|
+
/**
|
|
1211
|
+
* Root the caller keeps memory under, when it is not an agent home.
|
|
1212
|
+
*
|
|
1213
|
+
* Only pass a value the host stated outright. A root defaulted from the
|
|
1214
|
+
* process working directory would make whichever directory the host happened
|
|
1215
|
+
* to start in look like a memory store — which is how a stray MEMORY.md once
|
|
1216
|
+
* ended up inside a plugin checkout.
|
|
1217
|
+
*/
|
|
1218
|
+
memoryRoot?: string;
|
|
1177
1219
|
}
|
|
1178
1220
|
/** Plugin-facing decision. Shape mirrors what plugins return from `before_tool_call`. */
|
|
1179
1221
|
interface GuardMemoryDecision {
|
|
@@ -1191,21 +1233,6 @@ interface GuardMemoryWriteResult {
|
|
|
1191
1233
|
/** Present when handled. True only after the chain transaction confirms. */
|
|
1192
1234
|
committed?: boolean;
|
|
1193
1235
|
}
|
|
1194
|
-
/**
|
|
1195
|
-
* Guarded memory-write flow. Returns `{ handled: false }` when the tool
|
|
1196
|
-
* call isn't a memory write, otherwise returns a `decision` the plugin
|
|
1197
|
-
* should return from its hook.
|
|
1198
|
-
*
|
|
1199
|
-
* Verdict handling:
|
|
1200
|
-
* - `red` → not persisted to chain; decision blocks (unless `enforce: false`)
|
|
1201
|
-
* - `yellow` → persisted with its LLM score; decision allows once the chain confirms
|
|
1202
|
-
* - `green` → persisted with its LLM score; decision allows once the chain confirms
|
|
1203
|
-
* - anything else → not persisted; decision blocks (unless `enforce: false`)
|
|
1204
|
-
*
|
|
1205
|
-
* A write is acknowledged only after the chain transaction confirms, for
|
|
1206
|
-
* yellow exactly as for green. An unconfirmed write blocks in enforce mode
|
|
1207
|
-
* and remains unaudited in observe mode.
|
|
1208
|
-
*/
|
|
1209
1236
|
declare function guardMemoryWrite(input: GuardMemoryWriteInput): Promise<GuardMemoryWriteResult>;
|
|
1210
1237
|
|
|
1211
1238
|
/**
|
|
@@ -1269,10 +1296,19 @@ declare class PointerStore {
|
|
|
1269
1296
|
private cache;
|
|
1270
1297
|
private loading;
|
|
1271
1298
|
constructor(filePath: string);
|
|
1272
|
-
/**
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1299
|
+
/**
|
|
1300
|
+
* The pointer for one agent's file, or a zero-pointer forcing a sync.
|
|
1301
|
+
*
|
|
1302
|
+
* @param filePath - The file's chain slot, i.e. its basename.
|
|
1303
|
+
*/
|
|
1304
|
+
get(agentPubkeyHex: string, filePath: string): Promise<MemoryPointer>;
|
|
1305
|
+
/**
|
|
1306
|
+
* Persist one file's pointer, leaving the agent's other files alone.
|
|
1307
|
+
*
|
|
1308
|
+
* Write failures are reported to `onError` rather than thrown: a cache that
|
|
1309
|
+
* cannot be written must not take down the read it was speeding up.
|
|
1310
|
+
*/
|
|
1311
|
+
set(agentPubkeyHex: string, filePath: string, pointer: MemoryPointer, onError?: (err: Error) => void): Promise<void>;
|
|
1276
1312
|
private ensureLoaded;
|
|
1277
1313
|
private loadOnce;
|
|
1278
1314
|
private persist;
|
|
@@ -1367,6 +1403,17 @@ interface MemoryGuardManagerOptions {
|
|
|
1367
1403
|
workspaceDir: string;
|
|
1368
1404
|
/** Absolute MEMORY.md path. Default `<workspaceDir>/MEMORY.md`. */
|
|
1369
1405
|
memoryFilePath?: string;
|
|
1406
|
+
/**
|
|
1407
|
+
* Root this host keeps memory under, when it is not an agent home.
|
|
1408
|
+
*
|
|
1409
|
+
* Only set this from a value the host stated outright — never from
|
|
1410
|
+
* `process.cwd()`. A guessed root makes whichever directory the host started
|
|
1411
|
+
* in look like a memory store, which is how a stray MEMORY.md once ended up
|
|
1412
|
+
* inside a plugin checkout.
|
|
1413
|
+
*/
|
|
1414
|
+
memoryRoot?: string;
|
|
1415
|
+
/** Agent home directory names to accept beyond the built-in list. */
|
|
1416
|
+
agentHomeDirs?: string[];
|
|
1370
1417
|
/** Persistent pointer file. Default `<workspaceDir>/.atbash/memory-pointer.json`. */
|
|
1371
1418
|
pointerFilePath?: string;
|
|
1372
1419
|
/** File-backed log. Default `<workspaceDir>/.atbash/plugin.log`. */
|
|
@@ -1413,6 +1460,10 @@ declare class MemoryGuardManager {
|
|
|
1413
1460
|
private readonly pointerStore;
|
|
1414
1461
|
private readonly logger;
|
|
1415
1462
|
private readonly memoryFilePath;
|
|
1463
|
+
/** Base for resolving the relative paths a host sends. */
|
|
1464
|
+
private readonly workspaceDir;
|
|
1465
|
+
/** Set by `verifyOneFile` when the file it checked was actually on chain. */
|
|
1466
|
+
private lastVerified;
|
|
1416
1467
|
private readonly ttlMs;
|
|
1417
1468
|
private readonly rollbackMinScore;
|
|
1418
1469
|
private readonly enforce;
|
|
@@ -1430,6 +1481,14 @@ declare class MemoryGuardManager {
|
|
|
1430
1481
|
private _resolvedChainOpts;
|
|
1431
1482
|
private _resolveChainInflight?;
|
|
1432
1483
|
constructor(opts: MemoryGuardManagerOptions);
|
|
1484
|
+
/**
|
|
1485
|
+
* Carry this manager's host into `chainOpts`.
|
|
1486
|
+
*
|
|
1487
|
+
* Memory reads reach the chain through that host, and they are handed only
|
|
1488
|
+
* `chainOpts` — without this a self-hosted deployment would read from the
|
|
1489
|
+
* compiled-in default host while writing to its own.
|
|
1490
|
+
*/
|
|
1491
|
+
private withEndpoint;
|
|
1433
1492
|
/**
|
|
1434
1493
|
* Resolve `orgName` → chain once, cache forever. `commitMemoryVersion`
|
|
1435
1494
|
* already does this for writes; without the same call on the read
|
|
@@ -1447,15 +1506,27 @@ declare class MemoryGuardManager {
|
|
|
1447
1506
|
*/
|
|
1448
1507
|
runBootProbe(): Promise<void>;
|
|
1449
1508
|
/**
|
|
1450
|
-
*
|
|
1451
|
-
* Returns `null` for non-memory events, other files this manager does not
|
|
1452
|
-
* own, or unverified observe-mode reads. An enforced read of the managed
|
|
1453
|
-
* file blocks when verification cannot complete.
|
|
1509
|
+
* Bring one chain file into step with its local counterpart.
|
|
1454
1510
|
*
|
|
1455
|
-
*
|
|
1456
|
-
*
|
|
1457
|
-
*
|
|
1511
|
+
* Only a file that already exists locally is touched. Restoring one that is
|
|
1512
|
+
* absent would mean choosing where to create it, and the root is a guess the
|
|
1513
|
+
* moment more than one could apply — the same guess that once wrote a
|
|
1514
|
+
* MEMORY.md into a plugin checkout.
|
|
1515
|
+
*
|
|
1516
|
+
* @returns What happened, for the single summary line the caller logs.
|
|
1458
1517
|
*/
|
|
1518
|
+
private syncOneAtBoot;
|
|
1519
|
+
/**
|
|
1520
|
+
* Where a chain slot's file lives locally, or null when we do not have it.
|
|
1521
|
+
*
|
|
1522
|
+
* A stated root is tried first, then each agent home that actually exists in
|
|
1523
|
+
* the user's home directory — the same rule that produced the slot, run
|
|
1524
|
+
* backwards. Only an existing file is returned: creating one would mean
|
|
1525
|
+
* picking a root, and picking is guessing.
|
|
1526
|
+
*/
|
|
1527
|
+
private locate;
|
|
1528
|
+
/** Roots a chain slot may be joined to, most specific first. */
|
|
1529
|
+
private memoryRoots;
|
|
1459
1530
|
handleBeforeToolCall(event: unknown, ctx: unknown): Promise<HookDecision | null>;
|
|
1460
1531
|
private mapGuardResult;
|
|
1461
1532
|
/**
|
|
@@ -1473,12 +1544,70 @@ declare class MemoryGuardManager {
|
|
|
1473
1544
|
* also covers events carrying two different path keys, where the classifier
|
|
1474
1545
|
* and the host could otherwise disagree about which one is authoritative.
|
|
1475
1546
|
*/
|
|
1476
|
-
|
|
1547
|
+
/**
|
|
1548
|
+
* The memory files this tool call reads, as absolute paths.
|
|
1549
|
+
*
|
|
1550
|
+
* Relative paths resolve against the workspace, not `process.cwd()`. The host
|
|
1551
|
+
* sends paths relative to the agent's workspace; resolving them against the
|
|
1552
|
+
* process's own directory made the guard protect whichever directory the host
|
|
1553
|
+
* happened to start in, which on one machine was a plugin checkout.
|
|
1554
|
+
*
|
|
1555
|
+
* @returns Every named target, de-duplicated; empty when the call names none.
|
|
1556
|
+
*/
|
|
1557
|
+
private readTargets;
|
|
1558
|
+
/**
|
|
1559
|
+
* Say what the read classifier saw and what it concluded.
|
|
1560
|
+
*
|
|
1561
|
+
* The write path has `emitDebugProbe`; this is its counterpart, so a tool
|
|
1562
|
+
* call can be followed across the fork instead of only after it. `false` here
|
|
1563
|
+
* is the normal answer for a write — it means the call goes to the write
|
|
1564
|
+
* classifier next, not that it was ignored.
|
|
1565
|
+
*
|
|
1566
|
+
* @param isMemoryRead - What `classifyMemoryRead` returned.
|
|
1567
|
+
*/
|
|
1568
|
+
private emitReadProbe;
|
|
1569
|
+
/**
|
|
1570
|
+
* The chain slot for a path, or null when the file gets no chain record.
|
|
1571
|
+
*
|
|
1572
|
+
* One helper so the boot probe and every read agree: taking a basename in one
|
|
1573
|
+
* place and a relative path in the other would verify a file against a record
|
|
1574
|
+
* that is not its own.
|
|
1575
|
+
*/
|
|
1576
|
+
private slotFor;
|
|
1577
|
+
/**
|
|
1578
|
+
* Verify every memory file this call reads, each against its own chain slot.
|
|
1579
|
+
*
|
|
1580
|
+
* A call naming several files is only cleared when all of them are, so one
|
|
1581
|
+
* unverifiable file cannot ride along with a verified one.
|
|
1582
|
+
*
|
|
1583
|
+
* @returns A block for the first file that fails, an audited allow when all
|
|
1584
|
+
* were verified, or null when none of them is on chain.
|
|
1585
|
+
*/
|
|
1477
1586
|
private handleMemoryRead;
|
|
1587
|
+
/**
|
|
1588
|
+
* Check one memory file against the chain slot of the same name.
|
|
1589
|
+
*
|
|
1590
|
+
* A file with no chain version is passed through rather than blocked: there
|
|
1591
|
+
* is no claim to protect, so refusing would only stop an agent reading memory
|
|
1592
|
+
* it has never committed. A file that IS on chain must match, or the read is
|
|
1593
|
+
* refused — that is the whole guarantee.
|
|
1594
|
+
*
|
|
1595
|
+
* @returns A decision when the read must not proceed, else null.
|
|
1596
|
+
*/
|
|
1597
|
+
private verifyOneFile;
|
|
1478
1598
|
/** Complete queued audit-log writes before a host shuts down or removes its workspace. */
|
|
1479
1599
|
flushLogs(): Promise<void>;
|
|
1600
|
+
/**
|
|
1601
|
+
* A read this guard could not verify.
|
|
1602
|
+
*
|
|
1603
|
+
* Enforcing, that is a block. Observing, the host audits it as usual — but
|
|
1604
|
+
* the reason is said out loud either way, or an unverified read looks
|
|
1605
|
+
* identical to a clean one in the log.
|
|
1606
|
+
*/
|
|
1480
1607
|
private unverifiedRead;
|
|
1481
1608
|
private writeMemoryAtomic;
|
|
1609
|
+
/** Replace `target` in one step, so a reader never sees a half-written file. */
|
|
1610
|
+
private writeFileAtomic;
|
|
1482
1611
|
}
|
|
1483
1612
|
declare function createMemoryGuardManager(opts: MemoryGuardManagerOptions): MemoryGuardManager;
|
|
1484
1613
|
|
|
@@ -1631,4 +1760,4 @@ declare function containsSecret(text: string): boolean;
|
|
|
1631
1760
|
declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
|
|
1632
1761
|
declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
|
|
1633
1762
|
|
|
1634
|
-
export { type ActionType, type AgentAuth, type AgentLookupOptions, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, BOOT_SYNC_HINT, type ChainConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, EciesDomain, type EncryptedMemory, type Envelope, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, HttpClient, HttpTransportError, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, KEY_FILENAMES, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, PRIVATE_CHAIN, PUBLIC_CHAIN, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, bootSyncFailureLine, buildAllowedJudgeHosts, canonicalAllow, chainForNetwork, chooseKeyPath, claimHashHex, classifyMemoryRead, classifyMemoryWrite, columnAad, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptForOrg, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptForOrg, encryptMemoryContent, encryptedLength, flushTelemetry, generateKeypair, getActiveAgentMemory, getActiveMemoryId, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRecentAgentMemory, getRollbackHistory,
|
|
1763
|
+
export { type ActionType, type AgentAuth, type AgentLookupOptions, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, BOOT_SYNC_HINT, type ChainConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, EciesDomain, type EncryptedMemory, type Envelope, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, HttpClient, HttpTransportError, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, KEY_FILENAMES, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, PRIVATE_CHAIN, PUBLIC_CHAIN, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, bootSyncFailureLine, buildAllowedJudgeHosts, canonicalAllow, chainForNetwork, chooseKeyPath, claimHashHex, classifyMemoryRead, classifyMemoryWrite, columnAad, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptForOrg, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptForOrg, encryptMemoryContent, encryptedLength, flushTelemetry, generateKeypair, getActiveAgentMemory, getActiveMemoryId, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRecentAgentMemory, getRollbackHistory, guardMemoryWrite, isEnvelope, isValidPrivateKey, keyFingerprintOf, keyPathCandidates, loadAgent, loadAgentFromFile, loadUserConfig, normalizeActionForHash, normalizeActionType, normalizeForMatching, normalizeStatus, normalizeVerdict, packEnvelope, parseEnvelope, pubkeyToHex, recordCall, recordDuration, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signEncryptedToolCall, signJudgeAction, signLogToolCall, syncLocalMemory, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };
|
package/dist/browser.mjs
CHANGED
|
@@ -43455,6 +43455,17 @@ var native = {
|
|
|
43455
43455
|
defaultChromiaNodeUrls: () => [...DEFAULT_CHROMIA_NODE_URLS_ARR],
|
|
43456
43456
|
defaultPrivateNodeUrls: () => [...DEFAULT_PRIVATE_NODE_URLS_ARR],
|
|
43457
43457
|
// Server-only surfaces — throw at runtime, keep types satisfied.
|
|
43458
|
+
// The memory signers are here and not with the other signing shims because
|
|
43459
|
+
// their args are encrypted by `encryptMemoryContent`, which this build does
|
|
43460
|
+
// not have: a browser could sign the transaction but never produce one worth
|
|
43461
|
+
// sending.
|
|
43462
|
+
signAddAgentMemory: stub("signAddAgentMemory"),
|
|
43463
|
+
signRollbackAgentMemory: stub("signRollbackAgentMemory"),
|
|
43464
|
+
extractMemoryEdits: stub("extractMemoryEdits"),
|
|
43465
|
+
applyMemoryEdits: stub("applyMemoryEdits"),
|
|
43466
|
+
memorySlotForPath: stub("memorySlotForPath"),
|
|
43467
|
+
isSafeMemorySlot: stub("isSafeMemorySlot"),
|
|
43468
|
+
defaultAgentHomeDirs: stub("defaultAgentHomeDirs"),
|
|
43458
43469
|
classifyMemoryWrite: stub("classifyMemoryWrite"),
|
|
43459
43470
|
classifyMemoryRead: stub("classifyMemoryRead"),
|
|
43460
43471
|
defaultMemoryWriteToolNames: stub("defaultMemoryWriteToolNames"),
|
|
@@ -43531,6 +43542,32 @@ function randomHex(size) {
|
|
|
43531
43542
|
return hex;
|
|
43532
43543
|
}
|
|
43533
43544
|
|
|
43545
|
+
// src-ts/auth-bearer.ts
|
|
43546
|
+
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43547
|
+
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
43548
|
+
var BEARER_TTL_MS = 4 * 60 * 1e3;
|
|
43549
|
+
var bearers = /* @__PURE__ */ new Map();
|
|
43550
|
+
function agentAuthBearer(auth, blockchainRid) {
|
|
43551
|
+
const key3 = `${auth.pubkey}:${blockchainRid}`;
|
|
43552
|
+
const now = Date.now();
|
|
43553
|
+
const cached = bearers.get(key3);
|
|
43554
|
+
if (cached && now - cached.issuedAt < BEARER_TTL_MS) return cached.hex;
|
|
43555
|
+
const hex = native.signLogToolCall(
|
|
43556
|
+
`auth-${now.toString(36)}-${randomHex(4)}`,
|
|
43557
|
+
`auth:${now}`,
|
|
43558
|
+
"",
|
|
43559
|
+
"auth-bearer",
|
|
43560
|
+
"",
|
|
43561
|
+
auth.privkey,
|
|
43562
|
+
blockchainRid
|
|
43563
|
+
);
|
|
43564
|
+
bearers.set(key3, { hex, issuedAt: now });
|
|
43565
|
+
return hex;
|
|
43566
|
+
}
|
|
43567
|
+
function agentAuthHeaders(auth, blockchainRid) {
|
|
43568
|
+
return { Authorization: `Bearer ${agentAuthBearer(auth, blockchainRid)}` };
|
|
43569
|
+
}
|
|
43570
|
+
|
|
43534
43571
|
// src-ts/chain-config.ts
|
|
43535
43572
|
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
43536
43573
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
@@ -44723,6 +44760,12 @@ function resolve(_key, flagValue) {
|
|
|
44723
44760
|
function forcedChainNetwork(flagValue) {
|
|
44724
44761
|
return flagValue === "public" || flagValue === "private" ? flagValue : void 0;
|
|
44725
44762
|
}
|
|
44763
|
+
function agentKeyFromEnv() {
|
|
44764
|
+
return "";
|
|
44765
|
+
}
|
|
44766
|
+
function strandedAgentKey() {
|
|
44767
|
+
return "";
|
|
44768
|
+
}
|
|
44726
44769
|
|
|
44727
44770
|
// src-ts/client.ts
|
|
44728
44771
|
function generateToolCallId() {
|
|
@@ -44806,16 +44849,6 @@ var Atbash = class _Atbash {
|
|
|
44806
44849
|
*/
|
|
44807
44850
|
_agentExistsCache = null;
|
|
44808
44851
|
static AGENT_EXISTS_TTL_MS = 5e3;
|
|
44809
|
-
/**
|
|
44810
|
-
* Cached bearer token for risk-engine / insurance read calls. Built
|
|
44811
|
-
* lazily as a signed `log_tool_call` tx and refreshed every 4 min so
|
|
44812
|
-
* server-side replay protection windows never expire it mid-session.
|
|
44813
|
-
*/
|
|
44814
|
-
// Keyed by blockchainRid so bearers for the public and private chains can
|
|
44815
|
-
// coexist. The dashboard derives `authNetwork` from the BRID inside the
|
|
44816
|
-
// signed envelope, so a bearer signed for chain A cannot authenticate a
|
|
44817
|
-
// request routed to chain B — every chain the client talks to needs its own.
|
|
44818
|
-
_authBearers = /* @__PURE__ */ new Map();
|
|
44819
44852
|
/** Guards `logEnvironmentOnce` — hosts construct several clients. */
|
|
44820
44853
|
static environmentLogged = false;
|
|
44821
44854
|
constructor(privkey, options = {}) {
|
|
@@ -44903,6 +44936,84 @@ var Atbash = class _Atbash {
|
|
|
44903
44936
|
* validated against the trusted allowlist / self-hosted policy; a
|
|
44904
44937
|
* self-hosted endpoint's `verifyPubKey` becomes the client default.
|
|
44905
44938
|
*/
|
|
44939
|
+
/**
|
|
44940
|
+
* Decide which key this client signs as.
|
|
44941
|
+
*
|
|
44942
|
+
* Most specific wins: a key passed in code, then a key file the host named,
|
|
44943
|
+
* then the environment, then the default key file. `config.json` is absent
|
|
44944
|
+
* from that list on purpose — it is a settings file, writable by anything
|
|
44945
|
+
* that can write the user's home and read by every Atbash integration on the
|
|
44946
|
+
* machine, so letting it name the key meant one stray value silently
|
|
44947
|
+
* re-pointed who each of them signed as.
|
|
44948
|
+
*
|
|
44949
|
+
* A named `keyPath` that does not exist throws rather than falling through.
|
|
44950
|
+
* The caller said which file holds its identity; quietly signing as a
|
|
44951
|
+
* different one is the outcome worth refusing.
|
|
44952
|
+
*
|
|
44953
|
+
* @param options - The `fromConfig` options, read for `agentKey` and `keyPath`.
|
|
44954
|
+
* @returns The resolved agent identity.
|
|
44955
|
+
* @throws When a named key file is missing, or no identity can be found.
|
|
44956
|
+
*/
|
|
44957
|
+
static resolveIdentity(options) {
|
|
44958
|
+
if (options.agentKey) return native.loadAgent(options.agentKey);
|
|
44959
|
+
if (options.keyPath) return loadAgentFromFile(options.keyPath);
|
|
44960
|
+
const fromEnv = agentKeyFromEnv();
|
|
44961
|
+
if (fromEnv) return native.loadAgent(fromEnv);
|
|
44962
|
+
try {
|
|
44963
|
+
return loadAgentFromFile();
|
|
44964
|
+
} catch (err) {
|
|
44965
|
+
throw _Atbash.explainStrandedKey(err);
|
|
44966
|
+
}
|
|
44967
|
+
}
|
|
44968
|
+
/**
|
|
44969
|
+
* Add the one thing a machine with no key file needs to hear.
|
|
44970
|
+
*
|
|
44971
|
+
* This is the only path where the operator cannot see what happened: no key
|
|
44972
|
+
* file, and the key they are looking for sits in `config.json`, which no
|
|
44973
|
+
* longer selects the identity. A bare "key file not found" sends them hunting
|
|
44974
|
+
* for a key they already have. Only this branch gets the hint — a caller who
|
|
44975
|
+
* named a `keyPath` is told about that path, where a stranded key is noise.
|
|
44976
|
+
*
|
|
44977
|
+
* @param err - The "key file not found" error from the default lookup.
|
|
44978
|
+
* @returns The same error, or one that also names the key in config.json.
|
|
44979
|
+
*/
|
|
44980
|
+
static explainStrandedKey(err) {
|
|
44981
|
+
const stranded = strandedAgentKey();
|
|
44982
|
+
if (!stranded) return err;
|
|
44983
|
+
let identity;
|
|
44984
|
+
try {
|
|
44985
|
+
identity = native.derivePublicKey(stranded);
|
|
44986
|
+
} catch {
|
|
44987
|
+
identity = "(unreadable)";
|
|
44988
|
+
}
|
|
44989
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
44990
|
+
return new Error(
|
|
44991
|
+
`${message}
|
|
44992
|
+
config.json still holds an "agentKey" (${identity}), but a settings file no longer chooses the signing key. Move it into one of the key files above, or set ATBASH_AGENT_KEY.`
|
|
44993
|
+
);
|
|
44994
|
+
}
|
|
44995
|
+
/**
|
|
44996
|
+
* Say so when `config.json` still holds an agent key.
|
|
44997
|
+
*
|
|
44998
|
+
* Nothing signs with it any more, and silence would leave an operator
|
|
44999
|
+
* believing one identity is in force while another is. The pubkey is named,
|
|
45000
|
+
* not the key, so the line is safe in a log.
|
|
45001
|
+
*
|
|
45002
|
+
* @param logger - The host logger, when one was supplied.
|
|
45003
|
+
*/
|
|
45004
|
+
static warnOnStrandedKey(logger2) {
|
|
45005
|
+
const stranded = strandedAgentKey();
|
|
45006
|
+
if (!stranded) return;
|
|
45007
|
+
let identity;
|
|
45008
|
+
try {
|
|
45009
|
+
identity = native.derivePublicKey(stranded);
|
|
45010
|
+
} catch {
|
|
45011
|
+
identity = "(unreadable)";
|
|
45012
|
+
}
|
|
45013
|
+
logger2?.warn?.(
|
|
45014
|
+
`[atbash] "agentKey" in config.json is ignored \u2014 settings do not choose the signing key. It holds ${identity}; this client signs as the key file or ATBASH_AGENT_KEY instead. Move it into the key file, or delete the field, to silence this.`
|
|
45015
|
+
);
|
|
45016
|
+
}
|
|
44906
45017
|
static fromConfig(options = {}) {
|
|
44907
45018
|
const configuredEndpoint = resolve("judgeEndpoint") || void 0;
|
|
44908
45019
|
const configuredVerifyPubKey = resolve("judgeVerifyPubKey") || void 0;
|
|
@@ -44918,8 +45029,8 @@ var Atbash = class _Atbash {
|
|
|
44918
45029
|
verifyPubKey: configuredVerifyPubKey
|
|
44919
45030
|
} : { endpoint: configuredEndpoint })
|
|
44920
45031
|
);
|
|
44921
|
-
const
|
|
44922
|
-
|
|
45032
|
+
const auth = _Atbash.resolveIdentity(options);
|
|
45033
|
+
_Atbash.warnOnStrandedKey(options.logger);
|
|
44923
45034
|
return new _Atbash(auth.privkey, {
|
|
44924
45035
|
endpoint: validated.url,
|
|
44925
45036
|
chain: options.chain,
|
|
@@ -45699,25 +45810,10 @@ var Atbash = class _Atbash {
|
|
|
45699
45810
|
* trips the server's replay window.
|
|
45700
45811
|
*/
|
|
45701
45812
|
getAuthBearer(brid) {
|
|
45702
|
-
|
|
45703
|
-
const now = Date.now();
|
|
45704
|
-
const cached = this._authBearers.get(chainBrid);
|
|
45705
|
-
if (cached && now - cached.issuedAt < 4 * 60 * 1e3) return cached.hex;
|
|
45706
|
-
const nonce = `auth-${now.toString(36)}-${randomHex(4)}`;
|
|
45707
|
-
const hex = native.signLogToolCall(
|
|
45708
|
-
nonce,
|
|
45709
|
-
`auth:${now}`,
|
|
45710
|
-
"",
|
|
45711
|
-
"auth-bearer",
|
|
45712
|
-
"",
|
|
45713
|
-
this.auth.privkey,
|
|
45714
|
-
chainBrid
|
|
45715
|
-
);
|
|
45716
|
-
this._authBearers.set(chainBrid, { hex, issuedAt: now });
|
|
45717
|
-
return hex;
|
|
45813
|
+
return agentAuthBearer(this.auth, brid ?? this.blockchainRid);
|
|
45718
45814
|
}
|
|
45719
45815
|
authHeaders(brid) {
|
|
45720
|
-
return
|
|
45816
|
+
return agentAuthHeaders(this.auth, brid ?? this.blockchainRid);
|
|
45721
45817
|
}
|
|
45722
45818
|
async riskEngineGet(action, params, brid) {
|
|
45723
45819
|
let resp;
|
|
@@ -46108,22 +46204,6 @@ function bootSyncFailureLine(cause) {
|
|
|
46108
46204
|
);
|
|
46109
46205
|
}
|
|
46110
46206
|
|
|
46111
|
-
// src-ts/memory/_gtv_bytes.ts
|
|
46112
|
-
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46113
|
-
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
46114
|
-
function gtvToFfiSafe(value) {
|
|
46115
|
-
if (value instanceof Uint8Array) return Buffer.from(value).toString("hex");
|
|
46116
|
-
if (Array.isArray(value)) return value.map(gtvToFfiSafe);
|
|
46117
|
-
if (value !== null && typeof value === "object") {
|
|
46118
|
-
const out = {};
|
|
46119
|
-
for (const [key3, val] of Object.entries(value)) {
|
|
46120
|
-
out[key3] = gtvToFfiSafe(val);
|
|
46121
|
-
}
|
|
46122
|
-
return out;
|
|
46123
|
-
}
|
|
46124
|
-
return value;
|
|
46125
|
-
}
|
|
46126
|
-
|
|
46127
46207
|
// src-ts/memory/index.ts
|
|
46128
46208
|
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
46129
46209
|
init_define_ATBASH_PRIVATE_NODE_URLS();
|
|
@@ -46491,7 +46571,6 @@ export {
|
|
|
46491
46571
|
getMemoryHistory,
|
|
46492
46572
|
getRecentAgentMemory,
|
|
46493
46573
|
getRollbackHistory,
|
|
46494
|
-
gtvToFfiSafe,
|
|
46495
46574
|
guardMemoryWrite,
|
|
46496
46575
|
isEnvelope,
|
|
46497
46576
|
isValidPrivateKey2 as isValidPrivateKey,
|