@meetsmore-oss/use-ai-client 1.14.1 → 1.16.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
@@ -324,6 +324,18 @@ interface UseAIConfig {
324
324
  /** The WebSocket URL of the UseAI server */
325
325
  serverUrl: string;
326
326
  }
327
+ /**
328
+ * Toggles for optional chat UI features. Each feature defaults to enabled
329
+ * when its flag is omitted, so set a flag to false to opt out of that feature.
330
+ */
331
+ interface EnabledFeatures {
332
+ /**
333
+ * The "save as slash command" UI (hover save button + inline save editor)
334
+ * on user messages. Saved-command autocomplete via "/" is unaffected.
335
+ * @default true
336
+ */
337
+ slashCommands?: boolean;
338
+ }
327
339
 
328
340
  /**
329
341
  * Handler for AG-UI events from the server.
@@ -656,24 +668,40 @@ interface FileAttachment {
656
668
  transformedContent?: string;
657
669
  }
658
670
  /**
659
- * Abstract file upload backend interface.
660
- * Converts File objects to URLs at send time.
671
+ * Result of preparing a file for send.
672
+ *
673
+ * Only one of the two is returned:
674
+ * - `{ url }`: a directly usable url (an inline base64 data URL, or a remote url).
675
+ * The bytes travel along with the message.
676
+ * - `{ ref }`: a pointer into persistent storage (e.g. an S3 key). The bytes stay in
677
+ * storage; only the ref travels with the message and is kept in history. It is
678
+ * resolved on the server before being passed to the model.
679
+ *
680
+ * A backend may also return a bare `string`, which is treated as `{ url: string }`
681
+ * (for backward compatibility with backends written against the older signature).
682
+ */
683
+ type FileUploadResult = {
684
+ url: string;
685
+ } | {
686
+ ref: string;
687
+ };
688
+ /**
689
+ * Interface for an abstract file upload backend.
690
+ * Converts a File object into a sendable reference at send time.
661
691
  *
662
692
  * Implementations:
663
- * - EmbedFileUploadBackend: Converts to base64 data URL (built-in)
664
- * - S3FileUploadBackend: Uploads to S3 and returns public URL (future)
693
+ * - EmbedFileUploadBackend: converts to a base64 data URL (built-in)
694
+ * - S3FileUploadBackend: uploads to storage and returns a `ref` (future)
665
695
  */
666
696
  interface FileUploadBackend {
667
697
  /**
668
- * Prepare file for sending to AI.
669
- * Called at send time - converts File to URL.
698
+ * Prepare a file to send to the AI. Called at send time.
670
699
  *
671
700
  * @param file - The File object to prepare
672
- * @returns Promise resolving to a URL string
673
- * - For embed: base64 data URL
674
- * - For S3: public URL after upload
701
+ * @returns A {@link FileUploadResult} (`{ url }` or `{ ref }`), or a bare url string
702
+ * for backward compatibility (treated as `{ url }`).
675
703
  */
676
- prepareForSend(file: File): Promise<string>;
704
+ prepareForSend(file: File): Promise<string | FileUploadResult>;
677
705
  }
678
706
  /**
679
707
  * Context provided to file transformers.
@@ -761,6 +789,14 @@ interface FileUploadConfig {
761
789
  * before being sent to the AI.
762
790
  */
763
791
  transformers?: FileTransformerMap;
792
+ /**
793
+ * Maximum number of attachments allowed per message.
794
+ * Enforced at attach time; files beyond the limit are rejected with an error.
795
+ * The value is the host's policy (e.g. set it below the AI provider's per-message
796
+ * limit). use-ai only exposes the knob and assumes no default. When undefined, the
797
+ * number of attachments is not limited.
798
+ */
799
+ maxAttachments?: number;
764
800
  }
765
801
 
