@cmdoss/memwal-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/ARCHITECTURE.md +547 -463
- package/BENCHMARKS.md +238 -238
- package/README.md +181 -142
- 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/types.d.ts +2 -2
- package/dist/ai-sdk/types.d.ts.map +1 -1
- package/dist/browser.d.ts +12 -13
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +18 -12
- 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 +23 -0
- package/dist/client/SimplePDWClient.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.js +19 -6
- package/dist/client/SimplePDWClient.js.map +1 -1
- package/dist/client/namespaces/BatchNamespace.js +2 -2
- package/dist/client/namespaces/BatchNamespace.js.map +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.js +3 -3
- 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/StorageNamespace.js +4 -4
- package/dist/client/namespaces/StorageNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js +49 -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 +36 -2
- package/dist/client/namespaces/consolidated/StorageNamespace.js.map +1 -1
- package/dist/client/signers/DappKitSigner.d.ts +136 -0
- package/dist/client/signers/DappKitSigner.d.ts.map +1 -0
- package/dist/client/signers/DappKitSigner.js +128 -0
- package/dist/client/signers/DappKitSigner.js.map +1 -0
- package/dist/client/signers/KeypairSigner.d.ts +4 -0
- package/dist/client/signers/KeypairSigner.d.ts.map +1 -1
- package/dist/client/signers/KeypairSigner.js +6 -0
- package/dist/client/signers/KeypairSigner.js.map +1 -1
- package/dist/client/signers/UnifiedSigner.d.ts +10 -0
- package/dist/client/signers/UnifiedSigner.d.ts.map +1 -1
- package/dist/client/signers/WalletAdapterSigner.d.ts +7 -0
- package/dist/client/signers/WalletAdapterSigner.d.ts.map +1 -1
- package/dist/client/signers/WalletAdapterSigner.js +9 -0
- package/dist/client/signers/WalletAdapterSigner.js.map +1 -1
- package/dist/client/signers/index.d.ts +3 -0
- package/dist/client/signers/index.d.ts.map +1 -1
- package/dist/client/signers/index.js +2 -0
- package/dist/client/signers/index.js.map +1 -1
- package/dist/generated/utils/index.js +1 -1
- package/dist/generated/utils/index.js.map +1 -1
- package/dist/graph/GraphService.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- 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/services/CapabilityService.js +1 -1
- package/dist/services/CapabilityService.js.map +1 -1
- package/dist/services/EncryptionService.js +1 -1
- package/dist/services/EncryptionService.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/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/StorageService.d.ts +8 -8
- package/dist/services/StorageService.d.ts.map +1 -1
- package/dist/services/StorageService.js.map +1 -1
- package/dist/services/VectorService.js +2 -2
- package/dist/services/VectorService.js.map +1 -1
- package/dist/services/storage/BlobAttributesManager.d.ts +4 -4
- package/dist/services/storage/BlobAttributesManager.d.ts.map +1 -1
- package/dist/services/storage/BlobAttributesManager.js +6 -15
- package/dist/services/storage/BlobAttributesManager.js.map +1 -1
- package/dist/services/storage/QuiltBatchManager.d.ts +33 -8
- package/dist/services/storage/QuiltBatchManager.d.ts.map +1 -1
- package/dist/services/storage/QuiltBatchManager.js +153 -48
- package/dist/services/storage/QuiltBatchManager.js.map +1 -1
- package/dist/services/storage/WalrusMetadataManager.d.ts +2 -2
- package/dist/services/storage/WalrusMetadataManager.d.ts.map +1 -1
- package/dist/services/storage/WalrusMetadataManager.js +2 -5
- package/dist/services/storage/WalrusMetadataManager.js.map +1 -1
- package/dist/services/storage/WalrusStorageManager.d.ts +2 -2
- package/dist/services/storage/WalrusStorageManager.d.ts.map +1 -1
- package/dist/services/storage/WalrusStorageManager.js +7 -11
- package/dist/services/storage/WalrusStorageManager.js.map +1 -1
- package/dist/utils/rebuildIndexNode.d.ts.map +1 -1
- package/dist/utils/rebuildIndexNode.js +109 -35
- package/dist/utils/rebuildIndexNode.js.map +1 -1
- package/dist/vector/NodeHnswService.d.ts.map +1 -1
- package/dist/vector/NodeHnswService.js +26 -7
- package/dist/vector/NodeHnswService.js.map +1 -1
- package/dist/wallet/MainWalletService.js +1 -1
- package/dist/wallet/MainWalletService.js.map +1 -1
- package/package.json +10 -3
- package/src/access/index.ts +8 -8
- package/src/aggregation/index.ts +8 -8
- package/src/ai-sdk/PDWVectorStore.ts +4 -1
- package/src/ai-sdk/types.ts +2 -2
- package/src/browser.ts +28 -24
- package/src/client/ClientMemoryManager.ts +6 -1
- package/src/client/SimplePDWClient.ts +57 -15
- package/src/client/namespaces/BatchNamespace.ts +2 -2
- package/src/client/namespaces/IndexNamespace.ts +89 -11
- package/src/client/namespaces/MemoryNamespace.ts +3 -3
- package/src/client/namespaces/SearchNamespace.ts +27 -14
- package/src/client/namespaces/StorageNamespace.ts +4 -4
- package/src/client/namespaces/consolidated/BlockchainNamespace.ts +55 -1
- package/src/client/namespaces/consolidated/StorageNamespace.ts +59 -2
- package/src/client/signers/DappKitSigner.ts +207 -0
- package/src/client/signers/KeypairSigner.ts +7 -0
- package/src/client/signers/UnifiedSigner.ts +11 -0
- package/src/client/signers/WalletAdapterSigner.ts +10 -0
- package/src/client/signers/index.ts +7 -0
- package/src/generated/pdw/capability.ts +319 -319
- package/src/generated/utils/index.ts +1 -1
- package/src/graph/GraphService.ts +1 -1
- package/src/index.ts +16 -0
- package/src/permissions/ConsentRepository.browser.ts +249 -0
- package/src/permissions/index.ts +9 -9
- package/src/services/CapabilityService.ts +1 -1
- package/src/services/EncryptionService.ts +1 -1
- package/src/services/GeminiAIService.ts +283 -27
- package/src/services/MemoryIndexService.ts +85 -3
- package/src/services/StorageService.ts +8 -8
- package/src/services/VectorService.ts +2 -2
- package/src/services/storage/BlobAttributesManager.ts +10 -19
- package/src/services/storage/QuiltBatchManager.ts +178 -50
- package/src/services/storage/WalrusMetadataManager.ts +4 -7
- package/src/services/storage/WalrusStorageManager.ts +10 -13
- package/src/utils/rebuildIndexNode.ts +126 -43
- package/src/vector/NodeHnswService.ts +29 -7
- package/src/wallet/MainWalletService.ts +1 -1
- package/src/wallet/index.ts +17 -17
- package/dist/api/client.d.ts +0 -43
- package/dist/api/client.d.ts.map +0 -1
- package/dist/api/client.js +0 -136
- package/dist/api/client.js.map +0 -1
- package/dist/chat/index.d.ts +0 -13
- package/dist/chat/index.d.ts.map +0 -1
- package/dist/chat/index.js +0 -14
- package/dist/chat/index.js.map +0 -1
- package/dist/client/namespaces/ChatNamespace.d.ts +0 -110
- package/dist/client/namespaces/ChatNamespace.d.ts.map +0 -1
- package/dist/client/namespaces/ChatNamespace.js +0 -123
- package/dist/client/namespaces/ChatNamespace.js.map +0 -1
- package/dist/encryption/index.d.ts +0 -14
- package/dist/encryption/index.d.ts.map +0 -1
- package/dist/encryption/index.js +0 -14
- package/dist/encryption/index.js.map +0 -1
- package/dist/graph/BrowserKnowledgeGraphManager.d.ts +0 -101
- package/dist/graph/BrowserKnowledgeGraphManager.d.ts.map +0 -1
- package/dist/graph/BrowserKnowledgeGraphManager.js +0 -411
- package/dist/graph/BrowserKnowledgeGraphManager.js.map +0 -1
- package/dist/hooks.wip/index.d.ts +0 -55
- package/dist/hooks.wip/index.d.ts.map +0 -1
- package/dist/hooks.wip/index.js +0 -58
- package/dist/hooks.wip/index.js.map +0 -1
- package/dist/hooks.wip/useCreateMemory.d.ts +0 -111
- package/dist/hooks.wip/useCreateMemory.d.ts.map +0 -1
- package/dist/hooks.wip/useCreateMemory.js +0 -149
- package/dist/hooks.wip/useCreateMemory.js.map +0 -1
- package/dist/hooks.wip/useCreateMemoryBatch.d.ts +0 -122
- package/dist/hooks.wip/useCreateMemoryBatch.d.ts.map +0 -1
- package/dist/hooks.wip/useCreateMemoryBatch.js +0 -221
- package/dist/hooks.wip/useCreateMemoryBatch.js.map +0 -1
- package/dist/hooks.wip/useKnowledgeGraph.d.ts +0 -66
- package/dist/hooks.wip/useKnowledgeGraph.d.ts.map +0 -1
- package/dist/hooks.wip/useKnowledgeGraph.js +0 -229
- package/dist/hooks.wip/useKnowledgeGraph.js.map +0 -1
- package/dist/hooks.wip/useMemoryChat.d.ts +0 -106
- package/dist/hooks.wip/useMemoryChat.d.ts.map +0 -1
- package/dist/hooks.wip/useMemoryChat.js +0 -284
- package/dist/hooks.wip/useMemoryChat.js.map +0 -1
- package/dist/hooks.wip/useMemoryIndex.d.ts +0 -90
- package/dist/hooks.wip/useMemoryIndex.d.ts.map +0 -1
- package/dist/hooks.wip/useMemoryIndex.js +0 -218
- package/dist/hooks.wip/useMemoryIndex.js.map +0 -1
- package/dist/hooks.wip/useMemoryManager.d.ts +0 -35
- package/dist/hooks.wip/useMemoryManager.d.ts.map +0 -1
- package/dist/hooks.wip/useMemoryManager.js +0 -86
- package/dist/hooks.wip/useMemoryManager.js.map +0 -1
- package/dist/hooks.wip/useMemorySearch.d.ts +0 -100
- package/dist/hooks.wip/useMemorySearch.d.ts.map +0 -1
- package/dist/hooks.wip/useMemorySearch.js +0 -278
- package/dist/hooks.wip/useMemorySearch.js.map +0 -1
- package/dist/hooks.wip/useMemoryServices.d.ts +0 -80
- package/dist/hooks.wip/useMemoryServices.d.ts.map +0 -1
- package/dist/hooks.wip/useMemoryServices.js +0 -264
- package/dist/hooks.wip/useMemoryServices.js.map +0 -1
- package/dist/hooks.wip/usePDWRAG.d.ts +0 -112
- package/dist/hooks.wip/usePDWRAG.d.ts.map +0 -1
- package/dist/hooks.wip/usePDWRAG.js +0 -121
- package/dist/hooks.wip/usePDWRAG.js.map +0 -1
- package/dist/hooks.wip/usePDWVectorStore.d.ts +0 -68
- package/dist/hooks.wip/usePDWVectorStore.d.ts.map +0 -1
- package/dist/hooks.wip/usePDWVectorStore.js +0 -102
- package/dist/hooks.wip/usePDWVectorStore.js.map +0 -1
- package/dist/hooks.wip/useRetrieveEmbedding.d.ts +0 -138
- package/dist/hooks.wip/useRetrieveEmbedding.d.ts.map +0 -1
- package/dist/hooks.wip/useRetrieveEmbedding.js +0 -121
- package/dist/hooks.wip/useRetrieveEmbedding.js.map +0 -1
- package/dist/hooks.wip/useSearchMemories.d.ts +0 -103
- package/dist/hooks.wip/useSearchMemories.d.ts.map +0 -1
- package/dist/hooks.wip/useSearchMemories.js +0 -146
- package/dist/hooks.wip/useSearchMemories.js.map +0 -1
- package/dist/hooks.wip/useStoreEmbedding.d.ts +0 -174
- package/dist/hooks.wip/useStoreEmbedding.d.ts.map +0 -1
- package/dist/hooks.wip/useStoreEmbedding.js +0 -167
- package/dist/hooks.wip/useStoreEmbedding.js.map +0 -1
- package/dist/hooks.wip/useWalletMemories.d.ts +0 -119
- package/dist/hooks.wip/useWalletMemories.d.ts.map +0 -1
- package/dist/hooks.wip/useWalletMemories.js +0 -166
- package/dist/hooks.wip/useWalletMemories.js.map +0 -1
- package/dist/hooks.wip/utils/cache.d.ts +0 -25
- package/dist/hooks.wip/utils/cache.d.ts.map +0 -1
- package/dist/hooks.wip/utils/cache.js +0 -38
- package/dist/hooks.wip/utils/cache.js.map +0 -1
- package/dist/hooks.wip/utils/types.d.ts +0 -138
- package/dist/hooks.wip/utils/types.d.ts.map +0 -1
- package/dist/hooks.wip/utils/types.js +0 -5
- package/dist/hooks.wip/utils/types.js.map +0 -1
- package/dist/infrastructure/ai/EmbeddingService.d.ts +0 -101
- package/dist/infrastructure/ai/EmbeddingService.d.ts.map +0 -1
- package/dist/infrastructure/ai/EmbeddingService.js +0 -242
- package/dist/infrastructure/ai/EmbeddingService.js.map +0 -1
- package/dist/infrastructure/ai/GeminiAIService.d.ts +0 -84
- package/dist/infrastructure/ai/GeminiAIService.d.ts.map +0 -1
- package/dist/infrastructure/ai/GeminiAIService.js +0 -300
- package/dist/infrastructure/ai/GeminiAIService.js.map +0 -1
- package/dist/infrastructure/ai/index.d.ts +0 -8
- package/dist/infrastructure/ai/index.d.ts.map +0 -1
- package/dist/infrastructure/ai/index.js +0 -8
- package/dist/infrastructure/ai/index.js.map +0 -1
- package/dist/memory/index.d.ts +0 -13
- package/dist/memory/index.d.ts.map +0 -1
- package/dist/memory/index.js +0 -14
- package/dist/memory/index.js.map +0 -1
- package/dist/services/ChatService.d.ts +0 -89
- package/dist/services/ChatService.d.ts.map +0 -1
- package/dist/services/ChatService.js +0 -319
- package/dist/services/ChatService.js.map +0 -1
- package/dist/transactions/index.d.ts +0 -13
- package/dist/transactions/index.d.ts.map +0 -1
- package/dist/transactions/index.js +0 -14
- package/dist/transactions/index.js.map +0 -1
- package/dist/types/wallet.d.ts +0 -12
- package/dist/types/wallet.d.ts.map +0 -1
- package/dist/types/wallet.js +0 -13
- package/dist/types/wallet.js.map +0 -1
- package/dist/view/ViewService.d.ts +0 -136
- package/dist/view/ViewService.d.ts.map +0 -1
- package/dist/view/ViewService.js +0 -325
- package/dist/view/ViewService.js.map +0 -1
- package/dist/view/index.d.ts +0 -7
- package/dist/view/index.d.ts.map +0 -1
- package/dist/view/index.js +0 -7
- package/dist/view/index.js.map +0 -1
package/src/browser.ts
CHANGED
|
@@ -1,35 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Personal Data Wallet SDK - Browser Entry Point
|
|
3
3
|
*
|
|
4
|
-
* This entry point
|
|
5
|
-
*
|
|
4
|
+
* This entry point provides browser-safe exports that don't require Node.js modules.
|
|
5
|
+
* Exports that depend on Node.js (fs, hnswlib-node) are excluded.
|
|
6
6
|
*
|
|
7
|
-
* For
|
|
7
|
+
* For Node.js applications, use the main '@cmdoss/memwal-sdk' import instead.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
export { MemoryPipeline, PipelineManager } from './pipeline';
|
|
12
|
-
export type {
|
|
13
|
-
PipelineConfig,
|
|
14
|
-
PipelineExecution,
|
|
15
|
-
PipelineMetrics,
|
|
16
|
-
PipelineManagerConfig,
|
|
17
|
-
SystemMetrics
|
|
18
|
-
} from './pipeline';
|
|
19
|
-
|
|
20
|
-
// ==================== SERVICES ====================
|
|
10
|
+
// ==================== SERVICES (Browser-safe) ====================
|
|
21
11
|
export { StorageService } from './services/StorageService';
|
|
22
12
|
export { EmbeddingService } from './services/EmbeddingService';
|
|
23
13
|
export { GeminiAIService } from './services/GeminiAIService';
|
|
24
14
|
export { QueryService } from './services/QueryService';
|
|
25
15
|
export { ClassifierService } from './services/ClassifierService';
|
|
26
|
-
|
|
16
|
+
// Note: MemoryIndexService excluded - depends on createHnswService which imports hnswlib-node
|
|
27
17
|
export { ViewService } from './services/ViewService';
|
|
28
18
|
export { TransactionService } from './services/TransactionService';
|
|
29
19
|
export { BatchService } from './services/BatchService';
|
|
30
20
|
export { CrossContextPermissionService } from './services/CrossContextPermissionService';
|
|
31
21
|
export { MemoryService } from './services/MemoryService';
|
|
32
|
-
|
|
22
|
+
// Note: VectorService excluded - depends on HNSW which imports hnswlib-node
|
|
33
23
|
export { CapabilityService } from './services/CapabilityService';
|
|
34
24
|
|
|
35
25
|
// ==================== INFRASTRUCTURE ====================
|
|
@@ -41,9 +31,11 @@ export { EncryptionService } from './infrastructure/seal';
|
|
|
41
31
|
// ==================== CORE ====================
|
|
42
32
|
export * from './core/interfaces';
|
|
43
33
|
|
|
44
|
-
// ==================== UTILITIES ====================
|
|
45
|
-
|
|
46
|
-
|
|
34
|
+
// ==================== UTILITIES (Browser-safe) ====================
|
|
35
|
+
// Note: VectorManager excluded - depends on createHnswService which imports hnswlib-node
|
|
36
|
+
// Import directly from specific files to avoid loading Node.js dependencies
|
|
37
|
+
export { isBrowser, isNode } from './vector/IHnswService';
|
|
38
|
+
export type { IHnswService, IHnswSearchResultItem, IHnswSearchOptions, IHnswBatchStats } from './vector/IHnswService';
|
|
47
39
|
export { BrowserHnswIndexService } from './vector/BrowserHnswIndexService';
|
|
48
40
|
export { BatchManager, BatchingService, MemoryProcessingCache } from './batch';
|
|
49
41
|
export { GraphService, KnowledgeGraphManager } from './graph';
|
|
@@ -74,10 +66,11 @@ export type {
|
|
|
74
66
|
EmbeddingConfig
|
|
75
67
|
} from './embedding/types';
|
|
76
68
|
|
|
69
|
+
// Import from embedding/types directly to avoid loading vector/index.ts
|
|
77
70
|
export type {
|
|
78
71
|
VectorSearchResult,
|
|
79
72
|
HNSWIndexConfig
|
|
80
|
-
} from './
|
|
73
|
+
} from './embedding/types';
|
|
81
74
|
|
|
82
75
|
export type {
|
|
83
76
|
CacheConfig,
|
|
@@ -117,8 +110,11 @@ export const SDK_VERSION = '1.0.0';
|
|
|
117
110
|
export const SDK_NAME = 'Personal Data Wallet SDK (Browser)';
|
|
118
111
|
|
|
119
112
|
// Client-side memory management (without React)
|
|
120
|
-
|
|
113
|
+
// NOTE: ClientMemoryManager excluded from browser entry - it uses createHnswService
|
|
114
|
+
// which imports Node.js modules. Use SimplePDWClient for browser apps instead.
|
|
115
|
+
// export { ClientMemoryManager } from './client/ClientMemoryManager';
|
|
121
116
|
export { PersonalDataWallet } from './client/PersonalDataWallet';
|
|
117
|
+
// Types can still be exported (no runtime code)
|
|
122
118
|
export type {
|
|
123
119
|
ClientMemoryManagerConfig,
|
|
124
120
|
CreateMemoryOptions as ClientCreateMemoryOptions,
|
|
@@ -134,12 +130,13 @@ export { MainWalletService } from './wallet/MainWalletService';
|
|
|
134
130
|
/** @deprecated Use ContextNamespace instead */
|
|
135
131
|
export { ContextWalletService } from './wallet/ContextWalletService';
|
|
136
132
|
export { PermissionService } from './access/PermissionService';
|
|
137
|
-
|
|
133
|
+
// Import from browser-safe file to avoid loading FileSystemConsentRepository with fs/promises
|
|
134
|
+
export type { ConsentRepository } from './permissions/ConsentRepository.browser';
|
|
138
135
|
export {
|
|
139
136
|
InMemoryConsentRepository,
|
|
140
137
|
IndexedDBConsentRepository,
|
|
141
|
-
|
|
142
|
-
} from './permissions/ConsentRepository';
|
|
138
|
+
createBrowserConsentRepository
|
|
139
|
+
} from './permissions/ConsentRepository.browser';
|
|
143
140
|
export { AggregationService } from './aggregation/AggregationService';
|
|
144
141
|
export type {
|
|
145
142
|
MainWallet,
|
|
@@ -187,6 +184,13 @@ export type { PDWVectorStoreConfig, PDWAddDocumentOptions } from './langchain/PD
|
|
|
187
184
|
export { SimplePDWClient } from './client/SimplePDWClient';
|
|
188
185
|
export type { SimplePDWConfig } from './client/SimplePDWClient';
|
|
189
186
|
|
|
187
|
+
// ==================== SIGNERS ====================
|
|
188
|
+
// DappKitSigner - adapter for @mysten/dapp-kit wallet signing
|
|
189
|
+
export { DappKitSigner } from './client/signers/DappKitSigner';
|
|
190
|
+
export type { DappKitSignerConfig, DappKitSignAndExecuteFn, DappKitSignPersonalMessageFn } from './client/signers/DappKitSigner';
|
|
191
|
+
export { WalletAdapterSigner } from './client/signers/WalletAdapterSigner';
|
|
192
|
+
export type { UnifiedSigner, SignAndExecuteResult, SignPersonalMessageResult } from './client/signers/UnifiedSigner';
|
|
193
|
+
|
|
190
194
|
// Re-export common types from core for convenience
|
|
191
195
|
export type {
|
|
192
196
|
ChatSession,
|
|
@@ -39,7 +39,8 @@ import { WalrusClient } from '@mysten/walrus';
|
|
|
39
39
|
import { Transaction } from '@mysten/sui/transactions';
|
|
40
40
|
import { fromHex } from '@mysten/sui/utils';
|
|
41
41
|
import type { SuiClient } from '@mysten/sui/client';
|
|
42
|
-
|
|
42
|
+
// Import environment detection from browser-safe file (no Node.js deps)
|
|
43
|
+
import { isBrowser, isNode } from '../vector/IHnswService';
|
|
43
44
|
import type { IHnswService } from '../vector/IHnswService';
|
|
44
45
|
import { EmbeddingService } from '../services/EmbeddingService';
|
|
45
46
|
import { GeminiAIService } from '../services/GeminiAIService';
|
|
@@ -183,9 +184,13 @@ export class ClientMemoryManager {
|
|
|
183
184
|
|
|
184
185
|
/**
|
|
185
186
|
* Initialize HNSW service using factory (async)
|
|
187
|
+
* Uses dynamic import to avoid bundling Node.js modules in browser
|
|
186
188
|
*/
|
|
187
189
|
private async initializeHnswService(): Promise<IHnswService> {
|
|
188
190
|
try {
|
|
191
|
+
// Dynamic import to avoid webpack bundling Node.js modules at build time
|
|
192
|
+
const { createHnswService } = await import('../vector/createHnswService');
|
|
193
|
+
|
|
189
194
|
const service = await createHnswService({
|
|
190
195
|
indexConfig: {
|
|
191
196
|
dimension: 3072,
|
|
@@ -69,7 +69,8 @@ import { ViewService } from '../services/ViewService';
|
|
|
69
69
|
import { CapabilityService } from '../services/CapabilityService';
|
|
70
70
|
import { MemoryIndexService } from '../services/MemoryIndexService';
|
|
71
71
|
import { IndexManager, type IndexManagerOptions, type IndexProgressCallback } from '../services/IndexManager';
|
|
72
|
-
|
|
72
|
+
// Note: createHnswService is dynamically imported only when enableLocalIndexing is true
|
|
73
|
+
// This prevents bundling Node.js dependencies (hnswlib-node) in browser builds
|
|
73
74
|
import type { IHnswService } from '../vector/IHnswService';
|
|
74
75
|
|
|
75
76
|
/**
|
|
@@ -189,6 +190,23 @@ export interface SimplePDWConfig {
|
|
|
189
190
|
/** Progress callback for index operations */
|
|
190
191
|
onProgress?: IndexProgressCallback;
|
|
191
192
|
};
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Optional: Index backup to Walrus cloud storage
|
|
196
|
+
* Enables syncing local HNSW index to Walrus for cross-device restoration
|
|
197
|
+
*/
|
|
198
|
+
indexBackup?: {
|
|
199
|
+
/** Enable Walrus backup for local index */
|
|
200
|
+
enabled: boolean;
|
|
201
|
+
/** Walrus aggregator URL for downloading */
|
|
202
|
+
aggregatorUrl?: string;
|
|
203
|
+
/** Walrus publisher URL for uploading */
|
|
204
|
+
publisherUrl?: string;
|
|
205
|
+
/** Auto-sync index to Walrus on every save (default: false) */
|
|
206
|
+
autoSync?: boolean;
|
|
207
|
+
/** Storage duration in epochs (default: 3) */
|
|
208
|
+
epochs?: number;
|
|
209
|
+
};
|
|
192
210
|
}
|
|
193
211
|
|
|
194
212
|
/**
|
|
@@ -238,6 +256,13 @@ interface ResolvedConfig {
|
|
|
238
256
|
enableAutoSave?: boolean;
|
|
239
257
|
onProgress?: IndexProgressCallback;
|
|
240
258
|
};
|
|
259
|
+
indexBackup?: {
|
|
260
|
+
enabled: boolean;
|
|
261
|
+
aggregatorUrl?: string;
|
|
262
|
+
publisherUrl?: string;
|
|
263
|
+
autoSync?: boolean;
|
|
264
|
+
epochs?: number;
|
|
265
|
+
};
|
|
241
266
|
}
|
|
242
267
|
|
|
243
268
|
/**
|
|
@@ -359,7 +384,8 @@ export class SimplePDWClient {
|
|
|
359
384
|
enableLocalIndexing: config.features?.enableLocalIndexing ?? true,
|
|
360
385
|
enableKnowledgeGraph: config.features?.enableKnowledgeGraph ?? true
|
|
361
386
|
},
|
|
362
|
-
indexManager: config.indexManager
|
|
387
|
+
indexManager: config.indexManager,
|
|
388
|
+
indexBackup: config.indexBackup
|
|
363
389
|
};
|
|
364
390
|
}
|
|
365
391
|
|
|
@@ -472,20 +498,36 @@ export class SimplePDWClient {
|
|
|
472
498
|
// Note: This starts async initialization - services will wait for it when needed
|
|
473
499
|
let sharedHnswService: IHnswService | undefined;
|
|
474
500
|
if (config.features.enableLocalIndexing) {
|
|
475
|
-
//
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
501
|
+
// Prepare Walrus backup config if enabled
|
|
502
|
+
const walrusBackupConfig = config.indexBackup?.enabled ? {
|
|
503
|
+
enabled: true,
|
|
504
|
+
aggregatorUrl: config.indexBackup.aggregatorUrl || config.walrus.aggregator,
|
|
505
|
+
publisherUrl: config.indexBackup.publisherUrl || config.walrus.publisher,
|
|
506
|
+
autoSync: config.indexBackup.autoSync ?? false,
|
|
507
|
+
epochs: config.indexBackup.epochs ?? 3
|
|
508
|
+
} : undefined;
|
|
509
|
+
|
|
510
|
+
// Dynamic import to avoid bundling Node.js dependencies (hnswlib-node) in browser builds
|
|
511
|
+
// When enableLocalIndexing is false, this code never runs and webpack won't bundle it
|
|
512
|
+
this.sharedHnswServicePromise = import('../vector/createHnswService').then(
|
|
513
|
+
({ createHnswService }) => createHnswService({
|
|
514
|
+
indexConfig: {
|
|
515
|
+
dimension: embeddingConfig.dimensions,
|
|
516
|
+
maxElements: 10000,
|
|
517
|
+
efConstruction: 200,
|
|
518
|
+
m: 16
|
|
519
|
+
},
|
|
520
|
+
batchConfig: {
|
|
521
|
+
maxBatchSize: 100,
|
|
522
|
+
batchDelayMs: 5000
|
|
523
|
+
},
|
|
524
|
+
walrusBackup: walrusBackupConfig
|
|
525
|
+
})
|
|
526
|
+
);
|
|
488
527
|
console.log('✅ Shared HNSW service initialization started (singleton for all vector services)');
|
|
528
|
+
if (walrusBackupConfig?.enabled) {
|
|
529
|
+
console.log(' ☁️ Walrus backup enabled for local index');
|
|
530
|
+
}
|
|
489
531
|
}
|
|
490
532
|
|
|
491
533
|
// 9a. Vector Service (if local indexing enabled)
|
|
@@ -149,7 +149,7 @@ export class BatchNamespace {
|
|
|
149
149
|
identity: this.services.config.userAddress
|
|
150
150
|
},
|
|
151
151
|
{
|
|
152
|
-
signer: this.services.config.signer
|
|
152
|
+
signer: this.services.config.signer,
|
|
153
153
|
epochs: 3,
|
|
154
154
|
deletable: true
|
|
155
155
|
}
|
|
@@ -282,7 +282,7 @@ export class BatchNamespace {
|
|
|
282
282
|
const result = await this.services.storage.uploadMemoryBatch(
|
|
283
283
|
memories,
|
|
284
284
|
{
|
|
285
|
-
signer: this.services.config.signer
|
|
285
|
+
signer: this.services.config.signer,
|
|
286
286
|
epochs: 3,
|
|
287
287
|
userAddress: this.services.config.userAddress
|
|
288
288
|
}
|
|
@@ -189,13 +189,11 @@ export class IndexNamespace {
|
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/**
|
|
192
|
-
* Save index to
|
|
192
|
+
* Save index to local storage
|
|
193
193
|
*
|
|
194
|
-
* Persists the HNSW index binary to
|
|
195
|
-
* Uses HnswWasmService.saveIndex() which properly serializes the index.
|
|
194
|
+
* Persists the HNSW index binary to local filesystem.
|
|
196
195
|
*
|
|
197
196
|
* @param spaceId - Index space identifier (userAddress)
|
|
198
|
-
* @returns Blob ID of saved index on Walrus, or null if no index exists
|
|
199
197
|
*/
|
|
200
198
|
async save(spaceId: string): Promise<void> {
|
|
201
199
|
const { type, service } = this.getService();
|
|
@@ -211,26 +209,106 @@ export class IndexNamespace {
|
|
|
211
209
|
}
|
|
212
210
|
|
|
213
211
|
/**
|
|
214
|
-
* Load index from Walrus
|
|
212
|
+
* Load index from storage (local or Walrus)
|
|
215
213
|
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
214
|
+
* If blobId is provided, attempts to load from Walrus first.
|
|
215
|
+
* Falls back to local storage if Walrus load fails.
|
|
218
216
|
*
|
|
219
217
|
* @param spaceId - Index space identifier (userAddress)
|
|
220
|
-
* @param blobId -
|
|
218
|
+
* @param blobId - Optional Walrus blob ID to load from cloud
|
|
221
219
|
*/
|
|
222
|
-
async load(spaceId: string, blobId
|
|
220
|
+
async load(spaceId: string, blobId?: string): Promise<void> {
|
|
223
221
|
const { type, service } = this.getService();
|
|
224
222
|
|
|
225
223
|
if (type === 'memoryIndex') {
|
|
226
|
-
// MemoryIndexService.loadIndex(userAddress, indexBlobId?)
|
|
227
224
|
await service.loadIndex(spaceId, blobId);
|
|
228
|
-
|
|
225
|
+
if (blobId) {
|
|
226
|
+
console.log(`Index loaded from Walrus: ${blobId}`);
|
|
227
|
+
} else {
|
|
228
|
+
console.log(`Index loaded from local storage: ${spaceId}`);
|
|
229
|
+
}
|
|
229
230
|
} else {
|
|
230
231
|
await service.loadIndex(spaceId, blobId);
|
|
231
232
|
}
|
|
232
233
|
}
|
|
233
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Sync index to Walrus cloud storage
|
|
237
|
+
*
|
|
238
|
+
* Uploads the HNSW index binary + metadata to Walrus for durability.
|
|
239
|
+
* This enables cross-device index restoration.
|
|
240
|
+
*
|
|
241
|
+
* @param spaceId - Index space identifier (userAddress)
|
|
242
|
+
* @returns Walrus blob ID if successful, null if Walrus is disabled
|
|
243
|
+
*/
|
|
244
|
+
async syncToWalrus(spaceId: string): Promise<string | null> {
|
|
245
|
+
const { type, service } = this.getService();
|
|
246
|
+
|
|
247
|
+
if (type === 'memoryIndex' && 'syncToWalrus' in service) {
|
|
248
|
+
const blobId = await service.syncToWalrus(spaceId);
|
|
249
|
+
if (blobId) {
|
|
250
|
+
console.log(`Index synced to Walrus: ${blobId}`);
|
|
251
|
+
}
|
|
252
|
+
return blobId;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
console.warn('Walrus sync not available for this service type');
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Load index from Walrus cloud storage
|
|
261
|
+
*
|
|
262
|
+
* Downloads and restores a previously synced index from Walrus.
|
|
263
|
+
*
|
|
264
|
+
* @param spaceId - Index space identifier (userAddress)
|
|
265
|
+
* @param blobId - Walrus blob ID of the saved index
|
|
266
|
+
* @returns true if successfully loaded
|
|
267
|
+
*/
|
|
268
|
+
async loadFromWalrus(spaceId: string, blobId: string): Promise<boolean> {
|
|
269
|
+
const { type, service } = this.getService();
|
|
270
|
+
|
|
271
|
+
if (type === 'memoryIndex' && 'loadFromWalrus' in service) {
|
|
272
|
+
const loaded = await service.loadFromWalrus(spaceId, blobId);
|
|
273
|
+
if (loaded) {
|
|
274
|
+
console.log(`Index loaded from Walrus: ${blobId}`);
|
|
275
|
+
}
|
|
276
|
+
return loaded;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
console.warn('Walrus load not available for this service type');
|
|
280
|
+
return false;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Get the Walrus blob ID for a user's index (if backed up)
|
|
285
|
+
*
|
|
286
|
+
* @param spaceId - Index space identifier (userAddress)
|
|
287
|
+
* @returns Blob ID or null if not backed up
|
|
288
|
+
*/
|
|
289
|
+
getWalrusBlobId(spaceId: string): string | null {
|
|
290
|
+
const { type, service } = this.getService();
|
|
291
|
+
|
|
292
|
+
if (type === 'memoryIndex' && 'getWalrusBlobId' in service) {
|
|
293
|
+
return service.getWalrusBlobId(spaceId);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Check if Walrus backup is enabled
|
|
301
|
+
*/
|
|
302
|
+
isWalrusEnabled(): boolean {
|
|
303
|
+
const { type, service } = this.getService();
|
|
304
|
+
|
|
305
|
+
if (type === 'memoryIndex' && 'isWalrusEnabled' in service) {
|
|
306
|
+
return service.isWalrusEnabled();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
|
|
234
312
|
/**
|
|
235
313
|
* Clear index and remove all vectors
|
|
236
314
|
*
|
|
@@ -200,7 +200,7 @@ export class MemoryNamespace {
|
|
|
200
200
|
identity: this.services.config.userAddress
|
|
201
201
|
},
|
|
202
202
|
{
|
|
203
|
-
signer: this.services.config.signer
|
|
203
|
+
signer: this.services.config.signer,
|
|
204
204
|
epochs: 3,
|
|
205
205
|
deletable: true,
|
|
206
206
|
metadata: {
|
|
@@ -439,7 +439,7 @@ export class MemoryNamespace {
|
|
|
439
439
|
identity: this.services.config.userAddress
|
|
440
440
|
},
|
|
441
441
|
{
|
|
442
|
-
signer: this.services.config.signer
|
|
442
|
+
signer: this.services.config.signer,
|
|
443
443
|
epochs: 3,
|
|
444
444
|
deletable: true
|
|
445
445
|
}
|
|
@@ -723,7 +723,7 @@ export class MemoryNamespace {
|
|
|
723
723
|
const quiltResult = await this.services.storage.uploadMemoryBatch(
|
|
724
724
|
batchMemories,
|
|
725
725
|
{
|
|
726
|
-
signer: this.services.config.signer
|
|
726
|
+
signer: this.services.config.signer,
|
|
727
727
|
epochs: 3,
|
|
728
728
|
userAddress: this.services.config.userAddress
|
|
729
729
|
}
|
|
@@ -154,18 +154,26 @@ export class SearchNamespace {
|
|
|
154
154
|
|
|
155
155
|
// Convert to SearchResult format
|
|
156
156
|
// Option A+: Content may be available from local index when encryption is OFF
|
|
157
|
-
const searchResults: SearchResult[] = results.map((r: any) =>
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
157
|
+
const searchResults: SearchResult[] = results.map((r: any) => {
|
|
158
|
+
// blobId must be a valid Walrus blob ID, not a vectorId
|
|
159
|
+
// Only use metadata.blobId if it's a non-empty string that looks like a Walrus blobId
|
|
160
|
+
const rawBlobId = r.metadata?.blobId;
|
|
161
|
+
const isValidBlobId = rawBlobId && typeof rawBlobId === 'string' && rawBlobId.length > 10 && !/^\d+$/.test(rawBlobId);
|
|
162
|
+
const blobId = isValidBlobId ? rawBlobId : (r.metadata?.memoryObjectId || '');
|
|
163
|
+
|
|
164
|
+
return {
|
|
165
|
+
id: r.memoryId || r.vectorId.toString(),
|
|
166
|
+
content: r.metadata?.content || r.content || '', // ✅ Get content from index metadata if available
|
|
167
|
+
score: r.similarity,
|
|
168
|
+
similarity: r.similarity,
|
|
169
|
+
category: r.metadata?.category,
|
|
170
|
+
importance: r.metadata?.importance || 5,
|
|
171
|
+
topic: r.metadata?.topic,
|
|
172
|
+
blobId,
|
|
173
|
+
metadata: r.metadata || {},
|
|
174
|
+
timestamp: r.metadata?.timestamp || Date.now()
|
|
175
|
+
};
|
|
176
|
+
});
|
|
169
177
|
|
|
170
178
|
// Optionally fetch content from Walrus
|
|
171
179
|
if (fetchContent) {
|
|
@@ -329,7 +337,12 @@ export class SearchNamespace {
|
|
|
329
337
|
const localResults = this.services.vector.getVectorsByCategory(spaceId, category);
|
|
330
338
|
|
|
331
339
|
for (const { vectorId, metadata } of localResults) {
|
|
332
|
-
|
|
340
|
+
// blobId must be a valid Walrus blob ID, not a vectorId
|
|
341
|
+
const rawBlobId = metadata?.blobId;
|
|
342
|
+
const isValidBlobId = rawBlobId && typeof rawBlobId === 'string' && rawBlobId.length > 10 && !/^\d+$/.test(rawBlobId);
|
|
343
|
+
const blobId = isValidBlobId ? rawBlobId : (metadata?.memoryObjectId || '');
|
|
344
|
+
const id = blobId || metadata?.memoryId || vectorId?.toString();
|
|
345
|
+
|
|
333
346
|
if (id && !seenIds.has(id)) {
|
|
334
347
|
seenIds.add(id);
|
|
335
348
|
results.push({
|
|
@@ -340,7 +353,7 @@ export class SearchNamespace {
|
|
|
340
353
|
category: metadata?.category,
|
|
341
354
|
importance: metadata?.importance || 5,
|
|
342
355
|
topic: metadata?.topic,
|
|
343
|
-
blobId
|
|
356
|
+
blobId,
|
|
344
357
|
metadata: metadata || {},
|
|
345
358
|
timestamp: metadata?.timestamp || Date.now()
|
|
346
359
|
});
|
|
@@ -93,7 +93,7 @@ export class StorageNamespace {
|
|
|
93
93
|
const result = await this.services.storage.uploadBlob(
|
|
94
94
|
data,
|
|
95
95
|
{
|
|
96
|
-
signer: this.services.config.signer
|
|
96
|
+
signer: this.services.config.signer,
|
|
97
97
|
epochs: 3,
|
|
98
98
|
deletable: true,
|
|
99
99
|
metadata: metadata as any
|
|
@@ -158,7 +158,7 @@ export class StorageNamespace {
|
|
|
158
158
|
deleted_at: new Date().toISOString(),
|
|
159
159
|
deleted_by: this.services.config.userAddress
|
|
160
160
|
},
|
|
161
|
-
this.services.config.signer
|
|
161
|
+
this.services.config.signer
|
|
162
162
|
);
|
|
163
163
|
|
|
164
164
|
console.log(`Blob ${blobId} marked as deleted`);
|
|
@@ -189,7 +189,7 @@ export class StorageNamespace {
|
|
|
189
189
|
const result = await this.services.storage.uploadMemoryBatch(
|
|
190
190
|
memories,
|
|
191
191
|
{
|
|
192
|
-
signer: this.services.config.signer
|
|
192
|
+
signer: this.services.config.signer,
|
|
193
193
|
epochs: 3,
|
|
194
194
|
userAddress: this.services.config.userAddress
|
|
195
195
|
}
|
|
@@ -302,7 +302,7 @@ export class StorageNamespace {
|
|
|
302
302
|
await this.services.storage.attachMetadataToBlob(
|
|
303
303
|
blobId,
|
|
304
304
|
metadata as any,
|
|
305
|
-
this.services.config.signer
|
|
305
|
+
this.services.config.signer
|
|
306
306
|
);
|
|
307
307
|
} catch (error) {
|
|
308
308
|
throw new Error(`Set metadata failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -135,12 +135,66 @@ class TxSubNamespace {
|
|
|
135
135
|
* ```
|
|
136
136
|
*/
|
|
137
137
|
async execute(tx: Transaction): Promise<TransactionResult> {
|
|
138
|
+
const signer = this.services.config.signer;
|
|
139
|
+
|
|
140
|
+
// Check if signer supports signAndExecuteTransaction (browser wallets like DappKitSigner)
|
|
141
|
+
// Browser wallets cannot expose raw Signer for security reasons
|
|
142
|
+
if ('signAndExecuteTransaction' in signer && typeof signer.signAndExecuteTransaction === 'function') {
|
|
143
|
+
try {
|
|
144
|
+
// Use the signer's signAndExecuteTransaction directly
|
|
145
|
+
const result = await signer.signAndExecuteTransaction(tx);
|
|
146
|
+
|
|
147
|
+
// Get full transaction details to extract created objects
|
|
148
|
+
let createdObjects: Array<{ objectId: string; objectType: string }> | undefined;
|
|
149
|
+
let mutatedObjects: Array<{ objectId: string; objectType: string }> | undefined;
|
|
150
|
+
|
|
151
|
+
if (result.objectChanges && Array.isArray(result.objectChanges)) {
|
|
152
|
+
createdObjects = result.objectChanges
|
|
153
|
+
.filter((change: any) => change.type === 'created')
|
|
154
|
+
.map((change: any) => ({
|
|
155
|
+
objectId: change.objectId,
|
|
156
|
+
objectType: change.objectType || 'unknown',
|
|
157
|
+
}));
|
|
158
|
+
|
|
159
|
+
mutatedObjects = result.objectChanges
|
|
160
|
+
.filter((change: any) => change.type === 'mutated')
|
|
161
|
+
.map((change: any) => ({
|
|
162
|
+
objectId: change.objectId,
|
|
163
|
+
objectType: change.objectType || 'unknown',
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Determine status from effects
|
|
168
|
+
const status = result.effects?.status?.status === 'success' ? 'success' : 'failure';
|
|
169
|
+
|
|
170
|
+
return {
|
|
171
|
+
digest: result.digest,
|
|
172
|
+
status,
|
|
173
|
+
effects: result.effects,
|
|
174
|
+
createdObjects,
|
|
175
|
+
mutatedObjects,
|
|
176
|
+
gasUsed: result.effects?.gasUsed?.computationCost
|
|
177
|
+
? Number(result.effects.gasUsed.computationCost)
|
|
178
|
+
: undefined,
|
|
179
|
+
error: status === 'failure' ? result.effects?.status?.error : undefined,
|
|
180
|
+
};
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.error('Transaction execution failed:', error);
|
|
183
|
+
return {
|
|
184
|
+
digest: '',
|
|
185
|
+
status: 'failure',
|
|
186
|
+
error: error instanceof Error ? error.message : String(error),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Fallback: Use TransactionService with raw Signer (Node.js/backend)
|
|
138
192
|
if (!this.services.tx) {
|
|
139
193
|
throw new Error('Transaction service not configured.');
|
|
140
194
|
}
|
|
141
195
|
return await this.services.tx.executeTransaction(
|
|
142
196
|
tx,
|
|
143
|
-
|
|
197
|
+
signer.getSigner()
|
|
144
198
|
);
|
|
145
199
|
}
|
|
146
200
|
|
|
@@ -246,7 +246,7 @@ export class StorageNamespace {
|
|
|
246
246
|
|
|
247
247
|
// Upload to Walrus using uploadBlob method
|
|
248
248
|
const result = await this.services.storage.uploadBlob(bytes, {
|
|
249
|
-
signer: this.services.config.signer
|
|
249
|
+
signer: this.services.config.signer,
|
|
250
250
|
epochs: options.epochs,
|
|
251
251
|
deletable: true
|
|
252
252
|
});
|
|
@@ -353,7 +353,7 @@ export class StorageNamespace {
|
|
|
353
353
|
identity: this.services.config.userAddress
|
|
354
354
|
},
|
|
355
355
|
{
|
|
356
|
-
signer: this.services.config.signer
|
|
356
|
+
signer: this.services.config.signer,
|
|
357
357
|
epochs: 3,
|
|
358
358
|
deletable: true
|
|
359
359
|
}
|
|
@@ -437,4 +437,61 @@ export class StorageNamespace {
|
|
|
437
437
|
};
|
|
438
438
|
}
|
|
439
439
|
}
|
|
440
|
+
|
|
441
|
+
// ==========================================================================
|
|
442
|
+
// Batch Operations (Quilt)
|
|
443
|
+
// ==========================================================================
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Upload multiple memories as a Quilt (batch upload)
|
|
447
|
+
*
|
|
448
|
+
* Uses Walrus Quilt for ~90% gas savings compared to individual uploads.
|
|
449
|
+
* Requires 2 user signatures:
|
|
450
|
+
* - Transaction 1: Register blob on-chain
|
|
451
|
+
* - Transaction 2: Certify upload on-chain
|
|
452
|
+
*
|
|
453
|
+
* @param memories - Array of memories to upload
|
|
454
|
+
* @param options - Upload options including signer
|
|
455
|
+
* @returns Quilt result with file mappings
|
|
456
|
+
*
|
|
457
|
+
* @example
|
|
458
|
+
* ```typescript
|
|
459
|
+
* const result = await pdw.storage.uploadMemoryBatch(
|
|
460
|
+
* memories,
|
|
461
|
+
* {
|
|
462
|
+
* signer: pdw.getConfig().signer,
|
|
463
|
+
* epochs: 3,
|
|
464
|
+
* userAddress: pdw.getConfig().userAddress
|
|
465
|
+
* }
|
|
466
|
+
* );
|
|
467
|
+
* console.log(`Uploaded ${result.files.length} files`);
|
|
468
|
+
* ```
|
|
469
|
+
*/
|
|
470
|
+
async uploadMemoryBatch(
|
|
471
|
+
memories: Array<{
|
|
472
|
+
content: string;
|
|
473
|
+
category: string;
|
|
474
|
+
importance: number;
|
|
475
|
+
topic: string;
|
|
476
|
+
embedding: number[];
|
|
477
|
+
encryptedContent: Uint8Array;
|
|
478
|
+
summary?: string;
|
|
479
|
+
id?: string;
|
|
480
|
+
}>,
|
|
481
|
+
options: {
|
|
482
|
+
signer: any; // UnifiedSigner
|
|
483
|
+
epochs?: number;
|
|
484
|
+
userAddress: string;
|
|
485
|
+
}
|
|
486
|
+
): Promise<{
|
|
487
|
+
quiltId: string;
|
|
488
|
+
files: Array<{ identifier: string; blobId: string }>;
|
|
489
|
+
uploadTimeMs: number;
|
|
490
|
+
}> {
|
|
491
|
+
if (!this.services.storage) {
|
|
492
|
+
throw new Error('Storage service not configured.');
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return this.services.storage.uploadMemoryBatch(memories, options);
|
|
496
|
+
}
|
|
440
497
|
}
|