@atbash/sdk 0.3.11-dev.10 → 0.3.11-dev.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -31
- package/dist/index.cjs +32 -6
- package/dist/index.d.cts +3 -27
- package/dist/index.d.ts +3 -27
- package/dist/index.js +32 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,10 +23,12 @@ const agent = loadAgent(process.env.ATBASH_AGENT_PRIVKEY!);
|
|
|
23
23
|
// 2. Submit an action for judgment, before executing it.
|
|
24
24
|
// The SDK signs the transaction locally and sends it to the judge API.
|
|
25
25
|
// Private key stays on your machine — never sent over HTTP.
|
|
26
|
+
// Pass orgName so the SDK auto-resolves the correct chain (public or private).
|
|
26
27
|
const result = await judgeAction(
|
|
27
28
|
"Transfer $50,000 to external wallet 0xabc",
|
|
28
29
|
"Outbound AML check — new recipient, over threshold",
|
|
29
30
|
agent,
|
|
31
|
+
{ orgName: "my_org" },
|
|
30
32
|
);
|
|
31
33
|
|
|
32
34
|
// 3. Enforce the verdict
|
|
@@ -39,19 +41,19 @@ switch (result.verdict) {
|
|
|
39
41
|
console.log("Held for review:", result.tool_call_id);
|
|
40
42
|
break;
|
|
41
43
|
case "BLOCK":
|
|
42
|
-
// Refused — agent is jailed
|
|
44
|
+
// Refused — agent is auto-jailed
|
|
43
45
|
throw new Error(`Blocked: ${result.reason}`);
|
|
44
46
|
}
|
|
45
47
|
```
|
|
46
48
|
|
|
47
|
-
Before this works, the agent must be onboarded at [atbash.ai](https://atbash.ai/) — assigned to an org
|
|
49
|
+
Before this works, the agent must be onboarded at [atbash.ai](https://atbash.ai/) — assigned to an org with an active subscription and a policy pack attached.
|
|
48
50
|
|
|
49
51
|
### How it works
|
|
50
52
|
|
|
51
53
|
`judgeAction()` performs a two-step flow:
|
|
52
54
|
|
|
53
55
|
1. **Sign locally** — signs the transaction using the agent's private key. The key never leaves your machine.
|
|
54
|
-
2. **Request verdict** — sends the signed
|
|
56
|
+
2. **Request verdict** — sends the signed payload to the Atbash judge API, which records it on the Chromia blockchain and returns a verdict.
|
|
55
57
|
|
|
56
58
|
|
|
57
59
|
### Don't have an agent yet?
|
|
@@ -86,9 +88,9 @@ Every `judgeAction` call returns one of three verdicts:
|
|
|
86
88
|
|---------|---------|-------------------------|
|
|
87
89
|
| `ALLOW` | Action is within policy | Proceed with execution |
|
|
88
90
|
| `HOLD` | Requires operator review | Pause — poll `getJudgmentStatus` until resolved |
|
|
89
|
-
| `BLOCK` | Violates a red line | Abort — agent is jailed
|
|
91
|
+
| `BLOCK` | Violates a red line | Abort — agent is auto-jailed |
|
|
90
92
|
|
|
91
|
-
> **NB:** If your org
|
|
93
|
+
> **NB:** If your org has **no active subscription**, the judge returns `"No verdict"` — actions are logged on-chain for the audit trail but not evaluated. Assign a subscription plan at [atbash.ai/risk-engine/settings](https://atbash.ai/risk-engine/settings) for active verdicts. All subscription plans (including Free) get full enforcement.
|
|
92
94
|
|
|
93
95
|
## API
|
|
94
96
|
|
|
@@ -118,17 +120,11 @@ interface JudgeOptions {
|
|
|
118
120
|
model?: string; // Model override (e.g. "gpt-4o-mini")
|
|
119
121
|
toolName?: string; // Tool name for audit trail
|
|
120
122
|
toolArgsJson?: string; // Tool arguments JSON for audit trail
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
interface ChainOpts {
|
|
125
|
-
nodeUrls?: string[]; // Chromia node URLs (uses the default nodeurls)
|
|
126
|
-
blockchainRid?: string; // Blockchain RID (uses the default chromia rid)
|
|
123
|
+
orgName?: string; // Org name — SDK auto-resolves the correct chain
|
|
127
124
|
}
|
|
128
125
|
|
|
129
126
|
interface JudgeResult {
|
|
130
127
|
verdict: string; // "ALLOW", "HOLD", or "BLOCK"
|
|
131
|
-
action_type: string; // "allow", "hold_for_user_confirm", or "block"
|
|
132
128
|
reason: string; // Human-readable explanation
|
|
133
129
|
confidence: number; // 0–1
|
|
134
130
|
provider: string; // Which provider evaluated the action
|
|
@@ -138,20 +134,6 @@ interface JudgeResult {
|
|
|
138
134
|
}
|
|
139
135
|
```
|
|
140
136
|
|
|
141
|
-
### Log tool call (low-level)
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
logToolCall(
|
|
145
|
-
action: string,
|
|
146
|
-
context: string,
|
|
147
|
-
auth: AgentAuth,
|
|
148
|
-
chainOpts?: ChainOpts,
|
|
149
|
-
extra?: { toolName?: string; toolArgsJson?: string },
|
|
150
|
-
): Promise<LogToolCallResult>
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
Sign the transaction locally. Returns `{ success, toolCallId, signedHex?, error? }`. Use this if you need to separate the signing step from the verdict request.
|
|
154
|
-
|
|
155
137
|
### Poll judgment status
|
|
156
138
|
|
|
157
139
|
```ts
|
|
@@ -191,7 +173,6 @@ Functions that sign transactions and write to the Chromia blockchain.
|
|
|
191
173
|
| Function | Use case |
|
|
192
174
|
|----------|----------|
|
|
193
175
|
| `judgeAction(action, context, auth, opts?)` | Sign locally + request a verdict from the judge API |
|
|
194
|
-
| `logToolCall(action, context, auth, ...)` | Sign the transaction locally without requesting a verdict |
|
|
195
176
|
|
|
196
177
|
### Queries
|
|
197
178
|
|
|
@@ -204,7 +185,7 @@ Functions that sign transactions and write to the Chromia blockchain.
|
|
|
204
185
|
| `getAgentToolCalls(pubkey, maxCount)` | List tool calls for a specific agent |
|
|
205
186
|
| `getToolCallCount()` | Get total number of tool calls on-chain |
|
|
206
187
|
| `getToolCallFull(toolCallId)` | Get full details of a single tool call (verdict, context, timing) |
|
|
207
|
-
| `
|
|
188
|
+
| `getOrgSubscription(orgName)` | Check an org's subscription plan, network, and active status |
|
|
208
189
|
| `getAgentDetail(pubkey)` | Get agent metadata (org, status, creation date) |
|
|
209
190
|
| `getAgentPolicy(pubkey)` | Check agent's policy pack and jail status |
|
|
210
191
|
| `getPendingHeldActions(orgName, maxCount)` | List actions waiting for operator approval |
|
|
@@ -242,6 +223,7 @@ saveUserConfig({
|
|
|
242
223
|
// Then use resolve() anywhere
|
|
243
224
|
const agent = loadAgent(resolve("agentKey"));
|
|
244
225
|
const result = await judgeAction("Transfer $500", "finance", agent, {
|
|
226
|
+
orgName: resolve("orgName"),
|
|
245
227
|
provider: resolve("provider"), // omit to use the on-chain ATBASH judge
|
|
246
228
|
});
|
|
247
229
|
```
|
|
@@ -264,7 +246,7 @@ Config file location: `~/.config/atbash/config.json`
|
|
|
264
246
|
| `provider` | `ATBASH_PROVIDER` |
|
|
265
247
|
| `providerModel` | `ATBASH_PROVIDER_MODEL` |
|
|
266
248
|
|
|
267
|
-
> **
|
|
249
|
+
> **Chain routing:** When you pass `orgName`, the SDK automatically connects to the correct chain for your org's subscription plan. You don't need to configure chain details manually.
|
|
268
250
|
|
|
269
251
|
## Secret redaction
|
|
270
252
|
|
|
@@ -285,6 +267,32 @@ Common `kinds`:
|
|
|
285
267
|
|
|
286
268
|
Redaction is silent at the consumer level — the SDK's caller still has the original arguments. Only what's sent to the judge (and persisted on chain via the verdict log) is scrubbed.
|
|
287
269
|
|
|
270
|
+
## High-level client
|
|
271
|
+
|
|
272
|
+
For framework integrations, `createAtbashClient` wraps key loading, secret redaction, and verdict handling into a single `auditToolCall` method:
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
import { createAtbashClient } from "@atbash/sdk";
|
|
276
|
+
|
|
277
|
+
const atbash = createAtbashClient({
|
|
278
|
+
orgName: "my_org",
|
|
279
|
+
keyPair: { privKey: process.env.ATBASH_AGENT_KEY!, pubKey: "" },
|
|
280
|
+
failClosed: true, // block on errors (default: true)
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
const decision = await atbash.auditToolCall({
|
|
284
|
+
toolName: "send_email",
|
|
285
|
+
args: { to: "user@example.com", subject: "Reset" },
|
|
286
|
+
context: "Password reset flow",
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
if (!decision.allow) {
|
|
290
|
+
console.log(`${decision.verdict}: ${decision.reason}`);
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
The client auto-resolves the correct chain from the org's subscription on the first call and caches the result. Secret redaction runs automatically before signing.
|
|
295
|
+
|
|
288
296
|
## Integration patterns
|
|
289
297
|
|
|
290
298
|
### Pre-execution gate
|
|
@@ -334,8 +342,8 @@ API error 404: {"error":"Agent not registered..."}
|
|
|
334
342
|
|---|---|---|
|
|
335
343
|
| `API error 404: Agent not registered` | Agent not onboarded | [atbash.ai/risk-engine/agents](https://atbash.ai/risk-engine/agents) |
|
|
336
344
|
| `API error 400: Agent has no policy` | No policy attached to agent | [atbash.ai/risk-engine/agents](https://atbash.ai/risk-engine/agents) |
|
|
337
|
-
| `Agent is jailed` | BLOCK verdict triggered auto-jail
|
|
338
|
-
| `
|
|
345
|
+
| `Agent is jailed` | BLOCK verdict triggered auto-jail | [atbash.ai/risk-engine/agents](https://atbash.ai/risk-engine/agents) |
|
|
346
|
+
| `Verdicts are disabled` | Org has no active subscription | [atbash.ai/risk-engine/settings](https://atbash.ai/risk-engine/settings) |
|
|
339
347
|
| `API error 400: action is required` | Empty action string | Fix caller |
|
|
340
348
|
| `API error 502: Incorrect API key` | Invalid provider API key | Check saved key at [atbash.ai/risk-engine/settings](https://atbash.ai/risk-engine/settings) |
|
|
341
349
|
|
package/dist/index.cjs
CHANGED
|
@@ -59,7 +59,6 @@ __export(index_exports, {
|
|
|
59
59
|
loadAgent: () => loadAgent,
|
|
60
60
|
loadAgentFromFile: () => loadAgentFromFile,
|
|
61
61
|
loadUserConfig: () => loadUserConfig,
|
|
62
|
-
logToolCall: () => logToolCall,
|
|
63
62
|
normalizeForMatching: () => normalizeForMatching,
|
|
64
63
|
resolve: () => resolve,
|
|
65
64
|
resolveKeyPath: () => resolveKeyPath,
|
|
@@ -266,6 +265,23 @@ function toPubkeyHex(val) {
|
|
|
266
265
|
function baseUrl(opts) {
|
|
267
266
|
return opts?.endpoint || DEFAULT_ENDPOINT;
|
|
268
267
|
}
|
|
268
|
+
var AUTH_BEARER_REFRESH_MS = 4 * 60 * 1e3;
|
|
269
|
+
var bearerCache = /* @__PURE__ */ new Map();
|
|
270
|
+
async function getOrCreateAuthBearer(auth) {
|
|
271
|
+
const now = Date.now();
|
|
272
|
+
const cached = bearerCache.get(auth.pubkey);
|
|
273
|
+
if (cached && now - cached.issuedAt < AUTH_BEARER_REFRESH_MS) {
|
|
274
|
+
return cached.hex;
|
|
275
|
+
}
|
|
276
|
+
const nonce = `auth-${now.toString(36)}-${(0, import_crypto.randomBytes)(4).toString("hex")}`;
|
|
277
|
+
const hex = await buildSignedTx(
|
|
278
|
+
"log_tool_call",
|
|
279
|
+
[nonce, `auth:${now}`, "", "auth-bearer", ""],
|
|
280
|
+
auth
|
|
281
|
+
);
|
|
282
|
+
bearerCache.set(auth.pubkey, { hex, issuedAt: now });
|
|
283
|
+
return hex;
|
|
284
|
+
}
|
|
269
285
|
function generateToolCallId() {
|
|
270
286
|
const ts = Date.now();
|
|
271
287
|
const rand = (0, import_crypto.randomBytes)(4).toString("hex");
|
|
@@ -289,7 +305,7 @@ async function buildSignedTx(opName, args, auth, chainOpts) {
|
|
|
289
305
|
);
|
|
290
306
|
return Buffer.from(signed).toString("hex");
|
|
291
307
|
}
|
|
292
|
-
async function
|
|
308
|
+
async function checkAgentExistsInternal(pubkey, opts, chainOpts) {
|
|
293
309
|
const start = performance.now();
|
|
294
310
|
recordCall("checkAgentExists", void 0, pubkey);
|
|
295
311
|
try {
|
|
@@ -304,10 +320,13 @@ async function checkAgentExists(pubkey, opts, chainOpts) {
|
|
|
304
320
|
throw err;
|
|
305
321
|
}
|
|
306
322
|
}
|
|
323
|
+
async function checkAgentExists(pubkey, opts) {
|
|
324
|
+
return checkAgentExistsInternal(pubkey, opts);
|
|
325
|
+
}
|
|
307
326
|
async function logToolCall(action, context, auth, chainOpts, extra, clientOpts) {
|
|
308
327
|
const start = performance.now();
|
|
309
328
|
recordCall("logToolCall", void 0, auth.pubkey);
|
|
310
|
-
const exists = await
|
|
329
|
+
const exists = await checkAgentExistsInternal(auth.pubkey, clientOpts, chainOpts);
|
|
311
330
|
if (!exists) {
|
|
312
331
|
recordDuration("logToolCall", performance.now() - start, "error");
|
|
313
332
|
return {
|
|
@@ -376,9 +395,13 @@ function enrichError(status, body, statusText, opts) {
|
|
|
376
395
|
return new Error(message);
|
|
377
396
|
}
|
|
378
397
|
async function postJson(url, body, opts) {
|
|
398
|
+
const headers = { "Content-Type": "application/json" };
|
|
399
|
+
if (opts?.auth) {
|
|
400
|
+
headers["Authorization"] = `Bearer ${await getOrCreateAuthBearer(opts.auth)}`;
|
|
401
|
+
}
|
|
379
402
|
const resp = await fetch(url, {
|
|
380
403
|
method: "POST",
|
|
381
|
-
headers
|
|
404
|
+
headers,
|
|
382
405
|
body: JSON.stringify(body),
|
|
383
406
|
signal: opts?.timeout ? AbortSignal.timeout(opts.timeout) : void 0
|
|
384
407
|
});
|
|
@@ -390,9 +413,13 @@ async function postJson(url, body, opts) {
|
|
|
390
413
|
return ct.includes("application/json") ? resp.json() : {};
|
|
391
414
|
}
|
|
392
415
|
async function getJson(url, opts) {
|
|
416
|
+
const headers = { Accept: "application/json" };
|
|
417
|
+
if (opts?.auth) {
|
|
418
|
+
headers["Authorization"] = `Bearer ${await getOrCreateAuthBearer(opts.auth)}`;
|
|
419
|
+
}
|
|
393
420
|
const resp = await fetch(url, {
|
|
394
421
|
method: "GET",
|
|
395
|
-
headers
|
|
422
|
+
headers,
|
|
396
423
|
signal: opts?.timeout ? AbortSignal.timeout(opts.timeout) : void 0
|
|
397
424
|
});
|
|
398
425
|
if (!resp.ok) {
|
|
@@ -1575,7 +1602,6 @@ function deduplicateAnomalies(anomalies) {
|
|
|
1575
1602
|
loadAgent,
|
|
1576
1603
|
loadAgentFromFile,
|
|
1577
1604
|
loadUserConfig,
|
|
1578
|
-
logToolCall,
|
|
1579
1605
|
normalizeForMatching,
|
|
1580
1606
|
resolve,
|
|
1581
1607
|
resolveKeyPath,
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,6 @@ type PubkeyValue = string | Buffer | {
|
|
|
5
5
|
data: number[];
|
|
6
6
|
};
|
|
7
7
|
type JudgmentStatusState = "pending" | "answered" | "error";
|
|
8
|
-
type Network = "public" | "private";
|
|
9
8
|
interface Subscription {
|
|
10
9
|
subscription_name: string;
|
|
11
10
|
agent_number: number;
|
|
@@ -27,17 +26,12 @@ interface AgentAuth {
|
|
|
27
26
|
interface ClientOpts {
|
|
28
27
|
endpoint?: string;
|
|
29
28
|
timeout?: number;
|
|
29
|
+
auth?: AgentAuth;
|
|
30
30
|
}
|
|
31
31
|
interface ChainOpts {
|
|
32
32
|
nodeUrls?: string[];
|
|
33
33
|
blockchainRid?: string;
|
|
34
34
|
}
|
|
35
|
-
interface LogToolCallResult {
|
|
36
|
-
success: boolean;
|
|
37
|
-
toolCallId: string | null;
|
|
38
|
-
signedHex?: string;
|
|
39
|
-
error?: string;
|
|
40
|
-
}
|
|
41
35
|
interface JudgeResult {
|
|
42
36
|
verdict: Verdict;
|
|
43
37
|
action_type: ActionType;
|
|
@@ -204,9 +198,6 @@ interface AtbashClientConfig {
|
|
|
204
198
|
declare const DEFAULT_ENDPOINT = "https://chromia-verified-ai-dev-two.vercel.app";
|
|
205
199
|
declare const DEFAULT_CHROMIA_NODE_URLS: string[];
|
|
206
200
|
declare const DEFAULT_BLOCKCHAIN_RID = "B91106947F1EAED7B5D789C7D35755330A8A7DD7CB990D59366114EFFB79ED10";
|
|
207
|
-
interface InternalChainOpts extends ChainOpts {
|
|
208
|
-
network?: Network;
|
|
209
|
-
}
|
|
210
201
|
declare function isValidPrivateKey(hex: string): boolean;
|
|
211
202
|
declare function derivePublicKey(privKeyHex: string): string;
|
|
212
203
|
declare function generateKeyPair(): {
|
|
@@ -215,22 +206,7 @@ declare function generateKeyPair(): {
|
|
|
215
206
|
};
|
|
216
207
|
declare function loadAgent(privkey: string): AgentAuth;
|
|
217
208
|
declare function toPubkeyHex(val: unknown): string;
|
|
218
|
-
|
|
219
|
-
* Check if an agent is onboarded before signing anything.
|
|
220
|
-
* Calls GET /api/ai/exists?pubkey=<66-hex>
|
|
221
|
-
*/
|
|
222
|
-
declare function checkAgentExists(pubkey: string, opts?: ClientOpts, chainOpts?: InternalChainOpts): Promise<boolean>;
|
|
223
|
-
/**
|
|
224
|
-
* Sign `log_tool_call` locally and return the signed transaction hex.
|
|
225
|
-
*
|
|
226
|
-
* Checks that the agent is onboarded before signing. The private key
|
|
227
|
-
* is used locally — never sent over the network. The server will
|
|
228
|
-
* broadcast the signed transaction to the chain.
|
|
229
|
-
*/
|
|
230
|
-
declare function logToolCall(action: string, context: string, auth: AgentAuth, chainOpts?: InternalChainOpts, extra?: {
|
|
231
|
-
toolName?: string;
|
|
232
|
-
toolArgsJson?: string;
|
|
233
|
-
}, clientOpts?: ClientOpts): Promise<LogToolCallResult>;
|
|
209
|
+
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
234
210
|
declare function judgeAction(action: string, context: string | undefined, auth: AgentAuth, opts?: JudgeOptions): Promise<JudgeResult>;
|
|
235
211
|
declare function getJudgmentStatus(judgmentId: string, agentPubkey: string, opts?: ClientOpts): Promise<JudgmentStatus>;
|
|
236
212
|
declare function getToolCalls(maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
@@ -360,4 +336,4 @@ declare function normalizeForMatching(input: string): string;
|
|
|
360
336
|
*/
|
|
361
337
|
declare function containsEvasionCharacters(input: string): boolean;
|
|
362
338
|
|
|
363
|
-
export { type ActionType, type AgentAuth, type AgentPolicy, type AnomalySeverity, type AnomalyType, type AtbashClient, type AtbashClientConfig, type AtbashUserConfig, type
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ type PubkeyValue = string | Buffer | {
|
|
|
5
5
|
data: number[];
|
|
6
6
|
};
|
|
7
7
|
type JudgmentStatusState = "pending" | "answered" | "error";
|
|
8
|
-
type Network = "public" | "private";
|
|
9
8
|
interface Subscription {
|
|
10
9
|
subscription_name: string;
|
|
11
10
|
agent_number: number;
|
|
@@ -27,17 +26,12 @@ interface AgentAuth {
|
|
|
27
26
|
interface ClientOpts {
|
|
28
27
|
endpoint?: string;
|
|
29
28
|
timeout?: number;
|
|
29
|
+
auth?: AgentAuth;
|
|
30
30
|
}
|
|
31
31
|
interface ChainOpts {
|
|
32
32
|
nodeUrls?: string[];
|
|
33
33
|
blockchainRid?: string;
|
|
34
34
|
}
|
|
35
|
-
interface LogToolCallResult {
|
|
36
|
-
success: boolean;
|
|
37
|
-
toolCallId: string | null;
|
|
38
|
-
signedHex?: string;
|
|
39
|
-
error?: string;
|
|
40
|
-
}
|
|
41
35
|
interface JudgeResult {
|
|
42
36
|
verdict: Verdict;
|
|
43
37
|
action_type: ActionType;
|
|
@@ -204,9 +198,6 @@ interface AtbashClientConfig {
|
|
|
204
198
|
declare const DEFAULT_ENDPOINT = "https://chromia-verified-ai-dev-two.vercel.app";
|
|
205
199
|
declare const DEFAULT_CHROMIA_NODE_URLS: string[];
|
|
206
200
|
declare const DEFAULT_BLOCKCHAIN_RID = "B91106947F1EAED7B5D789C7D35755330A8A7DD7CB990D59366114EFFB79ED10";
|
|
207
|
-
interface InternalChainOpts extends ChainOpts {
|
|
208
|
-
network?: Network;
|
|
209
|
-
}
|
|
210
201
|
declare function isValidPrivateKey(hex: string): boolean;
|
|
211
202
|
declare function derivePublicKey(privKeyHex: string): string;
|
|
212
203
|
declare function generateKeyPair(): {
|
|
@@ -215,22 +206,7 @@ declare function generateKeyPair(): {
|
|
|
215
206
|
};
|
|
216
207
|
declare function loadAgent(privkey: string): AgentAuth;
|
|
217
208
|
declare function toPubkeyHex(val: unknown): string;
|
|
218
|
-
|
|
219
|
-
* Check if an agent is onboarded before signing anything.
|
|
220
|
-
* Calls GET /api/ai/exists?pubkey=<66-hex>
|
|
221
|
-
*/
|
|
222
|
-
declare function checkAgentExists(pubkey: string, opts?: ClientOpts, chainOpts?: InternalChainOpts): Promise<boolean>;
|
|
223
|
-
/**
|
|
224
|
-
* Sign `log_tool_call` locally and return the signed transaction hex.
|
|
225
|
-
*
|
|
226
|
-
* Checks that the agent is onboarded before signing. The private key
|
|
227
|
-
* is used locally — never sent over the network. The server will
|
|
228
|
-
* broadcast the signed transaction to the chain.
|
|
229
|
-
*/
|
|
230
|
-
declare function logToolCall(action: string, context: string, auth: AgentAuth, chainOpts?: InternalChainOpts, extra?: {
|
|
231
|
-
toolName?: string;
|
|
232
|
-
toolArgsJson?: string;
|
|
233
|
-
}, clientOpts?: ClientOpts): Promise<LogToolCallResult>;
|
|
209
|
+
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
234
210
|
declare function judgeAction(action: string, context: string | undefined, auth: AgentAuth, opts?: JudgeOptions): Promise<JudgeResult>;
|
|
235
211
|
declare function getJudgmentStatus(judgmentId: string, agentPubkey: string, opts?: ClientOpts): Promise<JudgmentStatus>;
|
|
236
212
|
declare function getToolCalls(maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
@@ -360,4 +336,4 @@ declare function normalizeForMatching(input: string): string;
|
|
|
360
336
|
*/
|
|
361
337
|
declare function containsEvasionCharacters(input: string): boolean;
|
|
362
338
|
|
|
363
|
-
export { type ActionType, type AgentAuth, type AgentPolicy, type AnomalySeverity, type AnomalyType, type AtbashClient, type AtbashClientConfig, type AtbashUserConfig, type
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -190,6 +190,23 @@ function toPubkeyHex(val) {
|
|
|
190
190
|
function baseUrl(opts) {
|
|
191
191
|
return opts?.endpoint || DEFAULT_ENDPOINT;
|
|
192
192
|
}
|
|
193
|
+
var AUTH_BEARER_REFRESH_MS = 4 * 60 * 1e3;
|
|
194
|
+
var bearerCache = /* @__PURE__ */ new Map();
|
|
195
|
+
async function getOrCreateAuthBearer(auth) {
|
|
196
|
+
const now = Date.now();
|
|
197
|
+
const cached = bearerCache.get(auth.pubkey);
|
|
198
|
+
if (cached && now - cached.issuedAt < AUTH_BEARER_REFRESH_MS) {
|
|
199
|
+
return cached.hex;
|
|
200
|
+
}
|
|
201
|
+
const nonce = `auth-${now.toString(36)}-${randomBytes(4).toString("hex")}`;
|
|
202
|
+
const hex = await buildSignedTx(
|
|
203
|
+
"log_tool_call",
|
|
204
|
+
[nonce, `auth:${now}`, "", "auth-bearer", ""],
|
|
205
|
+
auth
|
|
206
|
+
);
|
|
207
|
+
bearerCache.set(auth.pubkey, { hex, issuedAt: now });
|
|
208
|
+
return hex;
|
|
209
|
+
}
|
|
193
210
|
function generateToolCallId() {
|
|
194
211
|
const ts = Date.now();
|
|
195
212
|
const rand = randomBytes(4).toString("hex");
|
|
@@ -213,7 +230,7 @@ async function buildSignedTx(opName, args, auth, chainOpts) {
|
|
|
213
230
|
);
|
|
214
231
|
return Buffer.from(signed).toString("hex");
|
|
215
232
|
}
|
|
216
|
-
async function
|
|
233
|
+
async function checkAgentExistsInternal(pubkey, opts, chainOpts) {
|
|
217
234
|
const start = performance.now();
|
|
218
235
|
recordCall("checkAgentExists", void 0, pubkey);
|
|
219
236
|
try {
|
|
@@ -228,10 +245,13 @@ async function checkAgentExists(pubkey, opts, chainOpts) {
|
|
|
228
245
|
throw err;
|
|
229
246
|
}
|
|
230
247
|
}
|
|
248
|
+
async function checkAgentExists(pubkey, opts) {
|
|
249
|
+
return checkAgentExistsInternal(pubkey, opts);
|
|
250
|
+
}
|
|
231
251
|
async function logToolCall(action, context, auth, chainOpts, extra, clientOpts) {
|
|
232
252
|
const start = performance.now();
|
|
233
253
|
recordCall("logToolCall", void 0, auth.pubkey);
|
|
234
|
-
const exists = await
|
|
254
|
+
const exists = await checkAgentExistsInternal(auth.pubkey, clientOpts, chainOpts);
|
|
235
255
|
if (!exists) {
|
|
236
256
|
recordDuration("logToolCall", performance.now() - start, "error");
|
|
237
257
|
return {
|
|
@@ -300,9 +320,13 @@ function enrichError(status, body, statusText, opts) {
|
|
|
300
320
|
return new Error(message);
|
|
301
321
|
}
|
|
302
322
|
async function postJson(url, body, opts) {
|
|
323
|
+
const headers = { "Content-Type": "application/json" };
|
|
324
|
+
if (opts?.auth) {
|
|
325
|
+
headers["Authorization"] = `Bearer ${await getOrCreateAuthBearer(opts.auth)}`;
|
|
326
|
+
}
|
|
303
327
|
const resp = await fetch(url, {
|
|
304
328
|
method: "POST",
|
|
305
|
-
headers
|
|
329
|
+
headers,
|
|
306
330
|
body: JSON.stringify(body),
|
|
307
331
|
signal: opts?.timeout ? AbortSignal.timeout(opts.timeout) : void 0
|
|
308
332
|
});
|
|
@@ -314,9 +338,13 @@ async function postJson(url, body, opts) {
|
|
|
314
338
|
return ct.includes("application/json") ? resp.json() : {};
|
|
315
339
|
}
|
|
316
340
|
async function getJson(url, opts) {
|
|
341
|
+
const headers = { Accept: "application/json" };
|
|
342
|
+
if (opts?.auth) {
|
|
343
|
+
headers["Authorization"] = `Bearer ${await getOrCreateAuthBearer(opts.auth)}`;
|
|
344
|
+
}
|
|
317
345
|
const resp = await fetch(url, {
|
|
318
346
|
method: "GET",
|
|
319
|
-
headers
|
|
347
|
+
headers,
|
|
320
348
|
signal: opts?.timeout ? AbortSignal.timeout(opts.timeout) : void 0
|
|
321
349
|
});
|
|
322
350
|
if (!resp.ok) {
|
|
@@ -1498,7 +1526,6 @@ export {
|
|
|
1498
1526
|
loadAgent,
|
|
1499
1527
|
loadAgentFromFile,
|
|
1500
1528
|
loadUserConfig,
|
|
1501
|
-
logToolCall,
|
|
1502
1529
|
normalizeForMatching,
|
|
1503
1530
|
resolve,
|
|
1504
1531
|
resolveKeyPath,
|
package/package.json
CHANGED