@atbash/sdk 0.6.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.mts +201 -23
- package/dist/browser.mjs +523 -295
- package/dist/browser.mjs.map +1 -1
- package/dist/index.d.mts +201 -23
- package/dist/index.d.ts +201 -23
- package/dist/index.js +484 -89
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +473 -89
- package/dist/index.mjs.map +1 -1
- package/index.d.ts +0 -8
- package/index.js +52 -53
- package/package.json +5 -5
package/dist/browser.d.mts
CHANGED
|
@@ -150,6 +150,8 @@ interface JudgeResult {
|
|
|
150
150
|
latencyMs: number;
|
|
151
151
|
toolCallId: string;
|
|
152
152
|
onChain: boolean;
|
|
153
|
+
/** Severity 1 (poisonous) → 10 (benign). Present on memory-scan responses; absent for regular tool-call judgments. */
|
|
154
|
+
score?: number;
|
|
153
155
|
/**
|
|
154
156
|
* Whether the org's protection mode actually acts on a HOLD/BLOCK verdict.
|
|
155
157
|
* `false` in Monitor mode (verdict is logged for observation, agent is NOT
|
|
@@ -395,8 +397,17 @@ declare class Atbash {
|
|
|
395
397
|
static fromConfig(options?: FromConfigOptions): Atbash;
|
|
396
398
|
get pubkey(): string;
|
|
397
399
|
get privkey(): string;
|
|
398
|
-
/**
|
|
399
|
-
|
|
400
|
+
/**
|
|
401
|
+
* `GET /api/ai/exists?pubkey=…[&network=…]` — defaults to this client's
|
|
402
|
+
* pubkey. Pass `opts.network` when the caller already knows which
|
|
403
|
+
* network the agent lives on (e.g. after resolving via `orgName`) so
|
|
404
|
+
* the dashboard queries that chain directly instead of falling back
|
|
405
|
+
* across public → private, which double-round-trips and can return
|
|
406
|
+
* false negatives when the fallback chain client is misconfigured.
|
|
407
|
+
*/
|
|
408
|
+
checkAgentExists(pubkey?: string, opts?: {
|
|
409
|
+
network?: Network;
|
|
410
|
+
}): Promise<boolean>;
|
|
400
411
|
/**
|
|
401
412
|
* Pre-flight `checkAgentExists`, then sign `log_tool_call` locally and
|
|
402
413
|
* return the signed tx hex. The server broadcasts to chain.
|
|
@@ -560,33 +571,22 @@ declare function verifyJudgeResponseSignature(bodyBytes: Uint8Array, signatureHe
|
|
|
560
571
|
reason?: string;
|
|
561
572
|
};
|
|
562
573
|
|
|
563
|
-
/**
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
*/
|
|
568
|
-
declare function deriveMemoryKey(privkey: string): Buffer;
|
|
569
|
-
/**
|
|
570
|
-
* Encrypt UTF-8 plaintext. Returns `{ ciphertext, nonce }` — ciphertext
|
|
571
|
-
* has the 16-byte GCM auth tag appended, matching the TS SDK's on-chain
|
|
572
|
-
* byte layout for cross-language parity.
|
|
573
|
-
*/
|
|
574
|
-
declare function encryptMemoryContent(plaintext: string, key: Buffer): {
|
|
574
|
+
/** Derive the 32-byte AES key from an agent's secp256k1 privkey (hex). Deterministic — same privkey always yields the same key. */
|
|
575
|
+
declare function deriveMemoryKey(privkey: string): Promise<Buffer>;
|
|
576
|
+
/** Encrypt UTF-8 plaintext. `ciphertext` has the 16-byte GCM auth tag appended, matching the SDK's on-chain byte layout. */
|
|
577
|
+
declare function encryptMemoryContent(plaintext: string, key: Buffer): Promise<{
|
|
575
578
|
ciphertext: Buffer;
|
|
576
579
|
nonce: Buffer;
|
|
577
|
-
}
|
|
578
|
-
/**
|
|
579
|
-
|
|
580
|
-
* the GCM auth tag doesn't match (tamper detection / wrong key).
|
|
581
|
-
*/
|
|
582
|
-
declare function decryptMemoryContent(ciphertext: Buffer, nonce: Buffer, key: Buffer): string;
|
|
580
|
+
}>;
|
|
581
|
+
/** Decrypt ciphertext produced by `encryptMemoryContent`. Throws on GCM tag mismatch — indicates tampered ciphertext or wrong key. */
|
|
582
|
+
declare function decryptMemoryContent(ciphertext: Buffer, nonce: Buffer, key: Buffer): Promise<string>;
|
|
583
583
|
|
|
584
584
|
/**
|
|
585
585
|
* Scan a single memory entry for poisoning.
|
|
586
586
|
*
|
|
587
587
|
* `auth` is the agent that signs the on-chain audit log for the
|
|
588
|
-
* LLM-judge call.
|
|
589
|
-
*
|
|
588
|
+
* LLM-judge call. The LLM is authoritative; unicode-evasion presence
|
|
589
|
+
* is surfaced to the prompt so the LLM can weight suspicion accordingly.
|
|
590
590
|
*/
|
|
591
591
|
declare function scanMemory(entry: MemoryEntry, auth: AgentAuth, opts?: MemoryScanOptions): Promise<MemoryScanResult>;
|
|
592
592
|
/**
|
|
@@ -647,6 +647,15 @@ interface MemoryRollbackEvent {
|
|
|
647
647
|
signer: string;
|
|
648
648
|
createdAt: number;
|
|
649
649
|
}
|
|
650
|
+
/**
|
|
651
|
+
* Cheap version-pointer probe. Returns just the id of the current
|
|
652
|
+
* active memory (or null if none). No ciphertext is transferred — the
|
|
653
|
+
* response is a single integer, so this is safe to call on every
|
|
654
|
+
* memory-read hot path. Callers that hold a decrypted local copy can
|
|
655
|
+
* compare against a stored pointer and only refetch the full row via
|
|
656
|
+
* `getActiveMemory` when the id has changed.
|
|
657
|
+
*/
|
|
658
|
+
declare function getActiveMemoryId(auth: AgentAuth, chainOpts?: ChainOpts): Promise<number | null>;
|
|
650
659
|
/**
|
|
651
660
|
* Recent active memory entries — subset of active versions filtered
|
|
652
661
|
* by the chain's `MEMORY_RECENT_WINDOW_MS` (10 days at time of
|
|
@@ -825,6 +834,175 @@ interface GuardMemoryWriteResult {
|
|
|
825
834
|
*/
|
|
826
835
|
declare function guardMemoryWrite(input: GuardMemoryWriteInput): Promise<GuardMemoryWriteResult>;
|
|
827
836
|
|
|
837
|
+
/**
|
|
838
|
+
* Aligns a local `MemoryPointer` with chain's active memory version
|
|
839
|
+
* via a TTL-cached pointer check. Inside the TTL window: no-op.
|
|
840
|
+
* Past it: one cheap chain query for the current active id; only on
|
|
841
|
+
* mismatch does the full row get refetched and decrypted.
|
|
842
|
+
*
|
|
843
|
+
* Fail modes:
|
|
844
|
+
* - Chain unreachable → throws the network error verbatim; caller
|
|
845
|
+
* serves the local copy and retries on the next check.
|
|
846
|
+
* - Tampered ciphertext (GCM tag mismatch) → throws
|
|
847
|
+
* `MemoryIntegrityError`. Fail-closed — never silent.
|
|
848
|
+
*/
|
|
849
|
+
|
|
850
|
+
/** Per-agent state the caller persists between sync calls. */
|
|
851
|
+
interface MemoryPointer {
|
|
852
|
+
/** Last known chain-active memory id, or null if the agent had no active memory at the last check. */
|
|
853
|
+
activeId: number | null;
|
|
854
|
+
/** Wall-clock ms of the last successful chain check. Use 0 to force a check on the next call. */
|
|
855
|
+
checkedAt: number;
|
|
856
|
+
}
|
|
857
|
+
interface SyncMemoryOptions {
|
|
858
|
+
/** Trust the pointer without touching chain for this many ms since `checkedAt`. Default 30_000. */
|
|
859
|
+
ttlMs?: number;
|
|
860
|
+
/** Skip the TTL gate and force a chain check this call. Default false. */
|
|
861
|
+
force?: boolean;
|
|
862
|
+
chainOpts?: ChainOpts;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* `drifted: false` — pointer is still valid; caller can keep serving the local copy.
|
|
866
|
+
* `drifted: true` — active id changed on chain; `current` is the fresh decrypted row
|
|
867
|
+
* (or `null` if active memory was removed entirely).
|
|
868
|
+
*/
|
|
869
|
+
type SyncMemoryResult = {
|
|
870
|
+
drifted: false;
|
|
871
|
+
pointer: MemoryPointer;
|
|
872
|
+
} | {
|
|
873
|
+
drifted: true;
|
|
874
|
+
current: AgentMemoryEntry | null;
|
|
875
|
+
pointer: MemoryPointer;
|
|
876
|
+
};
|
|
877
|
+
/** Thrown when a fetched active row fails its GCM integrity check. Poisoning signal — do not swallow. */
|
|
878
|
+
declare class MemoryIntegrityError extends Error {
|
|
879
|
+
readonly id: number;
|
|
880
|
+
constructor(id: number, reason: string);
|
|
881
|
+
}
|
|
882
|
+
declare function syncLocalMemory(auth: AgentAuth, pointer: MemoryPointer, opts?: SyncMemoryOptions): Promise<SyncMemoryResult>;
|
|
883
|
+
|
|
884
|
+
declare class PointerStore {
|
|
885
|
+
private readonly filePath;
|
|
886
|
+
private cache;
|
|
887
|
+
private loading;
|
|
888
|
+
constructor(filePath: string);
|
|
889
|
+
/** Resolves the pointer for `agentPubkeyHex`, or a zero-pointer that will force a sync on first use. */
|
|
890
|
+
get(agentPubkeyHex: string): Promise<MemoryPointer>;
|
|
891
|
+
/** Persists an updated pointer. Failures are swallowed to a logger callback (if provided) so sync never blocks the caller. */
|
|
892
|
+
set(agentPubkeyHex: string, pointer: MemoryPointer, onError?: (err: Error) => void): Promise<void>;
|
|
893
|
+
private ensureLoaded;
|
|
894
|
+
private loadOnce;
|
|
895
|
+
private persist;
|
|
896
|
+
}
|
|
897
|
+
/** Default pointer-file location — `<workspaceDir>/.atbash/memory-pointer.json`. */
|
|
898
|
+
declare function defaultPointerPath(workspaceDir?: string): string;
|
|
899
|
+
|
|
900
|
+
/** Small logger shape used across the memory-poisoning surface. */
|
|
901
|
+
interface WrappedLogger {
|
|
902
|
+
info(message: string, meta?: Record<string, unknown>): void;
|
|
903
|
+
warn(message: string, meta?: Record<string, unknown>): void;
|
|
904
|
+
}
|
|
905
|
+
interface UpstreamLogger {
|
|
906
|
+
info: (...args: unknown[]) => void;
|
|
907
|
+
warn: (...args: unknown[]) => void;
|
|
908
|
+
}
|
|
909
|
+
/** Writes are serialized via an internal promise queue so lines interleave in call-order under concurrency. */
|
|
910
|
+
declare function createFileLogger(filePath: string, upstream?: UpstreamLogger): WrappedLogger;
|
|
911
|
+
/** Default log-file location — `<workspaceDir>/.atbash/plugin.log`. */
|
|
912
|
+
declare function defaultPluginLogPath(workspaceDir?: string): string;
|
|
913
|
+
|
|
914
|
+
/** Dedicated memory-read tool names, matched case-insensitively. Extend via options. */
|
|
915
|
+
declare const DEFAULT_MEMORY_READ_TOOL_NAMES: ReadonlyArray<string>;
|
|
916
|
+
interface ClassifyMemoryReadOptions {
|
|
917
|
+
/** Tool names that always count as memory reads. Merged with defaults. */
|
|
918
|
+
readToolNames?: ReadonlyArray<string>;
|
|
919
|
+
/** Additional path substrings that mark a file as memory. Merged with defaults. */
|
|
920
|
+
patterns?: ReadonlyArray<string>;
|
|
921
|
+
/** Additional generic-read tool names whose path arg to inspect. Merged with defaults. */
|
|
922
|
+
genericReadToolNames?: ReadonlyArray<string>;
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Returns `true` when this tool call is a memory read — either a
|
|
926
|
+
* dedicated memory-read tool from `readToolNames`, or a generic read
|
|
927
|
+
* tool (`read` / `read_file`) targeting a memory-shaped path.
|
|
928
|
+
*/
|
|
929
|
+
declare function classifyMemoryRead(event: unknown, ctx: unknown, opts?: ClassifyMemoryReadOptions): boolean;
|
|
930
|
+
|
|
931
|
+
/** Decision the manager returns to the plugin's `before_tool_call` handler. */
|
|
932
|
+
interface HookDecision {
|
|
933
|
+
allow?: boolean;
|
|
934
|
+
block?: boolean;
|
|
935
|
+
blockReason?: string;
|
|
936
|
+
reason?: string;
|
|
937
|
+
}
|
|
938
|
+
interface MemoryGuardManagerOptions {
|
|
939
|
+
auth: AgentAuth;
|
|
940
|
+
/** Host workspace root (used to derive default file paths). */
|
|
941
|
+
workspaceDir: string;
|
|
942
|
+
/** Absolute MEMORY.md path. Default `<workspaceDir>/MEMORY.md`. */
|
|
943
|
+
memoryFilePath?: string;
|
|
944
|
+
/** Persistent pointer file. Default `<workspaceDir>/.atbash/memory-pointer.json`. */
|
|
945
|
+
pointerFilePath?: string;
|
|
946
|
+
/** File-backed log. Default `<workspaceDir>/.atbash/plugin.log`. */
|
|
947
|
+
logFilePath?: string;
|
|
948
|
+
/** Optional host-native logger — every event mirrors here as well. */
|
|
949
|
+
hostLogger?: {
|
|
950
|
+
info: (...args: unknown[]) => void;
|
|
951
|
+
warn: (...args: unknown[]) => void;
|
|
952
|
+
};
|
|
953
|
+
/** TTL for the local-sync pointer between chain checks. Default 30_000 ms. */
|
|
954
|
+
ttlMs?: number;
|
|
955
|
+
/** Block memory reads when the chain-active version's score is below this. Default 1 (never blocks). */
|
|
956
|
+
rollbackMinScore?: number;
|
|
957
|
+
/** True → return `{block:true}` on defense triggers. False → log and return `null` (audit-only). Default true. */
|
|
958
|
+
enforce?: boolean;
|
|
959
|
+
/** Host-specific tuning of what counts as a memory read. */
|
|
960
|
+
memoryReadClassifier?: ClassifyMemoryReadOptions;
|
|
961
|
+
/** Passed through to `guardMemoryWrite`. Host memory-write tool names override. */
|
|
962
|
+
memoryWriteToolNames?: ReadonlyArray<string>;
|
|
963
|
+
/** Passed through to `guardMemoryWrite` — extra memory path substrings. */
|
|
964
|
+
memoryPathPatterns?: ReadonlyArray<string>;
|
|
965
|
+
/** Passed through to `guardMemoryWrite` — judge endpoint override (defaults to userConfig / DEFAULT_ENDPOINT). */
|
|
966
|
+
judgeEndpoint?: string;
|
|
967
|
+
/** Passed through to `guardMemoryWrite` — self-hosted judge verify pubkey. */
|
|
968
|
+
judgeVerifyPubKey?: string;
|
|
969
|
+
/** Passed through — org name for chain resolution. */
|
|
970
|
+
orgName?: string;
|
|
971
|
+
/** Debug probe in `guardMemoryWrite`. */
|
|
972
|
+
debug?: boolean;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Wire-once, dispatch-many factory. Plugins call once at register(),
|
|
976
|
+
* then feed every `before_tool_call` through `handleBeforeToolCall`.
|
|
977
|
+
*/
|
|
978
|
+
declare class MemoryGuardManager {
|
|
979
|
+
private readonly opts;
|
|
980
|
+
private readonly pointerStore;
|
|
981
|
+
private readonly logger;
|
|
982
|
+
private readonly memoryFilePath;
|
|
983
|
+
private readonly ttlMs;
|
|
984
|
+
private readonly rollbackMinScore;
|
|
985
|
+
private readonly enforce;
|
|
986
|
+
private readonly agentPubkeyHex;
|
|
987
|
+
constructor(opts: MemoryGuardManagerOptions);
|
|
988
|
+
/**
|
|
989
|
+
* One-shot chain probe at plugin registration. Refreshes MEMORY.md
|
|
990
|
+
* from chain when drifted and score passes threshold. Fire-and-forget
|
|
991
|
+
* — errors are logged, never thrown.
|
|
992
|
+
*/
|
|
993
|
+
runBootProbe(): Promise<void>;
|
|
994
|
+
/**
|
|
995
|
+
* Returns a `HookDecision` when the event is a memory read or write
|
|
996
|
+
* (host returns it verbatim to its runtime). Returns `null` when the
|
|
997
|
+
* event isn't memory-related — host falls through to its own audit.
|
|
998
|
+
*/
|
|
999
|
+
handleBeforeToolCall(event: unknown, ctx: unknown): Promise<HookDecision | null>;
|
|
1000
|
+
private mapGuardResult;
|
|
1001
|
+
private handleMemoryRead;
|
|
1002
|
+
private writeMemoryAtomic;
|
|
1003
|
+
}
|
|
1004
|
+
declare function createMemoryGuardManager(opts: MemoryGuardManagerOptions): MemoryGuardManager;
|
|
1005
|
+
|
|
828
1006
|
/**
|
|
829
1007
|
* Atbash SDK Telemetry — OpenTelemetry metrics for usage tracking.
|
|
830
1008
|
*
|
|
@@ -880,4 +1058,4 @@ declare function containsSecret(text: string): boolean;
|
|
|
880
1058
|
declare function createMemorySnapshot(entries: MemoryEntry[], takenAt: number): MemorySnapshot;
|
|
881
1059
|
declare function diffMemorySnapshots(before: MemorySnapshot, after: MemorySnapshot): MemoryDiffResult;
|
|
882
1060
|
|
|
883
|
-
export { type ActionType, type AgentAuth, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, type EncryptedMemory, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, classifyMemoryWrite, commitMemoryVersion, containsEvasionCharacters, containsSecret, createMemorySnapshot, decryptMemoryContent, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptMemoryContent, flushTelemetry, generateKeypair, getActiveMemory, getAllAgentMemory, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRollbackHistory, guardMemoryWrite, isValidPrivateKey, loadAgent, loadAgentFromFile, loadUserConfig, normalizeForMatching, normalizeStatus, normalizeVerdict, pubkeyToHex, recordCall, recordDuration, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signJudgeAction, signLogToolCall, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };
|
|
1061
|
+
export { type ActionType, type AgentAuth, type AgentMemoryEntry, type AgentPolicy, type AnomalySeverity, type AnomalyType, Atbash, AtbashAPIError, type AtbashLogger, type AtbashOptions, type AtbashUserConfig, type ChainOpts, type ClassifierToolContext, type ClassifierToolEvent, type ClassifyMemoryReadOptions, type ClassifyMemoryWriteOptions, type ClientSource, type CommitMemoryOptions, DEFAULT_BLOCKCHAIN_RID, DEFAULT_CHROMIA_NODE_URLS, DEFAULT_ENDPOINT, DEFAULT_MEMORY_PATH_PATTERNS, DEFAULT_MEMORY_READ_TOOL_NAMES, DEFAULT_MEMORY_WRITE_TOOL_NAMES, type Decision, type DecisionVerdict, type EncryptedMemory, type FromConfigOptions, type GuardLogger, type GuardMemoryDecision, type GuardMemoryWriteInput, type GuardMemoryWriteResult, type HeldAction, type HeldActionReview, type HookDecision, type JudgeEndpointConfig, type JudgeOptions, type JudgeResult, type JudgmentState, type JudgmentStatus, type KeyPair, type LogToolCallOptions, type LogToolCallResult, type MemoryAnomaly, type MemoryDiffResult, type MemoryEntry, MemoryGuardManager, type MemoryGuardManagerOptions, MemoryIntegrityError, type MemoryPointer, type MemoryRollbackEvent, type MemoryScanOptions, type MemoryScanResult, type MemoryScanVerdict, type MemorySnapshot, type ModifiedEntry, type Network, type OrgSubscription, PointerStore, type Provider, type PubkeyValue, type RedactResult, type RollbackMemoryOptions, type SecretKind, type SecretMatch, SignatureVerificationError, type Subscription, type SyncMemoryOptions, type SyncMemoryResult, type TelemetryConfig, type TierInfo, type ToolCallFull, type ToolCallInput, type ToolCallRecord, type ValidatedEndpoint, type Verdict, type WrappedLogger, classifyMemoryRead, classifyMemoryWrite, commitMemoryVersion, containsEvasionCharacters, containsSecret, createFileLogger, createMemoryGuardManager, createMemorySnapshot, decryptMemoryContent, defaultPluginLogPath, defaultPointerPath, deriveMemoryKey, derivePublicKey, diffMemorySnapshots, encryptMemoryContent, flushTelemetry, generateKeypair, getActiveMemory, getActiveMemoryId, getAllAgentMemory, getConfigDir, getConfigPath, getMemoryById, getMemoryHistory, getRollbackHistory, guardMemoryWrite, isValidPrivateKey, loadAgent, loadAgentFromFile, loadUserConfig, normalizeForMatching, normalizeStatus, normalizeVerdict, pubkeyToHex, recordCall, recordDuration, redactJsonStrings, redactSecrets, resolve, resolveKeyPath, rollbackMemory, saveUserConfig, scanMemory, scanMemoryBatch, setupTelemetry, shutdownTelemetry, signJudgeAction, signLogToolCall, syncLocalMemory, validateJudgeEndpoint, verifyJudgeResponseSignature, verifySignature };
|