Skip to content

Commit d9b3787

Browse files
committed
feat: render tool calls
1 parent 0183b9f commit d9b3787

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed
Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,50 @@
11
import { ActivityIndicator, Text, View } from "react-native";
2+
import type { AssistantToolCall } from "../types/max";
3+
import { ToolCallMessage } from "./ToolCallMessage";
24

35
interface AIMessageProps {
46
content: string;
57
isLoading?: boolean;
68
thinkingText?: string;
9+
toolCalls?: AssistantToolCall[];
710
}
811

912
export function AIMessage({
1013
content,
1114
isLoading,
1215
thinkingText,
16+
toolCalls,
1317
}: AIMessageProps) {
1418
return (
15-
<View className="items-start px-4 py-2">
16-
<View className="max-w-[85%] rounded-2xl rounded-bl-md bg-dark-surface px-4 py-3">
17-
{isLoading && !content ? (
18-
<View className="flex-row items-center gap-2">
19-
<ActivityIndicator size="small" color="#a3a3a3" />
20-
<Text className="text-base text-dark-text-muted italic">
21-
{thinkingText || "Thinking..."}
19+
<View className="items-start py-2">
20+
{toolCalls && toolCalls.length > 0 && (
21+
<View className="mb-1 w-full">
22+
{toolCalls.map((tc) => (
23+
<ToolCallMessage
24+
key={tc.id}
25+
toolName={tc.name}
26+
status="completed"
27+
args={tc.args}
28+
/>
29+
))}
30+
</View>
31+
)}
32+
{(content || isLoading) && (
33+
<View className="mx-4 max-w-[85%] rounded-2xl rounded-bl-md bg-dark-surface px-4 py-3">
34+
{isLoading && !content ? (
35+
<View className="flex-row items-center gap-2">
36+
<ActivityIndicator size="small" color="#a3a3a3" />
37+
<Text className="text-base text-dark-text-muted italic">
38+
{thinkingText || "Thinking..."}
39+
</Text>
40+
</View>
41+
) : (
42+
<Text className="text-base text-dark-text leading-6">
43+
{content}
2244
</Text>
23-
</View>
24-
) : (
25-
<Text className="text-base text-dark-text leading-6">{content}</Text>
26-
)}
27-
</View>
45+
)}
46+
</View>
47+
)}
2848
</View>
2949
);
3050
}

apps/mobile/src/components/MessagesList.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ import {
1212
isArtifactMessage,
1313
isAssistantMessage,
1414
isHumanMessage,
15-
isToolCallMessage,
1615
isVisualizationArtifactContent,
1716
type ThreadMessage,
1817
} from "../types/max";
1918
import { AIMessage } from "./AIMessage";
2019
import { FailureMessage } from "./FailureMessage";
2120
import { HumanMessage } from "./HumanMessage";
22-
import { ToolCallMessage } from "./ToolCallMessage";
2321
import { VisualizationArtifact } from "./VisualizationArtifact";
2422

2523
interface MessagesListProps {
@@ -33,23 +31,13 @@ function MessageItem({ item }: { item: ThreadMessage }) {
3331
return <HumanMessage content={item.content} />;
3432
}
3533

36-
if (isToolCallMessage(item)) {
37-
return (
38-
<ToolCallMessage
39-
toolName={item.toolName}
40-
status={item.status}
41-
args={item.args}
42-
result={item.result}
43-
/>
44-
);
45-
}
46-
4734
if (isAssistantMessage(item)) {
4835
return (
4936
<AIMessage
5037
content={item.content}
5138
isLoading={item.status === "loading"}
5239
thinkingText={item.meta?.thinking?.[0]?.thinking}
40+
toolCalls={item.tool_calls}
5341
/>
5442
);
5543
}

apps/mobile/src/types/max.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ export interface HumanMessage extends BaseAssistantMessage {
4747
content: string;
4848
}
4949

50+
export interface AssistantToolCall {
51+
id: string;
52+
name: string;
53+
args: Record<string, unknown>;
54+
type: "tool_call";
55+
}
56+
5057
export interface AssistantMessage extends BaseAssistantMessage {
5158
type: AssistantMessageType.Assistant;
5259
content: string;
60+
tool_calls?: AssistantToolCall[];
5361
meta?: {
5462
thinking?: Array<{ type: string; thinking: string }>;
5563
};

0 commit comments

Comments
 (0)