Skip to content

Commit

Permalink
feat: ThreadConfig.UserMessage / AssistantMessage / EditComposer (#1172)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Nov 13, 2024
1 parent 5462390 commit 0fb80c1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/serious-suns-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

feat: ThreadConfig.UserMessage / AssistantMessage / EditComposer
2 changes: 1 addition & 1 deletion apps/docs/content/docs/components/content-part.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ToolCallContentPartState,
} from "@/generated/typeDocs";

Each message (user or assistant) can have any number of content parts.
Each message can have any number of content parts.
Content parts are usually one of text, audio or tool-call.
Additionally, image and file content parts are available, but rarely used, since these are usually included as content parts of message attachments.

Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/ui/thread-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ export type ThreadConfig = {

components?:
| {
UserMessage?: ComponentType | undefined;
AssistantMessage?: ComponentType | undefined;
EditComposer?: ComponentType | undefined;
Composer?: ComponentType | undefined;
ThreadWelcome?: ComponentType | undefined;
}
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/ui/thread.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { ComponentType, forwardRef, type FC } from "react";
import { forwardRef, type FC } from "react";
import { ArrowDownIcon } from "lucide-react";

import { withDefaults } from "./utils/withDefaults";
Expand All @@ -27,13 +27,14 @@ const Thread: FC<ThreadConfig> = (config) => {
components: {
Composer: ComposerComponent = Composer,
ThreadWelcome: ThreadWelcomeComponent = ThreadWelcome,
...messageComponents
} = {},
} = config;
return (
<ThreadRoot config={config}>
<ThreadViewport>
<ThreadWelcomeComponent />
<ThreadMessages />
<ThreadMessages components={messageComponents} />
<ThreadFollowupSuggestions />
<ThreadViewportFooter>
<ThreadScrollToBottom />
Expand Down Expand Up @@ -77,11 +78,9 @@ const ThreadViewportFooter = withDefaults("div", {

ThreadViewportFooter.displayName = "ThreadViewportFooter";

const SystemMessage = () => null;

const ThreadMessages: FC<{
unstable_flexGrowDiv?: boolean;
components?: ThreadPrimitive.Messages.Props["components"];
components?: Partial<ThreadPrimitive.Messages.Props["components"]>;
}> = ({ components, unstable_flexGrowDiv: flexGrowDiv = true, ...rest }) => {
return (
<>
Expand All @@ -90,7 +89,6 @@ const ThreadMessages: FC<{
...components,
UserMessage: components?.UserMessage ?? UserMessage,
AssistantMessage: components?.AssistantMessage ?? AssistantMessage,
SystemMessage: components?.SystemMessage ?? SystemMessage,
EditComposer: components?.EditComposer ?? EditComposer,
}}
{...rest}
Expand Down

0 comments on commit 0fb80c1

Please sign in to comment.