@meetsmore-oss/use-ai-client 1.5.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  export { z } from 'zod';
3
- import * as _meetsmore_oss_use_ai_core from '@meetsmore-oss/use-ai-core';
4
- import { ToolAnnotations, ToolDefinition, WorkflowStatus, FeedbackValue, AgentInfo, McpHeadersMap, MultimodalContent, AGUIEvent, Message as Message$1, UseAIClientMessage } from '@meetsmore-oss/use-ai-core';
3
+ import { ToolAnnotations, ToolDefinition, WorkflowStatus, FeedbackValue, AgentInfo, MultimodalContent, UseAIForwardedProps, AGUIEvent, Message as Message$1, UseAIClientMessage } from '@meetsmore-oss/use-ai-core';
5
4
  export { AgentInfo, ToolAnnotations, ToolDefinition } from '@meetsmore-oss/use-ai-core';
6
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
7
6
  import React$1, { ReactNode } from 'react';
@@ -351,19 +350,30 @@ interface FileTransformerContext {
351
350
  }
352
351
  /**
353
352
  * A transformer that converts files into string representations for the AI.
353
+ *
354
+ * Receives all files that were matched to this transformer instance
355
+ * and returns one string per file in the same order.
356
+ *
357
+ * @example
358
+ * ```typescript
359
+ * const pdfTransformer: FileTransformer = {
360
+ * transform: async (files, context) =>
361
+ * Promise.all(files.map(f => extractText(f))),
362
+ * };
363
+ * ```
354
364
  */
355
365
  interface FileTransformer {
356
366
  /**
357
- * Transform the file into a string representation for the AI.
367
+ * Transform files into string representations for the AI.
358
368
  *
359
- * @param file - The file to transform
369
+ * @param files - The files to transform (all matched to this transformer instance)
360
370
  * @param context - Context including the current chat and its metadata
361
371
  * @param onProgress - Optional callback for reporting progress (0-100).
362
372
  * If called, UI shows progress bar; otherwise shows spinner.
363
- * @returns A string representation the AI will receive
373
+ * @returns One string per input file, in the same order
364
374
  * @throws If transformation fails
365
375
  */
366
- transform(file: File, context: FileTransformerContext, onProgress?: (progress: number) => void): Promise<string>;
376
+ transform(files: File[], context: FileTransformerContext, onProgress?: (progress: number) => void): Promise<string[]>;
367
377
  }
368
378
  /**
369
379
  * Map of MIME type patterns to transformers.
@@ -702,6 +712,24 @@ declare const defaultStrings: {
702
712
  /** Fallback messages when no tool title is provided (one randomly selected) */
703
713
  fallbackMessages: string[];
704
714
  };
715
+ toolApproval: {
716
+ /** Title shown in the approval dialog */
717
+ title: string;
718
+ /** Message shown in the approval dialog. {toolName} is replaced with tool name. */
719
+ message: string;
720
+ /** Message shown when multiple tools are awaiting approval. {count} is replaced with number. */
721
+ batchMessage: string;
722
+ /** Label for approve button */
723
+ approve: string;
724
+ /** Label for approve all button (batch mode) */
725
+ approveAll: string;
726
+ /** Label for reject button */
727
+ reject: string;
728
+ /** Label for reject all button (batch mode) */
729
+ rejectAll: string;
730
+ /** Label for showing tool arguments */
731
+ showDetails: string;
732
+ };
705
733
  };
706
734
  /**
707
735
  * Customizable text labels for the chat UI.
@@ -859,12 +887,23 @@ interface UseAIChatPanelProps {
859
887
  feedbackEnabled?: boolean;
860
888
  /** Callback when user submits feedback on a message */
861
889
  onFeedback?: (messageId: string, traceId: string, feedback: FeedbackValue) => void;
890
+ /** Pending tool approvals awaiting user confirmation */
891
+ pendingApprovals?: Array<{
892
+ toolCallId: string;
893
+ toolCallName: string;
894
+ toolCallArgs: Record<string, unknown>;
895
+ annotations?: ToolAnnotations;
896
+ }>;
897
+ /** Callback to approve all pending tool calls */
898
+ onApproveToolCall?: () => void;
899
+ /** Callback to reject all pending tool calls */
900
+ onRejectToolCall?: (reason?: string) => void;
862
901
  }
863
902
  /**
864
903
  * Chat panel content - fills its container.
865
904
  * Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
866
905
  */
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;
906
+ 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
907
 
869
908
  /**
870
909
  * Handler for AG-UI events from the server.
@@ -901,7 +940,6 @@ declare class UseAIClient {
901
940
  private _tools;
902
941
  private _messages;
903
942
  private _state;
904
- private mcpHeadersProvider?;
905
943
  private _availableAgents;
906
944
  private _defaultAgent;
907
945
  private _selectedAgent;
@@ -942,20 +980,15 @@ declare class UseAIClient {
942
980
  * @param state - The current state object to provide to the AI
943
981
  */
944
982
  updateState(state: unknown): void;
