Skip to content

Commit f0949d5

Browse files
committed
feat(ts#react-website#agui): render tool calls in all themed chat variants
Register WildcardToolCallRender on CopilotKitProvider so useRenderToolCall returns a renderer. Add CopilotChatToolCallsView to Cloudscape and forward messages prop to both Cloudscape and Shadcn assistant message components so tool call status resolves correctly.
1 parent b0ad58d commit f0949d5

4 files changed

Lines changed: 40 additions & 9 deletions

File tree

packages/nx-plugin/src/py/strands-agent/react-connection/__snapshots__/generator.spec.ts.snap

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,16 @@ export function Main() {
223223
224224
exports[`py strands agent react connection generator - AG-UI protocol > should generate a shared AguiProvider and a per-agent hook for AG-UI agents > AguiProvider.tsx 1`] = `
225225
"import { useAguiTestAgent } from '../hooks/useAguiTestAgent';
226-
import { CopilotKitProvider } from '@copilotkit/react-core/v2';
226+
import {
227+
CopilotKitProvider,
228+
WildcardToolCallRender,
229+
} from '@copilotkit/react-core/v2';
227230
import '@copilotkit/react-core/v2/styles.css';
228231
import { type FC, type PropsWithChildren, useMemo } from 'react';
229232
import type { AbstractAgent } from '@ag-ui/client';
230233
234+
const renderToolCalls = [WildcardToolCallRender];
235+
231236
export const AguiProvider: FC<PropsWithChildren> = ({ children }) => {
232237
const testAgentAgents = useAguiTestAgent();
233238
const selfManagedAgents = useMemo<Record<string, AbstractAgent>>(
@@ -236,7 +241,10 @@ export const AguiProvider: FC<PropsWithChildren> = ({ children }) => {
236241
);
237242
238243
return (
239-
<CopilotKitProvider selfManagedAgents={selfManagedAgents}>
244+
<CopilotKitProvider
245+
selfManagedAgents={selfManagedAgents}
246+
renderToolCalls={renderToolCalls}
247+
>
240248
{children}
241249
</CopilotKitProvider>
242250
);
@@ -330,11 +338,16 @@ export const useAguiTestAgent = (): Record<string, AbstractAgent> => {
330338
exports[`py strands agent react connection generator - AG-UI protocol > should register multiple AG-UI agents in the shared AguiProvider > AguiProvider-multi-agent.tsx 1`] = `
331339
"import { useAguiResearchAgent } from '../hooks/useAguiResearchAgent';
332340
import { useAguiTestAgent } from '../hooks/useAguiTestAgent';
333-
import { CopilotKitProvider } from '@copilotkit/react-core/v2';
341+
import {
342+
CopilotKitProvider,
343+
WildcardToolCallRender,
344+
} from '@copilotkit/react-core/v2';
334345
import '@copilotkit/react-core/v2/styles.css';
335346
import { type FC, type PropsWithChildren, useMemo } from 'react';
336347
import type { AbstractAgent } from '@ag-ui/client';
337348
349+
const renderToolCalls = [WildcardToolCallRender];
350+
338351
export const AguiProvider: FC<PropsWithChildren> = ({ children }) => {
339352
const testAgentAgents = useAguiTestAgent();
340353
const researchAgentAgents = useAguiResearchAgent();
@@ -344,7 +357,10 @@ export const AguiProvider: FC<PropsWithChildren> = ({ children }) => {
344357
);
345358
346359
return (
347-
<CopilotKitProvider selfManagedAgents={selfManagedAgents}>
360+
<CopilotKitProvider
361+
selfManagedAgents={selfManagedAgents}
362+
renderToolCalls={renderToolCalls}
363+
>
348364
{children}
349365
</CopilotKitProvider>
350366
);

packages/nx-plugin/src/ts/react-website/agui/files/cloudscape/src/components/copilot/CloudscapeAssistantMessage.tsx.template

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import type { FC } from 'react';
2-
import { CopilotChatAssistantMessage } from '@copilotkit/react-core/v2';
2+
import {
3+
CopilotChatAssistantMessage,
4+
CopilotChatToolCallsView,
5+
} from '@copilotkit/react-core/v2';
36
import type { CopilotChatAssistantMessageProps } from '@copilotkit/react-core/v2';
47
import ChatBubble from '@cloudscape-design/chat-components/chat-bubble';
58
import Avatar from '@cloudscape-design/chat-components/avatar';
@@ -18,7 +21,7 @@ import StatusIndicator from '@cloudscape-design/components/status-indicator';
1821
*/
1922
export const CloudscapeAssistantMessage: FC<
2023
CopilotChatAssistantMessageProps
21-
> = ({ message }) => {
24+
> = ({ message, messages }) => {
2225
const handleAction = (id: string) => {
2326
if (!message) return;
2427
if (id === 'copy' && typeof message.content === 'string') {
@@ -62,6 +65,9 @@ export const CloudscapeAssistantMessage: FC<
6265
<CopilotChatAssistantMessage.MarkdownRenderer
6366
content={message.content ?? ''}
6467
/>
68+
{message.toolCalls && message.toolCalls.length > 0 && (
69+
<CopilotChatToolCallsView message={message} messages={messages} />
70+
)}
6571
</ChatBubble>
6672
);
6773
};

packages/nx-plugin/src/ts/react-website/agui/files/common/src/components/AguiProvider.tsx.template

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1-
import { CopilotKitProvider } from '@copilotkit/react-core/v2';
1+
import {
2+
CopilotKitProvider,
3+
WildcardToolCallRender,
4+
} from '@copilotkit/react-core/v2';
25
import '@copilotkit/react-core/v2/styles.css';
36
import { type FC, type PropsWithChildren, useMemo } from 'react';
47
import type { AbstractAgent } from '@ag-ui/client';
58

9+
const renderToolCalls = [WildcardToolCallRender];
10+
611
export const AguiProvider: FC<PropsWithChildren> = ({ children }) => {
712
const selfManagedAgents = useMemo<Record<string, AbstractAgent>>(
813
() => ({}),
914
[],
1015
);
1116

1217
return (
13-
<CopilotKitProvider selfManagedAgents={selfManagedAgents}>
18+
<CopilotKitProvider
19+
selfManagedAgents={selfManagedAgents}
20+
renderToolCalls={renderToolCalls}
21+
>
1422
{children}
1523
</CopilotKitProvider>
1624
);

packages/nx-plugin/src/ts/react-website/agui/files/shadcn/src/components/copilot/ShadcnAssistantMessage.tsx.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { cn } from '<%= scopeAlias %>common-shadcn/lib/utils';
2727
*/
2828
export const ShadcnAssistantMessage: FC<CopilotChatAssistantMessageProps> = ({
2929
message,
30+
messages,
3031
}) => {
3132
const hasContent = !!(message.content && message.content.trim().length > 0);
3233

@@ -55,7 +56,7 @@ export const ShadcnAssistantMessage: FC<CopilotChatAssistantMessageProps> = ({
5556
/>
5657
</div>
5758
{message.toolCalls && message.toolCalls.length > 0 && (
58-
<CopilotChatToolCallsView message={message} />
59+
<CopilotChatToolCallsView message={message} messages={messages} />
5960
)}
6061
{hasContent && (
6162
<div className="text-muted-foreground flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100">

0 commit comments

Comments
 (0)