@atbash/sdk 0.3.11-dev.11 → 0.3.11-dev.13
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/index.cjs +98 -26
- package/dist/index.d.cts +18 -6
- package/dist/index.d.ts +18 -6
- package/dist/index.js +97 -26
- package/package.json +2 -3
package/dist/index.cjs
CHANGED
|
@@ -61,6 +61,7 @@ __export(index_exports, {
|
|
|
61
61
|
loadUserConfig: () => loadUserConfig,
|
|
62
62
|
normalizeForMatching: () => normalizeForMatching,
|
|
63
63
|
resolve: () => resolve,
|
|
64
|
+
resolveChainForOrg: () => resolveChainForOrg,
|
|
64
65
|
resolveKeyPath: () => resolveKeyPath,
|
|
65
66
|
saveUserConfig: () => saveUserConfig,
|
|
66
67
|
scanMemory: () => scanMemory,
|
|
@@ -192,11 +193,11 @@ async function shutdownTelemetry() {
|
|
|
192
193
|
var { createClient, encryption: encryption2, newSignatureProvider } = import_postchain_client2.default;
|
|
193
194
|
var DEFAULT_ENDPOINT = "https://chromia-verified-ai-dev-two.vercel.app";
|
|
194
195
|
var DEFAULT_CHROMIA_NODE_URLS = [
|
|
195
|
-
"https://
|
|
196
|
-
"https://
|
|
197
|
-
"https://
|
|
196
|
+
"https://node6.testnet.chromia.com:7740",
|
|
197
|
+
"https://node7.testnet.chromia.com:7740",
|
|
198
|
+
"https://node8.testnet.chromia.com:7740"
|
|
198
199
|
];
|
|
199
|
-
var DEFAULT_BLOCKCHAIN_RID = "
|
|
200
|
+
var DEFAULT_BLOCKCHAIN_RID = "72552FA964345BBA3748244B2D3F0C4A5C766EDFD2BAFA3B8A43F15BE7A59C5A";
|
|
200
201
|
var DEFAULT_PRIVATE_NODE_URLS = [
|
|
201
202
|
"https://node0-pvn-testnet.dynamic.chromia.dev"
|
|
202
203
|
];
|
|
@@ -305,7 +306,7 @@ async function buildSignedTx(opName, args, auth, chainOpts) {
|
|
|
305
306
|
);
|
|
306
307
|
return Buffer.from(signed).toString("hex");
|
|
307
308
|
}
|
|
308
|
-
async function
|
|
309
|
+
async function _checkAgentExists(pubkey, opts, chainOpts) {
|
|
309
310
|
const start = performance.now();
|
|
310
311
|
recordCall("checkAgentExists", void 0, pubkey);
|
|
311
312
|
try {
|
|
@@ -320,13 +321,13 @@ async function checkAgentExistsInternal(pubkey, opts, chainOpts) {
|
|
|
320
321
|
throw err;
|
|
321
322
|
}
|
|
322
323
|
}
|
|
323
|
-
async function checkAgentExists(pubkey, opts) {
|
|
324
|
-
return
|
|
324
|
+
async function checkAgentExists(pubkey, opts, chainOpts) {
|
|
325
|
+
return _checkAgentExists(pubkey, opts, chainOpts);
|
|
325
326
|
}
|
|
326
327
|
async function logToolCall(action, context, auth, chainOpts, extra, clientOpts) {
|
|
327
328
|
const start = performance.now();
|
|
328
329
|
recordCall("logToolCall", void 0, auth.pubkey);
|
|
329
|
-
const exists = await
|
|
330
|
+
const exists = await _checkAgentExists(auth.pubkey, clientOpts, chainOpts);
|
|
330
331
|
if (!exists) {
|
|
331
332
|
recordDuration("logToolCall", performance.now() - start, "error");
|
|
332
333
|
return {
|
|
@@ -395,7 +396,9 @@ function enrichError(status, body, statusText, opts) {
|
|
|
395
396
|
return new Error(message);
|
|
396
397
|
}
|
|
397
398
|
async function postJson(url, body, opts) {
|
|
398
|
-
const headers = {
|
|
399
|
+
const headers = {
|
|
400
|
+
"Content-Type": "application/json"
|
|
401
|
+
};
|
|
399
402
|
if (opts?.auth) {
|
|
400
403
|
headers["Authorization"] = `Bearer ${await getOrCreateAuthBearer(opts.auth)}`;
|
|
401
404
|
}
|
|
@@ -461,9 +464,14 @@ async function judgeAction(action, context = "", auth, opts) {
|
|
|
461
464
|
}
|
|
462
465
|
try {
|
|
463
466
|
let chainOpts = opts?.chainOpts;
|
|
464
|
-
if (opts?.orgName
|
|
465
|
-
const
|
|
466
|
-
|
|
467
|
+
if (opts?.orgName) {
|
|
468
|
+
const mapNetwork = await getActiveNetworkForOrg(opts.orgName, opts);
|
|
469
|
+
if (mapNetwork) {
|
|
470
|
+
chainOpts = { network: mapNetwork };
|
|
471
|
+
} else if (!chainOpts?.blockchainRid) {
|
|
472
|
+
const resolved = await resolveChainForOrg(opts.orgName, opts);
|
|
473
|
+
chainOpts = { ...chainOpts, network: resolved.network };
|
|
474
|
+
}
|
|
467
475
|
}
|
|
468
476
|
const logResult = await logToolCall(
|
|
469
477
|
action,
|
|
@@ -492,7 +500,9 @@ async function judgeAction(action, context = "", auth, opts) {
|
|
|
492
500
|
agent_pubkey: auth.pubkey,
|
|
493
501
|
action,
|
|
494
502
|
signed_log_tool_call: logResult.signedHex,
|
|
495
|
-
...signedJudgeActionHex && {
|
|
503
|
+
...signedJudgeActionHex && {
|
|
504
|
+
signed_judge_action: signedJudgeActionHex
|
|
505
|
+
},
|
|
496
506
|
...context && { context },
|
|
497
507
|
...opts?.provider && { provider: opts.provider },
|
|
498
508
|
...opts?.toolName && { tool_name: opts.toolName },
|
|
@@ -537,9 +547,10 @@ async function getJudgmentStatus(judgmentId, agentPubkey, opts) {
|
|
|
537
547
|
throw err;
|
|
538
548
|
}
|
|
539
549
|
}
|
|
540
|
-
function riskEngineUrl(action, params, opts) {
|
|
550
|
+
function riskEngineUrl(action, params, opts, network) {
|
|
541
551
|
const url = new URL(`${baseUrl(opts)}/api/risk-engine`);
|
|
542
552
|
url.searchParams.set("action", action);
|
|
553
|
+
if (network) url.searchParams.set("network", network);
|
|
543
554
|
for (const [k, v] of Object.entries(params)) {
|
|
544
555
|
if (v) url.searchParams.set(k, v);
|
|
545
556
|
}
|
|
@@ -644,12 +655,14 @@ function coerceOrgSubscription(row, orgName) {
|
|
|
644
655
|
is_active: Boolean(r.is_active)
|
|
645
656
|
};
|
|
646
657
|
}
|
|
647
|
-
async function getOrgSubscription(orgName, opts) {
|
|
658
|
+
async function getOrgSubscription(orgName, opts, network) {
|
|
648
659
|
const start = performance.now();
|
|
649
660
|
recordCall("getOrgSubscription");
|
|
650
661
|
try {
|
|
662
|
+
const params = { org: orgName };
|
|
663
|
+
if (network) params.network = network;
|
|
651
664
|
const result = await getJson(
|
|
652
|
-
riskEngineUrl("org-subscription",
|
|
665
|
+
riskEngineUrl("org-subscription", params, opts),
|
|
653
666
|
opts
|
|
654
667
|
);
|
|
655
668
|
recordDuration("getOrgSubscription", performance.now() - start, "success");
|
|
@@ -659,13 +672,47 @@ async function getOrgSubscription(orgName, opts) {
|
|
|
659
672
|
throw err;
|
|
660
673
|
}
|
|
661
674
|
}
|
|
675
|
+
async function getActiveNetworkForOrg(orgName, opts) {
|
|
676
|
+
try {
|
|
677
|
+
const url = `${baseUrl(opts)}/api/org-network?org=${encodeURIComponent(orgName)}`;
|
|
678
|
+
const data = await getJson(url, opts);
|
|
679
|
+
if (data?.network === "public" || data?.network === "private") {
|
|
680
|
+
return data.network;
|
|
681
|
+
}
|
|
682
|
+
return null;
|
|
683
|
+
} catch {
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
662
687
|
var _chainCache = /* @__PURE__ */ new Map();
|
|
663
688
|
async function resolveChainForOrg(orgName, opts) {
|
|
664
689
|
const cached = _chainCache.get(orgName);
|
|
665
690
|
if (cached) return cached;
|
|
691
|
+
const mapNetwork = await getActiveNetworkForOrg(orgName, opts);
|
|
692
|
+
if (mapNetwork) {
|
|
693
|
+
const chain = mapNetwork === "private" ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
694
|
+
_chainCache.set(orgName, chain);
|
|
695
|
+
return chain;
|
|
696
|
+
}
|
|
666
697
|
try {
|
|
667
|
-
const
|
|
668
|
-
|
|
698
|
+
const [pubSub, privSub] = await Promise.all([
|
|
699
|
+
getOrgSubscription(orgName, opts, "public").catch(() => null),
|
|
700
|
+
getOrgSubscription(orgName, opts, "private").catch(() => null)
|
|
701
|
+
]);
|
|
702
|
+
if (pubSub?.is_private_blockchain) {
|
|
703
|
+
_chainCache.set(orgName, PRIVATE_CHAIN);
|
|
704
|
+
return PRIVATE_CHAIN;
|
|
705
|
+
}
|
|
706
|
+
if (pubSub && privSub) {
|
|
707
|
+
const chain = privSub.assigned_at > pubSub.assigned_at ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
708
|
+
_chainCache.set(orgName, chain);
|
|
709
|
+
return chain;
|
|
710
|
+
}
|
|
711
|
+
if (pubSub) {
|
|
712
|
+
_chainCache.set(orgName, PUBLIC_CHAIN);
|
|
713
|
+
return PUBLIC_CHAIN;
|
|
714
|
+
}
|
|
715
|
+
if (privSub?.is_private_blockchain) {
|
|
669
716
|
_chainCache.set(orgName, PRIVATE_CHAIN);
|
|
670
717
|
return PRIVATE_CHAIN;
|
|
671
718
|
}
|
|
@@ -686,7 +733,11 @@ async function getPendingHeldActions(orgName, maxCount, opts) {
|
|
|
686
733
|
),
|
|
687
734
|
opts
|
|
688
735
|
);
|
|
689
|
-
recordDuration(
|
|
736
|
+
recordDuration(
|
|
737
|
+
"getPendingHeldActions",
|
|
738
|
+
performance.now() - start,
|
|
739
|
+
"success"
|
|
740
|
+
);
|
|
690
741
|
return raw.map((h) => ({ ...h, verdict: normalizeVerdict(h.verdict) }));
|
|
691
742
|
} catch (err) {
|
|
692
743
|
recordDuration("getPendingHeldActions", performance.now() - start, "error");
|
|
@@ -705,22 +756,36 @@ async function getHeldActionReviews(orgName, maxCount, opts) {
|
|
|
705
756
|
),
|
|
706
757
|
opts
|
|
707
758
|
);
|
|
708
|
-
recordDuration(
|
|
759
|
+
recordDuration(
|
|
760
|
+
"getHeldActionReviews",
|
|
761
|
+
performance.now() - start,
|
|
762
|
+
"success"
|
|
763
|
+
);
|
|
709
764
|
return result;
|
|
710
765
|
} catch (err) {
|
|
711
766
|
recordDuration("getHeldActionReviews", performance.now() - start, "error");
|
|
712
767
|
throw err;
|
|
713
768
|
}
|
|
714
769
|
}
|
|
715
|
-
function riskEnginePostUrl(opts) {
|
|
716
|
-
|
|
770
|
+
function riskEnginePostUrl(opts, network) {
|
|
771
|
+
let url = `${baseUrl(opts)}/api/risk-engine`;
|
|
772
|
+
if (network) {
|
|
773
|
+
url += `?network=${encodeURIComponent(network)}`;
|
|
774
|
+
}
|
|
775
|
+
return url;
|
|
717
776
|
}
|
|
718
|
-
async function getAgentDetail(agentPubkey, opts) {
|
|
777
|
+
async function getAgentDetail(agentPubkey, opts, chainOpts) {
|
|
719
778
|
const start = performance.now();
|
|
720
779
|
recordCall("getAgentDetail", void 0, agentPubkey);
|
|
721
780
|
try {
|
|
781
|
+
let resolvedChainOpts = chainOpts;
|
|
782
|
+
if (opts?.orgName && !resolvedChainOpts?.blockchainRid) {
|
|
783
|
+
const resolved = await resolveChainForOrg(opts.orgName, opts);
|
|
784
|
+
resolvedChainOpts = { ...resolvedChainOpts, network: resolved.network };
|
|
785
|
+
}
|
|
786
|
+
const network = resolvedChainOpts?.network;
|
|
722
787
|
const result = await postJson(
|
|
723
|
-
riskEnginePostUrl(opts),
|
|
788
|
+
riskEnginePostUrl(opts, network),
|
|
724
789
|
{ action: "agent-detail-batch", agent: agentPubkey },
|
|
725
790
|
opts
|
|
726
791
|
);
|
|
@@ -731,12 +796,18 @@ async function getAgentDetail(agentPubkey, opts) {
|
|
|
731
796
|
throw err;
|
|
732
797
|
}
|
|
733
798
|
}
|
|
734
|
-
async function getAgentPolicy(agentPubkey, opts) {
|
|
799
|
+
async function getAgentPolicy(agentPubkey, opts, chainOpts) {
|
|
735
800
|
const start = performance.now();
|
|
736
801
|
recordCall("getAgentPolicy", void 0, agentPubkey);
|
|
737
802
|
try {
|
|
803
|
+
let resolvedChainOpts = chainOpts;
|
|
804
|
+
if (opts?.orgName && !resolvedChainOpts?.blockchainRid) {
|
|
805
|
+
const resolved = await resolveChainForOrg(opts.orgName, opts);
|
|
806
|
+
resolvedChainOpts = { ...resolvedChainOpts, network: resolved.network };
|
|
807
|
+
}
|
|
808
|
+
const network = resolvedChainOpts?.network;
|
|
738
809
|
const result = await postJson(
|
|
739
|
-
riskEnginePostUrl(opts),
|
|
810
|
+
riskEnginePostUrl(opts, network),
|
|
740
811
|
{ action: "agent-policy-batch", agent: agentPubkey },
|
|
741
812
|
opts
|
|
742
813
|
);
|
|
@@ -1604,6 +1675,7 @@ function deduplicateAnomalies(anomalies) {
|
|
|
1604
1675
|
loadUserConfig,
|
|
1605
1676
|
normalizeForMatching,
|
|
1606
1677
|
resolve,
|
|
1678
|
+
resolveChainForOrg,
|
|
1607
1679
|
resolveKeyPath,
|
|
1608
1680
|
saveUserConfig,
|
|
1609
1681
|
scanMemory,
|
package/dist/index.d.cts
CHANGED
|
@@ -5,6 +5,12 @@ type PubkeyValue = string | Buffer | {
|
|
|
5
5
|
data: number[];
|
|
6
6
|
};
|
|
7
7
|
type JudgmentStatusState = "pending" | "answered" | "error";
|
|
8
|
+
type Network = "public" | "private";
|
|
9
|
+
interface ChainConfig {
|
|
10
|
+
network: Network;
|
|
11
|
+
blockchainRid: string;
|
|
12
|
+
nodeUrls: string[];
|
|
13
|
+
}
|
|
8
14
|
interface Subscription {
|
|
9
15
|
subscription_name: string;
|
|
10
16
|
agent_number: number;
|
|
@@ -31,6 +37,7 @@ interface ClientOpts {
|
|
|
31
37
|
interface ChainOpts {
|
|
32
38
|
nodeUrls?: string[];
|
|
33
39
|
blockchainRid?: string;
|
|
40
|
+
network?: Network;
|
|
34
41
|
}
|
|
35
42
|
interface JudgeResult {
|
|
36
43
|
verdict: Verdict;
|
|
@@ -197,7 +204,7 @@ interface AtbashClientConfig {
|
|
|
197
204
|
|
|
198
205
|
declare const DEFAULT_ENDPOINT = "https://chromia-verified-ai-dev-two.vercel.app";
|
|
199
206
|
declare const DEFAULT_CHROMIA_NODE_URLS: string[];
|
|
200
|
-
declare const DEFAULT_BLOCKCHAIN_RID = "
|
|
207
|
+
declare const DEFAULT_BLOCKCHAIN_RID = "72552FA964345BBA3748244B2D3F0C4A5C766EDFD2BAFA3B8A43F15BE7A59C5A";
|
|
201
208
|
declare function isValidPrivateKey(hex: string): boolean;
|
|
202
209
|
declare function derivePublicKey(privKeyHex: string): string;
|
|
203
210
|
declare function generateKeyPair(): {
|
|
@@ -206,7 +213,7 @@ declare function generateKeyPair(): {
|
|
|
206
213
|
};
|
|
207
214
|
declare function loadAgent(privkey: string): AgentAuth;
|
|
208
215
|
declare function toPubkeyHex(val: unknown): string;
|
|
209
|
-
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
216
|
+
declare function checkAgentExists(pubkey: string, opts?: ClientOpts, chainOpts?: ChainOpts): Promise<boolean>;
|
|
210
217
|
declare function judgeAction(action: string, context: string | undefined, auth: AgentAuth, opts?: JudgeOptions): Promise<JudgeResult>;
|
|
211
218
|
declare function getJudgmentStatus(judgmentId: string, agentPubkey: string, opts?: ClientOpts): Promise<JudgmentStatus>;
|
|
212
219
|
declare function getToolCalls(maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
@@ -214,11 +221,16 @@ declare function getOrgToolCalls(orgName: string, maxCount: number, opts?: Clien
|
|
|
214
221
|
declare function getAgentToolCalls(agentPubkey: string, maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
215
222
|
declare function getToolCallCount(opts?: ClientOpts): Promise<number>;
|
|
216
223
|
declare function getToolCallFull(toolCallId: string, opts?: ClientOpts): Promise<ToolCallFull | null>;
|
|
217
|
-
declare function getOrgSubscription(orgName: string, opts?: ClientOpts): Promise<OrgSubscription | null>;
|
|
224
|
+
declare function getOrgSubscription(orgName: string, opts?: ClientOpts, network?: Network): Promise<OrgSubscription | null>;
|
|
225
|
+
declare function resolveChainForOrg(orgName: string, opts?: ClientOpts): Promise<ChainConfig>;
|
|
218
226
|
declare function getPendingHeldActions(orgName: string, maxCount: number, opts?: ClientOpts): Promise<HeldAction[]>;
|
|
219
227
|
declare function getHeldActionReviews(orgName: string, maxCount: number, opts?: ClientOpts): Promise<HeldActionReview[]>;
|
|
220
|
-
declare function getAgentDetail(agentPubkey: string, opts?: ClientOpts
|
|
221
|
-
|
|
228
|
+
declare function getAgentDetail(agentPubkey: string, opts?: ClientOpts & {
|
|
229
|
+
orgName?: string;
|
|
230
|
+
}, chainOpts?: ChainOpts): Promise<Record<string, unknown>>;
|
|
231
|
+
declare function getAgentPolicy(agentPubkey: string, opts?: ClientOpts & {
|
|
232
|
+
orgName?: string;
|
|
233
|
+
}, chainOpts?: ChainOpts): Promise<AgentPolicy>;
|
|
222
234
|
declare function getSafetyStats(opts?: ClientOpts): Promise<Record<string, unknown>>;
|
|
223
235
|
|
|
224
236
|
interface AtbashClient {
|
|
@@ -336,4 +348,4 @@ declare function normalizeForMatching(input: string): string;
|
|
|
336
348
|
*/
|
|
337
349
|
declare function containsEvasionCharacters(input: string): boolean;
|
|
338
350
|
|
|
339
|
-
export { type ActionType, type AgentAuth, type AgentPolicy, type AnomalySeverity, type AnomalyType, type AtbashClient, type AtbashClientConfig, type AtbashUserConfig, type ClientOpts, type ClientSource, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, type Decision, type DecisionVerdict, type HeldAction, type HeldActionReview, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentStatus, type JudgmentStatusState, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type OrgSubscription, type Provider, type PubkeyValue, type TelemetryConfig, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, checkAgentExists, containsEvasionCharacters, createAtbashClient, createMemorySnapshot, derivePublicKey, diffMemorySnapshots, generateKeyPair, getAgentDetail, getAgentPolicy, getAgentToolCalls, getConfigDir, getConfigPath, getHeldActionReviews, getJudgmentStatus, getOrgSubscription, getOrgToolCalls, getPendingHeldActions, getSafetyStats, getToolCallCount, getToolCallFull, getToolCalls, isValidPrivateKey, judgeAction, loadAgent, loadAgentFromFile, loadUserConfig, normalizeForMatching, resolve, resolveKeyPath, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, toPubkeyHex, validateJudgeEndpoint, verifyJudgeResponseSignature };
|
|
351
|
+
export { type ActionType, type AgentAuth, type AgentPolicy, type AnomalySeverity, type AnomalyType, type AtbashClient, type AtbashClientConfig, type AtbashUserConfig, type ClientOpts, type ClientSource, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, type Decision, type DecisionVerdict, type HeldAction, type HeldActionReview, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentStatus, type JudgmentStatusState, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type OrgSubscription, type Provider, type PubkeyValue, type TelemetryConfig, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, checkAgentExists, containsEvasionCharacters, createAtbashClient, createMemorySnapshot, derivePublicKey, diffMemorySnapshots, generateKeyPair, getAgentDetail, getAgentPolicy, getAgentToolCalls, getConfigDir, getConfigPath, getHeldActionReviews, getJudgmentStatus, getOrgSubscription, getOrgToolCalls, getPendingHeldActions, getSafetyStats, getToolCallCount, getToolCallFull, getToolCalls, isValidPrivateKey, judgeAction, loadAgent, loadAgentFromFile, loadUserConfig, normalizeForMatching, resolve, resolveChainForOrg, resolveKeyPath, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, toPubkeyHex, validateJudgeEndpoint, verifyJudgeResponseSignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,12 @@ type PubkeyValue = string | Buffer | {
|
|
|
5
5
|
data: number[];
|
|
6
6
|
};
|
|
7
7
|
type JudgmentStatusState = "pending" | "answered" | "error";
|
|
8
|
+
type Network = "public" | "private";
|
|
9
|
+
interface ChainConfig {
|
|
10
|
+
network: Network;
|
|
11
|
+
blockchainRid: string;
|
|
12
|
+
nodeUrls: string[];
|
|
13
|
+
}
|
|
8
14
|
interface Subscription {
|
|
9
15
|
subscription_name: string;
|
|
10
16
|
agent_number: number;
|
|
@@ -31,6 +37,7 @@ interface ClientOpts {
|
|
|
31
37
|
interface ChainOpts {
|
|
32
38
|
nodeUrls?: string[];
|
|
33
39
|
blockchainRid?: string;
|
|
40
|
+
network?: Network;
|
|
34
41
|
}
|
|
35
42
|
interface JudgeResult {
|
|
36
43
|
verdict: Verdict;
|
|
@@ -197,7 +204,7 @@ interface AtbashClientConfig {
|
|
|
197
204
|
|
|
198
205
|
declare const DEFAULT_ENDPOINT = "https://chromia-verified-ai-dev-two.vercel.app";
|
|
199
206
|
declare const DEFAULT_CHROMIA_NODE_URLS: string[];
|
|
200
|
-
declare const DEFAULT_BLOCKCHAIN_RID = "
|
|
207
|
+
declare const DEFAULT_BLOCKCHAIN_RID = "72552FA964345BBA3748244B2D3F0C4A5C766EDFD2BAFA3B8A43F15BE7A59C5A";
|
|
201
208
|
declare function isValidPrivateKey(hex: string): boolean;
|
|
202
209
|
declare function derivePublicKey(privKeyHex: string): string;
|
|
203
210
|
declare function generateKeyPair(): {
|
|
@@ -206,7 +213,7 @@ declare function generateKeyPair(): {
|
|
|
206
213
|
};
|
|
207
214
|
declare function loadAgent(privkey: string): AgentAuth;
|
|
208
215
|
declare function toPubkeyHex(val: unknown): string;
|
|
209
|
-
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
216
|
+
declare function checkAgentExists(pubkey: string, opts?: ClientOpts, chainOpts?: ChainOpts): Promise<boolean>;
|
|
210
217
|
declare function judgeAction(action: string, context: string | undefined, auth: AgentAuth, opts?: JudgeOptions): Promise<JudgeResult>;
|
|
211
218
|
declare function getJudgmentStatus(judgmentId: string, agentPubkey: string, opts?: ClientOpts): Promise<JudgmentStatus>;
|
|
212
219
|
declare function getToolCalls(maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
@@ -214,11 +221,16 @@ declare function getOrgToolCalls(orgName: string, maxCount: number, opts?: Clien
|
|
|
214
221
|
declare function getAgentToolCalls(agentPubkey: string, maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
215
222
|
declare function getToolCallCount(opts?: ClientOpts): Promise<number>;
|
|
216
223
|
declare function getToolCallFull(toolCallId: string, opts?: ClientOpts): Promise<ToolCallFull | null>;
|
|
217
|
-
declare function getOrgSubscription(orgName: string, opts?: ClientOpts): Promise<OrgSubscription | null>;
|
|
224
|
+
declare function getOrgSubscription(orgName: string, opts?: ClientOpts, network?: Network): Promise<OrgSubscription | null>;
|
|
225
|
+
declare function resolveChainForOrg(orgName: string, opts?: ClientOpts): Promise<ChainConfig>;
|
|
218
226
|
declare function getPendingHeldActions(orgName: string, maxCount: number, opts?: ClientOpts): Promise<HeldAction[]>;
|
|
219
227
|
declare function getHeldActionReviews(orgName: string, maxCount: number, opts?: ClientOpts): Promise<HeldActionReview[]>;
|
|
220
|
-
declare function getAgentDetail(agentPubkey: string, opts?: ClientOpts
|
|
221
|
-
|
|
228
|
+
declare function getAgentDetail(agentPubkey: string, opts?: ClientOpts & {
|
|
229
|
+
orgName?: string;
|
|
230
|
+
}, chainOpts?: ChainOpts): Promise<Record<string, unknown>>;
|
|
231
|
+
declare function getAgentPolicy(agentPubkey: string, opts?: ClientOpts & {
|
|
232
|
+
orgName?: string;
|
|
233
|
+
}, chainOpts?: ChainOpts): Promise<AgentPolicy>;
|
|
222
234
|
declare function getSafetyStats(opts?: ClientOpts): Promise<Record<string, unknown>>;
|
|
223
235
|
|
|
224
236
|
interface AtbashClient {
|
|
@@ -336,4 +348,4 @@ declare function normalizeForMatching(input: string): string;
|
|
|
336
348
|
*/
|
|
337
349
|
declare function containsEvasionCharacters(input: string): boolean;
|
|
338
350
|
|
|
339
|
-
export { type ActionType, type AgentAuth, type AgentPolicy, type AnomalySeverity, type AnomalyType, type AtbashClient, type AtbashClientConfig, type AtbashUserConfig, type ClientOpts, type ClientSource, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, type Decision, type DecisionVerdict, type HeldAction, type HeldActionReview, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentStatus, type JudgmentStatusState, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type OrgSubscription, type Provider, type PubkeyValue, type TelemetryConfig, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, checkAgentExists, containsEvasionCharacters, createAtbashClient, createMemorySnapshot, derivePublicKey, diffMemorySnapshots, generateKeyPair, getAgentDetail, getAgentPolicy, getAgentToolCalls, getConfigDir, getConfigPath, getHeldActionReviews, getJudgmentStatus, getOrgSubscription, getOrgToolCalls, getPendingHeldActions, getSafetyStats, getToolCallCount, getToolCallFull, getToolCalls, isValidPrivateKey, judgeAction, loadAgent, loadAgentFromFile, loadUserConfig, normalizeForMatching, resolve, resolveKeyPath, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, toPubkeyHex, validateJudgeEndpoint, verifyJudgeResponseSignature };
|
|
351
|
+
export { type ActionType, type AgentAuth, type AgentPolicy, type AnomalySeverity, type AnomalyType, type AtbashClient, type AtbashClientConfig, type AtbashUserConfig, type ClientOpts, type ClientSource, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, type Decision, type DecisionVerdict, type HeldAction, type HeldActionReview, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentStatus, type JudgmentStatusState, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type OrgSubscription, type Provider, type PubkeyValue, type TelemetryConfig, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, checkAgentExists, containsEvasionCharacters, createAtbashClient, createMemorySnapshot, derivePublicKey, diffMemorySnapshots, generateKeyPair, getAgentDetail, getAgentPolicy, getAgentToolCalls, getConfigDir, getConfigPath, getHeldActionReviews, getJudgmentStatus, getOrgSubscription, getOrgToolCalls, getPendingHeldActions, getSafetyStats, getToolCallCount, getToolCallFull, getToolCalls, isValidPrivateKey, judgeAction, loadAgent, loadAgentFromFile, loadUserConfig, normalizeForMatching, resolve, resolveChainForOrg, resolveKeyPath, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, toPubkeyHex, validateJudgeEndpoint, verifyJudgeResponseSignature };
|
package/dist/index.js
CHANGED
|
@@ -117,11 +117,11 @@ async function shutdownTelemetry() {
|
|
|
117
117
|
var { createClient, encryption: encryption2, newSignatureProvider } = postchain2;
|
|
118
118
|
var DEFAULT_ENDPOINT = "https://chromia-verified-ai-dev-two.vercel.app";
|
|
119
119
|
var DEFAULT_CHROMIA_NODE_URLS = [
|
|
120
|
-
"https://
|
|
121
|
-
"https://
|
|
122
|
-
"https://
|
|
120
|
+
"https://node6.testnet.chromia.com:7740",
|
|
121
|
+
"https://node7.testnet.chromia.com:7740",
|
|
122
|
+
"https://node8.testnet.chromia.com:7740"
|
|
123
123
|
];
|
|
124
|
-
var DEFAULT_BLOCKCHAIN_RID = "
|
|
124
|
+
var DEFAULT_BLOCKCHAIN_RID = "72552FA964345BBA3748244B2D3F0C4A5C766EDFD2BAFA3B8A43F15BE7A59C5A";
|
|
125
125
|
var DEFAULT_PRIVATE_NODE_URLS = [
|
|
126
126
|
"https://node0-pvn-testnet.dynamic.chromia.dev"
|
|
127
127
|
];
|
|
@@ -230,7 +230,7 @@ async function buildSignedTx(opName, args, auth, chainOpts) {
|
|
|
230
230
|
);
|
|
231
231
|
return Buffer.from(signed).toString("hex");
|
|
232
232
|
}
|
|
233
|
-
async function
|
|
233
|
+
async function _checkAgentExists(pubkey, opts, chainOpts) {
|
|
234
234
|
const start = performance.now();
|
|
235
235
|
recordCall("checkAgentExists", void 0, pubkey);
|
|
236
236
|
try {
|
|
@@ -245,13 +245,13 @@ async function checkAgentExistsInternal(pubkey, opts, chainOpts) {
|
|
|
245
245
|
throw err;
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
async function checkAgentExists(pubkey, opts) {
|
|
249
|
-
return
|
|
248
|
+
async function checkAgentExists(pubkey, opts, chainOpts) {
|
|
249
|
+
return _checkAgentExists(pubkey, opts, chainOpts);
|
|
250
250
|
}
|
|
251
251
|
async function logToolCall(action, context, auth, chainOpts, extra, clientOpts) {
|
|
252
252
|
const start = performance.now();
|
|
253
253
|
recordCall("logToolCall", void 0, auth.pubkey);
|
|
254
|
-
const exists = await
|
|
254
|
+
const exists = await _checkAgentExists(auth.pubkey, clientOpts, chainOpts);
|
|
255
255
|
if (!exists) {
|
|
256
256
|
recordDuration("logToolCall", performance.now() - start, "error");
|
|
257
257
|
return {
|
|
@@ -320,7 +320,9 @@ function enrichError(status, body, statusText, opts) {
|
|
|
320
320
|
return new Error(message);
|
|
321
321
|
}
|
|
322
322
|
async function postJson(url, body, opts) {
|
|
323
|
-
const headers = {
|
|
323
|
+
const headers = {
|
|
324
|
+
"Content-Type": "application/json"
|
|
325
|
+
};
|
|
324
326
|
if (opts?.auth) {
|
|
325
327
|
headers["Authorization"] = `Bearer ${await getOrCreateAuthBearer(opts.auth)}`;
|
|
326
328
|
}
|
|
@@ -386,9 +388,14 @@ async function judgeAction(action, context = "", auth, opts) {
|
|
|
386
388
|
}
|
|
387
389
|
try {
|
|
388
390
|
let chainOpts = opts?.chainOpts;
|
|
389
|
-
if (opts?.orgName
|
|
390
|
-
const
|
|
391
|
-
|
|
391
|
+
if (opts?.orgName) {
|
|
392
|
+
const mapNetwork = await getActiveNetworkForOrg(opts.orgName, opts);
|
|
393
|
+
if (mapNetwork) {
|
|
394
|
+
chainOpts = { network: mapNetwork };
|
|
395
|
+
} else if (!chainOpts?.blockchainRid) {
|
|
396
|
+
const resolved = await resolveChainForOrg(opts.orgName, opts);
|
|
397
|
+
chainOpts = { ...chainOpts, network: resolved.network };
|
|
398
|
+
}
|
|
392
399
|
}
|
|
393
400
|
const logResult = await logToolCall(
|
|
394
401
|
action,
|
|
@@ -417,7 +424,9 @@ async function judgeAction(action, context = "", auth, opts) {
|
|
|
417
424
|
agent_pubkey: auth.pubkey,
|
|
418
425
|
action,
|
|
419
426
|
signed_log_tool_call: logResult.signedHex,
|
|
420
|
-
...signedJudgeActionHex && {
|
|
427
|
+
...signedJudgeActionHex && {
|
|
428
|
+
signed_judge_action: signedJudgeActionHex
|
|
429
|
+
},
|
|
421
430
|
...context && { context },
|
|
422
431
|
...opts?.provider && { provider: opts.provider },
|
|
423
432
|
...opts?.toolName && { tool_name: opts.toolName },
|
|
@@ -462,9 +471,10 @@ async function getJudgmentStatus(judgmentId, agentPubkey, opts) {
|
|
|
462
471
|
throw err;
|
|
463
472
|
}
|
|
464
473
|
}
|
|
465
|
-
function riskEngineUrl(action, params, opts) {
|
|
474
|
+
function riskEngineUrl(action, params, opts, network) {
|
|
466
475
|
const url = new URL(`${baseUrl(opts)}/api/risk-engine`);
|
|
467
476
|
url.searchParams.set("action", action);
|
|
477
|
+
if (network) url.searchParams.set("network", network);
|
|
468
478
|
for (const [k, v] of Object.entries(params)) {
|
|
469
479
|
if (v) url.searchParams.set(k, v);
|
|
470
480
|
}
|
|
@@ -569,12 +579,14 @@ function coerceOrgSubscription(row, orgName) {
|
|
|
569
579
|
is_active: Boolean(r.is_active)
|
|
570
580
|
};
|
|
571
581
|
}
|
|
572
|
-
async function getOrgSubscription(orgName, opts) {
|
|
582
|
+
async function getOrgSubscription(orgName, opts, network) {
|
|
573
583
|
const start = performance.now();
|
|
574
584
|
recordCall("getOrgSubscription");
|
|
575
585
|
try {
|
|
586
|
+
const params = { org: orgName };
|
|
587
|
+
if (network) params.network = network;
|
|
576
588
|
const result = await getJson(
|
|
577
|
-
riskEngineUrl("org-subscription",
|
|
589
|
+
riskEngineUrl("org-subscription", params, opts),
|
|
578
590
|
opts
|
|
579
591
|
);
|
|
580
592
|
recordDuration("getOrgSubscription", performance.now() - start, "success");
|
|
@@ -584,13 +596,47 @@ async function getOrgSubscription(orgName, opts) {
|
|
|
584
596
|
throw err;
|
|
585
597
|
}
|
|
586
598
|
}
|
|
599
|
+
async function getActiveNetworkForOrg(orgName, opts) {
|
|
600
|
+
try {
|
|
601
|
+
const url = `${baseUrl(opts)}/api/org-network?org=${encodeURIComponent(orgName)}`;
|
|
602
|
+
const data = await getJson(url, opts);
|
|
603
|
+
if (data?.network === "public" || data?.network === "private") {
|
|
604
|
+
return data.network;
|
|
605
|
+
}
|
|
606
|
+
return null;
|
|
607
|
+
} catch {
|
|
608
|
+
return null;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
587
611
|
var _chainCache = /* @__PURE__ */ new Map();
|
|
588
612
|
async function resolveChainForOrg(orgName, opts) {
|
|
589
613
|
const cached = _chainCache.get(orgName);
|
|
590
614
|
if (cached) return cached;
|
|
615
|
+
const mapNetwork = await getActiveNetworkForOrg(orgName, opts);
|
|
616
|
+
if (mapNetwork) {
|
|
617
|
+
const chain = mapNetwork === "private" ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
618
|
+
_chainCache.set(orgName, chain);
|
|
619
|
+
return chain;
|
|
620
|
+
}
|
|
591
621
|
try {
|
|
592
|
-
const
|
|
593
|
-
|
|
622
|
+
const [pubSub, privSub] = await Promise.all([
|
|
623
|
+
getOrgSubscription(orgName, opts, "public").catch(() => null),
|
|
624
|
+
getOrgSubscription(orgName, opts, "private").catch(() => null)
|
|
625
|
+
]);
|
|
626
|
+
if (pubSub?.is_private_blockchain) {
|
|
627
|
+
_chainCache.set(orgName, PRIVATE_CHAIN);
|
|
628
|
+
return PRIVATE_CHAIN;
|
|
629
|
+
}
|
|
630
|
+
if (pubSub && privSub) {
|
|
631
|
+
const chain = privSub.assigned_at > pubSub.assigned_at ? PRIVATE_CHAIN : PUBLIC_CHAIN;
|
|
632
|
+
_chainCache.set(orgName, chain);
|
|
633
|
+
return chain;
|
|
634
|
+
}
|
|
635
|
+
if (pubSub) {
|
|
636
|
+
_chainCache.set(orgName, PUBLIC_CHAIN);
|
|
637
|
+
return PUBLIC_CHAIN;
|
|
638
|
+
}
|
|
639
|
+
if (privSub?.is_private_blockchain) {
|
|
594
640
|
_chainCache.set(orgName, PRIVATE_CHAIN);
|
|
595
641
|
return PRIVATE_CHAIN;
|
|
596
642
|
}
|
|
@@ -611,7 +657,11 @@ async function getPendingHeldActions(orgName, maxCount, opts) {
|
|
|
611
657
|
),
|
|
612
658
|
opts
|
|
613
659
|
);
|
|
614
|
-
recordDuration(
|
|
660
|
+
recordDuration(
|
|
661
|
+
"getPendingHeldActions",
|
|
662
|
+
performance.now() - start,
|
|
663
|
+
"success"
|
|
664
|
+
);
|
|
615
665
|
return raw.map((h) => ({ ...h, verdict: normalizeVerdict(h.verdict) }));
|
|
616
666
|
} catch (err) {
|
|
617
667
|
recordDuration("getPendingHeldActions", performance.now() - start, "error");
|
|
@@ -630,22 +680,36 @@ async function getHeldActionReviews(orgName, maxCount, opts) {
|
|
|
630
680
|
),
|
|
631
681
|
opts
|
|
632
682
|
);
|
|
633
|
-
recordDuration(
|
|
683
|
+
recordDuration(
|
|
684
|
+
"getHeldActionReviews",
|
|
685
|
+
performance.now() - start,
|
|
686
|
+
"success"
|
|
687
|
+
);
|
|
634
688
|
return result;
|
|
635
689
|
} catch (err) {
|
|
636
690
|
recordDuration("getHeldActionReviews", performance.now() - start, "error");
|
|
637
691
|
throw err;
|
|
638
692
|
}
|
|
639
693
|
}
|
|
640
|
-
function riskEnginePostUrl(opts) {
|
|
641
|
-
|
|
694
|
+
function riskEnginePostUrl(opts, network) {
|
|
695
|
+
let url = `${baseUrl(opts)}/api/risk-engine`;
|
|
696
|
+
if (network) {
|
|
697
|
+
url += `?network=${encodeURIComponent(network)}`;
|
|
698
|
+
}
|
|
699
|
+
return url;
|
|
642
700
|
}
|
|
643
|
-
async function getAgentDetail(agentPubkey, opts) {
|
|
701
|
+
async function getAgentDetail(agentPubkey, opts, chainOpts) {
|
|
644
702
|
const start = performance.now();
|
|
645
703
|
recordCall("getAgentDetail", void 0, agentPubkey);
|
|
646
704
|
try {
|
|
705
|
+
let resolvedChainOpts = chainOpts;
|
|
706
|
+
if (opts?.orgName && !resolvedChainOpts?.blockchainRid) {
|
|
707
|
+
const resolved = await resolveChainForOrg(opts.orgName, opts);
|
|
708
|
+
resolvedChainOpts = { ...resolvedChainOpts, network: resolved.network };
|
|
709
|
+
}
|
|
710
|
+
const network = resolvedChainOpts?.network;
|
|
647
711
|
const result = await postJson(
|
|
648
|
-
riskEnginePostUrl(opts),
|
|
712
|
+
riskEnginePostUrl(opts, network),
|
|
649
713
|
{ action: "agent-detail-batch", agent: agentPubkey },
|
|
650
714
|
opts
|
|
651
715
|
);
|
|
@@ -656,12 +720,18 @@ async function getAgentDetail(agentPubkey, opts) {
|
|
|
656
720
|
throw err;
|
|
657
721
|
}
|
|
658
722
|
}
|
|
659
|
-
async function getAgentPolicy(agentPubkey, opts) {
|
|
723
|
+
async function getAgentPolicy(agentPubkey, opts, chainOpts) {
|
|
660
724
|
const start = performance.now();
|
|
661
725
|
recordCall("getAgentPolicy", void 0, agentPubkey);
|
|
662
726
|
try {
|
|
727
|
+
let resolvedChainOpts = chainOpts;
|
|
728
|
+
if (opts?.orgName && !resolvedChainOpts?.blockchainRid) {
|
|
729
|
+
const resolved = await resolveChainForOrg(opts.orgName, opts);
|
|
730
|
+
resolvedChainOpts = { ...resolvedChainOpts, network: resolved.network };
|
|
731
|
+
}
|
|
732
|
+
const network = resolvedChainOpts?.network;
|
|
663
733
|
const result = await postJson(
|
|
664
|
-
riskEnginePostUrl(opts),
|
|
734
|
+
riskEnginePostUrl(opts, network),
|
|
665
735
|
{ action: "agent-policy-batch", agent: agentPubkey },
|
|
666
736
|
opts
|
|
667
737
|
);
|
|
@@ -1528,6 +1598,7 @@ export {
|
|
|
1528
1598
|
loadUserConfig,
|
|
1529
1599
|
normalizeForMatching,
|
|
1530
1600
|
resolve,
|
|
1601
|
+
resolveChainForOrg,
|
|
1531
1602
|
resolveKeyPath,
|
|
1532
1603
|
saveUserConfig,
|
|
1533
1604
|
scanMemory,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atbash/sdk",
|
|
3
|
-
"version": "0.3.11-dev.
|
|
3
|
+
"version": "0.3.11-dev.13",
|
|
4
4
|
"description": "Atbash SDK — control boundary before the last irreversible step in an agent workflow",
|
|
5
5
|
"homepage": "https://atbash.ai",
|
|
6
6
|
"author": "Atbash",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
29
29
|
"typecheck": "tsc --noEmit",
|
|
30
30
|
"release": "npm version patch --no-git-tag-version && npm run build && npx npm@10 publish --access public",
|
|
31
|
-
"release:dev": "npm version prerelease --preid
|
|
31
|
+
"release:dev": "npm version prerelease --preid=dev --no-git-tag-version && npm run build && npx npm@10 publish --access public --tag dev"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^20.19.39",
|
|
@@ -42,7 +42,6 @@
|
|
|
42
42
|
"ai-safety"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@atbash/sdk": "^0.3.11-dev.8",
|
|
46
45
|
"@opentelemetry/api": "^1.9.1",
|
|
47
46
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.217.0",
|
|
48
47
|
"@opentelemetry/resources": "^2.7.1",
|