@cmdoss/memwal-sdk 0.6.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ARCHITECTURE.md +547 -547
- package/BENCHMARKS.md +238 -238
- package/README.md +310 -181
- package/dist/ai-sdk/tools.d.ts +2 -2
- package/dist/ai-sdk/tools.js +2 -2
- package/dist/client/ClientMemoryManager.js +2 -2
- package/dist/client/ClientMemoryManager.js.map +1 -1
- package/dist/client/PersonalDataWallet.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.d.ts +29 -1
- package/dist/client/SimplePDWClient.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.js +45 -13
- package/dist/client/SimplePDWClient.js.map +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.d.ts +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.js +1 -1
- package/dist/client/namespaces/MemoryNamespace.d.ts +31 -0
- package/dist/client/namespaces/MemoryNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/MemoryNamespace.js +272 -39
- package/dist/client/namespaces/MemoryNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/AINamespace.d.ts +2 -2
- package/dist/client/namespaces/consolidated/AINamespace.js +2 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts +12 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js +62 -4
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts +67 -2
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.js +549 -16
- package/dist/client/namespaces/consolidated/StorageNamespace.js.map +1 -1
- package/dist/config/ConfigurationHelper.js +61 -61
- package/dist/config/defaults.js +2 -2
- package/dist/config/defaults.js.map +1 -1
- package/dist/graph/GraphService.js +21 -21
- package/dist/graph/GraphService.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/seal/EncryptionService.d.ts +9 -5
- package/dist/infrastructure/seal/EncryptionService.d.ts.map +1 -1
- package/dist/infrastructure/seal/EncryptionService.js +37 -15
- package/dist/infrastructure/seal/EncryptionService.js.map +1 -1
- package/dist/infrastructure/seal/SealService.d.ts +13 -5
- package/dist/infrastructure/seal/SealService.d.ts.map +1 -1
- package/dist/infrastructure/seal/SealService.js +36 -34
- package/dist/infrastructure/seal/SealService.js.map +1 -1
- package/dist/langchain/createPDWRAG.js +30 -30
- package/dist/retrieval/MemoryDecryptionPipeline.d.ts.map +1 -1
- package/dist/retrieval/MemoryDecryptionPipeline.js +2 -1
- package/dist/retrieval/MemoryDecryptionPipeline.js.map +1 -1
- package/dist/retrieval/MemoryRetrievalService.d.ts +31 -0
- package/dist/retrieval/MemoryRetrievalService.d.ts.map +1 -1
- package/dist/retrieval/MemoryRetrievalService.js +44 -4
- package/dist/retrieval/MemoryRetrievalService.js.map +1 -1
- package/dist/services/CapabilityService.d.ts.map +1 -1
- package/dist/services/CapabilityService.js +30 -14
- package/dist/services/CapabilityService.js.map +1 -1
- package/dist/services/CrossContextPermissionService.d.ts.map +1 -1
- package/dist/services/CrossContextPermissionService.js +9 -7
- package/dist/services/CrossContextPermissionService.js.map +1 -1
- package/dist/services/EmbeddingService.d.ts +28 -1
- package/dist/services/EmbeddingService.d.ts.map +1 -1
- package/dist/services/EmbeddingService.js +54 -0
- package/dist/services/EmbeddingService.js.map +1 -1
- package/dist/services/EncryptionService.d.ts.map +1 -1
- package/dist/services/EncryptionService.js +6 -5
- package/dist/services/EncryptionService.js.map +1 -1
- package/dist/services/GeminiAIService.js +309 -309
- package/dist/services/IndexManager.d.ts +5 -1
- package/dist/services/IndexManager.d.ts.map +1 -1
- package/dist/services/IndexManager.js +17 -40
- package/dist/services/IndexManager.js.map +1 -1
- package/dist/services/QueryService.js +1 -1
- package/dist/services/QueryService.js.map +1 -1
- package/dist/services/StorageService.d.ts +11 -0
- package/dist/services/StorageService.d.ts.map +1 -1
- package/dist/services/StorageService.js +73 -10
- package/dist/services/StorageService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +20 -0
- package/dist/services/TransactionService.d.ts.map +1 -1
- package/dist/services/TransactionService.js +43 -0
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/ViewService.js +2 -2
- package/dist/services/ViewService.js.map +1 -1
- package/dist/services/storage/QuiltBatchManager.d.ts +101 -1
- package/dist/services/storage/QuiltBatchManager.d.ts.map +1 -1
- package/dist/services/storage/QuiltBatchManager.js +410 -20
- package/dist/services/storage/QuiltBatchManager.js.map +1 -1
- package/dist/services/storage/index.d.ts +1 -1
- package/dist/services/storage/index.d.ts.map +1 -1
- package/dist/services/storage/index.js.map +1 -1
- package/dist/utils/LRUCache.d.ts +106 -0
- package/dist/utils/LRUCache.d.ts.map +1 -0
- package/dist/utils/LRUCache.js +281 -0
- package/dist/utils/LRUCache.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/memoryIndexOnChain.d.ts +212 -0
- package/dist/utils/memoryIndexOnChain.d.ts.map +1 -0
- package/dist/utils/memoryIndexOnChain.js +312 -0
- package/dist/utils/memoryIndexOnChain.js.map +1 -0
- package/dist/utils/rebuildIndexNode.d.ts +29 -0
- package/dist/utils/rebuildIndexNode.d.ts.map +1 -1
- package/dist/utils/rebuildIndexNode.js +366 -98
- package/dist/utils/rebuildIndexNode.js.map +1 -1
- package/dist/vector/HnswWasmService.d.ts +20 -5
- package/dist/vector/HnswWasmService.d.ts.map +1 -1
- package/dist/vector/HnswWasmService.js +73 -40
- package/dist/vector/HnswWasmService.js.map +1 -1
- package/dist/vector/IHnswService.d.ts +10 -1
- package/dist/vector/IHnswService.d.ts.map +1 -1
- package/dist/vector/IHnswService.js.map +1 -1
- package/dist/vector/NodeHnswService.d.ts +16 -0
- package/dist/vector/NodeHnswService.d.ts.map +1 -1
- package/dist/vector/NodeHnswService.js +84 -5
- package/dist/vector/NodeHnswService.js.map +1 -1
- package/dist/vector/createHnswService.d.ts +1 -1
- package/dist/vector/createHnswService.js +1 -1
- package/dist/vector/index.d.ts +1 -1
- package/dist/vector/index.js +1 -1
- package/package.json +157 -157
- package/src/access/PermissionService.ts +635 -635
- package/src/aggregation/AggregationService.ts +389 -389
- package/src/ai-sdk/PDWVectorStore.ts +715 -715
- package/src/ai-sdk/index.ts +65 -65
- package/src/ai-sdk/tools.ts +460 -460
- package/src/ai-sdk/types.ts +404 -404
- package/src/batch/BatchManager.ts +597 -597
- package/src/batch/BatchingService.ts +429 -429
- package/src/batch/MemoryProcessingCache.ts +492 -492
- package/src/batch/index.ts +30 -30
- package/src/browser.ts +200 -200
- package/src/client/ClientMemoryManager.ts +987 -987
- package/src/client/PersonalDataWallet.ts +345 -345
- package/src/client/SimplePDWClient.ts +1289 -1222
- package/src/client/factory.ts +154 -154
- package/src/client/namespaces/AnalyticsNamespace.ts +377 -377
- package/src/client/namespaces/BatchNamespace.ts +356 -356
- package/src/client/namespaces/CacheNamespace.ts +123 -123
- package/src/client/namespaces/CapabilityNamespace.ts +217 -217
- package/src/client/namespaces/ClassifyNamespace.ts +169 -169
- package/src/client/namespaces/ContextNamespace.ts +297 -297
- package/src/client/namespaces/EmbeddingsNamespace.ts +99 -99
- package/src/client/namespaces/EncryptionNamespace.ts +221 -221
- package/src/client/namespaces/GraphNamespace.ts +468 -468
- package/src/client/namespaces/IndexNamespace.ts +361 -361
- package/src/client/namespaces/MemoryNamespace.ts +1422 -1135
- package/src/client/namespaces/PermissionsNamespace.ts +254 -254
- package/src/client/namespaces/PipelineNamespace.ts +220 -220
- package/src/client/namespaces/SearchNamespace.ts +1049 -1049
- package/src/client/namespaces/StorageNamespace.ts +458 -458
- package/src/client/namespaces/TxNamespace.ts +260 -260
- package/src/client/namespaces/WalletNamespace.ts +243 -243
- package/src/client/namespaces/consolidated/AINamespace.ts +449 -449
- package/src/client/namespaces/consolidated/BlockchainNamespace.ts +607 -546
- package/src/client/namespaces/consolidated/SecurityNamespace.ts +648 -648
- package/src/client/namespaces/consolidated/StorageNamespace.ts +1141 -497
- package/src/client/namespaces/consolidated/index.ts +39 -39
- package/src/client/signers/KeypairSigner.ts +108 -108
- package/src/client/signers/UnifiedSigner.ts +110 -110
- package/src/client/signers/WalletAdapterSigner.ts +159 -159
- package/src/client/signers/index.ts +26 -26
- package/src/config/ConfigurationHelper.ts +412 -412
- package/src/config/defaults.ts +51 -51
- package/src/config/index.ts +8 -8
- package/src/config/validation.ts +70 -70
- package/src/core/index.ts +14 -14
- package/src/core/interfaces/IService.ts +307 -307
- package/src/core/interfaces/index.ts +8 -8
- package/src/core/types/capability.ts +297 -297
- package/src/core/types/index.ts +870 -870
- package/src/core/types/wallet.ts +270 -270
- package/src/core/types.ts +9 -9
- package/src/core/wallet.ts +222 -222
- package/src/embedding/index.ts +19 -19
- package/src/embedding/types.ts +357 -357
- package/src/errors/index.ts +602 -602
- package/src/errors/recovery.ts +461 -461
- package/src/errors/validation.ts +567 -567
- package/src/generated/pdw/capability.ts +319 -319
- package/src/graph/GraphService.ts +887 -887
- package/src/graph/KnowledgeGraphManager.ts +728 -728
- package/src/graph/index.ts +25 -25
- package/src/index.ts +498 -474
- package/src/infrastructure/index.ts +22 -22
- package/src/infrastructure/seal/EncryptionService.ts +628 -603
- package/src/infrastructure/seal/SealService.ts +613 -615
- package/src/infrastructure/seal/index.ts +9 -9
- package/src/infrastructure/sui/BlockchainManager.ts +627 -627
- package/src/infrastructure/sui/SuiService.ts +888 -888
- package/src/infrastructure/sui/index.ts +9 -9
- package/src/infrastructure/walrus/StorageManager.ts +604 -604
- package/src/infrastructure/walrus/WalrusStorageService.ts +612 -612
- package/src/infrastructure/walrus/index.ts +9 -9
- package/src/langchain/PDWEmbeddings.ts +145 -145
- package/src/langchain/PDWVectorStore.ts +456 -456
- package/src/langchain/createPDWRAG.ts +303 -303
- package/src/langchain/index.ts +47 -47
- package/src/permissions/ConsentRepository.browser.ts +249 -249
- package/src/permissions/ConsentRepository.ts +364 -364
- package/src/pipeline/MemoryPipeline.ts +862 -862
- package/src/pipeline/PipelineManager.ts +683 -683
- package/src/pipeline/index.ts +26 -26
- package/src/retrieval/AdvancedSearchService.ts +629 -629
- package/src/retrieval/MemoryAnalyticsService.ts +711 -711
- package/src/retrieval/MemoryDecryptionPipeline.ts +825 -824
- package/src/retrieval/MemoryRetrievalService.ts +904 -830
- package/src/retrieval/index.ts +42 -42
- package/src/services/BatchService.ts +352 -352
- package/src/services/CapabilityService.ts +464 -448
- package/src/services/ClassifierService.ts +465 -465
- package/src/services/CrossContextPermissionService.ts +486 -484
- package/src/services/EmbeddingService.ts +771 -706
- package/src/services/EncryptionService.ts +712 -711
- package/src/services/GeminiAIService.ts +753 -753
- package/src/services/IndexManager.ts +977 -1004
- package/src/services/MemoryIndexService.ts +1003 -1003
- package/src/services/MemoryService.ts +369 -369
- package/src/services/QueryService.ts +890 -890
- package/src/services/StorageService.ts +1182 -1111
- package/src/services/TransactionService.ts +838 -790
- package/src/services/VectorService.ts +462 -462
- package/src/services/ViewService.ts +484 -484
- package/src/services/index.ts +25 -25
- package/src/services/storage/BlobAttributesManager.ts +333 -333
- package/src/services/storage/KnowledgeGraphManager.ts +425 -425
- package/src/services/storage/MemorySearchManager.ts +387 -387
- package/src/services/storage/QuiltBatchManager.ts +1130 -660
- package/src/services/storage/WalrusMetadataManager.ts +268 -268
- package/src/services/storage/WalrusStorageManager.ts +287 -287
- package/src/services/storage/index.ts +57 -52
- package/src/types/index.ts +13 -13
- package/src/utils/LRUCache.ts +378 -0
- package/src/utils/index.ts +76 -68
- package/src/utils/memoryIndexOnChain.ts +507 -0
- package/src/utils/rebuildIndex.ts +290 -290
- package/src/utils/rebuildIndexNode.ts +771 -424
- package/src/vector/BrowserHnswIndexService.ts +758 -758
- package/src/vector/HnswWasmService.ts +731 -679
- package/src/vector/IHnswService.ts +233 -224
- package/src/vector/NodeHnswService.ts +833 -735
- package/src/vector/VectorManager.ts +478 -478
- package/src/vector/createHnswService.ts +135 -135
- package/src/vector/index.ts +56 -56
- package/src/wallet/ContextWalletService.ts +656 -656
- package/src/wallet/MainWalletService.ts +317 -317
package/src/core/types/index.ts
CHANGED
|
@@ -1,871 +1,871 @@
|
|
|
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
|
|
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
|
+
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[];
|
|
871
871
|
}
|