|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { |
| 4 | + MessageInputTextarea, |
| 5 | + type MessageInputTextareaProps, |
| 6 | + type ResourceProvider, |
| 7 | +} from "@/components/ui/tambo/message-input"; |
| 8 | +import { useInteractablesResourceProvider } from "@/hooks/use-interactables-resource-provider"; |
| 9 | +import * as React from "react"; |
| 10 | + |
| 11 | +/** |
| 12 | + * MessageInputTextarea wrapper that automatically integrates with Tambo interactables. |
| 13 | + * |
| 14 | + * This is the apps/web-specific version that combines the generic MessageInputTextarea |
| 15 | + * with the interactables system. It's a drop-in replacement for MessageInputTextarea |
| 16 | + * that adds automatic @ mention support for registered components. |
| 17 | + * |
| 18 | + * **For apps/web developers:** Use this component instead of MessageInputTextarea |
| 19 | + * when you want automatic interactables integration. |
| 20 | + * |
| 21 | + * @example |
| 22 | + * ```tsx |
| 23 | + * import { MessageInput } from "@/components/ui/tambo/message-input"; |
| 24 | + * import { MessageInputTextareaWithInteractables } from "@/components/ui/tambo/message-input-with-interactables"; |
| 25 | + * |
| 26 | + * <MessageInput> |
| 27 | + * <MessageInputTextareaWithInteractables /> |
| 28 | + * <MessageInput.Toolbar> |
| 29 | + * <MessageInput.SubmitButton /> |
| 30 | + * </MessageInput.Toolbar> |
| 31 | + * </MessageInput> |
| 32 | + * ``` |
| 33 | + * |
| 34 | + * @example With external resource provider |
| 35 | + * ```tsx |
| 36 | + * const mcpResourceProvider: ResourceProvider = { |
| 37 | + * search: async (query) => { |
| 38 | + * // Fetch MCP resources... |
| 39 | + * return mcpResources; |
| 40 | + * } |
| 41 | + * }; |
| 42 | + * |
| 43 | + * <MessageInput> |
| 44 | + * <MessageInputTextareaWithInteractables |
| 45 | + * resourceProvider={mcpResourceProvider} |
| 46 | + * /> |
| 47 | + * </MessageInput> |
| 48 | + * ``` |
| 49 | + */ |
| 50 | +export const MessageInputTextareaWithInteractables = ({ |
| 51 | + resourceProvider: externalResourceProvider, |
| 52 | + ...props |
| 53 | +}: Omit<MessageInputTextareaProps, "onResourceSelect"> & { |
| 54 | + /** Optional external resource provider to merge with interactables */ |
| 55 | + resourceProvider?: ResourceProvider; |
| 56 | +}) => { |
| 57 | + const { resourceProvider, onResourceSelect } = |
| 58 | + useInteractablesResourceProvider(externalResourceProvider); |
| 59 | + |
| 60 | + return ( |
| 61 | + <MessageInputTextarea |
| 62 | + resourceProvider={resourceProvider} |
| 63 | + onResourceSelect={onResourceSelect} |
| 64 | + {...props} |
| 65 | + /> |
| 66 | + ); |
| 67 | +}; |
| 68 | + |
| 69 | +MessageInputTextareaWithInteractables.displayName = |
| 70 | + "MessageInputTextareaWithInteractables"; |
0 commit comments