@assistant-ui/mcp-docs-server 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/.docs/organized/code-examples/with-ai-sdk-v5.md +12 -12
  2. package/.docs/organized/code-examples/with-cloud.md +16 -24
  3. package/.docs/organized/code-examples/with-external-store.md +6 -6
  4. package/.docs/organized/code-examples/with-ffmpeg.md +18 -20
  5. package/.docs/organized/code-examples/with-langgraph.md +6 -8
  6. package/.docs/organized/code-examples/with-parent-id-grouping.md +6 -6
  7. package/.docs/organized/code-examples/with-react-hook-form.md +16 -20
  8. package/.docs/raw/docs/api-reference/overview.mdx +1 -4
  9. package/.docs/raw/docs/getting-started.mdx +33 -33
  10. package/.docs/raw/docs/guides/Attachments.mdx +1 -102
  11. package/.docs/raw/docs/guides/ToolUI.mdx +3 -3
  12. package/.docs/raw/docs/guides/Tools.mdx +101 -84
  13. package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +134 -55
  14. package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +182 -0
  15. package/.docs/raw/docs/runtimes/langgraph/index.mdx +0 -1
  16. package/.docs/raw/docs/runtimes/langserve.mdx +9 -11
  17. package/package.json +6 -6
  18. package/.docs/organized/code-examples/local-ollama.md +0 -1135
  19. package/.docs/organized/code-examples/search-agent-for-e-commerce.md +0 -1721
  20. package/.docs/organized/code-examples/with-ai-sdk.md +0 -1082
  21. package/.docs/organized/code-examples/with-openai-assistants.md +0 -1175
  22. package/.docs/raw/docs/runtimes/ai-sdk/rsc.mdx +0 -226
  23. package/.docs/raw/docs/runtimes/ai-sdk/use-assistant-hook.mdx +0 -195
  24. package/.docs/raw/docs/runtimes/ai-sdk/use-chat-hook.mdx +0 -138
  25. package/.docs/raw/docs/runtimes/ai-sdk/use-chat-v5.mdx +0 -212
