@meetsmore-oss/use-ai-client 1.2.3 → 1.3.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.
@@ -43,4 +43,4 @@ export {
43
43
  generateChatId,
44
44
  generateMessageId
45
45
  };
46
- //# sourceMappingURL=chunk-EGD4LT6R.js.map
46
+ //# sourceMappingURL=chunk-AKQM6IWU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/providers/chatRepository/types.ts"],"sourcesContent":["import type { PersistedFileMetadata } from '../../fileUpload/types';\n\n/**\n * Arbitrary metadata attached to a chat.\n * Use this to store context about the chat (e.g., how it was invoked, document type being processed).\n */\nexport type ChatMetadata = Record<string, unknown>;\n\n/**\n * Display mode for chat messages.\n * Determines the visual styling of the message bubble.\n */\nexport type MessageDisplayMode = 'default' | 'error';\n\n/**\n * Text content part for persisted messages.\n */\nexport interface PersistedTextContent {\n type: 'text';\n text: string;\n}\n\n/**\n * File content part for persisted messages.\n * Only stores metadata, not the actual file data.\n */\nexport interface PersistedFileContent {\n type: 'file';\n file: PersistedFileMetadata;\n}\n\n/**\n * Content part for persisted messages.\n * Can be text or file metadata.\n */\nexport type PersistedContentPart = PersistedTextContent | PersistedFileContent;\n\n/**\n * Content that can be persisted.\n * Simple string for text-only messages, or array for multimodal content.\n */\nexport type PersistedMessageContent = string | PersistedContentPart[];\n\n/**\n * Message format for persisted chat history.\n * Compatible with AI SDK's UIMessage format for future integration.\n */\nexport interface PersistedMessage {\n id: string;\n role: 'user' | 'assistant' | 'tool';\n /** Content can be a string or multimodal content array */\n content: PersistedMessageContent;\n createdAt: Date;\n displayMode?: MessageDisplayMode;\n}\n\n/**\n * Represents a stored chat conversation.\n */\nexport interface Chat {\n id: string;\n title?: string;\n messages: PersistedMessage[];\n createdAt: Date;\n updatedAt: Date;\n /** Arbitrary metadata attached to the chat */\n metadata?: ChatMetadata;\n}\n\n/**\n * Options for creating a new chat.\n */\nexport interface CreateChatOptions {\n title?: string;\n /** Initial metadata for the chat */\n metadata?: ChatMetadata;\n}\n\n/**\n * Options for listing chats.\n */\nexport interface ListChatsOptions {\n limit?: number;\n offset?: number;\n}\n\n/**\n * Abstract repository interface for chat persistence.\n * Implementations can store chats locally (localStorage, IndexedDB)\n * or remotely (REST API, GraphQL, etc.)\n */\nexport interface ChatRepository {\n /**\n * Creates a new chat and returns its ID.\n * @param options Optional configuration for the new chat\n * @returns Promise resolving to the new chat ID\n */\n createChat(options?: CreateChatOptions): Promise<string>;\n\n /**\n * Loads a chat by ID.\n * @param id Chat ID to load\n * @returns Promise resolving to the chat, or null if not found\n */\n loadChat(id: string): Promise<Chat | null>;\n\n /**\n * Saves or updates a chat.\n * @param chat Chat to save\n * @returns Promise resolving when save is complete\n */\n saveChat(chat: Chat): Promise<void>;\n\n /**\n * Deletes a chat by ID.\n * @param id Chat ID to delete\n * @returns Promise resolving when deletion is complete\n */\n deleteChat(id: string): Promise<void>;\n\n /**\n * Lists all available chats (metadata only, without full message history).\n * @param options Optional pagination and filtering options\n * @returns Promise resolving to array of chat metadata\n */\n listChats(options?: ListChatsOptions): Promise<Array<Omit<Chat, 'messages'>>>;\n\n /**\n * Deletes all stored chats.\n * @returns Promise resolving when all chats are deleted\n */\n deleteAll(): Promise<void>;\n\n /**\n * Updates metadata for a chat.\n * By default, merges with existing metadata. Set `overwrite: true` to replace entirely.\n * @param id Chat ID\n * @param metadata Metadata to set/merge\n * @param overwrite If true, replaces all metadata instead of merging\n * @returns Promise resolving when update is complete\n */\n updateMetadata(id: string, metadata: ChatMetadata, overwrite?: boolean): Promise<void>;\n}\n\n/**\n * Generates a unique chat ID.\n */\nexport function generateChatId(): string {\n return `chat_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n}\n\n/**\n * Generates a unique message ID.\n */\nexport function generateMessageId(): string {\n return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmJO,SAAS,iBAAyB;AACvC,SAAO,QAAQ,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,CAAC,CAAC;AACzE;AAKO,SAAS,oBAA4B;AAC1C,SAAO,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,CAAC,CAAC;AACxE;","names":[]}
@@ -10,4 +10,4 @@ export {
10
10
  generateChatId,
11
11
  generateMessageId
12
12
  };
