@cmdoss/memwal-sdk 0.9.0 → 1.0.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 (174) hide show
  1. package/README.md +157 -52
  2. package/dist/client/ClientMemoryManager.d.ts.map +1 -1
  3. package/dist/client/ClientMemoryManager.js +25 -8
  4. package/dist/client/ClientMemoryManager.js.map +1 -1
  5. package/dist/client/PersonalDataWallet.d.ts.map +1 -1
  6. package/dist/client/SimplePDWClient.d.ts +2 -1
  7. package/dist/client/SimplePDWClient.d.ts.map +1 -1
  8. package/dist/client/SimplePDWClient.js +23 -6
  9. package/dist/client/SimplePDWClient.js.map +1 -1
  10. package/dist/client/namespaces/MemoryNamespace.d.ts +6 -0
  11. package/dist/client/namespaces/MemoryNamespace.d.ts.map +1 -1
  12. package/dist/client/namespaces/MemoryNamespace.js +131 -18
  13. package/dist/client/namespaces/MemoryNamespace.js.map +1 -1
  14. package/dist/client/namespaces/consolidated/StorageNamespace.d.ts +3 -1
  15. package/dist/client/namespaces/consolidated/StorageNamespace.d.ts.map +1 -1
  16. package/dist/client/namespaces/consolidated/StorageNamespace.js.map +1 -1
  17. package/dist/config/ConfigurationHelper.js +61 -61
  18. package/dist/config/index.d.ts +1 -0
  19. package/dist/config/index.d.ts.map +1 -1
  20. package/dist/config/index.js +2 -0
  21. package/dist/config/index.js.map +1 -1
  22. package/dist/config/modelDefaults.d.ts +67 -0
  23. package/dist/config/modelDefaults.d.ts.map +1 -0
  24. package/dist/config/modelDefaults.js +91 -0
  25. package/dist/config/modelDefaults.js.map +1 -0
  26. package/dist/graph/GraphService.d.ts.map +1 -1
  27. package/dist/graph/GraphService.js +22 -21
  28. package/dist/graph/GraphService.js.map +1 -1
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/langchain/createPDWRAG.js +30 -30
  34. package/dist/pipeline/MemoryPipeline.d.ts.map +1 -1
  35. package/dist/pipeline/MemoryPipeline.js +2 -1
  36. package/dist/pipeline/MemoryPipeline.js.map +1 -1
  37. package/dist/services/GeminiAIService.d.ts.map +1 -1
  38. package/dist/services/GeminiAIService.js +311 -310
  39. package/dist/services/GeminiAIService.js.map +1 -1
  40. package/dist/services/StorageService.d.ts +4 -1
  41. package/dist/services/StorageService.d.ts.map +1 -1
  42. package/dist/services/StorageService.js.map +1 -1
  43. package/dist/services/storage/QuiltBatchManager.d.ts +7 -0
  44. package/dist/services/storage/QuiltBatchManager.d.ts.map +1 -1
  45. package/dist/services/storage/QuiltBatchManager.js +24 -5
  46. package/dist/services/storage/QuiltBatchManager.js.map +1 -1
  47. package/dist/services/storage/WalrusStorageManager.d.ts +10 -1
  48. package/dist/services/storage/WalrusStorageManager.d.ts.map +1 -1
  49. package/dist/services/storage/WalrusStorageManager.js +53 -12
  50. package/dist/services/storage/WalrusStorageManager.js.map +1 -1
  51. package/dist/vector/BrowserHnswIndexService.js +2 -2
  52. package/dist/vector/BrowserHnswIndexService.js.map +1 -1
  53. package/dist/vector/NodeHnswService.js +4 -4
  54. package/dist/vector/NodeHnswService.js.map +1 -1
  55. package/dist/vector/createHnswService.d.ts +4 -0
  56. package/dist/vector/createHnswService.d.ts.map +1 -1
  57. package/dist/vector/createHnswService.js +15 -3
  58. package/dist/vector/createHnswService.js.map +1 -1
  59. package/package.json +1 -1
  60. package/src/access/PermissionService.ts +635 -635
  61. package/src/aggregation/AggregationService.ts +389 -389
  62. package/src/ai-sdk/PDWVectorStore.ts +715 -715
  63. package/src/ai-sdk/index.ts +65 -65
  64. package/src/ai-sdk/tools.ts +460 -460
  65. package/src/ai-sdk/types.ts +404 -404
  66. package/src/batch/BatchManager.ts +597 -597
  67. package/src/batch/BatchingService.ts +429 -429
  68. package/src/batch/MemoryProcessingCache.ts +492 -492
  69. package/src/batch/index.ts +30 -30
  70. package/src/browser.ts +200 -200
  71. package/src/client/ClientMemoryManager.ts +1004 -987
  72. package/src/client/PersonalDataWallet.ts +345 -345
  73. package/src/client/SimplePDWClient.ts +1387 -1369
  74. package/src/client/factory.ts +154 -154
  75. package/src/client/namespaces/AnalyticsNamespace.ts +377 -377
  76. package/src/client/namespaces/BatchNamespace.ts +356 -356
  77. package/src/client/namespaces/CacheNamespace.ts +123 -123
  78. package/src/client/namespaces/CapabilityNamespace.ts +217 -217
  79. package/src/client/namespaces/ClassifyNamespace.ts +169 -169
  80. package/src/client/namespaces/ContextNamespace.ts +297 -297
  81. package/src/client/namespaces/EncryptionNamespace.ts +221 -221
  82. package/src/client/namespaces/GraphNamespace.ts +468 -468
  83. package/src/client/namespaces/IndexNamespace.ts +364 -364
  84. package/src/client/namespaces/MemoryNamespace.ts +1704 -1569
  85. package/src/client/namespaces/PermissionsNamespace.ts +254 -254
  86. package/src/client/namespaces/PipelineNamespace.ts +220 -220
  87. package/src/client/namespaces/StorageNamespace.ts +458 -458
  88. package/src/client/namespaces/TxNamespace.ts +260 -260
  89. package/src/client/namespaces/WalletNamespace.ts +243 -243
  90. package/src/client/namespaces/consolidated/BlockchainNamespace.ts +607 -607
  91. package/src/client/namespaces/consolidated/SecurityNamespace.ts +648 -648
  92. package/src/client/namespaces/consolidated/StorageNamespace.ts +1143 -1141
  93. package/src/client/namespaces/consolidated/index.ts +41 -41
  94. package/src/client/signers/KeypairSigner.ts +108 -108
  95. package/src/client/signers/UnifiedSigner.ts +110 -110
  96. package/src/client/signers/WalletAdapterSigner.ts +159 -159
  97. package/src/client/signers/index.ts +26 -26
  98. package/src/config/ConfigurationHelper.ts +412 -412
  99. package/src/config/defaults.ts +56 -56
  100. package/src/config/index.ts +16 -9
  101. package/src/config/modelDefaults.ts +103 -0
  102. package/src/config/validation.ts +70 -70
  103. package/src/core/index.ts +14 -14
  104. package/src/core/interfaces/IService.ts +307 -307
  105. package/src/core/interfaces/index.ts +8 -8
  106. package/src/core/types/capability.ts +297 -297
  107. package/src/core/types/index.ts +874 -874
  108. package/src/core/types/wallet.ts +270 -270
  109. package/src/core/types.ts +9 -9
  110. package/src/core/wallet.ts +222 -222
  111. package/src/embedding/index.ts +19 -19
  112. package/src/embedding/types.ts +357 -357
  113. package/src/errors/index.ts +602 -602
  114. package/src/errors/recovery.ts +461 -461
  115. package/src/errors/validation.ts +567 -567
  116. package/src/generated/pdw/capability.ts +319 -319
  117. package/src/graph/GraphService.ts +888 -887
  118. package/src/graph/KnowledgeGraphManager.ts +728 -728
  119. package/src/graph/index.ts +25 -25
  120. package/src/index.ts +498 -498
  121. package/src/infrastructure/index.ts +22 -22
  122. package/src/infrastructure/seal/EncryptionService.ts +628 -628
  123. package/src/infrastructure/seal/SealService.ts +613 -613
  124. package/src/infrastructure/seal/index.ts +9 -9
  125. package/src/infrastructure/sui/BlockchainManager.ts +627 -627
  126. package/src/infrastructure/sui/SuiService.ts +888 -888
  127. package/src/infrastructure/sui/index.ts +9 -9
  128. package/src/infrastructure/walrus/StorageManager.ts +604 -604
  129. package/src/infrastructure/walrus/WalrusStorageService.ts +637 -637
  130. package/src/infrastructure/walrus/index.ts +9 -9
  131. package/src/langchain/createPDWRAG.ts +303 -303
  132. package/src/langchain/index.ts +47 -47
  133. package/src/permissions/ConsentRepository.browser.ts +249 -249
  134. package/src/permissions/ConsentRepository.ts +364 -364
  135. package/src/pipeline/MemoryPipeline.ts +863 -862
  136. package/src/pipeline/PipelineManager.ts +683 -683
  137. package/src/pipeline/index.ts +26 -26
  138. package/src/retrieval/AdvancedSearchService.ts +629 -629
  139. package/src/retrieval/MemoryAnalyticsService.ts +711 -711
  140. package/src/retrieval/MemoryDecryptionPipeline.ts +825 -825
  141. package/src/retrieval/index.ts +42 -42
  142. package/src/services/BatchService.ts +352 -352
  143. package/src/services/CapabilityService.ts +464 -464
  144. package/src/services/ClassifierService.ts +465 -465
  145. package/src/services/CrossContextPermissionService.ts +486 -486
  146. package/src/services/EmbeddingService.ts +796 -796
  147. package/src/services/EncryptionService.ts +712 -712
  148. package/src/services/GeminiAIService.ts +754 -753
  149. package/src/services/MemoryIndexService.ts +1009 -1009
  150. package/src/services/MemoryService.ts +369 -369
  151. package/src/services/QueryService.ts +890 -890
  152. package/src/services/StorageService.ts +1185 -1182
  153. package/src/services/TransactionService.ts +838 -838
  154. package/src/services/VectorService.ts +462 -462
  155. package/src/services/ViewService.ts +484 -484
  156. package/src/services/index.ts +25 -25
  157. package/src/services/storage/BlobAttributesManager.ts +333 -333
  158. package/src/services/storage/KnowledgeGraphManager.ts +425 -425
  159. package/src/services/storage/MemorySearchManager.ts +387 -387
  160. package/src/services/storage/QuiltBatchManager.ts +1157 -1130
  161. package/src/services/storage/WalrusMetadataManager.ts +268 -268
  162. package/src/services/storage/WalrusStorageManager.ts +333 -287
  163. package/src/services/storage/index.ts +57 -57
  164. package/src/types/index.ts +13 -13
  165. package/src/utils/index.ts +76 -76
  166. package/src/utils/memoryIndexOnChain.ts +507 -507
  167. package/src/vector/BrowserHnswIndexService.ts +758 -758
  168. package/src/vector/HnswWasmService.ts +731 -731
  169. package/src/vector/IHnswService.ts +233 -233
  170. package/src/vector/NodeHnswService.ts +833 -833
  171. package/src/vector/createHnswService.ts +147 -135
  172. package/src/vector/index.ts +56 -56
  173. package/src/wallet/ContextWalletService.ts +656 -656
  174. package/src/wallet/MainWalletService.ts +317 -317
@@ -1,875 +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
- /** 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[];
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[];
875
875
  }