Skip to content

Commit e2ca3a3

Browse files
Backport: chore(examples/next-openai): ai-elements, update web search example (#9425)
This is an automated backport of #9423 to the release-v5.0 branch. --------- Co-authored-by: Lars Grammel <lars.grammel@gmail.com>
1 parent 39c9b5e commit e2ca3a3

File tree

61 files changed

+2369
-141
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2369
-141
lines changed

examples/next-openai/agent/openai-web-search-agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { openai } from '@ai-sdk/openai';
21
import {
32
Experimental_Agent as Agent,
43
Experimental_InferAgentUIMessage as InferAgentUIMessage,
54
} from 'ai';
5+
import { openai } from '@ai-sdk/openai';
66

77
export const openaiWebSearchAgent = new Agent({
88
model: openai('gpt-5-mini'),

examples/next-openai/app/anthropic-web-fetch/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

3-
import AnthropicWebFetchView from '@/component/anthropic-web-fetch-view';
4-
import ChatInput from '@/component/chat-input';
3+
import ChatInput from '@/components/chat-input';
4+
import AnthropicWebFetchView from '@/components/tool/anthropic-web-fetch-view';
55
import { useChat } from '@ai-sdk/react';
66
import { DefaultChatTransport } from 'ai';
77
import { AnthropicWebFetchMessage } from '../api/anthropic-web-fetch/route';

examples/next-openai/app/anthropic-web-search/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use client';
22

3+
import { AnthropicWebSearchMessage } from '@/app/api/anthropic-web-search/route';
4+
import ChatInput from '@/components/chat-input';
5+
import AnthropicWebSearchView from '@/components/tool/anthropic-web-search-view';
36
import { useChat } from '@ai-sdk/react';
47
import { DefaultChatTransport } from 'ai';
5-
import ChatInput from '@/component/chat-input';
6-
import { AnthropicWebSearchMessage } from '@/app/api/anthropic-web-search/route';
7-
import AnthropicWebSearchView from '@/component/anthropic-web-search-view';
88

99
export default function TestAnthropicWebSearch() {
1010
const { status, sendMessage, messages } = useChat<AnthropicWebSearchMessage>({

examples/next-openai/app/bedrock/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
'use client';
22

3+
import ChatInput from '@/components/chat-input';
34
import { useChat } from '@ai-sdk/react';
45
import { DefaultChatTransport } from 'ai';
5-
import ChatInput from '@/component/chat-input';
66

77
export default function Chat() {
88
const { error, status, sendMessage, messages, regenerate, stop } = useChat({
99
transport: new DefaultChatTransport({ api: '/api/bedrock' }),
1010
});
1111

1212
return (
13-
<div className="flex flex-col w-full max-w-md py-24 mx-auto stretch">
13+
<div className="flex flex-col py-24 mx-auto w-full max-w-md stretch">
1414
{messages.map(m => (
1515
<div key={m.id} className="whitespace-pre-wrap">
1616
{m.role === 'user' ? 'User: ' : 'AI: '}
@@ -27,7 +27,7 @@ export default function Chat() {
2727
{status === 'submitted' && <div>Loading...</div>}
2828
<button
2929
type="button"
30-
className="px-4 py-2 mt-4 text-blue-500 border border-blue-500 rounded-md"
30+
className="px-4 py-2 mt-4 text-blue-500 rounded-md border border-blue-500"
3131
onClick={stop}
3232
>
3333
Stop
@@ -40,7 +40,7 @@ export default function Chat() {
4040
<div className="text-red-500">An error occurred.</div>
4141
<button
4242
type="button"
43-
className="px-4 py-2 mt-4 text-blue-500 border border-blue-500 rounded-md"
43+
className="px-4 py-2 mt-4 text-blue-500 rounded-md border border-blue-500"
4444
onClick={() => regenerate()}
4545
>
4646
Retry
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
'use client';
2+
3+
import { OpenAIWebSearchMessage } from '@/agent/openai-web-search-agent';
4+
import { Response } from '@/components/ai-elements/response';
5+
import ChatInput from '@/components/chat-input';
6+
import { ReasoningView } from '@/components/reasoning-view';
7+
import SourcesView from '@/components/sources-view';
8+
import OpenAIWebSearchView from '@/components/tool/openai-web-search-view';
9+
import { useChat } from '@ai-sdk/react';
10+
import { DefaultChatTransport } from 'ai';
11+
12+
export default function TestOpenAIWebSearch() {
13+
const { error, status, sendMessage, messages, regenerate } =
14+
useChat<OpenAIWebSearchMessage>({
15+
transport: new DefaultChatTransport({
16+
api: '/api/chat-openai-web-search',
17+
}),
18+
});
19+
20+
return (
21+
<div className="flex flex-col py-24 mx-auto w-full max-w-md stretch">
22+
<h1 className="mb-4 text-xl font-bold">OpenAI Web Search Test</h1>
23+
24+
{messages.map(message => (
25+
<div key={message.id} className="whitespace-pre-wrap">
26+
{message.role === 'user' ? 'User: ' : 'AI: '}
27+
{message.parts.map((part, index) => {
28+
switch (part.type) {
29+
case 'text': {
30+
return <Response key={index}>{part.text}</Response>;
31+
}
32+
case 'reasoning': {
33+
return <ReasoningView part={part} key={index} />;
34+
}
35+
case 'tool-web_search': {
36+
return <OpenAIWebSearchView invocation={part} key={index} />;
37+
}
38+
}
39+
})}
40+
41+
<SourcesView
42+
sources={message.parts.filter(part => part.type === 'source-url')}
43+
/>
44+
</div>
45+
))}
46+
47+
{error && (
48+
<div className="mt-4">
49+
<div className="text-red-500">An error occurred.</div>
50+
<button
51+
type="button"
52+
className="px-4 py-2 mt-4 text-blue-500 rounded-md border border-blue-500"
53+
onClick={() => regenerate()}
54+
>
55+
Retry
56+
</button>
57+
</div>
58+
)}
59+
60+
<ChatInput status={status} onSubmit={text => sendMessage({ text })} />
61+
</div>
62+
);
63+
}

examples/next-openai/app/dynamic-tools/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import ChatInput from '@/component/chat-input';
3+
import ChatInput from '@/components/chat-input';
44
import { useChat } from '@ai-sdk/react';
55
import { DefaultChatTransport } from 'ai';
66
import { ToolsMessage } from '../api/dynamic-tools/route';
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
11
@tailwind base;
22
@tailwind components;
33
@tailwind utilities;
4+
5+
@source "../node_modules/streamdown/dist/index.js";
6+
7+
@layer base {
8+
:root {
9+
--background: 0 0% 100%;
10+
--foreground: 0 0% 3.9%;
11+
--card: 0 0% 100%;
12+
--card-foreground: 0 0% 3.9%;
13+
--popover: 0 0% 100%;
14+
--popover-foreground: 0 0% 3.9%;
15+
--primary: 0 0% 9%;
16+
--primary-foreground: 0 0% 98%;
17+
--secondary: 0 0% 96.1%;
18+
--secondary-foreground: 0 0% 9%;
19+
--muted: 0 0% 96.1%;
20+
--muted-foreground: 0 0% 45.1%;
21+
--accent: 0 0% 96.1%;
22+
--accent-foreground: 0 0% 9%;
23+
--destructive: 0 84.2% 60.2%;
24+
--destructive-foreground: 0 0% 98%;
25+
--border: 0 0% 89.8%;
26+
--input: 0 0% 89.8%;
27+
--ring: 0 0% 3.9%;
28+
--chart-1: 12 76% 61%;
29+
--chart-2: 173 58% 39%;
30+
--chart-3: 197 37% 24%;
31+
--chart-4: 43 74% 66%;
32+
--chart-5: 27 87% 67%;
33+
--radius: 0.5rem;
34+
}
35+
.dark {
36+
--background: 0 0% 3.9%;
37+
--foreground: 0 0% 98%;
38+
--card: 0 0% 3.9%;
39+
--card-foreground: 0 0% 98%;
40+
--popover: 0 0% 3.9%;
41+
--popover-foreground: 0 0% 98%;
42+
--primary: 0 0% 98%;
43+
--primary-foreground: 0 0% 9%;
44+
--secondary: 0 0% 14.9%;
45+
--secondary-foreground: 0 0% 98%;
46+
--muted: 0 0% 14.9%;
47+
--muted-foreground: 0 0% 63.9%;
48+
--accent: 0 0% 14.9%;
49+
--accent-foreground: 0 0% 98%;
50+
--destructive: 0 62.8% 30.6%;
51+
--destructive-foreground: 0 0% 98%;
52+
--border: 0 0% 14.9%;
53+
--input: 0 0% 14.9%;
54+
--ring: 0 0% 83.1%;
55+
--chart-1: 220 70% 50%;
56+
--chart-2: 160 60% 45%;
57+
--chart-3: 30 80% 55%;
58+
--chart-4: 280 65% 60%;
59+
--chart-5: 340 75% 55%;
60+
}
61+
}
62+
63+
@layer base {
64+
* {
65+
@apply border-border;
66+
}
67+
body {
68+
@apply bg-background text-foreground;
69+
}
70+
}

examples/next-openai/app/mcp/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import ChatInput from '@/component/chat-input';
3+
import ChatInput from '@/components/chat-input';
44
import { useChat } from '@ai-sdk/react';
55
import { DefaultChatTransport } from 'ai';
66

examples/next-openai/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import { useChat } from '@ai-sdk/react';
4-
import ChatInput from '@/component/chat-input';
4+
import ChatInput from '@/components/chat-input';
55

66
export default function Chat() {
77
const { error, status, sendMessage, messages, regenerate, stop } = useChat();

examples/next-openai/app/test-cohere/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
import { useChat } from '@ai-sdk/react';
44
import { DefaultChatTransport } from 'ai';
5-
import ChatInput from '@/component/chat-input';
5+
import ChatInput from '@/components/chat-input';
66

77
export default function TestCohere() {
88
const { error, status, sendMessage, messages, regenerate, stop } = useChat({
99
transport: new DefaultChatTransport({ api: '/api/chat-cohere' }),
1010
});
1111

1212
return (
13-
<div className="flex flex-col w-full max-w-md py-24 mx-auto stretch">
13+
<div className="flex flex-col py-24 mx-auto w-full max-w-md stretch">
1414
<h1 className="mb-4 text-xl font-bold">
1515
Cohere Block-Based Streaming Test
1616
</h1>
@@ -31,7 +31,7 @@ export default function TestCohere() {
3131
{status === 'submitted' && <div>Loading...</div>}
3232
<button
3333
type="button"
34-
className="px-4 py-2 mt-4 text-blue-500 border border-blue-500 rounded-md"
34+
className="px-4 py-2 mt-4 text-blue-500 rounded-md border border-blue-500"
3535
onClick={stop}
3636
>
3737
Stop
@@ -44,7 +44,7 @@ export default function TestCohere() {
4444
<div className="text-red-500">An error occurred.</div>
4545
<button
4646
type="button"
47-
className="px-4 py-2 mt-4 text-blue-500 border border-blue-500 rounded-md"
47+
className="px-4 py-2 mt-4 text-blue-500 rounded-md border border-blue-500"
4848
onClick={() => regenerate()}
4949
>
5050
Retry

0 commit comments

Comments
 (0)