Skip to content

Commit 7a38a09

Browse files
committed
feat: add tool response bottom sheet
1 parent ef34ee0 commit 7a38a09

4 files changed

Lines changed: 92 additions & 0 deletions

File tree

i18n/mobile/chat/en.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@
156156
},
157157
"MESSAGE_FOLLOW_UPS": {
158158
"TEXT_FOLLOW_UP": "Follow up"
159+
},
160+
"AI_MESSAGE": {
161+
"TOOL_OUTPUT_SHEET": {
162+
"TEXT_VIEW_RESULT_PREFIX": "View result from",
163+
"TEXT_INPUT": "Input",
164+
"TEXT_OUTPUT": "Output"
165+
}
159166
}
160167
}
161168
}

libs/mobile/chat/features/chat/src/lib/components/ai-message/component.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { formatDateTime } from '@open-webui-react-native/shared/utils/date';
2020
import { parseResponseMessageContent } from '../../utils';
2121
import { ChatImagesGroup } from '../images';
2222
import { SkeletonMessage } from '../skeleton-message';
23+
import { ToolOutputBottomSheet } from '../tool-output-bottom-sheet';
2324

2425
interface ChatAiMessageProps {
2526
message: Message;
@@ -87,6 +88,18 @@ export function ChatAiMessage({
8788
{socketStatusData && <AppText className='mt-4 text-text-secondary'>{socketStatusData.description}</AppText>}
8889
{text ? (
8990
<Fragment>
91+
{toolsData.length > 0 && (
92+
<View className='mt-8 gap-8'>
93+
{toolsData.map((tool, index) => (
94+
<ToolOutputBottomSheet
95+
key={tool.id ?? `${tool.toolName}-${index}`}
96+
toolName={tool.toolName}
97+
input={tool.input}
98+
output={tool.output}
99+
/>
100+
))}
101+
</View>
102+
)}
90103
<ChatImagesGroup
91104
images={attachedImages}
92105
onImagePress={handleImagePress}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { BottomSheetModal } from '@gorhom/bottom-sheet';
2+
import { useTranslation } from '@ronas-it/react-native-common-modules/i18n';
3+
import { ReactElement, ReactNode, useRef } from 'react';
4+
import {
5+
AppBottomSheet,
6+
AppBottomSheetKeyboardAwareScrollView,
7+
AppPressable,
8+
AppSafeAreaView,
9+
AppText,
10+
Icon,
11+
SheetHeader,
12+
View,
13+
} from '@open-webui-react-native/mobile/shared/ui/ui-kit';
14+
15+
export interface ToolOutputBottomSheetProps {
16+
toolName: string;
17+
input: string;
18+
output: string;
19+
}
20+
21+
export function ToolOutputBottomSheet({ toolName, input, output }: ToolOutputBottomSheetProps): ReactElement {
22+
const translate = useTranslation('CHAT.AI_MESSAGE.TOOL_OUTPUT_SHEET');
23+
const sheetRef = useRef<BottomSheetModal>(null);
24+
25+
const renderTrigger = ({ onPress }: { onPress: () => void }): ReactNode => (
26+
<AppPressable
27+
onPress={onPress}
28+
className='flex-row items-center gap-8 rounded-xl bg-background-secondary px-12 py-10 active:opacity-70'>
29+
<Icon name='tick' className='size-20 shrink-0 color-emerald-500' />
30+
<View className='min-w-0 flex-1 flex-row flex-wrap items-center'>
31+
<AppText className='text-sm-sm sm:text-sm text-text-secondary'>{translate('TEXT_VIEW_RESULT_PREFIX')} </AppText>
32+
<AppText className='text-sm-sm sm:text-sm font-mono font-semibold text-text-primary'>{toolName}</AppText>
33+
</View>
34+
<Icon name='chevronDown' className='size-16 shrink-0 color-text-secondary' />
35+
</AppPressable>
36+
);
37+
38+
return (
39+
<AppBottomSheet
40+
ref={sheetRef}
41+
isModal={true}
42+
isScrollable={true}
43+
snapPoints={['100%']}
44+
className='px-0'
45+
renderTrigger={renderTrigger}
46+
content={
47+
<View className='flex-1 bg-background-primary'>
48+
<SheetHeader title={toolName} onGoBack={() => sheetRef.current?.close()} />
49+
<AppBottomSheetKeyboardAwareScrollView
50+
className='flex-1'
51+
contentContainerClassName='px-content-offset pb-safe pt-8 android:pb-24'>
52+
<AppSafeAreaView edges={['bottom']}>
53+
<AppText className='mb-8 text-xs font-medium uppercase tracking-wide text-text-secondary'>
54+
{translate('TEXT_INPUT')}
55+
</AppText>
56+
<AppText selectable className='mb-16 text-sm-sm sm:text-sm font-mono text-text-primary'>
57+
{input}
58+
</AppText>
59+
<AppText className='mb-8 text-xs font-medium uppercase tracking-wide text-text-secondary'>
60+
{translate('TEXT_OUTPUT')}
61+
</AppText>
62+
<AppText selectable className='text-sm-sm sm:text-sm font-mono text-text-primary'>
63+
{output}
64+
</AppText>
65+
</AppSafeAreaView>
66+
</AppBottomSheetKeyboardAwareScrollView>
67+
</View>
68+
}
69+
/>
70+
);
71+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './component';

0 commit comments

Comments
 (0)