13
- //# sourceMappingURL=chunk-EGKUR4C7.js.map
13
+ //# sourceMappingURL=chunk-QTQR7MAU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/providers/chatRepository/types.ts"],"sourcesContent":["import type { PersistedFileMetadata } from '../../fileUpload/types';\n\n/**\n * Arbitrary metadata attached to a chat.\n * Use this to store context about the chat (e.g., how it was invoked, document type being processed).\n */\nexport type ChatMetadata = Record<string, unknown>;\n\n/**\n * Display mode for chat messages.\n * Determines the visual styling of the message bubble.\n */\nexport type MessageDisplayMode = 'default' | 'error';\n\n/**\n * Text content part for persisted messages.\n */\nexport interface PersistedTextContent {\n type: 'text';\n text: string;\n}\n\n/**\n * File content part for persisted messages.\n * Only stores metadata, not the actual file data.\n */\nexport interface PersistedFileContent {\n type: 'file';\n file: PersistedFileMetadata;\n}\n\n/**\n * Content part for persisted messages.\n * Can be text or file metadata.\n */\nexport type PersistedContentPart = PersistedTextContent | PersistedFileContent;\n\n/**\n * Content that can be persisted.\n * Simple string for text-only messages, or array for multimodal content.\n */\nexport type PersistedMessageContent = string | PersistedContentPart[];\n\n/**\n * Message format for persisted chat history.\n * Compatible with AI SDK's UIMessage format for future integration.\n */\nexport interface PersistedMessage {\n id: string;\n role: 'user' | 'assistant' | 'tool';\n /** Content can be a string or multimodal content array */\n content: PersistedMessageContent;\n createdAt: Date;\n displayMode?: MessageDisplayMode;\n}\n\n/**\n * Represents a stored chat conversation.\n */\nexport interface Chat {\n id: string;\n title?: string;\n messages: PersistedMessage[];\n createdAt: Date;\n updatedAt: Date;\n /** Arbitrary metadata attached to the chat */\n metadata?: ChatMetadata;\n}\n\n/**\n * Options for creating a new chat.\n */\nexport interface CreateChatOptions {\n title?: string;\n /** Initial metadata for the chat */\n metadata?: ChatMetadata;\n}\n\n/**\n * Options for listing chats.\n */\nexport interface ListChatsOptions {\n limit?: number;\n offset?: number;\n}\n\n/**\n * Abstract repository interface for chat persistence.\n * Implementations can store chats locally (localStorage, IndexedDB)\n * or remotely (REST API, GraphQL, etc.)\n */\nexport interface ChatRepository {\n /**\n * Creates a new chat and returns its ID.\n * @param options Optional configuration for the new chat\n * @returns Promise resolving to the new chat ID\n */\n createChat(options?: CreateChatOptions): Promise<string>;\n\n /**\n * Loads a chat by ID.\n * @param id Chat ID to load\n * @returns Promise resolving to the chat, or null if not found\n */\n loadChat(id: string): Promise<Chat | null>;\n\n /**\n * Saves or updates a chat.\n * @param chat Chat to save\n * @returns Promise resolving when save is complete\n */\n saveChat(chat: Chat): Promise<void>;\n\n /**\n * Deletes a chat by ID.\n * @param id Chat ID to delete\n * @returns Promise resolving when deletion is complete\n */\n deleteChat(id: string): Promise<void>;\n\n /**\n * Lists all available chats (metadata only, without full message history).\n * @param options Optional pagination and filtering options\n * @returns Promise resolving to array of chat metadata\n */\n listChats(options?: ListChatsOptions): Promise<Array<Omit<Chat, 'messages'>>>;\n\n /**\n * Deletes all stored chats.\n * @returns Promise resolving when all chats are deleted\n */\n deleteAll(): Promise<void>;\n\n /**\n * Updates metadata for a chat.\n * By default, merges with existing metadata. Set `overwrite: true` to replace entirely.\n * @param id Chat ID\n * @param metadata Metadata to set/merge\n * @param overwrite If true, replaces all metadata instead of merging\n * @returns Promise resolving when update is complete\n */\n updateMetadata(id: string, metadata: ChatMetadata, overwrite?: boolean): Promise<void>;\n}\n\n/**\n * Generates a unique chat ID.\n */\nexport function generateChatId(): string {\n return `chat_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n}\n\n/**\n * Generates a unique message ID.\n */\nexport function generateMessageId(): string {\n return `msg_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;\n}\n"],"mappings":";AAmJO,SAAS,iBAAyB;AACvC,SAAO,QAAQ,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,CAAC,CAAC;AACzE;AAKO,SAAS,oBAA4B;AAC1C,SAAO,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,CAAC,CAAC;AACxE;","names":[]}
package/dist/index.d.ts CHANGED
@@ -316,6 +316,11 @@ interface FileAttachment {
316
316
  file: File;
317
317
  /** Data URL for image thumbnails (generated on attach for preview) */
318
318
  preview?: string;
319
+ /**
320
+ * Transformed content (if a transformer matched this file's MIME type).
321
+ * Populated asynchronously after attachment - check processingState for status.
322
+ */
323
+ transformedContent?: string;
319
324
  }
