@cmdoss/memwal-sdk 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/README.md +427 -41
  2. package/dist/client/ClientMemoryManager.js +2 -2
  3. package/dist/client/ClientMemoryManager.js.map +1 -1
  4. package/dist/client/PersonalDataWallet.d.ts.map +1 -1
  5. package/dist/client/SimplePDWClient.d.ts +88 -1
  6. package/dist/client/SimplePDWClient.d.ts.map +1 -1
  7. package/dist/client/SimplePDWClient.js +102 -11
  8. package/dist/client/SimplePDWClient.js.map +1 -1
  9. package/dist/client/namespaces/IndexNamespace.d.ts +1 -1
  10. package/dist/client/namespaces/IndexNamespace.d.ts.map +1 -1
  11. package/dist/client/namespaces/IndexNamespace.js +7 -4
  12. package/dist/client/namespaces/IndexNamespace.js.map +1 -1
  13. package/dist/client/namespaces/MemoryNamespace.d.ts +45 -0
  14. package/dist/client/namespaces/MemoryNamespace.d.ts.map +1 -1
  15. package/dist/client/namespaces/MemoryNamespace.js +292 -46
  16. package/dist/client/namespaces/MemoryNamespace.js.map +1 -1
  17. package/dist/client/namespaces/consolidated/AdvancedNamespace.d.ts +215 -0
  18. package/dist/client/namespaces/consolidated/AdvancedNamespace.d.ts.map +1 -0
  19. package/dist/client/namespaces/consolidated/AdvancedNamespace.js +214 -0
  20. package/dist/client/namespaces/consolidated/AdvancedNamespace.js.map +1 -0
  21. package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts +12 -2
  22. package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts.map +1 -1
  23. package/dist/client/namespaces/consolidated/BlockchainNamespace.js +40 -2
  24. package/dist/client/namespaces/consolidated/BlockchainNamespace.js.map +1 -1
  25. package/dist/client/namespaces/consolidated/StorageNamespace.d.ts +67 -2
  26. package/dist/client/namespaces/consolidated/StorageNamespace.d.ts.map +1 -1
  27. package/dist/client/namespaces/consolidated/StorageNamespace.js +549 -16
  28. package/dist/client/namespaces/consolidated/StorageNamespace.js.map +1 -1
  29. package/dist/client/namespaces/consolidated/index.d.ts +1 -0
  30. package/dist/client/namespaces/consolidated/index.d.ts.map +1 -1
  31. package/dist/client/namespaces/consolidated/index.js +1 -0
  32. package/dist/client/namespaces/consolidated/index.js.map +1 -1
  33. package/dist/config/ConfigurationHelper.js +61 -61
  34. package/dist/config/defaults.d.ts.map +1 -1
  35. package/dist/config/defaults.js +11 -6
  36. package/dist/config/defaults.js.map +1 -1
  37. package/dist/core/types/index.d.ts +4 -0
  38. package/dist/core/types/index.d.ts.map +1 -1
  39. package/dist/core/types/index.js.map +1 -1
  40. package/dist/graph/GraphService.js +20 -20
  41. package/dist/infrastructure/seal/EncryptionService.d.ts +9 -5
  42. package/dist/infrastructure/seal/EncryptionService.d.ts.map +1 -1
  43. package/dist/infrastructure/seal/EncryptionService.js +37 -15
  44. package/dist/infrastructure/seal/EncryptionService.js.map +1 -1
  45. package/dist/infrastructure/seal/SealService.d.ts +13 -5
  46. package/dist/infrastructure/seal/SealService.d.ts.map +1 -1
  47. package/dist/infrastructure/seal/SealService.js +36 -34
  48. package/dist/infrastructure/seal/SealService.js.map +1 -1
  49. package/dist/infrastructure/walrus/WalrusStorageService.d.ts +6 -0
  50. package/dist/infrastructure/walrus/WalrusStorageService.d.ts.map +1 -1
  51. package/dist/infrastructure/walrus/WalrusStorageService.js +23 -4
  52. package/dist/infrastructure/walrus/WalrusStorageService.js.map +1 -1
  53. package/dist/langchain/createPDWRAG.js +30 -30
  54. package/dist/retrieval/MemoryDecryptionPipeline.d.ts.map +1 -1
  55. package/dist/retrieval/MemoryDecryptionPipeline.js +2 -1
  56. package/dist/retrieval/MemoryDecryptionPipeline.js.map +1 -1
  57. package/dist/services/CapabilityService.d.ts.map +1 -1
  58. package/dist/services/CapabilityService.js +30 -14
  59. package/dist/services/CapabilityService.js.map +1 -1
  60. package/dist/services/CrossContextPermissionService.d.ts.map +1 -1
  61. package/dist/services/CrossContextPermissionService.js +9 -7
  62. package/dist/services/CrossContextPermissionService.js.map +1 -1
  63. package/dist/services/EmbeddingService.d.ts +9 -0
  64. package/dist/services/EmbeddingService.d.ts.map +1 -1
  65. package/dist/services/EmbeddingService.js +31 -10
  66. package/dist/services/EmbeddingService.js.map +1 -1
  67. package/dist/services/EncryptionService.d.ts.map +1 -1
  68. package/dist/services/EncryptionService.js +6 -5
  69. package/dist/services/EncryptionService.js.map +1 -1
  70. package/dist/services/GeminiAIService.js +309 -309
  71. package/dist/services/MemoryIndexService.d.ts +2 -0
  72. package/dist/services/MemoryIndexService.d.ts.map +1 -1
  73. package/dist/services/MemoryIndexService.js +11 -4
  74. package/dist/services/MemoryIndexService.js.map +1 -1
  75. package/dist/services/StorageService.d.ts +1 -0
  76. package/dist/services/StorageService.d.ts.map +1 -1
  77. package/dist/services/StorageService.js +60 -10
  78. package/dist/services/StorageService.js.map +1 -1
  79. package/dist/services/TransactionService.d.ts +20 -0
  80. package/dist/services/TransactionService.d.ts.map +1 -1
  81. package/dist/services/TransactionService.js +43 -0
  82. package/dist/services/TransactionService.js.map +1 -1
  83. package/dist/services/VectorService.js +1 -1
  84. package/dist/services/VectorService.js.map +1 -1
  85. package/dist/services/ViewService.js +2 -2
  86. package/dist/services/ViewService.js.map +1 -1
  87. package/dist/vector/BrowserHnswIndexService.js +1 -1
  88. package/dist/vector/BrowserHnswIndexService.js.map +1 -1
  89. package/dist/vector/HnswWasmService.js +1 -1
  90. package/dist/vector/HnswWasmService.js.map +1 -1
  91. package/dist/vector/NodeHnswService.js +1 -1
  92. package/dist/vector/NodeHnswService.js.map +1 -1
  93. package/package.json +1 -1
  94. package/src/access/PermissionService.ts +635 -635
  95. package/src/access/index.ts +8 -8
  96. package/src/aggregation/AggregationService.ts +389 -389
  97. package/src/aggregation/index.ts +8 -8
  98. package/src/ai-sdk/PDWVectorStore.ts +715 -715
  99. package/src/ai-sdk/index.ts +65 -65
  100. package/src/ai-sdk/tools.ts +460 -460
  101. package/src/ai-sdk/types.ts +404 -404
  102. package/src/batch/BatchManager.ts +597 -597
  103. package/src/batch/BatchingService.ts +429 -429
  104. package/src/batch/MemoryProcessingCache.ts +492 -492
  105. package/src/batch/index.ts +30 -30
  106. package/src/browser.ts +200 -200
  107. package/src/client/ClientMemoryManager.ts +987 -987
  108. package/src/client/PersonalDataWallet.ts +345 -345
  109. package/src/client/SimplePDWClient.ts +1369 -1237
  110. package/src/client/factory.ts +154 -154
  111. package/src/client/namespaces/AnalyticsNamespace.ts +377 -377
  112. package/src/client/namespaces/BatchNamespace.ts +356 -356
  113. package/src/client/namespaces/CacheNamespace.ts +123 -123
  114. package/src/client/namespaces/CapabilityNamespace.ts +217 -217
  115. package/src/client/namespaces/ClassifyNamespace.ts +169 -169
  116. package/src/client/namespaces/ContextNamespace.ts +297 -297
  117. package/src/client/namespaces/EmbeddingsNamespace.ts +99 -99
  118. package/src/client/namespaces/EncryptionNamespace.ts +221 -221
  119. package/src/client/namespaces/GraphNamespace.ts +468 -468
  120. package/src/client/namespaces/IndexNamespace.ts +364 -361
  121. package/src/client/namespaces/MemoryNamespace.ts +1569 -1272
  122. package/src/client/namespaces/PermissionsNamespace.ts +254 -254
  123. package/src/client/namespaces/PipelineNamespace.ts +220 -220
  124. package/src/client/namespaces/SearchNamespace.ts +1049 -1049
  125. package/src/client/namespaces/StorageNamespace.ts +458 -458
  126. package/src/client/namespaces/TxNamespace.ts +260 -260
  127. package/src/client/namespaces/WalletNamespace.ts +243 -243
  128. package/src/client/namespaces/consolidated/AINamespace.ts +449 -449
  129. package/src/client/namespaces/consolidated/AdvancedNamespace.ts +264 -0
  130. package/src/client/namespaces/consolidated/BlockchainNamespace.ts +607 -564
  131. package/src/client/namespaces/consolidated/SecurityNamespace.ts +648 -648
  132. package/src/client/namespaces/consolidated/StorageNamespace.ts +1141 -497
  133. package/src/client/namespaces/consolidated/index.ts +41 -39
  134. package/src/client/signers/DappKitSigner.ts +207 -207
  135. package/src/client/signers/KeypairSigner.ts +108 -108
  136. package/src/client/signers/UnifiedSigner.ts +110 -110
  137. package/src/client/signers/WalletAdapterSigner.ts +159 -159
  138. package/src/client/signers/index.ts +26 -26
  139. package/src/config/ConfigurationHelper.ts +412 -412
  140. package/src/config/defaults.ts +56 -51
  141. package/src/config/index.ts +8 -8
  142. package/src/config/validation.ts +70 -70
  143. package/src/core/index.ts +14 -14
  144. package/src/core/interfaces/IService.ts +307 -307
  145. package/src/core/interfaces/index.ts +8 -8
  146. package/src/core/types/capability.ts +297 -297
  147. package/src/core/types/index.ts +874 -870
  148. package/src/core/types/wallet.ts +270 -270
  149. package/src/core/types.ts +9 -9
  150. package/src/core/wallet.ts +222 -222
  151. package/src/embedding/index.ts +19 -19
  152. package/src/embedding/types.ts +357 -357
  153. package/src/errors/index.ts +602 -602
  154. package/src/errors/recovery.ts +461 -461
  155. package/src/errors/validation.ts +567 -567
  156. package/src/generated/pdw/capability.ts +319 -319
  157. package/src/generated/pdw/deps/sui/object.ts +12 -12
  158. package/src/generated/pdw/deps/sui/vec_map.ts +32 -32
  159. package/src/generated/pdw/memory.ts +1087 -1087
  160. package/src/generated/pdw/wallet.ts +123 -123
  161. package/src/generated/utils/index.ts +159 -159
  162. package/src/graph/GraphService.ts +887 -887
  163. package/src/graph/KnowledgeGraphManager.ts +728 -728
  164. package/src/graph/index.ts +25 -25
  165. package/src/index.ts +498 -498
  166. package/src/infrastructure/index.ts +22 -22
  167. package/src/infrastructure/seal/EncryptionService.ts +628 -603
  168. package/src/infrastructure/seal/SealService.ts +613 -615
  169. package/src/infrastructure/seal/index.ts +9 -9
  170. package/src/infrastructure/sui/BlockchainManager.ts +627 -627
  171. package/src/infrastructure/sui/SuiService.ts +888 -888
  172. package/src/infrastructure/sui/index.ts +9 -9
  173. package/src/infrastructure/walrus/StorageManager.ts +604 -604
  174. package/src/infrastructure/walrus/WalrusStorageService.ts +637 -612
  175. package/src/infrastructure/walrus/index.ts +9 -9
  176. package/src/langchain/PDWEmbeddings.ts +145 -145
  177. package/src/langchain/PDWVectorStore.ts +456 -456
  178. package/src/langchain/createPDWRAG.ts +303 -303
  179. package/src/langchain/index.ts +47 -47
  180. package/src/permissions/ConsentRepository.browser.ts +249 -249
  181. package/src/permissions/ConsentRepository.ts +364 -364
  182. package/src/permissions/index.ts +9 -9
  183. package/src/pipeline/MemoryPipeline.ts +862 -862
  184. package/src/pipeline/PipelineManager.ts +683 -683
  185. package/src/pipeline/index.ts +26 -26
  186. package/src/retrieval/AdvancedSearchService.ts +629 -629
  187. package/src/retrieval/MemoryAnalyticsService.ts +711 -711
  188. package/src/retrieval/MemoryDecryptionPipeline.ts +825 -824
  189. package/src/retrieval/MemoryRetrievalService.ts +904 -904
  190. package/src/retrieval/index.ts +42 -42
  191. package/src/services/BatchService.ts +352 -352
  192. package/src/services/CapabilityService.ts +464 -448
  193. package/src/services/ClassifierService.ts +465 -465
  194. package/src/services/CrossContextPermissionService.ts +486 -484
  195. package/src/services/EmbeddingService.ts +796 -771
  196. package/src/services/EncryptionService.ts +712 -711
  197. package/src/services/GeminiAIService.ts +753 -753
  198. package/src/services/IndexManager.ts +977 -977
  199. package/src/services/MemoryIndexService.ts +1009 -1003
  200. package/src/services/MemoryService.ts +369 -369
  201. package/src/services/QueryService.ts +890 -890
  202. package/src/services/StorageService.ts +1182 -1126
  203. package/src/services/TransactionService.ts +838 -790
  204. package/src/services/VectorService.ts +462 -462
  205. package/src/services/ViewService.ts +484 -484
  206. package/src/services/index.ts +25 -25
  207. package/src/services/storage/BlobAttributesManager.ts +333 -333
  208. package/src/services/storage/KnowledgeGraphManager.ts +425 -425
  209. package/src/services/storage/MemorySearchManager.ts +387 -387
  210. package/src/services/storage/QuiltBatchManager.ts +1130 -1130
  211. package/src/services/storage/WalrusMetadataManager.ts +268 -268
  212. package/src/services/storage/WalrusStorageManager.ts +287 -287
  213. package/src/services/storage/index.ts +57 -57
  214. package/src/types/index.ts +13 -13
  215. package/src/utils/LRUCache.ts +378 -378
  216. package/src/utils/index.ts +76 -76
  217. package/src/utils/memoryIndexOnChain.ts +507 -507
  218. package/src/utils/rebuildIndex.ts +290 -290
  219. package/src/utils/rebuildIndexNode.ts +771 -771
  220. package/src/vector/BrowserHnswIndexService.ts +758 -758
  221. package/src/vector/HnswWasmService.ts +731 -731
  222. package/src/vector/IHnswService.ts +233 -233
  223. package/src/vector/NodeHnswService.ts +833 -833
  224. package/src/vector/VectorManager.ts +478 -478
  225. package/src/vector/createHnswService.ts +135 -135
  226. package/src/vector/index.ts +56 -56
  227. package/src/wallet/ContextWalletService.ts +656 -656
  228. package/src/wallet/MainWalletService.ts +317 -317
  229. package/src/wallet/index.ts +17 -17
