@atbash/sdk 0.3.25 → 0.4.0-dev.1
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 +99 -321
- package/dist/index.d.mts +560 -0
- package/dist/index.d.ts +463 -242
- package/dist/index.js +1196 -1348
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1334 -0
- package/dist/index.mjs.map +1 -0
- package/index.d.ts +37 -0
- package/index.js +607 -0
- package/package.json +68 -32
- package/LICENSE +0 -28
- package/dist/index.cjs +0 -1616
- package/dist/index.d.cts +0 -339
package/dist/index.d.cts
DELETED
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
type Verdict = "ALLOW" | "HOLD" | "BLOCK" | "No verdict";
|
|
2
|
-
type Provider = "openai" | "google" | "microsoft" | "custom" | (string & {});
|
|
3
|
-
type ActionType = "allow" | "hold_for_user_confirm" | "block" | (string & {});
|
|
4
|
-
type PubkeyValue = string | Buffer | {
|
|
5
|
-
data: number[];
|
|
6
|
-
};
|
|
7
|
-
type JudgmentStatusState = "pending" | "answered" | "error";
|
|
8
|
-
interface Subscription {
|
|
9
|
-
subscription_name: string;
|
|
10
|
-
agent_number: number;
|
|
11
|
-
is_private_blockchain: boolean;
|
|
12
|
-
monthly_price: number;
|
|
13
|
-
yearly_price: number;
|
|
14
|
-
}
|
|
15
|
-
interface OrgSubscription extends Subscription {
|
|
16
|
-
org_name: string;
|
|
17
|
-
duration_months: number;
|
|
18
|
-
assigned_at: number;
|
|
19
|
-
expires_at: number;
|
|
20
|
-
is_active: boolean;
|
|
21
|
-
}
|
|
22
|
-
interface AgentAuth {
|
|
23
|
-
pubkey: string;
|
|
24
|
-
privkey: string;
|
|
25
|
-
}
|
|
26
|
-
interface ClientOpts {
|
|
27
|
-
endpoint?: string;
|
|
28
|
-
timeout?: number;
|
|
29
|
-
auth?: AgentAuth;
|
|
30
|
-
}
|
|
31
|
-
interface ChainOpts {
|
|
32
|
-
nodeUrls?: string[];
|
|
33
|
-
blockchainRid?: string;
|
|
34
|
-
}
|
|
35
|
-
interface JudgeResult {
|
|
36
|
-
verdict: Verdict;
|
|
37
|
-
action_type: ActionType;
|
|
38
|
-
reason: string;
|
|
39
|
-
confidence: number;
|
|
40
|
-
provider: Provider;
|
|
41
|
-
latency_ms: number;
|
|
42
|
-
tool_call_id: string;
|
|
43
|
-
on_chain: boolean;
|
|
44
|
-
}
|
|
45
|
-
interface JudgeOptions extends ClientOpts {
|
|
46
|
-
provider?: Provider;
|
|
47
|
-
model?: string;
|
|
48
|
-
toolName?: string;
|
|
49
|
-
toolArgsJson?: string;
|
|
50
|
-
orgName?: string;
|
|
51
|
-
chainOpts?: ChainOpts;
|
|
52
|
-
verifyPubKey?: string;
|
|
53
|
-
}
|
|
54
|
-
interface JudgmentStatus {
|
|
55
|
-
status: JudgmentStatusState;
|
|
56
|
-
verdict: Verdict;
|
|
57
|
-
reason: string;
|
|
58
|
-
judgmentId: string;
|
|
59
|
-
onChain?: boolean;
|
|
60
|
-
cached?: boolean;
|
|
61
|
-
responseTimeMs?: number;
|
|
62
|
-
}
|
|
63
|
-
interface ToolCallRecord {
|
|
64
|
-
tool_call_id: string;
|
|
65
|
-
agent_pubkey: PubkeyValue;
|
|
66
|
-
tool_name: string;
|
|
67
|
-
command_text: string;
|
|
68
|
-
tool_args_json: string;
|
|
69
|
-
context_text: string;
|
|
70
|
-
org_name: string;
|
|
71
|
-
rowid: number;
|
|
72
|
-
}
|
|
73
|
-
interface ToolCallFull {
|
|
74
|
-
tool_call_id: string;
|
|
75
|
-
agent_pubkey: PubkeyValue;
|
|
76
|
-
tool_name: string;
|
|
77
|
-
command_text: string;
|
|
78
|
-
context_text: string;
|
|
79
|
-
tool_args_json?: string;
|
|
80
|
-
org_name: string;
|
|
81
|
-
created_at?: number;
|
|
82
|
-
action_type?: ActionType;
|
|
83
|
-
result_status?: string;
|
|
84
|
-
verdict_color?: string;
|
|
85
|
-
verdict_reason?: string;
|
|
86
|
-
verdict_source?: string;
|
|
87
|
-
verdict_response_time_ms?: number;
|
|
88
|
-
}
|
|
89
|
-
interface HeldAction {
|
|
90
|
-
judgment_id: string;
|
|
91
|
-
agent_pubkey: PubkeyValue;
|
|
92
|
-
action_text: string;
|
|
93
|
-
action_context: string;
|
|
94
|
-
verdict: Verdict;
|
|
95
|
-
reason: string;
|
|
96
|
-
created_at: number;
|
|
97
|
-
}
|
|
98
|
-
interface HeldActionReview {
|
|
99
|
-
judgment_id: string;
|
|
100
|
-
action_text: string;
|
|
101
|
-
status: string;
|
|
102
|
-
review_note: string;
|
|
103
|
-
reviewed_by: PubkeyValue | null;
|
|
104
|
-
reviewed_at: number;
|
|
105
|
-
created_at: number;
|
|
106
|
-
}
|
|
107
|
-
interface AgentPolicy {
|
|
108
|
-
policy: string;
|
|
109
|
-
is_jailed: boolean;
|
|
110
|
-
is_custom: boolean;
|
|
111
|
-
default_policy: string;
|
|
112
|
-
}
|
|
113
|
-
type DecisionVerdict = "ALLOW" | "HOLD" | "BLOCK" | "ERROR";
|
|
114
|
-
interface Decision {
|
|
115
|
-
allow: boolean;
|
|
116
|
-
verdict: DecisionVerdict;
|
|
117
|
-
reason?: string;
|
|
118
|
-
toolCallId?: string;
|
|
119
|
-
}
|
|
120
|
-
interface ToolCallInput {
|
|
121
|
-
toolName: string;
|
|
122
|
-
args?: unknown;
|
|
123
|
-
context?: string;
|
|
124
|
-
}
|
|
125
|
-
type JudgeEndpointConfig = {
|
|
126
|
-
policy?: "default";
|
|
127
|
-
endpoint?: string;
|
|
128
|
-
} | {
|
|
129
|
-
policy: "self-hosted";
|
|
130
|
-
endpoint: string;
|
|
131
|
-
verifyPubKey: string;
|
|
132
|
-
};
|
|
133
|
-
interface ValidatedEndpoint {
|
|
134
|
-
url: string;
|
|
135
|
-
policy: "default" | "self-hosted";
|
|
136
|
-
verifyPubKey: string | null;
|
|
137
|
-
}
|
|
138
|
-
interface MemoryEntry {
|
|
139
|
-
key: string;
|
|
140
|
-
value: string;
|
|
141
|
-
source?: string;
|
|
142
|
-
timestamp?: number;
|
|
143
|
-
}
|
|
144
|
-
type MemoryScanVerdict = "green" | "yellow" | "red";
|
|
145
|
-
type AnomalySeverity = "low" | "medium" | "high" | "critical";
|
|
146
|
-
type AnomalyType = "behavioral_override" | "bulk_insertion" | "safety_bypass" | "privilege_escalation" | "gradual_drift";
|
|
147
|
-
interface MemoryScanResult {
|
|
148
|
-
safe: boolean;
|
|
149
|
-
verdict: MemoryScanVerdict;
|
|
150
|
-
reason: string;
|
|
151
|
-
confidence: number;
|
|
152
|
-
toolCallId?: string;
|
|
153
|
-
}
|
|
154
|
-
interface MemoryScanOptions extends JudgeOptions {
|
|
155
|
-
/** Confidence threshold below which the entry is allowed (default 0.6). */
|
|
156
|
-
threshold?: number;
|
|
157
|
-
/** Stop batch scanning on the first red verdict (default true). */
|
|
158
|
-
stopOnRed?: boolean;
|
|
159
|
-
}
|
|
160
|
-
interface MemorySnapshot {
|
|
161
|
-
entries: MemoryEntry[];
|
|
162
|
-
takenAt: number;
|
|
163
|
-
}
|
|
164
|
-
interface MemoryAnomaly {
|
|
165
|
-
type: AnomalyType;
|
|
166
|
-
severity: AnomalySeverity;
|
|
167
|
-
description: string;
|
|
168
|
-
entries: string[];
|
|
169
|
-
}
|
|
170
|
-
interface MemoryDiffResult {
|
|
171
|
-
safe: boolean;
|
|
172
|
-
added: MemoryEntry[];
|
|
173
|
-
removed: MemoryEntry[];
|
|
174
|
-
modified: Array<{
|
|
175
|
-
key: string;
|
|
176
|
-
before: string;
|
|
177
|
-
after: string;
|
|
178
|
-
}>;
|
|
179
|
-
anomalies: MemoryAnomaly[];
|
|
180
|
-
}
|
|
181
|
-
interface AtbashClientConfig {
|
|
182
|
-
judge?: JudgeEndpointConfig;
|
|
183
|
-
nodeUrls?: string[];
|
|
184
|
-
blockchainRid?: string;
|
|
185
|
-
orgName?: string;
|
|
186
|
-
keyPath?: string;
|
|
187
|
-
keyPair?: {
|
|
188
|
-
privKey: string;
|
|
189
|
-
pubKey: string;
|
|
190
|
-
};
|
|
191
|
-
failClosed?: boolean;
|
|
192
|
-
logger?: {
|
|
193
|
-
info?(...a: unknown[]): void;
|
|
194
|
-
warn?(...a: unknown[]): void;
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
declare const DEFAULT_ENDPOINT = "https://atbash.ai";
|
|
199
|
-
declare const DEFAULT_CHROMIA_NODE_URLS: string[];
|
|
200
|
-
declare const DEFAULT_BLOCKCHAIN_RID = "B91106947F1EAED7B5D789C7D35755330A8A7DD7CB990D59366114EFFB79ED10";
|
|
201
|
-
declare function isValidPrivateKey(hex: string): boolean;
|
|
202
|
-
declare function derivePublicKey(privKeyHex: string): string;
|
|
203
|
-
declare function generateKeyPair(): {
|
|
204
|
-
privKey: string;
|
|
205
|
-
pubKey: string;
|
|
206
|
-
};
|
|
207
|
-
declare function loadAgent(privkey: string): AgentAuth;
|
|
208
|
-
declare function toPubkeyHex(val: unknown): string;
|
|
209
|
-
declare function checkAgentExists(pubkey: string, opts?: ClientOpts): Promise<boolean>;
|
|
210
|
-
declare function judgeAction(action: string, context: string | undefined, auth: AgentAuth, opts?: JudgeOptions): Promise<JudgeResult>;
|
|
211
|
-
declare function getJudgmentStatus(judgmentId: string, agentPubkey: string, opts?: ClientOpts): Promise<JudgmentStatus>;
|
|
212
|
-
declare function getToolCalls(maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
213
|
-
declare function getOrgToolCalls(orgName: string, maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
214
|
-
declare function getAgentToolCalls(agentPubkey: string, maxCount: number, opts?: ClientOpts): Promise<ToolCallRecord[]>;
|
|
215
|
-
declare function getToolCallCount(opts?: ClientOpts): Promise<number>;
|
|
216
|
-
declare function getToolCallFull(toolCallId: string, opts?: ClientOpts): Promise<ToolCallFull | null>;
|
|
217
|
-
declare function getOrgSubscription(orgName: string, opts?: ClientOpts): Promise<OrgSubscription | null>;
|
|
218
|
-
declare function getPendingHeldActions(orgName: string, maxCount: number, opts?: ClientOpts): Promise<HeldAction[]>;
|
|
219
|
-
declare function getHeldActionReviews(orgName: string, maxCount: number, opts?: ClientOpts): Promise<HeldActionReview[]>;
|
|
220
|
-
declare function getAgentDetail(agentPubkey: string, opts?: ClientOpts): Promise<Record<string, unknown>>;
|
|
221
|
-
declare function getAgentPolicy(agentPubkey: string, opts?: ClientOpts): Promise<AgentPolicy>;
|
|
222
|
-
declare function getSafetyStats(opts?: ClientOpts): Promise<Record<string, unknown>>;
|
|
223
|
-
|
|
224
|
-
interface AtbashClient {
|
|
225
|
-
auditToolCall(input: ToolCallInput): Promise<Decision>;
|
|
226
|
-
}
|
|
227
|
-
declare function createAtbashClient(config?: AtbashClientConfig): AtbashClient;
|
|
228
|
-
|
|
229
|
-
declare function validateJudgeEndpoint(judge?: JudgeEndpointConfig): ValidatedEndpoint;
|
|
230
|
-
|
|
231
|
-
declare function resolveKeyPath(input?: string): string;
|
|
232
|
-
declare function loadAgentFromFile(keyPath?: string): AgentAuth;
|
|
233
|
-
|
|
234
|
-
declare function verifyJudgeResponseSignature(bodyBytes: Uint8Array, signatureHex: string | null, pubKeyHex: string): {
|
|
235
|
-
ok: boolean;
|
|
236
|
-
reason?: string;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Atbash SDK Telemetry — OpenTelemetry metrics for usage tracking.
|
|
241
|
-
*
|
|
242
|
-
* Tracks: function call counts, latency, source (CLI/plugin/SDK),
|
|
243
|
-
* and agent identity. ON by default.
|
|
244
|
-
*
|
|
245
|
-
* Opt-out: create ~/.config/atbash/telemetry.json with { "enabled": false }
|
|
246
|
-
* The file must be mode 0600. If missing, corrupted, or unreadable → telemetry stays ON.
|
|
247
|
-
* Environment variables cannot disable telemetry (prevents agent bypass).
|
|
248
|
-
*/
|
|
249
|
-
type ClientSource = "cli" | "sdk" | "plugin:openclaw" | "plugin:langchain" | "plugin:langgraph" | "plugin:hermes" | "plugin:eliza" | "plugin:crewai" | "plugin:mcp" | "plugin:autogen" | "plugin:jeenai" | (string & {});
|
|
250
|
-
interface TelemetryConfig {
|
|
251
|
-
/** Must be true to send any telemetry. Default: false */
|
|
252
|
-
enabled: boolean;
|
|
253
|
-
/** Where calls originate */
|
|
254
|
-
source?: ClientSource;
|
|
255
|
-
/** Flush interval in ms. Default: 60000 */
|
|
256
|
-
exportIntervalMs?: number;
|
|
257
|
-
}
|
|
258
|
-
declare function setupTelemetry(config: TelemetryConfig): void;
|
|
259
|
-
/**
|
|
260
|
-
* Flush pending metrics and shut down. Call before process exits.
|
|
261
|
-
*/
|
|
262
|
-
declare function shutdownTelemetry(): Promise<void>;
|
|
263
|
-
|
|
264
|
-
interface AtbashUserConfig {
|
|
265
|
-
agentKey?: string;
|
|
266
|
-
orgName?: string;
|
|
267
|
-
judgeEndpoint?: string;
|
|
268
|
-
blockchainRid?: string;
|
|
269
|
-
network?: string;
|
|
270
|
-
provider?: string;
|
|
271
|
-
providerModel?: string;
|
|
272
|
-
}
|
|
273
|
-
declare function getConfigDir(): string;
|
|
274
|
-
declare function getConfigPath(): string;
|
|
275
|
-
declare function loadUserConfig(): AtbashUserConfig;
|
|
276
|
-
declare function saveUserConfig(config: AtbashUserConfig): void;
|
|
277
|
-
declare function resolve(key: keyof AtbashUserConfig, flagValue?: string): string;
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Scan a single memory entry for poisoning.
|
|
281
|
-
*
|
|
282
|
-
* Defence layers (in order):
|
|
283
|
-
* 1. **Regex pre-filter** — catches obvious attacks instantly, zero latency
|
|
284
|
-
* 2. **LLM-as-Judge** — catches semantic / rephrased attacks the regex misses
|
|
285
|
-
*
|
|
286
|
-
* Both layers run against unicode-normalized text. The entry is fenced
|
|
287
|
-
* in the judge prompt so attackers cannot meta-inject into the scanner.
|
|
288
|
-
* Every scan is logged on-chain via the judge API for forensic audit.
|
|
289
|
-
*/
|
|
290
|
-
declare function scanMemory(entry: MemoryEntry, auth: AgentAuth, opts?: MemoryScanOptions): Promise<MemoryScanResult>;
|
|
291
|
-
/**
|
|
292
|
-
* Scan multiple memory entries. By default stops on the first red
|
|
293
|
-
* verdict. Set `stopOnRed: false` to scan all entries regardless.
|
|
294
|
-
*/
|
|
295
|
-
declare function scanMemoryBatch(entries: MemoryEntry[], auth: AgentAuth, opts?: MemoryScanOptions): Promise<MemoryScanResult[]>;
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Create a timestamped snapshot of the current memory state.
|
|
299
|
-
*/
|
|
300
|
-
declare function createMemorySnapshot(entries: MemoryEntry[]): MemorySnapshot;
|
|
301
|
-
/**
|
|
302
|
-
* Compute the diff between two memory snapshots and run anomaly
|
|
303
|
-
* detection heuristics on the result.
|
|
304
|
-
*
|
|
305
|
-
* Catches what other defenses miss:
|
|
306
|
-
* - HMAC detects external tampering, not entries the agent wrote itself
|
|
307
|
-
* - Provenance tagging neutralizes untrusted sources, but a trusted
|
|
308
|
-
* channel can still be exploited
|
|
309
|
-
* - Regex catches fixed phrases, but attackers rephrase
|
|
310
|
-
* - LLM-as-judge catches semantic manipulation on individual entries
|
|
311
|
-
* - This function catches the *cumulative effect* — gradual multi-step
|
|
312
|
-
* poisoning where entries shift agent behavior across sessions
|
|
313
|
-
*/
|
|
314
|
-
declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Unicode normalization for memory content before regex matching.
|
|
318
|
-
*
|
|
319
|
-
* Defeats evasion techniques:
|
|
320
|
-
* - Zero-width characters inserted between letters
|
|
321
|
-
* - Homoglyphs (Cyrillic "а" instead of Latin "a")
|
|
322
|
-
* - Mixed-script confusables
|
|
323
|
-
* - Invisible formatting characters
|
|
324
|
-
*/
|
|
325
|
-
/**
|
|
326
|
-
* Normalize a string for safe regex matching:
|
|
327
|
-
* 1. NFKC normalization (collapses compatibility decompositions)
|
|
328
|
-
* 2. Strip zero-width / invisible characters
|
|
329
|
-
* 3. Map common confusable characters to their Latin equivalents
|
|
330
|
-
*/
|
|
331
|
-
declare function normalizeForMatching(input: string): string;
|
|
332
|
-
/**
|
|
333
|
-
* Check whether a string contains suspicious encoding that may indicate
|
|
334
|
-
* an evasion attempt (presence of confusables, invisible chars, etc.).
|
|
335
|
-
* Returns true if the raw and normalized forms differ.
|
|
336
|
-
*/
|
|
337
|
-
declare function containsEvasionCharacters(input: string): boolean;
|
|
338
|
-
|
|
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 };
|