@rohankumar4179/engram-sdk 0.0.0-stage → 0.1.0

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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -2
  3. package/dist/anchor.d.ts +101 -0
  4. package/dist/anchor.js +215 -0
  5. package/dist/anchor.js.map +1 -0
  6. package/dist/audit.d.ts +48 -0
  7. package/dist/audit.js +93 -0
  8. package/dist/audit.js.map +1 -0
  9. package/dist/consolidator.d.ts +62 -0
  10. package/dist/consolidator.js +141 -0
  11. package/dist/consolidator.js.map +1 -0
  12. package/dist/crypto.d.ts +26 -0
  13. package/dist/crypto.js +72 -0
  14. package/dist/crypto.js.map +1 -0
  15. package/dist/engram.d.ts +253 -0
  16. package/dist/engram.js +660 -0
  17. package/dist/engram.js.map +1 -0
  18. package/dist/env.d.ts +28 -0
  19. package/dist/env.js +81 -0
  20. package/dist/env.js.map +1 -0
  21. package/dist/index.d.ts +17 -0
  22. package/dist/index.js +18 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/inspect.d.ts +19 -0
  25. package/dist/inspect.js +61 -0
  26. package/dist/inspect.js.map +1 -0
  27. package/dist/llm.d.ts +60 -0
  28. package/dist/llm.js +188 -0
  29. package/dist/llm.js.map +1 -0
  30. package/dist/memwal-account.d.ts +39 -0
  31. package/dist/memwal-account.js +75 -0
  32. package/dist/memwal-account.js.map +1 -0
  33. package/dist/merkle.d.ts +14 -0
  34. package/dist/merkle.js +69 -0
  35. package/dist/merkle.js.map +1 -0
  36. package/dist/mind.d.ts +130 -0
  37. package/dist/mind.js +156 -0
  38. package/dist/mind.js.map +1 -0
  39. package/dist/proof.d.ts +21 -0
  40. package/dist/proof.js +46 -0
  41. package/dist/proof.js.map +1 -0
  42. package/dist/remote.d.ts +112 -0
  43. package/dist/remote.js +232 -0
  44. package/dist/remote.js.map +1 -0
  45. package/dist/store.d.ts +28 -0
  46. package/dist/store.js +72 -0
  47. package/dist/store.js.map +1 -0
  48. package/dist/tatum.d.ts +83 -0
  49. package/dist/tatum.js +148 -0
  50. package/dist/tatum.js.map +1 -0
  51. package/dist/types.d.ts +122 -0
  52. package/dist/types.js +2 -0
  53. package/dist/types.js.map +1 -0
  54. package/dist/vault.d.ts +31 -0
  55. package/dist/vault.js +45 -0
  56. package/dist/vault.js.map +1 -0
  57. package/package.json +53 -3
