@cmdoss/memwal-sdk 0.6.1 → 0.7.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/dist/ai-sdk/PDWVectorStore.d.ts.map +1 -1
- package/dist/ai-sdk/PDWVectorStore.js +4 -1
- package/dist/ai-sdk/PDWVectorStore.js.map +1 -1
- package/dist/ai-sdk/tools.d.ts +2 -2
- package/dist/ai-sdk/tools.js +2 -2
- package/dist/browser.d.ts +5 -6
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +7 -6
- package/dist/browser.js.map +1 -1
- package/dist/client/ClientMemoryManager.d.ts +1 -0
- package/dist/client/ClientMemoryManager.d.ts.map +1 -1
- package/dist/client/ClientMemoryManager.js +5 -1
- package/dist/client/ClientMemoryManager.js.map +1 -1
- package/dist/client/SimplePDWClient.d.ts +24 -1
- package/dist/client/SimplePDWClient.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.js +31 -9
- package/dist/client/SimplePDWClient.js.map +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.d.ts +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.js +1 -1
- package/dist/client/namespaces/IndexNamespace.d.ts +38 -9
- package/dist/client/namespaces/IndexNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/IndexNamespace.js +77 -10
- package/dist/client/namespaces/IndexNamespace.js.map +1 -1
- package/dist/client/namespaces/MemoryNamespace.d.ts +27 -0
- package/dist/client/namespaces/MemoryNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/MemoryNamespace.js +104 -0
- package/dist/client/namespaces/MemoryNamespace.js.map +1 -1
- package/dist/client/namespaces/SearchNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/SearchNamespace.js +25 -14
- package/dist/client/namespaces/SearchNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/AINamespace.d.ts +2 -2
- package/dist/client/namespaces/consolidated/AINamespace.js +2 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js +69 -1
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts +46 -0
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.js +34 -0
- package/dist/client/namespaces/consolidated/StorageNamespace.js.map +1 -1
- package/dist/graph/GraphService.js +2 -2
- package/dist/graph/GraphService.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/permissions/ConsentRepository.browser.d.ts +56 -0
- package/dist/permissions/ConsentRepository.browser.d.ts.map +1 -0
- package/dist/permissions/ConsentRepository.browser.js +198 -0
- package/dist/permissions/ConsentRepository.browser.js.map +1 -0
- package/dist/retrieval/MemoryRetrievalService.d.ts +31 -0
- package/dist/retrieval/MemoryRetrievalService.d.ts.map +1 -1
- package/dist/retrieval/MemoryRetrievalService.js +44 -4
- package/dist/retrieval/MemoryRetrievalService.js.map +1 -1
- package/dist/services/EmbeddingService.d.ts +28 -1
- package/dist/services/EmbeddingService.d.ts.map +1 -1
- package/dist/services/EmbeddingService.js +54 -0
- package/dist/services/EmbeddingService.js.map +1 -1
- package/dist/services/GeminiAIService.d.ts.map +1 -1
- package/dist/services/GeminiAIService.js +283 -27
- package/dist/services/GeminiAIService.js.map +1 -1
- package/dist/services/IndexManager.d.ts +5 -1
- package/dist/services/IndexManager.d.ts.map +1 -1
- package/dist/services/IndexManager.js +17 -40
- package/dist/services/IndexManager.js.map +1 -1
- package/dist/services/MemoryIndexService.d.ts +31 -2
- package/dist/services/MemoryIndexService.d.ts.map +1 -1
- package/dist/services/MemoryIndexService.js +75 -3
- package/dist/services/MemoryIndexService.js.map +1 -1
- package/dist/services/QueryService.js +1 -1
- package/dist/services/QueryService.js.map +1 -1
- package/dist/services/StorageService.d.ts +10 -0
- package/dist/services/StorageService.d.ts.map +1 -1
- package/dist/services/StorageService.js +13 -0
- package/dist/services/StorageService.js.map +1 -1
- package/dist/services/storage/QuiltBatchManager.d.ts +111 -4
- package/dist/services/storage/QuiltBatchManager.d.ts.map +1 -1
- package/dist/services/storage/QuiltBatchManager.js +450 -38
- package/dist/services/storage/QuiltBatchManager.js.map +1 -1
- package/dist/services/storage/index.d.ts +1 -1
- package/dist/services/storage/index.d.ts.map +1 -1
- package/dist/services/storage/index.js.map +1 -1
- package/dist/utils/LRUCache.d.ts +106 -0
- package/dist/utils/LRUCache.d.ts.map +1 -0
- package/dist/utils/LRUCache.js +281 -0
- package/dist/utils/LRUCache.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/memoryIndexOnChain.d.ts +212 -0
- package/dist/utils/memoryIndexOnChain.d.ts.map +1 -0
- package/dist/utils/memoryIndexOnChain.js +312 -0
- package/dist/utils/memoryIndexOnChain.js.map +1 -0
- package/dist/utils/rebuildIndexNode.d.ts +29 -0
- package/dist/utils/rebuildIndexNode.d.ts.map +1 -1
- package/dist/utils/rebuildIndexNode.js +387 -45
- package/dist/utils/rebuildIndexNode.js.map +1 -1
- package/dist/vector/HnswWasmService.d.ts +20 -5
- package/dist/vector/HnswWasmService.d.ts.map +1 -1
- package/dist/vector/HnswWasmService.js +73 -40
- package/dist/vector/HnswWasmService.js.map +1 -1
- package/dist/vector/IHnswService.d.ts +10 -1
- package/dist/vector/IHnswService.d.ts.map +1 -1
- package/dist/vector/IHnswService.js.map +1 -1
- package/dist/vector/NodeHnswService.d.ts +16 -0
- package/dist/vector/NodeHnswService.d.ts.map +1 -1
- package/dist/vector/NodeHnswService.js +108 -10
- package/dist/vector/NodeHnswService.js.map +1 -1
- package/dist/vector/createHnswService.d.ts +1 -1
- package/dist/vector/createHnswService.js +1 -1
- package/dist/vector/index.d.ts +1 -1
- package/dist/vector/index.js +1 -1
- package/package.json +157 -157
- package/src/ai-sdk/PDWVectorStore.ts +4 -1
- package/src/ai-sdk/tools.ts +2 -2
- package/src/browser.ts +15 -10
- package/src/client/ClientMemoryManager.ts +6 -1
- package/src/client/SimplePDWClient.ts +63 -10
- package/src/client/namespaces/EmbeddingsNamespace.ts +1 -1
- package/src/client/namespaces/IndexNamespace.ts +89 -11
- package/src/client/namespaces/MemoryNamespace.ts +137 -0
- package/src/client/namespaces/SearchNamespace.ts +27 -14
- package/src/client/namespaces/consolidated/AINamespace.ts +2 -2
- package/src/client/namespaces/consolidated/BlockchainNamespace.ts +73 -1
- package/src/client/namespaces/consolidated/StorageNamespace.ts +57 -0
- package/src/core/types/index.ts +1 -1
- package/src/generated/pdw/capability.ts +319 -319
- package/src/graph/GraphService.ts +2 -2
- package/src/index.ts +25 -1
- package/src/permissions/ConsentRepository.browser.ts +249 -0
- package/src/retrieval/MemoryRetrievalService.ts +78 -4
- package/src/services/EmbeddingService.ts +66 -1
- package/src/services/GeminiAIService.ts +283 -27
- package/src/services/IndexManager.ts +18 -45
- package/src/services/MemoryIndexService.ts +85 -3
- package/src/services/QueryService.ts +1 -1
- package/src/services/StorageService.ts +15 -0
- package/src/services/storage/QuiltBatchManager.ts +538 -42
- package/src/services/storage/index.ts +6 -1
- package/src/utils/LRUCache.ts +378 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/memoryIndexOnChain.ts +507 -0
- package/src/utils/rebuildIndexNode.ts +482 -52
- package/src/vector/HnswWasmService.ts +95 -43
- package/src/vector/IHnswService.ts +10 -1
- package/src/vector/NodeHnswService.ts +130 -10
- package/src/vector/createHnswService.ts +1 -1
- package/src/vector/index.ts +1 -1
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Index On-Chain Utilities
|
|
3
|
+
*
|
|
4
|
+
* Utilities for managing MemoryIndex object on Sui blockchain:
|
|
5
|
+
* - Reading current MemoryIndex state from chain
|
|
6
|
+
* - Updating blob IDs after Walrus sync
|
|
7
|
+
* - Creating new MemoryIndex if doesn't exist
|
|
8
|
+
*
|
|
9
|
+
* Environment Variables:
|
|
10
|
+
* - MEMORY_INDEX_ID: Sui object ID of the MemoryIndex
|
|
11
|
+
* - INDEX_BLOB_ID: Current Walrus blob ID for HNSW index (updated after sync)
|
|
12
|
+
* - GRAPH_BLOB_ID: Current Walrus blob ID for knowledge graph
|
|
13
|
+
*/
|
|
14
|
+
import { SuiClient } from '@mysten/sui/client';
|
|
15
|
+
import type { Signer } from '@mysten/sui/cryptography';
|
|
16
|
+
/**
|
|
17
|
+
* On-chain MemoryIndex object structure
|
|
18
|
+
*/
|
|
19
|
+
export interface OnChainMemoryIndex {
|
|
20
|
+
/** Sui object ID */
|
|
21
|
+
objectId: string;
|
|
22
|
+
/** Owner address */
|
|
23
|
+
owner: string;
|
|
24
|
+
/** Version number for optimistic locking */
|
|
25
|
+
version: number;
|
|
26
|
+
/** Walrus blob ID for HNSW index */
|
|
27
|
+
indexBlobId: string;
|
|
28
|
+
/** Walrus blob ID for knowledge graph */
|
|
29
|
+
graphBlobId: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Options for getting MemoryIndex from chain
|
|
33
|
+
*/
|
|
34
|
+
export interface GetMemoryIndexOptions {
|
|
35
|
+
/** Sui client instance */
|
|
36
|
+
client: SuiClient;
|
|
37
|
+
/** MemoryIndex object ID (from MEMORY_INDEX_ID env var) */
|
|
38
|
+
memoryIndexId: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Options for updating MemoryIndex on-chain
|
|
42
|
+
*/
|
|
43
|
+
export interface UpdateMemoryIndexOnChainOptions {
|
|
44
|
+
/** Sui client instance */
|
|
45
|
+
client: SuiClient;
|
|
46
|
+
/** Signer for transaction */
|
|
47
|
+
signer: Signer;
|
|
48
|
+
/** Package ID of the PDW contract */
|
|
49
|
+
packageId: string;
|
|
50
|
+
/** MemoryIndex object ID */
|
|
51
|
+
memoryIndexId: string;
|
|
52
|
+
/** Current version for optimistic locking */
|
|
53
|
+
expectedVersion: number;
|
|
54
|
+
/** New index blob ID from Walrus */
|
|
55
|
+
newIndexBlobId: string;
|
|
56
|
+
/** New graph blob ID from Walrus */
|
|
57
|
+
newGraphBlobId: string;
|
|
58
|
+
/** Optional gas budget */
|
|
59
|
+
gasBudget?: number;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Options for creating a new MemoryIndex
|
|
63
|
+
*/
|
|
64
|
+
export interface CreateMemoryIndexOnChainOptions {
|
|
65
|
+
/** Sui client instance */
|
|
66
|
+
client: SuiClient;
|
|
67
|
+
/** Signer for transaction */
|
|
68
|
+
signer: Signer;
|
|
69
|
+
/** Package ID of the PDW contract */
|
|
70
|
+
packageId: string;
|
|
71
|
+
/** Initial index blob ID (can be placeholder) */
|
|
72
|
+
indexBlobId: string;
|
|
73
|
+
/** Initial graph blob ID (can be placeholder) */
|
|
74
|
+
graphBlobId: string;
|
|
75
|
+
/** Optional gas budget */
|
|
76
|
+
gasBudget?: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Result of updating MemoryIndex
|
|
80
|
+
*/
|
|
81
|
+
export interface UpdateMemoryIndexResult {
|
|
82
|
+
success: boolean;
|
|
83
|
+
/** Transaction digest */
|
|
84
|
+
digest?: string;
|
|
85
|
+
/** New version number after update */
|
|
86
|
+
newVersion?: number;
|
|
87
|
+
/** Error message if failed */
|
|
88
|
+
error?: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Result of creating MemoryIndex
|
|
92
|
+
*/
|
|
93
|
+
export interface CreateMemoryIndexResult {
|
|
94
|
+
success: boolean;
|
|
95
|
+
/** Created MemoryIndex object ID */
|
|
96
|
+
memoryIndexId?: string;
|
|
97
|
+
/** Transaction digest */
|
|
98
|
+
digest?: string;
|
|
99
|
+
/** Error message if failed */
|
|
100
|
+
error?: string;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Read MemoryIndex object from Sui blockchain
|
|
104
|
+
*
|
|
105
|
+
* @param options - Options containing client and memoryIndexId
|
|
106
|
+
* @returns The MemoryIndex object data or null if not found
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const memoryIndex = await getMemoryIndex({
|
|
111
|
+
* client: suiClient,
|
|
112
|
+
* memoryIndexId: process.env.MEMORY_INDEX_ID!
|
|
113
|
+
* });
|
|
114
|
+
*
|
|
115
|
+
* if (memoryIndex) {
|
|
116
|
+
* console.log(`Version: ${memoryIndex.version}`);
|
|
117
|
+
* console.log(`Index Blob: ${memoryIndex.indexBlobId}`);
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function getMemoryIndex(options: GetMemoryIndexOptions): Promise<OnChainMemoryIndex | null>;
|
|
122
|
+
/**
|
|
123
|
+
* Update MemoryIndex on-chain with new blob IDs
|
|
124
|
+
*
|
|
125
|
+
* Call this after uploading index/graph to Walrus to update the on-chain reference.
|
|
126
|
+
* Uses optimistic locking (expectedVersion must match current version).
|
|
127
|
+
*
|
|
128
|
+
* @param options - Update options
|
|
129
|
+
* @returns Result with success status and new version
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // First, read current state
|
|
134
|
+
* const current = await getMemoryIndex({ client, memoryIndexId });
|
|
135
|
+
*
|
|
136
|
+
* // Then upload to Walrus and get new blob ID
|
|
137
|
+
* const newBlobId = await uploadIndexToWalrus();
|
|
138
|
+
*
|
|
139
|
+
* // Finally, update on-chain
|
|
140
|
+
* const result = await updateMemoryIndexOnChain({
|
|
141
|
+
* client,
|
|
142
|
+
* signer: keypair,
|
|
143
|
+
* packageId: process.env.PACKAGE_ID!,
|
|
144
|
+
* memoryIndexId: process.env.MEMORY_INDEX_ID!,
|
|
145
|
+
* expectedVersion: current.version,
|
|
146
|
+
* newIndexBlobId: newBlobId,
|
|
147
|
+
* newGraphBlobId: current.graphBlobId, // Keep existing if not changed
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function updateMemoryIndexOnChain(options: UpdateMemoryIndexOnChainOptions): Promise<UpdateMemoryIndexResult>;
|
|
152
|
+
/**
|
|
153
|
+
* Create a new MemoryIndex on-chain
|
|
154
|
+
*
|
|
155
|
+
* Use this when setting up a new wallet or if MEMORY_INDEX_ID doesn't exist.
|
|
156
|
+
*
|
|
157
|
+
* @param options - Creation options
|
|
158
|
+
* @returns Result with created object ID
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const result = await createMemoryIndexOnChain({
|
|
163
|
+
* client,
|
|
164
|
+
* signer: keypair,
|
|
165
|
+
* packageId: process.env.PACKAGE_ID!,
|
|
166
|
+
* indexBlobId: 'placeholder-index',
|
|
167
|
+
* graphBlobId: 'placeholder-graph',
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* if (result.success) {
|
|
171
|
+
* console.log(`Created MemoryIndex: ${result.memoryIndexId}`);
|
|
172
|
+
* // Save to .env: MEMORY_INDEX_ID=${result.memoryIndexId}
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export declare function createMemoryIndexOnChain(options: CreateMemoryIndexOnChainOptions): Promise<CreateMemoryIndexResult>;
|
|
177
|
+
/**
|
|
178
|
+
* Sync index to Walrus and update on-chain MemoryIndex
|
|
179
|
+
*
|
|
180
|
+
* Convenience function that combines:
|
|
181
|
+
* 1. Reading current MemoryIndex state
|
|
182
|
+
* 2. Uploading index to Walrus
|
|
183
|
+
* 3. Updating on-chain blob ID
|
|
184
|
+
*
|
|
185
|
+
* @param options - Combined sync options
|
|
186
|
+
* @returns Result with new blob ID and transaction digest
|
|
187
|
+
*/
|
|
188
|
+
export interface SyncAndUpdateOptions {
|
|
189
|
+
client: SuiClient;
|
|
190
|
+
signer: Signer;
|
|
191
|
+
packageId: string;
|
|
192
|
+
memoryIndexId: string;
|
|
193
|
+
/** Function to upload index to Walrus, returns new blob ID */
|
|
194
|
+
uploadToWalrus: () => Promise<string>;
|
|
195
|
+
/** Optional: also update graph blob ID */
|
|
196
|
+
newGraphBlobId?: string;
|
|
197
|
+
}
|
|
198
|
+
export interface SyncAndUpdateResult {
|
|
199
|
+
success: boolean;
|
|
200
|
+
newIndexBlobId?: string;
|
|
201
|
+
newGraphBlobId?: string;
|
|
202
|
+
digest?: string;
|
|
203
|
+
newVersion?: number;
|
|
204
|
+
error?: string;
|
|
205
|
+
}
|
|
206
|
+
export declare function syncIndexAndUpdateOnChain(options: SyncAndUpdateOptions): Promise<SyncAndUpdateResult>;
|
|
207
|
+
/**
|
|
208
|
+
* Upload placeholder blob to Walrus
|
|
209
|
+
* Used when creating initial MemoryIndex
|
|
210
|
+
*/
|
|
211
|
+
export declare function uploadPlaceholderToWalrus(walrusPublisherUrl: string, type: 'index' | 'graph'): Promise<string>;
|
|
212
|
+
//# sourceMappingURL=memoryIndexOnChain.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoryIndexOnChain.d.ts","sourceRoot":"","sources":["../../src/utils/memoryIndexOnChain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,oBAAoB;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,4CAA4C;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,oCAAoC;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,yCAAyC;IACzC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,W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-0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Memory Index On-Chain Utilities
|
|
3
|
+
*
|
|
4
|
+
* Utilities for managing MemoryIndex object on Sui blockchain:
|
|
5
|
+
* - Reading current MemoryIndex state from chain
|
|
6
|
+
* - Updating blob IDs after Walrus sync
|
|
7
|
+
* - Creating new MemoryIndex if doesn't exist
|
|
8
|
+
*
|
|
9
|
+
* Environment Variables:
|
|
10
|
+
* - MEMORY_INDEX_ID: Sui object ID of the MemoryIndex
|
|
11
|
+
* - INDEX_BLOB_ID: Current Walrus blob ID for HNSW index (updated after sync)
|
|
12
|
+
* - GRAPH_BLOB_ID: Current Walrus blob ID for knowledge graph
|
|
13
|
+
*/
|
|
14
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
15
|
+
/**
|
|
16
|
+
* Read MemoryIndex object from Sui blockchain
|
|
17
|
+
*
|
|
18
|
+
* @param options - Options containing client and memoryIndexId
|
|
19
|
+
* @returns The MemoryIndex object data or null if not found
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* const memoryIndex = await getMemoryIndex({
|
|
24
|
+
* client: suiClient,
|
|
25
|
+
* memoryIndexId: process.env.MEMORY_INDEX_ID!
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* if (memoryIndex) {
|
|
29
|
+
* console.log(`Version: ${memoryIndex.version}`);
|
|
30
|
+
* console.log(`Index Blob: ${memoryIndex.indexBlobId}`);
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export async function getMemoryIndex(options) {
|
|
35
|
+
const { client, memoryIndexId } = options;
|
|
36
|
+
if (!memoryIndexId) {
|
|
37
|
+
console.warn('⚠️ MEMORY_INDEX_ID not provided');
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
const object = await client.getObject({
|
|
42
|
+
id: memoryIndexId,
|
|
43
|
+
options: {
|
|
44
|
+
showContent: true,
|
|
45
|
+
showOwner: true,
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
if (!object.data?.content || object.data.content.dataType !== 'moveObject') {
|
|
49
|
+
console.warn(`⚠️ MemoryIndex object ${memoryIndexId} not found or not a Move object`);
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const fields = object.data.content.fields;
|
|
53
|
+
const owner = object.data.owner;
|
|
54
|
+
// Extract owner address
|
|
55
|
+
let ownerAddress = '';
|
|
56
|
+
if (owner && typeof owner === 'object' && 'AddressOwner' in owner) {
|
|
57
|
+
ownerAddress = owner.AddressOwner;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
objectId: memoryIndexId,
|
|
61
|
+
owner: ownerAddress,
|
|
62
|
+
version: Number(fields.version || 1),
|
|
63
|
+
indexBlobId: fields.index_blob_id || '',
|
|
64
|
+
graphBlobId: fields.graph_blob_id || '',
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error(`❌ Failed to read MemoryIndex ${memoryIndexId}:`, error);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Update MemoryIndex on-chain with new blob IDs
|
|
74
|
+
*
|
|
75
|
+
* Call this after uploading index/graph to Walrus to update the on-chain reference.
|
|
76
|
+
* Uses optimistic locking (expectedVersion must match current version).
|
|
77
|
+
*
|
|
78
|
+
* @param options - Update options
|
|
79
|
+
* @returns Result with success status and new version
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // First, read current state
|
|
84
|
+
* const current = await getMemoryIndex({ client, memoryIndexId });
|
|
85
|
+
*
|
|
86
|
+
* // Then upload to Walrus and get new blob ID
|
|
87
|
+
* const newBlobId = await uploadIndexToWalrus();
|
|
88
|
+
*
|
|
89
|
+
* // Finally, update on-chain
|
|
90
|
+
* const result = await updateMemoryIndexOnChain({
|
|
91
|
+
* client,
|
|
92
|
+
* signer: keypair,
|
|
93
|
+
* packageId: process.env.PACKAGE_ID!,
|
|
94
|
+
* memoryIndexId: process.env.MEMORY_INDEX_ID!,
|
|
95
|
+
* expectedVersion: current.version,
|
|
96
|
+
* newIndexBlobId: newBlobId,
|
|
97
|
+
* newGraphBlobId: current.graphBlobId, // Keep existing if not changed
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export async function updateMemoryIndexOnChain(options) {
|
|
102
|
+
const { client, signer, packageId, memoryIndexId, expectedVersion, newIndexBlobId, newGraphBlobId, gasBudget = 10000000, } = options;
|
|
103
|
+
try {
|
|
104
|
+
console.log(`\n📝 Updating MemoryIndex on-chain...`);
|
|
105
|
+
console.log(` Object ID: ${memoryIndexId}`);
|
|
106
|
+
console.log(` Expected version: ${expectedVersion}`);
|
|
107
|
+
console.log(` New index blob: ${newIndexBlobId}`);
|
|
108
|
+
console.log(` New graph blob: ${newGraphBlobId}`);
|
|
109
|
+
const tx = new Transaction();
|
|
110
|
+
tx.setGasBudget(gasBudget);
|
|
111
|
+
// Convert strings to vector<u8> for Move
|
|
112
|
+
const newIndexBlobIdBytes = Array.from(new TextEncoder().encode(newIndexBlobId));
|
|
113
|
+
const newGraphBlobIdBytes = Array.from(new TextEncoder().encode(newGraphBlobId));
|
|
114
|
+
tx.moveCall({
|
|
115
|
+
target: `${packageId}::memory::update_memory_index`,
|
|
116
|
+
arguments: [
|
|
117
|
+
tx.object(memoryIndexId), // &mut MemoryIndex
|
|
118
|
+
tx.pure.u64(expectedVersion), // expected_version: u64
|
|
119
|
+
tx.pure.vector('u8', newIndexBlobIdBytes), // new_index_blob_id: vector<u8>
|
|
120
|
+
tx.pure.vector('u8', newGraphBlobIdBytes), // new_graph_blob_id: vector<u8>
|
|
121
|
+
]
|
|
122
|
+
});
|
|
123
|
+
const result = await client.signAndExecuteTransaction({
|
|
124
|
+
transaction: tx,
|
|
125
|
+
signer,
|
|
126
|
+
options: {
|
|
127
|
+
showEffects: true,
|
|
128
|
+
showObjectChanges: true,
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
if (result.effects?.status?.status !== 'success') {
|
|
132
|
+
const error = result.effects?.status?.error || 'Unknown error';
|
|
133
|
+
console.error(`❌ Transaction failed: ${error}`);
|
|
134
|
+
return { success: false, error };
|
|
135
|
+
}
|
|
136
|
+
const newVersion = expectedVersion + 1;
|
|
137
|
+
console.log(`✅ MemoryIndex updated successfully`);
|
|
138
|
+
console.log(` Transaction: ${result.digest}`);
|
|
139
|
+
console.log(` New version: ${newVersion}`);
|
|
140
|
+
return {
|
|
141
|
+
success: true,
|
|
142
|
+
digest: result.digest,
|
|
143
|
+
newVersion,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
148
|
+
console.error(`❌ Failed to update MemoryIndex:`, errorMsg);
|
|
149
|
+
return { success: false, error: errorMsg };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Create a new MemoryIndex on-chain
|
|
154
|
+
*
|
|
155
|
+
* Use this when setting up a new wallet or if MEMORY_INDEX_ID doesn't exist.
|
|
156
|
+
*
|
|
157
|
+
* @param options - Creation options
|
|
158
|
+
* @returns Result with created object ID
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const result = await createMemoryIndexOnChain({
|
|
163
|
+
* client,
|
|
164
|
+
* signer: keypair,
|
|
165
|
+
* packageId: process.env.PACKAGE_ID!,
|
|
166
|
+
* indexBlobId: 'placeholder-index',
|
|
167
|
+
* graphBlobId: 'placeholder-graph',
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* if (result.success) {
|
|
171
|
+
* console.log(`Created MemoryIndex: ${result.memoryIndexId}`);
|
|
172
|
+
* // Save to .env: MEMORY_INDEX_ID=${result.memoryIndexId}
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export async function createMemoryIndexOnChain(options) {
|
|
177
|
+
const { client, signer, packageId, indexBlobId, graphBlobId, gasBudget = 10000000, } = options;
|
|
178
|
+
try {
|
|
179
|
+
console.log(`\n📝 Creating new MemoryIndex on-chain...`);
|
|
180
|
+
console.log(` Package ID: ${packageId}`);
|
|
181
|
+
console.log(` Index blob: ${indexBlobId}`);
|
|
182
|
+
console.log(` Graph blob: ${graphBlobId}`);
|
|
183
|
+
const tx = new Transaction();
|
|
184
|
+
tx.setGasBudget(gasBudget);
|
|
185
|
+
// Convert strings to vector<u8> for Move
|
|
186
|
+
const indexBlobIdBytes = Array.from(new TextEncoder().encode(indexBlobId));
|
|
187
|
+
const graphBlobIdBytes = Array.from(new TextEncoder().encode(graphBlobId));
|
|
188
|
+
tx.moveCall({
|
|
189
|
+
target: `${packageId}::memory::create_memory_index`,
|
|
190
|
+
arguments: [
|
|
191
|
+
tx.pure.vector('u8', indexBlobIdBytes),
|
|
192
|
+
tx.pure.vector('u8', graphBlobIdBytes),
|
|
193
|
+
]
|
|
194
|
+
});
|
|
195
|
+
const result = await client.signAndExecuteTransaction({
|
|
196
|
+
transaction: tx,
|
|
197
|
+
signer,
|
|
198
|
+
options: {
|
|
199
|
+
showEffects: true,
|
|
200
|
+
showObjectChanges: true,
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
if (result.effects?.status?.status !== 'success') {
|
|
204
|
+
const error = result.effects?.status?.error || 'Unknown error';
|
|
205
|
+
console.error(`❌ Transaction failed: ${error}`);
|
|
206
|
+
return { success: false, error };
|
|
207
|
+
}
|
|
208
|
+
// Find the created MemoryIndex object
|
|
209
|
+
const createdObject = result.objectChanges?.find((change) => change.type === 'created' && change.objectType?.includes('::memory::MemoryIndex'));
|
|
210
|
+
if (!createdObject || createdObject.type !== 'created') {
|
|
211
|
+
return { success: false, error: 'MemoryIndex object not found in transaction result' };
|
|
212
|
+
}
|
|
213
|
+
const memoryIndexId = createdObject.objectId;
|
|
214
|
+
console.log(`✅ MemoryIndex created successfully`);
|
|
215
|
+
console.log(` Object ID: ${memoryIndexId}`);
|
|
216
|
+
console.log(` Transaction: ${result.digest}`);
|
|
217
|
+
console.log(`\n Add to .env:`);
|
|
218
|
+
console.log(` MEMORY_INDEX_ID=${memoryIndexId}`);
|
|
219
|
+
return {
|
|
220
|
+
success: true,
|
|
221
|
+
memoryIndexId,
|
|
222
|
+
digest: result.digest,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
227
|
+
console.error(`❌ Failed to create MemoryIndex:`, errorMsg);
|
|
228
|
+
return { success: false, error: errorMsg };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
export async function syncIndexAndUpdateOnChain(options) {
|
|
232
|
+
const { client, signer, packageId, memoryIndexId, uploadToWalrus, newGraphBlobId, } = options;
|
|
233
|
+
try {
|
|
234
|
+
// Step 1: Read current state
|
|
235
|
+
console.log(`\n🔍 Reading current MemoryIndex state...`);
|
|
236
|
+
const current = await getMemoryIndex({ client, memoryIndexId });
|
|
237
|
+
if (!current) {
|
|
238
|
+
return { success: false, error: 'MemoryIndex not found on-chain' };
|
|
239
|
+
}
|
|
240
|
+
console.log(` Current version: ${current.version}`);
|
|
241
|
+
console.log(` Current index blob: ${current.indexBlobId}`);
|
|
242
|
+
// Step 2: Upload to Walrus
|
|
243
|
+
console.log(`\n☁️ Uploading index to Walrus...`);
|
|
244
|
+
const newIndexBlobId = await uploadToWalrus();
|
|
245
|
+
console.log(` New index blob: ${newIndexBlobId}`);
|
|
246
|
+
// Step 3: Update on-chain
|
|
247
|
+
const graphBlobId = newGraphBlobId || current.graphBlobId;
|
|
248
|
+
const updateResult = await updateMemoryIndexOnChain({
|
|
249
|
+
client,
|
|
250
|
+
signer,
|
|
251
|
+
packageId,
|
|
252
|
+
memoryIndexId,
|
|
253
|
+
expectedVersion: current.version,
|
|
254
|
+
newIndexBlobId,
|
|
255
|
+
newGraphBlobId: graphBlobId,
|
|
256
|
+
});
|
|
257
|
+
if (!updateResult.success) {
|
|
258
|
+
return { success: false, error: updateResult.error };
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
success: true,
|
|
262
|
+
newIndexBlobId,
|
|
263
|
+
newGraphBlobId: graphBlobId,
|
|
264
|
+
digest: updateResult.digest,
|
|
265
|
+
newVersion: updateResult.newVersion,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
270
|
+
return { success: false, error: errorMsg };
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Upload placeholder blob to Walrus
|
|
275
|
+
* Used when creating initial MemoryIndex
|
|
276
|
+
*/
|
|
277
|
+
export async function uploadPlaceholderToWalrus(walrusPublisherUrl, type) {
|
|
278
|
+
const content = JSON.stringify({
|
|
279
|
+
type: type === 'index' ? 'hnsw-index-placeholder' : 'knowledge-graph',
|
|
280
|
+
version: 1,
|
|
281
|
+
created: new Date().toISOString(),
|
|
282
|
+
note: type === 'index'
|
|
283
|
+
? 'Placeholder for HNSW index. Actual index synced after adding memories.'
|
|
284
|
+
: 'Empty knowledge graph. Will be populated as memories are processed.',
|
|
285
|
+
...(type === 'graph' ? { nodes: [], edges: [] } : {}),
|
|
286
|
+
});
|
|
287
|
+
const response = await fetch(walrusPublisherUrl, {
|
|
288
|
+
method: 'PUT',
|
|
289
|
+
headers: { 'Content-Type': 'application/octet-stream' },
|
|
290
|
+
body: new TextEncoder().encode(content),
|
|
291
|
+
});
|
|
292
|
+
if (!response.ok) {
|
|
293
|
+
throw new Error(`Walrus upload failed: ${response.status}`);
|
|
294
|
+
}
|
|
295
|
+
const result = await response.json();
|
|
296
|
+
// Handle different response formats
|
|
297
|
+
let blobId;
|
|
298
|
+
if (result.newlyCreated?.blobObject?.blobId) {
|
|
299
|
+
blobId = result.newlyCreated.blobObject.blobId;
|
|
300
|
+
}
|
|
301
|
+
else if (result.alreadyCertified?.blobId) {
|
|
302
|
+
blobId = result.alreadyCertified.blobId;
|
|
303
|
+
}
|
|
304
|
+
else if (result.blobId) {
|
|
305
|
+
blobId = result.blobId;
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
throw new Error('Could not extract blobId from Walrus response');
|
|
309
|
+
}
|
|
310
|
+
return blobId;
|
|
311
|
+
}
|
|
312
|
+
//# sourceMappingURL=memoryIndexOnChain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoryIndexOnChain.js","sourceRoot":"","sources":["../../src/utils/memoryIndexOnChain.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AA+FvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA8B;IAE9B,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAE1C,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC;YACpC,EAAE,EAAE,aAAa;YACjB,OAAO,EAAE;gBACP,WAAW,EAAE,IAAI;gBACjB,SAAS,EAAE,IAAI;aAChB;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,YAAY,EAAE,CAAC;YAC3E,OAAO,CAAC,IAAI,CAAC,yBAAyB,aAAa,iCAAiC,CAAC,CAAC;YACtF,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,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G,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC;IAC1C,CAAC;SAAM,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QACzB,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;IACnE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -43,6 +43,18 @@ export interface RebuildIndexNodeOptions {
|
|
|
43
43
|
onProgress?: (current: number, total: number, status: string) => void;
|
|
44
44
|
/** Whether to force re-index even if index exists */
|
|
45
45
|
force?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Quilt IDs to include in the rebuild.
|
|
48
|
+
* Quilts contain batch-uploaded memories that may not have on-chain Memory objects.
|
|
49
|
+
* Pass Quilt IDs here to include them in the index rebuild.
|
|
50
|
+
*/
|
|
51
|
+
quiltIds?: string[];
|
|
52
|
+
/**
|
|
53
|
+
* Number of concurrent blob fetches (default: 10)
|
|
54
|
+
* Higher values can speed up rebuilding but may overwhelm the server
|
|
55
|
+
* Benchmark results: 10 is ~1.64x faster than sequential
|
|
56
|
+
*/
|
|
57
|
+
fetchConcurrency?: number;
|
|
46
58
|
}
|
|
47
59
|
export interface RebuildIndexNodeResult {
|
|
48
60
|
success: boolean;
|
|
@@ -54,6 +66,23 @@ export interface RebuildIndexNodeResult {
|
|
|
54
66
|
error: string;
|
|
55
67
|
}>;
|
|
56
68
|
duration: number;
|
|
69
|
+
/** Detailed timing breakdown for performance analysis */
|
|
70
|
+
timing?: {
|
|
71
|
+
/** Time to initialize services (ms) */
|
|
72
|
+
initMs: number;
|
|
73
|
+
/** Time to fetch blockchain data (ms) */
|
|
74
|
+
blockchainFetchMs: number;
|
|
75
|
+
/** Time to fetch all blobs from Walrus (ms) */
|
|
76
|
+
walrusFetchMs: number;
|
|
77
|
+
/** Time to process memories and build index (ms) */
|
|
78
|
+
processingMs: number;
|
|
79
|
+
/** Time to save index to disk (ms) */
|
|
80
|
+
saveMs: number;
|
|
81
|
+
/** Total blobs fetched */
|
|
82
|
+
blobsFetched: number;
|
|
83
|
+
/** Total content bytes downloaded */
|
|
84
|
+
totalBytesDownloaded: number;
|
|
85
|
+
};
|
|
57
86
|
}
|
|
58
87
|
/**
|
|
59
88
|
* Rebuild HNSW index from blockchain + Walrus (Node.js)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rebuildIndexNode.d.ts","sourceRoot":"","sources":["../../src/utils/rebuildIndexNode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,MAAM,WAAW,uBAAuB;IACtC,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAC;IAEpB,0BAA0B;IAC1B,MAAM,EAAE,SAAS,CAAC;IAElB,4CAA4C;IAC5C,SAAS,EAAE,MAAM,CAAC;IAElB,0CAA0C;IAC1C,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAEhC,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,8CAA8C;IAC9C,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,wBAAwB;IACxB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAEtE,qDAAqD;IACrD,KAAK,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"rebuildIndexNode.d.ts","sourceRoot":"","sources":["../../src/utils/rebuildIndexNode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAGpD,MAAM,WAAW,uBAAuB;IACtC,gCAAgC;IAChC,WAAW,EAAE,MA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