Skip to content

Commit 48436bb

Browse files
committed
feat: hide tools response input block if it is empty
1 parent 7a38a09 commit 48436bb

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

libs/mobile/chat/features/chat/src/lib/components/tool-output-bottom-sheet/component.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BottomSheetModal } from '@gorhom/bottom-sheet';
22
import { useTranslation } from '@ronas-it/react-native-common-modules/i18n';
3-
import { ReactElement, ReactNode, useRef } from 'react';
3+
import { Fragment, ReactElement, ReactNode, useRef } from 'react';
44
import {
55
AppBottomSheet,
66
AppBottomSheetKeyboardAwareScrollView,
@@ -14,7 +14,7 @@ import {
1414

1515
export interface ToolOutputBottomSheetProps {
1616
toolName: string;
17-
input: string;
17+
input?: string;
1818
output: string;
1919
}
2020

@@ -50,12 +50,16 @@ export function ToolOutputBottomSheet({ toolName, input, output }: ToolOutputBot
5050
className='flex-1'
5151
contentContainerClassName='px-content-offset pb-safe pt-8 android:pb-24'>
5252
<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>
53+
{!!input && (
54+
<Fragment>
55+
<AppText className='mb-8 text-xs font-medium uppercase tracking-wide text-text-secondary'>
56+
{translate('TEXT_INPUT')}
57+
</AppText>
58+
<AppText selectable className='mb-16 text-sm-sm sm:text-sm font-mono text-text-primary'>
59+
{input}
60+
</AppText>
61+
</Fragment>
62+
)}
5963
<AppText className='mb-8 text-xs font-medium uppercase tracking-wide text-text-secondary'>
6064
{translate('TEXT_OUTPUT')}
6165
</AppText>

libs/mobile/chat/features/chat/src/lib/utils/parse-response-message-content.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { decode } from 'html-entities';
2+
import { isEmpty } from 'lodash-es';
23

34
type PayloadContentType = 'json' | 'text';
45

56
export type ToolData = {
67
id?: string;
78
toolName: string;
8-
input: string;
9+
input: string | undefined;
910
output: string;
1011
outputContentType: PayloadContentType;
1112
};
@@ -199,6 +200,9 @@ const tryParseLeadingToolCallsDetails = (content: string): { tool: ToolData; res
199200

200201
const inputPayload = classifyAndNormalizePayload(argsRaw);
201202
const outputPayload = classifyAndNormalizePayload(resultRaw);
203+
const parsedArgs = parseJsonRecursive(decode(argsRaw).trim());
204+
const input =
205+
typeof parsedArgs === 'object' && parsedArgs !== null && isEmpty(parsedArgs) ? undefined : inputPayload.normalized;
202206

203207
const blockEnd = leadingWs.length + openEnd + closeMatch.index + closeMatch[0].length;
204208
const rest = content.slice(blockEnd).trimStart();
@@ -207,7 +211,7 @@ const tryParseLeadingToolCallsDetails = (content: string): { tool: ToolData; res
207211
tool: {
208212
id,
209213
toolName,
210-
input: inputPayload.normalized,
214+
input,
211215
output: normalizeToolResultText(outputPayload.normalized),
212216
outputContentType: outputPayload.contentType,
213217
},

0 commit comments

Comments
 (0)