@atbash/sdk 0.3.2 → 0.3.4
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 +43 -48
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +47 -46
- package/dist/index.d.ts +47 -46
- package/dist/index.js +9 -9
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @atbash/sdk
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for the
|
|
3
|
+
TypeScript SDK for Atbash — the safety layer that evaluates AI agent actions against operator-defined policies before execution.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,16 +8,16 @@ TypeScript SDK for the Atbash judge and risk-engine APIs. Evaluate agent actions
|
|
|
8
8
|
npm install @atbash/sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
Requires Node.js 18
|
|
11
|
+
Requires Node.js 18+. Server-side only — private keys are used for local signing and must never be exposed to browsers.
|
|
12
12
|
|
|
13
13
|
## Quickstart
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
16
|
import { loadAgent, judgeAction } from "@atbash/sdk";
|
|
17
17
|
|
|
18
|
-
// 1. Load your agent identity
|
|
19
|
-
//
|
|
20
|
-
//
|
|
18
|
+
// 1. Load your agent identity using the private key you saved during
|
|
19
|
+
// agent creation. loadAgent() validates the key and derives the
|
|
20
|
+
// matching public key for you.
|
|
21
21
|
const agent = loadAgent(process.env.ATBASH_AGENT_PRIVKEY!);
|
|
22
22
|
|
|
23
23
|
// 2. Submit an action for judgment, before executing it.
|
|
@@ -57,7 +57,11 @@ If you need finer control, you can call `logToolCall()` and the judge API separa
|
|
|
57
57
|
|
|
58
58
|
### Don't have an agent yet?
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
There are two ways to create an agent:
|
|
61
|
+
|
|
62
|
+
1. **Dashboard (recommended)** — create an agent at [atbash.ai/risk-engine/agents](https://atbash.ai/risk-engine/agents). The dashboard generates the keypair, assigns the agent to your org, and lets you attach a policy pack — all in one step.
|
|
63
|
+
|
|
64
|
+
2. **Programmatic** — generate a new keypair locally or bring an existing secp256k1 private key from another platform, then onboard it via the dashboard:
|
|
61
65
|
|
|
62
66
|
```ts
|
|
63
67
|
import { generateKeyPair, loadAgent } from "@atbash/sdk";
|
|
@@ -67,7 +71,7 @@ console.log("Save this private key somewhere safe:", privKey);
|
|
|
67
71
|
const agent = loadAgent(privKey);
|
|
68
72
|
```
|
|
69
73
|
|
|
70
|
-
|
|
74
|
+
> **Note:** After generating a key programmatically, you must still onboard the agent at [atbash.ai/risk-engine/agents](https://atbash.ai/risk-engine/agents) — assign it to an org and attach a policy pack before `judgeAction` will work.
|
|
71
75
|
|
|
72
76
|
### Secret storage
|
|
73
77
|
|
|
@@ -88,6 +92,8 @@ Every `judgeAction` call returns one of three verdicts:
|
|
|
88
92
|
| `HOLD` | Requires operator review | Pause — poll `getJudgmentStatus` until resolved |
|
|
89
93
|
| `BLOCK` | Violates a red line | Abort — agent is jailed in Enforcement tier |
|
|
90
94
|
|
|
95
|
+
> **NB:** If your org is on the **Audit** tier, the judge returns `"No verdict"` — actions are logged on-chain for the audit trail but not evaluated by an AI provider. Upgrade to **Audit+** or **Enforcement** at [atbash.ai/risk-engine/settings](https://atbash.ai/risk-engine/settings) for active verdicts.
|
|
96
|
+
|
|
91
97
|
## API
|
|
92
98
|
|
|
93
99
|
### Judge
|
|
@@ -147,10 +153,10 @@ logToolCall(
|
|
|
147
153
|
auth: AgentAuth,
|
|
148
154
|
chainOpts?: ChainOpts,
|
|
149
155
|
extra?: { toolName?: string; toolArgsJson?: string },
|
|
150
|
-
): Promise<
|
|
156
|
+
): Promise<LogToolCallResult>
|
|
151
157
|
```
|
|
152
158
|
|
|
153
|
-
Sign
|
|
159
|
+
Sign `log_tool_call` on the Chromia chain. Returns `{ success, toolCallId, error? }`. Use this if you need to separate the on-chain logging step from the verdict request.
|
|
154
160
|
|
|
155
161
|
### Poll judgment status
|
|
156
162
|
|
|
@@ -184,39 +190,32 @@ toPubkeyHex(val: unknown): string
|
|
|
184
190
|
|
|
185
191
|
`loadAgent(privkey)` is the canonical loader — pass in the private key from the dashboard, get back `{ pubkey, privkey }` ready for `judgeAction`. It accepts `0x`-prefixed, padded, or mixed-case input and throws on malformed keys. Use `generateKeyPair()` only for local development; for production, create agents in the dashboard so operators can attach policies.
|
|
186
192
|
|
|
187
|
-
###
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
```ts
|
|
215
|
-
interface ClientOpts {
|
|
216
|
-
endpoint?: string; // Default: https://atbash.ai
|
|
217
|
-
timeout?: number;
|
|
218
|
-
}
|
|
219
|
-
```
|
|
193
|
+
### Operations
|
|
194
|
+
|
|
195
|
+
Functions that sign transactions and write to the Chromia blockchain.
|
|
196
|
+
|
|
197
|
+
| Function | Use case |
|
|
198
|
+
|----------|----------|
|
|
199
|
+
| `judgeAction(action, context, auth, opts?)` | Sign `log_tool_call` on-chain + request a verdict from the judge API |
|
|
200
|
+
| `logToolCall(action, context, auth, ...)` | Sign and broadcast `log_tool_call` to chain without requesting a verdict |
|
|
201
|
+
|
|
202
|
+
### Queries
|
|
203
|
+
|
|
204
|
+
| Function | Use case |
|
|
205
|
+
|----------|----------|
|
|
206
|
+
| `checkAgentExists(pubkey, opts?)` | Check if an agent is onboarded before signing |
|
|
207
|
+
| `getJudgmentStatus(judgmentId, opts?)` | Poll whether a held action has been approved or rejected |
|
|
208
|
+
| `getToolCalls(maxCount)` | List recent tool calls across all agents |
|
|
209
|
+
| `getOrgToolCalls(orgName, maxCount)` | List tool calls for a specific org |
|
|
210
|
+
| `getAgentToolCalls(pubkey, maxCount)` | List tool calls for a specific agent |
|
|
211
|
+
| `getToolCallCount()` | Get total number of tool calls on-chain |
|
|
212
|
+
| `getToolCallFull(toolCallId)` | Get full details of a single tool call (verdict, context, timing) |
|
|
213
|
+
| `getOrgTierInfo(orgName)` | Check an org's tier and whether verdicts are enabled |
|
|
214
|
+
| `getAgentDetail(pubkey)` | Get agent metadata (org, status, creation date) |
|
|
215
|
+
| `getAgentPolicy(pubkey)` | Check agent's policy pack and jail status |
|
|
216
|
+
| `getPendingHeldActions(orgName, maxCount)` | List actions waiting for operator approval |
|
|
217
|
+
| `getHeldActionReviews(orgName, maxCount)` | List completed operator reviews |
|
|
218
|
+
| `getSafetyStats()` | Get chain-wide safety statistics (total judgments, verdicts, etc.) |
|
|
220
219
|
|
|
221
220
|
## Configuration
|
|
222
221
|
|
|
@@ -235,14 +234,10 @@ const result = await judgeAction(action, context, auth, {
|
|
|
235
234
|
model: "gpt-4o",
|
|
236
235
|
});
|
|
237
236
|
|
|
238
|
-
// Custom Chromia chain (e.g. production RID)
|
|
239
|
-
const result = await judgeAction(action, context, auth, {
|
|
240
|
-
chainOpts: {
|
|
241
|
-
blockchainRid: "YOUR_PRODUCTION_BLOCKCHAIN_RID",
|
|
242
|
-
},
|
|
243
|
-
});
|
|
244
237
|
```
|
|
245
238
|
|
|
239
|
+
> **Advanced:** The SDK connects to the default Atbash Chromia chain. To use a different chain, pass `chainOpts` with custom `nodeUrls` and `blockchainRid` in `JudgeOptions`.
|
|
240
|
+
|
|
246
241
|
## Integration patterns
|
|
247
242
|
|
|
248
243
|
### Pre-execution gate
|
package/dist/index.cjs
CHANGED
|
@@ -60,7 +60,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
60
60
|
var import_crypto = require("crypto");
|
|
61
61
|
var import_postchain_client = __toESM(require("postchain-client"), 1);
|
|
62
62
|
var { createClient, encryption, newSignatureProvider } = import_postchain_client.default;
|
|
63
|
-
var DEFAULT_ENDPOINT = "https://
|
|
63
|
+
var DEFAULT_ENDPOINT = "https://atbash.ai";
|
|
64
64
|
var DEFAULT_CHROMIA_NODE_URLS = [
|
|
65
65
|
"https://node6.testnet.chromia.com:7740",
|
|
66
66
|
"https://node7.testnet.chromia.com:7740",
|
|
@@ -111,13 +111,9 @@ function generateToolCallId() {
|
|
|
111
111
|
return `tc-${ts}-${rand}`;
|
|
112
112
|
}
|
|
113
113
|
async function checkAgentExists(pubkey, opts) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return Boolean(data.registered);
|
|
118
|
-
} catch {
|
|
119
|
-
return false;
|
|
120
|
-
}
|
|
114
|
+
const url = `${baseUrl(opts)}/api/ai/exists?pubkey=${encodeURIComponent(pubkey)}`;
|
|
115
|
+
const data = await getJson(url, opts);
|
|
116
|
+
return Boolean(data.registered);
|
|
121
117
|
}
|
|
122
118
|
async function logToolCall(action, context, auth, chainOpts, extra, clientOpts) {
|
|
123
119
|
const exists = await checkAgentExists(auth.pubkey, clientOpts);
|
|
@@ -165,7 +161,7 @@ async function logToolCall(action, context, auth, chainOpts, extra, clientOpts)
|
|
|
165
161
|
}
|
|
166
162
|
}
|
|
167
163
|
function normalizeVerdict(raw) {
|
|
168
|
-
if (raw === null || raw === void 0) return "
|
|
164
|
+
if (raw === null || raw === void 0) return "No verdict";
|
|
169
165
|
const v = String(raw).toUpperCase();
|
|
170
166
|
if (v === "ALLOW" || v === "GREEN") return "ALLOW";
|
|
171
167
|
if (v === "HOLD" || v === "YELLOW") return "HOLD";
|
|
@@ -215,6 +211,7 @@ async function postJson(url, body, opts) {
|
|
|
215
211
|
async function getJson(url, opts) {
|
|
216
212
|
const resp = await fetch(url, {
|
|
217
213
|
method: "GET",
|
|
214
|
+
headers: { Accept: "application/json" },
|
|
218
215
|
signal: opts?.timeout ? AbortSignal.timeout(opts.timeout) : void 0
|
|
219
216
|
});
|
|
220
217
|
if (!resp.ok) {
|
|
@@ -224,6 +221,9 @@ async function getJson(url, opts) {
|
|
|
224
221
|
return resp.json();
|
|
225
222
|
}
|
|
226
223
|
async function judgeAction(action, context, auth, opts) {
|
|
224
|
+
if (!action || !action.trim()) {
|
|
225
|
+
throw new Error("action is required and cannot be empty.");
|
|
226
|
+
}
|
|
227
227
|
const logResult = await logToolCall(
|
|
228
228
|
action,
|
|
229
229
|
context,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
declare const DEFAULT_CHROMIA_NODE_URLS: string[];
|
|
3
|
-
declare const DEFAULT_BLOCKCHAIN_RID = "25B41DF620C489349C54944496FF5C6E58CFCEFED0C51658780B67299D40E8ED";
|
|
4
|
-
type Verdict = "ALLOW" | "HOLD" | "BLOCK" | "LOGGED";
|
|
1
|
+
type Verdict = "ALLOW" | "HOLD" | "BLOCK" | "No verdict";
|
|
5
2
|
type Provider = "atbash" | "openai" | "google" | "microsoft" | "custom" | (string & {});
|
|
6
3
|
type Tier = "audit" | "audit_plus" | "enforcement" | (string & {});
|
|
7
4
|
type ActionType = "allow" | "hold_for_user_confirm" | "block" | (string & {});
|
|
@@ -9,18 +6,10 @@ type PubkeyValue = string | Buffer | {
|
|
|
9
6
|
data: number[];
|
|
10
7
|
};
|
|
11
8
|
type JudgmentStatusState = "pending" | "answered" | "error";
|
|
12
|
-
declare function isValidPrivateKey(hex: string): boolean;
|
|
13
|
-
declare function derivePublicKey(privKeyHex: string): string;
|
|
14
|
-
declare function generateKeyPair(): {
|
|
15
|
-
privKey: string;
|
|
16
|
-
pubKey: string;
|
|
17
|
-
};
|
|
18
9
|
interface AgentAuth {
|
|
19
10
|
pubkey: string;
|
|
20
11
|
privkey: string;
|
|
21
12
|
}
|
|
22
|
-
declare function loadAgent(privkey: string): AgentAuth;
|
|
23
|
-
declare function toPubkeyHex(val: unknown): string;
|
|
24
13
|
interface ClientOpts {
|
|
25
14
|
endpoint?: string;
|
|
26
15
|
timeout?: number;
|
|
@@ -34,21 +23,6 @@ interface LogToolCallResult {
|
|
|
34
23
|
toolCallId: string | null;
|
|
35
24
|
error?: string;
|
|
36
25
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Check if an agent is onboarded before signing anything.
|
|
39
|
-
* Calls GET /api/ai/exists?pubkey=<66-hex>
|
|
40
|
-
*/
|
|
41
|
-
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
42
|
-
/**
|
|
43
|
-
* Sign and broadcast `log_tool_call` to the Chromia chain.
|
|
44
|
-
*
|
|
45
|
-
* Checks that the agent is onboarded before signing. The agent's private
|
|
46
|
-
* key is used to sign the transaction locally — never sent over the network.
|
|
47
|
-
*/
|
|
48
|
-
declare function logToolCall(action: string, context: string, auth: AgentAuth, chainOpts?: ChainOpts, extra?: {
|
|
49
|
-
toolName?: string;
|
|
50
|
-
toolArgsJson?: string;
|
|
51
|
-
}, clientOpts?: ClientOpts): Promise<LogToolCallResult>;
|
|
52
26
|
interface JudgeResult {
|
|
53
27
|
verdict: Verdict;
|
|
54
28
|
action_type: ActionType;
|
|
@@ -59,6 +33,24 @@ interface JudgeResult {
|
|
|
59
33
|
tool_call_id: string;
|
|
60
34
|
on_chain: boolean;
|
|
61
35
|
}
|
|
36
|
+
interface JudgeOptions extends ClientOpts {
|
|
37
|
+
provider?: Provider;
|
|
38
|
+
apiKey?: string;
|
|
39
|
+
providerEndpoint?: string;
|
|
40
|
+
model?: string;
|
|
41
|
+
toolName?: string;
|
|
42
|
+
toolArgsJson?: string;
|
|
43
|
+
chainOpts?: ChainOpts;
|
|
44
|
+
}
|
|
45
|
+
interface JudgmentStatus {
|
|
46
|
+
status: JudgmentStatusState;
|
|
47
|
+
verdict: Verdict;
|
|
48
|
+
reason: string;
|
|
49
|
+
judgmentId: string;
|
|
50
|
+
onChain?: boolean;
|
|
51
|
+
cached?: boolean;
|
|
52
|
+
responseTimeMs?: number;
|
|
53
|
+
}
|
|
62
54
|
interface TierInfo {
|
|
63
55
|
org_name: string;
|
|
64
56
|
tier: Tier;
|
|
@@ -109,30 +101,39 @@ interface HeldActionReview {
|
|
|
109
101
|
reviewed_at: number;
|
|
110
102
|
created_at: number;
|
|
111
103
|
}
|
|
112
|
-
interface JudgmentStatus {
|
|
113
|
-
status: JudgmentStatusState;
|
|
114
|
-
verdict: Verdict;
|
|
115
|
-
reason: string;
|
|
116
|
-
judgmentId: string;
|
|
117
|
-
onChain?: boolean;
|
|
118
|
-
cached?: boolean;
|
|
119
|
-
responseTimeMs?: number;
|
|
120
|
-
}
|
|
121
|
-
interface JudgeOptions extends ClientOpts {
|
|
122
|
-
provider?: Provider;
|
|
123
|
-
apiKey?: string;
|
|
124
|
-
providerEndpoint?: string;
|
|
125
|
-
model?: string;
|
|
126
|
-
toolName?: string;
|
|
127
|
-
toolArgsJson?: string;
|
|
128
|
-
chainOpts?: ChainOpts;
|
|
129
|
-
}
|
|
130
104
|
interface AgentPolicy {
|
|
131
105
|
policy: string;
|
|
132
106
|
is_jailed: boolean;
|
|
133
107
|
is_custom: boolean;
|
|
134
108
|
default_policy: string;
|
|
135
109
|
}
|
|
110
|
+
|
|
111
|
+
declare const DEFAULT_ENDPOINT = "https://atbash.ai";
|
|
112
|
+
declare const DEFAULT_CHROMIA_NODE_URLS: string[];
|
|
113
|
+
declare const DEFAULT_BLOCKCHAIN_RID = "25B41DF620C489349C54944496FF5C6E58CFCEFED0C51658780B67299D40E8ED";
|
|
114
|
+
declare function isValidPrivateKey(hex: string): boolean;
|
|
115
|
+
declare function derivePublicKey(privKeyHex: string): string;
|
|
116
|
+
declare function generateKeyPair(): {
|
|
117
|
+
privKey: string;
|
|
118
|
+
pubKey: string;
|
|
119
|
+
};
|
|
120
|
+
declare function loadAgent(privkey: string): AgentAuth;
|
|
121
|
+
declare function toPubkeyHex(val: unknown): string;
|
|
122
|
+
/**
|
|
123
|
+
* Check if an agent is onboarded before signing anything.
|
|
124
|
+
* Calls GET /api/ai/exists?pubkey=<66-hex>
|
|
125
|
+
*/
|
|
126
|
+
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
127
|
+
/**
|
|
128
|
+
* Sign and broadcast `log_tool_call` to the Chromia chain.
|
|
129
|
+
*
|
|
130
|
+
* Checks that the agent is onboarded before signing. The agent's private
|
|
131
|
+
* key is used to sign the transaction locally — never sent over the network.
|
|
132
|
+
*/
|
|
133
|
+
declare function logToolCall(action: string, context: string, auth: AgentAuth, chainOpts?: ChainOpts, extra?: {
|
|
134
|
+
toolName?: string;
|
|
135
|
+
toolArgsJson?: string;
|
|
136
|
+
}, clientOpts?: ClientOpts): Promise<LogToolCallResult>;
|
|
136
137
|
declare function judgeAction(action: string, context: string, auth: AgentAuth, opts?: JudgeOptions): Promise<JudgeResult>;
|
|
137
138
|
declare function getJudgmentStatus(judgmentId: string, opts?: ClientOpts): Promise<JudgmentStatus>;
|
|
138
139
|
declare function getToolCalls(maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
@@ -147,4 +148,4 @@ declare function getAgentDetail(agentPubkey: string, opts?: ClientOpts): Promise
|
|
|
147
148
|
declare function getAgentPolicy(agentPubkey: string, opts?: ClientOpts): Promise<AgentPolicy>;
|
|
148
149
|
declare function getSafetyStats(opts?: ClientOpts): Promise<Record<string, unknown>>;
|
|
149
150
|
|
|
150
|
-
export { type AgentAuth, type ChainOpts, type ClientOpts, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, type HeldAction, type HeldActionReview, type JudgeOptions, type JudgeResult, type JudgmentStatus, type LogToolCallResult, type TierInfo, type ToolCallFull, type ToolCallRecord, type Verdict, checkAgentExists, derivePublicKey, generateKeyPair, getAgentDetail, getAgentPolicy, getAgentToolCalls, getHeldActionReviews, getJudgmentStatus, getOrgTierInfo, getOrgToolCalls, getPendingHeldActions, getSafetyStats, getToolCallCount, getToolCallFull, getToolCalls, isValidPrivateKey, judgeAction, loadAgent, logToolCall, toPubkeyHex };
|
|
151
|
+
export { type ActionType, type AgentAuth, type AgentPolicy, type ChainOpts, type ClientOpts, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, type HeldAction, type HeldActionReview, type JudgeOptions, type JudgeResult, type JudgmentStatus, type JudgmentStatusState, type LogToolCallResult, type Provider, type PubkeyValue, type Tier, type TierInfo, type ToolCallFull, type ToolCallRecord, type Verdict, checkAgentExists, derivePublicKey, generateKeyPair, getAgentDetail, getAgentPolicy, getAgentToolCalls, getHeldActionReviews, getJudgmentStatus, getOrgTierInfo, getOrgToolCalls, getPendingHeldActions, getSafetyStats, getToolCallCount, getToolCallFull, getToolCalls, isValidPrivateKey, judgeAction, loadAgent, logToolCall, toPubkeyHex };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
declare const DEFAULT_CHROMIA_NODE_URLS: string[];
|
|
3
|
-
declare const DEFAULT_BLOCKCHAIN_RID = "25B41DF620C489349C54944496FF5C6E58CFCEFED0C51658780B67299D40E8ED";
|
|
4
|
-
type Verdict = "ALLOW" | "HOLD" | "BLOCK" | "LOGGED";
|
|
1
|
+
type Verdict = "ALLOW" | "HOLD" | "BLOCK" | "No verdict";
|
|
5
2
|
type Provider = "atbash" | "openai" | "google" | "microsoft" | "custom" | (string & {});
|
|
6
3
|
type Tier = "audit" | "audit_plus" | "enforcement" | (string & {});
|
|
7
4
|
type ActionType = "allow" | "hold_for_user_confirm" | "block" | (string & {});
|
|
@@ -9,18 +6,10 @@ type PubkeyValue = string | Buffer | {
|
|
|
9
6
|
data: number[];
|
|
10
7
|
};
|
|
11
8
|
type JudgmentStatusState = "pending" | "answered" | "error";
|
|
12
|
-
declare function isValidPrivateKey(hex: string): boolean;
|
|
13
|
-
declare function derivePublicKey(privKeyHex: string): string;
|
|
14
|
-
declare function generateKeyPair(): {
|
|
15
|
-
privKey: string;
|
|
16
|
-
pubKey: string;
|
|
17
|
-
};
|
|
18
9
|
interface AgentAuth {
|
|
19
10
|
pubkey: string;
|
|
20
11
|
privkey: string;
|
|
21
12
|
}
|
|
22
|
-
declare function loadAgent(privkey: string): AgentAuth;
|
|
23
|
-
declare function toPubkeyHex(val: unknown): string;
|
|
24
13
|
interface ClientOpts {
|
|
25
14
|
endpoint?: string;
|
|
26
15
|
timeout?: number;
|
|
@@ -34,21 +23,6 @@ interface LogToolCallResult {
|
|
|
34
23
|
toolCallId: string | null;
|
|
35
24
|
error?: string;
|
|
36
25
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Check if an agent is onboarded before signing anything.
|
|
39
|
-
* Calls GET /api/ai/exists?pubkey=<66-hex>
|
|
40
|
-
*/
|
|
41
|
-
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
42
|
-
/**
|
|
43
|
-
* Sign and broadcast `log_tool_call` to the Chromia chain.
|
|
44
|
-
*
|
|
45
|
-
* Checks that the agent is onboarded before signing. The agent's private
|
|
46
|
-
* key is used to sign the transaction locally — never sent over the network.
|
|
47
|
-
*/
|
|
48
|
-
declare function logToolCall(action: string, context: string, auth: AgentAuth, chainOpts?: ChainOpts, extra?: {
|
|
49
|
-
toolName?: string;
|
|
50
|
-
toolArgsJson?: string;
|
|
51
|
-
}, clientOpts?: ClientOpts): Promise<LogToolCallResult>;
|
|
52
26
|
interface JudgeResult {
|
|
53
27
|
verdict: Verdict;
|
|
54
28
|
action_type: ActionType;
|
|
@@ -59,6 +33,24 @@ interface JudgeResult {
|
|
|
59
33
|
tool_call_id: string;
|
|
60
34
|
on_chain: boolean;
|
|
61
35
|
}
|
|
36
|
+
interface JudgeOptions extends ClientOpts {
|
|
37
|
+
provider?: Provider;
|
|
38
|
+
apiKey?: string;
|
|
39
|
+
providerEndpoint?: string;
|
|
40
|
+
model?: string;
|
|
41
|
+
toolName?: string;
|
|
42
|
+
toolArgsJson?: string;
|
|
43
|
+
chainOpts?: ChainOpts;
|
|
44
|
+
}
|
|
45
|
+
interface JudgmentStatus {
|
|
46
|
+
status: JudgmentStatusState;
|
|
47
|
+
verdict: Verdict;
|
|
48
|
+
reason: string;
|
|
49
|
+
judgmentId: string;
|
|
50
|
+
onChain?: boolean;
|
|
51
|
+
cached?: boolean;
|
|
52
|
+
responseTimeMs?: number;
|
|
53
|
+
}
|
|
62
54
|
interface TierInfo {
|
|
63
55
|
org_name: string;
|
|
64
56
|
tier: Tier;
|
|
@@ -109,30 +101,39 @@ interface HeldActionReview {
|
|
|
109
101
|
reviewed_at: number;
|
|
110
102
|
created_at: number;
|
|
111
103
|
}
|
|
112
|
-
interface JudgmentStatus {
|
|
113
|
-
status: JudgmentStatusState;
|
|
114
|
-
verdict: Verdict;
|
|
115
|
-
reason: string;
|
|
116
|
-
judgmentId: string;
|
|
117
|
-
onChain?: boolean;
|
|
118
|
-
cached?: boolean;
|
|
119
|
-
responseTimeMs?: number;
|
|
120
|
-
}
|
|
121
|
-
interface JudgeOptions extends ClientOpts {
|
|
122
|
-
provider?: Provider;
|
|
123
|
-
apiKey?: string;
|
|
124
|
-
providerEndpoint?: string;
|
|
125
|
-
model?: string;
|
|
126
|
-
toolName?: string;
|
|
127
|
-
toolArgsJson?: string;
|
|
128
|
-
chainOpts?: ChainOpts;
|
|
129
|
-
}
|
|
130
104
|
interface AgentPolicy {
|
|
131
105
|
policy: string;
|
|
132
106
|
is_jailed: boolean;
|
|
133
107
|
is_custom: boolean;
|
|
134
108
|
default_policy: string;
|
|
135
109
|
}
|
|
110
|
+
|
|
111
|
+
declare const DEFAULT_ENDPOINT = "https://atbash.ai";
|
|
112
|
+
declare const DEFAULT_CHROMIA_NODE_URLS: string[];
|
|
113
|
+
declare const DEFAULT_BLOCKCHAIN_RID = "25B41DF620C489349C54944496FF5C6E58CFCEFED0C51658780B67299D40E8ED";
|
|
114
|
+
declare function isValidPrivateKey(hex: string): boolean;
|
|
115
|
+
declare function derivePublicKey(privKeyHex: string): string;
|
|
116
|
+
declare function generateKeyPair(): {
|
|
117
|
+
privKey: string;
|
|
118
|
+
pubKey: string;
|
|
119
|
+
};
|
|
120
|
+
declare function loadAgent(privkey: string): AgentAuth;
|
|
121
|
+
declare function toPubkeyHex(val: unknown): string;
|
|
122
|
+
/**
|
|
123
|
+
* Check if an agent is onboarded before signing anything.
|
|
124
|
+
* Calls GET /api/ai/exists?pubkey=<66-hex>
|
|
125
|
+
*/
|
|
126
|
+
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
127
|
+
/**
|
|
128
|
+
* Sign and broadcast `log_tool_call` to the Chromia chain.
|
|
129
|
+
*
|
|
130
|
+
* Checks that the agent is onboarded before signing. The agent's private
|
|
131
|
+
* key is used to sign the transaction locally — never sent over the network.
|
|
132
|
+
*/
|
|
133
|
+
declare function logToolCall(action: string, context: string, auth: AgentAuth, chainOpts?: ChainOpts, extra?: {
|
|
134
|
+
toolName?: string;
|
|
135
|
+
toolArgsJson?: string;
|
|
136
|
+
}, clientOpts?: ClientOpts): Promise<LogToolCallResult>;
|
|
136
137
|
declare function judgeAction(action: string, context: string, auth: AgentAuth, opts?: JudgeOptions): Promise<JudgeResult>;
|
|
137
138
|
declare function getJudgmentStatus(judgmentId: string, opts?: ClientOpts): Promise<JudgmentStatus>;
|
|
138
139
|
declare function getToolCalls(maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
@@ -147,4 +148,4 @@ declare function getAgentDetail(agentPubkey: string, opts?: ClientOpts): Promise
|
|
|
147
148
|
declare function getAgentPolicy(agentPubkey: string, opts?: ClientOpts): Promise<AgentPolicy>;
|
|
148
149
|
declare function getSafetyStats(opts?: ClientOpts): Promise<Record<string, unknown>>;
|
|
149
150
|
|
|
150
|
-
export { type AgentAuth, type ChainOpts, type ClientOpts, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, type HeldAction, type HeldActionReview, type JudgeOptions, type JudgeResult, type JudgmentStatus, type LogToolCallResult, type TierInfo, type ToolCallFull, type ToolCallRecord, type Verdict, checkAgentExists, derivePublicKey, generateKeyPair, getAgentDetail, getAgentPolicy, getAgentToolCalls, getHeldActionReviews, getJudgmentStatus, getOrgTierInfo, getOrgToolCalls, getPendingHeldActions, getSafetyStats, getToolCallCount, getToolCallFull, getToolCalls, isValidPrivateKey, judgeAction, loadAgent, logToolCall, toPubkeyHex };
|
|
151
|
+
export { type ActionType, type AgentAuth, type AgentPolicy, type ChainOpts, type ClientOpts, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, type HeldAction, type HeldActionReview, type JudgeOptions, type JudgeResult, type JudgmentStatus, type JudgmentStatusState, type LogToolCallResult, type Provider, type PubkeyValue, type Tier, type TierInfo, type ToolCallFull, type ToolCallRecord, type Verdict, checkAgentExists, derivePublicKey, generateKeyPair, getAgentDetail, getAgentPolicy, getAgentToolCalls, getHeldActionReviews, getJudgmentStatus, getOrgTierInfo, getOrgToolCalls, getPendingHeldActions, getSafetyStats, getToolCallCount, getToolCallFull, getToolCalls, isValidPrivateKey, judgeAction, loadAgent, logToolCall, toPubkeyHex };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createECDH, randomBytes } from "crypto";
|
|
3
3
|
import postchain from "postchain-client";
|
|
4
4
|
var { createClient, encryption, newSignatureProvider } = postchain;
|
|
5
|
-
var DEFAULT_ENDPOINT = "https://
|
|
5
|
+
var DEFAULT_ENDPOINT = "https://atbash.ai";
|
|
6
6
|
var DEFAULT_CHROMIA_NODE_URLS = [
|
|
7
7
|
"https://node6.testnet.chromia.com:7740",
|
|
8
8
|
"https://node7.testnet.chromia.com:7740",
|
|
@@ -53,13 +53,9 @@ function generateToolCallId() {
|
|
|
53
53
|
return `tc-${ts}-${rand}`;
|
|
54
54
|
}
|
|
55
55
|
async function checkAgentExists(pubkey, opts) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return Boolean(data.registered);
|
|
60
|
-
} catch {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
56
|
+
const url = `${baseUrl(opts)}/api/ai/exists?pubkey=${encodeURIComponent(pubkey)}`;
|
|
57
|
+
const data = await getJson(url, opts);
|
|
58
|
+
return Boolean(data.registered);
|
|
63
59
|
}
|
|
64
60
|
async function logToolCall(action, context, auth, chainOpts, extra, clientOpts) {
|
|
65
61
|
const exists = await checkAgentExists(auth.pubkey, clientOpts);
|
|
@@ -107,7 +103,7 @@ async function logToolCall(action, context, auth, chainOpts, extra, clientOpts)
|
|
|
107
103
|
}
|
|
108
104
|
}
|
|
109
105
|
function normalizeVerdict(raw) {
|
|
110
|
-
if (raw === null || raw === void 0) return "
|
|
106
|
+
if (raw === null || raw === void 0) return "No verdict";
|
|
111
107
|
const v = String(raw).toUpperCase();
|
|
112
108
|
if (v === "ALLOW" || v === "GREEN") return "ALLOW";
|
|
113
109
|
if (v === "HOLD" || v === "YELLOW") return "HOLD";
|
|
@@ -157,6 +153,7 @@ async function postJson(url, body, opts) {
|
|
|
157
153
|
async function getJson(url, opts) {
|
|
158
154
|
const resp = await fetch(url, {
|
|
159
155
|
method: "GET",
|
|
156
|
+
headers: { Accept: "application/json" },
|
|
160
157
|
signal: opts?.timeout ? AbortSignal.timeout(opts.timeout) : void 0
|
|
161
158
|
});
|
|
162
159
|
if (!resp.ok) {
|
|
@@ -166,6 +163,9 @@ async function getJson(url, opts) {
|
|
|
166
163
|
return resp.json();
|
|
167
164
|
}
|
|
168
165
|
async function judgeAction(action, context, auth, opts) {
|
|
166
|
+
if (!action || !action.trim()) {
|
|
167
|
+
throw new Error("action is required and cannot be empty.");
|
|
168
|
+
}
|
|
169
169
|
const logResult = await logToolCall(
|
|
170
170
|
action,
|
|
171
171
|
context,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atbash/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
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",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsup src/index.ts --format esm,cjs --dts --clean",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
29
30
|
"release": "npm version patch --no-git-tag-version && npm run build && npx npm@10 publish --access public"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|