@@ -1,871 +1,875 @@
1
- /**
2
- * Core TypeScript types for Personal Data Wallet SDK
3
- */
4
-
5
- import type { Transaction, TransactionArgument } from '@mysten/sui/transactions';
6
- import type { Signer } from '@mysten/sui/cryptography';
7
-
8
- // Batch processing types
9
- export interface BatchConfig {
10
- batchSize: number;
11
- delayMs: number;
12
- }
13
-
14
- export interface BatchStats {
15
- totalBatches: number;
16
- totalItems: number;
17
- averageBatchSize: number;
18
- totalProcessingTime: number;
19
- averageProcessingTime: number;
20
- successCount: number;
21
- errorCount: number;
22
- lastProcessed: Date;
23
- pendingBatches: number;
24
- processedToday: number;
25
- }
26
-
27
- // Base configuration for the SDK
28
- export interface PDWConfig {
29
- /** Package ID for the deployed Move contracts */
30
- packageId?: string;
31
- /** Access Registry ID for OAuth-style permission management */
32
- accessRegistryId?: string;
33
- /** Wallet Registry ID for wallet tracking */
34
- walletRegistryId?: string;
35
- /** Default encryption options */
36
- encryptionConfig?: EncryptionConfig;
37
- /** Storage configuration */
38
- storageConfig?: StorageConfig;
39
- /** Walrus storage configuration */
40
- walrusPublisherUrl?: string;
41
- walrusAggregatorUrl?: string;
42
- walrusMaxFileSize?: number;
43
- walrusTimeout?: number;
44
- }
45
-
46
- // Memory operations
47
- export interface MemoryCreateOptions {
48
- content: string;
49
- category: string;
50
- userAddress: string;
51
- topic?: string;
52
- importance?: number;
53
- customMetadata?: Record<string, string>;
54
- signer?: Signer;
55
- encrypt?: boolean;
56
- metadata?: Record<string, any>;
57
- }
58
-
59
- export interface MemoryContextOptions {
60
- query_text: string;
61
- user_address: string;
62
- user_signature?: string;
63
- k?: number;
64
- }
65
-
66
- export interface MemorySearchOptions {
67
- query: string;
68
- userAddress: string;
69
- category?: string;
70
- k?: number;
71
- includeContent?: boolean;
72
- threshold?: number; // Similarity threshold (0.0-1.0)
73
- userSignature?: string;
74
- includeMetadata?: boolean;
75
- timeRange?: {
76
- start?: string; // ISO date string
77
- end?: string; // ISO date string
78
- };
79
- }
80
-
81
- export interface MemorySearchResult {
82
- id: string;
83
- content?: string;
84
- category: string;
85
- timestamp: string;
86
- similarity_score?: number;
87
- isEncrypted: boolean;
88
- owner: string;
89
- blobId?: string;
90
- vectorId?: number;
91
- embeddings?: {
92
- content?: number[];
93
- metadata?: number[];
94
- dimension?: number;
95
- };
96
- metadata?: Record<string, any>;
97
- importance?: number;
98
- topic?: string;
99
- }
100
-
101
- // Advanced Memory Features - Embeddings & Vector Search
102
- export interface EmbeddingOptions {
103
- text: string;
104
- type?: 'content' | 'metadata' | 'query';
105
- userAddress: string;
106
- }
107
-
108
- export interface BasicEmbeddingResult {
109
- embeddings: number[];
110
- dimension: number;
111
- model: string;
112
- processingTime: number;
113
- }
114
-
115
- export interface VectorSearchOptions {
116
- queryVector: number[];
117
- userAddress: string;
118
- k?: number;
119
- efSearch?: number;
120
- category?: string;
121
- minSimilarity?: number;
122
- }
123
-
124
- export interface VectorSearchResult {
125
- results: Array<{
126
- memoryId: string;
127
- vectorId: number;
128
- similarity: number;
129
- distance: number;
130
- metadata?: any;
131
- }>;
132
- searchStats: {
133
- searchTime: number;
134
- nodesVisited: number;
135
- exactMatches: number;
136
- approximateMatches: number;
137
- };
138
- }
139
-
140
- export interface MemoryWithEmbeddingsOptions {
141
- content: string;
142
- category: string;
143
- topic?: string;
144
- importance?: number;
145
- userAddress: string;
146
- signer?: any;
147
- customMetadata?: Record<string, string>;
148
- generateEmbeddings?: boolean;
149
- }
150
-
151
- export interface MemoryWithEmbeddingsResult {
152
- memoryId: string;
153
- embeddings?: {
154
- content: number[];
155
- metadata: number[];
156
- };
157
- processingStats: {
158
- totalTime: number;
159
- embeddingTime: number;
160
- storageTime: number;
161
- blockchainTime: number;
162
- };
163
- }
164
-
165
- export interface MemoryWithContextOptions {
166
- memoryId: string;
167
- userAddress: string;
168
- includeRelated?: boolean;
169
- relatedCount?: number;
170
- contextRadius?: number;
171
- }
172
-
173
- export interface MemoryWithContextResult {
174
- memory: MemorySearchResult;
175
- relatedMemories?: MemorySearchResult[];
176
- contextGraph?: {
177
- nodes: Array<{ id: string; label: string; category: string }>;
178
- edges: Array<{ from: string; to: string; similarity: number }>;
179
- };
180
- }
181
-
182
- export interface BatchMemoryOptions {
183
- memories: Array<{
184
- content: string;
185
- category: string;
186
- topic?: string;
187
- importance?: number;
188
- }>;
189
- userAddress: string;
190
- batchSize?: number;
191
- generateEmbeddings?: boolean;
192
- }
193
-
194
- export interface BatchMemoryResult {
195
- results: Array<{
196
- success: boolean;
197
- memoryId?: string;
198
- error?: string;
199
- }>;
200
- batchStats: {
201
- totalProcessed: number;
202
- successful: number;
203
- failed: number;
204
- totalTime: number;
205
- averageTimePerMemory: number;
206
- };
207
- }
208
-
209
- export interface MemoryContext {
210
- context: string;
211
- relevantMemories: MemorySearchResult[];
212
- queryMetadata: {
213
- queryTimeMs: number;
214
- memoriesFound: number;
215
- contextLength: number;
216
- };
217
- }
218
-
219
- // ==================== VECTOR EMBEDDING INTERFACES ====================
220
-
221
- export interface VectorEmbedding {
222
- vector: number[];
223
- dimension: number;
224
- model: string; // e.g., 'text-embedding-ada-002', 'gemini-embedding'
225
- metadata?: {
226
- contentType?: string;
227
- category?: string;
228
- timestamp?: number;
229
- source?: string;
230
- };
231
- }
232
-
233
- export interface EmbeddingOptions {
234
- model?: string;
235
- dimension?: number; // Default 3072 for Gemini
236
- normalize?: boolean;
237
- batchSize?: number; // For batch processing
238
- }
239
-
240
- export interface EmbeddingResult {
241
- embedding: VectorEmbedding;
242
- tokenCount?: number;
243
- processingTimeMs?: number;
244
- }
245
-
246
- export interface VectorSearchOptions {
247
- vector: number[];
248
- k?: number;
249
- threshold?: number; // Similarity threshold
250
- category?: string;
251
- timeRange?: {
252
- start?: number;
253
- end?: number;
254
- };
255
- includeMetadata?: boolean;
256
- }
257
-
258
- export interface VectorSearchMatch {
259
- memoryId: string;
260
- similarity: number;
261
- distance: number;
262
- embedding?: VectorEmbedding;
263
- memory?: MemorySearchResult;
264
- }
265
-
266
- export interface HNSWIndexOptions {
267
- dimension: number;
268
- maxElements: number;
269
- efConstruction?: number; // Default 200
270
- m?: number; // Default 16
271
- randomSeed?: number;
272
- allowReplaceDeleted?: boolean;
273
- }
274
-
275
- export interface HNSWIndexStats {
276
- totalElements: number;
277
- dimension: number;
278
- maxElements: number;
279
- efConstruction: number;
280
- m: number;
281
- currentElementCount: number;
282
- deletedElementCount?: number;
283
- }
284
-
285
- export interface BatchEmbeddingJob {
286
- id: string;
287
- status: 'pending' | 'processing' | 'completed' | 'failed';
288
- userAddress: string;
289
- memories: Array<{
290
- memoryId: string;
291
- content: string;
292
- category: string;
293
- }>;
294
- progress: {
295
- total: number;
296
- completed: number;
297
- failed: number;
298
- };
299
- createdAt: number;
300
- updatedAt: number;
301
- completedAt?: number;
302
- }
303
-
304
- // Chat operations
305
- export interface ChatOptions {
306
- text: string;
307
- userId: string;
308
- sessionId?: string;
309
- model?: string;
310
- userAddress?: string;
311
- memoryContext?: string;
312
- enableMemoryContext?: boolean;
313
- maxMemoryContext?: number;
314
- signer?: Signer;
315
- }
316
-
317
- export interface ChatStreamEvent {
318
- type: 'start' | 'chunk' | 'end' | 'error';
319
- content?: string;
320
- intent?: string;
321
- memoryStored?: boolean;
322
- memoryId?: string;
323
- memoryExtraction?: any;
324
- relevantMemories?: MemorySearchResult[];
325
- message?: string;
326
- }
327
-
328
- export interface CreateSessionOptions {
329
- userAddress: string;
330
- title?: string;
331
- }
332
-
333
- // Note: ChatMessage and ChatSession are defined in "Chat System Types" section below
334
-
335
- // Storage operations (unified interface)
336
- export interface StorageConfig {
337
- provider?: 'walrus' | 'local';
338
- cacheEnabled?: boolean;
339
- encryptionEnabled?: boolean;
340
- }
341
-
342
- export interface StorageUploadResult {
343
- blobId: string;
344
- size: number;
345
- contentHash?: string;
346
- }
347
-
348
- // Encryption configuration
349
- export interface EncryptionConfig {
350
- enabled: boolean;
351
- keyServers?: string[];
352
- policyConfig?: Record<string, any>;
353
- }
354
-
355
- // View query result types
356
- export interface MemoryRecord {
357
- id: string;
358
- owner: string;
359
- category: string;
360
- vectorId: number;
361
- blobId: string;
362
- contentType: string;
363
- contentSize: number;
364
- contentHash: string;
365
- topic: string;
366
- importance: number;
367
- embeddingBlobId: string;
368
- createdAt: number;
369
- updatedAt: number;
370
- }
371
-
372
- export interface MemoryIndex {
373
- id: string;
374
- owner: string;
375
- version: number;
376
- indexBlobId: string;
377
- graphBlobId: string;
378
- memoryCount: number;
379
- lastUpdated: number;
380
- }
381
-
382
- export interface MemoryStats {
383
- totalMemories: number;
384
- categoryCounts: Record<string, number>;
385
- totalSize: number;
386
- averageImportance: number;
387
- lastActivityTime: number;
388
- }
389
-
390
- export interface AccessPermission {
391
- id: string;
392
- grantor: string;
393
- grantee: string;
394
- contentId: string;
395
- permissionType: string;
396
- expiresAt?: number;
397
- createdAt: number;
398
- isActive: boolean;
399
- }
400
-
401
- export interface ContentRegistry {
402
- id: string;
403
- owner: string;
404
- contentHash: string;
405
- encryptionInfo: string;
406
- accessCount: number;
407
- createdAt: number;
408
- }
409
-
410
- // Transaction builder types
411
- export type TransactionThunk = (tx: Transaction) => TransactionArgument | Promise<TransactionArgument>;
412
- export type AsyncTransactionThunk = (tx: Transaction) => Promise<TransactionArgument>;
413
-
414
- // API response types
415
- export interface APIResponse<T = any> {
416
- success: boolean;
417
- data?: T;
418
- message?: string;
419
- error?: string;
420
- }
421
-
422
- export interface MemoryStatsResponse {
423
- totalMemories: number;
424
- categoryCounts: Record<string, number>;
425
- totalSize: number;
426
- lastUpdated: string;
427
- }
428
-
429
- // BatchStats moved to core/index.ts to avoid duplication
430
-
431
- // Client extension types
432
- export interface ClientWithCoreApi {
433
- core: {
434
- getObject: (objectId: string) => Promise<any>;
435
- getObjects: (objectIds: string[]) => Promise<any[]>;
436
- executeTransaction: (tx: any) => Promise<any>;
437
- };
438
- $extend: <T>(extension: T) => any;
439
- }
440
-
441
- // Storage types
442
- export interface WalrusQuiltFile {
443
- identifier: string;
444
- content: Uint8Array | string;
445
- tags?: Record<string, string>;
446
- }
447
-
448
- export interface QuiltUploadResult {
449
- quiltId: string;
450
- files: Array<{
451
- identifier: string;
452
- blobId: string;
453
- }>;
454
- metadata?: Record<string, string>;
455
- }
456
-
457
- // Encryption types
458
- export interface EncryptionResult {
459
- encryptedData: Uint8Array;
460
- backupKey: Uint8Array;
461
- sessionKey?: any;
462
- }
463
-
464
- export interface DecryptionOptions {
465
- encryptedData: Uint8Array;
466
- userAddress: string;
467
- sessionKey?: any;
468
- signedTxBytes?: Uint8Array;
469
- }
470
-
471
- // SEAL-specific encryption types
472
- export interface SealEncryptionResult {
473
- encryptedContent: Uint8Array; // Changed from encryptedData: string to preserve binary format
474
- backupKey: string;
475
- contentHash: string;
476
- }
477
-
478
- export interface SealDecryptionOptions {
479
- encryptedContent?: Uint8Array; // New binary format (preferred)
480
- encryptedData?: string; // Legacy base64 format (deprecated)
481
- userAddress: string;
482
- requestingWallet?: string; // Wallet address requesting decryption (defaults to user)
483
- sessionKey?: any; // SessionKey from @mysten/seal
484
- signedTxBytes?: Uint8Array;
485
- /** MemoryCap object ID for capability-based access control */
486
- memoryCapId?: string;
487
- /** SEAL key ID bytes (computed from owner + nonce) - required for capability pattern */
488
- keyId?: Uint8Array;
489
- }
490
-
491
- export interface AccessGrantOptions {
492
- ownerAddress: string;
493
- recipientAddress: string;
494
- contentId: string;
495
- accessLevel: 'read' | 'write';
496
- expiresIn?: number;
497
- }
498
-
499
- export interface AccessRevokeOptions {
500
- ownerAddress: string;
501
- recipientAddress: string;
502
- contentId: string;
503
- }
504
-
505
- // Re-export capability types
506
- export * from './capability';
507
-
508
- // Error handling types
509
- export type ErrorCategory =
510
- | 'validation'
511
- | 'blockchain'
512
- | 'storage'
513
- | 'encryption'
514
- | 'network'
515
- | 'configuration'
516
- | 'authentication'
517
- | 'permission';
518
-
519
- export type ErrorSeverity = 'info' | 'warning' | 'error' | 'critical';
520
-
521
- export interface ErrorObject {
522
- name: string;
523
- message: string;
524
- code: string;
525
- category: ErrorCategory;
526
- severity: ErrorSeverity;
527
- context?: Record<string, any>;
528
- timestamp: string;
529
- stack?: string;
530
- originalError?: {
531
- name: string;
532
- message: string;
533
- stack?: string;
534
- };
535
- }
536
-
537
- export interface AccessControlOptions {
538
- memoryId: string;
539
- grantee: string;
540
- accessLevel: 'read' | 'write';
541
- expiresIn?: number;
542
- }
543
-
544
- // Utility types
545
- export type Thunk<T = any> = (tx: any) => T;
546
- export type AsyncThunk<T = any> = (tx: any) => Promise<T>;
547
-
548
- // Client extension interface
549
- export interface PDWClientExtension {
550
- // Top-level imperative methods
551
- createMemory: (options: MemoryCreateOptions) => Promise<string>;
552
- searchMemories: (options: MemorySearchOptions) => Promise<MemorySearchResult[]>;
553
- getMemoryContext: (query: string, userAddress: string) => Promise<MemoryContext>;
554
-
555
- // Transaction builders
556
- tx: {
557
- createMemoryRecord: (options: Omit<MemoryCreateOptions, 'signer'>) => Promise<Transaction>;
558
- deleteMemory: (memoryId: string) => Promise<Transaction>;
559
- updateMemoryIndex: (indexId: string, options: any) => Promise<Transaction>;
560
- };
561
-
562
- // Move call builders (for transaction composition)
563
- call: {
564
- createMemoryRecord: (options: any) => TransactionThunk;
565
- deleteMemory: (memoryId: string) => TransactionThunk;
566
- updateMemoryIndex: (indexId: string, options: any) => TransactionThunk;
567
- };
568
-
569
- // View/query methods
570
- view: {
571
- getUserMemories: (userAddress: string) => Promise<MemorySearchResult[]>;
572
- getMemoryIndex: (userAddress: string) => Promise<any>;
573
- getMemory: (memoryId: string) => Promise<MemorySearchResult | null>;
574
- };
575
-
576
- // BCS types (will be populated by generated code)
577
- bcs: Record<string, any>;
578
- }
579
-
580
- // Chat System Types
581
- export interface ChatMessage {
582
- id: string;
583
- type: 'user' | 'assistant' | 'system' | 'memory';
584
- content: string;
585
- timestamp?: string;
586
- memoryId?: string;
587
- walrusHash?: string;
588
- metadata?: Record<string, any>;
589
- }
590
-
591
- export interface ChatSession {
592
- id: string;
593
- title: string;
594
- owner: string;
595
- summary?: string;
596
- messages: ChatMessage[];
597
- created_at: string;
598
- updated_at: string;
599
- message_count: number;
600
- sui_object_id?: string;
601
- metadata?: Record<string, any>;
602
- }
603
-
604
- export interface ChatMessageRequest {
605
- text: string;
606
- userId: string;
607
- sessionId?: string;
608
- model?: string;
609
- originalUserMessage?: string;
610
- memoryContext?: string;
611
- userAddress?: string;
612
- }
613
-
614
- export interface ChatMessageResponse {
615
- content: string;
616
- type: string;
617
- memoryExtraction?: any;
618
- memoryStored?: boolean;
619
- memoryId?: string;
620
- }
621
-
622
- export interface CreateChatSessionRequest {
623
- userAddress: string;
624
- title?: string;
625
- modelName: string;
626
- suiObjectId?: string;
627
- }
628
-
629
- export interface ChatSessionResponse {
630
- session: ChatSession;
631
- success: boolean;
632
- message?: string;
633
- }
634
-
635
- export interface ChatSessionsResponse {
636
- success: boolean;
637
- sessions: ChatSession[];
638
- message?: string;
639
- }
640
-
641
- export interface StreamChatEvent {
642
- type: 'message' | 'memory' | 'error' | 'done' | 'thinking';
643
- data: string;
644
- timestamp?: string;
645
- metadata?: Record<string, any>;
646
- }
647
-
648
- export interface UpdateSessionTitleRequest {
649
- userAddress: string;
650
- title: string;
651
- }
652
-
653
- export interface AddMessageRequest {
654
- content: string;
655
- type: 'user' | 'assistant' | 'system';
656
- userAddress: string;
657
- memoryId?: string;
658
- metadata?: Record<string, any>;
659
- }
660
-
661
- export interface SaveSummaryRequest {
662
- sessionId: string;
663
- summary: string;
664
- userAddress: string;
665
- }
666
-
667
- export interface ChatStreamOptions {
668
- onMessage?: (event: StreamChatEvent) => void;
669
- onThinking?: (event: StreamChatEvent) => void;
670
- onMemory?: (event: StreamChatEvent) => void;
671
- onError?: (event: StreamChatEvent) => void;
672
- onDone?: () => void;
673
- abortController?: AbortController;
674
- }
675
-
676
- // Storage System Types
677
- export interface StorageMetadata {
678
- contentType: string;
679
- size: number;
680
- tags: Record<string, string>;
681
- createdAt: string;
682
- updatedAt?: string;
683
- encrypted: boolean;
684
- compressionType?: 'gzip' | 'brotli' | 'none';
685
- checksumSha256: string;
686
- }
687
-
688
- export interface StorageOptions {
689
- provider?: 'walrus' | 'local';
690
- encrypt?: boolean;
691
- compress?: 'gzip' | 'none'; // Remove brotli as it's not widely supported
692
- tags?: Record<string, string>;
693
- cacheLocally?: boolean;
694
- cacheExpiry?: number; // milliseconds
695
- retryAttempts?: number;
696
- }
697
-
698
- export interface StorageResult {
699
- blobId: string;
700
- walrusUrl: string;
701
- metadata: StorageMetadata;
702
- cached: boolean;
703
- processingTimeMs: number;
704
- }
705
-
706
- export interface RetrieveOptions {
707
- useCache?: boolean;
708
- decrypt?: boolean;
709
- decompress?: boolean;
710
- maxCacheAge?: number; // milliseconds
711
- }
712
-
713
- export interface RetrieveResult {
714
- content: Uint8Array | string;
715
- metadata: StorageMetadata;
716
- fromCache: boolean;
717
- retrievalTimeMs: number;
718
- }
719
-
720
- export interface StorageStats {
721
- totalItems: number;
722
- totalSize: number;
723
- cacheSize: number;
724
- cacheHitRate: number;
725
- averageStorageTime: number;
726
- averageRetrievalTime: number;
727
- }
728
-
729
- export interface WalrusConfig {
730
- publisherUrl: string;
731
- aggregatorUrl: string;
732
- maxFileSize?: number; // bytes, default 1GB
733
- timeout?: number; // milliseconds, default 30s
734
- }
735
-
736
- export interface CacheEntry {
737
- content: Uint8Array | string;
738
- metadata: StorageMetadata;
739
- cachedAt: number;
740
- accessCount: number;
741
- lastAccessed: number;
742
- }
743
-
744
- export interface StorageFilter {
745
- tags?: Record<string, string>;
746
- contentType?: string;
747
- minSize?: number;
748
- maxSize?: number;
749
- createdAfter?: string;
750
- createdBefore?: string;
751
- encrypted?: boolean;
752
- }
753
-
754
- // Transaction Types
755
- export interface TransactionOptions {
756
- /** Gas budget for the transaction */
757
- gasBudget?: number;
758
- /** Gas price override */
759
- gasPrice?: number;
760
- /** Sender address override (defaults to signer address) */
761
- sender?: string;
762
- }
763
-
764
- export interface TransactionResult {
765
- /** Transaction digest */
766
- digest: string;
767
- /** Transaction effects */
768
- effects?: any;
769
- /** Created objects */
770
- createdObjects?: Array<{ objectId: string; objectType: string }>;
771
- /** Mutated objects */
772
- mutatedObjects?: Array<{ objectId: string; objectType: string }>;
773
- /** Deleted objects */
774
- deletedObjects?: string[];
775
- /** Gas used */
776
- gasUsed?: number;
777
- /** Transaction status */
778
- status: 'success' | 'failure';
779
- /** Error message if failed */
780
- error?: string;
781
- }
782
-
783
- // Memory Transaction Types
784
- export interface CreateMemoryRecordTxOptions extends TransactionOptions {
785
- category: string;
786
- vectorId: number | bigint;
787
- blobId: string;
788
- contentType: string;
789
- contentSize: number | bigint;
790
- contentHash: string;
791
- topic: string;
792
- importance: number;
793
- embeddingBlobId: string;
794
- }
795
-
796
- export interface CreateMemoryRecordLightweightTxOptions extends TransactionOptions {
797
- category: string;
798
- vectorId: number | bigint;
799
- blobId: string;
800
- blobObjectId?: string; // Optional Walrus blob object ID for metadata queries
801
- importance: number;
802
- }
803
-
804
- export interface UpdateMemoryMetadataTxOptions extends TransactionOptions {
805
- memoryId: string;
806
- metadataBlobId: string;
807
- embeddingDimension: number;
808
- }
809
-
810
- /**
811
- * Options for comprehensive memory record update
812
- *
813
- * All fields are optional - empty string or 0 means "no change"
814
- */
815
- export interface UpdateMemoryRecordTxOptions extends TransactionOptions {
816
- /** Memory object ID on Sui */
817
- memoryId: string;
818
- /** New Walrus blob ID (empty = no change) */
819
- newBlobId?: string;
820
- /** New category (empty = no change) */
821
- newCategory?: string;
822
- /** New topic (empty = no change) */
823
- newTopic?: string;
824
- /** New importance 1-10 (0 = no change) */
825
- newImportance?: number;
826
- /** New embedding blob ID (empty = no change) */
827
- newEmbeddingBlobId?: string;
828
- /** New content hash (empty = no change) */
829
- newContentHash?: string;
830
- /** New content size (0 = no change) */
831
- newContentSize?: number;
832
- }
833
-
834
- export interface DeleteMemoryRecordTxOptions extends TransactionOptions {
835
- memoryId: string;
836
- }
837
-
838
- export interface CreateMemoryIndexTxOptions extends TransactionOptions {
839
- indexBlobId: string;
840
- graphBlobId: string;
841
- }
842
-
843
- export interface UpdateMemoryIndexTxOptions extends TransactionOptions {
844
- /** MemoryIndex object ID on-chain */
845
- indexId: string;
846
- /** Expected version for optimistic locking (must match current on-chain version) */
847
- expectedVersion: number;
848
- /** New index blob ID on Walrus */
849
- newIndexBlobId: string;
850
- /** New graph blob ID on Walrus */
851
- newGraphBlobId: string;
852
- }
853
-
854
- // Access Control Transaction Types
855
- export interface GrantAccessTxOptions extends TransactionOptions {
856
- contentId: string;
857
- recipient: string;
858
- permissions: number[];
859
- expirationTime?: number;
860
- }
861
-
862
- export interface RevokeAccessTxOptions extends TransactionOptions {
863
- contentId: string;
864
- recipient: string;
865
- }
866
-
867
- export interface RegisterContentTxOptions extends TransactionOptions {
868
- contentHash: string;
869
- encryptionKey: string;
870
- accessPolicy: number[];
1
+ /**
2
+ * Core TypeScript types for Personal Data Wallet SDK
3
+ */
4
+
5
+ import type { Transaction, TransactionArgument } from '@mysten/sui/transactions';
6
+ import type { Signer } from '@mysten/sui/cryptography';
7
+
8
+ // Batch processing types
9
+ export interface BatchConfig {
10
+ batchSize: number;
11
+ delayMs: number;
12
+ }
13
+
14
+ export interface BatchStats {
15
+ totalBatches: number;
16
+ totalItems: number;
17
+ averageBatchSize: number;
18
+ totalProcessingTime: number;
19
+ averageProcessingTime: number;
20
+ successCount: number;
21
+ errorCount: number;
22
+ lastProcessed: Date;
23
+ pendingBatches: number;
24
+ processedToday: number;
25
+ }
26
+
27
+ // Base configuration for the SDK
28
+ export interface PDWConfig {
29
+ /** Package ID for the deployed Move contracts */
30
+ packageId?: string;
31
+ /** Access Registry ID for OAuth-style permission management */
32
+ accessRegistryId?: string;
33
+ /** Wallet Registry ID for wallet tracking */
34
+ walletRegistryId?: string;
35
+ /** Default encryption options */
36
+ encryptionConfig?: EncryptionConfig;
37
+ /** Storage configuration */
38
+ storageConfig?: StorageConfig;
39
+ /** Walrus storage configuration */
40
+ /** Publisher URL for direct blob uploads (server-side) */
41
+ walrusPublisherUrl?: string;
42
+ /** Upload Relay URL for browser/mobile uploads (fewer connections, faster) */
43
+ walrusUploadRelayUrl?: string;
44
+ /** Aggregator URL for blob retrieval */
45
+ walrusAggregatorUrl?: string;
46
+ walrusMaxFileSize?: number;
47
+ walrusTimeout?: number;
48
+ }
49
+
50
+ // Memory operations
51
+ export interface MemoryCreateOptions {
52
+ content: string;
53
+ category: string;
54
+ userAddress: string;
55
+ topic?: string;
56
+ importance?: number;
57
+ customMetadata?: Record<string, string>;
58
+ signer?: Signer;
59
+ encrypt?: boolean;
60
+ metadata?: Record<string, any>;
61
+ }
62
+
63
+ export interface MemoryContextOptions {
64
+ query_text: string;
65
+ user_address: string;
66
+ user_signature?: string;
67
+ k?: number;
68
+ }
69
+
70
+ export interface MemorySearchOptions {
71
+ query: string;
72
+ userAddress: string;
73
+ category?: string;
74
+ k?: number;
75
+ includeContent?: boolean;
76
+ threshold?: number; // Similarity threshold (0.0-1.0)
77
+ userSignature?: string;
78
+ includeMetadata?: boolean;
79
+ timeRange?: {
80
+ start?: string; // ISO date string
81
+ end?: string; // ISO date string
82
+ };
83
+ }
84
+
85
+ export interface MemorySearchResult {
86
+ id: string;
87
+ content?: string;
88
+ category: string;
89
+ timestamp: string;
90
+ similarity_score?: number;
91
+ isEncrypted: boolean;
92
+ owner: string;
93
+ blobId?: string;
94
+ vectorId?: number;
95
+ embeddings?: {
96
+ content?: number[];
97
+ metadata?: number[];
98
+ dimension?: number;
99
+ };
100
+ metadata?: Record<string, any>;
101
+ importance?: number;
102
+ topic?: string;
103
+ }
104
+
105
+ // Advanced Memory Features - Embeddings & Vector Search
106
+ export interface EmbeddingOptions {
107
+ text: string;
108
+ type?: 'content' | 'metadata' | 'query';
109
+ userAddress: string;
110
+ }
111
+
112
+ export interface BasicEmbeddingResult {
113
+ embeddings: number[];
114
+ dimension: number;
115
+ model: string;
116
+ processingTime: number;
117
+ }
118
+
119
+ export interface VectorSearchOptions {
120
+ queryVector: number[];
121
+ userAddress: string;
122
+ k?: number;
123
+ efSearch?: number;
124
+ category?: string;
125
+ minSimilarity?: number;
126
+ }
127
+
128
+ export interface VectorSearchResult {
129
+ results: Array<{
130
+ memoryId: string;
131
+ vectorId: number;
132
+ similarity: number;
133
+ distance: number;
134
+ metadata?: any;
135
+ }>;
136
+ searchStats: {
137
+ searchTime: number;
138
+ nodesVisited: number;
139
+ exactMatches: number;
140
+ approximateMatches: number;
141
+ };
142
+ }
143
+
144
+ export interface MemoryWithEmbeddingsOptions {
145
+ content: string;
146
+ category: string;
147
+ topic?: string;
148
+ importance?: number;
149
+ userAddress: string;
150
+ signer?: any;
151
+ customMetadata?: Record<string, string>;
152
+ generateEmbeddings?: boolean;
153
+ }
154
+
155
+ export interface MemoryWithEmbeddingsResult {
156
+ memoryId: string;
157
+ embeddings?: {
158
+ content: number[];
159
+ metadata: number[];
160
+ };
161
+ processingStats: {
162
+ totalTime: number;
163
+ embeddingTime: number;
164
+ storageTime: number;
165
+ blockchainTime: number;
166
+ };
167
+ }
168
+
169
+ export interface MemoryWithContextOptions {
170
+ memoryId: string;
171
+ userAddress: string;
172
+ includeRelated?: boolean;
173
+ relatedCount?: number;
174
+ contextRadius?: number;
175
+ }
176
+
177
+ export interface MemoryWithContextResult {
178
+ memory: MemorySearchResult;
179
+ relatedMemories?: MemorySearchResult[];
180
+ contextGraph?: {
181
+ nodes: Array<{ id: string; label: string; category: string }>;
182
+ edges: Array<{ from: string; to: string; similarity: number }>;
183
+ };
184
+ }
185
+
186
+ export interface BatchMemoryOptions {
187
+ memories: Array<{
188
+ content: string;
189
+ category: string;
190
+ topic?: string;
191
+ importance?: number;
192
+ }>;
193
+ userAddress: string;
194
+ batchSize?: number;
195
+ generateEmbeddings?: boolean;
196
+ }
197
+
198
+ export interface BatchMemoryResult {
199
+ results: Array<{
200
+ success: boolean;
201
+ memoryId?: string;
202
+ error?: string;
203
+ }>;
204
+ batchStats: {
205
+ totalProcessed: number;
206
+ successful: number;
207
+ failed: number;
208
+ totalTime: number;
209
+ averageTimePerMemory: number;
210
+ };
211
+ }
212
+
213
+ export interface MemoryContext {
214
+ context: string;
215
+ relevantMemories: MemorySearchResult[];
216
+ queryMetadata: {
217
+ queryTimeMs: number;
218
+ memoriesFound: number;
219
+ contextLength: number;
220
+ };
221
+ }
222
+
223
+ // ==================== VECTOR EMBEDDING INTERFACES ====================
224
+
225
+ export interface VectorEmbedding {
226
+ vector: number[];
227
+ dimension: number;
228
+ model: string; // e.g., 'text-embedding-ada-002', 'gemini-embedding'
229
+ metadata?: {
230
+ contentType?: string;
231
+ category?: string;
232
+ timestamp?: number;
233
+ source?: string;
234
+ };
235
+ }
236
+
237
+ export interface EmbeddingOptions {
238
+ model?: string;
239
+ dimension?: number; // Default 3072 for Gemini
240
+ normalize?: boolean;
241
+ batchSize?: number; // For batch processing
242
+ }
243
+
244
+ export interface EmbeddingResult {
245
+ embedding: VectorEmbedding;
246
+ tokenCount?: number;
247
+ processingTimeMs?: number;
248
+ }
249
+
250
+ export interface VectorSearchOptions {
251
+ vector: number[];
252
+ k?: number;
253
+ threshold?: number; // Similarity threshold
254
+ category?: string;
255
+ timeRange?: {
256
+ start?: number;
257
+ end?: number;
258
+ };
259
+ includeMetadata?: boolean;
260
+ }
261
+
262
+ export interface VectorSearchMatch {
263
+ memoryId: string;
264
+ similarity: number;
265
+ distance: number;
266
+ embedding?: VectorEmbedding;
267
+ memory?: MemorySearchResult;
268
+ }
269
+
270
+ export interface HNSWIndexOptions {
271
+ dimension: number;
272
+ maxElements: number;
273
+ efConstruction?: number; // Default 200
274
+ m?: number; // Default 16
275
+ randomSeed?: number;
276
+ allowReplaceDeleted?: boolean;
277
+ }
278
+
279
+ export interface HNSWIndexStats {
280
+ totalElements: number;
281
+ dimension: number;
282
+ maxElements: number;
283
+ efConstruction: number;
284
+ m: number;
285
+ currentElementCount: number;
286
+ deletedElementCount?: number;
287
+ }
288
+
289
+ export interface BatchEmbeddingJob {
290
+ id: string;
291
+ status: 'pending' | 'processing' | 'completed' | 'failed';
292
+ userAddress: string;
293
+ memories: Array<{
294
+ memoryId: string;
295
+ content: string;
296
+ category: string;
297
+ }>;
298
+ progress: {
299
+ total: number;
300
+ completed: number;
301
+ failed: number;
302
+ };
303
+ createdAt: number;
304
+ updatedAt: number;
305
+ completedAt?: number;
306
+ }
307
+
308
+ // Chat operations
309
+ export interface ChatOptions {
310
+ text: string;
311
+ userId: string;
312
+ sessionId?: string;
313
+ model?: string;
314
+ userAddress?: string;
315
+ memoryContext?: string;
316
+ enableMemoryContext?: boolean;
317
+ maxMemoryContext?: number;
318
+ signer?: Signer;
319
+ }
320
+
321
+ export interface ChatStreamEvent {
322
+ type: 'start' | 'chunk' | 'end' | 'error';
323
+ content?: string;
324
+ intent?: string;
325
+ memoryStored?: boolean;
326
+ memoryId?: string;
327
+ memoryExtraction?: any;
328
+ relevantMemories?: MemorySearchResult[];
329
+ message?: string;
330
+ }
331
+
332
+ export interface CreateSessionOptions {
333
+ userAddress: string;
334
+ title?: string;
335
+ }
336
+
337
+ // Note: ChatMessage and ChatSession are defined in "Chat System Types" section below
338
+
339
+ // Storage operations (unified interface)
340
+ export interface StorageConfig {
341
+ provider?: 'walrus' | 'local';
342
+ cacheEnabled?: boolean;
343
+ encryptionEnabled?: boolean;
344
+ }
345
+
346
+ export interface StorageUploadResult {
347
+ blobId: string;
348
+ size: number;
349
+ contentHash?: string;
350
+ }
351
+
352
+ // Encryption configuration
353
+ export interface EncryptionConfig {
354
+ enabled: boolean;
355
+ keyServers?: string[];
356
+ policyConfig?: Record<string, any>;
357
+ }
358
+
359
+ // View query result types
360
+ export interface MemoryRecord {
361
+ id: string;
362
+ owner: string;
363
+ category: string;
364
+ vectorId: number;
365
+ blobId: string;
366
+ contentType: string;
367
+ contentSize: number;
368
+ contentHash: string;
369
+ topic: string;
370
+ importance: number;
371
+ embeddingBlobId: string;
372
+ createdAt: number;
373
+ updatedAt: number;
374
+ }
375
+
376
+ export interface MemoryIndex {
377
+ id: string;
378
+ owner: string;
379
+ version: number;
380
+ indexBlobId: string;
381
+ graphBlobId: string;
382
+ memoryCount: number;
383
+ lastUpdated: number;
384
+ }
385
+
386
+ export interface MemoryStats {
387
+ totalMemories: number;
388
+ categoryCounts: Record<string, number>;
389
+ totalSize: number;
390
+ averageImportance: number;
391
+ lastActivityTime: number;
392
+ }
393
+
394
+ export interface AccessPermission {
395
+ id: string;
396
+ grantor: string;
397
+ grantee: string;
398
+ contentId: string;
399
+ permissionType: string;
400
+ expiresAt?: number;
401
+ createdAt: number;
402
+ isActive: boolean;
403
+ }
404
+
405
+ export interface ContentRegistry {
406
+ id: string;
407
+ owner: string;
408
+ contentHash: string;
409
+ encryptionInfo: string;
410
+ accessCount: number;
411
+ createdAt: number;
412
+ }
413
+
414
+ // Transaction builder types
415
+ export type TransactionThunk = (tx: Transaction) => TransactionArgument | Promise<TransactionArgument>;
416
+ export type AsyncTransactionThunk = (tx: Transaction) => Promise<TransactionArgument>;
417
+
418
+ // API response types
419
+ export interface APIResponse<T = any> {
420
+ success: boolean;
421
+ data?: T;
422
+ message?: string;
423
+ error?: string;
424
+ }
425
+
426
+ export interface MemoryStatsResponse {
427
+ totalMemories: number;
428
+ categoryCounts: Record<string, number>;
429
+ totalSize: number;
430
+ lastUpdated: string;
431
+ }
432
+
433
+ // BatchStats moved to core/index.ts to avoid duplication
434
+
435
+ // Client extension types
436
+ export interface ClientWithCoreApi {
437
+ core: {
438
+ getObject: (objectId: string) => Promise<any>;
439
+ getObjects: (objectIds: string[]) => Promise<any[]>;
440
+ executeTransaction: (tx: any) => Promise<any>;
441
+ };
442
+ $extend: <T>(extension: T) => any;
443
+ }
444
+
445
+ // Storage types
446
+ export interface WalrusQuiltFile {
447
+ identifier: string;
448
+ content: Uint8Array | string;
449
+ tags?: Record<string, string>;
450
+ }
451
+
452
+ export interface QuiltUploadResult {
453
+ quiltId: string;
454
+ files: Array<{
455
+ identifier: string;
456
+ blobId: string;
457
+ }>;
458
+ metadata?: Record<string, string>;
459
+ }
460
+
461
+ // Encryption types
462
+ export interface EncryptionResult {
463
+ encryptedData: Uint8Array;
464
+ backupKey: Uint8Array;
465
+ sessionKey?: any;
466
+ }
467
+
468
+ export interface DecryptionOptions {
469
+ encryptedData: Uint8Array;
470
+ userAddress: string;
471
+ sessionKey?: any;
472
+ signedTxBytes?: Uint8Array;
473
+ }
474
+
475
+ // SEAL-specific encryption types
476
+ export interface SealEncryptionResult {
477
+ encryptedContent: Uint8Array; // Changed from encryptedData: string to preserve binary format
478
+ backupKey: string;
479
+ contentHash: string;
480
+ }
481
+
482
+ export interface SealDecryptionOptions {
483
+ encryptedContent?: Uint8Array; // New binary format (preferred)
484
+ encryptedData?: string; // Legacy base64 format (deprecated)
485
+ userAddress: string;
486
+ requestingWallet?: string; // Wallet address requesting decryption (defaults to user)
487
+ sessionKey?: any; // SessionKey from @mysten/seal
488
+ signedTxBytes?: Uint8Array;
489
+ /** MemoryCap object ID for capability-based access control */
490
+ memoryCapId?: string;
491
+ /** SEAL key ID bytes (computed from owner + nonce) - required for capability pattern */
492
+ keyId?: Uint8Array;
493
+ }
494
+
495
+ export interface AccessGrantOptions {
496
+ ownerAddress: string;
497
+ recipientAddress: string;
498
+ contentId: string;
499
+ accessLevel: 'read' | 'write';
500
+ expiresIn?: number;
501
+ }
502
+
503
+ export interface AccessRevokeOptions {
504
+ ownerAddress: string;
505
+ recipientAddress: string;
506
+ contentId: string;
507
+ }
508
+
509
+ // Re-export capability types
510
+ export * from './capability';
511
+
512
+ // Error handling types
513
+ export type ErrorCategory =
514
+ | 'validation'
515
+ | 'blockchain'
516
+ | 'storage'
517
+ | 'encryption'
518
+ | 'network'
519
+ | 'configuration'
520
+ | 'authentication'
521
+ | 'permission';
522
+
523
+ export type ErrorSeverity = 'info' | 'warning' | 'error' | 'critical';
524
+
525
+ export interface ErrorObject {
526
+ name: string;
527
+ message: string;
528
+ code: string;
529
+ category: ErrorCategory;
530
+ severity: ErrorSeverity;
531
+ context?: Record<string, any>;
532
+ timestamp: string;
533
+ stack?: string;
534
+ originalError?: {
535
+ name: string;
536
+ message: string;
537
+ stack?: string;
538
+ };
539
+ }
540
+
541
+ export interface AccessControlOptions {
542
+ memoryId: string;
543
+ grantee: string;
544
+ accessLevel: 'read' | 'write';
545
+ expiresIn?: number;
546
+ }
547
+
548
+ // Utility types
549
+ export type Thunk<T = any> = (tx: any) => T;
550
+ export type AsyncThunk<T = any> = (tx: any) => Promise<T>;
551
+
552
+ // Client extension interface
553
+ export interface PDWClientExtension {
554
+ // Top-level imperative methods
555
+ createMemory: (options: MemoryCreateOptions) => Promise<string>;
556
+ searchMemories: (options: MemorySearchOptions) => Promise<MemorySearchResult[]>;
557
+ getMemoryContext: (query: string, userAddress: string) => Promise<MemoryContext>;
558
+
559
+ // Transaction builders
560
+ tx: {
561
+ createMemoryRecord: (options: Omit<MemoryCreateOptions, 'signer'>) => Promise<Transaction>;
562
+ deleteMemory: (memoryId: string) => Promise<Transaction>;
563
+ updateMemoryIndex: (indexId: string, options: any) => Promise<Transaction>;
564
+ };
565
+
566
+ // Move call builders (for transaction composition)
567
+ call: {
568
+ createMemoryRecord: (options: any) => TransactionThunk;
569
+ deleteMemory: (memoryId: string) => TransactionThunk;
570
+ updateMemoryIndex: (indexId: string, options: any) => TransactionThunk;
571
+ };
572
+
573
+ // View/query methods
574
+ view: {
575
+ getUserMemories: (userAddress: string) => Promise<MemorySearchResult[]>;
576
+ getMemoryIndex: (userAddress: string) => Promise<any>;
577
+ getMemory: (memoryId: string) => Promise<MemorySearchResult | null>;
578
+ };
579
+
580
+ // BCS types (will be populated by generated code)
581
+ bcs: Record<string, any>;
582
+ }
583
+
584
+ // Chat System Types
585
+ export interface ChatMessage {
586
+ id: string;
587
+ type: 'user' | 'assistant' | 'system' | 'memory';
588
+ content: string;
589
+ timestamp?: string;
590
+ memoryId?: string;
591
+ walrusHash?: string;
592
+ metadata?: Record<string, any>;
593
+ }
594
+
595
+ export interface ChatSession {
596
+ id: string;
597
+ title: string;
598
+ owner: string;
599
+ summary?: string;
600
+ messages: ChatMessage[];
601
+ created_at: string;
602
+ updated_at: string;
603
+ message_count: number;
604
+ sui_object_id?: string;
605
+ metadata?: Record<string, any>;
606
+ }
607
+
608
+ export interface ChatMessageRequest {
609
+ text: string;
610
+ userId: string;
611
+ sessionId?: string;
612
+ model?: string;
613
+ originalUserMessage?: string;
614
+ memoryContext?: string;
615
+ userAddress?: string;
616
+ }
617
+
618
+ export interface ChatMessageResponse {
619
+ content: string;
620
+ type: string;
621
+ memoryExtraction?: any;
622
+ memoryStored?: boolean;
623
+ memoryId?: string;
624
+ }
625
+
626
+ export interface CreateChatSessionRequest {
627
+ userAddress: string;
628
+ title?: string;
629
+ modelName: string;
630
+ suiObjectId?: string;
631
+ }
632
+
633
+ export interface ChatSessionResponse {
634
+ session: ChatSession;
635
+ success: boolean;
636
+ message?: string;
637
+ }
638
+
639
+ export interface ChatSessionsResponse {
640
+ success: boolean;
641
+ sessions: ChatSession[];
642
+ message?: string;
643
+ }
644
+
645
+ export interface StreamChatEvent {
646
+ type: 'message' | 'memory' | 'error' | 'done' | 'thinking';
647
+ data: string;
648
+ timestamp?: string;
649
+ metadata?: Record<string, any>;
650
+ }
651
+
652
+ export interface UpdateSessionTitleRequest {
653
+ userAddress: string;
654
+ title: string;
655
+ }
656
+
657
+ export interface AddMessageRequest {
658
+ content: string;
659
+ type: 'user' | 'assistant' | 'system';
660
+ userAddress: string;
661
+ memoryId?: string;
662
+ metadata?: Record<string, any>;
663
+ }
664
+
665
+ export interface SaveSummaryRequest {
666
+ sessionId: string;
667
+ summary: string;
668
+ userAddress: string;
669
+ }
670
+
671
+ export interface ChatStreamOptions {
672
+ onMessage?: (event: StreamChatEvent) => void;
673
+ onThinking?: (event: StreamChatEvent) => void;
674
+ onMemory?: (event: StreamChatEvent) => void;
675
+ onError?: (event: StreamChatEvent) => void;
676
+ onDone?: () => void;
677
+ abortController?: AbortController;
678
+ }
679
+
680
+ // Storage System Types
681
+ export interface StorageMetadata {
682
+ contentType: string;
683
+ size: number;
684
+ tags: Record<string, string>;
685
+ createdAt: string;
686
+ updatedAt?: string;
687
+ encrypted: boolean;
688
+ compressionType?: 'gzip' | 'brotli' | 'none';
689
+ checksumSha256: string;
690
+ }
691
+
692
+ export interface StorageOptions {
693
+ provider?: 'walrus' | 'local';
694
+ encrypt?: boolean;
695
+ compress?: 'gzip' | 'none'; // Remove brotli as it's not widely supported
696
+ tags?: Record<string, string>;
697
+ cacheLocally?: boolean;
698
+ cacheExpiry?: number; // milliseconds
699
+ retryAttempts?: number;
700
+ }
701
+
702
+ export interface StorageResult {
703
+ blobId: string;
704
+ walrusUrl: string;
705
+ metadata: StorageMetadata;
706
+ cached: boolean;
707
+ processingTimeMs: number;
708
+ }
709
+
710
+ export interface RetrieveOptions {
711
+ useCache?: boolean;
712
+ decrypt?: boolean;
713
+ decompress?: boolean;
714
+ maxCacheAge?: number; // milliseconds
715
+ }
716
+
717
+ export interface RetrieveResult {
718
+ content: Uint8Array | string;
719
+ metadata: StorageMetadata;
720
+ fromCache: boolean;
721
+ retrievalTimeMs: number;
722
+ }
723
+
724
+ export interface StorageStats {
725
+ totalItems: number;
726
+ totalSize: number;
727
+ cacheSize: number;
728
+ cacheHitRate: number;
729
+ averageStorageTime: number;
730
+ averageRetrievalTime: number;
731
+ }
732
+
733
+ export interface WalrusConfig {
734
+ publisherUrl: string;
735
+ aggregatorUrl: string;
736
+ maxFileSize?: number; // bytes, default 1GB
737
+ timeout?: number; // milliseconds, default 30s
738
+ }
739
+
740
+ export interface CacheEntry {
741
+ content: Uint8Array | string;
742
+ metadata: StorageMetadata;
743
+ cachedAt: number;
744
+ accessCount: number;
745
+ lastAccessed: number;
746
+ }
747
+
748
+ export interface StorageFilter {
749
+ tags?: Record<string, string>;
750
+ contentType?: string;
751
+ minSize?: number;
752
+ maxSize?: number;
753
+ createdAfter?: string;
754
+ createdBefore?: string;
755
+ encrypted?: boolean;
756
+ }
757
+
758
+ // Transaction Types
759
+ export interface TransactionOptions {
760
+ /** Gas budget for the transaction */
761
+ gasBudget?: number;
762
+ /** Gas price override */
763
+ gasPrice?: number;
764
+ /** Sender address override (defaults to signer address) */
765
+ sender?: string;
766
+ }
767
+
768
+ export interface TransactionResult {
769
+ /** Transaction digest */
770
+ digest: string;
771
+ /** Transaction effects */
772
+ effects?: any;
773
+ /** Created objects */
774
+ createdObjects?: Array<{ objectId: string; objectType: string }>;
775
+ /** Mutated objects */
776
+ mutatedObjects?: Array<{ objectId: string; objectType: string }>;
777
+ /** Deleted objects */
778
+ deletedObjects?: string[];
779
+ /** Gas used */
780
+ gasUsed?: number;
781
+ /** Transaction status */
782
+ status: 'success' | 'failure';
783
+ /** Error message if failed */
784
+ error?: string;
785
+ }
786
+
787
+ // Memory Transaction Types
788
+ export interface CreateMemoryRecordTxOptions extends TransactionOptions {
789
+ category: string;
790
+ vectorId: number | bigint;
791
+ blobId: string;
792
+ contentType: string;
793
+ contentSize: number | bigint;
794
+ contentHash: string;
795
+ topic: string;
796
+ importance: number;
797
+ embeddingBlobId: string;
798
+ }
799
+
800
+ export interface CreateMemoryRecordLightweightTxOptions extends TransactionOptions {
801
+ category: string;
802
+ vectorId: number | bigint;
803
+ blobId: string;
804
+ blobObjectId?: string; // Optional Walrus blob object ID for metadata queries
805
+ importance: number;
806
+ }
807
+
808
+ export interface UpdateMemoryMetadataTxOptions extends TransactionOptions {
809
+ memoryId: string;
810
+ metadataBlobId: string;
811
+ embeddingDimension: number;
812
+ }
813
+
814
+ /**
815
+ * Options for comprehensive memory record update
816
+ *
817
+ * All fields are optional - empty string or 0 means "no change"
818
+ */
819
+ export interface UpdateMemoryRecordTxOptions extends TransactionOptions {
820
+ /** Memory object ID on Sui */
821
+ memoryId: string;
822
+ /** New Walrus blob ID (empty = no change) */
823
+ newBlobId?: string;
824
+ /** New category (empty = no change) */
825
+ newCategory?: string;
826
+ /** New topic (empty = no change) */
827
+ newTopic?: string;
828
+ /** New importance 1-10 (0 = no change) */
829
+ newImportance?: number;
830
+ /** New embedding blob ID (empty = no change) */
831
+ newEmbeddingBlobId?: string;
832
+ /** New content hash (empty = no change) */
833
+ newContentHash?: string;
834
+ /** New content size (0 = no change) */
835
+ newContentSize?: number;
836
+ }
837
+
838
+ export interface DeleteMemoryRecordTxOptions extends TransactionOptions {
839
+ memoryId: string;
840
+ }
841
+
842
+ export interface CreateMemoryIndexTxOptions extends TransactionOptions {
843
+ indexBlobId: string;
844
+ graphBlobId: string;
845
+ }
846
+
847
+ export interface UpdateMemoryIndexTxOptions extends TransactionOptions {
848
+ /** MemoryIndex object ID on-chain */
849
+ indexId: string;
850
+ /** Expected version for optimistic locking (must match current on-chain version) */
851
+ expectedVersion: number;
852
+ /** New index blob ID on Walrus */
853
+ newIndexBlobId: string;
854
+ /** New graph blob ID on Walrus */
855
+ newGraphBlobId: string;
856
+ }
857
+
858
+ // Access Control Transaction Types
859
+ export interface GrantAccessTxOptions extends TransactionOptions {
860
+ contentId: string;
861
+ recipient: string;
862
+ permissions: number[];
863
+ expirationTime?: number;
864
+ }
865
+
866
+ export interface RevokeAccessTxOptions extends TransactionOptions {
867
+ contentId: string;
868
+ recipient: string;
869
+ }
870
+
871
+ export interface RegisterContentTxOptions extends TransactionOptions {
872
+ contentHash: string;
873
+ encryptionKey: string;
874
+ accessPolicy: number[];
871
875
  }