mindcache 3.5.3 → 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/index.d.ts CHANGED
@@ -1,8 +1,44 @@
1
- import { e as MindCacheOptions, M as MindCache } from './CloudAdapter-DK4YecbV.js';
2
- export { A as AccessLevel, a as CloudAdapter, c as CloudAdapterEvents, C as CloudConfig, b as ConnectionState, h as ContextRules, n as DEFAULT_KEY_ATTRIBUTES, G as GlobalListener, H as HistoryEntry, k as HistoryOptions, K as KeyAttributes, j as KeyEntry, f as KeyType, L as Listener, l as MindCacheCloudOptions, m as MindCacheIndexedDBOptions, i as STM, j as STMEntry, g as SystemTag, o as SystemTagHelpers } from './CloudAdapter-DK4YecbV.js';
1
+ import { e as CustomTypeDefinition, f as MindCacheOptions, M as MindCache } from './CloudAdapter-PLGvGjoA.js';
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.js';
3
3
  export { IndexedDBAdapter, IndexedDBConfig } from './server.js';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+ import React, { ReactNode } from 'react';
4
6
  import 'yjs';
5
7
 
8
+ /**
9
+ * Parses markdown-based schema definitions into structured CustomTypeDefinition objects.
10
+ *
11
+ * Schema format:
12
+ * ```
13
+ * #TypeName
14
+ * * fieldName: description of the field
15
+ * * anotherField: description
16
+ * ```
17
+ */
18
+ declare class SchemaParser {
19
+ /**
20
+ * Parse a markdown schema string into a CustomTypeDefinition
21
+ * @param schema - Markdown schema string
22
+ * @returns Parsed type definition
23
+ * @throws Error if schema format is invalid
24
+ */
25
+ static parse(schema: string): CustomTypeDefinition;
26
+ /**
27
+ * Generate a markdown representation of a type definition
28
+ * Useful for including in LLM prompts
29
+ */
30
+ static toMarkdown(typeDef: CustomTypeDefinition): string;
31
+ /**
32
+ * Generate a prompt-friendly description of the type
33
+ * More verbose than toMarkdown, better for LLM guidance
34
+ */
35
+ static toPromptDescription(typeDef: CustomTypeDefinition): string;
36
+ /**
37
+ * Generate an example value structure based on the type definition
38
+ */
39
+ static generateExample(typeDef: CustomTypeDefinition): string;
40
+ }
41
+
6
42
  /**
7
43
  * MindCache OAuth Client
8
44
  *
@@ -12,23 +48,17 @@ import 'yjs';
12
48
  interface OAuthConfig {
13
49
  /** Client ID from developer portal */
14
50
  clientId: string;
51
+ /**
52
+ * MindCache API base URL - REQUIRED!
53
+ * All OAuth endpoints are derived from this.
54
+ * - Production: 'https://api.mindcache.dev'
55
+ * - Local dev: 'http://localhost:8787'
56
+ */
57
+ baseUrl: string;
15
58
  /** Redirect URI (defaults to current URL) */
16
59
  redirectUri?: string;
17
60
  /** Scopes to request (default: ['read', 'write']) */
18
61
  scopes?: string[];
19
- /**
20
- * MindCache API base URL (default: 'https://api.mindcache.dev')
21
- * This is the ONLY URL you need to set! All OAuth endpoints are derived from this.
22
- * - authUrl = baseUrl + '/oauth/authorize'
23
- * - tokenUrl = baseUrl + '/oauth/token'
24
- */
25
- baseUrl?: string;
26
- /** @deprecated Use baseUrl instead. MindCache authorize URL */
27
- authUrl?: string;
28
- /** @deprecated Use baseUrl instead. MindCache token URL */
29
- tokenUrl?: string;
30
- /** @deprecated Use baseUrl instead. MindCache API URL */
31
- apiUrl?: string;
32
62
  /** Use PKCE for security (default: true) */
33
63
  usePKCE?: boolean;
34
64
  /** Storage key prefix (default: 'mindcache_oauth') */
@@ -69,8 +99,14 @@ declare class OAuthClient {
69
99
  private tokens;
70
100
  private refreshPromise;
71
101
  constructor(config: OAuthConfig);
102
+ /** Derived auth URL */
103
+ private get authUrl();
104
+ /** Derived token URL */
105
+ private get tokenUrl();
106
+ /** Derived userinfo URL */
107
+ private get userinfoUrl();
72
108
  /**
73
- * Validate the API is reachable and warn about common misconfigurations
109
+ * Validate the API is reachable
74
110
  */
75
111
  private validateApi;
76
112
  /**
@@ -123,13 +159,12 @@ declare class OAuthClient {
123
159
  private clearAuth;
124
160
  /**
125
161
  * Token provider for MindCache cloud config
126
- * This fetches a WebSocket token (short-lived) using the OAuth access token
162
+ * This fetches a WebSocket token using the OAuth access token
127
163
  * Use this with MindCacheCloudOptions.tokenProvider
128
164
  */
129
165
  tokenProvider: () => Promise<string>;
130
166
  /**
131
167
  * Get raw OAuth access token (for API calls, not WebSocket)
132
- * Use getAccessToken() for most cases
133
168
  */
134
169
  accessTokenProvider: () => Promise<string>;
135
170
  private getStorage;
@@ -173,6 +208,369 @@ interface UseMindCacheResult {
173
208
  */
174
209
  declare function useMindCache(options?: MindCacheOptions): UseMindCacheResult;
175
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
+
176
574
  declare const mindcache: MindCache;
177
575
 
178
- export { MindCache, MindCacheOptions, type MindCacheUser, OAuthClient, type OAuthConfig, type OAuthTokens, 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 };