320
325
  /**
321
326
  * Abstract file upload backend interface.
@@ -337,6 +342,55 @@ interface FileUploadBackend {
337
342
  */
338
343
  prepareForSend(file: File): Promise<string>;
339
344
  }
345
+ /**
346
+ * Context provided to file transformers.
347
+ */
348
+ interface FileTransformerContext {
349
+ /** The current chat (includes metadata) */
350
+ chat: Chat | null;
351
+ }
352
+ /**
353
+ * A transformer that converts files into string representations for the AI.
354
+ */
355
+ interface FileTransformer {
356
+ /**
357
+ * Transform the file into a string representation for the AI.
358
+ *
359
+ * @param file - The file to transform
360
+ * @param context - Context including the current chat and its metadata
361
+ * @param onProgress - Optional callback for reporting progress (0-100).
362
+ * If called, UI shows progress bar; otherwise shows spinner.
363
+ * @returns A string representation the AI will receive
364
+ * @throws If transformation fails
365
+ */
366
+ transform(file: File, context: FileTransformerContext, onProgress?: (progress: number) => void): Promise<string>;
367
+ }
368
+ /**
369
+ * Map of MIME type patterns to transformers.
370
+ *
371
+ * Keys are MIME type patterns:
372
+ * - Exact match: 'application/pdf'
373
+ * - Partial wildcard: 'image/*'
374
+ * - Global wildcard: '*' or '*\/*'
375
+ *
376
+ * When multiple patterns match, the most specific one wins:
377
+ * 1. Exact match (e.g., 'application/pdf')
378
+ * 2. Partial wildcard (e.g., 'image/*')
379
+ * 3. Global wildcard ('*' or '*\/*')
380
+ */
381
+ type FileTransformerMap = Record<string, FileTransformer>;
382
+ /**
383
+ * Status of file processing during send.
384
+ */
385
+ type FileProcessingStatus = 'idle' | 'processing' | 'done' | 'error';
386
+ /**
387
+ * Processing state for a file attachment.
388
+ */
389
+ interface FileProcessingState {
390
+ status: FileProcessingStatus;
391
+ /** Progress 0-100, or undefined for indeterminate (spinner) */
392
+ progress?: number;
393
+ }
340
394
  /**
341
395
  * Configuration for file uploads in UseAIProvider.
342
396
  */
@@ -357,8 +411,19 @@ interface FileUploadConfig {
357
411
  * If undefined, all types are accepted.
358
412
  */
359
413
  acceptedTypes?: string[];
414
+ /**
415
+ * Map of MIME type patterns to transformers.
416
+ * Files matching a transformer pattern will be converted to text
417
+ * before being sent to the AI.
418
+ */
419
+ transformers?: FileTransformerMap;
360
420
  }
361
421
 
422
+ /**
423
+ * Arbitrary metadata attached to a chat.
424
+ * Use this to store context about the chat (e.g., how it was invoked, document type being processed).
425
+ */
426
+ type ChatMetadata = Record<string, unknown>;
362
427
  /**
363
428
  * Display mode for chat messages.
364
429
  * Determines the visual styling of the message bubble.
@@ -410,12 +475,16 @@ interface Chat {
410
475
  messages: PersistedMessage[];
411
476
  createdAt: Date;
412
477
  updatedAt: Date;
478
+ /** Arbitrary metadata attached to the chat */
479
+ metadata?: ChatMetadata;
413
480
  }
414
481
  /**
415
482
  * Options for creating a new chat.
416
483
  */
417
484
  interface CreateChatOptions {
418
485
  title?: string;
486
+ /** Initial metadata for the chat */
487
+ metadata?: ChatMetadata;
419
488
  }
420
489
  /**
421
490
  * Options for listing chats.
@@ -465,6 +534,15 @@ interface ChatRepository {
465
534
  * @returns Promise resolving when all chats are deleted
466
535
  */
467
536
  deleteAll(): Promise<void>;
537
+ /**
538
+ * Updates metadata for a chat.
539
+ * By default, merges with existing metadata. Set `overwrite: true` to replace entirely.
540
+ * @param id Chat ID
541
+ * @param metadata Metadata to set/merge
542
+ * @param overwrite If true, replaces all metadata instead of merging
543
+ * @returns Promise resolving when update is complete
544
+ */
545
+ updateMetadata(id: string, metadata: ChatMetadata, overwrite?: boolean): Promise<void>;
468
546
  }
469
547
  /**
470
548
  * Generates a unique chat ID.
@@ -565,8 +643,6 @@ declare const defaultStrings: {
565
643
  placeholder: string;
566
644
  /** Input placeholder when connecting */
