Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/components/BitteAiChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const BitteAiChat = ({
historyApiUrl,
agentId,
options,
customToolComponents,
}: BitteAiChatProps) => {
const [loadedData, setLoadedData] = useState({
agentIdLoaded: "",
Expand Down Expand Up @@ -62,6 +63,7 @@ export const BitteAiChat = ({
agentId={agentId ?? agentIdLoaded}
messages={uiMessages}
options={optionsProps}
customToolComponents={customToolComponents}
/>
</AccountProvider>
);
Expand Down
2 changes: 2 additions & 0 deletions src/components/chat/ChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ChatContent = ({
apiKey,
options,
messages: initialMessages,
customToolComponents,
}: BitteAiChatProps) => {
const chatId = useRef(options?.chatId || generateId()).current;
const [isAtBottom, setIsAtBottom] = useState(true);
Expand Down Expand Up @@ -269,6 +270,7 @@ export const ChatContent = ({
customMessageContainer={
options?.customComponents?.messageContainer
}
customToolComponents={customToolComponents}
/>
);
})}
Expand Down
14 changes: 14 additions & 0 deletions src/components/chat/MessageGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ interface MessageGroupProps {
toolCallId: string;
result: BitteToolResult;
}) => void;
customToolComponents?: {
toolName: string;
component: React.ComponentType<{ data: any }>; // Changed from JSX.Element to ComponentType
}[];
customMessageContainer?: React.ComponentType<MessageGroupComponentProps>;
customTxContainer?: React.ComponentType<TransactionContainerProps>;
customApproveTxButton?: React.ComponentType<TransactionButtonProps>;
Expand All @@ -68,6 +72,7 @@ export const MessageGroup = ({
customTxContainer,
customApproveTxButton,
customDeclineTxButton,
customToolComponents,
}: MessageGroupProps) => {
// State to track agentId for each message
const [messagesWithAgentId, setMessagesWithAgentId] = useState<
Expand Down Expand Up @@ -234,6 +239,15 @@ export const MessageGroup = ({
/>
);
}
// Check for custom tool component first
const customTool = customToolComponents?.find(
(tool) => tool.toolName === toolName
);
if (customTool) {
const CustomComponent = customTool.component;
return <CustomComponent data={result.data} />;
}

switch (toolName) {
case BittePrimitiveName.GENERATE_IMAGE: {
return (
Expand Down
4 changes: 4 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ export interface BitteAiChatProps {
messages?: Message[];
wallet?: WalletOptions;
options?: BitteAiChatOptions;
customToolComponents: {
toolName: string;
component: React.ComponentType<{ data: any }>;
}[];
}

/**
Expand Down