766
802
  /**
@@ -799,11 +835,35 @@ interface PersistedTransformedFileContent {
799
835
  text: string;
800
836
  originalFile: PersistedFileMetadata;
801
837
  }
838
+ /**
839
+ * Ref-backed attachment content part for persisted messages.
840
+ *
841
+ * Unlike {@link PersistedFileContent} (metadata only, discarded on reload), this part
842
+ * holds a `ref` into persistent storage (e.g. an S3 key). This lets attachments be
843
+ * re-sent to the AI even after a page reload. The actual bytes live in storage rather
844
+ * than localStorage, and the ref is resolved on the host before the next run.
845
+ *
846
+ * Covers both image and non-image attachments in a single type (the persistence layer
847
+ * does not split them: display is identical, and the re-send tag is derived from
848
+ * `mimeType`). On reload it is read two ways: as a name/size chip for display, and as a
849
+ * re-sendable `{ type: 'image_ref' | 'file_ref', ref }` wire part (see `messageConversion.ts`).
850
+ */
851
+ interface PersistedAttachmentRefContent {
852
+ type: 'attachment_ref';
853
+ /** Ref into persistent storage (e.g. an S3 key). Never expires. */
854
+ ref: string;
855
+ /** Original file name (for display). */
856
+ name: string;
857
+ /** MIME type, e.g. 'image/jpeg' | 'application/pdf'. Decides whether to re-send as image or file. */
858
+ mimeType: string;
859
+ /** Byte size after client-side resize (for display). */
860
+ size: number;
861
+ }
802
862
  /**
803
863
  * Content part for persisted messages.
804
- * Can be text, file metadata, or transformed file content.
864
+ * One of: text, file metadata, transformed file content, or a ref-backed attachment.
805
865
  */
806
- type PersistedContentPart = PersistedTextContent | PersistedFileContent | PersistedTransformedFileContent;
866
+ type PersistedContentPart = PersistedTextContent | PersistedFileContent | PersistedTransformedFileContent | PersistedAttachmentRefContent;
807
867
  /**
808
868
  * Content that can be persisted.
809
869
  * Simple string for text-only messages, or array for multimodal content.
@@ -1188,6 +1248,8 @@ declare const defaultStrings: {
1188
1248
  fileSizeError: string;
1189
1249
  /** File type error (use {type} placeholder) */
1190
1250
  fileTypeError: string;
1251
+ /** Error when too many files are attached (use {max} placeholder) */
1252
+ maxAttachmentsError: string;
1191
1253
  };
1192
1254
  floatingButton: {
1193
1255
  /** Floating button title when connected */
@@ -1584,6 +1646,13 @@ interface UseAIProviderProps extends UseAIConfig {
1584
1646
  * Defaults to LocalStorageCommandRepository if not provided.
1585
1647
  */
1586
1648
  commandRepository?: CommandRepository;
1649
+ /**
1650
+ * Opt-out toggles for optional chat UI features. Each feature defaults to
1651
+ * enabled, so only set a flag to false to hide it. For example, set
1652
+ * `{ slashCommands: false }` to hide the "save as slash command" UI while
1653
+ * keeping "/" autocomplete for existing saved commands.
1654
+ */
1655
+ enabledFeatures?: EnabledFeatures;
1587
1656
  /**
1588
1657
  * Whether to render the built-in chat UI (floating button + panel).
1589
1658
  * Set to false when using the `<UseAIChat>` component to control chat placement.
@@ -1695,7 +1764,7 @@ interface UseAIProviderProps extends UseAIConfig {
1695
1764
  * }
1696
1765
  * ```
1697
1766
  */
1698
- declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton, CustomChat, chatRepository, forwardedPropsProvider, fileUploadConfig: fileUploadConfigProp, commandRepository, renderChat, theme: customTheme, strings: customStrings, visibleAgentIds, onOpenChange, submitMode, }: UseAIProviderProps): react_jsx_runtime.JSX.Element;
1767
+ declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton, CustomChat, chatRepository, forwardedPropsProvider, fileUploadConfig: fileUploadConfigProp, commandRepository, enabledFeatures, renderChat, theme: customTheme, strings: customStrings, visibleAgentIds, onOpenChange, submitMode, }: UseAIProviderProps): react_jsx_runtime.JSX.Element;
1699
1768
  /**
1700
1769
  * Hook to access the UseAI context.
1701
1770
  * When used outside a UseAIProvider, returns a no-op context and logs a warning.
@@ -1744,6 +1813,13 @@ interface UseAIChatPanelProps {
1744
1813
  fileProcessing?: FileProcessingState | null;
1745
1814
  commands?: SavedCommand[];
1746
1815
  onSaveCommand?: (name: string, text: string) => Promise<string>;
1816
+ /**
1817
+ * Opt-out toggles for optional chat UI features. Each feature defaults to
1818
+ * enabled when omitted. `slashCommands` controls the "save as slash command"
1819
+ * UI (hover save button + inline editor); saved-command autocomplete is
1820
+ * unaffected.
1821
+ */
1822
+ enabledFeatures?: EnabledFeatures;
1747
1823
  onRenameCommand?: (id: string, newName: string) => Promise<void>;