@@ -1,1082 +0,0 @@
1
- # Example: with-ai-sdk
2
-
3
- ## app/api/chat/route.ts
4
-
5
- ```typescript
6
- import { openai } from "@ai-sdk/openai";
7
- import { frontendTools } from "@assistant-ui/react-ai-sdk-v4";
8
- import { streamText } from "ai";
9
- import { z } from "zod";
10
-
11
- export const runtime = "edge";
12
- export const maxDuration = 30;
13
-
14
- export async function POST(req: Request) {
15
- const { messages, system, tools } = await req.json();
16
-
17
- const result = streamText({
18
- model: openai("gpt-4o"),
19
- messages,
20
- toolCallStreaming: true,
21
- system,
22
- tools: {
23
- ...frontendTools(tools),
24
- weather: {
25
- description: "Get weather information",
26
- parameters: z.object({
27
- location: z.string().describe("Location to get weather for"),
28
- }),
29
- execute: async ({ location }) => {
30
- return `The weather in ${location} is sunny.`;
31
- },
32
- },
33
- },
34
- });
35
-
36
- return result.toDataStreamResponse();
37
- }
38
-
39
- ```
40
-
41
- ## app/assistant.tsx
42
-
43
- ```tsx
44
- "use client";
45
-
46
- import { AssistantRuntimeProvider } from "@assistant-ui/react";
47
- import { Thread } from "@/components/assistant-ui/thread";
48
- import { useChatRuntime } from "@assistant-ui/react-ai-sdk-v4";
49
-
50
- export const Assistant = () => {
51
- const runtime = useChatRuntime({
52
- api: "/api/chat",
53
- });
54
-
55
- return (
56
- <AssistantRuntimeProvider runtime={runtime}>
57
- <div className="grid h-dvh gap-x-2 px-4 py-4">
58
- <Thread />
59
- </div>
60
- </AssistantRuntimeProvider>
61
- );
62
- };
63
-
64
- ```
65
-
66
- ## app/globals.css
67
-
68
- ```css
69
- @import "tailwindcss";
70
- @import "tw-animate-css";
71
-
72
- @custom-variant dark (&:is(.dark *));
73
-
74
- @theme inline {
75
- --color-background: var(--background);
76
- --color-foreground: var(--foreground);
77
- --font-sans: var(--font-geist-sans);
78
- --font-mono: var(--font-geist-mono);
79
- --color-sidebar-ring: var(--sidebar-ring);
80
- --color-sidebar-border: var(--sidebar-border);
81
- --color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
82
- --color-sidebar-accent: var(--sidebar-accent);
83
- --color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
84
- --color-sidebar-primary: var(--sidebar-primary);
85
- --color-sidebar-foreground: var(--sidebar-foreground);
86
- --color-sidebar: var(--sidebar);
87
- --color-chart-5: var(--chart-5);
88
- --color-chart-4: var(--chart-4);
89
- --color-chart-3: var(--chart-3);
90
- --color-chart-2: var(--chart-2);
91
- --color-chart-1: var(--chart-1);
92
- --color-ring: var(--ring);
93
- --color-input: var(--input);
94
- --color-border: var(--border);
95
- --color-destructive: var(--destructive);
96
- --color-accent-foreground: var(--accent-foreground);
97
- --color-accent: var(--accent);
98
- --color-muted-foreground: var(--muted-foreground);
99
- --color-muted: var(--muted);
100
- --color-secondary-foreground: var(--secondary-foreground);
101
- --color-secondary: var(--secondary);
102
- --color-primary-foreground: var(--primary-foreground);
103
- --color-primary: var(--primary);
104
- --color-popover-foreground: var(--popover-foreground);
105
- --color-popover: var(--popover);
106
- --color-card-foreground: var(--card-foreground);
107
- --color-card: var(--card);
108
- --radius-sm: calc(var(--radius) - 4px);
109
- --radius-md: calc(var(--radius) - 2px);
110
- --radius-lg: var(--radius);
111
- --radius-xl: calc(var(--radius) + 4px);
112
- }
113
-
114
- :root {
115
- --radius: 0.625rem;
116
- --background: oklch(1 0 0);
117
- --foreground: oklch(0.141 0.005 285.823);
118
- --card: oklch(1 0 0);
119
- --card-foreground: oklch(0.141 0.005 285.823);
120
- --popover: oklch(1 0 0);
121
- --popover-foreground: oklch(0.141 0.005 285.823);
122
- --primary: oklch(0.21 0.006 285.885);
123
- --primary-foreground: oklch(0.985 0 0);
124
- --secondary: oklch(0.967 0.001 286.375);
125
- --secondary-foreground: oklch(0.21 0.006 285.885);
126
- --muted: oklch(0.967 0.001 286.375);
127
- --muted-foreground: oklch(0.552 0.016 285.938);
128
- --accent: oklch(0.967 0.001 286.375);
129
- --accent-foreground: oklch(0.21 0.006 285.885);
130
- --destructive: oklch(0.577 0.245 27.325);
131
- --border: oklch(0.92 0.004 286.32);
132
- --input: oklch(0.92 0.004 286.32);
133
- --ring: oklch(0.705 0.015 286.067);
134
- --chart-1: oklch(0.646 0.222 41.116);
135
- --chart-2: oklch(0.6 0.118 184.704);
136
- --chart-3: oklch(0.398 0.07 227.392);
137
- --chart-4: oklch(0.828 0.189 84.429);
138
- --chart-5: oklch(0.769 0.188 70.08);
139
- --sidebar: oklch(0.985 0 0);
140
- --sidebar-foreground: oklch(0.141 0.005 285.823);
141
- --sidebar-primary: oklch(0.21 0.006 285.885);
142
- --sidebar-primary-foreground: oklch(0.985 0 0);
143
- --sidebar-accent: oklch(0.967 0.001 286.375);
144
- --sidebar-accent-foreground: oklch(0.21 0.006 285.885);
145
- --sidebar-border: oklch(0.92 0.004 286.32);
146
- --sidebar-ring: oklch(0.705 0.015 286.067);
147
- }
148
-
149
- .dark {
150
- --background: oklch(0.141 0.005 285.823);
151
- --foreground: oklch(0.985 0 0);
152
- --card: oklch(0.21 0.006 285.885);
153
- --card-foreground: oklch(0.985 0 0);
154
- --popover: oklch(0.21 0.006 285.885);
155
- --popover-foreground: oklch(0.985 0 0);
156
- --primary: oklch(0.92 0.004 286.32);
157
- --primary-foreground: oklch(0.21 0.006 285.885);
158
- --secondary: oklch(0.274 0.006 286.033);
159
- --secondary-foreground: oklch(0.985 0 0);
160
- --muted: oklch(0.274 0.006 286.033);
161
- --muted-foreground: oklch(0.705 0.015 286.067);
162
- --accent: oklch(0.274 0.006 286.033);
163
- --accent-foreground: oklch(0.985 0 0);
164
- --destructive: oklch(0.704 0.191 22.216);
165
- --border: oklch(1 0 0 / 10%);
166
- --input: oklch(1 0 0 / 15%);
167
- --ring: oklch(0.552 0.016 285.938);
168
- --chart-1: oklch(0.488 0.243 264.376);
169
- --chart-2: oklch(0.696 0.17 162.48);
170
- --chart-3: oklch(0.769 0.188 70.08);
171
- --chart-4: oklch(0.627 0.265 303.9);
172
- --chart-5: oklch(0.645 0.246 16.439);
173
- --sidebar: oklch(0.21 0.006 285.885);
174
- --sidebar-foreground: oklch(0.985 0 0);
175
- --sidebar-primary: oklch(0.488 0.243 264.376);
176
- --sidebar-primary-foreground: oklch(0.985 0 0);
177
- --sidebar-accent: oklch(0.274 0.006 286.033);
178
- --sidebar-accent-foreground: oklch(0.985 0 0);
179
- --sidebar-border: oklch(1 0 0 / 10%);
180
- --sidebar-ring: oklch(0.552 0.016 285.938);
181
- }
182
-
183
- @layer base {
184
- * {
185
- @apply border-border outline-ring/50;
186
- }
187
- body {
188
- @apply bg-background text-foreground;
189
- }
190
- }
191
-
192
- ```
193
-
194
- ## app/layout.tsx
195
-
196
- ```tsx
197
- import type { Metadata } from "next";
198
- import { Geist, Geist_Mono } from "next/font/google";
199
-
200
- import "./globals.css";
201
-
202
- const geistSans = Geist({
203
- variable: "--font-geist-sans",
204
- subsets: ["latin"],
205
- });
206
-
207
- const geistMono = Geist_Mono({
208
- variable: "--font-geist-mono",
209
- subsets: ["latin"],
210
- });
211
-
212
- export const metadata: Metadata = {
213
- title: "assistant-ui App",
214
- description: "Generated by create-assistant-ui",
215
- };
216
-
217
- export default function RootLayout({
218
- children,
219
- }: Readonly<{
220
- children: React.ReactNode;
221
- }>) {
222
- return (
223
- <html lang="en" className="h-dvh">
224
- <body
225
- className={`${geistSans.variable} ${geistMono.variable} h-dvh antialiased`}
226
- >
227
- {children}
228
- </body>
229
- </html>
230
- );
231
- }
232
-
233
- ```
234
-
235
- ## app/page.tsx
236
-
237
- ```tsx
238
- "use client";
239
-
240
- import { Assistant } from "./assistant";
241
-
242
- export default function Home() {
243
- return (
244
- <main className="h-dvh">
245
- <Assistant />
246
- </main>
247
- );
248
- }
249
-
250
- ```
251
-
252
- ## components.json
253
-
254
- ```json
255
- {
256
- "$schema": "https://ui.shadcn.com/schema.json",
257
- "style": "new-york",
258
- "rsc": true,
259
- "tsx": true,
260
- "tailwind": {
261
- "config": "",
262
- "css": "app/globals.css",
263
- "baseColor": "zinc",
264
- "cssVariables": true,
265
- "prefix": ""
266
- },
267
- "aliases": {
268
- "components": "@/components",
269
- "utils": "@/lib/utils",
270
- "ui": "@/components/ui",
271
- "lib": "@/lib",
272
- "hooks": "@/hooks"
273
- },
274
- "iconLibrary": "lucide"
275
- }
276
-
277
- ```
278
-
279
- ## components/assistant-ui/markdown-text.tsx
280
-
281
- ```tsx
282
- "use client";
283
-
284
- import "@assistant-ui/react-markdown/styles/dot.css";
285
-
286
- import {
287
- CodeHeaderProps,
288
- MarkdownTextPrimitive,
289
- unstable_memoizeMarkdownComponents as memoizeMarkdownComponents,
290
- useIsMarkdownCodeBlock,
291
- } from "@assistant-ui/react-markdown";
292
- import remarkGfm from "remark-gfm";
293
- import { FC, memo, useState } from "react";
294
- import { CheckIcon, CopyIcon } from "lucide-react";
295
-
296
- import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
297
- import { cn } from "@/lib/utils";
298
-
299
- const MarkdownTextImpl = () => {
300
- return (
301
- <MarkdownTextPrimitive
302
- remarkPlugins={[remarkGfm]}
303
- className="aui-md"
304
- components={defaultComponents}
305
- />
306
- );
307
- };
308
-
309
- export const MarkdownText = memo(MarkdownTextImpl);
310
-
311
- const CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {
312
- const { isCopied, copyToClipboard } = useCopyToClipboard();
313
- const onCopy = () => {
314
- if (!code || isCopied) return;
315
- copyToClipboard(code);
316
- };
317
-
318
- return (
319
- <div className="flex items-center justify-between gap-4 rounded-t-lg bg-zinc-900 px-4 py-2 text-sm font-semibold text-white">
320
- <span className="lowercase [&>span]:text-xs">{language}</span>
321
- <TooltipIconButton tooltip="Copy" onClick={onCopy}>
322
- {!isCopied && <CopyIcon />}
323
- {isCopied && <CheckIcon />}
324
- </TooltipIconButton>
325
- </div>
326
- );
327
- };
328
-
329
- const useCopyToClipboard = ({
330
- copiedDuration = 3000,
331
- }: {
332
- copiedDuration?: number;
333
- } = {}) => {
334
- const [isCopied, setIsCopied] = useState<boolean>(false);
335
-
336
- const copyToClipboard = (value: string) => {
337
- if (!value) return;
338
-
339
- navigator.clipboard.writeText(value).then(() => {
340
- setIsCopied(true);
341
- setTimeout(() => setIsCopied(false), copiedDuration);
342
- });
343
- };
344
-
345
- return { isCopied, copyToClipboard };
346
- };
347
-
348
- const defaultComponents = memoizeMarkdownComponents({
349
- h1: ({ className, ...props }) => (
350
- <h1
351
- className={cn(
352
- "mb-8 scroll-m-20 text-4xl font-extrabold tracking-tight last:mb-0",
353
- className,
354
- )}
355
- {...props}
356
- />
357
- ),
358
- h2: ({ className, ...props }) => (
359
- <h2
360
- className={cn(
361
- "mb-4 mt-8 scroll-m-20 text-3xl font-semibold tracking-tight first:mt-0 last:mb-0",
362
- className,
363
- )}
364
- {...props}
365
- />
366
- ),
367
- h3: ({ className, ...props }) => (
368
- <h3
369
- className={cn(
370
- "mb-4 mt-6 scroll-m-20 text-2xl font-semibold tracking-tight first:mt-0 last:mb-0",
371
- className,
372
- )}
373
- {...props}
374
- />
375
- ),
376
- h4: ({ className, ...props }) => (
377
- <h4
378
- className={cn(
379
- "mb-4 mt-6 scroll-m-20 text-xl font-semibold tracking-tight first:mt-0 last:mb-0",
380
- className,
381
- )}
382
- {...props}
383
- />
384
- ),
385
- h5: ({ className, ...props }) => (
386
- <h5
387
- className={cn(
388
- "my-4 text-lg font-semibold first:mt-0 last:mb-0",
389
- className,
390
- )}
391
- {...props}
392
- />
393
- ),
394
- h6: ({ className, ...props }) => (
395
- <h6
396
- className={cn("my-4 font-semibold first:mt-0 last:mb-0", className)}
397
- {...props}
398
- />
399
- ),
400
- p: ({ className, ...props }) => (
401
- <p
402
- className={cn("mb-5 mt-5 leading-7 first:mt-0 last:mb-0", className)}
403
- {...props}
404
- />
405
- ),
406
- a: ({ className, ...props }) => (
407
- <a
408
- className={cn(
409
- "text-primary font-medium underline underline-offset-4",
410
- className,
411
- )}
412
- {...props}
413
- />
414
- ),
415
- blockquote: ({ className, ...props }) => (
416
- <blockquote
417
- className={cn("border-l-2 pl-6 italic", className)}
418
- {...props}
419
- />
420
- ),
421
- ul: ({ className, ...props }) => (
422
- <ul
423
- className={cn("my-5 ml-6 list-disc [&>li]:mt-2", className)}
424
- {...props}
425
- />
426
- ),
427
- ol: ({ className, ...props }) => (
428
- <ol
429
- className={cn("my-5 ml-6 list-decimal [&>li]:mt-2", className)}
430
- {...props}
431
- />
432
- ),
433
- hr: ({ className, ...props }) => (
434
- <hr className={cn("my-5 border-b", className)} {...props} />
435
- ),
436
- table: ({ className, ...props }) => (
437
- <table
438
- className={cn(
439
- "my-5 w-full border-separate border-spacing-0 overflow-y-auto",
440
- className,
441
- )}
442
- {...props}
443
- />
444
- ),
445
- th: ({ className, ...props }) => (
446
- <th
447
- className={cn(
448
- "bg-muted px-4 py-2 text-left font-bold first:rounded-tl-lg last:rounded-tr-lg [&[align=center]]:text-center [&[align=right]]:text-right",
449
- className,
450
- )}
451
- {...props}
452
- />
453
- ),
454
- td: ({ className, ...props }) => (
455
- <td
456
- className={cn(
457
- "border-b border-l px-4 py-2 text-left last:border-r [&[align=center]]:text-center [&[align=right]]:text-right",
458
- className,
459
- )}
460
- {...props}
461
- />
462
- ),
463
- tr: ({ className, ...props }) => (
464
- <tr
465
- className={cn(
466
- "m-0 border-b p-0 first:border-t [&:last-child>td:first-child]:rounded-bl-lg [&:last-child>td:last-child]:rounded-br-lg",
467
- className,
468
- )}
469
- {...props}
470
- />
471
- ),
472
- sup: ({ className, ...props }) => (
473
- <sup
474
- className={cn("[&>a]:text-xs [&>a]:no-underline", className)}
475
- {...props}
476
- />
477
- ),
478
- pre: ({ className, ...props }) => (
479
- <pre
480
- className={cn(
481
- "overflow-x-auto rounded-b-lg bg-black p-4 text-white",
482
- className,
483
- )}
484
- {...props}
485
- />
486
- ),
487
- code: function Code({ className, ...props }) {
488
- const isCodeBlock = useIsMarkdownCodeBlock();
489
- return (
490
- <code
491
- className={cn(
492
- !isCodeBlock && "bg-muted rounded border font-semibold",
493
- className,
494
- )}
495
- {...props}
496
- />
497
- );
498
- },
499
- CodeHeader,
500
- });
501
-
502
- ```
503
-
504
- ## components/assistant-ui/thread.tsx
505
-
506
- ```tsx
507
- import {
508
- ActionBarPrimitive,
509
- BranchPickerPrimitive,
510
- ComposerPrimitive,
511
- MessagePrimitive,
512
- ThreadPrimitive,
513
- } from "@assistant-ui/react";
514
- import type { FC } from "react";
515
- import {
516
- ArrowDownIcon,
517
- CheckIcon,
518
- ChevronLeftIcon,
519
- ChevronRightIcon,
520
- CopyIcon,
521
- PencilIcon,
522
- RefreshCwIcon,
523
- SendHorizontalIcon,
524
- } from "lucide-react";
525
- import { cn } from "@/lib/utils";
526
-
527
- import { Button } from "@/components/ui/button";
528
- import { MarkdownText } from "@/components/assistant-ui/markdown-text";
529
- import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
530
-
531
- export const Thread: FC = () => {
532
- return (
533
- <ThreadPrimitive.Root
534
- className="bg-background box-border flex h-full flex-col overflow-hidden"
535
- style={{
536
- ["--thread-max-width" as string]: "42rem",
537
- }}
538
- >
539
- <ThreadPrimitive.Viewport className="flex h-full flex-col items-center overflow-y-scroll scroll-smooth bg-inherit px-4 pt-8">
540
- <ThreadWelcome />
541
-
542
- <ThreadPrimitive.Messages
543
- components={{
544
- UserMessage: UserMessage,
545
- EditComposer: EditComposer,
546
- AssistantMessage: AssistantMessage,
547
- }}
548
- />
549
-
550
- <ThreadPrimitive.If empty={false}>
551
- <div className="min-h-8 flex-grow" />
552
- </ThreadPrimitive.If>
553
-
554
- <div className="sticky bottom-0 mt-3 flex w-full max-w-[var(--thread-max-width)] flex-col items-center justify-end rounded-t-lg bg-inherit pb-4">
555
- <ThreadScrollToBottom />
556
- <Composer />
557
- </div>
558
- </ThreadPrimitive.Viewport>
559
- </ThreadPrimitive.Root>
560
- );
561
- };
562
-
563
- const ThreadScrollToBottom: FC = () => {
564
- return (
565
- <ThreadPrimitive.ScrollToBottom asChild>
566
- <TooltipIconButton
567
- tooltip="Scroll to bottom"
568
- variant="outline"
569
- className="absolute -top-8 rounded-full disabled:invisible"
570
- >
571
- <ArrowDownIcon />
572
- </TooltipIconButton>
573
- </ThreadPrimitive.ScrollToBottom>
574
- );
575
- };
576
-
577
- const ThreadWelcome: FC = () => {
578
- return (
579
- <ThreadPrimitive.Empty>
580
- <div className="flex w-full max-w-[var(--thread-max-width)] flex-grow flex-col">
581
- <div className="flex w-full flex-grow flex-col items-center justify-center">
582
- <p className="mt-4 font-medium">How can I help you today?</p>
583
- </div>
584
- <ThreadWelcomeSuggestions />
585
- </div>
586
- </ThreadPrimitive.Empty>
587
- );
588
- };
589
-
590
- const ThreadWelcomeSuggestions: FC = () => {
591
- return (
592
- <div className="mt-3 flex w-full items-stretch justify-center gap-4">
593
- <ThreadPrimitive.Suggestion
594
- className="hover:bg-muted/80 flex max-w-sm grow basis-0 flex-col items-center justify-center rounded-lg border p-3 transition-colors ease-in"
595
- prompt="What is the weather in Tokyo?"
596
- method="replace"
597
- autoSend
598
- >
599
- <span className="line-clamp-2 text-ellipsis text-sm font-semibold">
600
- What is the weather in Tokyo?
601
- </span>
602
- </ThreadPrimitive.Suggestion>
603
- <ThreadPrimitive.Suggestion
604
- className="hover:bg-muted/80 flex max-w-sm grow basis-0 flex-col items-center justify-center rounded-lg border p-3 transition-colors ease-in"
605
- prompt="What is assistant-ui?"
606
- method="replace"
607
- autoSend
608
- >
609
- <span className="line-clamp-2 text-ellipsis text-sm font-semibold">
610
- What is assistant-ui?
611
- </span>
612
- </ThreadPrimitive.Suggestion>
613
- </div>
614
- );
615
- };
616
-
617
- const Composer: FC = () => {
618
- return (
619
- <ComposerPrimitive.Root className="focus-within:border-ring/20 flex w-full flex-wrap items-end rounded-lg border bg-inherit px-2.5 shadow-sm transition-colors ease-in">
620
- <ComposerPrimitive.Input
621
- rows={1}
622
- autoFocus
623
- placeholder="Write a message..."
624
- className="placeholder:text-muted-foreground max-h-40 flex-grow resize-none border-none bg-transparent px-2 py-4 text-sm outline-none focus:ring-0 disabled:cursor-not-allowed"
625
- />
626
- <ComposerAction />
627
- </ComposerPrimitive.Root>
628
- );
629
- };
630
-
631
- const ComposerAction: FC = () => {
632
- return (
633
- <>
634
- <ThreadPrimitive.If running={false}>
635
- <ComposerPrimitive.Send asChild>
636
- <TooltipIconButton
637
- tooltip="Send"
638
- variant="default"
639
- className="my-2.5 size-8 p-2 transition-opacity ease-in"
640
- >
641
- <SendHorizontalIcon />
642
- </TooltipIconButton>
643
- </ComposerPrimitive.Send>
644
- </ThreadPrimitive.If>
645
- <ThreadPrimitive.If running>
646
- <ComposerPrimitive.Cancel asChild>
647
- <TooltipIconButton
648
- tooltip="Cancel"
649
- variant="default"
650
- className="my-2.5 size-8 p-2 transition-opacity ease-in"
651
- >
652
- <CircleStopIcon />
653
- </TooltipIconButton>
654
- </ComposerPrimitive.Cancel>
655
- </ThreadPrimitive.If>
656
- </>
657
- );
658
- };
659
-
660
- const UserMessage: FC = () => {
661
- return (
662
- <MessagePrimitive.Root className="grid w-full max-w-[var(--thread-max-width)] auto-rows-auto grid-cols-[minmax(72px,1fr)_auto] gap-y-2 py-4 [&:where(>*)]:col-start-2">
663
- <UserActionBar />
664
-
665
- <div className="bg-muted text-foreground col-start-2 row-start-2 max-w-[calc(var(--thread-max-width)*0.8)] break-words rounded-3xl px-5 py-2.5">
666
- <MessagePrimitive.Parts />
667
- </div>
668
-
669
- <BranchPicker className="col-span-full col-start-1 row-start-3 -mr-1 justify-end" />
670
- </MessagePrimitive.Root>
671
- );
672
- };
673
-
674
- const UserActionBar: FC = () => {
675
- return (
676
- <ActionBarPrimitive.Root
677
- hideWhenRunning
678
- autohide="not-last"
679
- className="col-start-1 row-start-2 mr-3 mt-2.5 flex flex-col items-end"
680
- >
681
- <ActionBarPrimitive.Edit asChild>
682
- <TooltipIconButton tooltip="Edit">
683
- <PencilIcon />
684
- </TooltipIconButton>
685
- </ActionBarPrimitive.Edit>
686
- </ActionBarPrimitive.Root>
687
- );
688
- };
689
-
690
- const EditComposer: FC = () => {
691
- return (
692
- <ComposerPrimitive.Root className="bg-muted my-4 flex w-full max-w-[var(--thread-max-width)] flex-col gap-2 rounded-xl">
693
- <ComposerPrimitive.Input className="text-foreground flex h-8 w-full resize-none bg-transparent p-4 pb-0 outline-none" />
694
-
695
- <div className="mx-3 mb-3 flex items-center justify-center gap-2 self-end">
696
- <ComposerPrimitive.Cancel asChild>
697
- <Button variant="ghost">Cancel</Button>
698
- </ComposerPrimitive.Cancel>
699
- <ComposerPrimitive.Send asChild>
700
- <Button>Send</Button>
701
- </ComposerPrimitive.Send>
702
- </div>
703
- </ComposerPrimitive.Root>
704
- );
705
- };
706
-
707
- const AssistantMessage: FC = () => {
708
- return (
709
- <MessagePrimitive.Root className="relative grid w-full max-w-[var(--thread-max-width)] grid-cols-[auto_auto_1fr] grid-rows-[auto_1fr] py-4">
710
- <div className="text-foreground col-span-2 col-start-2 row-start-1 my-1.5 max-w-[calc(var(--thread-max-width)*0.8)] break-words leading-7">
711
- <MessagePrimitive.Parts components={{ Text: MarkdownText }} />
712
- </div>
713
-
714
- <AssistantActionBar />
715
-
716
- <BranchPicker className="col-start-2 row-start-2 -ml-2 mr-2" />
717
- </MessagePrimitive.Root>
718
- );
719
- };
720
-
721
- const AssistantActionBar: FC = () => {
722
- return (
723
- <ActionBarPrimitive.Root
724
- hideWhenRunning
725
- autohide="not-last"
726
- autohideFloat="single-branch"
727
- className="text-muted-foreground data-[floating]:bg-background col-start-3 row-start-2 -ml-1 flex gap-1 data-[floating]:absolute data-[floating]:rounded-md data-[floating]:border data-[floating]:p-1 data-[floating]:shadow-sm"
728
- >
729
- <ActionBarPrimitive.Copy asChild>
730
- <TooltipIconButton tooltip="Copy">
731
- <MessagePrimitive.If copied>
732
- <CheckIcon />
733
- </MessagePrimitive.If>
734
- <MessagePrimitive.If copied={false}>
735
- <CopyIcon />
736
- </MessagePrimitive.If>
737
- </TooltipIconButton>
738
- </ActionBarPrimitive.Copy>
739
- <ActionBarPrimitive.Reload asChild>
740
- <TooltipIconButton tooltip="Refresh">
741
- <RefreshCwIcon />
742
- </TooltipIconButton>
743
- </ActionBarPrimitive.Reload>
744
- </ActionBarPrimitive.Root>
745
- );
746
- };
747
-
748
- const BranchPicker: FC<BranchPickerPrimitive.Root.Props> = ({
749
- className,
750
- ...rest
751
- }) => {
752
- return (
753
- <BranchPickerPrimitive.Root
754
- hideWhenSingleBranch
755
- className={cn(
756
- "text-muted-foreground inline-flex items-center text-xs",
757
- className,
758
- )}
759
- {...rest}
760
- >
761
- <BranchPickerPrimitive.Previous asChild>
762
- <TooltipIconButton tooltip="Previous">
763
- <ChevronLeftIcon />
764
- </TooltipIconButton>
765
- </BranchPickerPrimitive.Previous>
766
- <span className="font-medium">
767
- <BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
768
- </span>
769
- <BranchPickerPrimitive.Next asChild>
770
- <TooltipIconButton tooltip="Next">
771
- <ChevronRightIcon />
772
- </TooltipIconButton>
773
- </BranchPickerPrimitive.Next>
774
- </BranchPickerPrimitive.Root>
775
- );
776
- };
777
-
778
- const CircleStopIcon = () => {
779
- return (
780
- <svg
781
- xmlns="http://www.w3.org/2000/svg"
782
- viewBox="0 0 16 16"
783
- fill="currentColor"
784
- width="16"
785
- height="16"
786
- >
787
- <rect width="10" height="10" x="3" y="3" rx="2" />
788
- </svg>
789
- );
790
- };
791
-
792
- ```
793
-
794
- ## components/assistant-ui/tooltip-icon-button.tsx
795
-
796
- ```tsx
797
- "use client";
798
-
799
- import { ComponentPropsWithoutRef, forwardRef } from "react";
800
-
801
- import {
802
- Tooltip,
803
- TooltipContent,
804
- TooltipTrigger,
805
- } from "@/components/ui/tooltip";
806
- import { Button } from "@/components/ui/button";
807
- import { cn } from "@/lib/utils";
808
-
809
- export type TooltipIconButtonProps = ComponentPropsWithoutRef<typeof Button> & {
810
- tooltip: string;
811
- side?: "top" | "bottom" | "left" | "right";
812
- };
813
-
814
- export const TooltipIconButton = forwardRef<
815
- HTMLButtonElement,
816
- TooltipIconButtonProps
817
- >(({ children, tooltip, side = "bottom", className, ...rest }, ref) => {
818
- return (
819
- <Tooltip>
820
- <TooltipTrigger asChild>
821
- <Button
822
- variant="ghost"
823
- size="icon"
824
- {...rest}
825
- className={cn("size-6 p-1", className)}
826
- ref={ref}
827
- >
828
- {children}
829
- <span className="sr-only">{tooltip}</span>
830
- </Button>
831
- </TooltipTrigger>
832
- <TooltipContent side={side}>{tooltip}</TooltipContent>
833
- </Tooltip>
834
- );
835
- });
836
-
837
- TooltipIconButton.displayName = "TooltipIconButton";
838
-
839
- ```
840
-
841
- ## components/ui/button.tsx
842
-
843
- ```tsx
844
- import * as React from "react";
845
- import { Slot } from "@radix-ui/react-slot";
846
- import { cva, type VariantProps } from "class-variance-authority";
847
-
848
- import { cn } from "@/lib/utils";
849
-
850
- const buttonVariants = cva(
851
- "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
852
- {
853
- variants: {
854
- variant: {
855
- default:
856
- "bg-primary text-primary-foreground shadow-xs hover:bg-primary/90",
857
- destructive:
858
- "bg-destructive text-white shadow-xs hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
859
- outline:
860
- "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
861
- secondary:
862
- "bg-secondary text-secondary-foreground shadow-xs hover:bg-secondary/80",
863
- ghost:
864
- "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
865
- link: "text-primary underline-offset-4 hover:underline",
866
- },
867
- size: {
868
- default: "h-9 px-4 py-2 has-[>svg]:px-3",
869
- sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
870
- lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
871
- icon: "size-9",
872
- },
873
- },
874
- defaultVariants: {
875
- variant: "default",
876
- size: "default",
877
- },
878
- },
879
- );
880
-
881
- function Button({
882
- className,
883
- variant,
884
- size,
885
- asChild = false,
886
- ...props
887
- }: React.ComponentProps<"button"> &
888
- VariantProps<typeof buttonVariants> & {
889
- asChild?: boolean;
890
- }) {
891
- const Comp = asChild ? Slot : "button";
892
-
893
- return (
894
- <Comp
895
- data-slot="button"
896
- className={cn(buttonVariants({ variant, size, className }))}
897
- {...props}
898
- />
899
- );
900
- }
901
-
902
- export { Button, buttonVariants };
903
-
904
- ```
905
-
906
- ## components/ui/tooltip.tsx
907
-
908
- ```tsx
909
- "use client";
910
-
911
- import * as React from "react";
912
- import * as TooltipPrimitive from "@radix-ui/react-tooltip";
913
-
914
- import { cn } from "@/lib/utils";
915
-
916
- function TooltipProvider({
917
- delayDuration = 0,
918
- ...props
919
- }: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
920
- return (
921
- <TooltipPrimitive.Provider
922
- data-slot="tooltip-provider"
923
- delayDuration={delayDuration}
924
- {...props}
925
- />
926
- );
927
- }
928
-
929
- function Tooltip({
930
- ...props
931
- }: React.ComponentProps<typeof TooltipPrimitive.Root>) {
932
- return (
933
- <TooltipProvider>
934
- <TooltipPrimitive.Root data-slot="tooltip" {...props} />
935
- </TooltipProvider>
936
- );
937
- }
938
-
939
- function TooltipTrigger({
940
- ...props
941
- }: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
942
- return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
943
- }
944
-
945
- function TooltipContent({
946
- className,
947
- sideOffset = 0,
948
- children,
949
- ...props
950
- }: React.ComponentProps<typeof TooltipPrimitive.Content>) {
951
- return (
952
- <TooltipPrimitive.Portal>
953
- <TooltipPrimitive.Content
954
- data-slot="tooltip-content"
955
- sideOffset={sideOffset}
956
- className={cn(
957
- "bg-primary text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 w-fit origin-[--radix-tooltip-content-transform-origin] text-balance rounded-md px-3 py-1.5 text-xs",
958
- className,
959
- )}
960
- {...props}
961
- >
962
- {children}
963
- <TooltipPrimitive.Arrow className="bg-primary fill-primary z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px]" />
964
- </TooltipPrimitive.Content>
965
- </TooltipPrimitive.Portal>
966
- );
967
- }
968
-
969
- export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
970
-
971
- ```
972
-
973
- ## eslint.config.ts
974
-
975
- ```typescript
976
- export { default } from "@assistant-ui/x-buildutils/eslint";
977
-
978
- ```
979
-
980
- ## lib/utils.ts
981
-
982
- ```typescript
983
- import { clsx, type ClassValue } from "clsx";
984
- import { twMerge } from "tailwind-merge";
985
-
986
- export function cn(...inputs: ClassValue[]) {
987
- return twMerge(clsx(inputs));
988
- }
989
-
990
- ```
991
-
992
- ## next.config.ts
993
-
994
- ```typescript
995
- import type { NextConfig } from "next";
996
-
997
- const nextConfig: NextConfig = {
998
- /* config options here */
999
- };
1000
-
1001
- export default nextConfig;
1002
-
1003
- ```
1004
-
1005
- ## package.json
1006
-
1007
- ```json
1008
- {
1009
- "name": "with-ai-sdk",
1010
- "version": "0.1.0",
1011
- "private": true,
1012
- "scripts": {
1013
- "dev": "next dev --turbo",
1014
- "build": "next build",
1015
- "start": "next start",
1016
- "lint": "next lint"
1017
- },
1018
- "dependencies": {
1019
- "@ai-sdk/openai": "^1.3.22",
1020
- "@assistant-ui/react": "workspace:*",
1021
- "@assistant-ui/react-ai-sdk-v4": "workspace:*",
1022
- "@assistant-ui/react-markdown": "workspace:*",
1023
- "@radix-ui/react-slot": "^1.2.3",
1024
- "@radix-ui/react-tooltip": "^1.2.7",
1025
- "ai": "^4.3.16",
1026
- "class-variance-authority": "^0.7.1",
1027
- "clsx": "^2.1.1",
1028
- "lucide-react": "^0.535.0",
1029
- "next": "15.4.5",
1030
- "react": "19.1.1",
1031
- "react-dom": "19.1.1",
1032
- "remark-gfm": "^4.0.1",
1033
- "tailwind-merge": "^3.3.1",
1034
- "tw-animate-css": "^1.3.6",
1035
- "zod": "^4.0.14"
1036
- },
1037
- "devDependencies": {
1038
- "@assistant-ui/x-buildutils": "workspace:*",
1039
- "@types/node": "^24",
1040
- "@types/react": "^19",
1041
- "@types/react-dom": "^19",
1042
- "eslint": "^9",
1043
- "eslint-config-next": "15.4.5",
1044
- "postcss": "^8",
1045
- "tailwindcss": "^4.1.11",
1046
- "typescript": "^5"
1047
- }
1048
- }
1049
-
1050
- ```
1051
-
1052
- ## tsconfig.json
1053
-
1054
- ```json
1055
- {
1056
- "extends": "@assistant-ui/x-buildutils/ts/base",
1057
- "compilerOptions": {
1058
- "target": "ES6",
1059
- "module": "ESNext",
1060
- "incremental": true,
1061
- "plugins": [
1062
- {
1063
- "name": "next"
1064
- }
1065
- ],
1066
- "allowJs": true,
1067
- "strictNullChecks": true,
1068
- "jsx": "preserve",
1069
- "paths": {
1070
- "@/*": ["./*"],
1071
- "@assistant-ui/*": ["../../packages/*/src"],
1072
- "@assistant-ui/react/*": ["../../packages/react/src/*"],
1073
- "assistant-stream": ["../../packages/assistant-stream/src"],
1074
- "assistant-stream/*": ["../../packages/assistant-stream/src/*"]
1075
- }
1076
- },
1077
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
1078
- "exclude": ["node_modules"]
1079
- }
1080
-
1081
- ```
1082
-