@@ -0,0 +1,112 @@
1
+ export interface RemoteHit {
2
+ blobId: string;
3
+ text: string;
4
+ distance: number;
5
+ }
6
+ /**
7
+ * Durable remote for Engram objects. The real one is Walrus Memory;
8
+ * tests use the in-memory one.
9
+ */
10
+ export interface RemoteMemory {
11
+ /** Stores each text and returns its Walrus blob ID, in order. */
12
+ putMany(items: {
13
+ namespace: string;
14
+ text: string;
15
+ }[]): Promise<string[]>;
16
+ /**
17
+ * `deep`: also look where cheap search can't (e.g. Walrus Memory manual-mode
18
+ * records) — for verification, which needs one exact record.
19
+ */
20
+ search(namespace: string, query: string, limit?: number, opts?: SearchOptions): Promise<RemoteHit[]>;
21
+ }
22
+ export interface SearchOptions {
23
+ deep?: boolean;
24
+ }
25
+ export interface WalrusMemoryConfig {
26
+ key: string;
27
+ accountId: string;
28
+ serverUrl?: string;
29
+ /**
30
+ * Manual-mode fallback: when the relayer's own embedding service fails, Engram
31
+ * embeds locally, Seal-encrypts with the account owner's key and has the relayer
32
+ * only store the ciphertext + vector. Reads use the same path.
33
+ */
34
+ manual?: ManualModeConfig;
35
+ }
36
+ export interface ManualModeConfig {
37
+ /** Account owner's Sui private key (suiprivkey1…) — Seal encrypt/decrypt. */
38
+ suiPrivateKey: string;
39
+ /** Text → embedding vector (1536 dims, like the relayer's own). */
40
+ embed: (text: string) => Promise<number[]>;
41
+ /** Walrus Memory Move package and AccountRegistry (mainnet defaults). */
42
+ packageId?: string;
43
+ registryId?: string;
44
+ /** Sui client for Seal and Walrus reads (a gRPC client works). */
45
+ suiClient: unknown;
46
+ }
47
+ /** Walrus Memory on Sui Mainnet (read from the account object and its creating transaction). */
48
+ export declare const MEMWAL_MAINNET: {
49
+ packageId: string;
50
+ registryId: string;
51
+ };
52
+ export declare class WalrusMemoryRemote implements RemoteMemory {
53
+ private cfg;
54
+ private client;
55
+ private manualClient?;
56
+ /** Until when writes go straight to manual mode after a relayer failure. */
57
+ private manualUntil;
58
+ /** Set when the last write used the manual fallback (for logs and the UI). */
59
+ lastWriteMode: "relayer" | "manual";
60
+ constructor(cfg: WalrusMemoryConfig);
61
+ private manual;
62
+ putMany(items: {
63
+ namespace: string;
64
+ text: string;
65
+ }[]): Promise<string[]>;
66
+ private putManual;
67
+ private putRelayer;
68
+ /**
69
+ * Relayer recall first. Manual-mode recall (embed locally, decrypt here) runs
70
+ * when the relayer fails, or for a deep search — it is slower and only sees
71
+ * records written in manual mode. Results are merged by blob ID.
72
+ */
73
+ search(namespace: string, query: string, limit?: number, opts?: SearchOptions): Promise<RemoteHit[]>;
74
+ health(): Promise<boolean>;
75
+ }
76
+ /** Offline stand-in. Blob IDs are sha256 of the text, base64url. */
77
+ export declare class InMemoryRemote implements RemoteMemory {
78
+ readonly items: {
79
+ namespace: string;
80
+ text: string;
81
+ blobId: string;
82
+ }[];
83
+ putMany(items: {
84
+ namespace: string;
85
+ text: string;
86
+ }[]): Promise<string[]>;
87
+ search(namespace: string, query: string, limit?: number): Promise<RemoteHit[]>;
88
+ }
89
+ /**
90
+ * Writes go to `primary`; searches merge `primary` and `secondary`. Used when an
91
+ * agent moves to its owner's own Walrus Memory account: older memories stay
92
+ * readable (and verifiable) in the account they were written to.
93
+ */
94
+ export declare class CombinedRemote implements RemoteMemory {
95
+ readonly primary: RemoteMemory;
96
+ readonly secondary: RemoteMemory;
97
+ constructor(primary: RemoteMemory, secondary: RemoteMemory);
98
+ putMany(items: {
99
+ namespace: string;
100
+ text: string;
101
+ }[]): Promise<string[]>;
102
+ search(namespace: string, query: string, limit?: number, opts?: SearchOptions): Promise<RemoteHit[]>;
103
+ }
104
+ /**
105
+ * The relayer limits each key to 60 weighted requests a minute and answers 429
106
+ * with retry_after_seconds; it also has brief 5xx hiccups. Wait and retry
107
+ * instead of failing.
108
+ */
109
+ export declare function relayerRetry<T>(fn: () => Promise<T>, opts?: {
110
+ attempts?: number;
111
+ sleep?: (ms: number) => Promise<void>;
112
+ }): Promise<T>;
package/dist/remote.js ADDED
@@ -0,0 +1,232 @@
1
+ import { MemWal } from "@mysten-incubation/memwal";
2
+ import { MemWalManual } from "@mysten-incubation/memwal/manual";
3
+ import { sha256Bytes } from "./crypto.js";
4
+ /** Walrus Memory on Sui Mainnet (read from the account object and its creating transaction). */
5
+ export const MEMWAL_MAINNET = {
6
+ packageId: "0xe7c16fbea0560e7057e2bf7422feaa4fb313749fc69c9e9092fac7a33b81d7f5",
7
+ registryId: "0x8bf82c9e09e36b8d1c38298f68b7cb68e7b8762887e7592add9986d5e9cf199f",
8
+ };
9
+ /** Errors that mean the relayer's server-side pipeline is down (not our request). */
10
+ const RELAYER_DOWN = /embedding|internal error|internal server error|\b5\d\d\b|unavailable|timed? ?out/i;
11
+ export class WalrusMemoryRemote {
12
+ cfg;
13
+ client;
14
+ manualClient;
15
+ /** Until when writes go straight to manual mode after a relayer failure. */
16
+ manualUntil = 0;
17
+ /** Set when the last write used the manual fallback (for logs and the UI). */
18
+ lastWriteMode = "relayer";
19
+ constructor(cfg) {
20
+ this.cfg = cfg;
21
+ this.client = MemWal.create({
22
+ key: cfg.key,
23
+ accountId: cfg.accountId,
24
+ serverUrl: cfg.serverUrl ?? "https://relayer.memory.walrus.xyz",
25
+ requestTimeoutMs: 60_000,
26
+ });
27
+ }
28
+ manual() {
29
+ const m = this.cfg.manual;
30
+ if (!m)
31
+ return undefined;
32
+ if (!this.manualClient) {
33
+ this.manualClient = MemWalManual.create({
34
+ key: this.cfg.key,
35
+ accountId: this.cfg.accountId,
36
+ serverUrl: this.cfg.serverUrl ?? "https://relayer.memory.walrus.xyz",
37
+ suiPrivateKey: m.suiPrivateKey,
38
+ suiClient: m.suiClient,
39
+ embeddingApiKey: "local", // embedding is done by m.embed below
40
+ packageId: m.packageId ?? MEMWAL_MAINNET.packageId,
41
+ registryId: m.registryId ?? MEMWAL_MAINNET.registryId,
42
+ });
43
+ // The SDK only knows OpenAI-style embedding APIs; use ours instead.
44
+ this.manualClient.embed = m.embed;
45
+ }
46
+ return this.manualClient;
47
+ }
48
+ async putMany(items) {
49
+ if (items.length === 0)
50
+ return [];
51
+ const manual = this.manual();
52
+ if (manual && Date.now() < this.manualUntil)
53
+ return this.putManual(manual, items);
54
+ try {
55
+ const ids = await this.putRelayer(items);
56
+ this.lastWriteMode = "relayer";
57
+ return ids;
58
+ }
59
+ catch (err) {
60
+ if (!manual || !RELAYER_DOWN.test(err.message))
61
+ throw err;
62
+ this.manualUntil = Date.now() + 10 * 60_000;
63
+ return this.putManual(manual, items);
64
+ }
65
+ }
66
+ async putManual(manual, items) {
67
+ const out = [];
68
+ // Three at a time keeps Seal key servers and the embedder within rate limits.
69
+ for (let i = 0; i < items.length; i += 3) {
70
+ const batch = items.slice(i, i + 3);
71
+ const res = await Promise.all(batch.map((it) => relayerRetry(() => manual.rememberManual(it.text, it.namespace))));
72
+ for (const r of res) {
73
+ if (!r.blob_id)
74
+ throw new Error("Walrus Memory manual write returned no blob ID");
75
+ out.push(r.blob_id);
76
+ }
77
+ }
78
+ this.lastWriteMode = "manual";
79
+ return out;
80
+ }
81
+ async putRelayer(items) {
82
+ const out = [];
83
+ // Keep batches small so one slow item doesn't hold up everything.
84
+ for (let i = 0; i < items.length; i += 20) {
85
+ const batch = items.slice(i, i + 20);
86
+ const res = await relayerRetry(() => this.client.rememberBulkAndWait(batch, { timeoutMs: 300_000 }));
87
+ batch.forEach((_, j) => {
88
+ const r = res.results[j];
89
+ if (!r || r.status !== "done" || !r.blob_id) {
90
+ throw new Error(`Walrus Memory write failed: ${r?.error ?? r?.status ?? "no result"}`);
91
+ }
92
+ out.push(r.blob_id);
93
+ });
94
+ }
95
+ return out;
96
+ }
97
+ /**
98
+ * Relayer recall first. Manual-mode recall (embed locally, decrypt here) runs
99
+ * when the relayer fails, or for a deep search — it is slower and only sees
100
+ * records written in manual mode. Results are merged by blob ID.
101
+ */
102
+ async search(namespace, query, limit = 10, opts = {}) {
103
+ const manual = this.manual();
104
+ let auto = [];
105
+ let autoErr = null;
106
+ try {
107
+ const res = await relayerRetry(() => this.client.recall({ query, limit, namespace }));
108
+ auto = res.results.map((r) => ({ blobId: r.blob_id, text: r.text, distance: r.distance }));
109
+ }
110
+ catch (err) {
111
+ autoErr = err;
112
+ }
113
+ if (!manual || (!autoErr && !opts.deep)) {
114
+ if (autoErr)
115
+ throw autoErr;
116
+ return auto;
117
+ }
118
+ let man = [];
119
+ try {
120
+ man = await quietSealLogs(() => manual.recallManual(query, { limit, namespace })).then((res) => res.results.flatMap((r) => ("text" in r ? [{ blobId: r.blob_id, text: r.text, distance: r.distance }] : [])));
121
+ }
122
+ catch (err) {
123
+ if (autoErr)
124
+ throw autoErr;
125
+ }
126
+ const merged = new Map();
127
+ for (const r of [...auto, ...man]) {
128
+ const prev = merged.get(r.blobId);
129
+ if (!prev || r.distance < prev.distance)
130
+ merged.set(r.blobId, r);
131
+ }
132
+ return [...merged.values()].sort((x, y) => x.distance - y.distance).slice(0, limit);
133
+ }
134
+ async health() {
135
+ return (await this.client.health()).status === "ok";
136
+ }
137
+ }
138
+ /** Offline stand-in. Blob IDs are sha256 of the text, base64url. */
139
+ export class InMemoryRemote {
140
+ items = [];
141
+ async putMany(items) {
142
+ return items.map((it) => {
143
+ const blobId = Buffer.from(sha256Bytes(Buffer.from(it.namespace + "\n" + it.text))).toString("base64url");
144
+ this.items.push({ ...it, blobId });
145
+ return blobId;
146
+ });
147
+ }
148
+ async search(namespace, query, limit = 10) {
149
+ const words = query.toLowerCase().split(/\W+/).filter(Boolean);
150
+ return this.items
151
+ .filter((i) => i.namespace === namespace)
152
+ .map((i) => {
153
+ const t = i.text.toLowerCase();
154
+ const hits = words.filter((w) => t.includes(w)).length;
155
+ return { blobId: i.blobId, text: i.text, distance: words.length ? 1 - hits / words.length : 1 };
156
+ })
157
+ .sort((a, b) => a.distance - b.distance)
158
+ .slice(0, limit);
159
+ }
160
+ }
161
+ /**
162
+ * Writes go to `primary`; searches merge `primary` and `secondary`. Used when an
163
+ * agent moves to its owner's own Walrus Memory account: older memories stay
164
+ * readable (and verifiable) in the account they were written to.
165
+ */
166
+ export class CombinedRemote {
167
+ primary;
168
+ secondary;
169
+ constructor(primary, secondary) {
170
+ this.primary = primary;
171
+ this.secondary = secondary;
172
+ }
173
+ putMany(items) {
174
+ return this.primary.putMany(items);
175
+ }
176
+ async search(namespace, query, limit = 10, opts) {
177
+ const [a, b] = await Promise.allSettled([this.primary.search(namespace, query, limit, opts), this.secondary.search(namespace, query, limit, opts)]);
178
+ if (a.status === "rejected" && b.status === "rejected")
179
+ throw a.reason;
180
+ const merged = new Map();
181
+ for (const h of [...(a.status === "fulfilled" ? a.value : []), ...(b.status === "fulfilled" ? b.value : [])]) {
182
+ const prev = merged.get(h.blobId);
183
+ if (!prev || h.distance < prev.distance)
184
+ merged.set(h.blobId, h);
185
+ }
186
+ return [...merged.values()].sort((x, y) => x.distance - y.distance).slice(0, limit);
187
+ }
188
+ }
189
+ /**
190
+ * Manual recall tries to decrypt every hit in the namespace, including records
191
+ * written by the relayer under a different Seal identity; the SDK logs each of
192
+ * those expected failures. Keep them out of the agent's output.
193
+ */
194
+ async function quietSealLogs(fn) {
195
+ const orig = console.error;
196
+ console.error = (...args) => {
197
+ if (typeof args[0] === "string" && args[0].startsWith("[MemWalManual]"))
198
+ return;
199
+ orig(...args);
200
+ };
201
+ try {
202
+ return await fn();
203
+ }
204
+ finally {
205
+ console.error = orig;
206
+ }
207
+ }
208
+ /**
209
+ * The relayer limits each key to 60 weighted requests a minute and answers 429
210
+ * with retry_after_seconds; it also has brief 5xx hiccups. Wait and retry
211
+ * instead of failing.
212
+ */
213
+ export async function relayerRetry(fn, opts = {}) {
214
+ const attempts = opts.attempts ?? 4;
215
+ const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
216
+ for (let i = 0;; i++) {
217
+ try {
218
+ return await fn();
219
+ }
220
+ catch (err) {
221
+ const msg = String(err.message ?? err);
222
+ const limited = /\b429\b|rate limit/i.test(msg);
223
+ // Transient server errors (the relayer has been flaky) get a short backoff too.
224
+ const transient = /\b50[0234]\b|internal server error|ECONNRESET|fetch failed/i.test(msg);
225
+ if (i + 1 >= attempts || (!limited && !transient))
226
+ throw err;
227
+ const after = limited ? Number(/retry_after_seconds"?\s*:\s*(\d+)/.exec(msg)?.[1] ?? 30) : 5 * (i + 1);
228
+ await sleep(Math.min(after, 90) * 1000 + 500);
229
+ }
230
+ }
231
+ }
232
+ //# sourceMappingURL=remote.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remote.js","sourceRoot":"","sources":["../src/remote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAkD1C,gGAAgG;AAChG,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,SAAS,EAAE,oEAAoE;IAC/E,UAAU,EAAE,oEAAoE;CACjF,CAAC;AAEF,qFAAqF;AACrF,MAAM,YAAY,GAAG,mFAAmF,CAAC;AAEzG,MAAM,OAAO,kBAAkB;IAQT;IAPZ,MAAM,CAAS;IACf,YAAY,CAAgB;IACpC,4EAA4E;IACpE,WAAW,GAAG,CAAC,CAAC;IACxB,8EAA8E;IAC9E,aAAa,GAAyB,SAAS,CAAC;IAEhD,YAAoB,GAAuB;QAAvB,QAAG,GAAH,GAAG,CAAoB;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YAC1B,GAAG,EAAE,GAAG,CAAC,GAAG;YACZ,SAAS,EAAE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MAAM,SAAS,GAAG,6DAA6D,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC1F,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,IAAI,CAAC,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC;gBAAE,MAAM,GAAG,CAAC;YAC7D,MAAM,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,mCAAmC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACvG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,IAAI,GAAG,GAAG,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,28 @@
1
+ /** A JSON file written atomically (temp file + rename). */
2
+ export declare class JsonFile<T> {
3
+ readonly path: string;
4
+ constructor(path: string);
5
+ read(): T | null;
6
+ write(value: T): void;
7
+ }
8
+ /**
9
+ * The `.engram/` folder — Engram's local copy of the agent's mind, like `.git/`.
10
+ *
11
+ * config.json agent name, public key, namespaces
12
+ * agent.key Ed25519 signing key (secret)
13
+ * master.key wraps the data keys (secret)
14
+ * vault.json wrapped per-episode data keys
15
+ * HEAD current commit ID
16
+ * objects/<kind>/<id>.json
17
+ */
18
+ export declare class LocalStore {
19
+ readonly root: string;
20
+ constructor(root: string);
21
+ file<T>(...parts: string[]): JsonFile<T>;
22
+ exists(): boolean;
23
+ readText(name: string): string | null;
24
+ writeText(name: string, value: string): void;
25
+ put<T>(kind: string, id: string, value: T): void;
26
+ get<T>(kind: string, id: string): T | null;
27
+ list<T>(kind: string): T[];
28
+ }
package/dist/store.js ADDED
@@ -0,0 +1,72 @@
1
+ import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ /** A JSON file written atomically (temp file + rename). */
4
+ export class JsonFile {
5
+ path;
6
+ constructor(path) {
7
+ this.path = path;
8
+ }
9
+ read() {
10
+ if (!existsSync(this.path))
11
+ return null;
12
+ return JSON.parse(readFileSync(this.path, "utf8"));
13
+ }
14
+ write(value) {
15
+ mkdirSync(dirname(this.path), { recursive: true });
16
+ const tmp = `${this.path}.${process.pid}.tmp`;
17
+ writeFileSync(tmp, JSON.stringify(value, null, 2) + "\n", { mode: 0o600 });
18
+ renameSync(tmp, this.path);
19
+ }
20
+ }
21
+ /**
22
+ * The `.engram/` folder — Engram's local copy of the agent's mind, like `.git/`.
23
+ *
24
+ * config.json agent name, public key, namespaces
25
+ * agent.key Ed25519 signing key (secret)
26
+ * master.key wraps the data keys (secret)
27
+ * vault.json wrapped per-episode data keys
28
+ * HEAD current commit ID
29
+ * objects/<kind>/<id>.json
30
+ */
31
+ export class LocalStore {
32
+ root;
33
+ constructor(root) {
34
+ this.root = root;
35
+ }
36
+ file(...parts) {
37
+ return new JsonFile(join(this.root, ...parts));
38
+ }
39
+ exists() {
40
+ return existsSync(join(this.root, "config.json"));
41
+ }
42
+ readText(name) {
43
+ const p = join(this.root, name);
44
+ return existsSync(p) ? readFileSync(p, "utf8").trim() : null;
45
+ }
46
+ writeText(name, value) {
47
+ mkdirSync(this.root, { recursive: true });
48
+ writeFileSync(join(this.root, name), value + "\n", { mode: 0o600 });
49
+ }
50
+ put(kind, id, value) {
51
+ this.file("objects", kind, `${safe(id)}.json`).write(value);
52
+ }
53
+ get(kind, id) {
54
+ return this.file("objects", kind, `${safe(id)}.json`).read();
55
+ }
56
+ list(kind) {
57
+ const dir = join(this.root, "objects", kind);
58
+ if (!existsSync(dir))
59
+ return [];
60
+ return readdirSync(dir)
61
+ .filter((f) => f.endsWith(".json"))
62
+ .sort()
63
+ .map((f) => JSON.parse(readFileSync(join(dir, f), "utf8")));
64
+ }
65
+ }
66
+ /** Belief keys look like "b_rent@2"; '@' is fine on all platforms but be strict anyway. */
67
+ function safe(id) {
68
+ if (!/^[A-Za-z0-9_@.-]+$/.test(id))
69
+ throw new Error(`invalid object id: ${id}`);
70
+ return id;
71
+ }
72
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACtG,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,2DAA2D;AAC3D,MAAM,OAAO,QAAQ;IACE;IAArB,YAAqB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAErC,IAAI;QACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QACxC,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAM,CAAC;IAC1D,CAAC;IAED,KAAK,CAAC,KAAQ;QACZ,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACnD,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC;QAC9C,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3E,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,UAAU;IACA;IAArB,YAAqB,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,C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EAAE,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,EAAE,CAAC;QAChC,OAAO,WAAW,CAAC,GAAG,CAAC;aACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;aAClC,IAAI,EAAE;aACN,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAM,CAAC,CAAC;IACrE,CAAC;CACF;AAED,2FAA2F;AAC3F,SAAS,IAAI,CAAC,EAAU;IACtB,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;IAChF,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { SuiGrpcClient } from "@mysten/sui/grpc";
2
+ /** Walrus `Blob` Move type on Sui Mainnet. */
3
+ export declare const WALRUS_BLOB_TYPE_MAINNET = "0xfdc88f7d7cf30afab2f82e8380d11ee8f70efb90e863d1de8616fae1bb09ea77::blob::Blob";
4
+ /** Tatum's Sui Mainnet gRPC gateway (Sui JSON-RPC was switched off in July 2026). */
5
+ export declare const TATUM_SUI_GRPC_HOST = "sui-mainnet-grpc.gateway.tatum.io:443";
6
+ export interface TatumOptions {
7
+ apiKey: string;
8
+ network?: "mainnet";
9
+ /** Override the gRPC host (`host:port`). */
10
+ host?: string;
11
+ /** Use a ready-made client instead (tests). */
12
+ client?: SuiGrpcClient;
13
+ }
14
+ export interface SuiBlobObject {
15
+ objectId: string;
16
+ blobId: string;
17
+ size: number;
18
+ registeredEpoch: number;
19
+ certifiedEpoch: number | null;
20
+ previousTransaction: string;
21
+ }
22
+ export interface SuiTx {
23
+ digest: string;
24
+ checkpoint: string;
25
+ timestampMs: number;
26
+ }
27
+ /** Walrus stores blob_id as a u256; the SDK shows it as little-endian base64url. */
28
+ export declare function blobIdFromU256(u256: string): string;
29
+ /**
30
+ * Sui Mainnet through Tatum's gRPC gateway. All of Engram's mainnet reads (and
31
+ * mainnet anchor transactions) go through here.
32
+ */
33
+ export declare class TatumSui {
34
+ readonly host: string;
35
+ private apiKey;
36
+ private _client?;
37
+ constructor(opts: TatumOptions);
38
+ /** The Sui SDK client, connected to Tatum with native gRPC (Tatum doesn't serve gRPC-Web). */
39
+ get client(): SuiGrpcClient;
40
+ /** Retries Tatum's transient failures (rate limit, unavailable upstream). */
41
+ private retry;
42
+ latestCheckpoint(): Promise<string>;
43
+ getObject(id: string): Promise<SuiObjectData | null>;
44
+ /** Owner address of a Walrus Memory account (the wallet that owns the blobs). */
45
+ memwalAccountOwner(accountId: string): Promise<string>;
46
+ /** All Walrus Blob objects owned by an address. */
47
+ ownedBlobs(owner: string, blobType?: string): AsyncGenerator<SuiBlobObject>;
48
+ getTransaction(digest: string): Promise<SuiTx>;
49
+ /** Recent transactions that touched an address (sent or received), newest first. */
50
+ transactionsOf(address: string, limit?: number): Promise<SuiTxDetail[]>;
51
+ /** Decimals and symbol of a coin type, or null if it has no metadata. */
52
+ coinMetadata(coinType: string): Promise<{
53
+ decimals: number;
54
+ symbol: string;
55
+ } | null>;
56
+ }
57
+ export interface SuiObjectData {
58
+ objectId: string;
59
+ version: string;
60
+ type?: string;
61
+ owner?: unknown;
62
+ previousTransaction?: string;
63
+ content?: {
64
+ fields?: unknown;
65
+ };
66
+ }
67
+ export interface SuiTxDetail {
68
+ digest: string;
69
+ timestampMs?: string;
70
+ checkpoint?: string;
71
+ transaction?: {
72
+ data?: {
73
+ sender?: string;
74
+ };
75
+ };
76
+ balanceChanges?: {
77
+ owner: {
78
+ AddressOwner?: string;
79
+ } | unknown;
80
+ coinType: string;
81
+ amount: string;
82
+ }[];
83
+ }