1748
1824
  onDeleteCommand?: (id: string) => Promise<void>;
1749
1825
  /** Optional close button to render in header (for floating mode) */
@@ -1786,7 +1862,7 @@ interface UseAIChatPanelProps {
1786
1862
  * Chat panel content - fills its container.
1787
1863
  * Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
1788
1864
  */
1789
- declare function UseAIChatPanel({ onSendMessage, onAbort, messages, loading, connected, streamingText, streamingReasoning, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, fileProcessing, commands, onSaveCommand, onRenameCommand, onDeleteCommand, closeButton, executingTool, feedbackEnabled, onFeedback, pendingApprovals, onApproveToolCall, onRejectToolCall, submitMode, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
1865
+ declare function UseAIChatPanel({ onSendMessage, onAbort, messages, loading, connected, streamingText, streamingReasoning, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, fileProcessing, commands, onSaveCommand, enabledFeatures, onRenameCommand, onDeleteCommand, closeButton, executingTool, feedbackEnabled, onFeedback, pendingApprovals, onApproveToolCall, onRejectToolCall, submitMode, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
1790
1866
 
1791
1867
  /**
1792
1868
  * Props for the floating chat wrapper.
@@ -2612,4 +2688,4 @@ interface UseDropdownStateOptions {
2612
2688
  */
2613
2689
  declare function useDropdownState(options?: UseDropdownStateOptions): UseDropdownStateReturn;
2614
2690
 
2615
- 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 ExecutingToolDisplay, 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 PendingToolApproval, type PersistedContentPart, type PersistedFileContent, type PersistedFileMetadata, type PersistedMessage, type PersistedMessageContent, type PersistedTextContent, type ProcessAttachmentsConfig, type PromptsContextValue, type RegisterToolsOptions, type SavedCommand, type SendMessageOptions, type SubmitMode, type ToolExecutionContext, 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 UseMessageQueueOptions, type UseMessageQueueReturn, type UsePromptStateOptions, type UsePromptStateReturn, type UseServerEventsOptions, type UseServerEventsReturn, type UseSlashCommandsOptions, type UseSlashCommandsReturn, type UseToolSystemOptions, type UseToolSystemReturn, type WorkflowProgress, clearTransformationCache, convertToolsToDefinitions, defaultStrings, defaultTheme, defineTool, executeDefinedTool, findTransformerPattern, generateChatId, generateCommandId, generateMessageId, matchesMimeType, processAttachments, useAI, useAIContext, useAIWorkflow, useAgentSelection, useChatManagement, useCommandManagement, useDropdownState, useFeedback, useFileUpload, useMessageQueue, usePromptState, useServerEvents, useSlashCommands, useStableTools, useStrings, useTheme, useToolSystem, validateCommandName };
2691
+ 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 EnabledFeatures, type ExecutingToolDisplay, type FileAttachment, type FileProcessingState, type FileProcessingStatus, type FileTransformer, type FileTransformerContext, type FileTransformerMap, type FileUploadBackend, type FileUploadConfig, type FileUploadResult, type FloatingButtonProps, type InlineSaveProps, type ListChatsOptions, type ListCommandsOptions, LocalStorageChatRepository, LocalStorageCommandRepository, type Message, type PendingToolApproval, type PersistedAttachmentRefContent, type PersistedContentPart, type PersistedFileContent, type PersistedFileMetadata, type PersistedMessage, type PersistedMessageContent, type PersistedTextContent, type PersistedTransformedFileContent, type ProcessAttachmentsConfig, type PromptsContextValue, type RegisterToolsOptions, type SavedCommand, type SendMessageOptions, type SubmitMode, type ToolExecutionContext, 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 UseMessageQueueOptions, type UseMessageQueueReturn, type UsePromptStateOptions, type UsePromptStateReturn, type UseServerEventsOptions, type UseServerEventsReturn, type UseSlashCommandsOptions, type UseSlashCommandsReturn, type UseToolSystemOptions, type UseToolSystemReturn, type WorkflowProgress, clearTransformationCache, convertToolsToDefinitions, defaultStrings, defaultTheme, defineTool, executeDefinedTool, findTransformerPattern, generateChatId, generateCommandId, generateMessageId, matchesMimeType, processAttachments, useAI, useAIContext, useAIWorkflow, useAgentSelection, useChatManagement, useCommandManagement, useDropdownState, useFeedback, useFileUpload, useMessageQueue, usePromptState, useServerEvents, useSlashCommands, useStableTools, useStrings, useTheme, useToolSystem, validateCommandName };