@assistant-ui/mcp-docs-server 0.1.18 → 0.1.20
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.
- package/.docs/organized/code-examples/with-ag-ui.md +69 -1336
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +429 -0
- package/.docs/organized/code-examples/with-assistant-transport.md +41 -1454
- package/.docs/organized/code-examples/with-cloud.md +73 -1442
- package/.docs/organized/code-examples/with-custom-thread-list.md +95 -1424
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +674 -0
- package/.docs/organized/code-examples/with-external-store.md +68 -1334
- package/.docs/organized/code-examples/with-ffmpeg.md +73 -1341
- package/.docs/organized/code-examples/with-langgraph.md +52 -1545
- package/.docs/organized/code-examples/with-parent-id-grouping.md +58 -1364
- package/.docs/organized/code-examples/with-react-hook-form.md +73 -1726
- package/.docs/organized/code-examples/with-react-router.md +915 -0
- package/.docs/organized/code-examples/with-store.md +31 -31
- package/.docs/organized/code-examples/with-tanstack.md +78 -862
- package/.docs/raw/blog/2025-01-31-changelog/index.mdx +0 -2
- package/.docs/raw/docs/{architecture.mdx → (docs)/architecture.mdx} +3 -2
- package/.docs/raw/docs/{cli.mdx → (docs)/cli.mdx} +66 -18
- package/.docs/raw/docs/{copilots → (docs)/copilots}/make-assistant-readable.mdx +1 -0
- package/.docs/raw/docs/{copilots → (docs)/copilots}/make-assistant-tool-ui.mdx +2 -1
- package/.docs/raw/docs/{copilots → (docs)/copilots}/make-assistant-tool.mdx +2 -1
- package/.docs/raw/docs/{copilots → (docs)/copilots}/model-context.mdx +5 -4
- package/.docs/raw/docs/{copilots → (docs)/copilots}/motivation.mdx +4 -3
- package/.docs/raw/docs/{copilots → (docs)/copilots}/use-assistant-instructions.mdx +1 -0
- package/.docs/raw/docs/{devtools.mdx → (docs)/devtools.mdx} +4 -4
- package/.docs/raw/docs/{guides/Attachments.mdx → (docs)/guides/attachments.mdx} +6 -7
- package/.docs/raw/docs/{guides/Branching.mdx → (docs)/guides/branching.mdx} +2 -1
- package/.docs/raw/docs/{guides → (docs)/guides}/context-api.mdx +118 -117
- package/.docs/raw/docs/(docs)/guides/dictation.mdx +370 -0
- package/.docs/raw/docs/{guides/Editing.mdx → (docs)/guides/editing.mdx} +1 -0
- package/.docs/raw/docs/{guides/Latex.mdx → (docs)/guides/latex.mdx} +1 -2
- package/.docs/raw/docs/{guides/Speech.mdx → (docs)/guides/speech.mdx} +9 -10
- package/.docs/raw/docs/(docs)/guides/suggestions.mdx +296 -0
- package/.docs/raw/docs/{guides/ToolUI.mdx → (docs)/guides/tool-ui.mdx} +15 -14
- package/.docs/raw/docs/(docs)/guides/tools.mdx +564 -0
- package/.docs/raw/docs/(docs)/index.mdx +74 -0
- package/.docs/raw/docs/{getting-started.mdx → (docs)/installation.mdx} +18 -23
- package/.docs/raw/docs/(docs)/llm.mdx +209 -0
- package/.docs/raw/docs/{api-reference/context-providers/AssistantRuntimeProvider.mdx → (reference)/api-reference/context-providers/assistant-runtime-provider.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/context-providers/TextMessagePartProvider.mdx → (reference)/api-reference/context-providers/text-message-part-provider.mdx} +2 -1
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/integrations/react-data-stream.mdx +50 -3
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/integrations/react-hook-form.mdx +2 -1
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/integrations/vercel-ai-sdk.mdx +2 -2
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/overview.mdx +10 -4
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar-more.mdx +327 -0
- package/.docs/raw/docs/{api-reference/primitives/ActionBar.mdx → (reference)/api-reference/primitives/action-bar.mdx} +7 -5
- package/.docs/raw/docs/{api-reference/primitives/AssistantIf.mdx → (reference)/api-reference/primitives/assistant-if.mdx} +51 -51
- package/.docs/raw/docs/{api-reference/primitives/AssistantModal.mdx → (reference)/api-reference/primitives/assistant-modal.mdx} +3 -1
- package/.docs/raw/docs/{api-reference/primitives/Attachment.mdx → (reference)/api-reference/primitives/attachment.mdx} +3 -2
- package/.docs/raw/docs/{api-reference/primitives/BranchPicker.mdx → (reference)/api-reference/primitives/branch-picker.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/primitives/Composer.mdx → (reference)/api-reference/primitives/composer.mdx} +101 -2
- package/.docs/raw/docs/{api-reference → (reference)/api-reference}/primitives/composition.mdx +1 -0
- package/.docs/raw/docs/{api-reference/primitives/Error.mdx → (reference)/api-reference/primitives/error.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/primitives/MessagePart.mdx → (reference)/api-reference/primitives/message-part.mdx} +2 -2
- package/.docs/raw/docs/{api-reference/primitives/Message.mdx → (reference)/api-reference/primitives/message.mdx} +2 -1
- package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +153 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item-more.mdx +221 -0
- package/.docs/raw/docs/{api-reference/primitives/ThreadListItem.mdx → (reference)/api-reference/primitives/thread-list-item.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/primitives/ThreadList.mdx → (reference)/api-reference/primitives/thread-list.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/primitives/Thread.mdx → (reference)/api-reference/primitives/thread.mdx} +30 -40
- package/.docs/raw/docs/{api-reference/runtimes/AssistantRuntime.mdx → (reference)/api-reference/runtimes/assistant-runtime.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/runtimes/AttachmentRuntime.mdx → (reference)/api-reference/runtimes/attachment-runtime.mdx} +3 -2
- package/.docs/raw/docs/{api-reference/runtimes/ComposerRuntime.mdx → (reference)/api-reference/runtimes/composer-runtime.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/runtimes/MessagePartRuntime.mdx → (reference)/api-reference/runtimes/message-part-runtime.mdx} +3 -2
- package/.docs/raw/docs/{api-reference/runtimes/MessageRuntime.mdx → (reference)/api-reference/runtimes/message-runtime.mdx} +3 -2
- package/.docs/raw/docs/{api-reference/runtimes/ThreadListItemRuntime.mdx → (reference)/api-reference/runtimes/thread-list-item-runtime.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/runtimes/ThreadListRuntime.mdx → (reference)/api-reference/runtimes/thread-list-runtime.mdx} +2 -1
- package/.docs/raw/docs/{api-reference/runtimes/ThreadRuntime.mdx → (reference)/api-reference/runtimes/thread-runtime.mdx} +3 -5
- package/.docs/raw/docs/{legacy/styled/AssistantModal.mdx → (reference)/legacy/styled/assistant-modal.mdx} +2 -3
- package/.docs/raw/docs/{legacy/styled/Decomposition.mdx → (reference)/legacy/styled/decomposition.mdx} +6 -5
- package/.docs/raw/docs/{legacy/styled/Markdown.mdx → (reference)/legacy/styled/markdown.mdx} +2 -4
- package/.docs/raw/docs/{legacy/styled/Scrollbar.mdx → (reference)/legacy/styled/scrollbar.mdx} +2 -1
- package/.docs/raw/docs/{legacy/styled/ThreadWidth.mdx → (reference)/legacy/styled/thread-width.mdx} +1 -0
- package/.docs/raw/docs/{legacy/styled/Thread.mdx → (reference)/legacy/styled/thread.mdx} +2 -3
- package/.docs/raw/docs/{migrations → (reference)/migrations}/deprecation-policy.mdx +1 -0
- package/.docs/raw/docs/{migrations → (reference)/migrations}/react-langgraph-v0-7.mdx +1 -2
- package/.docs/raw/docs/{migrations → (reference)/migrations}/v0-11.mdx +1 -0
- package/.docs/raw/docs/(reference)/migrations/v0-12.mdx +300 -0
- package/.docs/raw/docs/{react-compatibility.mdx → (reference)/react-compatibility.mdx} +2 -3
- package/.docs/raw/docs/cloud/authorization.mdx +1 -0
- package/.docs/raw/docs/cloud/overview.mdx +1 -0
- package/.docs/raw/docs/cloud/persistence/ai-sdk.mdx +2 -3
- package/.docs/raw/docs/cloud/persistence/langgraph.mdx +5 -7
- package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +9 -8
- package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +2 -3
- package/.docs/raw/docs/runtimes/assistant-transport.mdx +10 -9
- package/.docs/raw/docs/runtimes/custom/custom-thread-list.mdx +7 -8
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +6 -8
- package/.docs/raw/docs/runtimes/custom/local.mdx +55 -42
- package/.docs/raw/docs/runtimes/data-stream.mdx +67 -6
- package/.docs/raw/docs/runtimes/helicone.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/index.mdx +3 -3
- package/.docs/raw/docs/runtimes/langgraph/tutorial/index.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +1 -0
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +2 -1
- package/.docs/raw/docs/runtimes/langserve.mdx +2 -2
- package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +4 -5
- package/.docs/raw/docs/runtimes/mastra/overview.mdx +1 -0
- package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +3 -4
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +2 -4
- package/.docs/raw/docs/ui/accordion.mdx +261 -0
- package/.docs/raw/docs/ui/assistant-modal.mdx +163 -0
- package/.docs/raw/docs/ui/assistant-sidebar.mdx +90 -0
- package/.docs/raw/docs/ui/attachment.mdx +227 -0
- package/.docs/raw/docs/ui/badge.mdx +140 -0
- package/.docs/raw/docs/ui/file.mdx +153 -0
- package/.docs/raw/docs/ui/image.mdx +101 -0
- package/.docs/raw/docs/ui/{Markdown.mdx → markdown.mdx} +11 -6
- package/.docs/raw/docs/ui/{Mermaid.mdx → mermaid.mdx} +12 -5
- package/.docs/raw/docs/ui/model-selector.mdx +226 -0
- package/.docs/raw/docs/ui/{PartGrouping.mdx → part-grouping.mdx} +6 -8
- package/.docs/raw/docs/ui/reasoning.mdx +150 -0
- package/.docs/raw/docs/ui/{Scrollbar.mdx → scrollbar.mdx} +9 -1
- package/.docs/raw/docs/ui/select.mdx +247 -0
- package/.docs/raw/docs/ui/sources.mdx +89 -0
- package/.docs/raw/docs/ui/streamdown.mdx +348 -0
- package/.docs/raw/docs/ui/{SyntaxHighlighting.mdx → syntax-highlighting.mdx} +9 -5
- package/.docs/raw/docs/ui/tabs.mdx +261 -0
- package/.docs/raw/docs/ui/thread-list.mdx +275 -0
- package/.docs/raw/docs/ui/{Thread.mdx → thread.mdx} +61 -76
- package/.docs/raw/docs/ui/tool-fallback.mdx +112 -0
- package/.docs/raw/docs/ui/tool-group.mdx +214 -0
- package/README.md +3 -3
- package/dist/tools/docs.js +1 -1
- package/dist/tools/examples.js +1 -1
- package/dist/tools/examples.js.map +1 -1
- package/package.json +5 -5
- package/src/tools/docs.ts +1 -1
- package/src/tools/examples.ts +1 -1
- package/src/tools/tests/docs.test.ts +18 -16
- package/src/tools/tests/examples.test.ts +6 -6
- package/src/tools/tests/path-traversal.test.ts +3 -3
- package/src/utils/tests/security.test.ts +3 -3
- package/.docs/organized/code-examples/with-ai-sdk-v5.md +0 -1735
- package/.docs/raw/docs/about-assistantui.mdx +0 -53
- package/.docs/raw/docs/guides/Tools.mdx +0 -738
- package/.docs/raw/docs/index.mdx +0 -7
- package/.docs/raw/docs/mcp-docs-server.mdx +0 -322
- package/.docs/raw/docs/migrations/v0-12.mdx +0 -125
- package/.docs/raw/docs/ui/AssistantModal.mdx +0 -45
- package/.docs/raw/docs/ui/AssistantSidebar.mdx +0 -41
- package/.docs/raw/docs/ui/Attachment.mdx +0 -84
- package/.docs/raw/docs/ui/Reasoning.mdx +0 -152
- package/.docs/raw/docs/ui/ThreadList.mdx +0 -90
- package/.docs/raw/docs/ui/ToolFallback.mdx +0 -63
- package/.docs/raw/docs/ui/ToolGroup.mdx +0 -96
- /package/.docs/raw/docs/{copilots → (docs)/copilots}/assistant-frame.mdx +0 -0
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
@import "tailwindcss";
|
|
7
7
|
@import "tw-animate-css";
|
|
8
8
|
|
|
9
|
+
@source "../../../packages/ui/src";
|
|
10
|
+
|
|
9
11
|
@custom-variant dark (&:is(.dark *));
|
|
10
12
|
|
|
11
13
|
@theme inline {
|
|
@@ -281,1332 +283,12 @@ export default function Home() {
|
|
|
281
283
|
"lib": "@/lib",
|
|
282
284
|
"hooks": "@/hooks"
|
|
283
285
|
},
|
|
284
|
-
"iconLibrary": "lucide"
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
## components/assistant-ui/attachment.tsx
|
|
290
|
-
|
|
291
|
-
```tsx
|
|
292
|
-
"use client";
|
|
293
|
-
|
|
294
|
-
import { PropsWithChildren, useEffect, useState, type FC } from "react";
|
|
295
|
-
import Image from "next/image";
|
|
296
|
-
import { XIcon, PlusIcon, FileText } from "lucide-react";
|
|
297
|
-
import {
|
|
298
|
-
AttachmentPrimitive,
|
|
299
|
-
ComposerPrimitive,
|
|
300
|
-
MessagePrimitive,
|
|
301
|
-
useAssistantState,
|
|
302
|
-
useAssistantApi,
|
|
303
|
-
} from "@assistant-ui/react";
|
|
304
|
-
import { useShallow } from "zustand/shallow";
|
|
305
|
-
import {
|
|
306
|
-
Tooltip,
|
|
307
|
-
TooltipContent,
|
|
308
|
-
TooltipTrigger,
|
|
309
|
-
} from "@/components/ui/tooltip";
|
|
310
|
-
import {
|
|
311
|
-
Dialog,
|
|
312
|
-
DialogTitle,
|
|
313
|
-
DialogContent,
|
|
314
|
-
DialogTrigger,
|
|
315
|
-
} from "@/components/ui/dialog";
|
|
316
|
-
import { Avatar, AvatarImage, AvatarFallback } from "@/components/ui/avatar";
|
|
317
|
-
import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
|
|
318
|
-
import { cn } from "@/lib/utils";
|
|
319
|
-
|
|
320
|
-
const useFileSrc = (file: File | undefined) => {
|
|
321
|
-
const [src, setSrc] = useState<string | undefined>(undefined);
|
|
322
|
-
|
|
323
|
-
useEffect(() => {
|
|
324
|
-
if (!file) {
|
|
325
|
-
setSrc(undefined);
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const objectUrl = URL.createObjectURL(file);
|
|
330
|
-
setSrc(objectUrl);
|
|
331
|
-
|
|
332
|
-
return () => {
|
|
333
|
-
URL.revokeObjectURL(objectUrl);
|
|
334
|
-
};
|
|
335
|
-
}, [file]);
|
|
336
|
-
|
|
337
|
-
return src;
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
const useAttachmentSrc = () => {
|
|
341
|
-
const { file, src } = useAssistantState(
|
|
342
|
-
useShallow(({ attachment }): { file?: File; src?: string } => {
|
|
343
|
-
if (attachment.type !== "image") return {};
|
|
344
|
-
if (attachment.file) return { file: attachment.file };
|
|
345
|
-
const src = attachment.content?.filter((c) => c.type === "image")[0]
|
|
346
|
-
?.image;
|
|
347
|
-
if (!src) return {};
|
|
348
|
-
return { src };
|
|
349
|
-
}),
|
|
350
|
-
);
|
|
351
|
-
|
|
352
|
-
return useFileSrc(file) ?? src;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
type AttachmentPreviewProps = {
|
|
356
|
-
src: string;
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
const AttachmentPreview: FC<AttachmentPreviewProps> = ({ src }) => {
|
|
360
|
-
const [isLoaded, setIsLoaded] = useState(false);
|
|
361
|
-
return (
|
|
362
|
-
<Image
|
|
363
|
-
src={src}
|
|
364
|
-
alt="Image Preview"
|
|
365
|
-
width={1}
|
|
366
|
-
height={1}
|
|
367
|
-
className={
|
|
368
|
-
isLoaded
|
|
369
|
-
? "aui-attachment-preview-image-loaded block h-auto max-h-[80vh] w-auto max-w-full object-contain"
|
|
370
|
-
: "aui-attachment-preview-image-loading hidden"
|
|
371
|
-
}
|
|
372
|
-
onLoadingComplete={() => setIsLoaded(true)}
|
|
373
|
-
priority={false}
|
|
374
|
-
/>
|
|
375
|
-
);
|
|
376
|
-
};
|
|
377
|
-
|
|
378
|
-
const AttachmentPreviewDialog: FC<PropsWithChildren> = ({ children }) => {
|
|
379
|
-
const src = useAttachmentSrc();
|
|
380
|
-
|
|
381
|
-
if (!src) return children;
|
|
382
|
-
|
|
383
|
-
return (
|
|
384
|
-
<Dialog>
|
|
385
|
-
<DialogTrigger
|
|
386
|
-
className="aui-attachment-preview-trigger cursor-pointer transition-colors hover:bg-accent/50"
|
|
387
|
-
asChild
|
|
388
|
-
>
|
|
389
|
-
{children}
|
|
390
|
-
</DialogTrigger>
|
|
391
|
-
<DialogContent className="aui-attachment-preview-dialog-content p-2 sm:max-w-3xl [&>button]:rounded-full [&>button]:bg-foreground/60 [&>button]:p-1 [&>button]:opacity-100 [&>button]:ring-0! [&_svg]:text-background [&>button]:hover:[&_svg]:text-destructive">
|
|
392
|
-
<DialogTitle className="aui-sr-only sr-only">
|
|
393
|
-
Image Attachment Preview
|
|
394
|
-
</DialogTitle>
|
|
395
|
-
<div className="aui-attachment-preview relative mx-auto flex max-h-[80dvh] w-full items-center justify-center overflow-hidden bg-background">
|
|
396
|
-
<AttachmentPreview src={src} />
|
|
397
|
-
</div>
|
|
398
|
-
</DialogContent>
|
|
399
|
-
</Dialog>
|
|
400
|
-
);
|
|
401
|
-
};
|
|
402
|
-
|
|
403
|
-
const AttachmentThumb: FC = () => {
|
|
404
|
-
const isImage = useAssistantState(
|
|
405
|
-
({ attachment }) => attachment.type === "image",
|
|
406
|
-
);
|
|
407
|
-
const src = useAttachmentSrc();
|
|
408
|
-
|
|
409
|
-
return (
|
|
410
|
-
<Avatar className="aui-attachment-tile-avatar h-full w-full rounded-none">
|
|
411
|
-
<AvatarImage
|
|
412
|
-
src={src}
|
|
413
|
-
alt="Attachment preview"
|
|
414
|
-
className="aui-attachment-tile-image object-cover"
|
|
415
|
-
/>
|
|
416
|
-
<AvatarFallback delayMs={isImage ? 200 : 0}>
|
|
417
|
-
<FileText className="aui-attachment-tile-fallback-icon size-8 text-muted-foreground" />
|
|
418
|
-
</AvatarFallback>
|
|
419
|
-
</Avatar>
|
|
420
|
-
);
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
const AttachmentUI: FC = () => {
|
|
424
|
-
const api = useAssistantApi();
|
|
425
|
-
const isComposer = api.attachment.source === "composer";
|
|
426
|
-
|
|
427
|
-
const isImage = useAssistantState(
|
|
428
|
-
({ attachment }) => attachment.type === "image",
|
|
429
|
-
);
|
|
430
|
-
const typeLabel = useAssistantState(({ attachment }) => {
|
|
431
|
-
const type = attachment.type;
|
|
432
|
-
switch (type) {
|
|
433
|
-
case "image":
|
|
434
|
-
return "Image";
|
|
435
|
-
case "document":
|
|
436
|
-
return "Document";
|
|
437
|
-
case "file":
|
|
438
|
-
return "File";
|
|
439
|
-
default:
|
|
440
|
-
const _exhaustiveCheck: never = type;
|
|
441
|
-
throw new Error(`Unknown attachment type: ${_exhaustiveCheck}`);
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
return (
|
|
446
|
-
<Tooltip>
|
|
447
|
-
<AttachmentPrimitive.Root
|
|
448
|
-
className={cn(
|
|
449
|
-
"aui-attachment-root relative",
|
|
450
|
-
isImage &&
|
|
451
|
-
"aui-attachment-root-composer only:[&>#attachment-tile]:size-24",
|
|
452
|
-
)}
|
|
453
|
-
>
|
|
454
|
-
<AttachmentPreviewDialog>
|
|
455
|
-
<TooltipTrigger asChild>
|
|
456
|
-
<div
|
|
457
|
-
className={cn(
|
|
458
|
-
"aui-attachment-tile size-14 cursor-pointer overflow-hidden rounded-[14px] border bg-muted transition-opacity hover:opacity-75",
|
|
459
|
-
isComposer &&
|
|
460
|
-
"aui-attachment-tile-composer border-foreground/20",
|
|
461
|
-
)}
|
|
462
|
-
role="button"
|
|
463
|
-
id="attachment-tile"
|
|
464
|
-
aria-label={`${typeLabel} attachment`}
|
|
465
|
-
>
|
|
466
|
-
<AttachmentThumb />
|
|
467
|
-
</div>
|
|
468
|
-
</TooltipTrigger>
|
|
469
|
-
</AttachmentPreviewDialog>
|
|
470
|
-
{isComposer && <AttachmentRemove />}
|
|
471
|
-
</AttachmentPrimitive.Root>
|
|
472
|
-
<TooltipContent side="top">
|
|
473
|
-
<AttachmentPrimitive.Name />
|
|
474
|
-
</TooltipContent>
|
|
475
|
-
</Tooltip>
|
|
476
|
-
);
|
|
477
|
-
};
|
|
478
|
-
|
|
479
|
-
const AttachmentRemove: FC = () => {
|
|
480
|
-
return (
|
|
481
|
-
<AttachmentPrimitive.Remove asChild>
|
|
482
|
-
<TooltipIconButton
|
|
483
|
-
tooltip="Remove file"
|
|
484
|
-
className="aui-attachment-tile-remove absolute top-1.5 right-1.5 size-3.5 rounded-full bg-white text-muted-foreground opacity-100 shadow-sm hover:bg-white! [&_svg]:text-black hover:[&_svg]:text-destructive"
|
|
485
|
-
side="top"
|
|
486
|
-
>
|
|
487
|
-
<XIcon className="aui-attachment-remove-icon size-3 dark:stroke-[2.5px]" />
|
|
488
|
-
</TooltipIconButton>
|
|
489
|
-
</AttachmentPrimitive.Remove>
|
|
490
|
-
);
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
export const UserMessageAttachments: FC = () => {
|
|
494
|
-
return (
|
|
495
|
-
<div className="aui-user-message-attachments-end col-span-full col-start-1 row-start-1 flex w-full flex-row justify-end gap-2">
|
|
496
|
-
<MessagePrimitive.Attachments components={{ Attachment: AttachmentUI }} />
|
|
497
|
-
</div>
|
|
498
|
-
);
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
export const ComposerAttachments: FC = () => {
|
|
502
|
-
return (
|
|
503
|
-
<div className="aui-composer-attachments mb-2 flex w-full flex-row items-center gap-2 overflow-x-auto px-1.5 pt-0.5 pb-1 empty:hidden">
|
|
504
|
-
<ComposerPrimitive.Attachments
|
|
505
|
-
components={{ Attachment: AttachmentUI }}
|
|
506
|
-
/>
|
|
507
|
-
</div>
|
|
508
|
-
);
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
export const ComposerAddAttachment: FC = () => {
|
|
512
|
-
return (
|
|
513
|
-
<ComposerPrimitive.AddAttachment asChild>
|
|
514
|
-
<TooltipIconButton
|
|
515
|
-
tooltip="Add Attachment"
|
|
516
|
-
side="bottom"
|
|
517
|
-
variant="ghost"
|
|
518
|
-
size="icon"
|
|
519
|
-
className="aui-composer-add-attachment size-[34px] rounded-full p-1 font-semibold text-xs hover:bg-muted-foreground/15 dark:border-muted-foreground/15 dark:hover:bg-muted-foreground/30"
|
|
520
|
-
aria-label="Add Attachment"
|
|
521
|
-
>
|
|
522
|
-
<PlusIcon className="aui-attachment-add-icon size-5 stroke-[1.5px]" />
|
|
523
|
-
</TooltipIconButton>
|
|
524
|
-
</ComposerPrimitive.AddAttachment>
|
|
525
|
-
);
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
## components/assistant-ui/markdown-text.tsx
|
|
531
|
-
|
|
532
|
-
```tsx
|
|
533
|
-
"use client";
|
|
534
|
-
|
|
535
|
-
import "@assistant-ui/react-markdown/styles/dot.css";
|
|
536
|
-
|
|
537
|
-
import {
|
|
538
|
-
type CodeHeaderProps,
|
|
539
|
-
MarkdownTextPrimitive,
|
|
540
|
-
unstable_memoizeMarkdownComponents as memoizeMarkdownComponents,
|
|
541
|
-
useIsMarkdownCodeBlock,
|
|
542
|
-
} from "@assistant-ui/react-markdown";
|
|
543
|
-
import remarkGfm from "remark-gfm";
|
|
544
|
-
import { type FC, memo, useState } from "react";
|
|
545
|
-
import { CheckIcon, CopyIcon } from "lucide-react";
|
|
546
|
-
|
|
547
|
-
import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
|
|
548
|
-
import { cn } from "@/lib/utils";
|
|
549
|
-
|
|
550
|
-
const MarkdownTextImpl = () => {
|
|
551
|
-
return (
|
|
552
|
-
<MarkdownTextPrimitive
|
|
553
|
-
remarkPlugins={[remarkGfm]}
|
|
554
|
-
className="aui-md"
|
|
555
|
-
components={defaultComponents}
|
|
556
|
-
/>
|
|
557
|
-
);
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
export const MarkdownText = memo(MarkdownTextImpl);
|
|
561
|
-
|
|
562
|
-
const CodeHeader: FC<CodeHeaderProps> = ({ language, code }) => {
|
|
563
|
-
const { isCopied, copyToClipboard } = useCopyToClipboard();
|
|
564
|
-
const onCopy = () => {
|
|
565
|
-
if (!code || isCopied) return;
|
|
566
|
-
copyToClipboard(code);
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
return (
|
|
570
|
-
<div className="aui-code-header-root mt-4 flex items-center justify-between gap-4 rounded-t-lg bg-muted-foreground/15 px-4 py-2 font-semibold text-foreground text-sm dark:bg-muted-foreground/20">
|
|
571
|
-
<span className="aui-code-header-language lowercase [&>span]:text-xs">
|
|
572
|
-
{language}
|
|
573
|
-
</span>
|
|
574
|
-
<TooltipIconButton tooltip="Copy" onClick={onCopy}>
|
|
575
|
-
{!isCopied && <CopyIcon />}
|
|
576
|
-
{isCopied && <CheckIcon />}
|
|
577
|
-
</TooltipIconButton>
|
|
578
|
-
</div>
|
|
579
|
-
);
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
const useCopyToClipboard = ({
|
|
583
|
-
copiedDuration = 3000,
|
|
584
|
-
}: {
|
|
585
|
-
copiedDuration?: number;
|
|
586
|
-
} = {}) => {
|
|
587
|
-
const [isCopied, setIsCopied] = useState<boolean>(false);
|
|
588
|
-
|
|
589
|
-
const copyToClipboard = (value: string) => {
|
|
590
|
-
if (!value) return;
|
|
591
|
-
|
|
592
|
-
navigator.clipboard.writeText(value).then(() => {
|
|
593
|
-
setIsCopied(true);
|
|
594
|
-
setTimeout(() => setIsCopied(false), copiedDuration);
|
|
595
|
-
});
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
return { isCopied, copyToClipboard };
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
const defaultComponents = memoizeMarkdownComponents({
|
|
602
|
-
h1: ({ className, ...props }) => (
|
|
603
|
-
<h1
|
|
604
|
-
className={cn(
|
|
605
|
-
"aui-md-h1 mb-8 scroll-m-20 font-extrabold text-4xl tracking-tight last:mb-0",
|
|
606
|
-
className,
|
|
607
|
-
)}
|
|
608
|
-
{...props}
|
|
609
|
-
/>
|
|
610
|
-
),
|
|
611
|
-
h2: ({ className, ...props }) => (
|
|
612
|
-
<h2
|
|
613
|
-
className={cn(
|
|
614
|
-
"aui-md-h2 mt-8 mb-4 scroll-m-20 font-semibold text-3xl tracking-tight first:mt-0 last:mb-0",
|
|
615
|
-
className,
|
|
616
|
-
)}
|
|
617
|
-
{...props}
|
|
618
|
-
/>
|
|
619
|
-
),
|
|
620
|
-
h3: ({ className, ...props }) => (
|
|
621
|
-
<h3
|
|
622
|
-
className={cn(
|
|
623
|
-
"aui-md-h3 mt-6 mb-4 scroll-m-20 font-semibold text-2xl tracking-tight first:mt-0 last:mb-0",
|
|
624
|
-
className,
|
|
625
|
-
)}
|
|
626
|
-
{...props}
|
|
627
|
-
/>
|
|
628
|
-
),
|
|
629
|
-
h4: ({ className, ...props }) => (
|
|
630
|
-
<h4
|
|
631
|
-
className={cn(
|
|
632
|
-
"aui-md-h4 mt-6 mb-4 scroll-m-20 font-semibold text-xl tracking-tight first:mt-0 last:mb-0",
|
|
633
|
-
className,
|
|
634
|
-
)}
|
|
635
|
-
{...props}
|
|
636
|
-
/>
|
|
637
|
-
),
|
|
638
|
-
h5: ({ className, ...props }) => (
|
|
639
|
-
<h5
|
|
640
|
-
className={cn(
|
|
641
|
-
"aui-md-h5 my-4 font-semibold text-lg first:mt-0 last:mb-0",
|
|
642
|
-
className,
|
|
643
|
-
)}
|
|
644
|
-
{...props}
|
|
645
|
-
/>
|
|
646
|
-
),
|
|
647
|
-
h6: ({ className, ...props }) => (
|
|
648
|
-
<h6
|
|
649
|
-
className={cn(
|
|
650
|
-
"aui-md-h6 my-4 font-semibold first:mt-0 last:mb-0",
|
|
651
|
-
className,
|
|
652
|
-
)}
|
|
653
|
-
{...props}
|
|
654
|
-
/>
|
|
655
|
-
),
|
|
656
|
-
p: ({ className, ...props }) => (
|
|
657
|
-
<p
|
|
658
|
-
className={cn(
|
|
659
|
-
"aui-md-p mt-5 mb-5 leading-7 first:mt-0 last:mb-0",
|
|
660
|
-
className,
|
|
661
|
-
)}
|
|
662
|
-
{...props}
|
|
663
|
-
/>
|
|
664
|
-
),
|
|
665
|
-
a: ({ className, ...props }) => (
|
|
666
|
-
<a
|
|
667
|
-
className={cn(
|
|
668
|
-
"aui-md-a font-medium text-primary underline underline-offset-4",
|
|
669
|
-
className,
|
|
670
|
-
)}
|
|
671
|
-
{...props}
|
|
672
|
-
/>
|
|
673
|
-
),
|
|
674
|
-
blockquote: ({ className, ...props }) => (
|
|
675
|
-
<blockquote
|
|
676
|
-
className={cn("aui-md-blockquote border-l-2 pl-6 italic", className)}
|
|
677
|
-
{...props}
|
|
678
|
-
/>
|
|
679
|
-
),
|
|
680
|
-
ul: ({ className, ...props }) => (
|
|
681
|
-
<ul
|
|
682
|
-
className={cn("aui-md-ul my-5 ml-6 list-disc [&>li]:mt-2", className)}
|
|
683
|
-
{...props}
|
|
684
|
-
/>
|
|
685
|
-
),
|
|
686
|
-
ol: ({ className, ...props }) => (
|
|
687
|
-
<ol
|
|
688
|
-
className={cn("aui-md-ol my-5 ml-6 list-decimal [&>li]:mt-2", className)}
|
|
689
|
-
{...props}
|
|
690
|
-
/>
|
|
691
|
-
),
|
|
692
|
-
hr: ({ className, ...props }) => (
|
|
693
|
-
<hr className={cn("aui-md-hr my-5 border-b", className)} {...props} />
|
|
694
|
-
),
|
|
695
|
-
table: ({ className, ...props }) => (
|
|
696
|
-
<table
|
|
697
|
-
className={cn(
|
|
698
|
-
"aui-md-table my-5 w-full border-separate border-spacing-0 overflow-y-auto",
|
|
699
|
-
className,
|
|
700
|
-
)}
|
|
701
|
-
{...props}
|
|
702
|
-
/>
|
|
703
|
-
),
|
|
704
|
-
th: ({ className, ...props }) => (
|
|
705
|
-
<th
|
|
706
|
-
className={cn(
|
|
707
|
-
"aui-md-th 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",
|
|
708
|
-
className,
|
|
709
|
-
)}
|
|
710
|
-
{...props}
|
|
711
|
-
/>
|
|
712
|
-
),
|
|
713
|
-
td: ({ className, ...props }) => (
|
|
714
|
-
<td
|
|
715
|
-
className={cn(
|
|
716
|
-
"aui-md-td border-b border-l px-4 py-2 text-left last:border-r [[align=center]]:text-center [[align=right]]:text-right",
|
|
717
|
-
className,
|
|
718
|
-
)}
|
|
719
|
-
{...props}
|
|
720
|
-
/>
|
|
721
|
-
),
|
|
722
|
-
tr: ({ className, ...props }) => (
|
|
723
|
-
<tr
|
|
724
|
-
className={cn(
|
|
725
|
-
"aui-md-tr 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",
|
|
726
|
-
className,
|
|
727
|
-
)}
|
|
728
|
-
{...props}
|
|
729
|
-
/>
|
|
730
|
-
),
|
|
731
|
-
sup: ({ className, ...props }) => (
|
|
732
|
-
<sup
|
|
733
|
-
className={cn("aui-md-sup [&>a]:text-xs [&>a]:no-underline", className)}
|
|
734
|
-
{...props}
|
|
735
|
-
/>
|
|
736
|
-
),
|
|
737
|
-
pre: ({ className, ...props }) => (
|
|
738
|
-
<pre
|
|
739
|
-
className={cn(
|
|
740
|
-
"aui-md-pre overflow-x-auto rounded-t-none! rounded-b-lg bg-black p-4 text-white",
|
|
741
|
-
className,
|
|
742
|
-
)}
|
|
743
|
-
{...props}
|
|
744
|
-
/>
|
|
745
|
-
),
|
|
746
|
-
code: function Code({ className, ...props }) {
|
|
747
|
-
const isCodeBlock = useIsMarkdownCodeBlock();
|
|
748
|
-
return (
|
|
749
|
-
<code
|
|
750
|
-
className={cn(
|
|
751
|
-
!isCodeBlock &&
|
|
752
|
-
"aui-md-inline-code rounded border bg-muted font-semibold",
|
|
753
|
-
className,
|
|
754
|
-
)}
|
|
755
|
-
{...props}
|
|
756
|
-
/>
|
|
757
|
-
);
|
|
758
|
-
},
|
|
759
|
-
CodeHeader,
|
|
760
|
-
});
|
|
761
|
-
|
|
762
|
-
```
|
|
763
|
-
|
|
764
|
-
## components/assistant-ui/thread.tsx
|
|
765
|
-
|
|
766
|
-
```tsx
|
|
767
|
-
import {
|
|
768
|
-
ComposerAddAttachment,
|
|
769
|
-
ComposerAttachments,
|
|
770
|
-
UserMessageAttachments,
|
|
771
|
-
} from "@/components/assistant-ui/attachment";
|
|
772
|
-
import { MarkdownText } from "@/components/assistant-ui/markdown-text";
|
|
773
|
-
import { ToolFallback } from "@/components/assistant-ui/tool-fallback";
|
|
774
|
-
import { TooltipIconButton } from "@/components/assistant-ui/tooltip-icon-button";
|
|
775
|
-
import { Button } from "@/components/ui/button";
|
|
776
|
-
import { cn } from "@/lib/utils";
|
|
777
|
-
import {
|
|
778
|
-
ActionBarPrimitive,
|
|
779
|
-
AssistantIf,
|
|
780
|
-
BranchPickerPrimitive,
|
|
781
|
-
ComposerPrimitive,
|
|
782
|
-
ErrorPrimitive,
|
|
783
|
-
MessagePrimitive,
|
|
784
|
-
ThreadPrimitive,
|
|
785
|
-
} from "@assistant-ui/react";
|
|
786
|
-
import {
|
|
787
|
-
ArrowDownIcon,
|
|
788
|
-
ArrowUpIcon,
|
|
789
|
-
CheckIcon,
|
|
790
|
-
ChevronLeftIcon,
|
|
791
|
-
ChevronRightIcon,
|
|
792
|
-
CopyIcon,
|
|
793
|
-
DownloadIcon,
|
|
794
|
-
PencilIcon,
|
|
795
|
-
RefreshCwIcon,
|
|
796
|
-
SquareIcon,
|
|
797
|
-
} from "lucide-react";
|
|
798
|
-
import type { FC } from "react";
|
|
799
|
-
|
|
800
|
-
export const Thread: FC = () => {
|
|
801
|
-
return (
|
|
802
|
-
<ThreadPrimitive.Root
|
|
803
|
-
className="aui-root aui-thread-root @container flex h-full flex-col bg-background"
|
|
804
|
-
style={{
|
|
805
|
-
["--thread-max-width" as string]: "44rem",
|
|
806
|
-
}}
|
|
807
|
-
>
|
|
808
|
-
<ThreadPrimitive.Viewport
|
|
809
|
-
turnAnchor="top"
|
|
810
|
-
className="aui-thread-viewport relative flex flex-1 flex-col overflow-x-auto overflow-y-scroll scroll-smooth px-4 pt-4"
|
|
811
|
-
>
|
|
812
|
-
<AssistantIf condition={({ thread }) => thread.isEmpty}>
|
|
813
|
-
<ThreadWelcome />
|
|
814
|
-
</AssistantIf>
|
|
815
|
-
|
|
816
|
-
<ThreadPrimitive.Messages
|
|
817
|
-
components={{
|
|
818
|
-
UserMessage,
|
|
819
|
-
EditComposer,
|
|
820
|
-
AssistantMessage,
|
|
821
|
-
}}
|
|
822
|
-
/>
|
|
823
|
-
|
|
824
|
-
<ThreadPrimitive.ViewportFooter className="aui-thread-viewport-footer sticky bottom-0 mx-auto mt-auto flex w-full max-w-(--thread-max-width) flex-col gap-4 overflow-visible rounded-t-3xl bg-background pb-4 md:pb-6">
|
|
825
|
-
<ThreadScrollToBottom />
|
|
826
|
-
<Composer />
|
|
827
|
-
</ThreadPrimitive.ViewportFooter>
|
|
828
|
-
</ThreadPrimitive.Viewport>
|
|
829
|
-
</ThreadPrimitive.Root>
|
|
830
|
-
);
|
|
831
|
-
};
|
|
832
|
-
|
|
833
|
-
const ThreadScrollToBottom: FC = () => {
|
|
834
|
-
return (
|
|
835
|
-
<ThreadPrimitive.ScrollToBottom asChild>
|
|
836
|
-
<TooltipIconButton
|
|
837
|
-
tooltip="Scroll to bottom"
|
|
838
|
-
variant="outline"
|
|
839
|
-
className="aui-thread-scroll-to-bottom absolute -top-12 z-10 self-center rounded-full p-4 disabled:invisible dark:bg-background dark:hover:bg-accent"
|
|
840
|
-
>
|
|
841
|
-
<ArrowDownIcon />
|
|
842
|
-
</TooltipIconButton>
|
|
843
|
-
</ThreadPrimitive.ScrollToBottom>
|
|
844
|
-
);
|
|
845
|
-
};
|
|
846
|
-
|
|
847
|
-
const ThreadWelcome: FC = () => {
|
|
848
|
-
return (
|
|
849
|
-
<div className="aui-thread-welcome-root mx-auto my-auto flex w-full max-w-(--thread-max-width) grow flex-col">
|
|
850
|
-
<div className="aui-thread-welcome-center flex w-full grow flex-col items-center justify-center">
|
|
851
|
-
<div className="aui-thread-welcome-message flex size-full flex-col justify-center px-4">
|
|
852
|
-
<h1 className="aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in font-semibold text-2xl duration-200">
|
|
853
|
-
Hello there!
|
|
854
|
-
</h1>
|
|
855
|
-
<p className="aui-thread-welcome-message-inner fade-in slide-in-from-bottom-1 animate-in text-muted-foreground text-xl delay-75 duration-200">
|
|
856
|
-
How can I help you today?
|
|
857
|
-
</p>
|
|
858
|
-
</div>
|
|
859
|
-
</div>
|
|
860
|
-
<ThreadSuggestions />
|
|
861
|
-
</div>
|
|
862
|
-
);
|
|
863
|
-
};
|
|
864
|
-
|
|
865
|
-
const SUGGESTIONS = [
|
|
866
|
-
{
|
|
867
|
-
title: "What's the weather",
|
|
868
|
-
label: "in San Francisco?",
|
|
869
|
-
prompt: "What's the weather in San Francisco?",
|
|
870
|
-
},
|
|
871
|
-
{
|
|
872
|
-
title: "Explain React hooks",
|
|
873
|
-
label: "like useState and useEffect",
|
|
874
|
-
prompt: "Explain React hooks like useState and useEffect",
|
|
875
|
-
},
|
|
876
|
-
] as const;
|
|
877
|
-
|
|
878
|
-
const ThreadSuggestions: FC = () => {
|
|
879
|
-
return (
|
|
880
|
-
<div className="aui-thread-welcome-suggestions grid w-full @md:grid-cols-2 gap-2 pb-4">
|
|
881
|
-
{SUGGESTIONS.map((suggestion, index) => (
|
|
882
|
-
<div
|
|
883
|
-
key={suggestion.prompt}
|
|
884
|
-
className="aui-thread-welcome-suggestion-display fade-in slide-in-from-bottom-2 @md:nth-[n+3]:block nth-[n+3]:hidden animate-in fill-mode-both duration-200"
|
|
885
|
-
style={{ animationDelay: `${100 + index * 50}ms` }}
|
|
886
|
-
>
|
|
887
|
-
<ThreadPrimitive.Suggestion prompt={suggestion.prompt} send asChild>
|
|
888
|
-
<Button
|
|
889
|
-
variant="ghost"
|
|
890
|
-
className="aui-thread-welcome-suggestion h-auto w-full @md:flex-col flex-wrap items-start justify-start gap-1 rounded-2xl border px-4 py-3 text-left text-sm transition-colors hover:bg-muted"
|
|
891
|
-
aria-label={suggestion.prompt}
|
|
892
|
-
>
|
|
893
|
-
<span className="aui-thread-welcome-suggestion-text-1 font-medium">
|
|
894
|
-
{suggestion.title}
|
|
895
|
-
</span>
|
|
896
|
-
<span className="aui-thread-welcome-suggestion-text-2 text-muted-foreground">
|
|
897
|
-
{suggestion.label}
|
|
898
|
-
</span>
|
|
899
|
-
</Button>
|
|
900
|
-
</ThreadPrimitive.Suggestion>
|
|
901
|
-
</div>
|
|
902
|
-
))}
|
|
903
|
-
</div>
|
|
904
|
-
);
|
|
905
|
-
};
|
|
906
|
-
|
|
907
|
-
const Composer: FC = () => {
|
|
908
|
-
return (
|
|
909
|
-
<ComposerPrimitive.Root className="aui-composer-root relative flex w-full flex-col">
|
|
910
|
-
<ComposerPrimitive.AttachmentDropzone className="aui-composer-attachment-dropzone flex w-full flex-col rounded-2xl border border-input bg-background px-1 pt-2 outline-none transition-shadow has-[textarea:focus-visible]:border-ring has-[textarea:focus-visible]:ring-2 has-[textarea:focus-visible]:ring-ring/20 data-[dragging=true]:border-ring data-[dragging=true]:border-dashed data-[dragging=true]:bg-accent/50">
|
|
911
|
-
<ComposerAttachments />
|
|
912
|
-
<ComposerPrimitive.Input
|
|
913
|
-
placeholder="Send a message..."
|
|
914
|
-
className="aui-composer-input mb-1 max-h-32 min-h-14 w-full resize-none bg-transparent px-4 pt-2 pb-3 text-sm outline-none placeholder:text-muted-foreground focus-visible:ring-0"
|
|
915
|
-
rows={1}
|
|
916
|
-
autoFocus
|
|
917
|
-
aria-label="Message input"
|
|
918
|
-
/>
|
|
919
|
-
<ComposerAction />
|
|
920
|
-
</ComposerPrimitive.AttachmentDropzone>
|
|
921
|
-
</ComposerPrimitive.Root>
|
|
922
|
-
);
|
|
923
|
-
};
|
|
924
|
-
|
|
925
|
-
const ComposerAction: FC = () => {
|
|
926
|
-
return (
|
|
927
|
-
<div className="aui-composer-action-wrapper relative mx-2 mb-2 flex items-center justify-between">
|
|
928
|
-
<ComposerAddAttachment />
|
|
929
|
-
|
|
930
|
-
<AssistantIf condition={({ thread }) => !thread.isRunning}>
|
|
931
|
-
<ComposerPrimitive.Send asChild>
|
|
932
|
-
<TooltipIconButton
|
|
933
|
-
tooltip="Send message"
|
|
934
|
-
side="bottom"
|
|
935
|
-
type="submit"
|
|
936
|
-
variant="default"
|
|
937
|
-
size="icon"
|
|
938
|
-
className="aui-composer-send size-8 rounded-full"
|
|
939
|
-
aria-label="Send message"
|
|
940
|
-
>
|
|
941
|
-
<ArrowUpIcon className="aui-composer-send-icon size-4" />
|
|
942
|
-
</TooltipIconButton>
|
|
943
|
-
</ComposerPrimitive.Send>
|
|
944
|
-
</AssistantIf>
|
|
945
|
-
|
|
946
|
-
<AssistantIf condition={({ thread }) => thread.isRunning}>
|
|
947
|
-
<ComposerPrimitive.Cancel asChild>
|
|
948
|
-
<Button
|
|
949
|
-
type="button"
|
|
950
|
-
variant="default"
|
|
951
|
-
size="icon"
|
|
952
|
-
className="aui-composer-cancel size-8 rounded-full"
|
|
953
|
-
aria-label="Stop generating"
|
|
954
|
-
>
|
|
955
|
-
<SquareIcon className="aui-composer-cancel-icon size-3 fill-current" />
|
|
956
|
-
</Button>
|
|
957
|
-
</ComposerPrimitive.Cancel>
|
|
958
|
-
</AssistantIf>
|
|
959
|
-
</div>
|
|
960
|
-
);
|
|
961
|
-
};
|
|
962
|
-
|
|
963
|
-
const MessageError: FC = () => {
|
|
964
|
-
return (
|
|
965
|
-
<MessagePrimitive.Error>
|
|
966
|
-
<ErrorPrimitive.Root className="aui-message-error-root mt-2 rounded-md border border-destructive bg-destructive/10 p-3 text-destructive text-sm dark:bg-destructive/5 dark:text-red-200">
|
|
967
|
-
<ErrorPrimitive.Message className="aui-message-error-message line-clamp-2" />
|
|
968
|
-
</ErrorPrimitive.Root>
|
|
969
|
-
</MessagePrimitive.Error>
|
|
970
|
-
);
|
|
971
|
-
};
|
|
972
|
-
|
|
973
|
-
const AssistantMessage: FC = () => {
|
|
974
|
-
return (
|
|
975
|
-
<MessagePrimitive.Root
|
|
976
|
-
className="aui-assistant-message-root fade-in slide-in-from-bottom-1 relative mx-auto w-full max-w-(--thread-max-width) animate-in py-3 duration-150"
|
|
977
|
-
data-role="assistant"
|
|
978
|
-
>
|
|
979
|
-
<div className="aui-assistant-message-content wrap-break-word px-2 text-foreground leading-relaxed">
|
|
980
|
-
<MessagePrimitive.Parts
|
|
981
|
-
components={{
|
|
982
|
-
Text: MarkdownText,
|
|
983
|
-
tools: { Fallback: ToolFallback },
|
|
984
|
-
}}
|
|
985
|
-
/>
|
|
986
|
-
<MessageError />
|
|
987
|
-
</div>
|
|
988
|
-
|
|
989
|
-
<div className="aui-assistant-message-footer mt-1 ml-2 flex">
|
|
990
|
-
<BranchPicker />
|
|
991
|
-
<AssistantActionBar />
|
|
992
|
-
</div>
|
|
993
|
-
</MessagePrimitive.Root>
|
|
994
|
-
);
|
|
995
|
-
};
|
|
996
|
-
|
|
997
|
-
const AssistantActionBar: FC = () => {
|
|
998
|
-
return (
|
|
999
|
-
<ActionBarPrimitive.Root
|
|
1000
|
-
hideWhenRunning
|
|
1001
|
-
autohide="not-last"
|
|
1002
|
-
autohideFloat="single-branch"
|
|
1003
|
-
className="aui-assistant-action-bar-root col-start-3 row-start-2 -ml-1 flex gap-1 text-muted-foreground data-floating:absolute data-floating:rounded-md data-floating:border data-floating:bg-background data-floating:p-1 data-floating:shadow-sm"
|
|
1004
|
-
>
|
|
1005
|
-
<ActionBarPrimitive.Copy asChild>
|
|
1006
|
-
<TooltipIconButton tooltip="Copy">
|
|
1007
|
-
<AssistantIf condition={({ message }) => message.isCopied}>
|
|
1008
|
-
<CheckIcon />
|
|
1009
|
-
</AssistantIf>
|
|
1010
|
-
<AssistantIf condition={({ message }) => !message.isCopied}>
|
|
1011
|
-
<CopyIcon />
|
|
1012
|
-
</AssistantIf>
|
|
1013
|
-
</TooltipIconButton>
|
|
1014
|
-
</ActionBarPrimitive.Copy>
|
|
1015
|
-
<ActionBarPrimitive.ExportMarkdown asChild>
|
|
1016
|
-
<TooltipIconButton tooltip="Export as Markdown">
|
|
1017
|
-
<DownloadIcon />
|
|
1018
|
-
</TooltipIconButton>
|
|
1019
|
-
</ActionBarPrimitive.ExportMarkdown>
|
|
1020
|
-
<ActionBarPrimitive.Reload asChild>
|
|
1021
|
-
<TooltipIconButton tooltip="Refresh">
|
|
1022
|
-
<RefreshCwIcon />
|
|
1023
|
-
</TooltipIconButton>
|
|
1024
|
-
</ActionBarPrimitive.Reload>
|
|
1025
|
-
</ActionBarPrimitive.Root>
|
|
1026
|
-
);
|
|
1027
|
-
};
|
|
1028
|
-
|
|
1029
|
-
const UserMessage: FC = () => {
|
|
1030
|
-
return (
|
|
1031
|
-
<MessagePrimitive.Root
|
|
1032
|
-
className="aui-user-message-root fade-in slide-in-from-bottom-1 mx-auto grid w-full max-w-(--thread-max-width) animate-in auto-rows-auto grid-cols-[minmax(72px,1fr)_auto] content-start gap-y-2 px-2 py-3 duration-150 [&:where(>*)]:col-start-2"
|
|
1033
|
-
data-role="user"
|
|
1034
|
-
>
|
|
1035
|
-
<UserMessageAttachments />
|
|
1036
|
-
|
|
1037
|
-
<div className="aui-user-message-content-wrapper relative col-start-2 min-w-0">
|
|
1038
|
-
<div className="aui-user-message-content wrap-break-word rounded-2xl bg-muted px-4 py-2.5 text-foreground">
|
|
1039
|
-
<MessagePrimitive.Parts />
|
|
1040
|
-
</div>
|
|
1041
|
-
<div className="aui-user-action-bar-wrapper absolute top-1/2 left-0 -translate-x-full -translate-y-1/2 pr-2">
|
|
1042
|
-
<UserActionBar />
|
|
1043
|
-
</div>
|
|
1044
|
-
</div>
|
|
1045
|
-
|
|
1046
|
-
<BranchPicker className="aui-user-branch-picker col-span-full col-start-1 row-start-3 -mr-1 justify-end" />
|
|
1047
|
-
</MessagePrimitive.Root>
|
|
1048
|
-
);
|
|
1049
|
-
};
|
|
1050
|
-
|
|
1051
|
-
const UserActionBar: FC = () => {
|
|
1052
|
-
return (
|
|
1053
|
-
<ActionBarPrimitive.Root
|
|
1054
|
-
hideWhenRunning
|
|
1055
|
-
autohide="not-last"
|
|
1056
|
-
className="aui-user-action-bar-root flex flex-col items-end"
|
|
1057
|
-
>
|
|
1058
|
-
<ActionBarPrimitive.Edit asChild>
|
|
1059
|
-
<TooltipIconButton tooltip="Edit" className="aui-user-action-edit p-4">
|
|
1060
|
-
<PencilIcon />
|
|
1061
|
-
</TooltipIconButton>
|
|
1062
|
-
</ActionBarPrimitive.Edit>
|
|
1063
|
-
</ActionBarPrimitive.Root>
|
|
1064
|
-
);
|
|
1065
|
-
};
|
|
1066
|
-
|
|
1067
|
-
const EditComposer: FC = () => {
|
|
1068
|
-
return (
|
|
1069
|
-
<MessagePrimitive.Root className="aui-edit-composer-wrapper mx-auto flex w-full max-w-(--thread-max-width) flex-col px-2 py-3">
|
|
1070
|
-
<ComposerPrimitive.Root className="aui-edit-composer-root ml-auto flex w-full max-w-[85%] flex-col rounded-2xl bg-muted">
|
|
1071
|
-
<ComposerPrimitive.Input
|
|
1072
|
-
className="aui-edit-composer-input min-h-14 w-full resize-none bg-transparent p-4 text-foreground text-sm outline-none"
|
|
1073
|
-
autoFocus
|
|
1074
|
-
/>
|
|
1075
|
-
<div className="aui-edit-composer-footer mx-3 mb-3 flex items-center gap-2 self-end">
|
|
1076
|
-
<ComposerPrimitive.Cancel asChild>
|
|
1077
|
-
<Button variant="ghost" size="sm">
|
|
1078
|
-
Cancel
|
|
1079
|
-
</Button>
|
|
1080
|
-
</ComposerPrimitive.Cancel>
|
|
1081
|
-
<ComposerPrimitive.Send asChild>
|
|
1082
|
-
<Button size="sm">Update</Button>
|
|
1083
|
-
</ComposerPrimitive.Send>
|
|
1084
|
-
</div>
|
|
1085
|
-
</ComposerPrimitive.Root>
|
|
1086
|
-
</MessagePrimitive.Root>
|
|
1087
|
-
);
|
|
1088
|
-
};
|
|
1089
|
-
|
|
1090
|
-
const BranchPicker: FC<BranchPickerPrimitive.Root.Props> = ({
|
|
1091
|
-
className,
|
|
1092
|
-
...rest
|
|
1093
|
-
}) => {
|
|
1094
|
-
return (
|
|
1095
|
-
<BranchPickerPrimitive.Root
|
|
1096
|
-
hideWhenSingleBranch
|
|
1097
|
-
className={cn(
|
|
1098
|
-
"aui-branch-picker-root mr-2 -ml-2 inline-flex items-center text-muted-foreground text-xs",
|
|
1099
|
-
className,
|
|
1100
|
-
)}
|
|
1101
|
-
{...rest}
|
|
1102
|
-
>
|
|
1103
|
-
<BranchPickerPrimitive.Previous asChild>
|
|
1104
|
-
<TooltipIconButton tooltip="Previous">
|
|
1105
|
-
<ChevronLeftIcon />
|
|
1106
|
-
</TooltipIconButton>
|
|
1107
|
-
</BranchPickerPrimitive.Previous>
|
|
1108
|
-
<span className="aui-branch-picker-state font-medium">
|
|
1109
|
-
<BranchPickerPrimitive.Number /> / <BranchPickerPrimitive.Count />
|
|
1110
|
-
</span>
|
|
1111
|
-
<BranchPickerPrimitive.Next asChild>
|
|
1112
|
-
<TooltipIconButton tooltip="Next">
|
|
1113
|
-
<ChevronRightIcon />
|
|
1114
|
-
</TooltipIconButton>
|
|
1115
|
-
</BranchPickerPrimitive.Next>
|
|
1116
|
-
</BranchPickerPrimitive.Root>
|
|
1117
|
-
);
|
|
1118
|
-
};
|
|
1119
|
-
|
|
1120
|
-
```
|
|
1121
|
-
|
|
1122
|
-
## components/assistant-ui/tool-fallback.tsx
|
|
1123
|
-
|
|
1124
|
-
```tsx
|
|
1125
|
-
import type { ToolCallMessagePartComponent } from "@assistant-ui/react";
|
|
1126
|
-
import {
|
|
1127
|
-
CheckIcon,
|
|
1128
|
-
ChevronDownIcon,
|
|
1129
|
-
ChevronUpIcon,
|
|
1130
|
-
XCircleIcon,
|
|
1131
|
-
} from "lucide-react";
|
|
1132
|
-
import { useState } from "react";
|
|
1133
|
-
import { Button } from "@/components/ui/button";
|
|
1134
|
-
import { cn } from "@/lib/utils";
|
|
1135
|
-
|
|
1136
|
-
export const ToolFallback: ToolCallMessagePartComponent = ({
|
|
1137
|
-
toolName,
|
|
1138
|
-
argsText,
|
|
1139
|
-
result,
|
|
1140
|
-
status,
|
|
1141
|
-
}) => {
|
|
1142
|
-
const [isCollapsed, setIsCollapsed] = useState(true);
|
|
1143
|
-
|
|
1144
|
-
const isCancelled =
|
|
1145
|
-
status?.type === "incomplete" && status.reason === "cancelled";
|
|
1146
|
-
const cancelledReason =
|
|
1147
|
-
isCancelled && status.error
|
|
1148
|
-
? typeof status.error === "string"
|
|
1149
|
-
? status.error
|
|
1150
|
-
: JSON.stringify(status.error)
|
|
1151
|
-
: null;
|
|
1152
|
-
|
|
1153
|
-
return (
|
|
1154
|
-
<div
|
|
1155
|
-
className={cn(
|
|
1156
|
-
"aui-tool-fallback-root mb-4 flex w-full flex-col gap-3 rounded-lg border py-3",
|
|
1157
|
-
isCancelled && "border-muted-foreground/30 bg-muted/30",
|
|
1158
|
-
)}
|
|
1159
|
-
>
|
|
1160
|
-
<div className="aui-tool-fallback-header flex items-center gap-2 px-4">
|
|
1161
|
-
{isCancelled ? (
|
|
1162
|
-
<XCircleIcon className="aui-tool-fallback-icon size-4 text-muted-foreground" />
|
|
1163
|
-
) : (
|
|
1164
|
-
<CheckIcon className="aui-tool-fallback-icon size-4" />
|
|
1165
|
-
)}
|
|
1166
|
-
<p
|
|
1167
|
-
className={cn(
|
|
1168
|
-
"aui-tool-fallback-title grow",
|
|
1169
|
-
isCancelled && "text-muted-foreground line-through",
|
|
1170
|
-
)}
|
|
1171
|
-
>
|
|
1172
|
-
{isCancelled ? "Cancelled tool: " : "Used tool: "}
|
|
1173
|
-
<b>{toolName}</b>
|
|
1174
|
-
</p>
|
|
1175
|
-
<Button onClick={() => setIsCollapsed(!isCollapsed)}>
|
|
1176
|
-
{isCollapsed ? <ChevronUpIcon /> : <ChevronDownIcon />}
|
|
1177
|
-
</Button>
|
|
1178
|
-
</div>
|
|
1179
|
-
{!isCollapsed && (
|
|
1180
|
-
<div className="aui-tool-fallback-content flex flex-col gap-2 border-t pt-2">
|
|
1181
|
-
{cancelledReason && (
|
|
1182
|
-
<div className="aui-tool-fallback-cancelled-root px-4">
|
|
1183
|
-
<p className="aui-tool-fallback-cancelled-header font-semibold text-muted-foreground">
|
|
1184
|
-
Cancelled reason:
|
|
1185
|
-
</p>
|
|
1186
|
-
<p className="aui-tool-fallback-cancelled-reason text-muted-foreground">
|
|
1187
|
-
{cancelledReason}
|
|
1188
|
-
</p>
|
|
1189
|
-
</div>
|
|
1190
|
-
)}
|
|
1191
|
-
<div
|
|
1192
|
-
className={cn(
|
|
1193
|
-
"aui-tool-fallback-args-root px-4",
|
|
1194
|
-
isCancelled && "opacity-60",
|
|
1195
|
-
)}
|
|
1196
|
-
>
|
|
1197
|
-
<pre className="aui-tool-fallback-args-value whitespace-pre-wrap">
|
|
1198
|
-
{argsText}
|
|
1199
|
-
</pre>
|
|
1200
|
-
</div>
|
|
1201
|
-
{!isCancelled && result !== undefined && (
|
|
1202
|
-
<div className="aui-tool-fallback-result-root border-t border-dashed px-4 pt-2">
|
|
1203
|
-
<p className="aui-tool-fallback-result-header font-semibold">
|
|
1204
|
-
Result:
|
|
1205
|
-
</p>
|
|
1206
|
-
<pre className="aui-tool-fallback-result-content whitespace-pre-wrap">
|
|
1207
|
-
{typeof result === "string"
|
|
1208
|
-
? result
|
|
1209
|
-
: JSON.stringify(result, null, 2)}
|
|
1210
|
-
</pre>
|
|
1211
|
-
</div>
|
|
1212
|
-
)}
|
|
1213
|
-
</div>
|
|
1214
|
-
)}
|
|
1215
|
-
</div>
|
|
1216
|
-
);
|
|
1217
|
-
};
|
|
1218
|
-
|
|
1219
|
-
```
|
|
1220
|
-
|
|
1221
|
-
## components/assistant-ui/tooltip-icon-button.tsx
|
|
1222
|
-
|
|
1223
|
-
```tsx
|
|
1224
|
-
"use client";
|
|
1225
|
-
|
|
1226
|
-
import { ComponentPropsWithRef, forwardRef } from "react";
|
|
1227
|
-
import { Slottable } from "@radix-ui/react-slot";
|
|
1228
|
-
|
|
1229
|
-
import {
|
|
1230
|
-
Tooltip,
|
|
1231
|
-
TooltipContent,
|
|
1232
|
-
TooltipTrigger,
|
|
1233
|
-
} from "@/components/ui/tooltip";
|
|
1234
|
-
import { Button } from "@/components/ui/button";
|
|
1235
|
-
import { cn } from "@/lib/utils";
|
|
1236
|
-
|
|
1237
|
-
export type TooltipIconButtonProps = ComponentPropsWithRef<typeof Button> & {
|
|
1238
|
-
tooltip: string;
|
|
1239
|
-
side?: "top" | "bottom" | "left" | "right";
|
|
1240
|
-
};
|
|
1241
|
-
|
|
1242
|
-
export const TooltipIconButton = forwardRef<
|
|
1243
|
-
HTMLButtonElement,
|
|
1244
|
-
TooltipIconButtonProps
|
|
1245
|
-
>(({ children, tooltip, side = "bottom", className, ...rest }, ref) => {
|
|
1246
|
-
return (
|
|
1247
|
-
<Tooltip>
|
|
1248
|
-
<TooltipTrigger asChild>
|
|
1249
|
-
<Button
|
|
1250
|
-
variant="ghost"
|
|
1251
|
-
size="icon"
|
|
1252
|
-
{...rest}
|
|
1253
|
-
className={cn("aui-button-icon size-6 p-1", className)}
|
|
1254
|
-
ref={ref}
|
|
1255
|
-
>
|
|
1256
|
-
<Slottable>{children}</Slottable>
|
|
1257
|
-
<span className="aui-sr-only sr-only">{tooltip}</span>
|
|
1258
|
-
</Button>
|
|
1259
|
-
</TooltipTrigger>
|
|
1260
|
-
<TooltipContent side={side}>{tooltip}</TooltipContent>
|
|
1261
|
-
</Tooltip>
|
|
1262
|
-
);
|
|
1263
|
-
});
|
|
1264
|
-
|
|
1265
|
-
TooltipIconButton.displayName = "TooltipIconButton";
|
|
1266
|
-
|
|
1267
|
-
```
|
|
1268
|
-
|
|
1269
|
-
## components/ui/avatar.tsx
|
|
1270
|
-
|
|
1271
|
-
```tsx
|
|
1272
|
-
"use client";
|
|
1273
|
-
|
|
1274
|
-
import * as React from "react";
|
|
1275
|
-
import * as AvatarPrimitive from "@radix-ui/react-avatar";
|
|
1276
|
-
|
|
1277
|
-
import { cn } from "@/lib/utils";
|
|
1278
|
-
|
|
1279
|
-
function Avatar({
|
|
1280
|
-
className,
|
|
1281
|
-
...props
|
|
1282
|
-
}: React.ComponentProps<typeof AvatarPrimitive.Root>) {
|
|
1283
|
-
return (
|
|
1284
|
-
<AvatarPrimitive.Root
|
|
1285
|
-
data-slot="avatar"
|
|
1286
|
-
className={cn(
|
|
1287
|
-
"relative flex size-8 shrink-0 overflow-hidden rounded-full",
|
|
1288
|
-
className,
|
|
1289
|
-
)}
|
|
1290
|
-
{...props}
|
|
1291
|
-
/>
|
|
1292
|
-
);
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
function AvatarImage({
|
|
1296
|
-
className,
|
|
1297
|
-
...props
|
|
1298
|
-
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
|
|
1299
|
-
return (
|
|
1300
|
-
<AvatarPrimitive.Image
|
|
1301
|
-
data-slot="avatar-image"
|
|
1302
|
-
className={cn("aspect-square size-full", className)}
|
|
1303
|
-
{...props}
|
|
1304
|
-
/>
|
|
1305
|
-
);
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
function AvatarFallback({
|
|
1309
|
-
className,
|
|
1310
|
-
...props
|
|
1311
|
-
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
|
|
1312
|
-
return (
|
|
1313
|
-
<AvatarPrimitive.Fallback
|
|
1314
|
-
data-slot="avatar-fallback"
|
|
1315
|
-
className={cn(
|
|
1316
|
-
"flex size-full items-center justify-center rounded-full bg-muted",
|
|
1317
|
-
className,
|
|
1318
|
-
)}
|
|
1319
|
-
{...props}
|
|
1320
|
-
/>
|
|
1321
|
-
);
|
|
1322
|
-
}
|
|
1323
|
-
|
|
1324
|
-
export { Avatar, AvatarImage, AvatarFallback };
|
|
1325
|
-
|
|
1326
|
-
```
|
|
1327
|
-
|
|
1328
|
-
## components/ui/button.tsx
|
|
1329
|
-
|
|
1330
|
-
```tsx
|
|
1331
|
-
import * as React from "react";
|
|
1332
|
-
import { Slot } from "@radix-ui/react-slot";
|
|
1333
|
-
import { cva, type VariantProps } from "class-variance-authority";
|
|
1334
|
-
|
|
1335
|
-
import { cn } from "@/lib/utils";
|
|
1336
|
-
|
|
1337
|
-
const buttonVariants = cva(
|
|
1338
|
-
"inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-md font-medium text-sm outline-none transition-all focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
1339
|
-
{
|
|
1340
|
-
variants: {
|
|
1341
|
-
variant: {
|
|
1342
|
-
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
1343
|
-
destructive:
|
|
1344
|
-
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40",
|
|
1345
|
-
outline:
|
|
1346
|
-
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
1347
|
-
secondary:
|
|
1348
|
-
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
1349
|
-
ghost:
|
|
1350
|
-
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
1351
|
-
link: "text-primary underline-offset-4 hover:underline",
|
|
1352
|
-
},
|
|
1353
|
-
size: {
|
|
1354
|
-
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
1355
|
-
sm: "h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",
|
|
1356
|
-
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
1357
|
-
icon: "size-9",
|
|
1358
|
-
"icon-sm": "size-8",
|
|
1359
|
-
"icon-lg": "size-10",
|
|
1360
|
-
},
|
|
1361
|
-
},
|
|
1362
|
-
defaultVariants: {
|
|
1363
|
-
variant: "default",
|
|
1364
|
-
size: "default",
|
|
1365
|
-
},
|
|
1366
|
-
},
|
|
1367
|
-
);
|
|
1368
|
-
|
|
1369
|
-
function Button({
|
|
1370
|
-
className,
|
|
1371
|
-
variant = "default",
|
|
1372
|
-
size = "default",
|
|
1373
|
-
asChild = false,
|
|
1374
|
-
...props
|
|
1375
|
-
}: React.ComponentProps<"button"> &
|
|
1376
|
-
VariantProps<typeof buttonVariants> & {
|
|
1377
|
-
asChild?: boolean;
|
|
1378
|
-
}) {
|
|
1379
|
-
const Comp = asChild ? Slot : "button";
|
|
1380
|
-
|
|
1381
|
-
return (
|
|
1382
|
-
<Comp
|
|
1383
|
-
data-slot="button"
|
|
1384
|
-
data-variant={variant}
|
|
1385
|
-
data-size={size}
|
|
1386
|
-
className={cn(buttonVariants({ variant, size, className }))}
|
|
1387
|
-
{...props}
|
|
1388
|
-
/>
|
|
1389
|
-
);
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
export { Button, buttonVariants };
|
|
1393
|
-
|
|
1394
|
-
```
|
|
1395
|
-
|
|
1396
|
-
## components/ui/dialog.tsx
|
|
1397
|
-
|
|
1398
|
-
```tsx
|
|
1399
|
-
"use client";
|
|
1400
|
-
|
|
1401
|
-
import * as React from "react";
|
|
1402
|
-
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
1403
|
-
import { XIcon } from "lucide-react";
|
|
1404
|
-
|
|
1405
|
-
import { cn } from "@/lib/utils";
|
|
1406
|
-
|
|
1407
|
-
function Dialog({
|
|
1408
|
-
...props
|
|
1409
|
-
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
|
1410
|
-
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
function DialogTrigger({
|
|
1414
|
-
...props
|
|
1415
|
-
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
|
1416
|
-
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
|
|
1417
|
-
}
|
|
1418
|
-
|
|
1419
|
-
function DialogPortal({
|
|
1420
|
-
...props
|
|
1421
|
-
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
|
1422
|
-
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
function DialogClose({
|
|
1426
|
-
...props
|
|
1427
|
-
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
|
1428
|
-
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
function DialogOverlay({
|
|
1432
|
-
className,
|
|
1433
|
-
...props
|
|
1434
|
-
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
|
1435
|
-
return (
|
|
1436
|
-
<DialogPrimitive.Overlay
|
|
1437
|
-
data-slot="dialog-overlay"
|
|
1438
|
-
className={cn(
|
|
1439
|
-
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=open]:animate-in",
|
|
1440
|
-
className,
|
|
1441
|
-
)}
|
|
1442
|
-
{...props}
|
|
1443
|
-
/>
|
|
1444
|
-
);
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
function DialogContent({
|
|
1448
|
-
className,
|
|
1449
|
-
children,
|
|
1450
|
-
showCloseButton = true,
|
|
1451
|
-
...props
|
|
1452
|
-
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
|
1453
|
-
showCloseButton?: boolean;
|
|
1454
|
-
}) {
|
|
1455
|
-
return (
|
|
1456
|
-
<DialogPortal data-slot="dialog-portal">
|
|
1457
|
-
<DialogOverlay />
|
|
1458
|
-
<DialogPrimitive.Content
|
|
1459
|
-
data-slot="dialog-content"
|
|
1460
|
-
className={cn(
|
|
1461
|
-
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg outline-none duration-200 data-[state=closed]:animate-out data-[state=open]:animate-in sm:max-w-lg",
|
|
1462
|
-
className,
|
|
1463
|
-
)}
|
|
1464
|
-
{...props}
|
|
1465
|
-
>
|
|
1466
|
-
{children}
|
|
1467
|
-
{showCloseButton && (
|
|
1468
|
-
<DialogPrimitive.Close
|
|
1469
|
-
data-slot="dialog-close"
|
|
1470
|
-
className="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-hidden focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0"
|
|
1471
|
-
>
|
|
1472
|
-
<XIcon />
|
|
1473
|
-
<span className="sr-only">Close</span>
|
|
1474
|
-
</DialogPrimitive.Close>
|
|
1475
|
-
)}
|
|
1476
|
-
</DialogPrimitive.Content>
|
|
1477
|
-
</DialogPortal>
|
|
1478
|
-
);
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
1482
|
-
return (
|
|
1483
|
-
<div
|
|
1484
|
-
data-slot="dialog-header"
|
|
1485
|
-
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
|
1486
|
-
{...props}
|
|
1487
|
-
/>
|
|
1488
|
-
);
|
|
1489
|
-
}
|
|
1490
|
-
|
|
1491
|
-
function DialogFooter({ className, ...props }: React.ComponentProps<"div">) {
|
|
1492
|
-
return (
|
|
1493
|
-
<div
|
|
1494
|
-
data-slot="dialog-footer"
|
|
1495
|
-
className={cn(
|
|
1496
|
-
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
|
1497
|
-
className,
|
|
1498
|
-
)}
|
|
1499
|
-
{...props}
|
|
1500
|
-
/>
|
|
1501
|
-
);
|
|
1502
|
-
}
|
|
1503
|
-
|
|
1504
|
-
function DialogTitle({
|
|
1505
|
-
className,
|
|
1506
|
-
...props
|
|
1507
|
-
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
|
1508
|
-
return (
|
|
1509
|
-
<DialogPrimitive.Title
|
|
1510
|
-
data-slot="dialog-title"
|
|
1511
|
-
className={cn("font-semibold text-lg leading-none", className)}
|
|
1512
|
-
{...props}
|
|
1513
|
-
/>
|
|
1514
|
-
);
|
|
1515
|
-
}
|
|
1516
|
-
|
|
1517
|
-
function DialogDescription({
|
|
1518
|
-
className,
|
|
1519
|
-
...props
|
|
1520
|
-
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
|
1521
|
-
return (
|
|
1522
|
-
<DialogPrimitive.Description
|
|
1523
|
-
data-slot="dialog-description"
|
|
1524
|
-
className={cn("text-muted-foreground text-sm", className)}
|
|
1525
|
-
{...props}
|
|
1526
|
-
/>
|
|
1527
|
-
);
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
export {
|
|
1531
|
-
Dialog,
|
|
1532
|
-
DialogClose,
|
|
1533
|
-
DialogContent,
|
|
1534
|
-
DialogDescription,
|
|
1535
|
-
DialogFooter,
|
|
1536
|
-
DialogHeader,
|
|
1537
|
-
DialogOverlay,
|
|
1538
|
-
DialogPortal,
|
|
1539
|
-
DialogTitle,
|
|
1540
|
-
DialogTrigger,
|
|
1541
|
-
};
|
|
1542
|
-
|
|
1543
|
-
```
|
|
1544
|
-
|
|
1545
|
-
## components/ui/tooltip.tsx
|
|
1546
|
-
|
|
1547
|
-
```tsx
|
|
1548
|
-
"use client";
|
|
1549
|
-
|
|
1550
|
-
import * as React from "react";
|
|
1551
|
-
import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
1552
|
-
|
|
1553
|
-
import { cn } from "@/lib/utils";
|
|
1554
|
-
|
|
1555
|
-
function TooltipProvider({
|
|
1556
|
-
delayDuration = 0,
|
|
1557
|
-
...props
|
|
1558
|
-
}: React.ComponentProps<typeof TooltipPrimitive.Provider>) {
|
|
1559
|
-
return (
|
|
1560
|
-
<TooltipPrimitive.Provider
|
|
1561
|
-
data-slot="tooltip-provider"
|
|
1562
|
-
delayDuration={delayDuration}
|
|
1563
|
-
{...props}
|
|
1564
|
-
/>
|
|
1565
|
-
);
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
function Tooltip({
|
|
1569
|
-
...props
|
|
1570
|
-
}: React.ComponentProps<typeof TooltipPrimitive.Root>) {
|
|
1571
|
-
return (
|
|
1572
|
-
<TooltipProvider>
|
|
1573
|
-
<TooltipPrimitive.Root data-slot="tooltip" {...props} />
|
|
1574
|
-
</TooltipProvider>
|
|
1575
|
-
);
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
function TooltipTrigger({
|
|
1579
|
-
...props
|
|
1580
|
-
}: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {
|
|
1581
|
-
return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
function TooltipContent({
|
|
1585
|
-
className,
|
|
1586
|
-
sideOffset = 0,
|
|
1587
|
-
children,
|
|
1588
|
-
...props
|
|
1589
|
-
}: React.ComponentProps<typeof TooltipPrimitive.Content>) {
|
|
1590
|
-
return (
|
|
1591
|
-
<TooltipPrimitive.Portal>
|
|
1592
|
-
<TooltipPrimitive.Content
|
|
1593
|
-
data-slot="tooltip-content"
|
|
1594
|
-
sideOffset={sideOffset}
|
|
1595
|
-
className={cn(
|
|
1596
|
-
"fade-in-0 zoom-in-95 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) animate-in text-balance rounded-md bg-foreground px-3 py-1.5 text-background text-xs data-[state=closed]:animate-out",
|
|
1597
|
-
className,
|
|
1598
|
-
)}
|
|
1599
|
-
{...props}
|
|
1600
|
-
>
|
|
1601
|
-
{children}
|
|
1602
|
-
<TooltipPrimitive.Arrow className="z-50 size-2.5 translate-y-[calc(-50%_-_2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground" />
|
|
1603
|
-
</TooltipPrimitive.Content>
|
|
1604
|
-
</TooltipPrimitive.Portal>
|
|
1605
|
-
);
|
|
286
|
+
"iconLibrary": "lucide",
|
|
287
|
+
"registries": {
|
|
288
|
+
"@assistant-ui": "https://r.assistant-ui.com/{name}.json"
|
|
289
|
+
}
|
|
1606
290
|
}
|
|
1607
291
|
|
|
1608
|
-
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };
|
|
1609
|
-
|
|
1610
292
|
```
|
|
1611
293
|
|
|
1612
294
|
## lib/utils.ts
|
|
@@ -1648,29 +330,29 @@ export default nextConfig;
|
|
|
1648
330
|
"start": "next start"
|
|
1649
331
|
},
|
|
1650
332
|
"dependencies": {
|
|
333
|
+
"@ag-ui/client": "^0.0.43",
|
|
1651
334
|
"@assistant-ui/react": "workspace:*",
|
|
1652
|
-
"@assistant-ui/react-markdown": "workspace:*",
|
|
1653
335
|
"@assistant-ui/react-ag-ui": "workspace:*",
|
|
1654
|
-
"@
|
|
336
|
+
"@assistant-ui/react-markdown": "workspace:*",
|
|
337
|
+
"@assistant-ui/ui": "workspace:*",
|
|
1655
338
|
"@radix-ui/react-avatar": "^1.1.11",
|
|
339
|
+
"@radix-ui/react-collapsible": "^1.1.12",
|
|
1656
340
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
1657
341
|
"@radix-ui/react-slot": "^1.2.4",
|
|
1658
342
|
"@radix-ui/react-tooltip": "^1.2.8",
|
|
1659
343
|
"class-variance-authority": "^0.7.1",
|
|
1660
344
|
"clsx": "^2.1.1",
|
|
1661
|
-
"lucide-react": "^0.
|
|
1662
|
-
"next": "16.1.
|
|
1663
|
-
"react": "19.2.
|
|
1664
|
-
"react-dom": "19.2.
|
|
1665
|
-
"
|
|
1666
|
-
"tailwind-merge": "^3.4.0",
|
|
1667
|
-
"zustand": "^5.0.9"
|
|
345
|
+
"lucide-react": "^0.563.0",
|
|
346
|
+
"next": "^16.1.5",
|
|
347
|
+
"react": "^19.2.4",
|
|
348
|
+
"react-dom": "^19.2.4",
|
|
349
|
+
"tailwind-merge": "^3.4.0"
|
|
1668
350
|
},
|
|
1669
351
|
"devDependencies": {
|
|
1670
352
|
"@assistant-ui/x-buildutils": "workspace:*",
|
|
1671
353
|
"@tailwindcss/postcss": "^4.1.18",
|
|
1672
|
-
"@types/node": "^25.0.
|
|
1673
|
-
"@types/react": "^19.2.
|
|
354
|
+
"@types/node": "^25.0.10",
|
|
355
|
+
"@types/react": "^19.2.9",
|
|
1674
356
|
"@types/react-dom": "^19.2.3",
|
|
1675
357
|
"postcss": "^8.5.6",
|
|
1676
358
|
"tailwindcss": "^4.1.18",
|
|
@@ -1681,13 +363,64 @@ export default nextConfig;
|
|
|
1681
363
|
|
|
1682
364
|
```
|
|
1683
365
|
|
|
366
|
+
## README.md
|
|
367
|
+
|
|
368
|
+
```markdown
|
|
369
|
+
# AG-UI Protocol Integration
|
|
370
|
+
|
|
371
|
+
This example demonstrates how to integrate assistant-ui with the AG-UI protocol for connecting to AG-UI compatible agents.
|
|
372
|
+
|
|
373
|
+
## Quick Start
|
|
374
|
+
|
|
375
|
+
### Using CLI (Recommended)
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
npx assistant-ui@latest create my-app --example with-ag-ui
|
|
379
|
+
cd my-app
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Environment Variables
|
|
383
|
+
|
|
384
|
+
Create `.env.local`:
|
|
385
|
+
|
|
386
|
+
```
|
|
387
|
+
NEXT_PUBLIC_AGUI_AGENT_URL=http://localhost:8000/agent
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Run
|
|
391
|
+
|
|
392
|
+
```bash
|
|
393
|
+
npm run dev
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
## Features
|
|
397
|
+
|
|
398
|
+
- AG-UI protocol integration via `@assistant-ui/react-ag-ui`
|
|
399
|
+
- Custom browser alert tool demonstration
|
|
400
|
+
- Client-side tool execution
|
|
401
|
+
- Tool result rendering
|
|
402
|
+
|
|
403
|
+
## Related Documentation
|
|
404
|
+
|
|
405
|
+
- [assistant-ui Documentation](https://www.assistant-ui.com/docs)
|
|
406
|
+
- [AG-UI Protocol](https://docs.ag-ui.com)
|
|
407
|
+
|
|
408
|
+
```
|
|
409
|
+
|
|
1684
410
|
## tsconfig.json
|
|
1685
411
|
|
|
1686
412
|
```json
|
|
1687
413
|
{
|
|
1688
414
|
"extends": "@assistant-ui/x-buildutils/ts/next",
|
|
1689
415
|
"compilerOptions": {
|
|
1690
|
-
"paths": {
|
|
416
|
+
"paths": {
|
|
417
|
+
"@/*": ["./*"],
|
|
418
|
+
"@/components/assistant-ui/*": [
|
|
419
|
+
"../../packages/ui/src/components/assistant-ui/*"
|
|
420
|
+
],
|
|
421
|
+
"@/components/ui/*": ["../../packages/ui/src/components/ui/*"],
|
|
422
|
+
"@assistant-ui/ui/*": ["../../packages/ui/src/*"]
|
|
423
|
+
}
|
|
1691
424
|
},
|
|
1692
425
|
"include": ["**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
1693
426
|
"exclude": ["node_modules"]
|