945
- /**
946
- * Sets the MCP headers provider.
947
- * The provider will be called each time a message is sent to get fresh headers.
948
- *
949
- * @param provider - Function that returns MCP headers configuration
950
- */
951
- setMcpHeadersProvider(provider: () => McpHeadersMap | Promise<McpHeadersMap>): void;
952
983
  /**
953
984
  * Sends a user prompt to the AI.
954
985
  *
955
986
  * @param prompt - The user's prompt/question (text part)
956
987
  * @param multimodalContent - Optional multimodal content (text, images, files)
988
+ * @param forwardedProps - Optional props to forward to the server (e.g., telemetryMetadata, mcpHeaders).
989
+ * Internally merged with other forwardedProps.
957
990
  */
958
- sendPrompt(prompt: string, multimodalContent?: MultimodalContent[]): Promise<void>;
991
+ sendPrompt(prompt: string, multimodalContent?: MultimodalContent[], forwardedProps?: UseAIForwardedProps): Promise<void>;
959
992
  /**
960
993
  * Sends the result of a tool execution back to the server.
961
994
  *
@@ -964,6 +997,14 @@ declare class UseAIClient {
964
997
  * @param state - Optional updated state to send back to the AI
965
998
  */
966
999
  sendToolResponse(toolCallId: string, result: unknown, state?: unknown): void;
1000
+ /**
1001
+ * Sends a tool approval response back to the server.
1002
+ *
1003
+ * @param toolCallId - The ID of the tool call being approved/rejected
1004
+ * @param approved - Whether the tool execution is approved
1005
+ * @param reason - Optional reason for rejection (shown to AI)
1006
+ */
1007
+ sendToolApprovalResponse(toolCallId: string, approved: boolean, reason?: string): void;
967
1008
  /**
968
1009
  * Retrieves accumulated tool call data for a specific tool call ID.
969
1010
  * Used to get the complete tool name and arguments after they've been streamed
@@ -1114,6 +1155,11 @@ interface SendMessageOptions {
1114
1155
  openChat?: boolean;
1115
1156
  /** Metadata to set on the new chat (only used when newChat: true) */
1116
1157
  metadata?: ChatMetadata;
1158
+ /**
1159
+ * Forwarded props for observability and configuration (e.g., telemetryMetadata, mcpHeaders).
1160
+ * This is merged with provider-level forwardedProps (message-level takes precedence).
1161
+ */
1162
+ forwardedProps?: UseAIForwardedProps;
1117
1163
  }
