@meetsmore-oss/use-ai-client 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -351,19 +351,30 @@ interface FileTransformerContext {
351
351
  }
352
352
  /**
353
353
  * A transformer that converts files into string representations for the AI.
354
+ *
355
+ * Receives all files that were matched to this transformer instance
356
+ * and returns one string per file in the same order.
357
+ *
358
+ * @example
359
+ * ```typescript
360
+ * const pdfTransformer: FileTransformer = {
361
+ * transform: async (files, context) =>
362
+ * Promise.all(files.map(f => extractText(f))),
363
+ * };
364
+ * ```
354
365
  */
355
366
  interface FileTransformer {
356
367
  /**
357
- * Transform the file into a string representation for the AI.
368
+ * Transform files into string representations for the AI.
358
369
  *
359
- * @param file - The file to transform
370
+ * @param files - The files to transform (all matched to this transformer instance)
360
371
  * @param context - Context including the current chat and its metadata
361
372
  * @param onProgress - Optional callback for reporting progress (0-100).
362
373
  * If called, UI shows progress bar; otherwise shows spinner.
363
- * @returns A string representation the AI will receive
374
+ * @returns One string per input file, in the same order
364
375
  * @throws If transformation fails
365
376
  */
366
- transform(file: File, context: FileTransformerContext, onProgress?: (progress: number) => void): Promise<string>;
377
+ transform(files: File[], context: FileTransformerContext, onProgress?: (progress: number) => void): Promise<string[]>;
367
378
  }
368
379
  /**
369
380
  * Map of MIME type patterns to transformers.
@@ -702,6 +713,24 @@ declare const defaultStrings: {
702
713
  /** Fallback messages when no tool title is provided (one randomly selected) */
703
714
  fallbackMessages: string[];
704
715
  };
716
+ toolApproval: {
717
+ /** Title shown in the approval dialog */
718
+ title: string;
719
+ /** Message shown in the approval dialog. {toolName} is replaced with tool name. */
720
+ message: string;
721
+ /** Message shown when multiple tools are awaiting approval. {count} is replaced with number. */
722
+ batchMessage: string;
723
+ /** Label for approve button */
724
+ approve: string;
725
+ /** Label for approve all button (batch mode) */
726
+ approveAll: string;
727
+ /** Label for reject button */
728
+ reject: string;
729
+ /** Label for reject all button (batch mode) */
730
+ rejectAll: string;
731
+ /** Label for showing tool arguments */
732
+ showDetails: string;
733
+ };
705
734
  };
706
735
  /**
707
736
  * Customizable text labels for the chat UI.
@@ -859,12 +888,23 @@ interface UseAIChatPanelProps {
859
888
  feedbackEnabled?: boolean;
860
889
  /** Callback when user submits feedback on a message */
861
890
  onFeedback?: (messageId: string, traceId: string, feedback: FeedbackValue) => void;
891
+ /** Pending tool approvals awaiting user confirmation */
892
+ pendingApprovals?: Array<{
893
+ toolCallId: string;
894
+ toolCallName: string;
895
+ toolCallArgs: Record<string, unknown>;
896
+ annotations?: ToolAnnotations;
897
+ }>;
898
+ /** Callback to approve all pending tool calls */
899
+ onApproveToolCall?: () => void;
900
+ /** Callback to reject all pending tool calls */
901
+ onRejectToolCall?: (reason?: string) => void;
862
902
  }
863
903
  /**
864
904
  * Chat panel content - fills its container.
865
905
  * Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
866
906
  */
867
- 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, executingTool, feedbackEnabled, onFeedback, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
907
+ 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, executingTool, feedbackEnabled, onFeedback, pendingApprovals, onApproveToolCall, onRejectToolCall, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
868
908
 
869
909
  /**
870
910
  * Handler for AG-UI events from the server.
@@ -964,6 +1004,14 @@ declare class UseAIClient {
964
1004
  * @param state - Optional updated state to send back to the AI
965
1005
  */
966
1006
  sendToolResponse(toolCallId: string, result: unknown, state?: unknown): void;
