mindcache 3.6.0 → 3.7.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/dist/cloud/index.js.map +1 -1
- package/dist/cloud/index.mjs.map +1 -1
- package/dist/index.d.mts +366 -1
- package/dist/index.d.ts +366 -1
- package/dist/index.js +1021 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1012 -3
- package/dist/index.mjs.map +1 -1
- package/dist/server.js.map +1 -1
- package/dist/server.mjs.map +1 -1
- package/package.json +4 -8
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { e as CustomTypeDefinition, f as MindCacheOptions, M as MindCache } from './CloudAdapter-PLGvGjoA.mjs';
|
|
2
2
|
export { A as AccessLevel, a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, i as ContextRules, o as CustomTypeField, p as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, l as HistoryOptions, K as KeyAttributes, k as KeyEntry, g as KeyType, L as Listener, m as MindCacheCloudOptions, n as MindCacheIndexedDBOptions, j as STM, k as STMEntry, h as SystemTag, q as SystemTagHelpers } from './CloudAdapter-PLGvGjoA.mjs';
|
|
3
3
|
export { IndexedDBAdapter, IndexedDBConfig } from './server.mjs';
|
|
4
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
|
+
import React, { ReactNode } from 'react';
|
|
4
6
|
import 'yjs';
|
|
5
7
|
|
|
6
8
|
/**
|
|
@@ -206,6 +208,369 @@ interface UseMindCacheResult {
|
|
|
206
208
|
*/
|
|
207
209
|
declare function useMindCache(options?: MindCacheOptions): UseMindCacheResult;
|
|
208
210
|
|
|
211
|
+
/** Supported AI providers */
|
|
212
|
+
type AIProvider = 'openai' | 'anthropic' | 'custom';
|
|
213
|
+
/**
|
|
214
|
+
* Configuration for local-first sync
|
|
215
|
+
*/
|
|
216
|
+
interface LocalFirstSyncConfig {
|
|
217
|
+
/** Optional server URL for real-time sync when online */
|
|
218
|
+
serverUrl?: string;
|
|
219
|
+
/** GitStore configuration for GitHub backup */
|
|
220
|
+
gitstore?: {
|
|
221
|
+
owner: string;
|
|
222
|
+
repo: string;
|
|
223
|
+
path?: string;
|
|
224
|
+
/** Token provider function or direct token */
|
|
225
|
+
token: string | (() => Promise<string>);
|
|
226
|
+
};
|
|
227
|
+
/** Auto-sync interval in ms (default: 30000 = 30s) */
|
|
228
|
+
autoSyncInterval?: number;
|
|
229
|
+
/** Debounce delay for saves in ms (default: 2000) */
|
|
230
|
+
saveDebounceMs?: number;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* AI configuration for client-side chat
|
|
234
|
+
*/
|
|
235
|
+
interface AIConfig {
|
|
236
|
+
/**
|
|
237
|
+
* AI provider: 'openai' | 'anthropic' | 'custom'
|
|
238
|
+
* If using 'custom', you must provide modelProvider
|
|
239
|
+
* @default 'openai'
|
|
240
|
+
*/
|
|
241
|
+
provider?: AIProvider;
|
|
242
|
+
/**
|
|
243
|
+
* Model name (e.g., 'gpt-4o', 'gpt-4o-mini', 'claude-3-5-sonnet')
|
|
244
|
+
* @default 'gpt-4o'
|
|
245
|
+
*/
|
|
246
|
+
model?: string;
|
|
247
|
+
/** API key - stored in localStorage if keyStorage is 'localStorage' */
|
|
248
|
+
apiKey?: string;
|
|
249
|
+
/** Where to store the API key: 'localStorage' | 'memory' | 'prompt' */
|
|
250
|
+
keyStorage?: 'localStorage' | 'memory' | 'prompt';
|
|
251
|
+
/** localStorage key for API key (default: 'ai_api_key') */
|
|
252
|
+
storageKey?: string;
|
|
253
|
+
/**
|
|
254
|
+
* Custom model provider function (advanced usage)
|
|
255
|
+
* Use this for providers not built-in or custom configurations
|
|
256
|
+
* @example
|
|
257
|
+
* ```ts
|
|
258
|
+
* import { createOpenAI } from '@ai-sdk/openai';
|
|
259
|
+
* modelProvider: (apiKey) => createOpenAI({ apiKey, baseURL: '...' })('gpt-4o')
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
modelProvider?: (apiKey: string) => any;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* MindCache Provider configuration
|
|
266
|
+
*/
|
|
267
|
+
interface MindCacheProviderConfig {
|
|
268
|
+
/** MindCache options (IndexedDB config, etc.) */
|
|
269
|
+
mindcache?: MindCacheOptions;
|
|
270
|
+
/** Local-first sync configuration */
|
|
271
|
+
sync?: LocalFirstSyncConfig;
|
|
272
|
+
/** AI configuration for client-side chat */
|
|
273
|
+
ai?: AIConfig;
|
|
274
|
+
/** Children components */
|
|
275
|
+
children: ReactNode;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* MindCache context value
|
|
279
|
+
*/
|
|
280
|
+
interface MindCacheContextValue {
|
|
281
|
+
/** The MindCache instance */
|
|
282
|
+
mindcache: MindCache | null;
|
|
283
|
+
/** Whether MindCache is loaded and ready */
|
|
284
|
+
isLoaded: boolean;
|
|
285
|
+
/** Any error during initialization */
|
|
286
|
+
error: Error | null;
|
|
287
|
+
/** AI configuration */
|
|
288
|
+
aiConfig: AIConfig;
|
|
289
|
+
/** Sync configuration */
|
|
290
|
+
syncConfig: LocalFirstSyncConfig | undefined;
|
|
291
|
+
/** Get the API key (from storage or prompt) */
|
|
292
|
+
getApiKey: () => string | null;
|
|
293
|
+
/** Set the API key */
|
|
294
|
+
setApiKey: (key: string) => void;
|
|
295
|
+
/** Whether API key is configured */
|
|
296
|
+
hasApiKey: boolean;
|
|
297
|
+
/** Get the AI model (uses API key from storage) */
|
|
298
|
+
getModel: () => any;
|
|
299
|
+
/** Trigger a manual sync to GitStore */
|
|
300
|
+
syncToGitStore: () => Promise<void>;
|
|
301
|
+
/** Last sync timestamp */
|
|
302
|
+
lastSyncAt: Date | null;
|
|
303
|
+
/** Whether currently syncing */
|
|
304
|
+
isSyncing: boolean;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Hook to access MindCache context
|
|
308
|
+
*/
|
|
309
|
+
declare function useMindCacheContext(): MindCacheContextValue;
|
|
310
|
+
/**
|
|
311
|
+
* MindCacheProvider - Context provider for local-first MindCache apps
|
|
312
|
+
*
|
|
313
|
+
* @example
|
|
314
|
+
* ```tsx
|
|
315
|
+
* <MindCacheProvider
|
|
316
|
+
* mindcache={{ indexedDB: { dbName: 'my-app' } }}
|
|
317
|
+
* ai={{ keyStorage: 'localStorage' }}
|
|
318
|
+
* sync={{ gitstore: { owner: 'me', repo: 'data', token: 'ghp_...' } }}
|
|
319
|
+
* >
|
|
320
|
+
* <App />
|
|
321
|
+
* </MindCacheProvider>
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
declare function MindCacheProvider({ mindcache: mcOptions, sync: syncConfig, ai: aiConfig, children }: MindCacheProviderConfig): react_jsx_runtime.JSX.Element;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Message part types (compatible with AI SDK UIMessage)
|
|
328
|
+
*/
|
|
329
|
+
interface TextPart {
|
|
330
|
+
type: 'text';
|
|
331
|
+
text: string;
|
|
332
|
+
}
|
|
333
|
+
interface ToolCallPart {
|
|
334
|
+
type: 'tool-call';
|
|
335
|
+
toolCallId: string;
|
|
336
|
+
toolName: string;
|
|
337
|
+
args: Record<string, unknown>;
|
|
338
|
+
}
|
|
339
|
+
interface ToolResultPart {
|
|
340
|
+
type: 'tool-result';
|
|
341
|
+
toolCallId: string;
|
|
342
|
+
toolName: string;
|
|
343
|
+
result: unknown;
|
|
344
|
+
}
|
|
345
|
+
type MessagePart = TextPart | ToolCallPart | ToolResultPart;
|
|
346
|
+
/**
|
|
347
|
+
* Chat message structure (compatible with AI SDK UIMessage)
|
|
348
|
+
*/
|
|
349
|
+
interface ChatMessage {
|
|
350
|
+
id: string;
|
|
351
|
+
role: 'user' | 'assistant' | 'system';
|
|
352
|
+
content: string;
|
|
353
|
+
parts?: MessagePart[];
|
|
354
|
+
createdAt: Date;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Chat status
|
|
358
|
+
*/
|
|
359
|
+
type ChatStatus = 'idle' | 'loading' | 'streaming' | 'error';
|
|
360
|
+
/**
|
|
361
|
+
* useClientChat options
|
|
362
|
+
*/
|
|
363
|
+
interface UseClientChatOptions {
|
|
364
|
+
/** MindCache instance (uses context if not provided) */
|
|
365
|
+
mindcache?: MindCache;
|
|
366
|
+
/** Initial messages */
|
|
367
|
+
initialMessages?: ChatMessage[];
|
|
368
|
+
/** Custom system prompt (overrides MindCache system prompt) */
|
|
369
|
+
systemPrompt?: string;
|
|
370
|
+
/** Callback when AI modifies MindCache */
|
|
371
|
+
onMindCacheChange?: () => void;
|
|
372
|
+
/** Callback when message is complete */
|
|
373
|
+
onFinish?: (message: ChatMessage) => void;
|
|
374
|
+
/** Callback on error */
|
|
375
|
+
onError?: (error: Error) => void;
|
|
376
|
+
/** Max tool call iterations (default: 5) */
|
|
377
|
+
maxToolCalls?: number;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* useClientChat return value
|
|
381
|
+
*/
|
|
382
|
+
interface UseClientChatReturn {
|
|
383
|
+
/** All messages in the conversation */
|
|
384
|
+
messages: ChatMessage[];
|
|
385
|
+
/** Current status */
|
|
386
|
+
status: ChatStatus;
|
|
387
|
+
/** Current error if any */
|
|
388
|
+
error: Error | null;
|
|
389
|
+
/** Send a message */
|
|
390
|
+
sendMessage: (content: string) => Promise<void>;
|
|
391
|
+
/** Clear all messages */
|
|
392
|
+
clearMessages: () => void;
|
|
393
|
+
/** Whether currently loading/streaming */
|
|
394
|
+
isLoading: boolean;
|
|
395
|
+
/** Add a message programmatically */
|
|
396
|
+
addMessage: (message: Omit<ChatMessage, 'id' | 'createdAt'>) => void;
|
|
397
|
+
/** Stop the current generation */
|
|
398
|
+
stop: () => void;
|
|
399
|
+
/** Current streaming text (updates in real-time) */
|
|
400
|
+
streamingContent: string;
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* useClientChat - Client-side AI chat hook with real-time streaming
|
|
404
|
+
*
|
|
405
|
+
* Runs AI entirely in the browser using the Vercel AI SDK.
|
|
406
|
+
* Automatically integrates with MindCache for context and tool execution.
|
|
407
|
+
* Shows text streaming in real-time as it's generated.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```tsx
|
|
411
|
+
* function Chat() {
|
|
412
|
+
* const { messages, sendMessage, isLoading, streamingContent } = useClientChat();
|
|
413
|
+
*
|
|
414
|
+
* return (
|
|
415
|
+
* <div>
|
|
416
|
+
* {messages.map(m => <div key={m.id}>{m.content}</div>)}
|
|
417
|
+
* {streamingContent && <div>{streamingContent}</div>}
|
|
418
|
+
* <input onSubmit={e => sendMessage(e.target.value)} />
|
|
419
|
+
* </div>
|
|
420
|
+
* );
|
|
421
|
+
* }
|
|
422
|
+
* ```
|
|
423
|
+
*/
|
|
424
|
+
declare function useClientChat(options?: UseClientChatOptions): UseClientChatReturn;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Chat theme configuration
|
|
428
|
+
*/
|
|
429
|
+
interface ChatTheme {
|
|
430
|
+
/** Container background */
|
|
431
|
+
background?: string;
|
|
432
|
+
/** User message background */
|
|
433
|
+
userBubble?: string;
|
|
434
|
+
/** Assistant message background */
|
|
435
|
+
assistantBubble?: string;
|
|
436
|
+
/** Text color */
|
|
437
|
+
textColor?: string;
|
|
438
|
+
/** Secondary text color */
|
|
439
|
+
secondaryTextColor?: string;
|
|
440
|
+
/** Border color */
|
|
441
|
+
borderColor?: string;
|
|
442
|
+
/** Primary/accent color */
|
|
443
|
+
primaryColor?: string;
|
|
444
|
+
/** Font family */
|
|
445
|
+
fontFamily?: string;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* MindCacheChat props
|
|
449
|
+
*/
|
|
450
|
+
interface MindCacheChatProps extends Omit<UseClientChatOptions, 'mindcache'> {
|
|
451
|
+
/** Custom theme */
|
|
452
|
+
theme?: ChatTheme;
|
|
453
|
+
/** Placeholder text for input */
|
|
454
|
+
placeholder?: string;
|
|
455
|
+
/** Welcome message (shown when no messages) */
|
|
456
|
+
welcomeMessage?: string;
|
|
457
|
+
/** Show API key input if not configured */
|
|
458
|
+
showApiKeyInput?: boolean;
|
|
459
|
+
/** Custom class name for container */
|
|
460
|
+
className?: string;
|
|
461
|
+
/** Custom styles for container */
|
|
462
|
+
style?: React.CSSProperties;
|
|
463
|
+
/** Render custom message component */
|
|
464
|
+
renderMessage?: (message: ChatMessage) => React.ReactNode;
|
|
465
|
+
/** Header component */
|
|
466
|
+
header?: React.ReactNode;
|
|
467
|
+
/** Footer component (below input) */
|
|
468
|
+
footer?: React.ReactNode;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* MindCacheChat - Ready-to-use chat component for local-first AI
|
|
472
|
+
*
|
|
473
|
+
* @example
|
|
474
|
+
* ```tsx
|
|
475
|
+
* <MindCacheProvider ai={{ keyStorage: 'localStorage' }}>
|
|
476
|
+
* <MindCacheChat
|
|
477
|
+
* welcomeMessage="Hello! How can I help you today?"
|
|
478
|
+
* placeholder="Ask me anything..."
|
|
479
|
+
* />
|
|
480
|
+
* </MindCacheProvider>
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
declare function MindCacheChat({ theme: customTheme, placeholder, welcomeMessage, showApiKeyInput, className, style, renderMessage, header, footer, initialMessages, ...chatOptions }: MindCacheChatProps): react_jsx_runtime.JSX.Element;
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* GitStore sync configuration
|
|
487
|
+
*/
|
|
488
|
+
interface GitStoreSyncConfig {
|
|
489
|
+
/** GitHub repository owner */
|
|
490
|
+
owner: string;
|
|
491
|
+
/** GitHub repository name */
|
|
492
|
+
repo: string;
|
|
493
|
+
/** File path in repo (default: 'mindcache.md') */
|
|
494
|
+
path?: string;
|
|
495
|
+
/** GitHub token or token provider */
|
|
496
|
+
token: string | (() => Promise<string>);
|
|
497
|
+
/** Branch to sync to (default: 'main') */
|
|
498
|
+
branch?: string;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Server sync configuration
|
|
502
|
+
*/
|
|
503
|
+
interface ServerSyncConfig {
|
|
504
|
+
/** Server URL for sync endpoint */
|
|
505
|
+
url: string;
|
|
506
|
+
/** Optional auth token */
|
|
507
|
+
authToken?: string;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* useLocalFirstSync options
|
|
511
|
+
*/
|
|
512
|
+
interface UseLocalFirstSyncOptions {
|
|
513
|
+
/** MindCache instance to sync */
|
|
514
|
+
mindcache: MindCache | null;
|
|
515
|
+
/** GitStore configuration */
|
|
516
|
+
gitstore?: GitStoreSyncConfig;
|
|
517
|
+
/** Optional server sync configuration */
|
|
518
|
+
server?: ServerSyncConfig;
|
|
519
|
+
/** Auto-sync interval in ms (0 = disabled, default: 0) */
|
|
520
|
+
autoSyncInterval?: number;
|
|
521
|
+
/** Debounce delay for auto-save in ms (default: 5000) */
|
|
522
|
+
saveDebounceMs?: number;
|
|
523
|
+
/** Load from remote on mount (default: true) */
|
|
524
|
+
loadOnMount?: boolean;
|
|
525
|
+
/** Merge remote data with local (default: true) */
|
|
526
|
+
mergeOnLoad?: boolean;
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Sync status
|
|
530
|
+
*/
|
|
531
|
+
type SyncStatus = 'idle' | 'loading' | 'saving' | 'syncing' | 'error';
|
|
532
|
+
/**
|
|
533
|
+
* useLocalFirstSync return value
|
|
534
|
+
*/
|
|
535
|
+
interface UseLocalFirstSyncReturn {
|
|
536
|
+
/** Current sync status */
|
|
537
|
+
status: SyncStatus;
|
|
538
|
+
/** Last error */
|
|
539
|
+
error: Error | null;
|
|
540
|
+
/** Last successful sync timestamp */
|
|
541
|
+
lastSyncAt: Date | null;
|
|
542
|
+
/** Whether there are unsaved local changes */
|
|
543
|
+
hasLocalChanges: boolean;
|
|
544
|
+
/** Load data from remote (GitStore or server) */
|
|
545
|
+
load: () => Promise<void>;
|
|
546
|
+
/** Save current state to remote */
|
|
547
|
+
save: (message?: string) => Promise<void>;
|
|
548
|
+
/** Full sync: load then save if changes */
|
|
549
|
+
sync: () => Promise<void>;
|
|
550
|
+
/** Mark local changes as saved (for manual tracking) */
|
|
551
|
+
markSaved: () => void;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* useLocalFirstSync - Hook for local-first sync with GitStore
|
|
555
|
+
*
|
|
556
|
+
* Provides automatic syncing between local MindCache and GitHub via GitStore.
|
|
557
|
+
* Data is always available locally via IndexedDB, with async GitHub backup.
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
* ```tsx
|
|
561
|
+
* const { status, save, load, hasLocalChanges } = useLocalFirstSync({
|
|
562
|
+
* mindcache,
|
|
563
|
+
* gitstore: {
|
|
564
|
+
* owner: 'myuser',
|
|
565
|
+
* repo: 'my-data',
|
|
566
|
+
* token: process.env.GITHUB_TOKEN,
|
|
567
|
+
* },
|
|
568
|
+
* autoSyncInterval: 60000, // Sync every minute
|
|
569
|
+
* });
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
declare function useLocalFirstSync(options: UseLocalFirstSyncOptions): UseLocalFirstSyncReturn;
|
|
573
|
+
|
|
209
574
|
declare const mindcache: MindCache;
|
|
210
575
|
|
|
211
|
-
export { CustomTypeDefinition, MindCache, MindCacheOptions, type MindCacheUser, OAuthClient, type OAuthConfig, type OAuthTokens, SchemaParser, type UseMindCacheResult, createOAuthClient, mindcache, useMindCache };
|
|
576
|
+
export { type AIConfig, type ChatMessage, type ChatStatus, type ChatTheme, CustomTypeDefinition, type GitStoreSyncConfig, type LocalFirstSyncConfig, MindCache, MindCacheChat, type MindCacheChatProps, type MindCacheContextValue, MindCacheOptions, MindCacheProvider, type MindCacheProviderConfig, type MindCacheUser, OAuthClient, type OAuthConfig, type OAuthTokens, SchemaParser, type ServerSyncConfig, type SyncStatus, type UseClientChatOptions, type UseClientChatReturn, type UseLocalFirstSyncOptions, type UseLocalFirstSyncReturn, type UseMindCacheResult, createOAuthClient, mindcache, useClientChat, useLocalFirstSync, useMindCache, useMindCacheContext };
|