1118
1164
  interface UseChatManagementOptions {
1119
1165
  /** Chat repository for persistence */
@@ -1125,13 +1171,15 @@ interface UseChatManagementOptions {
1125
1171
  /** Setter for messages state (owned by provider) */
1126
1172
  setMessages: React.Dispatch<React.SetStateAction<Message[]>>;
1127
1173
  /** Callback to send a message (from UseAIProvider) */
1128
- onSendMessage?: (message: string, attachments?: FileAttachment[]) => Promise<void>;
1174
+ onSendMessage?: (message: string, attachments?: FileAttachment[], forwardedProps?: UseAIForwardedProps) => Promise<void>;
1129
1175
  /** Callback to open/close the chat panel */
1130
1176
  setOpen?: (open: boolean) => void;
1131
1177
  /** Whether the client is connected */
1132
1178
  connected?: boolean;
1133
1179
  /** Whether the AI is currently loading/processing a response */
1134
1180
  loading?: boolean;
1181
+ /** Whether there's a pending tool approval blocking the queue */
1182
+ hasPendingApproval?: boolean;
1135
1183
  }
1136
1184
  interface UseChatManagementReturn {
1137
1185
  /** Current active chat ID where AI responses are saved */
@@ -1202,7 +1250,7 @@ interface UseChatManagementReturn {
1202
1250
  * });
1203
1251
  * ```
1204
1252
  */
1205
- declare function useChatManagement({ repository, clientRef, messages, setMessages, onSendMessage, setOpen, connected, loading, }: UseChatManagementOptions): UseChatManagementReturn;
1253
+ declare function useChatManagement({ repository, clientRef, messages, setMessages, onSendMessage, setOpen, connected, loading, hasPendingApproval, }: UseChatManagementOptions): UseChatManagementReturn;
1206
1254
 
1207
1255
  /**
1208
1256
  * Chat management context (from useChatManagement hook).
@@ -1357,33 +1405,41 @@ interface UseAIProviderProps extends UseAIConfig {
1357
1405
  */
1358
1406
  chatRepository?: ChatRepository;
1359
1407
  /**
1360
- * Callback to provide HTTP headers for MCP endpoints.
1361
- * Called each time AI is invoked by use-ai.
1362
- * Returns a mapping of MCP endpoint patterns to header configurations.
1363
- *
1364
- * Patterns can be:
1365
- * - Constant strings: `https://api.example.com` - Exact match
1366
- * - Glob patterns: `https://*.meetsmore.com` - Wildcard matching using picomatch
1408
+ * Provider function for forwarded props (telemetry metadata, MCP headers, etc.).
1409
+ * Called before each message is sent. Can be sync or async.
1410
+ * Props from this provider are merged with message-level forwardedProps,
1411
+ * with message-level taking precedence.
1367
1412
  *
1368
1413
  * @example
1369
- * ```typescript
1370
- * mcpHeadersProvider={() => ({
1371
- * // Exact match
1372
- * 'https://api.example.com': {
1373
- * headers: { 'Authorization': `Bearer ${userToken}` }
1374
- * },
1375
- * // Wildcard subdomain
1376
- * 'https://*.meetsmore.com': {
1377
- * headers: { 'X-API-Key': apiKey }
1378
- * },
1379
- * // Multiple wildcards
1380
- * '*://*.example.com': {
1381
- * headers: { 'X-Custom': 'value' }
1382
- * }
1383
- * })}
1414
+ * ```tsx
1415
+ * <UseAIProvider
1416
+ * serverUrl="wss://your-server.com"
1417
+ * forwardedPropsProvider={() => ({
1418
+ * mcpHeaders: {
1419
+ * // Exact match
1420
+ * 'https://api.example.com': {
1421
+ * headers: { 'Authorization': `Bearer ${userToken}` }
1422
+ * },
1423
+ * // Wildcard subdomain
1424
+ * 'https://*.meetsmore.com': {
1425
+ * headers: { 'X-API-Key': apiKey }
1426
+ * },
1427
+ * // Multiple wildcards
1428
+ * '*://*.example.com': {
1429
+ * headers: { 'X-Custom': 'value' }
1430
+ * },
1431
+ * },
1432
+ * telemetryMetadata: {
1433
+ * userId: currentUser.id,
1434
+ * tenantId: tenant.id,
1435
+ * },
1436
+ * })}
1437
+ * >
1438
+ * <App />
1439
+ * </UseAIProvider>
1384
1440
  * ```
1385
1441
  */
1386
- mcpHeadersProvider?: () => _meetsmore_oss_use_ai_core.McpHeadersMap | Promise<_meetsmore_oss_use_ai_core.McpHeadersMap>;
1442
+ forwardedPropsProvider?: () => UseAIForwardedProps | Promise<UseAIForwardedProps>;
1387
1443
  /**
1388
1444
  * Configuration for file uploads.
1389
1445
  * File upload is enabled by default with EmbedFileUploadBackend, 10MB max size,
@@ -1497,7 +1553,7 @@ interface UseAIProviderProps extends UseAIConfig {
1497
1553
  * }
1498
1554
  * ```
1499
1555
  */
1500
- 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;
1556
+ declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton, CustomChat, chatRepository, forwardedPropsProvider, fileUploadConfig: fileUploadConfigProp, commandRepository, renderChat, theme: customTheme, strings: customStrings, visibleAgentIds, onOpenChange, }: UseAIProviderProps): react_jsx_runtime.JSX.Element;
1501
1557
  /**
1502
1558
  * Hook to access the UseAI context.
1503
1559
  * When used outside a UseAIProvider, returns a no-op context and logs a warning.
@@ -1770,7 +1826,8 @@ declare function useFileUpload({ config, disabled, resetDependency, getCurrentCh
1770
1826
  */
1771
1827
  declare function matchesMimeType(mimeType: string, pattern: string): boolean;
1772
1828
  /**
1773
- * Find the most specific transformer for a MIME type.
1829
+ * Find the most specific transformer pattern key for a MIME type.
1830
+ * Returns the pattern string (e.g., 'application/pdf', 'image/*') or undefined.
1774
1831
  *
1775
1832
  * Specificity rules:
1776
1833
  * 1. Exact match (no wildcard) always wins
@@ -1781,7 +1838,7 @@ declare function matchesMimeType(mimeType: string, pattern: string): boolean;
1781
1838
  * - 'image/*' (length 7, second)
1782
1839
  * - '*' (length 1, last)
1783
1840
  */
1784
- declare function findTransformer(mimeType: string, transformers: FileTransformerMap | undefined): FileTransformer | undefined;
1841
+ declare function findTransformerPattern(mimeType: string, transformers: FileTransformerMap | undefined): string | undefined;
1785
1842
 
1786
1843
  /**
1787
1844
  * Configuration for processing file attachments.
@@ -1800,6 +1857,9 @@ interface ProcessAttachmentsConfig {
1800
1857
  * Process file attachments into multimodal content for AI.
1801
1858
  * Handles transformation (with caching) or URL encoding.
1802
1859
  *
1860
+ * Files matching the same transformer are grouped and passed together
1861
+ * to `transformer.transform()`.
1862
+ *
1803
1863
  * @param attachments - The file attachments to process
1804
1864
  * @param config - Processing configuration
1805
1865
  * @returns Array of multimodal content parts
@@ -2244,4 +2304,4 @@ interface UseDropdownStateOptions {
2244
2304
  */
2245
2305
  declare function useDropdownState(options?: UseDropdownStateOptions): UseDropdownStateReturn;
2246
2306
 
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 };
2307
+ 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 };