@meetsmore-oss/use-ai-client 1.2.4 → 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.
- package/dist/bundled.js +664 -219
- 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 +288 -74
- package/dist/index.js +664 -219
- 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.
|
|
@@ -743,6 +821,8 @@ interface UseAIChatPanelProps {
|
|
|
743
821
|
onLoadChat?: (chatId: string) => Promise<void>;
|
|
744
822
|
onDeleteChat?: (chatId: string) => Promise<void>;
|
|
745
823
|
onListChats?: () => Promise<Array<Omit<Chat, 'messages'>>>;
|
|
824
|
+
/** Gets the current chat */
|
|
825
|
+
onGetChat?: () => Promise<Chat | null>;
|
|
746
826
|
suggestions?: string[];
|
|
747
827
|
availableAgents?: AgentInfo[];
|
|
748
828
|
defaultAgent?: string | null;
|
|
@@ -760,7 +840,7 @@ interface UseAIChatPanelProps {
|
|
|
760
840
|
* Chat panel content - fills its container.
|
|
761
841
|
* Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
|
|
762
842
|
*/
|
|
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;
|
|
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;
|
|
764
844
|
|
|
765
845
|
/**
|
|
766
846
|
* Handler for AG-UI events from the server.
|
|
@@ -980,6 +1060,105 @@ declare class UseAIClient {
|
|
|
980
1060
|
isConnected(): boolean;
|
|
981
1061
|
}
|
|
982
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
|
+
|
|
983
1162
|
/**
|
|
984
1163
|
* Chat management context (from useChatManagement hook).
|
|
985
1164
|
*/
|
|
@@ -987,7 +1166,7 @@ interface ChatContextValue {
|
|
|
987
1166
|
/** The current chat ID */
|
|
988
1167
|
currentId: string | null;
|
|
989
1168
|
/** Creates a new chat and switches to it */
|
|
990
|
-
create: () => Promise<string>;
|
|
1169
|
+
create: (options?: CreateChatOptions) => Promise<string>;
|
|
991
1170
|
/** Loads an existing chat by ID */
|
|
992
1171
|
load: (chatId: string) => Promise<void>;
|
|
993
1172
|
/** Deletes a chat by ID */
|
|
@@ -996,6 +1175,19 @@ interface ChatContextValue {
|
|
|
996
1175
|
list: () => Promise<Array<Omit<Chat, 'messages'>>>;
|
|
997
1176
|
/** Clears the current chat messages */
|
|
998
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>;
|
|
999
1191
|
}
|
|
1000
1192
|
/**
|
|
1001
1193
|
* Agent selection context (from useAgentSelection hook).
|
|
@@ -1207,6 +1399,30 @@ interface UseAIProviderProps extends UseAIConfig {
|
|
|
1207
1399
|
* ```
|
|
1208
1400
|
*/
|
|
1209
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;
|
|
1210
1426
|
}
|
|
1211
1427
|
/**
|
|
1212
1428
|
* Provider component that manages AI client connection and tool registration.
|
|
@@ -1236,7 +1452,7 @@ interface UseAIProviderProps extends UseAIConfig {
|
|
|
1236
1452
|
* }
|
|
1237
1453
|
* ```
|
|
1238
1454
|
*/
|
|
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;
|
|
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;
|
|
1240
1456
|
/**
|
|
1241
1457
|
* Hook to access the UseAI context.
|
|
1242
1458
|
* When used outside a UseAIProvider, returns a no-op context and logs a warning.
|
|
@@ -1356,6 +1572,7 @@ declare class LocalStorageChatRepository implements ChatRepository {
|
|
|
1356
1572
|
deleteChat(id: string): Promise<void>;
|
|
1357
1573
|
listChats(options?: ListChatsOptions): Promise<Array<Omit<Chat, 'messages'>>>;
|
|
1358
1574
|
deleteAll(): Promise<void>;
|
|
1575
|
+
updateMetadata(id: string, metadata: ChatMetadata, overwrite?: boolean): Promise<void>;
|
|
1359
1576
|
private getChatKey;
|
|
1360
1577
|
private getIndex;
|
|
1361
1578
|
private addToIndex;
|
|
@@ -1415,6 +1632,8 @@ interface DropZoneProps {
|
|
|
1415
1632
|
onDrop: (e: React$1.DragEvent) => void;
|
|
1416
1633
|
}
|
|
1417
1634
|
interface UseFileUploadOptions {
|
|
1635
|
+
/** Function to get the current chat (for transformer context) */
|
|
1636
|
+
getCurrentChat: () => Promise<Chat | null>;
|
|
1418
1637
|
/** Configuration for file uploads. If undefined, file upload is disabled. */
|
|
1419
1638
|
config?: FileUploadConfig;
|
|
1420
1639
|
/** Whether file operations should be disabled (e.g., during loading) */
|
|
@@ -1435,6 +1654,8 @@ interface UseFileUploadReturn {
|
|
|
1435
1654
|
maxFileSize: number;
|
|
1436
1655
|
/** Accepted MIME types */
|
|
1437
1656
|
acceptedTypes?: string[];
|
|
1657
|
+
/** Processing state for each file (by attachment ID) */
|
|
1658
|
+
processingState: Map<string, FileProcessingState>;
|
|
1438
1659
|
/** Ref to attach to hidden file input */
|
|
1439
1660
|
fileInputRef: React$1.MutableRefObject<HTMLInputElement | null>;
|
|
1440
1661
|
/** Validates and adds files to attachments */
|
|
@@ -1490,7 +1711,69 @@ interface UseFileUploadReturn {
|
|
|
1490
1711
|
* });
|
|
1491
1712
|
* ```
|
|
1492
1713
|
*/
|
|
1493
|
-
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;
|
|
1494
1777
|
|
|
1495
1778
|
/**
|
|
1496
1779
|
* LocalStorage-based implementation of CommandRepository.
|
|
@@ -1630,75 +1913,6 @@ interface UseSlashCommandsReturn {
|
|
|
1630
1913
|
*/
|
|
1631
1914
|
declare function useSlashCommands({ commands, onCommandSelect, onSaveCommand, onRenameCommand, onDeleteCommand, }: UseSlashCommandsOptions): UseSlashCommandsReturn;
|
|
1632
1915
|
|
|
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
1916
|
interface UseAgentSelectionOptions {
|
|
1703
1917
|
/** Reference to the UseAIClient (can be null during initialization) */
|
|
1704
1918
|
clientRef: React.MutableRefObject<UseAIClient | null>;
|
|
@@ -1948,4 +2162,4 @@ interface UseDropdownStateOptions {
|
|
|
1948
2162
|
*/
|
|
1949
2163
|
declare function useDropdownState(options?: UseDropdownStateOptions): UseDropdownStateReturn;
|
|
1950
2164
|
|
|
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 };
|
|
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 };
|