@atbash/sdk 0.12.0-dev.0 → 0.13.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/dist/browser.d.mts +82 -9
- package/dist/browser.mjs +125 -22
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +82 -9
- package/dist/index.d.ts +82 -9
- package/dist/index.js +154 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -23
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +25 -16
- package/index.js +294 -103
- package/package.json +5 -5
package/dist/browser.d.mts
CHANGED
|
@@ -30,6 +30,15 @@ interface ValidatedEndpoint {
|
|
|
30
30
|
declare function buildAllowedJudgeHosts(): ReadonlySet<string>;
|
|
31
31
|
declare function validateJudgeEndpoint(judge?: JudgeEndpointConfig): ValidatedEndpoint;
|
|
32
32
|
|
|
33
|
+
interface ChainConfig {
|
|
34
|
+
readonly network: Network;
|
|
35
|
+
readonly blockchainRid: string;
|
|
36
|
+
readonly nodeUrls: readonly string[];
|
|
37
|
+
}
|
|
38
|
+
declare const PUBLIC_CHAIN: ChainConfig;
|
|
39
|
+
declare const PRIVATE_CHAIN: ChainConfig;
|
|
40
|
+
declare function chainForNetwork(network: Network): ChainConfig;
|
|
41
|
+
|
|
33
42
|
/**
|
|
34
43
|
* User-facing types. Two groups:
|
|
35
44
|
* - Core types — the exact shapes the Rust core emits across the NAPI
|
|
@@ -290,7 +299,24 @@ interface AtbashLogger {
|
|
|
290
299
|
interface AtbashOptions {
|
|
291
300
|
endpoint?: string;
|
|
292
301
|
timeoutMs?: number;
|
|
302
|
+
/**
|
|
303
|
+
* Full chain override — BRID + nodeUrls in one object. Wins over every
|
|
304
|
+
* other chain selector. Prefer this over paired `nodeUrls`/`blockchainRid`
|
|
305
|
+
* for anything but backwards compatibility.
|
|
306
|
+
*/
|
|
307
|
+
chain?: ChainConfig;
|
|
308
|
+
/**
|
|
309
|
+
* Preset chain selector — `"public"` or `"private"`. Resolves to the
|
|
310
|
+
* matching `ChainConfig` via `chainForNetwork()`. Overridden by `chain`,
|
|
311
|
+
* overrides env `ATBASH_DEFAULT_CHAIN_NETWORK` and the config file.
|
|
312
|
+
*/
|
|
313
|
+
network?: Network;
|
|
314
|
+
/**
|
|
315
|
+
* Explicit node URLs. Must be paired with `blockchainRid`. Passing one
|
|
316
|
+
* without the other throws — a BRID/nodes mismatch 404s every request.
|
|
317
|
+
*/
|
|
293
318
|
nodeUrls?: readonly string[];
|
|
319
|
+
/** Explicit BRID. Must be paired with `nodeUrls`. See {@link nodeUrls}. */
|
|
294
320
|
blockchainRid?: string;
|
|
295
321
|
/**
|
|
296
322
|
* Default org name. When set, `judgeAction` / `auditToolCall` resolve
|
|
@@ -357,6 +383,10 @@ interface FromConfigOptions {
|
|
|
357
383
|
keyPath?: string;
|
|
358
384
|
/** Judge endpoint config — validated against the allowlist / self-hosted policy. */
|
|
359
385
|
judge?: JudgeEndpointConfig;
|
|
386
|
+
/** See {@link AtbashOptions.chain}. */
|
|
387
|
+
chain?: ChainConfig;
|
|
388
|
+
/** See {@link AtbashOptions.network}. */
|
|
389
|
+
network?: Network;
|
|
360
390
|
blockchainRid?: string;
|
|
361
391
|
timeoutMs?: number;
|
|
362
392
|
nodeUrls?: readonly string[];
|
|
@@ -408,12 +438,6 @@ interface LogToolCallOptions {
|
|
|
408
438
|
orgEncryptionPubKey?: string;
|
|
409
439
|
}
|
|
410
440
|
|
|
411
|
-
interface ChainConfig {
|
|
412
|
-
readonly network: Network;
|
|
413
|
-
readonly blockchainRid: string;
|
|
414
|
-
readonly nodeUrls: readonly string[];
|
|
415
|
-
}
|
|
416
|
-
|
|
417
441
|
declare class Atbash {
|
|
418
442
|
readonly auth: AgentAuth;
|
|
419
443
|
readonly endpoint: string;
|
|
@@ -437,6 +461,27 @@ declare class Atbash {
|
|
|
437
461
|
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
438
462
|
*/
|
|
439
463
|
private readonly _chainCache;
|
|
464
|
+
/**
|
|
465
|
+
* The chain the constructor settled on. Used only where a lookup returns no
|
|
466
|
+
* answer — see {@link resolveChainFromMap}.
|
|
467
|
+
*/
|
|
468
|
+
private readonly _defaultChain;
|
|
469
|
+
/**
|
|
470
|
+
* True when the caller named a chain outright — `chain`, `network`, or the
|
|
471
|
+
* paired `blockchainRid` + `nodeUrls`.
|
|
472
|
+
*
|
|
473
|
+
* Such a client is never re-pointed: not by the migration switch, and not by
|
|
474
|
+
* where an org turns out to live. Naming a chain is the caller saying "talk
|
|
475
|
+
* to this one", and silently routing elsewhere would make the argument a
|
|
476
|
+
* suggestion. A client that names nothing is the one that follows the org.
|
|
477
|
+
*/
|
|
478
|
+
private readonly _explicitChain;
|
|
479
|
+
/**
|
|
480
|
+
* The fleet-wide chain switch, read once at construction. `resolve()` hits
|
|
481
|
+
* the config file on disk, so re-reading it per call would put a file read
|
|
482
|
+
* on every judge.
|
|
483
|
+
*/
|
|
484
|
+
private readonly _forcedNetwork;
|
|
440
485
|
/**
|
|
441
486
|
* Short-TTL cache for `/api/ai/exists`. The `registered` field is
|
|
442
487
|
* monotonic (once true, stays true), so most calls in a burst re-fetch
|
|
@@ -552,7 +597,9 @@ declare class Atbash {
|
|
|
552
597
|
* 2. Per-chain subscription fallback — public + private records
|
|
553
598
|
* are fetched in parallel, with `is_private_blockchain` and
|
|
554
599
|
* `assigned_at` reconciling mixed states.
|
|
555
|
-
*
|
|
600
|
+
* A lookup that names exactly one chain wins outright. Where it names
|
|
601
|
+
* neither (a brand-new org) or cannot choose between them, the client's
|
|
602
|
+
* configured default decides.
|
|
556
603
|
*/
|
|
557
604
|
resolveChainForOrg(orgName: string): Promise<ChainConfig>;
|
|
558
605
|
/**
|
|
@@ -606,6 +653,25 @@ declare class Atbash {
|
|
|
606
653
|
* back to the client default (best-effort discovery).
|
|
607
654
|
*/
|
|
608
655
|
private bridForOrg;
|
|
656
|
+
/**
|
|
657
|
+
* BRID for the client's configured default org, if it has one.
|
|
658
|
+
*
|
|
659
|
+
* Calls that carry no `orgName` argument are not chain-less: they still
|
|
660
|
+
* belong to `this.orgName`, and that org lives on exactly one chain. Routing
|
|
661
|
+
* them by the constructor's chain instead means a client configured
|
|
662
|
+
* `network: "private"` reads the private chain for an org that lives on
|
|
663
|
+
* public, and gets an empty answer rather than an error. So where an org is
|
|
664
|
+
* known the org decides the chain, and the constructor's chain is what is
|
|
665
|
+
* left when no org is known at all — the order `resolveAgentLookupNetwork`
|
|
666
|
+
* already applies to agent metadata reads, and the order the dashboard
|
|
667
|
+
* applies in `resolveChainForWallet`.
|
|
668
|
+
*
|
|
669
|
+
* Undefined when there is no default org, so callers keep falling back to
|
|
670
|
+
* the client default.
|
|
671
|
+
*/
|
|
672
|
+
/** The switch's chain, unless this client named one of its own. */
|
|
673
|
+
private forcedNetwork;
|
|
674
|
+
private defaultOrgBrid;
|
|
609
675
|
private raiseIfError;
|
|
610
676
|
/** Wrap a failed HTTP *response* (non-2xx / non-200) as an AtbashAPIError. */
|
|
611
677
|
private httpError;
|
|
@@ -695,7 +761,14 @@ interface AtbashUserConfig {
|
|
|
695
761
|
* only way a non-allowlisted judge host is accepted.
|
|
696
762
|
*/
|
|
697
763
|
judgeVerifyPubKey?: string;
|
|
698
|
-
|
|
764
|
+
/**
|
|
765
|
+
* `"private"` pins every org to the private chain regardless of where the
|
|
766
|
+
* dashboard says it lives — the migration switch. Leave it unset for the
|
|
767
|
+
* normal mode, where each org's own chain decides. There is no `"public"`
|
|
768
|
+
* value; a caller that wants one specific chain passes `chain` or `network`
|
|
769
|
+
* at construction instead.
|
|
770
|
+
*/
|
|
771
|
+
defaultChainNetwork?: Network;
|
|
699
772
|
provider?: string;
|
|
700
773
|
providerModel?: string;
|
|
701
774
|
/** "1" / "true" turns on verbose diagnostics. See AtbashOptions.debug. */
|
|
@@ -1398,4 +1471,4 @@ declare function containsSecret(text: string): boolean;
|
|
|
1398
1471
|
declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
|
|
1399
1472
|
declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
|
|
1400
1473
|
|
|
1401
|
-
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 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, 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, 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, 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 };
|
|
1474
|
+
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, 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, 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
|
@@ -43559,6 +43559,9 @@ var PRIVATE_CHAIN = {
|
|
|
43559
43559
|
blockchainRid: DEFAULT_PRIVATE_BLOCKCHAIN_RID,
|
|
43560
43560
|
nodeUrls: DEFAULT_PRIVATE_NODE_URLS
|
|
43561
43561
|
};
|
|
43562
|
+
function chainForNetwork(network) {
|
|
43563
|
+
return network === "private" ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
43564
|
+
}
|
|
43562
43565
|
|
|
43563
43566
|
// src-ts/browser/encrypted-toolcall.ts
|
|
43564
43567
|
init_define_ATBASH_CHROMIA_NODE_URLS();
|
|
@@ -44612,11 +44615,36 @@ function saveUserConfig(_) {
|
|
|
44612
44615
|
function resolve(_key, flagValue) {
|
|
44613
44616
|
return flagValue ?? "";
|
|
44614
44617
|
}
|
|
44618
|
+
function forcedChainNetwork(flagValue) {
|
|
44619
|
+
return flagValue === "public" || flagValue === "private" ? flagValue : void 0;
|
|
44620
|
+
}
|
|
44621
|
+
function warnDeprecatedEnvVarsOnce(_log) {
|
|
44622
|
+
}
|
|
44615
44623
|
|
|
44616
44624
|
// src-ts/client.ts
|
|
44617
44625
|
function generateToolCallId() {
|
|
44618
44626
|
return `tc-${Date.now()}-${randomHex(4)}`;
|
|
44619
44627
|
}
|
|
44628
|
+
function resolveConstructorChain(options) {
|
|
44629
|
+
if (options.chain) return options.chain;
|
|
44630
|
+
const hasNodeUrls = options.nodeUrls !== void 0;
|
|
44631
|
+
const hasBrid = options.blockchainRid !== void 0;
|
|
44632
|
+
if (hasNodeUrls !== hasBrid) {
|
|
44633
|
+
throw new Error(
|
|
44634
|
+
'nodeUrls and blockchainRid must be provided together \u2014 passing one without the other 404s every chain request. Prefer `chain: PUBLIC_CHAIN | PRIVATE_CHAIN` or `network: "public" | "private"`.'
|
|
44635
|
+
);
|
|
44636
|
+
}
|
|
44637
|
+
if (hasNodeUrls && hasBrid) {
|
|
44638
|
+
const brid = options.blockchainRid;
|
|
44639
|
+
const derivedNetwork = options.network ?? (brid === PUBLIC_CHAIN.blockchainRid ? "public" : brid === PRIVATE_CHAIN.blockchainRid ? "private" : "private");
|
|
44640
|
+
return {
|
|
44641
|
+
network: derivedNetwork,
|
|
44642
|
+
blockchainRid: brid,
|
|
44643
|
+
nodeUrls: options.nodeUrls
|
|
44644
|
+
};
|
|
44645
|
+
}
|
|
44646
|
+
return chainForNetwork(options.network ?? forcedChainNetwork() ?? "private");
|
|
44647
|
+
}
|
|
44620
44648
|
var Atbash = class _Atbash {
|
|
44621
44649
|
auth;
|
|
44622
44650
|
endpoint;
|
|
@@ -44640,6 +44668,27 @@ var Atbash = class _Atbash {
|
|
|
44640
44668
|
* calls don't re-hit the dashboard. Cleared by `clearChainCache()`.
|
|
44641
44669
|
*/
|
|
44642
44670
|
_chainCache = /* @__PURE__ */ new Map();
|
|
44671
|
+
/**
|
|
44672
|
+
* The chain the constructor settled on. Used only where a lookup returns no
|
|
44673
|
+
* answer — see {@link resolveChainFromMap}.
|
|
44674
|
+
*/
|
|
44675
|
+
_defaultChain;
|
|
44676
|
+
/**
|
|
44677
|
+
* True when the caller named a chain outright — `chain`, `network`, or the
|
|
44678
|
+
* paired `blockchainRid` + `nodeUrls`.
|
|
44679
|
+
*
|
|
44680
|
+
* Such a client is never re-pointed: not by the migration switch, and not by
|
|
44681
|
+
* where an org turns out to live. Naming a chain is the caller saying "talk
|
|
44682
|
+
* to this one", and silently routing elsewhere would make the argument a
|
|
44683
|
+
* suggestion. A client that names nothing is the one that follows the org.
|
|
44684
|
+
*/
|
|
44685
|
+
_explicitChain;
|
|
44686
|
+
/**
|
|
44687
|
+
* The fleet-wide chain switch, read once at construction. `resolve()` hits
|
|
44688
|
+
* the config file on disk, so re-reading it per call would put a file read
|
|
44689
|
+
* on every judge.
|
|
44690
|
+
*/
|
|
44691
|
+
_forcedNetwork;
|
|
44643
44692
|
/**
|
|
44644
44693
|
* Short-TTL cache for `/api/ai/exists`. The `registered` field is
|
|
44645
44694
|
* monotonic (once true, stays true), so most calls in a burst re-fetch
|
|
@@ -44672,8 +44721,13 @@ var Atbash = class _Atbash {
|
|
|
44672
44721
|
} : { endpoint: options.endpoint }
|
|
44673
44722
|
);
|
|
44674
44723
|
this.endpoint = validated.url;
|
|
44675
|
-
|
|
44676
|
-
this.
|
|
44724
|
+
const resolvedChain = resolveConstructorChain(options);
|
|
44725
|
+
this.nodeUrls = [...resolvedChain.nodeUrls];
|
|
44726
|
+
this.blockchainRid = resolvedChain.blockchainRid;
|
|
44727
|
+
this._defaultChain = resolvedChain;
|
|
44728
|
+
this._explicitChain = options.chain !== void 0 || options.network !== void 0 || options.blockchainRid !== void 0 && options.nodeUrls !== void 0;
|
|
44729
|
+
this._forcedNetwork = forcedChainNetwork();
|
|
44730
|
+
warnDeprecatedEnvVarsOnce((msg) => options.logger?.warn?.(msg));
|
|
44677
44731
|
this.orgName = options.orgName;
|
|
44678
44732
|
this.verifyPubKey = validated.verifyPubKey ?? void 0;
|
|
44679
44733
|
this.orgEncryptionPubKey = options.orgEncryptionPubKey;
|
|
@@ -44749,10 +44803,11 @@ var Atbash = class _Atbash {
|
|
|
44749
44803
|
);
|
|
44750
44804
|
const agentKey = resolve("agentKey", options.agentKey);
|
|
44751
44805
|
const auth = agentKey ? native.loadAgent(agentKey) : loadAgentFromFile(options.keyPath);
|
|
44752
|
-
const blockchainRid = resolve("blockchainRid", options.blockchainRid) || void 0;
|
|
44753
44806
|
return new _Atbash(auth.privkey, {
|
|
44754
44807
|
endpoint: validated.url,
|
|
44755
|
-
|
|
44808
|
+
chain: options.chain,
|
|
44809
|
+
network: options.network,
|
|
44810
|
+
blockchainRid: options.blockchainRid,
|
|
44756
44811
|
timeoutMs: options.timeoutMs,
|
|
44757
44812
|
nodeUrls: options.nodeUrls,
|
|
44758
44813
|
orgName: options.orgName,
|
|
@@ -44793,7 +44848,7 @@ var Atbash = class _Atbash {
|
|
|
44793
44848
|
return this.track("checkAgentExists", pk, async () => {
|
|
44794
44849
|
const query = { pubkey: pk };
|
|
44795
44850
|
if (network) query.network = network;
|
|
44796
|
-
const brid = this.bridFromChainOpts(
|
|
44851
|
+
const brid = network ? this.bridFromChainOpts({ network }) : await this.defaultOrgBrid();
|
|
44797
44852
|
const resp = await this.http.get(
|
|
44798
44853
|
"/api/ai/exists",
|
|
44799
44854
|
query,
|
|
@@ -44844,7 +44899,7 @@ var Atbash = class _Atbash {
|
|
|
44844
44899
|
};
|
|
44845
44900
|
}
|
|
44846
44901
|
const toolCallId = generateToolCallId();
|
|
44847
|
-
const brid = this.bridFromChainOpts(options.chainOpts);
|
|
44902
|
+
const brid = options.chainOpts?.blockchainRid || options.chainOpts?.network ? this.bridFromChainOpts(options.chainOpts) : await this.defaultOrgBrid() ?? this.blockchainRid;
|
|
44848
44903
|
const orgKey = options.orgEncryptionPubKey ?? this.orgEncryptionPubKey ?? this._orgKeyFromChain;
|
|
44849
44904
|
try {
|
|
44850
44905
|
const signedHex = orgKey ? signEncryptedToolCall(
|
|
@@ -44895,7 +44950,11 @@ var Atbash = class _Atbash {
|
|
|
44895
44950
|
throw new Error("action is required and cannot be empty.");
|
|
44896
44951
|
}
|
|
44897
44952
|
let chainOpts = options.chainOpts;
|
|
44898
|
-
if (options.orgName) {
|
|
44953
|
+
if (options.orgName && this._explicitChain) {
|
|
44954
|
+
chainOpts = options.chainOpts ?? { network: this._defaultChain.network };
|
|
44955
|
+
} else if (options.orgName && this.forcedNetwork()) {
|
|
44956
|
+
chainOpts = { network: this.forcedNetwork() };
|
|
44957
|
+
} else if (options.orgName) {
|
|
44899
44958
|
const cached = this._chainCache.get(options.orgName);
|
|
44900
44959
|
if (cached) {
|
|
44901
44960
|
chainOpts = { network: cached.network };
|
|
@@ -45129,7 +45188,7 @@ var Atbash = class _Atbash {
|
|
|
45129
45188
|
const resp = await this.http.get(
|
|
45130
45189
|
"/api/v1/judge",
|
|
45131
45190
|
{ tool_call_id: judgmentId, agent_pubkey: pk },
|
|
45132
|
-
this.authHeaders()
|
|
45191
|
+
this.authHeaders(await this.defaultOrgBrid())
|
|
45133
45192
|
);
|
|
45134
45193
|
await this.raiseIfError(resp);
|
|
45135
45194
|
const data = await this.json(resp) ?? {};
|
|
@@ -45149,7 +45208,11 @@ var Atbash = class _Atbash {
|
|
|
45149
45208
|
return this.track(
|
|
45150
45209
|
"getToolCalls",
|
|
45151
45210
|
void 0,
|
|
45152
|
-
() => this.riskEngineRecords(
|
|
45211
|
+
async () => this.riskEngineRecords(
|
|
45212
|
+
"tool-calls",
|
|
45213
|
+
{ limit: maxCount },
|
|
45214
|
+
await this.defaultOrgBrid()
|
|
45215
|
+
)
|
|
45153
45216
|
);
|
|
45154
45217
|
}
|
|
45155
45218
|
async getOrgToolCalls(orgName, maxCount) {
|
|
@@ -45166,24 +45229,31 @@ var Atbash = class _Atbash {
|
|
|
45166
45229
|
return this.track(
|
|
45167
45230
|
"getAgentToolCalls",
|
|
45168
45231
|
agentPubkey,
|
|
45169
|
-
() => this.riskEngineRecords(
|
|
45170
|
-
agent
|
|
45171
|
-
limit: maxCount
|
|
45172
|
-
|
|
45232
|
+
async () => this.riskEngineRecords(
|
|
45233
|
+
"agent-tool-calls",
|
|
45234
|
+
{ agent: agentPubkey, limit: maxCount },
|
|
45235
|
+
await this.defaultOrgBrid()
|
|
45236
|
+
)
|
|
45173
45237
|
);
|
|
45174
45238
|
}
|
|
45175
45239
|
async getToolCallCount() {
|
|
45176
45240
|
return this.track("getToolCallCount", void 0, async () => {
|
|
45177
|
-
const raw2 = await this.riskEngineGet(
|
|
45241
|
+
const raw2 = await this.riskEngineGet(
|
|
45242
|
+
"tool-call-count",
|
|
45243
|
+
{},
|
|
45244
|
+
await this.defaultOrgBrid()
|
|
45245
|
+
);
|
|
45178
45246
|
const n = Number(raw2);
|
|
45179
45247
|
return Number.isFinite(n) ? n : 0;
|
|
45180
45248
|
});
|
|
45181
45249
|
}
|
|
45182
45250
|
async getToolCallFull(toolCallId) {
|
|
45183
45251
|
return this.track("getToolCallFull", void 0, async () => {
|
|
45184
|
-
const raw2 = await this.riskEngineGet(
|
|
45185
|
-
|
|
45186
|
-
|
|
45252
|
+
const raw2 = await this.riskEngineGet(
|
|
45253
|
+
"tool-call-full",
|
|
45254
|
+
{ tool_call_id: toolCallId },
|
|
45255
|
+
await this.defaultOrgBrid()
|
|
45256
|
+
);
|
|
45187
45257
|
if (!isRecord(raw2)) return null;
|
|
45188
45258
|
return toToolCallFull(raw2);
|
|
45189
45259
|
});
|
|
@@ -45269,7 +45339,7 @@ var Atbash = class _Atbash {
|
|
|
45269
45339
|
const resp = await this.http.get(
|
|
45270
45340
|
"/api/insurance",
|
|
45271
45341
|
{ action: "safety-stats" },
|
|
45272
|
-
this.authHeaders()
|
|
45342
|
+
this.authHeaders(await this.defaultOrgBrid())
|
|
45273
45343
|
);
|
|
45274
45344
|
await this.raiseIfError(resp);
|
|
45275
45345
|
const data = await this.json(resp) ?? {};
|
|
@@ -45325,10 +45395,15 @@ var Atbash = class _Atbash {
|
|
|
45325
45395
|
* 2. Per-chain subscription fallback — public + private records
|
|
45326
45396
|
* are fetched in parallel, with `is_private_blockchain` and
|
|
45327
45397
|
* `assigned_at` reconciling mixed states.
|
|
45328
|
-
*
|
|
45398
|
+
* A lookup that names exactly one chain wins outright. Where it names
|
|
45399
|
+
* neither (a brand-new org) or cannot choose between them, the client's
|
|
45400
|
+
* configured default decides.
|
|
45329
45401
|
*/
|
|
45330
45402
|
async resolveChainForOrg(orgName) {
|
|
45331
45403
|
const name2 = orgName.trim();
|
|
45404
|
+
if (this._explicitChain) return this._defaultChain;
|
|
45405
|
+
const forced = this.forcedNetwork();
|
|
45406
|
+
if (forced) return chainForNetwork(forced);
|
|
45332
45407
|
const cached = this._chainCache.get(name2);
|
|
45333
45408
|
if (cached) return cached;
|
|
45334
45409
|
const mapNetwork = await this.getActiveNetworkForOrg(name2);
|
|
@@ -45360,7 +45435,7 @@ var Atbash = class _Atbash {
|
|
|
45360
45435
|
return PRIVATE_CHAIN;
|
|
45361
45436
|
}
|
|
45362
45437
|
if (pubSub && privSub) {
|
|
45363
|
-
const chain = privSub.assigned_at > pubSub.assigned_at ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
45438
|
+
const chain = privSub.assigned_at === pubSub.assigned_at ? this._defaultChain : privSub.assigned_at > pubSub.assigned_at ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
45364
45439
|
this._chainCache.set(orgName, chain);
|
|
45365
45440
|
return chain;
|
|
45366
45441
|
}
|
|
@@ -45381,8 +45456,8 @@ var Atbash = class _Atbash {
|
|
|
45381
45456
|
this.endpoint
|
|
45382
45457
|
);
|
|
45383
45458
|
}
|
|
45384
|
-
this._chainCache.set(orgName,
|
|
45385
|
-
return
|
|
45459
|
+
this._chainCache.set(orgName, this._defaultChain);
|
|
45460
|
+
return this._defaultChain;
|
|
45386
45461
|
}
|
|
45387
45462
|
/** Drop any cached chain resolutions. Useful in tests. */
|
|
45388
45463
|
clearChainCache() {
|
|
@@ -45433,6 +45508,7 @@ var Atbash = class _Atbash {
|
|
|
45433
45508
|
async resolveAgentLookupNetwork(options) {
|
|
45434
45509
|
if (options.chainOpts?.network) return options.chainOpts.network;
|
|
45435
45510
|
if (options.chainOpts?.blockchainRid) return void 0;
|
|
45511
|
+
if (this._explicitChain) return this._defaultChain.network;
|
|
45436
45512
|
const orgName = options.orgName ?? this.orgName;
|
|
45437
45513
|
if (!orgName) return void 0;
|
|
45438
45514
|
return (await this.resolveChainForOrg(orgName)).network;
|
|
@@ -45508,6 +45584,30 @@ var Atbash = class _Atbash {
|
|
|
45508
45584
|
return void 0;
|
|
45509
45585
|
}
|
|
45510
45586
|
}
|
|
45587
|
+
/**
|
|
45588
|
+
* BRID for the client's configured default org, if it has one.
|
|
45589
|
+
*
|
|
45590
|
+
* Calls that carry no `orgName` argument are not chain-less: they still
|
|
45591
|
+
* belong to `this.orgName`, and that org lives on exactly one chain. Routing
|
|
45592
|
+
* them by the constructor's chain instead means a client configured
|
|
45593
|
+
* `network: "private"` reads the private chain for an org that lives on
|
|
45594
|
+
* public, and gets an empty answer rather than an error. So where an org is
|
|
45595
|
+
* known the org decides the chain, and the constructor's chain is what is
|
|
45596
|
+
* left when no org is known at all — the order `resolveAgentLookupNetwork`
|
|
45597
|
+
* already applies to agent metadata reads, and the order the dashboard
|
|
45598
|
+
* applies in `resolveChainForWallet`.
|
|
45599
|
+
*
|
|
45600
|
+
* Undefined when there is no default org, so callers keep falling back to
|
|
45601
|
+
* the client default.
|
|
45602
|
+
*/
|
|
45603
|
+
/** The switch's chain, unless this client named one of its own. */
|
|
45604
|
+
forcedNetwork() {
|
|
45605
|
+
return this._explicitChain ? void 0 : this._forcedNetwork;
|
|
45606
|
+
}
|
|
45607
|
+
async defaultOrgBrid() {
|
|
45608
|
+
if (this._explicitChain || !this.orgName) return void 0;
|
|
45609
|
+
return this.bridForOrg(this.orgName);
|
|
45610
|
+
}
|
|
45511
45611
|
async raiseIfError(resp) {
|
|
45512
45612
|
if (resp.ok) return;
|
|
45513
45613
|
throw await this.httpError(resp);
|
|
@@ -46200,10 +46300,13 @@ export {
|
|
|
46200
46300
|
KEY_FILENAMES,
|
|
46201
46301
|
MemoryGuardManager,
|
|
46202
46302
|
MemoryIntegrityError,
|
|
46303
|
+
PRIVATE_CHAIN,
|
|
46304
|
+
PUBLIC_CHAIN,
|
|
46203
46305
|
PointerStore,
|
|
46204
46306
|
SignatureVerificationError,
|
|
46205
46307
|
bootSyncFailureLine,
|
|
46206
46308
|
buildAllowedJudgeHosts,
|
|
46309
|
+
chainForNetwork,
|
|
46207
46310
|
chooseKeyPath,
|
|
46208
46311
|
claimHashHex,
|
|
46209
46312
|
classifyMemoryRead,
|