Skip to content

Commit 319474f

Browse files
refactor: address code review feedback — remove redundant type check, extract output formatter
Agent-Logs-Url: https://github.com/objectstack-ai/framework/sessions/8a978a0a-5a20-45f0-b841-51f0a8857945 Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
1 parent 61cdd27 commit 319474f

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

apps/studio/src/components/AiChatPanel.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function formatToolArgs(input: unknown): string {
4848
.slice(0, 4)
4949
.map(([k, v]) => {
5050
const val = typeof v === 'string' ? v : JSON.stringify(v);
51-
const display = typeof val === 'string' && val.length > 30 ? val.slice(0, 30) + '…' : val;
51+
const display = val.length > 30 ? val.slice(0, 30) + '…' : val;
5252
return `${k}: ${display}`;
5353
})
5454
.join(', ');
@@ -61,6 +61,14 @@ function isToolPart(part: UIMessage['parts'][number]): part is Extract<UIMessage
6161
return part.type === 'dynamic-tool';
6262
}
6363

64+
/**
65+
* Format tool output for display, truncating to a max length.
66+
*/
67+
function formatToolOutput(output: unknown, maxLen = 80): string {
68+
const raw = typeof output === 'string' ? output : JSON.stringify(output);
69+
return raw.length > maxLen ? raw.slice(0, maxLen) + '…' : raw;
70+
}
71+
6472
// ── Tool Invocation State Labels ────────────────────────────────────
6573

6674
interface ToolInvocationDisplayProps {
@@ -144,9 +152,7 @@ function ToolInvocationDisplay({ part, onApprove, onDeny }: ToolInvocationDispla
144152
<div className="min-w-0">
145153
<span className="font-medium">{toolLabel}</span>
146154
<p className="mt-0.5 text-muted-foreground truncate">
147-
{typeof part.output === 'string'
148-
? part.output.length > 80 ? part.output.slice(0, 80) + '…' : part.output
149-
: JSON.stringify(part.output).slice(0, 80)}
155+
{formatToolOutput(part.output)}
150156
</p>
151157
</div>
152158
</div>

0 commit comments

Comments
 (0)