1007
+ /**
1008
+ * Sends a tool approval response back to the server.
1009
+ *
1010
+ * @param toolCallId - The ID of the tool call being approved/rejected
1011
+ * @param approved - Whether the tool execution is approved
1012
+ * @param reason - Optional reason for rejection (shown to AI)
1013
+ */
1014
+ sendToolApprovalResponse(toolCallId: string, approved: boolean, reason?: string): void;
967
1015
  /**
968
1016
  * Retrieves accumulated tool call data for a specific tool call ID.
969
1017
  * Used to get the complete tool name and arguments after they've been streamed
@@ -1132,6 +1180,8 @@ interface UseChatManagementOptions {
1132
1180
  connected?: boolean;
1133
1181
  /** Whether the AI is currently loading/processing a response */
1134
1182
  loading?: boolean;
1183
+ /** Whether there's a pending tool approval blocking the queue */
1184
+ hasPendingApproval?: boolean;
1135
1185
  }
1136
1186
  interface UseChatManagementReturn {
1137
1187
  /** Current active chat ID where AI responses are saved */
@@ -1202,7 +1252,7 @@ interface UseChatManagementReturn {
1202
1252
  * });
1203
1253
  * ```
1204
1254
  */
1205
- declare function useChatManagement({ repository, clientRef, messages, setMessages, onSendMessage, setOpen, connected, loading, }: UseChatManagementOptions): UseChatManagementReturn;
1255
+ declare function useChatManagement({ repository, clientRef, messages, setMessages, onSendMessage, setOpen, connected, loading, hasPendingApproval, }: UseChatManagementOptions): UseChatManagementReturn;
1206
1256
 
1207
1257
  /**
1208
1258
  * Chat management context (from useChatManagement hook).
@@ -1770,7 +1820,8 @@ declare function useFileUpload({ config, disabled, resetDependency, getCurrentCh
1770
1820
  */
1771
1821
  declare function matchesMimeType(mimeType: string, pattern: string): boolean;
1772
1822
  /**
1773
- * Find the most specific transformer for a MIME type.
1823
+ * Find the most specific transformer pattern key for a MIME type.
1824
+ * Returns the pattern string (e.g., 'application/pdf', 'image/*') or undefined.
1774
1825
  *
1775
1826
  * Specificity rules:
1776
1827
  * 1. Exact match (no wildcard) always wins
@@ -1781,7 +1832,7 @@ declare function matchesMimeType(mimeType: string, pattern: string): boolean;
1781
1832
  * - 'image/*' (length 7, second)
1782
1833
  * - '*' (length 1, last)
1783
1834
  */
1784
- declare function findTransformer(mimeType: string, transformers: FileTransformerMap | undefined): FileTransformer | undefined;
1835
+ declare function findTransformerPattern(mimeType: string, transformers: FileTransformerMap | undefined): string | undefined;
1785
1836
 
1786
1837
  /**
1787
1838
  * Configuration for processing file attachments.
@@ -1800,6 +1851,9 @@ interface ProcessAttachmentsConfig {
1800
1851
  * Process file attachments into multimodal content for AI.
1801
1852
  * Handles transformation (with caching) or URL encoding.
1802
1853
  *
1854
+ * Files matching the same transformer are grouped and passed together
1855
+ * to `transformer.transform()`.
1856
+ *
1803
1857
  * @param attachments - The file attachments to process
1804
1858
  * @param config - Processing configuration
1805
1859
  * @returns Array of multimodal content parts
@@ -2244,4 +2298,4 @@ interface UseDropdownStateOptions {
2244
2298
  */
2245
2299
  declare function useDropdownState(options?: UseDropdownStateOptions): UseDropdownStateReturn;
2246
2300
 
2247
- 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 UseFeedbackOptions, type UseFeedbackReturn, 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, useFeedback, useFileUpload, usePromptState, useSlashCommands, useStableTools, useStrings, useTheme, useToolRegistry, validateCommandName };
2301
+ 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 UseFeedbackOptions, type UseFeedbackReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UsePromptStateOptions, type UsePromptStateReturn, type UseSlashCommandsOptions, type UseSlashCommandsReturn, type UseToolRegistryReturn, type WorkflowProgress, clearTransformationCache, convertToolsToDefinitions, defaultStrings, defaultTheme, defineTool, executeDefinedTool, findTransformerPattern, generateChatId, generateCommandId, generateMessageId, matchesMimeType, processAttachments, useAI, useAIContext, useAIWorkflow, useAgentSelection, useChatManagement, useCommandManagement, useDropdownState, useFeedback, useFileUpload, usePromptState, useSlashCommands, useStableTools, useStrings, useTheme, useToolRegistry, validateCommandName };