@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.
- package/LICENSE +21 -0
- package/README.md +21 -2
- package/dist/anchor.d.ts +101 -0
- package/dist/anchor.js +215 -0
- package/dist/anchor.js.map +1 -0
- package/dist/audit.d.ts +48 -0
- package/dist/audit.js +93 -0
- package/dist/audit.js.map +1 -0
- package/dist/consolidator.d.ts +62 -0
- package/dist/consolidator.js +141 -0
- package/dist/consolidator.js.map +1 -0
- package/dist/crypto.d.ts +26 -0
- package/dist/crypto.js +72 -0
- package/dist/crypto.js.map +1 -0
- package/dist/engram.d.ts +253 -0
- package/dist/engram.js +660 -0
- package/dist/engram.js.map +1 -0
- package/dist/env.d.ts +28 -0
- package/dist/env.js +81 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/inspect.d.ts +19 -0
- package/dist/inspect.js +61 -0
- package/dist/inspect.js.map +1 -0
- package/dist/llm.d.ts +60 -0
- package/dist/llm.js +188 -0
- package/dist/llm.js.map +1 -0
- package/dist/memwal-account.d.ts +39 -0
- package/dist/memwal-account.js +75 -0
- package/dist/memwal-account.js.map +1 -0
- package/dist/merkle.d.ts +14 -0
- package/dist/merkle.js +69 -0
- package/dist/merkle.js.map +1 -0
- package/dist/mind.d.ts +130 -0
- package/dist/mind.js +156 -0
- package/dist/mind.js.map +1 -0
- package/dist/proof.d.ts +21 -0
- package/dist/proof.js +46 -0
- package/dist/proof.js.map +1 -0
- package/dist/remote.d.ts +112 -0
- package/dist/remote.js +232 -0
- package/dist/remote.js.map +1 -0
- package/dist/store.d.ts +28 -0
- package/dist/store.js +72 -0
- package/dist/store.js.map +1 -0
- package/dist/tatum.d.ts +83 -0
- package/dist/tatum.js +148 -0
- package/dist/tatum.js.map +1 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vault.d.ts +31 -0
- package/dist/vault.js +45 -0
- package/dist/vault.js.map +1 -0
- package/package.json +53 -3
package/dist/tatum.js
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { SuiGrpcClient } from "@mysten/sui/grpc";
|
|
2
|
+
import { GrpcTransport } from "@protobuf-ts/grpc-transport";
|
|
3
|
+
import { ChannelCredentials } from "@grpc/grpc-js";
|
|
4
|
+
/** Walrus `Blob` Move type on Sui Mainnet. */
|
|
5
|
+
export const WALRUS_BLOB_TYPE_MAINNET = "0xfdc88f7d7cf30afab2f82e8380d11ee8f70efb90e863d1de8616fae1bb09ea77::blob::Blob";
|
|
6
|
+
/** Tatum's Sui Mainnet gRPC gateway (Sui JSON-RPC was switched off in July 2026). */
|
|
7
|
+
export const TATUM_SUI_GRPC_HOST = "sui-mainnet-grpc.gateway.tatum.io:443";
|
|
8
|
+
/** Walrus stores blob_id as a u256; the SDK shows it as little-endian base64url. */
|
|
9
|
+
export function blobIdFromU256(u256) {
|
|
10
|
+
let x = BigInt(u256);
|
|
11
|
+
const b = Buffer.alloc(32);
|
|
12
|
+
for (let i = 0; i < 32; i++) {
|
|
13
|
+
b[i] = Number(x & 0xffn);
|
|
14
|
+
x >>= 8n;
|
|
15
|
+
}
|
|
16
|
+
return b.toString("base64url");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Sui Mainnet through Tatum's gRPC gateway. All of Engram's mainnet reads (and
|
|
20
|
+
* mainnet anchor transactions) go through here.
|
|
21
|
+
*/
|
|
22
|
+
export class TatumSui {
|
|
23
|
+
host;
|
|
24
|
+
apiKey;
|
|
25
|
+
_client;
|
|
26
|
+
constructor(opts) {
|
|
27
|
+
this.apiKey = opts.apiKey;
|
|
28
|
+
this.host = opts.host ?? TATUM_SUI_GRPC_HOST;
|
|
29
|
+
this._client = opts.client;
|
|
30
|
+
}
|
|
31
|
+
/** The Sui SDK client, connected to Tatum with native gRPC (Tatum doesn't serve gRPC-Web). */
|
|
32
|
+
get client() {
|
|
33
|
+
if (!this._client) {
|
|
34
|
+
const transport = new GrpcTransport({ host: this.host, channelCredentials: ChannelCredentials.createSsl(), meta: { "x-api-key": this.apiKey } });
|
|
35
|
+
this._client = new SuiGrpcClient({ network: "mainnet", transport });
|
|
36
|
+
}
|
|
37
|
+
return this._client;
|
|
38
|
+
}
|
|
39
|
+
/** Retries Tatum's transient failures (rate limit, unavailable upstream). */
|
|
40
|
+
async retry(what, fn) {
|
|
41
|
+
let last;
|
|
42
|
+
for (let attempt = 0; attempt < 4; attempt++) {
|
|
43
|
+
try {
|
|
44
|
+
return await fn();
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
last = err;
|
|
48
|
+
const msg = String(err.message ?? err);
|
|
49
|
+
if (!/UNAVAILABLE|RESOURCE_EXHAUSTED|DEADLINE|429|503|502|ECONNRESET|healthy upstream/i.test(msg))
|
|
50
|
+
break;
|
|
51
|
+
await new Promise((r) => setTimeout(r, 800 * (attempt + 1)));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
throw new Error(`Tatum Sui ${what}: ${last?.message ?? last}`);
|
|
55
|
+
}
|
|
56
|
+
async latestCheckpoint() {
|
|
57
|
+
return this.retry("service info", async () => {
|
|
58
|
+
const info = await this.client.ledgerService.getServiceInfo({}).response;
|
|
59
|
+
return String(info.checkpointHeight ?? "");
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async getObject(id) {
|
|
63
|
+
return this.retry("getObject", async () => {
|
|
64
|
+
try {
|
|
65
|
+
const { object: o } = await this.client.getObject({ objectId: id, include: { json: true, previousTransaction: true } });
|
|
66
|
+
return toObjectData(o);
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
if (/not ?found/i.test(String(err.message)))
|
|
70
|
+
return null;
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/** Owner address of a Walrus Memory account (the wallet that owns the blobs). */
|
|
76
|
+
async memwalAccountOwner(accountId) {
|
|
77
|
+
const o = await this.getObject(accountId);
|
|
78
|
+
const owner = o?.content?.fields?.owner;
|
|
79
|
+
if (!owner)
|
|
80
|
+
throw new Error(`Walrus Memory account ${accountId} not found on Sui`);
|
|
81
|
+
return owner;
|
|
82
|
+
}
|
|
83
|
+
/** All Walrus Blob objects owned by an address. */
|
|
84
|
+
async *ownedBlobs(owner, blobType = WALRUS_BLOB_TYPE_MAINNET) {
|
|
85
|
+
let cursor = null;
|
|
86
|
+
do {
|
|
87
|
+
const page = await this.retry("listOwnedObjects", () => this.client.listOwnedObjects({ owner, type: blobType, cursor, limit: 50, include: { json: true, previousTransaction: true } }));
|
|
88
|
+
for (const o of page.objects) {
|
|
89
|
+
const f = o.json;
|
|
90
|
+
if (!f)
|
|
91
|
+
continue;
|
|
92
|
+
yield {
|
|
93
|
+
objectId: o.objectId,
|
|
94
|
+
blobId: blobIdFromU256(String(f.blob_id)),
|
|
95
|
+
size: Number(f.size),
|
|
96
|
+
registeredEpoch: Number(f.registered_epoch),
|
|
97
|
+
certifiedEpoch: f.certified_epoch == null ? null : Number(f.certified_epoch),
|
|
98
|
+
previousTransaction: o.previousTransaction ?? "",
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
cursor = page.hasNextPage ? page.cursor : null;
|
|
102
|
+
} while (cursor);
|
|
103
|
+
}
|
|
104
|
+
async getTransaction(digest) {
|
|
105
|
+
return this.retry("getTransaction", async () => {
|
|
106
|
+
const r = await this.client.getTransaction({ digest });
|
|
107
|
+
const t = r.Transaction ?? r.FailedTransaction;
|
|
108
|
+
return { digest: t?.digest ?? digest, checkpoint: t?.checkpoint ?? "", timestampMs: Number(t?.timestampMs ?? 0) };
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Recent transactions that touched an address (sent or received), newest first. */
|
|
112
|
+
async transactionsOf(address, limit = 20) {
|
|
113
|
+
return this.retry("listTransactions", async () => {
|
|
114
|
+
const call = this.client.ledgerService.listTransactions({
|
|
115
|
+
readMask: { paths: ["digest", "timestamp", "checkpoint", "balance_changes", "transaction.sender"] },
|
|
116
|
+
filter: { terms: [{ literals: [{ negated: false, predicate: { oneofKind: "affectedAddress", affectedAddress: { address } } }] }] },
|
|
117
|
+
options: { limit, ordering: 1 /* descending */ },
|
|
118
|
+
});
|
|
119
|
+
const out = [];
|
|
120
|
+
for await (const frame of call.responses) {
|
|
121
|
+
const t = frame.transaction;
|
|
122
|
+
if (!t?.digest)
|
|
123
|
+
continue;
|
|
124
|
+
out.push({
|
|
125
|
+
digest: t.digest,
|
|
126
|
+
checkpoint: t.checkpoint != null ? String(t.checkpoint) : undefined,
|
|
127
|
+
timestampMs: t.timestamp ? String(Number(t.timestamp.seconds) * 1000 + Math.floor((t.timestamp.nanos ?? 0) / 1e6)) : undefined,
|
|
128
|
+
transaction: { data: { sender: t.transaction?.sender } },
|
|
129
|
+
balanceChanges: (t.balanceChanges ?? []).map((b) => ({ owner: { AddressOwner: b.address ?? "" }, coinType: b.coinType ?? "", amount: b.amount ?? "0" })),
|
|
130
|
+
});
|
|
131
|
+
if (out.length >= limit)
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
return out;
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
/** Decimals and symbol of a coin type, or null if it has no metadata. */
|
|
138
|
+
async coinMetadata(coinType) {
|
|
139
|
+
return this.retry("getCoinMetadata", async () => {
|
|
140
|
+
const r = await this.client.getCoinMetadata({ coinType });
|
|
141
|
+
return r.coinMetadata ? { decimals: r.coinMetadata.decimals, symbol: r.coinMetadata.symbol } : null;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function toObjectData(o) {
|
|
146
|
+
return { objectId: o.objectId, version: o.version, type: o.type, owner: o.owner, previousTransaction: o.previousTransaction ?? undefined, content: { fields: o.json ?? undefined } };
|
|
147
|
+
}
|
|
148
|
+
//# source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CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACtG,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,SAAS,YAAY,CAAC,CAAkJ;IACtK,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,mBAAmB,EAAE,CAAC,CAAC,mBAAmB,IAAI,SAAS,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,IAAI,SAAS,EAAE,EAAE,CAAC;AACvL,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/** Where an episode came from. */
|
|
2
|
+
export type EpisodeSource = "user" | "tool" | "tatum" | "agent" | "system";
|
|
3
|
+
/** Encrypted payload as stored on Walrus Memory and on disk. */
|
|
4
|
+
export interface Envelope {
|
|
5
|
+
/** Format marker so Engram can recognise its own memories. */
|
|
6
|
+
engram: "episode";
|
|
7
|
+
v: 1;
|
|
8
|
+
id: string;
|
|
9
|
+
keyId: string;
|
|
10
|
+
/** base64 AES-256-GCM nonce, ciphertext and auth tag. */
|
|
11
|
+
iv: string;
|
|
12
|
+
ct: string;
|
|
13
|
+
tag: string;
|
|
14
|
+
}
|
|
15
|
+
/** An immutable raw event. Its plaintext only exists encrypted. */
|
|
16
|
+
export interface Episode {
|
|
17
|
+
id: string;
|
|
18
|
+
ts: number;
|
|
19
|
+
source: EpisodeSource;
|
|
20
|
+
/** Short, non-sensitive label shown in logs (e.g. "transfer 450 USDC"). */
|
|
21
|
+
summary?: string;
|
|
22
|
+
/** sha256 of the canonical plaintext, before encryption. */
|
|
23
|
+
contentHash: string;
|
|
24
|
+
keyId: string;
|
|
25
|
+
envelope: Envelope;
|
|
26
|
+
/** Walrus blob ID, set once pushed. */
|
|
27
|
+
blobId?: string;
|
|
28
|
+
/** Set when the episode's key was destroyed. */
|
|
29
|
+
forgottenAt?: number;
|
|
30
|
+
/** Set once `sleep()` has processed it. */
|
|
31
|
+
consolidatedAt?: number;
|
|
32
|
+
}
|
|
33
|
+
/** The decrypted contents of an episode. */
|
|
34
|
+
export interface EpisodeContent {
|
|
35
|
+
source: EpisodeSource;
|
|
36
|
+
ts: number;
|
|
37
|
+
data: unknown;
|
|
38
|
+
}
|
|
39
|
+
export type BeliefStatus = "active" | "revised" | "retracted";
|
|
40
|
+
/** One version of a belief. A new version supersedes the previous one. */
|
|
41
|
+
export interface Belief {
|
|
42
|
+
/** Stable belief ID across versions, e.g. "b_rent". */
|
|
43
|
+
id: string;
|
|
44
|
+
version: number;
|
|
45
|
+
statement: string;
|
|
46
|
+
/** 0..1 */
|
|
47
|
+
confidence: number;
|
|
48
|
+
/** Episode IDs that support this version. */
|
|
49
|
+
evidence: string[];
|
|
50
|
+
tags: string[];
|
|
51
|
+
/** Key of the version this one replaced ("b_rent@1"). */
|
|
52
|
+
supersedes?: string;
|
|
53
|
+
status: BeliefStatus;
|
|
54
|
+
createdAt: number;
|
|
55
|
+
/** Why this version exists (from the consolidator). */
|
|
56
|
+
reason?: string;
|
|
57
|
+
blobId?: string;
|
|
58
|
+
}
|
|
59
|
+
export interface MerkleProofStep {
|
|
60
|
+
/** hex sha256 of the sibling node */
|
|
61
|
+
hash: string;
|
|
62
|
+
/** whether the sibling is on the left */
|
|
63
|
+
left: boolean;
|
|
64
|
+
}
|
|
65
|
+
/** The signed part of a commit. Hashing this gives the commit ID. */
|
|
66
|
+
export interface CommitManifest {
|
|
67
|
+
engram: "commit";
|
|
68
|
+
v: 1;
|
|
69
|
+
agent: string;
|
|
70
|
+
parent: string | null;
|
|
71
|
+
ts: number;
|
|
72
|
+
message: string;
|
|
73
|
+
merkleRoot: string;
|
|
74
|
+
/** "id@version" of every active belief, sorted. */
|
|
75
|
+
beliefs: string[];
|
|
76
|
+
/** Episode IDs whose keys were destroyed (ever), sorted. */
|
|
77
|
+
tombstones: string[];
|
|
78
|
+
/** Episode ID → Walrus blob ID, for every episode referenced by an active belief. */
|
|
79
|
+
episodes: Record<string, string>;
|
|
80
|
+
/** "id@version" → Walrus blob ID of that belief version. */
|
|
81
|
+
beliefBlobs: Record<string, string>;
|
|
82
|
+
agentPubKey: string;
|
|
83
|
+
}
|
|
84
|
+
export interface Anchor {
|
|
85
|
+
/**
|
|
86
|
+
* walrus-blob: the manifest's own Walrus Blob object on Sui (option A).
|
|
87
|
+
* move-event: an `engram_anchor::anchor::Anchored` event carrying the root publicly (option B).
|
|
88
|
+
*/
|
|
89
|
+
method: "walrus-blob" | "move-event";
|
|
90
|
+
/** walrus-blob: Sui object ID of the Walrus Blob. move-event: the package ID. */
|
|
91
|
+
objectId: string;
|
|
92
|
+
/** Sui transaction that created it. */
|
|
93
|
+
txDigest: string;
|
|
94
|
+
checkpoint?: string;
|
|
95
|
+
timestampMs?: number;
|
|
96
|
+
/** move-event: Sui network the anchor lives on. Absent means mainnet. */
|
|
97
|
+
network?: "mainnet" | "testnet";
|
|
98
|
+
}
|
|
99
|
+
export interface Commit {
|
|
100
|
+
id: string;
|
|
101
|
+
manifest: CommitManifest;
|
|
102
|
+
/** hex Ed25519 signature over the canonical manifest. */
|
|
103
|
+
signature: string;
|
|
104
|
+
manifestBlobId?: string;
|
|
105
|
+
anchor?: Anchor;
|
|
106
|
+
}
|
|
107
|
+
export interface Receipt {
|
|
108
|
+
engram: "receipt";
|
|
109
|
+
v: 1;
|
|
110
|
+
id: string;
|
|
111
|
+
agent: string;
|
|
112
|
+
commitId: string;
|
|
113
|
+
ts: number;
|
|
114
|
+
action: string;
|
|
115
|
+
inputHash: string;
|
|
116
|
+
/** "id@version" of beliefs used. */
|
|
117
|
+
beliefs: string[];
|
|
118
|
+
proofs: Record<string, MerkleProofStep[]>;
|
|
119
|
+
agentPubKey: string;
|
|
120
|
+
signature: string;
|
|
121
|
+
blobId?: string;
|
|
122
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/vault.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Sealed } from "./crypto.js";
|
|
2
|
+
import type { JsonFile } from "./store.js";
|
|
3
|
+
interface VaultFile {
|
|
4
|
+
v: 1;
|
|
5
|
+
/** keyId → data key wrapped (AES-GCM) with the master key */
|
|
6
|
+
keys: Record<string, Sealed & {
|
|
7
|
+
createdAt: number;
|
|
8
|
+
}>;
|
|
9
|
+
/** keyId → time it was destroyed */
|
|
10
|
+
destroyed: Record<string, number>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Holds one random data key per episode, each wrapped by a master key.
|
|
14
|
+
* Destroying a data key makes that episode unreadable everywhere — the
|
|
15
|
+
* ciphertext on Walrus stays, but can never be opened again.
|
|
16
|
+
*/
|
|
17
|
+
export declare class KeyVault {
|
|
18
|
+
private file;
|
|
19
|
+
private masterKey;
|
|
20
|
+
constructor(file: JsonFile<VaultFile>, masterKey: Uint8Array);
|
|
21
|
+
private load;
|
|
22
|
+
create(): {
|
|
23
|
+
keyId: string;
|
|
24
|
+
key: Buffer;
|
|
25
|
+
};
|
|
26
|
+
get(keyId: string): Buffer | null;
|
|
27
|
+
isDestroyed(keyId: string): boolean;
|
|
28
|
+
/** Removes the wrapped key from disk. Returns false if it was already gone. */
|
|
29
|
+
destroy(keyId: string): boolean;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
package/dist/vault.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { decrypt, encrypt, newDataKey, randomId } from "./crypto.js";
|
|
2
|
+
/**
|
|
3
|
+
* Holds one random data key per episode, each wrapped by a master key.
|
|
4
|
+
* Destroying a data key makes that episode unreadable everywhere — the
|
|
5
|
+
* ciphertext on Walrus stays, but can never be opened again.
|
|
6
|
+
*/
|
|
7
|
+
export class KeyVault {
|
|
8
|
+
file;
|
|
9
|
+
masterKey;
|
|
10
|
+
constructor(file, masterKey) {
|
|
11
|
+
this.file = file;
|
|
12
|
+
this.masterKey = masterKey;
|
|
13
|
+
if (masterKey.length !== 32)
|
|
14
|
+
throw new Error("master key must be 32 bytes");
|
|
15
|
+
}
|
|
16
|
+
load() {
|
|
17
|
+
return this.file.read() ?? { v: 1, keys: {}, destroyed: {} };
|
|
18
|
+
}
|
|
19
|
+
create() {
|
|
20
|
+
const vault = this.load();
|
|
21
|
+
const keyId = randomId("k", 8);
|
|
22
|
+
const key = newDataKey();
|
|
23
|
+
vault.keys[keyId] = { ...encrypt(key, this.masterKey, keyId), createdAt: Date.now() };
|
|
24
|
+
this.file.write(vault);
|
|
25
|
+
return { keyId, key };
|
|
26
|
+
}
|
|
27
|
+
get(keyId) {
|
|
28
|
+
const wrapped = this.load().keys[keyId];
|
|
29
|
+
return wrapped ? decrypt(wrapped, this.masterKey, keyId) : null;
|
|
30
|
+
}
|
|
31
|
+
isDestroyed(keyId) {
|
|
32
|
+
return keyId in this.load().destroyed;
|
|
33
|
+
}
|
|
34
|
+
/** Removes the wrapped key from disk. Returns false if it was already gone. */
|
|
35
|
+
destroy(keyId) {
|
|
36
|
+
const vault = this.load();
|
|
37
|
+
if (!vault.keys[keyId])
|
|
38
|
+
return false;
|
|
39
|
+
delete vault.keys[keyId];
|
|
40
|
+
vault.destroyed[keyId] = Date.now();
|
|
41
|
+
this.file.write(vault);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=vault.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vault.js","sourceRoot":"","sources":["../src/vault.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAe,MAAM,aAAa,CAAC;AAWlF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AA+E;IAC/E,OAAO,CAAC,KAAa;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACrC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzB,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,56 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rohankumar4179/engram-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Git for agent memory — versioned, provable memory on Walrus Memory",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@grpc/grpc-js": "1.13.4",
|
|
21
|
+
"@mysten-incubation/memwal": "^0.1.8",
|
|
22
|
+
"@mysten/seal": "1.5.1",
|
|
23
|
+
"@mysten/sui": "^2.37.0",
|
|
24
|
+
"@noble/curves": "^2.4.0",
|
|
25
|
+
"@noble/hashes": "^2.4.0",
|
|
26
|
+
"@protobuf-ts/grpc-transport": "2.11.1"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@scure/bip39": "2.4.0"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/rohan911438/Engram.git",
|
|
34
|
+
"directory": "packages/sdk"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://github.com/rohan911438/Engram#readme",
|
|
37
|
+
"keywords": [
|
|
38
|
+
"agents",
|
|
39
|
+
"memory",
|
|
40
|
+
"walrus",
|
|
41
|
+
"sui",
|
|
42
|
+
"merkle",
|
|
43
|
+
"ai"
|
|
44
|
+
],
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
},
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsc -p tsconfig.json",
|
|
53
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
54
|
+
"test": "vitest run"
|
|
55
|
+
}
|
|
6
56
|
}
|