mindcache 1.0.1 → 2.0.0-alpha.1

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.
@@ -0,0 +1,279 @@
1
+ /**
2
+ * Attributes that can be set on a MindCache key
3
+ */
4
+ interface KeyAttributes {
5
+ /** If true, the key cannot be modified by AI tools */
6
+ readonly: boolean;
7
+ /** If true, the key is included in system prompts */
8
+ visible: boolean;
9
+ /** If true, the key is a system key that cannot be deleted */
10
+ hardcoded: boolean;
11
+ /** If true, the value will be processed through template injection */
12
+ template: boolean;
13
+ /** The type of value stored */
14
+ type: 'text' | 'image' | 'file' | 'json';
15
+ /** MIME type for files/images */
16
+ contentType?: string;
17
+ /** Tags for categorizing keys */
18
+ tags?: string[];
19
+ }
20
+ /**
21
+ * A single entry in the MindCache store
22
+ */
23
+ interface STMEntry {
24
+ value: unknown;
25
+ attributes: KeyAttributes;
26
+ }
27
+ /**
28
+ * The full MindCache state (key-value pairs with attributes)
29
+ */
30
+ type STM = {
31
+ [key: string]: STMEntry;
32
+ };
33
+ /**
34
+ * A function that is called when a key changes
35
+ */
36
+ type Listener = () => void;
37
+ /**
38
+ * Default attributes for new keys
39
+ */
40
+ declare const DEFAULT_KEY_ATTRIBUTES: KeyAttributes;
41
+
42
+ /**
43
+ * Cloud configuration options for MindCache constructor
44
+ */
45
+ interface MindCacheCloudOptions {
46
+ /** Instance ID to connect to */
47
+ instanceId: string;
48
+ /** Project ID (optional, defaults to 'default') */
49
+ projectId?: string;
50
+ /** API endpoint to fetch WS token (recommended for browser) */
51
+ tokenEndpoint?: string;
52
+ /** Direct API key (server-side only, never expose in browser!) */
53
+ apiKey?: string;
54
+ /** WebSocket base URL (defaults to production) */
55
+ baseUrl?: string;
56
+ }
57
+ /**
58
+ * Constructor options for MindCache
59
+ */
60
+ interface MindCacheOptions {
61
+ /** Cloud sync configuration. If omitted, runs in local-only mode. */
62
+ cloud?: MindCacheCloudOptions;
63
+ }
64
+ type ConnectionState$1 = 'disconnected' | 'connecting' | 'connected' | 'error';
65
+ declare class MindCache {
66
+ private stm;
67
+ private listeners;
68
+ private globalListeners;
69
+ private _isRemoteUpdate;
70
+ private _cloudAdapter;
71
+ private _connectionState;
72
+ private _isLoaded;
73
+ private _cloudConfig;
74
+ constructor(options?: MindCacheOptions);
75
+ private _initCloud;
76
+ /**
77
+ * Get the current cloud connection state
78
+ */
79
+ get connectionState(): ConnectionState$1;
80
+ /**
81
+ * Check if data is loaded (true for local, true after sync for cloud)
82
+ */
83
+ get isLoaded(): boolean;
84
+ /**
85
+ * Check if this instance is connected to cloud
86
+ */
87
+ get isCloud(): boolean;
88
+ /**
89
+ * Disconnect from cloud (if connected)
90
+ */
91
+ disconnect(): void;
92
+ private encodeFileToBase64;
93
+ private createDataUrl;
94
+ private validateContentType;
95
+ /** @deprecated Use get_value instead */
96
+ get(key: string): any;
97
+ get_value(key: string, _processingStack?: Set<string>): any;
98
+ get_attributes(key: string): KeyAttributes | undefined;
99
+ set_value(key: string, value: any, attributes?: Partial<KeyAttributes>): void;
100
+ _setFromRemote(key: string, value: any, attributes: KeyAttributes): void;
101
+ isRemoteUpdate(): boolean;
102
+ _deleteFromRemote(key: string): void;
103
+ _clearFromRemote(): void;
104
+ set_attributes(key: string, attributes: Partial<KeyAttributes>): boolean;
105
+ set(key: string, value: any): void;
106
+ set_file(key: string, file: File, attributes?: Partial<KeyAttributes>): Promise<void>;
107
+ set_base64(key: string, base64Data: string, contentType: string, type?: 'image' | 'file', attributes?: Partial<KeyAttributes>): void;
108
+ add_image(key: string, base64Data: string, contentType?: string, attributes?: Partial<KeyAttributes>): void;
109
+ get_data_url(key: string): string | undefined;
110
+ get_base64(key: string): string | undefined;
111
+ has(key: string): boolean;
112
+ delete(key: string): boolean;
113
+ clear(): void;
114
+ keys(): string[];
115
+ values(): any[];
116
+ entries(): [string, any][];
117
+ size(): number;
118
+ getAll(): Record<string, any>;
119
+ update(newValues: Record<string, any>): void;
120
+ subscribe(key: string, listener: Listener): void;
121
+ unsubscribe(key: string, listener: Listener): void;
122
+ subscribeToAll(listener: Listener): void;
123
+ unsubscribeFromAll(listener: Listener): void;
124
+ private notifyGlobalListeners;
125
+ injectSTM(template: string, _processingStack?: Set<string>): string;
126
+ getSTM(): string;
127
+ getSTMObject(): Record<string, any>;
128
+ getSTMForAPI(): Array<{
129
+ key: string;
130
+ value: any;
131
+ type: string;
132
+ contentType?: string;
133
+ }>;
134
+ getVisibleImages(): Array<{
135
+ type: 'file';
136
+ mediaType: string;
137
+ url: string;
138
+ filename?: string;
139
+ }>;
140
+ toJSON(): string;
141
+ fromJSON(jsonString: string): void;
142
+ serialize(): Record<string, STMEntry>;
143
+ deserialize(data: Record<string, STMEntry>): void;
144
+ get_system_prompt(): string;
145
+ private findKeyFromToolName;
146
+ get_aisdk_tools(): Record<string, any>;
147
+ executeToolCall(toolName: string, value: any): {
148
+ result: string;
149
+ key: string;
150
+ value: any;
151
+ } | null;
152
+ addTag(key: string, tag: string): boolean;
153
+ removeTag(key: string, tag: string): boolean;
154
+ getTags(key: string): string[];
155
+ getAllTags(): string[];
156
+ hasTag(key: string, tag: string): boolean;
157
+ getTagged(tag: string): string;
158
+ toMarkdown(): string;
159
+ fromMarkdown(markdown: string): void;
160
+ }
161
+ declare const mindcache: MindCache;
162
+
163
+ /**
164
+ * Configuration for connecting to MindCache Cloud
165
+ */
166
+ interface CloudConfig {
167
+ /** The project ID from mindcache.io */
168
+ projectId: string;
169
+ /** The instance ID to connect to */
170
+ instanceId: string;
171
+ /** API key for authentication (server-to-server only) */
172
+ apiKey?: string;
173
+ /** Base URL for the API (optional, defaults to production) */
174
+ baseUrl?: string;
175
+ /** Token provider function for automatic token refresh */
176
+ tokenProvider?: () => Promise<string>;
177
+ }
178
+ interface SetOperation {
179
+ type: 'set';
180
+ key: string;
181
+ value: unknown;
182
+ attributes: KeyAttributes;
183
+ timestamp: number;
184
+ }
185
+ interface DeleteOperation {
186
+ type: 'delete';
187
+ key: string;
188
+ timestamp: number;
189
+ }
190
+ interface ClearOperation {
191
+ type: 'clear';
192
+ timestamp: number;
193
+ }
194
+ type Operation = SetOperation | DeleteOperation | ClearOperation;
195
+ /**
196
+ * Connection state
197
+ */
198
+ type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error';
199
+ /**
200
+ * Event types emitted by CloudAdapter
201
+ */
202
+ interface CloudAdapterEvents {
203
+ connected: () => void;
204
+ disconnected: () => void;
205
+ error: (error: Error) => void;
206
+ synced: () => void;
207
+ }
208
+
209
+ /**
210
+ * CloudAdapter connects a MindCache instance to the cloud service
211
+ * for real-time sync and persistence.
212
+ *
213
+ * Auth modes:
214
+ * 1. Token (recommended): Pass a short-lived token from /api/ws-token
215
+ * 2. API Key (server-to-server): Pass apiKey for direct connections
216
+ */
217
+ declare class CloudAdapter {
218
+ private config;
219
+ private ws;
220
+ private queue;
221
+ private mindcache;
222
+ private unsubscribe;
223
+ private reconnectAttempts;
224
+ private reconnectTimeout;
225
+ private _state;
226
+ private listeners;
227
+ private token;
228
+ constructor(config: CloudConfig);
229
+ /**
230
+ * Set auth token (short-lived, from /api/ws-token)
231
+ * Call this before connect() or use setTokenProvider for auto-refresh
232
+ */
233
+ setToken(token: string): void;
234
+ /**
235
+ * Set a function that returns a fresh token
236
+ * Used for automatic token refresh on reconnect
237
+ */
238
+ setTokenProvider(provider: () => Promise<string>): void;
239
+ /**
240
+ * Get current connection state
241
+ */
242
+ get state(): ConnectionState;
243
+ /**
244
+ * Attach to a MindCache instance and start syncing
245
+ */
246
+ attach(mc: MindCache): void;
247
+ /**
248
+ * Detach from the MindCache instance
249
+ */
250
+ detach(): void;
251
+ /**
252
+ * Connect to the cloud service
253
+ */
254
+ connect(): Promise<void>;
255
+ /**
256
+ * Disconnect from the cloud service
257
+ */
258
+ disconnect(): void;
259
+ /**
260
+ * Push an operation to the cloud
261
+ */
262
+ push(op: Operation): void;
263
+ /**
264
+ * Add event listener
265
+ */
266
+ on<K extends keyof CloudAdapterEvents>(event: K, listener: CloudAdapterEvents[K]): void;
267
+ /**
268
+ * Remove event listener
269
+ */
270
+ off<K extends keyof CloudAdapterEvents>(event: K, listener: CloudAdapterEvents[K]): void;
271
+ private emit;
272
+ private setupWebSocket;
273
+ private handleMessage;
274
+ private flushQueue;
275
+ private scheduleReconnect;
276
+ private syncLocalChanges;
277
+ }
278
+
279
+ export { type CloudConfig as C, type DeleteOperation as D, type KeyAttributes as K, type Listener as L, MindCache as M, type Operation as O, type SetOperation as S, CloudAdapter as a, type ConnectionState as b, type CloudAdapterEvents as c, type ClearOperation as d, type STM as e, type STMEntry as f, type MindCacheOptions as g, type MindCacheCloudOptions as h, DEFAULT_KEY_ATTRIBUTES as i, mindcache as m };
@@ -0,0 +1 @@
1
+ export { a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, i as DEFAULT_KEY_ATTRIBUTES, K as KeyAttributes, L as Listener, M as MindCache, h as MindCacheCloudOptions, g as MindCacheOptions, e as STM, f as STMEntry, m as mindcache } from './index-CFJtj3DL.mjs';
@@ -0,0 +1 @@
1
+ export { a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, i as DEFAULT_KEY_ATTRIBUTES, K as KeyAttributes, L as Listener, M as MindCache, h as MindCacheCloudOptions, g as MindCacheOptions, e as STM, f as STMEntry, m as mindcache } from './index-CFJtj3DL.js';