567
645
  connectingPlaceholder: string;
568
- /** Send button text */
569
- send: string;
570
646
  /** Loading indicator text */
571
647
  thinking: string;
572
648
  };
@@ -745,6 +821,8 @@ interface UseAIChatPanelProps {
745
821
  onLoadChat?: (chatId: string) => Promise<void>;
746
822
  onDeleteChat?: (chatId: string) => Promise<void>;
747
823
  onListChats?: () => Promise<Array<Omit<Chat, 'messages'>>>;
824
+ /** Gets the current chat */
825
+ onGetChat?: () => Promise<Chat | null>;
748
826
  suggestions?: string[];
749
827
  availableAgents?: AgentInfo[];
750
828
  defaultAgent?: string | null;
@@ -762,7 +840,7 @@ interface UseAIChatPanelProps {
762
840
  * Chat panel content - fills its container.
763
841
  * Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
764
842
  */
765
- declare function UseAIChatPanel({ onSendMessage, messages, loading, connected, streamingText, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, commands, onSaveCommand, onRenameCommand, onDeleteCommand, closeButton, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
843
+ declare function UseAIChatPanel({ onSendMessage, messages, loading, connected, streamingText, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, commands, onSaveCommand, onRenameCommand, onDeleteCommand, closeButton, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
766
844
 
767
845
  /**
768
846
  * Handler for AG-UI events from the server.
@@ -982,6 +1060,105 @@ declare class UseAIClient {
982
1060
  isConnected(): boolean;
983
1061
  }
984
1062
 
1063
+ /**
1064
+ * Options for programmatically sending a message via sendMessage().
1065
+ */
1066
+ interface SendMessageOptions {
1067
+ /** Start a new chat before sending. Default: false (continue existing chat) */
1068
+ newChat?: boolean;
1069
+ /** File attachments to include with the message */
1070
+ attachments?: File[];
1071
+ /** Open the chat panel after sending. Default: true */
1072
+ openChat?: boolean;
1073
+ /** Metadata to set on the new chat (only used when newChat: true) */
1074
+ metadata?: ChatMetadata;
1075
+ }
1076
+ interface UseChatManagementOptions {
1077
+ /** Chat repository for persistence */
1078
+ repository: ChatRepository;
1079
+ /** Reference to the UseAIClient (can be null during initialization) */
1080
+ clientRef: React.MutableRefObject<UseAIClient | null>;
1081
+ /** Callback to send a message (from UseAIProvider) */
1082
+ onSendMessage?: (message: string, attachments?: FileAttachment[]) => Promise<void>;
1083
+ /** Callback to open/close the chat panel */
1084
+ setOpen?: (open: boolean) => void;
1085
+ /** Whether the client is connected */
1086
+ connected?: boolean;
1087
+ /** Whether the AI is currently loading/processing a response */
1088
+ loading?: boolean;
1089
+ }
1090
+ interface UseChatManagementReturn {
1091
+ /** Current active chat ID where AI responses are saved */
1092
+ currentChatId: string | null;
1093
+ /** Chat loaded for viewing but not yet active for AI responses */
1094
+ pendingChatId: string | null;
1095
+ /** Current messages in the chat */
1096
+ messages: Message[];
1097
+ /** The displayed chat ID (pending or current) */
1098
+ displayedChatId: string | null;
1099
+ /** Creates a new chat and switches to it */
1100
+ createNewChat: (options?: CreateChatOptions) => Promise<string>;
1101
+ /** Loads an existing chat by ID */
1102
+ loadChat: (chatId: string) => Promise<void>;
1103
+ /** Deletes a chat by ID */
1104
+ deleteChat: (chatId: string) => Promise<void>;
1105
+ /** Lists all available chats */
1106
+ listChats: () => Promise<Array<Omit<Chat, 'messages'>>>;
1107
+ /** Clears the current chat messages */
1108
+ clearCurrentChat: () => Promise<void>;
1109
+ /** Activates the pending chat (called when user sends first message) */
1110
+ activatePendingChat: () => string | null;
1111
+ /** Saves a user message to storage and reloads messages */
1112
+ saveUserMessage: (chatId: string, content: PersistedMessageContent) => Promise<boolean>;
1113
+ /** Saves an AI response to storage and optionally reloads messages */
1114
+ saveAIResponse: (content: string, displayMode?: 'default' | 'error') => Promise<void>;
1115
+ /** Reloads messages from storage for the given chat ID */
1116
+ reloadMessages: (chatId: string) => Promise<void>;
1117
+ /**
1118
+ * Programmatically send a message to the chat.
1119
+ * Throws on failure (e.g., not connected, no onSendMessage callback).
1120
+ */
1121
+ sendMessage: (message: string, options?: SendMessageOptions) => Promise<void>;
1122
+ /** Get the current chat object. Metadata is frozen to prevent accidental mutation. */
1123
+ getCurrentChat: () => Promise<Chat | null>;
1124
+ /** Update metadata for the current chat */
1125
+ updateMetadata: (metadata: ChatMetadata, overwrite?: boolean) => Promise<void>;
1126
+ /** Snapshot refs for use in event handlers */
1127
+ currentChatIdSnapshot: React.MutableRefObject<string | null>;
1128
+ pendingChatIdSnapshot: React.MutableRefObject<string | null>;
1129
+ }
1130
+ /**
1131
+ * Hook for managing chat lifecycle operations.
1132
+ *
1133
+ * Features:
1134
+ * - Creates, loads, deletes chats
1135
+ * - Manages pending/active chat state machine
1136
+ * - Saves user messages and AI responses
1137
+ * - Auto-generates chat titles
1138
+ * - Initializes with most recent chat or creates new one
1139
+ *
1140
+ * @example
1141
+ * ```typescript
1142
+ * const {
1143
+ * currentChatId,
1144
+ * pendingChatId,
1145
+ * messages,
1146
+ * createNewChat,
1147
+ * loadChat,
1148
+ * deleteChat,
1149
+ * listChats,
1150
+ * clearCurrentChat,
1151
+ * activatePendingChat,
1152
+ * saveUserMessage,
1153
+ * saveAIResponse,
1154
+ * } = useChatManagement({
1155
+ * repository: chatRepository,
1156
+ * clientRef,
1157
+ * });
1158
+ * ```
1159
+ */
1160
+ declare function useChatManagement({ repository, clientRef, onSendMessage, setOpen, connected, loading, }: UseChatManagementOptions): UseChatManagementReturn;
1161
+
985
1162
  /**
986
1163
  * Chat management context (from useChatManagement hook).
987
1164
  */
@@ -989,7 +1166,7 @@ interface ChatContextValue {
989
1166
  /** The current chat ID */
990
1167
  currentId: string | null;
991
1168
  /** Creates a new chat and switches to it */
992
- create: () => Promise<string>;
1169
+ create: (options?: CreateChatOptions) => Promise<string>;
993
1170
  /** Loads an existing chat by ID */
994
1171
  load: (chatId: string) => Promise<void>;
995
1172
  /** Deletes a chat by ID */
@@ -998,6 +1175,19 @@ interface ChatContextValue {
998
1175
  list: () => Promise<Array<Omit<Chat, 'messages'>>>;
999
1176
  /** Clears the current chat messages */
1000
1177
  clear: () => Promise<void>;
1178
+ /**
1179
+ * Programmatically send a message to the chat.
1180
+ * Throws on failure (e.g., not connected).
1181
+ */
1182
+ sendMessage: (message: string, options?: SendMessageOptions) => Promise<void>;
1183
+ /** Get the current chat object. Metadata is frozen to prevent accidental mutation. */
1184
+ get: () => Promise<Chat | null>;
1185
+ /**
1186
+ * Update metadata for the current chat.
1187
+ * @param metadata Metadata to set/merge
1188
+ * @param overwrite If true, replaces all metadata instead of merging (default: false)
1189
+ */
1190
+ updateMetadata: (metadata: ChatMetadata, overwrite?: boolean) => Promise<void>;
1001
1191
  }
1002
1192
  /**
1003
1193
  * Agent selection context (from useAgentSelection hook).
@@ -1209,6 +1399,30 @@ interface UseAIProviderProps extends UseAIConfig {
1209
1399
  * ```
1210
1400
  */
1211
1401
  visibleAgentIds?: AgentInfo['id'][];
1402
+ /**
1403
+ * Callback when the chat open state should change.
1404
+ * Called by programmatic actions like `sendMessage({ openChat: true })`.
1405
+ * Useful when `renderChat=false` and you control the chat panel's visibility externally.
1406
+ *
1407
+ * @example
1408
+ * ```tsx
1409
+ * const [sidebarOpen, setSidebarOpen] = useState(false);
1410
+ *
1411
+ * <UseAIProvider
1412
+ * serverUrl="ws://localhost:8081"
1413
+ * renderChat={false}
1414
+ * onOpenChange={(isOpen) => {
1415
+ * // Sync with external sidebar state
1416
+ * setSidebarOpen(isOpen);
1417
+ * }}
1418
+ * >
1419
+ * <Sidebar isOpen={sidebarOpen} onClose={() => setSidebarOpen(false)}>
1420
+ * <UseAIChat />
1421
+ * </Sidebar>
1422
+ * </UseAIProvider>
1423
+ * ```
1424
+ */
1425
+ onOpenChange?: (isOpen: boolean) => void;
1212
1426
  }
1213
1427
  /**
1214
1428
  * Provider component that manages AI client connection and tool registration.
@@ -1238,7 +1452,7 @@ interface UseAIProviderProps extends UseAIConfig {
1238
1452
  * }
1239
1453
  * ```
1240
1454
  */
1241
- declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton, CustomChat, chatRepository, mcpHeadersProvider, fileUploadConfig: fileUploadConfigProp, commandRepository, renderChat, theme: customTheme, strings: customStrings, visibleAgentIds, }: UseAIProviderProps): react_jsx_runtime.JSX.Element;
1455
+ declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton, CustomChat, chatRepository, mcpHeadersProvider, fileUploadConfig: fileUploadConfigProp, commandRepository, renderChat, theme: customTheme, strings: customStrings, visibleAgentIds, onOpenChange, }: UseAIProviderProps): react_jsx_runtime.JSX.Element;
1242
1456
  /**
1243
1457
  * Hook to access the UseAI context.
1244
1458
  * When used outside a UseAIProvider, returns a no-op context and logs a warning.
@@ -1358,6 +1572,7 @@ declare class LocalStorageChatRepository implements ChatRepository {
1358
1572
  deleteChat(id: string): Promise<void>;
1359
1573
  listChats(options?: ListChatsOptions): Promise<Array<Omit<Chat, 'messages'>>>;
1360
1574
  deleteAll(): Promise<void>;
1575
+ updateMetadata(id: string, metadata: ChatMetadata, overwrite?: boolean): Promise<void>;
1361
1576
  private getChatKey;
1362
1577
  private getIndex;
1363
1578
  private addToIndex;
@@ -1417,6 +1632,8 @@ interface DropZoneProps {
1417
1632
  onDrop: (e: React$1.DragEvent) => void;
1418
1633
  }
1419
1634
  interface UseFileUploadOptions {
1635
+ /** Function to get the current chat (for transformer context) */
1636
+ getCurrentChat: () => Promise<Chat | null>;
1420
1637
  /** Configuration for file uploads. If undefined, file upload is disabled. */
1421
1638
  config?: FileUploadConfig;
1422
1639
  /** Whether file operations should be disabled (e.g., during loading) */
@@ -1437,6 +1654,8 @@ interface UseFileUploadReturn {
1437
1654
  maxFileSize: number;
1438
1655
  /** Accepted MIME types */
1439
1656
  acceptedTypes?: string[];
1657
+ /** Processing state for each file (by attachment ID) */
1658
+ processingState: Map<string, FileProcessingState>;
1440
1659
  /** Ref to attach to hidden file input */
1441
1660
  fileInputRef: React$1.MutableRefObject<HTMLInputElement | null>;
1442
1661
  /** Validates and adds files to attachments */
@@ -1492,7 +1711,69 @@ interface UseFileUploadReturn {
1492
1711
  * });
1493
1712
  * ```
1494
1713
  */
1495
- declare function useFileUpload({ config, disabled, resetDependency, }: UseFileUploadOptions): UseFileUploadReturn;
1714
+ declare function useFileUpload({ config, disabled, resetDependency, getCurrentChat, }: UseFileUploadOptions): UseFileUploadReturn;
1715
+
1716
+ /**
1717
+ * Check if a MIME type matches a pattern.
1718
+ * Supports exact match and wildcard patterns ending with '*'.
1719
+ *
1720
+ * Examples:
1721
+ * - 'application/pdf' matches 'application/pdf' (exact)
1722
+ * - 'image/png' matches 'image/*' (partial wildcard)
1723
+ * - 'text/plain' matches '*' (global wildcard)
1724
+ * - 'text/plain' matches '*\/*' (global wildcard)
1725
+ */
1726
+ declare function matchesMimeType(mimeType: string, pattern: string): boolean;
1727
+ /**
1728
+ * Find the most specific transformer for a MIME type.
1729
+ *
1730
+ * Specificity rules:
1731
+ * 1. Exact match (no wildcard) always wins
1732
+ * 2. Among wildcard patterns, longer pattern = more specific
1733
+ *
1734
+ * Example for 'image/png':
1735
+ * - 'image/png' (exact, wins)
1736
+ * - 'image/*' (length 7, second)
1737
+ * - '*' (length 1, last)
1738
+ */
1739
+ declare function findTransformer(mimeType: string, transformers: FileTransformerMap | undefined): FileTransformer | undefined;
1740
+
1741
+ /**
1742
+ * Configuration for processing file attachments.
1743
+ */
1744
+ interface ProcessAttachmentsConfig {
1745
+ /** Function to get the current chat (for transformer context) */
1746
+ getCurrentChat: () => Promise<Chat | null>;
1747
+ /** Backend for converting files to URLs (default: EmbedFileUploadBackend) */
1748
+ backend?: FileUploadBackend;
1749
+ /** Map of MIME type patterns to transformers */
1750
+ transformers?: FileTransformerMap;
1751
+ /** Called when a file's processing state changes */
1752
+ onFileProgress?: (fileId: string, state: FileProcessingState) => void;
1753
+ }
1754
+ /**
1755
+ * Process file attachments into multimodal content for AI.
1756
+ * Handles transformation (with caching) or URL encoding.
1757
+ *
1758
+ * @param attachments - The file attachments to process
1759
+ * @param config - Processing configuration
1760
+ * @returns Array of multimodal content parts
1761
+ * @throws On any processing error - caller should handle and show to user
1762
+ *
1763
+ * @example
1764
+ * ```typescript
1765
+ * const content = await processAttachments(attachments, {
1766
+ * transformers: { 'application/pdf': pdfTransformer },
1767
+ * onFileProgress: (id, state) => setProgress(prev => new Map(prev).set(id, state)),
1768
+ * });
1769
+ * ```
1770
+ */
1771
+ declare function processAttachments(attachments: FileAttachment[], config: ProcessAttachmentsConfig): Promise<MultimodalContent[]>;
1772
+ /**
1773
+ * Clear the transformation cache.
1774
+ * Useful for testing or when memory needs to be freed.
1775
+ */
1776
+ declare function clearTransformationCache(): void;
1496
1777
 
1497
1778
  /**
1498
1779
  * LocalStorage-based implementation of CommandRepository.
@@ -1632,75 +1913,6 @@ interface UseSlashCommandsReturn {
1632
1913
  */
1633
1914
  declare function useSlashCommands({ commands, onCommandSelect, onSaveCommand, onRenameCommand, onDeleteCommand, }: UseSlashCommandsOptions): UseSlashCommandsReturn;
1634
1915
 
1635
- interface UseChatManagementOptions {
1636
- /** Chat repository for persistence */
1637
- repository: ChatRepository;
1638
- /** Reference to the UseAIClient (can be null during initialization) */
1639
- clientRef: React.MutableRefObject<UseAIClient | null>;
1640
- }
1641
- interface UseChatManagementReturn {
1642
- /** Current active chat ID where AI responses are saved */
1643
- currentChatId: string | null;
1644
- /** Chat loaded for viewing but not yet active for AI responses */
1645
- pendingChatId: string | null;
1646
- /** Current messages in the chat */
1647
- messages: Message[];
1648
- /** The displayed chat ID (pending or current) */
1649
- displayedChatId: string | null;
1650
- /** Creates a new chat and switches to it */
1651
- createNewChat: () => Promise<string>;
1652
- /** Loads an existing chat by ID */
1653
- loadChat: (chatId: string) => Promise<void>;
1654
- /** Deletes a chat by ID */
1655
- deleteChat: (chatId: string) => Promise<void>;
1656
- /** Lists all available chats */
1657
- listChats: () => Promise<Array<Omit<Chat, 'messages'>>>;
1658
- /** Clears the current chat messages */
1659
- clearCurrentChat: () => Promise<void>;
1660
- /** Activates the pending chat (called when user sends first message) */
1661
- activatePendingChat: () => string | null;
1662
- /** Saves a user message to storage and reloads messages */
1663
- saveUserMessage: (chatId: string, content: PersistedMessageContent) => Promise<boolean>;
1664
- /** Saves an AI response to storage and optionally reloads messages */
1665
- saveAIResponse: (content: string, displayMode?: 'default' | 'error') => Promise<void>;
1666
- /** Reloads messages from storage for the given chat ID */
1667
- reloadMessages: (chatId: string) => Promise<void>;
1668
- /** Snapshot refs for use in event handlers */
1669
- currentChatIdSnapshot: React.MutableRefObject<string | null>;
1670
- pendingChatIdSnapshot: React.MutableRefObject<string | null>;
1671
- }
1672
- /**
1673
- * Hook for managing chat lifecycle operations.
1674
- *
1675
- * Features:
1676
- * - Creates, loads, deletes chats
1677
- * - Manages pending/active chat state machine
1678
- * - Saves user messages and AI responses
1679
- * - Auto-generates chat titles
1680
- * - Initializes with most recent chat or creates new one
1681
- *
1682
- * @example
1683
- * ```typescript
1684
- * const {
1685
- * currentChatId,
1686
- * pendingChatId,
1687
- * messages,
1688
- * createNewChat,
1689
- * loadChat,
1690
- * deleteChat,
1691
- * listChats,
1692
- * clearCurrentChat,
1693
- * activatePendingChat,
1694
- * saveUserMessage,
1695
- * saveAIResponse,
1696
- * } = useChatManagement({
1697
- * repository: chatRepository,
1698
- * clientRef,
1699
- * });
1700
- * ```
1701
- */
1702
- declare function useChatManagement({ repository, clientRef, }: UseChatManagementOptions): UseChatManagementReturn;
1703
-
1704
1916
  interface UseAgentSelectionOptions {
1705
1917
  /** Reference to the UseAIClient (can be null during initialization) */
1706
1918
  clientRef: React.MutableRefObject<UseAIClient | null>;
@@ -1950,4 +2162,4 @@ interface UseDropdownStateOptions {
1950
2162
  */
1951
2163
  declare function useDropdownState(options?: UseDropdownStateOptions): UseDropdownStateReturn;
1952
2164
 
1953
- export { type AgentContextValue, type Chat, type ChatContextValue, type ChatPanelProps, type ChatRepository, CloseButton, type CommandContextValue, type CommandRepository, type CreateChatOptions, type CreateCommandOptions, DEFAULT_MAX_FILE_SIZE, type DefinedTool, type DropZoneProps, EmbedFileUploadBackend, type FileAttachment, type FileUploadBackend, type FileUploadConfig, type FloatingButtonProps, type InlineSaveProps, type ListChatsOptions, type ListCommandsOptions, LocalStorageChatRepository, LocalStorageCommandRepository, type Message, type PersistedContentPart, type PersistedFileContent, type PersistedFileMetadata, type PersistedMessage, type PersistedMessageContent, type PersistedTextContent, type PromptsContextValue, type RegisterToolsOptions, type SavedCommand, type ToolOptions, type ToolRegistryContextValue, type ToolsDefinition, type TriggerWorkflowOptions, UseAIChat, UseAIChatPanel, type UseAIChatPanelProps, type UseAIChatPanelStrings, type UseAIChatPanelTheme, type UseAIChatProps, UseAIClient, type UseAIConfig, type UseAIContextValue, UseAIFloatingButton, UseAIFloatingChatWrapper, type UseAIOptions, UseAIProvider, type UseAIProviderProps, type UseAIResult, type UseAIStrings, type UseAITheme, type UseAIWorkflowResult, type UseAgentSelectionOptions, type UseAgentSelectionReturn, type UseChatManagementOptions, type UseChatManagementReturn, type UseCommandManagementOptions, type UseCommandManagementReturn, type UseDropdownStateOptions, type UseDropdownStateReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UsePromptStateOptions, type UsePromptStateReturn, type UseSlashCommandsOptions, type UseSlashCommandsReturn, type UseToolRegistryReturn, type WorkflowProgress, convertToolsToDefinitions, defaultStrings, defaultTheme, defineTool, executeDefinedTool, generateChatId, generateCommandId, generateMessageId, useAI, useAIContext, useAIWorkflow, useAgentSelection, useChatManagement, useCommandManagement, useDropdownState, useFileUpload, usePromptState, useSlashCommands, useStableTools, useStrings, useTheme, useToolRegistry, validateCommandName };
2165
+ export { type AgentContextValue, type Chat, type ChatContextValue, type ChatMetadata, type ChatPanelProps, type ChatRepository, CloseButton, type CommandContextValue, type CommandRepository, type CreateChatOptions, type CreateCommandOptions, DEFAULT_MAX_FILE_SIZE, type DefinedTool, type DropZoneProps, EmbedFileUploadBackend, type FileAttachment, type FileProcessingState, type FileProcessingStatus, type FileTransformer, type FileTransformerContext, type FileTransformerMap, type FileUploadBackend, type FileUploadConfig, type FloatingButtonProps, type InlineSaveProps, type ListChatsOptions, type ListCommandsOptions, LocalStorageChatRepository, LocalStorageCommandRepository, type Message, type PersistedContentPart, type PersistedFileContent, type PersistedFileMetadata, type PersistedMessage, type PersistedMessageContent, type PersistedTextContent, type ProcessAttachmentsConfig, type PromptsContextValue, type RegisterToolsOptions, type SavedCommand, type SendMessageOptions, type ToolOptions, type ToolRegistryContextValue, type ToolsDefinition, type TriggerWorkflowOptions, UseAIChat, UseAIChatPanel, type UseAIChatPanelProps, type UseAIChatPanelStrings, type UseAIChatPanelTheme, type UseAIChatProps, UseAIClient, type UseAIConfig, type UseAIContextValue, UseAIFloatingButton, UseAIFloatingChatWrapper, type UseAIOptions, UseAIProvider, type UseAIProviderProps, type UseAIResult, type UseAIStrings, type UseAITheme, type UseAIWorkflowResult, type UseAgentSelectionOptions, type UseAgentSelectionReturn, type UseChatManagementOptions, type UseChatManagementReturn, type UseCommandManagementOptions, type UseCommandManagementReturn, type UseDropdownStateOptions, type UseDropdownStateReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UsePromptStateOptions, type UsePromptStateReturn, type UseSlashCommandsOptions, type UseSlashCommandsReturn, type UseToolRegistryReturn, type WorkflowProgress, clearTransformationCache, convertToolsToDefinitions, defaultStrings, defaultTheme, defineTool, executeDefinedTool, findTransformer, generateChatId, generateCommandId, generateMessageId, matchesMimeType, processAttachments, useAI, useAIContext, useAIWorkflow, useAgentSelection, useChatManagement, useCommandManagement, useDropdownState, useFileUpload, usePromptState, useSlashCommands, useStableTools, useStrings, useTheme, useToolRegistry, validateCommandName };