@meetsmore-oss/use-ai-client 1.2.4 → 1.4.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/bundled.js +710 -222
- package/dist/bundled.js.map +1 -1
- package/dist/{chunk-EGD4LT6R.js → chunk-AKQM6IWU.js} +1 -1
- package/dist/chunk-AKQM6IWU.js.map +1 -0
- package/dist/{chunk-EGKUR4C7.js → chunk-QTQR7MAU.js} +1 -1
- package/dist/chunk-QTQR7MAU.js.map +1 -0
- package/dist/index.d.ts +292 -74
- package/dist/index.js +710 -222
- package/dist/index.js.map +1 -1
- package/dist/{types-INERONQV.js → types-64CH2HXY.js} +2 -2
- package/dist/{types-TVUXB3NB.js → types-STDS67SG.js} +2 -2
- package/package.json +2 -2
- package/dist/chunk-EGD4LT6R.js.map +0 -1
- package/dist/chunk-EGKUR4C7.js.map +0 -1
- /package/dist/{types-INERONQV.js.map → types-64CH2HXY.js.map} +0 -0
- /package/dist/{types-TVUXB3NB.js.map → types-STDS67SG.js.map} +0 -0
|
@@ -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":[]}
|
|
@@ -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.
|
|
@@ -567,6 +645,8 @@ declare const defaultStrings: {
|
|
|
567
645
|
connectingPlaceholder: string;
|
|
568
646
|
/** Loading indicator text */
|
|
569
647
|
thinking: string;
|
|
648
|
+
/** File processing indicator text (shown during file transformation like OCR) */
|
|
649
|
+
processingFile: string;
|
|
570
650
|
};
|
|
571
651
|
fileUpload: {
|
|
572
652
|
/** Attach files button tooltip */
|
|
@@ -743,12 +823,16 @@ interface UseAIChatPanelProps {
|
|
|
743
823
|
onLoadChat?: (chatId: string) => Promise<void>;
|
|
744
824
|
onDeleteChat?: (chatId: string) => Promise<void>;
|
|
745
825
|
onListChats?: () => Promise<Array<Omit<Chat, 'messages'>>>;
|
|
826
|
+
/** Gets the current chat */
|
|
827
|
+
onGetChat?: () => Promise<Chat | null>;
|
|
746
828
|
suggestions?: string[];
|
|
747
829
|
availableAgents?: AgentInfo[];
|
|
748
830
|
defaultAgent?: string | null;
|
|
749
831
|
selectedAgent?: string | null;
|
|
750
832
|
onAgentChange?: (agentId: string | null) => void;
|
|
751
833
|
fileUploadConfig?: FileUploadConfig;
|
|
834
|
+
/** File processing state for send-time transformations (e.g., OCR) */
|
|
835
|
+
fileProcessing?: FileProcessingState | null;
|
|
752
836
|
commands?: SavedCommand[];
|
|
753
837
|
onSaveCommand?: (name: string, text: string) => Promise<string>;
|
|
754
838
|
onRenameCommand?: (id: string, newName: string) => Promise<void>;
|
|
@@ -760,7 +844,7 @@ interface UseAIChatPanelProps {
|
|
|
760
844
|
* Chat panel content - fills its container.
|
|
761
845
|
* Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
|
|
762
846
|
*/
|
|
763
|
-
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;
|
|
847
|
+
declare function UseAIChatPanel({ onSendMessage, messages, loading, connected, streamingText, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, fileProcessing, commands, onSaveCommand, onRenameCommand, onDeleteCommand, closeButton, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
|
|
764
848
|
|
|
765
849
|
/**
|
|
766
850
|
* Handler for AG-UI events from the server.
|
|
@@ -980,6 +1064,105 @@ declare class UseAIClient {
|
|
|
980
1064
|
isConnected(): boolean;
|
|
981
1065
|
}
|
|
982
1066
|
|
|
1067
|
+
/**
|
|
1068
|
+
* Options for programmatically sending a message via sendMessage().
|
|
1069
|
+
*/
|
|
1070
|
+
interface SendMessageOptions {
|
|
1071
|
+
/** Start a new chat before sending. Default: false (continue existing chat) */
|
|
1072
|
+
newChat?: boolean;
|
|
1073
|
+
/** File attachments to include with the message */
|
|
1074
|
+
attachments?: File[];
|
|
1075
|
+
/** Open the chat panel after sending. Default: true */
|
|
1076
|
+
openChat?: boolean;
|
|
1077
|
+
/** Metadata to set on the new chat (only used when newChat: true) */
|
|
1078
|
+
metadata?: ChatMetadata;
|
|
1079
|
+
}
|
|
1080
|
+
interface UseChatManagementOptions {
|
|
1081
|
+
/** Chat repository for persistence */
|
|
1082
|
+
repository: ChatRepository;
|
|
1083
|
+
/** Reference to the UseAIClient (can be null during initialization) */
|
|
1084
|
+
clientRef: React.MutableRefObject<UseAIClient | null>;
|
|
1085
|
+
/** Callback to send a message (from UseAIProvider) */
|
|
1086
|
+
onSendMessage?: (message: string, attachments?: FileAttachment[]) => Promise<void>;
|
|
1087
|
+
/** Callback to open/close the chat panel */
|
|
1088
|
+
setOpen?: (open: boolean) => void;
|
|
1089
|
+
/** Whether the client is connected */
|
|
1090
|
+
connected?: boolean;
|
|
1091
|
+
/** Whether the AI is currently loading/processing a response */
|
|
1092
|
+
loading?: boolean;
|
|
1093
|
+
}
|
|
1094
|
+
interface UseChatManagementReturn {
|
|
1095
|
+
/** Current active chat ID where AI responses are saved */
|
|
1096
|
+
currentChatId: string | null;
|
|
1097
|
+
/** Chat loaded for viewing but not yet active for AI responses */
|
|
1098
|
+
pendingChatId: string | null;
|
|
1099
|
+
/** Current messages in the chat */
|
|
1100
|
+
messages: Message[];
|
|
1101
|
+
/** The displayed chat ID (pending or current) */
|
|
1102
|
+
displayedChatId: string | null;
|
|
1103
|
+
/** Creates a new chat and switches to it */
|
|
1104
|
+
createNewChat: (options?: CreateChatOptions) => Promise<string>;
|
|
1105
|
+
/** Loads an existing chat by ID */
|
|
1106
|
+
loadChat: (chatId: string) => Promise<void>;
|
|
1107
|
+
/** Deletes a chat by ID */
|
|
1108
|
+
deleteChat: (chatId: string) => Promise<void>;
|
|
1109
|
+
/** Lists all available chats */
|
|
1110
|
+
listChats: () => Promise<Array<Omit<Chat, 'messages'>>>;
|
|
1111
|
+
/** Clears the current chat messages */
|
|
1112
|
+
clearCurrentChat: () => Promise<void>;
|
|
1113
|
+
/** Activates the pending chat (called when user sends first message) */
|
|
1114
|
+
activatePendingChat: () => string | null;
|
|
1115
|
+
/** Saves a user message to storage and reloads messages */
|
|
1116
|
+
saveUserMessage: (chatId: string, content: PersistedMessageContent) => Promise<boolean>;
|
|
1117
|
+
/** Saves an AI response to storage and optionally reloads messages */
|
|
1118
|
+
saveAIResponse: (content: string, displayMode?: 'default' | 'error') => Promise<void>;
|
|
1119
|
+
/** Reloads messages from storage for the given chat ID */
|
|
1120
|
+
reloadMessages: (chatId: string) => Promise<void>;
|
|
1121
|
+
/**
|
|
1122
|
+
* Programmatically send a message to the chat.
|
|
1123
|
+
* Throws on failure (e.g., not connected, no onSendMessage callback).
|
|
1124
|
+
*/
|
|
1125
|
+
sendMessage: (message: string, options?: SendMessageOptions) => Promise<void>;
|
|
1126
|
+
/** Get the current chat object. Metadata is frozen to prevent accidental mutation. */
|
|
1127
|
+
getCurrentChat: () => Promise<Chat | null>;
|
|
1128
|
+
/** Update metadata for the current chat */
|
|
1129
|
+
updateMetadata: (metadata: ChatMetadata, overwrite?: boolean) => Promise<void>;
|
|
1130
|
+
/** Snapshot refs for use in event handlers */
|
|
1131
|
+
currentChatIdSnapshot: React.MutableRefObject<string | null>;
|
|
1132
|
+
pendingChatIdSnapshot: React.MutableRefObject<string | null>;
|
|
1133
|
+
}
|
|
1134
|
+
/**
|
|
1135
|
+
* Hook for managing chat lifecycle operations.
|
|
1136
|
+
*
|
|
1137
|
+
* Features:
|
|
1138
|
+
* - Creates, loads, deletes chats
|
|
1139
|
+
* - Manages pending/active chat state machine
|
|
1140
|
+
* - Saves user messages and AI responses
|
|
1141
|
+
* - Auto-generates chat titles
|
|
1142
|
+
* - Initializes with most recent chat or creates new one
|
|
1143
|
+
*
|
|
1144
|
+
* @example
|
|
1145
|
+
* ```typescript
|
|
1146
|
+
* const {
|
|
1147
|
+
* currentChatId,
|
|
1148
|
+
* pendingChatId,
|
|
1149
|
+
* messages,
|
|
1150
|
+
* createNewChat,
|
|
1151
|
+
* loadChat,
|
|
1152
|
+
* deleteChat,
|
|
1153
|
+
* listChats,
|
|
1154
|
+
* clearCurrentChat,
|
|
1155
|
+
* activatePendingChat,
|
|
1156
|
+
* saveUserMessage,
|
|
1157
|
+
* saveAIResponse,
|
|
1158
|
+
* } = useChatManagement({
|
|
1159
|
+
* repository: chatRepository,
|
|
1160
|
+
* clientRef,
|
|
1161
|
+
* });
|
|
1162
|
+
* ```
|
|
1163
|
+
*/
|
|
1164
|
+
declare function useChatManagement({ repository, clientRef, onSendMessage, setOpen, connected, loading, }: UseChatManagementOptions): UseChatManagementReturn;
|
|
1165
|
+
|
|
983
1166
|
/**
|
|
984
1167
|
* Chat management context (from useChatManagement hook).
|
|
985
1168
|
*/
|
|
@@ -987,7 +1170,7 @@ interface ChatContextValue {
|
|
|
987
1170
|
/** The current chat ID */
|
|
988
1171
|
currentId: string | null;
|
|
989
1172
|
/** Creates a new chat and switches to it */
|
|
990
|
-
create: () => Promise<string>;
|
|
1173
|
+
create: (options?: CreateChatOptions) => Promise<string>;
|
|
991
1174
|
/** Loads an existing chat by ID */
|
|
992
1175
|
load: (chatId: string) => Promise<void>;
|
|
993
1176
|
/** Deletes a chat by ID */
|
|
@@ -996,6 +1179,19 @@ interface ChatContextValue {
|
|
|
996
1179
|
list: () => Promise<Array<Omit<Chat, 'messages'>>>;
|
|
997
1180
|
/** Clears the current chat messages */
|
|
998
1181
|
clear: () => Promise<void>;
|
|
1182
|
+
/**
|
|
1183
|
+
* Programmatically send a message to the chat.
|
|
1184
|
+
* Throws on failure (e.g., not connected).
|
|
1185
|
+
*/
|
|
1186
|
+
sendMessage: (message: string, options?: SendMessageOptions) => Promise<void>;
|
|
1187
|
+
/** Get the current chat object. Metadata is frozen to prevent accidental mutation. */
|
|
1188
|
+
get: () => Promise<Chat | null>;
|
|
1189
|
+
/**
|
|
1190
|
+
* Update metadata for the current chat.
|
|
1191
|
+
* @param metadata Metadata to set/merge
|
|
1192
|
+
* @param overwrite If true, replaces all metadata instead of merging (default: false)
|
|
1193
|
+
*/
|
|
1194
|
+
updateMetadata: (metadata: ChatMetadata, overwrite?: boolean) => Promise<void>;
|
|
999
1195
|
}
|
|
1000
1196
|
/**
|
|
1001
1197
|
* Agent selection context (from useAgentSelection hook).
|
|
@@ -1207,6 +1403,30 @@ interface UseAIProviderProps extends UseAIConfig {
|
|
|
1207
1403
|
* ```
|
|
1208
1404
|
*/
|
|
1209
1405
|
visibleAgentIds?: AgentInfo['id'][];
|
|
1406
|
+
/**
|
|
1407
|
+
* Callback when the chat open state should change.
|
|
1408
|
+
* Called by programmatic actions like `sendMessage({ openChat: true })`.
|
|
1409
|
+
* Useful when `renderChat=false` and you control the chat panel's visibility externally.
|
|
1410
|
+
*
|
|
1411
|
+
* @example
|
|
1412
|
+
* ```tsx
|
|
1413
|
+
* const [sidebarOpen, setSidebarOpen] = useState(false);
|
|
1414
|
+
*
|
|
1415
|
+
* <UseAIProvider
|
|
1416
|
+
* serverUrl="ws://localhost:8081"
|
|
1417
|
+
* renderChat={false}
|
|
1418
|
+
* onOpenChange={(isOpen) => {
|
|
1419
|
+
* // Sync with external sidebar state
|
|
1420
|
+
* setSidebarOpen(isOpen);
|
|
1421
|
+
* }}
|
|
1422
|
+
* >
|
|
1423
|
+
* <Sidebar isOpen={sidebarOpen} onClose={() => setSidebarOpen(false)}>
|
|
1424
|
+
* <UseAIChat />
|
|
1425
|
+
* </Sidebar>
|
|
1426
|
+
* </UseAIProvider>
|
|
1427
|
+
* ```
|
|
1428
|
+
*/
|
|
1429
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
1210
1430
|
}
|
|
1211
1431
|
/**
|
|
1212
1432
|
* Provider component that manages AI client connection and tool registration.
|
|
@@ -1236,7 +1456,7 @@ interface UseAIProviderProps extends UseAIConfig {
|
|
|
1236
1456
|
* }
|
|
1237
1457
|
* ```
|
|
1238
1458
|
*/
|
|
1239
|
-
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;
|
|
1459
|
+
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;
|
|
1240
1460
|
/**
|
|
1241
1461
|
* Hook to access the UseAI context.
|
|
1242
1462
|
* When used outside a UseAIProvider, returns a no-op context and logs a warning.
|
|
@@ -1356,6 +1576,7 @@ declare class LocalStorageChatRepository implements ChatRepository {
|
|
|
1356
1576
|
deleteChat(id: string): Promise<void>;
|
|
1357
1577
|
listChats(options?: ListChatsOptions): Promise<Array<Omit<Chat, 'messages'>>>;
|
|
1358
1578
|
deleteAll(): Promise<void>;
|
|
1579
|
+
updateMetadata(id: string, metadata: ChatMetadata, overwrite?: boolean): Promise<void>;
|
|
1359
1580
|
private getChatKey;
|
|
1360
1581
|
private getIndex;
|
|
1361
1582
|
private addToIndex;
|
|
@@ -1415,6 +1636,8 @@ interface DropZoneProps {
|
|
|
1415
1636
|
onDrop: (e: React$1.DragEvent) => void;
|
|
1416
1637
|
}
|
|
1417
1638
|
interface UseFileUploadOptions {
|
|
1639
|
+
/** Function to get the current chat (for transformer context) */
|
|
1640
|
+
getCurrentChat: () => Promise<Chat | null>;
|
|
1418
1641
|
/** Configuration for file uploads. If undefined, file upload is disabled. */
|
|
1419
1642
|
config?: FileUploadConfig;
|
|
1420
1643
|
/** Whether file operations should be disabled (e.g., during loading) */
|
|
@@ -1435,6 +1658,8 @@ interface UseFileUploadReturn {
|
|
|
1435
1658
|
maxFileSize: number;
|
|
1436
1659
|
/** Accepted MIME types */
|
|
1437
1660
|
acceptedTypes?: string[];
|
|
1661
|
+
/** Processing state for each file (by attachment ID) */
|
|
1662
|
+
processingState: Map<string, FileProcessingState>;
|
|
1438
1663
|
/** Ref to attach to hidden file input */
|
|
1439
1664
|
fileInputRef: React$1.MutableRefObject<HTMLInputElement | null>;
|
|
1440
1665
|
/** Validates and adds files to attachments */
|
|
@@ -1490,7 +1715,69 @@ interface UseFileUploadReturn {
|
|
|
1490
1715
|
* });
|
|
1491
1716
|
* ```
|
|
1492
1717
|
*/
|
|
1493
|
-
declare function useFileUpload({ config, disabled, resetDependency, }: UseFileUploadOptions): UseFileUploadReturn;
|
|
1718
|
+
declare function useFileUpload({ config, disabled, resetDependency, getCurrentChat, }: UseFileUploadOptions): UseFileUploadReturn;
|
|
1719
|
+
|
|
1720
|
+
/**
|
|
1721
|
+
* Check if a MIME type matches a pattern.
|
|
1722
|
+
* Supports exact match and wildcard patterns ending with '*'.
|
|
1723
|
+
*
|
|
1724
|
+
* Examples:
|
|
1725
|
+
* - 'application/pdf' matches 'application/pdf' (exact)
|
|
1726
|
+
* - 'image/png' matches 'image/*' (partial wildcard)
|
|
1727
|
+
* - 'text/plain' matches '*' (global wildcard)
|
|
1728
|
+
* - 'text/plain' matches '*\/*' (global wildcard)
|
|
1729
|
+
*/
|
|
1730
|
+
declare function matchesMimeType(mimeType: string, pattern: string): boolean;
|
|
1731
|
+
/**
|
|
1732
|
+
* Find the most specific transformer for a MIME type.
|
|
1733
|
+
*
|
|
1734
|
+
* Specificity rules:
|
|
1735
|
+
* 1. Exact match (no wildcard) always wins
|
|
1736
|
+
* 2. Among wildcard patterns, longer pattern = more specific
|
|
1737
|
+
*
|
|
1738
|
+
* Example for 'image/png':
|
|
1739
|
+
* - 'image/png' (exact, wins)
|
|
1740
|
+
* - 'image/*' (length 7, second)
|
|
1741
|
+
* - '*' (length 1, last)
|
|
1742
|
+
*/
|
|
1743
|
+
declare function findTransformer(mimeType: string, transformers: FileTransformerMap | undefined): FileTransformer | undefined;
|
|
1744
|
+
|
|
1745
|
+
/**
|
|
1746
|
+
* Configuration for processing file attachments.
|
|
1747
|
+
*/
|
|
1748
|
+
interface ProcessAttachmentsConfig {
|
|
1749
|
+
/** Function to get the current chat (for transformer context) */
|
|
1750
|
+
getCurrentChat: () => Promise<Chat | null>;
|
|
1751
|
+
/** Backend for converting files to URLs (default: EmbedFileUploadBackend) */
|
|
1752
|
+
backend?: FileUploadBackend;
|
|
1753
|
+
/** Map of MIME type patterns to transformers */
|
|
1754
|
+
transformers?: FileTransformerMap;
|
|
1755
|
+
/** Called when a file's processing state changes */
|
|
1756
|
+
onFileProgress?: (fileId: string, state: FileProcessingState) => void;
|
|
1757
|
+
}
|
|
1758
|
+
/**
|
|
1759
|
+
* Process file attachments into multimodal content for AI.
|
|
1760
|
+
* Handles transformation (with caching) or URL encoding.
|
|
1761
|
+
*
|
|
1762
|
+
* @param attachments - The file attachments to process
|
|
1763
|
+
* @param config - Processing configuration
|
|
1764
|
+
* @returns Array of multimodal content parts
|
|
1765
|
+
* @throws On any processing error - caller should handle and show to user
|
|
1766
|
+
*
|
|
1767
|
+
* @example
|
|
1768
|
+
* ```typescript
|
|
1769
|
+
* const content = await processAttachments(attachments, {
|
|
1770
|
+
* transformers: { 'application/pdf': pdfTransformer },
|
|
1771
|
+
* onFileProgress: (id, state) => setProgress(prev => new Map(prev).set(id, state)),
|
|
1772
|
+
* });
|
|
1773
|
+
* ```
|
|
1774
|
+
*/
|
|
1775
|
+
declare function processAttachments(attachments: FileAttachment[], config: ProcessAttachmentsConfig): Promise<MultimodalContent[]>;
|
|
1776
|
+
/**
|
|
1777
|
+
* Clear the transformation cache.
|
|
1778
|
+
* Useful for testing or when memory needs to be freed.
|
|
1779
|
+
*/
|
|
1780
|
+
declare function clearTransformationCache(): void;
|
|
1494
1781
|
|
|
1495
1782
|
/**
|
|
1496
1783
|
* LocalStorage-based implementation of CommandRepository.
|
|
@@ -1630,75 +1917,6 @@ interface UseSlashCommandsReturn {
|
|
|
1630
1917
|
*/
|
|
1631
1918
|
declare function useSlashCommands({ commands, onCommandSelect, onSaveCommand, onRenameCommand, onDeleteCommand, }: UseSlashCommandsOptions): UseSlashCommandsReturn;
|
|
1632
1919
|
|
|
1633
|
-
interface UseChatManagementOptions {
|
|
1634
|
-
/** Chat repository for persistence */
|
|
1635
|
-
repository: ChatRepository;
|
|
1636
|
-
/** Reference to the UseAIClient (can be null during initialization) */
|
|
1637
|
-
clientRef: React.MutableRefObject<UseAIClient | null>;
|
|
1638
|
-
}
|
|
1639
|
-
interface UseChatManagementReturn {
|
|
1640
|
-
/** Current active chat ID where AI responses are saved */
|
|
1641
|
-
currentChatId: string | null;
|
|
1642
|
-
/** Chat loaded for viewing but not yet active for AI responses */
|
|
1643
|
-
pendingChatId: string | null;
|
|
1644
|
-
/** Current messages in the chat */
|
|
1645
|
-
messages: Message[];
|
|
1646
|
-
/** The displayed chat ID (pending or current) */
|
|
1647
|
-
displayedChatId: string | null;
|
|
1648
|
-
/** Creates a new chat and switches to it */
|
|
1649
|
-
createNewChat: () => Promise<string>;
|
|
1650
|
-
/** Loads an existing chat by ID */
|
|
1651
|
-
loadChat: (chatId: string) => Promise<void>;
|
|
1652
|
-
/** Deletes a chat by ID */
|
|
1653
|
-
deleteChat: (chatId: string) => Promise<void>;
|
|
1654
|
-
/** Lists all available chats */
|
|
1655
|
-
listChats: () => Promise<Array<Omit<Chat, 'messages'>>>;
|
|
1656
|
-
/** Clears the current chat messages */
|
|
1657
|
-
clearCurrentChat: () => Promise<void>;
|
|
1658
|
-
/** Activates the pending chat (called when user sends first message) */
|
|
1659
|
-
activatePendingChat: () => string | null;
|
|
1660
|
-
/** Saves a user message to storage and reloads messages */
|
|
1661
|
-
saveUserMessage: (chatId: string, content: PersistedMessageContent) => Promise<boolean>;
|
|
1662
|
-
/** Saves an AI response to storage and optionally reloads messages */
|
|
1663
|
-
saveAIResponse: (content: string, displayMode?: 'default' | 'error') => Promise<void>;
|
|
1664
|
-
/** Reloads messages from storage for the given chat ID */
|
|
1665
|
-
reloadMessages: (chatId: string) => Promise<void>;
|
|
1666
|
-
/** Snapshot refs for use in event handlers */
|
|
1667
|
-
currentChatIdSnapshot: React.MutableRefObject<string | null>;
|
|
1668
|
-
pendingChatIdSnapshot: React.MutableRefObject<string | null>;
|
|
1669
|
-
}
|
|
1670
|
-
/**
|
|
1671
|
-
* Hook for managing chat lifecycle operations.
|
|
1672
|
-
*
|
|
1673
|
-
* Features:
|
|
1674
|
-
* - Creates, loads, deletes chats
|
|
1675
|
-
* - Manages pending/active chat state machine
|
|
1676
|
-
* - Saves user messages and AI responses
|
|
1677
|
-
* - Auto-generates chat titles
|
|
1678
|
-
* - Initializes with most recent chat or creates new one
|
|
1679
|
-
*
|
|
1680
|
-
* @example
|
|
1681
|
-
* ```typescript
|
|
1682
|
-
* const {
|
|
1683
|
-
* currentChatId,
|
|
1684
|
-
* pendingChatId,
|
|
1685
|
-
* messages,
|
|
1686
|
-
* createNewChat,
|
|
1687
|
-
* loadChat,
|
|
1688
|
-
* deleteChat,
|
|
1689
|
-
* listChats,
|
|
1690
|
-
* clearCurrentChat,
|
|
1691
|
-
* activatePendingChat,
|
|
1692
|
-
* saveUserMessage,
|
|
1693
|
-
* saveAIResponse,
|
|
1694
|
-
* } = useChatManagement({
|
|
1695
|
-
* repository: chatRepository,
|
|
1696
|
-
* clientRef,
|
|
1697
|
-
* });
|
|
1698
|
-
* ```
|
|
1699
|
-
*/
|
|
1700
|
-
declare function useChatManagement({ repository, clientRef, }: UseChatManagementOptions): UseChatManagementReturn;
|
|
1701
|
-
|
|
1702
1920
|
interface UseAgentSelectionOptions {
|
|
1703
1921
|
/** Reference to the UseAIClient (can be null during initialization) */
|
|
1704
1922
|
clientRef: React.MutableRefObject<UseAIClient | null>;
|
|
@@ -1948,4 +2166,4 @@ interface UseDropdownStateOptions {
|
|
|
1948
2166
|
*/
|
|
1949
2167
|
declare function useDropdownState(options?: UseDropdownStateOptions): UseDropdownStateReturn;
|
|
1950
2168
|
|
|
1951
|
-
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 };
|
|
2169
|
+
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 };
|